use of com.unboundid.ldap.sdk.SearchResultEntry in project oxCore by GluuFederation.
the class LdapEntryManager method createEntities.
protected <T> List<T> createEntities(Class<T> entryClass, List<PropertyAnnotation> propertiesAnnotations, SearchResultEntry... searchResultEntries) {
List<T> result = new ArrayList<T>(searchResultEntries.length);
Map<String, List<AttributeData>> entriesAttributes = new HashMap<String, List<AttributeData>>(100);
int count = 0;
for (int i = 0; i < searchResultEntries.length; i++) {
count++;
SearchResultEntry entry = searchResultEntries[i];
entriesAttributes.put(entry.getDN(), getAttributeDataList(entry));
// Remove reference to allow java clean up object
searchResultEntries[i] = null;
// Allow java to clean up temporary objects
if (count >= 100) {
List<T> currentResult = createEntities(entryClass, propertiesAnnotations, entriesAttributes);
result.addAll(currentResult);
entriesAttributes = new HashMap<String, List<AttributeData>>(100);
count = 0;
}
}
List<T> currentResult = createEntities(entryClass, propertiesAnnotations, entriesAttributes);
result.addAll(currentResult);
return result;
}
use of com.unboundid.ldap.sdk.SearchResultEntry in project oxCore by GluuFederation.
the class LdapEntryManager method find.
@Override
protected List<AttributeData> find(String dn, String... ldapReturnAttributes) {
try {
SearchResultEntry entry = this.ldapOperationService.lookup(dn, ldapReturnAttributes);
List<AttributeData> result = getAttributeDataList(entry);
if (result != null) {
return result;
}
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to find entry: %s", dn), ex);
}
throw new EntryPersistenceException(String.format("Failed to find entry: %s", dn));
}
use of com.unboundid.ldap.sdk.SearchResultEntry in project oxCore by GluuFederation.
the class LdapEntryManager method createEntitiesVirtualListView.
@Deprecated
private <T> List<T> createEntitiesVirtualListView(Class<T> entryClass, List<PropertyAnnotation> propertiesAnnotations, SearchResultEntry... searchResultEntries) {
List<T> result = new LinkedList<T>();
Map<String, List<AttributeData>> entriesAttributes = new LinkedHashMap<String, List<AttributeData>>(100);
int count = 0;
for (int i = 0; i < searchResultEntries.length; i++) {
count++;
SearchResultEntry entry = searchResultEntries[i];
LinkedList<AttributeData> attributeDataLinkedList = new LinkedList<AttributeData>();
attributeDataLinkedList.addAll(getAttributeDataList(entry));
entriesAttributes.put(entry.getDN(), attributeDataLinkedList);
// Remove reference to allow java clean up object
searchResultEntries[i] = null;
// Allow java to clean up temporary objects
if (count >= 100) {
List<T> currentResult = new LinkedList<T>();
currentResult.addAll(createEntities(entryClass, propertiesAnnotations, entriesAttributes, false));
result.addAll(currentResult);
entriesAttributes = new LinkedHashMap<String, List<AttributeData>>(100);
count = 0;
}
}
List<T> currentResult = createEntities(entryClass, propertiesAnnotations, entriesAttributes, false);
result.addAll(currentResult);
return result;
}
use of com.unboundid.ldap.sdk.SearchResultEntry in project oxCore by GluuFederation.
the class LdapEntryManager method getLDIF.
@Override
public List<String[]> getLDIF(String dn, String[] attributes) {
SearchResult searchResult;
try {
searchResult = this.ldapOperationService.search(dn, toLdapFilter(Filter.create("objectclass=*")), toLdapSearchScope(SearchScope.BASE), -1, 0, null, attributes);
if (!ResultCode.SUCCESS.equals(searchResult.getResultCode())) {
throw new EntryPersistenceException(String.format("Failed to find entries with baseDN: %s", dn));
}
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to find entries with baseDN: %s, filter: %s", dn, null), ex);
}
List<String[]> result = new ArrayList<String[]>();
if (searchResult.getEntryCount() == 0) {
return result;
}
for (SearchResultEntry searchResultEntry : searchResult.getSearchEntries()) {
result.add(searchResultEntry.toLDIF());
}
return result;
}
use of com.unboundid.ldap.sdk.SearchResultEntry 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);
}
}
}
Aggregations