Search in sources :

Example 96 with Scope

use of org.wso2.ballerinalang.compiler.semantics.model.Scope in project carbon-business-process by wso2.

the class FlowImpl 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) {
    if (dimensions != null) {
        // Aligns the activities to the center of the layout
        int centreOfMyLayout = startXLeft + (dimensions.getWidth() / 2);
        // Positioning the startIcon
        int xLeft = centreOfMyLayout - (getStartIconWidth() / 2);
        int yTop = startYTop + (getYSpacing() / 2);
        // Positioning the endIcon
        int endXLeft = centreOfMyLayout - (getEndIconWidth() / 2);
        int endYTop = startYTop + dimensions.getHeight() - getEndIconHeight() - (getYSpacing() / 2);
        ActivityInterface activity = null;
        Iterator<ActivityInterface> itr = getSubActivities().iterator();
        // Adjusting the childXLeft and childYTop positions
        int childYTop = yTop + getStartIconHeight() + (getYSpacing() / 2);
        int childXLeft = startXLeft + (getXSpacing() / 2);
        // Iterates through all the subActivities
        while (itr.hasNext()) {
            activity = itr.next();
            /* If the activity inside Flow activity is an instance of If activity, then setCheckIfinFlow becomes
                true.
                This If check is done to space the subActivities when an If activity is inside a Flow activity.
                This is a special case.
                 */
            if (activity instanceof IfImpl) {
                ((IfImpl) activity).setCheckIfinFlow(true);
            }
            /* If the activity inside Flow 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.
                 */
            if (activity instanceof RepeatUntilImpl || activity instanceof ForEachImpl || activity instanceof WhileImpl || activity instanceof IfImpl) {
                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();
            }
        }
        // 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);
        // Sets the xLeft and yTop positions of the SVG  of the composite activity after setting the dimensions
        getDimensions().setXLeft(startXLeft);
        getDimensions().setYTop(startYTop);
    }
}
Also used : ActivityInterface(org.wso2.carbon.bpel.ui.bpel2svg.ActivityInterface)

Example 97 with Scope

use of org.wso2.ballerinalang.compiler.semantics.model.Scope in project carbon-business-process by wso2.

the class SequenceImpl 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 + (dimensions.getWidth() / 2);
    // Positioning the startIcon
    int xLeft = centreOfMyLayout - (getStartIconWidth() / 2);
    int yTop = startYTop + (getYSpacing() / 2);
    ActivityInterface activity = null;
    Iterator<ActivityInterface> itr = getSubActivities().iterator();
    // Adjusting the childXLeft and childYTop positions
    int childYTop = yTop;
    int childXLeft;
    // Iterates through all the subActivities
    while (itr.hasNext()) {
        activity = itr.next();
        // Sets the xLeft position of the iterated activity : childXleft= center of the layout - (width of the
        // activity icon)/2
        childXLeft = centreOfMyLayout - activity.getDimensions().getWidth() / 2;
        /* If the activity inside Sequence 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.
                 */
        if (activity instanceof RepeatUntilImpl || activity instanceof ForEachImpl || activity instanceof WhileImpl || activity instanceof IfImpl) {
            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
            childYTop += activity.getDimensions().getHeight() + getYSpacing();
        } else {
            // Sets the xLeft and yTop position of the iterated activity
            activity.layout(childXLeft, childYTop);
            // Calculate the yTop position of the next activity
            childYTop += activity.getDimensions().getHeight();
        }
    /*   activity.layout(childXLeft, childYTop);
            childYTop += activity.getDimensions().getHeight();*/
    }
    // Sets the xLeft and yTop positions of the start icon
    setStartIconXLeft(xLeft);
    setStartIconYTop(yTop);
    // Sets the xLeft and yTop positions of the start icon text
    setStartIconTextXLeft(startXLeft + BOX_MARGIN);
    setStartIconTextYTop(startYTop + BOX_MARGIN + BPEL2SVGFactory.TEXT_ADJUST);
    // Sets the xLeft and yTop positions of the SVG  of the composite activity after setting the dimensions
    getDimensions().setXLeft(startXLeft);
    getDimensions().setYTop(startYTop);
}
Also used : ActivityInterface(org.wso2.carbon.bpel.ui.bpel2svg.ActivityInterface)

Example 98 with Scope

use of org.wso2.ballerinalang.compiler.semantics.model.Scope in project carbon-business-process by wso2.

the class HistoricTaskInstanceService method getVariableFromRequest.

