Search in sources :

Example 16 with OrganizationalEntityDAO

use of org.wso2.carbon.humantask.core.dao.OrganizationalEntityDAO in project carbon-business-process by wso2.

the class TransformerUtils method transformOrganizationalEntityList.

/**
 * Transforms the TOrganizationalEntity type to OrganizationalEntity.
 *
 * @param tOEntity : The object to be transformed.
 * @return : The transformed object list.
 */
public static List<OrganizationalEntityDAO> transformOrganizationalEntityList(TOrganizationalEntity tOEntity) {
    HumanTaskEngine taskEngine = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine();
    HumanTaskDAOConnection daoConn = taskEngine.getDaoConnectionFactory().getConnection();
    List<OrganizationalEntityDAO> organizationalEntities = new ArrayList<OrganizationalEntityDAO>();
    TOrganizationalEntityChoice[] usersAndGroups = tOEntity.getTOrganizationalEntityChoice();
    for (TOrganizationalEntityChoice userOrGroup : usersAndGroups) {
        String userName = null;
        OrganizationalEntityDAO.OrganizationalEntityType type = null;
        if (userOrGroup.getUser() != null) {
            TUser user = userOrGroup.getUser();
            userName = user.getTUser().trim();
            type = OrganizationalEntityDAO.OrganizationalEntityType.USER;
        } else if (userOrGroup.getGroup() != null) {
            TGroup group = userOrGroup.getGroup();
            userName = group.getTGroup().trim();
            type = OrganizationalEntityDAO.OrganizationalEntityType.GROUP;
        }
        if (org.h2.util.StringUtils.isNullOrEmpty(userName) || type == null) {
            throw new HumanTaskRuntimeException("Cannot extract OrganizationalEntity from :" + tOEntity);
        }
        OrganizationalEntityDAO orgEntity = daoConn.createNewOrgEntityObject(userName, type);
        organizationalEntities.add(orgEntity);
    }
    return organizationalEntities;
}
Also used : HumanTaskEngine(org.wso2.carbon.humantask.core.engine.HumanTaskEngine) ArrayList(java.util.ArrayList) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)

Example 17 with OrganizationalEntityDAO

use of org.wso2.carbon.humantask.core.dao.OrganizationalEntityDAO in project carbon-business-process by wso2.

the class TransformerUtils method generateAttachmentDAOFromID.

/**
 * Generate an {@code AttachmentDAO} for a given attachment-id
 *
 * @param task task to be associated with the particular attachment
 * @param attachmentID id of the attachment, so this will be used to extract attachment information from the
 * attachment-mgt OSGi service
 *
 * @return reference to the created {@code AttachmentDAO}
 * @throws HumanTaskException If if was failed to retrieve data from the attachment-mgt OSGi service
 */
public static AttachmentDAO generateAttachmentDAOFromID(TaskDAO task, String attachmentID) throws HumanTaskException {
    try {
        org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment attachment = HumanTaskServerHolder.getInstance().getAttachmentService().getAttachmentService().getAttachmentInfo(attachmentID);
        AttachmentDAO dao = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getDaoConnectionFactory().getConnection().createAttachment();
        // Constructing the attachment DAO from the DTO
        dao.setName(attachment.getName());
        dao.setContentType(attachment.getContentType());
        dao.setTask((Task) task);
        String attachmentURL = attachment.getUrl().toString();
        // Extracting the attachment uri
        String attachmentUniqueID = attachmentURL.substring(attachmentURL.lastIndexOf("/") + 1);
        dao.setValue(attachmentUniqueID);
        dao.setAttachedAt(attachment.getCreatedTime().getTime());
        OrganizationalEntityDAO orgEntityDAO = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getDaoConnectionFactory().getConnection().createNewOrgEntityObject(attachment.getCreatedBy(), OrganizationalEntityDAO.OrganizationalEntityType.USER);
        dao.setAttachedBy((OrganizationalEntity) orgEntityDAO);
        // TODO : "AccessType is not supported by Attachment-Mgt DTOs. So using a dummy value: " + HumanTaskConstants.DEFAULT_ATTACHMENT_ACCESS_TYPE);
        dao.setAccessType(HumanTaskConstants.DEFAULT_ATTACHMENT_ACCESS_TYPE);
        return dao;
    } catch (AttachmentMgtException e) {
        String errorMsg = "Attachment Data retrieval operation failed for attachment id:" + attachmentID + ". " + "Reason:";
        log.error(e.getLocalizedMessage(), e);
        throw new HumanTaskException(errorMsg + e.getLocalizedMessage(), e);
    }
}
Also used : AttachmentMgtException(org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException) org.wso2.carbon.humantask.client.api.types(org.wso2.carbon.humantask.client.api.types) HumanTaskException(org.wso2.carbon.humantask.core.engine.HumanTaskException)

