Skip to content

Commit eedae7c

Browse files
zuglahrouazana
authored andcommitted
Allow LinkedHashMap attributes value management
1 parent 255f324 commit eedae7c

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

sample/msgraphapi-to-ldap-advanced/lsc.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
<msgraphapi:filter>startsWith(mail, 'a')</msgraphapi:filter>
4646
<msgraphapi:pivot>userPrincipalName</msgraphapi:pivot>
4747
<msgraphapi:pageSize>999</msgraphapi:pageSize>
48-
<msgraphapi:select>userPrincipalName,mail,displayName</msgraphapi:select>
48+
<msgraphapi:select>userPrincipalName,mail,displayName,onPremisesExtensionAttributes</msgraphapi:select>
4949
</msgraphapi:msGraphApiUsersService>
5050
</pluginSourceService>
5151
<ldapDestinationService>
@@ -61,6 +61,7 @@
6161
<string>cn</string>
6262
<string>mail</string>
6363
<string>sn</string>
64+
<string>description</string>
6465
</fetchedAttributes>
6566
<getAllFilter>(&amp;(objectClass=person)(uid=*))</getAllFilter>
6667
<getOneFilter>(&amp;(objectClass=person)(uid={userPrincipalName}))</getOneFilter>
@@ -99,6 +100,12 @@
99100
<string>srcBean.getDatasetValuesById("displayName")</string>
100101
</forceValues>
101102
</dataset>
103+
<dataset>
104+
<name>description<name>
105+
<forceValues>
106+
<string>srcBean.getDatasetFirstValueById("onPremisesExtensionAttributes/extensionAttribute1")</string>
107+
</forceValues>
108+
</dataset>
102109
</propertiesBasedSyncOptions>
103110
</task>
104111
</tasks>

src/main/java/org/lsc/plugins/connectors/msgraphapi/MsGraphApiUsersSrcService.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@
4646

4747
import java.util.HashMap;
4848
import java.util.LinkedHashSet;
49+
import java.util.Set;
4950
import java.util.List;
5051
import java.util.Map;
5152
import java.util.Optional;
53+
import java.util.LinkedHashMap;
5254

5355
import javax.ws.rs.NotFoundException;
5456
import javax.ws.rs.ProcessingException;
@@ -189,8 +191,26 @@ IBean mapToBean(String idValue, Map<String, Object> user) throws InstantiationEx
189191
bean.setMainIdentifier(idValue);
190192

191193
LscDatasets datasets = new LscDatasets();
192-
user.entrySet().stream()
193-
.forEach(entry -> datasets.put(entry.getKey(), entry.getValue() == null ? new LinkedHashSet<>() : entry.getValue()));
194+
/* In new version, graphApi uses LinkedHashMap values
195+
* like: Key={childKey=value, childKey2=value2, ...}
196+
* Then in this case you could retrieve in bean
197+
* attribute values as "<Key>/<childKey>" = "<childValue>".
198+
* ex: "onPremisesExtensionAttributes/extensionAttribute1" = "toto"
199+
*/
200+
for (Map.Entry entry : user.entrySet()) {
201+
if (entry.getValue() instanceof java.util.LinkedHashMap) {
202+
LinkedHashMap innerMap = (LinkedHashMap) entry.getValue();
203+
Set<String> keys = innerMap.keySet();
204+
for ( String key : keys ) {
205+
datasets.put(entry.getKey() + "/" + key,
206+
innerMap.get(key) == null ? new LinkedHashSet<>() : innerMap.get(key));
207+
}
208+
}
209+
else {
210+
datasets.put((String)entry.getKey(),
211+
entry.getValue() == null ? new LinkedHashSet<>() : entry.getValue());
212+
}
213+
}
194214

195215
bean.setDatasets(datasets);
196216

0 commit comments

Comments
 (0)