gluu
公開メンバ関数 | 非公開メンバ関数 | 非公開変数類 | 全メンバ一覧
org.gluu.oxtrust.service.scim2.serialization.ScimResourceSerializer クラス
org.gluu.oxtrust.service.scim2.serialization.ScimResourceSerializer 連携図
Collaboration graph

公開メンバ関数

String serialize (BaseScimResource resource, String attributes, String exclusions) throws Exception
 
String serialize (BaseScimResource resource) throws Exception
 
ObjectMapper getListResponseMapper ()
 

非公開メンバ関数

Set< String > expandAttributesPaths (String attributes, String defaultSchemaUrn, List< String > schemas, SortedSet< String > attribs)
 
void buildIncludeSet (SortedSet< String > include, Class<? extends BaseScimResource > resourceClass, List< String > schemas, String attributes, String exclussions)
 
boolean containsProperty (SortedSet< String > properties, String prefix, String key)
 
String getNewPrefix (String prefix, String key)
 
Map< String, Object > smallerMap (String prefix, Map< String, Object > value, SortedSet< String > include)
 
void traverse (String prefix, Map< String, Object > map, LinkedHashMap< String, Object > destination, SortedSet< String > include)
 

非公開変数類

Logger log
 
ExtensionService extService
 
ObjectMapper mapper =new ObjectMapper()
 

詳解

Created by jgomer on 2017-10-01.

関数詳解

◆ buildIncludeSet()

void org.gluu.oxtrust.service.scim2.serialization.ScimResourceSerializer.buildIncludeSet ( SortedSet< String >  include,
Class<? extends BaseScimResource resourceClass,
List< String >  schemas,
String  attributes,
String  exclussions 
)
inlineprivate
89  {
90 
91  Set<String> tempSet;
92  Set<String> alwaysSet= IntrospectUtil.alwaysCoreAttrs.get(resourceClass).keySet();
93  Set<String> neverSet=IntrospectUtil.neverCoreAttrs.get(resourceClass).keySet();
94  Set<String> defaultSet=new HashSet<String>();
95 
96  //Here we assume all attributes part of extensions have returnability="default"...
97  SortedSet<String> extendedSet=new TreeSet<String>();
98  for (Extension ext : extService.getResourceExtensions(resourceClass)) {
99  extendedSet.add(ext.getUrn());
100  extendedSet.addAll(IntrospectUtil.getPathsInExtension(ext));
101  }
102 
103  defaultSet.addAll(IntrospectUtil.defaultCoreAttrs.get(resourceClass).keySet());
104  defaultSet.addAll(extendedSet);
105 
106  String defaultSchema=ScimResourceUtil.getDefaultSchemaUrn(resourceClass);
107 
108  if (attributes!=null) {
109  log.info("buildIncludeSet. Processing attributes query param (excludedAttributes ignored)");
110 
111  extendedSet.addAll(IntrospectUtil.allAttrs.get(resourceClass));
112  tempSet= expandAttributesPaths(attributes, defaultSchema, schemas, extendedSet);
113  tempSet.removeAll(neverSet);
114  include.addAll(tempSet);
115  }
116  else
117  if (exclussions!=null){
118  log.info("buildIncludeSet. Processing excludedAttributes query param");
119 
120  extendedSet.addAll(IntrospectUtil.allAttrs.get(resourceClass));
121  tempSet= defaultSet;
122  tempSet.removeAll(expandAttributesPaths(exclussions, defaultSchema, schemas, extendedSet));
123  include.addAll(tempSet);
124  }
125  else{
126  log.info("buildIncludeSet. No attributes neither excludedAttributes query param were passed");
127  include.addAll(defaultSet);
128  }
129  include.addAll(alwaysSet);
130 
131  }
Set< String > expandAttributesPaths(String attributes, String defaultSchemaUrn, List< String > schemas, SortedSet< String > attribs)
Definition: ScimResourceSerializer.java:49
ExtensionService extService
Definition: ScimResourceSerializer.java:45
List< Extension > getResourceExtensions(Class<? extends BaseScimResource > cls)
Definition: ExtensionService.java:46
Logger log
Definition: ScimResourceSerializer.java:42

