1 package org.enhydra.shark.swingclient; 2 3 import java.text.SimpleDateFormat ; 4 import java.util.ArrayList ; 5 import java.util.Calendar ; 6 import java.util.Date ; 7 import java.util.GregorianCalendar ; 8 import java.util.HashMap ; 9 import java.util.Iterator ; 10 import java.util.LinkedHashMap ; 11 import java.util.Map ; 12 13 import org.enhydra.shark.Shark; 14 import org.enhydra.shark.api.client.timebase.UtcT; 15 import org.enhydra.shark.api.client.wfbase.BaseException; 16 import org.enhydra.shark.api.client.wfmodel.WfActivity; 17 18 21 public class WorkflowUtilities { 22 23 public static final String BOOLEAN_KEY="BooleanKey"; 24 public static final String STRING_KEY="StringKey"; 25 public static final String INTEGER_KEY="IntegerKey"; 26 public static final String DOUBLE_KEY="DoubleKey"; 27 public static final String DATE_KEY="DateKey"; 28 public static final String ENUMERATION_KEY="EnumerationKey"; 29 public static final String ARRAY_KEY="ArrayKey"; 30 public static final String UNKNOWN_KEY="UnknownKey"; 31 public static final String MAP_KEY="MapKey"; 32 33 public static final String VARIABLE_TO_PROCESS_UPDATE="VariableToProcess_UPDATE"; 34 public static final String VARIABLE_TO_PROCESS_VIEW="VariableToProcess_VIEW"; 35 public static final String VARIABLE_TO_PROCESS_ALL="VariableToProcess_ALL"; 36 37 public static ArrayList convertMapToTheListOfNameValueString (Map m) { 38 ArrayList l=new ArrayList (); 39 if (m!=null) { 40 for (Iterator i=m.entrySet().iterator(); i.hasNext();) { 41 Map.Entry me=(Map.Entry )i.next(); 42 l.add(new NameValueStringMap((String )me.getKey(),(String )me.getValue())); 43 } 44 } 45 return l; 46 } 47 48 57 58 public static String getTypeKeyOfAnyObject (Object theValueHolder) { 59 try { 60 if (theValueHolder instanceof Boolean ) { 62 return BOOLEAN_KEY; 63 } else if (theValueHolder instanceof String ) { 64 return STRING_KEY; 65 } else if (theValueHolder instanceof Date ) { 66 return DATE_KEY; 67 } else if (theValueHolder instanceof Long ) { 68 return INTEGER_KEY; 69 } else if (theValueHolder instanceof Double ) { 70 return DOUBLE_KEY; 71 } else if (theValueHolder instanceof HashMap ) { 72 return MAP_KEY; 73 } else { 78 return UNKNOWN_KEY; 79 } 80 } catch (Exception bo) { 81 return UNKNOWN_KEY; 82 } 83 } 84 85 public static String getTypeKeyOfAnyObject (String javaClassName) { 86 try { 87 if (javaClassName.equals(Boolean .class.getName())) { 89 return BOOLEAN_KEY; 90 } else if (javaClassName.equals(String .class.getName())) { 91 return STRING_KEY; 92 } else if (javaClassName.equals(Date .class.getName())) { 93 return DATE_KEY; 94 } else if (javaClassName.equals(Long .class.getName())) { 95 return INTEGER_KEY; 96 } else if (javaClassName.equals(Double .class.getName())) { 97 return DOUBLE_KEY; 98 } else if (javaClassName.equals(HashMap .class.getName())) { 99 return MAP_KEY; 100 } else { 105 return UNKNOWN_KEY; 106 } 107 } catch (Exception bo) { 108 return UNKNOWN_KEY; 109 } 110 } 111 112 public static Object insertValueIntoAnyObject (Object theValueHolder,String txtVal,String typeKey) { 113 try { 114 if (typeKey.equals(BOOLEAN_KEY)) { 115 if (txtVal.equalsIgnoreCase("true") || txtVal.equalsIgnoreCase("false")) { 116 Boolean val=new Boolean (txtVal); 117 theValueHolder=val; 118 } else { 119 return null; 120 } 121 } else if (typeKey.equals(STRING_KEY)) { 122 theValueHolder=txtVal; 123 } else if (typeKey.equals(DATE_KEY)) { 124 System.out.println("dte="+txtVal); 125 SimpleDateFormat sdf=new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss"); 126 theValueHolder=sdf.parse(txtVal); 127 System.out.println("dtec="+theValueHolder); 128 } else if (typeKey.equals(INTEGER_KEY)) { 129 theValueHolder=new Long (txtVal); 130 } else if (typeKey.equals(DOUBLE_KEY)) { 131 theValueHolder=new Double (txtVal); 132 } else { 142 System.out.println("Unknown type"); 143 return null; 144 } 145 } catch (Exception ex) { 146 System.out.println("Wrong value"); 147 ex.printStackTrace(); 148 return null; 149 } 150 return theValueHolder; 151 } 152 153 158 public static Map getActivityContext (Map contextToSearch, 159 WfActivity act,String type) throws BaseException { 160 169 String [][] extAttribs=null; 170 try { 171 extAttribs=Shark.getInstance().getAdminInterface().getAdminMisc(). 172 getActivitiesExtendedAttributeNameValuePairs(act.container().key(),act.key()); 173 } catch (Exception ex) {} 174 175 Map updateContext=new LinkedHashMap (); 176 if (extAttribs!=null) { 177 for (int i=0; i<extAttribs.length; i++) { 178 String eaName=extAttribs[i][0]; 179 if (type.equals(VARIABLE_TO_PROCESS_ALL)) { 180 if (eaName.equalsIgnoreCase(VARIABLE_TO_PROCESS_UPDATE) || 181 eaName.equalsIgnoreCase(VARIABLE_TO_PROCESS_VIEW)) { 182 String variableId=extAttribs[i][1]; 183 if (contextToSearch.containsKey(variableId)) { 184 updateContext.put(variableId,contextToSearch.get(variableId)); 185 } 186 } 187 } else { 188 if (eaName.equalsIgnoreCase(type)) { 189 String variableId=extAttribs[i][1]; 190 if (contextToSearch.containsKey(variableId)) { 191 updateContext.put(variableId,contextToSearch.get(variableId)); 192 } 193 } 194 } 195 } 196 } 197 198 return updateContext; 199 } 200 201 205 public static String getDateFromUTC (UtcT utct) { 206 String dateSeparator="-"; 209 String timeSeparator=":"; 210 Calendar cal=new GregorianCalendar (); 211 cal.setTimeInMillis(utct.time); 212 213 int YYYY=cal.get(Calendar.YEAR); 214 int MM=cal.get(Calendar.MONTH)+1; 215 int DD=cal.get(Calendar.DAY_OF_MONTH); 216 int HH=cal.get(Calendar.HOUR_OF_DAY); 217 int mm=cal.get(Calendar.MINUTE); 218 int ss=cal.get(Calendar.SECOND); 219 int mmm=cal.get(Calendar.MILLISECOND); 220 221 String dateTime=""; 222 223 dateTime=dateTime+String.valueOf(YYYY)+dateSeparator; 224 if (MM<10) { 225 dateTime=dateTime+"0"; 226 } 227 dateTime=dateTime+String.valueOf(MM)+dateSeparator; 228 if (DD<10) { 229 dateTime=dateTime+"0"; 230 } 231 dateTime=dateTime+String.valueOf(DD)+" "; 232 233 if (cal.get(Calendar.AM_PM)==Calendar.PM && HH<12) { 234 HH+=12; 235 } 236 if (HH<10) { 237 dateTime=dateTime+"0"; 238 } 239 dateTime=dateTime+String.valueOf(HH)+timeSeparator; 240 241 if (mm<10) { 242 dateTime=dateTime+"0"; 243 } 244 dateTime=dateTime+String.valueOf(mm)+timeSeparator; 245 246 if (ss<10) { 247 dateTime=dateTime+"0"; 248 } 249 dateTime=dateTime+String.valueOf(ss)+timeSeparator; 250 251 if (mmm<10) { 252 dateTime=dateTime+"00"; 253 } else if (mmm<100) { 254 dateTime=dateTime+"0"; 255 } else { 256 dateTime=dateTime; 257 } 258 dateTime=dateTime+String.valueOf(mmm); 259 260 return dateTime; 261 } 262 263 public static String getDuration (UtcT started) { 264 long sec=1000; 265 long min=sec*60; 266 long hour=min*60; 267 long day=hour*24; 268 long month=day*30; 269 long year=365*day; 270 271 long diffInMills=System.currentTimeMillis()-started.time; 273 if (diffInMills<min) { 274 return String.valueOf(diffInMills/sec)+" [s]"; 275 } else if (diffInMills<hour) { 276 long m=diffInMills/min; 277 long s=(diffInMills-m*min)/sec; 278 return String.valueOf(m)+" [min] "+String.valueOf(s)+" [s]"; 279 } else if (diffInMills<day) { 280 long h=diffInMills/hour; 281 long m=(diffInMills-h*hour)/min; 282 long s=(diffInMills-h*hour-m*min)/sec; 283 return String.valueOf(h)+" [h] "+String.valueOf(m)+" [min] "+ 284 String.valueOf(s)+" [s]"; 285 } else if (diffInMills<month) { 286 long d=diffInMills/day; 287 long h=(diffInMills-d*day)/hour; 288 long m=(diffInMills-d*day-h*hour)/min; 289 long s=(diffInMills-d*day-h*hour-m*min)/sec; 290 return String.valueOf(d)+" [d] "+String.valueOf(h)+" [h] "+ 291 String.valueOf(m)+" [min] "+String.valueOf(s)+" [s]"; 292 } else if (diffInMills<year) { 293 long mn=diffInMills/month; 294 long d=(diffInMills-mn*month)/day; 295 long h=(diffInMills-mn*month-d*day)/hour; 296 long m=(diffInMills-mn*month-d*day-h*hour)/min; 297 long s=(diffInMills-mn*month-d*day-h*hour-m*min)/sec; 298 return String.valueOf(mn)+" [m] "+String.valueOf(d)+" [d] "+ 299 String.valueOf(h)+" [h] "+String.valueOf(m)+ 300 " [min] "+String.valueOf(s)+" [s]"; 301 } else { long y=diffInMills/year; 303 long mn=(diffInMills-y*year)/month; 304 long d=(diffInMills-y*year-mn*month)/day; 305 long h=(diffInMills-y*year-mn*month-d*day)/hour; 306 long m=(diffInMills-y*year-mn*month-d*day-h*hour)/min; 307 long s=(diffInMills-y*year-mn*month-d*day-h*hour-m*min)/sec; 308 return String.valueOf(y)+" [y] "+String.valueOf(mn)+" [m] "+ 309 String.valueOf(d)+" [d] "+String.valueOf(h)+" [h] "+ 310 String.valueOf(m)+" [min] "+String.valueOf(s)+" [s]"; 311 } 312 } 313 314 public static String createParticipantOrApplicationKey (String packageId,String processDefinitionId, 315 String participantOrAppDefId) { 316 if (processDefinitionId==null) processDefinitionId=""; 317 String key=""; 318 if( processDefinitionId == null ) processDefinitionId = ""; 319 key+=packageId+";"+processDefinitionId+";"+participantOrAppDefId; 320 return key; 321 } 322 323 372 373 } 374 | Popular Tags |