1 17 package org.alfresco.repo.rule; 18 19 import java.io.File ; 20 import java.io.Serializable ; 21 import java.util.ArrayList ; 22 import java.util.HashMap ; 23 import java.util.List ; 24 import java.util.Map ; 25 26 import javax.transaction.UserTransaction ; 27 28 import junit.framework.TestCase; 29 30 import org.alfresco.model.ContentModel; 31 import org.alfresco.repo.action.ActionServiceImplTest; 32 import org.alfresco.repo.action.ActionServiceImplTest.AsyncTest; 33 import org.alfresco.repo.action.evaluator.ComparePropertyValueEvaluator; 34 import org.alfresco.repo.action.evaluator.InCategoryEvaluator; 35 import org.alfresco.repo.action.evaluator.NoConditionEvaluator; 36 import org.alfresco.repo.action.executer.AddFeaturesActionExecuter; 37 import org.alfresco.repo.action.executer.CheckInActionExecuter; 38 import org.alfresco.repo.action.executer.CheckOutActionExecuter; 39 import org.alfresco.repo.action.executer.CopyActionExecuter; 40 import org.alfresco.repo.action.executer.ImageTransformActionExecuter; 41 import org.alfresco.repo.action.executer.LinkCategoryActionExecuter; 42 import org.alfresco.repo.action.executer.MailActionExecuter; 43 import org.alfresco.repo.action.executer.MoveActionExecuter; 44 import org.alfresco.repo.action.executer.SimpleWorkflowActionExecuter; 45 import org.alfresco.repo.action.executer.TransformActionExecuter; 46 import org.alfresco.repo.content.MimetypeMap; 47 import org.alfresco.repo.content.transform.AbstractContentTransformerTest; 48 import org.alfresco.repo.content.transform.ContentTransformerRegistry; 49 import org.alfresco.repo.dictionary.DictionaryDAO; 50 import org.alfresco.repo.dictionary.M2Aspect; 51 import org.alfresco.repo.dictionary.M2Model; 52 import org.alfresco.repo.dictionary.M2Property; 53 import org.alfresco.repo.security.authentication.AuthenticationComponent; 54 import org.alfresco.repo.transaction.TransactionUtil; 55 import org.alfresco.service.ServiceRegistry; 56 import org.alfresco.service.cmr.action.Action; 57 import org.alfresco.service.cmr.action.ActionCondition; 58 import org.alfresco.service.cmr.action.ActionService; 59 import org.alfresco.service.cmr.coci.CheckOutCheckInService; 60 import org.alfresco.service.cmr.dictionary.DataTypeDefinition; 61 import org.alfresco.service.cmr.lock.LockService; 62 import org.alfresco.service.cmr.lock.LockStatus; 63 import org.alfresco.service.cmr.repository.ChildAssociationRef; 64 import org.alfresco.service.cmr.repository.ContentData; 65 import org.alfresco.service.cmr.repository.ContentService; 66 import org.alfresco.service.cmr.repository.ContentWriter; 67 import org.alfresco.service.cmr.repository.CopyService; 68 import org.alfresco.service.cmr.repository.NodeRef; 69 import org.alfresco.service.cmr.repository.NodeService; 70 import org.alfresco.service.cmr.repository.StoreRef; 71 import org.alfresco.service.cmr.rule.Rule; 72 import org.alfresco.service.cmr.rule.RuleService; 73 import org.alfresco.service.cmr.rule.RuleServiceException; 74 import org.alfresco.service.cmr.rule.RuleType; 75 import org.alfresco.service.namespace.NamespaceService; 76 import org.alfresco.service.namespace.QName; 77 import org.alfresco.service.namespace.RegexQNamePattern; 78 import org.alfresco.service.transaction.TransactionService; 79 import org.springframework.context.ApplicationContext; 80 import org.springframework.context.support.ClassPathXmlApplicationContext; 81 import org.springframework.util.StopWatch; 82 83 86 public class RuleServiceCoverageTest extends TestCase 87 { 88 90 93 static ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:alfresco/application-context.xml"); 94 95 98 private TransactionService transactionService; 99 private RuleService ruleService; 100 private NodeService nodeService; 101 private StoreRef testStoreRef; 102 private NodeRef rootNodeRef; 103 private NodeRef nodeRef; 104 private CheckOutCheckInService cociService; 105 private LockService lockService; 106 private ContentService contentService; 107 private ServiceRegistry serviceRegistry; 108 private DictionaryDAO dictionaryDAO; 109 private ActionService actionService; 110 private ContentTransformerRegistry transformerRegistry; 111 private CopyService copyService; 112 113 116 private static final String TEST_NAMESPACE = "http://www.alfresco.org/test/rulesystemtest"; 117 private static final QName CAT_PROP_QNAME = QName.createQName(TEST_NAMESPACE, "region"); 118 private QName regionCategorisationQName; 119 private NodeRef catContainer; 120 private NodeRef catRoot; 121 private NodeRef catRBase; 122 private NodeRef catROne; 123 private NodeRef catRTwo; 124 @SuppressWarnings ("unused") 125 private NodeRef catRThree; 126 127 130 private static final String STANDARD_TEXT_CONTENT = "standardTextContent"; 131 132 135 @Override 136 protected void setUp() throws Exception 137 { 138 this.serviceRegistry = (ServiceRegistry)applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY); 140 this.nodeService = serviceRegistry.getNodeService(); 141 this.ruleService = serviceRegistry.getRuleService(); 142 this.cociService = serviceRegistry.getCheckOutCheckInService(); 143 this.lockService = serviceRegistry.getLockService(); 144 this.copyService = serviceRegistry.getCopyService(); 145 this.contentService = serviceRegistry.getContentService(); 146 this.dictionaryDAO = (DictionaryDAO)applicationContext.getBean("dictionaryDAO"); 147 this.actionService = serviceRegistry.getActionService(); 148 this.transactionService = serviceRegistry.getTransactionService(); 149 this.transformerRegistry = (ContentTransformerRegistry)applicationContext.getBean("contentTransformerRegistry"); 150 151 AuthenticationComponent authenticationComponent = (AuthenticationComponent)applicationContext.getBean("authenticationComponent"); 152 authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName()); 153 154 this.testStoreRef = this.nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis()); 155 this.rootNodeRef = this.nodeService.getRootNode(this.testStoreRef); 156 157 this.nodeRef = this.nodeService.createNode( 159 this.rootNodeRef, 160 ContentModel.ASSOC_CHILDREN, 161 ContentModel.ASSOC_CHILDREN, 162 ContentModel.TYPE_CONTAINER).getChildRef(); 163 164 } 168 169 private Rule createRule( 170 String ruleTypeName, 171 String actionName, 172 Map <String , Serializable > actionParams, 173 String conditionName, 174 Map <String , Serializable > conditionParams) 175 { 176 Rule rule = this.ruleService.createRule(ruleTypeName); 177 ActionCondition condition = this.actionService.createActionCondition(conditionName, conditionParams); 178 rule.addActionCondition(condition); 179 Action action = this.actionService.createAction(actionName, actionParams); 180 rule.addAction(action); 181 return rule; 182 } 183 184 187 private void createTestCategories() 188 { 189 M2Model model = M2Model.createModel("test:rulecategory"); 191 model.createNamespace(TEST_NAMESPACE, "test"); 192 model.createImport(NamespaceService.DICTIONARY_MODEL_1_0_URI, "d"); 193 model.createImport(NamespaceService.CONTENT_MODEL_1_0_URI, NamespaceService.CONTENT_MODEL_PREFIX); 194 195 regionCategorisationQName = QName.createQName(TEST_NAMESPACE, "Region"); 197 M2Aspect generalCategorisation = model.createAspect("test:" + regionCategorisationQName.getLocalName()); 198 generalCategorisation.setParentName("cm:" + ContentModel.ASPECT_CLASSIFIABLE.getLocalName()); 199 M2Property genCatProp = generalCategorisation.createProperty("test:region"); 200 genCatProp.setIndexed(true); 201 genCatProp.setIndexedAtomically(true); 202 genCatProp.setMandatory(true); 203 genCatProp.setMultiValued(false); 204 genCatProp.setStoredInIndex(true); 205 genCatProp.setTokenisedInIndex(true); 206 genCatProp.setType("d:" + DataTypeDefinition.CATEGORY.getLocalName()); 207 208 dictionaryDAO.putModel(model); 210 211 catContainer = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(TEST_NAMESPACE, "categoryContainer"), ContentModel.TYPE_CONTAINER).getChildRef(); 213 catRoot = nodeService.createNode(catContainer, ContentModel.ASSOC_CHILDREN, QName.createQName(TEST_NAMESPACE, "categoryRoot"), ContentModel.TYPE_CATEGORYROOT).getChildRef(); 214 215 catRBase = nodeService.createNode(catRoot, ContentModel.ASSOC_CATEGORIES, QName.createQName(TEST_NAMESPACE, "Region"), ContentModel.TYPE_CATEGORY).getChildRef(); 217 catROne = nodeService.createNode(catRBase, ContentModel.ASSOC_SUBCATEGORIES, QName.createQName(TEST_NAMESPACE, "Europe"), ContentModel.TYPE_CATEGORY).getChildRef(); 218 catRTwo = nodeService.createNode(catRBase, ContentModel.ASSOC_SUBCATEGORIES, QName.createQName(TEST_NAMESPACE, "RestOfWorld"), ContentModel.TYPE_CATEGORY).getChildRef(); 219 catRThree = nodeService.createNode(catRTwo, ContentModel.ASSOC_SUBCATEGORIES, QName.createQName(TEST_NAMESPACE, "US"), ContentModel.TYPE_CATEGORY).getChildRef(); 220 } 221 222 225 226 229 public void testAsyncRuleExecution() 230 { 231 final NodeRef newNodeRef = TransactionUtil.executeInUserTransaction( 232 this.transactionService, 233 new TransactionUtil.TransactionWork<NodeRef>() 234 { 235 public NodeRef doWork() 236 { 237 RuleServiceCoverageTest.this.nodeService.addAspect( 238 RuleServiceCoverageTest.this.nodeRef, 239 ContentModel.ASPECT_LOCKABLE, 240 null); 241 242 Map <String , Serializable > params = new HashMap <String , Serializable >(1); 243 params.put("aspect-name", ContentModel.ASPECT_VERSIONABLE); 244 245 Rule rule = createRule( 246 RuleType.INBOUND, 247 AddFeaturesActionExecuter.NAME, 248 params, 249 NoConditionEvaluator.NAME, 250 null); 251 rule.setExecuteAsynchronously(true); 252 253 RuleServiceCoverageTest.this.ruleService.saveRule(RuleServiceCoverageTest.this.nodeRef, rule); 254 255 NodeRef newNodeRef = RuleServiceCoverageTest.this.nodeService.createNode( 256 RuleServiceCoverageTest.this.nodeRef, 257 ContentModel.ASSOC_CHILDREN, 258 QName.createQName(TEST_NAMESPACE, "children"), 259 ContentModel.TYPE_CONTENT, 260 getContentProperties()).getChildRef(); 261 addContentToNode(newNodeRef); 262 263 return newNodeRef; 264 } 265 }); 266 267 ActionServiceImplTest.postAsyncActionTest( 268 this.transactionService, 269 1000, 270 10, 271 new AsyncTest() 272 { 273 public boolean executeTest() 274 { 275 return RuleServiceCoverageTest.this.nodeService.hasAspect( 276 newNodeRef, 277 ContentModel.ASPECT_VERSIONABLE); 278 }; 279 }); 280 } 281 282 284 287 288 295 public void testAddFeaturesAction() 296 { 297 this.nodeService.addAspect(this.nodeRef, ContentModel.ASPECT_LOCKABLE, null); 298 299 Map <String , Serializable > params = new HashMap <String , Serializable >(1); 300 params.put("aspect-name", ContentModel.ASPECT_VERSIONABLE); 301 302 Rule rule = createRule( 303 RuleType.INBOUND, 304 AddFeaturesActionExecuter.NAME, 305 params, 306 NoConditionEvaluator.NAME, 307 null); 308 309 this.ruleService.saveRule(this.nodeRef, rule); 310 311 NodeRef newNodeRef = this.nodeService.createNode( 312 this.nodeRef, 313 ContentModel.ASSOC_CHILDREN, 314 QName.createQName(TEST_NAMESPACE, "children"), 315 ContentModel.TYPE_CONTENT, 316 getContentProperties()).getChildRef(); 317 addContentToNode(newNodeRef); 318 assertTrue(this.nodeService.hasAspect(newNodeRef, ContentModel.ASPECT_VERSIONABLE)); 319 320 Map <String , Serializable > params2 = new HashMap <String , Serializable >(2); 321 params2.put(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_SIMPLE_WORKFLOW); 322 params2.put(ContentModel.PROP_APPROVE_STEP.toString(), "approveStep"); 323 params2.put(ContentModel.PROP_APPROVE_MOVE.toString(), false); 324 325 rule.removeAllActions(); 327 Action action2 = this.actionService.createAction(AddFeaturesActionExecuter.NAME, params2); 328 rule.addAction(action2); 329 this.ruleService.saveRule(this.nodeRef, rule); 330 331 NodeRef newNodeRef2 = this.nodeService.createNode( 332 this.nodeRef, 333 ContentModel.ASSOC_CHILDREN, 334 QName.createQName(TEST_NAMESPACE, "children"), 335 ContentModel.TYPE_CONTENT, 336 getContentProperties()).getChildRef(); 337 addContentToNode(newNodeRef2); 338 assertTrue(this.nodeService.hasAspect(newNodeRef2, ContentModel.ASPECT_SIMPLE_WORKFLOW)); 339 assertEquals("approveStep", this.nodeService.getProperty(newNodeRef2, ContentModel.PROP_APPROVE_STEP)); 340 assertEquals(false, this.nodeService.getProperty(newNodeRef2, ContentModel.PROP_APPROVE_MOVE)); 341 342 } 344 345 public void testDisableRule() 346 { 347 this.nodeService.addAspect(this.nodeRef, ContentModel.ASPECT_LOCKABLE, null); 348 349 Map <String , Serializable > params = new HashMap <String , Serializable >(1); 350 params.put("aspect-name", ContentModel.ASPECT_VERSIONABLE); 351 352 Rule rule = createRule( 353 RuleType.INBOUND, 354 AddFeaturesActionExecuter.NAME, 355 params, 356 NoConditionEvaluator.NAME, 357 null); 358 359 this.ruleService.saveRule(this.nodeRef, rule); 360 this.ruleService.disableRule(rule); 361 362 NodeRef newNodeRef = this.nodeService.createNode( 363 this.nodeRef, 364 ContentModel.ASSOC_CHILDREN, 365 QName.createQName(TEST_NAMESPACE, "children"), 366 ContentModel.TYPE_CONTENT, 367 getContentProperties()).getChildRef(); 368 addContentToNode(newNodeRef); 369 assertFalse(this.nodeService.hasAspect(newNodeRef, ContentModel.ASPECT_VERSIONABLE)); 370 371 this.ruleService.enableRule(rule); 372 373 NodeRef newNodeRef2 = this.nodeService.createNode( 374 this.nodeRef, 375 ContentModel.ASSOC_CHILDREN, 376 QName.createQName(TEST_NAMESPACE, "children"), 377 ContentModel.TYPE_CONTENT, 378 getContentProperties()).getChildRef(); 379 addContentToNode(newNodeRef2); 380 assertTrue(this.nodeService.hasAspect(newNodeRef2, ContentModel.ASPECT_VERSIONABLE)); 381 382 } 383 384 public void testAddFeaturesToAFolder() 385 { 386 Map <String , Serializable > params = new HashMap <String , Serializable >(1); 387 params.put("aspect-name", ContentModel.ASPECT_TEMPLATABLE); 388 389 Rule rule = createRule( 390 RuleType.INBOUND, 391 AddFeaturesActionExecuter.NAME, 392 params, 393 NoConditionEvaluator.NAME, 394 null); 395 396 this.ruleService.saveRule(this.nodeRef, rule); 397 398 NodeRef newNodeRef = this.nodeService.createNode( 399 this.nodeRef, 400 ContentModel.ASSOC_CHILDREN, 401 QName.createQName(TEST_NAMESPACE, "children"), 402 ContentModel.TYPE_FOLDER).getChildRef(); 403 404 assertTrue(this.nodeService.hasAspect(newNodeRef, ContentModel.ASPECT_TEMPLATABLE)); 405 406 } 408 409 public void testCopyFolderToTriggerRules() 410 { 411 NodeRef copyToFolder = this.nodeService.createNode( 413 this.rootNodeRef, 414 ContentModel.ASSOC_CHILDREN, 415 QName.createQName("{test}copyToFolder"), 416 ContentModel.TYPE_FOLDER).getChildRef(); 417 NodeRef folderToCopy = this.nodeService.createNode( 418 this.rootNodeRef, 419 ContentModel.ASSOC_CHILDREN, 420 QName.createQName("{test}folderToCopy"), 421 ContentModel.TYPE_FOLDER).getChildRef(); 422 NodeRef contentToCopy = this.nodeService.createNode( 423 folderToCopy, 424 ContentModel.ASSOC_CONTAINS, 425 QName.createQName("{test}contentToCopy"), 426 ContentModel.TYPE_CONTENT, 427 getContentProperties()).getChildRef(); 428 addContentToNode(contentToCopy); 429 430 Map <String , Serializable > params = new HashMap <String , Serializable >(1); 432 params.put("aspect-name", ContentModel.ASPECT_TEMPLATABLE); 433 Rule rule = createRule( 434 RuleType.INBOUND, 435 AddFeaturesActionExecuter.NAME, 436 params, 437 NoConditionEvaluator.NAME, 438 null); 439 rule.applyToChildren(true); 440 this.ruleService.saveRule(copyToFolder, rule); 441 442 NodeRef copiedFolder = this.copyService.copy(folderToCopy, copyToFolder, ContentModel.ASSOC_CONTAINS, QName.createQName("{test}coppiedFolder"), true); 444 assertNotNull(copiedFolder); 445 446 assertTrue(this.nodeService.hasAspect(copiedFolder, ContentModel.ASPECT_TEMPLATABLE)); 448 for (ChildAssociationRef childAssoc : this.nodeService.getChildAssocs(copiedFolder)) 449 { 450 assertTrue(this.nodeService.hasAspect(childAssoc.getChildRef(), ContentModel.ASPECT_TEMPLATABLE)); 451 } 452 453 } 455 456 private Map <QName, Serializable > getContentProperties() 457 { 458 return null; 461 } 462 463 469 public void testSimpleWorkflowAction() 470 { 471 this.nodeService.addAspect(this.nodeRef, ContentModel.ASPECT_LOCKABLE, null); 472 473 Map <String , Serializable > params = new HashMap <String , Serializable >(1); 474 params.put(SimpleWorkflowActionExecuter.PARAM_APPROVE_STEP, "approveStep"); 475 params.put(SimpleWorkflowActionExecuter.PARAM_APPROVE_FOLDER, this.rootNodeRef); 476 params.put(SimpleWorkflowActionExecuter.PARAM_APPROVE_MOVE, true); 477 params.put(SimpleWorkflowActionExecuter.PARAM_REJECT_STEP, "rejectStep"); 478 params.put(SimpleWorkflowActionExecuter.PARAM_REJECT_FOLDER, this.rootNodeRef); 479 params.put(SimpleWorkflowActionExecuter.PARAM_REJECT_MOVE, false); 480 481 Rule rule = createRule( 482 RuleType.INBOUND, 483 SimpleWorkflowActionExecuter.NAME, 484 params, 485 NoConditionEvaluator.NAME, 486 null); 487 488 this.ruleService.saveRule(this.nodeRef, rule); 489 490 NodeRef newNodeRef = this.nodeService.createNode( 491 this.nodeRef, 492 ContentModel.ASSOC_CHILDREN, 493 QName.createQName(TEST_NAMESPACE, "children"), 494 ContentModel.TYPE_CONTENT, 495 getContentProperties()).getChildRef(); 496 addContentToNode(newNodeRef); 497 498 assertTrue(this.nodeService.hasAspect(newNodeRef, ContentModel.ASPECT_SIMPLE_WORKFLOW)); 499 assertEquals("approveStep", this.nodeService.getProperty(newNodeRef, ContentModel.PROP_APPROVE_STEP)); 500 assertEquals(this.rootNodeRef, this.nodeService.getProperty(newNodeRef, ContentModel.PROP_APPROVE_FOLDER)); 501 assertTrue(((Boolean )this.nodeService.getProperty(newNodeRef, ContentModel.PROP_APPROVE_MOVE)).booleanValue()); 502 assertTrue(this.nodeService.hasAspect(newNodeRef, ContentModel.ASPECT_SIMPLE_WORKFLOW)); 503 assertEquals("rejectStep", this.nodeService.getProperty(newNodeRef, ContentModel.PROP_REJECT_STEP)); 504 assertEquals(this.rootNodeRef, this.nodeService.getProperty(newNodeRef, ContentModel.PROP_REJECT_FOLDER)); 505 assertFalse(((Boolean )this.nodeService.getProperty(newNodeRef, ContentModel.PROP_REJECT_MOVE)).booleanValue()); 506 507 } 509 510 516 public void testInCategoryCondition() 517 { 518 createTestCategories(); 520 521 try 522 { 523 Map <String , Serializable > params = new HashMap <String , Serializable >(1); 524 params.put(InCategoryEvaluator.PARAM_CATEGORY_ASPECT, this.regionCategorisationQName); 525 params.put(InCategoryEvaluator.PARAM_CATEGORY_VALUE, this.catROne); 526 527 Map <String , Serializable > params2 = new HashMap <String , Serializable >(1); 528 params2.put("aspect-name", ContentModel.ASPECT_VERSIONABLE); 529 530 Rule rule = createRule( 531 RuleType.INBOUND, 532 AddFeaturesActionExecuter.NAME, 533 params2, 534 InCategoryEvaluator.NAME, 535 params); 536 537 this.ruleService.saveRule(this.nodeRef, rule); 538 539 NodeRef newNodeRef2 = this.nodeService.createNode( 541 this.nodeRef, 542 ContentModel.ASSOC_CHILDREN, 543 QName.createQName(TEST_NAMESPACE, "noAspect"), 544 ContentModel.TYPE_CONTENT, 545 getContentProperties()).getChildRef(); 546 addContentToNode(newNodeRef2); 547 assertFalse(this.nodeService.hasAspect(newNodeRef2, ContentModel.ASPECT_VERSIONABLE)); 548 549 UserTransaction tx = transactionService.getUserTransaction(); 551 tx.begin(); 552 NodeRef newNodeRef = this.nodeService.createNode( 553 this.nodeRef, 554 ContentModel.ASSOC_CHILDREN, 555 QName.createQName(TEST_NAMESPACE, "hasAspectAndValue"), 556 ContentModel.TYPE_CONTENT, 557 getContentProperties()).getChildRef(); 558 addContentToNode(newNodeRef); 559 Map <QName, Serializable > catProps = new HashMap <QName, Serializable >(); 560 catProps.put(CAT_PROP_QNAME, this.catROne); 561 this.nodeService.addAspect(newNodeRef, this.regionCategorisationQName, catProps); 562 tx.commit(); 563 assertTrue(this.nodeService.hasAspect(newNodeRef, ContentModel.ASPECT_VERSIONABLE)); 564 565 UserTransaction tx3 = transactionService.getUserTransaction(); 567 tx3.begin(); 568 NodeRef newNodeRef3 = this.nodeService.createNode( 569 this.nodeRef, 570 ContentModel.ASSOC_CHILDREN, 571 QName.createQName(TEST_NAMESPACE, "hasAspectAndValue"), 572 ContentModel.TYPE_CONTENT, 573 getContentProperties()).getChildRef(); 574 addContentToNode(newNodeRef3); 575 Map <QName, Serializable > catProps3 = new HashMap <QName, Serializable >(); 576 catProps3.put(CAT_PROP_QNAME, this.catRTwo); 577 this.nodeService.addAspect(newNodeRef3, this.regionCategorisationQName, catProps3); 578 tx3.commit(); 579 assertFalse(this.nodeService.hasAspect(newNodeRef3, ContentModel.ASPECT_VERSIONABLE)); 580 581 } 583 catch (Exception exception) 584 { 585 throw new RuntimeException (exception); 586 } 587 } 588 589 595 public void testLinkCategoryAction() 596 { 597 createTestCategories(); 599 600 Map <String , Serializable > params = new HashMap <String , Serializable >(1); 601 params.put(LinkCategoryActionExecuter.PARAM_CATEGORY_ASPECT, this.regionCategorisationQName); 602 params.put(LinkCategoryActionExecuter.PARAM_CATEGORY_VALUE, this.catROne); 603 604 Rule rule = createRule( 605 RuleType.INBOUND, 606 LinkCategoryActionExecuter.NAME, 607 params, 608 NoConditionEvaluator.NAME, 609 null); 610 611 this.ruleService.saveRule(this.nodeRef, rule); 612 613 NodeRef newNodeRef2 = this.nodeService.createNode( 614 this.nodeRef, 615 ContentModel.ASSOC_CHILDREN, 616 QName.createQName(TEST_NAMESPACE, "noAspect"), 617 ContentModel.TYPE_CONTENT, 618 getContentProperties()).getChildRef(); 619 addContentToNode(newNodeRef2); 620 621 NodeRef setValue = (NodeRef)this.nodeService.getProperty(newNodeRef2, CAT_PROP_QNAME); 623 assertNotNull(setValue); 624 assertEquals(this.catROne, setValue); 625 } 626 627 628 636 public void xtestMailAction() 637 { 638 this.nodeService.addAspect(this.nodeRef, ContentModel.ASPECT_LOCKABLE, null); 639 640 Map <String , Serializable > params = new HashMap <String , Serializable >(1); 641 params.put(MailActionExecuter.PARAM_TO, "alfresco.test@gmail.com"); 642 params.put(MailActionExecuter.PARAM_SUBJECT, "Unit test"); 643 params.put(MailActionExecuter.PARAM_TEXT, "This is a test to check that the mail action is working."); 644 645 Rule rule = createRule( 646 RuleType.INBOUND, 647 MailActionExecuter.NAME, 648 params, 649 NoConditionEvaluator.NAME, 650 null); 651 652 this.ruleService.saveRule(this.nodeRef, rule); 653 654 this.nodeService.createNode( 655 this.nodeRef, 656 ContentModel.ASSOC_CHILDREN, 657 QName.createQName(TEST_NAMESPACE, "children"), 658 ContentModel.TYPE_CONTENT, 659 getContentProperties()).getChildRef(); 660 661 663 } 665 666 672 public void testCopyAction() 673 { 674 Map <String , Serializable > params = new HashMap <String , Serializable >(1); 675 params.put(MoveActionExecuter.PARAM_DESTINATION_FOLDER, this.rootNodeRef); 676 params.put(MoveActionExecuter.PARAM_ASSOC_TYPE_QNAME, ContentModel.ASSOC_CHILDREN); 677 params.put(MoveActionExecuter.PARAM_ASSOC_QNAME, QName.createQName(TEST_NAMESPACE, "copy")); 678 679 Rule rule = createRule( 680 RuleType.INBOUND, 681 CopyActionExecuter.NAME, 682 params, 683 NoConditionEvaluator.NAME, 684 null); 685 686 this.ruleService.saveRule(this.nodeRef, rule); 687 688 NodeRef newNodeRef = this.nodeService.createNode( 689 this.nodeRef, 690 ContentModel.ASSOC_CHILDREN, 691 QName.createQName(TEST_NAMESPACE, "origional"), 692 ContentModel.TYPE_CONTENT, 693 getContentProperties()).getChildRef(); 694 addContentToNode(newNodeRef); 695 696 698 List <ChildAssociationRef> origRefs = this.nodeService.getChildAssocs( 700 this.nodeRef, 701 RegexQNamePattern.MATCH_ALL, 702 QName.createQName(TEST_NAMESPACE, "origional")); 703 assertNotNull(origRefs); 704 assertEquals(1, origRefs.size()); 705 NodeRef origNodeRef = origRefs.get(0).getChildRef(); 706 assertEquals(newNodeRef, origNodeRef); 707 708 List <ChildAssociationRef> copyChildAssocRefs = this.nodeService.getChildAssocs( 710 this.rootNodeRef, 711 RegexQNamePattern.MATCH_ALL, QName.createQName(TEST_NAMESPACE, "copy")); 712 assertNotNull(copyChildAssocRefs); 713 714 assertEquals(1, copyChildAssocRefs.size()); 718 719 NodeRef copyNodeRef = copyChildAssocRefs.get(0).getChildRef(); 720 assertTrue(this.nodeService.hasAspect(copyNodeRef, ContentModel.ASPECT_COPIEDFROM)); 721 NodeRef source = (NodeRef)this.nodeService.getProperty(copyNodeRef, ContentModel.PROP_COPY_REFERENCE); 722 assertEquals(newNodeRef, source); 723 724 } 726 727 733 public void testTransformAction() 734 { 735 if (this.transformerRegistry.getTransformer(MimetypeMap.MIMETYPE_EXCEL, MimetypeMap.MIMETYPE_TEXT_PLAIN) != null) 736 { 737 try 738 { 739 Map <String , Serializable > params = new HashMap <String , Serializable >(1); 740 params.put(TransformActionExecuter.PARAM_MIME_TYPE, MimetypeMap.MIMETYPE_TEXT_PLAIN); 741 params.put(TransformActionExecuter.PARAM_DESTINATION_FOLDER, this.rootNodeRef); 742 params.put(TransformActionExecuter.PARAM_ASSOC_TYPE_QNAME, ContentModel.ASSOC_CHILDREN); 743 params.put(TransformActionExecuter.PARAM_ASSOC_QNAME, QName.createQName(TEST_NAMESPACE, "transformed")); 744 745 Rule rule = createRule( 746 RuleType.INBOUND, 747 TransformActionExecuter.NAME, 748 params, 749 NoConditionEvaluator.NAME, 750 null); 751 752 this.ruleService.saveRule(this.nodeRef, rule); 753 754 UserTransaction tx = transactionService.getUserTransaction(); 755 tx.begin(); 756 757 Map <QName, Serializable > props =new HashMap <QName, Serializable >(1); 758 props.put(ContentModel.PROP_NAME, "test.xls"); 759 760 NodeRef newNodeRef = this.nodeService.createNode( 762 this.nodeRef, 763 ContentModel.ASSOC_CHILDREN, 764 QName.createQName(TEST_NAMESPACE, "origional"), 765 ContentModel.TYPE_CONTENT, 766 props).getChildRef(); 767 768 ContentWriter contentWriter = this.contentService.getWriter(newNodeRef, ContentModel.PROP_CONTENT, true); 770 contentWriter.setMimetype(MimetypeMap.MIMETYPE_EXCEL); 771 File testFile = AbstractContentTransformerTest.loadQuickTestFile("xls"); 772 contentWriter.putContent(testFile); 773 774 tx.commit(); 775 776 778 AuthenticationComponent authenticationComponent = (AuthenticationComponent)applicationContext.getBean("authenticationComponent"); 779 authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName()); 780 781 List <ChildAssociationRef> origRefs = this.nodeService.getChildAssocs( 783 this.nodeRef, 784 RegexQNamePattern.MATCH_ALL, QName.createQName(TEST_NAMESPACE, "origional")); 785 assertNotNull(origRefs); 786 assertEquals(1, origRefs.size()); 787 NodeRef origNodeRef = origRefs.get(0).getChildRef(); 788 assertEquals(newNodeRef, origNodeRef); 789 790 List <ChildAssociationRef> copyChildAssocRefs = this.nodeService.getChildAssocs( 792 this.rootNodeRef, 793 RegexQNamePattern.MATCH_ALL, QName.createQName(TEST_NAMESPACE, "transformed")); 794 assertNotNull(copyChildAssocRefs); 795 assertEquals(1, copyChildAssocRefs.size()); 796 NodeRef copyNodeRef = copyChildAssocRefs.get(0).getChildRef(); 797 assertTrue(this.nodeService.hasAspect(copyNodeRef, ContentModel.ASPECT_COPIEDFROM)); 798 NodeRef source = (NodeRef)this.nodeService.getProperty(copyNodeRef, ContentModel.PROP_COPY_REFERENCE); 799 assertEquals(newNodeRef, source); 800 801 ContentData contentData = (ContentData) nodeService.getProperty(copyNodeRef, ContentModel.PROP_CONTENT); 803 assertEquals(MimetypeMap.MIMETYPE_TEXT_PLAIN, contentData.getMimetype()); 804 805 } 806 catch (Exception exception) 807 { 808 throw new RuntimeException (exception); 809 } 810 } 811 } 812 813 817 public void testImageTransformAction() 818 { 819 if (this.transformerRegistry.getTransformer(MimetypeMap.MIMETYPE_IMAGE_GIF, MimetypeMap.MIMETYPE_IMAGE_JPEG) != null) 820 { 821 try 822 { 823 Map <String , Serializable > params = new HashMap <String , Serializable >(1); 824 params.put(ImageTransformActionExecuter.PARAM_DESTINATION_FOLDER, this.rootNodeRef); 825 params.put(ImageTransformActionExecuter.PARAM_ASSOC_TYPE_QNAME, ContentModel.ASSOC_CHILDREN); 826 params.put(TransformActionExecuter.PARAM_MIME_TYPE, MimetypeMap.MIMETYPE_IMAGE_JPEG); 827 params.put(ImageTransformActionExecuter.PARAM_ASSOC_QNAME, QName.createQName(TEST_NAMESPACE, "transformed")); 828 params.put(ImageTransformActionExecuter.PARAM_CONVERT_COMMAND, "-negate"); 829 830 Rule rule = createRule( 831 RuleType.INBOUND, 832 ImageTransformActionExecuter.NAME, 833 params, 834 NoConditionEvaluator.NAME, 835 null); 836 837 this.ruleService.saveRule(this.nodeRef, rule); 838 839 UserTransaction tx = transactionService.getUserTransaction(); 840 tx.begin(); 841 842 Map <QName, Serializable > props =new HashMap <QName, Serializable >(1); 843 props.put(ContentModel.PROP_NAME, "test.gif"); 844 845 NodeRef newNodeRef = this.nodeService.createNode( 847 this.nodeRef, 848 ContentModel.ASSOC_CHILDREN, 849 QName.createQName(TEST_NAMESPACE, "origional"), 850 ContentModel.TYPE_CONTENT, 851 props).getChildRef(); 852 853 ContentWriter contentWriter = this.contentService.getWriter(newNodeRef, ContentModel.PROP_CONTENT, true); 855 contentWriter.setMimetype(MimetypeMap.MIMETYPE_IMAGE_GIF); 856 File testFile = AbstractContentTransformerTest.loadQuickTestFile("gif"); 857 contentWriter.putContent(testFile); 858 859 tx.commit(); 860 861 863 List <ChildAssociationRef> origRefs = this.nodeService.getChildAssocs( 865 this.nodeRef, 866 RegexQNamePattern.MATCH_ALL, QName.createQName(TEST_NAMESPACE, "origional")); 867 assertNotNull(origRefs); 868 assertEquals(1, origRefs.size()); 869 NodeRef origNodeRef = origRefs.get(0).getChildRef(); 870 assertEquals(newNodeRef, origNodeRef); 871 872 List <ChildAssociationRef> copyChildAssocRefs = this.nodeService.getChildAssocs( 874 this.rootNodeRef, 875 RegexQNamePattern.MATCH_ALL, QName.createQName(TEST_NAMESPACE, "transformed")); 876 assertNotNull(copyChildAssocRefs); 877 assertEquals(1, copyChildAssocRefs.size()); 878 NodeRef copyNodeRef = copyChildAssocRefs.get(0).getChildRef(); 879 assertTrue(this.nodeService.hasAspect(copyNodeRef, ContentModel.ASPECT_COPIEDFROM)); 880 NodeRef source = (NodeRef)this.nodeService.getProperty(copyNodeRef, ContentModel.PROP_COPY_REFERENCE); 881 assertEquals(newNodeRef, source); 882 } 883 catch (Exception exception) 884 { 885 throw new RuntimeException (exception); 886 } 887 } 888 } 889 890 896 public void testMoveAction() 897 { 898 Map <String , Serializable > params = new HashMap <String , Serializable >(1); 899 params.put(MoveActionExecuter.PARAM_DESTINATION_FOLDER, this.rootNodeRef); 900 params.put(MoveActionExecuter.PARAM_ASSOC_TYPE_QNAME, ContentModel.ASSOC_CHILDREN); 901 params.put(MoveActionExecuter.PARAM_ASSOC_QNAME, QName.createQName(TEST_NAMESPACE, "copy")); 902 903 Rule rule = createRule( 904 RuleType.INBOUND, 905 MoveActionExecuter.NAME, 906 params, 907 NoConditionEvaluator.NAME, 908 null); 909 910 this.ruleService.saveRule(this.nodeRef, rule); 911 912 NodeRef newNodeRef = this.nodeService.createNode( 913 this.nodeRef, 914 ContentModel.ASSOC_CHILDREN, 915 QName.createQName(TEST_NAMESPACE, "origional"), 916 ContentModel.TYPE_CONTENT, 917 getContentProperties()).getChildRef(); 918 addContentToNode(newNodeRef); 919 920 922 List <ChildAssociationRef> origRefs = this.nodeService.getChildAssocs( 924 this.nodeRef, 925 RegexQNamePattern.MATCH_ALL, QName.createQName(TEST_NAMESPACE, "origional")); 926 assertNotNull(origRefs); 927 assertEquals(0, origRefs.size()); 928 929 List <ChildAssociationRef> copyChildAssocRefs = this.nodeService.getChildAssocs( 931 this.rootNodeRef, 932 RegexQNamePattern.MATCH_ALL, QName.createQName(TEST_NAMESPACE, "copy")); 933 assertNotNull(copyChildAssocRefs); 934 assertEquals(1, copyChildAssocRefs.size()); 935 NodeRef movedNodeRef = copyChildAssocRefs.get(0).getChildRef(); 936 assertEquals(newNodeRef, movedNodeRef); 937 } 938 939 945 public void testCheckOutAction() 946 { 947 Rule rule = createRule( 948 RuleType.INBOUND, 949 CheckOutActionExecuter.NAME, 950 null, 951 NoConditionEvaluator.NAME, 952 null); 953 954 this.ruleService.saveRule(this.nodeRef, rule); 955 956 NodeRef newNodeRef = null; 957 UserTransaction tx = this.transactionService.getUserTransaction(); 958 try 959 { 960 tx.begin(); 961 962 newNodeRef = this.nodeService.createNode( 964 this.nodeRef, 965 ContentModel.ASSOC_CHILDREN, 966 QName.createQName(TEST_NAMESPACE, "checkout"), 967 ContentModel.TYPE_CONTENT, 968 getContentProperties()).getChildRef(); 969 addContentToNode(newNodeRef); 970 971 tx.commit(); 972 } 973 catch (Exception exception) 974 { 975 throw new RuntimeException (exception); 976 } 977 978 980 List <ChildAssociationRef> children = this.nodeService.getChildAssocs(this.nodeRef); 982 assertNotNull(children); 983 assertEquals(3, children.size()); for (ChildAssociationRef child : children) 985 { 986 NodeRef childNodeRef = child.getChildRef(); 987 if (childNodeRef.equals(newNodeRef) == true) 988 { 989 LockStatus lockStatus = this.lockService.getLockStatus(childNodeRef); 991 assertEquals(LockStatus.LOCK_OWNER, lockStatus); 992 } 993 else if (this.nodeService.hasAspect(childNodeRef, ContentModel.ASPECT_WORKING_COPY) == true) 994 { 995 NodeRef copiedFromNodeRef = (NodeRef)this.nodeService.getProperty(childNodeRef, ContentModel.PROP_COPY_REFERENCE); 997 assertEquals(newNodeRef, copiedFromNodeRef); 998 } 999 } 1000 } 1001 1002 1008 @SuppressWarnings ("unchecked") 1009 public void testCheckInAction() 1010 { 1011 Map <String , Serializable > params = new HashMap <String , Serializable >(1); 1012 params.put(CheckInActionExecuter.PARAM_DESCRIPTION, "The version description."); 1013 1014 Rule rule = createRule( 1015 RuleType.INBOUND, 1016 CheckInActionExecuter.NAME, 1017 params, 1018 NoConditionEvaluator.NAME, 1019 null); 1020 1021 this.ruleService.saveRule(this.nodeRef, rule); 1022 1023 List <NodeRef> list = TransactionUtil.executeInUserTransaction( 1024 this.transactionService, 1025 new TransactionUtil.TransactionWork<List <NodeRef>>() 1026 { 1027 public List <NodeRef> doWork() 1028 { 1029 NodeRef newNodeRef = RuleServiceCoverageTest.this.nodeService.createNode( 1031 RuleServiceCoverageTest.this.rootNodeRef, 1032 ContentModel.ASSOC_CHILDREN, 1033 QName.createQName(TEST_NAMESPACE, "origional"), 1034 ContentModel.TYPE_CONTENT, 1035 getContentProperties()).getChildRef(); 1036 NodeRef workingCopy = RuleServiceCoverageTest.this.cociService.checkout(newNodeRef); 1037 1038 RuleServiceCoverageTest.this.nodeService.moveNode( 1040 workingCopy, 1041 RuleServiceCoverageTest.this.nodeRef, 1042 ContentModel.ASSOC_CHILDREN, 1043 QName.createQName(TEST_NAMESPACE, "moved")); 1044 1045 List <NodeRef> result = new ArrayList <NodeRef>(); 1046 result.add(newNodeRef); 1047 result.add(workingCopy); 1048 return result; 1049 } 1050 1051 }); 1052 1053 assertFalse(this.nodeService.exists(list.get(1))); 1055 1056 assertEquals(LockStatus.NO_LOCK, this.lockService.getLockStatus(list.get(0))); 1058 1059 } 1061 1062 1065 public void testRulesDisabled() 1066 { 1067 Map <String , Serializable > actionParams = new HashMap <String , Serializable >(1); 1068 actionParams.put("aspect-name", ContentModel.ASPECT_VERSIONABLE); 1069 1070 Rule rule = createRule( 1071 RuleType.INBOUND, 1072 AddFeaturesActionExecuter.NAME, 1073 actionParams, 1074 NoConditionEvaluator.NAME, 1075 null); 1076 1077 this.ruleService.saveRule(this.nodeRef, rule); 1078 this.ruleService.disableRules(this.nodeRef); 1079 1080 NodeRef newNodeRef = this.nodeService.createNode( 1081 this.nodeRef, 1082 ContentModel.ASSOC_CHILDREN, 1083 QName.createQName(TEST_NAMESPACE, "children"), 1084 ContentModel.TYPE_CONTENT, 1085 getContentProperties()).getChildRef(); 1086 addContentToNode(newNodeRef); 1087 assertFalse(this.nodeService.hasAspect(newNodeRef, ContentModel.ASPECT_VERSIONABLE)); 1088 1089 this.ruleService.enableRules(this.nodeRef); 1090 1091 NodeRef newNodeRef2 = this.nodeService.createNode( 1092 this.nodeRef, 1093 ContentModel.ASSOC_CHILDREN, 1094 QName.createQName(TEST_NAMESPACE, "children"), 1095 ContentModel.TYPE_CONTENT, 1096 getContentProperties()).getChildRef(); 1097 addContentToNode(newNodeRef2); 1098 assertTrue(this.nodeService.hasAspect(newNodeRef2, ContentModel.ASPECT_VERSIONABLE)); 1099 } 1100 1101 1108 private void addContentToNode(NodeRef nodeRef) 1109 { 1110 ContentWriter contentWriter = this.contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true); 1111 contentWriter.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); 1112 contentWriter.setEncoding("UTF-8"); 1113 assertNotNull(contentWriter); 1114 contentWriter.putContent(STANDARD_TEXT_CONTENT + System.currentTimeMillis()); 1115 } 1116 1117 1120 public void testCheckMandatoryProperties() 1121 { 1122 Map <String , Serializable > actionParams = new HashMap <String , Serializable >(1); 1123 actionParams.put("aspect-name", ContentModel.ASPECT_VERSIONABLE); 1124 1125 Map <String , Serializable > condParams = new HashMap <String , Serializable >(1); 1126 1128 Rule rule = createRule( 1129 RuleType.INBOUND, 1130 AddFeaturesActionExecuter.NAME, 1131 actionParams, 1132 ComparePropertyValueEvaluator.NAME, 1133 condParams); 1134 1135 this.ruleService.saveRule(this.nodeRef, rule); 1136 1137 try 1138 { 1139 Map <QName, Serializable > props2 = getContentProperties(); 1141 props2.put(ContentModel.PROP_NAME, "bobbins.doc"); 1142 NodeRef newNodeRef2 = this.nodeService.createNode( 1143 this.nodeRef, 1144 ContentModel.ASSOC_CHILDREN, 1145 QName.createQName(TEST_NAMESPACE, "children"), 1146 ContentModel.TYPE_CONTENT, 1147 props2).getChildRef(); 1148 addContentToNode(newNodeRef2); 1149 fail("An exception should have been thrown since a mandatory parameter was missing from the condition."); 1150 } 1151 catch (Throwable ruleServiceException) 1152 { 1153 } 1155 } 1156 1157 1166 public void testContainsTextCondition() 1167 { 1168 Map <String , Serializable > actionParams = new HashMap <String , Serializable >(1); 1169 actionParams.put("aspect-name", ContentModel.ASPECT_VERSIONABLE); 1170 1171 Map <String , Serializable > condParams = new HashMap <String , Serializable >(1); 1173 condParams.put(ComparePropertyValueEvaluator.PARAM_VALUE, ".doc"); 1174 1175 Rule rule = createRule( 1176 RuleType.INBOUND, 1177 AddFeaturesActionExecuter.NAME, 1178 actionParams, 1179 ComparePropertyValueEvaluator.NAME, 1180 condParams); 1181 1182 this.ruleService.saveRule(this.nodeRef, rule); 1183 1184 Map <QName, Serializable > props1 = new HashMap <QName, Serializable >(); 1186 props1.put(ContentModel.PROP_NAME, "bobbins.txt"); 1187 NodeRef newNodeRef = this.nodeService.createNode( 1189 this.nodeRef, 1190 ContentModel.ASSOC_CHILDREN, 1191 QName.createQName(TEST_NAMESPACE, "children"), 1192 ContentModel.TYPE_CONTENT, 1193 props1).getChildRef(); 1194 addContentToNode(newNodeRef); 1195 1196 1199 assertFalse(this.nodeService.hasAspect(newNodeRef, ContentModel.ASPECT_VERSIONABLE)); 1200 1201 Map <QName, Serializable > props2 = new HashMap <QName, Serializable >(); 1203 props2.put(ContentModel.PROP_NAME, "bobbins.doc"); 1204 NodeRef newNodeRef2 = this.nodeService.createNode( 1206 this.nodeRef, 1207 ContentModel.ASSOC_CHILDREN, 1208 QName.createQName(TEST_NAMESPACE, "children"), 1209 ContentModel.TYPE_CONTENT, 1210 props2).getChildRef(); 1211 addContentToNode(newNodeRef2); 1212 assertTrue(this.nodeService.hasAspect( 1213 newNodeRef2, 1214 ContentModel.ASPECT_VERSIONABLE)); 1215 1216 try 1217 { 1218 NodeRef newNodeRef3 = this.nodeService.createNode( 1220 this.nodeRef, 1221 ContentModel.ASSOC_CHILDREN, 1222 QName.createQName(TEST_NAMESPACE, "children"), 1223 ContentModel.TYPE_CONTENT, 1224 getContentProperties()).getChildRef(); 1225 addContentToNode(newNodeRef3); 1226 } 1227 catch (RuleServiceException exception) 1228 { 1229 } 1231 1232 Map <String , Serializable > condParamsBegins = new HashMap <String , Serializable >(1); 1234 condParamsBegins.put(ComparePropertyValueEvaluator.PARAM_VALUE, "bob*"); 1235 rule.removeAllActionConditions(); 1236 ActionCondition condition1 = this.actionService.createActionCondition(ComparePropertyValueEvaluator.NAME, condParamsBegins); 1237 rule.addActionCondition(condition1); 1238 this.ruleService.saveRule(this.nodeRef, rule); 1239 Map <QName, Serializable > propsx = new HashMap <QName, Serializable >(); 1240 propsx.put(ContentModel.PROP_NAME, "mybobbins.doc"); 1241 NodeRef newNodeRefx = this.nodeService.createNode( 1243 this.nodeRef, 1244 ContentModel.ASSOC_CHILDREN, 1245 QName.createQName(TEST_NAMESPACE, "children"), 1246 ContentModel.TYPE_CONTENT, 1247 propsx).getChildRef(); 1248 addContentToNode(newNodeRefx); 1249 assertFalse(this.nodeService.hasAspect(newNodeRefx, ContentModel.ASPECT_VERSIONABLE)); 1250 Map <QName, Serializable > propsy = new HashMap <QName, Serializable >(); 1251 propsy.put(ContentModel.PROP_NAME, "bobbins.doc"); 1252 NodeRef newNodeRefy = this.nodeService.createNode( 1254 this.nodeRef, 1255 ContentModel.ASSOC_CHILDREN, 1256 QName.createQName(TEST_NAMESPACE, "children"), 1257 ContentModel.TYPE_CONTENT, 1258 propsy).getChildRef(); 1259 addContentToNode(newNodeRefy); 1260 assertTrue(this.nodeService.hasAspect( 1261 newNodeRefy, 1262 ContentModel.ASPECT_VERSIONABLE)); 1263 1264 Map <String , Serializable > condParamsEnds = new HashMap <String , Serializable >(1); 1266 condParamsEnds.put(ComparePropertyValueEvaluator.PARAM_VALUE, "*s.doc"); 1267 rule.removeAllActionConditions(); 1268 ActionCondition condition2 = this.actionService.createActionCondition(ComparePropertyValueEvaluator.NAME, condParamsEnds); 1269 rule.addActionCondition(condition2); 1270 this.ruleService.saveRule(this.nodeRef, rule); 1271 Map <QName, Serializable > propsa = new HashMap <QName, Serializable >(); 1272 propsa.put(ContentModel.PROP_NAME, "bobbins.document"); 1273 NodeRef newNodeRefa = this.nodeService.createNode( 1275 this.nodeRef, 1276 ContentModel.ASSOC_CHILDREN, 1277 QName.createQName(TEST_NAMESPACE, "children"), 1278 ContentModel.TYPE_CONTENT, 1279 propsa).getChildRef(); 1280 addContentToNode(newNodeRefa); 1281 assertFalse(this.nodeService.hasAspect(newNodeRefa, ContentModel.ASPECT_VERSIONABLE)); 1282 Map <QName, Serializable > propsb = new HashMap <QName, Serializable >(); 1283 propsb.put(ContentModel.PROP_NAME, "bobbins.doc"); 1284 NodeRef newNodeRefb = this.nodeService.createNode( 1286 this.nodeRef, 1287 ContentModel.ASSOC_CHILDREN, 1288 QName.createQName(TEST_NAMESPACE, "children"), 1289 ContentModel.TYPE_CONTENT, 1290 propsb).getChildRef(); 1291 addContentToNode(newNodeRefb); 1292 assertTrue(this.nodeService.hasAspect( 1293 newNodeRefb, 1294 ContentModel.ASPECT_VERSIONABLE)); 1295 } 1296 1297 1304 public void testOutboundRuleType() 1305 { 1306 this.nodeService.addAspect(this.nodeRef, ContentModel.ASPECT_LOCKABLE, null); 1307 1308 Map <String , Serializable > params = new HashMap <String , Serializable >(1); 1309 params.put("aspect-name", ContentModel.ASPECT_VERSIONABLE); 1310 1311 Rule rule = createRule( 1312 "outbound", 1313 AddFeaturesActionExecuter.NAME, 1314 params, 1315 NoConditionEvaluator.NAME, 1316 null); 1317 1318 this.ruleService.saveRule(this.nodeRef, rule); 1319 1320 NodeRef newNodeRef = this.nodeService.createNode( 1322 this.nodeRef, 1323 ContentModel.ASSOC_CHILDREN, 1324 QName.createQName(TEST_NAMESPACE, "children"), 1325 ContentModel.TYPE_CONTAINER).getChildRef(); 1326 assertFalse(this.nodeService.hasAspect(newNodeRef, ContentModel.ASPECT_VERSIONABLE)); 1327 1328 this.nodeService.moveNode( 1330 newNodeRef, 1331 this.rootNodeRef, 1332 ContentModel.ASSOC_CHILDREN, 1333 QName.createQName(TEST_NAMESPACE, "children")); 1334 assertTrue(this.nodeService.hasAspect(newNodeRef, ContentModel.ASPECT_VERSIONABLE)); 1335 1336 1338 NodeRef newNodeRef2 = this.nodeService.createNode( 1340 this.nodeRef, 1341 ContentModel.ASSOC_CHILDREN, 1342 QName.createQName(TEST_NAMESPACE, "children"), 1343 ContentModel.TYPE_CONTAINER).getChildRef(); 1344 this.nodeService.deleteNode(newNodeRef2); 1345 } 1346 1347 1351 public void xtestPerformanceOfRuleExecution() 1352 { 1353 try 1354 { 1355 StopWatch sw = new StopWatch(); 1356 1357 sw.start("create nodes with no rule executed"); 1359 UserTransaction userTransaction1 = this.transactionService.getUserTransaction(); 1360 userTransaction1.begin(); 1361 1362 for (int i = 0; i < 100; i++) 1363 { 1364 this.nodeService.createNode( 1365 this.nodeRef, 1366 ContentModel.ASSOC_CONTAINS, 1367 ContentModel.ASSOC_CONTAINS, 1368 ContentModel.TYPE_CONTAINER).getChildRef(); 1369 assertFalse(this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE)); 1370 } 1371 1372 userTransaction1.commit(); 1373 sw.stop(); 1374 1375 Map <String , Serializable > params = new HashMap <String , Serializable >(1); 1376 params.put("aspect-name", ContentModel.ASPECT_VERSIONABLE); 1377 1378 Rule rule = createRule( 1379 RuleType.INBOUND, 1380 AddFeaturesActionExecuter.NAME, 1381 params, 1382 NoConditionEvaluator.NAME, 1383 null); 1384 1385 this.ruleService.saveRule(this.nodeRef, rule); 1386 1387 sw.start("create nodes with one rule run (apply versionable aspect)"); 1388 UserTransaction userTransaction2 = this.transactionService.getUserTransaction(); 1389 userTransaction2.begin(); 1390 1391 NodeRef[] nodeRefs = new NodeRef[100]; 1392 for (int i = 0; i < 100; i++) 1393 { 1394 NodeRef nodeRef = this.nodeService.createNode( 1395 this.nodeRef, 1396 ContentModel.ASSOC_CHILDREN, 1397 QName.createQName(TEST_NAMESPACE, "children"), 1398 ContentModel.TYPE_CONTAINER).getChildRef(); 1399 addContentToNode(nodeRef); 1400 nodeRefs[i] = nodeRef; 1401 1402 assertFalse(this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE)); 1404 } 1405 1406 userTransaction2.commit(); 1407 sw.stop(); 1408 1409 for (NodeRef ref : nodeRefs) 1411 { 1412 assertTrue(this.nodeService.hasAspect(ref, ContentModel.ASPECT_VERSIONABLE)); 1413 } 1414 1415 System.out.println(sw.prettyPrint()); 1416 } 1417 catch (Exception exception) 1418 { 1419 throw new RuntimeException (exception); 1420 } 1421 } 1422} 1423 | Popular Tags |