Search in sources :

Example 1 with LdifDataUtility

use of org.gluu.site.ldap.persistence.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.getLdapOperationService().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.getLdapOperationService().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 LdapMappingException("Error writing to file, try again", e);
        }
    }
}
Also used : LdapMappingException(org.gluu.site.ldap.persistence.exception.LdapMappingException) LDIFWriter(com.unboundid.ldif.LDIFWriter) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) IOException(java.io.IOException) LdifDataUtility(org.gluu.site.ldap.persistence.LdifDataUtility) IOException(java.io.IOException) LdapMappingException(org.gluu.site.ldap.persistence.exception.LdapMappingException) LDAPException(com.unboundid.ldap.sdk.LDAPException) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry)

Example 2 with LdifDataUtility

use of org.gluu.site.ldap.persistence.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.getLdapOperationService().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.getLdapOperationService().releaseConnection(connection);
    }
    return result;
}
Also used : LDIFReader(com.unboundid.ldif.LDIFReader) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) LdifDataUtility(org.gluu.site.ldap.persistence.LdifDataUtility) ResultCode(com.unboundid.ldap.sdk.ResultCode) IOException(java.io.IOException) LdapMappingException(org.gluu.site.ldap.persistence.exception.LdapMappingException) LDAPException(com.unboundid.ldap.sdk.LDAPException)

Example 3 with LdifDataUtility

use of org.gluu.site.ldap.persistence.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.site.ldap.persistence.LdifDataUtility) ResultCode(com.unboundid.ldap.sdk.ResultCode) IOException(java.io.IOException) LdapMappingException(org.gluu.site.ldap.persistence.exception.LdapMappingException) LDAPException(com.unboundid.ldap.sdk.LDAPException)

Aggregations

LDAPException (com.unboundid.ldap.sdk.LDAPException)3 IOException (java.io.IOException)3 LdifDataUtility (org.gluu.site.ldap.persistence.LdifDataUtility)3 LdapMappingException (org.gluu.site.ldap.persistence.exception.LdapMappingException)3 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)2 ResultCode (com.unboundid.ldap.sdk.ResultCode)2 LDIFReader (com.unboundid.ldif.LDIFReader)2 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)1 LDIFWriter (com.unboundid.ldif.LDIFWriter)1