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());
}
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());
}
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());
}
});
}
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());
}
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);
}
Aggregations