◆ containsProperty()

boolean org.gluu.oxtrust.service.scim2.serialization.ScimResourceSerializer.containsProperty ( SortedSet< String >  properties,
String  prefix,
String  key 
)
inlineprivate
133  {
134 
135  key = key.startsWith("$") ? key.substring(1) : key; //makes attributes like $ref to be accepted...
136  String property = (prefix.length() == 0) ? key : prefix + "." + key;
137  Set<String> set=properties.tailSet(property);
138 
139  boolean flag=set.contains(property);
140  if (!flag){
141  for (String prop : set)
142  if (prop.startsWith(property + ".")) {
143  flag=true;
144  break;
145  }
146  }
147  return flag;
148 
149  }

◆ expandAttributesPaths()

Set<String> org.gluu.oxtrust.service.scim2.serialization.ScimResourceSerializer.expandAttributesPaths ( String  attributes,
String  defaultSchemaUrn,
List< String >  schemas,
SortedSet< String >  attribs 
)
inlineprivate
49  {
50 
51  Set<String> set=new HashSet<String>();
52 
53  for (String attr : attributes.split(",")) {
54  String shorterName=attr.replaceAll("\\s", "");
55  set.add(ScimResourceUtil.adjustNotationInPath(shorterName, defaultSchemaUrn, schemas));
56  }
57 
58  Set<String> enlargedSet =new HashSet<String>();
59 
60  //attribs is already sorted
61  for (String basicAttr : set){
62  enlargedSet.add(basicAttr);
63 
64  for (String elem : attribs.tailSet(basicAttr + "."))
65  if (elem.startsWith(basicAttr + "."))
66  enlargedSet.add(elem);
67  else
68  break;
69  }
70  //No need for this block: containsProperty method is smart enough
71  /*
72  //Remove redundancies
73  String attrArray[]=list.toArray(new String[]{});
74  Arrays.sort(attrArray);
75  list=new ArrayList<>();
76  int j=0;
77 
78  for (int i=0; i<attrArray.length-1;){
79  String prevAttr=attrArray[i];
80  for (j=i+1;j<attrArray.length && attrArray[j].startsWith(prevAttr + ".");j++);
81  i=j;
82  list.add(prevAttr);
83  }
84  */
85  return enlargedSet;
86  }

◆ getListResponseMapper()

ObjectMapper org.gluu.oxtrust.service.scim2.serialization.ScimResourceSerializer.getListResponseMapper ( )
inline
226  {
227 
228  ObjectMapper mapper = new ObjectMapper();
229  SimpleModule module=new SimpleModule("ListResponseModule", Version.unknownVersion());
230  module.addSerializer(ListResponse.class, new ListResponseJsonSerializer(this));
231  mapper.registerModule(module);
232 
233  return mapper;
234  }
ObjectMapper mapper
Definition: ScimResourceSerializer.java:47

◆ getNewPrefix()

String org.gluu.oxtrust.service.scim2.serialization.ScimResourceSerializer.getNewPrefix ( String  prefix,
String  key 
)
inlineprivate
151  {
152  return prefix + (prefix.length()==0 ? "" : ".") + key;
153  }

◆ serialize() [1/2]

