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;
}
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);
}
}
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;
}
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);
}
}
}
}
}
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);
}
}
}
}
}
}
}
Aggregations