Search in sources :

Example 91 with Operation

use of org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation in project charon by wso2.

the class PatchOperationUtil method doPatchReplaceOnResource.

/*
     *
     * @param oldResource
     * @param copyOfOldResource
     * @param schema
     * @param decoder
     * @param operation
     * @return
     * @throws CharonException
     */
private static AbstractSCIMObject doPatchReplaceOnResource(AbstractSCIMObject oldResource, AbstractSCIMObject copyOfOldResource, SCIMResourceTypeSchema schema, JSONDecoder decoder, PatchOperation operation) throws CharonException {
    try {
        AbstractSCIMObject attributeHoldingSCIMObject = decoder.decode(operation.getValues().toString(), schema);
        if (oldResource != null) {
            for (String attributeName : attributeHoldingSCIMObject.getAttributeList().keySet()) {
                Attribute oldAttribute = oldResource.getAttribute(attributeName);
                if (oldAttribute != null) {
                    // if the attribute is there, append it.
                    if (oldAttribute.getMultiValued()) {
                        // this is multivalued complex case.
                        MultiValuedAttribute attributeValue = (MultiValuedAttribute) attributeHoldingSCIMObject.getAttribute(attributeName);
                        if (oldAttribute.getMutability().equals(SCIMDefinitions.Mutability.IMMUTABLE) || oldAttribute.getMutability().equals(SCIMDefinitions.Mutability.READ_ONLY)) {
                            throw new BadRequestException("Immutable or Read-Only attributes can not be modified.", ResponseCodeConstants.MUTABILITY);
                        } else {
                            // delete the old attribute
                            oldResource.deleteAttribute(attributeName);
                            // replace with new attribute
                            oldResource.setAttribute(attributeValue);
                        }
                    } else if (oldAttribute.getType().equals(SCIMDefinitions.DataType.COMPLEX)) {
                        // this is the complex attribute case.
                        Map<String, Attribute> subAttributeList = ((ComplexAttribute) attributeHoldingSCIMObject.getAttribute(attributeName)).getSubAttributesList();
                        for (Map.Entry<String, Attribute> subAttrib : subAttributeList.entrySet()) {
                            Attribute subAttribute = oldAttribute.getSubAttribute(subAttrib.getKey());
                            if (subAttribute != null) {
                                if (subAttribute.getType().equals(SCIMDefinitions.DataType.COMPLEX)) {
                                    if (subAttribute.getMultiValued()) {
                                        // extension schema is the only one who reaches here.
                                        MultiValuedAttribute attributeSubValue = (MultiValuedAttribute) ((ComplexAttribute) attributeHoldingSCIMObject.getAttribute(attributeName)).getSubAttribute(subAttrib.getKey());
                                        if (subAttribute.getMutability().equals(SCIMDefinitions.Mutability.IMMUTABLE) || subAttribute.getMutability().equals(SCIMDefinitions.Mutability.READ_ONLY)) {
                                            throw new BadRequestException("Immutable or Read-Only attributes can not be modified.", ResponseCodeConstants.MUTABILITY);
                                        } else {
                                            // delete the old attribute
                                            ((ComplexAttribute) (oldAttribute)).removeSubAttribute(subAttribute.getName());
                                            // replace with new attribute
                                            ((ComplexAttribute) (oldAttribute)).setSubAttribute(attributeSubValue);
                                        }
                                    } else {
                                        // extension schema is the only one who reaches here.
                                        Map<String, Attribute> subSubAttributeList = ((ComplexAttribute) (attributeHoldingSCIMObject.getAttribute(attributeName).getSubAttribute(subAttrib.getKey()))).getSubAttributesList();
                                        for (Map.Entry<String, Attribute> subSubAttrb : subSubAttributeList.entrySet()) {
                                            Attribute subSubAttribute = oldAttribute.getSubAttribute(subAttrib.getKey()).getSubAttribute(subSubAttrb.getKey());
                                            if (subSubAttribute != null) {
                                                if (subSubAttribute.getMultiValued()) {
                                                    if (subSubAttribute.getMutability().equals(SCIMDefinitions.Mutability.IMMUTABLE) || subSubAttribute.getMutability().equals(SCIMDefinitions.Mutability.READ_ONLY)) {
                                                        throw new BadRequestException("Immutable or Read-Only attributes " + "can not be modified.", ResponseCodeConstants.MUTABILITY);
                                                    } else {
                                                        // delete the old attribute
                                                        ((ComplexAttribute) (oldAttribute.getSubAttribute(subAttrib.getKey()))).removeSubAttribute(subSubAttribute.getName());
                                                        // replace with new attribute
                                                        ((ComplexAttribute) (oldAttribute.getSubAttribute(subAttrib.getKey()))).setSubAttribute(subSubAttribute);
                                                    }
                                                } else {
                                                    ((SimpleAttribute) subSubAttribute).setValue(((SimpleAttribute) subSubAttrb.getValue()));
                                                }
                                            } else {
                                                ((ComplexAttribute) (subAttribute)).setSubAttribute(subSubAttrb.getValue());
                                            }
                                        }
                                    }
                                } else {
                                    if (subAttribute.getMutability().equals(SCIMDefinitions.Mutability.IMMUTABLE) || subAttribute.getMutability().equals(SCIMDefinitions.Mutability.READ_ONLY)) {
                                        throw new BadRequestException("Immutable or Read-Only " + "attributes can not be modified.", ResponseCodeConstants.MUTABILITY);
                                    } else {
                                        // delete the old attribute
                                        ((ComplexAttribute) (oldAttribute)).removeSubAttribute(subAttribute.getName());
                                        // replace with new attribute
                                        ((ComplexAttribute) (oldAttribute)).setSubAttribute(subAttributeList.get(subAttribute.getName()));
                                    }
                                }
                            } else {
                                // add the attribute
                                ((ComplexAttribute) oldAttribute).setSubAttribute(subAttrib.getValue());
                            }
                        }
                    } else {
                        if (oldAttribute.getMutability().equals(SCIMDefinitions.Mutability.IMMUTABLE) || oldAttribute.getMutability().equals(SCIMDefinitions.Mutability.READ_ONLY)) {
                            throw new BadRequestException("Immutable or Read-Only attributes can not be modified.", ResponseCodeConstants.MUTABILITY);
                        } else {
                            // this is the simple attribute case.replace the value
                            ((SimpleAttribute) oldAttribute).setValue(((SimpleAttribute) attributeHoldingSCIMObject.getAttribute(oldAttribute.getName())).getValue());
                        }
                    }
                } else {
                    // add the attribute
                    oldResource.setAttribute(attributeHoldingSCIMObject.getAttributeList().get(attributeName));
                }
            }
            AbstractSCIMObject validatedResource = ServerSideValidator.validateUpdatedSCIMObject(copyOfOldResource, oldResource, schema);
            return validatedResource;
        } else {
            throw new CharonException("Error in getting the old resource.");
        }
    } catch (BadRequestException | CharonException e) {
        throw new CharonException("Error in performing the add operation", e);
    }
}
Also used : AbstractSCIMObject(org.wso2.charon3.core.objects.AbstractSCIMObject) MultiValuedAttribute(org.wso2.charon3.core.attributes.MultiValuedAttribute) SimpleAttribute(org.wso2.charon3.core.attributes.SimpleAttribute) ComplexAttribute(org.wso2.charon3.core.attributes.ComplexAttribute) Attribute(org.wso2.charon3.core.attributes.Attribute) SimpleAttribute(org.wso2.charon3.core.attributes.SimpleAttribute) ComplexAttribute(org.wso2.charon3.core.attributes.ComplexAttribute) BadRequestException(org.wso2.charon3.core.exceptions.BadRequestException) CharonException(org.wso2.charon3.core.exceptions.CharonException) Map(java.util.Map) MultiValuedAttribute(org.wso2.charon3.core.attributes.MultiValuedAttribute)

