use of org.wso2.siddhi.query.api.extension.Extension in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisValidateDefinitionPost.
/**
* Validates a provided API definition
*
* @param type API definition type (SWAGGER or WSDL)
* @param fileInputStream file content stream
* @param fileDetail file details
* @param url URL of the definition
* @param request msf4j request
* @return API definition validation information
* @throws NotFoundException
*/
@Override
public Response apisValidateDefinitionPost(String type, InputStream fileInputStream, FileInfo fileDetail, String url, Request request) throws NotFoundException {
String errorMessage = "Error while validating the definition";
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
if (StringUtils.isBlank(type)) {
type = APIDefinitionValidationResponseDTO.DefinitionTypeEnum.SWAGGER.toString();
}
Response responseIfParamsInvalid = buildResponseIfParamsInvalid(type, fileInputStream, url);
if (responseIfParamsInvalid != null) {
return responseIfParamsInvalid;
}
if (APIDefinitionValidationResponseDTO.DefinitionTypeEnum.SWAGGER.toString().equals(type)) {
if (log.isDebugEnabled()) {
log.debug("Validating a swagger file.");
}
// TODO implement swagger validation
return Response.noContent().build();
} else {
// WSDL type
WSDLProcessor processor = null;
WSDLInfo info = null;
if (!StringUtils.isBlank(url)) {
processor = WSDLProcessFactory.getInstance().getWSDLProcessor(url);
info = processor.getWsdlInfo();
if (log.isDebugEnabled()) {
log.debug("Successfully validated WSDL URL " + url);
}
} else {
if (fileDetail.getFileName().endsWith(".zip")) {
WSDLArchiveInfo archiveInfo = apiPublisher.extractAndValidateWSDLArchive(fileInputStream);
info = archiveInfo.getWsdlInfo();
if (log.isDebugEnabled()) {
log.debug("Successfully validated WSDL archive " + fileDetail.getFileName());
}
} else if (fileDetail.getFileName().endsWith(".wsdl")) {
byte[] wsdlContent = IOUtils.toByteArray(fileInputStream);
processor = WSDLProcessFactory.getInstance().getWSDLProcessor(wsdlContent);
info = processor.getWsdlInfo();
if (log.isDebugEnabled()) {
log.debug("Successfully validated WSDL file " + fileDetail.getFileName());
}
} else {
String msg = "Unsupported extension type of file: " + fileDetail.getFileName();
log.error(msg);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(msg, 900700L, msg);
return Response.status(Response.Status.BAD_REQUEST).entity(errorDTO).build();
}
}
if (info != null) {
APIDefinitionValidationResponseDTO responseDTO = MappingUtil.toWSDLValidationResponseDTO(info);
return Response.ok(responseDTO).build();
}
APIDefinitionValidationResponseDTO responseDTO = new APIDefinitionValidationResponseDTO();
responseDTO.isValid(false);
return Response.ok().entity(responseDTO).build();
}
} catch (APIManagementException e) {
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
} catch (IOException e) {
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(errorMessage, 900313L, errorMessage);
log.error(errorMessage, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorDTO).build();
}
}
use of org.wso2.siddhi.query.api.extension.Extension in project carbon-business-process by wso2.
the class BPELUploadExecutor method execute.
public boolean execute(HttpServletRequest request, HttpServletResponse response) throws CarbonException, IOException {
String errMsg;
response.setContentType("text/html; charset=utf-8");
PrintWriter out = response.getWriter();
String webContext = (String) request.getAttribute(CarbonConstants.WEB_CONTEXT);
String serverURL = (String) request.getAttribute(CarbonConstants.SERVER_URL);
String cookie = (String) request.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
Map<String, ArrayList<FileItemData>> fileItemsMap = getFileItemsMap();
if (fileItemsMap == null || fileItemsMap.isEmpty()) {
String msg = "File uploading failed.";
log.error(msg);
out.write("<textarea>" + "(function(){i18n.fileUplodedFailed();})();" + "</textarea>");
return true;
}
BPELUploaderClient uploaderClient = new BPELUploaderClient(configurationContext, serverURL + "BPELUploader", cookie);
SaveExtractReturn uploadedFiles = null;
ArrayList<String> extractedFiles = new ArrayList<String>();
try {
for (FileItemData fieldData : fileItemsMap.get("bpelFileName")) {
String fileName = getFileName(fieldData.getFileItem().getName());
// Check filename for \ charactors. This cannot be handled at the lower stages.
if (fileName.matches("(.*[\\\\].*[/].*|.*[/].*[\\\\].*)")) {
log.error("BPEL Package Validation Failure: one or many of the following illegal characters are " + "in " + "the package.\n ~!@#$;%^*()+={}[]| \\<>");
throw new Exception("BPEL Package Validation Failure: one or many of the following illegal " + "characters " + "are in the package. ~!@#$;%^*()+={}[]| \\<>");
}
// Check file extension.
checkServiceFileExtensionValidity(fileName, ALLOWED_FILE_EXTENSIONS);
if (fileName.lastIndexOf('\\') != -1) {
int indexOfColon = fileName.lastIndexOf('\\') + 1;
fileName = fileName.substring(indexOfColon, fileName.length());
}
if (fieldData.getFileItem().getFieldName().equals("bpelFileName")) {
uploadedFiles = saveAndExtractUploadedFile(fieldData.getFileItem());
extractedFiles.add(uploadedFiles.extractedFile);
validateBPELPackage(uploadedFiles.extractedFile);
DataSource dataSource = new FileDataSource(uploadedFiles.zipFile);
uploaderClient.addUploadedFileItem(new DataHandler(dataSource), fileName, "zip");
}
}
uploaderClient.uploadFileItems();
String msg = "Your BPEL package been uploaded successfully. Please refresh this page in a" + " while to see the status of the new process.";
CarbonUIMessage.sendCarbonUIMessage(msg, CarbonUIMessage.INFO, request, response, getContextRoot(request) + "/" + webContext + "/bpel/process_list.jsp");
return true;
} catch (Exception e) {
errMsg = "File upload failed :" + e.getMessage();
log.error(errMsg, e);
CarbonUIMessage.sendCarbonUIMessage(errMsg, CarbonUIMessage.ERROR, request, response, getContextRoot(request) + "/" + webContext + "/bpel/upload_bpel.jsp");
} finally {
for (String s : extractedFiles) {
File extractedFile = new File(s);
if (log.isDebugEnabled()) {
log.debug("Cleaning temporarily extracted BPEL artifacts in " + extractedFile.getParent());
}
try {
FileUtils.cleanDirectory(new File(extractedFile.getParent()));
} catch (IOException ex) {
log.warn("Failed to clean temporary extractedFile.", ex);
}
}
}
return false;
}
use of org.wso2.siddhi.query.api.extension.Extension in project carbon-business-process by wso2.
the class BPMNUploadExecutor method execute.
@Override
public boolean execute(HttpServletRequest request, HttpServletResponse response) throws CarbonException, IOException {
String errMsg;
response.setContentType("text/html; charset=utf-8");
PrintWriter out = response.getWriter();
String webContext = (String) request.getAttribute(CarbonConstants.WEB_CONTEXT);
String serverURL = (String) request.getAttribute(CarbonConstants.SERVER_URL);
String cookie = (String) request.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
Map<String, ArrayList<FileItemData>> fileItemsMap = getFileItemsMap();
if (fileItemsMap == null || fileItemsMap.isEmpty()) {
String msg = "File uploading failed.";
log.error(msg);
out.write("<textarea>" + "(function(){i18n.fileUplodedFailed();})();" + "</textarea>");
return true;
}
BPMNUploaderClient uploaderClient = new BPMNUploaderClient(configurationContext, serverURL + "BPMNUploaderService", cookie);
File uploadedTempFile;
try {
for (FileItemData fileData : fileItemsMap.get("bpmnFileName")) {
String fileName = getFileName(fileData.getFileItem().getName());
// Check filename for \ charactors. This cannot be handled at the lower stages.
if (fileName.matches("(.*[\\\\].*[/].*|.*[/].*[\\\\].*)")) {
log.error("BPMN Package Validation Failure: one or more of the following illegal characters are in " + "the package.\n ~!@#$;%^*()+={}[]| \\<>");
throw new Exception("BPMN Package Validation Failure: one or more of the following illegal characters " + "are in the package. ~!@#$;%^*()+={}[]| \\<>");
}
// Check file extension.
checkServiceFileExtensionValidity(fileName, ALLOWED_FILE_EXTENSIONS);
if (fileName.lastIndexOf('\\') != -1) {
int indexOfColon = fileName.lastIndexOf('\\') + 1;
fileName = fileName.substring(indexOfColon, fileName.length());
}
if (fileData.getFileItem().getFieldName().equals("bpmnFileName")) {
uploadedTempFile = new File(CarbonUtils.getTmpDir(), fileName);
fileData.getFileItem().write(uploadedTempFile);
DataSource dataSource = new FileDataSource(uploadedTempFile);
uploaderClient.addUploadedFileItem(new DataHandler(dataSource), fileName, "bar");
}
}
uploaderClient.uploadFileItems();
String msg = "Your BPMN package has been uploaded successfully. Please refresh this page in a" + " while to see the status of the new process.";
CarbonUIMessage.sendCarbonUIMessage(msg, CarbonUIMessage.INFO, request, response, getContextRoot(request) + "/" + webContext + "/bpmn/process_list_view.jsp");
return true;
} catch (Exception e) {
errMsg = "File upload failed :" + e.getMessage();
log.error(errMsg, e);
CarbonUIMessage.sendCarbonUIMessage(errMsg, CarbonUIMessage.ERROR, request, response, getContextRoot(request) + "/" + webContext + "/bpmn/process_list_view.jsp");
}
return false;
}
use of org.wso2.siddhi.query.api.extension.Extension in project charon by wso2.
the class PatchOperationUtil method doPatchRemoveWithFiltersForLevelTwo.
/*
*
* @param oldResource
* @param attributeParts
* @param expressionNode
* @return
* @throws BadRequestException
* @throws CharonException
*/
private static AbstractSCIMObject doPatchRemoveWithFiltersForLevelTwo(AbstractSCIMObject oldResource, String[] attributeParts, ExpressionNode expressionNode) throws BadRequestException, CharonException {
Attribute attribute = oldResource.getAttribute(attributeParts[0]);
if (attribute != null) {
if (attribute.getMultiValued()) {
List<Attribute> subValues = ((MultiValuedAttribute) attribute).getAttributeValues();
if (subValues != null) {
for (Attribute subValue : subValues) {
Map<String, Attribute> subAttributes = ((ComplexAttribute) subValue).getSubAttributesList();
// this map is to avoid concurrent modification exception.
Map<String, Attribute> tempSubAttributes = (Map<String, Attribute>) CopyUtil.deepCopy(subAttributes);
for (Iterator<Attribute> iterator = tempSubAttributes.values().iterator(); iterator.hasNext(); ) {
Attribute subAttribute = iterator.next();
if (subAttribute.getName().equals(expressionNode.getAttributeValue())) {
if (((SimpleAttribute) subAttribute).getValue().equals(expressionNode.getValue())) {
Attribute removingAttribute = subAttributes.get(attributeParts[1]);
if (removingAttribute == null) {
throw new BadRequestException("No such sub attribute with the name : " + attributeParts[1] + " " + "within the attribute " + attributeParts[0], ResponseCodeConstants.INVALID_PATH);
}
if (removingAttribute.getMutability().equals(SCIMDefinitions.Mutability.READ_ONLY) || removingAttribute.getRequired().equals(true)) {
throw new BadRequestException("Can not remove a required attribute or a read-only attribute", ResponseCodeConstants.MUTABILITY);
} else {
((ComplexAttribute) subValue).removeSubAttribute(removingAttribute.getName());
}
}
}
}
}
if (subValues.size() == 0) {
// if the attribute has no values, make it unassigned
oldResource.deleteAttribute(attribute.getName());
}
}
} else if (attribute.getType().equals(SCIMDefinitions.DataType.COMPLEX)) {
// this is only valid for extension
Attribute subAttribute = attribute.getSubAttribute(attributeParts[1]);
if (subAttribute == null) {
throw new BadRequestException("No such sub attribute with the name : " + attributeParts[1] + " " + "within the attribute " + attributeParts[0], ResponseCodeConstants.INVALID_PATH);
}
List<Attribute> subValues = ((MultiValuedAttribute) (subAttribute)).getAttributeValues();
if (subValues != null) {
for (Iterator<Attribute> subValueIterator = subValues.iterator(); subValueIterator.hasNext(); ) {
Attribute subValue = subValueIterator.next();
Map<String, Attribute> subValuesSubAttribute = ((ComplexAttribute) subValue).getSubAttributesList();
for (Iterator<Attribute> iterator = subValuesSubAttribute.values().iterator(); iterator.hasNext(); ) {
Attribute subSubAttribute = iterator.next();
if (subSubAttribute.getName().equals(expressionNode.getAttributeValue())) {
if (((SimpleAttribute) (subSubAttribute)).getValue().equals(expressionNode.getValue())) {
if (subValue.getMutability().equals(SCIMDefinitions.Mutability.READ_ONLY) || subValue.getRequired().equals(true)) {
throw new BadRequestException("Can not remove a required attribute or a read-only attribute", ResponseCodeConstants.MUTABILITY);
} else {
subValueIterator.remove();
}
}
}
}
}
// if the attribute has no values, make it unassigned
if (((MultiValuedAttribute) (subAttribute)).getAttributeValues().size() == 0) {
((ComplexAttribute) attribute).removeSubAttribute(subAttribute.getName());
}
}
} else {
throw new BadRequestException("Attribute : " + expressionNode.getAttributeValue() + " " + "is not a multivalued attribute.", ResponseCodeConstants.INVALID_PATH);
}
} else {
throw new BadRequestException("No such attribute with the name : " + attributeParts[0] + " " + "in the current resource", ResponseCodeConstants.INVALID_PATH);
}
return oldResource;
}
use of org.wso2.siddhi.query.api.extension.Extension in project charon by wso2.
the class PatchOperationUtil method doPatchReplaceOnPathWithoutFiltersForLevelTwo.
/*
* This performs patch on resource based on the path value.No filter is specified here.
* And this is for level two attributes.
* @param oldResource
* @param schema
* @param decoder
* @param operation
* @param attributeParts
* @throws BadRequestException
* @throws CharonException
* @throws JSONException
* @throws InternalErrorException
*/
private static void doPatchReplaceOnPathWithoutFiltersForLevelTwo(AbstractSCIMObject oldResource, SCIMResourceTypeSchema schema, JSONDecoder decoder, PatchOperation operation, String[] attributeParts) throws BadRequestException, CharonException, InternalErrorException {
Attribute attribute = oldResource.getAttribute(attributeParts[0]);
if (attribute != null) {
if (attribute.getMultiValued()) {
List<Attribute> subValues = ((MultiValuedAttribute) attribute).getAttributeValues();
for (Attribute subValue : subValues) {
Attribute subAttribute = ((ComplexAttribute) subValue).getSubAttribute(attributeParts[1]);
if (subAttribute != null) {
if (subAttribute.getMutability().equals(SCIMDefinitions.Mutability.READ_ONLY) || subAttribute.getMutability().equals(SCIMDefinitions.Mutability.IMMUTABLE)) {
throw new BadRequestException("Can not replace a immutable attribute or a read-only attribute", ResponseCodeConstants.MUTABILITY);
} else {
if (subAttribute.getMultiValued()) {
((MultiValuedAttribute) subAttribute).deletePrimitiveValues();
JSONArray jsonArray = null;
try {
jsonArray = new JSONArray(operation.getValues());
} catch (JSONException e) {
throw new BadRequestException(ResponseCodeConstants.INVALID_SYNTAX);
}
for (int i = 0; i < jsonArray.length(); i++) {
try {
((MultiValuedAttribute) subAttribute).setAttributePrimitiveValue(jsonArray.get(i));
} catch (JSONException e) {
throw new BadRequestException(ResponseCodeConstants.INVALID_SYNTAX);
}
}
} else {
((SimpleAttribute) subAttribute).setValue(operation.getValues());
}
}
} else {
AttributeSchema subAttributeSchema = SchemaUtil.getAttributeSchema(attributeParts[0] + "." + attributeParts[1], schema);
if (subAttributeSchema.getMultiValued()) {
JSONArray jsonArray = null;
try {
jsonArray = new JSONArray(new JSONTokener(operation.getValues().toString()));
} catch (JSONException e) {
throw new BadRequestException(ResponseCodeConstants.INVALID_SYNTAX);
}
MultiValuedAttribute newMultiValuedAttribute = decoder.buildPrimitiveMultiValuedAttribute(subAttributeSchema, jsonArray);
((ComplexAttribute) (subValue)).setSubAttribute(newMultiValuedAttribute);
} else {
SimpleAttribute simpleAttribute = decoder.buildSimpleAttribute(subAttributeSchema, operation.getValues());
((ComplexAttribute) (subValue)).setSubAttribute(simpleAttribute);
}
}
}
} else {
Attribute subAttribute = ((attribute)).getSubAttribute(attributeParts[1]);
AttributeSchema subAttributeSchema = SchemaUtil.getAttributeSchema(attributeParts[0] + "." + attributeParts[1], schema);
if (subAttributeSchema != null) {
if (subAttributeSchema.getType().equals(SCIMDefinitions.DataType.COMPLEX)) {
// only extension schema reaches here.
if (subAttribute != null) {
if (!subAttribute.getMultiValued()) {
if (subAttribute.getMutability().equals(SCIMDefinitions.Mutability.READ_ONLY) || subAttribute.getMutability().equals(SCIMDefinitions.Mutability.IMMUTABLE)) {
throw new BadRequestException("Can not replace a immutable attribute or a read-only attribute", ResponseCodeConstants.MUTABILITY);
} else {
ComplexAttribute newComplexAttribute = null;
try {
newComplexAttribute = decoder.buildComplexAttribute(subAttributeSchema, (JSONObject) operation.getValues());
} catch (JSONException e) {
throw new BadRequestException(ResponseCodeConstants.INVALID_SYNTAX);
}
((ComplexAttribute) (attribute)).removeSubAttribute(attributeParts[1]);
((ComplexAttribute) (attribute)).setSubAttribute(newComplexAttribute);
}
} else {
if (subAttribute.getMutability().equals(SCIMDefinitions.Mutability.READ_ONLY) || subAttribute.getMutability().equals(SCIMDefinitions.Mutability.IMMUTABLE)) {
throw new BadRequestException("Can not replace a immutable attribute or a read-only attribute", ResponseCodeConstants.MUTABILITY);
} else {
JSONArray jsonArray = null;
try {
jsonArray = new JSONArray(new JSONTokener(operation.getValues().toString()));
} catch (JSONException e) {
throw new BadRequestException(ResponseCodeConstants.INVALID_SYNTAX);
}
MultiValuedAttribute newMultiValuesAttribute = decoder.buildComplexMultiValuedAttribute(subAttributeSchema, jsonArray);
((ComplexAttribute) (attribute)).removeSubAttribute(attributeParts[1]);
((ComplexAttribute) (attribute)).setSubAttribute(newMultiValuesAttribute);
}
}
} else {
if (subAttributeSchema.getMultiValued()) {
JSONArray jsonArray = null;
try {
jsonArray = new JSONArray(new JSONTokener(operation.getValues().toString()));
} catch (JSONException e) {
throw new BadRequestException(ResponseCodeConstants.INVALID_SYNTAX);
}
MultiValuedAttribute newMultiValuesAttribute = decoder.buildComplexMultiValuedAttribute(subAttributeSchema, jsonArray);
((ComplexAttribute) (attribute)).setSubAttribute(newMultiValuesAttribute);
} else {
ComplexAttribute newComplexAttribute = null;
try {
newComplexAttribute = decoder.buildComplexAttribute(subAttributeSchema, (JSONObject) operation.getValues());
} catch (JSONException e) {
throw new BadRequestException(ResponseCodeConstants.INVALID_SYNTAX);
}
((ComplexAttribute) (attribute)).setSubAttribute(newComplexAttribute);
}
}
} else {
if (subAttribute != null) {
if (subAttribute.getMutability().equals(SCIMDefinitions.Mutability.READ_ONLY) || subAttribute.getMutability().equals(SCIMDefinitions.Mutability.IMMUTABLE)) {
throw new BadRequestException("Can not replace a immutable attribute or a read-only attribute", ResponseCodeConstants.MUTABILITY);
} else {
AttributeSchema attributeSchema = SchemaUtil.getAttributeSchema(attributeParts[0] + "." + attributeParts[1], schema);
if (subAttribute.getMultiValued()) {
JSONArray jsonArray = null;
try {
jsonArray = new JSONArray(new JSONTokener(operation.getValues().toString()));
} catch (JSONException e) {
throw new BadRequestException(ResponseCodeConstants.INVALID_SYNTAX);
}
MultiValuedAttribute newMultiValuedAttribute = decoder.buildPrimitiveMultiValuedAttribute(attributeSchema, jsonArray);
((ComplexAttribute) (attribute)).removeSubAttribute(attributeParts[1]);
((ComplexAttribute) (attribute)).setSubAttribute(newMultiValuedAttribute);
} else {
SimpleAttribute simpleAttribute = decoder.buildSimpleAttribute(attributeSchema, operation.getValues());
((ComplexAttribute) (attribute)).removeSubAttribute(attributeParts[1]);
((ComplexAttribute) (attribute)).setSubAttribute(simpleAttribute);
}
}
} else {
// add the values
AttributeSchema attributeSchema = SchemaUtil.getAttributeSchema(attributeParts[0] + "." + attributeParts[1], schema);
if (attributeSchema.getMultiValued()) {
JSONArray jsonArray = null;
try {
jsonArray = new JSONArray(new JSONTokener(operation.getValues().toString()));
} catch (JSONException e) {
throw new BadRequestException(ResponseCodeConstants.INVALID_SYNTAX);
}
MultiValuedAttribute newMultiValuedAttribute = decoder.buildPrimitiveMultiValuedAttribute(attributeSchema, jsonArray);
((ComplexAttribute) (attribute)).setSubAttribute(newMultiValuedAttribute);
} else {
SimpleAttribute simpleAttribute = decoder.buildSimpleAttribute(attributeSchema, operation.getValues());
((ComplexAttribute) (attribute)).setSubAttribute(simpleAttribute);
}
}
}
} else {
throw new BadRequestException("No such attribute with the name : " + attributeParts[1], ResponseCodeConstants.NO_TARGET);
}
}
} else {
AttributeSchema attributeSchema = SchemaUtil.getAttributeSchema(attributeParts[0], schema);
if (attributeSchema != null) {
if (attributeSchema.getMultiValued()) {
MultiValuedAttribute multiValuedAttribute = new MultiValuedAttribute(attributeSchema.getName());
DefaultAttributeFactory.createAttribute(attributeSchema, multiValuedAttribute);
AttributeSchema subAttributeSchema = SchemaUtil.getAttributeSchema(attributeParts[0] + "." + attributeParts[1], schema);
if (subAttributeSchema != null) {
SimpleAttribute simpleAttribute = new SimpleAttribute(subAttributeSchema.getName(), operation.getValues());
DefaultAttributeFactory.createAttribute(subAttributeSchema, simpleAttribute);
String complexAttributeName = attributeSchema.getName() + "_" + operation.getValues() + "_" + SCIMConstants.DEFAULT;
ComplexAttribute complexAttribute = new ComplexAttribute(complexAttributeName);
DefaultAttributeFactory.createAttribute(attributeSchema, complexAttribute);
complexAttribute.setSubAttribute(simpleAttribute);
multiValuedAttribute.setAttributeValue(complexAttribute);
oldResource.setAttribute(multiValuedAttribute);
} else {
throw new BadRequestException("No such attribute with the name : " + attributeParts[1], ResponseCodeConstants.NO_TARGET);
}
} else {
ComplexAttribute complexAttribute = new ComplexAttribute(attributeSchema.getName());
DefaultAttributeFactory.createAttribute(attributeSchema, complexAttribute);
AttributeSchema subAttributeSchema = SchemaUtil.getAttributeSchema(attributeParts[0] + "." + attributeParts[1], schema);
if (subAttributeSchema != null) {
if (subAttributeSchema.getType().equals(SCIMDefinitions.DataType.COMPLEX)) {
if (subAttributeSchema.getMultiValued()) {
JSONArray jsonArray = null;
try {
jsonArray = new JSONArray(new JSONTokener(operation.getValues().toString()));
} catch (JSONException e) {
throw new BadRequestException(ResponseCodeConstants.INVALID_SYNTAX);
}
MultiValuedAttribute multiValuedAttribute = decoder.buildComplexMultiValuedAttribute(subAttributeSchema, jsonArray);
complexAttribute.setSubAttribute(multiValuedAttribute);
} else {
ComplexAttribute subComplexAttribute = null;
try {
subComplexAttribute = decoder.buildComplexAttribute(subAttributeSchema, (JSONObject) operation.getValues());
} catch (JSONException e) {
throw new BadRequestException(ResponseCodeConstants.INVALID_SYNTAX);
}
complexAttribute.setSubAttribute(subComplexAttribute);
}
} else {
SimpleAttribute simpleAttribute = new SimpleAttribute(subAttributeSchema.getName(), operation.getValues());
DefaultAttributeFactory.createAttribute(subAttributeSchema, simpleAttribute);
complexAttribute.setSubAttribute(simpleAttribute);
}
oldResource.setAttribute(complexAttribute);
} else {
throw new BadRequestException("No such attribute with the name : " + attributeParts[1], ResponseCodeConstants.NO_TARGET);
}
}
} else {
throw new BadRequestException("No such attribute with the name : " + attributeParts[0], ResponseCodeConstants.NO_TARGET);
}
}
}
Aggregations