Search in sources :

Example 1 with Rule

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

the class RuleDelete method executeImpl.

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    Map<String, Object> model = new HashMap<String, Object>();
    NodeRef nodeRef = parseRequestForNodeRef(req);
    // get request parameters
    Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
    String ruleId = templateVars.get("rule_id");
    Rule ruleToDelete = null;
    // get all rules for given nodeRef
    List<Rule> rules = ruleService.getRules(nodeRef, false);
    // filter by rule id
    for (Rule rule : rules) {
        if (rule.getNodeRef().getId().equalsIgnoreCase(ruleId)) {
            ruleToDelete = rule;
            break;
        }
    }
    if (ruleToDelete == null) {
        throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find rule with id: " + ruleId);
    }
    // delete rule
    ruleService.removeRule(nodeRef, ruleToDelete);
    return model;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap) Rule(org.alfresco.service.cmr.rule.Rule)

Example 2 with Rule

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

the class RuleGet method executeImpl.

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    Map<String, Object> model = new HashMap<String, Object>();
    NodeRef nodeRef = parseRequestForNodeRef(req);
    // get request parameters
    Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
    String ruleId = templateVars.get("rule_id");
    Rule ruleToReturn = null;
    // get all rules for given nodeRef
    List<Rule> rules = ruleService.getRules(nodeRef);
    // filter by rule id
    for (Rule rule : rules) {
        if (rule.getNodeRef().getId().equalsIgnoreCase(ruleId)) {
            ruleToReturn = rule;
            break;
        }
    }
    if (ruleToReturn == null) {
        throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find rule with id: " + ruleId);
    }
    RuleRef ruleRefToReturn = new RuleRef(ruleToReturn, fileFolderService.getFileInfo(ruleService.getOwningNodeRef(ruleToReturn)));
    model.put("ruleRef", ruleRefToReturn);
    return model;
}
Also used : RuleRef(org.alfresco.repo.web.scripts.rule.ruleset.RuleRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap) Rule(org.alfresco.service.cmr.rule.Rule)

Example 3 with Rule

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

the class RulesetGet method executeImpl.

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    Map<String, Object> model = new HashMap<String, Object>();
    // get request parameters
    NodeRef nodeRef = parseRequestForNodeRef(req);
    String ruleType = req.getParameter("ruleType");
    RuleType type = ruleService.getRuleType(ruleType);
    if (type == null) {
        ruleType = null;
    }
    RuleSet ruleset = new RuleSet();
    // get all "owned" rules
    List<Rule> ownedRules = ruleService.getRules(nodeRef, false, ruleType);
    // get all rules (including inherited)
    List<Rule> inheritedRules = ruleService.getRules(nodeRef, true, ruleType);
    // remove "owned" rules
    inheritedRules.removeAll(ownedRules);
    List<RuleRef> rulesToSet = new ArrayList<RuleRef>();
    for (Rule rule : ownedRules) {
        rulesToSet.add(new RuleRef(rule, fileFolderService.getFileInfo(ruleService.getOwningNodeRef(rule))));
    }
    ruleset.setRules(rulesToSet);
    List<RuleRef> inheritedRulesToSet = new ArrayList<RuleRef>();
    for (Rule rule : inheritedRules) {
        inheritedRulesToSet.add(new RuleRef(rule, fileFolderService.getFileInfo(ruleService.getOwningNodeRef(rule))));
    }
    ruleset.setInheritedRules(inheritedRulesToSet);
    ruleset.setLinkedToRuleSet(ruleService.getLinkedToRuleNode(nodeRef));
    ruleset.setLinkedFromRuleSets(ruleService.getLinkedFromRuleNodes(nodeRef));
    ruleset.setRulesetNodeRef(nodeRef);
    model.put("ruleset", ruleset);
    return model;
}
Also used : RuleRef(org.alfresco.repo.web.scripts.rule.ruleset.RuleRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) RuleSet(org.alfresco.repo.web.scripts.rule.ruleset.RuleSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RuleType(org.alfresco.service.cmr.rule.RuleType) Rule(org.alfresco.service.cmr.rule.Rule)

Example 4 with Rule

use of org.alfresco.service.cmr.rule.Rule in project acs-community-packaging by Alfresco.

the class RulesDialog method getRules.

/**
 * Returns the list of rules to display
 *
 * @return List of WrappedRule objects
 */
public List<WrappedRule> getRules() {
    boolean includeInherited = true;
    if (this.filterModeMode.equals(LOCAL)) {
        includeInherited = false;
    }
    // get the rules from the repository
    List<Rule> repoRules = this.getRuleService().getRules(getSpace().getNodeRef(), includeInherited);
    this.rules = new ArrayList<WrappedRule>(repoRules.size());
    // wrap them all passing the current space
    for (Rule rule : repoRules) {
        Date createdDate = (Date) this.getNodeService().getProperty(rule.getNodeRef(), ContentModel.PROP_CREATED);
        Date modifiedDate = (Date) this.getNodeService().getProperty(rule.getNodeRef(), ContentModel.PROP_MODIFIED);
        boolean isLocal = getSpace().getNodeRef().equals(this.getRuleService().getOwningNodeRef(rule));
        WrappedRule wrapped = new WrappedRule(rule, isLocal, createdDate, modifiedDate);
        this.rules.add(wrapped);
    }
    return this.rules;
}
Also used : Rule(org.alfresco.service.cmr.rule.Rule) Date(java.util.Date)

Example 5 with Rule

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

the class RM3993Test 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
            nodeRefCategory1 = filePlanService.createRecordCategory(filePlan, "category1");
            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, "/category1/{node.cm:description}");
            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) * NUMBER_IN_BATCH + (j + 1);
                    String name = "content" + count + ".txt";
                    System.out.println(name + " - creating");
                    Random rand = new Random();
                    int descInt = rand.nextInt(2) + 1;
                    NodeRef record = createFile(ruleFolder, name, Integer.toString(descInt), ContentModel.TYPE_CONTENT);
                    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;
    }
    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;
        }
    });
    assertTrue(numberOfRecords == NUMBER_OF_BATCHES * NUMBER_IN_BATCH);
}
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) Random(java.util.Random) ArrayList(java.util.ArrayList) List(java.util.List) 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