Example 92 with Operation

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

the class AttachmentManagerService method add.

/**
 * {@inheritDoc}
 */
@Override
public String add(final TAttachment attachment) throws AttachmentMgtException {
    if (log.isDebugEnabled() && attachment != null) {
        log.debug("Saving the attachment with id " + attachment.getId());
    }
    try {
        Attachment att = TransformerUtil.convertAttachment(attachment);
        // 1. get Att-Mgt DAO Conn factory
        // 2. get Att-Mgt DAO Connection
        // 3. addAttachment
        // getDaoConnectionFactory().getDAOConnection().addAttachment(att);
        AttachmentDAO daoImpl = getDaoConnectionFactory().getDAOConnection().getAttachmentMgtDAOFactory().addAttachment(att);
        return daoImpl.getID().toString();
    } catch (org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException ex) {
        String errMsg = "org.wso2.carbon.attachment.mgt.core.service.AttachmentManagerService.add " + "operation failed. Reason:" + ex.getLocalizedMessage();
        log.error(errMsg, ex);
        throw new AttachmentMgtException(errMsg, ex);
    }
}
Also used : AttachmentMgtException(org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException) AttachmentDAO(org.wso2.carbon.attachment.mgt.core.dao.AttachmentDAO) TAttachment(org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment) Attachment(org.wso2.carbon.attachment.mgt.api.attachment.Attachment)

