use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-business-process by wso2.
the class SVGGenerateServlet method processRequest.
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* Handles the HTTP process request which creates the SVG graph for a bpel process
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Log log = LogFactory.getLog(SVGGenerateServlet.class);
HttpSession session = request.getSession(true);
// Get the bpel process id
String pid = CharacterEncoder.getSafeText(request.getParameter("pid"));
ServletConfig config = getServletConfig();
String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
ConfigurationContext configContext = (ConfigurationContext) config.getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
String processDef = null;
ProcessManagementServiceClient client = null;
SVGInterface svg = null;
String svgStr = null;
ServletOutputStream sos = null;
sos = response.getOutputStream();
try {
client = new ProcessManagementServiceClient(cookie, backendServerURL, configContext, request.getLocale());
// Gets the bpel process definition needed to create the SVG from the processId
processDef = client.getProcessInfo(QName.valueOf(pid)).getDefinitionInfo().getDefinition().getExtraElement().toString();
BPELInterface bpel = new BPELImpl();
// Converts the bpel process definition to an omElement which is how the AXIS2 Object Model (AXIOM)
// represents an XML document
OMElement bpelStr = bpel.load(processDef);
/**
* Process the OmElement containing the bpel process definition
* Process the subactivites of the bpel process by iterating through the omElement
*/
bpel.processBpelString(bpelStr);
// Create a new instance of the LayoutManager for the bpel process
LayoutManager layoutManager = BPEL2SVGFactory.getInstance().getLayoutManager();
// Set the layout of the SVG to vertical
layoutManager.setVerticalLayout(true);
// Get the root activity i.e. the Process Activity
layoutManager.layoutSVG(bpel.getRootActivity());
svg = new SVGImpl();
// Set the root activity of the SVG i.e. the Process Activity
svg.setRootActivity(bpel.getRootActivity());
// Set the content type of the HTTP response as "image/svg+xml"
response.setContentType("image/svg+xml");
// Get the SVG graph created for the process as a SVG string
svgStr = svg.generateSVGString();
// Checks whether the SVG string generated contains a value
if (svgStr != null) {
// stream to write binary data into the response
sos.write(svgStr.getBytes(Charset.defaultCharset()));
sos.flush();
sos.close();
}
} catch (ProcessManagementException e) {
log.error("SVG Generation Error", e);
String errorSVG = "<svg version=\"1.1\"\n" + " xmlns=\"http://www.w3.org/2000/svg\"><text y=\"50\">Could not display SVG</text></svg>";
sos.write(errorSVG.getBytes(Charset.defaultCharset()));
sos.flush();
sos.close();
}
}
use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-business-process by wso2.
the class ScopeImpl method getDimensions.
/**
* At the start: width=0, height=0
*
* @return dimensions of the composite activity i.e. the final width and height after doing calculations by
* iterating
* through the dimensions of the subActivities
*/
@Override
public SVGDimension getDimensions() {
if (dimensions == null) {
int width = 0;
int height = 0;
int coreWidth = 0;
int coreHeight = 0;
int conWidth = 0;
int conHeight = 0;
// Set the dimensions at the start to (0,0)
dimensions = new SVGDimension(coreWidth, coreHeight);
coreDimensions = new SVGDimension(coreWidth, coreHeight);
conditionalDimensions = new SVGDimension(conWidth, conHeight);
// Dimensons of the subActivities
SVGDimension subActivityDim = null;
ActivityInterface activity = null;
// Iterates through the subActivites inside the composite activity
Iterator<ActivityInterface> itr = getSubActivities().iterator();
while (itr.hasNext()) {
activity = itr.next();
// Gets the dimensions of each subActivity separately
subActivityDim = activity.getDimensions();
/*Checks whether the subActivity is any of the handlers i.e. FaultHandler, TerminationHandler,
CompensateHandler
or EventHandler
*/
if (activity instanceof FaultHandlerImpl || activity instanceof TerminationHandlerImpl || activity instanceof CompensationHandlerImpl || activity instanceof EventHandlerImpl) {
if (subActivityDim.getHeight() > conHeight) {
// height of the icon is added to the conditional height
conHeight = subActivityDim.getHeight();
}
// width of the subActivities added to the conditional width
conWidth += subActivityDim.getWidth();
} else if (activity instanceof RepeatUntilImpl || activity instanceof ForEachImpl || activity instanceof WhileImpl || activity instanceof IfImpl) {
/* If the activity is an instance of ForEach, Repeat Until, While or If activity,
ySpacing = 70 is also added to the core height of the composite activity as the start icons
of those activities are placed on the scope of the composite activity, so it requires more spacing.
*/
if (subActivityDim.getWidth() > coreWidth) {
// width of the subActivities added to the core width
coreWidth = subActivityDim.getWidth();
}
coreHeight += subActivityDim.getHeight() + getYSpacing();
} else {
// If the subActivites are not instances of any handlers
if (subActivityDim.getWidth() > coreWidth) {
// width of the subActivities added to the core width
coreWidth = subActivityDim.getWidth();
}
// height of the subActivities added to the core height
coreHeight += subActivityDim.getHeight();
}
}
// Spacing the core height by adding ySpacing + startIcon height + endIcon height
coreHeight += getYSpacing() + getStartIconHeight() + getEndIconHeight();
// Check if its a simple layout
if (!isSimpleLayout()) {
coreWidth += getXSpacing();
}
conHeight += getHandlerAdjustment();
// Setting the core dimensions after calculations
coreDimensions.setHeight(coreHeight);
coreDimensions.setWidth(coreWidth);
// Setting the conditional dimensions after calculations
conditionalDimensions.setHeight(conHeight);
conditionalDimensions.setWidth(conWidth);
// Checks if the core height is greater than the conditional height
if (coreHeight > conHeight) {
height = coreHeight;
} else {
height = conHeight;
}
// core width and conditional width is added to the final width of the composite activity
width = coreWidth + conWidth;
// Get the final height and width by adding Xspacing and Yspacing
height += getYSpacing();
width += getXSpacing();
// Set the Calculated dimensions for the SVG height and width
dimensions.setWidth(width);
dimensions.setHeight(height);
}
return dimensions;
}
use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-business-process by wso2.
the class ScopeImpl method layoutVertical.
/**
* Sets the x and y positions of the activities
* At the start: startXLeft=0, startYTop=0
* centreOfMyLayout- center of the the SVG
*
* @param startXLeft x-coordinate
* @param startYTop y-coordinate
*/
public void layoutVertical(int startXLeft, int startYTop) {
// Aligns the activities to the center of the layout
int centreOfMyLayout = startXLeft + (getDimensions().getWidth() / 2);
int xLeft = 0;
int yTop = 0;
int endXLeft = 0;
int endYTop = 0;
int centerNHLayout = startXLeft + (getCoreDimensions().getWidth() / 2);
// Set the dimensions
getDimensions().setXLeft(startXLeft);
getDimensions().setYTop(startYTop);
// Set the xLeft and yTop of the core dimensions
getCoreDimensions().setXLeft(startXLeft + (getXSpacing() / 2));
getCoreDimensions().setYTop(startYTop + (getYSpacing() / 2));
/* Checks whether its a simple layout i.e. whether the subActivities are any handlers
if so --> true , else --> false
*/
if (isSimpleLayout()) {
// Positioning the startIcon
xLeft = centreOfMyLayout - (getStartIconWidth() / 2);
yTop = startYTop + (getYSpacing() / 2);
// Positioning the endIcon
endXLeft = centreOfMyLayout - (getEndIconWidth() / 2);
endYTop = startYTop + getDimensions().getHeight() - getEndIconHeight() - (getYSpacing() / 2);
} else {
// Positioning the startIcon
xLeft = centerNHLayout - (getStartIconWidth() / 2) + (getXSpacing() / 2);
yTop = getCoreDimensions().getYTop() + (getYSpacing() / 2);
// Positioning the endIcon
endXLeft = centerNHLayout - (getEndIconWidth() / 2) + (getXSpacing() / 2);
endYTop = getCoreDimensions().getYTop() + getCoreDimensions().getHeight() - getEndIconHeight() - (getYSpacing() / 2);
}
ActivityInterface activity = null;
Iterator<ActivityInterface> itr = getSubActivities().iterator();
int childYTop = 0;
int childXLeft = 0;
/* Checks whether its a simple layout i.e. whether the subActivities are any handlers
if so --> true , else --> false
*/
if (isSimpleLayout()) {
// Adjusting the childXLeft and childYTop positions
childYTop = yTop + getStartIconHeight() + (getYSpacing() / 2);
childXLeft = startXLeft + (getXSpacing() / 2);
} else {
// Adjusting the childXLeft and childYTop positions
childYTop = getCoreDimensions().getYTop() + getStartIconHeight() + (getYSpacing() / 2);
childXLeft = getCoreDimensions().getXLeft() + (getXSpacing() / 2);
}
// Iterates through the subActivities
while (itr.hasNext()) {
activity = itr.next();
// Checks whether the activity is of any handler type
if (activity instanceof FaultHandlerImpl || activity instanceof TerminationHandlerImpl || activity instanceof CompensationHandlerImpl || activity instanceof EventHandlerImpl) {
} else if (activity instanceof RepeatUntilImpl || activity instanceof ForEachImpl || activity instanceof WhileImpl || activity instanceof IfImpl) {
/* If the activity inside Scope activity is an instance of ForEach, Repeat Until, While or If activity,
then increase the yTop position of start icon of those activities , as the start icon is placed
on the scope/box which contains the subActivities.This requires more spacing, so the yTop of the
activity following it i.e. the activity after it is also increased.
*/
int x = childYTop + (getYSpacing() / 2);
// Sets the xLeft and yTop position of the iterated activity
activity.layout(childXLeft, x);
// Calculate the yTop position of the next activity
childXLeft += activity.getDimensions().getWidth();
} else {
// Sets the xLeft and yTop position of the iterated activity
activity.layout(childXLeft, childYTop);
// Calculate the yTop position of the next activity
childXLeft += activity.getDimensions().getWidth();
}
}
// Process Handlers
itr = getSubActivities().iterator();
// Adjusting the childXLeft and childYTop positions
childXLeft = startXLeft + getCoreDimensions().getWidth();
childYTop = yTop + getHandlerAdjustment();
// Iterates through the subActivities
while (itr.hasNext()) {
activity = itr.next();
// Checks whether the activity is of any handler type
if (activity instanceof FaultHandlerImpl || activity instanceof TerminationHandlerImpl || activity instanceof CompensationHandlerImpl || activity instanceof EventHandlerImpl) {
// Sets the xLeft and yTop position of the iterated activity
activity.layout(childXLeft, childYTop);
childXLeft += activity.getDimensions().getWidth();
}
}
// Sets the xLeft and yTop positions of the start icon
setStartIconXLeft(xLeft);
setStartIconYTop(yTop);
// Sets the xLeft and yTop positions of the end icon
setEndIconXLeft(endXLeft);
setEndIconYTop(endYTop);
// Sets the xLeft and yTop positions of the start icon text
setStartIconTextXLeft(startXLeft + BOX_MARGIN);
setStartIconTextYTop(startYTop + BOX_MARGIN + BPEL2SVGFactory.TEXT_ADJUST);
}
use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance 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.carbon.bpel.core.ode.integration.jmx.Instance 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());
}
}
Aggregations