protected RestVariable getVariableFromRequest(boolean includeBinary, String taskId, String variableName, String scope) {
    HistoryService historyService = BPMNOSGIService.getHistoryService();
    RestVariable.RestVariableScope variableScope = RestVariable.getScopeFromString(scope);
    HistoricTaskInstanceQuery taskQuery = historyService.createHistoricTaskInstanceQuery().taskId(taskId);
    if (variableScope != null) {
        if (variableScope == RestVariable.RestVariableScope.GLOBAL) {
            taskQuery.includeProcessVariables();
        } else {
            taskQuery.includeTaskLocalVariables();
        }
    } else {
        taskQuery.includeTaskLocalVariables().includeProcessVariables();
    }
    HistoricTaskInstance taskObject = taskQuery.singleResult();
    if (taskObject == null) {
        throw new ActivitiObjectNotFoundException("Historic task instance '" + taskId + "' couldn't be found.", HistoricTaskInstanceEntity.class);
    }
    Object value = null;
    if (variableScope != null) {
        if (variableScope == RestVariable.RestVariableScope.GLOBAL) {
            value = taskObject.getProcessVariables().get(variableName);
        } else {
            value = taskObject.getTaskLocalVariables().get(variableName);
        }
    } else {
        // look for local task restVariables first
        if (taskObject.getTaskLocalVariables().containsKey(variableName)) {
            value = taskObject.getTaskLocalVariables().get(variableName);
        } else {
            value = taskObject.getProcessVariables().get(variableName);
        }
    }
    if (value == null) {
        throw new ActivitiObjectNotFoundException("Historic task instance '" + taskId + "' variable value for " + variableName + " couldn't be found.", VariableInstanceEntity.class);
    } else {
        return new RestResponseFactory().createRestVariable(variableName, value, null, taskId, RestResponseFactory.VARIABLE_HISTORY_TASK, includeBinary, uriInfo.getBaseUri().toString());
    }
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) HistoryService(org.activiti.engine.HistoryService) HistoricTaskInstanceQuery(org.activiti.engine.history.HistoricTaskInstanceQuery) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Example 99 with Scope

use of org.wso2.ballerinalang.compiler.semantics.model.Scope in project carbon-business-process by wso2.

the class HistoricTaskInstanceService method getVariableData.

@GET
@Path("/{taskId}/variables/{variableName}/data")
public byte[] getVariableData(@PathParam("taskId") String taskId, @PathParam("variableName") String variableName) {
    String scope = uriInfo.getQueryParameters().getFirst("scope");
    Response.ResponseBuilder response = Response.ok();
    try {
        byte[] result = null;
        RestVariable variable = getVariableFromRequest(true, taskId, variableName, scope);
        if (RestResponseFactory.BYTE_ARRAY_VARIABLE_TYPE.equals(variable.getType())) {
            result = (byte[]) variable.getValue();
            response.type("application/octet-stream");
        } else if (RestResponseFactory.SERIALIZABLE_VARIABLE_TYPE.equals(variable.getType())) {
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            ObjectOutputStream outputStream = new ObjectOutputStream(buffer);
            outputStream.writeObject(variable.getValue());
            outputStream.close();
            result = buffer.toByteArray();
            response.type("application/x-java-serialized-object");
        } else {
            throw new ActivitiObjectNotFoundException("The variable does not have a binary data stream.", null);
        }
        return result;
    } catch (IOException ioe) {
        // Re-throw IOException
        throw new ActivitiException("Unexpected exception getting variable data", ioe);
    }
}
Also used : HistoricIdentityLinkResponse(org.wso2.carbon.bpmn.rest.model.history.HistoricIdentityLinkResponse) DataResponse(org.wso2.carbon.bpmn.rest.model.common.DataResponse) Response(javax.ws.rs.core.Response) HistoricTaskInstanceResponse(org.wso2.carbon.bpmn.rest.model.runtime.HistoricTaskInstanceResponse) RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) ActivitiException(org.activiti.engine.ActivitiException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Example 100 with Scope

use of org.wso2.ballerinalang.compiler.semantics.model.Scope in project carbon-business-process by wso2.

the class BaseTaskService method getVariableFromRequest.

public RestVariable getVariableFromRequest(String taskId, String variableName, String scope, boolean includeBinary, String baseUri) {
    boolean variableFound = false;
    Object value = null;
    RestVariable.RestVariableScope variableScope = RestVariable.getScopeFromString(scope);
    TaskService taskService = BPMNOSGIService.getTaskService();
    RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
    if (variableScope == null) {
        // First, check local variables (which have precedence when no scope is supplied)
        if (taskService.hasVariableLocal(taskId, variableName)) {
            value = taskService.getVariableLocal(taskId, variableName);
            variableScope = RestVariable.RestVariableScope.LOCAL;
            variableFound = true;
        } else {
            // Revert to execution-variable when not present local on the task
            Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
            if (task.getExecutionId() != null && runtimeService.hasVariable(task.getExecutionId(), variableName)) {
                value = runtimeService.getVariable(task.getExecutionId(), variableName);
                variableScope = RestVariable.RestVariableScope.GLOBAL;
                variableFound = true;
            }
        }
    } else if (variableScope == RestVariable.RestVariableScope.GLOBAL) {
        Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
        if (task.getExecutionId() != null && runtimeService.hasVariable(task.getExecutionId(), variableName)) {
            value = runtimeService.getVariable(task.getExecutionId(), variableName);
            variableFound = true;
        }
    } else if (variableScope == RestVariable.RestVariableScope.LOCAL) {
        if (taskService.hasVariableLocal(taskId, variableName)) {
            value = taskService.getVariableLocal(taskId, variableName);
            variableFound = true;
        }
    }
    if (!variableFound) {
        throw new ActivitiObjectNotFoundException("Task '" + taskId + "' doesn't have a variable with name: '" + variableName + "'.", VariableInstanceEntity.class);
    } else {
        return new RestResponseFactory().createRestVariable(variableName, value, variableScope, taskId, RestResponseFactory.VARIABLE_TASK, includeBinary, baseUri);
    }
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) Task(org.activiti.engine.task.Task) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory)

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