diff --git a/oxService/src/main/java/org/gluu/model/DisplayNameEntry.java b/oxService/src/main/java/org/gluu/model/DisplayNameEntry.java index 283fd9fa..c9a2f1c2 100644 --- a/oxService/src/main/java/org/gluu/model/DisplayNameEntry.java +++ b/oxService/src/main/java/org/gluu/model/DisplayNameEntry.java @@ -10,6 +10,7 @@ import org.gluu.persist.model.base.Entry; import org.gluu.persist.annotation.AttributeName; +import org.gluu.persist.annotation.CustomObjectClass; import org.gluu.persist.annotation.DataEntry; /** @@ -31,6 +32,9 @@ public DisplayNameEntry(String dn, String inum, String displayName) { this.displayName = displayName; } + @CustomObjectClass + private String[] customObjectClasses; + @AttributeName(ignoreDuringUpdate = true) private String inum; @@ -76,4 +80,12 @@ public String getUid() { return uid; } + public String[] getCustomObjectClasses() { + return customObjectClasses; + } + + public void setCustomObjectClasses(String[] customObjectClasses) { + this.customObjectClasses = customObjectClasses; + } + } diff --git a/oxService/src/main/java/org/gluu/service/LookupService.java b/oxService/src/main/java/org/gluu/service/LookupService.java index de4f608d..0b47d4a7 100644 --- a/oxService/src/main/java/org/gluu/service/LookupService.java +++ b/oxService/src/main/java/org/gluu/service/LookupService.java @@ -47,8 +47,28 @@ public class LookupService implements Serializable { * display name * @return DisplayNameEntry object */ + public DisplayNameEntry getDisplayNameEntry(String dn, String objectClass) throws Exception { + String key = "l_" + objectClass + "_" + dn; + DisplayNameEntry entry = (DisplayNameEntry) cacheService.get(OxConstants.CACHE_LOOKUP_NAME, key); + if (entry == null) { + // Prepare sample for search + DisplayNameEntry sample = new DisplayNameEntry(); + sample.setBaseDn(dn); + sample.setCustomObjectClasses(new String[] { objectClass }); + + List entries = persistenceEntryManager.findEntries(sample, 1); + if (entries.size() == 1) { + entry = entries.get(0); + } + + cacheService.put(OxConstants.CACHE_LOOKUP_NAME, key, entry); + } + + return entry; + } + public T getDisplayNameEntry(String dn, Class entryClass) throws Exception { - String key = "l_" + dn; + String key = "l_" + entryClass.getSimpleName() + "_" + dn; T entry = (T) cacheService.get(OxConstants.CACHE_LOOKUP_NAME, key); if (entry == null) { entry = persistenceEntryManager.find(dn, entryClass, null); @@ -76,7 +96,7 @@ public Object getTypedEntry(String dn, String clazz) throws Exception { } Class entryClass = Class.class.forName(clazz); - String key = "l_" + dn; + String key = "l_" + entryClass.getSimpleName() + "_" + dn; Object entry = cacheService.get(OxConstants.CACHE_LOOKUP_NAME, key); if (entry == null) { entry = persistenceEntryManager.find(entryClass, dn); @@ -103,7 +123,7 @@ public List getDisplayNameEntries(String baseDn, Class entryClass, Lis return null; } - String key = getCompoundKey(inums); + String key = getCompoundKey(entryClass, inums); List entries = (List) cacheService.get(OxConstants.CACHE_LOOKUP_NAME, key); if (entries == null) { Filter searchFilter = buildInumFilter(inums); @@ -144,13 +164,13 @@ public List getInumsFromDns(List dns) { return inums; } - private String getCompoundKey(List inums) { + private String getCompoundKey(Class entryClass, List inums) { StringBuilder compoundKey = new StringBuilder(); for (String inum : inums) { if (compoundKey.length() > 0) { compoundKey.append("_"); } else { - compoundKey.append("l_"); + compoundKey.append("l_" + entryClass.getSimpleName() + "_"); } compoundKey.append(inum); }