Search in sources :

Example 1 with LdifDataUtility

use of org.gluu.persist.ldap.impl.LdifDataUtility in project oxTrust by GluuFederation.

the class LdifService method exportLDIFFile.

public void exportLDIFFile(List<String> checkedItems, OutputStream output) throws LDAPException {
    List<SearchResultEntry> result = null;
    LDAPConnection connection = ldapEntryManager.getOperationService().getConnection();
    try {
        LdifDataUtility ldifDataUtility = LdifDataUtility.instance();
        result = ldifDataUtility.getAttributeResultEntryLDIF(connection, checkedItems, attributeService.getDnForAttribute(null));
    } catch (Exception ex) {
        log.error("Failed to export ldif file: ", ex);
    } finally {
        ldapEntryManager.getOperationService().releaseConnection(connection);
    }
    if (result != null && result.size() > 0) {
        // Write all of the matching entries to LDIF.
        LDIFWriter ldifWriter;
        try {
            ldifWriter = new LDIFWriter(output);
            for (SearchResultEntry entry : result) {
                ldifWriter.writeEntry(entry);
            }
            ldifWriter.close();
        } catch (IOException e) {
            throw new BaseMappingException("Error writing to file, try again", e);
        }
    }
}
Also used : BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) LDIFWriter(com.unboundid.ldif.LDIFWriter) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) IOException(java.io.IOException) LdifDataUtility(org.gluu.persist.ldap.impl.LdifDataUtility) IOException(java.io.IOException) BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) LDAPException(com.unboundid.ldap.sdk.LDAPException) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry)

Example 2 with LdifDataUtility

use of org.gluu.persist.ldap.impl.LdifDataUtility in project oxTrust by GluuFederation.

the class LdifService method importLdifFileInLdap.

public ResultCode importLdifFileInLdap(Class<?> entryClass, InputStream is) throws LDAPException {
    if (dataSourceTypeService.isLDAP(attributeService.getDnForAttribute(null))) {
        ResultCode result = ResultCode.UNAVAILABLE;
        PersistenceOperationService persistenceOperationService = persistenceManager.getOperationService();
        LdapOperationService ldapOperationService = (LdapOperationService) persistenceOperationService;
        LDAPConnection connection = ldapOperationService.getConnection();
        try {
            LdifDataUtility ldifDataUtility = LdifDataUtility.instance();
            LDIFReader importLdifReader = new LDIFReader(is);
            result = ldifDataUtility.importLdifFile(connection, importLdifReader);
            importLdifReader.close();
        } catch (Exception ex) {
            log.error("Failed to import ldif file: ", ex);
        } finally {
            ldapOperationService.releaseConnection(connection);
        }
        return result;
    } else {
        performImport(entryClass, is);
        return ResultCode.SUCCESS;
    }
}
Also used : LdapOperationService(org.gluu.persist.ldap.operation.LdapOperationService) LDIFReader(com.unboundid.ldif.LDIFReader) PersistenceOperationService(org.gluu.persist.operation.PersistenceOperationService) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) LdifDataUtility(org.gluu.persist.ldap.impl.LdifDataUtility) ResultCode(com.unboundid.ldap.sdk.ResultCode) IOException(java.io.IOException) LDAPException(com.unboundid.ldap.sdk.LDAPException)

Example 3 with LdifDataUtility

use of org.gluu.persist.ldap.impl.LdifDataUtility in project oxTrust by GluuFederation.

the class LdifService method validateLdifFile.

public ResultCode validateLdifFile(InputStream is, String dn) throws LDAPException {
    ResultCode result = ResultCode.UNAVAILABLE;
    try {
        LdifDataUtility ldifDataUtility = LdifDataUtility.instance();
        LDIFReader validateLdifReader = new LDIFReader(is);
        result = ldifDataUtility.validateLDIF(validateLdifReader, dn);
        validateLdifReader.close();
    } catch (Exception ex) {
        log.error("Failed to validate ldif file: ", ex);
    }
    return result;
}
Also used : LDIFReader(com.unboundid.ldif.LDIFReader) LdifDataUtility(org.gluu.persist.ldap.impl.LdifDataUtility) ResultCode(com.unboundid.ldap.sdk.ResultCode) IOException(java.io.IOException) BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) LDAPException(com.unboundid.ldap.sdk.LDAPException)

Example 4 with LdifDataUtility

use of org.gluu.persist.ldap.impl.LdifDataUtility in project oxTrust by GluuFederation.

the class LdifService method importLdifFileInLdap.

public ResultCode importLdifFileInLdap(InputStream is) throws LDAPException {
    ResultCode result = ResultCode.UNAVAILABLE;
    LDAPConnection connection = ldapEntryManager.getOperationService().getConnection();
    try {
        LdifDataUtility ldifDataUtility = LdifDataUtility.instance();
        LDIFReader importLdifReader = new LDIFReader(is);
        result = ldifDataUtility.importLdifFile(connection, importLdifReader);
        importLdifReader.close();
    } catch (Exception ex) {
        log.error("Failed to import ldif file: ", ex);
    } finally {
        ldapEntryManager.getOperationService().releaseConnection(connection);
    }
    return result;
}
Also used : LDIFReader(com.unboundid.ldif.LDIFReader) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) LdifDataUtility(org.gluu.persist.ldap.impl.LdifDataUtility) ResultCode(com.unboundid.ldap.sdk.ResultCode) IOException(java.io.IOException) BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) LDAPException(com.unboundid.ldap.sdk.LDAPException)

Example 5 with LdifDataUtility

use of org.gluu.persist.ldap.impl.LdifDataUtility in project oxTrust by GluuFederation.

the class LdifService method validateLdifFile.

public ResultCode validateLdifFile(InputStream is, String dn) throws LDAPException {
    ResultCode result = ResultCode.UNAVAILABLE;
    try {
        LdifDataUtility ldifDataUtility = LdifDataUtility.instance();
        LDIFReader validateLdifReader = new LDIFReader(is);
        result = ldifDataUtility.validateLDIF(validateLdifReader, dn);
        validateLdifReader.close();
    } catch (Exception ex) {
        log.error("Failed to validate ldif file: ", ex);
    }
    return result;
}
Also used : LDIFReader(com.unboundid.ldif.LDIFReader) LdifDataUtility(org.gluu.persist.ldap.impl.LdifDataUtility) ResultCode(com.unboundid.ldap.sdk.ResultCode) IOException(java.io.IOException) LDAPException(com.unboundid.ldap.sdk.LDAPException)

Aggregations

LDAPException (com.unboundid.ldap.sdk.LDAPException)5 IOException (java.io.IOException)5 LdifDataUtility (org.gluu.persist.ldap.impl.LdifDataUtility)5 ResultCode (com.unboundid.ldap.sdk.ResultCode)4 LDIFReader (com.unboundid.ldif.LDIFReader)4 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)3 BaseMappingException (org.gluu.persist.exception.mapping.BaseMappingException)3 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)1 LDIFWriter (com.unboundid.ldif.LDIFWriter)1 LdapOperationService (org.gluu.persist.ldap.operation.LdapOperationService)1 PersistenceOperationService (org.gluu.persist.operation.PersistenceOperationService)1