Search in sources :

Example 16 with Rule

use of org.alfresco.service.cmr.rule.Rule in project alfresco-remote-api by Alfresco.

the class RuleServiceTest method testRuleReorder.

@SuppressWarnings("unused")
public void testRuleReorder() throws Exception {
    assertEquals(0, ruleService.getRules(testNodeRef).size());
    // Create 3 rules
    NodeRef rule1 = createRuleNodeRef(testNodeRef, "Rule 1");
    NodeRef rule2 = createRuleNodeRef(testNodeRef, "Rule 2");
    NodeRef rule3 = createRuleNodeRef(testNodeRef, "Rule 3");
    List<Rule> rules = ruleService.getRules(testNodeRef);
    assertEquals(3, rules.size());
    assertEquals("Rule 1", rules.get(0).getTitle());
    assertEquals("Rule 2", rules.get(1).getTitle());
    assertEquals("Rule 3", rules.get(2).getTitle());
    JSONObject action = new JSONObject();
    action.put("actionDefinitionName", "reorder-rules");
    action.put("actionedUponNode", testNodeRef.toString());
    JSONObject params = new JSONObject();
    JSONArray orderArray = new JSONArray();
    orderArray.put(rules.get(2).getNodeRef().toString());
    orderArray.put(rules.get(1).getNodeRef().toString());
    orderArray.put(rules.get(0).getNodeRef().toString());
    params.put("rules", orderArray);
    action.put("parameterValues", params);
    String url = formateQueueActionUrl(false);
    // execute before response (should be successful)
    Response successResponse = sendRequest(new PostRequest(url, action.toString(), "application/json"), 200);
    JSONObject successResult = new JSONObject(successResponse.getContentAsString());
    assertNotNull(successResult);
    assertTrue(successResult.has("data"));
    JSONObject successData = successResult.getJSONObject("data");
    assertTrue(successData.has("status"));
    assertEquals("success", successData.getString("status"));
    assertTrue(successData.has("actionedUponNode"));
    assertFalse(successData.has("exception"));
    assertTrue(successData.has("action"));
    rules = ruleService.getRules(testNodeRef);
    assertEquals(3, rules.size());
    assertEquals("Rule 3", rules.get(0).getTitle());
    assertEquals("Rule 2", rules.get(1).getTitle());
    assertEquals("Rule 1", rules.get(2).getTitle());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) NodeRef(org.alfresco.service.cmr.repository.NodeRef) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Rule(org.alfresco.service.cmr.rule.Rule)

Example 17 with Rule

use of org.alfresco.service.cmr.rule.Rule in project alfresco-remote-api by Alfresco.

the class RuleServiceTest method testCreateRule.

public void testCreateRule() throws Exception {
    JSONObject result = createRule(testNodeRef);
    checkRuleSummary(result);
    List<Rule> rules = ruleService.getRules(testNodeRef);
    assertEquals(1, rules.size());
}
Also used : JSONObject(org.json.JSONObject) Rule(org.alfresco.service.cmr.rule.Rule)

Example 18 with Rule

use of org.alfresco.service.cmr.rule.Rule in project records-management by Alfresco.

the class RM2190Test method testUploadDocumentsSimultaneouslyWithRules.

