use of org.wso2.ballerinalang.compiler.semantics.model.Scope 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.ballerinalang.compiler.semantics.model.Scope 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.ballerinalang.compiler.semantics.model.Scope in project carbon-business-process by wso2.
the class BpelUIUtil method updateScopeEvents.
/**
* when scope events defined in deploy.xml is changed in runtime by DD Editor this method is used to get the
* updated events list
* assigned with each scope event. It is got as a string array with the data about the events selected and
* categories into (5 for each) groups. Then these events list is again written back to the corresponding scope
* event
*/
public static void updateScopeEvents(String[] selecttype, List<String> scopeNames, DeploymentDescriptorUpdater deployDescriptorUpdater) {
ArrayList<String> valueArray = selecttype != null ? new ArrayList<String>(Arrays.asList(selecttype)) : new ArrayList<String>();
ListIterator<String> it = valueArray.listIterator();
while (it.hasNext()) {
String nextVal = it.next();
if (!nextVal.equalsIgnoreCase("0") && it.hasNext()) {
it.next();
it.remove();
}
}
String[] allEnabledEvents = valueArray.toArray(new String[valueArray.size()]);
ScopeEventType[] scopeEventTypes = new ScopeEventType[scopeNames.size()];
for (int j = 0; j < scopeNames.size(); j++) {
ScopeEventType scopeEventType = new ScopeEventType();
scopeEventType.setScope(scopeNames.get(j));
String[] events = new String[5];
System.arraycopy(allEnabledEvents, 0, events, 0, 5);
ArrayList<String> actualEventsList = new ArrayList<String>();
for (String event : events) {
if (!event.equalsIgnoreCase("0")) {
actualEventsList.add(event);
}
}
String[] eventsArray = actualEventsList.toArray(new String[actualEventsList.size()]);
EnableEventListType enableEventListType = new EnableEventListType();
enableEventListType.setEnableEvent(eventsArray);
scopeEventType.setEnabledEventList(enableEventListType);
scopeEventTypes[j] = scopeEventType;
}
deployDescriptorUpdater.setScopeEvents(scopeEventTypes);
}
use of org.wso2.ballerinalang.compiler.semantics.model.Scope 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.ballerinalang.compiler.semantics.model.Scope in project carbon-business-process by wso2.
the class ProcessInstanceService method getVariableData.
@GET
@Path("/{processInstanceId}/variables/{variableName}/data")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getVariableData(@PathParam("processInstanceId") String processInstanceId, @PathParam("variableName") String variableName, @Context HttpServletRequest request) {
String scope = uriInfo.getQueryParameters().getFirst("scope");
Execution execution = getExecutionInstanceFromRequest(processInstanceId);
Response.ResponseBuilder responseBuilder = Response.ok();
return responseBuilder.entity(getVariableDataByteArray(execution, variableName, scope, responseBuilder)).build();
}
Aggregations