use of com.linkedin.restli.server.RestLiServiceException in project rest.li by linkedin.
the class ValidationDemoResource method batchCreate.
@RestMethod.BatchCreate
public BatchCreateResult<Integer, ValidationDemo> batchCreate(final BatchCreateRequest<Integer, ValidationDemo> entities, @ValidatorParam RestLiDataValidator validator) {
List<CreateResponse> results = new ArrayList<CreateResponse>();
int id = 0;
for (ValidationDemo entity : entities.getInput()) {
ValidationResult result = validator.validateInput(entity);
if (result.isValid()) {
results.add(new CreateResponse(id));
id++;
} else {
results.add(new CreateResponse(new RestLiServiceException(HttpStatus.S_422_UNPROCESSABLE_ENTITY, result.getMessages().toString())));
}
}
return new BatchCreateResult<Integer, ValidationDemo>(results);
}
use of com.linkedin.restli.server.RestLiServiceException 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<Integer, UpdateResponse>();
Map<Integer, RestLiServiceException> errors = new HashMap<Integer, RestLiServiceException>();
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<Integer, ValidationDemo>(results, errors);
}
use of com.linkedin.restli.server.RestLiServiceException 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<Long, UpdateResponse>();
responseMap.put(3l, new UpdateResponse(HttpStatus.S_201_CREATED));
final Map<Long, RestLiServiceException> errorsMap = new HashMap<Long, RestLiServiceException>();
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<Long, Greeting>(null);
} else if (entities.getData().containsKey(3l)) {
//Return a BatchUpdateResult with a null errors Map
return new BatchUpdateResult<Long, Greeting>(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<Long, Greeting>(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<Long, Greeting>(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<Long, Greeting>(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<Long, UpdateResponse>(responseMap);
return new BatchUpdateResult<Long, Greeting>(concurrentResponseMap, new ConcurrentHashMap<Long, RestLiServiceException>());
}
}
use of com.linkedin.restli.server.RestLiServiceException in project rest.li by linkedin.
the class StreamingGreetings method create.
public void create(Greeting entity, @CallbackParam Callback<CreateResponse> callback, @RestLiAttachmentsParam RestLiAttachmentReader attachmentReader) {
if (attachmentReader != null) {
final String headerValue = getContext().getRequestHeaders().get("createHeader");
getContext().setResponseHeader("createHeader", headerValue);
attachmentReader.registerAttachmentReaderCallback(new GreetingBlobReaderCallback(callback));
return;
}
callback.onError(new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST, "You must supply some attachments!"));
}
use of com.linkedin.restli.server.RestLiServiceException in project rest.li by linkedin.
the class StringKeysResource method batchGet.
@RestMethod.BatchGet
public Map<String, Message> batchGet(Set<String> ids) {
Map<String, Message> batch = new HashMap<String, Message>();
Map<String, RestLiServiceException> errors = new HashMap<String, RestLiServiceException>();
for (String id : ids) {
Message g = _db.get(id);
if (g != null) {
batch.put(id, g);
} else {
errors.put(id, new RestLiServiceException(HttpStatus.S_404_NOT_FOUND));
}
}
return new BatchResult<String, Message>(batch, errors);
}
Aggregations