use of org.wso2.ei.dashboard.core.rest.model.NodeList in project carbon-apimgt by wso2.
the class WSDL11SOAPOperationExtractor method initModels.
/**
* Initiallize SOAP to REST Operations
*
* @return true if extracting operations was successful
*/
private boolean initModels() throws APIMgtWSDLException {
wsdlDefinition = getWSDLDefinition();
boolean canProcess = true;
targetNamespace = wsdlDefinition.getTargetNamespace();
Types types = wsdlDefinition.getTypes();
if (types != null) {
typeList = types.getExtensibilityElements();
}
if (typeList != null) {
for (Object ext : typeList) {
if (ext instanceof Schema) {
Schema schema = (Schema) ext;
Map importedSchemas = schema.getImports();
Element schemaElement = schema.getElement();
NodeList schemaNodes = schemaElement.getChildNodes();
schemaNodeList.addAll(SOAPOperationBindingUtils.list(schemaNodes));
// gets types from imported schemas from the parent wsdl. Nested schemas will not be imported.
if (importedSchemas != null) {
for (Object importedSchemaObj : importedSchemas.keySet()) {
String schemaUrl = (String) importedSchemaObj;
if (importedSchemas.get(schemaUrl) != null) {
Vector vector = (Vector) importedSchemas.get(schemaUrl);
for (Object schemaVector : vector) {
if (schemaVector instanceof SchemaImport) {
Schema referencedSchema = ((SchemaImport) schemaVector).getReferencedSchema();
if (referencedSchema != null && referencedSchema.getElement() != null) {
if (referencedSchema.getElement().hasChildNodes()) {
schemaNodeList.addAll(SOAPOperationBindingUtils.list(referencedSchema.getElement().getChildNodes()));
} else {
log.warn("The referenced schema : " + schemaUrl + " doesn't have any defined types");
}
} else {
boolean isInlineSchema = false;
for (Object aSchema : typeList) {
if (schemaUrl.equalsIgnoreCase(((Schema) aSchema).getElement().getAttribute(TARGET_NAMESPACE_ATTRIBUTE))) {
isInlineSchema = true;
break;
}
}
if (isInlineSchema) {
log.debug(schemaUrl + " is already defined inline. Hence continue.");
} else {
log.warn("Cannot access referenced schema for the schema defined at: " + schemaUrl);
}
}
}
}
}
}
} else {
log.info("No any imported schemas found in the given wsdl.");
}
List schemaIncludes = schema.getIncludes();
for (Iterator iter = schemaIncludes.iterator(); iter.hasNext(); ) {
SchemaReference schemaInclude = (SchemaReference) iter.next();
Schema schemaImp = schemaInclude.getReferencedSchema();
String schemaLoc = schemaInclude.getSchemaLocationURI();
if (schemaImp != null && schemaImp.getElement() != null) {
if (schemaImp.getElement().hasChildNodes()) {
schemaNodeList.addAll(SOAPOperationBindingUtils.list(schemaImp.getElement().getChildNodes()));
} else {
log.warn("The referenced schema : " + schemaLoc + " doesn't have any defined types");
}
}
}
if (log.isDebugEnabled()) {
Gson gson = new GsonBuilder().setExclusionStrategies(new SwaggerFieldsExcludeStrategy()).create();
log.debug("swagger definition model map from the wsdl: " + gson.toJson(parameterModelMap));
}
if (schemaNodeList == null) {
log.warn("No schemas found in the type element for target namespace:" + schema.getDocumentBaseURI());
}
}
}
if (schemaNodeList != null) {
for (Node node : schemaNodeList) {
WSDLParamDefinition wsdlParamDefinition = new WSDLParamDefinition();
ModelImpl model = new ModelImpl();
Property currentProperty = null;
try {
traverseTypeElement(node, null, model, currentProperty);
} catch (APIManagementException e) {
throw new APIMgtWSDLException(e);
}
if (StringUtils.isNotBlank(model.getName())) {
parameterModelMap.put(model.getName(), model);
}
if (wsdlParamDefinition.getDefinitionName() != null) {
wsdlParamDefinitions.add(wsdlParamDefinition);
}
}
} else {
log.info("No schema is defined in the wsdl document");
}
}
if (log.isDebugEnabled()) {
log.debug("Successfully initialized an instance of " + this.getClass().getSimpleName() + " with a single WSDL.");
}
return canProcess;
}
use of org.wso2.ei.dashboard.core.rest.model.NodeList in project carbon-apimgt by wso2.
the class ImportUtils method getLifeCycleAction.
/**
* This method returns the lifecycle action which can be used to transit from currentStatus to targetStatus.
*
* @param tenantDomain Tenant domain
* @param currentStatus Current status to do status transition
* @param targetStatus Target status to do status transition
* @return Lifecycle action or null if target is not reachable
* @throws APIImportExportException If getting lifecycle action failed
*/
public static String getLifeCycleAction(String tenantDomain, String currentStatus, String targetStatus, APIProvider provider) throws APIManagementException {
// No need to change the lifecycle if both the statuses are same
if (StringUtils.equalsIgnoreCase(currentStatus, targetStatus)) {
return null;
}
LifeCycle lifeCycle = new LifeCycle();
// Parse DOM of APILifeCycle
try {
String data = provider.getLifecycleConfiguration(tenantDomain);
DocumentBuilderFactory factory = APIUtil.getSecuredDocumentBuilder();
DocumentBuilder builder = factory.newDocumentBuilder();
ByteArrayInputStream inputStream = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8));
Document doc = builder.parse(inputStream);
Element root = doc.getDocumentElement();
// Get all nodes with state
NodeList states = root.getElementsByTagName("state");
int nStates = states.getLength();
for (int i = 0; i < nStates; i++) {
Node node = states.item(i);
Node id = node.getAttributes().getNamedItem("id");
if (id != null && !id.getNodeValue().isEmpty()) {
LifeCycleTransition lifeCycleTransition = new LifeCycleTransition();
NodeList transitions = node.getChildNodes();
int nTransitions = transitions.getLength();
for (int j = 0; j < nTransitions; j++) {
Node transition = transitions.item(j);
// Add transitions
if (ImportExportConstants.NODE_TRANSITION.equals(transition.getNodeName())) {
Node target = transition.getAttributes().getNamedItem("target");
Node action = transition.getAttributes().getNamedItem("event");
if (target != null && action != null) {
lifeCycleTransition.addTransition(target.getNodeValue().toLowerCase(), action.getNodeValue());
}
}
}
lifeCycle.addLifeCycleState(id.getNodeValue().toLowerCase(), lifeCycleTransition);
}
}
} catch (ParserConfigurationException | SAXException e) {
throw new APIManagementException("Error parsing APILifeCycle for tenant: " + tenantDomain, e);
} catch (UnsupportedEncodingException e) {
throw new APIManagementException("Error parsing unsupported encoding for APILifeCycle in tenant: " + tenantDomain, e);
} catch (IOException e) {
throw new APIManagementException("Error reading APILifeCycle for tenant: " + tenantDomain, e);
}
// Retrieve lifecycle action
LifeCycleTransition transition = lifeCycle.getTransition(currentStatus.toLowerCase());
if (transition != null) {
return transition.getAction(targetStatus.toLowerCase());
}
return null;
}
use of org.wso2.ei.dashboard.core.rest.model.NodeList in project carbon-business-process by wso2.
the class NotificationScheduler method publishSMSNotifications.
/**
* Publish SMS notifications by extracting the information from the incoming message rendering tags
* <htd:renderings>
* <htd:rendering type="wso2:email" xmlns:wso2="http://wso2.org/ht/schema/renderings/">
* <wso2:to name="to" type="xsd:string">wso2bpsemail@wso2.com</wso2:to>
* <wso2:subject name="subject" type="xsd:string">email subject to user</wso2:subject>
* <wso2:body name="body" type="xsd:string">Hi email notifications</wso2:body>
* </htd:rendering>
* <htd:rendering type="wso2:sms" xmlns:wso2="http://wso2.org/ht/schema/renderings/">
* <wso2:receiver name="receiver" type="xsd:string">94777459299</wso2:receiver>
* <wso2:body name="body" type="xsd:string">Hi $firstname$</wso2:body>
* </htd:rendering>
* </htd:renderings>
* @param task Task Dao Object for this notification task
* @param taskConfiguration task Configuration for this notification task instance
*/
public void publishSMSNotifications(TaskDAO task, HumanTaskBaseConfiguration taskConfiguration) throws IOException, SAXException, ParserConfigurationException {
String renderingSMS = CommonTaskUtil.getRendering(task, taskConfiguration, new QName(HumanTaskConstants.RENDERING_NAMESPACE, HumanTaskConstants.RENDERING_TYPE_SMS));
if (renderingSMS != null) {
Map<String, String> dynamicPropertiesForSms = new HashMap<String, String>();
Element rootSMS = DOMUtils.stringToDOM(renderingSMS);
if (rootSMS != null) {
String smsReceiver = null;
String smsBody = null;
if (log.isDebugEnabled()) {
log.debug("Parsing SMS notification rendering element 'receiver' for notification id " + task.getId());
}
NodeList smsReceiverList = rootSMS.getElementsByTagNameNS(HumanTaskConstants.RENDERING_NAMESPACE, HumanTaskConstants.SMS_RECEIVER_TAG);
if (smsReceiverList != null && smsReceiverList.getLength() > 0) {
smsReceiver = smsReceiverList.item(0).getTextContent();
} else {
log.warn("SMS notification rendering element 'receiver' not specified for notification with id " + task.getId());
}
NodeList smsBodyList = rootSMS.getElementsByTagNameNS(HumanTaskConstants.RENDERING_NAMESPACE, HumanTaskConstants.EMAIL_OR_SMS_BODY_TAG);
if (log.isDebugEnabled()) {
log.debug("Parsing SMS notification rendering element 'body' for notification id " + task.getId());
}
if (smsBodyList != null && smsBodyList.getLength() > 0) {
smsBody = smsBodyList.item(0).getTextContent();
} else {
log.warn("SMS notification rendering element 'body' not specified for notification with id " + task.getId());
}
dynamicPropertiesForSms.put(HumanTaskConstants.ARRAY_SMS_NO, smsReceiver);
String adaptorName = getAdaptorName(task.getName(), HumanTaskConstants.RENDERING_TYPE_SMS);
if (!smsAdapterNames.contains(adaptorName)) {
OutputEventAdapterConfiguration outputEventAdapterConfiguration = createOutputEventAdapterConfiguration(adaptorName, HumanTaskConstants.RENDERING_TYPE_SMS, HumanTaskConstants.SMS_MESSAGE_FORMAT);
try {
HumanTaskServiceComponent.getOutputEventAdapterService().create(outputEventAdapterConfiguration);
smsAdapterNames.add(adaptorName);
} catch (OutputEventAdapterException e) {
log.error("Unable to create Output Event Adapter : " + adaptorName, e);
}
}
HumanTaskServiceComponent.getOutputEventAdapterService().publish(adaptorName, dynamicPropertiesForSms, smsBody);
// smsAdapter.publish(smsBody, dynamicPropertiesForSms);
}
} else {
log.warn("SMS Rendering type not found for task definition with task id " + task.getId());
}
}
use of org.wso2.ei.dashboard.core.rest.model.NodeList in project carbon-business-process by wso2.
the class NotificationScheduler method publishEmailNotifications.
/**
* Publish Email notifications by extracting the information from the incoming message rendering tags
* <htd:renderings>
* <htd:rendering type="wso2:email" xmlns:wso2="http://wso2.org/ht/schema/renderings/">
* <wso2:to name="to" type="xsd:string">wso2bpsemail@wso2.com</wso2:to>
* <wso2:subject name="subject" type="xsd:string">email subject to user</wso2:subject>
* <wso2:body name="body" type="xsd:string">Hi email notifications</wso2:body>
* </htd:rendering>
* <htd:rendering type="wso2:sms" xmlns:wso2="http://wso2.org/ht/schema/renderings/">
* <wso2:receiver name="receiver" type="xsd:string">94777459299</wso2:receiver>
* <wso2:body name="body" type="xsd:string">Hi $firstname$</wso2:body>
* </htd:rendering>
*</htd:renderings>
*
* @param task TaskDAO object for this notification task instance
* @param taskConfiguration task configuration instance for this notification task definition
*/
public void publishEmailNotifications(TaskDAO task, HumanTaskBaseConfiguration taskConfiguration) throws IOException, SAXException, ParserConfigurationException {
String rendering = CommonTaskUtil.getRendering(task, taskConfiguration, new QName(HumanTaskConstants.RENDERING_NAMESPACE, HumanTaskConstants.RENDERING_TYPE_EMAIL));
if (rendering != null) {
Map<String, String> dynamicPropertiesForEmail = new HashMap<String, String>();
Element root = DOMUtils.stringToDOM(rendering);
if (root != null) {
String emailBody = null;
String mailSubject = null;
String mailTo = null;
String contentType = null;
NodeList mailToList = root.getElementsByTagNameNS(HumanTaskConstants.RENDERING_NAMESPACE, HumanTaskConstants.EMAIL_TO_TAG);
if (log.isDebugEnabled()) {
log.debug("Parsing Email notification rendering element to for notification id " + task.getId());
}
if (mailToList != null && mailToList.getLength() > 0) {
mailTo = mailToList.item(0).getTextContent();
} else {
log.warn("Email to address not specified for email notification with notification id " + task.getId());
}
NodeList mailSubjectList = root.getElementsByTagNameNS(HumanTaskConstants.RENDERING_NAMESPACE, HumanTaskConstants.EMAIL_SUBJECT_TAG);
if (log.isDebugEnabled()) {
log.debug("Paring Email notification rendering element subject " + task.getId());
}
if (mailSubjectList != null && mailSubjectList.getLength() > 0) {
mailSubject = mailSubjectList.item(0).getTextContent();
} else {
log.warn("Email subject not specified for email notification with notification id " + task.getId());
}
NodeList mailContentType = root.getElementsByTagNameNS(HumanTaskConstants.RENDERING_NAMESPACE, HumanTaskConstants.EMAIL_CONTENT_TYPE_TAG);
if (log.isDebugEnabled()) {
log.debug("Paring Email notification rendering element contentType " + task.getId());
}
if (mailContentType != null && mailContentType.getLength() > 0) {
contentType = mailContentType.item(0).getTextContent();
} else {
contentType = HumanTaskConstants.CONTENT_TYPE_TEXT_PLAIN;
log.warn("Email contentType not specified for email notification with notification id " + task.getId() + ". Using text/plain.");
}
if (log.isDebugEnabled()) {
log.debug("Parsing Email notification rendering element body tag for notification id " + task.getId());
}
NodeList emailBodyList = root.getElementsByTagNameNS(HumanTaskConstants.RENDERING_NAMESPACE, HumanTaskConstants.EMAIL_OR_SMS_BODY_TAG);
if (emailBodyList != null && emailBodyList.getLength() > 0) {
emailBody = emailBodyList.item(0).getTextContent();
} else {
log.warn("Email notification message body not specified for notification with id " + task.getId());
}
dynamicPropertiesForEmail.put(HumanTaskConstants.ARRAY_EMAIL_ADDRESS, mailTo);
dynamicPropertiesForEmail.put(HumanTaskConstants.ARRAY_EMAIL_SUBJECT, mailSubject);
dynamicPropertiesForEmail.put(HumanTaskConstants.ARRAY_EMAIL_TYPE, contentType);
String adaptorName = getAdaptorName(task.getName(), HumanTaskConstants.RENDERING_TYPE_EMAIL);
if (!emailAdapterNames.contains(adaptorName)) {
OutputEventAdapterConfiguration outputEventAdapterConfiguration = createOutputEventAdapterConfiguration(adaptorName, HumanTaskConstants.RENDERING_TYPE_EMAIL, HumanTaskConstants.EMAIL_MESSAGE_FORMAT);
try {
HumanTaskServiceComponent.getOutputEventAdapterService().create(outputEventAdapterConfiguration);
emailAdapterNames.add(adaptorName);
} catch (OutputEventAdapterException e) {
log.error("Unable to create Output Event Adapter : " + adaptorName, e);
}
}
HumanTaskServiceComponent.getOutputEventAdapterService().publish(adaptorName, dynamicPropertiesForEmail, emailBody);
// emailAdapter.publish(emailBody, dynamicPropertiesForEmail);
}
} else {
log.warn("Email Rendering type not found for task definition with task id " + task.getId());
}
}
use of org.wso2.ei.dashboard.core.rest.model.NodeList in project carbon-business-process by wso2.
the class HTRenderingApiImpl method getRenderingInputElements.
/**
* @param taskIdentifier : interested task identifier
* @return set of input renderings wrapped within InputType
* @throws IllegalArgumentFault : error occured while retrieving renderings from task definition
* @throws IOException If an error occurred while reading from the input source
* @throws SAXException If the content in the input source is invalid
*/
private InputType getRenderingInputElements(URI taskIdentifier) throws IllegalArgumentFault, IOException, SAXException, IllegalOperationFault, IllegalAccessFault, IllegalStateFault, XPathExpressionException {
// TODO Chaching : check cache against task id for input renderings
QName renderingType = new QName(htRenderingNS, "input", "wso2");
String inputRenderings = (String) taskOps.getRendering(taskIdentifier, renderingType);
// Create input element
InputType renderingInputs = null;
// check availability of input renderings
if (inputRenderings != null && inputRenderings.length() > 0) {
// parse input renderings
Element inputRenderingsElement = DOMUtils.stringToDOM(inputRenderings);
// retrieve input elements
NodeList inputElementList = inputRenderingsElement.getElementsByTagNameNS(htRenderingNS, "element");
Element taskInputMsgElement = DOMUtils.stringToDOM((String) taskOps.getInput(taskIdentifier, null));
if (inputElementList != null && inputElementList.getLength() > 0) {
// hold number of input element
int inputElementNum = inputElementList.getLength();
InputElementType[] inputElements = new InputElementType[inputElementNum];
for (int i = 0; i < inputElementNum; i++) {
Element tempElement = (Element) inputElementList.item(i);
String label = tempElement.getElementsByTagNameNS(htRenderingNS, "label").item(0).getTextContent();
String value = tempElement.getElementsByTagNameNS(htRenderingNS, "value").item(0).getTextContent();
// if the value starts with '/' then considered as an xpath and evaluate over received Input Message
if (value.startsWith("/") && taskInputMsgElement != null) {
// value represents xpath. evaluate against the input message
String xpathValue = evaluateXPath(value, taskInputMsgElement, inputRenderingsElement.getOwnerDocument());
if (xpathValue != null) {
value = xpathValue;
}
}
inputElements[i] = new InputElementType();
inputElements[i].setLabel(label);
inputElements[i].setValue(value);
}
renderingInputs = new InputType();
renderingInputs.setElement(inputElements);
// TODO cache renderingInputs against task instance id
}
}
return renderingInputs;
}
Aggregations