/** @see com.linkedin.restli.server.resources.ComplexKeyResourceTemplate#batchCreate(com.linkedin.restli.server.BatchCreateRequest) */ @Override public BatchCreateResult<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, ComplexKeyGroupMembership> batchCreate(BatchCreateRequest<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, ComplexKeyGroupMembership> groupMemberships) { List<CreateResponse> list = new LinkedList<CreateResponse>(); for (ComplexKeyGroupMembership groupMembership : groupMemberships.getInput()) { list.add(create(groupMembership)); } return new BatchCreateResult<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, ComplexKeyGroupMembership>(list); }
@RestMethod.BatchCreate public BatchCreateResult<Long, Greeting> batchCreate(BatchCreateRequest<Long, Greeting> entities) { List<CreateResponse> responses = new ArrayList<CreateResponse>(entities.getInput().size()); for (Greeting g : entities.getInput()) { responses.add(create(g, false)); } return new BatchCreateResult<Long, Greeting>(responses); }
@RestMethod.BatchCreate public BatchCreateResult<Long, Greeting> batchCreate(BatchCreateRequest<Long, Greeting> entities) { List<CreateResponse> responses = new ArrayList<CreateResponse>(1); if (entities.getInput().size() == 0) { //Return null return null; } else if (entities.getInput().size() == 1) { //Return a new BatchCreateResult with a null list return new BatchCreateResult<Long, Greeting>(null); } else { //Return a new BatchCreateResult with a response list that has a null inside of it responses.add(new CreateResponse(1l)); responses.add(null); return new BatchCreateResult<Long, Greeting>(responses); } }
@Override public BatchCreateResult<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> batchCreate(final BatchCreateRequest<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> entities) { List<CreateResponse> createResponses = new ArrayList<CreateResponse>(entities.getInput().size()); for(Message message : entities.getInput()) { ComplexResourceKey<TwoPartKey, TwoPartKey> key = _dataProvider.create(message); CreateResponse createResponse = new CreateResponse(key); createResponses.add(createResponse); } return new BatchCreateResult<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message>(createResponses); }
@RestMethod.BatchCreate public BatchCreateResult<String, Message> batchCreate(BatchCreateRequest<String, Message> entities) { List<CreateResponse> responses = new ArrayList<CreateResponse>(entities.getInput().size()); for (Message g : entities.getInput()) { responses.add(create(g)); } return new BatchCreateResult<String, Message>(responses); }
/** * For a batch create request, responds with an error for requests to create insulting greetings, responds * with 201 created for all other requests. */ @Override public BatchCreateResult<Long, Greeting> batchCreate(BatchCreateRequest<Long, Greeting> entities) { List<CreateResponse> responses = new ArrayList<CreateResponse>(entities.getInput().size()); for (Greeting g : entities.getInput()) { try { responses.add(create(g)); } catch (RestLiServiceException restliException) { responses.add(new CreateResponse(restliException)); } } return new BatchCreateResult<Long, Greeting>(responses); } }
@Override public BatchCreateResult<CustomLong, Greeting> batchCreate(BatchCreateRequest<CustomLong, Greeting> entities) { List<CreateResponse> results = new ArrayList<CreateResponse>(); for (Greeting greeting: entities.getInput()) { // just echo back the provided ids (for testing only, this would not a be correct implementation of POST) results.add(new CreateResponse(new CustomLong(greeting.getId()), HttpStatus.S_204_NO_CONTENT)); } return new BatchCreateResult<CustomLong, Greeting>(results); } }
@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); }
public ExampleRequestResponse batchCreate() { checkSupports(ResourceMethod.BATCH_CREATE); BatchCreateRequestBuilder<Object, RecordTemplatePlaceholder> create = new BatchCreateRequestBuilder<Object, RecordTemplatePlaceholder>( _uriTemplate, RecordTemplatePlaceholder.class, _resourceSpec, _requestOptions); create.input(generateEntity()); create.input(generateEntity()); addParams(create, ResourceMethod.BATCH_CREATE); addPathKeys(create); BatchCreateRequest<RecordTemplatePlaceholder> request = create.build(); BatchCreateResult<Object, RecordTemplatePlaceholder> result = new BatchCreateResult<Object, RecordTemplatePlaceholder>(Arrays.asList( new CreateResponse(generateKey(), HttpStatus.S_201_CREATED), new CreateResponse(generateKey(), HttpStatus.S_201_CREATED))); return buildRequestResponse(request, result, buildResourceMethodDescriptorForRestMethod(request)); }