use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-business-process by wso2.
the class IfImpl method getArrows.
/**
* Get the arrow coordinates of the activities
*
* @param doc SVG document which defines the components including shapes, gradients etc. of the activity
* @return An element which contains the arrow coordinates of the If activity and its subActivities
*/
protected Element getArrows(SVGDocument doc) {
if (subActivities != null) {
ActivityInterface prevActivity = null;
ActivityInterface prevElseActivity = null;
ActivityInterface activity = null;
ActivityInterface seqActivity = null;
boolean throwOrNot = true;
String id = null;
// Coordinates of the start icon exit arrow
SVGCoordinates myStartCoords = getStartIconExitArrowCoords();
// Coordinates of the end icon entry arrow
SVGCoordinates myExitCoords = getEndIconEntryArrowCoords();
// Coordinates of the Else activity start icon entry arrow
SVGCoordinates myStartElseCoords = getStartIconElseArrowCoords();
SVGCoordinates exitCoords = null;
SVGCoordinates activityEntryCoords = null;
SVGCoordinates activityExitCoords = null;
Iterator<ActivityInterface> itr = subActivities.iterator();
Element subGroup = doc.createElementNS(SVGNamespace.SVG_NAMESPACE, "g");
// Iterates through all the subActivities
while (itr.hasNext()) {
activity = itr.next();
// Gets the entry and exit coordinates of the iterated activity
activityEntryCoords = activity.getEntryArrowCoords();
activityExitCoords = activity.getExitArrowCoords();
// Checks if the iterated activity is an instance of ElseIf or Else activity
if (activity instanceof ElseIfImpl || activity instanceof ElseImpl) {
// Checks whether there is a previous activity and if so whether that activity is an ElseIf
if (prevActivity != null && prevActivity instanceof ElseIfImpl) {
// Get the exit arrow coordinates of the ElseIf activity
exitCoords = ((ElseIfInterface) prevActivity).getNextElseExitArrowCoords();
// id is assigned with the id of the previous activity + id of the current activity
id = prevActivity.getId() + "-" + activity.getId();
// Checks whether the activity is an instance of Else
if (activity instanceof ElseImpl) {
// Gets the boolean value assigned inside ElseImpl when a throw activity is in Else
boolean check = ((ElseImpl) activity).throwOrNot;
// Define the entry arrow flow coordinates for the activity
subGroup.appendChild(getArrowDefinition(doc, exitCoords.getXLeft(), exitCoords.getYTop(), activityEntryCoords.getXLeft() - getEndIconWidth() / 2, exitCoords.getYTop(), id));
// If there is a Throw activity inside Else, no exit arrow from Throw activity
if (check != true) {
subGroup.appendChild(getArrowDefinition(doc, activityExitCoords.getXLeft(), activityExitCoords.getYTop(), myExitCoords.getXLeft(), myExitCoords.getYTop(), id));
}
} else if (activity instanceof ElseIfImpl) {
// Checks whether the activity is an instance of ElseIf
// Gets the boolean value assigned inside ElseIfImpl when a throw activity is in ElseIf
boolean check = ((ElseIfImpl) activity).throwOrNot;
// Define the entry arrow flow coordinates for the activity
subGroup.appendChild(getArrowDefinition(doc, exitCoords.getXLeft(), exitCoords.getYTop(), activityEntryCoords.getXLeft(), activityEntryCoords.getYTop(), id));
// If there is a Throw activity inside ElseIf, no exit arrow from Throw activity
if (check != true) {
subGroup.appendChild(getArrowDefinition(doc, activityExitCoords.getXLeft(), activityExitCoords.getYTop(), myExitCoords.getXLeft(), myExitCoords.getYTop(), id));
}
} else {
// Entry and exit arrow flows defined for other activities except for instances of Elseif and
// Else
subGroup.appendChild(getArrowDefinition(doc, exitCoords.getXLeft(), exitCoords.getYTop(), activityEntryCoords.getXLeft(), activityEntryCoords.getYTop(), id));
subGroup.appendChild(getArrowDefinition(doc, activityExitCoords.getXLeft(), activityExitCoords.getYTop(), myExitCoords.getXLeft(), myExitCoords.getYTop(), id));
}
} else if (prevActivity instanceof ThrowImpl && activity instanceof ElseImpl) {
// IF conditon fifnished --> ELSE IF ( previous activity is null and its is not an instance of
// ElseIf)
/*Checks if the previous activity is a Throw and if the current activity an Else, if so no exit
arrow flows only entry arrow flows.
*/
subGroup.appendChild(getArrowDefinition(doc, myStartElseCoords.getXLeft(), myStartElseCoords.getYTop(), activityEntryCoords.getXLeft(), activityEntryCoords.getYTop(), id));
} else if (activity instanceof ElseIfImpl) {
// Checks whether the activity is an instance of ElseIf
// Gets the boolean value assigned inside ElseIfImpl when a throw activity is in ElseIf
boolean check = ((ElseIfImpl) activity).throwOrNot;
// Define the entry arrow flow coordinates for the activity
subGroup.appendChild(getArrowDefinition(doc, myStartElseCoords.getXLeft(), myStartElseCoords.getYTop(), activityEntryCoords.getXLeft(), activityEntryCoords.getYTop(), id));
// If there is a Throw activity inside ElseIf, no exit arrow from Throw activity
if (check != true) {
subGroup.appendChild(getArrowDefinition(doc, activityExitCoords.getXLeft(), activityExitCoords.getYTop(), myExitCoords.getXLeft(), myExitCoords.getYTop(), id));
}
} else if (activity instanceof ElseImpl) {
// Checks whether the activity is an instance of Else
// Gets the boolean value assigned inside ElseIfImpl when a throw activity is in Else
boolean check = ((ElseImpl) activity).throwOrNot;
// Define the entry arrow flow coordinates for the activity
subGroup.appendChild(getArrowDefinition(doc, myStartElseCoords.getXLeft(), myStartElseCoords.getYTop(), activityEntryCoords.getXLeft(), activityEntryCoords.getYTop(), id));
// If there is a Throw activity inside Else, no exit arrow from Throw activity
if (check != true) {
subGroup.appendChild(getArrowDefinition(doc, activityExitCoords.getXLeft(), activityExitCoords.getYTop(), myExitCoords.getXLeft(), myExitCoords.getYTop(), id));
}
} else {
id = prevActivity.getId() + "-" + activity.getId();
// flows
if (activity instanceof ThrowImpl) {
subGroup.appendChild(getArrowDefinition(doc, myStartElseCoords.getXLeft(), myStartElseCoords.getYTop(), activityEntryCoords.getXLeft(), activityEntryCoords.getYTop(), id));
} else {
// Define both the entry and the exit arrow flows to the activity
subGroup.appendChild(getArrowDefinition(doc, myStartElseCoords.getXLeft(), myStartElseCoords.getYTop(), activityEntryCoords.getXLeft(), activityEntryCoords.getYTop(), id));
subGroup.appendChild(getArrowDefinition(doc, activityExitCoords.getXLeft(), activityExitCoords.getYTop(), myExitCoords.getXLeft(), myExitCoords.getYTop(), id));
}
}
} else if (activity instanceof ThrowImpl) {
// Checks if the current activity a Throw activity, if so no exit arrow flows only entry arrow flows
subGroup.appendChild(getArrowDefinition(doc, myStartCoords.getXLeft(), myStartCoords.getYTop(), activityEntryCoords.getXLeft(), activityEntryCoords.getYTop(), id));
} else if (activity instanceof SourceImpl || activity instanceof TargetImpl || activity instanceof SourcesImpl || activity instanceof TargetsImpl) {
// Checks if the current activity a Source/s or Target/s activity, if so no exit or entry arrow flows
// as no icons are defined
// No arrow flows for Sources or Targets..
} else {
if (prevActivity != null) {
// Gets the coordinates of the exit arrows of the previous activity
exitCoords = prevActivity.getExitArrowCoords();
id = prevActivity.getId() + "-" + activity.getId();
// arrow flows as no icons are defined
if (prevActivity instanceof SourceImpl || prevActivity instanceof TargetImpl || prevActivity instanceof SourcesImpl || prevActivity instanceof TargetsImpl) {
// No arrow flows for Sources or Targets..
} else {
subGroup.appendChild(getArrowDefinition(doc, exitCoords.getXLeft(), exitCoords.getYTop(), activityEntryCoords.getXLeft(), activityEntryCoords.getYTop(), id));
}
} else {
// Checks whether the activity is a Sequence
if (activity instanceof SequenceImpl) {
List<ActivityInterface> sub = activity.getSubActivities();
// Iterates through the subActivities
Iterator<ActivityInterface> as = sub.iterator();
while (as.hasNext()) {
seqActivity = as.next();
// Checks if the subActivity is a Throw activity
if (seqActivity instanceof ThrowImpl) {
throwOrNot = true;
// if condition breaks if the subActivity is a Throw activity
break;
} else {
throwOrNot = false;
}
}
// If its a Throw activity , no exit arrow flow only entry arrow flow to the activity
if (throwOrNot == true) {
subGroup.appendChild(getArrowDefinition(doc, myStartCoords.getXLeft(), myStartCoords.getYTop(), activityEntryCoords.getXLeft(), activityEntryCoords.getYTop(), id));
} else {
// If not, define both the entry and the exit arrow flows to the activity
subGroup.appendChild(getArrowDefinition(doc, myStartCoords.getXLeft(), myStartCoords.getYTop(), activityEntryCoords.getXLeft(), activityEntryCoords.getYTop(), id));
subGroup.appendChild(getArrowDefinition(doc, activityExitCoords.getXLeft(), activityExitCoords.getYTop(), myExitCoords.getXLeft(), myExitCoords.getYTop(), id));
}
} else {
// Define both the entry and the exit arrow flows to the activity
subGroup.appendChild(getArrowDefinition(doc, myStartCoords.getXLeft(), myStartCoords.getYTop(), activityEntryCoords.getXLeft(), activityEntryCoords.getYTop(), id));
subGroup.appendChild(getArrowDefinition(doc, activityExitCoords.getXLeft(), activityExitCoords.getYTop(), myExitCoords.getXLeft(), myExitCoords.getYTop(), id));
}
}
}
// current activity is assigned to the previous activity
prevActivity = activity;
}
return subGroup;
}
return null;
}
use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-business-process by wso2.
the class IfImpl method isSimpleLayout.
/**
* @return false- if the subActivities are instances of ElseIf or Else
* true - otherwise
*/
private boolean isSimpleLayout() {
boolean simple = true;
ActivityInterface activity = null;
// Iterates through the subActivities
Iterator<ActivityInterface> itr = getSubActivities().iterator();
while (itr.hasNext()) {
activity = itr.next();
// if the activity is an instance of ElseIf or Else, break the if condition
if (activity instanceof ElseIfImpl || activity instanceof ElseImpl) {
simple = false;
break;
}
}
return simple;
}
use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-business-process by wso2.
the class PNGGenarateServlet method processRequest.
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
*
* @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(PNGGenarateServlet.class);
HttpSession session = request.getSession(true);
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;
ProcessManagementServiceClient client;
SVGInterface svg;
String svgStr;
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/png"
response.setContentType("image/png");
// Create an instance of ServletOutputStream to write the output
ServletOutputStream sos = response.getOutputStream();
// Convert the image as a byte array of a PNG
byte[] pngBytes = svg.toPNGBytes();
// stream to write binary data into the response
sos.write(pngBytes);
sos.flush();
sos.close();
} catch (ProcessManagementException e) {
log.error("PNG Generation Error", e);
}
}
use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-business-process by wso2.
the class ProcessInstanceService method createExecutionVariable.
protected Response createExecutionVariable(Execution execution, boolean override, int variableType, HttpServletRequest httpServletRequest) throws IOException, ServletException {
boolean debugEnabled = log.isDebugEnabled();
if (debugEnabled) {
log.debug("httpServletRequest.getContentType():" + httpServletRequest.getContentType());
}
Response.ResponseBuilder responseBuilder = Response.ok();
if (debugEnabled) {
log.debug("Processing non binary variable");
}
List<RestVariable> inputVariables = new ArrayList<>();
List<RestVariable> resultVariables = new ArrayList<>();
try {
if (Utils.isApplicationJsonRequest(httpServletRequest)) {
ObjectMapper objectMapper = new ObjectMapper();
@SuppressWarnings("unchecked") List<Object> variableObjects = (List<Object>) objectMapper.readValue(httpServletRequest.getInputStream(), List.class);
for (Object restObject : variableObjects) {
RestVariable restVariable = objectMapper.convertValue(restObject, RestVariable.class);
inputVariables.add(restVariable);
}
} else if (Utils.isApplicationXmlRequest(httpServletRequest)) {
JAXBContext jaxbContext;
try {
XMLInputFactory xif = XMLInputFactory.newInstance();
xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
XMLStreamReader xsr = xif.createXMLStreamReader(new StreamSource(httpServletRequest.getInputStream()));
jaxbContext = JAXBContext.newInstance(RestVariableCollection.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
RestVariableCollection restVariableCollection = (RestVariableCollection) jaxbUnmarshaller.unmarshal(xsr);
if (restVariableCollection == null) {
throw new ActivitiIllegalArgumentException("xml request body could not be transformed to a " + "RestVariable Collection instance.");
}
List<RestVariable> restVariableList = restVariableCollection.getRestVariables();
if (restVariableList.size() == 0) {
throw new ActivitiIllegalArgumentException("xml request body could not identify any rest " + "variables to be updated");
}
for (RestVariable restVariable : restVariableList) {
inputVariables.add(restVariable);
}
} catch (JAXBException | IOException e) {
throw new ActivitiIllegalArgumentException("xml request body could not be transformed to a " + "RestVariable instance.", e);
}
}
} catch (Exception e) {
throw new ActivitiIllegalArgumentException("Failed to serialize to a RestVariable instance", e);
}
if (inputVariables.size() == 0) {
throw new ActivitiIllegalArgumentException("Request didn't contain a list of variables to create.");
}
RestVariable.RestVariableScope sharedScope = null;
RestVariable.RestVariableScope varScope;
Map<String, Object> variablesToSet = new HashMap<>();
for (RestVariable var : inputVariables) {
// Validate if scopes match
varScope = var.getVariableScope();
if (var.getName() == null) {
throw new ActivitiIllegalArgumentException("Variable name is required");
}
if (varScope == null) {
varScope = RestVariable.RestVariableScope.LOCAL;
}
if (sharedScope == null) {
sharedScope = varScope;
}
if (varScope != sharedScope) {
throw new ActivitiIllegalArgumentException("Only allowed to update multiple variables in the same scope.");
}
if (!override && hasVariableOnScope(execution, var.getName(), varScope)) {
throw new BPMNConflictException("Variable '" + var.getName() + "' is already present on execution '" + execution.getId() + "'.");
}
RestResponseFactory restResponseFactory = new RestResponseFactory();
Object actualVariableValue = restResponseFactory.getVariableValue(var);
variablesToSet.put(var.getName(), actualVariableValue);
resultVariables.add(restResponseFactory.createRestVariable(var.getName(), actualVariableValue, varScope, execution.getId(), variableType, false, uriInfo.getBaseUri().toString()));
}
if (!variablesToSet.isEmpty()) {
RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
if (sharedScope == RestVariable.RestVariableScope.LOCAL) {
runtimeService.setVariablesLocal(execution.getId(), variablesToSet);
} else {
if (execution.getParentId() != null) {
// Explicitly set on parent, setting non-local variables on execution itself will override local-variables if exists
runtimeService.setVariables(execution.getParentId(), variablesToSet);
} else {
// Standalone task, no global variables possible
throw new ActivitiIllegalArgumentException("Cannot set global variables on execution '" + execution.getId() + "', task is not part of process.");
}
}
}
RestVariableCollection restVariableCollection = new RestVariableCollection();
restVariableCollection.setRestVariables(resultVariables);
responseBuilder.entity(restVariableCollection);
// }
return responseBuilder.status(Response.Status.CREATED).build();
}
use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-business-process by wso2.
the class ProcessInstanceService method getProcessInstanceDiagram.
@GET
@Path("/{processInstanceId}/diagram")
@Produces(MediaType.APPLICATION_JSON)
public Response getProcessInstanceDiagram(@PathParam("processInstanceId") String processInstanceId) {
ProcessInstance processInstance = getProcessInstanceFromRequest(processInstanceId);
RepositoryService repositoryService = BPMNOSGIService.getRepositoryService();
ProcessDefinition pde = repositoryService.getProcessDefinition(processInstance.getProcessDefinitionId());
if (pde != null && pde.hasGraphicalNotation()) {
RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
InputStream diagramStream = new DefaultProcessDiagramGenerator().generateDiagram(repositoryService.getBpmnModel(pde.getId()), "png", runtimeService.getActiveActivityIds(processInstanceId));
try {
return Response.ok().type("image/png").entity(IOUtils.toByteArray(diagramStream)).build();
} catch (Exception e) {
throw new ActivitiIllegalArgumentException("Error exporting diagram", e);
}
} else {
throw new ActivitiIllegalArgumentException("Process instance with id '" + processInstance.getId() + "' has no graphical notation defined.");
}
}
Aggregations