public void testUploadDocumentsSimultaneouslyWithRules() {
    doTestInTransaction(new Test<Void>() {

        @Override
        public Void run() {
            rootFolder = fileFolderService.create(documentLibrary, generate(), TYPE_FOLDER).getNodeRef();
            Action createAction = actionService.createAction(CreateRecordAction.NAME);
            createAction.setParameterValue(CreateRecordAction.PARAM_FILE_PLAN, filePlan);
            Rule declareRule = new Rule();
            declareRule.setRuleType(INBOUND);
            declareRule.setTitle(generate());
            declareRule.setAction(createAction);
            declareRule.setExecuteAsynchronously(true);
            declareRule.applyToChildren(true);
            ruleService.saveRule(rootFolder, declareRule);
            folder1 = fileFolderService.create(rootFolder, generate(), TYPE_FOLDER).getNodeRef();
            folder2 = fileFolderService.create(rootFolder, generate(), TYPE_FOLDER).getNodeRef();
            Action fileAction = actionService.createAction(FileToAction.NAME);
            fileAction.setParameterValue(FileToAction.PARAM_PATH, PATH);
            fileAction.setParameterValue(FileToAction.PARAM_CREATE_RECORD_PATH, true);
            Rule fileRule = new Rule();
            fileRule.setRuleType(INBOUND);
            fileRule.setTitle(generate());
            fileRule.setAction(fileAction);
            fileRule.setExecuteAsynchronously(true);
            ruleService.saveRule(unfiledContainer, fileRule);
            return null;
        }

        @Override
        public void test(Void result) throws Exception {
            assertFalse(ruleService.getRules(rootFolder).isEmpty());
            assertFalse(ruleService.getRules(unfiledContainer).isEmpty());
        }
    });
    doTestInTransaction(new Test<Void>() {

        @Override
        public Void run() throws FileNotFoundException, InterruptedException {
            Thread thread1 = new Thread() {

                public void run() {
                    List<NodeRef> files = addFilesToFolder(folder1);
                    waitForFilesToBeDeclared(files);
                }
            };
            Thread thread2 = new Thread() {

                public void run() {
                    List<NodeRef> files = addFilesToFolder(folder2);
                    waitForFilesToBeDeclared(files);
                }
            };
            thread1.start();
            thread2.start();
            thread1.join(300000);
            thread2.join(300000);
            return null;
        }

        @Override
        public void test(Void result) throws Exception {
            FileInfo category = fileFolderService.resolveNamePath(filePlan, asList(tokenizeToStringArray(PATH, "/", false, true)));
            assertEquals(NUMBER_IN_BATCH * 2, nodeService.getChildAssocs(category.getNodeRef()).size());
        }
    });
}
Also used : FileToAction(org.alfresco.module.org_alfresco_module_rm.action.impl.FileToAction) CreateRecordAction(org.alfresco.module.org_alfresco_module_rm.action.dm.CreateRecordAction) Action(org.alfresco.service.cmr.action.Action) FileInfo(org.alfresco.service.cmr.model.FileInfo) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) ArrayList(java.util.ArrayList) List(java.util.List) Arrays.asList(java.util.Arrays.asList) Rule(org.alfresco.service.cmr.rule.Rule) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException)

Example 19 with Rule

use of org.alfresco.service.cmr.rule.Rule in project records-management by Alfresco.

the class RM4163Test method testDeclareRecordsConcurently.

public void testDeclareRecordsConcurently() throws Exception {
    doTestInTransaction(new Test<Void>() {

        @Override
        public Void run() {
            // create the folder
            ruleFolder = fileFolderService.create(documentLibrary, "mytestfolder", ContentModel.TYPE_FOLDER).getNodeRef();
            // create record category
            nodeRefCategory1 = filePlanService.createRecordCategory(filePlan, "category1");
            // define declare as record rule and apply it to the created folder from documentLibrary
            Action action = actionService.createAction(CreateRecordAction.NAME);
            action.setParameterValue(CreateRecordAction.PARAM_FILE_PLAN, filePlan);
            Rule rule = new Rule();
            rule.setRuleType(RuleType.INBOUND);
            rule.setTitle("declareAsRecordRule");
            rule.setAction(action);
            rule.setExecuteAsynchronously(true);
            ruleService.saveRule(ruleFolder, rule);
            // define filing rule and apply it to unfiled record container
            Action fileAction = actionService.createAction(FileToAction.NAME);
            fileAction.setParameterValue(FileToAction.PARAM_PATH, "/category1/{node.cm:description}");
            fileAction.setParameterValue(FileToAction.PARAM_CREATE_RECORD_PATH, true);
            Rule fileRule = new Rule();
            fileRule.setRuleType(RuleType.INBOUND);
            fileRule.setTitle("filingRule");
            fileRule.setAction(fileAction);
            fileRule.setExecuteAsynchronously(true);
            ruleService.saveRule(filePlanService.getUnfiledContainer(filePlan), fileRule);
            return null;
        }

        @Override
        public void test(Void result) throws Exception {
            assertFalse(ruleService.getRules(ruleFolder).isEmpty());
        }
    });
    // create 4 documents in documentLibrary
    List<NodeRef> documents = new ArrayList<NodeRef>(4);
    documents.addAll(doTestInTransaction(new Test<List<NodeRef>>() {

        @Override
        public List<NodeRef> run() throws Exception {
            List<NodeRef> documents = new ArrayList<NodeRef>(4);
            NodeRef document = createFile(documentLibrary, "document1.txt", "desc1", ContentModel.TYPE_CONTENT);
            documents.add(document);
            document = createFile(documentLibrary, "document2.txt", "desc2", ContentModel.TYPE_CONTENT);
            documents.add(document);
            document = createFile(documentLibrary, "document3.txt", "desc1", ContentModel.TYPE_CONTENT);
            documents.add(document);
            document = createFile(documentLibrary, "document4.txt", "desc1", ContentModel.TYPE_CONTENT);
            documents.add(document);
            return documents;
        }
    }));
    // move created documents in the folder that has Declare as Record rule
    final Iterator<NodeRef> temp = documents.iterator();
    doTestInTransaction(new Test<Void>() {

        @Override
        public Void run() throws Exception {
            while (temp.hasNext()) {
                NodeRef document = temp.next();
                fileFolderService.move(document, ruleFolder, null);
            }
            return null;
        }
    });
    // give enough time for filing all records
    Thread.sleep(5000);
    // check that target category has in created record folders 4 records
    Integer numberOfRecords = AuthenticationUtil.runAsSystem(new RunAsWork<Integer>() {

        @Override
        public Integer doWork() throws Exception {
            List<NodeRef> containedRecordFolders = filePlanService.getContainedRecordFolders(nodeRefCategory1);
            int numberOfRecords = 0;
            for (NodeRef recordFolder : containedRecordFolders) {
                numberOfRecords = numberOfRecords + fileFolderService.list(recordFolder).size();
            }
            return numberOfRecords;
        }
    });
    assertEquals(4, numberOfRecords.intValue());
}
Also used : FileToAction(org.alfresco.module.org_alfresco_module_rm.action.impl.FileToAction) CreateRecordAction(org.alfresco.module.org_alfresco_module_rm.action.dm.CreateRecordAction) Action(org.alfresco.service.cmr.action.Action) ArrayList(java.util.ArrayList) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ArrayList(java.util.ArrayList) List(java.util.List) Rule(org.alfresco.service.cmr.rule.Rule)

