1 19 20 package org.openharmonise.dav.server.apm; 21 22 23 import java.io.*; 24 import java.util.*; 25 import java.util.logging.*; 26 27 import javax.xml.parsers.*; 28 29 import org.openharmonise.commons.dsi.*; 30 import org.openharmonise.commons.net.*; 31 import org.openharmonise.commons.xml.*; 32 import org.openharmonise.commons.xml.namespace.*; 33 import org.openharmonise.dav.server.utils.*; 34 import org.openharmonise.rm.*; 35 import org.openharmonise.rm.DataAccessException; 36 import org.openharmonise.rm.config.*; 37 import org.openharmonise.rm.dsi.*; 38 import org.openharmonise.rm.factory.*; 39 import org.openharmonise.rm.metadata.*; 40 import org.openharmonise.rm.resources.*; 41 import org.openharmonise.rm.resources.content.*; 42 import org.openharmonise.rm.resources.content.utils.*; 43 import org.openharmonise.rm.resources.lifecycle.*; 44 import org.openharmonise.rm.resources.metadata.properties.*; 45 import org.openharmonise.rm.resources.metadata.values.*; 46 import org.openharmonise.rm.resources.publishing.*; 47 import org.openharmonise.rm.resources.users.*; 48 import org.openharmonise.rm.resources.workflow.properties.*; 49 import org.openharmonise.rm.resources.workflow.properties.ranges.*; 50 import org.openharmonise.rm.resources.workflow.values.*; 51 import org.openharmonise.rm.resources.xml.*; 52 import org.openharmonise.rm.workflow.*; 53 import org.w3c.dom.*; 54 import org.xml.sax.*; 55 56 57 68 public class StandardAPM implements AuxillaryProcessManager { 69 70 private static final String ATTRIB_HREF = "href"; 71 protected static final String PNAME_IMAGE_THUMBNAIL_SIZE = "IMAGE_THUMBNAIL_SIZE"; 72 73 private static final String PROPNAME_WORKFLOW_PROP_RELN = "workflow_prop"; 74 protected static final String SECTION_CONVERSION = "conversions"; 75 protected static final String PROPNAME_THUMBNAIL = "thumbnail"; 76 protected static final String PROPNAME_LOWRES = "lowres"; 77 protected static final String MIMETYPE_THUMBNAIL = "image/png"; 78 protected static final String MIMETYPE_LOWRES = "image/jpg"; 79 protected int m_nSizeThumbnail = 50; 80 81 82 { 83 try { 84 m_nSizeThumbnail = 85 ConfigSettings.getIntProperty( 86 PNAME_IMAGE_THUMBNAIL_SIZE, 87 "50"); 88 } catch (ConfigException e) { 89 m_logger.log(Level.WARNING, "Ignoring config exception for thumbnail size", e); 90 } 91 } 92 93 protected AbstractDataStoreInterface m_dsi = null; 94 95 98 private static final Logger m_logger = Logger.getLogger(StandardAPM.class.getName()); 99 100 103 public StandardAPM() throws DataStoreException { 104 super(); 105 106 m_dsi = DataStoreInterfaceFactory.getDataStoreInterface(); 107 108 } 109 110 111 114 public void save(User usr, AbstractChildObject obj) throws APMException { 115 116 try { 117 118 if (obj instanceof WorkflowProperty) { 119 WorkflowProperty prop = (WorkflowProperty) obj; 120 121 String sPath = prop.getFullPath(); 122 123 sPath = sPath.replaceAll("/root/workflow", "/root/workflow_defs"); 124 125 126 WorkflowStageValueGroup valGrp = (WorkflowStageValueGroup) HarmoniseObjectFactory.instantiateHarmoniseObject(m_dsi, WorkflowStageValueGroup.class.getName(), sPath); 127 128 129 if(valGrp == null) { 130 131 valGrp = (WorkflowStageValueGroup) getWorkflowValueGroup(sPath); 132 133 prop.setWorkflowValueGroup(valGrp); 134 135 prop.save(); 136 } 137 } 138 } catch (DataAccessException e) { 139 throw new APMException(e.getLocalizedMessage(),e); 140 } catch (EditException e) { 141 throw new APMException(e.getLocalizedMessage(),e); 142 } catch (HarmoniseFactoryException e) { 143 throw new APMException(e.getLocalizedMessage(),e); 144 } catch (InvalidChildException e) { 145 throw new APMException(e.getLocalizedMessage(),e); 146 } catch (PopulateException e) { 147 throw new APMException(e.getLocalizedMessage(),e); 148 } catch (InvalidNameException e) { 149 throw new APMException(e.getLocalizedMessage(),e); 150 } 151 152 } 153 154 157 public void delete(User usr, Editable obj) throws APMException { 158 159 try { 160 if (obj instanceof Asset 161 && ((Asset) obj).getContentType().startsWith("image")) { 162 163 Profile prof = ((AbstractProfiledObject) obj).getProfile(); 164 165 if (prof != null) { 166 ChildObjectPropertyInstance propInst = 167 (ChildObjectPropertyInstance) prof.getPropertyInstance( 168 PROPNAME_THUMBNAIL); 169 170 if (propInst != null && propInst.hasValues()) { 171 Asset thumb = (Asset) propInst.getValue(); 172 173 thumb.archive(); 174 } 175 } 176 } else if(obj instanceof WorkflowStageValue) { 177 WorkflowStageValue stage = (WorkflowStageValue) obj; 178 179 if(stage.getPath().startsWith("/root/workflow_stages")) { 180 stage.removeAllInstances(); 181 } 182 } 183 } catch (DataAccessException e) { 184 throw new APMException(e.getLocalizedMessage(), e); 185 } catch (EditException e) { 186 throw new APMException(e.getLocalizedMessage(), e); 187 } catch (InvalidPropertyInstanceException e) { 188 throw new APMException(e.getLocalizedMessage(), e); 189 } 190 191 } 192 193 196 public void saveProperties(User usr, Editable obj, Profile pro) 197 throws APMException { 198 200 } 201 202 205 public boolean isChangeStatusValid(User usr, Editable obj) throws APMException { 206 boolean bIsValid = true; 207 208 try { 209 if(obj instanceof AbstractProfiledObject) { 210 AbstractProfiledObject profObj = (AbstractProfiledObject) obj; 211 212 List wrkflwProps = WorkflowProfile.getAvailableWorkflowProperties(profObj); 213 214 if(wrkflwProps.size() > 0) { 215 Profile wrkflwProf = profObj.getProfile(WorkflowProfile.WORKFLOW_PROFILE_NAME); 216 217 if(wrkflwProf != null && wrkflwProf.getPropertyInstances().size() > 0) { 218 Iterator iter = wrkflwProps.iterator(); 219 220 while (iter.hasNext() && bIsValid == true) { 221 WorkflowProperty tmpProp = (WorkflowProperty) iter.next(); 222 223 WorkflowPropertyInstance propInst = (WorkflowPropertyInstance) wrkflwProf.getPropertyInstance(tmpProp); 224 225 if(propInst != null) { 226 bIsValid = propInst.isComplete(); 227 } else { 228 bIsValid = false; 229 } 230 } 231 } else { 232 WorkflowProperty wrkflwProp = (WorkflowProperty) wrkflwProps.get(0); 234 235 WorkflowRange range = (WorkflowRange) wrkflwProp.getRange(); 236 237 List stages = range.getAvailableValues(); 238 239 Iterator iter = stages.iterator(); 240 241 while (iter.hasNext()) { 242 WorkflowStageValue stage = (WorkflowStageValue) iter.next(); 243 if(stage.isMandatory()) { 244 bIsValid = false; 245 break; 246 } 247 } 248 249 } 250 } 251 } 252 } catch (DataAccessException e) { 253 throw new APMException(e.getLocalizedMessage(),e); 254 } catch (InvalidPropertyInstanceException e) { 255 throw new APMException(e.getLocalizedMessage(),e); 256 } 257 258 return bIsValid; 259 } 260 261 264 public void changeStatus( 265 User usr, 266 Editable obj, 267 Status startStatus, 268 Status newStatus) 269 throws APMException { 270 271 try { 272 if (obj instanceof Asset) { 273 changeAssetStatus(usr, (Asset) obj, startStatus, newStatus); 274 } else if (obj instanceof XMLResource) { 275 changeXMLResourceStatus( 276 usr, 277 (XMLResource) obj, 278 startStatus, 279 newStatus); 280 } else if (obj instanceof ValueGroup) { 281 282 } 283 } catch (DataAccessException e) { 284 throw new APMException(e.getLocalizedMessage(), e); 285 } catch (InvalidProfileException e) { 286 throw new APMException(e.getLocalizedMessage(), e); 287 } catch (InvalidXMLContentException e) { 288 throw new APMException(e); 289 } catch (InvalidPropertyValueException e) { 290 throw new APMException(e.getLocalizedMessage(), e); 291 } catch (PopulateException e) { 292 throw new APMException(e.getLocalizedMessage(), e); 293 } catch (EditException e) { 294 throw new APMException(e.getLocalizedMessage(), e); 295 } catch (HarmoniseFactoryException e) { 296 throw new APMException(e.getLocalizedMessage(), e); 297 } catch (ProfileException e) { 298 throw new APMException(e.getLocalizedMessage(), e); 299 } catch (InvalidChildException e) { 300 throw new APMException(e.getLocalizedMessage(), e); 301 } catch (Exception e) { 302 throw new APMException(e.getLocalizedMessage(), e); 303 } 304 305 } 306 307 protected Section getConversionsSection(Section parent) 308 throws APMException { 309 Section secConversion; 310 try { 311 StringBuffer sPath = new StringBuffer (parent.getFullPath()); 312 sPath.append(AbstractParentObject.separator); 313 sPath.append(SECTION_CONVERSION); 314 315 secConversion = 316 (Section) HarmoniseObjectFactory.instantiateHarmoniseObject( 317 m_dsi, 318 Section.class.getName(), 319 sPath.toString()); 320 321 if (secConversion == null) { 322 secConversion = new Section(m_dsi); 323 secConversion.setName(SECTION_CONVERSION); 324 325 Profile secProf = new Profile(m_dsi); 326 secConversion.setProfile(secProf); 327 328 329 secConversion = (Section) secConversion.save(); 330 331 parent.acquireEditWriteLock(); 332 try { 333 parent.addChild(secConversion); 334 335 parent.save(); 336 } finally { 337 parent.releaseEditWriteLock(); 338 } 339 340 secConversion.changeStatus(Status.APPROVED); 341 } 342 } catch (DataAccessException e) { 343 throw new APMException(e.getLocalizedMessage(), e); 344 } catch (HarmoniseFactoryException e) { 345 throw new APMException(e.getLocalizedMessage(), e); 346 } catch (InvalidProfileException e) { 347 throw new APMException(e.getLocalizedMessage(), e); 348 } catch (EditException e) { 349 throw new APMException(e.getLocalizedMessage(), e); 350 } catch (InvalidChildException e) { 351 throw new APMException(e.getLocalizedMessage(), e); 352 } catch (PopulateException e) { 353 throw new APMException(e.getLocalizedMessage(), e); 354 } catch (InvalidNameException e) { 355 throw new APMException(e.getLocalizedMessage(), e); 356 } 357 358 return secConversion; 359 } 360 361 protected void updateAsset( 362 Asset thumb, 363 Asset asset, 364 String sType, 365 int nSize) 366 throws APMException { 367 try { 368 File fileNew = 369 ImageConverter.convertImage( 370 asset.getContentFile(), "thumb", 371 (String ) MimeTypeMapping.getExtensions(sType).get(0), 372 nSize); 373 374 thumb.setContentFile(fileNew); 375 376 Asset unapprovedAsset = (Asset) thumb.save(); 377 unapprovedAsset.ignoreProfileRestrictions(true); 378 unapprovedAsset.changeStatus(Status.APPROVED); 379 } catch (DataAccessException e) { 380 throw new APMException(e.getLocalizedMessage(), e); 381 } catch (PopulateException e) { 382 throw new APMException(e.getLocalizedMessage(), e); 383 } catch (EditException e) { 384 throw new APMException(e.getLocalizedMessage(), e); 385 } catch (Exception e) { 386 throw new APMException(e.getLocalizedMessage(), e); 387 } 388 } 389 390 protected void updateAsset(Asset thumb, Asset asset, String sType) 391 throws Exception { 392 File fileNew = 393 ImageConverter.convertImage( 394 asset.getContentFile(), "thumb", 395 (String ) MimeTypeMapping.getExtensions(sType).get(0)); 396 thumb.setContentFile(fileNew); 397 398 Asset unapprovedAsset = (Asset) thumb.save(); 399 unapprovedAsset.ignoreProfileRestrictions(true); 400 unapprovedAsset.changeStatus(Status.APPROVED); 401 } 402 403 public String getContent( 404 User user, 405 TextResource txtResource, 406 Status status) 407 throws APMException { 408 String sContent = null; 410 411 try { 412 sContent = txtResource.getContent(); 414 if ((txtResource instanceof XMLResource 418 || txtResource instanceof Template) 419 && status.equals(Status.APPROVED)) { 420 421 org.w3c.dom.Document doc = ((XMLResource)txtResource).getDocument(); 422 423 NodeList pathNodes = 425 doc.getElementsByTagName(AbstractChildObject.TAG_PATH); 426 Element curElm = null; 427 428 Element parentEl = null; 429 430 for (int i = 0; i < pathNodes.getLength(); i++) { 431 curElm = (Element) pathNodes.item(i); Text pathText = (Text) curElm.getFirstChild(); if(pathText != null) { 434 parentEl = (Element) curElm.getParentNode(); 435 String sDavPath = HarmoniseNameResolver.getDAVPath(m_dsi, pathText.getData()); 436 437 if (sDavPath != null) { 438 pathText.setData(sDavPath); 439 } 440 } 441 } 442 443 NodeList xincludes = 444 doc.getElementsByTagNameNS( 445 NamespaceType.XINCLUDE.getURI(), 446 "include"); 447 448 for (int i = 0; i < xincludes.getLength(); i++) { 449 curElm = (Element) xincludes.item(i); 450 Attr hrefAttr = 452 (Attr) curElm.getAttributeNode( 453 ATTRIB_HREF); 454 hrefAttr.setValue( 456 HarmoniseNameResolver.getDAVPath( 457 txtResource.getClass(), 458 hrefAttr.getValue())); 459 } 460 461 XMLPrettyPrint xmlPrettyPrint = new XMLPrettyPrint(); 462 xmlPrettyPrint.setNamespaceAware(true); 463 sContent = xmlPrettyPrint.printNode(doc); 464 } 465 } catch (DataAccessException e) { 466 throw new APMException(e.getLocalizedMessage(), e); 467 } catch (FactoryConfigurationError e) { 468 throw new APMException(e.getLocalizedMessage(), e); 469 } catch (NamespaceClashException e) { 470 throw new APMException(e.getLocalizedMessage(), e); 471 } catch (DOMException e) { 472 throw new APMException(e.getLocalizedMessage(), e); 473 } catch (NameResolverException e) { 474 throw new APMException(e.getLocalizedMessage(), e); 475 } 476 477 return sContent; 478 } 479 480 protected void changeAssetStatus( 481 User usr, 482 Asset asset, 483 Status startStatus, 484 Status newStatus) 485 throws 486 DataAccessException, 487 InvalidProfileException, 488 PopulateException, 489 EditException, 490 InvalidChildException, 491 HarmoniseFactoryException, 492 InvalidPropertyValueException, 493 ProfileException, 494 APMException, 495 Exception { 496 497 if (asset.getContentType().startsWith("image") 498 && (startStatus == Status.UNAPPROVED) 499 && (newStatus == Status.APPROVED)) { 500 501 if (m_logger.isLoggable(Level.FINE)) { 502 m_logger.logp(Level.FINE,this.getClass().getName(),"changeAssetStatus","Approving asset " + asset.getName()); 503 } 504 505 String sContentType = asset.getContentType(); 506 Profile prof = asset.getProfile(); 507 508 Section secConversions = getConversionsSection((Section) asset.getRealParent()); 509 510 511 Asset unApprovedAsset = asset; 512 boolean bIsChanged = false; 513 514 try { 516 AbstractPropertyInstance lowresPropInst = 517 prof.getPropertyInstance(PROPNAME_LOWRES); 518 519 if (sContentType.equals("image/tif")) { 520 if (lowresPropInst == null) { 521 if (m_logger.isLoggable(Level.FINE)) { 522 m_logger.log(Level.FINE,"Creating lowres image"); 523 } 524 525 Asset lowres = createLowRes(asset, secConversions); 526 527 Property prop = 528 PropertyFactory.getPropertyFromName( 529 m_dsi, 530 PROPNAME_LOWRES); 531 532 lowresPropInst = 533 PropertyInstanceFactory.getPropertyInstance( 534 m_dsi, 535 prop); 536 537 ((ChildObjectPropertyInstance) lowresPropInst).addValue( 538 lowres); 539 540 prof.addPropertyInstance(lowresPropInst); 541 542 unApprovedAsset = (Asset)asset.save(); 543 bIsChanged = true; 544 } else { 545 updateAsset( 546 (Asset) lowresPropInst.getValue(), 547 asset, 548 MIMETYPE_LOWRES); 549 } 550 } 551 } catch (InvalidPropertyInstanceException e) { 552 if(m_logger.isLoggable(Level.INFO)) { 553 m_logger.logp(Level.INFO, this.getClass().getName(), "changeAssetStatus", PROPNAME_LOWRES + " is invalid on this asset"); 554 } 555 } 556 557 try { 559 AbstractPropertyInstance thumbPropInst = 560 prof.getPropertyInstance(PROPNAME_THUMBNAIL); 561 562 if (ImageConverter.getImageHeight(asset.getContentFile()) 563 > m_nSizeThumbnail) { 564 565 if (thumbPropInst == null) { 566 if (m_logger.isLoggable(Level.FINE)) { 567 m_logger.log(Level.FINE,"Creating thumbnail image"); 568 } 569 570 Asset thumb = createThumbnail(asset, secConversions); 571 572 Property prop = 573 PropertyFactory.getPropertyFromName( 574 m_dsi, 575 PROPNAME_THUMBNAIL); 576 577 thumbPropInst = 578 PropertyInstanceFactory.getPropertyInstance( 579 m_dsi, 580 prop); 581 582 ((ChildObjectPropertyInstance) thumbPropInst).addValue( 583 thumb); 584 585 if(unApprovedAsset != null){ 586 unApprovedAsset.getProfile().addPropertyInstance(thumbPropInst); 587 588 unApprovedAsset = (Asset)unApprovedAsset.save(); 589 } else { 590 prof.addPropertyInstance(thumbPropInst); 591 unApprovedAsset = (Asset)asset.save(); 592 } 593 594 bIsChanged = true; 595 596 } else { 597 updateAsset( 598 (Asset) thumbPropInst.getValue(), 599 asset, 600 MIMETYPE_THUMBNAIL, 601 m_nSizeThumbnail); 602 } 603 } 604 } catch (InvalidPropertyInstanceException e) { 605 if(m_logger.isLoggable(Level.INFO)) { 606 m_logger.logp(Level.INFO, this.getClass().getName(), "changeAssetStatus", PROPNAME_THUMBNAIL + " is invalid on this asset"); 607 } 608 } 609 610 if(bIsChanged == true){ 612 unApprovedAsset.changeStatus(Status.APPROVED); 613 } 614 } 615 } 616 617 632 private Asset createThumbnail(Asset asset, Section secConversions) throws DataAccessException, InvalidNameException, InvalidProfileException, Exception , PopulateException, EditException, InvalidChildException { 633 StringBuffer sNewName = new StringBuffer (asset.getName()); 634 sNewName.append("_thumbnail"); 635 636 Asset thumb = new Asset(m_dsi); 637 thumb.setName(sNewName.toString()); 638 thumb.setSummary(asset.getSummary()); 639 640 Profile newProf = new Profile(m_dsi); 641 thumb.addProfile(newProf); 642 643 File fileMain = asset.getContentFile(); 644 String sPath = asset.getContentFile().getAbsolutePath(); 645 String sNewFileName = sPath.substring(0,sPath.indexOf(".")) + "_thumb"; 646 647 File fileNew = 648 ImageConverter.convertImage( 649 fileMain, 650 MimeTypeMapping.getExtensionFromMimeType(MIMETYPE_THUMBNAIL), 651 sNewFileName , 652 m_nSizeThumbnail); 653 654 thumb.setContentFile(fileNew); 655 656 if (m_logger.isLoggable(Level.FINE)) { 657 m_logger.log(Level.FINE,"Conversion section for new thumbnail is " + secConversions.toString()); 658 } 659 660 thumb = (Asset) thumb.save(); 661 662 secConversions.addChild(thumb); 663 secConversions.save(); 664 thumb.ignoreProfileRestrictions(true); 665 666 thumb.changeStatus(Status.APPROVED); 667 return thumb; 668 } 669 670 671 685 private Asset createLowRes(Asset asset, Section secConversions) throws DataAccessException, InvalidNameException, InvalidProfileException, Exception , PopulateException, EditException { 686 StringBuffer sNewName = new StringBuffer (asset.getName()); 687 sNewName.append("_lowres"); 688 689 Asset lowres = new Asset(m_dsi); 690 lowres.setName(sNewName.toString()); 691 lowres.setSummary(asset.getSummary()); 692 693 Profile newProf = new Profile(m_dsi); 694 lowres.addProfile(newProf); 695 696 File fileMain = asset.getContentFile(); 697 String sPath = asset.getContentFile().getAbsolutePath(); 698 String sNewFileName = sPath.substring(0,sPath.indexOf(".")) + "_lowres"; 699 700 File fileNew = 701 ImageConverter.convertImage( 702 fileMain, sNewFileName, 703 MimeTypeMapping.getExtensionFromMimeType(MIMETYPE_LOWRES)); 704 705 lowres.setContentFile(fileNew); 706 707 if (m_logger.isLoggable(Level.FINE)) { 708 m_logger.log(Level.FINE,"Conversion section for new lowres image is " + secConversions.toString()); 709 } 710 711 lowres = (Asset) lowres.save(); 712 713 secConversions.acquireEditWriteLock(); 714 try { 715 secConversions.addChild(lowres); 716 secConversions.save(); 717 718 } finally { 719 secConversions.releaseEditWriteLock(); 720 } 721 lowres.ignoreProfileRestrictions(true); 722 723 lowres = (Asset) lowres.changeStatus(Status.APPROVED); 724 725 return lowres; 726 } 727 728 729 private void changeXMLResourceStatus( 730 User usr, 731 XMLResource xml, 732 Status startStatus, 733 Status newStatus) 734 throws 735 DataAccessException, 736 SAXException, 737 IOException, 738 ParserConfigurationException, 739 FactoryConfigurationError, 740 DOMException, 741 NameResolverException, 742 NamespaceClashException, 743 EditException, PopulateException { 744 if ((startStatus == Status.UNAPPROVED) 745 && (newStatus == Status.APPROVED)) { 746 boolean bHasChanged = false; 747 748 if (m_logger.isLoggable(Level.FINE)) { 749 m_logger.logp(Level.FINE,this.getClass().getName(),"changeXMLResourceStatus","Approving TextResource " + xml.getName()); 750 } 751 752 String sContentType = xml.getContentType(); 753 754 org.w3c.dom.Document doc = xml.getDocument(); 755 756 NodeList pathNodes = 758 doc.getElementsByTagName(AbstractChildObject.TAG_PATH); 759 Element curElm = null; 760 761 for (int i = 0; i < pathNodes.getLength(); i++) { 762 curElm = (Element) pathNodes.item(i); 763 Text pathText = (Text) curElm.getFirstChild(); 765 if(pathText != null) { 766 String sPath = pathText.getData(); 767 if(sPath.startsWith(HarmoniseNameResolver.URL_SEPARATOR) && HarmoniseNameResolver.isDAVPath(sPath)) { 770 pathText.setData( 772 HarmoniseNameResolver.getRealPath(sPath)); 773 bHasChanged = true; 774 } 775 } 776 } 777 778 NodeList xincludes = 779 doc.getElementsByTagNameNS( 780 NamespaceType.XINCLUDE.getURI(), 781 "include"); 782 783 for (int i = 0; i < xincludes.getLength(); i++) { 784 curElm = (Element) xincludes.item(i); 785 Attr hrefAttr = 787 (Attr) curElm.getAttributeNode( 788 ATTRIB_HREF); 789 hrefAttr.setValue( 791 HarmoniseNameResolver.getRealPath(hrefAttr.getValue())); 792 bHasChanged = true; 793 } 794 795 if(bHasChanged == true) { 797 XMLPrettyPrint xmlPrettyPrint = new XMLPrettyPrint(); 798 xmlPrettyPrint.setNamespaceAware(true); 799 String sContent = xmlPrettyPrint.printNode(doc); 800 801 xml.setContent(sContent); 802 xml.save().changeStatus(Status.APPROVED); 803 } 804 } 805 } 806 807 private void changeValueGroupStatus( 808 User usr, 809 ValueGroup valGrp, 810 Status startStatus, 811 Status newStatus) 812 throws 813 EditException, 814 InvalidChildException, 815 PopulateException, 816 HarmoniseFactoryException, 817 InvalidPropertyValueException, 818 ProfileException, InvalidNameException, DataAccessException { 819 if (valGrp instanceof WorkflowStageValueGroup) { 820 if (startStatus == Status.UNAPPROVED 821 && newStatus == Status.APPROVED) { 822 823 List children = valGrp.getChildren(); 824 825 if (children.size() > 0 828 && children.get(0) instanceof WorkflowStageValue) { 829 Profile prof = valGrp.getProfile(); 830 831 Property wrkflwRelnProp = 832 PropertyFactory.getPropertyFromName( 833 m_dsi, 834 PROPNAME_WORKFLOW_PROP_RELN); 835 836 AbstractPropertyInstance propInst = 837 prof.getPropertyInstance(wrkflwRelnProp); 838 839 if (propInst == null) { 840 WorkflowProperty prop = new WorkflowProperty(m_dsi); 841 prop.setName(valGrp.getName()); 842 prop.setWorkflowValueGroup((WorkflowStageValueGroup) valGrp); 843 prop.save(); 844 845 String sParentPath = valGrp.getPath(); 846 847 WorkflowPropertyGroup propGrp = 848 (WorkflowPropertyGroup) getWorkflowPropertyGroup(sParentPath); 849 850 propGrp.acquireEditWriteLock(); 851 try { 852 propGrp.addChild(prop); 853 854 propGrp.save(); 855 } finally { 856 propGrp.releaseEditWriteLock(); 857 } 858 859 860 prop.changeStatus(Status.APPROVED); 861 862 ChildObjectPropertyInstance newPropInst = 863 new ChildObjectPropertyInstance( 864 m_dsi, 865 wrkflwRelnProp); 866 867 newPropInst.addValue(prop); 868 869 prof.addPropertyInstance(newPropInst); 870 871 valGrp = (ValueGroup) valGrp.save(); 872 873 valGrp.changeStatus(Status.APPROVED); 874 } 875 } 876 877 } 878 } 879 } 880 881 885 private PropertyGroup getWorkflowPropertyGroup(String sParentPath) 886 throws 887 HarmoniseFactoryException, 888 EditException, 889 InvalidChildException, 890 PopulateException, InvalidNameException { 891 PropertyGroup propGrp = 893 (PropertyGroup) HarmoniseObjectFactory.instantiateHarmoniseObject( 894 m_dsi, 895 WorkflowPropertyGroup.class.getName(), 896 sParentPath); 897 898 if (propGrp == null) { 900 propGrp = 901 (PropertyGroup) HarmoniseObjectFactory.instantiateHarmoniseObject( 902 m_dsi, 903 PropertyGroup.class.getName(), 904 sParentPath); 905 } 906 907 if (propGrp == null) { 909 int nIndex = 910 sParentPath.lastIndexOf(AbstractParentObject.separator); 911 912 if (nIndex > 0) { 913 PropertyGroup parentGrp = 914 getWorkflowPropertyGroup( 915 sParentPath.substring(0, nIndex - 1)); 916 String sName = HarmoniseNameResolver.getLastSegment(sParentPath); 917 propGrp = new WorkflowPropertyGroup(m_dsi); 918 propGrp.setName(sName); 919 propGrp.save(); 920 parentGrp.acquireEditWriteLock(); 921 try { 922 parentGrp.addChild(propGrp); 923 parentGrp.save(); 924 } finally { 925 parentGrp.releaseEditWriteLock(); 926 } 927 928 propGrp.changeStatus(Status.APPROVED); 929 } 930 931 } 932 return propGrp; 933 } 934 935 939 private ValueGroup getWorkflowValueGroup(String sPath) 940 throws 941 HarmoniseFactoryException, 942 EditException, 943 InvalidChildException, 944 PopulateException, InvalidNameException { 945 ValueGroup valGrp = 947 (ValueGroup) HarmoniseObjectFactory.instantiateHarmoniseObject( 948 m_dsi, 949 WorkflowStageValueGroup.class.getName(), 950 sPath); 951 952 if (valGrp == null) { 954 valGrp = 955 (ValueGroup) HarmoniseObjectFactory.instantiateHarmoniseObject( 956 m_dsi, 957 ValueGroup.class.getName(), 958 sPath); 959 } 960 961 if (valGrp == null) { 963 int nIndex = sPath.lastIndexOf(AbstractParentObject.separator); 964 965 if (nIndex > 0) { 966 ValueGroup parentGrp = 967 getWorkflowValueGroup(sPath.substring(0, nIndex)); 968 String sName = HarmoniseNameResolver.getLastSegment(sPath); 969 valGrp = new WorkflowStageValueGroup(m_dsi); 970 valGrp.setName(sName); 971 valGrp.save(); 972 parentGrp.acquireEditWriteLock(); 973 try { 974 parentGrp.addChild(valGrp); 975 parentGrp.save(); 976 } finally { 977 parentGrp.releaseEditWriteLock(); 978 } 979 980 valGrp.changeStatus(Status.APPROVED); 981 } 982 983 } 984 return valGrp; 985 } 986 987 } 988 | Popular Tags |