use of org.wso2.ei.dashboard.core.rest.model.NodeList in project carbon-business-process by wso2.
the class XMLDocument method set.
/**
* Function to set/replace/update an object (String / Element) to matching the xPath provided. (In case new element
* is added, this api will clone it and merge the new node to the target location pointed by xPath and return the new cloned node)
*
* @param xPathStr xPath to the location object need to set
* @param obj String or Node
* @return returns the node get updated when the set object is String, or returns newly added Node in case object is Element
* @throws XPathExpressionException If expression cannot be evaluated
* @throws BPMNXmlException is thrown due to : Provided XPath and object does not match, provided object is not a Node or String
* result is NodeList, not a Text node or Element
*/
public Node set(String xPathStr, Object obj) throws XPathExpressionException, BPMNXmlException {
NodeList evalResult = (NodeList) Utils.evaluateXPath(this.doc, xPathStr, XPathConstants.NODESET);
if (evalResult.getLength() == 1) {
Node targetNode = evalResult.item(0);
if (obj instanceof String && targetNode instanceof Text) {
// if string is provided, assume that user
// need to replace the node value
targetNode.setNodeValue((String) obj);
// return updated Text Node
return targetNode;
} else if ((obj instanceof Integer || obj instanceof Byte || obj instanceof Character || obj instanceof Short || obj instanceof Long || obj instanceof Float || obj instanceof Double || obj instanceof Boolean) && targetNode instanceof Text) {
// need to replace the node value
targetNode.setNodeValue(obj.toString());
// return updated Text Node
return targetNode;
} else if (obj instanceof Element && targetNode instanceof Element && targetNode.getParentNode() != null) {
// if the user provides Node object,
// assume that need to replace the target node
Node targetParent = targetNode.getParentNode();
Node nextSibling = targetNode.getNextSibling();
// remove the target node
targetParent.removeChild(targetNode);
// add new node
Node newNode = doc.importNode((Node) obj, true);
if (nextSibling != null) {
// If next sibling exists we have to put the new node before it
targetParent.insertBefore(newNode, nextSibling);
} else {
targetParent.appendChild(newNode);
}
// return new node
return newNode;
} else {
// provided XPath and object to set does not match
throw new BPMNXmlException("Provided XPath and provided object does not match");
}
} else if (evalResult.getLength() > 0) {
throw new BPMNXmlException("Error in provided xPath. Evaluation result is NodeList, not a Text node or Element");
} else {
throw new BPMNXmlException("Error in provided xPath. Evaluation result is not a Text node or Element");
}
}
use of org.wso2.ei.dashboard.core.rest.model.NodeList in project carbon-business-process by wso2.
the class LiteralBasedOrgEntityProvider method getOrganizationalEntities.
public List<OrganizationalEntityDAO> getOrganizationalEntities(PeopleQueryEvaluator peopleQueryEvaluator, TFrom tFrom, EvaluationContext evaluationContext) {
TLiteral literal = tFrom.getLiteral();
List<OrganizationalEntityDAO> orgEntityList = new ArrayList<OrganizationalEntityDAO>();
Element domNode = (Element) literal.getDomNode();
if (domNode != null) {
NodeList orgEntityNodes = domNode.getElementsByTagNameNS(HumanTaskConstants.organizationalEntityQname.getNamespaceURI(), HumanTaskConstants.organizationalEntityQname.getLocalPart());
// There should be only one organizational Entity
if (orgEntityNodes.getLength() == 1) {
Node orgEntityNode = orgEntityNodes.item(0);
addOrgEntitiesForOrganizationEntityNode(orgEntityNode, peopleQueryEvaluator, orgEntityList);
} else {
NodeList elements = domNode.getElementsByTagNameNS(HumanTaskConstants.userQname.getNamespaceURI(), HumanTaskConstants.userQname.getLocalPart());
if (elements.getLength() == 1) {
// There should only be one user element
CommonTaskUtil.addOrgEntityForUserNode(elements.item(0), peopleQueryEvaluator, orgEntityList);
}
}
}
return orgEntityList;
}
use of org.wso2.ei.dashboard.core.rest.model.NodeList in project product-mi-tooling by wso2.
the class LogConfigDelegate method addLogger.
public Ack addLogger(String groupId, LogConfigAddRequest request) throws ManagementApiException {
logger.debug("Adding new Logger " + request.getName() + " for all nodes in group " + groupId);
Ack ack = new Ack(Constants.FAIL_STATUS);
JsonObject payload = createAddLoggerPayload(request);
NodeList nodeList = databaseManager.fetchNodes(groupId);
for (NodeListInner node : nodeList) {
String nodeId = node.getNodeId();
String mgtApiUrl = ManagementApiUtils.getMgtApiUrl(groupId, nodeId);
String accessToken = databaseManager.getAccessToken(groupId, nodeId);
String addLoggerUrl = mgtApiUrl.concat("logging");
logger.debug("Adding new logger on node " + nodeId);
CloseableHttpResponse httpResponse = Utils.doPatch(groupId, nodeId, accessToken, addLoggerUrl, payload);
if (httpResponse.getStatusLine().getStatusCode() != 200) {
logger.error("Error occurred while adding logger on node " + nodeId + " in group " + groupId);
String message = HttpUtils.getJsonResponse(httpResponse).get("Error").getAsString();
ack.setMessage(message);
return ack;
}
}
ack.setStatus(Constants.SUCCESS_STATUS);
return ack;
}
use of org.wso2.ei.dashboard.core.rest.model.NodeList in project product-mi-tooling by wso2.
the class LogConfigDelegate method updateLogLevel.
public Ack updateLogLevel(String groupId, LogConfigUpdateRequest request) throws ManagementApiException {
logger.debug("Updating logger " + request.getName() + " for all nodes in group " + groupId);
Ack ack = new Ack(Constants.FAIL_STATUS);
JsonObject payload = createUpdateLoggerPayload(request);
NodeList nodeList = databaseManager.fetchNodes(groupId);
for (NodeListInner node : nodeList) {
String nodeId = node.getNodeId();
CloseableHttpResponse httpResponse = updateLogLevelByNodeId(groupId, nodeId, payload);
if (httpResponse.getStatusLine().getStatusCode() != 200) {
logger.error("Error occurred while updating logger on node " + nodeId + " in group " + groupId);
String message = HttpUtils.getJsonResponse(httpResponse).get("Error").getAsString();
ack.setMessage(message);
return ack;
}
}
ack.setStatus(Constants.SUCCESS_STATUS);
return ack;
}
use of org.wso2.ei.dashboard.core.rest.model.NodeList in project product-mi-tooling by wso2.
the class UsersDelegate method addUser.
public Ack addUser(String groupId, AddUserRequest request) throws ManagementApiException {
log.debug("Adding user " + request.getUserId() + " in group " + groupId);
Ack ack = new Ack(Constants.FAIL_STATUS);
JsonObject payload = createAddUserPayload(request);
NodeList nodeList = databaseManager.fetchNodes(groupId);
// assumption - In a group, all nodes use a shared user-store
String nodeId = nodeList.get(0).getNodeId();
String mgtApiUrl = ManagementApiUtils.getMgtApiUrl(groupId, nodeId);
String accessToken = databaseManager.getAccessToken(groupId, nodeId);
String url = mgtApiUrl.concat("users");
Utils.doPost(groupId, nodeId, accessToken, url, payload);
ack.setStatus(Constants.SUCCESS_STATUS);
return ack;
}
Aggregations