use of javax.validation.Valid in project gravitee-management-rest-api by gravitee-io.
the class ConfigurationResourceTest method shouldGetApplicationTypes.
@Test
public void shouldGetApplicationTypes() throws TechnicalException {
resetAllMocks();
ApplicationTypesEntity typesEntity = new ApplicationTypesEntity();
List<ApplicationTypeEntity> data = new ArrayList<>();
ApplicationTypeEntity simple = new ApplicationTypeEntity();
simple.setId("simple");
simple.setAllowed_grant_types(new ArrayList<>());
simple.setDefault_grant_types(new ArrayList<>());
simple.setMandatory_grant_types(new ArrayList<>());
simple.setName("Simple");
simple.setDescription("Simple type");
data.add(simple);
ApplicationTypeEntity web = new ApplicationTypeEntity();
web.setId("web");
List<ApplicationGrantTypeEntity> grantTypes = new ArrayList<>();
ApplicationGrantTypeEntity grantType = new ApplicationGrantTypeEntity();
grantType.setName("name");
List<String> responses_types = new ArrayList<>();
responses_types.add("token");
grantType.setResponse_types(responses_types);
grantTypes.add(grantType);
web.setAllowed_grant_types(grantTypes);
web.setDefault_grant_types(new ArrayList<>());
web.setMandatory_grant_types(new ArrayList<>());
web.setName("Web");
web.setDescription("Web type");
data.add(web);
typesEntity.setData(data);
when(applicationTypeService.getEnabledApplicationTypes()).thenReturn(typesEntity);
final Response response = target().path("applications").path("types").request().get();
assertEquals(HttpStatusCode.OK_200, response.getStatus());
final ConfigurationApplicationTypesResponse appTypes = response.readEntity(ConfigurationApplicationTypesResponse.class);
assertNotNull(appTypes);
@Valid List<ApplicationType> types = appTypes.getData();
assertNotNull(types);
assertEquals(2, types.size());
assertEquals("web", types.get(1).getId());
assertEquals(1, types.get(1).getAllowedGrantTypes().size());
}
use of javax.validation.Valid in project keywhiz by square.
the class ClientResource method createClient.
/**
* Creates a client and assigns to given groups
*
* @excludeParams automationClient
* @param request JSON request to create a client
*
* @responseMessage 201 Created client and assigned to given groups
* @responseMessage 409 Client already exists
*/
@Timed
@ExceptionMetered
@POST
@Consumes(APPLICATION_JSON)
public Response createClient(@Auth AutomationClient automationClient, @Valid CreateClientRequestV2 request) {
String creator = automationClient.getName();
String client = request.name();
clientDAOReadWrite.getClient(client).ifPresent((c) -> {
logger.info("Automation ({}) - Client {} already exists", creator, client);
throw new ConflictException("Client name already exists.");
});
// Creates new client record
long clientId = clientDAOReadWrite.createClient(client, creator, request.description());
auditLog.recordEvent(new Event(Instant.now(), EventTag.CLIENT_CREATE, creator, client));
// Enrolls client in any requested groups
groupsToGroupIds(request.groups()).forEach((maybeGroupId) -> maybeGroupId.ifPresent((groupId) -> aclDAOReadWrite.findAndEnrollClient(clientId, groupId, auditLog, creator, new HashMap<>())));
URI uri = UriBuilder.fromResource(ClientResource.class).path(client).build();
return Response.created(uri).build();
}
use of javax.validation.Valid in project ocvn by devgateway.
the class TenderPriceByTypeYearController method tenderPriceByAllBidSelectionMethods.
@ApiOperation(value = "Same as /api/tenderPriceByBidSelectionMethod, but it always returns " + "all bidSelectionMethods (it adds the missing bid selection methods with zero totals")
@RequestMapping(value = "/api/tenderPriceByAllBidSelectionMethods", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> tenderPriceByAllBidSelectionMethods(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
List<DBObject> tenderPriceByBidSelectionMethod = tenderPriceByBidSelectionMethod(filter);
// create a treeset ordered by procurment method details key
Collection<DBObject> ret = new TreeSet<>((DBObject o1, DBObject o2) -> o1.get(Keys.PROCUREMENT_METHOD_DETAILS).toString().compareTo(o2.get(Keys.PROCUREMENT_METHOD_DETAILS).toString()));
// add them all to sorted set
for (DBObject o : tenderPriceByBidSelectionMethod) {
if (o.containsField(Keys.PROCUREMENT_METHOD_DETAILS) && o.get(Keys.PROCUREMENT_METHOD_DETAILS) != null) {
ret.add(o);
} else {
o.put(Keys.PROCUREMENT_METHOD_DETAILS, UNSPECIFIED);
ret.add(o);
}
}
// get all the non null bid selection methods
Set<Object> bidSelectionMethods = bidSelectionMethodSearchController.bidSelectionMethods().stream().filter(e -> e.get(Fields.UNDERSCORE_ID) != null).map(e -> e.get(Fields.UNDERSCORE_ID)).collect(Collectors.toCollection(LinkedHashSet::new));
bidSelectionMethods.add(UNSPECIFIED);
// remove elements that already are in the result
bidSelectionMethods.removeAll(ret.stream().map(e -> e.get(Keys.PROCUREMENT_METHOD_DETAILS)).collect(Collectors.toSet()));
// add the missing procurementmethoddetails with zero amounts
bidSelectionMethods.forEach(e -> {
DBObject obj = new BasicDBObject(Keys.PROCUREMENT_METHOD_DETAILS, e.toString());
obj.put(Keys.TOTAL_TENDER_AMOUNT, BigDecimal.ZERO);
ret.add(obj);
});
return new ArrayList<>(ret);
}
use of javax.validation.Valid in project bisq-api by mrosseel.
the class OfferResource method takeOffer.
@ApiOperation(value = "Take offer", response = TradeDetails.class)
@POST
@Path("/{id}/take")
public void takeOffer(@Suspended final AsyncResponse asyncResponse, @PathParam("id") String id, @Valid TakeOffer data) {
// TODO how do we go about not blocking this REST thread?
final CompletableFuture<Trade> completableFuture = bisqProxy.offerTake(id, data.paymentAccountId, data.amount, true);
completableFuture.thenApply(trade -> asyncResponse.resume(new TradeDetails(trade))).exceptionally(e -> {
final Throwable cause = e.getCause();
final Response.ResponseBuilder responseBuilder;
if (cause instanceof ValidationException) {
final int status = 422;
responseBuilder = toValidationErrorResponse(cause, status);
} else if (cause instanceof IncompatiblePaymentAccountException) {
responseBuilder = toValidationErrorResponse(cause, 423);
} else if (cause instanceof NoAcceptedArbitratorException) {
responseBuilder = toValidationErrorResponse(cause, 424);
} else if (cause instanceof PaymentAccountNotFoundException) {
responseBuilder = toValidationErrorResponse(cause, 425);
} else if (cause instanceof InsufficientMoneyException) {
responseBuilder = toValidationErrorResponse(cause, 427);
} else if (cause instanceof NotFoundException) {
responseBuilder = toValidationErrorResponse(cause, 404);
} else {
final String message = cause.getMessage();
responseBuilder = Response.status(500);
if (null != message)
responseBuilder.entity(new ValidationErrorMessage(ImmutableList.of(message)));
log.error("Unable to take offer: " + id + " " + Json.pretty(data), cause);
}
return asyncResponse.resume(responseBuilder.build());
});
}
use of javax.validation.Valid in project rpki-validator-3 by RIPE-NCC.
the class ValidatedRpkiObjects method initialize.
@PostConstruct
private synchronized void initialize() {
new TransactionTemplate(transactionManager).execute((status) -> {
Map<@NotNull @Valid TrustAnchor, List<RpkiObject>> grouped = Stream.concat(rpkiObjects.findCurrentlyValidated(RpkiObject.Type.ROA), rpkiObjects.findCurrentlyValidated(RpkiObject.Type.ROUTER_CER)).collect(Collectors.groupingBy(pair -> pair.getLeft().getTrustAnchor(), Collectors.mapping(pair -> pair.getRight(), Collectors.toList())));
grouped.forEach(this::update);
return null;
});
}
Aggregations