Example 18 with OrganizationalEntityDAO

use of org.wso2.carbon.humantask.core.dao.OrganizationalEntityDAO in project carbon-business-process by wso2.

the class ExpressionBasedOrgEntityProvider method getOrganizationalEntities.

public List<OrganizationalEntityDAO> getOrganizationalEntities(PeopleQueryEvaluator peopleQueryEvaluator, TFrom tFrom, EvaluationContext evaluationContext) {
    String expression = tFrom.newCursor().getTextValue().trim();
    log.debug("Evaluating expression " + expression + " for ExpressionBasedOrgEntityProvider");
    String expLang = (tFrom.getExpressionLanguage() == null) ? HumanTaskConstants.WSHT_EXP_LANG_XPATH20 : tFrom.getExpressionLanguage();
    ExpressionLanguageRuntime expLangRuntime = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getExpressionLanguageRuntime(expLang);
    List list = expLangRuntime.evaluate(expression, evaluationContext);
    List<OrganizationalEntityDAO> orgEntityList = new ArrayList<OrganizationalEntityDAO>();
    if (list.isEmpty() || list.size() > 1) {
        log.debug(" Organizational Entities evaluated to null or multiple list");
        return orgEntityList;
    }
    // Returned list should evaluate to an organizationalEntity or a user
    for (Object item : list) {
        if (item instanceof NodeList) {
            for (int i = 0; i < ((NodeList) item).getLength(); i++) {
                Node node = ((NodeList) item).item(i);
                if (node.getNodeType() == Node.ELEMENT_NODE) {
                    if (node.getLocalName().equals(HumanTaskConstants.userQname.getLocalPart()) && node.getNamespaceURI().equals(HumanTaskConstants.userQname.getNamespaceURI())) {
                        CommonTaskUtil.addOrgEntityForUserNode(node, peopleQueryEvaluator, orgEntityList);
                    } else if (node.getLocalName().equals(HumanTaskConstants.groupQname.getLocalPart()) && node.getNamespaceURI().equals(HumanTaskConstants.groupQname.getNamespaceURI())) {
                        CommonTaskUtil.addOrgEntityForGroupNode(node, peopleQueryEvaluator, orgEntityList);
                    } else if (node.getLocalName().equals("wrapper")) {
                        // Expression evaluator wraps the string with wrapper element name
                        CommonTaskUtil.addOrgEntityForUserNode(node, peopleQueryEvaluator, orgEntityList);
                    } else if (node.getLocalName().equals(HumanTaskConstants.organizationalEntityQname.getLocalPart()) && node.getNamespaceURI().equals(HumanTaskConstants.organizationalEntityQname.getNamespaceURI())) {
                        // This is an organizational Entity node, hence parse it as org entity
                        // Most probably this logic wont be required
                        CommonTaskUtil.addOrgEntitiesForOrganizationEntityNode(node, peopleQueryEvaluator, orgEntityList);
                    }
                } else if (node.getNodeType() == Node.TEXT_NODE) {
                    String nodeValue = node.getNodeValue().trim();
                    if (nodeValue.length() > 0) {
                        OrganizationalEntityDAO userOrgEntityForName = peopleQueryEvaluator.createUserOrgEntityForName(nodeValue);
                        if (userOrgEntityForName != null) {
                            orgEntityList.add(userOrgEntityForName);
                        }
                    }
                }
            }
        }
    }
    return orgEntityList;
}
Also used : OrganizationalEntityDAO(org.wso2.carbon.humantask.core.dao.OrganizationalEntityDAO) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List) ExpressionLanguageRuntime(org.wso2.carbon.humantask.core.engine.runtime.api.ExpressionLanguageRuntime)

Example 19 with OrganizationalEntityDAO

use of org.wso2.carbon.humantask.core.dao.OrganizationalEntityDAO in project carbon-business-process by wso2.

the class LiteralBasedOrgEntityProvider method addOrgEntityForUserNode.

