TSK-1265: further cleanup of representationModelAssemblers

This commit is contained in:
Mustapha Zorgati 2020-06-02 05:20:10 +02:00
parent 2fc38a2b85
commit 6c4fef7635
28 changed files with 168 additions and 176 deletions

View File

@ -66,7 +66,7 @@ public class ClassificationDefinitionController {
this.classificationRepresentationModelAssembler = classificationRepresentationModelAssembler;
}
@GetMapping(path = Mapping.URL_CLASSIFICATIONDEFINITION)
@GetMapping(path = Mapping.URL_CLASSIFICATIONDEFINITIONS)
@Transactional(readOnly = true, rollbackFor = Exception.class)
public ResponseEntity<TaskanaPagedModel<ClassificationRepresentationModel>> exportClassifications(
@RequestParam(required = false) String domain) {
@ -93,7 +93,7 @@ public class ClassificationDefinitionController {
return response;
}
@PostMapping(path = Mapping.URL_CLASSIFICATIONDEFINITION)
@PostMapping(path = Mapping.URL_CLASSIFICATIONDEFINITIONS)
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<Void> importClassifications(@RequestParam("file") MultipartFile file)
throws InvalidArgumentException, NotAuthorizedException, ConcurrencyException,

View File

@ -37,15 +37,6 @@ public class ClassificationRepresentationModelAssembler
public ClassificationRepresentationModel toModel(@NonNull Classification classification) {
ClassificationRepresentationModel repModel =
new ClassificationRepresentationModel();
try {
repModel.add(
WebMvcLinkBuilder.linkTo(
methodOn(ClassificationController.class)
.getClassification(classification.getId()))
.withSelfRel());
} catch (ClassificationNotFoundException e) {
throw new SystemException("caught unexpected Exception.", e.getCause());
}
repModel.setClassificationId(classification.getId());
repModel.setApplicationEntryPoint(classification.getApplicationEntryPoint());
repModel.setCategory(classification.getCategory());
@ -69,6 +60,15 @@ public class ClassificationRepresentationModelAssembler
repModel.setCreated(classification.getCreated());
repModel.setModified(classification.getModified());
repModel.setDescription(classification.getDescription());
try {
repModel.add(
WebMvcLinkBuilder.linkTo(
methodOn(ClassificationController.class)
.getClassification(classification.getId()))
.withSelfRel());
} catch (ClassificationNotFoundException e) {
throw new SystemException("caught unexpected Exception.", e.getCause());
}
return repModel;
}

View File

@ -35,8 +35,8 @@ public class ClassificationSummaryRepresentationModelAssembler
@Override
public ClassificationSummaryRepresentationModel toModel(
@NonNull ClassificationSummary classificationSummary) {
ClassificationSummaryRepresentationModel repModel
= new ClassificationSummaryRepresentationModel();
ClassificationSummaryRepresentationModel repModel =
new ClassificationSummaryRepresentationModel();
repModel.setClassificationId(classificationSummary.getId());
repModel.setApplicationEntryPoint(classificationSummary.getApplicationEntryPoint());
repModel.setCategory(classificationSummary.getCategory());
@ -62,8 +62,8 @@ public class ClassificationSummaryRepresentationModelAssembler
public ClassificationSummary toEntityModel(ClassificationSummaryRepresentationModel repModel) {
ClassificationImpl classification =
(ClassificationImpl)
classificationService
.newClassification(repModel.getKey(), repModel.getDomain(), repModel.getType());
classificationService.newClassification(
repModel.getKey(), repModel.getDomain(), repModel.getType());
classification.setId(repModel.getClassificationId());
classification.setApplicationEntryPoint(repModel.getApplicationEntryPoint());
classification.setCategory(repModel.getCategory());
@ -88,10 +88,10 @@ public class ClassificationSummaryRepresentationModelAssembler
return CLASSIFICATIONS;
}
@PageLinks(Mapping.URL_CLASSIFICATIONS)
@Override
@PageLinks(Mapping.URL_CLASSIFICATIONS)
public TaskanaPagedModel<ClassificationSummaryRepresentationModel> toPageModel(
Iterable<? extends ClassificationSummary> entities, PageMetadata pageMetadata) {
Iterable<ClassificationSummary> entities, PageMetadata pageMetadata) {
return TaskanaPagingAssembler.super.toPageModel(entities, pageMetadata);
}
}

View File

@ -8,13 +8,13 @@ public final class Mapping {
public static final String URL_ACCESSID_GROUPS = URL_ACCESSID + "/groups";
public static final String URL_CLASSIFICATIONS = PRE + "classifications";
public static final String URL_CLASSIFICATIONS_ID = URL_CLASSIFICATIONS + "/{classificationId}";
public static final String URL_CLASSIFICATIONDEFINITION = PRE + "classification-definitions";
public static final String URL_CLASSIFICATIONDEFINITIONS = PRE + "classification-definitions";
public static final String URL_MONITOR = PRE + "monitor";
public static final String URL_MONITOR_TASKSSTATUS = URL_MONITOR + "/tasks-status-report";
public static final String URL_MONITOR_TASKSWORKBASKET = URL_MONITOR + "/tasks-workbasket-report";
public static final String URL_MONITOR_TASKSWORKBASKETPLANNED =
public static final String URL_MONITOR_TASKS_STATUS = URL_MONITOR + "/tasks-status-report";
public static final String URL_MONITOR_TASKS_WORKBASKET = URL_MONITOR + "/tasks-workbasket-report";
public static final String URL_MONITOR_TASKS_WORKBASKET_PLANNED =
URL_MONITOR + "/tasks-workbasket-planned-date-report";
public static final String URL_MONITOR_TASKSCLASSIFICATION =
public static final String URL_MONITOR_TASKS_CLASSIFICATION =
URL_MONITOR + "/tasks-classification-report";
public static final String URL_MONITOR_TIMESTAMP = URL_MONITOR + "/timestamp-report";
public static final String URL_DOMAIN = PRE + "domains";
@ -36,14 +36,14 @@ public final class Mapping {
public static final String URL_TASKS_ID_COMPLETE = URL_TASKS_ID + "/complete";
public static final String URL_TASKS_ID_TRANSFER_WORKBASKETID =
URL_TASKS_ID + "/transfer/{workbasketId}";
public static final String URL_WORKBASKETACCESSITEMS = PRE + "workbasket-access-items";
public static final String URL_WORKBASKET_ACCESS_ITEMS = PRE + "workbasket-access-items";
public static final String URL_WORKBASKET = PRE + "workbaskets";
public static final String URL_WORKBASKET_ID = URL_WORKBASKET + "/{workbasketId}";
public static final String URL_WORKBASKET_ID_ACCESSITEMS =
URL_WORKBASKET_ID + "/workbasketAccessItems";
public static final String URL_WORKBASKET_ID_DISTRIBUTION =
URL_WORKBASKET_ID + "/distribution-targets";
public static final String URL_WORKBASKETDEFINITIONS = PRE + "workbasket-definitions";
public static final String URL_WORKBASKET_DEFINITIONS = PRE + "workbasket-definitions";
private Mapping() {}
}

View File

@ -15,7 +15,7 @@ public interface TaskanaPagingAssembler<T, D extends RepresentationModel<? super
TaskanaPagedModelKeys getProperty();
default TaskanaPagedModel<D> toPageModel(
Iterable<? extends T> entities, PageMetadata pageMetadata) {
Iterable<T> entities, PageMetadata pageMetadata) {
return StreamSupport.stream(entities.spliterator(), false)
.map(this::toModel)
.collect(
@ -23,7 +23,7 @@ public interface TaskanaPagingAssembler<T, D extends RepresentationModel<? super
Collectors.toList(), l -> new TaskanaPagedModel<>(getProperty(), l, pageMetadata)));
}
default TaskanaPagedModel<D> toPageModel(Iterable<? extends T> entities) {
default TaskanaPagedModel<D> toPageModel(Iterable<T> entities) {
return toPageModel(entities, null);
}
}

View File

@ -44,7 +44,7 @@ public class MonitorController {
this.reportRepresentationModelAssembler = reportRepresentationModelAssembler;
}
@GetMapping(path = Mapping.URL_MONITOR_TASKSSTATUS)
@GetMapping(path = Mapping.URL_MONITOR_TASKS_STATUS)
@Transactional(readOnly = true, rollbackFor = Exception.class)
public ResponseEntity<ReportRepresentationModel> getTasksStatusReport(
@RequestParam(required = false) List<String> domains,
@ -68,7 +68,7 @@ public class MonitorController {
return response;
}
@GetMapping(path = Mapping.URL_MONITOR_TASKSWORKBASKET)
@GetMapping(path = Mapping.URL_MONITOR_TASKS_WORKBASKET)
@Transactional(readOnly = true, rollbackFor = Exception.class)
public ResponseEntity<ReportRepresentationModel> getTasksWorkbasketReport(
@RequestParam(value = "states") List<TaskState> states)
@ -90,7 +90,7 @@ public class MonitorController {
return ResponseEntity.status(HttpStatus.OK).body(report);
}
@GetMapping(path = Mapping.URL_MONITOR_TASKSWORKBASKETPLANNED)
@GetMapping(path = Mapping.URL_MONITOR_TASKS_WORKBASKET_PLANNED)
@Transactional(readOnly = true, rollbackFor = Exception.class)
public ResponseEntity<ReportRepresentationModel> getTasksWorkbasketPlannedDateReport(
@RequestParam(value = "daysInPast") int daysInPast,
@ -114,7 +114,7 @@ public class MonitorController {
return ResponseEntity.status(HttpStatus.OK).body(report);
}
@GetMapping(path = Mapping.URL_MONITOR_TASKSCLASSIFICATION)
@GetMapping(path = Mapping.URL_MONITOR_TASKS_CLASSIFICATION)
@Transactional(readOnly = true, rollbackFor = Exception.class)
public ResponseEntity<ReportRepresentationModel> getTasksClassificationReport()
throws NotAuthorizedException, InvalidArgumentException {

View File

@ -3,6 +3,7 @@ package pro.taskana.task.rest;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.config.EnableHypermediaSupport;
import org.springframework.hateoas.config.EnableHypermediaSupport.HypermediaType;
import org.springframework.http.HttpStatus;
@ -35,9 +36,10 @@ public class TaskCommentController {
private static final Logger LOGGER = LoggerFactory.getLogger(TaskCommentController.class);
private TaskService taskService;
private TaskCommentRepresentationModelAssembler taskCommentRepresentationModelAssembler;
private final TaskService taskService;
private final TaskCommentRepresentationModelAssembler taskCommentRepresentationModelAssembler;
@Autowired
TaskCommentController(
TaskService taskService,
TaskCommentRepresentationModelAssembler taskCommentRepresentationModelAssembler) {

View File

@ -53,11 +53,7 @@ public class AttachmentRepresentationModelAssembler
return repModel;
}
public List<Attachment> toAttachmentList(List<AttachmentRepresentationModel> resources) {
return resources.stream().map(this::toEntityModel).collect(Collectors.toList());
}
private AttachmentImpl toEntityModel(
public AttachmentImpl toEntityModel(
AttachmentRepresentationModel attachmentRepresentationModel) {
AttachmentImpl attachment = (AttachmentImpl) taskService.newAttachment();
attachment.setId(attachmentRepresentationModel.getAttachmentId());

View File

@ -4,7 +4,6 @@ import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
import static pro.taskana.common.rest.models.TaskanaPagedModelKeys.TASK_COMMENTS;
import java.time.Instant;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
@ -15,7 +14,9 @@ import org.springframework.stereotype.Component;
import pro.taskana.common.api.exceptions.SystemException;
import pro.taskana.common.rest.Mapping;
import pro.taskana.common.rest.assembler.TaskanaPagingAssembler;
import pro.taskana.common.rest.models.TaskanaPagedModel;
import pro.taskana.common.rest.models.TaskanaPagedModelKeys;
import pro.taskana.resource.rest.PageLinks;
import pro.taskana.task.api.TaskService;
import pro.taskana.task.api.models.TaskComment;
@ -26,7 +27,7 @@ import pro.taskana.task.rest.models.TaskCommentRepresentationModel;
/** EntityModel assembler for {@link TaskCommentRepresentationModel}. */
@Component
public class TaskCommentRepresentationModelAssembler
implements RepresentationModelAssembler<TaskComment, TaskCommentRepresentationModel> {
implements TaskanaPagingAssembler<TaskComment, TaskCommentRepresentationModel> {
private final TaskService taskService;
@ -38,14 +39,13 @@ public class TaskCommentRepresentationModelAssembler
@NonNull
@Override
public TaskCommentRepresentationModel toModel(@NonNull TaskComment taskComment) {
TaskCommentRepresentationModel repModel =
new TaskCommentRepresentationModel();
TaskCommentRepresentationModel repModel = new TaskCommentRepresentationModel();
repModel.setTaskCommentId(taskComment.getId());
repModel.setTaskId(taskComment.getTaskId());
repModel.setTextField(taskComment.getTextField());
repModel.setCreator(taskComment.getCreator());
repModel.setCreated(taskComment.getCreated().toString());
repModel.setModified(taskComment.getModified().toString());
repModel.setCreated(taskComment.getCreated());
repModel.setModified(taskComment.getModified());
try {
repModel.add(
linkTo(methodOn(TaskCommentController.class).getTaskComment(taskComment.getId()))
@ -57,29 +57,25 @@ public class TaskCommentRepresentationModelAssembler
}
public TaskComment toEntityModel(TaskCommentRepresentationModel repModel) {
TaskCommentImpl taskComment =
(TaskCommentImpl) taskService.newTaskComment(repModel.getTaskId());
taskComment.setId(repModel.getTaskCommentId());
taskComment.setTextField(repModel.getTextField());
taskComment.setCreator(repModel.getCreator());
if (repModel.getCreated() != null) {
taskComment.setCreated(Instant.parse(repModel.getCreated()));
}
if (repModel.getModified() != null) {
taskComment.setModified(Instant.parse(repModel.getModified()));
}
taskComment.setCreated(repModel.getCreated());
taskComment.setModified(repModel.getModified());
return taskComment;
}
@Override
@PageLinks(Mapping.URL_TASK_COMMENTS)
public TaskanaPagedModel<TaskCommentRepresentationModel> toPageModel(
List<TaskComment> taskComments, PageMetadata pageMetadata) {
return taskComments.stream()
.map(this::toModel)
.collect(
Collectors.collectingAndThen(
Collectors.toList(),
list -> new TaskanaPagedModel<>(TASK_COMMENTS, list, pageMetadata)));
Iterable<TaskComment> taskComments, PageMetadata pageMetadata) {
return TaskanaPagingAssembler.super.toPageModel(taskComments, pageMetadata);
}
@Override
public TaskanaPagedModelKeys getProperty() {
return TASK_COMMENTS;
}
}

View File

@ -11,11 +11,8 @@ import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;
import pro.taskana.classification.rest.assembler.ClassificationSummaryRepresentationModelAssembler;
import pro.taskana.common.api.exceptions.InvalidArgumentException;
import pro.taskana.common.api.exceptions.NotAuthorizedException;
import pro.taskana.common.api.exceptions.SystemException;
import pro.taskana.task.api.TaskService;
import pro.taskana.task.api.exceptions.TaskNotFoundException;
import pro.taskana.task.api.models.Task;
import pro.taskana.task.internal.models.TaskImpl;
import pro.taskana.task.rest.TaskController;
@ -23,20 +20,14 @@ import pro.taskana.task.rest.models.TaskRepresentationModel;
import pro.taskana.task.rest.models.TaskRepresentationModel.CustomAttribute;
import pro.taskana.workbasket.rest.assembler.WorkbasketSummaryRepresentationModelAssembler;
/**
* EntityModel assembler for {@link TaskRepresentationModel}.
*/
/** EntityModel assembler for {@link TaskRepresentationModel}. */
@Component
public class TaskRepresentationModelAssembler
implements RepresentationModelAssembler<Task, TaskRepresentationModel> {
private final TaskService taskService;
private final ClassificationSummaryRepresentationModelAssembler classificationAssembler;
private final WorkbasketSummaryRepresentationModelAssembler
workbasketAssembler;
private final WorkbasketSummaryRepresentationModelAssembler workbasketAssembler;
private final AttachmentRepresentationModelAssembler attachmentAssembler;
@Autowired
@ -47,8 +38,7 @@ public class TaskRepresentationModelAssembler
AttachmentRepresentationModelAssembler attachmentAssembler) {
this.taskService = taskService;
this.classificationAssembler = classificationAssembler;
this.workbasketAssembler
= workbasketAssembler;
this.workbasketAssembler = workbasketAssembler;
this.attachmentAssembler = attachmentAssembler;
}
@ -85,14 +75,13 @@ public class TaskRepresentationModelAssembler
.collect(Collectors.toList()));
repModel.setCustomAttributes(
task.getCustomAttributes().entrySet().stream()
.map(e -> new TaskRepresentationModel.CustomAttribute(e.getKey(), e.getValue()))
.map(CustomAttribute::of)
.collect(Collectors.toList()));
repModel.setCallbackInfo(
task.getCallbackInfo().entrySet().stream()
.map(e -> new TaskRepresentationModel.CustomAttribute(e.getKey(), e.getValue()))
.map(CustomAttribute::of)
.collect(Collectors.toList()));
try {
repModel.add(linkTo(methodOn(TaskController.class).getTask(task.getId())).withSelfRel());
repModel.setCustom1(task.getCustomAttribute("1"));
repModel.setCustom2(task.getCustomAttribute("2"));
repModel.setCustom3(task.getCustomAttribute("3"));
@ -109,15 +98,16 @@ public class TaskRepresentationModelAssembler
repModel.setCustom14(task.getCustomAttribute("14"));
repModel.setCustom15(task.getCustomAttribute("15"));
repModel.setCustom16(task.getCustomAttribute("16"));
} catch (InvalidArgumentException | TaskNotFoundException | NotAuthorizedException e) {
repModel.add(linkTo(methodOn(TaskController.class).getTask(task.getId())).withSelfRel());
} catch (Exception e) {
throw new SystemException("caught unexpected Exception.", e.getCause());
}
return repModel;
}
public Task toEntityModel(TaskRepresentationModel repModel) {
TaskImpl task = (TaskImpl) taskService
.newTask(repModel.getWorkbasketSummary().getWorkbasketId());
TaskImpl task =
(TaskImpl) taskService.newTask(repModel.getWorkbasketSummary().getWorkbasketId());
task.setId(repModel.getTaskId());
task.setExternalId(repModel.getExternalId());
task.setCreated(repModel.getCreated());
@ -134,8 +124,7 @@ public class TaskRepresentationModelAssembler
task.setState(repModel.getState());
task.setClassificationSummary(
classificationAssembler.toEntityModel(repModel.getClassificationSummary()));
task
.setWorkbasketSummary(workbasketAssembler.toEntityModel(repModel.getWorkbasketSummary()));
task.setWorkbasketSummary(workbasketAssembler.toEntityModel(repModel.getWorkbasketSummary()));
task.setBusinessProcessId(repModel.getBusinessProcessId());
task.setParentBusinessProcessId(repModel.getParentBusinessProcessId());
task.setOwner(repModel.getOwner());
@ -158,7 +147,10 @@ public class TaskRepresentationModelAssembler
task.setCustom14(repModel.getCustom14());
task.setCustom15(repModel.getCustom15());
task.setCustom16(repModel.getCustom16());
task.setAttachments(attachmentAssembler.toAttachmentList(repModel.getAttachments()));
task.setAttachments(
repModel.getAttachments().stream()
.map(attachmentAssembler::toEntityModel)
.collect(Collectors.toList()));
task.setCustomAttributes(
repModel.getCustomAttributes().stream()
.filter(e -> Objects.nonNull(e.getKey()) && !e.getKey().isEmpty())

View File

@ -6,7 +6,6 @@ import java.util.List;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.PagedModel.PageMetadata;
import org.springframework.hateoas.server.RepresentationModelAssembler;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;
@ -14,7 +13,9 @@ import pro.taskana.classification.rest.assembler.ClassificationSummaryRepresenta
import pro.taskana.common.api.exceptions.InvalidArgumentException;
import pro.taskana.common.api.exceptions.SystemException;
import pro.taskana.common.rest.Mapping;
import pro.taskana.common.rest.assembler.TaskanaPagingAssembler;
import pro.taskana.common.rest.models.TaskanaPagedModel;
import pro.taskana.common.rest.models.TaskanaPagedModelKeys;
import pro.taskana.resource.rest.PageLinks;
import pro.taskana.task.api.TaskService;
import pro.taskana.task.api.models.TaskSummary;
@ -22,12 +23,10 @@ import pro.taskana.task.internal.models.TaskImpl;
import pro.taskana.task.rest.models.TaskSummaryRepresentationModel;
import pro.taskana.workbasket.rest.assembler.WorkbasketSummaryRepresentationModelAssembler;
/**
* EntityModel assembler for {@link TaskSummaryRepresentationModel}.
*/
/** EntityModel assembler for {@link TaskSummaryRepresentationModel}. */
@Component
public class TaskSummaryRepresentationModelAssembler
implements RepresentationModelAssembler<TaskSummary, TaskSummaryRepresentationModel> {
implements TaskanaPagingAssembler<TaskSummary, TaskSummaryRepresentationModel> {
private final ClassificationSummaryRepresentationModelAssembler classificationAssembler;
private final WorkbasketSummaryRepresentationModelAssembler workbasketAssembler;
@ -118,8 +117,8 @@ public class TaskSummaryRepresentationModelAssembler
taskSummary.setState(repModel.getState());
taskSummary.setClassificationSummary(
classificationAssembler.toEntityModel(repModel.getClassificationSummary()));
taskSummary
.setWorkbasketSummary(workbasketAssembler.toEntityModel(repModel.getWorkbasketSummary()));
taskSummary.setWorkbasketSummary(
workbasketAssembler.toEntityModel(repModel.getWorkbasketSummary()));
taskSummary.setBusinessProcessId(repModel.getBusinessProcessId());
taskSummary.setParentBusinessProcessId(repModel.getParentBusinessProcessId());
taskSummary.setOwner(repModel.getOwner());
@ -152,11 +151,11 @@ public class TaskSummaryRepresentationModelAssembler
@PageLinks(Mapping.URL_TASKS)
public TaskanaPagedModel<TaskSummaryRepresentationModel> toPageModel(
List<TaskSummary> taskSummaries, PageMetadata pageMetadata) {
return taskSummaries.stream()
.map(this::toModel)
.collect(
Collectors.collectingAndThen(
Collectors.toList(),
list -> new TaskanaPagedModel<>(TASKS, list, pageMetadata)));
return TaskanaPagingAssembler.super.toPageModel(taskSummaries, pageMetadata);
}
@Override
public TaskanaPagedModelKeys getProperty() {
return TASKS;
}
}

View File

@ -1,5 +1,6 @@
package pro.taskana.task.rest.models;
import java.time.Instant;
import org.springframework.hateoas.RepresentationModel;
import pro.taskana.task.api.models.TaskComment;
@ -12,15 +13,15 @@ public class TaskCommentRepresentationModel
private String taskId;
private String textField;
private String creator;
private String created;
private String modified;
private Instant created;
private Instant modified;
public String getTaskCommentId() {
return taskCommentId;
}
public void setTaskCommentId(String id) {
this.taskCommentId = id;
public void setTaskCommentId(String taskCommentId) {
this.taskCommentId = taskCommentId;
}
public String getTaskId() {
@ -31,14 +32,6 @@ public class TaskCommentRepresentationModel
this.taskId = taskId;
}
public String getCreator() {
return creator;
}
public void setCreator(String creator) {
this.creator = creator;
}
public String getTextField() {
return textField;
}
@ -47,20 +40,27 @@ public class TaskCommentRepresentationModel
this.textField = textField;
}
public String getCreated() {
public String getCreator() {
return creator;
}
public void setCreator(String creator) {
this.creator = creator;
}
public Instant getCreated() {
return created;
}
public void setCreated(String created) {
public void setCreated(Instant created) {
this.created = created;
}
public String getModified() {
public Instant getModified() {
return modified;
}
public void setModified(String modified) {
public void setModified(Instant modified) {
this.modified = modified;
}
}

View File

@ -4,17 +4,15 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map.Entry;
import pro.taskana.task.api.models.Task;
import pro.taskana.task.rest.assembler.AttachmentRepresentationModelAssembler;
/**
* EntityModel class for {@link Task}.
*/
/** EntityModel class for {@link Task}. */
@JsonIgnoreProperties("attachmentSummaries")
public class TaskRepresentationModel extends TaskSummaryRepresentationModel {
protected AttachmentRepresentationModelAssembler attachmentAssembler;
// All objects have to be serializable
private List<CustomAttribute> customAttributes = Collections.emptyList();
@ -51,27 +49,34 @@ public class TaskRepresentationModel extends TaskSummaryRepresentationModel {
*/
public static class CustomAttribute {
private final String key;
private final String value;
private String key;
private String value;
@SuppressWarnings("unused")
public CustomAttribute() {
this(null, null);
// necessary for jackson.
public static CustomAttribute of(Entry<String, String> entry) {
return of(entry.getKey(), entry.getValue());
}
public CustomAttribute(String key, String value) {
this.key = key;
this.value = value;
public static CustomAttribute of (String key, String value) {
CustomAttribute customAttribute = new CustomAttribute();
customAttribute.setKey(key);
customAttribute.setValue(value);
return customAttribute;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
}

View File

@ -72,7 +72,7 @@ public class WorkbasketAccessItemController extends AbstractPagingController {
* @throws NotAuthorizedException if the user is not authorized.
* @throws InvalidArgumentException if some argument is invalid.
*/
@GetMapping(path = Mapping.URL_WORKBASKETACCESSITEMS)
@GetMapping(path = Mapping.URL_WORKBASKET_ACCESS_ITEMS)
public ResponseEntity<TaskanaPagedModel<WorkbasketAccessItemRepresentationModel>>
getWorkbasketAccessItems(
@RequestParam MultiValueMap<String, String> params)
@ -110,7 +110,7 @@ public class WorkbasketAccessItemController extends AbstractPagingController {
* @throws NotAuthorizedException if the user is not authorized.
* @throws InvalidArgumentException if some argument is invalid.
*/
@DeleteMapping(path = Mapping.URL_WORKBASKETACCESSITEMS)
@DeleteMapping(path = Mapping.URL_WORKBASKET_ACCESS_ITEMS)
public ResponseEntity<Void> removeWorkbasketAccessItems(
@RequestParam("access-id") String accessId)
throws NotAuthorizedException, InvalidArgumentException {

View File

@ -73,7 +73,7 @@ public class WorkbasketDefinitionController {
this.mapper = mapper;
}
@GetMapping(path = Mapping.URL_WORKBASKETDEFINITIONS)
@GetMapping(path = Mapping.URL_WORKBASKET_DEFINITIONS)
@Transactional(readOnly = true, rollbackFor = Exception.class)
public ResponseEntity<TaskanaPagedModel<WorkbasketDefinitionRepresentationModel>>
exportWorkbaskets(@RequestParam(required = false) String domain) {
@ -122,7 +122,7 @@ public class WorkbasketDefinitionController {
* workbasket and access_id already exists.
* @throws ConcurrencyException if workbasket was updated by an other user
*/
@PostMapping(path = Mapping.URL_WORKBASKETDEFINITIONS)
@PostMapping(path = Mapping.URL_WORKBASKET_DEFINITIONS)
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<Void> importWorkbaskets(@RequestParam("file") MultipartFile file)
throws IOException, NotAuthorizedException, DomainNotFoundException,

View File

@ -115,7 +115,7 @@ public class WorkbasketAccessItemRepresentationModelAssembler
return pageModel;
}
@PageLinks(Mapping.URL_WORKBASKETACCESSITEMS)
@PageLinks(Mapping.URL_WORKBASKET_ACCESS_ITEMS)
public TaskanaPagedModel<WorkbasketAccessItemRepresentationModel> toPageModel(
List<WorkbasketAccessItem> workbasketAccessItems, PageMetadata pageMetadata) {
return workbasketAccessItems.stream()

View File

@ -34,16 +34,14 @@ public class WorkbasketDefinitionRepresentationModelAssembler
private final WorkbasketService workbasketService;
@Autowired
public WorkbasketDefinitionRepresentationModelAssembler(WorkbasketService workbasketService,
WorkbasketRepresentationModelAssembler workbasketAssembler
) {
public WorkbasketDefinitionRepresentationModelAssembler(WorkbasketService workbasketService) {
this.workbasketService = workbasketService;
}
@NonNull
public WorkbasketDefinitionRepresentationModel toModel(@NonNull Workbasket workbasket) {
WorkbasketRepresentationModelWithoutLinks basket
= new WorkbasketRepresentationModelWithoutLinks();
WorkbasketRepresentationModelWithoutLinks basket =
new WorkbasketRepresentationModelWithoutLinks();
basket.setKey(workbasket.getKey());
basket.setModified(workbasket.getModified());
@ -64,7 +62,7 @@ public class WorkbasketDefinitionRepresentationModelAssembler
basket.setOrgLevel4(workbasket.getOrgLevel4());
List<WorkbasketAccessItemImpl> authorizations = new ArrayList<>();
Set<String> distroTargets = null;
Set<String> distroTargets;
try {
for (WorkbasketAccessItem accessItem :
workbasketService.getWorkbasketAccessItems(basket.getWorkbasketId())) {
@ -78,8 +76,8 @@ public class WorkbasketDefinitionRepresentationModelAssembler
throw new SystemException("Caught Exception", e);
}
WorkbasketDefinitionRepresentationModel repModel
= new WorkbasketDefinitionRepresentationModel();
WorkbasketDefinitionRepresentationModel repModel =
new WorkbasketDefinitionRepresentationModel();
repModel.setWorkbasket(basket);
repModel.setAuthorizations(authorizations);
@ -89,8 +87,7 @@ public class WorkbasketDefinitionRepresentationModelAssembler
public Workbasket toEntityModel(WorkbasketRepresentationModel repModel) {
WorkbasketImpl workbasket =
(WorkbasketImpl)
workbasketService.newWorkbasket(repModel.getKey(), repModel.getDomain());
(WorkbasketImpl) workbasketService.newWorkbasket(repModel.getKey(), repModel.getDomain());
workbasket.setId(repModel.getWorkbasketId());
workbasket.setName(repModel.getName());
workbasket.setType(repModel.getType());

View File

@ -2,6 +2,7 @@ package pro.taskana.workbasket.rest.assembler;
import static pro.taskana.common.rest.models.TaskanaPagedModelKeys.DISTRIBUTION_TARGETS;
import static pro.taskana.common.rest.models.TaskanaPagedModelKeys.WORKBASKETS;
import static pro.taskana.common.rest.models.TaskanaPagedModelKeys.WORKBASKET_DEFINITIONS;
import java.util.List;
import java.util.stream.Collectors;
@ -12,7 +13,9 @@ import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;
import pro.taskana.common.rest.Mapping;
import pro.taskana.common.rest.assembler.TaskanaPagingAssembler;
import pro.taskana.common.rest.models.TaskanaPagedModel;
import pro.taskana.common.rest.models.TaskanaPagedModelKeys;
import pro.taskana.resource.rest.PageLinks;
import pro.taskana.workbasket.api.WorkbasketService;
import pro.taskana.workbasket.api.models.WorkbasketSummary;
@ -24,7 +27,7 @@ import pro.taskana.workbasket.rest.models.WorkbasketSummaryRepresentationModel;
*/
@Component
public class WorkbasketSummaryRepresentationModelAssembler implements
RepresentationModelAssembler<WorkbasketSummary, WorkbasketSummaryRepresentationModel> {
TaskanaPagingAssembler<WorkbasketSummary, WorkbasketSummaryRepresentationModel> {
private WorkbasketService workbasketService;
@ -80,15 +83,16 @@ public class WorkbasketSummaryRepresentationModelAssembler implements
return workbasket;
}
@Override
@PageLinks(Mapping.URL_WORKBASKET)
public TaskanaPagedModel<WorkbasketSummaryRepresentationModel> toPageModel(
List<WorkbasketSummary> workbasketSummaries, PageMetadata pageMetadata) {
return workbasketSummaries.stream()
.map(this::toModel)
.collect(
Collectors.collectingAndThen(
Collectors.toList(),
list -> new TaskanaPagedModel<>(WORKBASKETS, list, pageMetadata)));
Iterable<WorkbasketSummary> entities, PageMetadata pageMetadata) {
return TaskanaPagingAssembler.super.toPageModel(entities, pageMetadata);
}
@Override
public TaskanaPagedModelKeys getProperty() {
return WORKBASKETS;
}
@PageLinks(Mapping.URL_WORKBASKET_ID_DISTRIBUTION)

View File

@ -79,7 +79,7 @@ class ClassificationDefinitionControllerIntTest {
void testExportClassifications() {
ResponseEntity<TaskanaPagedModel<ClassificationRepresentationModel>> response =
template.exchange(
restHelper.toUrl(Mapping.URL_CLASSIFICATIONDEFINITION) + "?domain=DOMAIN_B",
restHelper.toUrl(Mapping.URL_CLASSIFICATIONDEFINITIONS) + "?domain=DOMAIN_B",
HttpMethod.GET,
restHelper.defaultRequest(),
CLASSIFICATION_PAGE_MODEL_TYPE);
@ -99,7 +99,7 @@ class ClassificationDefinitionControllerIntTest {
void testExportClassificationsFromWrongDomain() {
ResponseEntity<TaskanaPagedModel<ClassificationRepresentationModel>> response =
template.exchange(
restHelper.toUrl(Mapping.URL_CLASSIFICATIONDEFINITION) + "?domain=ADdfe",
restHelper.toUrl(Mapping.URL_CLASSIFICATIONDEFINITIONS) + "?domain=ADdfe",
HttpMethod.GET,
restHelper.defaultRequest(),
CLASSIFICATION_PAGE_MODEL_TYPE);
@ -444,7 +444,7 @@ class ClassificationDefinitionControllerIntTest {
body.add("file", new FileSystemResource(tmpFile));
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
String serverUrl = restHelper.toUrl(Mapping.URL_CLASSIFICATIONDEFINITION);
String serverUrl = restHelper.toUrl(Mapping.URL_CLASSIFICATIONDEFINITIONS);
return template.postForEntity(serverUrl, requestEntity, Void.class);
}

View File

@ -37,7 +37,7 @@ class ClassificationDefinitionControllerRestDocumentation extends BaseRestDocume
this.mockMvc
.perform(
RestDocumentationRequestBuilders.get(
restHelper.toUrl(Mapping.URL_CLASSIFICATIONDEFINITION))
restHelper.toUrl(Mapping.URL_CLASSIFICATIONDEFINITIONS))
.accept("application/json")
.header("Authorization", "Basic dGVhbWxlYWRfMTp0ZWFtbGVhZF8x"))
.andExpect(MockMvcResultMatchers.status().isOk())
@ -54,7 +54,7 @@ class ClassificationDefinitionControllerRestDocumentation extends BaseRestDocume
this.mockMvc
.perform(
multipart(restHelper.toUrl(Mapping.URL_CLASSIFICATIONDEFINITION))
multipart(restHelper.toUrl(Mapping.URL_CLASSIFICATIONDEFINITIONS))
.file("file", definitionString.getBytes(UTF_8))
.header("Authorization", "Basic dGVhbWxlYWRfMTp0ZWFtbGVhZF8x"))
.andExpect(MockMvcResultMatchers.status().isNoContent())

View File

@ -52,7 +52,7 @@ class MonitorControllerRestDocumentation extends BaseRestDocumentation {
void getTaskStatusReport() throws Exception {
this.mockMvc
.perform(
RestDocumentationRequestBuilders.get(restHelper.toUrl(Mapping.URL_MONITOR_TASKSSTATUS))
RestDocumentationRequestBuilders.get(restHelper.toUrl(Mapping.URL_MONITOR_TASKS_STATUS))
.header("Authorization", "Basic YWRtaW46YWRtaW4="))
.andExpect(MockMvcResultMatchers.status().isOk())
.andDo(
@ -65,7 +65,7 @@ class MonitorControllerRestDocumentation extends BaseRestDocumentation {
this.mockMvc
.perform(
RestDocumentationRequestBuilders.get(
restHelper.toUrl(Mapping.URL_MONITOR_TASKSWORKBASKET)
restHelper.toUrl(Mapping.URL_MONITOR_TASKS_WORKBASKET)
+ "?daysInPast=4&states=READY,CLAIMED,COMPLETED")
.accept("application/hal+json")
.header("Authorization", "Basic YWRtaW46YWRtaW4="))
@ -80,7 +80,7 @@ class MonitorControllerRestDocumentation extends BaseRestDocumentation {
this.mockMvc
.perform(
RestDocumentationRequestBuilders.get(
restHelper.toUrl(Mapping.URL_MONITOR_TASKSCLASSIFICATION))
restHelper.toUrl(Mapping.URL_MONITOR_TASKS_CLASSIFICATION))
.accept("application/hal+json")
.header("Authorization", "Basic YWRtaW46YWRtaW4="))
.andExpect(MockMvcResultMatchers.status().isOk())

View File

@ -113,7 +113,7 @@ class WorkbasketAccessItemControllerRestDocumentation extends BaseRestDocumentat
this.mockMvc
.perform(
RestDocumentationRequestBuilders.get(
restHelper.toUrl(Mapping.URL_WORKBASKETACCESSITEMS)
restHelper.toUrl(Mapping.URL_WORKBASKET_ACCESS_ITEMS)
+ "?sort-by=workbasket-key&order=asc&access-ids=user_2_2")
.accept("application/hal+json")
.header("Authorization", "Basic dGVhbWxlYWRfMTp0ZWFtbGVhZF8x"))
@ -129,7 +129,7 @@ class WorkbasketAccessItemControllerRestDocumentation extends BaseRestDocumentat
this.mockMvc
.perform(
RestDocumentationRequestBuilders.delete(
restHelper.toUrl(Mapping.URL_WORKBASKETACCESSITEMS) + "?access-id=user_2_2")
restHelper.toUrl(Mapping.URL_WORKBASKET_ACCESS_ITEMS) + "?access-id=user_2_2")
.header("Authorization", "Basic dGVhbWxlYWRfMTp0ZWFtbGVhZF8x"))
.andExpect(MockMvcResultMatchers.status().isNoContent())
.andDo(MockMvcRestDocumentation.document("RemoveWorkbasketAccessItemsDocTest"));

View File

@ -39,7 +39,7 @@ class WorkbasketDefinitionControllerRestDocumentation extends BaseRestDocumentat
this.mockMvc
.perform(
RestDocumentationRequestBuilders
.get(restHelper.toUrl(Mapping.URL_WORKBASKETDEFINITIONS))
.get(restHelper.toUrl(Mapping.URL_WORKBASKET_DEFINITIONS))
.accept("application/json")
.header("Authorization", "Basic dGVhbWxlYWRfMTp0ZWFtbGVhZF8x"))
.andExpect(MockMvcResultMatchers.status().isOk())
@ -64,7 +64,7 @@ class WorkbasketDefinitionControllerRestDocumentation extends BaseRestDocumentat
this.mockMvc
.perform(
multipart(restHelper.toUrl(Mapping.URL_WORKBASKETDEFINITIONS))
multipart(restHelper.toUrl(Mapping.URL_WORKBASKET_DEFINITIONS))
.file("file", definitionString.getBytes(UTF_8))
.header("Authorization", "Basic dGVhbWxlYWRfMTp0ZWFtbGVhZF8x"))
.andExpect(MockMvcResultMatchers.status().isNoContent())

View File

@ -160,13 +160,13 @@ class TaskCommentControllerIntTest {
HttpMethod.GET,
new HttpEntity<String>(restHelper.getHeadersAdmin()),
ParameterizedTypeReference.forType(TaskCommentRepresentationModel.class));
assertThat(getTaskCommentResponse.getBody().getLink(IanaLinkRelations.SELF)).isNotNull();
assertThat(getTaskCommentResponse.getBody().getCreator()).isEqualTo("user_1_1");
assertThat(getTaskCommentResponse.getBody().getTextField()).isEqualTo("some text in textfield");
assertThat(getTaskCommentResponse.getBody()).isNotNull();
TaskCommentRepresentationModel taskCommentToUpdate = getTaskCommentResponse.getBody();
assertThat(taskCommentToUpdate.getLink(IanaLinkRelations.SELF)).isNotNull();
assertThat(taskCommentToUpdate.getCreator()).isEqualTo("user_1_1");
assertThat(taskCommentToUpdate.getTextField()).isEqualTo("some text in textfield");
TaskCommentRepresentationModel taskCommentRepresentationModelToUpdate =
getTaskCommentResponse.getBody();
taskCommentRepresentationModelToUpdate.setModified(Instant.now().toString());
taskCommentToUpdate.setModified(Instant.now());
ThrowingCallable httpCall =
() -> {
@ -174,7 +174,7 @@ class TaskCommentControllerIntTest {
url,
HttpMethod.PUT,
new HttpEntity<>(
taskCommentRepresentationModelToUpdate,
taskCommentToUpdate,
restHelper.getHeadersUser_1_1()),
ParameterizedTypeReference.forType(TaskCommentRepresentationModel.class));
};

View File

@ -54,8 +54,8 @@ class TaskCommentRepresentationModelAssemblerTest {
taskCommentRepresentationModel.setTaskId("TKI:000000000000000000000000000000000000");
taskCommentRepresentationModel.setTaskCommentId("TCI:000000000000000000000000000000000000");
taskCommentRepresentationModel.setCreator("user_1_1");
taskCommentRepresentationModel.setCreated("2010-01-01T12:00:00Z");
taskCommentRepresentationModel.setModified("2011-11-11T11:00:00Z");
taskCommentRepresentationModel.setCreated(Instant.parse("2010-01-01T12:00:00Z"));
taskCommentRepresentationModel.setModified(Instant.parse("2011-11-11T11:00:00Z"));
TaskComment taskComment =
taskCommentRepresentationModelAssembler.toEntityModel(taskCommentRepresentationModel);

View File

@ -6,6 +6,7 @@ import java.time.Instant;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
@ -89,9 +90,9 @@ class TaskRepresentationModelAssemberTest {
resource.setRead(true);
resource.setTransferred(true);
resource.setCustomAttributes(
Collections.singletonList(new TaskRepresentationModel.CustomAttribute("abc", "def")));
Collections.singletonList(TaskRepresentationModel.CustomAttribute.of("abc", "def")));
resource.setCallbackInfo(
Collections.singletonList(new TaskRepresentationModel.CustomAttribute("ghi", "jkl")));
Collections.singletonList(TaskRepresentationModel.CustomAttribute.of("ghi", "jkl")));
resource.setAttachments(Collections.singletonList(attachement));
resource.setCustom1("custom1");
resource.setCustom2("custom2");

View File

@ -45,7 +45,7 @@ class WorkbasketAccessItemControllerIntTest {
void testGetAllWorkbasketAccessItems() {
ResponseEntity<TaskanaPagedModel<WorkbasketAccessItemRepresentationModel>> response =
template.exchange(
restHelper.toUrl(Mapping.URL_WORKBASKETACCESSITEMS),
restHelper.toUrl(Mapping.URL_WORKBASKET_ACCESS_ITEMS),
HttpMethod.GET,
restHelper.defaultRequest(),
WORKBASKET_ACCESS_ITEM_PAGE_MODEL_TYPE);
@ -58,7 +58,7 @@ class WorkbasketAccessItemControllerIntTest {
String parameters = "?sort-by=workbasket-key&order=asc&page-size=9&access-ids=user_1_1&page=1";
ResponseEntity<TaskanaPagedModel<WorkbasketAccessItemRepresentationModel>> response =
template.exchange(
restHelper.toUrl(Mapping.URL_WORKBASKETACCESSITEMS) + parameters,
restHelper.toUrl(Mapping.URL_WORKBASKET_ACCESS_ITEMS) + parameters,
HttpMethod.GET,
restHelper.defaultRequest(),
WORKBASKET_ACCESS_ITEM_PAGE_MODEL_TYPE);
@ -77,7 +77,7 @@ class WorkbasketAccessItemControllerIntTest {
void testThrowsExceptionIfInvalidFilterIsUsed() {
ThrowingCallable httpCall =
() -> template.exchange(
restHelper.toUrl(Mapping.URL_WORKBASKETACCESSITEMS)
restHelper.toUrl(Mapping.URL_WORKBASKET_ACCESS_ITEMS)
+ "?sort-by=workbasket-key&order=asc&page=1&page-size=9&invalid=user_1_1",
HttpMethod.GET,
restHelper.defaultRequest(),
@ -94,7 +94,7 @@ class WorkbasketAccessItemControllerIntTest {
String parameters = "?sort-by=workbasket-key&order=asc&page-size=9&access-ids=user_1_1&page=1";
ResponseEntity<TaskanaPagedModel<WorkbasketAccessItemRepresentationModel>> response =
template.exchange(
restHelper.toUrl(Mapping.URL_WORKBASKETACCESSITEMS) + parameters,
restHelper.toUrl(Mapping.URL_WORKBASKET_ACCESS_ITEMS) + parameters,
HttpMethod.GET,
restHelper.defaultRequest(),
WORKBASKET_ACCESS_ITEM_PAGE_MODEL_TYPE);
@ -124,7 +124,7 @@ class WorkbasketAccessItemControllerIntTest {
String parameters = "?access-id=user_1_1";
ResponseEntity<Void> response =
template.exchange(
restHelper.toUrl(Mapping.URL_WORKBASKETACCESSITEMS) + parameters,
restHelper.toUrl(Mapping.URL_WORKBASKET_ACCESS_ITEMS) + parameters,
HttpMethod.DELETE,
restHelper.defaultRequest(),
ParameterizedTypeReference.forType(Void.class));
@ -137,7 +137,7 @@ class WorkbasketAccessItemControllerIntTest {
String parameters = "?access-id=cn=DevelopersGroup,ou=groups,o=TaskanaTest";
ThrowingCallable httpCall =
() -> template.exchange(
restHelper.toUrl(Mapping.URL_WORKBASKETACCESSITEMS) + parameters,
restHelper.toUrl(Mapping.URL_WORKBASKET_ACCESS_ITEMS) + parameters,
HttpMethod.DELETE,
restHelper.defaultRequest(),
ParameterizedTypeReference.forType(Void.class));

View File

@ -261,7 +261,7 @@ class WorkbasketDefinitionControllerIntTest {
private ResponseEntity<TaskanaPagedModel<WorkbasketDefinitionRepresentationModel>>
executeExportRequestForDomain(String domain) {
return TEMPLATE.exchange(
restHelper.toUrl(Mapping.URL_WORKBASKETDEFINITIONS) + "?domain=" + domain,
restHelper.toUrl(Mapping.URL_WORKBASKET_DEFINITIONS) + "?domain=" + domain,
HttpMethod.GET,
restHelper.defaultRequest(),
new ParameterizedTypeReference<TaskanaPagedModel<WorkbasketDefinitionRepresentationModel>>(
@ -292,7 +292,7 @@ class WorkbasketDefinitionControllerIntTest {
body.add("file", new FileSystemResource(tmpFile));
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
String serverUrl = restHelper.toUrl(Mapping.URL_WORKBASKETDEFINITIONS);
String serverUrl = restHelper.toUrl(Mapping.URL_WORKBASKET_DEFINITIONS);
ResponseEntity<Void> responseImport =
TEMPLATE.postForEntity(serverUrl, requestEntity, Void.class);