1 56 57 package org.opencrx.kernel.layer.application; 58 59 import java.io.ByteArrayOutputStream ; 60 import java.io.InputStream ; 61 import java.math.BigDecimal ; 62 import java.util.ArrayList ; 63 import java.util.Arrays ; 64 import java.util.HashMap ; 65 import java.util.HashSet ; 66 import java.util.Iterator ; 67 import java.util.List ; 68 import java.util.ListIterator ; 69 import java.util.Map ; 70 import java.util.Set ; 71 import java.util.StringTokenizer ; 72 73 import org.opencrx.kernel.generic.OpenCrxException; 74 import org.opencrx.kernel.generic.SecurityKeys; 75 import org.openmdx.application.log.AppLog; 76 import org.openmdx.base.accessor.generic.cci.ObjectFactory_1_0; 77 import org.openmdx.base.accessor.generic.view.Manager_1; 78 import org.openmdx.base.accessor.jmi.cci.RefPackage_1_0; 79 import org.openmdx.base.accessor.jmi.spi.RefRootPackage_1; 80 import org.openmdx.base.exception.ServiceException; 81 import org.openmdx.base.text.format.DateFormat; 82 import org.openmdx.base.text.pattern.StringExpression; 83 import org.openmdx.compatibility.base.application.configuration.Configuration; 84 import org.openmdx.compatibility.base.collection.SparseList; 85 import org.openmdx.compatibility.base.dataprovider.cci.AttributeSelectors; 86 import org.openmdx.compatibility.base.dataprovider.cci.AttributeSpecifier; 87 import org.openmdx.compatibility.base.dataprovider.cci.DataproviderObject; 88 import org.openmdx.compatibility.base.dataprovider.cci.DataproviderObject_1_0; 89 import org.openmdx.compatibility.base.dataprovider.cci.DataproviderOperations; 90 import org.openmdx.compatibility.base.dataprovider.cci.DataproviderReply; 91 import org.openmdx.compatibility.base.dataprovider.cci.DataproviderRequest; 92 import org.openmdx.compatibility.base.dataprovider.cci.Dataprovider_1_0; 93 import org.openmdx.compatibility.base.dataprovider.cci.Directions; 94 import org.openmdx.compatibility.base.dataprovider.cci.Orders; 95 import org.openmdx.compatibility.base.dataprovider.cci.QualityOfService; 96 import org.openmdx.compatibility.base.dataprovider.cci.RequestCollection; 97 import org.openmdx.compatibility.base.dataprovider.cci.ServiceHeader; 98 import org.openmdx.compatibility.base.dataprovider.cci.SharedConfigurationEntries; 99 import org.openmdx.compatibility.base.dataprovider.cci.SystemAttributes; 100 import org.openmdx.compatibility.base.dataprovider.layer.application.ProvidingUid_1; 101 import org.openmdx.compatibility.base.dataprovider.spi.Layer_1_0; 102 import org.openmdx.compatibility.base.dataprovider.transport.adapter.Provider_1; 103 import org.openmdx.compatibility.base.dataprovider.transport.adapter.Switch_1; 104 import org.openmdx.compatibility.base.dataprovider.transport.cci.Provider_1_0; 105 import org.openmdx.compatibility.base.dataprovider.transport.delegation.Connection_1; 106 import org.openmdx.compatibility.base.naming.Path; 107 import org.openmdx.compatibility.base.query.FilterOperators; 108 import org.openmdx.compatibility.base.query.FilterProperty; 109 import org.openmdx.compatibility.base.query.Quantors; 110 import org.openmdx.kernel.exception.BasicException; 111 import org.openmdx.kernel.log.SysLog; 112 import org.openmdx.model1.accessor.basic.cci.ModelElement_1_0; 113 import org.openmdx.model1.accessor.basic.cci.Model_1_0; 114 import org.openmdx.uses.org.apache.commons.collections.set.ListOrderedSet; 115 116 132 133 public class OpenCrxKernel_1 134 extends ProvidingUid_1 { 135 136 public void activate( 138 short id, 139 Configuration configuration, 140 Layer_1_0 delegation 141 ) throws ServiceException, Exception { 142 super.activate( 143 id, 144 configuration, 145 delegation 146 ); 147 148 if(configuration.values(SharedConfigurationEntries.MODEL).size() > 0) { 150 this.model = (Model_1_0)configuration.values(SharedConfigurationEntries.MODEL).get(0); 151 } 152 else { 153 throw new ServiceException( 154 BasicException.Code.DEFAULT_DOMAIN, 155 BasicException.Code.INVALID_CONFIGURATION, 156 null, 157 "A model must be configured with options 'modelPackage' and 'packageImpl'" 158 ); 159 } 160 161 if(configuration.values(ConfigurationKeys.REALM_IDENTITY).size() > 0) { 163 this.loginRealmIdentity = new Path((String )configuration.values(ConfigurationKeys.REALM_IDENTITY).get(0)); 164 } 165 else { 166 throw new ServiceException( 167 BasicException.Code.DEFAULT_DOMAIN, 168 BasicException.Code.INVALID_CONFIGURATION, 169 null, 170 "A realm identity must be configured with option 'realmIdentity'" 171 ); 172 } 173 174 this.passwordEncodingAlgorithm = "MD5"; 176 if(configuration.values(ConfigurationKeys.PASSWORD_ENCODING_ALGORITHM).size() > 0) { 177 this.passwordEncodingAlgorithm = (String )configuration.values(ConfigurationKeys.PASSWORD_ENCODING_ALGORITHM).get(0); 178 } 179 180 List exposedPaths = configuration.values(SharedConfigurationEntries.EXPOSED_PATH); 182 this.codeSegment = null; 183 for(int i = 0; i < exposedPaths.size(); i++) { 184 Path exposedPath = (Path)exposedPaths.get(i); 185 if( 186 "org:opencrx:kernel:code1".equals(exposedPath.get(0)) && 187 (exposedPath.size() == 5) 188 ) { 189 this.codeSegment = exposedPath; 190 break; 191 } 192 } 193 if(this.codeSegment == null) { 194 throw new ServiceException( 195 BasicException.Code.DEFAULT_DOMAIN, 196 BasicException.Code.INVALID_CONFIGURATION, 197 new BasicException.Parameter[]{ 198 new BasicException.Parameter( 199 "exposed paths", exposedPaths 200 ) 201 }, 202 "provider must expose a code segment, i.e. a path of the form xri:@openmdx:org.opencrx.kernel.code1/provider/<id>/segment/<id>" 203 ); 204 } 205 206 this.readOnlyObjectTypes = configuration.values("readOnlyObjectType"); 208 209 SparseList dataproviderSource = configuration.values( 211 SharedConfigurationEntries.DATAPROVIDER_CONNECTION 212 ); 213 SparseList delegationPathSource = configuration.values( 214 SharedConfigurationEntries.DELEGATION_PATH 215 ); 216 if(delegationPathSource.isEmpty()){ 217 if(dataproviderSource.isEmpty()) { 218 this.router = this.getDelegation(); 219 } 220 else { 221 throw new ServiceException( 222 BasicException.Code.DEFAULT_DOMAIN, 223 BasicException.Code.INVALID_CONFIGURATION, 224 new BasicException.Parameter[]{}, 225 "The org:openmdx:compatibility:runtime1 model allowing to explore other dataproviders is deprecated." + 226 " Specifying " + SharedConfigurationEntries.DATAPROVIDER_CONNECTION + 227 " entries without their corresponding " + SharedConfigurationEntries.DELEGATION_PATH + 228 " is not supported" 229 ); 230 } 231 } 232 else { 233 List dataproviderTarget = new ArrayList (); 234 List delegationPathTarget = new ArrayList (); 235 for( 236 ListIterator dpi = delegationPathSource.populationIterator(); 237 dpi.hasNext(); 238 ) { 239 int i = dpi.nextIndex(); 240 Object dp = dataproviderSource.get(i); 241 if(dp == null) { 242 throw new ServiceException( 243 BasicException.Code.DEFAULT_DOMAIN, 244 BasicException.Code.INVALID_CONFIGURATION, 245 new BasicException.Parameter[]{ 246 new BasicException.Parameter(SharedConfigurationEntries.DELEGATION_PATH, delegationPathSource), 247 new BasicException.Parameter("index", i), 248 new BasicException.Parameter(SharedConfigurationEntries.DATAPROVIDER_CONNECTION, dataproviderSource) 249 }, 250 "The delegation path at the given index has no corresponding dataprovider counterpart" 251 ); 252 } 253 delegationPathTarget.add( 254 new Path((String )dpi.next()) 255 ); 256 dataproviderTarget.add(dp); 257 } 258 this.router = new Switch_1( 259 (Dataprovider_1_0[]) dataproviderTarget.toArray( 260 new Dataprovider_1_0[dataproviderTarget.size()] 261 ), 262 Path.toPathArray(delegationPathTarget), 263 this.getDelegation() 264 ); 265 } 266 } 267 268 public String getUidAsString( 270 ) { 271 return super.uidAsString(); 272 } 273 274 public Contracts getContracts( 276 ) { 277 return this.contracts; 278 } 279 280 public DataproviderObject_1_0 retrieveObjectFromLocal( 282 ServiceHeader header, 283 Path identity 284 ) throws ServiceException { 285 return super.get( 286 header, 287 new DataproviderRequest( 288 new DataproviderObject(identity), 289 DataproviderOperations.OBJECT_RETRIEVAL, 290 AttributeSelectors.ALL_ATTRIBUTES, 291 new AttributeSpecifier[]{} 292 ) 293 ).getObject(); 294 } 295 296 public DataproviderObject_1_0 retrieveObjectFromDelegation( 298 Path identity 299 ) throws ServiceException { 300 return this.delegation.addGetRequest( 301 identity, 302 AttributeSelectors.ALL_ATTRIBUTES, 303 new AttributeSpecifier[]{} 304 ); 305 } 306 307 public void removeObject( 309 Path identity 310 ) throws ServiceException { 311 this.delegation.addRemoveRequest( 312 identity 313 ); 314 this.modifiedObjects.remove(identity); 315 for( 316 Iterator i = this.pendingModifications.iterator(); 317 i.hasNext(); 318 ) { 319 DataproviderObject object = (DataproviderObject)i.next(); 320 if(object.path().equals(identity)) { 321 i.remove(); 322 break; 323 } 324 } 325 } 326 327 public void testReferenceIsChangeable( 329 Path referencePath 330 ) throws ServiceException { 331 ModelElement_1_0 reference = null; 333 try { 334 reference = this.model.getReferenceType(referencePath); 335 } 336 catch(ServiceException e) { 337 AppLog.warning("Reference not found in model", referencePath); 338 } 339 if( 340 (reference != null) && 341 !((Boolean )reference.values("isChangeable").get(0)).booleanValue() 342 ) { 343 throw new ServiceException( 344 OpenCrxException.DOMAIN, 345 OpenCrxException.REFERENCE_IS_READONLY, 346 new BasicException.Parameter[]{ 347 new BasicException.Parameter("param0", referencePath) 348 }, 349 "Reference is readonly. Can not add/remove objects." 350 ); 351 } 352 } 353 354 public void testObjectIsChangeable( 356 DataproviderObject_1_0 object 357 ) throws ServiceException { 358 String objectClass = (String )object.values(SystemAttributes.OBJECT_CLASS).get(0); 359 for( 360 Iterator i = this.readOnlyObjectTypes.iterator(); 361 i.hasNext(); 362 ) { 363 String type = (String )i.next(); 364 if(this.model.isSubtypeOf(objectClass, type)) { 365 for( 366 Iterator j = object.attributeNames().iterator(); 367 j.hasNext(); 368 ) { 369 String attributeName = (String )j.next(); 370 if( 371 !SystemAttributes.OBJECT_CLASS.equals(attributeName) && 372 !SystemAttributes.MODIFIED_AT.equals(attributeName) && 373 !SystemAttributes.MODIFIED_BY.equals(attributeName) 374 ) { 375 throw new ServiceException( 376 OpenCrxException.DOMAIN, 377 OpenCrxException.OBJECT_TYPE_IS_READONLY, 378 new BasicException.Parameter[]{ 379 new BasicException.Parameter("param0", objectClass) 380 }, 381 "Object type is readonly. Can not modify object." 382 ); 383 } 384 } 385 } 386 } 387 } 388 389 public DataproviderObject retrieveObjectForModification( 391 Path identity 392 ) throws ServiceException { 393 DataproviderObject object = null; 394 if(this.modifiedObjects.keySet().contains(identity)) { 395 object = (DataproviderObject)this.modifiedObjects.get(identity); 396 } 397 else { 398 object = 399 new DataproviderObject( 400 this.delegation.addGetRequest( 401 identity, 402 AttributeSelectors.ALL_ATTRIBUTES, 403 new AttributeSpecifier[]{} 404 ) 405 ); 406 this.modifiedObjects.put( 407 identity, 408 object 409 ); 410 } 411 return object; 412 } 413 414 public void createObject( 416 DataproviderObject object 417 ) throws ServiceException { 418 try { 419 this.delegation.addCreateRequest( 420 object 421 ); 422 } 423 catch(ServiceException e) { 424 if(e.getExceptionCode() != BasicException.Code.DUPLICATE) { 425 throw e; 426 } 427 throw new ServiceException( 428 OpenCrxException.DOMAIN, 429 OpenCrxException.DUPLICATE_OBJECT, 430 new BasicException.Parameter[]{ 431 new BasicException.Parameter("param0", object.path().getBase()) 432 }, 433 "Duplicate object. Object with qualifier already exists." 434 ); 435 } 436 } 437 438 public Codes getCodes( 440 ) { 441 return this.codes; 442 } 443 444 public boolean isContract( 446 DataproviderObject_1_0 position 447 ) throws ServiceException { 448 String objectClass = (String )position.values(SystemAttributes.OBJECT_CLASS).get(0); 449 return this.model.isSubtypeOf( 450 objectClass, 451 "org:opencrx:kernel:contract1:AbstractContract" 452 ); 453 } 454 455 public boolean isLead( 457 DataproviderObject_1_0 position 458 ) throws ServiceException { 459 String objectClass = (String )position.values(SystemAttributes.OBJECT_CLASS).get(0); 460 return this.model.isSubtypeOf( 461 objectClass, 462 "org:opencrx:kernel:contract1:Lead" 463 ); 464 } 465 466 public boolean isContact( 468 DataproviderObject_1_0 position 469 ) throws ServiceException { 470 String objectClass = (String )position.values(SystemAttributes.OBJECT_CLASS).get(0); 471 return this.model.isSubtypeOf( 472 objectClass, 473 "org:opencrx:kernel:account1:Contact" 474 ); 475 } 476 477 public boolean isDepot( 479 DataproviderObject_1_0 position 480 ) throws ServiceException { 481 String objectClass = (String )position.values(SystemAttributes.OBJECT_CLASS).get(0); 482 return this.model.isSubtypeOf( 483 objectClass, 484 "org:opencrx:kernel:depot1:Depot" 485 ); 486 } 487 488 public boolean isDepotHolder( 490 DataproviderObject_1_0 position 491 ) throws ServiceException { 492 String objectClass = (String )position.values(SystemAttributes.OBJECT_CLASS).get(0); 493 return this.model.isSubtypeOf( 494 objectClass, 495 "org:opencrx:kernel:depot1:DepotHolder" 496 ); 497 } 498 499 public boolean isMedia( 501 DataproviderObject_1_0 position 502 ) throws ServiceException { 503 String objectClass = (String )position.values(SystemAttributes.OBJECT_CLASS).get(0); 504 return this.model.isSubtypeOf( 505 objectClass, 506 "org:opencrx:kernel:document1:Media" 507 ); 508 } 509 510 public boolean isSecureObject( 512 DataproviderObject_1_0 object 513 ) throws ServiceException { 514 String objectClass = (String )object.values(SystemAttributes.OBJECT_CLASS).get(0); 515 return this.model.isSubtypeOf( 516 objectClass, 517 "org:opencrx:kernel:base:SecureObject" 518 ); 519 } 520 521 public boolean isContractPosition( 523 DataproviderObject_1_0 position 524 ) throws ServiceException { 525 String objectClass = (String )position.values(SystemAttributes.OBJECT_CLASS).get(0); 526 return this.model.isSubtypeOf( 527 objectClass, 528 "org:opencrx:kernel:contract1:ContractPosition" 529 ); 530 } 531 532 public boolean isPictured( 534 DataproviderObject_1_0 object 535 ) throws ServiceException { 536 String objectClass = (String )object.values(SystemAttributes.OBJECT_CLASS).get(0); 537 return this.model.isSubtypeOf( 538 objectClass, 539 "org:opencrx:kernel:generic:Pictured" 540 ); 541 } 542 543 public boolean isSegment( 545 DataproviderObject_1_0 object 546 ) throws ServiceException { 547 String objectClass = (String )object.values(SystemAttributes.OBJECT_CLASS).get(0); 548 return this.model.isSubtypeOf( 549 objectClass, 550 "org:openmdx:base:Segment" 551 ); 552 } 553 554 public boolean isUserHome( 556 DataproviderObject_1_0 object 557 ) throws ServiceException { 558 String objectClass = (String )object.values(SystemAttributes.OBJECT_CLASS).get(0); 559 return this.model.isSubtypeOf( 560 objectClass, 561 "org:opencrx:kernel:home1:UserHome" 562 ); 563 } 564 565 public boolean isActivityTracker( 567 DataproviderObject_1_0 object 568 ) throws ServiceException { 569 String objectClass = (String )object.values(SystemAttributes.OBJECT_CLASS).get(0); 570 return this.model.isSubtypeOf( 571 objectClass, 572 "org:opencrx:kernel:activity1:ActivityTracker" 573 ); 574 } 575 576 public boolean isEffortEstimate( 578 DataproviderObject_1_0 object 579 ) throws ServiceException { 580 String objectClass = (String )object.values(SystemAttributes.OBJECT_CLASS).get(0); 581 return this.model.isSubtypeOf( 582 objectClass, 583 "org:opencrx:kernel:activity1:EffortEstimate" 584 ); 585 } 586 587 public boolean isActivity( 589 DataproviderObject_1_0 object 590 ) throws ServiceException { 591 String objectClass = (String )object.values(SystemAttributes.OBJECT_CLASS).get(0); 592 return this.model.isSubtypeOf( 593 objectClass, 594 "org:opencrx:kernel:activity1:Activity" 595 ); 596 } 597 598 public boolean isActivityGroup( 600 DataproviderObject_1_0 object 601 ) throws ServiceException { 602 String objectClass = (String )object.values(SystemAttributes.OBJECT_CLASS).get(0); 603 return this.model.isSubtypeOf( 604 objectClass, 605 "org:opencrx:kernel:activity1:ActivityGroup" 606 ); 607 } 608 609 public boolean isModelElement( 611 DataproviderObject_1_0 object 612 ) throws ServiceException { 613 String objectClass = (String )object.values(SystemAttributes.OBJECT_CLASS).get(0); 614 return this.model.isSubtypeOf( 615 objectClass, 616 "org:opencrx:kernel:model1:Element" 617 ); 618 } 619 620 public boolean isActivityWorkRecord( 622 DataproviderObject_1_0 object 623 ) throws ServiceException { 624 String objectClass = (String )object.values(SystemAttributes.OBJECT_CLASS).get(0); 625 return this.model.isSubtypeOf( 626 objectClass, 627 "org:opencrx:kernel:activity1:ActivityWorkRecord" 628 ); 629 } 630 631 public void removeAll( 633 Path forReference, 634 FilterProperty[] includeFilter, 635 int excludeFirst, 636 Set exclude 637 ) { 638 try { 639 List objects = this.delegation.addFindRequest( 642 forReference, 643 includeFilter, 644 AttributeSelectors.NO_ATTRIBUTES, 645 new AttributeSpecifier[]{ 646 new AttributeSpecifier( 647 SystemAttributes.MODIFIED_AT, 648 0, 649 Integer.MAX_VALUE, 650 Directions.DESCENDING 651 ) 652 }, 653 0, Integer.MAX_VALUE, 654 Directions.ASCENDING 655 ); 656 List identities = new ArrayList (); 658 int ii = 0; 659 for( 660 Iterator i = objects.iterator(); 661 i.hasNext(); 662 ii++ 663 ) { 664 Path identity = ((DataproviderObject_1_0)i.next()).path(); 665 if((ii >= excludeFirst) && ((exclude == null) || !exclude.contains(identity))) { 666 identities.add(identity); 667 } 668 } 669 for( 671 Iterator i = identities.iterator(); 672 i.hasNext(); 673 ) { 674 this.delegation.addRemoveRequest((Path)i.next()); 675 } 676 } 677 catch(ServiceException e) { 678 SysLog.info("can not remove objects"); 679 SysLog.info(e.getMessage(), e.getCause(), 1); 680 } 681 } 682 683 689 public void collectReferencedObjects( 690 DataproviderObject_1_0 object, 691 List referenceFilter, 692 Set referencedObjectPaths 693 ) { 694 for( 695 Iterator i = object.attributeNames().iterator(); 696 i.hasNext(); 697 ) { 698 String attributeName = (String )i.next(); 699 List values = object.values(attributeName); 700 for(Iterator j = values.iterator(); j.hasNext(); ) { 701 Object value = j.next(); 702 if(value instanceof Path) { 703 Path referencedObjectPath = (Path)value; 704 Path reference = object.path().getChild(attributeName); 705 boolean matches = referenceFilter == null; 707 Path matchingReferencePattern = null; 708 if(!matches) { 709 for(Iterator k = referenceFilter.iterator(); k.hasNext(); ) { 710 Path f = (Path)k.next(); 711 if(reference.isLike(f) && !f.endsWith(new String []{":*"})) { 712 matchingReferencePattern = f; 713 matches = true; 714 break; 715 } 716 } 717 } 718 if(matches) { 719 referencedObjectPaths.add(referencedObjectPath); 720 List newReferenceFilter = new ArrayList (); 721 if(referenceFilter != null) { 722 for(Iterator k = referenceFilter.iterator(); k.hasNext(); ) { 724 Path f = (Path)k.next(); 725 if( 726 (f.size() > matchingReferencePattern.size()) && 727 f.startsWith(matchingReferencePattern) 728 ) { 729 newReferenceFilter.add( 730 referencedObjectPath.getDescendant( 731 f.getSuffix(matchingReferencePattern.size()+1) 732 ) 733 ); 734 } 735 } 736 referenceFilter.addAll(newReferenceFilter); 737 } 738 } 739 } 740 } 741 } 742 } 743 744 public void parsePhoneNumber( 746 DataproviderObject object, 747 DataproviderObject_1_0 oldValues 748 ) throws ServiceException { 749 String objectClass = (String )object.values(SystemAttributes.OBJECT_CLASS).get(0); 750 List phoneNumberFullValues = this.getNewValue("phoneNumberFull", object, oldValues); 751 List automaticParsingValues = this.getNewValue("automaticParsing", object, oldValues); 752 if( 753 this.model.isSubtypeOf(objectClass, "org:opencrx:kernel:address1:PhoneNumberAddressable") && 754 (automaticParsingValues.size() > 0) && ((Boolean )automaticParsingValues.get(0)).booleanValue() && 755 (phoneNumberFullValues.size() > 0) 756 ) { 757 String phoneNumberFull = (String )phoneNumberFullValues.get(0); 759 List parts = new ArrayList (); 760 StringTokenizer tokenizer = new StringTokenizer (phoneNumberFull, "+()x"); 761 while(tokenizer.hasMoreTokens()) { 762 parts.add(tokenizer.nextToken()); 763 } 764 if(parts.size() >= 3) { 765 String countryCode = parts.get(0).toString().trim(); 766 if("1".equals(countryCode)) { 767 countryCode = "840"; 768 } 769 else { 770 Map phoneCountryPrefix = this.codes.getShortText( 771 "org:opencrx:kernel:address1:PhoneNumberAddressable:phoneCountryPrefix", 772 (short)0, 773 false 774 ); 775 Short code = (Short )phoneCountryPrefix.get(countryCode); 776 countryCode = code == null 777 ? "0" 778 : code.toString(); 779 } 780 String areaCode = parts.get(1).toString().trim(); 781 String localNumber = parts.get(2).toString().trim(); 782 String extension = parts.size() >= 4 ? parts.get(3).toString().trim() : ""; 783 784 object.clearValues("phoneCountryPrefix").add(new Short (countryCode)); 785 object.clearValues("phoneCityArea").add(areaCode); 786 object.clearValues("phoneLocalNumber").add(localNumber); 787 object.clearValues("phoneExtension").add(extension); 788 } 789 } 790 } 791 792 public Path createSubject( 794 String subjectName, 795 Path identitySegment, 796 List errors 797 ) { 798 Path subjectIdentity = identitySegment; 799 subjectIdentity = subjectIdentity.getDescendant(new String []{"subject", subjectName}); 800 try { 801 this.delegation.addGetRequest( 802 subjectIdentity, 803 AttributeSelectors.ALL_ATTRIBUTES, 804 new AttributeSpecifier[]{} 805 ); 806 } 807 catch(Exception e) { 808 DataproviderObject newSubject = new DataproviderObject( 809 subjectIdentity 810 ); 811 newSubject.values(SystemAttributes.OBJECT_CLASS).add("org:opencrx:security:identity1:Subject"); 812 newSubject.values("description").add(subjectName); 813 try { 814 this.delegation.addCreateRequest(newSubject); 815 } 816 catch(Exception e0) { 817 ServiceException e1 = new ServiceException(e); 818 AppLog.warning(e1.getMessage(), e1.getCause(), 1); 819 errors.add("can not create subject " + subjectName + " in segment " + identitySegment); 820 errors.add("reason is " + e0.getMessage()); 821 return null; 822 } 823 } 824 return subjectIdentity; 825 } 826 827 public Path createPrincipal( 829 String principalName, 830 Path realmIdentity, 831 String principalClass, 832 Path[] isMemberOf, 833 Path subjectIdentity, 834 List errors 835 ) { 836 Path principalIdentity = realmIdentity; 837 principalIdentity = principalIdentity.getDescendant(new String []{"principal", principalName}); 838 try { 839 DataproviderObject principal = new DataproviderObject( 840 this.delegation.addGetRequest( 841 principalIdentity, 842 AttributeSelectors.ALL_ATTRIBUTES, 843 new AttributeSpecifier[]{} 844 ) 845 ); 846 List isMemberOfAsList = Arrays.asList(isMemberOf); 847 if(!principal.values("isMemberOf").containsAll(isMemberOfAsList)) { 848 Set modifiedIsMemberOf = new ListOrderedSet(); 849 modifiedIsMemberOf.addAll(principal.values("isMemberOf")); 850 modifiedIsMemberOf.addAll(isMemberOfAsList); 851 principal.clearValues("isMemberOf").addAll( 852 modifiedIsMemberOf 853 ); 854 try { 855 this.delegation.addReplaceRequest(principal); 856 } 857 catch(ServiceException e) { 858 ServiceException e1 = new ServiceException(e); 859 AppLog.warning(e1.getMessage(), e1.getCause(), 1); 860 errors.add("can not update principal " + principalName + " in realm " + realmIdentity); 861 errors.add("reason is " + e1.getMessage()); 862 return null; 863 } 864 } 865 } 866 catch(Exception e) { 867 DataproviderObject newPrincipal = new DataproviderObject( 868 principalIdentity 869 ); 870 newPrincipal.values(SystemAttributes.OBJECT_CLASS).add(principalClass); 871 newPrincipal.values("description").add(principalIdentity.get(6) + "\\\\" + principalName); 872 newPrincipal.values("isMemberOf").addAll( 873 Arrays.asList(isMemberOf) 874 ); 875 if(subjectIdentity != null) { 876 newPrincipal.values("subject").add(subjectIdentity); 877 } 878 try { 879 this.delegation.addCreateRequest(newPrincipal); 880 } 881 catch(Exception e0) { 882 ServiceException e1 = new ServiceException(e); 883 AppLog.warning(e1.getMessage(), e1.getCause(), 1); 884 errors.add("can not create principal " + principalName + " in realm " + realmIdentity); 885 errors.add("reason is " + e0.getMessage()); 886 return null; 887 } 888 } 889 return principalIdentity; 890 } 891 892 public List mapToAccountIdentities( 894 List accountContentIdentities 895 ) throws ServiceException { 896 List accountIdentities = new ArrayList (); 897 for(Iterator i = accountContentIdentities.iterator(); i.hasNext(); ) { 898 accountIdentities.add( 899 ((Path)i.next()).getPrefix(7) 900 ); 901 } 902 return accountIdentities; 903 } 904 905 909 DataproviderObject_1_0 getAdditionalDescription( 910 Path forObject, 911 int language 912 ) { 913 try { 914 List additionalDescriptions = this.delegation.addFindRequest( 915 forObject.getChild("additionalDescription"), 916 new FilterProperty[]{ 917 new FilterProperty( 918 Quantors.THERE_EXISTS, 919 "language", 920 FilterOperators.IS_IN, 921 new Object []{ 922 new Integer (language) 923 } 924 ) 925 }, 926 AttributeSelectors.ALL_ATTRIBUTES, 927 null, 928 0, 929 Integer.MAX_VALUE, 930 Orders.ASCENDING 931 ); 932 DataproviderObject_1_0 additionalDescription = null; 933 for(Iterator i = additionalDescriptions.iterator(); i.hasNext(); ) { 934 additionalDescription = (DataproviderObject_1_0)i.next(); 935 AppLog.trace("additionalDescription", additionalDescription); 936 } 937 return additionalDescription; 938 } 939 catch(ServiceException e) { 940 e.log(); 941 return null; 942 } 943 } 944 945 public List getNewValue( 947 String feature, 948 DataproviderObject obj, 949 DataproviderObject_1_0 oldValues 950 ) throws ServiceException { 951 if((obj != null) && (obj.getValues(feature) != null)) { 952 return obj.values(feature); 953 } 954 else if(oldValues != null) { 955 return oldValues.values(feature); 956 } 957 return new ArrayList (); 958 } 959 960 public void initCharts( 962 DataproviderObject userHome, 963 DataproviderObject_1_0 oldValues 964 ) { 965 String objectClass = (String )userHome.values(SystemAttributes.OBJECT_CLASS).get(0); 966 if( 969 "org:opencrx:kernel:home1:UserHome".equals(objectClass) && 970 ((oldValues == null) || (oldValues.values("contact").size() == 0)) && 971 (userHome.values("contact").size() > 0) 972 ) { 973 userHome.clearValues("chart0").add( 975 userHome.path().getDescendant(new String []{"chart", "0"}) 976 ); 977 userHome.clearValues("chart1").add( 978 userHome.path().getDescendant(new String []{"chart", "2"}) 979 ); 980 userHome.clearValues("chart2").add( 981 userHome.path().getDescendant(new String []{"chart", "1"}) 982 ); 983 userHome.clearValues("chart3").add( 984 userHome.path().getDescendant(new String []{"chart", "3"}) 985 ); 986 } 987 } 988 989 private void preStore( 991 ServiceHeader header, 992 DataproviderObject obj, 993 DataproviderObject_1_0 oldValues 994 ) throws ServiceException { 995 this.accounts.setAccountFullName( 996 obj, 997 oldValues 998 ); 999 this.parsePhoneNumber( 1000 obj, 1001 oldValues 1002 ); 1003 this.initCharts( 1004 obj, 1005 oldValues 1006 ); 1007 this.contracts.updateContractPosition( 1008 header, 1009 obj, 1010 oldValues 1011 ); 1012 this.userHomes.encodeEMailAccountPassword( 1013 obj, 1014 oldValues 1015 ); 1016 this.activities.updateWorkRecord( 1017 header, 1018 obj, 1019 oldValues 1020 ); 1021 this.activities.updateActivity( 1022 obj, 1023 oldValues 1024 ); 1025 this.models.updateModelElement( 1026 header, 1027 obj, 1028 oldValues 1029 ); 1030 1031 if(oldValues == null) { 1033 this.assignToMe( 1034 header, 1035 obj, 1036 null, 1037 false, 1038 null 1039 ); 1040 } 1041 } 1042 1043 public DataproviderObject_1_0 getUserHome( 1045 ServiceHeader header, 1046 Path from 1047 ) throws ServiceException { 1048 return this.getUserHome( 1049 header, 1050 (String )header.getPrincipalChain().get(0), 1051 from 1052 ); 1053 } 1054 1055 private DataproviderObject_1_0 getUserHome( 1057 ServiceHeader header, 1058 String user, 1059 Path from 1060 ) throws ServiceException { 1061 if(user == null) return null; 1062 Path userHomePath = new Path( 1063 new String []{ 1064 "org:opencrx:kernel:home1", 1065 "provider", 1066 from.get(2), 1067 "segment", 1068 from.get(4), 1069 "userHome", 1070 user 1071 } 1072 ); 1073 try { 1074 DataproviderObject_1_0 userHome = this.retrieveObjectFromLocal( 1075 header, 1076 userHomePath 1077 ); 1078 return userHome; 1079 } 1080 catch(ServiceException e) { 1081 AppLog.info("can not retrieve UserHome", userHomePath); 1082 } 1083 return null; 1084 } 1085 1086 void assignToMe( 1088 ServiceHeader header, 1089 Path targetIdentity, 1090 boolean overwrite, 1091 Set attributeFilter 1092 ) throws ServiceException { 1093 this.assignToMe( 1094 header, 1095 this.retrieveObjectForModification(targetIdentity), 1096 this.retrieveObjectFromLocal(header, targetIdentity), 1097 overwrite, 1098 attributeFilter 1099 ); 1100 } 1101 1102 void assignToMe( 1104 ServiceHeader header, 1105 DataproviderObject target, 1106 DataproviderObject_1_0 targetOldValues, 1107 boolean overwrite, 1108 Set attributeFilter 1109 ) throws ServiceException { 1110 if(attributeFilter == null) { 1111 attributeFilter = new HashSet (); 1112 attributeFilter.add("assignedTo"); 1113 attributeFilter.add("salesRep"); 1114 attributeFilter.add("ratedBy"); 1115 } 1116 DataproviderObject_1_0 source = targetOldValues == null 1117 ? target 1118 : targetOldValues; 1119 String objectClass = (String )source.values(SystemAttributes.OBJECT_CLASS).get(0); 1120 ModelElement_1_0 classDef = this.model.getElement(objectClass); 1121 Map attributeDefs = this.model.getAttributeDefs(classDef, false, true); 1122 1123 if(header.getPrincipalChain().size() > 0) { 1126 DataproviderObject_1_0 userHome = this.getUserHome( 1127 header, 1128 target.path() 1129 ); 1130 if((userHome != null) && (userHome.values("contact").size() > 0)) { 1131 for(Iterator i = attributeFilter.iterator(); i.hasNext(); ) { 1132 String attribute = (String )i.next(); 1133 if( 1134 attributeDefs.keySet().contains(attribute) && 1135 (overwrite || (source.getValues(attribute) == null) || (source.getValues(attribute).size() == 0)) 1136 ) { 1137 target.clearValues(attribute).add( 1138 userHome.values("contact").get(0) 1139 ); 1140 } 1141 } 1142 } 1143 } 1144 } 1145 1146 private void addAsBookmark( 1148 ServiceHeader header, 1149 Path referencePath, 1150 List description 1151 ) throws ServiceException { 1152 DataproviderObject_1_0 userHome = this.getUserHome( 1153 header, 1154 referencePath 1155 ); 1156 if(userHome != null) { 1157 DataproviderObject bookmark = new DataproviderObject( 1158 userHome.path().getDescendant(new String []{"quickAccess", super.uidAsString()}) 1159 ); 1160 bookmark.values(SystemAttributes.OBJECT_CLASS).add("org:opencrx:kernel:home1:QuickAccess"); 1161 bookmark.values("description").addAll(description); 1162 bookmark.values("reference").add(referencePath); 1163 try { 1164 this.delegation.addCreateRequest( 1165 bookmark 1166 ); 1167 } 1168 catch(ServiceException e) { 1169 AppLog.warning("can not create bookmark", bookmark); 1170 e.log(); 1171 } 1172 } 1173 } 1174 1175 public DataproviderObject_1_0 sendAlert( 1177 ServiceHeader header, 1178 Path targetIdentity, 1179 DataproviderObject sendAlertParam 1180 ) throws ServiceException { 1181 String toUsers = sendAlertParam.values("toUsers").size() == 0 1182 ? "" 1183 : (String )sendAlertParam.values("toUsers").get(0); 1184 StringTokenizer tokenizer = new StringTokenizer (toUsers, ";, "); 1185 while(tokenizer.hasMoreTokens()) { 1186 String toUser = tokenizer.nextToken(); 1187 DataproviderObject_1_0 userHome = this.getUserHome( 1188 header, 1189 toUser, 1190 targetIdentity 1191 ); 1192 if(userHome != null) { 1193 DataproviderObject alert = new DataproviderObject( 1194 userHome.path().getDescendant(new String []{"alert", super.uidAsString()}) 1195 ); 1196 alert.values(SystemAttributes.OBJECT_CLASS).add("org:opencrx:kernel:home1:Alert"); 1197 alert.values("alertState").add(new Short ((short)1)); 1198 alert.values("name").addAll( 1199 sendAlertParam.values("name") 1200 ); 1201 alert.values("description").addAll( 1202 sendAlertParam.values("description") 1203 ); 1204 alert.values("importance").addAll( 1205 sendAlertParam.values("importance") 1206 ); 1207 alert.values("reference").addAll( 1208 sendAlertParam.values("reference") 1209 ); 1210 alert.clearValues("owningGroup").addAll( 1211 userHome.values("owningGroup") 1212 ); 1213 try { 1214 this.delegation.addCreateRequest( 1215 alert 1216 ); 1217 return alert; 1218 } 1219 catch(ServiceException e) { 1220 AppLog.warning("can not create alert", alert); 1221 e.log(); 1222 } 1223 } 1224 } 1225 return null; 1226 } 1227 1228 protected DataproviderObject createResult( 1230 DataproviderRequest request, 1231 String structName 1232 ) { 1233 DataproviderObject result = new DataproviderObject( 1234 request.path().getDescendant( 1235 new String []{ "reply", super.uidAsString()} 1236 ) 1237 ); 1238 result.clearValues(SystemAttributes.OBJECT_CLASS).add( 1239 structName 1240 ); 1241 return result; 1242 } 1243 1244 private int applyReplacements( 1246 ServiceHeader header, 1247 Path source, 1248 String referenceFilterAsString 1249 ) throws ServiceException { 1250 List replacements = this.delegation.addFindRequest( 1251 source.getChild("replacement"), 1252 null, 1253 AttributeSelectors.ALL_ATTRIBUTES, 1254 0, 1255 Integer.MAX_VALUE, 1256 Directions.ASCENDING 1257 ); 1258 return this.cloneable.applyReplacements( 1259 header, 1260 source, 1261 true, 1262 replacements, 1263 referenceFilterAsString 1264 ); 1265 } 1266 1267 public Path createObjectFromTemplate( 1269 ServiceHeader header, 1270 DataproviderObject_1_0 source, 1271 String name, 1272 String referenceFilterAsString 1273 ) throws ServiceException { 1274 Path clonedIdentity = this.cloneable.cloneAndUpdateReferences( 1275 header, 1276 source, 1277 source.path().getParent(), 1278 null, 1279 referenceFilterAsString, 1280 false 1281 ).path(); 1282 DataproviderObject cloned = this.retrieveObjectForModification(clonedIdentity); 1283 cloned.clearValues("isTemplate").add(Boolean.FALSE); 1284 if(name != null) { 1285 cloned.clearValues("name").add(name); 1286 } 1287 return clonedIdentity; 1288 } 1289 1290 private void deleteTemplateEnabledObject( 1292 DataproviderObject_1_0 source, 1293 String referenceFilterAsString 1294 ) throws ServiceException { 1295 this.cloneable.deleteCompositeAndReferencedObjects( 1296 source, 1297 referenceFilterAsString 1298 ); 1299 } 1300 1301 private List completeSegment( 1303 ServiceHeader header, 1304 DataproviderObject_1_0 object, 1305 Set fetchSet 1306 ) throws ServiceException { 1307 List additionalFetchedObjects = new ArrayList (); 1308 String providerName = object.path().get(2); 1309 String segmentName = object.path().get(4); 1310 try { 1311 additionalFetchedObjects.add(this.retrieveObjectFromLocal(header, new Path("xri:@openmdx:org.opencrx.kernel.home1/provider/" + providerName + "/segment/" + segmentName))); 1312 additionalFetchedObjects.add(this.retrieveObjectFromLocal(header, new Path("xri:@openmdx:org.opencrx.kernel.account1/provider/" + providerName + "/segment/" + segmentName))); 1313 additionalFetchedObjects.add(this.retrieveObjectFromLocal(header, new Path("xri:@openmdx:org.opencrx.kernel.activity1/provider/" + providerName + "/segment/" + segmentName))); 1314 additionalFetchedObjects.add(this.retrieveObjectFromLocal(header, new Path("xri:@openmdx:org.opencrx.kernel.contract1/provider/" + providerName + "/segment/" + segmentName))); 1315 additionalFetchedObjects.add(this.retrieveObjectFromLocal(header, new Path("xri:@openmdx:org.opencrx.kernel.product1/provider/" + providerName + "/segment/" + segmentName))); 1316 additionalFetchedObjects.add(this.retrieveObjectFromLocal(header, new Path("xri:@openmdx:org.opencrx.kernel.depot1/provider/" + providerName + "/segment/" + segmentName))); 1317 additionalFetchedObjects.add(this.retrieveObjectFromLocal(header, new Path("xri:@openmdx:org.opencrx.kernel.document1/provider/" + providerName + "/segment/" + segmentName))); 1318 additionalFetchedObjects.add(this.retrieveObjectFromLocal(header, new Path("xri:@openmdx:org.opencrx.kernel.building1/provider/" + providerName + "/segment/" + segmentName))); 1319 additionalFetchedObjects.add(this.retrieveObjectFromLocal(header, new Path("xri:@openmdx:org.opencrx.kernel.uom1/provider/" + providerName + "/segment/" + segmentName))); 1320 additionalFetchedObjects.add(this.retrieveObjectFromLocal(header, new Path("xri:@openmdx:org.opencrx.kernel.forecast1/provider/" + providerName + "/segment/" + segmentName))); 1321 additionalFetchedObjects.add(this.retrieveObjectFromLocal(header, new Path("xri:@openmdx:org.opencrx.kernel.workflow1/provider/" + providerName + "/segment/" + segmentName))); 1322 additionalFetchedObjects.add(this.retrieveObjectFromLocal(header, new Path("xri:@openmdx:org.opencrx.kernel.model1/provider/" + providerName + "/segment/" + segmentName))); 1323 } catch(Exception e) {} 1324 additionalFetchedObjects.remove(object); 1325 return additionalFetchedObjects; 1326 } 1327 1328 private List completePictured( 1330 ServiceHeader header, 1331 DataproviderObject_1_0 object, 1332 Set fetchSet 1333 ) { 1334 object.values("pictureContent"); 1335 object.values("pictureContentName"); 1336 object.values("pictureContentMimeType"); 1337 List additionalFetchedObjects = new ArrayList (); 1338 if( 1339 (object.getValues("picture") != null) && 1340 (object.values("picture").size() > 0) 1341 ) { 1342 try { 1343 DataproviderObject_1_0 media = this.retrieveObjectFromLocal( 1344 header, 1345 (Path)object.values("picture").get(0) 1346 ); 1347 if( 1348 (media.getValues("content") != null) && 1349 (media.values("content").size() > 0) 1350 ) { 1351 InputStream is = (InputStream )media.values("content").get(0); 1353 ByteArrayOutputStream os = new ByteArrayOutputStream (); 1354 int b = 0; 1355 int length = 0; 1356 while((b = is.read()) != -1) { 1357 os.write(b); 1358 length++; 1359 } 1360 if(length > 0) { 1361 object.values("pictureContent").add( 1362 os.toByteArray() 1363 ); 1364 object.values("pictureContentName").addAll( 1365 media.values("contentName") 1366 ); 1367 object.values("pictureContentMimeType").addAll( 1368 media.values("contentMimeType") 1369 ); 1370 additionalFetchedObjects.add(media); 1371 } 1372 } 1373 } 1374 catch(Exception e) { 1375 ServiceException e0 = new ServiceException(e); 1376 AppLog.detail("can not get picture.", e.getMessage()); 1377 AppLog.warning(e0.getMessage(), e0.getCause(), 1); 1378 } 1379 } 1380 return additionalFetchedObjects; 1381 } 1382 1383 protected List completeObject( 1385 ServiceHeader header, 1386 Set fetchSet, 1387 DataproviderObject_1_0 object 1388 ) throws ServiceException { 1389 List additionalFetchedObjects = new ArrayList (); 1390 if(this.isSegment(object)) { 1392 additionalFetchedObjects.addAll( 1393 this.completeSegment( 1394 header, 1395 object, 1396 fetchSet 1397 ) 1398 ); 1399 } 1400 else if(this.isPictured(object)) { 1402 additionalFetchedObjects.addAll( 1403 this.completePictured( 1404 header, 1405 object, 1406 fetchSet 1407 ) 1408 ); 1409 } 1410 if(this.isUserHome(object)) { 1412 additionalFetchedObjects.addAll( 1413 this.userHomes.completeUserHome( 1414 header, 1415 object 1416 ) 1417 ); 1418 } 1419 else if(this.isContractPosition(object)) { 1421 this.contracts.calculateContractPosition( 1422 header, 1423 this.retrieveObjectFromLocal(header, object.path().getParent().getParent()), 1424 object 1425 ); 1426 } 1427 else if(this.isContract(object)) { 1429 this.contracts.calculateContract( 1430 header, 1431 object, 1432 fetchSet 1433 ); 1434 this.contracts.calculateForwardReferences( 1435 object, 1436 fetchSet 1437 ); 1438 } 1439 else if(this.isActivity(object)) { 1441 additionalFetchedObjects.addAll( 1442 this.activities.completeActivity( 1443 header, 1444 object, 1445 fetchSet 1446 ) 1447 ); 1448 } 1449 else if(this.isActivityGroup(object)) { 1451 additionalFetchedObjects.addAll( 1452 this.activities.completeActivityGroup( 1453 header, 1454 object, 1455 fetchSet 1456 ) 1457 ); 1458 } 1459 else if(this.isContact(object)) { 1461 object.attributeNames().remove("ouMembership"); 1463 if((fetchSet == null) || fetchSet.contains("ouMembership")) { 1464 this.accounts.completeOuMembership(object); 1465 } 1466 } 1467 else if(this.isMedia(object)) { 1469 } 1471 else if(this.isModelElement(object)) { 1473 additionalFetchedObjects.addAll( 1474 this.models.completeElement( 1475 header, 1476 object 1477 ) 1478 ); 1479 } 1480 return additionalFetchedObjects; 1481 } 1482 1483 1489 protected void verifyObject( 1490 ServiceHeader header, 1491 DataproviderObject object 1492 ) throws ServiceException { 1493 String objectClass = (String )object.values(SystemAttributes.OBJECT_CLASS).get(0); 1494 1495 if("org:opencrx:kernel:account1:Contact".equals(objectClass)) { 1498 List lastName = object.getValues("lastName"); 1499 if( 1500 ((lastName != null) && (lastName.size() > 0)) && 1501 ("##demo for user defined error##".equals(lastName.get(0))) 1502 ) { 1503 throw new ServiceException( 1506 OpenCrxException.DOMAIN, 1507 OpenCrxException.ASSERTION_FAILURE, 1508 new BasicException.Parameter[]{ 1509 new BasicException.Parameter("contact", object), 1510 new BasicException.Parameter("param0", "lastName"), 1511 new BasicException.Parameter("param1", lastName) 1512 }, 1513 "A contact's last name must not be '##demo for user defined error##'" 1514 ); 1515 } 1516 } 1517 } 1518 1519 1525 protected void notifyPreStoreObject( 1526 ServiceHeader header, 1527 DataproviderObject object 1528 ) throws ServiceException { 1529 } 1530 1531 1536 protected void notifyRemoveObject( 1537 ServiceHeader header, 1538 Path objectIdentity 1539 ) throws ServiceException { 1540 } 1541 1542 private DataproviderReply completeReply( 1544 ServiceHeader header, 1545 Set fetchSet, 1546 boolean fetchAdditionalObjects, 1547 DataproviderReply reply 1548 ) throws ServiceException { 1549 List additionalFetchedObjects = new ArrayList (); 1550 for(int i = 0; i < reply.getObjects().length; i++) { 1551 additionalFetchedObjects.addAll( 1552 this.completeObject( 1553 header, 1554 fetchSet, 1555 reply.getObjects()[i] 1556 ) 1557 ); 1558 } 1559 if(!fetchAdditionalObjects || additionalFetchedObjects.isEmpty()) { 1560 return reply; 1561 } 1562 else { 1563 List allObjects = new ArrayList (Arrays.asList(reply.getObjects())); 1564 allObjects.addAll(additionalFetchedObjects); 1565 return new DataproviderReply(allObjects); 1566 } 1567 } 1568 1569 public RequestCollection getRunAsRootDelegation( 1571 ) { 1572 return new RequestCollection( 1573 new ServiceHeader(SecurityKeys.ADMIN_PRINCIPAL + SecurityKeys.ID_SEPARATOR + "Root", null, false, new QualityOfService()), 1574 this.router == null 1575 ? this.getDelegation() 1576 : this.router 1577 ); 1578 } 1579 1580 public void prolog( 1582 ServiceHeader header, 1583 DataproviderRequest[] requests 1584 ) throws ServiceException { 1585 super.prolog( 1586 header, 1587 requests 1588 ); 1589 if(this.codes == null) { 1591 try { 1592 this.codes = new Codes( 1593 this.getRunAsRootDelegation(), 1594 codeSegment 1595 ); 1596 } 1597 catch(ServiceException e) { 1598 AppLog.warning("can not initialize codes", e.getMessage()); 1599 } 1600 } 1601 this.delegation = new RequestCollection( 1602 header, 1603 this.router == null 1604 ? this.getDelegation() 1605 : this.router 1606 ); 1607 this.modifiedObjects = new HashMap (); 1608 1609 this.pendingModifications = new ArrayList (); 1612 for( 1613 int i = 0; 1614 i < requests.length; 1615 i++ 1616 ) { 1617 if(requests[i].operation() == DataproviderOperations.OBJECT_REPLACEMENT) { 1618 Path p = requests[i].path(); 1619 if( 1621 p.isLike(PATTERN_CONTRACT_SELECTABLE_ITEM) || 1622 p.isLike(PATTERN_MODEL_EDITABLE_OPERATION) || 1623 p.isLike(PATTERN_MODEL_EDITABLE_PARAMETER) || 1624 p.isLike(PATTERN_MODEL_EDITABLE_ATTRIBUTE) || 1625 p.isLike(PATTERN_MODEL_EDITABLE_STRUCTURE_FIELD) || 1626 p.isLike(PATTERN_MODEL_EDITABLE_PACKAGE) || 1627 p.isLike(PATTERN_MODEL_EDITABLE_CLASS) || 1628 p.isLike(PATTERN_MODEL_EDITABLE_STRUCTURE_TYPE) || 1629 p.isLike(PATTERN_MODEL_EDITABLE_OPERATION_TAG) 1630 ) { 1631 } 1633 else { 1634 this.pendingModifications.add( 1635 requests[i].object() 1636 ); 1637 } 1638 } 1639 } 1640 Provider_1_0 provider = new Provider_1( 1642 new RequestCollection( 1643 header, 1644 this.router 1645 ), 1646 false 1647 ); 1648 ObjectFactory_1_0 objectFactory = new Manager_1( 1649 new Connection_1( 1650 provider, 1651 true 1652 ) 1653 ); 1654 this.rootPkg = new RefRootPackage_1( 1655 objectFactory, 1656 null, null, "cci", 1659 false ); 1661 1662 this.contracts = new Contracts( 1664 this.model, 1665 this, 1666 this.delegation, 1667 this.rootPkg 1668 ); 1669 this.cloneable = new Cloneable ( 1670 this.model, 1671 this, 1672 this.delegation, 1673 this.rootPkg 1674 ); 1675 this.depots = new Depots( 1676 this.model, 1677 this, 1678 this.delegation, 1679 this.rootPkg 1680 ); 1681 this.products = new Products( 1682 this.model, 1683 this, 1684 this.delegation, 1685 this.rootPkg 1686 ); 1687 this.activities = new Activities( 1688 this.model, 1689 this, 1690 this.delegation, 1691 this.rootPkg 1692 ); 1693 this.accounts = new Accounts( 1694 this.model, 1695 this, 1696 this.delegation, 1697 this.rootPkg 1698 ); 1699 this.models = new Models( 1700 this.model, 1701 this, 1702 this.delegation, 1703 this.rootPkg 1704 ); 1705 this.userHomes = new UserHomes( 1706 this.model, 1707 this, 1708 this.delegation, 1709 this.passwordEncodingAlgorithm, 1710 this.rootPkg 1711 ); 1712 this.workflows = workflows = new Workflows( 1713 this.model, 1714 header, 1715 this, 1716 this.router == null ? this.getDelegation() : this.router, 1717 this.rootPkg 1718 ); 1719 this.derivedReferences = new DerivedReferences( 1720 this.model, 1721 this, 1722 this.getDelegation(), 1723 this.rootPkg 1724 ); 1725 } 1726 1727 private void processPendingModifications( 1729 ) throws ServiceException { 1730 for( 1731 Iterator i = this.pendingModifications.iterator(); 1732 i.hasNext(); 1733 ) { 1734 DataproviderObject modification = (DataproviderObject)i.next(); 1735 this.testObjectIsChangeable(modification); 1736 DataproviderObject modifiedObject = this.retrieveObjectForModification(modification.path()); 1737 modifiedObject.addClones( 1738 modification, 1739 true 1740 ); 1741 } 1742 this.pendingModifications.clear(); 1743 } 1744 public void epilog( 1746 ServiceHeader header, 1747 DataproviderRequest[] requests, 1748 DataproviderReply[] replies 1749 ) throws ServiceException { 1750 this.processPendingModifications(); 1751 this.flushObjectModifications(header); 1752 super.epilog( 1753 header, 1754 requests, 1755 replies 1756 ); 1757 } 1758 1759 public void flushObjectModifications( 1761 ServiceHeader header 1762 ) throws ServiceException { 1763 int count = 0; 1765 while(this.modifiedObjects.size() > 0) { 1766 Map modifiedObjects = new HashMap (this.modifiedObjects); 1767 for( 1768 Iterator i = modifiedObjects.values().iterator(); 1769 i.hasNext(); 1770 ) { 1771 DataproviderObject object = (DataproviderObject)i.next(); 1772 DataproviderObject_1_0 existingObject = this.retrieveObjectFromDelegation(object.path()); 1773 this.preStore( 1774 header, 1775 object, 1776 existingObject 1777 ); 1778 this.verifyObject( 1779 header, 1780 object 1781 ); 1782 try { 1783 this.delegation.addReplaceRequest( 1784 object 1785 ); 1786 } 1787 catch(ServiceException e) { 1788 if(e.getExceptionCode() == BasicException.Code.MEDIA_ACCESS_FAILURE) { 1790 throw new ServiceException( 1791 e, 1792 OpenCrxException.DOMAIN, 1793 OpenCrxException.MEDIA_ACCESS_FAILURE, 1794 new BasicException.Parameter[]{ 1795 new BasicException.Parameter("param0", DateFormat.getInstance().format(e.getTimestamp())) 1796 }, 1797 e.getDescription() 1798 ); 1799 } 1800 else { 1801 throw e; 1802 } 1803 } 1804 } 1805 this.modifiedObjects.keySet().removeAll( 1806 modifiedObjects.keySet() 1807 ); 1808 count++; 1809 if(count > 5) { 1810 throw new ServiceException( 1811 OpenCrxException.DOMAIN, 1812 OpenCrxException.ASSERTION_FAILURE, 1813 new BasicException.Parameter[]{}, 1814 "maximum limit of pre-store count exceeded. Possible reason: update recursion in preStore()" 1815 ); 1816 } 1817 } 1818 this.modifiedObjects.clear(); 1819 } 1820 1821 String toFilename( 1823 String s 1824 ) { 1825 s = s.replace(' ', '-'); 1826 s = s.replace(',', '-'); 1827 s = s.replace('/', '-'); 1828 s = s.replace('\\', '-'); 1829 s = s.replace(':', '-'); 1830 s = s.replace('*', '-'); 1831 s = s.replace('?', '-'); 1832 s = s.replace('<', '-'); 1833 s = s.replace('>', '-'); 1834 s = s.replace('|', '-'); 1835 s = s.replace('"', '-'); 1836 s = s.replace('\'', '-'); 1837 s = StringExpression.compile("--").matcher(s).replaceAll("-"); 1838 if(s.length() > 50) { 1839 s = s.substring(0, 44) + s.substring(s.length()-5); 1840 } 1841 return s; 1842 } 1843 1844 1849 private String analyseReport( 1850 List report 1851 ) { 1852 Map reportAsMap = new HashMap (); 1853 for(int i = 0; i < report.size(); i++) { 1854 Object key = report.get(i); 1855 Short count = (Short )reportAsMap.get(key); 1856 if(count == null) { 1857 count = new Short ((short)0); 1858 } 1859 reportAsMap.put( 1860 key, 1861 new Short ((short)(count.shortValue() + 1)) 1862 ); 1863 } 1864 return reportAsMap.toString(); 1865 } 1866 1867 public DataproviderReply get( 1869 ServiceHeader header, 1870 DataproviderRequest request 1871 ) throws ServiceException { 1872 DataproviderReply reply = this.derivedReferences.getReply(header, request); 1873 if(reply == null) { 1874 reply = super.get( 1875 header, 1876 request 1877 ); 1878 } 1879 return this.completeReply( 1880 header, 1881 request.attributeSelector() == AttributeSelectors.SPECIFIED_AND_TYPICAL_ATTRIBUTES 1882 ? request.attributeSpecifierAsMap().keySet() 1883 : null, 1884 true, 1885 reply 1886 ); 1887 } 1888 1889 public DataproviderReply find( 1891 ServiceHeader header, 1892 DataproviderRequest request 1893 ) throws ServiceException { 1894 DataproviderReply reply = this.derivedReferences.getReply(header, request); 1895 if(reply == null) { 1896 reply = super.find( 1897 header, 1898 request 1899 ); 1900 } 1901 return this.completeReply( 1902 header, 1903 request.attributeSelector() == AttributeSelectors.SPECIFIED_AND_TYPICAL_ATTRIBUTES 1904 ? request.attributeSpecifierAsMap().keySet() 1905 : null, 1906 false, 1907 reply 1908 ); 1909 } 1910 1911 public DataproviderReply create( 1913 ServiceHeader header, 1914 DataproviderRequest request 1915 ) throws ServiceException { 1916 this.testReferenceIsChangeable( 1917 request.path().getParent() 1918 ); 1919 String objectClass = (String )request.object().values(SystemAttributes.OBJECT_CLASS).get(0); 1920 if(this.model.isSubtypeOf(objectClass, "org:opencrx:kernel:model1:EditableAttribute")) { 1921 this.models.createAttribute(header, request.object()); 1922 return new DataproviderReply(request.object()); 1923 } 1924 else if(this.model.isSubtypeOf(objectClass, "org:opencrx:kernel:model1:EditableOperation")) { 1925 this.models.createOperation(header, request.object()); 1926 return new DataproviderReply(request.object()); 1927 } 1928 else if(this.model.isSubtypeOf(objectClass, "org:opencrx:kernel:model1:EditableParameter")) { 1929 this.models.createParameter(header, request.object()); 1930 return new DataproviderReply(request.object()); 1931 } 1932 else if(this.model.isSubtypeOf(objectClass, "org:opencrx:kernel:model1:EditableStructureField")) { 1933 this.models.createStructureField(header, request.object()); 1934 return new DataproviderReply(request.object()); 1935 } 1936 else if(this.model.isSubtypeOf(objectClass, "org:opencrx:kernel:model1:EditablePackage")) { 1937 this.models.createPackage(header, request.object()); 1938 return new DataproviderReply(request.object()); 1939 } 1940 else if(this.model.isSubtypeOf(objectClass, "org:opencrx:kernel:model1:EditableClass")) { 1941 this.models.createClass(header, request.object()); 1942 return new DataproviderReply(request.object()); 1943 } 1944 else if(this.model.isSubtypeOf(objectClass, "org:opencrx:kernel:model1:EditableStructureType")) { 1945 this.models.createStructureType(header, request.object()); 1946 return new DataproviderReply(request.object()); 1947 } 1948 else if(this.model.isSubtypeOf(objectClass, "org:opencrx:kernel:model1:EditableOperationTag")) { 1949 this.models.createTag(header, request.object()); 1950 return new DataproviderReply(request.object()); 1951 } 1952 else { 1953 this.preStore( 1954 header, 1955 request.object(), 1956 null 1957 ); 1958 this.verifyObject( 1959 header, 1960 request.object() 1961 ); 1962 this.notifyPreStoreObject( 1963 header, 1964 request.object() 1965 ); 1966 return super.create( 1967 header, 1968 request 1969 ); 1970 } 1971 } 1972 1973 public DataproviderReply remove( 1975 ServiceHeader header, 1976 DataproviderRequest request 1977 ) throws ServiceException { 1978 1979 if(request.path().isLike(PATTERN_PRODUCT_PRICE_LEVEL)) { 1981 this.products.removePriceLevel( 1982 header, 1983 request.path() 1984 ); 1985 return new DataproviderReply(request.object()); 1986 } 1987 if(request.path().isLike(PATTERN_ACTIVITY_WORK_RECORD)) { 1989 this.activities.removeWorkRecord( 1990 header, 1991 request.path() 1992 ); 1993 return new DataproviderReply(request.object()); 1994 } 1995 else if( 1997 request.path().isLike(PATTERN_ACTIVITY_TRACKER) || 1998 request.path().isLike(PATTERN_ACTIVITY_CATEGORY) || 1999 request.path().isLike(PATTERN_ACTIVITY_MILESTONE) 2000 ) { 2001 this.activities.removeActivityGroup( 2002 header, 2003 request.path() 2004 ); 2005 return new DataproviderReply(request.object()); 2006 } 2007 else if(request.path().isLike(PATTERN_DEPOT_ENTITY)) { 2009 this.depots.removeDepotEntity(request.path()); 2010 return new DataproviderReply(request.object()); 2011 } 2012 else if(request.path().isLike(PATTERN_DEPOT_HOLDER)) { 2014 this.depots.removeDepotContract(request.path()); 2015 return new DataproviderReply(request.object()); 2016 } 2017 else if(request.path().isLike(PATTERN_DEPOT_DEPOT)) { 2019 this.depots.removeDepot(request.path()); 2020 return new DataproviderReply(request.object()); 2021 } 2022 else if(request.path().isLike(PATTERN_DEPOT_POSITION)) { 2024 this.depots.removeDepotPosition(request.path()); 2025 return new DataproviderReply(request.object()); 2026 } 2027 else if(request.path().isLike(PATTERN_DEPOT_BOOKING)) { 2029 this.depots.removeBooking(request.path()); 2030 return new DataproviderReply(request.object()); 2031 } 2032 else if(request.path().isLike(PATTERN_DEPOT_COMPOUND_BOOKING)) { 2034 this.depots.removeCompoundBooking(header, request.path()); 2035 return new DataproviderReply(request.object()); 2036 } 2037 else if(request.path().isLike(PATTERN_CONTRACT_POSITION)) { 2039 this.contracts.removeContractPosition( 2040 header, 2041 this.retrieveObjectFromLocal(header, request.path()), 2042 true 2043 ); 2044 return new DataproviderReply(request.object()); 2045 } 2046 else if(request.path().isLike(PATTERN_MODEL_EDITABLE_OPERATION)) { 2048 this.models.removeOperation(header, request.path()); 2049 return new DataproviderReply(request.object()); 2050 } 2051 else if(request.path().isLike(PATTERN_MODEL_EDITABLE_PARAMETER)) { 2053 this.models.removeParameter(header, request.path()); 2054 return new DataproviderReply(request.object()); 2055 } 2056 else if(request.path().isLike(PATTERN_MODEL_EDITABLE_ATTRIBUTE)) { 2058 this.models.removeAttribute(header, request.path()); 2059 return new DataproviderReply(request.object()); 2060 } 2061 else if(request.path().isLike(PATTERN_MODEL_EDITABLE_STRUCTURE_FIELD)) { 2063 this.models.removeStructureField(header, request.path()); 2064 return new DataproviderReply(request.object()); 2065 } 2066 else if(request.path().isLike(PATTERN_MODEL_EDITABLE_PACKAGE)) { 2068 this.models.removePackage(header, request.path()); 2069 return new DataproviderReply(request.object()); 2070 } 2071 else if(request.path().isLike(PATTERN_MODEL_EDITABLE_CLASS)) { 2073 this.models.removeClass(header, request.path()); 2074 return new DataproviderReply(request.object()); 2075 } 2076 else if(request.path().isLike(PATTERN_MODEL_EDITABLE_STRUCTURE_TYPE)) { 2078 this.models.removeStructureType(header, request.path()); 2079 return new DataproviderReply(request.object()); 2080 } 2081 else if(request.path().isLike(PATTERN_MODEL_EDITABLE_OPERATION_TAG)) { 2083 this.models.removeOperationTag(header, request.path()); 2084 return new DataproviderReply(request.object()); 2085 } 2086 else { 2088 this.testReferenceIsChangeable( 2089 request.path().getParent() 2090 ); 2091 this.notifyRemoveObject( 2092 header, 2093 request.path() 2094 ); 2095 return super.remove( 2096 header, 2097 request 2098 ); 2099 } 2100 } 2101 2102 public DataproviderReply replace( 2104 ServiceHeader header, 2105 DataproviderRequest request 2106 ) throws ServiceException { 2107 Path p = request.path(); 2108 if(p.isLike(PATTERN_CONTRACT_POSITION)) { 2109 this.contracts.replaceContractPosition( 2110 header, 2111 request 2112 ); 2113 } 2114 else if(p.isLike(PATTERN_CONTRACT_SELECTABLE_ITEM)) { 2115 this.contracts.processSelectableItem( 2116 header, 2117 request 2118 ); 2119 } 2120 else if(p.isLike(PATTERN_MODEL_EDITABLE_OPERATION)) { 2121 this.models.replaceOperation( 2122 header, 2123 request 2124 ); 2125 } 2126 else if(p.isLike(PATTERN_MODEL_EDITABLE_PARAMETER)) { 2127 this.models.replaceParameter( 2128 header, 2129 request 2130 ); 2131 } 2132 else if(p.isLike(PATTERN_MODEL_EDITABLE_ATTRIBUTE)) { 2133 this.models.replaceAttribute( 2134 header, 2135 request 2136 ); 2137 } 2138 else if(p.isLike(PATTERN_MODEL_EDITABLE_STRUCTURE_FIELD)) { 2139 this.models.replaceStructureField( 2140 header, 2141 request 2142 ); 2143 } 2144 else if(p.isLike(PATTERN_MODEL_EDITABLE_PACKAGE)) { 2145 this.models.replacePackage( 2146 header, 2147 request 2148 ); 2149 } 2150 else if(p.isLike(PATTERN_MODEL_EDITABLE_CLASS)) { 2151 this.models.replaceClass( 2152 header, 2153 request 2154 ); 2155 } 2156 else if(p.isLike(PATTERN_MODEL_EDITABLE_STRUCTURE_TYPE)) { 2157 this.models.replaceStructureType( 2158 header, 2159 request 2160 ); 2161 } 2162 else if(p.isLike(PATTERN_MODEL_EDITABLE_OPERATION_TAG)) { 2163 this.models.replaceOperationTag( 2164 header, 2165 request 2166 ); 2167 } 2168 else if(p.isLike(PATTERN_CODE_SEGMENT)) { 2169 this.codes.markAsDirty(); 2170 } 2171 return new DataproviderReply( 2172 new DataproviderObject(request.object()) 2173 ); 2174 } 2175 2176 public DataproviderReply operation( 2178 ServiceHeader header, 2179 DataproviderRequest request 2180 ) throws ServiceException { 2181 String operationName = request.path().get( 2182 request.path().size() - 2 2183 ); 2184 DataproviderObject_1_0 source = this.retrieveObjectFromLocal( 2185 header, 2186 request.path().getPrefix(request.path().size() - 2) 2187 ); 2188 String sourceClass = (String )source.values(SystemAttributes.OBJECT_CLASS).get(0); 2189 DataproviderObject param = request.object(); 2190 2191 DataproviderObject reply = null; 2193 boolean isSecureObject = this.isSecureObject(source); 2194 2195 if("clone".equals(operationName)) { 2197 this.testObjectIsChangeable(source); 2199 DataproviderObject clone = this.cloneable.cloneAndUpdateReferences( 2200 header, 2201 source, 2202 source.path().getParent(), 2203 null, 2204 (param.values("referenceFilter").get(0) == null) || (((String )param.values("referenceFilter").get(0)).length() == 0) 2205 ? DEFAULT_REFERENCE_FILTER 2206 : (String )param.values("referenceFilter").get(0), 2207 false 2208 ); 2209 reply = this.createResult( 2210 request, 2211 "org:opencrx:kernel:base:CloneResult" 2212 ); 2213 reply.values("clonedObject").add( 2214 clone.path() 2215 ); 2216 } 2217 2218 else if("assignToMe".equals(operationName)) { 2220 reply = this.retrieveObjectForModification(source.path()); 2221 this.assignToMe( 2222 header, 2223 source.path(), 2224 true, 2225 null 2226 ); 2227 } 2228 2229 else if("addAsBookmark".equals(operationName)) { 2231 reply = new DataproviderObject(source); 2232 this.addAsBookmark( 2233 header, 2234 source.path(), 2235 param.values("description") 2236 ); 2237 } 2238 2239 else if("sendAlert".equals(operationName)) { 2241 this.sendAlert( 2242 header, 2243 source.path(), 2244 param 2245 ); 2246 reply = this.createResult( 2247 request, 2248 "org:openmdx:base:Void" 2249 ); 2250 } 2251 2252 else if("markAsRead".equals(operationName)) { 2254 DataproviderObject alert = this.retrieveObjectForModification(source.path()); 2255 alert.clearValues("alertState").add(new Short ((short)2)); 2256 reply = this.createResult( 2257 request, 2258 "org:openmdx:base:Void" 2259 ); 2260 } 2261 2262 else if("markAsAccepted".equals(operationName)) { 2264 DataproviderObject alert = this.retrieveObjectForModification(source.path()); 2265 alert.clearValues("alertState").add(new Short ((short)3)); 2266 reply = this.createResult( 2267 request, 2268 "org:openmdx:base:Void" 2269 ); 2270 } 2271 2272 else if("markAsClosed".equals(operationName)) { 2274 this.contracts.markAsClosed( 2275 source.path(), 2276 param 2277 ); 2278 reply = this.createResult( 2279 request, 2280 "org:openmdx:base:Void" 2281 ); 2282 } 2283 2284 else if("refreshItems".equals(operationName)) { 2286 if(this.isUserHome(source)) { 2287 if(source.values("contact").size() > 0) { 2288 this.removeAll( 2289 source.path().getChild("wfProcessInstance"), 2290 new FilterProperty[]{ 2292 new FilterProperty( 2293 Quantors.THERE_EXISTS, 2294 "startedOn", 2295 FilterOperators.IS_NOT_IN, 2296 new String []{} 2297 ) 2298 }, 2299 0, 2300 null 2301 ); 2302 this.removeAll( 2304 source.path().getChild("alert"), 2305 new FilterProperty[]{ 2306 new FilterProperty( 2307 Quantors.THERE_EXISTS, 2308 "alertState", 2309 FilterOperators.IS_GREATER_OR_EQUAL, 2310 new Short []{new Short ((short)3)} 2311 ) 2312 }, 2313 0, 2314 null 2315 ); 2316 this.flushObjectModifications(header); 2318 this.userHomes.refreshCharts( 2319 header, 2320 source 2321 ); 2322 } 2323 } 2324 else if(this.isActivityTracker(source)) { 2325 this.flushObjectModifications(header); 2326 this.activities.refreshTracker( 2327 header, 2328 source 2329 ); 2330 } 2331 reply = this.createResult( 2332 request, 2333 "org:openmdx:base:Void" 2334 ); 2335 } 2336 2337 else if("setOwningUser".equals(operationName) && isSecureObject) { 2339 List report = new ArrayList (); 2340 new SecureObject( 2341 this, 2342 this.delegation, 2343 this.model, 2344 this.loginRealmIdentity, 2345 param 2346 ).setOwningUser(source, report); 2347 reply = this.createResult( 2348 request, 2349 "org:opencrx:kernel:base:ModifySecureObjectResult" 2350 ); 2351 reply.values("statusMessage").add( 2352 this.analyseReport(report) 2353 ); 2354 } 2355 2356 else if("addOwningGroup".equals(operationName) && isSecureObject) { 2358 List report = new ArrayList (); 2359 new SecureObject( 2360 this, 2361 this.delegation, 2362 this.model, 2363 this.loginRealmIdentity, 2364 param 2365 ).addOwningGroup(source, report); 2366 reply = this.createResult( 2367 request, 2368 "org:opencrx:kernel:base:ModifySecureObjectResult" 2369 ); 2370 reply.values("statusMessage").add( 2371 this.analyseReport(report) 2372 ); 2373 } 2374 2375 else if("removeOwningGroup".equals(operationName) && isSecureObject) { 2377 List report = new ArrayList (); 2378 new SecureObject( 2379 this, 2380 this.delegation, 2381 this.model, 2382 this.loginRealmIdentity, 2383 param 2384 ).removeOwningGroup(source, report); 2385 reply = this.createResult( 2386 request, 2387 "org:opencrx:kernel:base:ModifySecureObjectResult" 2388 ); 2389 reply.values("statusMessage").add( 2390 this.analyseReport(report) 2391 ); 2392 } 2393 2394 else if("removeAllOwningGroup".equals(operationName) && isSecureObject) { 2396 List report = new ArrayList (); 2397 new SecureObject( 2398 this, 2399 this.delegation, 2400 this.model, 2401 this.loginRealmIdentity, 2402 param 2403 ).removeAllOwningGroup(source, report); 2404 reply = this.createResult( 2405 request, 2406 "org:opencrx:kernel:base:ModifySecureObjectResult" 2407 ); 2408 reply.values("statusMessage").add( 2409 this.analyseReport(report) 2410 ); 2411 } 2412 else if("setAccessLevel".equals(operationName) && isSecureObject) { 2414 List report = new ArrayList (); 2415 new SecureObject( 2416 this, 2417 this.delegation, 2418 this.model, 2419 this.loginRealmIdentity, 2420 param 2421 ).setAccessLevel(source, report); 2422 reply = this.createResult( 2423 request, 2424 "org:opencrx:kernel:base:ModifySecureObjectResult" 2425 ); 2426 reply.values("statusMessage").add( 2427 this.analyseReport(report) 2428 ); 2429 } 2430 else if("executeWorkflow".equals(operationName)) { 2432 DataproviderObject workflowInstance = this.workflows.executeWorkflow( 2433 source, 2434 (Path)param.values("workflow").get(0), 2435 (Path)param.values("targetObject").get(0), 2436 (String )param.values("targetObjectXri").get(0), 2437 (String )param.values("triggeredByEventId").get(0), 2438 (Path)param.values("triggeredBySubscription").get(0), 2439 (Number )param.values("triggeredByEventType").get(0) 2440 ); 2441 reply = this.createResult( 2442 request, 2443 "org:opencrx:kernel:base:ExecuteWorkflowResult" 2444 ); 2445 if(workflowInstance != null) { 2446 reply.values("workflowInstance").add(workflowInstance.path()); 2447 } 2448 } 2449 else if("newActivity".equals(operationName)) { 2451 Path activityIdentity = this.activities.newActivity( 2452 header, 2453 source.path(), 2454 (String )param.values("name").get(0), 2455 (String )param.values("description").get(0), 2456 (String )param.values("detailedDescription").get(0), 2457 (String )param.values("scheduledStart").get(0), 2458 (String )param.values("scheduledEnd").get(0), 2459 (String )param.values("dueBy").get(0), 2460 (Number )param.values("priority").get(0), 2461 (Path)param.values("reportingContact").get(0) 2462 ); 2463 reply = this.createResult( 2464 request, 2465 "org:opencrx:kernel:activity1:NewActivityResult" 2466 ); 2467 if(activityIdentity != null) { 2468 reply.values("activity").add(activityIdentity); 2469 } 2470 } 2471 else if("voteForActivity".equals(operationName)) { 2473 this.activities.voteForActivity(header, source, param); 2474 reply = this.createResult( 2475 request, 2476 "org:openmdx:base:Void" 2477 ); 2478 } 2479 else if("addSubscription".equals(operationName)) { 2481 SubscriptionTarget subscriptionTarget = new SubscriptionTarget(this, this.delegation); 2482 subscriptionTarget.addSubscription(header, source, param); 2483 reply = this.createResult( 2484 request, 2485 "org:openmdx:base:Void" 2486 ); 2487 } 2488 else if("addSubscriptionForParent".equals(operationName)) { 2490 SubscriptionTarget subscriptionTarget = new SubscriptionTarget(this, this.delegation); 2491 subscriptionTarget.addSubscriptionForParent(header, source, param); 2492 reply = this.createResult( 2493 request, 2494 "org:openmdx:base:Void" 2495 ); 2496 } 2497 else if("removeSubscription".equals(operationName)) { 2499 SubscriptionTarget subscriptionTarget = new SubscriptionTarget(this, this.delegation); 2500 subscriptionTarget.removeSubscription(header, source, param); 2501 reply = this.createResult( 2502 request, 2503 "org:openmdx:base:Void" 2504 ); 2505 } 2506 2507 else if("removeSubscription".equals(operationName)) { 2509 SubscriptionTarget subscriptionTarget = new SubscriptionTarget(this, this.delegation); 2510 subscriptionTarget.removeSubscriptionForParent(header, source, param); 2511 reply = this.createResult( 2512 request, 2513 "org:openmdx:base:Void" 2514 ); 2515 } 2516 else if("applyReplacements".equals(operationName)) { 2518 int numberOfReplacements = this.applyReplacements( 2519 header, 2520 source.path(), 2521 (String )source.values("templateReferenceFilter").get(0) 2522 ); 2523 reply = this.createResult( 2524 request, 2525 "org:opencrx:kernel:base:TemplateApplyReplacementsResult" 2526 ); 2527 reply.values("numberOfReplacements").add( 2528 new Integer (numberOfReplacements) 2529 ); 2530 } 2531 else if("createObject".equals(operationName)) { 2533 Path createdObject = this.createObjectFromTemplate( 2534 header, 2535 source, 2536 (String )param.values("name").get(0), 2537 (String )source.values("templateReferenceFilter").get(0) 2538 ); 2539 reply = this.createResult( 2540 request, 2541 "org:opencrx:kernel:base:TemplateCreateObjectResult" 2542 ); 2543 reply.values("createdObject").add(createdObject); 2544 } 2545 else if("deleteObject".equals(operationName)) { 2547 this.deleteTemplateEnabledObject( 2548 source, 2549 (String )source.values("templateReferenceFilter").get(0) 2550 ); 2551 reply = this.createResult( 2552 request, 2553 "org:openmdx:base:Void" 2554 ); 2555 } 2556 else if("createBookingByPosition".equals(operationName)) { 2558 List errors = new ArrayList (); 2559 DataproviderObject_1_0 compoundBooking = 2560 this.depots.createBookingByPosition( 2561 header, 2562 source.path(), 2563 param, 2564 errors 2565 ); 2566 reply = this.createResult( 2567 request, 2568 "org:opencrx:kernel:depot1:CreateBookingResult" 2569 ); 2570 if(compoundBooking == null) { 2571 reply.values("status").add(new Integer (1)); 2572 reply.values("statusMessage").add(errors.toString()); 2573 } 2574 else { 2575 reply.values("status").add(new Integer (0)); 2576 reply.values("compoundBooking").add(compoundBooking.path()); 2577 } 2578 } 2579 else if("createBookingByPositionName".equals(operationName)) { 2581 List errors = new ArrayList (); 2582 DataproviderObject_1_0 compoundBooking = 2583 this.depots.createBookingByPositionName( 2584 header, 2585 source.path(), 2586 param, 2587 errors 2588 ); 2589 reply = this.createResult( 2590 request, 2591 "org:opencrx:kernel:depot1:CreateBookingResult" 2592 ); 2593 if(compoundBooking == null) { 2594 reply.values("status").add(new Integer (1)); 2595 reply.values("statusMessage").add(errors.toString()); 2596 } 2597 else { 2598 reply.values("status").add(new Integer (0)); 2599 reply.values("compoundBooking").add(compoundBooking.path()); 2600 } 2601 } 2602 else if("createBookingByProduct".equals(operationName)) { 2604 List errors = new ArrayList (); 2605 DataproviderObject_1_0 compoundBooking = 2606 this.depots.createBookingByProduct( 2607 header, 2608 source.path(), 2609 param, 2610 errors 2611 ); 2612 reply = this.createResult( 2613 request, 2614 "org:opencrx:kernel:depot1:CreateBookingResult" 2615 ); 2616 if(compoundBooking == null) { 2617 reply.values("status").add(new Integer (1)); 2618 reply.values("statusMessage").add(errors.toString()); 2619 } 2620 else { 2621 reply.values("status").add(new Integer (0)); 2622 reply.values("compoundBooking").add(compoundBooking.path()); 2623 } 2624 } 2625 else if("cancelCb".equals(operationName)) { 2627 List errors = new ArrayList (); 2628 DataproviderObject_1_0 cancelBooking = this.depots.cancelCompoundBooking(header, source, param, errors); 2629 reply = this.createResult( 2630 request, 2631 "org:opencrx:kernel:depot1:CancelCompoundBookingResult" 2632 ); 2633 if(cancelBooking == null) { 2634 reply.values("status").add(new Integer (1)); 2635 reply.values("statusMessage").add(errors.toString()); 2636 } 2637 else { 2638 reply.values("status").add(new Integer (0)); 2639 reply.values("cancelBooking").add(cancelBooking.path()); 2640 } 2641 } 2642 else if("acceptCb".equals(operationName)) { 2644 this.depots.acceptCompoundBooking(header, source); 2645 reply = this.createResult( 2646 request, 2647 "org:openmdx:base:Void" 2648 ); 2649 } 2650 else if("finalizeCb".equals(operationName)) { 2652 this.depots.finalizeCompoundBooking(header, source); 2653 reply = this.createResult( 2654 request, 2655 "org:openmdx:base:Void" 2656 ); 2657 } 2658 else if("lockCb".equals(operationName)) { 2660 this.depots.lockCompoundBooking(header, source, param); 2661 reply = this.createResult( 2662 request, 2663 "org:openmdx:base:Void" 2664 ); 2665 } 2666 else if("unlockCb".equals(operationName)) { 2668 this.depots.unlockCompoundBooking(header, source, param); 2669 reply = this.createResult( 2670 request, 2671 "org:openmdx:base:Void" 2672 ); 2673 } 2674 else if("openDepot".equals(operationName)) { 2676 List errors = new ArrayList (); 2677 DataproviderObject_1_0 depot = this.depots.openDepot(source, param, errors); 2678 reply = this.createResult( 2679 request, 2680 "org:opencrx:kernel:depot1:OpenDepotResult" 2681 ); 2682 if(depot == null) { 2683 reply.values("status").add(new Integer (1)); 2684 reply.values("statusMessage").add(errors.toString()); 2685 } 2686 else { 2687 reply.values("status").add(new Integer (0)); 2688 reply.values("depot").add(depot.path()); 2689 } 2690 } 2691 else if("closeDepot".equals(operationName)) { 2693 List errors = new ArrayList (); 2694 this.depots.closeDepot(source, param, errors); 2695 reply = this.createResult( 2696 request, 2697 "org:opencrx:kernel:depot1:CloseDepotResult" 2698 ); 2699 reply.values("status").add(new Integer (0)); 2700 } 2701 else if("openDepotPosition".equals(operationName)) { 2703 DataproviderObject_1_0 depotPosition = this.depots.openDepotPosition(header, source, param); 2704 reply = this.createResult( 2705 request, 2706 "org:opencrx:kernel:depot1:OpenDepotPositionResult" 2707 ); 2708 if(depotPosition == null) { 2709 reply.values("status").add(new Integer (1)); 2710 reply.values("statusMessage").add(""); 2711 } 2712 else { 2713 reply.values("status").add(new Integer (0)); 2714 reply.values("depotPosition").add(depotPosition.path()); 2715 } 2716 } 2717 else if("closeDepotPosition".equals(operationName)) { 2719 List errors = new ArrayList (); 2720 this.depots.closeDepotPosition(source, param, errors); 2721 reply = this.createResult( 2722 request, 2723 "org:opencrx:kernel:depot1:CloseDepotPositionResult" 2724 ); 2725 reply.values("status").add(new Integer (0)); 2726 } 2727 else if("assertReports".equals(operationName)) { 2729 if(this.isDepot(source)) { 2730 this.depots.assertReports(header, source.path()); 2731 } 2732 else if(this.isDepotHolder(source)) { 2733 List depots = this.delegation.addFindRequest( 2734 source.path().getChild("depot"), 2735 null 2736 ); 2737 for(Iterator i = depots.iterator(); i.hasNext(); ) { 2738 DataproviderObject_1_0 depot = (DataproviderObject_1_0)i.next(); 2739 this.depots.assertReports(header, depot.path()); 2740 } 2741 } 2742 reply = this.createResult( 2743 request, 2744 "org:openmdx:base:Void" 2745 ); 2746 } 2747 else if("setConfigurationType".equals(operationName)) { 2749 this.products.setConfigurationType( 2750 header, 2751 source, 2752 (Path)param.values("configurationType").get(0) 2753 ); 2754 reply = this.createResult( 2755 request, 2756 "org:openmdx:base:Void" 2757 ); 2758 } 2759 else if("unsetConfigurationType".equals(operationName)) { 2761 this.products.unsetConfigurationType( 2762 source 2763 ); 2764 reply = this.createResult( 2765 request, 2766 "org:openmdx:base:Void" 2767 ); 2768 } 2769 else if("assignProduct".equals(operationName)) { 2771 this.products.assignProduct( 2772 header, 2773 source, 2774 (Path)param.values("product").get(0) 2775 ); 2776 reply = this.createResult( 2777 request, 2778 "org:openmdx:base:Void" 2779 ); 2780 } 2781 else if("updateInventory".equals(operationName)) { 2783 Path compoundBookingIdentity = this.contracts.updateInventory( 2784 header, 2785 source, 2786 (Boolean )param.values("cancelPreviousInventoryUpdate").get(0) 2787 ); 2788 reply = this.createResult( 2789 request, 2790 "org:opencrx:kernel:contract1:UpdateInventoryResult" 2791 ); 2792 if(compoundBookingIdentity != null) { 2793 reply.values("compoundBooking").add(compoundBookingIdentity); 2794 } 2795 } 2796 else if("cancelInventoryUpdate".equals(operationName)) { 2798 this.contracts.cancelInventoryUpdate( 2799 header, 2800 source 2801 ); 2802 reply = this.createResult( 2803 request, 2804 "org:openmdx:base:Void" 2805 ); 2806 } 2807 else if("reapplyActivityCreator".equals(operationName)) { 2809 this.activities.reapplyActivityCreator( 2810 header, 2811 source.path(), 2812 (Path)param.values("activityCreator").get(0) 2813 ); 2814 reply = this.createResult( 2815 request, 2816 "org:openmdx:base:Void" 2817 ); 2818 } 2819 else if(this.model.isSubtypeOf(sourceClass, "org:opencrx:kernel:admin1:Segment")) { 2821 if("createAdministrator".equals(operationName)) { 2822 String segmentName = param.values("segmentName").size() > 0 2823 ? (String )param.values("segmentName").get(0) 2824 : "Standard"; 2825 String adminPrincipalName = param.values("adminPrincipalName").size() > 0 2826 ? (String )param.values("adminPrincipalName").get(0) 2827 : "admin-" + segmentName; 2828 String initialPassword = (String )param.values("initialPassword").get(0); 2829 String initialPasswordVerification = (String )param.values("initialPasswordVerification").get(0); 2830 2831 List errors = new ArrayList (); 2832 new Admin( 2833 this, 2834 this.delegation, 2835 this.passwordEncodingAlgorithm 2836 ).createAdministrator( 2837 source.path(), 2838 this.loginRealmIdentity, 2839 segmentName, 2840 adminPrincipalName, 2841 initialPassword, 2842 initialPasswordVerification, 2843 errors 2844 ); 2845 reply = this.createResult( 2846 request, 2847 "org:opencrx:kernel:admin1:CreateAdministratorResult" 2848 ); 2849 if(errors.size() > 0) { 2850 reply.values("status").add(new Short ((short)1)); 2851 reply.values("statusMessage").add( 2852 errors.toString() 2853 ); 2854 } 2855 else { 2856 reply.values("status").add(new Short ((short)0)); 2857 } 2858 } 2859 else if("importLoginPrincipals".equals(operationName)) { 2861 String statusMessage = new Admin( 2862 this, 2863 this.delegation, 2864 this.passwordEncodingAlgorithm 2865 ).importLoginPrincipals( 2866 source, 2867 (byte[])param.values("item").get(0) 2868 ); 2869 reply = this.createResult( 2870 request, 2871 "org:opencrx:kernel:admin1:ImportLoginPrincipalsResult" 2872 ); 2873 reply.values("statusMessage").add( 2874 statusMessage 2875 ); 2876 } 2877 } 2878 2879 else if(this.model.isSubtypeOf(sourceClass, "org:opencrx:kernel:account1:Segment")) { 2881 if("importItem".equals(operationName)) { 2882 short locale = ((Short )param.values("locale").get(0)).shortValue(); 2883 byte[] item = (byte[])param.values("item").get(0); 2884 String itemMimeType = (String )param.values("itemMimeType").get(0); 2885 AppLog.trace("import MIME_TYPE", itemMimeType); 2886 List report = new ArrayList (); 2887 DataproviderObject importedObject = null; 2888 if(VCard.MIME_TYPE.equals(itemMimeType)) { 2889 importedObject = new VCard( 2890 this, 2891 this.delegation, 2892 this.codes 2893 ).importItem( 2894 item, 2895 source.path().getPrefix(5), 2896 locale, 2897 report 2898 ); 2899 reply = this.createResult( 2900 request, 2901 "org:opencrx:kernel:base:ImportResult" 2902 ); 2903 if(importedObject != null) { 2904 reply.values("importedObject").add( 2905 importedObject.path() 2906 ); 2907 reply.values("status").add( 2908 new Short (IMPORT_EXPORT_OK) 2909 ); 2910 reply.values("statusMessage").add( 2911 this.analyseReport(report) 2912 ); 2913 } 2914 else { 2915 reply.values("status").add( 2916 new Short (IMPORT_EXPORT_ITEM_NOT_VALID) 2917 ); 2918 } 2919 } 2920 } 2921 } 2922 2923 else if(this.model.isSubtypeOf(sourceClass, "org:opencrx:kernel:activity1:Segment")) { 2925 if("importItem".equals(operationName)) { 2926 short locale = ((Short )param.values("locale").get(0)).shortValue(); 2927 byte[] item = (byte[])param.values("item").get(0); 2928 String itemMimeType = (String )param.values("itemMimeType").get(0); 2929 AppLog.trace("import MIME_TYPE", itemMimeType); 2930 2931 List errors = new ArrayList (); 2932 List report = new ArrayList (); 2933 DataproviderObject importedObject = null; 2934 2935 if(ICalendar.MIME_TYPE.equals(itemMimeType)) { 2937 importedObject = new ICalendar( 2938 this, 2939 this.delegation, 2940 this.codes 2941 ).importItem( 2942 item, 2943 source.path().getPrefix(5), 2944 new Path( 2945 new String []{"org:opencrx:kernel:account1", source.path().get(1), source.path().get(2), source.path().get(3), source.path().get(4)} 2946 ), 2947 locale, 2948 errors, 2949 report 2950 ); 2951 reply = this.createResult( 2952 request, 2953 "org:opencrx:kernel:base:ImportResult" 2954 ); 2955 if((importedObject == null) || (errors.size() > 0)) { 2956 reply.values("status").add( 2957 new Short (IMPORT_EXPORT_ITEM_NOT_VALID) 2958 ); 2959 reply.values("statusMessage").add( 2960 errors.toString() 2961 ); 2962 } 2963 else { 2964 reply.values("importedObject").add( 2965 importedObject.path() 2966 ); 2967 reply.values("status").add( 2968 new Short (IMPORT_EXPORT_OK) 2969 ); 2970 reply.values("statusMessage").add( 2971 this.analyseReport(report) 2972 ); 2973 } 2974 } 2975 } 2976 } 2977 2978 else if(this.model.isSubtypeOf(sourceClass, "org:opencrx:kernel:home1:Segment")) { 2980 if("createUser".equals(operationName)) { 2981 String principalName = (String )param.values("principalName").get(0); 2982 Path contactIdentity = (Path)param.values("contact").get(0); 2983 Path primaryUserGroupIdentity = (Path)param.values("primaryUserGroup").get(0); 2984 String initialPassword = (String )param.values("initialPassword").get(0); 2985 String initialPasswordVerification = (String )param.values("initialPasswordVerification").get(0); 2986 Path realmIdentity = this.loginRealmIdentity.getParent().getChild(source.path().get(4)); 2987 2988 List errors = new ArrayList (); 2989 DataproviderObject_1_0 userHome = this.userHomes.createUserHome( 2990 this.loginRealmIdentity, 2991 realmIdentity, 2992 contactIdentity, 2993 primaryUserGroupIdentity, 2994 principalName, 2995 false, 2996 initialPassword, 2997 initialPasswordVerification, 2998 errors 2999 ); 3000 reply = this.createResult( 3001 request, 3002 "org:opencrx:kernel:home1:CreateUserResult" 3003 ); 3004 if((userHome == null) || (errors.size() > 0)) { 3005 reply.values("status").add(new Short ((short)1)); 3006 reply.values("statusMessage").add( 3007 errors.toString() 3008 ); 3009 } 3010 else { 3011 reply.values("status").add(new Short ((short)0)); 3012 reply.values("createdUserHome").add(userHome.path()); 3013 } 3014 } 3015 else if("importUsers".equals(operationName)) { 3017 String statusMessage = this.userHomes.importUsers( 3018 source, 3019 (byte[])param.values("item").get(0) 3020 ); 3021 reply = this.createResult( 3022 request, 3023 "org:opencrx:kernel:home1:ImportUsersResult" 3024 ); 3025 reply.values("statusMessage").add(statusMessage); 3026 } 3027 } 3028 else if(this.model.isSubtypeOf(sourceClass, "org:opencrx:kernel:home1:UserHome")) { 3030 if("changePassword".equals(operationName)) { 3031 String requestingPrincipalName = header.getPrincipalChain().size() > 0 3032 ? (String )header.getPrincipalChain().get(0) 3033 : "guest"; 3034 boolean requestingPrincipalOwnsUserHome = source.path().getBase().equals(requestingPrincipalName); 3040 RequestCollection delegation = requestingPrincipalOwnsUserHome 3041 ? new RequestCollection( 3042 new ServiceHeader( 3043 SecurityKeys.ADMIN_PRINCIPAL + SecurityKeys.ID_SEPARATOR + source.path().get(4), 3045 null, 3046 false, 3047 new QualityOfService() 3048 ), this.router == null ? this.getDelegation() : this.router) 3049 : this.delegation; 3050 int status = this.userHomes.changePassword( 3051 source, 3052 loginRealmIdentity, 3053 requestingPrincipalOwnsUserHome, 3054 (String )param.values("oldPassword").get(0), 3055 (String )param.values("newPassword").get(0), 3056 (String )param.values("newPasswordVerification").get(0) 3057 ); 3058 reply = this.createResult( 3059 request, 3060 "org:opencrx:kernel:home1:ChangePasswordResult" 3061 ); 3062 reply.values("status").add( 3063 new Short ((short)status) 3064 ); 3065 } 3066 } 3067 else if(this.model.isSubtypeOf(sourceClass, "org:opencrx:kernel:activity1:Resource")) { 3069 if("addWorkRecordByPeriod".equals(operationName)) { 3070 DataproviderObject workRecord = this.activities.addWorkRecordByPeriod( 3071 header, 3072 source, 3073 param 3074 ); 3075 reply = this.createResult( 3076 request, 3077 "org:opencrx:kernel:activity1:AddWorkRecordResult" 3078 ); 3079 if(workRecord != null) { 3080 reply.values("workRecord").add( 3081 workRecord.path() 3082 ); 3083 } 3084 } 3085 else if("addWorkRecordByDuration".equals(operationName)) { 3086 DataproviderObject workRecord = this.activities.addWorkRecordByDuration( 3087 header, 3088 source, 3089 param 3090 ); 3091 reply = this.createResult( 3092 request, 3093 "org:opencrx:kernel:activity1:AddWorkRecordResult" 3094 ); 3095 if(workRecord != null) { 3096 reply.values("workRecord").add( 3097 workRecord.path() 3098 ); 3099 } 3100 } 3101 else if("addWorkRecordByCalendar".equals(operationName)) { 3102 DataproviderObject workRecord = this.activities.addWorkRecordByCalendar( 3103 header, 3104 source, 3105 param 3106 ); 3107 reply = this.createResult( 3108 request, 3109 "org:opencrx:kernel:activity1:AddWorkRecordResult" 3110 ); 3111 if(workRecord != null) { 3112 reply.values("workRecord").add( 3113 workRecord.path() 3114 ); 3115 } 3116 } 3117 } 3118 else if(this.model.isSubtypeOf(sourceClass, "org:opencrx:kernel:contract1:Lead")) { 3120 if("createOpportunity".equals(operationName)) { 3121 DataproviderObject opportunity = this.contracts.createOpportunity(header, source); 3122 reply = this.createResult( 3123 request, 3124 "org:opencrx:kernel:contract1:LeadCreateOpportunityResult" 3125 ); 3126 reply.values("opportunity").add( 3127 opportunity.path() 3128 ); 3129 } 3130 } 3131 else if(this.model.isSubtypeOf(sourceClass, "org:opencrx:kernel:contract1:Opportunity")) { 3133 if("reprice".equals(operationName)) { 3134 this.contracts.repriceContract( 3135 header, 3136 source 3137 ); 3138 reply = this.createResult( 3139 request, 3140 "org:openmdx:base:Void" 3141 ); 3142 } 3143 else if("createQuote".equals(operationName)) { 3144 DataproviderObject quote = this.contracts.createQuote(header, source); 3145 reply = this.createResult( 3146 request, 3147 "org:opencrx:kernel:contract1:OpportunityCreateQuoteResult" 3148 ); 3149 reply.values("quote").add( 3150 quote.path() 3151 ); 3152 } 3153 else if("createPosition".equals(operationName)) { 3154 DataproviderObject position = this.contracts.createContractPosition( 3155 header, 3156 source, 3157 param 3158 ); 3159 reply = this.createResult( 3160 request, 3161 "org:opencrx:kernel:contract1:CreatePositionResult" 3162 ); 3163 if(position != null) { 3164 reply.values("position").add(position.path()); 3165 } 3166 } 3167 else if("createProductOfferingPosition".equals(operationName)) { 3168 DataproviderObject position = this.contracts.createProductOfferingPosition( 3169 header, 3170 source.path(), 3171 (Path)param.values("offering").get(0), 3172 (BigDecimal )param.values("quantity").get(0) 3173 ); 3174 reply = this.createResult( 3175 request, 3176 "org:opencrx:kernel:contract1:CreateProductOfferingPositionResult" 3177 ); 3178 reply.values("offeringPosition").add( 3179 position.path() 3180 ); 3181 } 3182 } 3183 else if(this.model.isSubtypeOf(sourceClass, "org:opencrx:kernel:contract1:Quote")) { 3185 if("reprice".equals(operationName)) { 3186 this.contracts.repriceContract( 3187 header, 3188 source 3189 ); 3190 reply = this.createResult( 3191 request, 3192 "org:openmdx:base:Void" 3193 ); 3194 } 3195 else if("createSalesOrder".equals(operationName)) { 3196 DataproviderObject order = this.contracts.createSalesOrder(header, source); 3197 reply = this.createResult( 3198 request, 3199 "org:opencrx:kernel:contract1:QuoteCreateSalesOrderResult" 3200 ); 3201 reply.values("order").add( 3202 order.path() 3203 ); 3204 } 3205 else if("createPosition".equals(operationName)) { 3206 DataproviderObject position = this.contracts.createContractPosition( 3207 header, 3208 source, 3209 param 3210 ); 3211 reply = this.createResult( 3212 request, 3213 "org:opencrx:kernel:contract1:CreatePositionResult" 3214 ); 3215 if(position != null) { 3216 reply.values("position").add(position.path()); 3217 } 3218 } 3219 else if("createProductOfferingPosition".equals(operationName)) { 3220 DataproviderObject position = this.contracts.createProductOfferingPosition( 3221 header, 3222 source.path(), 3223 (Path)param.values("offering").get(0), 3224 (BigDecimal )param.values("quantity").get(0) 3225 ); 3226 reply = this.createResult( 3227 request, 3228 "org:opencrx:kernel:contract1:CreateProductOfferingPositionResult" 3229 ); 3230 reply.values("offeringPosition").add( 3231 position.path() 3232 ); 3233 } 3234 } 3235 else if(this.model.isSubtypeOf(sourceClass, "org:opencrx:kernel:contract1:SalesOrder")) { 3237 if("reprice".equals(operationName)) { 3238 this.contracts.repriceContract( 3239 header, 3240 source 3241 ); 3242 reply = this.createResult( 3243 request, 3244 "org:openmdx:base:Void" 3245 ); 3246 } 3247 else if("createInvoice".equals(operationName)) { 3248 DataproviderObject invoice = this.contracts.createInvoice(header, source); 3249 reply = this.createResult( 3250 request, 3251 "org:opencrx:kernel:contract1:SalesOrderCreateInvoiceResult" 3252 ); 3253 reply.values("invoice").add( 3254 invoice.path() 3255 ); 3256 } 3257 else if("createPosition".equals(operationName)) { 3258 DataproviderObject position = this.contracts.createContractPosition( 3259 header, 3260 source, 3261 param 3262 ); 3263 reply = this.createResult( 3264 request, 3265 "org:opencrx:kernel:contract1:CreatePositionResult" 3266 ); 3267 if(position != null) { 3268 reply.values("position").add(position.path()); 3269 } 3270 } 3271 else if("createProductOfferingPosition".equals(operationName)) { 3272 DataproviderObject position = this.contracts.createProductOfferingPosition( 3273 header, 3274 source.path(), 3275 (Path)param.values("offering").get(0), 3276 (BigDecimal )param.values("quantity").get(0) 3277 ); 3278 reply = this.createResult( 3279 request, 3280 "org:opencrx:kernel:contract1:CreateProductOfferingPositionResult" 3281 ); 3282 reply.values("offeringPosition").add( 3283 position.path() 3284 ); 3285 } 3286 } 3287 else if(this.model.isSubtypeOf(sourceClass, "org:opencrx:kernel:contract1:Invoice")) { 3289 if("reprice".equals(operationName)) { 3290 this.contracts.repriceContract( 3291 header, 3292 source 3293 ); 3294 reply = this.createResult( 3295 request, 3296 "org:openmdx:base:Void" 3297 ); 3298 } 3299 else if("createPosition".equals(operationName)) { 3300 DataproviderObject position = this.contracts.createContractPosition( 3301 header, 3302 source, 3303 param 3304 ); 3305 reply = this.createResult( 3306 request, 3307 "org:opencrx:kernel:contract1:CreatePositionResult" 3308 ); 3309 if(position != null) { 3310 reply.values("position").add(position.path()); 3311 } 3312 } 3313 else if("createProductOfferingPosition".equals(operationName)) { 3314 DataproviderObject position = this.contracts.createProductOfferingPosition( 3315 header, 3316 source.path(), 3317 (Path)param.values("offering").get(0), 3318 (BigDecimal )param.values("quantity").get(0) 3319 ); 3320 reply = this.createResult( 3321 request, 3322 "org:opencrx:kernel:contract1:CreateProductOfferingPositionResult" 3323 ); 3324 reply.values("offeringPosition").add( 3325 position.path() 3326 ); 3327 } 3328 } 3329 else if(this.model.isSubtypeOf(sourceClass, "org:opencrx:kernel:contract1:ContractPosition")) { 3331 if("reprice".equals(operationName)) { 3332 this.contracts.repriceContractPosition( 3333 header, 3334 source 3335 ); 3336 reply = this.createResult( 3337 request, 3338 "org:openmdx:base:Void" 3339 ); 3340 } 3341 } 3342 else if(this.model.isSubtypeOf(sourceClass, "org:opencrx:kernel:account1:Contact")) { 3344 3345 if("exportVCard".equals(operationName)) { 3347 short locale = 3348 ((Short )param.values("locale").get(0)).shortValue(); 3349 reply = this.createResult( 3350 request, 3351 "org:opencrx:kernel:base:ExportResult" 3352 ); 3353 reply.values("item").add( 3354 new VCard( 3355 this, 3356 this.delegation, 3357 this.codes 3358 ).exportItem( 3359 source, 3360 locale 3361 ) 3362 ); 3363 reply.values("itemName").add( 3364 source.values("fullName").size() == 0 3365 ? source.path().getBase() + ".vcf" 3366 : this.toFilename(source.values("fullName").get(0) + ".vcf") 3367 ); 3368 reply.values("itemMimeType").add( 3369 VCard.MIME_TYPE 3370 ); 3371 reply.values("status").add( 3372 new Short (IMPORT_EXPORT_OK) 3373 ); 3374 } 3375 else if("createLead".equals(operationName)) { 3377 DataproviderObject lead = this.accounts.createLead(header, source, param); 3378 reply = this.createResult( 3379 request, 3380 "org:opencrx:kernel:account1:CreateLeadResult" 3381 ); 3382 if(lead != null) { 3383 reply.values("lead").add(lead.path()); 3384 } 3385 } 3386 else if("createOpportunity".equals(operationName)) { 3388 DataproviderObject opportunity = this.accounts.createOpportunity(header, source, param); 3389 reply = this.createResult( 3390 request, 3391 "org:opencrx:kernel:account1:CreateOpportunityResult" 3392 ); 3393 if(opportunity != null) { 3394 reply.values("opportunity").add(opportunity.path()); 3395 } 3396 } 3397 else if("createQuote".equals(operationName)) { 3399 DataproviderObject quote = this.accounts.createQuote(header, source, param); 3400 reply = this.createResult( 3401 request, 3402 "org:opencrx:kernel:account1:CreateQuoteResult" 3403 ); 3404 if(quote != null) { 3405 reply.values("quote").add(quote.path()); 3406 } 3407 } 3408 else if("createSalesOrder".equals(operationName)) { 3410 DataproviderObject salesOrder = this.accounts.createSalesOrder(header, source, param); 3411 reply = this.createResult( 3412 request, 3413 "org:opencrx:kernel:account1:CreateSalesOrderResult" 3414 ); 3415 if(salesOrder != null) { 3416 reply.values("salesOrder").add(salesOrder.path()); 3417 } 3418 } 3419 else if("createInvoice".equals(operationName)) { 3421 DataproviderObject invoice = this.accounts.createInvoice(header, source, param); 3422 reply = this.createResult( 3423 request, 3424 "org:opencrx:kernel:account1:CreateInvoiceResult" 3425 ); 3426 if(invoice != null) { 3427 reply.values("invoice").add(invoice.path()); 3428 } 3429 } 3430 } 3431 else if( 3433 this.model.isSubtypeOf(sourceClass, "org:opencrx:kernel:account1:LegalEntity") || 3434 this.model.isSubtypeOf(sourceClass, "org:opencrx:kernel:account1:Group") || 3435 this.model.isSubtypeOf(sourceClass, "org:opencrx:kernel:account1:UnspecifiedAccount") 3436 ) { 3437 if("createLead".equals(operationName)) { 3439 DataproviderObject lead = this.accounts.createLead(header, source, param); 3440 reply = this.createResult( 3441 request, 3442 "org:opencrx:kernel:account1:CreateLeadResult" 3443 ); 3444 if(lead != null) { 3445 reply.values("lead").add(lead.path()); 3446 } 3447 } 3448 else if("createOpportunity".equals(operationName)) { 3450 DataproviderObject opportunity = this.accounts.createOpportunity(header, source, param); 3451 reply = this.createResult( 3452 request, 3453 "org:opencrx:kernel:account1:CreateOpportunityResult" 3454 ); 3455 if(opportunity != null) { 3456 reply.values("opportunity").add(opportunity.path()); 3457 } 3458 } 3459 else if("createQuote".equals(operationName)) { 3461 DataproviderObject quote = this.accounts.createQuote(header, source, param); 3462 reply = this.createResult( 3463 request, 3464 "org:opencrx:kernel:account1:CreateQuoteResult" 3465 ); 3466 if(quote != null) { 3467 reply.values("quote").add(quote.path()); 3468 } 3469 } 3470 else if("createSalesOrder".equals(operationName)) { 3472 DataproviderObject salesOrder = this.accounts.createSalesOrder(header, source, param); 3473 reply = this.createResult( 3474 request, 3475 "org:opencrx:kernel:account1:CreateSalesOrderResult" 3476 ); 3477 if(salesOrder != null) { 3478 reply.values("salesOrder").add(salesOrder.path()); 3479 } 3480 } 3481 else if("createInvoice".equals(operationName)) { 3483 DataproviderObject invoice = this.accounts.createInvoice(header, source, param); 3484 reply = this.createResult( 3485 request, 3486 "org:opencrx:kernel:account1:CreateInvoiceResult" 3487 ); 3488 if(invoice != null) { 3489 reply.values("invoice").add(invoice.path()); 3490 } 3491 } 3492 } 3493 else if(this.model.isSubtypeOf(sourceClass, "org:opencrx:kernel:activity1:Activity")) { 3495 if("doFollowUp".equals(operationName)) { 3496 this.activities.doFollowUp( 3497 header, 3498 source.path(), 3499 (String )param.values("followUpTitle").get(0), 3500 (String )param.values("followUpText").get(0), 3501 (Path)param.values("transition").get(0) 3502 ); 3503 reply = this.createResult( 3504 request, 3505 "org:openmdx:base:Void" 3506 ); 3507 } 3508 else if("assignTo".equals(operationName)) { 3509 this.activities.assignTo( 3510 header, 3511 source.path(), 3512 (Path)param.values("resource").get(0) 3513 ); 3514 reply = this.createResult( 3515 request, 3516 "org:openmdx:base:Void" 3517 ); 3518 } 3519 else if("exportICalendar".equals(operationName)) { 3521 short locale = 3522 ((Short )param.values("locale").get(0)).shortValue(); 3523 reply = this.createResult( 3524 request, 3525 "org:opencrx:kernel:base:ExportResult" 3526 ); 3527 List statusMessage = new ArrayList (); 3528 byte[] item = new ICalendar( 3529 this, 3530 this.delegation, 3531 this.codes 3532 ).exportItem( 3533 source, 3534 locale, 3535 statusMessage 3536 ); 3537 if((item == null) || (statusMessage.size() > 0)) { 3539 reply.values("status").add( 3540 new Short (IMPORT_EXPORT_MISSING_DATA) 3541 ); 3542 reply.values("statusMessage").add( 3543 statusMessage.toString() 3544 ); 3545 } 3546 else { 3548 reply.values("item").add(item); 3549 reply.values("itemName").add( 3550 source.values("name").size() == 0 3551 ? source.path().getBase() + ".ics" 3552 : this.toFilename(source.values("name").get(0) + ".ics") 3553 ); 3554 reply.values("itemMimeType").add( 3555 ICalendar.MIME_TYPE 3556 ); 3557 reply.values("status").add( 3558 new Short (IMPORT_EXPORT_OK) 3559 ); 3560 } 3561 } 3562 } 3563 else if(this.model.isSubtypeOf(sourceClass, "org:opencrx:kernel:product1:PricingRule")) { 3565 if("getPriceLevel".equals(operationName)) { 3566 this.products.getPriceLevel( 3567 header, 3568 source, 3569 param, 3570 reply = this.createResult( 3571 request, 3572 "org:opencrx:kernel:product1:GetPriceLevelResult" 3573 ) 3574 ); 3575 } 3576 } 3577 else if(this.model.isSubtypeOf(sourceClass, "org:opencrx:kernel:product1:PriceLevel")) { 3579 if("createPricesFromBasedOnPriceLevel".equals(operationName)) { 3580 int numberProcessed = this.products.createPricesFromBasedOnPriceLevel( 3581 header, 3582 source, 3583 param 3584 ); 3585 reply = this.createResult( 3586 request, 3587 "org:opencrx:kernel:product1:ProcessPricesResult" 3588 ); 3589 reply.values("numberProcessed").add( 3590 new Integer (numberProcessed) 3591 ); 3592 } 3593 else if("clearAssignedPrices".equals(operationName)) { 3594 int numberProcessed = this.products.clearAssignedPrices( 3595 header, 3596 source, 3597 param 3598 ); 3599 reply = this.createResult( 3600 request, 3601 "org:opencrx:kernel:product1:ProcessPricesResult" 3602 ); 3603 reply.values("numberProcessed").add( 3604 new Integer (numberProcessed) 3605 ); 3606 } 3607 else if("movePricesFromBasedOnPriceLevel".equals(operationName)) { 3608 int numberProcessed = this.products.movePricesFromBasedOnPriceLevel( 3609 header, 3610 source, 3611 param 3612 ); 3613 reply = this.createResult( 3614 request, 3615 "org:opencrx:kernel:product1:ProcessPricesResult" 3616 ); 3617 reply.values("numberProcessed").add( 3618 new Integer (numberProcessed) 3619 ); 3620 } 3621 else if("createInitialPrices".equals(operationName)) { 3622 int numberProcessed = this.products.createInitialPrices( 3623 header, 3624 source, 3625 param 3626 ); 3627 reply = this.createResult( 3628 request, 3629 "org:opencrx:kernel:product1:ProcessPricesResult" 3630 ); 3631 reply.values("numberProcessed").add( 3632 new Integer (numberProcessed) 3633 ); 3634 } 3635 } 3636 if( 3638 (reply == null) && 3639 "exportXml".equals(operationName) 3640 ) { 3641 reply = this.createResult( 3642 request, 3643 "org:opencrx:kernel:base:ExportResult" 3644 ); 3645 byte[] item = new Xml( 3646 this, 3647 header, 3648 new RequestCollection(header, this), 3651 this.model 3652 ).exportItem( 3653 source, 3654 param 3655 ); 3656 reply.values("status").add( 3657 new Short (IMPORT_EXPORT_OK) 3658 ); 3659 reply.values("item").add(item); 3660 reply.values("itemMimeType").add(MIME_TYPE_ZIP); 3661 reply.values("itemName").add(this.toFilename("export.zip")); 3662 } 3663 if( 3665 (reply == null) && 3666 "importItem".equals(operationName) 3667 ) { 3668 short locale = ((Short )param.values("locale").get(0)).shortValue(); 3669 byte[] item = (byte[])param.values("item").get(0); 3670 String itemMimeType = (String )param.values("itemMimeType").get(0); 3671 if(Xml.MIME_TYPE.equals(itemMimeType)) { 3672 List errors = new ArrayList (); 3673 List report = new ArrayList (); 3674 DataproviderObject importedObject = new Xml( 3675 this, 3676 new RequestCollection(header, this), 3678 this.delegation, 3680 this.model 3681 ).importItem( 3682 item, 3683 locale, 3684 errors, 3685 report 3686 ); 3687 reply = this.createResult( 3688 request, 3689 "org:opencrx:kernel:base:ImportResult" 3690 ); 3691 if((importedObject == null) || (errors.size() > 0)) { 3692 reply.values("status").add( 3693 new Short (IMPORT_EXPORT_ITEM_NOT_VALID) 3694 ); 3695 reply.values("statusMessage").add( 3696 errors.toString() 3697 ); 3698 } 3699 else { 3700 reply.values("importedObject").add( 3701 importedObject.path() 3702 ); 3703 reply.values("status").add( 3704 new Short (IMPORT_EXPORT_OK) 3705 ); 3706 reply.values("statusMessage").add( 3707 this.analyseReport(report) 3708 ); 3709 } 3710 } 3711 else { 3712 reply = this.createResult( 3713 request, 3714 "org:opencrx:kernel:base:ImportResult" 3715 ); 3716 reply.values("status").add( 3717 new Short (IMPORT_EXPORT_FORMAT_NOT_SUPPORTED) 3718 ); 3719 reply.values("statusMessage").add( 3720 "import for mime type " + itemMimeType + " and locale " + locale + " not supported" 3721 ); 3722 } 3723 } 3724 if(reply != null) { 3725 return new DataproviderReply( 3726 reply 3727 ); 3728 } 3729 else { 3730 return super.operation( 3731 header, 3732 request 3733 ); 3734 } 3735 } 3736 3737 public static final String MIME_TYPE_ZIP = "application/zip"; 3741 public static final String MAX_DATE = "99991231T000000.000Z"; 3742 3743 public static final short IMPORT_EXPORT_OK = 0; 3744 public static final short IMPORT_EXPORT_FORMAT_NOT_SUPPORTED = 1; 3745 public static final short IMPORT_EXPORT_ITEM_NOT_VALID = 2; 3746 public static final short IMPORT_EXPORT_MISSING_DATA = 3; 3747 3748 public static final Path PATTERN_ACTIVITY = new Path("xri:@openmdx:org.opencrx.kernel.activity1/provider/:*/segment/:*/activity/:*"); 3749 public static final Path PATTERN_ACTIVITY_WORK_RECORD = new Path("xri:@openmdx:org.opencrx.kernel.activity1/provider/:*/segment/:*/activity/:*/assignedResource/:*/workRecord/:*"); 3750 3751 public static final Path PATTERN_DEPOT_ENTITY = new Path("xri:@openmdx:org.opencrx.kernel.depot1/provider/:*/segment/:*/entity/:*"); 3753 public static final Path PATTERN_DEPOT_HOLDER = new Path("xri:@openmdx:org.opencrx.kernel.depot1/provider/:*/segment/:*/entity/:*/depotHolder/:*"); 3754 public static final Path PATTERN_DEPOT_DEPOT = new Path("xri:@openmdx:org.opencrx.kernel.depot1/provider/:*/segment/:*/entity/:*/depotHolder/:*/depot/:*"); 3755 public static final Path PATTERN_DEPOT_POSITION = new Path("xri:@openmdx:org.opencrx.kernel.depot1/provider/:*/segment/:*/entity/:*/depotHolder/:*/depot/:*/position/:*"); 3756 public static final Path PATTERN_DEPOT_BOOKING = new Path("xri:@openmdx:org.opencrx.kernel.depot1/provider/:*/segment/:*/booking/:*"); 3757 public static final Path PATTERN_DEPOT_COMPOUND_BOOKING = new Path("xri:@openmdx:org.opencrx.kernel.depot1/provider/:*/segment/:*/cb/:*"); 3758 public static final Path PATTERN_CONTRACT_POSITION = new Path("xri:@openmdx:org.opencrx.kernel.contract1/provider/:*/segment/:*/:*/:*/position/:*"); 3759 public static final Path PATTERN_CONTRACT_SELECTABLE_ITEM = new Path("xri:@openmdx:org.opencrx.kernel.contract1/provider/:*/segment/:*/:*/:*/position/:*/selectableItem/:*"); 3760 public static final Path PATTERN_MODEL_EDITABLE_OPERATION = new Path("xri:@openmdx:org.opencrx.kernel.model1/provider/:*/segment/:*/element/:*/operation/:*"); 3761 public static final Path PATTERN_MODEL_EDITABLE_PARAMETER = new Path("xri:@openmdx:org.opencrx.kernel.model1/provider/:*/segment/:*/element/:*/parameter/:*"); 3762 public static final Path PATTERN_MODEL_EDITABLE_ATTRIBUTE = new Path("xri:@openmdx:org.opencrx.kernel.model1/provider/:*/segment/:*/element/:*/attribute/:*"); 3763 public static final Path PATTERN_MODEL_EDITABLE_STRUCTURE_FIELD = new Path("xri:@openmdx:org.opencrx.kernel.model1/provider/:*/segment/:*/element/:*/field/:*"); 3764 public static final Path PATTERN_MODEL_EDITABLE_PACKAGE = new Path("xri:@openmdx:org.opencrx.kernel.model1/provider/:*/segment/:*/element/:*/package/:*"); 3765 public static final Path PATTERN_MODEL_EDITABLE_CLASS = new Path("xri:@openmdx:org.opencrx.kernel.model1/provider/:*/segment/:*/element/:*/class/:*"); 3766 public static final Path PATTERN_MODEL_EDITABLE_STRUCTURE_TYPE = new Path("xri:@openmdx:org.opencrx.kernel.model1/provider/:*/segment/:*/element/:*/structureType/:*"); 3767 public static final Path PATTERN_MODEL_EDITABLE_OPERATION_TAG = new Path("xri:@openmdx:org.opencrx.kernel.model1/provider/:*/segment/:*/element/:*/operationTag/:*"); 3768 public static final Path PATTERN_CODE_SEGMENT = new Path("xri:@openmdx:org.opencrx.kernel.code1/provider/:*/segment/:*"); 3769 public static final Path PATTERN_ACTIVITY_TRACKER = new Path("xri:@openmdx:org.opencrx.kernel.activity1/provider/:*/segment/:*/activityTracker/:*"); 3770 public static final Path PATTERN_ACTIVITY_CATEGORY = new Path("xri:@openmdx:org.opencrx.kernel.activity1/provider/:*/segment/:*/activityCategory/:*"); 3771 public static final Path PATTERN_ACTIVITY_MILESTONE = new Path("xri:@openmdx:org.opencrx.kernel.activity1/provider/:*/segment/:*/activityMilestone/:*"); 3772 public static final Path PATTERN_PRODUCT_PRICE_LEVEL = new Path("xri:@openmdx:org.opencrx.kernel.product1/provider/:*/segment/:*/priceLevel/:*"); 3773 public static final String DEFAULT_REFERENCE_FILTER = ":*, :*/:*/:*, :*/:*/:*/:*/:*"; 3774 3775 protected Codes codes = null; 3777 protected Path codeSegment = null; 3778 protected Model_1_0 model = null; 3779 protected Dataprovider_1_0 router = null; 3780 protected Path loginRealmIdentity = null; 3781 protected List readOnlyObjectTypes = null; 3782 3783 private RequestCollection delegation = null; 3785 private Map modifiedObjects = null; 3786 private List pendingModifications = null; 3787 protected Contracts contracts = null; 3788 protected Cloneable cloneable = null; 3789 protected Depots depots = null; 3790 protected Products products = null; 3791 protected Activities activities = null; 3792 protected Accounts accounts = null; 3793 protected Models models = null; 3794 protected UserHomes userHomes = null; 3795 protected Workflows workflows = null; 3796 protected DerivedReferences derivedReferences = null; 3797 protected RefPackage_1_0 rootPkg = null; 3798 3799 private String passwordEncodingAlgorithm = null; 3801 3802} 3803 3804 3806 | Popular Tags |