Example 20 with Rule

use of org.alfresco.service.cmr.rule.Rule in project records-management by Alfresco.

the class RM2192Test method testAccessToRecordAfterDeclaring.

public void testAccessToRecordAfterDeclaring() {
    doTestInTransaction(new Test<Void>() {

        @Override
        public Void run() {
            folder = fileFolderService.create(documentLibrary2, generate(), TYPE_FOLDER).getNodeRef();
            Action createAction = actionService.createAction(CreateRecordAction.NAME);
            createAction.setParameterValue(CreateRecordAction.PARAM_FILE_PLAN, filePlan);
            Rule declareRule = new Rule();
            declareRule.setRuleType(INBOUND);
            declareRule.setTitle(generate());
            declareRule.setAction(createAction);
            declareRule.setExecuteAsynchronously(true);
            declareRule.applyToChildren(true);
            ruleService.saveRule(folder, declareRule);
            Action fileAction = actionService.createAction(FileToAction.NAME);
            fileAction.setParameterValue(FileToAction.PARAM_PATH, PATH);
            fileAction.setParameterValue(FileToAction.PARAM_CREATE_RECORD_PATH, true);
            Rule fileRule = new Rule();
            fileRule.setRuleType(INBOUND);
            fileRule.setTitle(generate());
            fileRule.setAction(fileAction);
            fileRule.setExecuteAsynchronously(true);
            ruleService.saveRule(unfiledContainer, fileRule);
            return null;
        }

        @Override
        public void test(Void result) throws Exception {
            assertFalse(ruleService.getRules(folder).isEmpty());
            assertFalse(ruleService.getRules(unfiledContainer).isEmpty());
        }
    });
    doTestInTransaction(new Test<Void>() {

        NodeRef document;

        @Override
        public Void run() {
            document = fileFolderService.create(folder, generate(), TYPE_CONTENT).getNodeRef();
            return null;
        }

        @Override
        public void test(Void result) throws InterruptedException {
            Thread.sleep(10000);
            assertEquals(permissionService.hasPermission(document, READ_RECORDS), ALLOWED);
            assertTrue(recordService.isFiled(document));
            assertNotNull(converter.toJSON(document, true));
        }
    }, user);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileToAction(org.alfresco.module.org_alfresco_module_rm.action.impl.FileToAction) CreateRecordAction(org.alfresco.module.org_alfresco_module_rm.action.dm.CreateRecordAction) Action(org.alfresco.service.cmr.action.Action) Rule(org.alfresco.service.cmr.rule.Rule)

Aggregations

Rule (org.alfresco.service.cmr.rule.Rule)20 NodeRef (org.alfresco.service.cmr.repository.NodeRef)13 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)7 Action (org.alfresco.service.cmr.action.Action)7 RuleRef (org.alfresco.repo.web.scripts.rule.ruleset.RuleRef)6 CreateRecordAction (org.alfresco.module.org_alfresco_module_rm.action.dm.CreateRecordAction)5 FileToAction (org.alfresco.module.org_alfresco_module_rm.action.impl.FileToAction)5 JSONObject (org.json.JSONObject)5 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)5 List (java.util.List)3 RuleType (org.alfresco.service.cmr.rule.RuleType)3 IOException (java.io.IOException)2 CompositeAction (org.alfresco.service.cmr.action.CompositeAction)2 Node (org.alfresco.web.bean.repository.Node)2 JSONArray (org.json.JSONArray)2 JSONException (org.json.JSONException)2 JSONTokener (org.json.JSONTokener)2 Arrays.asList (java.util.Arrays.asList)1 Date (java.util.Date)1