Skip to content
This repository was archived by the owner on Dec 12, 2018. It is now read-only.

Commit f23ad22

Browse files
committed
Added simple group conversion which fixed another IT
1 parent d3004dc commit f23ad22

File tree

2 files changed

+49
-8
lines changed

2 files changed

+49
-8
lines changed

impl/src/main/java/com/stormpath/sdk/impl/group/DefaultGroup.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.stormpath.sdk.directory.Directory;
2424
import com.stormpath.sdk.group.*;
2525
import com.stormpath.sdk.impl.ds.InternalDataStore;
26+
import com.stormpath.sdk.impl.okta.OktaUserAccountConverter;
2627
import com.stormpath.sdk.impl.resource.AbstractExtendableInstanceResource;
2728
import com.stormpath.sdk.impl.resource.CollectionReference;
2829
import com.stormpath.sdk.impl.resource.Property;
@@ -64,7 +65,7 @@ public DefaultGroup(InternalDataStore dataStore) {
6465
}
6566

6667
public DefaultGroup(InternalDataStore dataStore, Map<String, Object> properties) {
67-
super(dataStore, properties);
68+
super(dataStore, OktaUserAccountConverter.toStormpathGroup(properties));
6869
}
6970

7071
@Override

impl/src/main/java/com/stormpath/sdk/impl/okta/OktaUserAccountConverter.java

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.stormpath.sdk.impl.okta;
22

33
import com.stormpath.sdk.account.AccountStatus;
4+
import com.stormpath.sdk.group.Group;
45
import com.stormpath.sdk.lang.Collections;
56
import com.stormpath.sdk.lang.Objects;
67
import com.stormpath.sdk.lang.Strings;
@@ -139,13 +140,11 @@ public static Map<String, Object> toAccount(Map<String, Object> userMap, String
139140
}
140141

141142
// _links.self.href -> href
142-
Map<String, Object> linksMap = getPropertyMap(userMap,OKTA_LINKS);
143-
if (!Collections.isEmpty(linksMap)) {
144-
Map<String, Object> self = getPropertyMap(linksMap, OKTA_SELF);
145-
if (!Collections.isEmpty(self)) {
146-
nullSafePut(accountMap, STORMPATH_HREF, self.get(OKTA_HREF));
147-
}
148-
}
143+
nullSafePut(accountMap, STORMPATH_HREF, getOktaHref(userMap));
144+
145+
Map<String, Object> groupsMap = new LinkedHashMap<>();
146+
groupsMap.put(STORMPATH_HREF, accountMap.get(STORMPATH_HREF) + "/groups");
147+
accountMap.put("groups", groupsMap);
149148

150149
return accountMap;
151150
}
@@ -189,6 +188,19 @@ public static Map<String, Object> toUser(Map<String, Object> accountMap) {
189188
return userMap;
190189
}
191190

191+
private static String getOktaHref(Map<String, Object> properties) {
192+
193+
// _links.self.href -> href
194+
Map<String, Object> linksMap = getPropertyMap(properties,OKTA_LINKS);
195+
if (!Collections.isEmpty(linksMap)) {
196+
Map<String, Object> self = getPropertyMap(linksMap, OKTA_SELF);
197+
if (!Collections.isEmpty(self)) {
198+
return (String) self.get(OKTA_HREF);
199+
}
200+
}
201+
return null;
202+
}
203+
192204
private static String buildFullName(Object firstName, Object lastName) {
193205
return (Objects.getDisplayString(firstName) + " " + Objects.getDisplayString(lastName)).trim();
194206
}
@@ -258,4 +270,32 @@ private static Map<String, Object> trimMap(Map<String, Object> map, String... ke
258270

259271
return result;
260272
}
273+
274+
public static Map<String, Object> toStormpathGroup(Map<String, Object> oktaGroup) {
275+
276+
if (Collections.isEmpty(oktaGroup) || !oktaGroup.containsKey(OKTA_PROFILE)) {
277+
return oktaGroup;
278+
}
279+
280+
Map<String, Object> stormpathGroup = new LinkedHashMap<>();
281+
282+
nullSafePut(stormpathGroup, STORMPATH_CREATED_AT, oktaGroup.get(OKTA_CREATED));
283+
nullSafePut(stormpathGroup, STORMPATH_MODIFIED_AT, oktaGroup.get(OKTA_LAST_UPDATED));
284+
285+
stormpathGroup.put(STORMPATH_STATUS, "ENABLED");
286+
287+
Map<String, Object> profile = getPropertyMap(oktaGroup, OKTA_PROFILE);
288+
if (!Collections.isEmpty(profile)) {
289+
nullSafePut(stormpathGroup, "name", profile.get("name"));
290+
nullSafePut(stormpathGroup, "description", profile.get("description"));
291+
}
292+
293+
// _links.self.href -> href
294+
nullSafePut(stormpathGroup, STORMPATH_HREF, "/api/v1/groups/" + oktaGroup.get("id"));
295+
296+
stormpathGroup.put(STORMPATH_CUSTOM_DATA, new LinkedHashMap<String, Object>());
297+
298+
return stormpathGroup;
299+
}
300+
261301
}

0 commit comments

Comments
 (0)