Package org.aperteworkflow.search

Examples of org.aperteworkflow.search.ProcessInstanceSearchData


        }
    session.saveOrUpdate(processInstance);
        session.flush();
        long time = System.currentTimeMillis();
        //update search indexes
        ProcessInstanceSearchData searchData = new ProcessInstanceSearchData(processInstance.getId());
        //put some default search attributes
        if (creator != null) {
            searchData.addSearchAttribute(new ProcessInstanceSearchAttribute("creator_login", creator.getLogin()));
            searchData.addSearchAttribute(new ProcessInstanceSearchAttribute("creator_email", creator.getEmail()));
            searchData.addSearchAttribute(new ProcessInstanceSearchAttribute("creator_realname", creator.getRealName()));
        }
        searchData.addSearchAttributes(new String[][]{
                {"instance_key", processInstance.getExternalKey()},
                {"definition_name", processInstance.getDefinitionName()},
                {"instance_description", processInstance.getDescription()},
                {"instance_internal_id", processInstance.getInternalId()},
                {"instance_keyword", processInstance.getKeyword()},
                {"instance_state", processInstance.getState()},//TODO remember about multiple states (when BpmTask is merged)
                {"instance_create_date", formatShortDate(processInstance.getCreateDate())},
        });
        ProcessDefinitionConfig def = processInstance.getDefinition();
        searchData.addSearchAttributes(new String[][]{
                {"definition_key", def.getBpmDefinitionKey()},
                {"definition_description", def.getDescription()},
                {"definition_comment", def.getComment()},
                {"definition_processname", def.getProcessName()},
        });
        for (ProcessDefinitionPermission perm : def.getPermissions()) {
            if ("SEARCH".equals(perm.getPrivilegeName())) {
                String roleName = perm.getRoleName();
                if (roleName.equals(".*"))
                    roleName = "__AWF__ROLE_ALL";
                roleName = roleName.replace(' ', '_');
                searchData.addSearchAttribute("__AWF__ROLE", roleName, true);
            }
        }
        //lookup process state configuration

        for (BpmTask t : nvl(processInstance.getActiveTasks(), new BpmTask[0])) {
            ProcessStateConfiguration psc
                    = new ProcessDefinitionDAOImpl(session).getProcessStateConfiguration(t);
            if (psc != null) {
                searchData.addSearchAttributes(new String[][]{
                                {"state_commentary", psc.getCommentary()},
                                {"state_description", psc.getDescription()},
                                {"state_name", psc.getName()},
                        });
                for (ProcessStatePermission perm : psc.getPermissions()) {
                    if ("SEARCH".equals(perm.getPrivilegeName())) {
                        String roleName = perm.getRoleName();
                        if (roleName.equals(".*"))
                            roleName = "__AWF__ROLE_ALL";
                        roleName = roleName.replace(' ', '_');
                        searchData.addSearchAttribute("__AWF__ROLE", roleName, true);
                    }
                }
            }
        }
        for (ProcessInstanceAttribute attr : processInstance.getProcessAttributes()) {
            if (attr instanceof Searchable) {
                Collection<ProcessInstanceSearchAttribute> attributes = ((Searchable) attr).getAttributes();
                for (ProcessInstanceSearchAttribute pisa : attributes) {
                    if (pisa.getName().startsWith("__AWF__")) { //no cheating please!
                        String newName = pisa.getName().replace("__AWF__", "");
                        logger.severe("Renaming process provided attribute " + pisa.getName() + " to " + newName +
                                " as it may clash with internal search attributes. PLEASE CORRECT PROCESS DEFINITION.");
                        pisa.setName(newName);
                    }
                }
                searchData.addSearchAttributes(attributes);
            }
        }
        for (String assignee : processInstance.getAssignees()) {
            searchData.addSearchAttribute("__AWF__assignee", assignee, true);
            logger.info("__AWF__assignee: "+ assignee);
        }
        for (String queue : processInstance.getTaskQueues()) {
            searchData.addSearchAttribute("__AWF__queue", queue, true);
            logger.info("__AWF__queue: "+ queue);
        }
        searchData.addSearchAttribute("__AWF__running", String.valueOf(processInstance.getRunning()), true);

        logger.finest("Prepare data for Lucene index update for" + processInstance + " took "
                + (System.currentTimeMillis()-time) + " ms");
        time = System.currentTimeMillis();
        searchProvider.updateIndex(searchData);
        logger.finest("Lucene index update for " + processInstance + " (" + searchData.getSearchAttributes().size()
                + "attributes)  took " + (System.currentTimeMillis()-time) + " ms");
       
    return processInstance.getId();
  }
View Full Code Here

TOP

Related Classes of org.aperteworkflow.search.ProcessInstanceSearchData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.