use of org.springframework.web.util.UriComponentsBuilder in project spring-data-commons by spring-projects.
the class HateoasPageableHandlerMethodArgumentResolverUnitTests method assertUriStringFor.
protected void assertUriStringFor(Pageable pageable, String expected) {
UriComponentsBuilder builder = UriComponentsBuilder.fromPath("/");
MethodParameter parameter = getParameterOfMethod("supportedMethod");
getResolver().enhance(builder, parameter, pageable);
assertThat(builder.build().toUriString()).endsWith(expected);
}
use of org.springframework.web.util.UriComponentsBuilder in project spring-data-commons by spring-projects.
the class HateoasSortHandlerMethodArgumentResolverUnitTests method assertUriStringFor.
private void assertUriStringFor(Sort sort, String expected, String baseUri) throws Exception {
UriComponentsBuilder builder = UriComponentsBuilder.fromUri(new URI(baseUri));
MethodParameter parameter = getParameterOfMethod("supportedMethod");
new HateoasSortHandlerMethodArgumentResolver().enhance(builder, parameter, sort);
assertThat(builder.build().toUriString()).endsWith(expected);
}
use of org.springframework.web.util.UriComponentsBuilder in project ma-modules-public by infiniteautomation.
the class DataPointRestController method bulkDataPointOperation.
@ApiOperation(value = "Bulk get/create/update/delete data points", notes = "User must have read/edit permission for the data point")
@RequestMapping(method = RequestMethod.POST, value = "/bulk")
public ResponseEntity<TemporaryResource<DataPointBulkResponse, AbstractRestV2Exception>> bulkDataPointOperation(@RequestBody DataPointBulkRequest requestBody, @AuthenticationPrincipal User user, UriComponentsBuilder builder) {
VoAction defaultAction = requestBody.getAction();
DataPointModel defaultBody = requestBody.getBody();
List<DataPointIndividualRequest> requests = requestBody.getRequests();
if (requests == null) {
throw new BadRequestException(new TranslatableMessage("rest.error.mustNotBeNull", "requests"));
}
String resourceId = requestBody.getId();
Long expiration = requestBody.getExpiration();
Long timeout = requestBody.getTimeout();
TemporaryResource<DataPointBulkResponse, AbstractRestV2Exception> responseBody = bulkResourceManager.newTemporaryResource(RESOURCE_TYPE_BULK_DATA_POINT, resourceId, user.getId(), expiration, timeout, (resource) -> {
DataPointBulkResponse bulkResponse = new DataPointBulkResponse();
int i = 0;
resource.progress(bulkResponse, i++, requests.size());
for (DataPointIndividualRequest request : requests) {
UriComponentsBuilder reqBuilder = UriComponentsBuilder.newInstance();
DataPointIndividualResponse individualResponse = doIndividualRequest(request, defaultAction, defaultBody, user, reqBuilder);
bulkResponse.addResponse(individualResponse);
resource.progressOrSuccess(bulkResponse, i++, requests.size());
}
});
HttpHeaders headers = new HttpHeaders();
headers.setLocation(builder.path("/v2/data-points/bulk/{id}").buildAndExpand(responseBody.getId()).toUri());
return new ResponseEntity<TemporaryResource<DataPointBulkResponse, AbstractRestV2Exception>>(responseBody, headers, HttpStatus.CREATED);
}
use of org.springframework.web.util.UriComponentsBuilder in project molgenis by molgenis.
the class RestControllerV2 method createEntityCollectionResponse.
private EntityCollectionResponseV2 createEntityCollectionResponse(String entityTypeId, EntityCollectionRequestV2 request, HttpServletRequest httpRequest, boolean includeCategories) {
EntityType meta = dataService.getEntityType(entityTypeId);
Query<Entity> q = request.getQ() != null ? request.getQ().createQuery(meta) : new QueryImpl<>();
q.pageSize(request.getNum()).offset(request.getStart()).sort(request.getSort());
Fetch fetch = AttributeFilterToFetchConverter.convert(request.getAttrs(), meta, LocaleContextHolder.getLocale().getLanguage());
if (fetch != null) {
q.fetch(fetch);
}
if (request.getAggs() != null) {
// return aggregates for aggregate query
AggregateQuery aggsQ = request.getAggs().createAggregateQuery(meta, q);
Attribute xAttr = aggsQ.getAttributeX();
Attribute yAttr = aggsQ.getAttributeY();
if (xAttr == null && yAttr == null) {
throw new MolgenisQueryException("Aggregate query is missing 'x' or 'y' attribute");
}
AggregateResult aggs = dataService.aggregate(entityTypeId, aggsQ);
AttributeResponseV2 xAttrResponse = xAttr != null ? new AttributeResponseV2(entityTypeId, meta, xAttr, fetch, permissionService, dataService) : null;
AttributeResponseV2 yAttrResponse = yAttr != null ? new AttributeResponseV2(entityTypeId, meta, yAttr, fetch, permissionService, dataService) : null;
return new EntityAggregatesResponse(aggs, xAttrResponse, yAttrResponse, BASE_URI + '/' + entityTypeId);
} else {
Long count = dataService.count(entityTypeId, new QueryImpl<>(q).setOffset(0).setPageSize(0));
Iterable<Entity> it;
if (count > 0 && q.getPageSize() > 0) {
it = () -> dataService.findAll(entityTypeId, q).iterator();
} else {
it = Collections.emptyList();
}
EntityPager pager = new EntityPager(request.getStart(), request.getNum(), count, it);
List<Map<String, Object>> entities = new ArrayList<>();
for (Entity entity : it) {
Map<String, Object> responseData = new LinkedHashMap<>();
createEntityValuesResponse(entity, fetch, responseData);
entities.add(responseData);
}
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(getFullURL(httpRequest));
String prevHref = null;
if (pager.getPrevStart() != null) {
builder.replaceQueryParam("start", pager.getPrevStart());
prevHref = builder.build(false).toUriString();
}
String nextHref = null;
if (pager.getNextStart() != null) {
builder.replaceQueryParam("start", pager.getNextStart());
nextHref = builder.build(false).toUriString();
}
return new EntityCollectionResponseV2(pager, entities, fetch, BASE_URI + '/' + entityTypeId, meta, permissionService, dataService, prevHref, nextHref, includeCategories);
}
}
use of org.springframework.web.util.UriComponentsBuilder in project spring-security by spring-projects.
the class Saml2LogoutRequestFilter method doRedirect.
private void doRedirect(HttpServletRequest request, HttpServletResponse response, Saml2LogoutResponse logoutResponse) throws IOException {
String location = logoutResponse.getResponseLocation();
UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromUriString(location);
addParameter(Saml2ParameterNames.SAML_RESPONSE, logoutResponse::getParameter, uriBuilder);
addParameter(Saml2ParameterNames.RELAY_STATE, logoutResponse::getParameter, uriBuilder);
addParameter(Saml2ParameterNames.SIG_ALG, logoutResponse::getParameter, uriBuilder);
addParameter(Saml2ParameterNames.SIGNATURE, logoutResponse::getParameter, uriBuilder);
this.redirectStrategy.sendRedirect(request, response, uriBuilder.build(true).toUriString());
}
Aggregations