1 19 package org.openharmonise.him.window.messages.builders; 20 21 import java.util.ArrayList ; 22 import java.util.HashMap ; 23 import java.util.Iterator ; 24 import java.util.List ; 25 26 import org.openharmonise.him.actions.dir.*; 27 import org.openharmonise.him.actions.file.*; 28 import org.openharmonise.him.actions.move.*; 29 import org.openharmonise.him.actions.publish.*; 30 import org.openharmonise.him.actions.system.*; 31 import org.openharmonise.him.harmonise.*; 32 import org.openharmonise.him.window.messages.*; 33 import org.openharmonise.vfs.status.*; 34 import org.openharmonise.webdav.client.*; 35 36 37 43 public class VFSMessageBuilder extends AbstractMessageBuilder implements 44 MessageBuilder { 45 46 private static MessageBuilder m_instance = null; 47 48 private HashMap m_statusStatementMapping = new HashMap (); 49 50 53 private VFSMessageBuilder() { 54 super(); 55 this.setup(); 56 } 57 58 private void setup() { 59 ActionStatement actionStatement = new ActionStatement(); 61 actionStatement.setKnownResourceOK("You have successfully ordered %NAME%."); 62 actionStatement.setUnknownResourceOK("You have successfully ordered this collection."); 63 actionStatement.setKnownResourceERROR("There was a problem ordering %NAME%."); 64 actionStatement.setUnknownResourceERROR("There was a problem ordering this collection."); 65 super.addActionStatementMapping(ActionOrder.ACTION_NAME, actionStatement); 66 67 actionStatement = new ActionStatement(); 68 actionStatement.setKnownResourceOK("You have successfully created a copy of %NAME%."); 69 actionStatement.setUnknownResourceOK("You have successfully created a copy of this resource."); 70 actionStatement.setKnownResourceERROR("There was a problem creating a copy of %NAME%."); 71 actionStatement.setUnknownResourceERROR("There was a problem creating a copy of this resource."); 72 super.addActionStatementMapping(ActionCreateCopy.ACTION_NAME, actionStatement); 73 74 actionStatement = new ActionStatement(); 75 actionStatement.setKnownResourceOK("You have successfully locked %NAME%."); 76 actionStatement.setUnknownResourceOK("You have successfully locked this resource."); 77 actionStatement.setKnownResourceERROR("There was a problem locking %NAME%, it is locked by %DESTINATION%."); 78 actionStatement.setUnknownResourceERROR("There was a problem locking this resource."); 79 super.addActionStatementMapping(ActionLock.ACTION_NAME, actionStatement); 80 81 actionStatement = new ActionStatement(); 82 actionStatement.setKnownResourceOK("You have successfully created the collection %NAME%."); 83 actionStatement.setUnknownResourceOK("You have successfully created a new collection."); 84 actionStatement.setKnownResourceERROR("There was a problem creating the collection %NAME%."); 85 actionStatement.setUnknownResourceERROR("There was a problem creating this new collection."); 86 super.addActionStatementMapping(ActionNewCollection.ACTION_NAME, actionStatement); 87 88 actionStatement = new ActionStatement(); 89 actionStatement.setKnownResourceOK("You have successfully created the resource %NAME%."); 90 actionStatement.setUnknownResourceOK("You have successfully created a new resource."); 91 actionStatement.setKnownResourceERROR("There was a problem creating the resource %NAME%."); 92 actionStatement.setUnknownResourceERROR("There was a problem creating this new resource."); 93 super.addActionStatementMapping(ActionNewFile.ACTION_NAME, actionStatement); 94 95 actionStatement = new ActionStatement(); 96 actionStatement.setKnownResourceOK("%NAME% opened."); 97 actionStatement.setUnknownResourceOK("Resource opened."); 98 actionStatement.setKnownResourceERROR("There was a problem opening the resource %NAME%."); 99 actionStatement.setUnknownResourceERROR("There was a problem opening this new resource."); 100 super.addActionStatementMapping(ActionOpen.ACTION_NAME, actionStatement); 101 102 actionStatement = new ActionStatement(); 103 actionStatement.setKnownResourceOK("You have successfully renamed %NAME% to %DESTINATION%."); 104 actionStatement.setUnknownResourceOK("You have successfully renamed this resource."); 105 actionStatement.setKnownResourceERROR("There was a problem renaming %NAME% to %DESTINATION%."); 106 actionStatement.setUnknownResourceERROR("There was a problem renaming this resource."); 107 super.addActionStatementMapping(ActionRename.ACTION_NAME, actionStatement); 108 109 actionStatement = new ActionStatement(); 110 actionStatement.setKnownResourceOK("You have successfully submitted %NAME% to the server."); 111 actionStatement.setUnknownResourceOK("You have successfully submitted this resource to the server."); 112 actionStatement.setKnownResourceERROR("There was a problem submitting %NAME% to the server."); 113 actionStatement.setUnknownResourceERROR("There was a problem submitting this resource to the server."); 114 super.addActionStatementMapping(ActionSynchronise.ACTION_NAME, actionStatement); 115 116 actionStatement = new ActionStatement(); 117 actionStatement.setKnownResourceOK("You have successfully unlocked %NAME%."); 118 actionStatement.setUnknownResourceOK("You have successfully unlocked this resource."); 119 actionStatement.setKnownResourceERROR("There was a problem unlocking %NAME%, it is locked by %DESTINATION%."); 120 actionStatement.setUnknownResourceERROR("There was a problem unlocking this resource."); 121 super.addActionStatementMapping(ActionUnlock.ACTION_NAME, actionStatement); 122 123 actionStatement = new ActionStatement(); 124 actionStatement.setKnownResourceOK("You have successfully uploaded %NAME%."); 125 actionStatement.setUnknownResourceOK("You have successfully uploaded this resource."); 126 actionStatement.setKnownResourceERROR("There was a problem uploading %NAME%."); 127 actionStatement.setUnknownResourceERROR("There was a problem uploading this resource."); 128 super.addActionStatementMapping(ActionUpload.ACTION_NAME, actionStatement); 129 130 actionStatement = new ActionStatement(); 131 actionStatement.setKnownResourceOK("ALIAS %NAME%."); 132 actionStatement.setUnknownResourceOK("ALIAS."); 133 actionStatement.setKnownResourceERROR("ALIAS %NAME%."); 134 actionStatement.setUnknownResourceERROR("ALIAS."); 135 super.addActionStatementMapping(ActionAlias.ACTION_NAME, actionStatement); 136 137 actionStatement = new ActionStatement(); 138 actionStatement = new ActionStatement(); 139 actionStatement.setKnownResourceOK("You have successfully copied %NAME% to %DESTINATION%."); 140 actionStatement.setUnknownResourceOK("You have successfully copied this resource."); 141 actionStatement.setKnownResourceERROR("There was a problem copying %NAME% to %DESTINATION%."); 142 actionStatement.setUnknownResourceERROR("There was a problem copying this resource."); 143 super.addActionStatementMapping(ActionCopy.ACTION_NAME, actionStatement); 144 145 actionStatement = new ActionStatement(); 146 actionStatement.setKnownResourceOK("You have successfully moved %NAME% to %DESTINATION%."); 147 actionStatement.setUnknownResourceOK("You have successfully moved this resource."); 148 actionStatement.setKnownResourceERROR("There was a problem moving %NAME% to %DESTINATION%."); 149 actionStatement.setUnknownResourceERROR("There was a problem moving this resource."); 150 super.addActionStatementMapping(ActionMove.ACTION_NAME, actionStatement); 151 152 actionStatement = new ActionStatement(); 153 actionStatement.setKnownResourceOK("You have successfully archived %NAME%."); 154 actionStatement.setUnknownResourceOK("You have successfully archived this resource."); 155 actionStatement.setKnownResourceERROR("There was a problem archiving %NAME%."); 156 actionStatement.setUnknownResourceERROR("There was a problem archiving this resource."); 157 super.addActionStatementMapping(ActionArchive.ACTION_NAME, actionStatement); 158 159 actionStatement = new ActionStatement(); 160 actionStatement.setKnownResourceOK("You have successfully exported %NAME%."); 161 actionStatement.setUnknownResourceOK("You have successfully exported this resource."); 162 actionStatement.setKnownResourceERROR("There was a problem exporting %NAME%."); 163 actionStatement.setUnknownResourceERROR("There was a problem exporting this resource."); 164 super.addActionStatementMapping(ActionExport.ACTION_NAME, actionStatement); 165 166 actionStatement = new ActionStatement(); 167 actionStatement.setKnownResourceOK("%NAME% opened for preview."); 168 actionStatement.setUnknownResourceOK("Resource opened for preview."); 169 actionStatement.setKnownResourceERROR("There was a problem opening %NAME% for preview."); 170 actionStatement.setUnknownResourceERROR("There was a problem opening this resource for preview."); 171 super.addActionStatementMapping(ActionPreview.ACTION_NAME, actionStatement); 172 173 actionStatement = new ActionStatement(); 174 actionStatement.setKnownResourceOK("You have successfully published %NAME%."); 175 actionStatement.setUnknownResourceOK("You have successfully published this resource."); 176 actionStatement.setKnownResourceERROR("There was a problem publishing %NAME%."); 177 actionStatement.setUnknownResourceERROR("There was a problem publishing this resource."); 178 super.addActionStatementMapping(ActionPublishToInternet.ACTION_NAME, actionStatement); 179 180 actionStatement = new ActionStatement(); 181 actionStatement.setKnownResourceOK("You have successfully unpublished %NAME%."); 182 actionStatement.setUnknownResourceOK("You have successfully unpublished this resource."); 183 actionStatement.setKnownResourceERROR("There was a problem unpublishing %NAME%."); 184 actionStatement.setUnknownResourceERROR("There was a problem unpublishing this resource."); 185 super.addActionStatementMapping(ActionRemoveFromInternet.ACTION_NAME, actionStatement); 186 187 actionStatement = new ActionStatement(); 188 actionStatement.setKnownResourceOK("You have successfully retrieved %NAME%."); 189 actionStatement.setUnknownResourceOK("You have successfully retrieved this resource."); 190 actionStatement.setKnownResourceERROR("There was a problem retrieving %NAME%."); 191 actionStatement.setUnknownResourceERROR("There was a problem retrieving this resource."); 192 super.addActionStatementMapping(ActionRetrieve.ACTION_NAME, actionStatement); 193 194 actionStatement = new ActionStatement(); 195 actionStatement.setKnownResourceOK("NO STATEMENT."); 196 actionStatement.setUnknownResourceOK("You have successfully submitted these resources to the server."); 197 actionStatement.setKnownResourceERROR("NO STATEMENT."); 198 actionStatement.setUnknownResourceERROR("There was a problem submitting these resources to the server."); 199 super.addActionStatementMapping(ActionSyncWithServer.ACTION_NAME, actionStatement); 200 201 actionStatement = new ActionStatement(); 202 actionStatement.setKnownResourceOK("NO STATEMENT."); 203 actionStatement.setUnknownResourceOK("The search was successful."); 204 actionStatement.setKnownResourceERROR("NO STATEMENT."); 205 actionStatement.setUnknownResourceERROR("There was a problem searching."); 206 super.addActionStatementMapping("ACTION_SEARCH", actionStatement); 207 208 this.m_statusStatementMapping.put(Integer.toString(StatusData.STATUS_INVALID_PERMISSIONS), "You do not have the correct permissions, please contact an administrator. To view your permissions select the Help Menu > About > Who am I tab. "); 210 this.m_statusStatementMapping.put(Integer.toString(StatusData.STATUS_INVALID_REQUEST), "There was a problem with the information sent to the server, this is probably because some metadata was invalid (indicated by a red cross next to the invalid metadata). If all the metadata tabs for the resource have green ticks on them there is a problem with the metadata definiations and you should inform an administrator."); 211 this.m_statusStatementMapping.put(Integer.toString(StatusData.STATUS_COMMUNICATIONS_FAILURE), "There was a problem communicating with the server. Please check that you network connection is okay, if it is you should inform an administrator about this problem."); 212 this.m_statusStatementMapping.put(Integer.toString(StatusData.STATUS_RESOURCE_NOT_FOUND), "The resource was not found, it may have been archived or moved. Refresh the collection (System menu). If there is a still a problem you should inform a system adminstrator."); 213 this.m_statusStatementMapping.put(Integer.toString(StatusData.STATUS_INVALID_RESOURCE_STATE), "The state of the resource is not valid for this action. Refresh the collection. If there is a still a problem you should inform a system adminstrator."); 214 this.m_statusStatementMapping.put(Integer.toString(StatusData.STATUS_TIMEOUT), "The connection with the server timed out. Please check that you network connection is okay, if it is you should inform an administrator about this problem."); 215 this.m_statusStatementMapping.put(Integer.toString(StatusData.STATUS_SERVER_ERROR), "There was an error on the server. Please inform an administrator."); 216 this.m_statusStatementMapping.put(Integer.toString(StatusData.STATUS_RESOURCE_LOCKED), "The resource is already locked. Please contact the lock owner."); 217 this.m_statusStatementMapping.put(Integer.toString(StatusData.STATUS_REQUEST_CONDITIONS_NOT_MET), "The resource is already locked. Please contact the lock owner."); 218 this.m_statusStatementMapping.put(Integer.toString(StatusData.STATUS_OK), ""); 219 this.m_statusStatementMapping.put(Integer.toString(StatusData.STATUS_RESOURCE_EXISTS), "A resource of this name already exists in the collection."); 220 221 this.m_statusStatementMapping.put(ActionCopy.ACTION_NAME+"#"+Integer.toString(StatusData.STATUS_REQUEST_CONDITIONS_NOT_MET), "There is already a resource with that name in the destination collection."); 223 this.m_statusStatementMapping.put(ActionMove.ACTION_NAME+"#"+Integer.toString(StatusData.STATUS_REQUEST_CONDITIONS_NOT_MET), "Either the resource is locked by another user or there is already a resource with that name in the destination collection."); 224 this.m_statusStatementMapping.put(ActionRetrieve.ACTION_NAME+"#"+Integer.toString(StatusData.STATUS_REQUEST_CONDITIONS_NOT_MET), "There is already a resource with that name in the destination collection."); 225 this.m_statusStatementMapping.put(ActionNewCollection.ACTION_NAME+"#"+Integer.toString(StatusData.STATUS_INVALID_PERMISSIONS), "Either the collection you are in has never been published or you do not have permission to create collections here."); 226 this.m_statusStatementMapping.put(ActionNewFile.ACTION_NAME+"#"+Integer.toString(StatusData.STATUS_INVALID_PERMISSIONS), "Either the collection you are in has never been published or you do not have permission to create resources here."); 227 } 228 229 public static MessageBuilder getInstance() { 230 if(m_instance==null) { 231 m_instance = new VFSMessageBuilder(); 232 } 233 return m_instance; 234 } 235 236 239 public void fireMessage(String sActionName, Object statusInformation) { 240 StringBuffer sBuff = new StringBuffer (); 241 String sMessageLevel = MessageHandler.TYPE_CONFIRM; 242 if(statusInformation!=null && !((StatusData)statusInformation).isOK()) { 243 sMessageLevel = MessageHandler.TYPE_ERROR; 244 } 245 246 sBuff.append( this.getActionStatement(sMessageLevel, sActionName) ); 247 sBuff.append( this.buildStatusStatements(sActionName, (StatusData) statusInformation) ); 248 249 System.out.println(sBuff.toString()); 250 251 MessageHandler.getInstance().fireMessageEvent(sBuff.toString(), sMessageLevel); 252 } 253 254 257 public void fireMessage(String sActionName, Object statusInformation, 258 String sResourceTitle) { 259 StringBuffer sBuff = new StringBuffer (); 260 String sMessageLevel = MessageHandler.TYPE_CONFIRM; 261 if(statusInformation!=null && !((StatusData)statusInformation).isOK()) { 262 sMessageLevel = MessageHandler.TYPE_ERROR; 263 } 264 265 sBuff.append( this.getActionStatement(sMessageLevel, sActionName, sResourceTitle) ); 266 sBuff.append( this.buildStatusStatements(sActionName, (StatusData) statusInformation) ); 267 268 System.out.println(sBuff.toString()); 269 270 MessageHandler.getInstance().fireMessageEvent(sBuff.toString(), sMessageLevel); 271 } 272 273 276 public void fireMessage(String sActionName, 277 Object statusInformation, String sResourceTitle, 278 String sDestinationTitle) { 279 StringBuffer sBuff = new StringBuffer (); 280 String sMessageLevel = MessageHandler.TYPE_CONFIRM; 281 if(statusInformation!=null && !((StatusData)statusInformation).isOK()) { 282 sMessageLevel = MessageHandler.TYPE_ERROR; 283 } 284 285 sBuff.append( this.getActionStatement(sMessageLevel, sActionName, sResourceTitle, sDestinationTitle) ); 286 sBuff.append( this.buildStatusStatements(sActionName, (StatusData) statusInformation) ); 287 288 System.out.println(sBuff.toString()); 289 290 MessageHandler.getInstance().fireMessageEvent(sBuff.toString(), sMessageLevel); 291 } 292 293 296 public void fireMessage(StatusMessage statusMessage) { 297 if(statusMessage.getPath()==null) { 298 if(statusMessage.getResourceTitle()!=null && statusMessage.getDestinationTitle()!=null) { 299 this.fireMessage(statusMessage.getActionName(), statusMessage.getStatusInformation(), statusMessage.getResourceTitle(), statusMessage.getDestinationTitle()); 300 } else if(statusMessage.getResourceTitle()!=null) { 301 this.fireMessage(statusMessage.getActionName(), statusMessage.getStatusInformation(), statusMessage.getResourceTitle()); 302 } else { 303 this.fireMessage(statusMessage.getActionName(), statusMessage.getStatusInformation()); 304 } 305 } else { 306 StringBuffer sBuff = new StringBuffer (); 307 String sMessageLevel = MessageHandler.TYPE_CONFIRM; 308 if(statusMessage.getStatusInformation()!=null && !((StatusData)statusMessage.getStatusInformation()).isOK()) { 309 sMessageLevel = MessageHandler.TYPE_ERROR; 310 } 311 312 if(statusMessage.getResourceTitle()!=null && statusMessage.getDestinationTitle()!=null) { 313 sBuff.append( this.getActionStatement(sMessageLevel, statusMessage.getActionName(), statusMessage.getResourceTitle(), statusMessage.getDestinationTitle()) ); 314 } else if(statusMessage.getResourceTitle()!=null) { 315 sBuff.append( this.getActionStatement(sMessageLevel, statusMessage.getActionName(), statusMessage.getResourceTitle()) ); 316 } else { 317 sBuff.append( this.getActionStatement(sMessageLevel, statusMessage.getActionName()) ); 318 } 319 320 if(statusMessage.getPath()!=null) { 321 sBuff.append( this.buildStatusStatements(statusMessage.getActionName(), (StatusData) statusMessage.getStatusInformation(), statusMessage.getPath()) ); 322 } else { 323 sBuff.append( this.buildStatusStatements(statusMessage.getActionName(), (StatusData) statusMessage.getStatusInformation()) ); 324 } 325 326 System.out.println(sBuff.toString()); 327 328 MessageHandler.getInstance().fireMessageEvent(sBuff.toString(), sMessageLevel); 329 } 330 } 331 332 private StringBuffer buildStatusStatements(String sActionName, StatusData status, String sPath) { 333 StringBuffer sBuff = new StringBuffer (); 334 335 ArrayList aCodes = new ArrayList (); 336 337 List aWorstStatus = this.getWorstStatusData(status); 338 Iterator itor = aWorstStatus.iterator(); 339 while (itor.hasNext()) { 340 StatusData element = (StatusData) itor.next(); 341 aCodes.add(new Integer ( element.getStatusCode() )); 342 } 343 344 if(sPath.startsWith(HarmonisePaths.PATH_USERS) && aCodes.contains(new Integer (StatusData.STATUS_INVALID_PERMISSIONS))) { 345 sBuff.append(" Either you do not have permission to do this, the user group you are in has never been published or there is another user with this name."); 346 } else if(sPath.startsWith(HarmonisePaths.PATH_PROPERTIES) && aCodes.contains(new Integer (StatusData.STATUS_INVALID_PERMISSIONS))) { 347 sBuff.append(" Either you do not have permission to do this, the property group you are in has never been published or there is another property with this name."); 348 } else if(sPath.startsWith(HarmonisePaths.PATH_WORKFLOW_STAGES) && aCodes.contains(new Integer (StatusData.STATUS_INVALID_PERMISSIONS))) { 349 sBuff.append(" Either there is a Workflow Stage in this collection (you cannot create a new collection if there is a Workflow Stage at the same level), you do not have permission to do this or the collection you are in has never been published."); 350 } else if(sActionName.equals(ActionPublishToInternet.ACTION_NAME) && sPath.startsWith(HarmonisePaths.PATH_WORKFLOW_PROPS) && aCodes.contains(new Integer (StatusData.STATUS_INVALID_RESOURCE_STATE))) { 351 sBuff.append(" This Workflow either has missing metadata or its Domain overlaps with that of another Workflow. This is not permitted, please ensure that Workflow Domains do not overlap."); 352 } else { 353 sBuff.append( this.buildStatusStatements(sActionName, status) ); 354 } 355 356 return sBuff; 357 } 358 359 private StringBuffer buildStatusStatements(String sActionName, StatusData status) { 360 StringBuffer sBuff = new StringBuffer (); 361 if(status!=null) { 362 sBuff.append(" "); 363 364 String sMessage = (String ) this.m_statusStatementMapping.get(sActionName + "#" + Integer.toString(status.getStatusCode())); 365 if(sMessage==null) { 366 sMessage = (String ) this.m_statusStatementMapping.get(Integer.toString(status.getStatusCode())); 367 } 368 if(sMessage!=null) { 369 sBuff.append(sMessage); 370 } 371 372 List aStatus = this.getWorstStatusData(status); 373 Iterator itor = aStatus.iterator(); 374 while (itor.hasNext()) { 375 StatusData element = (StatusData) itor.next(); 376 sBuff.append(" "); 377 378 sMessage = (String ) this.m_statusStatementMapping.get(sActionName + "#" + Integer.toString(element.getStatusCode())); 379 if(sMessage==null) { 380 sMessage = (String ) this.m_statusStatementMapping.get(Integer.toString(element.getStatusCode())); 381 } 382 sBuff.append(sMessage); 383 } 384 } 385 386 return sBuff; 387 } 388 389 private List getWorstStatusData(StatusData status) { 390 List aStatus = new ArrayList (); 391 392 if(!status.isOK()) { 393 List tempStatus = status.getStatusData(status.getWorstLevel()); 394 Iterator itor = tempStatus.iterator(); 395 while(itor.hasNext()) { 396 StatusData tempStatusData = (StatusData) itor.next(); 397 aStatus.addAll(this.getWorstStatusData(tempStatusData)); 398 } 399 aStatus.addAll(tempStatus); 400 } 401 402 403 return aStatus; 404 } 405 406 public static void main(String [] args) { 407 StatusData status = new VFSStatusWebDAV(); 408 StatusData status2 = new VFSStatusWebDAV(408); 409 ((VFSStatusWebDAV)status).addStatusData(status2); 410 StatusData status3 = new VFSStatusWebDAV(409); 411 ((VFSStatusWebDAV)status).addStatusData(status3); 412 VFSMessageBuilder.getInstance().fireMessage(ActionOrder.ACTION_NAME, status); 413 414 status = new VFSStatusWebDAV(); 415 VFSMessageBuilder.getInstance().fireMessage(ActionOrder.ACTION_NAME, status, "Matt Col"); 416 417 status = new VFSStatusWebDAV(); 418 status2 = new VFSStatusWebDAV(401); 419 ((VFSStatusWebDAV)status).addStatusData(status2); 420 status3 = new VFSStatusWebDAV(402); 421 ((VFSStatusWebDAV)status).addStatusData(status3); 422 VFSMessageBuilder.getInstance().fireMessage(ActionOrder.ACTION_NAME, status, "Matt Col"); 423 424 status = new VFSStatusWebDAV(); 425 status2 = new VFSStatusWebDAV(401); 426 ((VFSStatusWebDAV)status).addStatusData(status2); 427 status3 = new VFSStatusWebDAV(402); 428 ((VFSStatusWebDAV)status).addStatusData(status3); 429 VFSMessageBuilder.getInstance().fireMessage(ActionCopy.ACTION_NAME, status, "resource1", "col2"); 430 431 432 VFSMessageBuilder.getInstance().fireMessage(ActionMove.ACTION_NAME, null, "resource1", "col2"); 433 434 } 435 436 } 437 | Popular Tags |