Use the new Entry.parseAttribute() method
Replaced calls to ConnectionUtils.firstValueAsString() by Entry.parseAttribute().
Inlined BackendToolUtils.getStringSingleValuedAttribute().
| | |
| | | |
| | | import static org.forgerock.opendj.ldap.SearchScope.*; |
| | | import static org.forgerock.opendj.ldap.requests.Requests.*; |
| | | import static org.opends.admin.ads.util.ConnectionUtils.*; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | |
| | | { |
| | | SearchResultEntry sr = entryReader.readEntry(); |
| | | |
| | | String backendId = firstValueAsString(sr, "ds-cfg-backend-id"); |
| | | String backendId = sr.parseAttribute("ds-cfg-backend-id").asString(); |
| | | if (!isConfigBackend(backendId) || isSchemaBackend(backendId)) |
| | | { |
| | | Set<String> entries; |
| | |
| | | SearchResultEntry sr = entryReader.readEntry(); |
| | | |
| | | desc.serverProperties.put(ServerProperty.SCHEMA_GENERATION_ID, |
| | | firstValueAsString(sr, "ds-sync-generation-id")); |
| | | sr.parseAttribute("ds-sync-generation-id").asString()); |
| | | } |
| | | } |
| | | } |
| | |
| | | import java.util.Set; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.LocalizedIllegalArgumentException; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.EntryNotFoundException; |
| | |
| | | |
| | | 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.QuickSetupMessages.*; |
| | | |
| | | /** |
| | |
| | | { |
| | | SearchResultEntry sr = entryReader.readEntry(); |
| | | |
| | | final DN dn = DN.valueOf(firstValueAsString(sr, "domain-name")); |
| | | final DN dn = sr.parseAttribute("domain-name").asDN(); |
| | | int replicaId = -1; |
| | | try |
| | | { |
| | |
| | | |
| | | private void setAgeOfOldestMissingChange(ReplicaDescriptor replica, SearchResultEntry sr) |
| | | { |
| | | String s = firstValueAsString(sr, "approx-older-change-not-synchronized-millis"); |
| | | if (s != null) |
| | | try |
| | | { |
| | | try |
| | | { |
| | | replica.setAgeOfOldestMissingChange(Long.valueOf(s)); |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | logger.warn(LocalizableMessage.raw( |
| | | "Unexpected error reading age of oldest change: " + t, t)); |
| | | } |
| | | replica.setAgeOfOldestMissingChange( |
| | | sr.parseAttribute("approx-older-change-not-synchronized-millis").asLong()); |
| | | } |
| | | catch (LocalizedIllegalArgumentException t) |
| | | { |
| | | logger.warn(LocalizableMessage.raw("Unexpected error reading age of oldest change: " + t, t)); |
| | | } |
| | | } |
| | | |
| | |
| | | import javax.swing.tree.TreeNode; |
| | | import javax.swing.tree.TreePath; |
| | | |
| | | import org.forgerock.i18n.LocalizedIllegalArgumentException; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.Entry; |
| | | import org.forgerock.opendj.ldap.EntryNotFoundException; |
| | |
| | | */ |
| | | private static int getNumSubOrdinates(Entry entry) |
| | | { |
| | | return toInt(firstValueAsString(entry, NUMSUBORDINATES_ATTR)); |
| | | try |
| | | { |
| | | return entry.parseAttribute(NUMSUBORDINATES_ATTR).asInteger(0); |
| | | } |
| | | catch (LocalizedIllegalArgumentException e) |
| | | { |
| | | return 0; |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public static boolean getHasSubOrdinates(Entry entry) |
| | | { |
| | | String v = firstValueAsString(entry, HASSUBORDINATES_ATTR); |
| | | if (v != null) { |
| | | return "true".equalsIgnoreCase(v); |
| | | } |
| | | return getNumSubOrdinates(entry) > 0; |
| | | } |
| | | |
| | | private static int toInt(String v) |
| | | { |
| | | if (v == null) |
| | | { |
| | | return 0; |
| | | } |
| | | try |
| | | { |
| | | return Integer.parseInt(v); |
| | | } |
| | | catch (NumberFormatException x) |
| | | { |
| | | return 0; |
| | | } |
| | | Boolean val = entry.parseAttribute(HASSUBORDINATES_ATTR).asBoolean(); |
| | | return val != null ? val : getNumSubOrdinates(entry) > 0; |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | import static com.forgerock.opendj.util.OperatingSystem.*; |
| | | |
| | | import static org.opends.admin.ads.util.ConnectionUtils.*; |
| | | import static org.opends.admin.ads.util.PreferredConnection.Type.*; |
| | | import static org.opends.server.tools.ConfigureWindowsService.*; |
| | | |
| | |
| | | desc.setJvmMemoryUsageMonitor(rCtx.getJvmMemoryUsage()); |
| | | desc.setSystemInformationMonitor(rCtx.getSystemInformation()); |
| | | desc.setWorkQueueMonitor(rCtx.getWorkQueue()); |
| | | desc.setOpenDJVersion(firstValueAsString(rCtx.getVersionMonitor(), "fullVersion")); |
| | | String installPath = firstValueAsString(rCtx.getSystemInformation(), "installPath"); |
| | | desc.setOpenDJVersion(rCtx.getVersionMonitor().parseAttribute("fullVersion").asString()); |
| | | String installPath = rCtx.getSystemInformation().parseAttribute("installPath").asString(); |
| | | if (installPath != null) |
| | | { |
| | | desc.setInstallPath(installPath); |
| | | } |
| | | String instancePath = firstValueAsString(rCtx.getSystemInformation(), "instancePath"); |
| | | String instancePath = rCtx.getSystemInformation().parseAttribute("instancePath").asString(); |
| | | if (instancePath != null) |
| | | { |
| | | desc.setInstancePath(instancePath); |
| | |
| | | */ |
| | | package org.opends.guitools.controlpanel.datamodel; |
| | | |
| | | import static org.opends.admin.ads.util.ConnectionUtils.*; |
| | | import static org.opends.guitools.controlpanel.util.Utilities.*; |
| | | import static org.opends.messages.AdminToolMessages.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | |
| | | |
| | | private String[] getLine(BackendDescriptor backend) |
| | | { |
| | | final String defaultVal = NO_VALUE_SET.toString(); |
| | | |
| | | String[] line = new String[attributes.size() + 1]; |
| | | line[0] = getName(backend); |
| | | int i = 1; |
| | | SearchResultEntry monitoringEntry = getMonitoringEntry(backend); |
| | | for (String attr : attributes) |
| | | { |
| | | String o = firstValueAsString(monitoringEntry, attr); |
| | | line[i] = o != null ? o : NO_VALUE_SET.toString(); |
| | | line[i] = monitoringEntry.parseAttribute(attr).asString(defaultVal); |
| | | i++; |
| | | } |
| | | return line; |
| | |
| | | import org.forgerock.opendj.ldap.responses.SearchResultEntry; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.forgerock.opendj.ldap.schema.ObjectClass; |
| | | import org.forgerock.opendj.ldap.schema.Schema; |
| | | import org.opends.guitools.controlpanel.util.ConfigFromConnection; |
| | | import org.opends.quicksetup.UserData; |
| | | import org.opends.server.tools.tasks.TaskEntry; |
| | | import org.forgerock.opendj.ldap.schema.Schema; |
| | | |
| | | import com.forgerock.opendj.util.OperatingSystem; |
| | | |
| | |
| | | { |
| | | return false; |
| | | } |
| | | String os = firstValueAsString(sr, "operatingSystem"); |
| | | String os = sr.parseAttribute("operatingSystem").asString(); |
| | | return os != null && OperatingSystem.WINDOWS.equals(OperatingSystem.forName(os)); |
| | | } |
| | | |
| | |
| | | import static org.forgerock.opendj.ldap.SearchScope.*; |
| | | import static org.forgerock.opendj.ldap.requests.Requests.*; |
| | | import static org.forgerock.util.Utils.*; |
| | | import static org.opends.admin.ads.util.ConnectionUtils.*; |
| | | import static org.opends.messages.QuickSetupMessages.*; |
| | | import static org.opends.quicksetup.Installation.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | |
| | | try |
| | | { |
| | | SearchResultEntry sr = conn.getConnection().searchSingleEntry(request); |
| | | |
| | | String v = firstValueAsString(sr, "currentTime"); |
| | | String v = sr.parseAttribute("currentTime").asString(); |
| | | |
| | | SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss'Z'"); |
| | | formatter.setTimeZone(TimeZone.getTimeZone("UTC")); |
| | | |
| | | return formatter.parse(v).getTime(); |
| | | } |
| | | catch (Throwable t) |
| | |
| | | import org.forgerock.opendj.server.config.server.BackendCfg; |
| | | import org.forgerock.opendj.server.config.server.RootCfg; |
| | | import org.opends.server.api.Backend; |
| | | import org.opends.server.tools.BackendToolUtils; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.config.ConfigurationHandler; |
| | | import org.opends.server.core.DirectoryServer; |
| | |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | |
| | | /** |
| | | * This class defines a number of static utility methods for server tasks. |
| | | */ |
| | | /** This class defines a number of static utility methods for server tasks. */ |
| | | public class TaskUtils |
| | | { |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | |
| | | { |
| | | try |
| | | { |
| | | return BackendToolUtils.getStringSingleValuedAttribute(configEntry, ATTR_BACKEND_ID); |
| | | return configEntry.parseAttribute(ATTR_BACKEND_ID).asString(); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | |
| | | try |
| | | { |
| | | configEntry = Converters.to(configHandler.getEntry(childrenDn)); |
| | | backendID = BackendToolUtils.getStringSingleValuedAttribute(configEntry, ATTR_BACKEND_ID); |
| | | backendID = configEntry.parseAttribute(ATTR_BACKEND_ID).asString(); |
| | | if (backendID == null) |
| | | { |
| | | continue; |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Returns a string from the single valued attribute in provided entry. |
| | | * |
| | | * @param entry the entry |
| | | * @param attrName the attribute name |
| | | * @return the string value if available or {@code null} |
| | | */ |
| | | public static String getStringSingleValuedAttribute(Entry entry, String attrName) |
| | | { |
| | | Iterator<Attribute> attributes = entry.getAllAttributes(attrName).iterator(); |
| | | if (attributes.hasNext()) |
| | | { |
| | | Attribute attribute = attributes.next(); |
| | | for (ByteString byteString : attribute) |
| | | { |
| | | return byteString.toString(); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private static List<DN> getBaseDNsForEntry(final Entry configEntry) throws Exception |
| | | { |
| | | try |
| | |
| | | { |
| | | try |
| | | { |
| | | return getStringSingleValuedAttribute(configEntry, ATTR_BACKEND_CLASS); |
| | | return configEntry.parseAttribute(ATTR_BACKEND_CLASS).asString(); |
| | | } |
| | | catch (final Exception e) |
| | | { |
| | |
| | | { |
| | | try |
| | | { |
| | | return getStringSingleValuedAttribute(configEntry, ATTR_BACKEND_ID); |
| | | return configEntry.parseAttribute(ATTR_BACKEND_ID).asString(); |
| | | } |
| | | catch (final Exception e) |
| | | { |
| | |
| | | String backendID = null; |
| | | try |
| | | { |
| | | backendID = BackendToolUtils.getStringSingleValuedAttribute(configEntry, ATTR_BACKEND_ID); |
| | | backendID = configEntry.parseAttribute(ATTR_BACKEND_ID).asString(); |
| | | if (backendID == null) |
| | | { |
| | | continue; |
| | |
| | | } |
| | | sr = entryReader.readEntry(); |
| | | } |
| | | |
| | | String newStartCSN = firstValueAsString(sr, "replicationCSN"); |
| | | String newStartCSN = sr.parseAttribute("replicationCSN").asString(); |
| | | if (newStartCSN == null) |
| | | { |
| | | errPrintln(ERROR_RESET_CHANGE_NUMBER_NO_CSN_FOUND.get(newStartCN, uData.getSourceHostPort())); |
| | | return ERROR_RESET_CHANGE_NUMBER_NO_CSN; |
| | | } |
| | | String targetDN = firstValueAsString(sr, "targetDN"); |
| | | DN targetDN; |
| | | DN targetBaseDN = DN.rootDN(); |
| | | try |
| | | { |
| | | targetDN = sr.parseAttribute("targetDN").asDN(); |
| | | for (DN dn : getCommonSuffixes(connSource, connDest, SuffixRelationType.REPLICATED)) |
| | | { |
| | | if (DN.valueOf(targetDN).isSubordinateOrEqualTo(dn) && dn.isSubordinateOrEqualTo(targetBaseDN)) |
| | | if (targetDN.isSubordinateOrEqualTo(dn) && dn.isSubordinateOrEqualTo(targetBaseDN)) |
| | | { |
| | | targetBaseDN = dn; |
| | | } |
| | |
| | | { |
| | | SearchResultEntry sr = |
| | | conn.getConnection().searchSingleEntry("", BASE_OBJECT, "objectclass=*", "lastChangeNumber"); |
| | | return firstValueAsString(sr, "lastChangeNumber"); |
| | | return sr.parseAttribute("lastChangeNumber").asString(); |
| | | } |
| | | catch (LdapException e) |
| | | { |