use of org.wso2.carbon.device.mgt.common.operation.mgt.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);
}
}
use of org.wso2.carbon.device.mgt.common.operation.mgt.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);
}
}
use of org.wso2.carbon.device.mgt.common.operation.mgt.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());
}
}
}
use of org.wso2.carbon.device.mgt.common.operation.mgt.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());
}
}
}
use of org.wso2.carbon.device.mgt.common.operation.mgt.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());
}
}
}
Aggregations