Example 93 with Operation

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

the class HistoricProcessInstanceService method addVariables.

protected void addVariables(HistoricProcessInstanceQuery processInstanceQuery, 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;
        RestResponseFactory restResponseFactory = new RestResponseFactory();
        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 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) QueryVariable(org.wso2.carbon.bpmn.rest.engine.variable.QueryVariable)

Example 94 with Operation

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

the class BaseTaskService method addProcessvariables.

protected void addProcessvariables(TaskQuery taskQuery, 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) {
                    taskQuery.processVariableValueEquals(actualValue);
                } else {
                    taskQuery.processVariableValueEquals(variable.getName(), actualValue);
                }
                break;
            case EQUALS_IGNORE_CASE:
                if (actualValue instanceof String) {
                    taskQuery.processVariableValueEqualsIgnoreCase(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:
                taskQuery.processVariableValueNotEquals(variable.getName(), actualValue);
                break;
            case NOT_EQUALS_IGNORE_CASE:
                if (actualValue instanceof String) {
                    taskQuery.processVariableValueNotEqualsIgnoreCase(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:
                taskQuery.processVariableValueGreaterThan(variable.getName(), actualValue);
                break;
            case GREATER_THAN_OR_EQUALS:
                taskQuery.processVariableValueGreaterThanOrEqual(variable.getName(), actualValue);
                break;
            case LESS_THAN:
                taskQuery.processVariableValueLessThan(variable.getName(), actualValue);
                break;
            case LESS_THAN_OR_EQUALS:
                taskQuery.processVariableValueLessThanOrEqual(variable.getName(), actualValue);
                break;
            case LIKE:
                if (actualValue instanceof String) {
                    taskQuery.processVariableValueLike(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) QueryVariable(org.wso2.carbon.bpmn.rest.engine.variable.QueryVariable)

Example 95 with Operation

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

the class BaseHistoricTaskInstanceService method addProcessVariables.

protected void addProcessVariables(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:
                taskInstanceQuery.processVariableValueEquals(variable.getName(), actualValue);
                break;
            case EQUALS_IGNORE_CASE:
                if (actualValue instanceof String) {
                    taskInstanceQuery.processVariableValueEqualsIgnoreCase(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.processVariableValueNotEquals(variable.getName(), actualValue);
                break;
            case NOT_EQUALS_IGNORE_CASE:
                if (actualValue instanceof String) {
                    taskInstanceQuery.processVariableValueNotEqualsIgnoreCase(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.processVariableValueGreaterThan(variable.getName(), actualValue);
                break;
            case GREATER_THAN_OR_EQUALS:
                taskInstanceQuery.processVariableValueGreaterThanOrEqual(variable.getName(), actualValue);
                break;
            case LESS_THAN:
                taskInstanceQuery.processVariableValueLessThan(variable.getName(), actualValue);
                break;
            case LESS_THAN_OR_EQUALS:
                taskInstanceQuery.processVariableValueLessThanOrEqual(variable.getName(), actualValue);
                break;
            case LIKE:
                if (actualValue instanceof String) {
                    taskInstanceQuery.processVariableValueLike(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)

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