use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project ldapchai by ldapchai.
the class ApacheLdapProviderImpl method createEntry.
public void createEntry(final String entryDN, final Set<String> baseObjectClasses, final Map<String, String> stringAttributes) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
activityPreCheck();
getInputValidator().createEntry(entryDN, baseObjectClasses, stringAttributes);
try {
final AddRequest addRequest = new AddRequestImpl();
final Entry entry = new DefaultEntry();
entry.setDn(entryDN);
for (final String baseObjectClass : baseObjectClasses) {
entry.add(ChaiConstant.ATTR_LDAP_OBJECTCLASS, baseObjectClass);
}
for (final Map.Entry<String, String> entryIter : stringAttributes.entrySet()) {
final String name = entryIter.getKey();
final String value = entryIter.getValue();
entry.add(name, value);
}
final AddResponse response = connection.add(addRequest);
processResponse(response);
} catch (LdapException e) {
throw ChaiOperationException.forErrorMessage(e.getMessage());
}
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project syncope by apache.
the class LdifInputStreamLoader method execute.
/**
* Opens the LDIF file and loads the entries into the context.
*
* @return The count of entries created.
*/
public int execute() {
try {
try {
for (LdifEntry ldifEntry : new LdifReader(ldif)) {
Dn dn = ldifEntry.getDn();
if (ldifEntry.isEntry()) {
Entry entry = ldifEntry.getEntry();
try {
coreSession.lookup(dn);
LOG.debug("Found {}, will not create.", dn);
} catch (Exception e) {
try {
coreSession.add(new DefaultEntry(coreSession.getDirectoryService().getSchemaManager(), entry));
count++;
LOG.debug("Created {}.", dn);
} catch (LdapException e1) {
LOG.error("Could not create entry " + entry, e1);
}
}
} else {
// modify
List<Modification> items = ldifEntry.getModifications();
try {
coreSession.modify(dn, items);
LOG.debug("Modified: " + dn + " with modificationItems: " + items);
} catch (LdapException e) {
LOG.debug("Could not modify: " + dn + " with modificationItems: " + items, e);
}
}
}
} finally {
ldif.close();
}
} catch (Exception ioe) {
LOG.error(I18n.err(I18n.ERR_174), ioe);
}
return count;
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-ldap-api by apache.
the class SchemaElementImpl method nameToLdif.
/**
* @return the Names as Ldif lines
* @throws org.apache.directory.api.ldap.model.exception.LdapException If the conversion goes wrong
*/
private String nameToLdif() throws LdapException {
if (names.isEmpty()) {
return "";
} else {
Entry entry = new DefaultEntry();
Attribute attribute = new DefaultAttribute("m-name");
for (String name : names) {
attribute.add(name);
}
entry.put(attribute);
return LdifUtils.convertAttributesToLdif(entry);
}
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-ldap-api by apache.
the class SchemaElementImpl method descToLdif.
/**
* @return The description as a ldif line
* @throws org.apache.directory.api.ldap.model.exception.LdapException If the conversion goes wrong
*/
private String descToLdif() throws LdapException {
if (Strings.isEmpty(description)) {
return "";
} else {
Entry entry = new DefaultEntry();
Attribute attribute = new DefaultAttribute("m-description", description);
entry.put(attribute);
return LdifUtils.convertAttributesToLdif(entry);
}
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-ldap-api by apache.
the class SchemaElementImpl method extensionsToLdif.
/**
* Return the extensions formated as Ldif lines
*
* @param id The attributeId : can be m-objectClassExtension or
* m-attributeTypeExtension
* @return The extensions formated as ldif lines
* @throws org.apache.directory.api.ldap.model.exception.LdapException If the conversion goes wrong
*/
protected String extensionsToLdif(String id) throws LdapException {
StringBuilder sb = new StringBuilder();
Entry entry = new DefaultEntry();
Attribute attribute = new DefaultAttribute(id);
for (String extension : extensions.keySet()) {
attribute.add(extension);
}
sb.append(LdifUtils.convertAttributesToLdif(entry));
return sb.toString();
}
Aggregations