String org.gluu.oxtrust.service.scim2.serialization.ScimResourceSerializer.serialize ( BaseScimResource  resource,
String  attributes,
String  exclusions 
) throws Exception
inline
203  {
204 
205  SortedSet<String> include = new TreeSet<String>();
206  Class<? extends BaseScimResource> resourceClass = resource.getClass();
207  buildIncludeSet(include, resourceClass, new ArrayList<String>(resource.getSchemas()), attributes, exclusions);
208  log.trace("serialize. Attributes to include: {}", include);
209 
210  //Do generic serialization. This works for any POJO (not only subclasses of BaseScimResource)
211  Map<String, Object> map = mapper.convertValue(resource, new TypeReference<Map<String, Object>>() { });
212  //Using LinkedHashMap allows recursive routines to visit submaps in the same order as fields appear in java classes
213  LinkedHashMap<String, Object> newMap = new LinkedHashMap<String, Object>();
214  traverse("", map, newMap, include);
215 
216  String result = mapper.writeValueAsString(newMap);
217  log.trace("serialize. Output is {}", result);
218 
219  return result;
220  }
void buildIncludeSet(SortedSet< String > include, Class<? extends BaseScimResource > resourceClass, List< String > schemas, String attributes, String exclussions)
Definition: ScimResourceSerializer.java:88
void traverse(String prefix, Map< String, Object > map, LinkedHashMap< String, Object > destination, SortedSet< String > include)
Definition: ScimResourceSerializer.java:169
ObjectMapper mapper
Definition: ScimResourceSerializer.java:47
Logger log
Definition: ScimResourceSerializer.java:42

◆ serialize() [2/2]

String org.gluu.oxtrust.service.scim2.serialization.ScimResourceSerializer.serialize ( BaseScimResource  resource) throws Exception
inline
222  {
223  return serialize(resource, null, null);
224  }
String serialize(BaseScimResource resource, String attributes, String exclusions)
Definition: ScimResourceSerializer.java:203

◆ smallerMap()

Map<String, Object> org.gluu.oxtrust.service.scim2.serialization.ScimResourceSerializer.smallerMap ( String  prefix,
Map< String, Object >  value,
SortedSet< String >  include 
)
inlineprivate
155  {
156  LinkedHashMap<String, Object> smallMap = new LinkedHashMap<String, Object>();
157  traverse(prefix, value, smallMap, include);
158  return smallMap.size()==0 ? null : smallMap;
159  }
void traverse(String prefix, Map< String, Object > map, LinkedHashMap< String, Object > destination, SortedSet< String > include)
Definition: ScimResourceSerializer.java:169

◆ traverse()

void org.gluu.oxtrust.service.scim2.serialization.ScimResourceSerializer.traverse ( String  prefix,
Map< String, Object >  map,
LinkedHashMap< String, Object >  destination,
SortedSet< String >  include 
)
inlineprivate

Section 2.5 of RFC 7643: When a resource is expressed in JSON format, unassigned attributes, although they are defined in schema, MAY be omitted for compactness

引数
prefix
map
destination
include
169  {
170 
171  for (String key : map.keySet()){
172  Object value=map.get(key);
173 
174  if (value!=null && containsProperty(include, prefix, key)){
175 
176  if (value instanceof Map)
177  value = smallerMap(getNewPrefix(prefix, key), IntrospectUtil.strObjMap(value), include);
178  else
179  if (IntrospectUtil.isCollection(value.getClass())){
180  List list=new ArrayList();
181  Map<String, Object> innerMap;
182 
183  for (Object item : (Collection) value){
184  if (item!=null)
185  if (item instanceof Map) {
186  innerMap=smallerMap(getNewPrefix(prefix, key), IntrospectUtil.strObjMap(item), include);
187  if (innerMap!=null)
188  list.add(innerMap);
189  }
190  else {
191  list.add(item);
192  }
193  }
194  value=list;
195  }
196  if (value!=null)
197  destination.put(key, value);
198  }
199  }
200 
201  }
boolean containsProperty(SortedSet< String > properties, String prefix, String key)
Definition: ScimResourceSerializer.java:133
String getNewPrefix(String prefix, String key)
Definition: ScimResourceSerializer.java:151
Map< String, Object > smallerMap(String prefix, Map< String, Object > value, SortedSet< String > include)
Definition: ScimResourceSerializer.java:155

メンバ詳解

◆ extService

ExtensionService org.gluu.oxtrust.service.scim2.serialization.ScimResourceSerializer.extService
private

◆ log

Logger org.gluu.oxtrust.service.scim2.serialization.ScimResourceSerializer.log
private

◆ mapper

ObjectMapper org.gluu.oxtrust.service.scim2.serialization.ScimResourceSerializer.mapper =new ObjectMapper()
private

このクラス詳解は次のファイルから抽出されました: