opendj-server-legacy/src/main/java/org/opends/admin/ads/ServerDescriptor.java
@@ -35,6 +35,7 @@ import org.forgerock.i18n.LocalizableMessage; import org.forgerock.i18n.slf4j.LocalizedLogger; import org.forgerock.opendj.ldap.Attribute; import org.forgerock.opendj.ldap.ByteString; import org.forgerock.opendj.ldap.Connection; import org.forgerock.opendj.ldap.DN; import org.forgerock.opendj.ldap.LdapException; @@ -43,6 +44,7 @@ import org.forgerock.opendj.ldap.requests.SearchRequest; import org.forgerock.opendj.ldap.responses.SearchResultEntry; import org.forgerock.opendj.ldif.ConnectionEntryReader; import org.forgerock.util.Function; import org.forgerock.util.Pair; import org.opends.admin.ads.util.ConnectionWrapper; import org.opends.quicksetup.Constants; @@ -680,9 +682,9 @@ { SearchResultEntry sr = entryReader.readEntry(); Integer portNumber = asInteger(sr, "ds-cfg-listen-port"); boolean enabled = asBoolean(sr, "ds-cfg-enabled"); if (asBoolean(sr, "ds-cfg-use-ssl")) Integer portNumber = sr.parseAttribute("ds-cfg-listen-port").asInteger(); Boolean enabled = sr.parseAttribute("ds-cfg-enabled").asBoolean(); if (sr.parseAttribute("ds-cfg-use-ssl").asBoolean()) { ldapsPorts.add(portNumber); ldapsEnabled.add(enabled); @@ -691,7 +693,7 @@ { ldapPorts.add(portNumber); ldapEnabled.add(enabled); startTLSEnabled.add(asBoolean(sr, "ds-cfg-allow-start-tls")); startTLSEnabled.add(sr.parseAttribute("ds-cfg-allow-start-tls").asBoolean()); } } } @@ -704,7 +706,7 @@ "cn=config", WHOLE_SUBTREE, "(objectclass=ds-cfg-administration-connector)", "ds-cfg-listen-port", "objectclass"); SearchResultEntry sr = conn.getConnection().searchSingleEntry(request); Integer adminConnectorPort = asInteger(sr, "ds-cfg-listen-port"); Integer adminConnectorPort = sr.parseAttribute("ds-cfg-listen-port").asInteger(); // Even if we have a single port, use an array to be consistent with // other protocols. @@ -744,9 +746,9 @@ { SearchResultEntry sr = entryReader.readEntry(); Integer portNumber = asInteger(sr, "ds-cfg-listen-port"); boolean enabled = asBoolean(sr, "ds-cfg-enabled"); if (asBoolean(sr, "ds-cfg-use-ssl")) Integer portNumber = sr.parseAttribute("ds-cfg-listen-port").asInteger(); boolean enabled = sr.parseAttribute("ds-cfg-enabled").asBoolean(); if (sr.parseAttribute("ds-cfg-use-ssl").asBoolean()) { jmxsPorts.add(portNumber); jmxsEnabled.add(enabled); @@ -792,14 +794,14 @@ } Set<ReplicaDescriptor> replicas = desc.getReplicas(); Set<DN> baseDns = asSetOfDN(sr, "ds-cfg-base-dn"); Set<DN> baseDns = sr.parseAttribute("ds-cfg-base-dn").asSetOfDN(); for (DN baseDn : baseDns) { if (isAddReplica(cacheFilter, baseDn)) { ReplicaDescriptor replica = new ReplicaDescriptor(); replica.setServer(desc); replica.setObjectClasses(asSetOfString(sr, ConfigConstants.ATTR_OBJECTCLASS)); replica.setObjectClasses(sr.parseAttribute(ConfigConstants.ATTR_OBJECTCLASS).asSetOfString()); replica.setBackendId(backendId); replica.setSuffix(new SuffixDescriptor(baseDn, replica)); replica.setEntries(getNumberOfEntriesForBaseDn(entries, baseDn)); @@ -854,7 +856,7 @@ "(objectclass=ds-cfg-synchronization-provider)", "ds-cfg-enabled"); SearchResultEntry sre = conn.getConnection().searchSingleEntry(request); serverProps.put(ServerProperty.IS_REPLICATION_ENABLED, asBoolean(sre, "ds-cfg-enabled")); serverProps.put(ServerProperty.IS_REPLICATION_ENABLED, sre.parseAttribute("ds-cfg-enabled").asBoolean()); Set<HostPort> allReplicationServers = new LinkedHashSet<>(); @@ -874,9 +876,9 @@ { SearchResultEntry sr = entryReader.readEntry(); int serverId = asInteger(sr, "ds-cfg-server-id"); Set<HostPort> replicationServers = toHostPorts(asSetOfString(sr, "ds-cfg-replication-server")); Set<DN> dns = asSetOfDN(sr, "ds-cfg-base-dn"); int serverId = sr.parseAttribute("ds-cfg-server-id").asInteger(); Set<HostPort> replicationServers = sr.parseAttribute("ds-cfg-replication-server").asSetOf(hostPorts()); Set<DN> dns = sr.parseAttribute("ds-cfg-base-dn").asSetOfDN(); for (DN dn : dns) { for (ReplicaDescriptor replica : desc.getReplicas()) @@ -910,24 +912,29 @@ SearchResultEntry sr = entryReader.readEntry(); serverProps.put(ServerProperty.IS_REPLICATION_SERVER, Boolean.TRUE); serverProps.put(ServerProperty.REPLICATION_SERVER_PORT, asInteger(sr, "ds-cfg-replication-port")); serverProps.put(ServerProperty.REPLICATION_SERVER_ID, asInteger(sr, "ds-cfg-replication-server-id")); allReplicationServers.addAll(toHostPorts(asSetOfString(sr, "ds-cfg-replication-server"))); serverProps.put(ServerProperty.REPLICATION_SERVER_PORT, sr.parseAttribute("ds-cfg-replication-port").asInteger()); serverProps.put(ServerProperty.REPLICATION_SERVER_ID, sr.parseAttribute("ds-cfg-replication-server-id").asInteger()); allReplicationServers.addAll(sr.parseAttribute("ds-cfg-replication-server").asSetOf(hostPorts())); serverProps.put(ServerProperty.EXTERNAL_REPLICATION_SERVERS, allReplicationServers); } } serverProps.put(ServerProperty.IS_REPLICATION_SECURE, isReplicationSecure(conn, asBoolean(sre, "ds-cfg-enabled"))); serverProps.put(ServerProperty.IS_REPLICATION_SECURE, isReplicationSecure(conn, sre.parseAttribute("ds-cfg-enabled").asBoolean())); } private static Set<HostPort> toHostPorts(Set<String> hostPorts) private static Function<ByteString, HostPort, RuntimeException> hostPorts() { final LinkedHashSet<HostPort> results = new LinkedHashSet<>(); for (String hostPort : hostPorts) return new Function<ByteString, HostPort, RuntimeException>() { results.add(HostPort.valueOf(hostPort)); } return results; @Override public HostPort apply(ByteString value) { return HostPort.valueOf(value.toString()); } }; } private static boolean isReplicationSecure(ConnectionWrapper conn, boolean replicationEnabled) throws IOException @@ -942,7 +949,7 @@ while (entryReader.hasNext()) { SearchResultEntry sr = entryReader.readEntry(); return asBoolean(sr, "ds-cfg-ssl-encryption"); return sr.parseAttribute("ds-cfg-ssl-encryption").asBoolean(); } } } @@ -1086,7 +1093,7 @@ while (entryReader.hasNext()) { SearchResultEntry sr = entryReader.readEntry(); results.addAll(asSetOfString(sr, "ds-base-dn-entry-count")); results.addAll(sr.parseAttribute("ds-base-dn-entry-count").asSetOfString()); } } return results; opendj-server-legacy/src/main/java/org/opends/admin/ads/TopologyCache.java
@@ -462,7 +462,7 @@ int replicaId = -1; try { replicaId = sr.getAttribute("server-id").parse().asInteger(); replicaId = sr.parseAttribute("server-id").asInteger(); } catch (Throwable t) { @@ -492,7 +492,7 @@ private void setMissingChanges(ReplicaDescriptor replica, SearchResultEntry sr) { Integer value = asInteger(sr, "missing-changes"); Integer value = sr.parseAttribute("missing-changes").asInteger(); if (value != null) { try opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionUtils.java
@@ -16,11 +16,7 @@ */ package org.opends.admin.ads.util; import java.util.Collections; import java.util.Set; import org.forgerock.opendj.ldap.Attribute; import org.forgerock.opendj.ldap.DN; import org.forgerock.opendj.ldap.Entry; /** @@ -48,68 +44,4 @@ Attribute attr = entry.getAttribute(attrDesc); return (attr != null && !attr.isEmpty()) ? attr.firstValueAsString() : null; } /** * Returns the first value decoded as an Integer, or {@code null} if the attribute does not * contain any values. * * @param entry * the entry * @param attrDesc * the attribute description * @return The first value decoded as an Integer. */ public static Integer asInteger(Entry entry, String attrDesc) { Attribute attr = entry.getAttribute(attrDesc); return attr != null ? attr.parse().asInteger() : null; } /** * Returns the first value decoded as a Boolean, or {@code null} if the attribute does not contain * any values. * * @param entry * the entry * @param attrDesc * the attribute description * @return The first value decoded as an Boolean. */ public static Boolean asBoolean(Entry entry, String attrDesc) { Attribute attr = entry.getAttribute(attrDesc); return attr != null ? attr.parse().asBoolean() : null; } /** * Returns the values decoded as a set of Strings. * * @param entry * the entry * @param attrDesc * the attribute description * @return The values decoded as a set of Strings. Never {@code null} and never contains * {@code null} values. */ public static Set<String> asSetOfString(Entry entry, String attrDesc) { Attribute attr = entry.getAttribute(attrDesc); return attr != null ? attr.parse().asSetOfString() : Collections.<String> emptySet(); } /** * Returns the values decoded as a set of DNs. * * @param entry * the entry * @param attrDesc * the attribute description * @return The values decoded as a set of DNs. Never {@code null} and never contains {@code null} * values. */ public static Set<DN> asSetOfDN(Entry entry, String attrDesc) { Attribute attr = entry.getAttribute(attrDesc); return attr != null ? attr.parse().asSetOfDN() : Collections.<DN> emptySet(); } } opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/BrowserController.java
@@ -1386,8 +1386,8 @@ node.setHasSubOrdinates( node.getNumSubOrdinates() > 0 || getHasSubOrdinates(entry)); node.setReferral(getReferral(entry)); Set<String> ocValues = asSetOfString(entry, OBJECTCLASS_ATTRIBUTE_TYPE_NAME); node.setObjectClassValues(ocValues.toArray(new String[0])); String[] ocValues = entry.parseAttribute(OBJECTCLASS_ATTRIBUTE_TYPE_NAME).asSetOfString().toArray(new String[0]); node.setObjectClassValues(ocValues); } int aciCount = getAciCount(entry); @@ -1489,7 +1489,7 @@ private int getAciCount(SearchResultEntry entry) { if ((displayFlags & DISPLAY_ACI_COUNT) != 0 && entry != null) { return asSetOfString(entry, "aci").size(); return entry.parseAttribute("aci").asSetOfByteString().size(); } return 0; } @@ -1515,7 +1515,7 @@ SortedSet<String> objectClasses = new TreeSet<>(); if (entry != null) { objectClasses.addAll(asSetOfString(entry, "objectClass")); objectClasses.addAll(entry.parseAttribute("objectClass").asSetOfString()); } if (node instanceof SuffixNode) @@ -1719,12 +1719,12 @@ */ public static String[] getReferral(SearchResultEntry entry) { Set<String> values = asSetOfString(entry, OBJECTCLASS_ATTRIBUTE_TYPE_NAME); Set<String> values = entry.parseAttribute(OBJECTCLASS_ATTRIBUTE_TYPE_NAME).asSetOfString(); for (String value : values) { if ("referral".equalsIgnoreCase(value)) { Set<String> refValues = asSetOfString(entry, ATTR_REFERRAL_URL); Set<String> refValues = entry.parseAttribute(ATTR_REFERRAL_URL).asSetOfString(); return !refValues.isEmpty() ? refValues.toArray(new String[0]) : null; } } opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/NodeRefresher.java
@@ -879,7 +879,7 @@ */ private static boolean isReferralEntry(SearchResultEntry entry) { for (String value : asSetOfString(entry, "objectClass")) for (String value : entry.parseAttribute("objectClass").asSetOfString()) { if ("referral".equalsIgnoreCase(value)) { opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/AddToGroupTask.java
@@ -217,14 +217,14 @@ while (reader.hasNext()) { SearchResultEntry sr = reader.readEntry(); Set<String> objectClasses = asSetOfString(sr, OBJECTCLASS_ATTRIBUTE_TYPE_NAME); Set<String> objectClasses = sr.parseAttribute(OBJECTCLASS_ATTRIBUTE_TYPE_NAME).asSetOfString(); if (objectClasses.contains(OC_GROUP_OF_UNIQUE_NAMES)) { memberAttr = ATTR_UNIQUE_MEMBER; } Set<DN> dnsToAdd = new LinkedHashSet<>(dns); // remove all existing members dnsToAdd.removeAll(asSetOfDN(sr, memberAttr)); dnsToAdd.removeAll(sr.parseAttribute(memberAttr).asSetOfDN()); if (!dnsToAdd.isEmpty()) { modRequest.addModification(ADD, memberAttr, dnsToAdd.toArray()); opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/ResetUserPasswordTask.java
@@ -240,7 +240,7 @@ while (entries.hasNext()) { SearchResultEntry sr = entries.readEntry(); return asSetOfDN(sr, attrName).contains(bindDN); return sr.parseAttribute(attrName).asSetOfDN().contains(bindDN); } } catch (Throwable t) opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/StatusGenericPanel.java
@@ -18,7 +18,6 @@ import static org.forgerock.opendj.ldap.SearchScope.*; import static org.forgerock.opendj.ldap.requests.Requests.*; import static org.opends.admin.ads.util.ConnectionUtils.*; import static org.opends.guitools.controlpanel.browser.BrowserController.*; import static org.opends.guitools.controlpanel.ui.ControlCenterMainPane.*; import static org.opends.messages.AdminToolMessages.*; @@ -77,6 +76,7 @@ import org.forgerock.opendj.ldap.responses.SearchResultEntry; import org.forgerock.opendj.ldap.schema.ObjectClass; import org.forgerock.opendj.ldap.schema.ObjectClassType; import org.forgerock.opendj.ldap.schema.Schema; import org.forgerock.opendj.ldif.ConnectionEntryReader; import org.opends.guitools.controlpanel.browser.IconPool; import org.opends.guitools.controlpanel.datamodel.AbstractIndexDescriptor; @@ -102,8 +102,6 @@ import org.opends.guitools.controlpanel.util.Utilities; import org.opends.quicksetup.ui.CustomHTMLEditorKit; import org.opends.server.types.OpenDsException; import org.forgerock.opendj.ldap.schema.Schema; import org.opends.server.util.ServerConstants; import org.opends.server.util.StaticUtils; /** @@ -2037,7 +2035,7 @@ while (entryReader.hasNext()) { SearchResultEntry sr = entryReader.readEntry(); for (String oc : asSetOfString(sr, ServerConstants.OBJECTCLASS_ATTRIBUTE_TYPE_NAME)) for (String oc : sr.parseAttribute(OBJECTCLASS_ATTRIBUTE_TYPE_NAME).asSetOfString()) { for (String objectClass : objectClasses) { opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/ConfigFromConnection.java
@@ -18,7 +18,6 @@ import static org.forgerock.opendj.ldap.SearchScope.*; import static org.forgerock.opendj.ldap.requests.Requests.*; import static org.opends.admin.ads.util.ConnectionUtils.*; import static org.opends.messages.AdminToolMessages.*; import static org.opends.server.backends.pluggable.SuffixContainer.*; import static org.opends.server.config.ConfigConstants.*; @@ -41,7 +40,6 @@ import java.util.TreeSet; import org.forgerock.i18n.LocalizableMessage; import org.forgerock.i18n.LocalizedIllegalArgumentException; import org.forgerock.i18n.slf4j.LocalizedLogger; import org.forgerock.opendj.adapter.server3x.Converters; import org.forgerock.opendj.config.server.ConfigException; @@ -666,44 +664,30 @@ if (numberConnections == -1) { Integer nb = sr.getAttribute("currentConnections").parse().asInteger(); Integer nb = sr.parseAttribute("currentConnections").asInteger(); if (nb != null) { numberConnections = nb; } } Attribute dnAttr = sr.getAttribute("domain-name"); Attribute replicaIdAttr = sr.getAttribute("server-id"); Attribute missingChanges = sr.getAttribute("missing-changes"); DN suffixDn = sr.parseAttribute("domain-name").asDN(); Integer replicaId = sr.parseAttribute("server-id").asInteger(); Integer missingChanges = sr.parseAttribute("missing-changes").asInteger(); if (dnAttr != null && replicaIdAttr != null && missingChanges != null) if (suffixDn != null && replicaId != null && missingChanges != null) { DN dn = dnAttr.parse().asDN(); Integer replicaId = replicaIdAttr.parse().asInteger(); for (BackendDescriptor backend : backends) { for (BaseDNDescriptor baseDN : backend.getBaseDns()) { try { if (baseDN.getDn().equals(dn) && Objects.equals(baseDN.getReplicaID(), replicaId)) if (baseDN.getDn().equals(suffixDn) && Objects.equals(baseDN.getReplicaID(), replicaId)) { try { baseDN.setAgeOfOldestMissingChange( sr.getAttribute("approx-older-change-not-synchronized-millis").parse().asLong()); } catch (NullPointerException | LocalizedIllegalArgumentException ignored) { } try { baseDN.setMissingChanges(missingChanges.parse().asInteger()); } catch (NullPointerException | LocalizedIllegalArgumentException ignored) { } baseDN.setAgeOfOldestMissingChange( sr.parseAttribute("approx-older-change-not-synchronized-millis").asLong()); baseDN.setMissingChanges(missingChanges); } } catch (Throwable ignored) @@ -715,8 +699,8 @@ else { Attribute backendIdAttr = sr.getAttribute("ds-backend-id"); Attribute entryCount = sr.getAttribute("ds-backend-entry-count"); Set<String> baseDnEntries = asSetOfString(sr, "ds-base-dn-entry-count"); Integer entryCount = sr.parseAttribute("ds-backend-entry-count").asInteger(); Set<String> baseDnEntries = sr.parseAttribute("ds-base-dn-entry-count").asSetOfString(); if (backendIdAttr != null && (entryCount != null || !baseDnEntries.isEmpty())) { String backendID = backendIdAttr.firstValueAsString(); @@ -726,7 +710,7 @@ { if (entryCount != null) { backend.setEntries(entryCount.parse().asInteger()); backend.setEntries(entryCount); } for (String s : baseDnEntries) { @@ -1042,7 +1026,7 @@ DN parent = dn.parent(); if (parent != null && parent.equals(monitorDN)) { Set<String> vs = sr.getAttribute("cn").parse().asSetOfString(); Set<String> vs = sr.parseAttribute("cn").asSetOfString(); if (!vs.isEmpty()) { String cn = vs.iterator().next(); @@ -1058,7 +1042,7 @@ private static boolean isTaskEntry(SearchResultEntry sr) { for (String oc : sr.getAttribute("objectclass").parse().asSetOfString()) for (String oc : sr.parseAttribute("objectclass").asSetOfString()) { if (oc.equalsIgnoreCase("ds-task")) { opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java
@@ -4205,10 +4205,9 @@ try { SearchResultEntry sr = conn.getConnection().searchSingleEntry(searchRequest); // Get the number of entries that have been handled and // a percentage... long processed = asInteger(sr, "ds-task-processed-entry-count"); long unprocessed = asInteger(sr, "ds-task-unprocessed-entry-count"); // Get the number of entries that have been handled and a percentage... long processed = sr.parseAttribute("ds-task-processed-entry-count").asLong(); long unprocessed = sr.parseAttribute("ds-task-unprocessed-entry-count").asLong(); totalEntries = Math.max(totalEntries, processed + unprocessed); LocalizableMessage msg = getLocalizedMessage(lastDisplayedMsg, processed, unprocessed); opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java
@@ -6838,8 +6838,8 @@ "ds-task-processed-entry-count", "ds-task-log-message", "ds-task-state" ); // Get the number of entries that have been handled and a percentage... long processed = asInteger(sr, "ds-task-processed-entry-count"); long unprocessed = asInteger(sr, "ds-task-unprocessed-entry-count"); long processed = sr.parseAttribute("ds-task-processed-entry-count").asLong(); long unprocessed = sr.parseAttribute("ds-task-unprocessed-entry-count").asLong(); totalEntries = Math.max(totalEntries, processed+unprocessed); LocalizableMessage msg = getMsg(lastDisplayedMsg, processed, unprocessed);