public static void addOrgEntityForUserNode(Node userNode, PeopleQueryEvaluator pqe, List<OrganizationalEntityDAO> orgEntityList) {
    NodeList childNodes = userNode.getChildNodes();
    if (childNodes.getLength() == 1) {
        Node textNode = childNodes.item(0);
        if (textNode != null && textNode.getNodeType() == Node.TEXT_NODE) {
            String username = textNode.getNodeValue();
            if (username != null) {
                username = username.trim();
                if (username.length() > 0) {
                    OrganizationalEntityDAO userOrgEntityForUser = pqe.createUserOrgEntityForName(username);
                    orgEntityList.add(userOrgEntityForUser);
                }
            }
        }
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) OrganizationalEntityDAO(org.wso2.carbon.humantask.core.dao.OrganizationalEntityDAO)

Example 20 with OrganizationalEntityDAO

use of org.wso2.carbon.humantask.core.dao.OrganizationalEntityDAO in project carbon-business-process by wso2.

the class LiteralBasedOrgEntityProvider method addOrgEntitiesForOrganizationEntityNode.

public static void addOrgEntitiesForOrganizationEntityNode(Node orgEntityNode, PeopleQueryEvaluator pqe, List<OrganizationalEntityDAO> orgEntityList) {
    // Org entity node should contain either a user elements or group elements
    if (orgEntityNode.getNodeType() == Node.ELEMENT_NODE) {
        NodeList userList = ((Element) orgEntityNode).getElementsByTagNameNS(HumanTaskConstants.userQname.getNamespaceURI(), HumanTaskConstants.userQname.getLocalPart());
        for (int j = 0; j < userList.getLength(); j++) {
            Node item = userList.item(j);
            NodeList childNodes = item.getChildNodes();
            if (childNodes.getLength() == 1) {
                Node textNode = childNodes.item(0);
                if (textNode != null && textNode.getNodeType() == Node.TEXT_NODE) {
                    String username = textNode.getNodeValue();
                    if (username != null) {
                        username = username.trim();
                        if (username.length() > 0) {
                            OrganizationalEntityDAO userOrgEntityForName = pqe.createUserOrgEntityForName(username);
                            orgEntityList.add(userOrgEntityForName);
                        }
                    }
                }
            }
        }
        NodeList groupList = ((Element) orgEntityNode).getElementsByTagNameNS(HumanTaskConstants.groupQname.getNamespaceURI(), HumanTaskConstants.groupQname.getLocalPart());
        for (int j = 0; j < groupList.getLength(); j++) {
            Node item = groupList.item(j);
            NodeList childNodes = item.getChildNodes();
            if (childNodes.getLength() == 1) {
                Node textNode = childNodes.item(0);
                if (textNode != null && textNode.getNodeType() == Node.TEXT_NODE) {
                    String groupName = textNode.getNodeValue();
                    if (groupName != null) {
                        groupName = groupName.trim();
                        if (groupName.length() > 0) {
                            OrganizationalEntityDAO groupOrgEntityForName = pqe.createGroupOrgEntityForRole(groupName);
                            orgEntityList.add(groupOrgEntityForName);
                        }
                    }
                }
            }
        }
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) OrganizationalEntityDAO(org.wso2.carbon.humantask.core.dao.OrganizationalEntityDAO)

Aggregations

OrganizationalEntityDAO (org.wso2.carbon.humantask.core.dao.OrganizationalEntityDAO)10 HumanTaskRuntimeException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)10 ArrayList (java.util.ArrayList)7 Node (org.w3c.dom.Node)5 GenericHumanRoleDAO (org.wso2.carbon.humantask.core.dao.GenericHumanRoleDAO)5 HumanTaskIllegalArgumentException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalArgumentException)5 Element (org.w3c.dom.Element)4 NodeList (org.w3c.dom.NodeList)4 HumanTaskException (org.wso2.carbon.humantask.core.engine.HumanTaskException)4 HumanTaskIllegalAccessException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException)4 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)4 UserStoreException (org.wso2.carbon.user.core.UserStoreException)4 HumanTaskEngine (org.wso2.carbon.humantask.core.engine.HumanTaskEngine)3 PeopleQueryEvaluator (org.wso2.carbon.humantask.core.engine.PeopleQueryEvaluator)3 HumanTaskIllegalOperationException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalOperationException)3 HumanTaskIllegalStateException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalStateException)3 OrganizationalEntityProvider (org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.provider.OrganizationalEntityProvider)2 TaskConfiguration (org.wso2.carbon.humantask.core.store.TaskConfiguration)2 List (java.util.List)1 Callable (java.util.concurrent.Callable)1