use of org.apache.directory.api.ldap.model.message.ModifyResponse in project ldapchai by ldapchai.
the class ApacheLdapProviderImpl method writeStringAttributes.
public void writeStringAttributes(final String entryDN, final Map<String, String> attributeValueProps, final boolean overwrite) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
activityPreCheck();
getInputValidator().writeStringAttributes(entryDN, attributeValueProps, overwrite);
try {
final ModifyRequest modifyRequest = new ModifyRequestImpl();
modifyRequest.setName(new Dn(entryDN));
for (final Map.Entry<String, String> entry : attributeValueProps.entrySet()) {
final String name = entry.getKey();
final String value = entry.getValue();
final Modification modification = new DefaultModification();
modification.setOperation(overwrite ? ModificationOperation.REPLACE_ATTRIBUTE : ModificationOperation.ADD_ATTRIBUTE);
modification.setAttribute(new DefaultAttribute(name, value));
modifyRequest.addModification(modification);
}
final ModifyResponse response = connection.modify(modifyRequest);
processResponse(response);
} catch (LdapException e) {
throw ChaiOperationException.forErrorMessage(e.getMessage());
}
}
use of org.apache.directory.api.ldap.model.message.ModifyResponse in project ldapchai by ldapchai.
the class ApacheLdapProviderImpl method replaceAttributeImpl.
private void replaceAttributeImpl(final String entryDN, final String attributeName, final Value oldValue, final Value newValue) throws ChaiOperationException {
try {
final ModifyRequest modifyRequest = new ModifyRequestImpl();
modifyRequest.setName(new Dn(entryDN));
{
final Modification modification = new DefaultModification();
modification.setOperation(ModificationOperation.REMOVE_ATTRIBUTE);
modification.setAttribute(new DefaultAttribute(attributeName, oldValue));
modifyRequest.addModification(modification);
}
{
final Modification modification = new DefaultModification();
modification.setOperation(ModificationOperation.ADD_ATTRIBUTE);
modification.setAttribute(new DefaultAttribute(attributeName, newValue));
modifyRequest.addModification(modification);
}
final ModifyResponse response = connection.modify(modifyRequest);
processResponse(response);
} catch (LdapException e) {
throw ChaiOperationException.forErrorMessage(e.getMessage());
}
}
use of org.apache.directory.api.ldap.model.message.ModifyResponse in project ldapchai by ldapchai.
the class ApacheLdapProviderImpl method writeBinaryAttribute.
public void writeBinaryAttribute(final String entryDN, final String attributeName, final byte[][] values, final boolean overwrite) throws ChaiUnavailableException, ChaiOperationException {
activityPreCheck();
getInputValidator().writeBinaryAttribute(entryDN, attributeName, values, overwrite);
try {
final ModifyRequest modifyRequest = new ModifyRequestImpl();
modifyRequest.setName(new Dn(entryDN));
{
final Modification modification = new DefaultModification();
modification.setOperation(overwrite ? ModificationOperation.REPLACE_ATTRIBUTE : ModificationOperation.ADD_ATTRIBUTE);
modification.setAttribute(new DefaultAttribute(attributeName, values));
modifyRequest.addModification(modification);
}
final ModifyResponse response = connection.modify(modifyRequest);
processResponse(response);
} catch (LdapException e) {
throw ChaiOperationException.forErrorMessage(e.getMessage());
}
}
use of org.apache.directory.api.ldap.model.message.ModifyResponse in project ldapchai by ldapchai.
the class ApacheLdapProviderImpl method writeStringAttribute.
public void writeStringAttribute(final String entryDN, final String attributeName, final Set<String> values, final boolean overwrite) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
activityPreCheck();
getInputValidator().writeStringAttribute(entryDN, attributeName, values, overwrite);
try {
final ModifyRequest modifyRequest = new ModifyRequestImpl();
modifyRequest.setName(new Dn(entryDN));
{
final Modification modification = new DefaultModification();
modification.setOperation(overwrite ? ModificationOperation.REPLACE_ATTRIBUTE : ModificationOperation.ADD_ATTRIBUTE);
modification.setAttribute(new DefaultAttribute(attributeName, values.toArray(new String[values.size()])));
modifyRequest.addModification(modification);
}
final ModifyResponse response = connection.modify(modifyRequest);
processResponse(response);
} catch (LdapException e) {
throw ChaiOperationException.forErrorMessage(e.getMessage());
}
}
use of org.apache.directory.api.ldap.model.message.ModifyResponse in project directory-ldap-api by apache.
the class ModifyResponseTest method testResponseWithResultCode.
/**
* Test parsing of a response with Result Code
*/
@Test
public void testResponseWithResultCode() {
Dsmlv2ResponseParser parser = null;
try {
parser = new Dsmlv2ResponseParser(getCodec());
parser.setInput(ModifyResponseTest.class.getResource("response_with_result_code.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
ModifyResponse modifyResponse = (ModifyResponse) parser.getBatchResponse().getCurrentResponse();
LdapResult ldapResult = modifyResponse.getLdapResult();
assertEquals(ResultCodeEnum.PROTOCOL_ERROR, ldapResult.getResultCode());
}
Aggregations