Search in sources :

Example 56 with Operation

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

the class AttachmentMgtDAOFactoryImpl method removeAttachment.

@Override
public boolean removeAttachment(final String id) throws AttachmentMgtException {
    try {
        boolean isRemoved = false;
        isRemoved = jobExecutor.execTransaction(new Callable<Boolean>() {

            @Override
            public Boolean call() throws Exception {
                Query query = entityManager.createQuery("DELETE FROM org.wso2.carbon.attachment.mgt.core.dao.impl" + ".jpa.openjpa.entity.AttachmentDAOImpl x WHERE x.id = " + ":attachmentID");
                query.setParameter("attachmentID", Long.parseLong(id));
                int noOfRowsUpdated = query.executeUpdate();
                // entityManager.remove(getAttachmentInfo(id));
                if (noOfRowsUpdated == 1) {
                    return true;
                } else {
                    return false;
                }
            }
        });
        return isRemoved;
    } catch (Exception e) {
        String errorMsg = "org.wso2.carbon.attachment.mgt.core.dao.impl.jpa.openjpa.AttachmentMgtDAOFactoryImpl.removeAttachment operation failed. " + "Reason: " + e.getLocalizedMessage();
        log.error(errorMsg, e);
        throw new AttachmentMgtException(errorMsg, e);
    }
}
Also used : AttachmentMgtException(org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException) Query(javax.persistence.Query) Callable(java.util.concurrent.Callable) AttachmentMgtException(org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException)

Example 57 with Operation

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

the class BaseHistoricVariableInstanceService method addVariables.

protected void addVariables(HistoricVariableInstanceQuery variableInstanceQuery, List<QueryVariable> variables) {
    for (QueryVariable variable : variables) {
        if (variable.getVariableOperation() == null) {
            throw new ActivitiIllegalArgumentException("Variable operation is missing for variable: " + variable.getName());
        }
        if (variable.getValue() == null) {
            throw new ActivitiIllegalArgumentException("Variable value is missing for variable: " + variable.getName());
        }
        boolean nameLess = variable.getName() == null;
        Object actualValue = new RestResponseFactory().getVariableValue(variable);
        // A value-only query is only possible using equals-operator
        if (nameLess) {
            throw new ActivitiIllegalArgumentException("Value-only query (without a variable-name) is not supported");
        }
        switch(variable.getVariableOperation()) {
            case EQUALS:
                variableInstanceQuery.variableValueEquals(variable.getName(), actualValue);
                break;
            default:
                throw new ActivitiIllegalArgumentException("Unsupported variable query operation: " + variable.getVariableOperation());
        }
    }
}
Also used : RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) QueryVariable(org.wso2.carbon.bpmn.rest.engine.variable.QueryVariable)

Example 58 with Operation

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

the class BaseProcessInstanceService method addVariables.

protected void addVariables(ProcessInstanceQuery processInstanceQuery, List<QueryVariable> variables) {
    RestResponseFactory restResponseFactory = new RestResponseFactory();
    for (QueryVariable variable : variables) {
        if (variable.getVariableOperation() == null) {
            throw new ActivitiIllegalArgumentException("Variable operation is missing for variable: " + variable.getName());
        }
        if (variable.getValue() == null) {
            throw new ActivitiIllegalArgumentException("Variable value is missing for variable: " + variable.getName());
        }
        boolean nameLess = variable.getName() == null;
        Object actualValue = restResponseFactory.getVariableValue(variable);
        // A value-only query is only possible using equals-operator
        if (nameLess && variable.getVariableOperation() != QueryVariable.QueryVariableOperation.EQUALS) {
            throw new ActivitiIllegalArgumentException("Value-only query (without a variable-name) is only supported when using 'equals' operation.");
        }
        switch(variable.getVariableOperation()) {
            case EQUALS:
                if (nameLess) {
                    processInstanceQuery.variableValueEquals(actualValue);
                } else {
                    processInstanceQuery.variableValueEquals(variable.getName(), actualValue);
                }
                break;
            case EQUALS_IGNORE_CASE:
                if (actualValue instanceof String) {
                    processInstanceQuery.variableValueEqualsIgnoreCase(variable.getName(), (String) actualValue);
                } else {
                    throw new ActivitiIllegalArgumentException("Only string variable values are supported when ignoring casing, but was: " + actualValue.getClass().getName());
                }
                break;
            case NOT_EQUALS:
                processInstanceQuery.variableValueNotEquals(variable.getName(), actualValue);
                break;
            case NOT_EQUALS_IGNORE_CASE:
                if (actualValue instanceof String) {
                    processInstanceQuery.variableValueNotEqualsIgnoreCase(variable.getName(), (String) actualValue);
                } else {
                    throw new ActivitiIllegalArgumentException("Only string variable values are supported when ignoring casing, but was: " + actualValue.getClass().getName());
                }
                break;
            case LIKE:
                if (actualValue instanceof String) {
                    processInstanceQuery.variableValueLike(variable.getName(), (String) actualValue);
                } else {
                    throw new ActivitiIllegalArgumentException("Only string variable values are supported for like, but was: " + actualValue.getClass().getName());
                }
                break;
            case GREATER_THAN:
                processInstanceQuery.variableValueGreaterThan(variable.getName(), actualValue);
                break;
            case GREATER_THAN_OR_EQUALS:
                processInstanceQuery.variableValueGreaterThanOrEqual(variable.getName(), actualValue);
                break;
            case LESS_THAN:
                processInstanceQuery.variableValueLessThan(variable.getName(), actualValue);
                break;
            case LESS_THAN_OR_EQUALS:
                processInstanceQuery.variableValueLessThanOrEqual(variable.getName(), actualValue);
                break;
            default:
                throw new ActivitiIllegalArgumentException("Unsupported variable query operation: " + variable.getVariableOperation());
        }
    }
}
Also used : RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) QueryVariable(org.wso2.carbon.bpmn.rest.engine.variable.QueryVariable)

