Search in sources :

Example 6 with DataProcessingException

use of com.linkedin.data.transform.DataProcessingException in project rest.li by linkedin.

the class AbstractFilter method compose.

/**
   * Returns composition of two masks. This method does not modify any of the parameters
   * and returned mask is new object. Composition is achieved by invoking separate data
   * processing. If there was an error during mask composition, then null is returned.
   *
   * @param mask1 first mask
   * @param mask2 second mask
   * @return composed masks or null if there was an error during composition fast-fail
   *         mode
   */
private DataMap compose(String fieldName, DataMap mask1, DataMap mask2) {
    // precondition:
    assert mask2 != null;
    assert mask1 != null;
    try {
        final DataMap clone = mask1.copy();
        new DataComplexProcessor(new MaskComposition(), mask2, clone).run(true);
        return clone;
    } catch (CloneNotSupportedException e) {
        onError(fieldName, "could not clone mask: %1$s, exception: %2$s", mask1, e);
    } catch (DataProcessingException e) {
        onError(fieldName, "error composing mask %1$s with %2$s, exception: %3$s", mask1, mask2, e);
    }
    return null;
}
Also used : DataComplexProcessor(com.linkedin.data.transform.DataComplexProcessor) DataMap(com.linkedin.data.DataMap) DataProcessingException(com.linkedin.data.transform.DataProcessingException)

Example 7 with DataProcessingException

use of com.linkedin.data.transform.DataProcessingException in project rest.li by linkedin.

the class GroupMembershipsResource2 method update.

/**
     * @see AssociationResource#update
     */
@Override
public UpdateResponse update(CompoundKey id, PatchRequest<GroupMembership> patch) {
    GroupMembership membership = _app.getMembershipMgr().get(id);
    try {
        PatchApplier.applyPatch(membership, patch);
    } catch (DataProcessingException e) {
        return new UpdateResponse(S_400_BAD_REQUEST);
    }
    validate(membership);
    // we set groupID, memberID based on the URI
    membership.setId(URIParamUtils.encodeKeyForBody(id, true, AllProtocolVersions.BASELINE_PROTOCOL_VERSION));
    membership.setGroupID(getContext().getPathKeys().getAsInt(GROUP_ID));
    membership.setMemberID(getContext().getPathKeys().getAsInt(MEMBER_ID));
    _app.getMembershipMgr().save(membership);
    return new UpdateResponse(S_204_NO_CONTENT);
}
Also used : UpdateResponse(com.linkedin.restli.server.UpdateResponse) GroupMembership(com.linkedin.restli.examples.groups.api.GroupMembership) DataProcessingException(com.linkedin.data.transform.DataProcessingException)

Example 8 with DataProcessingException

use of com.linkedin.data.transform.DataProcessingException in project rest.li by linkedin.

the class GroupMembershipsResource3 method update.

/**
     * @see AssociationResource#update
     */
@Override
public UpdateResponse update(ComplexResourceKey<GroupMembershipKey, GroupMembershipParam> id, PatchRequest<ComplexKeyGroupMembership> patch) {
    ComplexKeyGroupMembership membership = fromGroupMembership(_app.getMembershipMgr().get(complexKeyToCompoundKey(id)));
    try {
        PatchApplier.applyPatch(membership, patch);
    } catch (DataProcessingException e) {
        return new UpdateResponse(S_400_BAD_REQUEST);
    }
    //validate(membership);
    // we set groupID, memberID based on the URI
    membership.setId(id.getKey());
    _app.getMembershipMgr().save(toGroupMembership(membership));
    return new UpdateResponse(S_204_NO_CONTENT);
}
Also used : UpdateResponse(com.linkedin.restli.server.UpdateResponse) ComplexKeyGroupMembership(com.linkedin.restli.examples.groups.api.ComplexKeyGroupMembership) DataProcessingException(com.linkedin.data.transform.DataProcessingException)

Example 9 with DataProcessingException

use of com.linkedin.data.transform.DataProcessingException in project rest.li by linkedin.

the class SimpleResourceUnderCollectionResource method update.

/**
   * Updates the greeting.
   */
@Override
public UpdateResponse update(PatchRequest<Greeting> patchRequest) {
    Long key = this.getContext().getPathKeys().get("subgreetingsId");
    if (TONES.containsKey(key)) {
        try {
            Greeting patched = new Greeting();
            PatchApplier.applyPatch(patched, patchRequest);
            TONES.put(key, patched.getTone());
            return new UpdateResponse(HttpStatus.S_204_NO_CONTENT);
        } catch (DataProcessingException e) {
            return new UpdateResponse((HttpStatus.S_400_BAD_REQUEST));
        }
    } else {
        return new UpdateResponse(HttpStatus.S_404_NOT_FOUND);
    }
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) UpdateResponse(com.linkedin.restli.server.UpdateResponse) DataProcessingException(com.linkedin.data.transform.DataProcessingException)

Example 10 with DataProcessingException

use of com.linkedin.data.transform.DataProcessingException in project rest.li by linkedin.

the class StringKeysResource method update.

@RestMethod.PartialUpdate
public UpdateResponse update(String key, PatchRequest<Message> patch) {
    Message g = _db.get(key);
    if (g == null) {
        return new UpdateResponse(HttpStatus.S_404_NOT_FOUND);
    }
    try {
        PatchApplier.applyPatch(g, patch);
    } catch (DataProcessingException e) {
        return new UpdateResponse(HttpStatus.S_400_BAD_REQUEST);
    }
    _db.put(key, g);
    return new UpdateResponse(HttpStatus.S_204_NO_CONTENT);
}
Also used : UpdateResponse(com.linkedin.restli.server.UpdateResponse) Message(com.linkedin.restli.examples.greetings.api.Message) DataProcessingException(com.linkedin.data.transform.DataProcessingException)

Aggregations

DataProcessingException (com.linkedin.data.transform.DataProcessingException)26 DataComplexProcessor (com.linkedin.data.transform.DataComplexProcessor)16 Test (org.testng.annotations.Test)13 DataMap (com.linkedin.data.DataMap)10 UpdateResponse (com.linkedin.restli.server.UpdateResponse)10 PatchRequest (com.linkedin.restli.common.PatchRequest)3 Message (com.linkedin.data.message.Message)2 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)2 GroupMembership (com.linkedin.restli.examples.groups.api.GroupMembership)2 BatchPatchRequest (com.linkedin.restli.server.BatchPatchRequest)2 BatchUpdateResult (com.linkedin.restli.server.BatchUpdateResult)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 SimpleDataElement (com.linkedin.data.element.SimpleDataElement)1 ValidationOptions (com.linkedin.data.schema.validation.ValidationOptions)1 ValidationResult (com.linkedin.data.schema.validation.ValidationResult)1 RecordTemplate (com.linkedin.data.template.RecordTemplate)1 MaskComposition (com.linkedin.data.transform.filter.MaskComposition)1 Patch (com.linkedin.data.transform.patch.Patch)1 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)1