use of com.linkedin.restli.server.UpdateResponse in project rest.li by linkedin.
the class GreetingsResourceImpl method update.
@RestMethod.Update
public UpdateResponse update(Long key, Greeting entity) {
Greeting g = _db.get(key);
if (g == null) {
return new UpdateResponse(HttpStatus.S_404_NOT_FOUND);
}
_db.put(key, entity);
return new UpdateResponse(HttpStatus.S_204_NO_CONTENT);
}
use of com.linkedin.restli.server.UpdateResponse in project rest.li by linkedin.
the class ValidationDemoResource method batchUpdate.
@RestMethod.BatchPartialUpdate
public BatchUpdateResult<Integer, ValidationDemo> batchUpdate(final BatchPatchRequest<Integer, ValidationDemo> entityUpdates, @ValidatorParam RestLiDataValidator validator) {
Map<Integer, UpdateResponse> results = new HashMap<>();
Map<Integer, RestLiServiceException> errors = new HashMap<>();
for (Map.Entry<Integer, PatchRequest<ValidationDemo>> entry : entityUpdates.getData().entrySet()) {
Integer key = entry.getKey();
PatchRequest<ValidationDemo> patch = entry.getValue();
ValidationResult result = validator.validateInput(patch);
if (result.isValid()) {
results.put(key, new UpdateResponse(HttpStatus.S_204_NO_CONTENT));
} else {
errors.put(key, new RestLiServiceException(HttpStatus.S_422_UNPROCESSABLE_ENTITY, result.getMessages().toString()));
}
}
return new BatchUpdateResult<>(results, errors);
}
use of com.linkedin.restli.server.UpdateResponse in project rest.li by linkedin.
the class AssociationAltKeyResource method update.
@Override
public UpdateResponse update(CompoundKey key, PatchRequest<Greeting> patch) {
Greeting g = 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);
}
update(key, g);
return new UpdateResponse(HttpStatus.S_204_NO_CONTENT);
}
use of com.linkedin.restli.server.UpdateResponse in project rest.li by linkedin.
the class GroupMembershipsResource2 method batchUpdate.
@Override
public BatchUpdateResult<CompoundKey, GroupMembership> batchUpdate(BatchPatchRequest<CompoundKey, GroupMembership> patches) {
Map<CompoundKey, UpdateResponse> results = new HashMap<>();
for (Map.Entry<CompoundKey, PatchRequest<GroupMembership>> entry : patches.getData().entrySet()) {
CompoundKey key = entry.getKey();
PatchRequest<GroupMembership> patch = entry.getValue();
GroupMembership groupMembership = _app.getMembershipMgr().get(key);
if (groupMembership == null) {
results.put(key, new UpdateResponse(HttpStatus.S_404_NOT_FOUND));
} else {
try {
PatchApplier.applyPatch(groupMembership, patch);
_app.getMembershipMgr().save(groupMembership);
results.put(key, new UpdateResponse(HttpStatus.S_204_NO_CONTENT));
} catch (DataProcessingException e) {
results.put(key, new UpdateResponse(HttpStatus.S_400_BAD_REQUEST));
}
}
}
return new BatchUpdateResult<>(results);
}
use of com.linkedin.restli.server.UpdateResponse in project rest.li by linkedin.
the class NullGreetingsResourceImpl method batchUpdate.
@RestMethod.BatchUpdate
public BatchUpdateResult<Long, Greeting> batchUpdate(BatchUpdateRequest<Long, Greeting> entities) {
final Map<Long, UpdateResponse> responseMap = new HashMap<>();
responseMap.put(3l, new UpdateResponse(HttpStatus.S_201_CREATED));
final Map<Long, RestLiServiceException> errorsMap = new HashMap<>();
errorsMap.put(8l, new RestLiServiceException(HttpStatus.S_202_ACCEPTED));
if (entities.getData().containsKey(1l)) {
// Return a null BatchUpdateResult
return null;
} else if (entities.getData().containsKey(2l)) {
// Return a BatchUpdateResult with a null results Map
return new BatchUpdateResult<>(null);
} else if (entities.getData().containsKey(3l)) {
// Return a BatchUpdateResult with a null errors Map
return new BatchUpdateResult<>(responseMap, null);
} else if (entities.getData().containsKey(4l)) {
// Return a BatchUpdateResult with a errors Map that has a null key in it
errorsMap.put(null, new RestLiServiceException(HttpStatus.S_202_ACCEPTED));
return new BatchUpdateResult<>(responseMap, errorsMap);
} else if (entities.getData().containsKey(5l)) {
// Return a BatchUpdateResult with a errors Map that has a null value in it
errorsMap.put(9l, null);
return new BatchUpdateResult<>(responseMap, errorsMap);
} else if (entities.getData().containsKey(6l)) {
// Return a BatchUpdateResult with a map that has a null key in it
responseMap.put(null, new UpdateResponse(HttpStatus.S_201_CREATED));
return new BatchUpdateResult<>(responseMap);
} else {
/*
* Return a BatchUpdateResult with java.util.concurrent.ConcurrentHashMap(s).
* This test is in place because certain map implementations, such as ConcurrentHashMap, can throw an NPE when
* calling contains(null). We want to verify that checking for the existence of nulls in maps returned by
* Rest.li resource methods do not cause such NPEs.
* This is one of the few cases in this file where an error will not be generated by Rest.li.
*/
final Map<Long, UpdateResponse> concurrentResponseMap = new ConcurrentHashMap<>(responseMap);
return new BatchUpdateResult<>(concurrentResponseMap, new ConcurrentHashMap<>());
}
}
Aggregations