Example 59 with Operation

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

the class BaseHistoricTaskInstanceService method addTaskVariables.

protected void addTaskVariables(HistoricTaskInstanceQuery taskInstanceQuery, List<QueryVariable> variables) {
    for (QueryVariable variable : variables) {
        if (variable.getVariableOperation() == null) {
            throw new ActivitiIllegalArgumentException("Variable operation is missing for variable: " + variable.getName());
        }
        if (variable.getValue() == null) {
            throw new ActivitiIllegalArgumentException("Variable value is missing for variable: " + variable.getName());
        }
        boolean nameLess = variable.getName() == null;
        Object actualValue = new RestResponseFactory().getVariableValue(variable);
        // A value-only query is only possible using equals-operator
        if (nameLess) {
            throw new ActivitiIllegalArgumentException("Value-only query (without a variable-name) is not supported.");
        }
        switch(variable.getVariableOperation()) {
            case EQUALS:
                if (nameLess) {
                    taskInstanceQuery.taskVariableValueEquals(actualValue);
                } else {
                    taskInstanceQuery.taskVariableValueEquals(variable.getName(), actualValue);
                }
                break;
            case EQUALS_IGNORE_CASE:
                if (actualValue instanceof String) {
                    taskInstanceQuery.taskVariableValueEqualsIgnoreCase(variable.getName(), (String) actualValue);
                } else {
                    throw new ActivitiIllegalArgumentException("Only string variable values are supported when ignoring casing, but was: " + actualValue.getClass().getName());
                }
                break;
            case NOT_EQUALS:
                taskInstanceQuery.taskVariableValueNotEquals(variable.getName(), actualValue);
                break;
            case NOT_EQUALS_IGNORE_CASE:
                if (actualValue instanceof String) {
                    taskInstanceQuery.taskVariableValueNotEqualsIgnoreCase(variable.getName(), (String) actualValue);
                } else {
                    throw new ActivitiIllegalArgumentException("Only string variable values are supported when ignoring casing, but was: " + actualValue.getClass().getName());
                }
                break;
            case GREATER_THAN:
                taskInstanceQuery.taskVariableValueGreaterThan(variable.getName(), actualValue);
                break;
            case GREATER_THAN_OR_EQUALS:
                taskInstanceQuery.taskVariableValueGreaterThanOrEqual(variable.getName(), actualValue);
                break;
            case LESS_THAN:
                taskInstanceQuery.taskVariableValueLessThan(variable.getName(), actualValue);
                break;
            case LESS_THAN_OR_EQUALS:
                taskInstanceQuery.taskVariableValueLessThanOrEqual(variable.getName(), actualValue);
                break;
            case LIKE:
                if (actualValue instanceof String) {
                    taskInstanceQuery.taskVariableValueLike(variable.getName(), (String) actualValue);
                } else {
                    throw new ActivitiIllegalArgumentException("Only string variable values are supported using like, but was: " + actualValue.getClass().getName());
                }
                break;
            default:
                throw new ActivitiIllegalArgumentException("Unsupported variable query operation: " + variable.getVariableOperation());
        }
    }
}
Also used : RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) QueryVariable(org.wso2.carbon.bpmn.rest.engine.variable.QueryVariable)

