Search in sources :

Example 6 with Rule

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;
    }
}
Also used : Action(org.alfresco.service.cmr.action.Action) FileToAction(org.alfresco.module.org_alfresco_module_rm.action.impl.FileToAction) CreateRecordAction(org.alfresco.module.org_alfresco_module_rm.action.dm.CreateRecordAction) ArrayList(java.util.ArrayList) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Rule(org.alfresco.service.cmr.rule.Rule)

Example 7 with Rule

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());
        }
    });
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Action(org.alfresco.service.cmr.action.Action) LinkToAction(org.alfresco.module.org_alfresco_module_rm.action.impl.LinkToAction) Rule(org.alfresco.service.cmr.rule.Rule)

Example 8 with Rule

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;
}
Also used : FacesContext(javax.faces.context.FacesContext) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) CompositeAction(org.alfresco.service.cmr.action.CompositeAction) Rule(org.alfresco.service.cmr.rule.Rule)

Example 9 with Rule

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;
}
Also used : Node(org.alfresco.web.bean.repository.Node) CompositeAction(org.alfresco.service.cmr.action.CompositeAction) Rule(org.alfresco.service.cmr.rule.Rule)

Example 10 with Rule

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;
}
Also used : Node(org.alfresco.web.bean.repository.Node) 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