1 package org
.argeo
.cms
.directory
.ldap
;
3 import java
.util
.Locale
;
5 import javax
.naming
.ldap
.LdapName
;
6 import javax
.naming
.ldap
.Rdn
;
8 import org
.argeo
.api
.cms
.directory
.HierarchyUnit
;
10 /** LDIF/LDAP based implementation of {@link HierarchyUnit}. */
11 public class LdapHierarchyUnit
extends DefaultLdapEntry
implements HierarchyUnit
{
12 // private final boolean functional;
14 private final Type type
;
16 public LdapHierarchyUnit(AbstractLdapDirectory directory
, LdapName dn
) {
19 Rdn rdn
= LdapNameUtils
.getLastRdn(dn
);
20 if (directory
.getUserBaseRdn().equals(rdn
))
22 else if (directory
.getGroupBaseRdn().equals(rdn
))
24 else if (directory
.getSystemRoleBaseRdn().equals(rdn
))
27 type
= Type
.FUNCTIONAL
;
28 // functional = !(directory.getUserBaseRdn().equals(rdn) || directory.getGroupBaseRdn().equals(rdn)
29 // || directory.getSystemRoleBaseRdn().equals(rdn));
33 public HierarchyUnit
getParent() {
34 return getDirectoryDao().doGetHierarchyUnit(LdapNameUtils
.getParent(getDn()));
38 public Iterable
<HierarchyUnit
> getDirectHierarchyUnits(boolean functionalOnly
) {
39 return getDirectoryDao().doGetDirectHierarchyUnits(getDn(), functionalOnly
);
43 public HierarchyUnit
getDirectChild(Type type
) {
44 return switch (type
) {
46 getDirectoryDao().doGetHierarchyUnit((LdapName
) getDn().add(getDirectory().getSystemRoleBaseRdn()));
47 case PEOPLE
-> getDirectoryDao().doGetHierarchyUnit((LdapName
) getDn().add(getDirectory().getUserBaseRdn()));
48 case GROUPS
-> getDirectoryDao().doGetHierarchyUnit((LdapName
) getDn().add(getDirectory().getGroupBaseRdn()));
49 case FUNCTIONAL
-> throw new IllegalArgumentException("Type must be a technical type");
54 public boolean isType(Type type
) {
55 return this.type
.equals(type
);
59 public String
getHierarchyUnitName() {
60 String name
= LdapNameUtils
.getLastRdnValue(getDn());
61 // TODO check ou, o, etc.
66 public String
getHierarchyUnitLabel(Locale locale
) {
67 String key
= LdapNameUtils
.getLastRdn(getDn()).getType();
68 Object value
= LdapEntry
.getLocalized(getProperties(), key
, locale
);
70 value
= getHierarchyUnitName();
72 return value
.toString();
76 public String
getBase() {
77 return getDn().toString();
81 public String
toString() {
82 return "Hierarchy Unit " + getDn().toString();