List of usage examples for org.springframework.hateoas Link Link
public Link(String href)
From source file:demo.BookResourceProcessor.java
@Override public Resources<Resource<Book>> process(Resources<Resource<Book>> resource) { resource.add(new Link("/users/{username}/books/{id}").withRel("findByUserUsernameAndId")); return resource; }
From source file:za.ac.cput.project.universalhardwarestore.api.UsersPage.java
@RequestMapping(value = "/faculties", method = RequestMethod.GET) public List<UsersResource> getFaculties() { List<UsersResource> hateos = new ArrayList<>(); List<Users> users = service.getUsers(); for (Users userss : users) { UsersResource res = new UsersResource.Builder(userss.getUserName()).password(userss.getPassword()) .status(userss.getStatus()).resid(userss.getId()).build(); Link usersss = new Link("http://localhost:8080/users/" + res.getResid().toString()).withRel("depts"); res.add(usersss);/* w w w.j a va 2 s . co m*/ hateos.add(res); } return hateos; }
From source file:org.hobsoft.contacts.server.controller.ContactResourceAssemblerTest.java
@Test public void toResourceReturnsResourceWithSelfLink() { Contact contact = new Contact(); contact.setId(1L);/* w w w . ja va 2 s .c om*/ Link actual = resourceAssembler.toResource(contact).getId(); assertEquals(new Link("http://localhost/contact/1"), actual); }
From source file:org.springsource.restbucks.GeneralMvcIntegrationTest.java
/** * @see https://github.com/SpringSource/spring-hateoas/issues/54 *//*from www . j a va 2 s . c o m*/ @Test public void handsLinkHeadersIntoControllerMethod() throws Exception { Link link = new Link("/something"); mvc.perform(get("/links").header("Link", link.toString())). // andExpect(header().string("Link", link.toString())). // andExpect(content().string("Result")); }
From source file:org.hobsoft.contacts.server.controller.ContactsControllerTest.java
@Test public void createReturnsSeeOtherAndLocation() throws URISyntaxException { Contact contact = new Contact(); Resource<Contact> resource = new Resource<>(contact, new Link("x")); when(contactResourceAssembler.toResource(contact)).thenReturn(resource); ResponseEntity<Object> actual = controller.create(contact); assertEquals(HttpStatus.SEE_OTHER, actual.getStatusCode()); assertEquals(new URI("x"), actual.getHeaders().getLocation()); }
From source file:org.ow2.proactive.workflow_catalog.rest.service.WorkflowRevisionServiceTest.java
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); workflowRevisionService = Mockito.spy(workflowRevisionService); Mockito.doReturn(new Link("test")).when(workflowRevisionService).createLink(Matchers.any(Long.class), Matchers.any(Long.class), Matchers.any(WorkflowRevision.class)); Long revCnt = EXISTING_ID;/*from ww w .j a va 2s . c om*/ mockedBucket = newMockedBucket(EXISTING_ID); revisions = new TreeSet<>(); revisions.add(newWorkflowRevision(mockedBucket.getId(), revCnt++, LocalDateTime.now().minusHours(1))); revisions.add(newWorkflowRevision(mockedBucket.getId(), revCnt, LocalDateTime.now())); workflow2Rev = newMockedWorkflow(EXISTING_ID, mockedBucket, revisions, 2L); }
From source file:io.onedecision.engine.decisions.web.DecisionDmnModelController.java
@RequestMapping(value = "/", method = RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED)//from w w w .j av a 2 s .c o m public @ResponseBody DmnModel createModelForTenant(@PathVariable("tenantId") String tenantId, @RequestBody(required = false) DmnModel dmnModel, HttpServletRequest request, HttpServletResponse response, UriComponentsBuilder uriBuilder) { if (dmnModel == null) { dmnModel = DmnModel.newModel(); } // ensure no discrepancy between tenant in URL and in model dmnModel.setTenantId(tenantId); dmnModel = createModelForTenant(dmnModel); // uriBuilder.fromPath(); String url = request.getRequestURL().append(dmnModel.getShortId()).toString(); response.setHeader("Location", url); dmnModel.addLink(new Link(url)); return dmnModel; }
From source file:org.ow2.proactive.workflow_catalog.rest.service.WorkflowRevisionService.java
public Link createLink(Long bucketId, Long workflowId, WorkflowRevision workflowRevision) { ControllerLinkBuilder controllerLinkBuilder = linkTo(methodOn(WorkflowRevisionController.class) .get(bucketId, workflowId, workflowRevision.getRevisionId(), null)); // alt request parameter name and value is added manually // otherwise a converter needs to be configured // for Optional class return new Link(controllerLinkBuilder.toString() + "?alt=" + SUPPORTED_ALT_VALUE).withRel("content"); }
From source file:de.tobiasbruns.content.storage.ContentController.java
@RequestMapping(method = RequestMethod.GET, params = "projection=metadata", produces = "application/json") public @ResponseBody Resource<MetaDatum[]> loadMetadata(HttpServletRequest req, UriComponentsBuilder uriBuilder) { Link selfLink = new Link(uriBuilder.path(getPath(req)).queryParam("projection", "metadata").toUriString()); Collection<MetaDatum> metaData = service.loadMetaData(getPath(req)).getData(); return new Resource<>(metaData.toArray(new MetaDatum[metaData.size()]), selfLink); }
From source file:de.tobiasbruns.content.storage.ContentController.java
private Link currentContentSelfLink(UriComponentsBuilder uriBuilder, String path) { return new Link(uriBuilder.path(path).toUriString()).withSelfRel(); }