155 String path=operation.getPath();
156 ObjectMapper mapper=
new ObjectMapper();
157 Class<? extends BaseScimResource> cls=resource.getClass();
158 Map<String, Object> resourceAsMap=mapper.convertValue(resource,
new TypeReference<Map<String, Object>>(){});
159 List<Map<String, Object>> list;
161 Attribute attrAnnot=IntrospectUtil.getFieldAnnotation(attribute, cls, Attribute.class);
162 if (attrAnnot!=null){
163 if (!attrAnnot.multiValueClass().equals(NullType.class) && attrAnnot.type().equals(AttributeDefinition.Type.COMPLEX)){
164 Object colObject=resourceAsMap.get(attribute);
165 list = colObject==null ? null :
new ArrayList<Map<String, Object>>((Collection<Map<String, Object>>) colObject);
168 throw new SCIMException(String.format(
"Attribute '%s' expected to be complex multi-valued", attribute));
171 throw new SCIMException(String.format(
"Attribute '%s' not recognized or expected to be complex multi-valued", attribute));
174 log.info(
"applyPatchOperationWithValueFilter. List of values for {} is empty. Operation has no effect", attribute);
177 valSelFilter = FilterUtil.preprocess(valSelFilter, cls);
180 List<Integer> matchingIndexes=
new ArrayList<Integer>();
181 for (
int i=0;i<list.size();i++){
183 matchingIndexes.add(0, i);
186 if (subAttribute.length()>0 && matchingIndexes.size()>0 && operation.getType().equals(PatchOperationType.REMOVE)){
188 Attribute subAttrAnnot=IntrospectUtil.getFieldAnnotation(attribute +
"." + subAttribute, cls, Attribute.class);
190 if (subAttrAnnot != null && (subAttrAnnot.mutability().equals(READ_ONLY) || subAttrAnnot.isRequired()))
191 throw new InvalidAttributeValueException(
"Cannot remove read-only or required attribute " + attribute +
"." + subAttribute);
197 log.info(
"There are {} entries matching the filter '{}'", matchingIndexes.size(), path);
199 for (Integer index : matchingIndexes){
200 if (operation.getType().equals(PatchOperationType.REMOVE)) {
201 if (subAttribute.length()==0)
202 list.remove(index.intValue());
204 list.get(index).remove(subAttribute);
210 log.trace(
"New {} list is:\n{}", attribute, mapper.writeValueAsString(list));
211 resourceAsMap.put(attribute, list.size()==0 ? null : list);
212 resource=mapper.convertValue(resourceAsMap, cls);
214 catch (InvalidAttributeValueException ei){
218 log.info(
"Error processing Patch operation with value selection path '{}'", path);
219 log.error(e.getMessage(), e);
220 throw new SCIMException(e.getMessage(), e);
void applyPartialUpdate(String attribute, String subAttribute, List< Map< String, Object >> list, int index, Object value, Class<? extends BaseScimResource > cls)
Definition: Scim2PatchService.java:261
ScimFilterParserService filterService
Definition: Scim2PatchService.java:53
Logger log
Definition: Scim2PatchService.java:50
ParseTree getParseTree(String filter, ScimFilterErrorListener errorListener)
Definition: ScimFilterParserService.java:37
Boolean complexAttributeMatch(ParseTree parseTree, Map< String, Object > item, String parent, Class<? extends BaseScimResource > clazz)
Definition: ScimFilterParserService.java:102