| | |
| | | import static org.forgerock.opendj.rest2ldap.Utils.newBadRequestException; |
| | | import static org.forgerock.opendj.rest2ldap.Utils.toFilter; |
| | | import static org.forgerock.opendj.rest2ldap.Utils.toLowerCase; |
| | | import static org.forgerock.util.promise.Promises.newResultPromise; |
| | | |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | |
| | | import org.forgerock.opendj.ldap.Filter; |
| | | import org.forgerock.opendj.ldap.Modification; |
| | | import org.forgerock.util.promise.Promise; |
| | | import org.forgerock.util.promise.Promises; |
| | | |
| | | /** |
| | | * An property mapper which maps a single JSON attribute to a fixed value. |
| | |
| | | } |
| | | |
| | | @Override |
| | | Promise<List<Attribute>, ResourceException> create(final Connection connection, final JsonPointer path, |
| | | final JsonValue v) { |
| | | Promise<List<Attribute>, ResourceException> create(final Connection connection, |
| | | final Resource resource, final JsonPointer path, |
| | | final JsonValue v) { |
| | | if (!isNullOrEmpty(v) && !v.getObject().equals(value.getObject())) { |
| | | return Promises.<List<Attribute>, ResourceException> newExceptionPromise( |
| | | newBadRequestException(ERR_CREATION_READ_ONLY_FIELD.get(path))); |
| | | return newBadRequestException(ERR_CREATION_READ_ONLY_FIELD.get(path)).asPromise(); |
| | | } else { |
| | | return Promises.newResultPromise(Collections.<Attribute> emptyList()); |
| | | return newResultPromise(Collections.<Attribute> emptyList()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | void getLdapAttributes(final Connection connection, final JsonPointer path, final JsonPointer subPath, |
| | | final Set<String> ldapAttributes) { |
| | | void getLdapAttributes(final JsonPointer path, final JsonPointer subPath, final Set<String> ldapAttributes) { |
| | | // Nothing to do. |
| | | } |
| | | |
| | | @Override |
| | | Promise<Filter, ResourceException> getLdapFilter(final Connection connection, final JsonPointer path, |
| | | final JsonPointer subPath, final FilterType type, |
| | | final String operator, final Object valueAssertion) { |
| | | Promise<Filter, ResourceException> getLdapFilter(final Connection connection, final Resource resource, |
| | | final JsonPointer path, final JsonPointer subPath, |
| | | final FilterType type, final String operator, |
| | | final Object valueAssertion) { |
| | | final Filter filter; |
| | | final JsonValue subValue = value.get(subPath); |
| | | if (subValue == null) { |
| | |
| | | // This property mapper is a candidate but it does not match. |
| | | filter = alwaysFalse(); |
| | | } |
| | | return Promises.newResultPromise(filter); |
| | | return newResultPromise(filter); |
| | | } |
| | | |
| | | @Override |
| | | Promise<List<Modification>, ResourceException> patch(final Connection connection, final JsonPointer path, |
| | | final PatchOperation operation) { |
| | | return Promises.<List<Modification>, ResourceException> newExceptionPromise( |
| | | newBadRequestException(ERR_PATCH_READ_ONLY_FIELD.get(path))); |
| | | Promise<List<Modification>, ResourceException> patch(final Connection connection, final Resource resource, |
| | | final JsonPointer path, final PatchOperation operation) { |
| | | return newBadRequestException(ERR_PATCH_READ_ONLY_FIELD.get(path)).asPromise(); |
| | | } |
| | | |
| | | @Override |
| | | Promise<JsonValue, ResourceException> read(final Connection connection, final JsonPointer path, final Entry e) { |
| | | return Promises.newResultPromise(value.copy()); |
| | | Promise<JsonValue, ResourceException> read(final Connection connection, final Resource resource, |
| | | final JsonPointer path, final Entry e) { |
| | | return newResultPromise(value.copy()); |
| | | } |
| | | |
| | | @Override |
| | | Promise<List<Modification>, ResourceException> update( |
| | | final Connection connection, final JsonPointer path, final Entry e, final JsonValue v) { |
| | | Promise<List<Modification>, ResourceException> update(final Connection connection, final Resource resource, |
| | | final JsonPointer path, final Entry e, final JsonValue v) { |
| | | if (!isNullOrEmpty(v) && !v.getObject().equals(value.getObject())) { |
| | | return Promises.<List<Modification>, ResourceException> newExceptionPromise( |
| | | newBadRequestException(ERR_MODIFY_READ_ONLY_FIELD.get("update", path))); |
| | | return newBadRequestException(ERR_MODIFY_READ_ONLY_FIELD.get("update", path)).asPromise(); |
| | | } else { |
| | | return Promises.newResultPromise(Collections.<Modification> emptyList()); |
| | | return newResultPromise(Collections.<Modification>emptyList()); |
| | | } |
| | | } |
| | | |
| | |
| | | return alwaysFalse(); // Not supported. |
| | | } |
| | | } |
| | | |
| | | } |