use of org.alfresco.service.cmr.rule.Rule in project records-management by Alfresco.
the class RM2072Test method testAutoDeclareAutoFileCreateRecordFolderOnly.
/**
* Given that I have auto declare configured
* And that I have auto file configured to a path where only the record folder needs to be created
* When I add lots of documents in the same transaction
* Then the rules should fire
* And the documents should be filed in the new record folder
*/
public void testAutoDeclareAutoFileCreateRecordFolderOnly() 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
NodeRef nodeRefA = filePlanService.createRecordCategory(filePlan, "A");
NodeRef nodeRefB = filePlanService.createRecordCategory(nodeRefA, "B");
filePlanService.createRecordCategory(nodeRefB, "C");
Action action = actionService.createAction(CreateRecordAction.NAME);
action.setParameterValue(CreateRecordAction.PARAM_FILE_PLAN, filePlan);
Rule rule = new Rule();
rule.setRuleType(RuleType.INBOUND);
rule.setTitle("my rule");
rule.setAction(action);
rule.setExecuteAsynchronously(true);
ruleService.saveRule(ruleFolder, rule);
Action fileAction = actionService.createAction(FileToAction.NAME);
fileAction.setParameterValue(FileToAction.PARAM_PATH, "/A/B/C/{date.year.long}/{date.month.long}/{date.day.month}");
fileAction.setParameterValue(FileToAction.PARAM_CREATE_RECORD_PATH, true);
Rule fileRule = new Rule();
fileRule.setRuleType(RuleType.INBOUND);
fileRule.setTitle("my rule");
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());
}
});
List<NodeRef> records = new ArrayList<NodeRef>(NUMBER_OF_BATCHES * NUMBER_IN_BATCH);
for (int i = 0; i < NUMBER_OF_BATCHES; i++) {
final int finali = i;
records.addAll(doTestInTransaction(new Test<List<NodeRef>>() {
@Override
public List<NodeRef> run() throws Exception {
List<NodeRef> records = new ArrayList<NodeRef>(NUMBER_IN_BATCH);
for (int j = 0; j < NUMBER_IN_BATCH; j++) {
int count = (finali + 1) * (j + 1);
String name = "content" + count + ".txt";
System.out.println(name + " - creating");
NodeRef record = fileFolderService.create(ruleFolder, name, ContentModel.TYPE_CONTENT).getNodeRef();
records.add(record);
}
return records;
}
}));
}
try {
while (!records.isEmpty()) {
Thread.sleep(1000);
final Iterator<NodeRef> temp = records.iterator();
doTestInTransaction(new Test<Void>() {
@Override
public Void run() throws Exception {
while (temp.hasNext()) {
NodeRef record = temp.next();
if (nodeService.hasAspect(record, ASPECT_RECORD) && recordService.isFiled(record)) {
String name = (String) nodeService.getProperty(record, ContentModel.PROP_NAME);
System.out.println(name + " - complete");
temp.remove();
}
}
return null;
}
});
}
} catch (Exception exception) {
exception.printStackTrace();
throw exception;
}
}
use of org.alfresco.service.cmr.rule.Rule in project records-management by Alfresco.
the class RM4101Test method testRunRuleNotInBackground.
public void testRunRuleNotInBackground() throws Exception {
final String categoryName = "category1" + UUID.randomUUID().toString();
final NodeRef category1 = doTestInTransaction(new Test<NodeRef>() {
@Override
public NodeRef run() {
return filePlanService.createRecordCategory(filePlan, categoryName);
}
});
final NodeRef folder1 = doTestInTransaction(new Test<NodeRef>() {
@Override
public NodeRef run() {
return recordFolderService.createRecordFolder(category1, "folder1WithRule" + UUID.randomUUID().toString());
}
});
final String folder2Name = "folder2FolderToLinkTo" + UUID.randomUUID().toString();
final NodeRef folder2 = doTestInTransaction(new Test<NodeRef>() {
@Override
public NodeRef run() {
return recordFolderService.createRecordFolder(category1, folder2Name);
}
});
doTestInTransaction(new Test<Void>() {
@Override
public Void run() {
Action linkToAction = actionService.createAction(LinkToAction.NAME);
linkToAction.setParameterValue(LinkToAction.PARAM_PATH, "/" + categoryName + "/" + folder2Name);
Rule rule = new Rule();
rule.setRuleType(RuleType.INBOUND);
rule.setTitle("LinkTo");
rule.setAction(linkToAction);
rule.setExecuteAsynchronously(false);
ruleService.saveRule(folder1, rule);
return null;
}
});
doTestInTransaction(new Test<Void>() {
@Override
public Void run() {
utils.createRecord(folder1, "record1" + UUID.randomUUID().toString());
return null;
}
@Override
public void test(Void result) throws Exception {
assertEquals(1, nodeService.getChildAssocs(folder2).size());
}
});
}
use of org.alfresco.service.cmr.rule.Rule in project acs-community-packaging by Alfresco.
the class EditRuleWizard method init.
// ------------------------------------------------------------------------------
// Wizard implementation
/* Loads up conditions and actions from the repository
*/
@Override
public void init(Map<String, String> parameters) {
super.init(parameters);
// get hold of the current rule details
Rule rule = this.rulesDialog.getCurrentRule();
if (rule == null) {
throw new AlfrescoRuntimeException("Failed to locate the current rule");
}
// populate the bean with current values
this.type = rule.getRuleTypes().get(0);
this.title = rule.getTitle();
this.description = rule.getDescription();
this.applyToSubSpaces = rule.isAppliedToChildren();
this.runInBackground = rule.getExecuteAsynchronously();
this.ruleDisabled = rule.getRuleDisabled();
FacesContext context = FacesContext.getCurrentInstance();
// Get the composite action
CompositeAction compositeAction = getCompositeAction(rule);
populateConditions(context, compositeAction);
populateActions(context, compositeAction);
// reset the current condition
this.selectedCondition = null;
// reset the current action
this.action = null;
}
use of org.alfresco.service.cmr.rule.Rule in project acs-community-packaging by Alfresco.
the class EditRuleWizard method finishImpl.
@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception {
// get hold of the space the rule will apply to and make sure
// it is actionable
Node currentSpace = browseBean.getActionSpace();
// get the existing rule
Rule rule = this.rulesDialog.getCurrentRule();
// Get the composite action
CompositeAction compositeAction = getCompositeAction(rule);
// remove all the conditions and actions from the current rule
compositeAction.removeAllActionConditions();
compositeAction.removeAllActions();
// re-setup the rule
outcome = setupRule(context, rule, outcome);
// Save the rule
this.getRuleService().saveRule(currentSpace.getNodeRef(), rule);
if (logger.isDebugEnabled())
logger.debug("Updated rule '" + this.title + "'");
return outcome;
}
use of org.alfresco.service.cmr.rule.Rule in project acs-community-packaging by Alfresco.
the class CreateRuleWizard method finishImpl.
@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception {
if (logger.isDebugEnabled())
logger.debug("finishImpl called - saving rules");
// get hold of the space the rule will apply to and make sure
// it is actionable
Node currentSpace = this.browseBean.getActionSpace();
// create the new rule
// Rule rule = this.ruleService.createRule(this.getType());
Rule rule = new Rule();
rule.setRuleType(this.getType());
// setup the rule
outcome = setupRule(context, rule, outcome);
// Save the rule
this.getRuleService().saveRule(currentSpace.getNodeRef(), rule);
if (logger.isDebugEnabled())
logger.debug("Added rule '" + this.title + "'");
return outcome;
}
Aggregations