org.springframework.hateoas.Resource Java Examples
The following examples show how to use
org.springframework.hateoas.Resource.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProjectController.java From service-block-samples with Apache License 2.0 | 6 votes |
private ResourceSupport getCommandsResource(Long id) { Project project = new Project(); project.setIdentity(id); CommandResources commandResources = new CommandResources(); // Add suspend command link commandResources.add(linkTo(ProjectController.class) .slash("projects") .slash(id) .slash("commands") .slash("commit") .withRel("commit")); return new Resource<>(commandResources); }
Example #2
Source File: ServiceDocumentControllerTest.java From Microservices-with-Spring-Cloud with MIT License | 6 votes |
@Test public void getServiceDocument() throws Exception { String result = mvc.perform( MockMvcRequestBuilders.get("/") .accept("application/hal+json;charset=UTF-8") ).andDo(print()) .andExpect(content() .contentTypeCompatibleWith("application/hal+json;charset=UTF-8")) .andReturn().getResponse().getContentAsString(); Resource<String> value = mapper.readValue(result, new TypeReference<Resource<String>>() { }); List<String> linkRels = value.getLinks().stream().map(link -> link.getRel()).collect(Collectors.toList()); assertThat(linkRels, Matchers.hasItem("self")); assertEquals(value.getLink("self"), value.getId()); assertTrue(value.hasLink("bookmarks")); }
Example #3
Source File: EventController.java From sos with Apache License 2.0 | 6 votes |
@GetMapping("events") HttpEntity<Resources<?>> events(PagedResourcesAssembler<AbstractEvent<?>> assembler, @SortDefault("publicationDate") Pageable pageable, @RequestParam(required = false) @DateTimeFormat(iso = ISO.DATE_TIME) LocalDateTime since, @RequestParam(required = false) String type) { QAbstractEvent $ = QAbstractEvent.abstractEvent; BooleanBuilder builder = new BooleanBuilder(); // Apply date Optional.ofNullable(since).ifPresent(it -> builder.and($.publicationDate.after(it))); // Apply type Optional.ofNullable(type) // .flatMap(events::findEventTypeByName) // .ifPresent(it -> builder.and($.instanceOf(it))); Page<AbstractEvent<?>> result = events.findAll(builder, pageable); PagedResources<Resource<AbstractEvent<?>>> resource = assembler.toResource(result, event -> toResource(event)); resource .add(links.linkTo(methodOn(EventController.class).events(assembler, pageable, since, type)).withRel("events")); return ResponseEntity.ok(resource); }
Example #4
Source File: BookmarkControllerTest.java From Microservices-with-Spring-Cloud with MIT License | 6 votes |
@Test public void updateABookmark() throws Exception { Bookmark input = getSimpleBookmark(); String location = addBookmark(input); Resource<Bookmark> output = getBookmark(location); String result = mvc.perform( put(output.getId().getHref()) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept("application/hal+json;charset=UTF-8", "application/json;charset=UTF-8") .content(objectMapper.writeValueAsString(output.getContent().withUrl("http://kulinariweb.de"))) .with(csrf()) ).andDo(print()).andExpect(status().isOk()) .andReturn().getResponse().getContentAsString(); output = objectMapper.readValue(result, new TypeReference<Resource<Bookmark>>() { }); assertEquals("http://kulinariweb.de", output.getContent().getUrl()); }
Example #5
Source File: RubricsServiceImpl.java From sakai with Educational Community License v2.0 | 6 votes |
protected Collection<Resource<Evaluation>> getRubricEvaluationsByAssociation(Long associationId) throws Exception { TypeReferences.ResourcesType<Resource<Evaluation>> resourceParameterizedTypeReference = new TypeReferences.ResourcesType<Resource<Evaluation>>() {}; URI apiBaseUrl = new URI(serverConfigurationService.getServerUrl() + RBCS_SERVICE_URL_PREFIX); Traverson traverson = new Traverson(apiBaseUrl, MediaTypes.HAL_JSON); Traverson.TraversalBuilder builder = traverson.follow("evaluations", "search", "by-association-id"); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", String.format("Bearer %s", generateJsonWebToken(RubricsConstants.RBCS_TOOL))); builder.withHeaders(headers); Map<String, Object> parameters = new HashMap<>(); parameters.put("toolItemRubricAssociationId", associationId); Resources<Resource<Evaluation>> evaluationResources = builder.withTemplateParameters(parameters).toObject(resourceParameterizedTypeReference); return evaluationResources.getContent(); }
Example #6
Source File: BugController.java From steady with Apache License 2.0 | 6 votes |
/** * Deletes the {@link Bug} with the given external ID. This ID is provided by the user when creating a bug, e.g., a CVE identifier. * * @return 404 {@link HttpStatus#NOT_FOUND} if bug with given bug ID does not exist, 200 {@link HttpStatus#OK} if the bug was successfully deleted * @param bugid a {@link java.lang.String} object. */ @RequestMapping(value = "/{bugid}", method = RequestMethod.DELETE) @CacheEvict(value = "bug") public ResponseEntity<Resource<Bug>> deleteBug(@PathVariable String bugid) { try { final Bug b = BugRepository.FILTER.findOne(this.bugRepository.findByBugId(bugid)); // Ensure that no affected libs for bug exist final List<AffectedLibrary> aff_libs = this.afflibRepository.findByBug(b); if(aff_libs!=null && aff_libs.size()>0) return new ResponseEntity<Resource<Bug>>(HttpStatus.UNPROCESSABLE_ENTITY); this.bugRepository.delete(b); return new ResponseEntity<Resource<Bug>>(HttpStatus.OK); } catch(EntityNotFoundException enfe) { return new ResponseEntity<Resource<Bug>>(HttpStatus.NOT_FOUND); } }
Example #7
Source File: LockingAndVersioningRestController.java From spring-content with Apache License 2.0 | 6 votes |
@ResponseBody @RequestMapping(value = ENTITY_VERSION_MAPPING, method = RequestMethod.PUT) public ResponseEntity<Resource<?>> version(RootResourceInformation repoInfo, @PathVariable String repository, @PathVariable String id, @RequestBody VersionInfo info, Principal principal, PersistentEntityResourceAssembler assembler) throws ResourceNotFoundException, HttpRequestMethodNotSupportedException { Object domainObj = repoInfo.getInvoker().invokeFindById(id).get(); domainObj = ReflectionUtils.invokeMethod(VERSION_METHOD, repositories.getRepositoryFor(domainObj.getClass()).get(), domainObj, info); if (domainObj != null) { return new ResponseEntity(assembler.toResource(domainObj), HttpStatus.OK); } else { return ResponseEntity.status(HttpStatus.CONFLICT).build(); } }
Example #8
Source File: LockingAndVersioningRestController.java From spring-content with Apache License 2.0 | 6 votes |
@ResponseBody @RequestMapping(value = ENTITY_LOCK_MAPPING, method = RequestMethod.DELETE) public ResponseEntity<Resource<?>> unlock(RootResourceInformation repoInfo, @PathVariable String repository, @PathVariable String id, Principal principal) throws ResourceNotFoundException, HttpRequestMethodNotSupportedException { Object domainObj = repoInfo.getInvoker().invokeFindById(id).get(); domainObj = ReflectionUtils.invokeMethod(UNLOCK_METHOD, repositories.getRepositoryFor(domainObj.getClass()).get(), domainObj); if (domainObj != null) { return ResponseEntity.ok().build(); } else { return ResponseEntity.status(HttpStatus.CONFLICT).build(); } }
Example #9
Source File: RubricsServiceImpl.java From sakai with Educational Community License v2.0 | 6 votes |
public void restoreRubricAssociation(String toolId, String itemId) { try{ Optional<Resource<ToolItemRubricAssociation>> associationResource = getRubricAssociationResource(toolId, itemId, null); if (associationResource.isPresent()) { String associationHref = associationResource.get().getLink(Link.REL_SELF).getHref(); ToolItemRubricAssociation association = associationResource.get().getContent(); String created = association.getMetadata().getCreated().toString(); String owner = association.getMetadata().getOwnerId(); String ownerType = association.getMetadata().getOwnerType(); String creatorId = association.getMetadata().getCreatorId(); Map <String,Boolean> oldParams = association.getParameters(); oldParams.put(RubricsConstants.RBCS_SOFT_DELETED, false); String input = "{\"toolId\" : \""+toolId+"\",\"itemId\" : \"" + association.getItemId() + "\",\"rubricId\" : " + association.getRubricId() + ",\"metadata\" : {\"created\" : \"" + created + "\",\"ownerId\" : \"" + owner + "\",\"ownerType\" : \"" + ownerType + "\",\"creatorId\" : \"" + creatorId + "\"},\"parameters\" : {" + setConfigurationParametersForDuplication(oldParams) + "}}"; log.debug("Restoring association {}", input); String resultPut = putRubricResource(associationHref, input, toolId, null); log.debug("resultPUT: {}", resultPut); } } catch (Exception e) { log.warn("Error restoring rubric association for item id prefix {} : {}", itemId, e.getMessage()); } }
Example #10
Source File: CatalogController.java From microservices-dashboard with Apache License 2.0 | 6 votes |
@GetMapping public CatalogResource getCatalog() { Catalog catalog = this.service.getCatalog(); List<Resource<String>> applicationInstanceResources = catalog.getApplications() .stream() .map(catalog::getApplicationInstancesForApplication) .flatMap(Collection::stream) .map(applicationInstance -> { Resource<String> resource = new Resource<>(applicationInstance); resource.add(linkTo(ApplicationInstanceController.class) .slash(applicationInstance) .withSelfRel()); return resource; }) .collect(Collectors.toList()); return new CatalogResource(applicationInstanceResources); }
Example #11
Source File: ProjectController.java From service-block-samples with Apache License 2.0 | 6 votes |
/** * Appends an {@link ProjectEvent} domain event to the event log of the {@link Project} * aggregate with the specified projectId. * * @param projectId is the unique identifier for the {@link Project} * @param event is the {@link ProjectEvent} that attempts to alter the state of the {@link Project} * @return a hypermedia resource for the newly appended {@link ProjectEvent} */ private Resource<ProjectEvent> appendEventResource(Long projectId, ProjectEvent event) { Assert.notNull(event, "Event body must be provided"); Project project = projectRepository.findById(projectId).get(); Assert.notNull(project, "Project could not be found"); event.setProjectId(project.getIdentity()); projectEventService.apply(event, projectService); return new Resource<>(event, linkTo(ProjectController.class) .slash("projects") .slash(projectId) .slash("events") .slash(event.getEventId()) .withSelfRel(), linkTo(ProjectController.class) .slash("projects") .slash(projectId) .withRel("project") ); }
Example #12
Source File: PaymentController.java From micro-ecommerce with Apache License 2.0 | 5 votes |
/** * Takes the {@link Receipt} for the given {@link Order} and thus completes * the process. * * @param order * @return */ @RequestMapping(value = PaymentLinks.RECEIPT, method = DELETE) HttpEntity<Resource<Receipt>> takeReceipt(@PathVariable("id") Order order) { if (order == null || !order.isPaid()) { return new ResponseEntity<Resource<Receipt>>(HttpStatus.NOT_FOUND); } return createReceiptResponse(paymentService.takeReceiptFor(order)); }
Example #13
Source File: RubricsServiceImpl.java From sakai with Educational Community License v2.0 | 5 votes |
/** * Returns the ToolItemRubricAssociation resource for the given tool and associated item ID, wrapped as an Optional. * @param toolId the tool id, something like "sakai.assignment" * @param associatedToolItemId the id of the associated element within the tool * @return */ protected Optional<Resource<ToolItemRubricAssociation>> getRubricAssociationResource(String toolId, String associatedToolItemId, String siteId) throws Exception { TypeReferences.ResourcesType<Resource<ToolItemRubricAssociation>> resourceParameterizedTypeReference = new TypeReferences.ResourcesType<Resource<ToolItemRubricAssociation>>() {}; URI apiBaseUrl = new URI(serverConfigurationService.getServerUrl() + RBCS_SERVICE_URL_PREFIX); Traverson traverson = new Traverson(apiBaseUrl, MediaTypes.HAL_JSON); Traverson.TraversalBuilder builder = traverson.follow("rubric-associations", "search", "by-tool-item-ids"); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", String.format("Bearer %s", generateJsonWebToken(toolId, siteId))); builder.withHeaders(headers); Map<String, Object> parameters = new HashMap<>(); parameters.put("toolId", toolId); parameters.put("itemId", associatedToolItemId); Resources<Resource<ToolItemRubricAssociation>> associationResources = builder.withTemplateParameters( parameters).toObject(resourceParameterizedTypeReference); // Should only be one matching this search criterion if (associationResources.getContent().size() > 1) { throw new IllegalStateException(String.format( "Number of rubric association resources greater than one for request: %s", associationResources.getLink(Link.REL_SELF).toString())); } Optional<Resource<ToolItemRubricAssociation>> associationResource = associationResources.getContent().stream().findFirst(); return associationResource; }
Example #14
Source File: PersonResourceProcessor.java From building-microservices with Apache License 2.0 | 5 votes |
@Override public Resource<Person> process(Resource<Person> resource) { String id = Long.toString(resource.getContent().getId()); UriComponents uriComponents = ServletUriComponentsBuilder.fromCurrentContextPath() .path("/people/{id}/photo").buildAndExpand(id); String uri = uriComponents.toUriString(); resource.add(new Link(uri, "photo")); return resource; }
Example #15
Source File: RubricsServiceImpl.java From sakai with Educational Community License v2.0 | 5 votes |
private void deleteRubricEvaluationsForAssociation(String associationHref, String tool){ try{ String [] assocSplitted = associationHref.split("/"); Long associationId = Long.valueOf(assocSplitted[assocSplitted.length-1]); log.debug("Deleting evaluations for association {}", associationId); Collection<Resource<Evaluation>> evaluations = getRubricEvaluationsByAssociation(Long.valueOf(associationId)); for(Resource<Evaluation> eval : evaluations){ deleteRubricResource(eval.getLink(Link.REL_SELF).getHref(), tool, null); } } catch (Exception e) { log.warn("Error deleting rubric association for tool {} and association {} : {}", tool, associationHref, e.getMessage()); } }
Example #16
Source File: RubricsServiceImpl.java From sakai with Educational Community License v2.0 | 5 votes |
/** * Returns the ToolItemRubricAssociation resource for the given tool and associated item ID, wrapped as an Optional. * @param toolId the tool id, something like "sakai.assignment" * @param associatedToolItemId the id of the associated element within the tool * @return */ protected Optional<Resource<ToolItemRubricAssociation>> getRubricAssociationResource(String toolId, String associatedToolItemId, String siteId) throws Exception { TypeReferences.ResourcesType<Resource<ToolItemRubricAssociation>> resourceParameterizedTypeReference = new TypeReferences.ResourcesType<Resource<ToolItemRubricAssociation>>() {}; URI apiBaseUrl = new URI(serverConfigurationService.getServerUrl() + RBCS_SERVICE_URL_PREFIX); Traverson traverson = new Traverson(apiBaseUrl, MediaTypes.HAL_JSON); Traverson.TraversalBuilder builder = traverson.follow("rubric-associations", "search", "by-tool-item-ids"); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", String.format("Bearer %s", generateJsonWebToken(toolId, siteId))); builder.withHeaders(headers); Map<String, Object> parameters = new HashMap<>(); parameters.put("toolId", toolId); parameters.put("itemId", associatedToolItemId); Resources<Resource<ToolItemRubricAssociation>> associationResources = builder.withTemplateParameters( parameters).toObject(resourceParameterizedTypeReference); // Should only be one matching this search criterion if (associationResources.getContent().size() > 1) { throw new IllegalStateException(String.format( "Number of rubric association resources greater than one for request: %s", associationResources.getLink(Link.REL_SELF).toString())); } Optional<Resource<ToolItemRubricAssociation>> associationResource = associationResources.getContent().stream().findFirst(); return associationResource; }
Example #17
Source File: MsgController.java From Spring5Tutorial with GNU Lesser General Public License v3.0 | 5 votes |
@GetMapping("newestMessages") public Resources<Resource<Message>> newestMessages(@RequestParam("n") int n) { List<Message> messages = messageService.newestMessages(n); List<Resource<Message>> result = IntStream.range(0, messages.size()) .mapToObj(idx -> new Resource<>(messages.get(idx))) .collect(toList()); String uri = String.format("%s/newestMessages?n=%d", linkTo(MsgController.class), n); return new Resources<>(result, new Link(uri)); }
Example #18
Source File: AccountServiceRest.java From Spring5Tutorial with GNU Lesser General Public License v3.0 | 5 votes |
public Optional<Account> accountByNameEmail(String name, String email) { RequestEntity<Void> request = RequestEntity .get(URI.create(String.format("http://localhost:8084/accountByNameEmail?username=%s&email=%s", name, email))) .build(); ResponseEntity<Resource<Account>> response = restTemplate.exchange(request, new TypeReferences.ResourceType<Account>() {}); return Optional.ofNullable(response.getBody().getContent()); }
Example #19
Source File: CustomSearchController.java From galeb with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @GetMapping(value = "/environment/findAllByVirtualhostgroupId", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<PagedResources<Resource<Environment>>> findAllByVirtualhostgroupId(@RequestParam("vhgid") Long vhgid) { List<Environment> environments = environmentRepository.findAllByVirtualhostgroupId(vhgid); List<Resource<Environment>> resources = environments.stream().map(Resource::new).collect(Collectors.toList()); PagedResources.PageMetadata meta = new PagedResources.PageMetadata(environments.size(), 0, environments.size()); return ResponseEntity.ok(new PagedResources<>(resources, meta, Collections.emptyList())); }
Example #20
Source File: UserService.java From myfeed with Apache License 2.0 | 5 votes |
public Observable<Resource<User>> getFollowing(String userid) { Resources<Resource<User>> users = traverson.create("myfeed-user") .follow("users", "search", "findByFollowing") .withTemplateParameters(Collections.singletonMap("userId", userid)) .toObject(TYPE_USERS); return Observable.from(users.getContent()); }
Example #21
Source File: MsgController.java From Spring5Tutorial with GNU Lesser General Public License v3.0 | 5 votes |
@GetMapping("newestMessages") public Resources<Resource<Message>> newestMessages(@RequestParam("n") int n) { List<Message> messages = messageService.newestMessages(n); List<Resource<Message>> result = IntStream.range(0, messages.size()) .mapToObj(idx -> new Resource<>(messages.get(idx))) .collect(toList()); String uri = String.format("%s/newestMessages?n=%d", linkTo(MsgController.class), n); return new Resources<>(result, new Link(uri)); }
Example #22
Source File: AcctController.java From Spring5Tutorial with GNU Lesser General Public License v3.0 | 5 votes |
@PostMapping("tryCreateUser") public Resource<Optional<Account>> tryCreateUser( @RequestParam("email") String email, @RequestParam("username") String username, @RequestParam("password") String password) { Optional<Account> acct = accountService.tryCreateUser(email, username, password); String uri = String.format("%s/tryCreateUser?email=%s&username=%s&password=%s", linkTo(AcctController.class), email, username, password); return new Resource<>(acct, new Link(uri)); }
Example #23
Source File: RubricsServiceImpl.java From sakai with Educational Community License v2.0 | 5 votes |
public void deleteSiteRubrics(String siteId) { try { TypeReferences.ResourcesType<Resource<Rubric>> resourceParameterizedTypeReference = new TypeReferences.ResourcesType<Resource<Rubric>>() {}; URI apiBaseUrl = new URI(serverConfigurationService.getServerUrl() + RBCS_SERVICE_URL_PREFIX); Traverson traverson = new Traverson(apiBaseUrl, MediaTypes.HAL_JSON); Traverson.TraversalBuilder builder = traverson.follow("rubrics", "search", "rubrics-from-site"); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", String.format("Bearer %s", generateJsonWebToken(RubricsConstants.RBCS_TOOL, siteId))); builder.withHeaders(headers); Map<String, Object> parameters = new HashMap<>(); parameters.put("siteId", siteId); Resources<Resource<Rubric>> rubricResources = builder.withTemplateParameters(parameters).toObject(resourceParameterizedTypeReference); for (Resource<Rubric> rubricResource : rubricResources) { String [] rubricSplitted = rubricResource.getLink(Link.REL_SELF).getHref().split("/"); Collection<Resource<ToolItemRubricAssociation>> assocs = getRubricAssociationByRubric(rubricSplitted[rubricSplitted.length-1],siteId); for(Resource<ToolItemRubricAssociation> associationResource : assocs){ String associationHref = associationResource.getLink(Link.REL_SELF).getHref(); deleteRubricResource(associationHref, RubricsConstants.RBCS_TOOL, siteId); } deleteRubricResource(rubricResource.getLink(Link.REL_SELF).getHref(), RubricsConstants.RBCS_TOOL, siteId); } } catch(Exception e){ log.error("Rubrics: error trying to delete rubric -> {}" , e.getMessage()); } }
Example #24
Source File: AccountServiceRest.java From Spring5Tutorial with GNU Lesser General Public License v3.0 | 5 votes |
public boolean userExisted(String username) { RequestEntity<Void> request = RequestEntity .post(URI.create(String.format("http://localhost:8084/userExisted?username=%s", username))) .build(); ResponseEntity<Resource<Boolean>> response = restTemplate.exchange(request, new TypeReferences.ResourceType<Boolean>() {}); return response.getBody().getContent(); }
Example #25
Source File: TodoController.java From Mastering-Spring-5.0 with MIT License | 5 votes |
@GetMapping(path = "/users/{name}/todos/{id}") public Resource<Todo> retrieveTodo(@PathVariable String name, @PathVariable int id) { Todo todo = todoService.retrieveTodo(id); if (todo == null) { throw new TodoNotFoundException("Todo Not Found"); } Resource<com.mastering.spring.springboot.bean.Todo> todoResource = new Resource<com.mastering.spring.springboot.bean.Todo>(todo); ControllerLinkBuilder linkTo = linkTo(methodOn(this.getClass()).retrieveTodos(name)); todoResource.add(linkTo.withRel("parent")); return todoResource; }
Example #26
Source File: RubricsServiceImpl.java From sakai with Educational Community License v2.0 | 5 votes |
public void restoreRubricAssociationsByItemIdPrefix(String itemId, String toolId) { try{ TypeReferences.ResourcesType<Resource<ToolItemRubricAssociation>> resourceParameterizedTypeReference = new TypeReferences.ResourcesType<Resource<ToolItemRubricAssociation>>() {}; URI apiBaseUrl = new URI(serverConfigurationService.getServerUrl() + RBCS_SERVICE_URL_PREFIX); Traverson traverson = new Traverson(apiBaseUrl, MediaTypes.HAL_JSON); Traverson.TraversalBuilder builder = traverson.follow("rubric-associations", "search", "by-item-id-prefix"); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", String.format("Bearer %s", generateJsonWebToken(toolId))); builder.withHeaders(headers); Map<String, Object> parameters = new HashMap<>(); parameters.put("toolId", toolId); parameters.put("itemId", itemId); Resources<Resource<ToolItemRubricAssociation>> associationResources = builder.withTemplateParameters(parameters).toObject(resourceParameterizedTypeReference); for (Resource<ToolItemRubricAssociation> associationResource : associationResources) { String associationHref = associationResource.getLink(Link.REL_SELF).getHref(); ToolItemRubricAssociation association = associationResource.getContent(); String created = association.getMetadata().getCreated().toString(); String owner = association.getMetadata().getOwnerId(); String ownerType = association.getMetadata().getOwnerType(); String creatorId = association.getMetadata().getCreatorId(); Map <String,Boolean> oldParams = association.getParameters(); oldParams.put(RubricsConstants.RBCS_SOFT_DELETED, false); String input = "{\"toolId\" : \""+toolId+"\",\"itemId\" : \"" + association.getItemId() + "\",\"rubricId\" : " + association.getRubricId() + ",\"metadata\" : {\"created\" : \"" + created + "\",\"ownerId\" : \"" + owner + "\",\"ownerType\" : \"" + ownerType + "\",\"creatorId\" : \"" + creatorId + "\"},\"parameters\" : {" + setConfigurationParametersForDuplication(oldParams) + "}}"; log.debug("Restoring association {}", input); String resultPut = putRubricResource(associationHref, input, toolId, null); log.debug("resultPUT: {}", resultPut); } } catch (Exception e) { log.warn("Error restoring rubric association for id {} : {}", itemId, e.getMessage()); } }
Example #27
Source File: CatalogIntegration.java From sos with Apache License 2.0 | 5 votes |
private void initializeInventory(Resources<Resource<ProductAdded>> resources) { log.info("Processing {} new events…", resources.getContent().size()); resources.forEach(resource -> { Integration integration = repository.apply(() -> initInventory(resource), it -> it.withCatalogUpdate(resource.getContent().getPublicationDate())); log.info("Successful catalog update. New reference time: {}.", integration.getCatalogUpdate().map(it -> it.format(DateTimeFormatter.ISO_DATE_TIME)) // .orElseThrow(() -> new IllegalStateException())); }); }
Example #28
Source File: WebsiteRestController.java From JiwhizBlogWeb with Apache License 2.0 | 5 votes |
/** * Get current user info. If not authenticated, return 401. * @return */ @RequestMapping(method = RequestMethod.GET, value = ApiUrls.URL_SITE_CURRENT_USER) public HttpEntity<Resource<UserAccount>> getCurrentUserAccount() { UserAccount currentUser = this.userAccountService.getCurrentUser(); Resource<UserAccount> resource = (currentUser == null)? null : new Resource<UserAccount>(currentUser); return new ResponseEntity<>(resource, HttpStatus.OK); }
Example #29
Source File: AmazonS3Controller.java From spring-boot-starter-amazon-s3 with Apache License 2.0 | 5 votes |
@RequestMapping(method = RequestMethod.GET) public List<Resource<S3ObjectSummary>> getBucketResources() { ObjectListing objectListing = amazonS3Template.getAmazonS3Client() .listObjects(new ListObjectsRequest() .withBucketName(bucketName)); return objectListing.getObjectSummaries() .stream() .map(a -> new Resource<>(a, new Link(String.format("https://s3.amazonaws.com/%s/%s", a.getBucketName(), a.getKey())).withRel("url"))) .collect(Collectors.toList()); }
Example #30
Source File: ContentPropertyCollectionRestController.java From spring-content with Apache License 2.0 | 5 votes |
Resource<?> toResource(final HttpServletRequest request, Object newContent) throws SecurityException, BeansException { Link self = new Link( StringUtils.trimTrailingCharacter(request.getRequestURL().toString(), '/') + "/" + BeanUtils.getFieldWithAnnotation(newContent, ContentId.class)); Resource<?> contentResource = new Resource<Object>(newContent, Collections.singletonList(self)); return contentResource; }