Example 60 with Operation

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

the class BaseExecutionService method addVariables.

protected void addVariables(ExecutionQuery processInstanceQuery, List<QueryVariable> variables, boolean process) {
    for (QueryVariable variable : variables) {
        if (variable.getVariableOperation() == null) {
            throw new ActivitiIllegalArgumentException("Variable operation is missing for variable: " + variable.getName());
        }
        if (variable.getValue() == null) {
            throw new ActivitiIllegalArgumentException("Variable value is missing for variable: " + variable.getName());
        }
        boolean nameLess = variable.getName() == null;
        Object actualValue = new RestResponseFactory().getVariableValue(variable);
        // A value-only query is only possible using equals-operator
        if (nameLess && variable.getVariableOperation() != QueryVariable.QueryVariableOperation.EQUALS) {
            throw new ActivitiIllegalArgumentException("Value-only query (without a variable-name) is only supported when using 'equals' operation.");
        }
        switch(variable.getVariableOperation()) {
            case EQUALS:
                if (nameLess) {
                    if (process) {
                        processInstanceQuery.processVariableValueEquals(actualValue);
                    } else {
                        processInstanceQuery.variableValueEquals(actualValue);
                    }
                } else {
                    if (process) {
                        processInstanceQuery.processVariableValueEquals(variable.getName(), actualValue);
                    } else {
                        processInstanceQuery.variableValueEquals(variable.getName(), actualValue);
                    }
                }
                break;
            case EQUALS_IGNORE_CASE:
                if (actualValue instanceof String) {
                    if (process) {
                        processInstanceQuery.processVariableValueEqualsIgnoreCase(variable.getName(), (String) actualValue);
                    } else {
                        processInstanceQuery.variableValueEqualsIgnoreCase(variable.getName(), (String) actualValue);
                    }
                } else {
                    throw new ActivitiIllegalArgumentException("Only string variable values are supported when ignoring casing, but was: " + actualValue.getClass().getName());
                }
                break;
            case NOT_EQUALS:
                if (process) {
                    processInstanceQuery.processVariableValueNotEquals(variable.getName(), actualValue);
                } else {
                    processInstanceQuery.variableValueNotEquals(variable.getName(), actualValue);
                }
                break;
            case NOT_EQUALS_IGNORE_CASE:
                if (actualValue instanceof String) {
                    if (process) {
                        processInstanceQuery.processVariableValueNotEqualsIgnoreCase(variable.getName(), (String) actualValue);
                    } else {
                        processInstanceQuery.variableValueNotEqualsIgnoreCase(variable.getName(), (String) actualValue);
                    }
                } else {
                    throw new ActivitiIllegalArgumentException("Only string variable values are supported when ignoring casing, but was: " + actualValue.getClass().getName());
                }
                break;
            default:
                throw new ActivitiIllegalArgumentException("Unsupported variable query operation: " + variable.getVariableOperation());
        }
    }
}
Also used : RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) QueryVariable(org.wso2.carbon.bpmn.rest.engine.variable.QueryVariable)

Aggregations

Test (org.testng.annotations.Test)34 HttpResponse (org.wso2.carbon.automation.test.utils.http.client.HttpResponse)29 HashMap (java.util.HashMap)19 ArrayList (java.util.ArrayList)16 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)15 HumanTaskRuntimeException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)12 QueryVariable (org.wso2.carbon.bpmn.rest.engine.variable.QueryVariable)11 List (java.util.List)10 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)10 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)9 Map (java.util.Map)8 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)8 Operation (io.swagger.models.Operation)7 Attribute (org.wso2.charon3.core.attributes.Attribute)7 ComplexAttribute (org.wso2.charon3.core.attributes.ComplexAttribute)7 MultiValuedAttribute (org.wso2.charon3.core.attributes.MultiValuedAttribute)7 SimpleAttribute (org.wso2.charon3.core.attributes.SimpleAttribute)7 Operation (org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation)6 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)6 AttributeSchema (org.wso2.charon3.core.schema.AttributeSchema)6