@Test public void toResourceShouldReturnResourceWithSelfLinkContainingResourceId() { Task model = new TaskImpl("my-identifier", "myTask", CREATED); given(converter.from(model)).willReturn(new CloudTaskImpl(model)); Resource<CloudTask> resource = resourceAssembler.toResource(model); Link selfResourceLink = resource.getLink("self"); assertThat(selfResourceLink).isNotNull(); assertThat(selfResourceLink.getHref()).contains("my-identifier"); }
@Override public Resource<CloudTask> toResource(Task task) { CloudTask cloudTask = converter.from(task); List<Link> links = new ArrayList<>(); links.add(linkTo(methodOn(TaskControllerImpl.class).getTaskById(cloudTask.getId())).withSelfRel()); if (ASSIGNED != cloudTask.getStatus()) { links.add(linkTo(methodOn(TaskControllerImpl.class).claimTask(cloudTask.getId())).withRel("claim")); } else { links.add(linkTo(methodOn(TaskControllerImpl.class).releaseTask(cloudTask.getId())).withRel("release")); links.add(linkTo(methodOn(TaskControllerImpl.class).completeTask(cloudTask.getId(), null)).withRel("complete")); } if (cloudTask.getProcessInstanceId() != null && !cloudTask.getProcessInstanceId().isEmpty()) { links.add(linkTo(methodOn(ProcessInstanceControllerImpl.class).getProcessInstanceById(cloudTask.getProcessInstanceId())).withRel("processInstance")); } if (cloudTask.getParentTaskId() != null && !cloudTask.getParentTaskId().isEmpty()) { links.add(linkTo(methodOn(TaskControllerImpl.class).getTaskById(cloudTask.getParentTaskId())).withRel("parent")); } links.add(linkTo(HomeControllerImpl.class).withRel("home")); return new Resource<>(cloudTask, links); }
TaskResourceAssembler implements ResourceAssembler<Task, Resource<CloudTask>> { @Override public Resource<CloudTask> toResource(Task task) { CloudTask cloudTask = converter.from(task); List<Link> links = new ArrayList<>(); links.add(linkTo(methodOn(TaskControllerImpl.class).getTaskById(cloudTask.getId())).withSelfRel()); if (ASSIGNED != cloudTask.getStatus()) { links.add(linkTo(methodOn(TaskControllerImpl.class).claimTask(cloudTask.getId())).withRel("claim")); } else { links.add(linkTo(methodOn(TaskControllerImpl.class).releaseTask(cloudTask.getId())).withRel("release")); links.add(linkTo(methodOn(TaskControllerImpl.class).completeTask(cloudTask.getId(), null)).withRel("complete")); } if (cloudTask.getProcessInstanceId() != null && !cloudTask.getProcessInstanceId().isEmpty()) { links.add(linkTo(methodOn(ProcessInstanceControllerImpl.class).getProcessInstanceById(cloudTask.getProcessInstanceId())).withRel("processInstance")); } if (cloudTask.getParentTaskId() != null && !cloudTask.getParentTaskId().isEmpty()) { links.add(linkTo(methodOn(TaskControllerImpl.class).getTaskById(cloudTask.getParentTaskId())).withRel("parent")); } links.add(linkTo(HomeControllerImpl.class).withRel("home")); return new Resource<>(cloudTask, links); } }
TaskResourceAssembler implements ResourceAssembler<Task, Resource<CloudTask>> { @Override public Resource<CloudTask> toResource(Task task) { CloudTask cloudTask = converter.from(task); List<Link> links = new ArrayList<>(); links.add(linkTo(methodOn(TaskControllerImpl.class).getTaskById(cloudTask.getId())).withSelfRel()); if (ASSIGNED != cloudTask.getStatus()) { links.add(linkTo(methodOn(TaskControllerImpl.class).claimTask(cloudTask.getId())).withRel("claim")); } else { links.add(linkTo(methodOn(TaskControllerImpl.class).releaseTask(cloudTask.getId())).withRel("release")); links.add(linkTo(methodOn(TaskControllerImpl.class).completeTask(cloudTask.getId(), null)).withRel("complete")); } if (cloudTask.getProcessInstanceId() != null && !cloudTask.getProcessInstanceId().isEmpty()) { links.add(linkTo(methodOn(ProcessInstanceControllerImpl.class).getProcessInstanceById(cloudTask.getProcessInstanceId())).withRel("processInstance")); } if (cloudTask.getParentTaskId() != null && !cloudTask.getParentTaskId().isEmpty()) { links.add(linkTo(methodOn(TaskControllerImpl.class).getTaskById(cloudTask.getParentTaskId())).withRel("parent")); } links.add(linkTo(HomeControllerImpl.class).withRel("home")); return new Resource<>(cloudTask, links); } TaskResourceAssembler(ToCloudTaskConverter converter); }
TaskResourceAssembler implements ResourceAssembler<Task, Resource<CloudTask>> { @Override public Resource<CloudTask> toResource(Task task) { CloudTask cloudTask = converter.from(task); List<Link> links = new ArrayList<>(); links.add(linkTo(methodOn(TaskControllerImpl.class).getTaskById(cloudTask.getId())).withSelfRel()); if (ASSIGNED != cloudTask.getStatus()) { links.add(linkTo(methodOn(TaskControllerImpl.class).claimTask(cloudTask.getId())).withRel("claim")); } else { links.add(linkTo(methodOn(TaskControllerImpl.class).releaseTask(cloudTask.getId())).withRel("release")); links.add(linkTo(methodOn(TaskControllerImpl.class).completeTask(cloudTask.getId(), null)).withRel("complete")); } if (cloudTask.getProcessInstanceId() != null && !cloudTask.getProcessInstanceId().isEmpty()) { links.add(linkTo(methodOn(ProcessInstanceControllerImpl.class).getProcessInstanceById(cloudTask.getProcessInstanceId())).withRel("processInstance")); } if (cloudTask.getParentTaskId() != null && !cloudTask.getParentTaskId().isEmpty()) { links.add(linkTo(methodOn(TaskControllerImpl.class).getTaskById(cloudTask.getParentTaskId())).withRel("parent")); } links.add(linkTo(HomeControllerImpl.class).withRel("home")); return new Resource<>(cloudTask, links); } TaskResourceAssembler(ToCloudTaskConverter converter); @Override Resource<CloudTask> toResource(Task task); }
TaskResourceAssembler implements ResourceAssembler<Task, Resource<CloudTask>> { @Override public Resource<CloudTask> toResource(Task task) { CloudTask cloudTask = converter.from(task); List<Link> links = new ArrayList<>(); links.add(linkTo(methodOn(TaskControllerImpl.class).getTaskById(cloudTask.getId())).withSelfRel()); if (ASSIGNED != cloudTask.getStatus()) { links.add(linkTo(methodOn(TaskControllerImpl.class).claimTask(cloudTask.getId())).withRel("claim")); } else { links.add(linkTo(methodOn(TaskControllerImpl.class).releaseTask(cloudTask.getId())).withRel("release")); links.add(linkTo(methodOn(TaskControllerImpl.class).completeTask(cloudTask.getId(), null)).withRel("complete")); } if (cloudTask.getProcessInstanceId() != null && !cloudTask.getProcessInstanceId().isEmpty()) { links.add(linkTo(methodOn(ProcessInstanceControllerImpl.class).getProcessInstanceById(cloudTask.getProcessInstanceId())).withRel("processInstance")); } if (cloudTask.getParentTaskId() != null && !cloudTask.getParentTaskId().isEmpty()) { links.add(linkTo(methodOn(TaskControllerImpl.class).getTaskById(cloudTask.getParentTaskId())).withRel("parent")); } links.add(linkTo(HomeControllerImpl.class).withRel("home")); return new Resource<>(cloudTask, links); } TaskResourceAssembler(ToCloudTaskConverter converter); @Override Resource<CloudTask> toResource(Task task);  }