use of com.liferay.apio.architect.operation.Method.DELETE in project com-liferay-apio-architect by liferay.
the class MockSingleModelWriter method write.
/**
* Writes a {@link RootModel}, with the hierarchy of embedded models and
* multiple fields.
*
* @param httpHeaders the request's {@code HttpHeaders}
* @param singleModelMessageMapper the {@link SingleModelMessageMapper} to
* use for writing the JSON object
*/
public static JsonObject write(HttpHeaders httpHeaders, SingleModelMessageMapper<RootModel> singleModelMessageMapper) {
RequestInfo requestInfo = getRequestInfo(httpHeaders);
Operation deleteOperation = new Operation(DELETE, "delete-operation");
Operation putOperation = new Operation(createForm("u", "r"), PUT, "update-operation");
SingleModel<RootModel> singleModel = new SingleModel<>(() -> "first", "root", asList(deleteOperation, putOperation));
SingleModelWriter<RootModel> singleModelWriter = SingleModelWriter.create(builder -> builder.singleModel(singleModel).modelMessageMapper(singleModelMessageMapper).pathFunction(MockWriterUtil::identifierToPath).resourceNameFunction(__ -> Optional.of("models")).representorFunction(MockWriterUtil::getRepresentorOptional).requestInfo(requestInfo).singleModelFunction(MockWriterUtil::getSingleModel).build());
Optional<String> optional = singleModelWriter.write();
if (!optional.isPresent()) {
throw new AssertionError("Writer failed to write");
}
return new Gson().fromJson(optional.get(), JsonObject.class);
}
use of com.liferay.apio.architect.operation.Method.DELETE in project com-liferay-apio-architect by liferay.
the class PageEndpointImpl method deleteCollectionItem.
@Override
public Response deleteCollectionItem(String id) throws Exception {
Try<ItemRoutes<T, S>> itemRoutesTry = Try.fromOptional(_itemRoutesSupplier::get, notFound(_name));
ThrowableConsumer<S> throwableConsumer = itemRoutesTry.mapOptional(ItemRoutes::getDeleteConsumerOptional, notAllowed(DELETE, _name, id)).map(function -> function.apply(_httpServletRequest)).getUnchecked();
Path path = new Path(_name, id);
throwableConsumer.accept(_identifierFunction.apply(path));
return noContent().build();
}
use of com.liferay.apio.architect.operation.Method.DELETE in project com-liferay-apio-architect by liferay.
the class ItemRoutesTest method _testItemRoutes.
private void _testItemRoutes(ItemRoutes<String, Long> itemRoutes) throws Exception {
Optional<ItemRoutes<String, Long>> optional = Optional.of(itemRoutes);
Map map = optional.flatMap(ItemRoutes::getFormOptional).map(form -> {
assertThat(form.id, is("u/name"));
return (Map) form.get(_body);
}).get();
Optional<String> valueOptional = _body.getValueOptional("key");
assertThat(map.get("key"), is(valueOptional.get()));
SingleModel<String> singleModel = optional.flatMap(ItemRoutes::getItemFunctionOptional).get().apply(null).apply(42L).getUnchecked();
assertThat(singleModel.getResourceName(), is("name"));
assertThat(singleModel.getModel(), is("Apio"));
optional.flatMap(ItemRoutes::getDeleteConsumerOptional).get().apply(null).accept(42L);
SingleModel<String> updatedSingleModel = optional.flatMap(ItemRoutes::getUpdateItemFunctionOptional).get().apply(null).apply(42L).apply(_body).getUnchecked();
assertThat(updatedSingleModel.getResourceName(), is("name"));
assertThat(updatedSingleModel.getModel(), is("Updated"));
List<Operation> operations = updatedSingleModel.getOperations();
assertThat(operations, hasSize(2));
Operation firstOperation = operations.get(0);
assertThat(firstOperation.getFormOptional(), is(emptyOptional()));
assertThat(firstOperation.method, is(DELETE));
assertThat(firstOperation.name, is("name/delete"));
Operation secondOperation = operations.get(1);
assertThat(secondOperation.getFormOptional(), is(optionalWithValue()));
assertThat(secondOperation.method, is(PUT));
assertThat(secondOperation.name, is("name/update"));
}
Aggregations