Search in sources :

Example 36 with Scope

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;
}
Also used : ActivityInterface(org.wso2.carbon.bpel.ui.bpel2svg.ActivityInterface) SVGDimension(org.wso2.carbon.bpel.ui.bpel2svg.SVGDimension)

Example 37 with Scope

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);
}
Also used : ActivityInterface(org.wso2.carbon.bpel.ui.bpel2svg.ActivityInterface)

Example 38 with Scope

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);
}
Also used : EnableEventListType(org.wso2.carbon.bpel.stub.mgt.types.EnableEventListType) ScopeEventType(org.wso2.carbon.bpel.stub.mgt.types.ScopeEventType) ArrayList(java.util.ArrayList)

Example 39 with Scope

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();
}
Also used : RestVariableCollection(org.wso2.carbon.bpmn.rest.model.runtime.RestVariableCollection) BPMNConflictException(org.wso2.carbon.bpmn.rest.common.exception.BPMNConflictException) XMLStreamReader(javax.xml.stream.XMLStreamReader) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JAXBContext(javax.xml.bind.JAXBContext) RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) List(java.util.List) ArrayList(java.util.ArrayList) Unmarshaller(javax.xml.bind.Unmarshaller) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) RuntimeService(org.activiti.engine.RuntimeService) StreamSource(javax.xml.transform.stream.StreamSource) ActivitiException(org.activiti.engine.ActivitiException) ServletException(javax.servlet.ServletException) BPMNRestException(org.wso2.carbon.bpmn.rest.common.exception.BPMNRestException) BPMNContentNotSupportedException(org.wso2.carbon.bpmn.rest.common.exception.BPMNContentNotSupportedException) XMLStreamException(javax.xml.stream.XMLStreamException) BPMNConflictException(org.wso2.carbon.bpmn.rest.common.exception.BPMNConflictException) JAXBException(javax.xml.bind.JAXBException) NotFoundException(javax.ws.rs.NotFoundException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) IOException(java.io.IOException) RestApiBasicAuthenticationException(org.wso2.carbon.bpmn.rest.common.exception.RestApiBasicAuthenticationException) DataResponse(org.wso2.carbon.bpmn.rest.model.common.DataResponse) Response(javax.ws.rs.core.Response) ProcessInstanceResponse(org.wso2.carbon.bpmn.rest.model.runtime.ProcessInstanceResponse) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 40 with Scope

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();
}
Also used : DataResponse(org.wso2.carbon.bpmn.rest.model.common.DataResponse) Response(javax.ws.rs.core.Response) ProcessInstanceResponse(org.wso2.carbon.bpmn.rest.model.runtime.ProcessInstanceResponse) Execution(org.activiti.engine.runtime.Execution) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Scope (org.wso2.carbon.apimgt.core.models.Scope)41 HashMap (java.util.HashMap)25 RestVariable (org.wso2.carbon.bpmn.rest.engine.variable.RestVariable)25 Test (org.testng.annotations.Test)23 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)19 Response (javax.ws.rs.core.Response)16 ScopeInfo (org.wso2.carbon.apimgt.core.auth.dto.ScopeInfo)15 FileInputStream (java.io.FileInputStream)14 API (org.wso2.carbon.apimgt.core.models.API)14 ArrayList (java.util.ArrayList)13 KeyManager (org.wso2.carbon.apimgt.core.api.KeyManager)13 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)13 Map (java.util.Map)12 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)12 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)12 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)12 IdentityProvider (org.wso2.carbon.apimgt.core.api.IdentityProvider)11 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)11 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)10 Scope (org.wso2.ballerinalang.compiler.semantics.model.Scope)10