use of com.unboundid.util.Nullable in project ldapsdk by pingidentity.
the class SplitLDIF method getSchema.
/**
* Retrieves the schema that should be used for processing.
*
* @return The schema that was created.
*
* @throws LDAPException If a problem is encountered while retrieving the
* schema.
*/
@Nullable()
private Schema getSchema() throws LDAPException {
// paths.
if (schemaPath.isPresent()) {
final ArrayList<File> schemaFiles = new ArrayList<>(10);
for (final File path : schemaPath.getValues()) {
if (path.isFile()) {
schemaFiles.add(path);
} else {
final TreeMap<String, File> fileMap = new TreeMap<>();
for (final File schemaDirFile : path.listFiles()) {
final String name = schemaDirFile.getName();
if (schemaDirFile.isFile() && name.toLowerCase().endsWith(".ldif")) {
fileMap.put(name, schemaDirFile);
}
}
schemaFiles.addAll(fileMap.values());
}
}
if (schemaFiles.isEmpty()) {
throw new LDAPException(ResultCode.PARAM_ERROR, ERR_SPLIT_LDIF_NO_SCHEMA_FILES.get(schemaPath.getIdentifierString()));
} else {
try {
return Schema.getSchema(schemaFiles);
} catch (final Exception e) {
Debug.debugException(e);
throw new LDAPException(ResultCode.LOCAL_ERROR, ERR_SPLIT_LDIF_ERROR_LOADING_SCHEMA.get(StaticUtils.getExceptionMessage(e)));
}
}
} else {
// schema files in it, then read the schema from that directory.
try {
final String instanceRootStr = StaticUtils.getEnvironmentVariable("INSTANCE_ROOT");
if (instanceRootStr != null) {
final File instanceRoot = new File(instanceRootStr);
final File configDir = new File(instanceRoot, "config");
final File schemaDir = new File(configDir, "schema");
if (schemaDir.exists()) {
final TreeMap<String, File> fileMap = new TreeMap<>();
for (final File schemaDirFile : schemaDir.listFiles()) {
final String name = schemaDirFile.getName();
if (schemaDirFile.isFile() && name.toLowerCase().endsWith(".ldif")) {
fileMap.put(name, schemaDirFile);
}
}
if (!fileMap.isEmpty()) {
return Schema.getSchema(new ArrayList<>(fileMap.values()));
}
}
}
} catch (final Exception e) {
Debug.debugException(e);
}
}
// the default standard schema.
return null;
}
use of com.unboundid.util.Nullable in project ldapsdk by pingidentity.
the class ToolInvocationLogger method acquireFileLock.
/**
* Attempts to acquire an exclusive file lock on the provided file channel.
*
* @param fileChannel The file channel on which to acquire the file
* lock.
* @param logFile The path to the log file being locked.
* @param toolErrorStream A print stream that may be used to report
* information about any problems encountered while
* attempting to perform invocation logging. It
* must not be {@code null}.
*
* @return The file lock that was acquired, or {@code null} if the lock could
* not be acquired.
*/
@Nullable()
private static FileLock acquireFileLock(@NotNull final FileChannel fileChannel, @NotNull final File logFile, @NotNull final PrintStream toolErrorStream) {
try {
final FileLock fileLock = fileChannel.tryLock();
if (fileLock != null) {
return fileLock;
}
} catch (final Exception e) {
Debug.debugException(e);
}
int numAttempts = 1;
final long stopWaitingTime = System.currentTimeMillis() + 1000L;
while (System.currentTimeMillis() <= stopWaitingTime) {
try {
Thread.sleep(10L);
final FileLock fileLock = fileChannel.tryLock();
if (fileLock != null) {
return fileLock;
}
} catch (final Exception e) {
Debug.debugException(e);
}
numAttempts++;
}
printError(ERR_TOOL_LOGGER_UNABLE_TO_ACQUIRE_FILE_LOCK.get(logFile.getAbsolutePath(), numAttempts), toolErrorStream);
return null;
}
use of com.unboundid.util.Nullable in project ldapsdk by pingidentity.
the class ToolInvocationLogger method getLogFileProperty.
/**
* Retrieves a file referenced by the specified property from the set of
* tool properties.
*
* @param propertyName The name of the property to retrieve.
* @param properties The set of tool properties.
* @param propertiesFilePath The path to the properties file.
* @param instanceRootDirectory The path to the server's instance root
* directory.
* @param toolErrorStream A print stream that may be used to report
* information about any problems encountered
* while attempting to perform invocation
* logging. It must not be {@code null}.
*
* @return A file referenced by the specified property, or {@code null} if
* the property is not set or does not reference a valid path.
*/
@Nullable()
private static File getLogFileProperty(@NotNull final String propertyName, @NotNull final Properties properties, @NotNull final File propertiesFilePath, @Nullable final File instanceRootDirectory, @NotNull final PrintStream toolErrorStream) {
final String propertyValue = properties.getProperty(propertyName);
if (propertyValue == null) {
return null;
}
final File absoluteFile;
final File configuredFile = new File(propertyValue);
if (configuredFile.isAbsolute()) {
absoluteFile = configuredFile;
} else {
absoluteFile = new File(instanceRootDirectory.getAbsolutePath() + File.separator + propertyValue);
}
if (absoluteFile.exists()) {
if (absoluteFile.isFile()) {
return absoluteFile;
} else {
printError(ERR_TOOL_LOGGER_PATH_NOT_FILE.get(propertyValue, propertyName, propertiesFilePath.getAbsolutePath()), toolErrorStream);
}
} else {
final File parentFile = absoluteFile.getParentFile();
if (parentFile.exists() && parentFile.isDirectory()) {
return absoluteFile;
} else {
printError(ERR_TOOL_LOGGER_PATH_PARENT_MISSING.get(propertyValue, propertyName, propertiesFilePath.getAbsolutePath(), parentFile.getAbsolutePath()), toolErrorStream);
}
}
return null;
}
use of com.unboundid.util.Nullable in project ldapsdk by pingidentity.
the class StartInteractiveTransactionExtendedResult method encodeValue.
/**
* Encodes the provided information into an ASN.1 octet string suitable for
* use as the value of this extended result.
*
* @param transactionID The transaction ID for this response, if available.
* @param baseDNs The list of base DNs for this response, if
* available.
*
* @return The ASN.1 octet string containing the encoded value, or
* {@code null} if no value should be used.
*/
@Nullable()
private static ASN1OctetString encodeValue(@Nullable final ASN1OctetString transactionID, @Nullable final List<String> baseDNs) {
if ((transactionID == null) && (baseDNs == null)) {
return null;
}
final ArrayList<ASN1Element> elements = new ArrayList<>(2);
if (transactionID != null) {
elements.add(new ASN1OctetString(TYPE_TXN_ID, transactionID.getValue()));
}
if ((baseDNs != null) && (!baseDNs.isEmpty())) {
final ArrayList<ASN1Element> baseDNElements = new ArrayList<>(baseDNs.size());
for (final String s : baseDNs) {
baseDNElements.add(new ASN1OctetString(s));
}
elements.add(new ASN1Sequence(TYPE_BASE_DNS, baseDNElements));
}
return new ASN1OctetString(new ASN1Sequence(elements).encode());
}
use of com.unboundid.util.Nullable in project ldapsdk by pingidentity.
the class ModifyDNAuditLogMessage method decodeAttributeModifications.
/**
* Decodes the list of attribute modifications from the audit log message, if
* available.
*
* @param logMessageLines The lines that comprise the log message. It
* must not be {@code null} or empty, and it
* must not contain any blank lines, although it
* may contain comments. In fact, it must
* contain at least one comment line that
* appears before any non-comment lines (but
* possibly after other comment lines) that
* serves as the message header.
* @param modifyDNChangeRecord The LDIF modify DN change record that is
* described by the provided log message lines.
*
* @return The list of attribute modifications from the audit log message, or
* {@code null} if there were no modifications.
*/
@Nullable()
private static List<Modification> decodeAttributeModifications(@NotNull final List<String> logMessageLines, @NotNull final LDIFModifyDNChangeRecord modifyDNChangeRecord) {
List<String> ldifLines = null;
for (final String line : logMessageLines) {
final String uncommentedLine;
if (line.startsWith("# ")) {
uncommentedLine = line.substring(2);
} else {
break;
}
if (ldifLines == null) {
final String lowerLine = StaticUtils.toLowerCase(uncommentedLine);
if (lowerLine.startsWith("modifydn attribute modifications")) {
ldifLines = new ArrayList<>(logMessageLines.size());
}
} else {
if (ldifLines.isEmpty()) {
ldifLines.add("dn: " + modifyDNChangeRecord.getDN());
ldifLines.add("changetype: modify");
}
ldifLines.add(uncommentedLine);
}
}
if (ldifLines == null) {
return null;
} else if (ldifLines.isEmpty()) {
return Collections.emptyList();
} else {
try {
final String[] ldifLineArray = ldifLines.toArray(StaticUtils.NO_STRINGS);
final LDIFModifyChangeRecord changeRecord = (LDIFModifyChangeRecord) LDIFReader.decodeChangeRecord(ldifLineArray);
return Collections.unmodifiableList(Arrays.asList(changeRecord.getModifications()));
} catch (final Exception e) {
Debug.debugException(e);
return null;
}
}
}
Aggregations