diff --git a/history/taskana-simplehistory-rest-spring/src/main/java/pro/taskana/simplehistory/rest/TaskHistoryEventController.java b/history/taskana-simplehistory-rest-spring/src/main/java/pro/taskana/simplehistory/rest/TaskHistoryEventController.java index 42d58c9b9..5f50ce78a 100644 --- a/history/taskana-simplehistory-rest-spring/src/main/java/pro/taskana/simplehistory/rest/TaskHistoryEventController.java +++ b/history/taskana-simplehistory-rest-spring/src/main/java/pro/taskana/simplehistory/rest/TaskHistoryEventController.java @@ -6,6 +6,7 @@ import java.time.ZoneId; import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.hateoas.PagedModel.PageMetadata; import org.springframework.hateoas.config.EnableHypermediaSupport; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -23,7 +24,6 @@ import pro.taskana.common.api.LoggerUtils; import pro.taskana.common.api.TimeInterval; import pro.taskana.common.api.exceptions.InvalidArgumentException; import pro.taskana.rest.AbstractPagingController; -import pro.taskana.rest.resource.PagedResources.PageMetadata; import pro.taskana.simplehistory.impl.HistoryEventImpl; import pro.taskana.simplehistory.impl.SimpleHistoryServiceImpl; import pro.taskana.simplehistory.query.HistoryQuery; diff --git a/history/taskana-simplehistory-rest-spring/src/main/java/pro/taskana/simplehistory/rest/resource/TaskHistoryEventListResource.java b/history/taskana-simplehistory-rest-spring/src/main/java/pro/taskana/simplehistory/rest/resource/TaskHistoryEventListResource.java index 2b88bf4f0..ab11ca425 100644 --- a/history/taskana-simplehistory-rest-spring/src/main/java/pro/taskana/simplehistory/rest/resource/TaskHistoryEventListResource.java +++ b/history/taskana-simplehistory-rest-spring/src/main/java/pro/taskana/simplehistory/rest/resource/TaskHistoryEventListResource.java @@ -3,6 +3,7 @@ package pro.taskana.simplehistory.rest.resource; import com.fasterxml.jackson.annotation.JsonProperty; import java.util.Collection; import org.springframework.hateoas.Link; +import org.springframework.hateoas.PagedModel.PageMetadata; import pro.taskana.rest.resource.PagedResources; diff --git a/history/taskana-simplehistory-rest-spring/src/main/java/pro/taskana/simplehistory/rest/resource/TaskHistoryEventListResourceAssembler.java b/history/taskana-simplehistory-rest-spring/src/main/java/pro/taskana/simplehistory/rest/resource/TaskHistoryEventListResourceAssembler.java index 1bb281933..28536265f 100644 --- a/history/taskana-simplehistory-rest-spring/src/main/java/pro/taskana/simplehistory/rest/resource/TaskHistoryEventListResourceAssembler.java +++ b/history/taskana-simplehistory-rest-spring/src/main/java/pro/taskana/simplehistory/rest/resource/TaskHistoryEventListResourceAssembler.java @@ -6,9 +6,9 @@ import java.util.ArrayList; import java.util.List; import org.springframework.hateoas.IanaLinkRelations; import org.springframework.hateoas.Link; +import org.springframework.hateoas.PagedModel.PageMetadata; import pro.taskana.rest.resource.AbstractRessourcesAssembler; -import pro.taskana.rest.resource.PagedResources.PageMetadata; import pro.taskana.simplehistory.impl.HistoryEventImpl; import pro.taskana.simplehistory.rest.TaskHistoryEventController; diff --git a/history/taskana-simplehistory-rest-spring/src/main/java/pro/taskana/simplehistory/rest/resource/TaskHistoryEventResource.java b/history/taskana-simplehistory-rest-spring/src/main/java/pro/taskana/simplehistory/rest/resource/TaskHistoryEventResource.java index b7f6a9955..f798fb184 100644 --- a/history/taskana-simplehistory-rest-spring/src/main/java/pro/taskana/simplehistory/rest/resource/TaskHistoryEventResource.java +++ b/history/taskana-simplehistory-rest-spring/src/main/java/pro/taskana/simplehistory/rest/resource/TaskHistoryEventResource.java @@ -1,6 +1,5 @@ package pro.taskana.simplehistory.rest.resource; -import javax.validation.constraints.NotNull; import org.springframework.hateoas.RepresentationModel; import pro.taskana.spi.history.api.events.TaskanaHistoryEvent; @@ -8,7 +7,7 @@ import pro.taskana.spi.history.api.events.TaskanaHistoryEvent; /** Resource class for {@link TaskanaHistoryEvent}. */ public class TaskHistoryEventResource extends RepresentationModel { - @NotNull private String taskHistoryEventId; + private String taskHistoryEventId; private String businessProcessId; private String parentBusinessProcessId; private String taskId; diff --git a/history/taskana-simplehistory-rest-spring/src/main/java/pro/taskana/simplehistory/rest/resource/TaskHistoryEventResourceAssembler.java b/history/taskana-simplehistory-rest-spring/src/main/java/pro/taskana/simplehistory/rest/resource/TaskHistoryEventResourceAssembler.java index 8c818d255..30369de84 100644 --- a/history/taskana-simplehistory-rest-spring/src/main/java/pro/taskana/simplehistory/rest/resource/TaskHistoryEventResourceAssembler.java +++ b/history/taskana-simplehistory-rest-spring/src/main/java/pro/taskana/simplehistory/rest/resource/TaskHistoryEventResourceAssembler.java @@ -5,6 +5,7 @@ import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn; import org.springframework.beans.BeanUtils; import org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport; +import org.springframework.lang.NonNull; import pro.taskana.common.api.exceptions.SystemException; import pro.taskana.simplehistory.impl.HistoryEventImpl; @@ -20,8 +21,9 @@ public class TaskHistoryEventResourceAssembler super(HistoryEventImpl.class, TaskHistoryEventResource.class); } + @NonNull @Override - public TaskHistoryEventResource toModel(TaskanaHistoryEvent historyEvent) { + public TaskHistoryEventResource toModel(@NonNull TaskanaHistoryEvent historyEvent) { TaskHistoryEventResource resource = createModelWithId(historyEvent.getId(), historyEvent); try { resource.removeLinks(); diff --git a/lib/taskana-core/src/main/java/pro/taskana/common/internal/configuration/DbSchemaCreator.java b/lib/taskana-core/src/main/java/pro/taskana/common/internal/configuration/DbSchemaCreator.java index 5ebd70944..32d0422de 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/common/internal/configuration/DbSchemaCreator.java +++ b/lib/taskana-core/src/main/java/pro/taskana/common/internal/configuration/DbSchemaCreator.java @@ -166,7 +166,7 @@ public class DbSchemaCreator { line = reader.readLine(); if (line != null) { content - .append(line.replaceAll("%schemaName%", schemaName)) + .append(line.replace("%schemaName%", schemaName)) .append(System.lineSeparator()); } } diff --git a/lib/taskana-core/src/main/java/pro/taskana/task/api/TaskState.java b/lib/taskana-core/src/main/java/pro/taskana/task/api/TaskState.java index 7047e18e5..522351e8e 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/task/api/TaskState.java +++ b/lib/taskana-core/src/main/java/pro/taskana/task/api/TaskState.java @@ -1,5 +1,7 @@ package pro.taskana.task.api; +import java.util.Arrays; + /** This enum contains all status of the tasks. */ public enum TaskState { READY, @@ -9,15 +11,10 @@ public enum TaskState { TERMINATED; public boolean in(TaskState... states) { - for (TaskState currState : states) { - if (this.equals(currState)) { - return true; - } - } - return false; + return Arrays.stream(states).anyMatch(state -> state == this); } public boolean isEndState() { - return this.equals(COMPLETED) || this.equals(CANCELLED) || this.equals(TERMINATED); + return this == COMPLETED || this == CANCELLED || this == TERMINATED; } } diff --git a/lib/taskana-core/src/main/java/pro/taskana/task/internal/jobs/TaskCleanupJob.java b/lib/taskana-core/src/main/java/pro/taskana/task/internal/jobs/TaskCleanupJob.java index fb70d5c4e..abfcf4ca1 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/task/internal/jobs/TaskCleanupJob.java +++ b/lib/taskana-core/src/main/java/pro/taskana/task/internal/jobs/TaskCleanupJob.java @@ -10,7 +10,7 @@ import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import pro.taskana.common.api.BaseQuery; +import pro.taskana.common.api.BaseQuery.SortDirection; import pro.taskana.common.api.BulkOperationResults; import pro.taskana.common.api.LoggerUtils; import pro.taskana.common.api.ScheduledJob; @@ -24,19 +24,21 @@ import pro.taskana.common.internal.transaction.TaskanaTransactionProvider; import pro.taskana.common.internal.util.LogSanitizer; import pro.taskana.task.api.models.TaskSummary; -/** Job to cleanup completed tasks after a period of time. */ +/** + * Job to cleanup completed tasks after a period of time. + */ public class TaskCleanupJob extends AbstractTaskanaJob { private static final Logger LOGGER = LoggerFactory.getLogger(TaskCleanupJob.class); - private static BaseQuery.SortDirection asc = BaseQuery.SortDirection.ASCENDING; + private static final SortDirection ASCENDING = SortDirection.ASCENDING; // Parameter - private Instant firstRun; - private Duration runEvery; - private Duration minimumAge; - private int batchSize; - private boolean allCompletedSameParentBusiness; + private final Instant firstRun; + private final Duration runEvery; + private final Duration minimumAge; + private final int batchSize; + private final boolean allCompletedSameParentBusiness; public TaskCleanupJob( TaskanaEngine taskanaEngine, @@ -55,7 +57,7 @@ public class TaskCleanupJob extends AbstractTaskanaJob { public void run() throws TaskanaException { Instant completedBefore = Instant.now().minus(minimumAge); LOGGER.info( - "Running job to delete all tasks completed before ({})", completedBefore.toString()); + "Running job to delete all tasks completed before ({})", completedBefore); try { List tasksCompletedBefore = getTasksCompletedBefore(completedBefore); int totalNumberOfTasksCompleted = 0; @@ -94,7 +96,7 @@ public class TaskCleanupJob extends AbstractTaskanaJob { .getTaskService() .createTaskQuery() .completedWithin(new TimeInterval(null, untilDate)) - .orderByBusinessProcessId(asc) + .orderByBusinessProcessId(ASCENDING) .list(); if (allCompletedSameParentBusiness) { diff --git a/lib/taskana-core/src/main/java/pro/taskana/workbasket/internal/jobs/WorkbasketCleanupJob.java b/lib/taskana-core/src/main/java/pro/taskana/workbasket/internal/jobs/WorkbasketCleanupJob.java index 3c5c724c6..5474ffd28 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/workbasket/internal/jobs/WorkbasketCleanupJob.java +++ b/lib/taskana-core/src/main/java/pro/taskana/workbasket/internal/jobs/WorkbasketCleanupJob.java @@ -26,9 +26,9 @@ public class WorkbasketCleanupJob extends AbstractTaskanaJob { private static final Logger LOGGER = LoggerFactory.getLogger(WorkbasketCleanupJob.class); // Parameter - private Instant firstRun; - private Duration runEvery; - private int batchSize; + private final Instant firstRun; + private final Duration runEvery; + private final int batchSize; public WorkbasketCleanupJob( TaskanaEngine taskanaEngine, @@ -76,31 +76,27 @@ public class WorkbasketCleanupJob extends AbstractTaskanaJob { } private List getWorkbasketsMarkedForDeletion() { - List workbasketList = - taskanaEngineImpl - .getWorkbasketService() - .createWorkbasketQuery() - .markedForDeletion(true) - .listValues(WorkbasketQueryColumnName.ID, BaseQuery.SortDirection.ASCENDING); - return workbasketList; + return taskanaEngineImpl + .getWorkbasketService() + .createWorkbasketQuery() + .markedForDeletion(true) + .listValues(WorkbasketQueryColumnName.ID, BaseQuery.SortDirection.ASCENDING); } private int deleteWorkbasketsTransactionally(List workbasketsToBeDeleted) { int deletedWorkbasketsCount = 0; if (txProvider != null) { - int count = - (Integer) - txProvider.executeInTransaction( - () -> { - try { - return deleteWorkbaskets(workbasketsToBeDeleted); - } catch (Exception e) { - LOGGER.warn("Could not delete workbaskets.", e); - return 0; - } - }); - return count; + return (Integer) + txProvider.executeInTransaction( + () -> { + try { + return deleteWorkbaskets(workbasketsToBeDeleted); + } catch (Exception e) { + LOGGER.warn("Could not delete workbaskets.", e); + return 0; + } + }); } else { try { deletedWorkbasketsCount = deleteWorkbaskets(workbasketsToBeDeleted); diff --git a/rest/taskana-rest-spring-example-common/src/main/java/pro/taskana/ldap/LdapCacheTestImpl.java b/rest/taskana-rest-spring-example-common/src/main/java/pro/taskana/ldap/LdapCacheTestImpl.java index 5b35f3d48..3d6937bbd 100644 --- a/rest/taskana-rest-spring-example-common/src/main/java/pro/taskana/ldap/LdapCacheTestImpl.java +++ b/rest/taskana-rest-spring-example-common/src/main/java/pro/taskana/ldap/LdapCacheTestImpl.java @@ -2,13 +2,14 @@ package pro.taskana.ldap; import java.util.ArrayList; import java.util.Arrays; +import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; import org.springframework.stereotype.Component; -import pro.taskana.rest.resource.AccessIdResource; +import pro.taskana.rest.resource.AccessIdRepresentationModel; /** * Implementation of LdapCache used for Unit tests. @@ -19,283 +20,292 @@ import pro.taskana.rest.resource.AccessIdResource; public class LdapCacheTestImpl implements LdapCache { /** - * Dictionary is a {@link Map} collection that contains {@link AccessIdResource} as key (user) and - * {@link List} as value (groups of which the user is a member) . + * Dictionary is a {@link Map} collection that contains {@link AccessIdRepresentationModel} as key + * (user) and {@link List} as value (groups of which the user is a member) . */ - private Map> users; + private Map> users; - private List accessIds = + private final List accessIds = new ArrayList<>( Arrays.asList( - new AccessIdResource("Martin, Rojas Miguel Angel", "user_1_1"), - new AccessIdResource("Zorgati, Mustapha", "user_2_1"), - new AccessIdResource("Behrendt, Maximilian", "max"), - new AccessIdResource("Bert, Ali", "teamlead_5"), - new AccessIdResource("Hagen, Holger", "teamlead_3"), - new AccessIdResource("Breier, Bernd", "user_2_2"), - new AccessIdResource("Fielmalz, Anke", "user017"), - new AccessIdResource("Mente, Maximilian", "max_mente"), - new AccessIdResource("Theke, Bernd", "user_2_3"), - new AccessIdResource("Ferrante, Elena", "elena"), - new AccessIdResource("Mueller, Simone", "simone"), - new AccessIdResource("Sirup, Aaron", "user001"), - new AccessIdResource("Nacho, recuerda", "user_1_2"), - new AccessIdResource("Lass, Ada", "user003"), - new AccessIdResource("Tion, Addi", "user004"), - new AccessIdResource("Lette, Adi", "user005"), - new AccessIdResource("Admin", "teamlead_2"), - new AccessIdResource("Native, Alter", "user006"), - new AccessIdResource("Herum, Albert", "user007"), - new AccessIdResource("Meyer, Dominik", "teamlead_1"), - new AccessIdResource("Mente, Ali", "user009"), - new AccessIdResource("Nach, Alma", "user011"), - new AccessIdResource("Gehzauch, Anders", "user012"), - new AccessIdResource("Theke, Andi", "user013"), - new AccessIdResource("Kreuz, Andreas", "user014"), - new AccessIdResource("Tiefsee, Anka", "user016"), - new AccessIdResource("Fassen, Ann", "user018"), - new AccessIdResource("Probe, Ann", "user019"), - new AccessIdResource("Bolika, Anna", "user020"), - new AccessIdResource("Ecke, Anna", "user021"), - new AccessIdResource("Hosi, Anna", "user022"), - new AccessIdResource("Kronis-Tisch, Anna", "user023"), - new AccessIdResource("Logie, Anna", "user024"), - new AccessIdResource("Luehse, Anna", "user025"), - new AccessIdResource("Nass, Anna", "user026"), - new AccessIdResource("Thalb, Anna", "user027"), - new AccessIdResource("Tomie, Anna", "user028"), - new AccessIdResource("Donnich, Anne", "user029"), - new AccessIdResource("Kaffek, Anne", "user030"), - new AccessIdResource("Thek, Anne", "user031"), - new AccessIdResource("Matoer, Anni", "user032"), - new AccessIdResource("Ragentor, Ansgar", "user033"), - new AccessIdResource("Stoteles, Ari", "user034"), - new AccessIdResource("Thmetik, Ari", "user035"), - new AccessIdResource("Nuehm, Arno", "user036"), - new AccessIdResource("Schocke, Artie", "user037"), - new AccessIdResource("Stoppel, Bart", "user038"), - new AccessIdResource("Beitung, Bea", "user039"), - new AccessIdResource("Ildich, Bea", "user040"), - new AccessIdResource("Vista, Bella", "user041"), - new AccessIdResource("Utzer, Ben", "user042"), - new AccessIdResource("Zien, Ben", "user043"), - new AccessIdResource("Stein, Bernd", "user044"), - new AccessIdResource("Deramen, Bill", "user045"), - new AccessIdResource("Honig, Bine", "user046"), - new AccessIdResource("Densatz, Bo", "user047"), - new AccessIdResource("Densee, Bo", "user048"), - new AccessIdResource("Lerwagen, Bo", "user049"), - new AccessIdResource("Tail, Bob", "user050"), - new AccessIdResource("Ketta, Bruce", "user051"), - new AccessIdResource("Terrie, Bud", "user052"), - new AccessIdResource("Biener-Haken, Cara", "user053"), - new AccessIdResource("Ass, Caro", "user054"), - new AccessIdResource("Kaffee, Caro", "user055"), - new AccessIdResource("Linger, Caro", "user056"), - new AccessIdResource("tenSaft, Caro", "user057"), - new AccessIdResource("Antheme, Chris", "user058"), - new AccessIdResource("Baum, Chris", "user059"), - new AccessIdResource("Tall, Chris", "user060"), - new AccessIdResource("Reiniger, Claas", "user061"), - new AccessIdResource("Grube, Claire", "user062"), - new AccessIdResource("Fall, Clara", "user063"), - new AccessIdResource("Korn, Clara", "user064"), - new AccessIdResource("Lenriff, Cora", "user065"), - new AccessIdResource("Schiert, Cora", "user066"), - new AccessIdResource("Hose, Cord", "user067"), - new AccessIdResource("Onbleu, Cord", "user068"), - new AccessIdResource("Umkleide, Damon", "user069"), - new AccessIdResource("Affier, Dean", "user070"), - new AccessIdResource("Orm, Dean", "user071"), - new AccessIdResource("Platz, Dennis", "user072"), - new AccessIdResource("Milch, Dick", "user073"), - new AccessIdResource("Mow, Dina", "user074"), - new AccessIdResource("Keil, Donna", "user075"), - new AccessIdResource("Littchen, Donna", "user076"), - new AccessIdResource("Wetter, Donna", "user077"), - new AccessIdResource("Was, Ed", "user078"), - new AccessIdResource("Khar, Ede", "user079"), - new AccessIdResource("Nut, Ella", "user080"), - new AccessIdResource("Stisch, Ella", "user081"), - new AccessIdResource("Diel, Emma", "user082"), - new AccessIdResource("Herdamit, Emma", "user083"), - new AccessIdResource("Mitter-Uhe, Emma", "user084"), - new AccessIdResource("Tatt, Erich", "user085"), - new AccessIdResource("Drigend, Ernie", "user086"), - new AccessIdResource("Poly, Esther", "user087"), - new AccessIdResource("Trautz, Eugen", "user088"), - new AccessIdResource("Quiert, Eva", "user089"), - new AccessIdResource("Inurlaub, Fatma", "user090"), - new AccessIdResource("Land, Finn", "user091"), - new AccessIdResource("Sternis, Finn", "user092"), - new AccessIdResource("Furt, Frank", "user093"), - new AccessIdResource("Reich, Frank", "user094"), - new AccessIdResource("Iskaner, Franz", "user095"), - new AccessIdResource("Nerr, Franziska", "user096"), - new AccessIdResource("Zafen, Friedrich", "user097"), - new AccessIdResource("Pomm, Fritz", "user098"), - new AccessIdResource("deWegs, Gera", "user099"), - new AccessIdResource("Staebe, Gitta", "user100"), - new AccessIdResource("Zend, Glenn", "user101"), - new AccessIdResource("Fisch, Grete", "user102"), - new AccessIdResource("Zucker, Gus", "user103"), - new AccessIdResource("Muhn, Hanni", "user104"), - new AccessIdResource("Fermesse, Hanno", "user105"), - new AccessIdResource("Aplast, Hans", "user106"), - new AccessIdResource("Eart, Hans", "user107"), - new AccessIdResource("Back, Hardy", "user108"), - new AccessIdResource("Beau, Harry", "user109"), - new AccessIdResource("Kraut, Heide", "user110"), - new AccessIdResource("Witzka, Heide", "user111"), - new AccessIdResource("Buchen, Hein", "user112"), - new AccessIdResource("Lichkeit, Hein", "user113"), - new AccessIdResource("Suchung, Hein", "user114"), - new AccessIdResource("Ellmann, Heinz", "user115"), - new AccessIdResource("Ketchup, Heinz", "user116"), - new AccessIdResource("Zeim, Hilde", "user117"), - new AccessIdResource("Bilien, Immo", "user118"), - new AccessIdResource("Her, Inge", "user119"), - new AccessIdResource("Wahrsam, Inge", "user120"), - new AccessIdResource("Flamm, Ingo", "user121"), - new AccessIdResource("Enzien, Ingrid", "user122"), - new AccessIdResource("Rohsch, Inken", "user123"), - new AccessIdResource("Ihr, Insa", "user124"), - new AccessIdResource("Nerda, Iska", "user125"), - new AccessIdResource("Eitz, Jens", "user126"), - new AccessIdResource("Nastik, Jim", "user127"), - new AccessIdResource("Gurt, Jo", "user128"), - new AccessIdResource("Kurrth, Jo", "user129"), - new AccessIdResource("Kolade, Joe", "user130"), - new AccessIdResource("Iter, Johann", "user131"), - new AccessIdResource("Tick, Joyce", "user132"), - new AccessIdResource("Case, Justin", "user133"), - new AccessIdResource("Time, Justin", "user134"), - new AccessIdResource("Komp, Jutta", "user135"), - new AccessIdResource("Mauer, Kai", "user136"), - new AccessIdResource("Pirinja, Kai", "user137"), - new AccessIdResource("Serpfalz, Kai", "user138"), - new AccessIdResource("Auer, Karl", "user139"), - new AccessIdResource("Ielauge, Karl", "user140"), - new AccessIdResource("Ifornjen, Karl", "user141"), - new AccessIdResource("Radi, Karl", "user142"), - new AccessIdResource("Verti, Karl", "user143"), - new AccessIdResource("Sery, Karo", "user144"), - new AccessIdResource("Lisator, Katha", "user145"), - new AccessIdResource("Flo, Kati", "user146"), - new AccessIdResource("Schenn, Knut", "user147"), - new AccessIdResource("Achse, Kurt", "user148"), - new AccessIdResource("Zepause, Kurt", "user149"), - new AccessIdResource("Zerr, Kurt", "user150"), - new AccessIdResource("Reden, Lasse", "user151"), - new AccessIdResource("Metten, Lee", "user152"), - new AccessIdResource("Arm, Lene", "user153"), - new AccessIdResource("Thur, Linnea", "user154"), - new AccessIdResource("Bonn, Lisa", "user155"), - new AccessIdResource("Sembourg, Luc", "user156"), - new AccessIdResource("Rung, Lucky", "user157"), - new AccessIdResource("Zafen, Ludwig", "user158"), - new AccessIdResource("Hauden, Lukas", "user159"), - new AccessIdResource("Hose, Lutz", "user160"), - new AccessIdResource("Tablette, Lutz", "user161"), - new AccessIdResource("Fehr, Luzie", "user162"), - new AccessIdResource("Nalyse, Magda", "user163"), - new AccessIdResource("Ehfer, Maik", "user164"), - new AccessIdResource("Sehr, Malte", "user165"), - new AccessIdResource("Thon, Mara", "user166"), - new AccessIdResource("Quark, Marga", "user167"), - new AccessIdResource("Nade, Marie", "user168"), - new AccessIdResource("Niert, Marie", "user169"), - new AccessIdResource("Neese, Mario", "user170"), - new AccessIdResource("Nette, Marion", "user171"), - new AccessIdResource("Nesium, Mark", "user172"), - new AccessIdResource("Thalle, Mark", "user173"), - new AccessIdResource("Diven, Marle", "user174"), - new AccessIdResource("Fitz, Marle", "user175"), - new AccessIdResource("Pfahl, Marta", "user176"), - new AccessIdResource("Zorn, Martin", "user177"), - new AccessIdResource("Krissmes, Mary", "user178"), - new AccessIdResource("Jess, Matt", "user179"), - new AccessIdResource("Strammer, Max", "user180"), - new AccessIdResource("Mumm, Maxi", "user181"), - new AccessIdResource("Morphose, Meta", "user182"), - new AccessIdResource("Uh, Mia", "user183"), - new AccessIdResource("Rofon, Mike", "user184"), - new AccessIdResource("Rosoft, Mike", "user185"), - new AccessIdResource("Liter, Milli", "user186"), - new AccessIdResource("Thär, Milli", "user187"), - new AccessIdResource("Welle, Mirko", "user188"), - new AccessIdResource("Thorat, Mo", "user189"), - new AccessIdResource("Thor, Moni", "user190"), - new AccessIdResource("Kinolta, Monika", "user191"), - new AccessIdResource("Mundhaar, Monika", "user192"), - new AccessIdResource("Munter, Monika", "user193"), - new AccessIdResource("Zwerg, Nat", "user194"), - new AccessIdResource("Elmine, Nick", "user195"), - new AccessIdResource("Thien, Niko", "user196"), - new AccessIdResource("Pferd, Nils", "user197"), - new AccessIdResource("Lerweise, Norma", "user198"), - new AccessIdResource("Motor, Otto", "user199"), - new AccessIdResource("Totol, Otto", "user200"), - new AccessIdResource("Nerr, Paula", "user201"), - new AccessIdResource("Imeter, Peer", "user202"), - new AccessIdResource("Serkatze, Peer", "user203"), - new AccessIdResource("Gogisch, Peter", "user204"), - new AccessIdResource("Silje, Peter", "user205"), - new AccessIdResource("Harmonie, Phil", "user206"), - new AccessIdResource("Ihnen, Philip", "user207"), - new AccessIdResource("Uto, Pia", "user208"), - new AccessIdResource("Kothek, Pina", "user209"), - new AccessIdResource("Zar, Pit", "user210"), - new AccessIdResource("Zeih, Polly", "user211"), - new AccessIdResource("Tswan, Puh", "user212"), - new AccessIdResource("Zufall, Rainer", "user213"), - new AccessIdResource("Lien, Rita", "user214"), - new AccessIdResource("Held, Roman", "user215"), - new AccessIdResource("Haar, Ross", "user216"), - new AccessIdResource("Dick, Roy", "user217"), - new AccessIdResource("Enplaner, Ruth", "user218"), - new AccessIdResource("Kommen, Ryan", "user219"), - new AccessIdResource("Philo, Sophie", "user220"), - new AccessIdResource("Matisier, Stig", "user221"), - new AccessIdResource("Loniki, Tessa", "user222"), - new AccessIdResource("Tralisch, Thea", "user223"), - new AccessIdResource("Logie, Theo", "user224"), - new AccessIdResource("Ister, Thorn", "user225"), - new AccessIdResource("Buktu, Tim", "user226"), - new AccessIdResource("Ate, Tom", "user227"), - new AccessIdResource("Pie, Udo", "user228"), - new AccessIdResource("Aloe, Vera", "user229"), - new AccessIdResource("Hausver, Walter", "user230"), - new AccessIdResource("Schuh, Wanda", "user231"), - new AccessIdResource("Rahm, Wolf", "user232"), - new AccessIdResource("businessadmin", "cn=businessadmin,ou=groups,o=taskanatest"), - new AccessIdResource("UsersGroup", "cn=usersgroup,ou=groups,o=taskanatest"), - new AccessIdResource("DevelopersGroup", "cn=developersgroup,ou=groups,o=taskanatest"), - new AccessIdResource("businessadmin", "cn=customersgroup,ou=groups,o=taskanatest"), - new AccessIdResource("user_domain_A", "cn=user_domain_a,ou=groups,o=taskanatest"), - new AccessIdResource("monitor", "cn=monitor,ou=groups,o=taskanatest"), - new AccessIdResource("user_domain_C", "cn=user_domain_c,ou=groups,o=taskanatest"), - new AccessIdResource("user_domain_D", "cn=user_domain_d,ou=groups,o=taskanatest"), - new AccessIdResource("admin", "cn=admin,ou=groups,o=taskanatest"), - new AccessIdResource( + new AccessIdRepresentationModel("Martin, Rojas Miguel Angel", "user_1_1"), + new AccessIdRepresentationModel("Zorgati, Mustapha", "user_2_1"), + new AccessIdRepresentationModel("Behrendt, Maximilian", "max"), + new AccessIdRepresentationModel("Bert, Ali", "teamlead_5"), + new AccessIdRepresentationModel("Hagen, Holger", "teamlead_3"), + new AccessIdRepresentationModel("Breier, Bernd", "user_2_2"), + new AccessIdRepresentationModel("Fielmalz, Anke", "user017"), + new AccessIdRepresentationModel("Mente, Maximilian", "max_mente"), + new AccessIdRepresentationModel("Theke, Bernd", "user_2_3"), + new AccessIdRepresentationModel("Ferrante, Elena", "elena"), + new AccessIdRepresentationModel("Mueller, Simone", "simone"), + new AccessIdRepresentationModel("Sirup, Aaron", "user001"), + new AccessIdRepresentationModel("Nacho, recuerda", "user_1_2"), + new AccessIdRepresentationModel("Lass, Ada", "user003"), + new AccessIdRepresentationModel("Tion, Addi", "user004"), + new AccessIdRepresentationModel("Lette, Adi", "user005"), + new AccessIdRepresentationModel("Admin", "teamlead_2"), + new AccessIdRepresentationModel("Native, Alter", "user006"), + new AccessIdRepresentationModel("Herum, Albert", "user007"), + new AccessIdRepresentationModel("Meyer, Dominik", "teamlead_1"), + new AccessIdRepresentationModel("Mente, Ali", "user009"), + new AccessIdRepresentationModel("Nach, Alma", "user011"), + new AccessIdRepresentationModel("Gehzauch, Anders", "user012"), + new AccessIdRepresentationModel("Theke, Andi", "user013"), + new AccessIdRepresentationModel("Kreuz, Andreas", "user014"), + new AccessIdRepresentationModel("Tiefsee, Anka", "user016"), + new AccessIdRepresentationModel("Fassen, Ann", "user018"), + new AccessIdRepresentationModel("Probe, Ann", "user019"), + new AccessIdRepresentationModel("Bolika, Anna", "user020"), + new AccessIdRepresentationModel("Ecke, Anna", "user021"), + new AccessIdRepresentationModel("Hosi, Anna", "user022"), + new AccessIdRepresentationModel("Kronis-Tisch, Anna", "user023"), + new AccessIdRepresentationModel("Logie, Anna", "user024"), + new AccessIdRepresentationModel("Luehse, Anna", "user025"), + new AccessIdRepresentationModel("Nass, Anna", "user026"), + new AccessIdRepresentationModel("Thalb, Anna", "user027"), + new AccessIdRepresentationModel("Tomie, Anna", "user028"), + new AccessIdRepresentationModel("Donnich, Anne", "user029"), + new AccessIdRepresentationModel("Kaffek, Anne", "user030"), + new AccessIdRepresentationModel("Thek, Anne", "user031"), + new AccessIdRepresentationModel("Matoer, Anni", "user032"), + new AccessIdRepresentationModel("Ragentor, Ansgar", "user033"), + new AccessIdRepresentationModel("Stoteles, Ari", "user034"), + new AccessIdRepresentationModel("Thmetik, Ari", "user035"), + new AccessIdRepresentationModel("Nuehm, Arno", "user036"), + new AccessIdRepresentationModel("Schocke, Artie", "user037"), + new AccessIdRepresentationModel("Stoppel, Bart", "user038"), + new AccessIdRepresentationModel("Beitung, Bea", "user039"), + new AccessIdRepresentationModel("Ildich, Bea", "user040"), + new AccessIdRepresentationModel("Vista, Bella", "user041"), + new AccessIdRepresentationModel("Utzer, Ben", "user042"), + new AccessIdRepresentationModel("Zien, Ben", "user043"), + new AccessIdRepresentationModel("Stein, Bernd", "user044"), + new AccessIdRepresentationModel("Deramen, Bill", "user045"), + new AccessIdRepresentationModel("Honig, Bine", "user046"), + new AccessIdRepresentationModel("Densatz, Bo", "user047"), + new AccessIdRepresentationModel("Densee, Bo", "user048"), + new AccessIdRepresentationModel("Lerwagen, Bo", "user049"), + new AccessIdRepresentationModel("Tail, Bob", "user050"), + new AccessIdRepresentationModel("Ketta, Bruce", "user051"), + new AccessIdRepresentationModel("Terrie, Bud", "user052"), + new AccessIdRepresentationModel("Biener-Haken, Cara", "user053"), + new AccessIdRepresentationModel("Ass, Caro", "user054"), + new AccessIdRepresentationModel("Kaffee, Caro", "user055"), + new AccessIdRepresentationModel("Linger, Caro", "user056"), + new AccessIdRepresentationModel("tenSaft, Caro", "user057"), + new AccessIdRepresentationModel("Antheme, Chris", "user058"), + new AccessIdRepresentationModel("Baum, Chris", "user059"), + new AccessIdRepresentationModel("Tall, Chris", "user060"), + new AccessIdRepresentationModel("Reiniger, Claas", "user061"), + new AccessIdRepresentationModel("Grube, Claire", "user062"), + new AccessIdRepresentationModel("Fall, Clara", "user063"), + new AccessIdRepresentationModel("Korn, Clara", "user064"), + new AccessIdRepresentationModel("Lenriff, Cora", "user065"), + new AccessIdRepresentationModel("Schiert, Cora", "user066"), + new AccessIdRepresentationModel("Hose, Cord", "user067"), + new AccessIdRepresentationModel("Onbleu, Cord", "user068"), + new AccessIdRepresentationModel("Umkleide, Damon", "user069"), + new AccessIdRepresentationModel("Affier, Dean", "user070"), + new AccessIdRepresentationModel("Orm, Dean", "user071"), + new AccessIdRepresentationModel("Platz, Dennis", "user072"), + new AccessIdRepresentationModel("Milch, Dick", "user073"), + new AccessIdRepresentationModel("Mow, Dina", "user074"), + new AccessIdRepresentationModel("Keil, Donna", "user075"), + new AccessIdRepresentationModel("Littchen, Donna", "user076"), + new AccessIdRepresentationModel("Wetter, Donna", "user077"), + new AccessIdRepresentationModel("Was, Ed", "user078"), + new AccessIdRepresentationModel("Khar, Ede", "user079"), + new AccessIdRepresentationModel("Nut, Ella", "user080"), + new AccessIdRepresentationModel("Stisch, Ella", "user081"), + new AccessIdRepresentationModel("Diel, Emma", "user082"), + new AccessIdRepresentationModel("Herdamit, Emma", "user083"), + new AccessIdRepresentationModel("Mitter-Uhe, Emma", "user084"), + new AccessIdRepresentationModel("Tatt, Erich", "user085"), + new AccessIdRepresentationModel("Drigend, Ernie", "user086"), + new AccessIdRepresentationModel("Poly, Esther", "user087"), + new AccessIdRepresentationModel("Trautz, Eugen", "user088"), + new AccessIdRepresentationModel("Quiert, Eva", "user089"), + new AccessIdRepresentationModel("Inurlaub, Fatma", "user090"), + new AccessIdRepresentationModel("Land, Finn", "user091"), + new AccessIdRepresentationModel("Sternis, Finn", "user092"), + new AccessIdRepresentationModel("Furt, Frank", "user093"), + new AccessIdRepresentationModel("Reich, Frank", "user094"), + new AccessIdRepresentationModel("Iskaner, Franz", "user095"), + new AccessIdRepresentationModel("Nerr, Franziska", "user096"), + new AccessIdRepresentationModel("Zafen, Friedrich", "user097"), + new AccessIdRepresentationModel("Pomm, Fritz", "user098"), + new AccessIdRepresentationModel("deWegs, Gera", "user099"), + new AccessIdRepresentationModel("Staebe, Gitta", "user100"), + new AccessIdRepresentationModel("Zend, Glenn", "user101"), + new AccessIdRepresentationModel("Fisch, Grete", "user102"), + new AccessIdRepresentationModel("Zucker, Gus", "user103"), + new AccessIdRepresentationModel("Muhn, Hanni", "user104"), + new AccessIdRepresentationModel("Fermesse, Hanno", "user105"), + new AccessIdRepresentationModel("Aplast, Hans", "user106"), + new AccessIdRepresentationModel("Eart, Hans", "user107"), + new AccessIdRepresentationModel("Back, Hardy", "user108"), + new AccessIdRepresentationModel("Beau, Harry", "user109"), + new AccessIdRepresentationModel("Kraut, Heide", "user110"), + new AccessIdRepresentationModel("Witzka, Heide", "user111"), + new AccessIdRepresentationModel("Buchen, Hein", "user112"), + new AccessIdRepresentationModel("Lichkeit, Hein", "user113"), + new AccessIdRepresentationModel("Suchung, Hein", "user114"), + new AccessIdRepresentationModel("Ellmann, Heinz", "user115"), + new AccessIdRepresentationModel("Ketchup, Heinz", "user116"), + new AccessIdRepresentationModel("Zeim, Hilde", "user117"), + new AccessIdRepresentationModel("Bilien, Immo", "user118"), + new AccessIdRepresentationModel("Her, Inge", "user119"), + new AccessIdRepresentationModel("Wahrsam, Inge", "user120"), + new AccessIdRepresentationModel("Flamm, Ingo", "user121"), + new AccessIdRepresentationModel("Enzien, Ingrid", "user122"), + new AccessIdRepresentationModel("Rohsch, Inken", "user123"), + new AccessIdRepresentationModel("Ihr, Insa", "user124"), + new AccessIdRepresentationModel("Nerda, Iska", "user125"), + new AccessIdRepresentationModel("Eitz, Jens", "user126"), + new AccessIdRepresentationModel("Nastik, Jim", "user127"), + new AccessIdRepresentationModel("Gurt, Jo", "user128"), + new AccessIdRepresentationModel("Kurrth, Jo", "user129"), + new AccessIdRepresentationModel("Kolade, Joe", "user130"), + new AccessIdRepresentationModel("Iter, Johann", "user131"), + new AccessIdRepresentationModel("Tick, Joyce", "user132"), + new AccessIdRepresentationModel("Case, Justin", "user133"), + new AccessIdRepresentationModel("Time, Justin", "user134"), + new AccessIdRepresentationModel("Komp, Jutta", "user135"), + new AccessIdRepresentationModel("Mauer, Kai", "user136"), + new AccessIdRepresentationModel("Pirinja, Kai", "user137"), + new AccessIdRepresentationModel("Serpfalz, Kai", "user138"), + new AccessIdRepresentationModel("Auer, Karl", "user139"), + new AccessIdRepresentationModel("Ielauge, Karl", "user140"), + new AccessIdRepresentationModel("Ifornjen, Karl", "user141"), + new AccessIdRepresentationModel("Radi, Karl", "user142"), + new AccessIdRepresentationModel("Verti, Karl", "user143"), + new AccessIdRepresentationModel("Sery, Karo", "user144"), + new AccessIdRepresentationModel("Lisator, Katha", "user145"), + new AccessIdRepresentationModel("Flo, Kati", "user146"), + new AccessIdRepresentationModel("Schenn, Knut", "user147"), + new AccessIdRepresentationModel("Achse, Kurt", "user148"), + new AccessIdRepresentationModel("Zepause, Kurt", "user149"), + new AccessIdRepresentationModel("Zerr, Kurt", "user150"), + new AccessIdRepresentationModel("Reden, Lasse", "user151"), + new AccessIdRepresentationModel("Metten, Lee", "user152"), + new AccessIdRepresentationModel("Arm, Lene", "user153"), + new AccessIdRepresentationModel("Thur, Linnea", "user154"), + new AccessIdRepresentationModel("Bonn, Lisa", "user155"), + new AccessIdRepresentationModel("Sembourg, Luc", "user156"), + new AccessIdRepresentationModel("Rung, Lucky", "user157"), + new AccessIdRepresentationModel("Zafen, Ludwig", "user158"), + new AccessIdRepresentationModel("Hauden, Lukas", "user159"), + new AccessIdRepresentationModel("Hose, Lutz", "user160"), + new AccessIdRepresentationModel("Tablette, Lutz", "user161"), + new AccessIdRepresentationModel("Fehr, Luzie", "user162"), + new AccessIdRepresentationModel("Nalyse, Magda", "user163"), + new AccessIdRepresentationModel("Ehfer, Maik", "user164"), + new AccessIdRepresentationModel("Sehr, Malte", "user165"), + new AccessIdRepresentationModel("Thon, Mara", "user166"), + new AccessIdRepresentationModel("Quark, Marga", "user167"), + new AccessIdRepresentationModel("Nade, Marie", "user168"), + new AccessIdRepresentationModel("Niert, Marie", "user169"), + new AccessIdRepresentationModel("Neese, Mario", "user170"), + new AccessIdRepresentationModel("Nette, Marion", "user171"), + new AccessIdRepresentationModel("Nesium, Mark", "user172"), + new AccessIdRepresentationModel("Thalle, Mark", "user173"), + new AccessIdRepresentationModel("Diven, Marle", "user174"), + new AccessIdRepresentationModel("Fitz, Marle", "user175"), + new AccessIdRepresentationModel("Pfahl, Marta", "user176"), + new AccessIdRepresentationModel("Zorn, Martin", "user177"), + new AccessIdRepresentationModel("Krissmes, Mary", "user178"), + new AccessIdRepresentationModel("Jess, Matt", "user179"), + new AccessIdRepresentationModel("Strammer, Max", "user180"), + new AccessIdRepresentationModel("Mumm, Maxi", "user181"), + new AccessIdRepresentationModel("Morphose, Meta", "user182"), + new AccessIdRepresentationModel("Uh, Mia", "user183"), + new AccessIdRepresentationModel("Rofon, Mike", "user184"), + new AccessIdRepresentationModel("Rosoft, Mike", "user185"), + new AccessIdRepresentationModel("Liter, Milli", "user186"), + new AccessIdRepresentationModel("Thär, Milli", "user187"), + new AccessIdRepresentationModel("Welle, Mirko", "user188"), + new AccessIdRepresentationModel("Thorat, Mo", "user189"), + new AccessIdRepresentationModel("Thor, Moni", "user190"), + new AccessIdRepresentationModel("Kinolta, Monika", "user191"), + new AccessIdRepresentationModel("Mundhaar, Monika", "user192"), + new AccessIdRepresentationModel("Munter, Monika", "user193"), + new AccessIdRepresentationModel("Zwerg, Nat", "user194"), + new AccessIdRepresentationModel("Elmine, Nick", "user195"), + new AccessIdRepresentationModel("Thien, Niko", "user196"), + new AccessIdRepresentationModel("Pferd, Nils", "user197"), + new AccessIdRepresentationModel("Lerweise, Norma", "user198"), + new AccessIdRepresentationModel("Motor, Otto", "user199"), + new AccessIdRepresentationModel("Totol, Otto", "user200"), + new AccessIdRepresentationModel("Nerr, Paula", "user201"), + new AccessIdRepresentationModel("Imeter, Peer", "user202"), + new AccessIdRepresentationModel("Serkatze, Peer", "user203"), + new AccessIdRepresentationModel("Gogisch, Peter", "user204"), + new AccessIdRepresentationModel("Silje, Peter", "user205"), + new AccessIdRepresentationModel("Harmonie, Phil", "user206"), + new AccessIdRepresentationModel("Ihnen, Philip", "user207"), + new AccessIdRepresentationModel("Uto, Pia", "user208"), + new AccessIdRepresentationModel("Kothek, Pina", "user209"), + new AccessIdRepresentationModel("Zar, Pit", "user210"), + new AccessIdRepresentationModel("Zeih, Polly", "user211"), + new AccessIdRepresentationModel("Tswan, Puh", "user212"), + new AccessIdRepresentationModel("Zufall, Rainer", "user213"), + new AccessIdRepresentationModel("Lien, Rita", "user214"), + new AccessIdRepresentationModel("Held, Roman", "user215"), + new AccessIdRepresentationModel("Haar, Ross", "user216"), + new AccessIdRepresentationModel("Dick, Roy", "user217"), + new AccessIdRepresentationModel("Enplaner, Ruth", "user218"), + new AccessIdRepresentationModel("Kommen, Ryan", "user219"), + new AccessIdRepresentationModel("Philo, Sophie", "user220"), + new AccessIdRepresentationModel("Matisier, Stig", "user221"), + new AccessIdRepresentationModel("Loniki, Tessa", "user222"), + new AccessIdRepresentationModel("Tralisch, Thea", "user223"), + new AccessIdRepresentationModel("Logie, Theo", "user224"), + new AccessIdRepresentationModel("Ister, Thorn", "user225"), + new AccessIdRepresentationModel("Buktu, Tim", "user226"), + new AccessIdRepresentationModel("Ate, Tom", "user227"), + new AccessIdRepresentationModel("Pie, Udo", "user228"), + new AccessIdRepresentationModel("Aloe, Vera", "user229"), + new AccessIdRepresentationModel("Hausver, Walter", "user230"), + new AccessIdRepresentationModel("Schuh, Wanda", "user231"), + new AccessIdRepresentationModel("Rahm, Wolf", "user232"), + new AccessIdRepresentationModel( + "businessadmin", "cn=businessadmin,ou=groups,o=taskanatest"), + new AccessIdRepresentationModel( + "UsersGroup", "cn=usersgroup,ou=groups,o=taskanatest"), + new AccessIdRepresentationModel( + "DevelopersGroup", "cn=developersgroup,ou=groups,o=taskanatest"), + new AccessIdRepresentationModel( + "businessadmin", "cn=customersgroup,ou=groups,o=taskanatest"), + new AccessIdRepresentationModel( + "user_domain_A", "cn=user_domain_a,ou=groups,o=taskanatest"), + new AccessIdRepresentationModel("monitor", "cn=monitor,ou=groups,o=taskanatest"), + new AccessIdRepresentationModel( + "user_domain_C", "cn=user_domain_c,ou=groups,o=taskanatest"), + new AccessIdRepresentationModel( + "user_domain_D", "cn=user_domain_d,ou=groups,o=taskanatest"), + new AccessIdRepresentationModel("admin", "cn=admin,ou=groups,o=taskanatest"), + new AccessIdRepresentationModel( "manager_domain_B", "cn=manager_domain_b,ou=groups,o=taskanatest"), - new AccessIdResource( + new AccessIdRepresentationModel( "manager_domain_C", "cn=manager_domain_c,ou=groups,o=taskanatest"), - new AccessIdResource( + new AccessIdRepresentationModel( "manager_domain_D", "cn=manager_domain_d,ou=groups,o=taskanatest"), - new AccessIdResource("teamlead_2", "cn=teamlead_2" + ",ou=groups,o=taskanatest"), - new AccessIdResource("teamlead_4", "cn=teamlead_4" + ",ou=groups,o=taskanatest"), - new AccessIdResource("team_3", "cn=team_3" + ",ou=groups,o=taskanatest"), - new AccessIdResource("team_4", "cn=team_4" + ",ou=groups,o=taskanatest"))); + new AccessIdRepresentationModel( + "teamlead_2", "cn=teamlead_2" + ",ou=groups,o=taskanatest"), + new AccessIdRepresentationModel( + "teamlead_4", "cn=teamlead_4" + ",ou=groups,o=taskanatest"), + new AccessIdRepresentationModel("team_3", "cn=team_3" + ",ou=groups,o=taskanatest"), + new AccessIdRepresentationModel("team_4", "cn=team_4" + ",ou=groups,o=taskanatest"))); @Override - public List findMatchingAccessId( + public List findMatchingAccessId( String searchFor, int maxNumberOfReturnedAccessIds) { return findAcessIdResource(searchFor, maxNumberOfReturnedAccessIds, false); } @Override - public List findGroupsOfUser( + public List findGroupsOfUser( String searchFor, int maxNumberOfReturnedAccessIds) { if (users == null) { users = addUsersToGroups(); @@ -304,15 +314,15 @@ public class LdapCacheTestImpl implements LdapCache { } @Override - public List validateAccessId(String accessId) { + public List validateAccessId(String accessId) { return accessIds.stream() .filter(t -> (t.getAccessId().equalsIgnoreCase(accessId.toLowerCase()))) .collect(Collectors.toList()); } - private List findAcessIdResource( + private List findAcessIdResource( String searchFor, int maxNumberOfReturnedAccessIds, boolean groupMember) { - List usersAndGroups = + List usersAndGroups = accessIds.stream() .filter( t -> @@ -320,7 +330,7 @@ public class LdapCacheTestImpl implements LdapCache { || t.getAccessId().toLowerCase().contains(searchFor.toLowerCase()))) .collect(Collectors.toList()); - List usersAndGroupsAux = new ArrayList<>(usersAndGroups); + List usersAndGroupsAux = new ArrayList<>(usersAndGroups); if (groupMember) { usersAndGroupsAux.forEach( item -> { @@ -331,36 +341,32 @@ public class LdapCacheTestImpl implements LdapCache { } usersAndGroups.sort( - (AccessIdResource a, AccessIdResource b) -> { - return a.getAccessId().compareToIgnoreCase(b.getAccessId()); - }); + Comparator.comparing( + AccessIdRepresentationModel::getAccessId, String.CASE_INSENSITIVE_ORDER)); - List result = - usersAndGroups.subList(0, Math.min(usersAndGroups.size(), maxNumberOfReturnedAccessIds)); - - return result; + return usersAndGroups.subList(0, Math.min(usersAndGroups.size(), maxNumberOfReturnedAccessIds)); } - private Map> addUsersToGroups() { - List groups = new ArrayList<>(); - Map> users = new HashMap<>(); + private Map> addUsersToGroups() { + List groups = new ArrayList<>(); + Map> userMap = new HashMap<>(); accessIds.forEach( item -> { if (!item.getAccessId().contains("ou=groups")) { - users.put(item, new ArrayList<>()); + userMap.put(item, new ArrayList<>()); } else { groups.add(item); } }); int groupNumber = 0; - List group0 = new ArrayList<>(); - List group1 = new ArrayList<>(); - List group2 = new ArrayList<>(); - List group3 = new ArrayList<>(); + List group0 = new ArrayList<>(); + List group1 = new ArrayList<>(); + List group2 = new ArrayList<>(); + List group3 = new ArrayList<>(); - for (AccessIdResource group : groups) { + for (AccessIdRepresentationModel group : groups) { switch (groupNumber) { case 0: group0.add(group); @@ -381,20 +387,20 @@ public class LdapCacheTestImpl implements LdapCache { } int countUser = 0; - for (AccessIdResource item : accessIds) { + for (AccessIdRepresentationModel item : accessIds) { if (!item.getAccessId().contains("ou=groups")) { switch (countUser) { case 0: - users.put(item, group0); + userMap.put(item, group0); break; case 1: - users.put(item, group1); + userMap.put(item, group1); break; case 2: - users.put(item, group2); + userMap.put(item, group2); break; case 3: - users.put(item, group3); + userMap.put(item, group3); break; default: break; @@ -402,6 +408,6 @@ public class LdapCacheTestImpl implements LdapCache { } countUser = (countUser + 1) % 4; } - return users; + return userMap; } } diff --git a/rest/taskana-rest-spring-example-common/src/main/java/pro/taskana/rest/security/SampleLoginModule.java b/rest/taskana-rest-spring-example-common/src/main/java/pro/taskana/rest/security/SampleLoginModule.java index c5f7bec3d..844febcae 100644 --- a/rest/taskana-rest-spring-example-common/src/main/java/pro/taskana/rest/security/SampleLoginModule.java +++ b/rest/taskana-rest-spring-example-common/src/main/java/pro/taskana/rest/security/SampleLoginModule.java @@ -13,7 +13,7 @@ import org.springframework.security.web.authentication.UsernamePasswordAuthentic import pro.taskana.common.internal.security.GroupPrincipal; import pro.taskana.common.internal.security.UserPrincipal; import pro.taskana.ldap.LdapCacheTestImpl; -import pro.taskana.rest.resource.AccessIdResource; +import pro.taskana.rest.resource.AccessIdRepresentationModel; /** TODO. */ public class SampleLoginModule extends UsernamePasswordAuthenticationFilter implements LoginModule { @@ -68,9 +68,10 @@ public class SampleLoginModule extends UsernamePasswordAuthenticationFilter impl private void addGroupSubjectsDerivedFromUsername() { LdapCacheTestImpl ldapCacheTest = new LdapCacheTestImpl(); String username = nameCallback.getName().toLowerCase(); - List groups = ldapCacheTest.findGroupsOfUser(username, Integer.MAX_VALUE); + List groups = + ldapCacheTest.findGroupsOfUser(username, Integer.MAX_VALUE); groups.forEach( - (AccessIdResource group) -> { + (AccessIdRepresentationModel group) -> { if (group.getAccessId().contains("ou=groups")) { subject.getPrincipals().add(new GroupPrincipal(group.getName())); } diff --git a/rest/taskana-rest-spring-example-common/src/test/java/pro/taskana/jobs/AsyncUpdateJobIntTest.java b/rest/taskana-rest-spring-example-common/src/test/java/pro/taskana/jobs/AsyncUpdateJobIntTest.java index 28965ca13..fb43da497 100644 --- a/rest/taskana-rest-spring-example-common/src/test/java/pro/taskana/jobs/AsyncUpdateJobIntTest.java +++ b/rest/taskana-rest-spring-example-common/src/test/java/pro/taskana/jobs/AsyncUpdateJobIntTest.java @@ -26,10 +26,10 @@ import pro.taskana.classification.api.models.Classification; import pro.taskana.common.api.exceptions.InvalidArgumentException; import pro.taskana.rest.Mapping; import pro.taskana.rest.RestConfiguration; -import pro.taskana.rest.resource.ClassificationResource; -import pro.taskana.rest.resource.ClassificationResourceAssembler; -import pro.taskana.rest.resource.TaskResource; -import pro.taskana.rest.resource.TaskResourceAssembler; +import pro.taskana.rest.resource.ClassificationRepresentationModel; +import pro.taskana.rest.resource.ClassificationRepresentationModelAssembler; +import pro.taskana.rest.resource.TaskRepresentationModel; +import pro.taskana.rest.resource.TaskRepresentationModelAssembler; import pro.taskana.task.api.models.Task; /** Test async updates. */ @@ -45,8 +45,8 @@ class AsyncUpdateJobIntTest { @SuppressWarnings("checkstyle:DeclarationOrder") static RestTemplate template; - @Autowired ClassificationResourceAssembler classificationResourceAssembler; - @Autowired TaskResourceAssembler taskResourceAssembler; + @Autowired ClassificationRepresentationModelAssembler classificationRepresentationModelAssembler; + @Autowired TaskRepresentationModelAssembler taskRepresentationModelAssembler; @Autowired JobScheduler jobScheduler; @Autowired RestHelper restHelper; @@ -62,15 +62,15 @@ class AsyncUpdateJobIntTest { final Instant before = Instant.now(); final ObjectMapper mapper = new ObjectMapper(); - ResponseEntity response = + ResponseEntity response = template.exchange( restHelper.toUrl(Mapping.URL_CLASSIFICATIONS_ID, CLASSIFICATION_ID), HttpMethod.GET, new HttpEntity(restHelper.getHeaders()), - ParameterizedTypeReference.forType(ClassificationResource.class)); + ParameterizedTypeReference.forType(ClassificationRepresentationModel.class)); assertThat(response.getBody()).isNotNull(); - ClassificationResource classification = response.getBody(); + ClassificationRepresentationModel classification = response.getBody(); assertThat(classification.getLink(IanaLinkRelations.SELF)).isNotNull(); // 2nd step: modify classification and trigger update @@ -88,18 +88,20 @@ class AsyncUpdateJobIntTest { jobScheduler.triggerJobs(); // verify the classification modified timestamp is after 'before' - ResponseEntity repeatedResponse = + ResponseEntity repeatedResponse = template.exchange( restHelper.toUrl(Mapping.URL_CLASSIFICATIONS_ID, CLASSIFICATION_ID), HttpMethod.GET, new HttpEntity(restHelper.getHeaders()), - ParameterizedTypeReference.forType(ClassificationResource.class)); + ParameterizedTypeReference.forType(ClassificationRepresentationModel.class)); assertThat(repeatedResponse.getBody()).isNotNull(); - ClassificationResource modifiedClassificationResource = repeatedResponse.getBody(); + ClassificationRepresentationModel modifiedClassificationRepresentationModel = + repeatedResponse.getBody(); Classification modifiedClassification = - classificationResourceAssembler.toModel(modifiedClassificationResource); + classificationRepresentationModelAssembler.toEntityModel( + modifiedClassificationRepresentationModel); assertThat(before).isBefore(modifiedClassification.getModified()); @@ -151,15 +153,15 @@ class AsyncUpdateJobIntTest { private void verifyTaskIsModifiedAfterOrEquals(String taskId, Instant before) throws InvalidArgumentException { - ResponseEntity taskResponse = + ResponseEntity taskResponse = template.exchange( restHelper.toUrl(Mapping.URL_TASKS_ID, taskId), HttpMethod.GET, new HttpEntity<>(restHelper.getHeadersAdmin()), - ParameterizedTypeReference.forType(TaskResource.class)); + ParameterizedTypeReference.forType(TaskRepresentationModel.class)); - TaskResource taskResource = taskResponse.getBody(); - Task task = taskResourceAssembler.toModel(taskResource); + TaskRepresentationModel taskRepresentationModel = taskResponse.getBody(); + Task task = taskRepresentationModelAssembler.toEntityModel(taskRepresentationModel); Instant modified = task.getModified(); assertThat(before).as("Task " + task.getId() + " has not been refreshed.").isBefore(modified); diff --git a/rest/taskana-rest-spring-example-common/src/test/java/pro/taskana/ldap/LdapTest.java b/rest/taskana-rest-spring-example-common/src/test/java/pro/taskana/ldap/LdapTest.java index 709fa9be0..cbf920183 100644 --- a/rest/taskana-rest-spring-example-common/src/test/java/pro/taskana/ldap/LdapTest.java +++ b/rest/taskana-rest-spring-example-common/src/test/java/pro/taskana/ldap/LdapTest.java @@ -13,7 +13,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; import pro.taskana.common.api.LoggerUtils; import pro.taskana.common.api.exceptions.InvalidArgumentException; import pro.taskana.rest.RestConfiguration; -import pro.taskana.rest.resource.AccessIdResource; +import pro.taskana.rest.resource.AccessIdRepresentationModel; /** Test Ldap attachment. */ @ActiveProfiles({"test"}) @@ -28,7 +28,7 @@ class LdapTest { @Test void testFindUsers() throws InvalidArgumentException { if (ldapClient.useLdap()) { - List usersAndGroups = ldapClient.searchUsersAndGroups("ser0"); + List usersAndGroups = ldapClient.searchUsersAndGroups("ser0"); System.out.println("#### found " + LoggerUtils.listToString(usersAndGroups)); assertThat(usersAndGroups).hasSize(50); } diff --git a/rest/taskana-rest-spring-example-wildfly/src/test/java/pro/taskana/TaskanaWildflyTest.java b/rest/taskana-rest-spring-example-wildfly/src/test/java/pro/taskana/TaskanaWildflyTest.java index 3e964b223..36c3dda46 100644 --- a/rest/taskana-rest-spring-example-wildfly/src/test/java/pro/taskana/TaskanaWildflyTest.java +++ b/rest/taskana-rest-spring-example-wildfly/src/test/java/pro/taskana/TaskanaWildflyTest.java @@ -22,11 +22,10 @@ import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; -import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.web.client.RestTemplate; -import pro.taskana.rest.resource.TaskanaUserInfoResource; +import pro.taskana.rest.resource.TaskanaUserInfoRepresentationModel; /** * This test class is configured to run with postgres DB if you want to run it with h2 it is needed. @@ -59,14 +58,14 @@ public class TaskanaWildflyTest { public void shouldGetStatusOK() { HttpHeaders headers = new HttpHeaders(); - HttpEntity request = new HttpEntity(headers); - ResponseEntity response = + HttpEntity request = new HttpEntity<>(headers); + ResponseEntity response = getRestTemplate() .exchange( "http://127.0.0.1:" + "8090" + "/api/v1/current-user-info", HttpMethod.GET, request, - ParameterizedTypeReference.forType(TaskanaUserInfoResource.class)); + ParameterizedTypeReference.forType(TaskanaUserInfoRepresentationModel.class)); assertEquals(HttpStatus.OK, response.getStatusCode()); } @@ -78,8 +77,6 @@ public class TaskanaWildflyTest { converter.setSupportedMediaTypes(MediaType.parseMediaTypes("application/json")); converter.setObjectMapper(mapper); - RestTemplate template = - new RestTemplate(Collections.>singletonList(converter)); - return template; + return new RestTemplate(Collections.singletonList(converter)); } } diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/ldap/LdapCache.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/ldap/LdapCache.java index d7b237adf..112cba764 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/ldap/LdapCache.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/ldap/LdapCache.java @@ -2,7 +2,7 @@ package pro.taskana.ldap; import java.util.List; -import pro.taskana.rest.resource.AccessIdResource; +import pro.taskana.rest.resource.AccessIdRepresentationModel; /** * This interface is used for caching Ldap data. @@ -20,7 +20,8 @@ public interface LdapCache { * @return a List of access ids for users and group where the name or id contains the search * string. */ - List findMatchingAccessId(String searchFor, int maxNumberOfReturnedAccessIds); + List findMatchingAccessId( + String searchFor, int maxNumberOfReturnedAccessIds); /** * Find the groups belong to a user. @@ -29,7 +30,8 @@ public interface LdapCache { * @param maxNumberOfReturnedAccessIds the maximum number of results to return. * @return a List of access ids for groups of users. */ - List findGroupsOfUser(String searchFor, int maxNumberOfReturnedAccessIds); + List findGroupsOfUser( + String searchFor, int maxNumberOfReturnedAccessIds); /** * Validate a access id. @@ -37,5 +39,5 @@ public interface LdapCache { * @param accessId the search string. * @return the corresponding access ids. */ - List validateAccessId(String accessId); + List validateAccessId(String accessId); } diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/ldap/LdapClient.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/ldap/LdapClient.java index db08f4599..98c3d9aeb 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/ldap/LdapClient.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/ldap/LdapClient.java @@ -2,6 +2,7 @@ package pro.taskana.ldap; import java.util.ArrayList; import java.util.Arrays; +import java.util.Comparator; import java.util.List; import java.util.Objects; import java.util.regex.Pattern; @@ -24,7 +25,7 @@ import org.springframework.stereotype.Component; import pro.taskana.common.api.LoggerUtils; import pro.taskana.common.api.exceptions.InvalidArgumentException; import pro.taskana.common.api.exceptions.SystemException; -import pro.taskana.rest.resource.AccessIdResource; +import pro.taskana.rest.resource.AccessIdRepresentationModel; /** * Class for Ldap access. @@ -62,15 +63,15 @@ public class LdapClient { * maxNumberOfReturnedAccessIds * @throws InvalidArgumentException if input is shorter than minSearchForLength */ - public List searchUsersAndGroups(final String name) + public List searchUsersAndGroups(final String name) throws InvalidArgumentException { LOGGER.debug("entry to searchUsersAndGroups(name = {})", name); isInitOrFail(); testMinSearchForLength(name); - List accessIds = new ArrayList<>(); + List accessIds = new ArrayList<>(); if (nameIsDn(name)) { - AccessIdResource groupByDn = searchGroupByDn(name); + AccessIdRepresentationModel groupByDn = searchGroupByDn(name); if (groupByDn != null) { accessIds.add(groupByDn); } @@ -79,7 +80,7 @@ public class LdapClient { accessIds.addAll(searchGroupsByName(name)); } sortListOfAccessIdResources(accessIds); - List result = getFirstPageOfaResultList(accessIds); + List result = getFirstPageOfaResultList(accessIds); LOGGER.debug( "exit from searchUsersAndGroups(name = {}). Returning {} users and groups: {}", @@ -90,7 +91,7 @@ public class LdapClient { return result; } - public List searchUsersByName(final String name) + public List searchUsersByName(final String name) throws InvalidArgumentException { LOGGER.debug("entry to searchUsersByName(name = {}).", name); isInitOrFail(); @@ -109,7 +110,7 @@ public class LdapClient { getUserFirstnameAttribute(), getUserLastnameAttribute(), getUserIdAttribute() }; - final List accessIds = + final List accessIds = ldapTemplate.search( getUserSearchBase(), andFilter.encode(), @@ -122,7 +123,7 @@ public class LdapClient { return accessIds; } - public List searchGroupsByName(final String name) + public List searchGroupsByName(final String name) throws InvalidArgumentException { LOGGER.debug("entry to searchGroupsByName(name = {}).", name); isInitOrFail(); @@ -137,7 +138,7 @@ public class LdapClient { } andFilter.and(orFilter); - final List accessIds = + final List accessIds = ldapTemplate.search( getGroupSearchBase(), andFilter.encode(), @@ -150,7 +151,7 @@ public class LdapClient { return accessIds; } - public AccessIdResource searchGroupByDn(final String name) { + public AccessIdRepresentationModel searchGroupByDn(final String name) { LOGGER.debug("entry to searchGroupByDn(name = {}).", name); isInitOrFail(); // Obviously Spring LdapTemplate does have a inconsistency and always adds the base name to the @@ -160,14 +161,14 @@ public class LdapClient { String nameWithoutBaseDn = getNameWithoutBaseDn(name); LOGGER.debug( "Removed baseDN {} from given DN. New DN to be used: {}", getBaseDn(), nameWithoutBaseDn); - final AccessIdResource accessId = + final AccessIdRepresentationModel accessId = ldapTemplate.lookup( nameWithoutBaseDn, getLookUpGoupAttributesToReturn(), new GroupContextMapper()); LOGGER.debug("Exit from searchGroupByDn. Retrieved the following group: {}", accessId); return accessId; } - public List searchGroupsofUsersIsMember(final String name) + public List searchGroupsofUsersIsMember(final String name) throws InvalidArgumentException { LOGGER.debug("entry to searchGroupsofUsersIsMember(name = {}).", name); isInitOrFail(); @@ -179,7 +180,7 @@ public class LdapClient { String[] userAttributesToReturn = {getUserIdAttribute(), getGroupNameAttribute()}; - final List accessIds = + final List accessIds = ldapTemplate.search( getGroupSearchBase(), andFilter.encode(), @@ -278,7 +279,8 @@ public class LdapClient { return name.toLowerCase().endsWith(getBaseDn().toLowerCase()); } - List getFirstPageOfaResultList(List accessIds) { + List getFirstPageOfaResultList( + List accessIds) { return accessIds.subList(0, Math.min(accessIds.size(), maxNumberOfReturnedAccessIds)); } @@ -288,10 +290,10 @@ public class LdapClient { } } - void sortListOfAccessIdResources(List accessIds) { + void sortListOfAccessIdResources(List accessIds) { accessIds.sort( - (AccessIdResource a, AccessIdResource b) -> - a.getAccessId().compareToIgnoreCase(b.getAccessId())); + Comparator.comparing( + AccessIdRepresentationModel::getAccessId, String.CASE_INSENSITIVE_ORDER)); } String getNameWithoutBaseDn(String name) { @@ -357,11 +359,11 @@ public class LdapClient { } /** Context Mapper for user entries. */ - class GroupContextMapper extends AbstractContextMapper { + class GroupContextMapper extends AbstractContextMapper { @Override - public AccessIdResource doMapFromContext(final DirContextOperations context) { - final AccessIdResource accessId = new AccessIdResource(); + public AccessIdRepresentationModel doMapFromContext(final DirContextOperations context) { + final AccessIdRepresentationModel accessId = new AccessIdRepresentationModel(); String dn = getDnWithBaseDn(context.getDn().toString()); accessId.setAccessId(dn); // fully qualified dn accessId.setName(context.getStringAttribute(getGroupNameAttribute())); @@ -370,11 +372,11 @@ public class LdapClient { } /** Context Mapper for user entries. */ - class UserContextMapper extends AbstractContextMapper { + class UserContextMapper extends AbstractContextMapper { @Override - public AccessIdResource doMapFromContext(final DirContextOperations context) { - final AccessIdResource accessId = new AccessIdResource(); + public AccessIdRepresentationModel doMapFromContext(final DirContextOperations context) { + final AccessIdRepresentationModel accessId = new AccessIdRepresentationModel(); accessId.setAccessId(context.getStringAttribute(getUserIdAttribute())); String firstName = context.getStringAttribute(getUserFirstnameAttribute()); String lastName = context.getStringAttribute(getUserLastnameAttribute()); diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/AbstractPagingController.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/AbstractPagingController.java index 804b4e377..5a55df799 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/AbstractPagingController.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/AbstractPagingController.java @@ -3,11 +3,11 @@ package pro.taskana.rest; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.springframework.hateoas.PagedModel.PageMetadata; import org.springframework.util.MultiValueMap; import pro.taskana.common.api.BaseQuery; import pro.taskana.common.api.exceptions.InvalidArgumentException; -import pro.taskana.rest.resource.PagedResources.PageMetadata; /** Abstract superclass for taskana REST controller with pageable resources. */ public abstract class AbstractPagingController { diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/AccessIdController.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/AccessIdController.java index 9417e27bf..b26cd480e 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/AccessIdController.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/AccessIdController.java @@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.RestController; import pro.taskana.common.api.exceptions.InvalidArgumentException; import pro.taskana.ldap.LdapCache; import pro.taskana.ldap.LdapClient; -import pro.taskana.rest.resource.AccessIdResource; +import pro.taskana.rest.resource.AccessIdRepresentationModel; /** * Controller for access id validation. @@ -30,7 +30,7 @@ public class AccessIdController { @Autowired LdapClient ldapClient; @GetMapping(path = Mapping.URL_ACCESSID) - public ResponseEntity> validateAccessIds( + public ResponseEntity> validateAccessIds( @RequestParam("search-for") String searchFor) throws InvalidArgumentException { LOGGER.debug("Entry to validateAccessIds(search-for= {})", searchFor); if (searchFor.length() < ldapClient.getMinSearchForLength()) { @@ -40,9 +40,9 @@ public class AccessIdController { + "' is too short. Minimum searchFor length = " + ldapClient.getMinSearchForLength()); } - ResponseEntity> response; + ResponseEntity> response; if (ldapClient.useLdap()) { - List accessIdUsers = ldapClient.searchUsersAndGroups(searchFor); + List accessIdUsers = ldapClient.searchUsersAndGroups(searchFor); response = ResponseEntity.ok(accessIdUsers); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Exit from validateAccessIds(), returning {}", response); @@ -67,7 +67,7 @@ public class AccessIdController { } @GetMapping(path = Mapping.URL_ACCESSID_GROUPS) - public ResponseEntity> getGroupsByAccessId( + public ResponseEntity> getGroupsByAccessId( @RequestParam("access-id") String accessId) throws InvalidArgumentException { LOGGER.debug("Entry to getGroupsByAccessId(access-id= {})", accessId); if (ldapClient.useLdap() || ldapCache != null) { @@ -75,8 +75,8 @@ public class AccessIdController { throw new InvalidArgumentException("The accessId is invalid"); } } - List accessIdUsers; - ResponseEntity> response; + List accessIdUsers; + ResponseEntity> response; if (ldapClient.useLdap()) { accessIdUsers = ldapClient.searchUsersAndGroups(accessId); accessIdUsers.addAll(ldapClient.searchGroupsofUsersIsMember(accessId)); diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/ClassificationController.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/ClassificationController.java index e34f0056a..ab4ad5faf 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/ClassificationController.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/ClassificationController.java @@ -4,6 +4,7 @@ import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.hateoas.MediaTypes; +import org.springframework.hateoas.PagedModel.PageMetadata; import org.springframework.hateoas.config.EnableHypermediaSupport; import org.springframework.hateoas.config.EnableHypermediaSupport.HypermediaType; import org.springframework.http.HttpStatus; @@ -31,11 +32,11 @@ import pro.taskana.common.api.exceptions.ConcurrencyException; import pro.taskana.common.api.exceptions.DomainNotFoundException; import pro.taskana.common.api.exceptions.InvalidArgumentException; import pro.taskana.common.api.exceptions.NotAuthorizedException; -import pro.taskana.rest.resource.ClassificationResource; -import pro.taskana.rest.resource.ClassificationResourceAssembler; -import pro.taskana.rest.resource.ClassificationSummaryListResource; -import pro.taskana.rest.resource.ClassificationSummaryResourceAssembler; -import pro.taskana.rest.resource.PagedResources.PageMetadata; +import pro.taskana.rest.resource.ClassificationRepresentationModel; +import pro.taskana.rest.resource.ClassificationRepresentationModelAssembler; +import pro.taskana.rest.resource.ClassificationSummaryRepresentationModel; +import pro.taskana.rest.resource.ClassificationSummaryRepresentationModelAssembler; +import pro.taskana.rest.resource.TaskanaPagedModel; /** Controller for all {@link Classification} related endpoints. */ @RestController @@ -78,39 +79,45 @@ public class ClassificationController extends AbstractPagingController { private static final String SORT_DIRECTION = "order"; - private ClassificationService classificationService; + private final ClassificationService classificationService; - private ClassificationResourceAssembler classificationResourceAssembler; + private final ClassificationRepresentationModelAssembler + classificationRepresentationModelAssembler; - private ClassificationSummaryResourceAssembler classificationSummaryResourceAssembler; + private final ClassificationSummaryRepresentationModelAssembler + classificationSummaryRepresentationModelAssembler; ClassificationController( ClassificationService classificationService, - ClassificationResourceAssembler classificationResourceAssembler, - ClassificationSummaryResourceAssembler classificationSummaryResourceAssembler) { + ClassificationRepresentationModelAssembler classificationRepresentationModelAssembler, + ClassificationSummaryRepresentationModelAssembler + classificationSummaryRepresentationModelAssembler) { this.classificationService = classificationService; - this.classificationResourceAssembler = classificationResourceAssembler; - this.classificationSummaryResourceAssembler = classificationSummaryResourceAssembler; + this.classificationRepresentationModelAssembler = classificationRepresentationModelAssembler; + this.classificationSummaryRepresentationModelAssembler = + classificationSummaryRepresentationModelAssembler; } @GetMapping(path = Mapping.URL_CLASSIFICATIONS) @Transactional(readOnly = true, rollbackFor = Exception.class) - public ResponseEntity getClassifications( - @RequestParam MultiValueMap params) throws InvalidArgumentException { + public ResponseEntity> + getClassifications( + @RequestParam MultiValueMap params) + throws InvalidArgumentException { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Entry to getClassifications(params= {})", params); } ClassificationQuery query = classificationService.createClassificationQuery(); query = applySortingParams(query, params); - query = applyFilterParams(query, params); + applyFilterParams(query, params); PageMetadata pageMetadata = getPageMetadata(params, query); List classificationSummaries = getQueryList(query, pageMetadata); - ResponseEntity response = + ResponseEntity> response = ResponseEntity.ok( - classificationSummaryResourceAssembler.toCollectionModel( + classificationSummaryRepresentationModelAssembler.toPageModel( classificationSummaries, pageMetadata)); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Exit from getClassifications(), returning {}", response); @@ -121,15 +128,15 @@ public class ClassificationController extends AbstractPagingController { @GetMapping(path = Mapping.URL_CLASSIFICATIONS_ID, produces = MediaTypes.HAL_JSON_VALUE) @Transactional(readOnly = true, rollbackFor = Exception.class) - public ResponseEntity getClassification( + public ResponseEntity getClassification( @PathVariable String classificationId) throws ClassificationNotFoundException { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Entry to getClassification(classificationId= {})", classificationId); } Classification classification = classificationService.getClassification(classificationId); - ResponseEntity response = - ResponseEntity.ok(classificationResourceAssembler.toModel(classification)); + ResponseEntity response = + ResponseEntity.ok(classificationRepresentationModelAssembler.toModel(classification)); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Exit from getClassification(), returning {}", response); } @@ -139,19 +146,20 @@ public class ClassificationController extends AbstractPagingController { @PostMapping(path = Mapping.URL_CLASSIFICATIONS) @Transactional(rollbackFor = Exception.class) - public ResponseEntity createClassification( - @RequestBody ClassificationResource resource) + public ResponseEntity createClassification( + @RequestBody ClassificationRepresentationModel resource) throws NotAuthorizedException, ClassificationAlreadyExistException, DomainNotFoundException, InvalidArgumentException { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Entry to createClassification(resource= {})", resource); } - Classification classification = classificationResourceAssembler.toModel(resource); + Classification classification = classificationRepresentationModelAssembler + .toEntityModel(resource); classification = classificationService.createClassification(classification); - ResponseEntity response = + ResponseEntity response = ResponseEntity.status(HttpStatus.CREATED) - .body(classificationResourceAssembler.toModel(classification)); + .body(classificationRepresentationModelAssembler.toModel(classification)); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Exit from createClassification(), returning {}", response); } @@ -161,9 +169,9 @@ public class ClassificationController extends AbstractPagingController { @PutMapping(path = Mapping.URL_CLASSIFICATIONS_ID) @Transactional(rollbackFor = Exception.class) - public ResponseEntity updateClassification( + public ResponseEntity updateClassification( @PathVariable(value = "classificationId") String classificationId, - @RequestBody ClassificationResource resource) + @RequestBody ClassificationRepresentationModel resource) throws NotAuthorizedException, ClassificationNotFoundException, ConcurrencyException, InvalidArgumentException { if (LOGGER.isDebugEnabled()) { @@ -173,11 +181,13 @@ public class ClassificationController extends AbstractPagingController { resource); } - ResponseEntity result; + ResponseEntity result; if (classificationId.equals(resource.getClassificationId())) { - Classification classification = classificationResourceAssembler.toModel(resource); + Classification classification = classificationRepresentationModelAssembler + .toEntityModel(resource); classification = classificationService.updateClassification(classification); - result = ResponseEntity.ok(classificationResourceAssembler.toModel(classification)); + result = + ResponseEntity.ok(classificationRepresentationModelAssembler.toModel(classification)); } else { throw new InvalidArgumentException( "ClassificationId ('" @@ -247,7 +257,7 @@ public class ClassificationController extends AbstractPagingController { return query; } - private ClassificationQuery applyFilterParams( + private void applyFilterParams( ClassificationQuery query, MultiValueMap params) throws InvalidArgumentException { if (LOGGER.isDebugEnabled()) { @@ -320,6 +330,5 @@ public class ClassificationController extends AbstractPagingController { LOGGER.debug("Exit from applyFilterParams(), returning {}", query); } - return query; } } diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/ClassificationDefinitionController.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/ClassificationDefinitionController.java index 4e6887eff..256012d6d 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/ClassificationDefinitionController.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/ClassificationDefinitionController.java @@ -34,8 +34,8 @@ import pro.taskana.common.api.exceptions.ConcurrencyException; import pro.taskana.common.api.exceptions.DomainNotFoundException; import pro.taskana.common.api.exceptions.InvalidArgumentException; import pro.taskana.common.api.exceptions.NotAuthorizedException; -import pro.taskana.rest.resource.ClassificationResource; -import pro.taskana.rest.resource.ClassificationResourceAssembler; +import pro.taskana.rest.resource.ClassificationRepresentationModel; +import pro.taskana.rest.resource.ClassificationRepresentationModelAssembler; /** Controller for Importing / Exporting classifications. */ @SuppressWarnings("unused") @@ -48,34 +48,34 @@ public class ClassificationDefinitionController { private ClassificationService classificationService; - private ClassificationResourceAssembler classificationResourceAssembler; + private ClassificationRepresentationModelAssembler classificationRepresentationModelAssembler; ClassificationDefinitionController( ClassificationService classificationService, - ClassificationResourceAssembler classificationResourceAssembler) { + ClassificationRepresentationModelAssembler classificationRepresentationModelAssembler) { this.classificationService = classificationService; - this.classificationResourceAssembler = classificationResourceAssembler; + this.classificationRepresentationModelAssembler = classificationRepresentationModelAssembler; } @GetMapping(path = Mapping.URL_CLASSIFICATIONDEFINITION) @Transactional(readOnly = true, rollbackFor = Exception.class) - public ResponseEntity> exportClassifications( + public ResponseEntity> exportClassifications( @RequestParam(required = false) String domain) throws ClassificationNotFoundException { LOGGER.debug("Entry to exportClassifications(domain= {})", domain); ClassificationQuery query = classificationService.createClassificationQuery(); List summaries = domain != null ? query.domainIn(domain).list() : query.list(); - List export = new ArrayList<>(); + List export = new ArrayList<>(); for (ClassificationSummary summary : summaries) { Classification classification = classificationService.getClassification(summary.getKey(), summary.getDomain()); - export.add(classificationResourceAssembler.toDefinition(classification)); + export.add(classificationRepresentationModelAssembler.toModel(classification)); } - ResponseEntity> response = ResponseEntity.ok(export); + ResponseEntity> response = ResponseEntity.ok(export); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Exit from exportClassifications(), returning {}", response); } @@ -91,7 +91,7 @@ public class ClassificationDefinitionController { DomainNotFoundException, IOException { LOGGER.debug("Entry to importClassifications()"); Map systemIds = getSystemIds(); - List classificationsResources = + List classificationsResources = extractClassificationResourcesFromFile(file); checkForDuplicates(classificationsResources); @@ -110,18 +110,18 @@ public class ClassificationDefinitionController { Collectors.toMap(i -> i.getKey() + "|" + i.getDomain(), ClassificationSummary::getId)); } - private List extractClassificationResourcesFromFile(MultipartFile file) - throws IOException { + private List extractClassificationResourcesFromFile( + MultipartFile file) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); return mapper.readValue( - file.getInputStream(), new TypeReference>() {}); + file.getInputStream(), new TypeReference>() {}); } - private void checkForDuplicates(List classificationList) { + private void checkForDuplicates(List classificationList) { List identifiers = new ArrayList<>(); Set duplicates = new HashSet<>(); - for (ClassificationResource classification : classificationList) { + for (ClassificationRepresentationModel classification : classificationList) { String identifier = classification.getKey() + "|" + classification.getDomain(); if (identifiers.contains(identifier)) { duplicates.add(identifier); @@ -136,19 +136,20 @@ public class ClassificationDefinitionController { } private Map mapChildrenToParentKeys( - List classificationResources, Map systemIds) { + List classificationRepresentationModels, + Map systemIds) { LOGGER.debug("Entry to mapChildrenToParentKeys()"); Map childrenInFile = new HashMap<>(); Set newKeysWithDomain = new HashSet<>(); - classificationResources.forEach( + classificationRepresentationModels.forEach( cl -> newKeysWithDomain.add(cl.getKey() + "|" + cl.getDomain())); - for (ClassificationResource cl : classificationResources) { + for (ClassificationRepresentationModel cl : classificationRepresentationModels) { cl.setParentId(cl.getParentId() == null ? "" : cl.getParentId()); cl.setParentKey(cl.getParentKey() == null ? "" : cl.getParentKey()); if (!cl.getParentId().equals("") && cl.getParentKey().equals("")) { - for (ClassificationResource parent : classificationResources) { + for (ClassificationRepresentationModel parent : classificationRepresentationModels) { if (cl.getParentId().equals(parent.getClassificationId())) { cl.setParentKey(parent.getKey()); } @@ -159,7 +160,8 @@ public class ClassificationDefinitionController { if (!cl.getParentKey().isEmpty() && !cl.getParentKey().equals("")) { if (newKeysWithDomain.contains(parentKeyAndDomain) || systemIds.containsKey(parentKeyAndDomain)) { - childrenInFile.put(classificationResourceAssembler.toModel(cl), cl.getParentKey()); + childrenInFile.put( + classificationRepresentationModelAssembler.toEntityModel(cl), cl.getParentKey()); } } } @@ -173,23 +175,29 @@ public class ClassificationDefinitionController { } private void insertOrUpdateClassificationsWithoutParent( - List classificationResources, Map systemIds) + List classificationRepresentationModels, + Map systemIds) throws ClassificationNotFoundException, NotAuthorizedException, InvalidArgumentException, ClassificationAlreadyExistException, DomainNotFoundException, ConcurrencyException { LOGGER.debug("Entry to insertOrUpdateClassificationsWithoutParent()"); - for (ClassificationResource classificationResource : classificationResources) { - classificationResource.setParentKey(null); - classificationResource.setParentId(null); - classificationResource.setClassificationId(null); + for (ClassificationRepresentationModel classificationRepresentationModel : + classificationRepresentationModels) { + classificationRepresentationModel.setParentKey(null); + classificationRepresentationModel.setParentId(null); + classificationRepresentationModel.setClassificationId(null); String systemId = - systemIds.get(classificationResource.getKey() + "|" + classificationResource.getDomain()); + systemIds.get( + classificationRepresentationModel.getKey() + + "|" + + classificationRepresentationModel.getDomain()); if (systemId != null) { - updateExistingClassification(classificationResource, systemId); + updateExistingClassification(classificationRepresentationModel, systemId); } else { classificationService.createClassification( - classificationResourceAssembler.toModel(classificationResource)); + classificationRepresentationModelAssembler + .toEntityModel(classificationRepresentationModel)); } } LOGGER.debug("Exit from insertOrUpdateClassificationsWithoutParent()"); @@ -221,7 +229,7 @@ public class ClassificationDefinitionController { LOGGER.debug("Exit from updateParentChildrenRelations()"); } - private void updateExistingClassification(ClassificationResource cl, String systemId) + private void updateExistingClassification(ClassificationRepresentationModel cl, String systemId) throws ClassificationNotFoundException, NotAuthorizedException, ConcurrencyException, InvalidArgumentException { LOGGER.debug("Entry to updateExistingClassification()"); diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/MonitorController.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/MonitorController.java index 17ef0f469..6a1904bf2 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/MonitorController.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/MonitorController.java @@ -19,8 +19,8 @@ import pro.taskana.common.api.exceptions.InvalidArgumentException; import pro.taskana.common.api.exceptions.NotAuthorizedException; import pro.taskana.monitor.api.MonitorService; import pro.taskana.monitor.api.reports.header.TimeIntervalColumnHeader; -import pro.taskana.rest.resource.ReportResource; -import pro.taskana.rest.resource.ReportResourceAssembler; +import pro.taskana.rest.resource.ReportRepresentationModel; +import pro.taskana.rest.resource.ReportRepresentationModelAssembler; import pro.taskana.task.api.TaskState; /** Controller for all monitoring endpoints. */ @@ -32,24 +32,25 @@ public class MonitorController { private MonitorService monitorService; - private ReportResourceAssembler reportResourceAssembler; + private ReportRepresentationModelAssembler reportRepresentationModelAssembler; MonitorController( - MonitorService monitorService, ReportResourceAssembler reportResourceAssembler) { + MonitorService monitorService, + ReportRepresentationModelAssembler reportRepresentationModelAssembler) { this.monitorService = monitorService; - this.reportResourceAssembler = reportResourceAssembler; + this.reportRepresentationModelAssembler = reportRepresentationModelAssembler; } @GetMapping(path = Mapping.URL_MONITOR_TASKSSTATUS) @Transactional(readOnly = true, rollbackFor = Exception.class) - public ResponseEntity getTasksStatusReport( + public ResponseEntity getTasksStatusReport( @RequestParam(required = false) List domains, @RequestParam(required = false) List states) throws NotAuthorizedException, InvalidArgumentException { LOGGER.debug("Entry to getTasksStatusReport()"); - ResponseEntity response = + ResponseEntity response = ResponseEntity.ok( - reportResourceAssembler.toModel( + reportRepresentationModelAssembler.toModel( monitorService .createTaskStatusReportBuilder() .stateIn(states) @@ -71,8 +72,8 @@ public class MonitorController { throws NotAuthorizedException, InvalidArgumentException { LOGGER.debug("Entry to getTasksWorkbasketReport()"); - ReportResource report = - reportResourceAssembler.toModel( + ReportRepresentationModel report = + reportRepresentationModelAssembler.toModel( monitorService .createWorkbasketReportBuilder() .withColumnHeaders(getRangeTimeInterval()) @@ -94,8 +95,8 @@ public class MonitorController { throws NotAuthorizedException, InvalidArgumentException { LOGGER.debug("Entry to getTasksWorkbasketPlannedDateReport()"); - ReportResource report = - reportResourceAssembler.toModel( + ReportRepresentationModel report = + reportRepresentationModelAssembler.toModel( monitorService .createWorkbasketReportBuilder() .stateIn(states) @@ -112,12 +113,12 @@ public class MonitorController { @GetMapping(path = Mapping.URL_MONITOR_TASKSCLASSIFICATION) @Transactional(readOnly = true, rollbackFor = Exception.class) - public ResponseEntity getTasksClassificationReport() + public ResponseEntity getTasksClassificationReport() throws NotAuthorizedException, InvalidArgumentException { LOGGER.debug("Entry to getTasksClassificationReport()"); - ReportResource report = - reportResourceAssembler.toModel( + ReportRepresentationModel report = + reportRepresentationModelAssembler.toModel( monitorService .createClassificationReportBuilder() .withColumnHeaders(getRangeTimeInterval()) @@ -132,7 +133,7 @@ public class MonitorController { @GetMapping(path = Mapping.URL_MONITOR_TIMESTAMP) @Transactional(readOnly = true, rollbackFor = Exception.class) - public ResponseEntity getDailyEntryExitReport() + public ResponseEntity getDailyEntryExitReport() throws NotAuthorizedException, InvalidArgumentException { List columnHeaders = IntStream.range(-14, 0) @@ -140,7 +141,7 @@ public class MonitorController { .collect(Collectors.toList()); return ResponseEntity.status(HttpStatus.OK) .body( - reportResourceAssembler.toModel( + reportRepresentationModelAssembler.toModel( monitorService .createTimestampReportBuilder() .withColumnHeaders(columnHeaders) diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/TaskCommentController.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/TaskCommentController.java index e5213a5bc..e6fa9911f 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/TaskCommentController.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/TaskCommentController.java @@ -19,9 +19,9 @@ import org.springframework.web.bind.annotation.RestController; import pro.taskana.common.api.exceptions.ConcurrencyException; import pro.taskana.common.api.exceptions.InvalidArgumentException; import pro.taskana.common.api.exceptions.NotAuthorizedException; -import pro.taskana.rest.resource.TaskCommentListResource; -import pro.taskana.rest.resource.TaskCommentResource; -import pro.taskana.rest.resource.TaskCommentResourceAssembler; +import pro.taskana.rest.resource.TaskCommentRepresentationModel; +import pro.taskana.rest.resource.TaskCommentRepresentationModelAssembler; +import pro.taskana.rest.resource.TaskanaPagedModel; import pro.taskana.task.api.TaskService; import pro.taskana.task.api.exceptions.TaskCommentNotFoundException; import pro.taskana.task.api.exceptions.TaskNotFoundException; @@ -35,17 +35,19 @@ public class TaskCommentController { private static final Logger LOGGER = LoggerFactory.getLogger(TaskCommentController.class); private TaskService taskService; - private TaskCommentResourceAssembler taskCommentResourceAssembler; + private TaskCommentRepresentationModelAssembler taskCommentRepresentationModelAssembler; TaskCommentController( - TaskService taskService, TaskCommentResourceAssembler taskCommentResourceAssembler) { + TaskService taskService, + TaskCommentRepresentationModelAssembler taskCommentRepresentationModelAssembler) { this.taskService = taskService; - this.taskCommentResourceAssembler = taskCommentResourceAssembler; + this.taskCommentRepresentationModelAssembler = taskCommentRepresentationModelAssembler; } @GetMapping(path = Mapping.URL_TASK_COMMENT) @Transactional(readOnly = true, rollbackFor = Exception.class) - public ResponseEntity getTaskComment(@PathVariable String taskCommentId) + public ResponseEntity getTaskComment( + @PathVariable String taskCommentId) throws NotAuthorizedException, TaskNotFoundException, TaskCommentNotFoundException, InvalidArgumentException { if (LOGGER.isDebugEnabled()) { @@ -54,9 +56,11 @@ public class TaskCommentController { TaskComment taskComment = taskService.getTaskComment(taskCommentId); - TaskCommentResource taskCommentResource = taskCommentResourceAssembler.toModel(taskComment); + TaskCommentRepresentationModel taskCommentRepresentationModel = + taskCommentRepresentationModelAssembler.toModel(taskComment); - ResponseEntity response = ResponseEntity.ok(taskCommentResource); + ResponseEntity response = + ResponseEntity.ok(taskCommentRepresentationModel); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Exit from getTaskComment(), returning {}", response); @@ -67,18 +71,19 @@ public class TaskCommentController { @GetMapping(path = Mapping.URL_TASK_GET_POST_COMMENTS) @Transactional(readOnly = true, rollbackFor = Exception.class) - public ResponseEntity getTaskComments(@PathVariable String taskId) - throws NotAuthorizedException, TaskNotFoundException { + public ResponseEntity> getTaskComments( + @PathVariable String taskId) throws NotAuthorizedException, TaskNotFoundException { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Entry to getTaskComments(taskId= {})", taskId); } List taskComments = taskService.getTaskComments(taskId); - TaskCommentListResource taskCommentListResource = - taskCommentResourceAssembler.toListResource(taskComments); + TaskanaPagedModel taskCommentListResource = + taskCommentRepresentationModelAssembler.toPageModel(taskComments, null); - ResponseEntity response = ResponseEntity.ok(taskCommentListResource); + ResponseEntity> response = + ResponseEntity.ok(taskCommentListResource); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Exit from getTaskComments(), returning {}", response); @@ -89,7 +94,8 @@ public class TaskCommentController { @DeleteMapping(path = Mapping.URL_TASK_COMMENT) @Transactional(readOnly = true, rollbackFor = Exception.class) - public ResponseEntity deleteTaskComment(@PathVariable String taskCommentId) + public ResponseEntity deleteTaskComment( + @PathVariable String taskCommentId) throws NotAuthorizedException, TaskNotFoundException, TaskCommentNotFoundException, InvalidArgumentException { if (LOGGER.isDebugEnabled()) { @@ -98,7 +104,7 @@ public class TaskCommentController { taskService.deleteTaskComment(taskCommentId); - ResponseEntity result = ResponseEntity.noContent().build(); + ResponseEntity result = ResponseEntity.noContent().build(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Exit from deleteTaskComment(), returning {}", result); @@ -109,25 +115,27 @@ public class TaskCommentController { @PutMapping(path = Mapping.URL_TASK_COMMENT) @Transactional(readOnly = true, rollbackFor = Exception.class) - public ResponseEntity updateTaskComment( - @PathVariable String taskCommentId, @RequestBody TaskCommentResource taskCommentResource) + public ResponseEntity updateTaskComment( + @PathVariable String taskCommentId, + @RequestBody TaskCommentRepresentationModel taskCommentRepresentationModel) throws NotAuthorizedException, TaskNotFoundException, TaskCommentNotFoundException, InvalidArgumentException, ConcurrencyException { if (LOGGER.isDebugEnabled()) { LOGGER.debug( "Entry to updateTaskComment(taskCommentId= {}, taskCommentResource= {})", taskCommentId, - taskCommentResource); + taskCommentRepresentationModel); } - ResponseEntity result = null; + ResponseEntity result = null; - if ((taskCommentId.equals(taskCommentResource.getTaskCommentId()))) { + if ((taskCommentId.equals(taskCommentRepresentationModel.getTaskCommentId()))) { - TaskComment taskComment = taskCommentResourceAssembler.toModel(taskCommentResource); + TaskComment taskComment = + taskCommentRepresentationModelAssembler.toEntityModel(taskCommentRepresentationModel); taskComment = taskService.updateTaskComment(taskComment); - result = ResponseEntity.ok(taskCommentResourceAssembler.toModel(taskComment)); + result = ResponseEntity.ok(taskCommentRepresentationModelAssembler.toModel(taskComment)); } else { throw new InvalidArgumentException( String.format( @@ -145,27 +153,29 @@ public class TaskCommentController { @PostMapping(path = Mapping.URL_TASK_GET_POST_COMMENTS) @Transactional(rollbackFor = Exception.class) - public ResponseEntity createTaskComment( - @PathVariable String taskId, @RequestBody TaskCommentResource taskCommentResource) + public ResponseEntity createTaskComment( + @PathVariable String taskId, + @RequestBody TaskCommentRepresentationModel taskCommentRepresentationModel) throws NotAuthorizedException, InvalidArgumentException, TaskNotFoundException { if (LOGGER.isDebugEnabled()) { LOGGER.debug( "Entry to createTaskComment(taskId= {}, taskCommentResource= {})", taskId, - taskCommentResource); + taskCommentRepresentationModel); } - taskCommentResource.setTaskId(taskId); + taskCommentRepresentationModel.setTaskId(taskId); - TaskComment taskCommentFromResource = taskCommentResourceAssembler.toModel(taskCommentResource); + TaskComment taskCommentFromResource = + taskCommentRepresentationModelAssembler.toEntityModel(taskCommentRepresentationModel); TaskComment createdTaskComment = taskService.createTaskComment(taskCommentFromResource); - ResponseEntity result; + ResponseEntity result; result = ResponseEntity.status(HttpStatus.CREATED) - .body(taskCommentResourceAssembler.toModel(createdTaskComment)); + .body(taskCommentRepresentationModelAssembler.toModel(createdTaskComment)); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Exit from createTaskComment(), returning {}", result); diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/TaskController.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/TaskController.java index 5070bf61e..3d6b912b9 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/TaskController.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/TaskController.java @@ -7,6 +7,7 @@ import java.util.Objects; import java.util.stream.Stream; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.hateoas.PagedModel.PageMetadata; import org.springframework.hateoas.config.EnableHypermediaSupport; import org.springframework.hateoas.config.EnableHypermediaSupport.HypermediaType; import org.springframework.http.HttpStatus; @@ -29,11 +30,11 @@ import pro.taskana.common.api.TimeInterval; import pro.taskana.common.api.exceptions.ConcurrencyException; import pro.taskana.common.api.exceptions.InvalidArgumentException; import pro.taskana.common.api.exceptions.NotAuthorizedException; -import pro.taskana.rest.resource.PagedResources.PageMetadata; -import pro.taskana.rest.resource.TaskResource; -import pro.taskana.rest.resource.TaskResourceAssembler; -import pro.taskana.rest.resource.TaskSummaryListResource; -import pro.taskana.rest.resource.TaskSummaryResourceAssembler; +import pro.taskana.rest.resource.TaskRepresentationModel; +import pro.taskana.rest.resource.TaskRepresentationModelAssembler; +import pro.taskana.rest.resource.TaskSummaryRepresentationModel; +import pro.taskana.rest.resource.TaskSummaryRepresentationModelAssembler; +import pro.taskana.rest.resource.TaskanaPagedModel; import pro.taskana.task.api.TaskQuery; import pro.taskana.task.api.TaskService; import pro.taskana.task.api.TaskState; @@ -90,22 +91,22 @@ public class TaskController extends AbstractPagingController { private TaskService taskService; - private TaskResourceAssembler taskResourceAssembler; + private TaskRepresentationModelAssembler taskRepresentationModelAssembler; - private TaskSummaryResourceAssembler taskSummaryResourceAssembler; + private TaskSummaryRepresentationModelAssembler taskSummaryRepresentationModelAssembler; TaskController( TaskService taskService, - TaskResourceAssembler taskResourceAssembler, - TaskSummaryResourceAssembler taskSummaryResourceAssembler) { + TaskRepresentationModelAssembler taskRepresentationModelAssembler, + TaskSummaryRepresentationModelAssembler taskSummaryRepresentationModelAssembler) { this.taskService = taskService; - this.taskResourceAssembler = taskResourceAssembler; - this.taskSummaryResourceAssembler = taskSummaryResourceAssembler; + this.taskRepresentationModelAssembler = taskRepresentationModelAssembler; + this.taskSummaryRepresentationModelAssembler = taskSummaryRepresentationModelAssembler; } @GetMapping(path = Mapping.URL_TASKS) @Transactional(readOnly = true, rollbackFor = Exception.class) - public ResponseEntity getTasks( + public ResponseEntity> getTasks( @RequestParam MultiValueMap params) throws InvalidArgumentException { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Entry to getTasks(params= {})", params); @@ -118,9 +119,10 @@ public class TaskController extends AbstractPagingController { PageMetadata pageMetadata = getPageMetadata(params, query); List taskSummaries = getQueryList(query, pageMetadata); - TaskSummaryListResource pagedResources = - taskSummaryResourceAssembler.toCollectionModel(taskSummaries, pageMetadata); - ResponseEntity response = ResponseEntity.ok(pagedResources); + TaskanaPagedModel pagedModels = + taskSummaryRepresentationModelAssembler.toPageModel(taskSummaries, pageMetadata); + ResponseEntity> response = + ResponseEntity.ok(pagedModels); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Exit from getTasks(), returning {}", response); } @@ -130,11 +132,12 @@ public class TaskController extends AbstractPagingController { @GetMapping(path = Mapping.URL_TASKS_ID) @Transactional(readOnly = true, rollbackFor = Exception.class) - public ResponseEntity getTask(@PathVariable String taskId) + public ResponseEntity getTask(@PathVariable String taskId) throws TaskNotFoundException, NotAuthorizedException { LOGGER.debug("Entry to getTask(taskId= {})", taskId); Task task = taskService.getTask(taskId); - ResponseEntity result = ResponseEntity.ok(taskResourceAssembler.toModel(task)); + ResponseEntity result = + ResponseEntity.ok(taskRepresentationModelAssembler.toModel(task)); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Exit from getTask(), returning {}", result); } @@ -144,7 +147,7 @@ public class TaskController extends AbstractPagingController { @PostMapping(path = Mapping.URL_TASKS_ID_CLAIM) @Transactional(rollbackFor = Exception.class) - public ResponseEntity claimTask( + public ResponseEntity claimTask( @PathVariable String taskId, @RequestBody String userName) throws TaskNotFoundException, InvalidStateException, InvalidOwnerException, NotAuthorizedException { @@ -152,8 +155,8 @@ public class TaskController extends AbstractPagingController { // TODO verify user taskService.claim(taskId); Task updatedTask = taskService.getTask(taskId); - ResponseEntity result = - ResponseEntity.ok(taskResourceAssembler.toModel(updatedTask)); + ResponseEntity result = + ResponseEntity.ok(taskRepresentationModelAssembler.toModel(updatedTask)); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Exit from claimTask(), returning {}", result); } @@ -163,7 +166,7 @@ public class TaskController extends AbstractPagingController { @DeleteMapping(path = Mapping.URL_TASKS_ID_CLAIM) @Transactional(rollbackFor = Exception.class) - public ResponseEntity cancelClaimTask(@PathVariable String taskId) + public ResponseEntity cancelClaimTask(@PathVariable String taskId) throws TaskNotFoundException, InvalidStateException, InvalidOwnerException, NotAuthorizedException { @@ -172,8 +175,8 @@ public class TaskController extends AbstractPagingController { taskService.cancelClaim(taskId); Task updatedTask = taskService.getTask(taskId); - ResponseEntity result = - ResponseEntity.ok(taskResourceAssembler.toModel(updatedTask)); + ResponseEntity result = + ResponseEntity.ok(taskRepresentationModelAssembler.toModel(updatedTask)); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Exit from cancelClaimTask(), returning {}", result); } @@ -182,14 +185,14 @@ public class TaskController extends AbstractPagingController { @PostMapping(path = Mapping.URL_TASKS_ID_COMPLETE) @Transactional(rollbackFor = Exception.class) - public ResponseEntity completeTask(@PathVariable String taskId) + public ResponseEntity completeTask(@PathVariable String taskId) throws TaskNotFoundException, InvalidOwnerException, InvalidStateException, NotAuthorizedException { LOGGER.debug("Entry to completeTask(taskId= {})", taskId); taskService.forceCompleteTask(taskId); Task updatedTask = taskService.getTask(taskId); - ResponseEntity result = - ResponseEntity.ok(taskResourceAssembler.toModel(updatedTask)); + ResponseEntity result = + ResponseEntity.ok(taskRepresentationModelAssembler.toModel(updatedTask)); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Exit from completeTask(), returning {}", result); } @@ -199,29 +202,31 @@ public class TaskController extends AbstractPagingController { @DeleteMapping(path = Mapping.URL_TASKS_ID) @Transactional(rollbackFor = Exception.class) - public ResponseEntity deleteTask(@PathVariable String taskId) + public ResponseEntity deleteTask(@PathVariable String taskId) throws TaskNotFoundException, InvalidStateException, NotAuthorizedException { LOGGER.debug("Entry to deleteTask(taskId= {})", taskId); taskService.forceDeleteTask(taskId); - ResponseEntity result = ResponseEntity.noContent().build(); + ResponseEntity result = ResponseEntity.noContent().build(); LOGGER.debug("Exit from deleteTask(), returning {}", result); return result; } @PostMapping(path = Mapping.URL_TASKS) @Transactional(rollbackFor = Exception.class) - public ResponseEntity createTask(@RequestBody TaskResource taskResource) + public ResponseEntity createTask( + @RequestBody TaskRepresentationModel taskRepresentationModel) throws WorkbasketNotFoundException, ClassificationNotFoundException, NotAuthorizedException, TaskAlreadyExistException, InvalidArgumentException { if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Entry to createTask(params= {})", taskResource); + LOGGER.debug("Entry to createTask(params= {})", taskRepresentationModel); } - Task fromResource = taskResourceAssembler.toModel(taskResource); + Task fromResource = taskRepresentationModelAssembler.toEntityModel(taskRepresentationModel); Task createdTask = taskService.createTask(fromResource); - ResponseEntity result = - ResponseEntity.status(HttpStatus.CREATED).body(taskResourceAssembler.toModel(createdTask)); + ResponseEntity result = + ResponseEntity.status(HttpStatus.CREATED) + .body(taskRepresentationModelAssembler.toModel(createdTask)); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Exit from createTask(), returning {}", result); } @@ -231,14 +236,14 @@ public class TaskController extends AbstractPagingController { @PostMapping(path = Mapping.URL_TASKS_ID_TRANSFER_WORKBASKETID) @Transactional(rollbackFor = Exception.class) - public ResponseEntity transferTask( + public ResponseEntity transferTask( @PathVariable String taskId, @PathVariable String workbasketId) throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException, InvalidStateException { LOGGER.debug("Entry to transferTask(taskId= {}, workbasketId= {})", taskId, workbasketId); Task updatedTask = taskService.transfer(taskId, workbasketId); - ResponseEntity result = - ResponseEntity.ok(taskResourceAssembler.toModel(updatedTask)); + ResponseEntity result = + ResponseEntity.ok(taskRepresentationModelAssembler.toModel(updatedTask)); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Exit from transferTask(), returning {}", result); } @@ -248,23 +253,25 @@ public class TaskController extends AbstractPagingController { @PutMapping(path = Mapping.URL_TASKS_ID) @Transactional(rollbackFor = Exception.class) - public ResponseEntity updateTask( - @PathVariable(value = "taskId") String taskId, @RequestBody TaskResource taskResource) + public ResponseEntity updateTask( + @PathVariable(value = "taskId") String taskId, + @RequestBody TaskRepresentationModel taskRepresentationModel) throws TaskNotFoundException, ClassificationNotFoundException, InvalidArgumentException, ConcurrencyException, NotAuthorizedException, AttachmentPersistenceException, InvalidStateException { - LOGGER.debug("Entry to updateTask(taskId= {}, taskResource= {})", taskId, taskResource); - ResponseEntity result; - if (taskId.equals(taskResource.getTaskId())) { - Task task = taskResourceAssembler.toModel(taskResource); + LOGGER.debug( + "Entry to updateTask(taskId= {}, taskResource= {})", taskId, taskRepresentationModel); + ResponseEntity result; + if (taskId.equals(taskRepresentationModel.getTaskId())) { + Task task = taskRepresentationModelAssembler.toEntityModel(taskRepresentationModel); task = taskService.updateTask(task); - result = ResponseEntity.ok(taskResourceAssembler.toModel(task)); + result = ResponseEntity.ok(taskRepresentationModelAssembler.toModel(task)); } else { throw new InvalidArgumentException( String.format( "TaskId ('%s') is not identical with the taskId of to " + "object in the payload which should be updated. ID=('%s')", - taskId, taskResource.getTaskId())); + taskId, taskRepresentationModel.getTaskId())); } if (LOGGER.isDebugEnabled()) { diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/TaskanaEngineController.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/TaskanaEngineController.java index e3c2cec69..7de5a3a43 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/TaskanaEngineController.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/TaskanaEngineController.java @@ -14,8 +14,8 @@ import pro.taskana.TaskanaEngineConfiguration; import pro.taskana.common.api.TaskanaEngine; import pro.taskana.common.api.TaskanaRole; import pro.taskana.common.internal.security.CurrentUserContext; -import pro.taskana.rest.resource.TaskanaUserInfoResource; -import pro.taskana.rest.resource.VersionResource; +import pro.taskana.rest.resource.TaskanaUserInfoRepresentationModel; +import pro.taskana.rest.resource.VersionRepresentationModel; /** Controller for TaskanaEngine related tasks. */ @RestController @@ -24,9 +24,9 @@ public class TaskanaEngineController { private static final Logger LOGGER = LoggerFactory.getLogger(TaskanaEngineController.class); - private TaskanaEngineConfiguration taskanaEngineConfiguration; + private final TaskanaEngineConfiguration taskanaEngineConfiguration; - private TaskanaEngine taskanaEngine; + private final TaskanaEngine taskanaEngine; @Value("${version:Local build}") private String version; @@ -87,9 +87,9 @@ public class TaskanaEngineController { } @GetMapping(path = Mapping.URL_CURRENT_USER) - public ResponseEntity getCurrentUserInfo() { + public ResponseEntity getCurrentUserInfo() { LOGGER.debug("Entry to getCurrentUserInfo()"); - TaskanaUserInfoResource resource = new TaskanaUserInfoResource(); + TaskanaUserInfoRepresentationModel resource = new TaskanaUserInfoRepresentationModel(); resource.setUserId(CurrentUserContext.getUserid()); resource.setGroupIds(CurrentUserContext.getGroupIds()); for (TaskanaRole role : taskanaEngineConfiguration.getRoleMap().keySet()) { @@ -97,7 +97,7 @@ public class TaskanaEngineController { resource.getRoles().add(role); } } - ResponseEntity response = ResponseEntity.ok(resource); + ResponseEntity response = ResponseEntity.ok(resource); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Exit from getCurrentUserInfo(), returning {}", response); } @@ -118,11 +118,11 @@ public class TaskanaEngineController { * @return The current version. */ @GetMapping(path = Mapping.URL_VERSION) - public ResponseEntity currentVersion() { + public ResponseEntity currentVersion() { LOGGER.debug("Entry to currentVersion()"); - VersionResource resource = new VersionResource(); + VersionRepresentationModel resource = new VersionRepresentationModel(); resource.setVersion(TaskanaEngineConfiguration.class.getPackage().getImplementationVersion()); - ResponseEntity response = ResponseEntity.ok(resource); + ResponseEntity response = ResponseEntity.ok(resource); LOGGER.debug("Exit from currentVersion(), returning {}", response); return response; } diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/WorkbasketAccessItemController.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/WorkbasketAccessItemController.java index 8111eb756..864c6ee2a 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/WorkbasketAccessItemController.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/WorkbasketAccessItemController.java @@ -6,6 +6,7 @@ import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.hateoas.PagedModel.PageMetadata; import org.springframework.hateoas.config.EnableHypermediaSupport; import org.springframework.http.ResponseEntity; import org.springframework.util.MultiValueMap; @@ -18,9 +19,9 @@ import pro.taskana.common.api.BaseQuery; import pro.taskana.common.api.exceptions.InvalidArgumentException; import pro.taskana.common.api.exceptions.NotAuthorizedException; import pro.taskana.ldap.LdapClient; -import pro.taskana.rest.resource.PagedResources.PageMetadata; -import pro.taskana.rest.resource.WorkbasketAccessItemListResource; -import pro.taskana.rest.resource.WorkbasketAccessItemResourceAssembler; +import pro.taskana.rest.resource.TaskanaPagedModel; +import pro.taskana.rest.resource.WorkbasketAccessItemRepresentationModel; +import pro.taskana.rest.resource.WorkbasketAccessItemRepresentationModelAssembler; import pro.taskana.workbasket.api.WorkbasketAccessItemQuery; import pro.taskana.workbasket.api.WorkbasketService; import pro.taskana.workbasket.api.models.WorkbasketAccessItem; @@ -43,22 +44,35 @@ public class WorkbasketAccessItemController extends AbstractPagingController { private static final String SORT_BY = "sort-by"; private static final String SORT_DIRECTION = "order"; - @Autowired LdapClient ldapClient; + final LdapClient ldapClient; - @Autowired private WorkbasketService workbasketService; + private final WorkbasketService workbasketService; - @Autowired private WorkbasketAccessItemResourceAssembler workbasketAccessItemResourceAssembler; + private final WorkbasketAccessItemRepresentationModelAssembler + workbasketAccessItemRepresentationModelAssembler; + + @Autowired + public WorkbasketAccessItemController( + LdapClient ldapClient, WorkbasketService workbasketService, + WorkbasketAccessItemRepresentationModelAssembler + workbasketAccessItemRepresentationModelAssembler) { + this.ldapClient = ldapClient; + this.workbasketService = workbasketService; + this.workbasketAccessItemRepresentationModelAssembler + = workbasketAccessItemRepresentationModelAssembler; + } /** * This GET method return all workbasketAccessItems that correspond the given data. * * @param params filter, order and access ids. * @return all WorkbasketAccesItemResource. - * @throws NotAuthorizedException if the user is not authorized. + * @throws NotAuthorizedException if the user is not authorized. * @throws InvalidArgumentException if some argument is invalid. */ @GetMapping(path = Mapping.URL_WORKBASKETACCESSITEMS) - public ResponseEntity getWorkbasketAccessItems( + public ResponseEntity> + getWorkbasketAccessItems( @RequestParam MultiValueMap params) throws NotAuthorizedException, InvalidArgumentException { if (LOGGER.isDebugEnabled()) { @@ -66,18 +80,19 @@ public class WorkbasketAccessItemController extends AbstractPagingController { } WorkbasketAccessItemQuery query = workbasketService.createWorkbasketAccessItemQuery(); - query = getAccessIds(query, params); - query = applyFilterParams(query, params); + getAccessIds(query, params); + applyFilterParams(query, params); query = applySortingParams(query, params); PageMetadata pageMetadata = getPageMetadata(params, query); List workbasketAccessItems = getQueryList(query, pageMetadata); - WorkbasketAccessItemListResource pagedResources = - workbasketAccessItemResourceAssembler.toCollectionModel( + TaskanaPagedModel pagedResources = + workbasketAccessItemRepresentationModelAssembler.toPageModel( workbasketAccessItems, pageMetadata); - ResponseEntity response = ResponseEntity.ok(pagedResources); + ResponseEntity> response = + ResponseEntity.ok(pagedResources); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Exit from getWorkbasketAccessItems(), returning {}", response); } @@ -118,7 +133,7 @@ public class WorkbasketAccessItemController extends AbstractPagingController { return response; } - private WorkbasketAccessItemQuery getAccessIds( + private void getAccessIds( WorkbasketAccessItemQuery query, MultiValueMap params) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Entry to getAccessIds(query= {}, params= {})", params); @@ -134,10 +149,9 @@ public class WorkbasketAccessItemController extends AbstractPagingController { LOGGER.debug("Exit from getAccessIds(), returning {}", query); } - return query; } - private WorkbasketAccessItemQuery applyFilterParams( + private void applyFilterParams( WorkbasketAccessItemQuery query, MultiValueMap params) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Entry to applyFilterParams(query= {}, params= {})", params); @@ -165,7 +179,6 @@ public class WorkbasketAccessItemController extends AbstractPagingController { LOGGER.debug("Exit from applyFilterParams(), returning {}", query); } - return query; } private WorkbasketAccessItemQuery applySortingParams( diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/WorkbasketController.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/WorkbasketController.java index fa9e2cd0e..090eef61c 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/WorkbasketController.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/WorkbasketController.java @@ -4,8 +4,8 @@ import java.util.ArrayList; import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.hateoas.CollectionModel; import org.springframework.hateoas.MediaTypes; +import org.springframework.hateoas.PagedModel.PageMetadata; import org.springframework.hateoas.config.EnableHypermediaSupport; import org.springframework.hateoas.config.EnableHypermediaSupport.HypermediaType; import org.springframework.http.HttpStatus; @@ -27,17 +27,14 @@ import pro.taskana.common.api.exceptions.ConcurrencyException; import pro.taskana.common.api.exceptions.DomainNotFoundException; import pro.taskana.common.api.exceptions.InvalidArgumentException; import pro.taskana.common.api.exceptions.NotAuthorizedException; -import pro.taskana.rest.resource.DistributionTargetListResource; -import pro.taskana.rest.resource.DistributionTargetResource; -import pro.taskana.rest.resource.DistributionTargetResourceAssembler; -import pro.taskana.rest.resource.PagedResources.PageMetadata; -import pro.taskana.rest.resource.WorkbasketAccessItemListResource; -import pro.taskana.rest.resource.WorkbasketAccessItemResource; -import pro.taskana.rest.resource.WorkbasketAccessItemResourceAssembler; -import pro.taskana.rest.resource.WorkbasketResource; -import pro.taskana.rest.resource.WorkbasketResourceAssembler; -import pro.taskana.rest.resource.WorkbasketSummaryListResource; -import pro.taskana.rest.resource.WorkbasketSummaryResourceAssembler; +import pro.taskana.rest.resource.DistributionTargetRepresentationModelAssembler; +import pro.taskana.rest.resource.TaskanaPagedModel; +import pro.taskana.rest.resource.WorkbasketAccessItemRepresentationModel; +import pro.taskana.rest.resource.WorkbasketAccessItemRepresentationModelAssembler; +import pro.taskana.rest.resource.WorkbasketRepresentationModel; +import pro.taskana.rest.resource.WorkbasketRepresentationModelAssembler; +import pro.taskana.rest.resource.WorkbasketSummaryRepresentationModel; +import pro.taskana.rest.resource.WorkbasketSummaryRepresentationModelAssembler; import pro.taskana.workbasket.api.WorkbasketPermission; import pro.taskana.workbasket.api.WorkbasketQuery; import pro.taskana.workbasket.api.WorkbasketService; @@ -74,32 +71,39 @@ public class WorkbasketController extends AbstractPagingController { private static final String SORT_BY = "sort-by"; private static final String SORT_DIRECTION = "order"; - private WorkbasketService workbasketService; + private final WorkbasketService workbasketService; - private WorkbasketResourceAssembler workbasketResourceAssembler; + private final WorkbasketRepresentationModelAssembler workbasketRepresentationModelAssembler; - private WorkbasketSummaryResourceAssembler workbasketSummaryResourceAssembler; + private final WorkbasketSummaryRepresentationModelAssembler + workbasketSummaryRepresentationModelAssembler; - private DistributionTargetResourceAssembler distributionTargetResourceAssembler; + private final DistributionTargetRepresentationModelAssembler + distributionTargetRepresentationModelAssembler; - private WorkbasketAccessItemResourceAssembler workbasketAccessItemResourceAssembler; + private final WorkbasketAccessItemRepresentationModelAssembler + workbasketAccessItemRepresentationModelAssembler; WorkbasketController( WorkbasketService workbasketService, - WorkbasketResourceAssembler workbasketResourceAssembler, - WorkbasketSummaryResourceAssembler workbasketSummaryResourceAssembler, - DistributionTargetResourceAssembler distributionTargetResourceAssembler, - WorkbasketAccessItemResourceAssembler workbasketAccessItemResourceAssembler) { + WorkbasketRepresentationModelAssembler workbasketRepresentationModelAssembler, + WorkbasketSummaryRepresentationModelAssembler workbasketSummaryRepresentationModelAssembler, + DistributionTargetRepresentationModelAssembler distributionTargetRepresentationModelAssembler, + WorkbasketAccessItemRepresentationModelAssembler + workbasketAccessItemRepresentationModelAssembler) { this.workbasketService = workbasketService; - this.workbasketResourceAssembler = workbasketResourceAssembler; - this.workbasketSummaryResourceAssembler = workbasketSummaryResourceAssembler; - this.distributionTargetResourceAssembler = distributionTargetResourceAssembler; - this.workbasketAccessItemResourceAssembler = workbasketAccessItemResourceAssembler; + this.workbasketRepresentationModelAssembler = workbasketRepresentationModelAssembler; + this.workbasketSummaryRepresentationModelAssembler = + workbasketSummaryRepresentationModelAssembler; + this.distributionTargetRepresentationModelAssembler = + distributionTargetRepresentationModelAssembler; + this.workbasketAccessItemRepresentationModelAssembler = + workbasketAccessItemRepresentationModelAssembler; } @GetMapping(path = Mapping.URL_WORKBASKET) @Transactional(readOnly = true, rollbackFor = Exception.class) - public ResponseEntity getWorkbaskets( + public ResponseEntity> getWorkbaskets( @RequestParam MultiValueMap params) throws InvalidArgumentException { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Entry to getWorkbaskets(params= {})", params); @@ -107,14 +111,16 @@ public class WorkbasketController extends AbstractPagingController { WorkbasketQuery query = workbasketService.createWorkbasketQuery(); query = applySortingParams(query, params); - query = applyFilterParams(query, params); + applyFilterParams(query, params); PageMetadata pageMetadata = getPageMetadata(params, query); List workbasketSummaries = getQueryList(query, pageMetadata); - WorkbasketSummaryListResource pagedResources = - workbasketSummaryResourceAssembler.toCollectionModel(workbasketSummaries, pageMetadata); + TaskanaPagedModel pagedModels = + workbasketSummaryRepresentationModelAssembler.toPageModel( + workbasketSummaries, pageMetadata); - ResponseEntity response = ResponseEntity.ok(pagedResources); + ResponseEntity> response = + ResponseEntity.ok(pagedModels); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Exit from getWorkbaskets(), returning {}", response); } @@ -124,13 +130,13 @@ public class WorkbasketController extends AbstractPagingController { @GetMapping(path = Mapping.URL_WORKBASKET_ID, produces = MediaTypes.HAL_JSON_VALUE) @Transactional(readOnly = true, rollbackFor = Exception.class) - public ResponseEntity getWorkbasket( + public ResponseEntity getWorkbasket( @PathVariable(value = "workbasketId") String workbasketId) throws WorkbasketNotFoundException, NotAuthorizedException { LOGGER.debug("Entry to getWorkbasket(workbasketId= {})", workbasketId); - ResponseEntity result; + ResponseEntity result; Workbasket workbasket = workbasketService.getWorkbasket(workbasketId); - result = ResponseEntity.ok(workbasketResourceAssembler.toModel(workbasket)); + result = ResponseEntity.ok(workbasketRepresentationModelAssembler.toModel(workbasket)); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Exit from getWorkbasket(), returning {}", result); } @@ -164,19 +170,21 @@ public class WorkbasketController extends AbstractPagingController { @PostMapping(path = Mapping.URL_WORKBASKET) @Transactional(rollbackFor = Exception.class) - public ResponseEntity createWorkbasket( - @RequestBody WorkbasketResource workbasketResource) + public ResponseEntity createWorkbasket( + @RequestBody WorkbasketRepresentationModel workbasketRepresentationModel) throws InvalidWorkbasketException, NotAuthorizedException, WorkbasketAlreadyExistException, DomainNotFoundException { if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Entry to createWorkbasket(workbasketResource= {})", workbasketResource); + LOGGER.debug( + "Entry to createWorkbasket(workbasketResource= {})", workbasketRepresentationModel); } - Workbasket workbasket = workbasketResourceAssembler.toModel(workbasketResource); + Workbasket workbasket = + workbasketRepresentationModelAssembler.toEntityModel(workbasketRepresentationModel); workbasket = workbasketService.createWorkbasket(workbasket); - ResponseEntity response = + ResponseEntity response = ResponseEntity.status(HttpStatus.CREATED) - .body(workbasketResourceAssembler.toModel(workbasket)); + .body(workbasketRepresentationModelAssembler.toModel(workbasket)); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Exit from createWorkbasket(), returning {}", response); } @@ -186,23 +194,24 @@ public class WorkbasketController extends AbstractPagingController { @PutMapping(path = Mapping.URL_WORKBASKET_ID) @Transactional(rollbackFor = Exception.class) - public ResponseEntity updateWorkbasket( + public ResponseEntity updateWorkbasket( @PathVariable(value = "workbasketId") String workbasketId, - @RequestBody WorkbasketResource workbasketResource) + @RequestBody WorkbasketRepresentationModel workbasketRepresentationModel) throws InvalidWorkbasketException, WorkbasketNotFoundException, NotAuthorizedException, ConcurrencyException { LOGGER.debug("Entry to updateWorkbasket(workbasketId= {})", workbasketId); - ResponseEntity result; - if (workbasketId.equals(workbasketResource.getWorkbasketId())) { - Workbasket workbasket = workbasketResourceAssembler.toModel(workbasketResource); + ResponseEntity result; + if (workbasketId.equals(workbasketRepresentationModel.getWorkbasketId())) { + Workbasket workbasket = + workbasketRepresentationModelAssembler.toEntityModel(workbasketRepresentationModel); workbasket = workbasketService.updateWorkbasket(workbasket); - result = ResponseEntity.ok(workbasketResourceAssembler.toModel(workbasket)); + result = ResponseEntity.ok(workbasketRepresentationModelAssembler.toModel(workbasket)); } else { throw new InvalidWorkbasketException( "Target-WB-ID('" + workbasketId + "') is not identical with the WB-ID of to object which should be updated. ID=('" - + workbasketResource.getWorkbasketId() + + workbasketRepresentationModel.getWorkbasketId() + "')"); } @@ -215,17 +224,18 @@ public class WorkbasketController extends AbstractPagingController { @GetMapping(path = Mapping.URL_WORKBASKET_ID_ACCESSITEMS, produces = MediaTypes.HAL_JSON_VALUE) @Transactional(readOnly = true, rollbackFor = Exception.class) - public ResponseEntity getWorkbasketAccessItems( - @PathVariable(value = "workbasketId") String workbasketId) + public ResponseEntity> + getWorkbasketAccessItems(@PathVariable(value = "workbasketId") String workbasketId) throws NotAuthorizedException, WorkbasketNotFoundException { LOGGER.debug("Entry to getWorkbasketAccessItems(workbasketId= {})", workbasketId); - ResponseEntity result; + ResponseEntity> result; List accessItems = workbasketService.getWorkbasketAccessItems(workbasketId); result = ResponseEntity.ok( - workbasketAccessItemResourceAssembler.toCollectionModel(workbasketId, accessItems)); + workbasketAccessItemRepresentationModelAssembler.toPageModel( + workbasketId, accessItems, null)); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Exit from getWorkbasketAccessItems(), returning {}", result); } @@ -235,11 +245,12 @@ public class WorkbasketController extends AbstractPagingController { @PutMapping(path = Mapping.URL_WORKBASKET_ID_ACCESSITEMS) @Transactional(rollbackFor = Exception.class) - public ResponseEntity setWorkbasketAccessItems( + public ResponseEntity> + setWorkbasketAccessItems( @PathVariable(value = "workbasketId") String workbasketId, - @RequestBody List workbasketAccessResourceItems) + @RequestBody List workbasketAccessResourceItems) throws NotAuthorizedException, InvalidArgumentException, WorkbasketNotFoundException, - WorkbasketAccessItemAlreadyExistException { + WorkbasketAccessItemAlreadyExistException { LOGGER.debug("Entry to setWorkbasketAccessItems(workbasketId= {})", workbasketId); if (workbasketAccessResourceItems == null) { throw new InvalidArgumentException("Can´t create something with NULL body-value."); @@ -247,15 +258,16 @@ public class WorkbasketController extends AbstractPagingController { List wbAccessItems = new ArrayList<>(); workbasketAccessResourceItems.forEach( - item -> wbAccessItems.add(workbasketAccessItemResourceAssembler.toModel(item))); + item -> wbAccessItems + .add(workbasketAccessItemRepresentationModelAssembler.toEntityModel(item))); workbasketService.setWorkbasketAccessItems(workbasketId, wbAccessItems); List updatedWbAccessItems = workbasketService.getWorkbasketAccessItems(workbasketId); - ResponseEntity response = + ResponseEntity> response = ResponseEntity.ok( - workbasketAccessItemResourceAssembler.toCollectionModel( - workbasketId, updatedWbAccessItems)); + workbasketAccessItemRepresentationModelAssembler.toPageModel( + workbasketId, updatedWbAccessItems, null)); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Exit from setWorkbasketAccessItems(), returning {}", response); } @@ -265,16 +277,16 @@ public class WorkbasketController extends AbstractPagingController { @GetMapping(path = Mapping.URL_WORKBASKET_ID_DISTRIBUTION, produces = MediaTypes.HAL_JSON_VALUE) @Transactional(readOnly = true, rollbackFor = Exception.class) - public ResponseEntity getDistributionTargets( - @PathVariable(value = "workbasketId") String workbasketId) + public ResponseEntity> + getDistributionTargets(@PathVariable(value = "workbasketId") String workbasketId) throws WorkbasketNotFoundException, NotAuthorizedException { LOGGER.debug("Entry to getDistributionTargets(workbasketId= {})", workbasketId); List distributionTargets = workbasketService.getDistributionTargets(workbasketId); - DistributionTargetListResource distributionTargetListResource = - distributionTargetResourceAssembler.toCollectionModel(workbasketId, distributionTargets); - ResponseEntity result = + TaskanaPagedModel distributionTargetListResource = + distributionTargetRepresentationModelAssembler.toPageModel(distributionTargets, null); + ResponseEntity> result = ResponseEntity.ok(distributionTargetListResource); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Exit from getDistributionTargets(), returning {}", result); @@ -285,7 +297,8 @@ public class WorkbasketController extends AbstractPagingController { @PutMapping(path = Mapping.URL_WORKBASKET_ID_DISTRIBUTION) @Transactional(rollbackFor = Exception.class) - public ResponseEntity setDistributionTargetsForWorkbasketId( + public ResponseEntity> + setDistributionTargetsForWorkbasketId( @PathVariable(value = "workbasketId") String sourceWorkbasketId, @RequestBody List targetWorkbasketIds) throws WorkbasketNotFoundException, NotAuthorizedException { @@ -300,10 +313,9 @@ public class WorkbasketController extends AbstractPagingController { List distributionTargets = workbasketService.getDistributionTargets(sourceWorkbasketId); - ResponseEntity response = + ResponseEntity> response = ResponseEntity.ok( - distributionTargetResourceAssembler.toCollectionModel( - sourceWorkbasketId, distributionTargets)); + distributionTargetRepresentationModelAssembler.toPageModel(distributionTargets, null)); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Exit from getTasksStatusReport(), returning {}", response); } @@ -313,10 +325,10 @@ public class WorkbasketController extends AbstractPagingController { @DeleteMapping(path = Mapping.URL_WORKBASKET_ID_DISTRIBUTION) @Transactional(rollbackFor = Exception.class) - public ResponseEntity> + public ResponseEntity> removeDistributionTargetForWorkbasketId( - @PathVariable(value = "workbasketId") String targetWorkbasketId) - throws WorkbasketNotFoundException, NotAuthorizedException { + @PathVariable(value = "workbasketId") String targetWorkbasketId) + throws WorkbasketNotFoundException, NotAuthorizedException { LOGGER.debug( "Entry to removeDistributionTargetForWorkbasketId(workbasketId= {})", targetWorkbasketId); @@ -326,7 +338,7 @@ public class WorkbasketController extends AbstractPagingController { workbasketService.removeDistributionTarget(source.getId(), targetWorkbasketId); } - ResponseEntity> response = + ResponseEntity> response = ResponseEntity.noContent().build(); LOGGER.debug("Exit from removeDistributionTargetForWorkbasketId(), returning {}", response); return response; @@ -377,7 +389,7 @@ public class WorkbasketController extends AbstractPagingController { return query; } - private WorkbasketQuery applyFilterParams( + private void applyFilterParams( WorkbasketQuery query, MultiValueMap params) throws InvalidArgumentException { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Entry to applyFilterParams(query= {}, params= {})", query, params); @@ -502,6 +514,5 @@ public class WorkbasketController extends AbstractPagingController { LOGGER.debug("Exit from applyFilterParams(), returning {}", query); } - return query; } } diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/WorkbasketDefinitionController.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/WorkbasketDefinitionController.java index bcf9d1331..ddabf00cc 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/WorkbasketDefinitionController.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/WorkbasketDefinitionController.java @@ -28,9 +28,9 @@ import pro.taskana.common.api.exceptions.ConcurrencyException; import pro.taskana.common.api.exceptions.DomainNotFoundException; import pro.taskana.common.api.exceptions.InvalidArgumentException; import pro.taskana.common.api.exceptions.NotAuthorizedException; -import pro.taskana.rest.resource.WorkbasketDefinitionResource; -import pro.taskana.rest.resource.WorkbasketDefinitionResourceAssembler; -import pro.taskana.rest.resource.WorkbasketResource; +import pro.taskana.rest.resource.WorkbasketDefinitionRepresentationModel; +import pro.taskana.rest.resource.WorkbasketDefinitionRepresentationModelAssembler; +import pro.taskana.rest.resource.WorkbasketRepresentationModel; import pro.taskana.workbasket.api.WorkbasketQuery; import pro.taskana.workbasket.api.WorkbasketService; import pro.taskana.workbasket.api.exceptions.InvalidWorkbasketException; @@ -43,7 +43,7 @@ import pro.taskana.workbasket.api.models.WorkbasketSummary; import pro.taskana.workbasket.internal.models.WorkbasketAccessItemImpl; import pro.taskana.workbasket.internal.models.WorkbasketImpl; -/** Controller for all {@link WorkbasketDefinitionResource} related endpoints. */ +/** Controller for all {@link WorkbasketDefinitionRepresentationModel} related endpoints. */ @RestController @EnableHypermediaSupport(type = EnableHypermediaSupport.HypermediaType.HAL) public class WorkbasketDefinitionController { @@ -53,31 +53,32 @@ public class WorkbasketDefinitionController { private WorkbasketService workbasketService; - private WorkbasketDefinitionResourceAssembler workbasketDefinitionAssembler; + private WorkbasketDefinitionRepresentationModelAssembler workbasketDefinitionAssembler; WorkbasketDefinitionController( WorkbasketService workbasketService, - WorkbasketDefinitionResourceAssembler workbasketDefinitionAssembler) { + WorkbasketDefinitionRepresentationModelAssembler workbasketDefinitionAssembler) { this.workbasketService = workbasketService; this.workbasketDefinitionAssembler = workbasketDefinitionAssembler; } @GetMapping(path = Mapping.URL_WORKBASKETDEFIITIONS) @Transactional(readOnly = true, rollbackFor = Exception.class) - public ResponseEntity> exportWorkbaskets( + public ResponseEntity> exportWorkbaskets( @RequestParam(required = false) String domain) throws NotAuthorizedException, WorkbasketNotFoundException { LOGGER.debug("Entry to exportWorkbaskets(domain= {})", domain); WorkbasketQuery workbasketQuery = workbasketService.createWorkbasketQuery(); List workbasketSummaryList = domain != null ? workbasketQuery.domainIn(domain).list() : workbasketQuery.list(); - List basketExports = new ArrayList<>(); + List basketExports = new ArrayList<>(); for (WorkbasketSummary summary : workbasketSummaryList) { Workbasket workbasket = workbasketService.getWorkbasket(summary.getId()); - basketExports.add(workbasketDefinitionAssembler.toModel(workbasket)); + basketExports.add(workbasketDefinitionAssembler.toEntityModel(workbasket)); } - ResponseEntity> response = ResponseEntity.ok(basketExports); + ResponseEntity> response = + ResponseEntity.ok(basketExports); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Exit from exportWorkbaskets(), returning {}", response); } @@ -86,9 +87,9 @@ public class WorkbasketDefinitionController { } /** - * This method imports a list of {@link WorkbasketDefinitionResource}. This does not - * exactly match the REST norm, but we want to have an option to import all settings at once. When - * a logical equal (key and domain are equal) workbasket already exists an update will be + * This method imports a list of {@link WorkbasketDefinitionRepresentationModel}. This does + * not exactly match the REST norm, but we want to have an option to import all settings at once. + * When a logical equal (key and domain are equal) workbasket already exists an update will be * executed. Otherwise a new workbasket will be created. * * @param file the list of workbasket definitions which will be imported to the current system. @@ -119,9 +120,10 @@ public class WorkbasketDefinitionController { ObjectMapper mapper = new ObjectMapper(); mapper.enable(SerializationFeature.INDENT_OUTPUT); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); - List definitions = + List definitions = mapper.readValue( - file.getInputStream(), new TypeReference>() {}); + file.getInputStream(), + new TypeReference>() {}); // key: logical ID // value: system ID (in database) @@ -135,8 +137,9 @@ public class WorkbasketDefinitionController { Map idConversion = new HashMap<>(); // STEP 1: update or create workbaskets from the import - for (WorkbasketDefinitionResource definition : definitions) { - Workbasket importedWb = workbasketDefinitionAssembler.toModel(definition.getWorkbasket()); + for (WorkbasketDefinitionRepresentationModel definition : definitions) { + Workbasket importedWb = workbasketDefinitionAssembler + .toEntityModel(definition.getWorkbasket()); String newId; WorkbasketImpl wbWithoutId = (WorkbasketImpl) removeId(importedWb); if (systemIds.containsKey(logicalId(importedWb))) { @@ -179,7 +182,7 @@ public class WorkbasketDefinitionController { // STEP 2: update distribution targets // This can not be done in step 1 because the system IDs are only known after step 1 - for (WorkbasketDefinitionResource definition : definitions) { + for (WorkbasketDefinitionRepresentationModel definition : definitions) { List distributionTargets = new ArrayList<>(); for (String oldId : definition.getDistributionTargets()) { if (idConversion.containsKey(oldId)) { @@ -204,17 +207,17 @@ public class WorkbasketDefinitionController { } private Workbasket removeId(Workbasket importedWb) { - WorkbasketResource wbRes = new WorkbasketResource(importedWb); + WorkbasketRepresentationModel wbRes = new WorkbasketRepresentationModel(importedWb); wbRes.setWorkbasketId(null); - return workbasketDefinitionAssembler.toModel(wbRes); + return workbasketDefinitionAssembler.toEntityModel(wbRes); } - private void checkForDuplicates(List definitions) { + private void checkForDuplicates(List definitions) { List identifiers = new ArrayList<>(); Set duplicates = new HashSet<>(); - for (WorkbasketDefinitionResource definition : definitions) { + for (WorkbasketDefinitionRepresentationModel definition : definitions) { String identifier = - logicalId(workbasketDefinitionAssembler.toModel(definition.getWorkbasket())); + logicalId(workbasketDefinitionAssembler.toEntityModel(definition.getWorkbasket())); if (identifiers.contains(identifier)) { duplicates.add(identifier); } else { diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/AbstractRessourcesAssembler.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/AbstractRessourcesAssembler.java index 8b01d4c86..e433fc8ee 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/AbstractRessourcesAssembler.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/AbstractRessourcesAssembler.java @@ -3,6 +3,7 @@ package pro.taskana.rest.resource; import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.springframework.hateoas.Link; +import org.springframework.hateoas.PagedModel.PageMetadata; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.servlet.support.ServletUriComponentsBuilder; @@ -41,7 +42,7 @@ public abstract class AbstractRessourcesAssembler { } protected PagedResources addPageLinks( - PagedResources pagedResources, PagedResources.PageMetadata pageMetadata) { + PagedResources pagedResources, PageMetadata pageMetadata) { UriComponentsBuilder original = getBuilderForOriginalUri(); pagedResources.add( (new Link(original.replaceQueryParam("page", 1).toUriString())).withRel("first")); @@ -51,7 +52,7 @@ public abstract class AbstractRessourcesAssembler { if (pageMetadata.getNumber() > 1L) { pagedResources.add( (new Link( - original.replaceQueryParam("page", pageMetadata.getNumber() - 1L).toUriString())) + original.replaceQueryParam("page", pageMetadata.getNumber() - 1L).toUriString())) .withRel("prev")); } diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/AccessIdResource.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/AccessIdRepresentationModel.java similarity index 79% rename from rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/AccessIdResource.java rename to rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/AccessIdRepresentationModel.java index f35b8d038..b6076f69f 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/AccessIdResource.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/AccessIdRepresentationModel.java @@ -5,14 +5,14 @@ package pro.taskana.rest.resource; * * @author bbr */ -public class AccessIdResource { +public class AccessIdRepresentationModel { private String name; private String accessId; - public AccessIdResource() {} + public AccessIdRepresentationModel() {} - public AccessIdResource(String name, String accessId) { + public AccessIdRepresentationModel(String name, String accessId) { this.accessId = accessId; this.name = name; } diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/AttachmentRepresentationModel.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/AttachmentRepresentationModel.java new file mode 100644 index 000000000..bef02d355 --- /dev/null +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/AttachmentRepresentationModel.java @@ -0,0 +1,54 @@ +package pro.taskana.rest.resource; + +import java.util.HashMap; +import java.util.Map; + +import pro.taskana.task.api.models.Attachment; + +/** + * EntityModel class for {@link Attachment}. + */ +public class AttachmentRepresentationModel + extends AttachmentSummaryRepresentationModel { + + private Map customAttributes = new HashMap<>(); + + public AttachmentRepresentationModel() { + } + + public AttachmentRepresentationModel(Attachment attachment) { + super(attachment); + this.customAttributes = attachment.getCustomAttributes(); + } + + public Map getCustomAttributes() { + return customAttributes; + } + + public void setCustomAttributes(Map customAttributes) { + this.customAttributes = customAttributes; + } + + @Override + public String toString() { + return "AttachmentRepresentationModel [customAttributes=" + + customAttributes + + ", attachmentId=" + + attachmentId + + ", taskId=" + + taskId + + ", created=" + + created + + ", modified=" + + modified + + ", classificationSummaryRepresentationModel=" + + classificationSummary + + ", objectReference=" + + objectReference + + ", channel=" + + channel + + ", received=" + + received + + "]"; + } +} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/AttachmentRepresentationModelAssembler.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/AttachmentRepresentationModelAssembler.java new file mode 100644 index 000000000..7eff6d8c9 --- /dev/null +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/AttachmentRepresentationModelAssembler.java @@ -0,0 +1,56 @@ +package pro.taskana.rest.resource; + +import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo; + +import java.util.List; +import java.util.stream.Collectors; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.hateoas.server.RepresentationModelAssembler; +import org.springframework.lang.NonNull; +import org.springframework.stereotype.Component; + +import pro.taskana.rest.AttachmentController; +import pro.taskana.task.api.TaskService; +import pro.taskana.task.api.models.Attachment; +import pro.taskana.task.internal.models.AttachmentImpl; + +/** + * EntityModel assembler for {@link AttachmentRepresentationModel}. + */ +@Component +public class AttachmentRepresentationModelAssembler + implements RepresentationModelAssembler { + + private final TaskService taskService; + + private final ClassificationSummaryRepresentationModelAssembler classificationAssembler; + + @Autowired + public AttachmentRepresentationModelAssembler(TaskService taskService, + ClassificationSummaryRepresentationModelAssembler classificationAssembler) { + this.taskService = taskService; + this.classificationAssembler = classificationAssembler; + } + + @NonNull + @Override + public AttachmentRepresentationModel toModel(@NonNull Attachment attachment) { + AttachmentRepresentationModel resource = new AttachmentRepresentationModel(attachment); + resource.add(linkTo(AttachmentController.class).slash(attachment.getId()).withSelfRel()); + return resource; + } + + public List toAttachmentList(List resources) { + return resources.stream().map(this::apply).collect(Collectors.toList()); + } + + private AttachmentImpl apply(AttachmentRepresentationModel attachmentRepresentationModel) { + AttachmentImpl attachment = (AttachmentImpl) taskService.newAttachment(); + BeanUtils.copyProperties(attachmentRepresentationModel, attachment); + attachment.setId(attachmentRepresentationModel.getAttachmentId()); + attachment.setClassificationSummary(classificationAssembler.toEntityModel( + attachmentRepresentationModel.getClassificationSummary())); + return attachment; + } +} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/AttachmentResource.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/AttachmentResource.java deleted file mode 100644 index d5ec75854..000000000 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/AttachmentResource.java +++ /dev/null @@ -1,132 +0,0 @@ -package pro.taskana.rest.resource; - -import java.util.HashMap; -import java.util.Map; -import org.springframework.hateoas.RepresentationModel; - -import pro.taskana.task.api.models.Attachment; -import pro.taskana.task.api.models.ObjectReference; - -/** EntityModel class for {@link Attachment}. */ -public class AttachmentResource extends RepresentationModel { - - private String attachmentId; - private String taskId; - private String created; - private String modified; - private ClassificationSummaryResource classificationSummaryResource; - private ObjectReference objectReference; - private String channel; - private String received; - private Map customAttributes = new HashMap(); - - public AttachmentResource() {} - - public AttachmentResource(Attachment attachment) { - this.attachmentId = attachment.getId(); - this.taskId = attachment.getTaskId(); - this.created = attachment.getCreated() != null ? attachment.getCreated().toString() : null; - this.modified = attachment.getModified() != null ? attachment.getModified().toString() : null; - this.classificationSummaryResource = - new ClassificationSummaryResource(attachment.getClassificationSummary()); - this.objectReference = attachment.getObjectReference(); - this.channel = attachment.getChannel(); - this.received = attachment.getReceived() != null ? attachment.getReceived().toString() : null; - this.customAttributes = attachment.getCustomAttributes(); - } - - public String getCreated() { - return created; - } - - public void setCreated(String created) { - this.created = created; - } - - public String getModified() { - return modified; - } - - public void setModified(String modified) { - this.modified = modified; - } - - public String getReceived() { - return received; - } - - public void setReceived(String received) { - this.received = received; - } - - public String getAttachmentId() { - return attachmentId; - } - - public void setAttachmentId(String attachmentId) { - this.attachmentId = attachmentId; - } - - public String getTaskId() { - return taskId; - } - - public void setTaskId(String taskId) { - this.taskId = taskId; - } - - public ClassificationSummaryResource getClassificationSummary() { - return classificationSummaryResource; - } - - public void setClassificationSummary( - ClassificationSummaryResource classificationSummaryResource) { - this.classificationSummaryResource = classificationSummaryResource; - } - - public ObjectReference getObjectReference() { - return objectReference; - } - - public void setObjectReference(ObjectReference objectReference) { - this.objectReference = objectReference; - } - - public String getChannel() { - return channel; - } - - public void setChannel(String channel) { - this.channel = channel; - } - - public Map getCustomAttributes() { - return customAttributes; - } - - public void setCustomAttributes(Map customAttributes) { - this.customAttributes = customAttributes; - } - - @Override - public String toString() { - return "AttachmentResource [" - + "attachmentId= " - + this.attachmentId - + "taskId= " - + this.taskId - + "created= " - + this.created - + "modified= " - + this.modified - + "classificationSummaryResource= " - + this.classificationSummaryResource - + "objectReference= " - + this.objectReference - + "channel= " - + this.channel - + "received= " - + this.received - + "]"; - } -} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/AttachmentResourceAssembler.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/AttachmentResourceAssembler.java deleted file mode 100644 index 400a194f6..000000000 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/AttachmentResourceAssembler.java +++ /dev/null @@ -1,50 +0,0 @@ -package pro.taskana.rest.resource; - -import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo; - -import java.util.List; -import java.util.stream.Collectors; -import org.springframework.beans.BeanUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport; -import org.springframework.stereotype.Component; - -import pro.taskana.rest.AttachmentController; -import pro.taskana.task.api.TaskService; -import pro.taskana.task.api.models.Attachment; -import pro.taskana.task.internal.models.AttachmentImpl; - -/** EntityModel assembler for {@link AttachmentResource}. */ -@Component -public class AttachmentResourceAssembler - extends RepresentationModelAssemblerSupport { - - @Autowired private TaskService taskService; - - @Autowired private ClassificationSummaryResourceAssembler classificationAssembler; - - public AttachmentResourceAssembler() { - super(AttachmentController.class, AttachmentResource.class); - } - - @Override - public AttachmentResource toModel(Attachment attachment) { - AttachmentResource resource = new AttachmentResource(attachment); - resource.add(linkTo(AttachmentController.class).slash(attachment.getId()).withSelfRel()); - return resource; - } - - public List toModel(List resources) { - return resources.stream() - .map( - attachmentResource -> { - AttachmentImpl attachment = (AttachmentImpl) taskService.newAttachment(); - BeanUtils.copyProperties(attachmentResource, attachment); - attachment.setId(attachmentResource.getAttachmentId()); - attachment.setClassificationSummary( - classificationAssembler.toModel(attachmentResource.getClassificationSummary())); - return attachment; - }) - .collect(Collectors.toList()); - } -} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/AttachmentSummaryResource.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/AttachmentSummaryRepresentationModel.java similarity index 55% rename from rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/AttachmentSummaryResource.java rename to rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/AttachmentSummaryRepresentationModel.java index 365361470..040222224 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/AttachmentSummaryResource.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/AttachmentSummaryRepresentationModel.java @@ -5,29 +5,33 @@ import org.springframework.hateoas.RepresentationModel; import pro.taskana.task.api.models.AttachmentSummary; import pro.taskana.task.api.models.ObjectReference; -/** EntityModel class for {@link AttachmentSummary}. */ -public class AttachmentSummaryResource extends RepresentationModel { +/** + * EntityModel class for {@link AttachmentSummary}. + */ +public class AttachmentSummaryRepresentationModel + extends RepresentationModel { - private String attachmentId; - private String taskId; - private String created; - private String modified; - private ClassificationSummaryResource classificationSummaryResource; - private ObjectReference objectReference; - private String channel; - private String received; + protected String attachmentId; + protected String taskId; + protected String created; + protected String modified; + protected ClassificationSummaryRepresentationModel classificationSummary; + protected ObjectReference objectReference; + protected String channel; + protected String received; - AttachmentSummaryResource() {} + AttachmentSummaryRepresentationModel() { + } - public AttachmentSummaryResource(AttachmentSummary attachmentSummary) { + public AttachmentSummaryRepresentationModel(AttachmentSummary attachmentSummary) { this.attachmentId = attachmentSummary.getId(); this.taskId = attachmentSummary.getTaskId(); this.created = attachmentSummary.getCreated() != null ? attachmentSummary.getCreated().toString() : null; this.modified = attachmentSummary.getModified() != null ? attachmentSummary.getModified().toString() : null; - this.classificationSummaryResource = - new ClassificationSummaryResource(attachmentSummary.getClassificationSummary()); + this.classificationSummary = + new ClassificationSummaryRepresentationModel(attachmentSummary.getClassificationSummary()); this.objectReference = attachmentSummary.getObjectReference(); this.channel = attachmentSummary.getChannel(); this.received = @@ -66,13 +70,13 @@ public class AttachmentSummaryResource extends RepresentationModel { + + @NonNull + @Override + public AttachmentSummaryRepresentationModel toModel( + @NonNull AttachmentSummary attachmentSummary) { + return new AttachmentSummaryRepresentationModel(attachmentSummary); + } +} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/AttachmentSummaryResourceAssembler.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/AttachmentSummaryResourceAssembler.java deleted file mode 100644 index 3e7bd181b..000000000 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/AttachmentSummaryResourceAssembler.java +++ /dev/null @@ -1,22 +0,0 @@ -package pro.taskana.rest.resource; - -import org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport; -import org.springframework.stereotype.Component; - -import pro.taskana.rest.AttachmentController; -import pro.taskana.task.api.models.AttachmentSummary; - -/** EntityModel assembler for {@link AttachmentSummaryResource}. */ -@Component -public class AttachmentSummaryResourceAssembler - extends RepresentationModelAssemblerSupport { - - public AttachmentSummaryResourceAssembler() { - super(AttachmentController.class, AttachmentSummaryResource.class); - } - - @Override - public AttachmentSummaryResource toModel(AttachmentSummary attachmentSummary) { - return new AttachmentSummaryResource(attachmentSummary); - } -} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ClassificationRepresentationModel.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ClassificationRepresentationModel.java new file mode 100644 index 000000000..fc0e8af6c --- /dev/null +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ClassificationRepresentationModel.java @@ -0,0 +1,111 @@ +package pro.taskana.rest.resource; + +import pro.taskana.classification.api.models.Classification; + +/** + * EntityModel class for {@link Classification}. + */ +public class ClassificationRepresentationModel + extends ClassificationSummaryRepresentationModel { + + private Boolean isValidInDomain; + private String created; // ISO-8601 + private String modified; // ISO-8601 + private String description; + + public ClassificationRepresentationModel() { + } + + public ClassificationRepresentationModel(Classification classification) { + super(classification); + this.isValidInDomain = classification.getIsValidInDomain(); + this.created = + classification.getCreated() != null ? classification.getCreated().toString() : null; + this.modified = + classification.getModified() != null ? classification.getModified().toString() : null; + this.description = classification.getDescription(); + } + + public Boolean getIsValidInDomain() { + return isValidInDomain; + } + + public void setIsValidInDomain(Boolean validInDomain) { + isValidInDomain = validInDomain; + } + + public String getCreated() { + return created; + } + + public void setCreated(String created) { + this.created = created; + } + + public String getModified() { + return modified; + } + + public void setModified(String modified) { + this.modified = modified; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + @Override + public String toString() { + return "ClassificationResource [classificationId=" + + classificationId + + ", key=" + + key + + ", parentId=" + + parentId + + ", parentKey=" + + parentKey + + ", category=" + + category + + ", type=" + + type + + ", domain=" + + domain + + ", isValidInDomain=" + + isValidInDomain + + ", created=" + + created + + ", modified=" + + modified + + ", name=" + + name + + ", description=" + + description + + ", priority=" + + priority + + ", serviceLevel=" + + serviceLevel + + ", applicationEntryPoint=" + + applicationEntryPoint + + ", custom1=" + + custom1 + + ", custom2=" + + custom2 + + ", custom3=" + + custom3 + + ", custom4=" + + custom4 + + ", custom5=" + + custom5 + + ", custom6=" + + custom6 + + ", custom7=" + + custom7 + + ", custom8=" + + custom8 + + "]"; + } +} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ClassificationRepresentationModelAssembler.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ClassificationRepresentationModelAssembler.java new file mode 100644 index 000000000..bad9966ae --- /dev/null +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ClassificationRepresentationModelAssembler.java @@ -0,0 +1,70 @@ +package pro.taskana.rest.resource; + +import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo; +import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn; + +import java.time.Instant; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.hateoas.server.RepresentationModelAssembler; +import org.springframework.lang.NonNull; +import org.springframework.stereotype.Component; + +import pro.taskana.classification.api.ClassificationService; +import pro.taskana.classification.api.exceptions.ClassificationNotFoundException; +import pro.taskana.classification.api.models.Classification; +import pro.taskana.classification.internal.models.ClassificationImpl; +import pro.taskana.common.api.exceptions.SystemException; +import pro.taskana.rest.ClassificationController; + +/** + * Transforms {@link Classification} to its resource counterpart {@link + * ClassificationRepresentationModel} and vice versa. + */ +@Component +public class ClassificationRepresentationModelAssembler + implements RepresentationModelAssembler { + + final ClassificationService classificationService; + + @Autowired + public ClassificationRepresentationModelAssembler( + ClassificationService classificationService) { + this.classificationService = classificationService; + } + + @NonNull + @Override + public ClassificationRepresentationModel toModel(@NonNull Classification classification) { + ClassificationRepresentationModel resource = + new ClassificationRepresentationModel(classification); + try { + resource.add( + linkTo(methodOn(ClassificationController.class).getClassification(classification.getId())) + .withSelfRel()); + } catch (ClassificationNotFoundException e) { + throw new SystemException("caught unexpected Exception.", e.getCause()); + } + return resource; + } + + public Classification toEntityModel( + ClassificationRepresentationModel classificationRepresentationModel) { + ClassificationImpl classification = + (ClassificationImpl) + classificationService.newClassification( + classificationRepresentationModel.getKey(), + classificationRepresentationModel.getDomain(), + classificationRepresentationModel.getType()); + BeanUtils.copyProperties(classificationRepresentationModel, classification); + + classification.setId(classificationRepresentationModel.getClassificationId()); + if (classificationRepresentationModel.getCreated() != null) { + classification.setCreated(Instant.parse(classificationRepresentationModel.getCreated())); + } + if (classificationRepresentationModel.getModified() != null) { + classification.setModified(Instant.parse(classificationRepresentationModel.getModified())); + } + return classification; + } +} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ClassificationResource.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ClassificationResource.java deleted file mode 100644 index f03f925bd..000000000 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ClassificationResource.java +++ /dev/null @@ -1,299 +0,0 @@ -package pro.taskana.rest.resource; - -import javax.validation.constraints.NotNull; -import org.springframework.hateoas.RepresentationModel; - -import pro.taskana.classification.api.models.Classification; - -/** EntityModel class for {@link Classification}. */ -public class ClassificationResource extends RepresentationModel { - - @NotNull private String classificationId; - @NotNull private String key; - private String parentId; - private String parentKey; - private String category; - private String type; - private String domain; - private Boolean isValidInDomain; - private String created; // ISO-8601 - private String modified; // ISO-8601 - private String name; - private String description; - private int priority; - private String serviceLevel; // PddDThhHmmM - private String applicationEntryPoint; - private String custom1; - private String custom2; - private String custom3; - private String custom4; - private String custom5; - private String custom6; - private String custom7; - private String custom8; - - public ClassificationResource() {} - - public ClassificationResource(Classification classification) { - this.classificationId = classification.getId(); - this.key = classification.getKey(); - this.parentId = classification.getParentId(); - this.parentKey = classification.getParentKey(); - this.category = classification.getCategory(); - this.type = classification.getType(); - this.domain = classification.getDomain(); - this.isValidInDomain = classification.getIsValidInDomain(); - this.created = - classification.getCreated() != null ? classification.getCreated().toString() : null; - this.modified = - classification.getModified() != null ? classification.getModified().toString() : null; - this.name = classification.getName(); - this.description = classification.getDescription(); - this.priority = classification.getPriority(); - this.serviceLevel = classification.getServiceLevel(); - this.applicationEntryPoint = classification.getApplicationEntryPoint(); - this.custom1 = classification.getCustom1(); - this.custom2 = classification.getCustom2(); - this.custom3 = classification.getCustom3(); - this.custom4 = classification.getCustom4(); - this.custom5 = classification.getCustom5(); - this.custom6 = classification.getCustom6(); - this.custom7 = classification.getCustom7(); - this.custom8 = classification.getCustom8(); - } - - public String getClassificationId() { - return classificationId; - } - - public void setClassificationId(String classificationId) { - this.classificationId = classificationId; - } - - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - - public String getParentId() { - return parentId; - } - - public void setParentId(String parentId) { - this.parentId = parentId; - } - - public String getParentKey() { - return parentKey; - } - - public void setParentKey(String parentKey) { - this.parentKey = parentKey; - } - - public String getCategory() { - return category; - } - - public void setCategory(String category) { - this.category = category; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getDomain() { - return domain; - } - - public void setDomain(String domain) { - this.domain = domain; - } - - public Boolean getIsValidInDomain() { - return isValidInDomain; - } - - public void setIsValidInDomain(Boolean validInDomain) { - isValidInDomain = validInDomain; - } - - public String getCreated() { - return created; - } - - public void setCreated(String created) { - this.created = created; - } - - public String getModified() { - return modified; - } - - public void setModified(String modified) { - this.modified = modified; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public int getPriority() { - return priority; - } - - public void setPriority(int priority) { - this.priority = priority; - } - - public String getServiceLevel() { - return serviceLevel; - } - - public void setServiceLevel(String serviceLevel) { - this.serviceLevel = serviceLevel; - } - - public String getApplicationEntryPoint() { - return applicationEntryPoint; - } - - public void setApplicationEntryPoint(String applicationEntryPoint) { - this.applicationEntryPoint = applicationEntryPoint; - } - - public String getCustom1() { - return custom1; - } - - public void setCustom1(String custom1) { - this.custom1 = custom1; - } - - public String getCustom2() { - return custom2; - } - - public void setCustom2(String custom2) { - this.custom2 = custom2; - } - - public String getCustom3() { - return custom3; - } - - public void setCustom3(String custom3) { - this.custom3 = custom3; - } - - public String getCustom4() { - return custom4; - } - - public void setCustom4(String custom4) { - this.custom4 = custom4; - } - - public String getCustom5() { - return custom5; - } - - public void setCustom5(String custom5) { - this.custom5 = custom5; - } - - public String getCustom6() { - return custom6; - } - - public void setCustom6(String custom6) { - this.custom6 = custom6; - } - - public String getCustom7() { - return custom7; - } - - public void setCustom7(String custom7) { - this.custom7 = custom7; - } - - public String getCustom8() { - return custom8; - } - - public void setCustom8(String custom8) { - this.custom8 = custom8; - } - - @Override - public String toString() { - return "ClassificationResource [classificationId=" - + classificationId - + ", key=" - + key - + ", parentId=" - + parentId - + ", parentKey=" - + parentKey - + ", category=" - + category - + ", type=" - + type - + ", domain=" - + domain - + ", isValidInDomain=" - + isValidInDomain - + ", created=" - + created - + ", modified=" - + modified - + ", name=" - + name - + ", description=" - + description - + ", priority=" - + priority - + ", serviceLevel=" - + serviceLevel - + ", applicationEntryPoint=" - + applicationEntryPoint - + ", custom1=" - + custom1 - + ", custom2=" - + custom2 - + ", custom3=" - + custom3 - + ", custom4=" - + custom4 - + ", custom5=" - + custom5 - + ", custom6=" - + custom6 - + ", custom7=" - + custom7 - + ", custom8=" - + custom8 - + "]"; - } -} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ClassificationResourceAssembler.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ClassificationResourceAssembler.java deleted file mode 100644 index a6ab67184..000000000 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ClassificationResourceAssembler.java +++ /dev/null @@ -1,72 +0,0 @@ -package pro.taskana.rest.resource; - -import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo; -import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn; - -import java.time.Instant; -import org.springframework.beans.BeanUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport; -import org.springframework.stereotype.Component; - -import pro.taskana.classification.api.ClassificationService; -import pro.taskana.classification.api.exceptions.ClassificationNotFoundException; -import pro.taskana.classification.api.models.Classification; -import pro.taskana.classification.internal.models.ClassificationImpl; -import pro.taskana.common.api.exceptions.SystemException; -import pro.taskana.rest.ClassificationController; - -/** - * Transforms {@link Classification} to its resource counterpart {@link ClassificationResource} and - * vice versa. - */ -@Component -public class ClassificationResourceAssembler - extends RepresentationModelAssemblerSupport { - - final ClassificationService classificationService; - - @Autowired - public ClassificationResourceAssembler(ClassificationService classificationService) { - super(ClassificationController.class, ClassificationResource.class); - this.classificationService = classificationService; - } - - public ClassificationResource toDefinition(Classification classification) { - ClassificationResource resource = new ClassificationResource(classification); - resource.add( - linkTo(ClassificationController.class).slash(classification.getId()).withSelfRel()); - return resource; - } - - public ClassificationResource toModel(Classification classification) { - ClassificationResource resource = new ClassificationResource(classification); - try { - resource.add( - linkTo(methodOn(ClassificationController.class).getClassification(classification.getId())) - .withSelfRel()); - } catch (ClassificationNotFoundException e) { - throw new SystemException("caught unexpected Exception.", e.getCause()); - } - return resource; - } - - public Classification toModel(ClassificationResource classificationResource) { - ClassificationImpl classification = - (ClassificationImpl) - classificationService.newClassification( - classificationResource.getKey(), - classificationResource.getDomain(), - classificationResource.getType()); - BeanUtils.copyProperties(classificationResource, classification); - - classification.setId(classificationResource.getClassificationId()); - if (classificationResource.getCreated() != null) { - classification.setCreated(Instant.parse(classificationResource.getCreated())); - } - if (classificationResource.getModified() != null) { - classification.setModified(Instant.parse(classificationResource.getModified())); - } - return classification; - } -} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ClassificationSummaryListResource.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ClassificationSummaryListResource.java deleted file mode 100644 index 224a8e233..000000000 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ClassificationSummaryListResource.java +++ /dev/null @@ -1,24 +0,0 @@ -package pro.taskana.rest.resource; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.Collection; -import org.springframework.hateoas.Link; - -/** EntityModel class for {@link ClassificationSummaryResource} with Pagination. */ -public class ClassificationSummaryListResource - extends PagedResources { - - public ClassificationSummaryListResource() { - super(); - } - - public ClassificationSummaryListResource( - Collection content, PageMetadata metadata, Link... links) { - super(content, metadata, links); - } - - @JsonProperty("classifications") - public Collection getContent() { - return super.getContent(); - } -} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ClassificationSummaryResource.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ClassificationSummaryRepresentationModel.java similarity index 83% rename from rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ClassificationSummaryResource.java rename to rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ClassificationSummaryRepresentationModel.java index ff48a5812..e2e6b2bd9 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ClassificationSummaryResource.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ClassificationSummaryRepresentationModel.java @@ -4,33 +4,36 @@ import org.springframework.hateoas.RepresentationModel; import pro.taskana.classification.api.models.ClassificationSummary; -/** EntityModel class for {@link ClassificationSummary}. */ -public class ClassificationSummaryResource - extends RepresentationModel { +/** + * EntityModel class for {@link ClassificationSummary}. + */ +public class ClassificationSummaryRepresentationModel + extends RepresentationModel { - private String classificationId; - private String applicationEntryPoint; - private String category; - private String domain; - private String key; - private String name; - private String parentId; - private String parentKey; - private int priority; - private String serviceLevel; - private String type; - private String custom1; - private String custom2; - private String custom3; - private String custom4; - private String custom5; - private String custom6; - private String custom7; - private String custom8; + protected String classificationId; + protected String key; + protected String applicationEntryPoint; + protected String category; + protected String domain; + protected String name; + protected String parentId; + protected String parentKey; + protected int priority; + protected String serviceLevel; + protected String type; + protected String custom1; + protected String custom2; + protected String custom3; + protected String custom4; + protected String custom5; + protected String custom6; + protected String custom7; + protected String custom8; - public ClassificationSummaryResource() {} + public ClassificationSummaryRepresentationModel() { + } - public ClassificationSummaryResource(ClassificationSummary classification) { + public ClassificationSummaryRepresentationModel(ClassificationSummary classification) { classificationId = classification.getId(); applicationEntryPoint = classification.getApplicationEntryPoint(); category = classification.getCategory(); diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ClassificationSummaryRepresentationModelAssembler.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ClassificationSummaryRepresentationModelAssembler.java new file mode 100644 index 000000000..7063adf98 --- /dev/null +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ClassificationSummaryRepresentationModelAssembler.java @@ -0,0 +1,63 @@ +package pro.taskana.rest.resource; + +import static pro.taskana.rest.resource.TaskanaPagedModelKeys.CLASSIFICATIONS; + +import java.util.List; +import java.util.stream.Collectors; +import org.springframework.beans.BeanUtils; +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; + +import pro.taskana.classification.api.ClassificationService; +import pro.taskana.classification.api.models.ClassificationSummary; +import pro.taskana.classification.internal.models.ClassificationImpl; +import pro.taskana.rest.Mapping; +import pro.taskana.rest.resource.links.PageLinks; + +/** + * EntityModel assembler for {@link ClassificationSummaryRepresentationModel}. + */ +@Component +public class ClassificationSummaryRepresentationModelAssembler + implements + RepresentationModelAssembler { + + private final ClassificationService classificationService; + + @Autowired + public ClassificationSummaryRepresentationModelAssembler( + ClassificationService classificationService) { + this.classificationService = classificationService; + } + + @NonNull + @Override + public ClassificationSummaryRepresentationModel toModel( + @NonNull ClassificationSummary classificationSummary) { + return new ClassificationSummaryRepresentationModel(classificationSummary); + } + + public ClassificationSummary toEntityModel(ClassificationSummaryRepresentationModel resource) { + ClassificationImpl classification = + (ClassificationImpl) + classificationService.newClassification( + resource.getKey(), resource.getDomain(), resource.getType()); + classification.setId(resource.getClassificationId()); + BeanUtils.copyProperties(resource, classification); + return classification.asSummary(); + } + + @PageLinks(Mapping.URL_CLASSIFICATIONS) + public TaskanaPagedModel toPageModel( + List classificationSummaries, PageMetadata pageMetadata) { + return classificationSummaries.stream() + .map(this::toModel) + .collect( + Collectors.collectingAndThen( + Collectors.toList(), + list -> new TaskanaPagedModel<>(CLASSIFICATIONS, list, pageMetadata))); + } +} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ClassificationSummaryResourceAssembler.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ClassificationSummaryResourceAssembler.java deleted file mode 100644 index 5196b1db3..000000000 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ClassificationSummaryResourceAssembler.java +++ /dev/null @@ -1,50 +0,0 @@ -package pro.taskana.rest.resource; - -import java.util.Collection; -import org.springframework.beans.BeanUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport; -import org.springframework.stereotype.Component; - -import pro.taskana.classification.api.ClassificationService; -import pro.taskana.classification.api.models.ClassificationSummary; -import pro.taskana.classification.internal.models.ClassificationImpl; -import pro.taskana.rest.ClassificationController; -import pro.taskana.rest.Mapping; -import pro.taskana.rest.resource.PagedResources.PageMetadata; -import pro.taskana.rest.resource.links.PageLinks; - -/** EntityModel assembler for {@link ClassificationSummaryResource}. */ -@Component -public class ClassificationSummaryResourceAssembler - extends RepresentationModelAssemblerSupport< - ClassificationSummary, ClassificationSummaryResource> { - - @Autowired private ClassificationService classificationService; - - public ClassificationSummaryResourceAssembler() { - super(ClassificationController.class, ClassificationSummaryResource.class); - } - - @Override - public ClassificationSummaryResource toModel(ClassificationSummary classificationSummary) { - return new ClassificationSummaryResource(classificationSummary); - } - - public ClassificationSummary toModel(ClassificationSummaryResource resource) { - ClassificationImpl classification = - (ClassificationImpl) - classificationService.newClassification( - resource.getKey(), resource.getDomain(), resource.getType()); - classification.setId(resource.getClassificationId()); - BeanUtils.copyProperties(resource, classification); - return classification.asSummary(); - } - - @PageLinks(Mapping.URL_CLASSIFICATIONS) - public ClassificationSummaryListResource toCollectionModel( - Collection entities, PageMetadata pageMetadata) { - return new ClassificationSummaryListResource( - toCollectionModel(entities).getContent(), pageMetadata); - } -} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/DistributionTargetListResource.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/DistributionTargetListResource.java deleted file mode 100644 index a0406e2aa..000000000 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/DistributionTargetListResource.java +++ /dev/null @@ -1,31 +0,0 @@ -package pro.taskana.rest.resource; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.Collection; -import org.springframework.hateoas.Link; - -/** EntityModel class for {@link DistributionTargetResource} with Pagination. */ -public class DistributionTargetListResource extends PagedResources { - - public DistributionTargetListResource() { - super(); - } - - public DistributionTargetListResource( - Collection content, Link... links) { - super(content, null, links); - } - - @Override - @JsonIgnore - public PageMetadata getMetadata() { - return super.getMetadata(); - } - - @Override - @JsonProperty("distributionTargets") - public Collection getContent() { - return super.getContent(); - } -} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/DistributionTargetRepresentationModelAssembler.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/DistributionTargetRepresentationModelAssembler.java new file mode 100644 index 000000000..53a116dcc --- /dev/null +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/DistributionTargetRepresentationModelAssembler.java @@ -0,0 +1,19 @@ +package pro.taskana.rest.resource; + +import static pro.taskana.rest.resource.TaskanaPagedModelKeys.DISTRIBUTION_TARGETS; + +import org.springframework.stereotype.Component; + +/** + * Transforms WorkbasketSummary to its resource counterpart DistributionTargerResource and vice + * versa. + */ +@Component +public class DistributionTargetRepresentationModelAssembler + extends WorkbasketSummaryRepresentationModelAssembler { + + @Override + protected TaskanaPagedModelKeys getKey() { + return DISTRIBUTION_TARGETS; + } +} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/DistributionTargetResource.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/DistributionTargetResource.java deleted file mode 100644 index ccceb5686..000000000 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/DistributionTargetResource.java +++ /dev/null @@ -1,16 +0,0 @@ -package pro.taskana.rest.resource; - -import org.springframework.hateoas.server.core.Relation; - -import pro.taskana.workbasket.api.models.WorkbasketSummary; - -/** EntityModel class for a distribution target based on {@link WorkbasketSummary}. */ -@Relation(collectionRelation = "distributionTargets") -public class DistributionTargetResource extends WorkbasketSummaryResource { - - DistributionTargetResource() {} - - DistributionTargetResource(WorkbasketSummary workbasketSummary) { - super(workbasketSummary); - } -} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/DistributionTargetResourceAssembler.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/DistributionTargetResourceAssembler.java deleted file mode 100644 index e5bd074a2..000000000 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/DistributionTargetResourceAssembler.java +++ /dev/null @@ -1,46 +0,0 @@ -package pro.taskana.rest.resource; - -import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo; -import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn; - -import java.util.List; -import org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport; -import org.springframework.stereotype.Component; - -import pro.taskana.common.api.exceptions.NotAuthorizedException; -import pro.taskana.rest.WorkbasketController; -import pro.taskana.workbasket.api.exceptions.WorkbasketNotFoundException; -import pro.taskana.workbasket.api.models.WorkbasketSummary; - -/** - * Transforms WorkbasketSummary to its resource counterpart DistributionTargerResource and vice - * versa. - */ -@Component -public class DistributionTargetResourceAssembler - extends RepresentationModelAssemblerSupport { - - public DistributionTargetResourceAssembler() { - super(WorkbasketController.class, DistributionTargetResource.class); - } - - public DistributionTargetResource toModel(WorkbasketSummary summary) { - return new DistributionTargetResource(summary); - } - - public DistributionTargetListResource toCollectionModel( - String workbasketId, List distributionTargets) - throws WorkbasketNotFoundException, NotAuthorizedException { - - DistributionTargetListResource distributionTargetListResource = - new DistributionTargetListResource(toCollectionModel(distributionTargets).getContent()); - distributionTargetListResource.add( - linkTo(methodOn(WorkbasketController.class).getDistributionTargets(workbasketId)) - .withSelfRel()); - distributionTargetListResource.add( - linkTo(methodOn(WorkbasketController.class).getWorkbasket(workbasketId)) - .withRel("workbasket")); - - return distributionTargetListResource; - } -} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/PagedResources.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/PagedResources.java index 754476bd7..b09f3f09e 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/PagedResources.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/PagedResources.java @@ -6,10 +6,9 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Objects; -import javax.xml.bind.annotation.XmlAttribute; import org.springframework.hateoas.Link; +import org.springframework.hateoas.PagedModel.PageMetadata; import org.springframework.hateoas.RepresentationModel; -import org.springframework.util.Assert; /** * Base Class for CollectionModel with pagination. @@ -78,135 +77,4 @@ public class PagedResources extends RepresentationModel> { return Collections.unmodifiableCollection(content); } - /** Class for Page Metadata. */ - public static class PageMetadata { - - @XmlAttribute @JsonProperty private long size; - @XmlAttribute @JsonProperty private long totalElements; - @XmlAttribute @JsonProperty private long totalPages; - @XmlAttribute @JsonProperty private long number; - - protected PageMetadata() {} - - /** - * Creates a new {@link PageMetadata} from the given size, number, total elements and total - * pages. - * - * @param size the size - * @param number zero-indexed, must be less than totalPages - * @param totalElements number of elements - * @param totalPages the total pages - */ - public PageMetadata(long size, long number, long totalElements, long totalPages) { - Assert.isTrue(size > -1, "Size must not be negative!"); - Assert.isTrue(number > -1, "Number must not be negative!"); - Assert.isTrue(totalElements > -1, "Total elements must not be negative!"); - Assert.isTrue(totalPages > -1, "Total pages must not be negative!"); - - this.size = size; - this.number = number; - this.totalElements = totalElements; - this.totalPages = totalPages; - } - - /** - * Creates a new {@link PageMetadata} from the given size, number and total elements. - * - * @param size the size of the page - * @param number the number of the page - * @param totalElements the total number of elements available - */ - public PageMetadata(long size, long number, long totalElements) { - this( - size, - number, - totalElements, - size == 0 ? 0 : (long) Math.ceil((double) totalElements / (double) size)); - } - - /** - * Returns the requested size of the page. - * - * @return the size a positive long. - */ - public long getSize() { - return size; - } - - /** - * Returns the total number of elements available. - * - * @return the totalElements a positive long. - */ - public long getTotalElements() { - return totalElements; - } - - /** - * Returns how many pages are available in total. - * - * @return the totalPages a positive long. - */ - public long getTotalPages() { - return totalPages; - } - - /** - * Returns the number of the current page. - * - * @return the number a positive long. - */ - public long getNumber() { - return number; - } - - /* - * (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - - int result = 17; - result += 31 * (int) (this.number ^ this.number >>> 32); - result += 31 * (int) (this.size ^ this.size >>> 32); - result += 31 * (int) (this.totalElements ^ this.totalElements >>> 32); - result += 31 * (int) (this.totalPages ^ this.totalPages >>> 32); - return result; - } - - /* - * (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) { - - if (this == obj) { - return true; - } - - if (obj == null || !obj.getClass().equals(getClass())) { - return false; - } - - PageMetadata that = (PageMetadata) obj; - - return this.number == that.number - && this.size == that.size - && this.totalElements == that.totalElements - && this.totalPages == that.totalPages; - } - - /* - * (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return String.format( - "Metadata { number: %d, total pages: %d, total elements: %d, size: %d }", - number, totalPages, totalElements, size); - } - } } diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ReportResource.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ReportRepresentationModel.java similarity index 92% rename from rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ReportResource.java rename to rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ReportRepresentationModel.java index 320be2670..369ddad22 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ReportResource.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ReportRepresentationModel.java @@ -8,7 +8,7 @@ import pro.taskana.monitor.api.reports.Report; import pro.taskana.monitor.api.reports.row.SingleRow; /** EntityModel class for {@link Report}. */ -public class ReportResource extends RepresentationModel { +public class ReportRepresentationModel extends RepresentationModel { private MetaInformation meta; @@ -16,7 +16,8 @@ public class ReportResource extends RepresentationModel { private List sumRow; - public ReportResource(MetaInformation meta, List rows, List sumRow) { + public ReportRepresentationModel( + MetaInformation meta, List rows, List sumRow) { this.meta = meta; this.rows = rows; this.sumRow = sumRow; diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ReportResourceAssembler.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ReportRepresentationModelAssembler.java similarity index 66% rename from rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ReportResourceAssembler.java rename to rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ReportRepresentationModelAssembler.java index 8078b5586..b4c897cc7 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ReportResourceAssembler.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ReportRepresentationModelAssembler.java @@ -10,6 +10,7 @@ import java.util.Comparator; import java.util.LinkedList; import java.util.List; import java.util.stream.Collectors; +import org.springframework.lang.NonNull; import org.springframework.stereotype.Component; import pro.taskana.common.api.exceptions.InvalidArgumentException; @@ -27,14 +28,16 @@ import pro.taskana.monitor.api.reports.row.SingleRow; import pro.taskana.rest.MonitorController; import pro.taskana.task.api.TaskState; -/** Transforms any {@link Report} into its {@link ReportResource}. */ +/** Transforms any {@link Report} into its {@link ReportRepresentationModel}. */ @Component -public class ReportResourceAssembler { +public class ReportRepresentationModelAssembler { - public ReportResource toModel( - TaskStatusReport report, List domains, List states) + @NonNull + public ReportRepresentationModel toModel( + @NonNull TaskStatusReport report, @NonNull List domains, + @NonNull List states) throws NotAuthorizedException, InvalidArgumentException { - ReportResource resource = toReportResource(report); + ReportRepresentationModel resource = toReportResource(report); resource.add( linkTo(methodOn(MonitorController.class).getTasksStatusReport(domains, states)) .withSelfRel() @@ -42,9 +45,10 @@ public class ReportResourceAssembler { return resource; } - public ReportResource toModel(ClassificationReport report) + @NonNull + public ReportRepresentationModel toModel(@NonNull ClassificationReport report) throws NotAuthorizedException, InvalidArgumentException { - ReportResource resource = toReportResource(report); + ReportRepresentationModel resource = toReportResource(report); resource.add( linkTo(methodOn(MonitorController.class).getTasksClassificationReport()) .withSelfRel() @@ -52,9 +56,11 @@ public class ReportResourceAssembler { return resource; } - public ReportResource toModel(WorkbasketReport report, List states) + @NonNull + public ReportRepresentationModel toModel(@NonNull WorkbasketReport report, + @NonNull List states) throws NotAuthorizedException, InvalidArgumentException { - ReportResource resource = toReportResource(report); + ReportRepresentationModel resource = toReportResource(report); resource.add( linkTo(methodOn(MonitorController.class).getTasksWorkbasketReport(states)) .withSelfRel() @@ -62,41 +68,44 @@ public class ReportResourceAssembler { return resource; } - public ReportResource toModel(WorkbasketReport report, int daysInPast, List states) + @NonNull + public ReportRepresentationModel toModel( + @NonNull WorkbasketReport report, int daysInPast, @NonNull List states) throws NotAuthorizedException, InvalidArgumentException { - ReportResource resource = toReportResource(report); + ReportRepresentationModel resource = toReportResource(report); resource.add( linkTo( - methodOn(MonitorController.class) - .getTasksWorkbasketPlannedDateReport(daysInPast, states)) + methodOn(MonitorController.class) + .getTasksWorkbasketPlannedDateReport(daysInPast, states)) .withSelfRel() .expand()); return resource; } - public ReportResource toModel(TimestampReport report) + @NonNull + public ReportRepresentationModel toModel(@NonNull TimestampReport report) throws NotAuthorizedException, InvalidArgumentException { - ReportResource resource = toReportResource(report); + ReportRepresentationModel resource = toReportResource(report); resource.add( linkTo(methodOn(MonitorController.class).getDailyEntryExitReport()).withSelfRel().expand()); return resource; } - > ReportResource toReportResource( - Report report) { + > + ReportRepresentationModel toReportResource(Report report) { return toReportResource(report, Instant.now()); } - > ReportResource toReportResource( - Report report, Instant time) { + > + ReportRepresentationModel toReportResource(Report report, Instant time) { String[] header = report.getColumnHeaders().stream().map(H::getDisplayName).toArray(String[]::new); - ReportResource.MetaInformation meta = - new ReportResource.MetaInformation( + ReportRepresentationModel.MetaInformation meta = + new ReportRepresentationModel.MetaInformation( report.getClass().getSimpleName(), time.toString(), header, report.getRowDesc()); // iterate over each Row and transform it to a RowResource while keeping the domain key. - List rows = + List rows = report.getRows().entrySet().stream() .sorted(Comparator.comparing(e -> e.getKey().toLowerCase())) .map( @@ -106,14 +115,14 @@ public class ReportResourceAssembler { .flatMap(Collection::stream) .collect(Collectors.toList()); - List sumRow = + List sumRow = transformRow( report.getSumRow(), meta.getTotalDesc(), new String[report.getRowDesc().length], 0); - return new ReportResource(meta, rows, sumRow); + return new ReportRepresentationModel(meta, rows, sumRow); } - private List transformRow( + private List transformRow( Row row, String currentDesc, String[] desc, int depth) { // This is a very dirty solution.. Personally I'd prefer to use a visitor-like pattern here. // The issue with that: Addition of the visitor code within taskana-core - and having clean code @@ -126,20 +135,20 @@ public class ReportResourceAssembler { return transformFoldableRow((FoldableRow) row, currentDesc, desc, depth); } - private ReportResource.RowResource transformSingleRow( + private ReportRepresentationModel.RowResource transformSingleRow( SingleRow row, String currentDesc, String[] previousRowDesc, int depth) { String[] rowDesc = new String[previousRowDesc.length]; System.arraycopy(previousRowDesc, 0, rowDesc, 0, depth); rowDesc[depth] = currentDesc; - return new ReportResource.RowResource( + return new ReportRepresentationModel.RowResource( row.getCells(), row.getTotalValue(), depth, rowDesc, depth == 0); } - private List transformFoldableRow( + private List transformFoldableRow( FoldableRow row, String currentDesc, String[] previousRowDesc, int depth) { - ReportResource.RowResource baseRow = + ReportRepresentationModel.RowResource baseRow = transformSingleRow(row, currentDesc, previousRowDesc, depth); - List rowList = new LinkedList<>(); + List rowList = new LinkedList<>(); rowList.add(baseRow); row.getFoldableRowKeySet().stream() .sorted(String.CASE_INSENSITIVE_ORDER) diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskCommentListResource.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskCommentListResource.java deleted file mode 100644 index e6a49cf97..000000000 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskCommentListResource.java +++ /dev/null @@ -1,24 +0,0 @@ -package pro.taskana.rest.resource; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.List; -import org.springframework.hateoas.RepresentationModel; - -/** EntityModel class for {@link TaskCommentResource} with Pagination. */ -public class TaskCommentListResource extends RepresentationModel { - - private List content; - - public TaskCommentListResource() { - super(); - } - - public TaskCommentListResource(List taskCommentResources) { - this.content = taskCommentResources; - } - - @JsonProperty("task comments") - public List getContent() { - return content; - } -} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskCommentResource.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskCommentRepresentationModel.java similarity index 89% rename from rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskCommentResource.java rename to rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskCommentRepresentationModel.java index 23587e83f..2be27dd93 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskCommentResource.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskCommentRepresentationModel.java @@ -5,7 +5,8 @@ import org.springframework.hateoas.RepresentationModel; import pro.taskana.task.api.models.TaskComment; /** EntityModel class for {@link TaskComment}. */ -public class TaskCommentResource extends RepresentationModel { +public class TaskCommentRepresentationModel + extends RepresentationModel { private String taskCommentId; private String taskId; @@ -14,9 +15,9 @@ public class TaskCommentResource extends RepresentationModel { + + private final TaskService taskService; + + @Autowired + public TaskCommentRepresentationModelAssembler(TaskService taskService) { + this.taskService = taskService; + } + + @NonNull + @Override + public TaskCommentRepresentationModel toModel(@NonNull TaskComment taskComment) { + TaskCommentRepresentationModel taskCommentRepresentationModel = + new TaskCommentRepresentationModel(taskComment); + try { + taskCommentRepresentationModel.add( + linkTo(methodOn(TaskCommentController.class).getTaskComment(taskComment.getId())) + .withSelfRel()); + } catch (Exception e) { + throw new SystemException("caught unexpected Exception.", e.getCause()); + } + + return taskCommentRepresentationModel; + } + + public TaskComment toEntityModel(TaskCommentRepresentationModel taskCommentRepresentationModel) { + + TaskCommentImpl taskComment = + (TaskCommentImpl) taskService.newTaskComment(taskCommentRepresentationModel.getTaskId()); + taskComment.setId(taskCommentRepresentationModel.getTaskCommentId()); + + BeanUtils.copyProperties(taskCommentRepresentationModel, taskComment); + + if (taskCommentRepresentationModel.getCreated() != null) { + taskComment.setCreated(Instant.parse(taskCommentRepresentationModel.getCreated())); + } + if (taskCommentRepresentationModel.getModified() != null) { + taskComment.setModified(Instant.parse(taskCommentRepresentationModel.getModified())); + } + + return taskComment; + } + + @PageLinks(Mapping.URL_TASK_COMMENTS) + public TaskanaPagedModel toPageModel( + List taskComments, PageMetadata pageMetadata) { + return taskComments.stream() + .map(this::toModel) + .collect( + Collectors.collectingAndThen( + Collectors.toList(), + list -> new TaskanaPagedModel<>(TASK_COMMENTS, list, pageMetadata))); + } +} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskCommentResourceAssembler.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskCommentResourceAssembler.java deleted file mode 100644 index 50625a2af..000000000 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskCommentResourceAssembler.java +++ /dev/null @@ -1,82 +0,0 @@ -package pro.taskana.rest.resource; - -import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo; -import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn; - -import java.time.Instant; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import org.springframework.beans.BeanUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport; -import org.springframework.stereotype.Component; - -import pro.taskana.common.api.exceptions.InvalidArgumentException; -import pro.taskana.common.api.exceptions.NotAuthorizedException; -import pro.taskana.common.api.exceptions.SystemException; -import pro.taskana.rest.Mapping; -import pro.taskana.rest.TaskCommentController; -import pro.taskana.rest.resource.links.PageLinks; -import pro.taskana.task.api.TaskService; -import pro.taskana.task.api.exceptions.TaskCommentNotFoundException; -import pro.taskana.task.api.exceptions.TaskNotFoundException; -import pro.taskana.task.api.models.TaskComment; -import pro.taskana.task.internal.models.TaskCommentImpl; - -/** EntityModel assembler for {@link TaskCommentResource}. */ -@Component -public class TaskCommentResourceAssembler - extends RepresentationModelAssemblerSupport { - - private final TaskService taskService; - - @Autowired - public TaskCommentResourceAssembler(TaskService taskService) { - super(TaskCommentController.class, TaskCommentResource.class); - this.taskService = taskService; - } - - @PageLinks(Mapping.URL_TASK_COMMENTS) - public TaskCommentListResource toListResource(List taskComments) { - Collection col = toCollectionModel(taskComments).getContent(); - List resourceList = new ArrayList<>(col); - return new TaskCommentListResource(resourceList); - } - - @Override - public TaskCommentResource toModel(TaskComment taskComment) { - - TaskCommentResource taskCommentResource = new TaskCommentResource(taskComment); - try { - taskCommentResource.add( - linkTo(methodOn(TaskCommentController.class).getTaskComment(taskComment.getId())) - .withSelfRel()); - } catch (TaskCommentNotFoundException - | TaskNotFoundException - | NotAuthorizedException - | InvalidArgumentException e) { - throw new SystemException("caught unexpected Exception.", e.getCause()); - } - - return taskCommentResource; - } - - public TaskComment toModel(TaskCommentResource taskCommentResource) { - - TaskCommentImpl taskComment = - (TaskCommentImpl) taskService.newTaskComment(taskCommentResource.getTaskId()); - taskComment.setId(taskCommentResource.getTaskCommentId()); - - BeanUtils.copyProperties(taskCommentResource, taskComment); - - if (taskCommentResource.getCreated() != null) { - taskComment.setCreated(Instant.parse(taskCommentResource.getCreated())); - } - if (taskCommentResource.getModified() != null) { - taskComment.setModified(Instant.parse(taskCommentResource.getModified())); - } - - return taskComment; - } -} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskRepresentationModel.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskRepresentationModel.java new file mode 100644 index 000000000..420bc06cd --- /dev/null +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskRepresentationModel.java @@ -0,0 +1,133 @@ +package pro.taskana.rest.resource; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +import pro.taskana.common.api.exceptions.InvalidArgumentException; +import pro.taskana.task.api.models.Task; + +/** + * EntityModel class for {@link Task}. + */ +@JsonIgnoreProperties("attachmentSummaries") +public class TaskRepresentationModel extends TaskSummaryRepresentationModel { + + + // All objects have to be serializable + private List customAttributes = Collections.emptyList(); + private List callbackInfo = Collections.emptyList(); + private List attachments = new ArrayList<>(); + + public TaskRepresentationModel() { + } + + public TaskRepresentationModel(Task task) throws InvalidArgumentException { + super(task); + customAttributes = + task.getCustomAttributes().entrySet().stream() + .map(e -> new TaskRepresentationModel.CustomAttribute(e.getKey(), e.getValue())) + .collect(Collectors.toList()); + callbackInfo = + task.getCallbackInfo().entrySet().stream() + .map(e -> new TaskRepresentationModel.CustomAttribute(e.getKey(), e.getValue())) + .collect(Collectors.toList()); + + attachments = + task.getAttachments().stream() + .map(AttachmentRepresentationModel::new) + .collect(Collectors.toList()); + } + + public List getCustomAttributes() { + return customAttributes; + } + + public void setCustomAttributes(List customAttributes) { + this.customAttributes = customAttributes; + } + + public List getCallbackInfo() { + return callbackInfo; + } + + public void setCallbackInfo(List callbackInfo) { + this.callbackInfo = callbackInfo; + } + + public List getAttachments() { + return attachments; + } + + public void setAttachments(List attachments) { + this.attachments = attachments; + } + + @Override + public String toString() { + return "TaskResource [" + + "taskId= " + + this.taskId + + "externalId= " + + this.externalId + + "created= " + + this.created + + "modified= " + + this.modified + + "claimed= " + + this.claimed + + "completed= " + + this.completed + + "planned= " + + this.planned + + "due= " + + this.due + + "name= " + + this.name + + "creator= " + + this.creator + + "description= " + + this.description + + "priority= " + + this.priority + + "owner= " + + this.owner + + "]"; + } + + /** + * A CustomAttribute is a user customized attribute which is saved as a Map and can be retreived + * from either {@link Task#getCustomAttributes()} or {@link Task#getCallbackInfo()}. + */ + public static class CustomAttribute { + + private final String key; + private final String value; + + @SuppressWarnings("unused") + public CustomAttribute() { + this(null, null); + // necessary for jackson. + } + + public CustomAttribute(String key, String value) { + this.key = key; + this.value = value; + } + + public String getKey() { + return key; + } + + public String getValue() { + return value; + } + + @Override + public String toString() { + return "CustomAttribute [" + "key= " + this.key + "value= " + this.value + "]"; + } + } +} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskResourceAssembler.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskRepresentationModelAssembler.java similarity index 54% rename from rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskResourceAssembler.java rename to rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskRepresentationModelAssembler.java index b6fabb0cf..254120faf 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskResourceAssembler.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskRepresentationModelAssembler.java @@ -9,47 +9,55 @@ import java.util.stream.Collectors; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport; +import org.springframework.lang.NonNull; import org.springframework.stereotype.Component; import pro.taskana.common.api.exceptions.InvalidArgumentException; import pro.taskana.common.api.exceptions.NotAuthorizedException; import pro.taskana.common.api.exceptions.SystemException; import pro.taskana.rest.TaskController; +import pro.taskana.rest.resource.TaskRepresentationModel.CustomAttribute; 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; -/** EntityModel assembler for {@link TaskResource}. */ +/** + * EntityModel assembler for {@link TaskRepresentationModel}. + */ @Component -public class TaskResourceAssembler extends RepresentationModelAssemblerSupport { +public class TaskRepresentationModelAssembler + extends RepresentationModelAssemblerSupport { private final TaskService taskService; - private final ClassificationSummaryResourceAssembler classificationAssembler; + private final ClassificationSummaryRepresentationModelAssembler classificationAssembler; - private final WorkbasketSummaryResourceAssembler workbasketAssembler; + private final WorkbasketSummaryRepresentationModelAssembler + workbasketSummaryRepresentationModelAssembler; - private final AttachmentResourceAssembler attachmentAssembler; + private final AttachmentRepresentationModelAssembler attachmentAssembler; @Autowired - public TaskResourceAssembler( + public TaskRepresentationModelAssembler( TaskService taskService, - ClassificationSummaryResourceAssembler classificationAssembler, - WorkbasketSummaryResourceAssembler workbasketAssembler, - AttachmentResourceAssembler attachmentAssembler) { - super(TaskController.class, TaskResource.class); + ClassificationSummaryRepresentationModelAssembler classificationAssembler, + WorkbasketSummaryRepresentationModelAssembler workbasketSummaryRepresentationModelAssembler, + AttachmentRepresentationModelAssembler attachmentAssembler) { + super(TaskController.class, TaskRepresentationModel.class); this.taskService = taskService; this.classificationAssembler = classificationAssembler; - this.workbasketAssembler = workbasketAssembler; + this.workbasketSummaryRepresentationModelAssembler + = workbasketSummaryRepresentationModelAssembler; this.attachmentAssembler = attachmentAssembler; } + @NonNull @Override - public TaskResource toModel(Task task) { - TaskResource resource; + public TaskRepresentationModel toModel(@NonNull Task task) { + TaskRepresentationModel resource; try { - resource = new TaskResource(task); + resource = new TaskRepresentationModel(task); resource.add(linkTo(methodOn(TaskController.class).getTask(task.getId())).withSelfRel()); } catch (InvalidArgumentException | TaskNotFoundException | NotAuthorizedException e) { throw new SystemException("caught unexpected Exception.", e.getCause()); @@ -57,10 +65,12 @@ public class TaskResourceAssembler extends RepresentationModelAssemblerSupport Objects.nonNull(e.getKey()) && !e.getKey().isEmpty()) - .collect( - Collectors.toMap( - TaskResource.CustomAttribute::getKey, TaskResource.CustomAttribute::getValue))); + .collect(Collectors.toMap(CustomAttribute::getKey, CustomAttribute::getValue))); task.setCallbackInfo( resource.getCallbackInfo().stream() .filter(e -> Objects.nonNull(e.getKey()) && !e.getKey().isEmpty()) - .collect( - Collectors.toMap( - TaskResource.CustomAttribute::getKey, TaskResource.CustomAttribute::getValue))); + .collect(Collectors.toMap(CustomAttribute::getKey, CustomAttribute::getValue))); return task; } - private void validateTaskResource(TaskResource resource) throws InvalidArgumentException { - if (resource.getWorkbasketSummaryResource() == null - || resource.getWorkbasketSummaryResource().getWorkbasketId() == null - || resource.getWorkbasketSummaryResource().getWorkbasketId().isEmpty()) { + private void validateTaskResource(TaskRepresentationModel resource) + throws InvalidArgumentException { + if (resource.getWorkbasketSummary() == null + || resource.getWorkbasketSummary().getWorkbasketId() == null + || resource.getWorkbasketSummary().getWorkbasketId().isEmpty()) { throw new InvalidArgumentException( "TaskResource must have a workbasket summary with a valid workbasketId."); } - if (resource.getClassificationSummaryResource() == null - || resource.getClassificationSummaryResource().getKey() == null - || resource.getClassificationSummaryResource().getKey().isEmpty()) { + if (resource.getClassificationSummary() == null + || resource.getClassificationSummary().getKey() == null + || resource.getClassificationSummary().getKey().isEmpty()) { throw new InvalidArgumentException( "TaskResource must have a classification summary with a valid classification key."); } diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskResource.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskResource.java deleted file mode 100644 index 9421b7792..000000000 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskResource.java +++ /dev/null @@ -1,510 +0,0 @@ -package pro.taskana.rest.resource; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; -import org.springframework.hateoas.RepresentationModel; - -import pro.taskana.common.api.exceptions.InvalidArgumentException; -import pro.taskana.task.api.TaskState; -import pro.taskana.task.api.models.ObjectReference; -import pro.taskana.task.api.models.Task; - -/** EntityModel class for {@link Task}. */ -public class TaskResource extends RepresentationModel { - - private String taskId; - private String externalId; - private String created; // ISO-8601 - private String claimed; // ISO-8601 - private String completed; // ISO-8601 - private String modified; // ISO-8601 - private String planned; // ISO-8601 - private String due; // ISO-8601 - private String name; - private String creator; - private String description; - private String note; - private int priority; - private TaskState state; - private ClassificationSummaryResource classificationSummaryResource; - private WorkbasketSummaryResource workbasketSummaryResource; - private String businessProcessId; - private String parentBusinessProcessId; - private String owner; - private ObjectReference primaryObjRef; - private boolean isRead; - private boolean isTransferred; - // All objects have to be serializable - private List customAttributes = Collections.emptyList(); - private List callbackInfo = Collections.emptyList(); - private List attachments = new ArrayList<>(); - private String custom1; - private String custom2; - private String custom3; - private String custom4; - private String custom5; - private String custom6; - private String custom7; - private String custom8; - private String custom9; - private String custom10; - private String custom11; - private String custom12; - private String custom13; - private String custom14; - private String custom15; - private String custom16; - - public TaskResource() {} - - public TaskResource(Task task) throws InvalidArgumentException { - - taskId = task.getId(); - externalId = task.getExternalId(); - created = task.getCreated() != null ? task.getCreated().toString() : null; - claimed = task.getClaimed() != null ? task.getClaimed().toString() : null; - completed = task.getCompleted() != null ? task.getCompleted().toString() : null; - modified = task.getModified() != null ? task.getModified().toString() : null; - planned = task.getPlanned() != null ? task.getPlanned().toString() : null; - due = task.getDue() != null ? task.getDue().toString() : null; - name = task.getName(); - creator = task.getCreator(); - description = task.getDescription(); - note = task.getNote(); - priority = task.getPriority(); - state = task.getState(); - classificationSummaryResource = - new ClassificationSummaryResource(task.getClassificationSummary()); - workbasketSummaryResource = new WorkbasketSummaryResource(task.getWorkbasketSummary()); - businessProcessId = task.getBusinessProcessId(); - parentBusinessProcessId = task.getParentBusinessProcessId(); - owner = task.getOwner(); - primaryObjRef = task.getPrimaryObjRef(); - isRead = task.isRead(); - isTransferred = task.isTransferred(); - customAttributes = - task.getCustomAttributes().entrySet().stream() - .map(e -> new TaskResource.CustomAttribute(e.getKey(), e.getValue())) - .collect(Collectors.toList()); - callbackInfo = - task.getCallbackInfo().entrySet().stream() - .map(e -> new TaskResource.CustomAttribute(e.getKey(), e.getValue())) - .collect(Collectors.toList()); - - attachments = - task.getAttachments().stream().map(AttachmentResource::new).collect(Collectors.toList()); - custom1 = task.getCustomAttribute("1"); - custom2 = task.getCustomAttribute("2"); - custom3 = task.getCustomAttribute("3"); - custom4 = task.getCustomAttribute("4"); - custom5 = task.getCustomAttribute("5"); - custom6 = task.getCustomAttribute("6"); - custom7 = task.getCustomAttribute("7"); - custom8 = task.getCustomAttribute("8"); - custom9 = task.getCustomAttribute("9"); - custom10 = task.getCustomAttribute("10"); - custom11 = task.getCustomAttribute("11"); - custom12 = task.getCustomAttribute("12"); - custom13 = task.getCustomAttribute("13"); - custom14 = task.getCustomAttribute("14"); - custom15 = task.getCustomAttribute("15"); - custom16 = task.getCustomAttribute("16"); - } - - public String getTaskId() { - return taskId; - } - - public void setTaskId(String taskId) { - this.taskId = taskId; - } - - public String getExternalId() { - return externalId; - } - - public void setExternalId(String externalId) { - this.externalId = externalId; - } - - public String getCreated() { - return created; - } - - public void setCreated(String created) { - this.created = created; - } - - public String getClaimed() { - return claimed; - } - - public void setClaimed(String claimed) { - this.claimed = claimed; - } - - public String getCompleted() { - return completed; - } - - public void setCompleted(String completed) { - this.completed = completed; - } - - public String getModified() { - return modified; - } - - public void setModified(String modified) { - this.modified = modified; - } - - public String getPlanned() { - return planned; - } - - public void setPlanned(String planned) { - this.planned = planned; - } - - public String getDue() { - return due; - } - - public void setDue(String due) { - this.due = due; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getCreator() { - return creator; - } - - public void setCreator(String creator) { - this.creator = creator; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getNote() { - return note; - } - - public void setNote(String note) { - this.note = note; - } - - public int getPriority() { - return priority; - } - - public void setPriority(int priority) { - this.priority = priority; - } - - public TaskState getState() { - return state; - } - - public void setState(TaskState state) { - this.state = state; - } - - public ClassificationSummaryResource getClassificationSummaryResource() { - return classificationSummaryResource; - } - - public void setClassificationSummaryResource( - ClassificationSummaryResource classificationSummaryResource) { - this.classificationSummaryResource = classificationSummaryResource; - } - - public WorkbasketSummaryResource getWorkbasketSummaryResource() { - return workbasketSummaryResource; - } - - public void setWorkbasketSummaryResource(WorkbasketSummaryResource workbasketSummaryResource) { - this.workbasketSummaryResource = workbasketSummaryResource; - } - - public String getBusinessProcessId() { - return businessProcessId; - } - - public void setBusinessProcessId(String businessProcessId) { - this.businessProcessId = businessProcessId; - } - - public String getParentBusinessProcessId() { - return parentBusinessProcessId; - } - - public void setParentBusinessProcessId(String parentBusinessProcessId) { - this.parentBusinessProcessId = parentBusinessProcessId; - } - - public String getOwner() { - return owner; - } - - public void setOwner(String owner) { - this.owner = owner; - } - - public ObjectReference getPrimaryObjRef() { - return primaryObjRef; - } - - public void setPrimaryObjRef(ObjectReference primaryObjRef) { - this.primaryObjRef = primaryObjRef; - } - - public boolean isRead() { - return isRead; - } - - public void setRead(boolean isRead) { - this.isRead = isRead; - } - - public boolean isTransferred() { - return isTransferred; - } - - public void setTransferred(boolean isTransferred) { - this.isTransferred = isTransferred; - } - - public List getCustomAttributes() { - return customAttributes; - } - - public void setCustomAttributes(List customAttributes) { - this.customAttributes = customAttributes; - } - - public List getCallbackInfo() { - return callbackInfo; - } - - public void setCallbackInfo(List callbackInfo) { - this.callbackInfo = callbackInfo; - } - - public List getAttachments() { - return attachments; - } - - public void setAttachments(List attachments) { - this.attachments = attachments; - } - - public String getCustom1() { - return custom1; - } - - public void setCustom1(String custom1) { - this.custom1 = custom1; - } - - public String getCustom2() { - return custom2; - } - - public void setCustom2(String custom2) { - this.custom2 = custom2; - } - - public String getCustom3() { - return custom3; - } - - public void setCustom3(String custom3) { - this.custom3 = custom3; - } - - public String getCustom4() { - return custom4; - } - - public void setCustom4(String custom4) { - this.custom4 = custom4; - } - - public String getCustom5() { - return custom5; - } - - public void setCustom5(String custom5) { - this.custom5 = custom5; - } - - public String getCustom6() { - return custom6; - } - - public void setCustom6(String custom6) { - this.custom6 = custom6; - } - - public String getCustom7() { - return custom7; - } - - public void setCustom7(String custom7) { - this.custom7 = custom7; - } - - public String getCustom8() { - return custom8; - } - - public void setCustom8(String custom8) { - this.custom8 = custom8; - } - - public String getCustom9() { - return custom9; - } - - public void setCustom9(String custom9) { - this.custom9 = custom9; - } - - public String getCustom10() { - return custom10; - } - - public void setCustom10(String custom10) { - this.custom10 = custom10; - } - - public String getCustom11() { - return custom11; - } - - public void setCustom11(String custom11) { - this.custom11 = custom11; - } - - public String getCustom12() { - return custom12; - } - - public void setCustom12(String custom12) { - this.custom12 = custom12; - } - - public String getCustom13() { - return custom13; - } - - public void setCustom13(String custom13) { - this.custom13 = custom13; - } - - public String getCustom14() { - return custom14; - } - - public void setCustom14(String custom14) { - this.custom14 = custom14; - } - - public String getCustom15() { - return custom15; - } - - public void setCustom15(String custom15) { - this.custom15 = custom15; - } - - public String getCustom16() { - return custom16; - } - - public void setCustom16(String custom16) { - this.custom16 = custom16; - } - - @Override - public String toString() { - return "TaskResource [" - + "taskId= " - + this.taskId - + "externalId= " - + this.externalId - + "created= " - + this.created - + "modified= " - + this.modified - + "claimed= " - + this.claimed - + "completed= " - + this.completed - + "planned= " - + this.planned - + "due= " - + this.due - + "name= " - + this.name - + "creator= " - + this.creator - + "description= " - + this.description - + "priority= " - + this.priority - + "owner= " - + this.owner - + "]"; - } - - /** - * A CustomAttribute is a user customized attribute which is saved as a Map and can be retreived - * from either {@link Task#getCustomAttributes()} or {@link Task#getCallbackInfo()}. - */ - public static class CustomAttribute { - - private final String key; - private final String value; - - @SuppressWarnings("unused") - public CustomAttribute() { - this(null, null); - // necessary for jackson. - } - - public CustomAttribute(String key, String value) { - this.key = key; - this.value = value; - } - - public String getKey() { - return key; - } - - public String getValue() { - return value; - } - - @Override - public String toString() { - return "CustomAttribute [" + "key= " + this.key + "value= " + this.value + "]"; - } - } -} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskSummaryListResource.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskSummaryListResource.java deleted file mode 100644 index f67ea3be0..000000000 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskSummaryListResource.java +++ /dev/null @@ -1,29 +0,0 @@ -package pro.taskana.rest.resource; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.Collection; -import org.springframework.hateoas.Link; - -/** EntityModel class for {@link TaskSummaryResource} with Pagination. */ -public class TaskSummaryListResource extends PagedResources { - - public TaskSummaryListResource() { - super(); - } - - public TaskSummaryListResource( - Collection content, PageMetadata metadata, Iterable links) { - super(content, metadata, links); - } - - public TaskSummaryListResource( - Collection content, PageMetadata metadata, Link... links) { - super(content, metadata, links); - } - - @Override - @JsonProperty("tasks") - public Collection getContent() { - return super.getContent(); - } -} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskSummaryResource.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskSummaryRepresentationModel.java similarity index 74% rename from rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskSummaryResource.java rename to rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskSummaryRepresentationModel.java index ef3dad6d7..ce4598e1f 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskSummaryResource.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskSummaryRepresentationModel.java @@ -4,7 +4,6 @@ import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; import org.springframework.hateoas.RepresentationModel; -import org.springframework.hateoas.server.core.Relation; import pro.taskana.common.api.exceptions.InvalidArgumentException; import pro.taskana.task.api.TaskState; @@ -12,53 +11,57 @@ import pro.taskana.task.api.models.ObjectReference; import pro.taskana.task.api.models.TaskSummary; import pro.taskana.workbasket.api.models.WorkbasketSummary; -/** EntityModel class for {@link WorkbasketSummary}. */ -@Relation(collectionRelation = "tasks") -public class TaskSummaryResource extends RepresentationModel { +/** + * EntityModel class for {@link WorkbasketSummary}. + */ +public class TaskSummaryRepresentationModel + extends RepresentationModel { - private String taskId; - private String externalId; - private String created; // ISO-8601 - private String claimed; // ISO-8601 - private String completed; // ISO-8601 - private String modified; // ISO-8601 - private String planned; // ISO-8601 - private String due; // ISO-8601 - private String name; - private String creator; - private String note; - private String description; - private int priority; - private TaskState state; - private ClassificationSummaryResource classificationSummaryResource; - private WorkbasketSummaryResource workbasketSummaryResource; - private String businessProcessId; - private String parentBusinessProcessId; - private String owner; - private ObjectReference primaryObjRef; - private boolean isRead; - private boolean isTransferred; - private List attachmentSummaryResources = new ArrayList<>(); - private String custom1; - private String custom2; - private String custom3; - private String custom4; - private String custom5; - private String custom6; - private String custom7; - private String custom8; - private String custom9; - private String custom10; - private String custom11; - private String custom12; - private String custom13; - private String custom14; - private String custom15; - private String custom16; + protected String taskId; + protected String externalId; + protected String created; // ISO-8601 + protected String claimed; // ISO-8601 + protected String completed; // ISO-8601 + protected String modified; // ISO-8601 + protected String planned; // ISO-8601 + protected String due; // ISO-8601 + protected String name; + protected String creator; + protected String note; + protected String description; + protected int priority; + protected TaskState state; + protected ClassificationSummaryRepresentationModel classificationSummary; + protected WorkbasketSummaryRepresentationModel workbasketSummary; + protected String businessProcessId; + protected String parentBusinessProcessId; + protected String owner; + protected ObjectReference primaryObjRef; + protected boolean isRead; + protected boolean isTransferred; + protected String custom1; + protected String custom2; + protected String custom3; + protected String custom4; + protected String custom5; + protected String custom6; + protected String custom7; + protected String custom8; + protected String custom9; + protected String custom10; + protected String custom11; + protected String custom12; + protected String custom13; + protected String custom14; + protected String custom15; + protected String custom16; + private List attachmentSummaries = + new ArrayList<>(); - TaskSummaryResource() {} + TaskSummaryRepresentationModel() { + } - public TaskSummaryResource(TaskSummary taskSummary) throws InvalidArgumentException { + public TaskSummaryRepresentationModel(TaskSummary taskSummary) throws InvalidArgumentException { this.taskId = taskSummary.getId(); this.externalId = taskSummary.getExternalId(); created = taskSummary.getCreated() != null ? taskSummary.getCreated().toString() : null; @@ -73,19 +76,19 @@ public class TaskSummaryResource extends RepresentationModel getAttachmentSummaries() { - return attachmentSummaryResources; + public List getAttachmentSummaries() { + return attachmentSummaries; } - public void setAttachmentSummaries(List attachmentSummaryResources) { - this.attachmentSummaryResources = attachmentSummaryResources; + public void setAttachmentSummaries( + List attachmentSummaries) { + this.attachmentSummaries = attachmentSummaries; } public String getCustom1() { diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskSummaryRepresentationModelAssembler.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskSummaryRepresentationModelAssembler.java new file mode 100644 index 000000000..f8c947bbe --- /dev/null +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskSummaryRepresentationModelAssembler.java @@ -0,0 +1,44 @@ +package pro.taskana.rest.resource; + +import static pro.taskana.rest.resource.TaskanaPagedModelKeys.TASKS; + +import java.util.List; +import java.util.stream.Collectors; +import org.springframework.hateoas.PagedModel.PageMetadata; +import org.springframework.hateoas.server.RepresentationModelAssembler; +import org.springframework.lang.NonNull; +import org.springframework.stereotype.Component; + +import pro.taskana.common.api.exceptions.InvalidArgumentException; +import pro.taskana.common.api.exceptions.SystemException; +import pro.taskana.rest.Mapping; +import pro.taskana.rest.resource.links.PageLinks; +import pro.taskana.task.api.models.TaskSummary; + +/** EntityModel assembler for {@link TaskSummaryRepresentationModel}. */ +@Component +public class TaskSummaryRepresentationModelAssembler + implements RepresentationModelAssembler { + + @NonNull + @Override + public TaskSummaryRepresentationModel toModel(@NonNull TaskSummary taskSummary) { + TaskSummaryRepresentationModel resource; + try { + resource = new TaskSummaryRepresentationModel(taskSummary); + return resource; + } catch (InvalidArgumentException e) { + throw new SystemException("caught unexpected Exception.", e.getCause()); + } + } + + @PageLinks(Mapping.URL_TASKS) + public TaskanaPagedModel toPageModel( + List taskSummaries, PageMetadata pageMetadata) { + return taskSummaries.stream() + .map(this::toModel) + .collect( + Collectors.collectingAndThen( + Collectors.toList(), list -> new TaskanaPagedModel<>(TASKS, list, pageMetadata))); + } +} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskSummaryResourceAssembler.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskSummaryResourceAssembler.java deleted file mode 100644 index b3cfe5494..000000000 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskSummaryResourceAssembler.java +++ /dev/null @@ -1,40 +0,0 @@ -package pro.taskana.rest.resource; - -import java.util.List; -import org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport; -import org.springframework.stereotype.Component; - -import pro.taskana.common.api.exceptions.InvalidArgumentException; -import pro.taskana.common.api.exceptions.SystemException; -import pro.taskana.rest.Mapping; -import pro.taskana.rest.TaskController; -import pro.taskana.rest.resource.PagedResources.PageMetadata; -import pro.taskana.rest.resource.links.PageLinks; -import pro.taskana.task.api.models.TaskSummary; - -/** EntityModel assembler for {@link TaskSummaryResource}. */ -@Component -public class TaskSummaryResourceAssembler - extends RepresentationModelAssemblerSupport { - - public TaskSummaryResourceAssembler() { - super(TaskController.class, TaskSummaryResource.class); - } - - @Override - public TaskSummaryResource toModel(TaskSummary taskSummary) { - TaskSummaryResource resource; - try { - resource = new TaskSummaryResource(taskSummary); - return resource; - } catch (InvalidArgumentException e) { - throw new SystemException("caught unexpected Exception.", e.getCause()); - } - } - - @PageLinks(Mapping.URL_TASKS) - public TaskSummaryListResource toCollectionModel( - List taskSummaries, PageMetadata pageMetadata) { - return new TaskSummaryListResource(toCollectionModel(taskSummaries).getContent(), pageMetadata); - } -} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskanaPagedModel.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskanaPagedModel.java new file mode 100644 index 000000000..7df667946 --- /dev/null +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskanaPagedModel.java @@ -0,0 +1,76 @@ +package pro.taskana.rest.resource; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonProperty.Access; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import org.springframework.hateoas.PagedModel.PageMetadata; +import org.springframework.hateoas.RepresentationModel; + +/** + * Optional Paging model for RepresentationModels. + * + * @param The class of the paginated content + */ +public class TaskanaPagedModel> + extends RepresentationModel> { + + @JsonIgnore + private TaskanaPagedModelKeys key; + @JsonIgnore + private Collection content; + + @JsonProperty(value = "page", access = Access.WRITE_ONLY) + private PageMetadata metadata; + + @SuppressWarnings("unused") // needed for jackson + private TaskanaPagedModel() { + } + + /** + * Creates a new {@link TaskanaPagedModel} from the given content. + * + * @param property property which will be used for serialization. + * @param content must not be {@literal null}. + * @param metadata the metadata. Can be null. If null, no metadata will be serialized. + */ + public TaskanaPagedModel( + TaskanaPagedModelKeys property, Collection content, PageMetadata metadata) { + this.content = content; + this.metadata = metadata; + this.key = property; + } + + public Collection getContent() { + return Collections.unmodifiableCollection(content); + } + + public PageMetadata getMetadata() { + return metadata; + } + + @JsonAnySetter + private void deserialize(String propertyName, Collection content) { + TaskanaPagedModelKeys.getEnumFromPropertyName(propertyName) + .ifPresent( + pagedModelKey -> { + this.key = pagedModelKey; + this.content = content; + }); + } + + @JsonAnyGetter + private Map serialize() { + HashMap jsonMap = new HashMap<>(); + if (metadata != null) { + jsonMap.put("page", metadata); + } + jsonMap.put(key.getPropertyName(), content); + return jsonMap; + } +} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskanaPagedModelKeys.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskanaPagedModelKeys.java new file mode 100644 index 000000000..35c4a2089 --- /dev/null +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskanaPagedModelKeys.java @@ -0,0 +1,34 @@ +package pro.taskana.rest.resource; + +import java.util.Arrays; +import java.util.Map; +import java.util.Optional; +import java.util.function.Function; +import java.util.stream.Collectors; + +public enum TaskanaPagedModelKeys { + ACCESSITEMS("accessItems"), + CLASSIFICATIONS("classifications"), + DISTRIBUTION_TARGETS("distributionTargets"), + TASKS("tasks"), + TASK_COMMENTS("taskComments"), + WORKBASKETS("workbaskets"); + + private static final Map PROPERTY_MAP = + Arrays.stream(TaskanaPagedModelKeys.values()) + .collect(Collectors.toMap(TaskanaPagedModelKeys::getPropertyName, Function.identity())); + + private final String propertyName; + + TaskanaPagedModelKeys(String propertyName) { + this.propertyName = propertyName; + } + + public String getPropertyName() { + return propertyName; + } + + public static Optional getEnumFromPropertyName(String propertyName) { + return Optional.ofNullable(PROPERTY_MAP.get(propertyName)); + } +} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskanaUserInfoResource.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskanaUserInfoRepresentationModel.java similarity index 86% rename from rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskanaUserInfoResource.java rename to rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskanaUserInfoRepresentationModel.java index dbf363153..e00a19ef7 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskanaUserInfoResource.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/TaskanaUserInfoRepresentationModel.java @@ -8,7 +8,8 @@ import pro.taskana.common.api.LoggerUtils; import pro.taskana.common.api.TaskanaRole; /** EntityModel class for user information. */ -public class TaskanaUserInfoResource extends RepresentationModel { +public class TaskanaUserInfoRepresentationModel + extends RepresentationModel { private String userId; private List groupIds = new ArrayList<>(); @@ -40,7 +41,7 @@ public class TaskanaUserInfoResource extends RepresentationModel getContent() { - return super.getContent(); - } -} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketAccessItemResource.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketAccessItemRepresentationModel.java similarity index 91% rename from rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketAccessItemResource.java rename to rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketAccessItemRepresentationModel.java index d410bfdc5..6e265b55b 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketAccessItemResource.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketAccessItemRepresentationModel.java @@ -1,26 +1,20 @@ package pro.taskana.rest.resource; -import javax.validation.constraints.NotNull; import org.springframework.hateoas.RepresentationModel; -import org.springframework.hateoas.server.core.Relation; import pro.taskana.workbasket.api.models.WorkbasketAccessItem; -/** EntityModel class for {@link WorkbasketAccessItem}. */ -@Relation(collectionRelation = "accessItems") -public class WorkbasketAccessItemResource - extends RepresentationModel { +/** + * EntityModel class for {@link WorkbasketAccessItem}. + */ +public class WorkbasketAccessItemRepresentationModel + extends RepresentationModel { private String accessItemId; - - @NotNull private String workbasketId; - - @NotNull private String workbasketKey; - - @NotNull private String accessId; - + private String workbasketId; + private String workbasketKey; + private String accessId; private String accessName; - private boolean permRead; private boolean permOpen; private boolean permAppend; @@ -39,9 +33,9 @@ public class WorkbasketAccessItemResource private boolean permCustom11; private boolean permCustom12; - public WorkbasketAccessItemResource() {} + public WorkbasketAccessItemRepresentationModel() {} - public WorkbasketAccessItemResource(WorkbasketAccessItem workbasketAccessItem) { + public WorkbasketAccessItemRepresentationModel(WorkbasketAccessItem workbasketAccessItem) { this.accessItemId = workbasketAccessItem.getId(); this.workbasketId = workbasketAccessItem.getWorkbasketId(); this.workbasketKey = workbasketAccessItem.getWorkbasketKey(); diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketAccessItemRepresentationModelAssembler.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketAccessItemRepresentationModelAssembler.java new file mode 100644 index 000000000..0ac770c7f --- /dev/null +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketAccessItemRepresentationModelAssembler.java @@ -0,0 +1,85 @@ +package pro.taskana.rest.resource; + +import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo; +import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn; +import static pro.taskana.rest.resource.TaskanaPagedModelKeys.ACCESSITEMS; + +import java.util.List; +import java.util.stream.Collectors; +import org.springframework.beans.BeanUtils; +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; + +import pro.taskana.common.api.exceptions.NotAuthorizedException; +import pro.taskana.rest.Mapping; +import pro.taskana.rest.WorkbasketController; +import pro.taskana.rest.resource.links.PageLinks; +import pro.taskana.workbasket.api.WorkbasketService; +import pro.taskana.workbasket.api.exceptions.WorkbasketNotFoundException; +import pro.taskana.workbasket.api.models.WorkbasketAccessItem; +import pro.taskana.workbasket.internal.models.WorkbasketAccessItemImpl; + +/** + * Transforms {@link WorkbasketAccessItem} to its resource counterpart {@link + * WorkbasketAccessItemRepresentationModel} and vice versa. + */ +@Component +public class WorkbasketAccessItemRepresentationModelAssembler + implements RepresentationModelAssembler< + WorkbasketAccessItem, WorkbasketAccessItemRepresentationModel> { + + private final WorkbasketService workbasketService; + + @Autowired + public WorkbasketAccessItemRepresentationModelAssembler( + WorkbasketService workbasketService) { + this.workbasketService = workbasketService; + } + + @NonNull + @Override + public WorkbasketAccessItemRepresentationModel toModel(@NonNull WorkbasketAccessItem wbAccItem) { + return new WorkbasketAccessItemRepresentationModel(wbAccItem); + } + + public WorkbasketAccessItem toEntityModel( + WorkbasketAccessItemRepresentationModel wbAccItemResource) { + WorkbasketAccessItemImpl wbAccItemModel = + (WorkbasketAccessItemImpl) + workbasketService.newWorkbasketAccessItem( + wbAccItemResource.getWorkbasketId(), wbAccItemResource.getAccessId()); + BeanUtils.copyProperties(wbAccItemResource, wbAccItemModel); + wbAccItemModel.setId(wbAccItemResource.getAccessItemId()); + return wbAccItemModel; + } + + public TaskanaPagedModel toPageModel( + String workbasketId, + List workbasketAccessItems, + PageMetadata pageMetadata) + throws NotAuthorizedException, WorkbasketNotFoundException { + TaskanaPagedModel pageModel = + toPageModel(workbasketAccessItems, pageMetadata); + pageModel.add( + linkTo(methodOn(WorkbasketController.class).getWorkbasketAccessItems(workbasketId)) + .withSelfRel()); + pageModel.add( + linkTo(methodOn(WorkbasketController.class).getWorkbasket(workbasketId)) + .withRel("workbasket")); + return pageModel; + } + + @PageLinks(Mapping.URL_WORKBASKETACCESSITEMS) + public TaskanaPagedModel toPageModel( + List workbasketAccessItems, PageMetadata pageMetadata) { + return workbasketAccessItems.stream() + .map(this::toModel) + .collect( + Collectors.collectingAndThen( + Collectors.toList(), + list -> new TaskanaPagedModel<>(ACCESSITEMS, list, pageMetadata))); + } +} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketAccessItemResourceAssembler.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketAccessItemResourceAssembler.java deleted file mode 100644 index 6dd1105d7..000000000 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketAccessItemResourceAssembler.java +++ /dev/null @@ -1,71 +0,0 @@ -package pro.taskana.rest.resource; - -import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo; -import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn; - -import java.util.List; -import org.springframework.beans.BeanUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport; -import org.springframework.stereotype.Component; - -import pro.taskana.common.api.exceptions.NotAuthorizedException; -import pro.taskana.rest.Mapping; -import pro.taskana.rest.WorkbasketController; -import pro.taskana.rest.resource.PagedResources.PageMetadata; -import pro.taskana.rest.resource.links.PageLinks; -import pro.taskana.workbasket.api.WorkbasketService; -import pro.taskana.workbasket.api.exceptions.WorkbasketNotFoundException; -import pro.taskana.workbasket.api.models.WorkbasketAccessItem; -import pro.taskana.workbasket.internal.models.WorkbasketAccessItemImpl; - -/** - * Transforms {@link WorkbasketAccessItem} to its resource counterpart {@link - * WorkbasketAccessItemResource} and vice versa. - */ -@Component -public class WorkbasketAccessItemResourceAssembler - extends RepresentationModelAssemblerSupport< - WorkbasketAccessItem, WorkbasketAccessItemResource> { - - @Autowired private WorkbasketService workbasketService; - - public WorkbasketAccessItemResourceAssembler() { - super(WorkbasketController.class, WorkbasketAccessItemResource.class); - } - - public WorkbasketAccessItemResource toModel(WorkbasketAccessItem wbAccItem) { - return new WorkbasketAccessItemResource(wbAccItem); - } - - public WorkbasketAccessItem toModel(WorkbasketAccessItemResource wbAccItemResource) { - WorkbasketAccessItemImpl wbAccItemModel = - (WorkbasketAccessItemImpl) - workbasketService.newWorkbasketAccessItem( - wbAccItemResource.getWorkbasketId(), wbAccItemResource.getAccessId()); - BeanUtils.copyProperties(wbAccItemResource, wbAccItemModel); - wbAccItemModel.setId(wbAccItemResource.getAccessItemId()); - return wbAccItemModel; - } - - @PageLinks(Mapping.URL_WORKBASKETACCESSITEMS) - public WorkbasketAccessItemListResource toCollectionModel( - List entities, PageMetadata pageMetadata) { - return new WorkbasketAccessItemListResource( - toCollectionModel(entities).getContent(), pageMetadata); - } - - public WorkbasketAccessItemListResource toCollectionModel( - String workbasketId, List entities) - throws NotAuthorizedException, WorkbasketNotFoundException { - WorkbasketAccessItemListResource accessItemListResource = - new WorkbasketAccessItemListResource(super.toCollectionModel(entities).getContent(), null); - accessItemListResource.add( - linkTo(methodOn(WorkbasketController.class).getWorkbasketAccessItems(workbasketId)) - .withSelfRel()); - accessItemListResource.add( - linkTo(methodOn(WorkbasketController.class).getWorkbasket(workbasketId)) - .withRel("workbasket")); - return accessItemListResource; - } -} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketDefinitionResource.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketDefinitionRepresentationModel.java similarity index 72% rename from rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketDefinitionResource.java rename to rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketDefinitionRepresentationModel.java index 445248a98..9853197de 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketDefinitionResource.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketDefinitionRepresentationModel.java @@ -2,23 +2,25 @@ package pro.taskana.rest.resource; import java.util.List; import java.util.Set; +import org.springframework.hateoas.RepresentationModel; import pro.taskana.common.api.LoggerUtils; import pro.taskana.workbasket.internal.models.WorkbasketAccessItemImpl; /** this class represents a workbasket including its distro targets and authorisations. */ -public class WorkbasketDefinitionResource { +public class WorkbasketDefinitionRepresentationModel + extends RepresentationModel { private Set distributionTargets; private List authorizations; - private WorkbasketResourceWithoutLinks workbasket; + private WorkbasketRepresentationModelWithoutLinks workbasket; - public WorkbasketDefinitionResource() { + public WorkbasketDefinitionRepresentationModel() { // necessary for de-serializing } - public WorkbasketDefinitionResource( - WorkbasketResourceWithoutLinks workbasket, + public WorkbasketDefinitionRepresentationModel( + WorkbasketRepresentationModelWithoutLinks workbasket, Set distributionTargets, List authorizations) { super(); @@ -43,11 +45,11 @@ public class WorkbasketDefinitionResource { this.authorizations = authorizations; } - public WorkbasketResourceWithoutLinks getWorkbasket() { + public WorkbasketRepresentationModelWithoutLinks getWorkbasket() { return workbasket; } - public void setWorkbasket(WorkbasketResourceWithoutLinks workbasket) { + public void setWorkbasket(WorkbasketRepresentationModelWithoutLinks workbasket) { this.workbasket = workbasket; } diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketDefinitionResourceAssembler.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketDefinitionRepresentationModelAssembler.java similarity index 70% rename from rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketDefinitionResourceAssembler.java rename to rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketDefinitionRepresentationModelAssembler.java index aa185f0b2..7b6dd497d 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketDefinitionResourceAssembler.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketDefinitionRepresentationModelAssembler.java @@ -7,6 +7,7 @@ import java.util.Set; import java.util.stream.Collectors; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.lang.NonNull; import org.springframework.stereotype.Component; import pro.taskana.common.api.exceptions.NotAuthorizedException; @@ -19,27 +20,35 @@ import pro.taskana.workbasket.internal.models.WorkbasketAccessItemImpl; import pro.taskana.workbasket.internal.models.WorkbasketImpl; /** - * Transforms {@link Workbasket} into a {@link WorkbasketDefinitionResource} containing all - * additional information about that workbasket. + * Transforms {@link Workbasket} into a {@link WorkbasketDefinitionRepresentationModel} containing + * all additional information about that workbasket. */ @Component -public class WorkbasketDefinitionResourceAssembler { +public class WorkbasketDefinitionRepresentationModelAssembler { - @Autowired private WorkbasketService workbasketService; + private final WorkbasketService workbasketService; + + @Autowired + public WorkbasketDefinitionRepresentationModelAssembler( + WorkbasketService workbasketService) { + this.workbasketService = workbasketService; + } /** * maps the distro targets to their id to remove overhead. * * @param workbasket {@link Workbasket} which will be converted - * @return a {@link WorkbasketDefinitionResource}, containing the {@code basket}, its distribution - * targets and its authorizations + * @return a {@link WorkbasketDefinitionRepresentationModel}, containing the {@code basket}, its + * distribution targets and its authorizations * @throws NotAuthorizedException if the user is not authorized * @throws WorkbasketNotFoundException if {@code basket} is an unknown workbasket */ - public WorkbasketDefinitionResource toModel(Workbasket workbasket) + @NonNull + public WorkbasketDefinitionRepresentationModel toEntityModel(Workbasket workbasket) throws NotAuthorizedException, WorkbasketNotFoundException { - WorkbasketResourceWithoutLinks basket = new WorkbasketResourceWithoutLinks(workbasket); + WorkbasketRepresentationModelWithoutLinks basket = + new WorkbasketRepresentationModelWithoutLinks(workbasket); List authorizations = new ArrayList<>(); for (WorkbasketAccessItem accessItem : @@ -50,10 +59,10 @@ public class WorkbasketDefinitionResourceAssembler { workbasketService.getDistributionTargets(workbasket.getId()).stream() .map(WorkbasketSummary::getId) .collect(Collectors.toSet()); - return new WorkbasketDefinitionResource(basket, distroTargets, authorizations); + return new WorkbasketDefinitionRepresentationModel(basket, distroTargets, authorizations); } - public Workbasket toModel(WorkbasketResource wbResource) { + public Workbasket toEntityModel(WorkbasketRepresentationModel wbResource) { WorkbasketImpl workbasket = (WorkbasketImpl) workbasketService.newWorkbasket(wbResource.getKey(), wbResource.getDomain()); diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketRepresentationModel.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketRepresentationModel.java new file mode 100644 index 000000000..efd3abd5d --- /dev/null +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketRepresentationModel.java @@ -0,0 +1,58 @@ +package pro.taskana.rest.resource; + +import pro.taskana.workbasket.api.models.Workbasket; + +/** + * EntityModel class for {@link Workbasket}. + */ +public class WorkbasketRepresentationModel + extends WorkbasketSummaryRepresentationModel { + + + private String created; // ISO-8601 + private String modified; // ISO-8601 + + @SuppressWarnings("unused") //Mandatory for Jackson + protected WorkbasketRepresentationModel() { + } + + public WorkbasketRepresentationModel(Workbasket workbasket) { + super(workbasket); + this.created = workbasket.getCreated() != null ? workbasket.getCreated().toString() : null; + this.modified = workbasket.getModified() != null ? workbasket.getModified().toString() : null; + } + + public String getCreated() { + return created; + } + + public void setCreated(String created) { + this.created = created; + } + + public String getModified() { + return modified; + } + + public void setModified(String modified) { + this.modified = modified; + } + + @Override + public String toString() { + return "WorkbasketResource [" + + "workbasketId= " + + this.workbasketId + + "key= " + + this.key + + "name= " + + this.name + + "domain= " + + this.domain + + "type= " + + this.type + + "owner= " + + this.owner + + "]"; + } +} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketResourceAssembler.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketRepresentationModelAssembler.java similarity index 77% rename from rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketResourceAssembler.java rename to rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketRepresentationModelAssembler.java index 99bc97ab1..925184a22 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketResourceAssembler.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketRepresentationModelAssembler.java @@ -6,7 +6,8 @@ import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn; import java.time.Instant; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport; +import org.springframework.hateoas.server.RepresentationModelAssembler; +import org.springframework.lang.NonNull; import org.springframework.stereotype.Component; import org.springframework.util.LinkedMultiValueMap; @@ -20,31 +21,33 @@ import pro.taskana.workbasket.api.models.Workbasket; import pro.taskana.workbasket.internal.models.WorkbasketImpl; /** - * Transforms {@link Workbasket} to its resource counterpart {@link WorkbasketResource} and vice - * versa. + * Transforms {@link Workbasket} to its resource counterpart {@link WorkbasketRepresentationModel} + * and vice versa. */ @Component -public class WorkbasketResourceAssembler - extends RepresentationModelAssemblerSupport { +public class WorkbasketRepresentationModelAssembler + implements RepresentationModelAssembler { private final WorkbasketService workbasketService; @Autowired - public WorkbasketResourceAssembler(WorkbasketService workbasketService) { - super(WorkbasketController.class, WorkbasketResource.class); + public WorkbasketRepresentationModelAssembler( + WorkbasketService workbasketService) { this.workbasketService = workbasketService; } - public WorkbasketResource toModel(Workbasket wb) { + @NonNull + @Override + public WorkbasketRepresentationModel toModel(@NonNull Workbasket wb) { try { - WorkbasketResource resource = new WorkbasketResource(wb); + WorkbasketRepresentationModel resource = new WorkbasketRepresentationModel(wb); return addLinks(resource, wb); } catch (Exception e) { throw new SystemException("caught unexpected Exception.", e.getCause()); } } - public Workbasket toModel(WorkbasketResource wbResource) { + public Workbasket toEntityModel(WorkbasketRepresentationModel wbResource) { String wbKey = wbResource.getKey(); String wbDomain = wbResource.getDomain(); WorkbasketImpl workbasket = (WorkbasketImpl) workbasketService.newWorkbasket(wbKey, wbDomain); @@ -60,7 +63,8 @@ public class WorkbasketResourceAssembler return workbasket; } - private WorkbasketResource addLinks(WorkbasketResource resource, Workbasket wb) + private WorkbasketRepresentationModel addLinks( + WorkbasketRepresentationModel resource, Workbasket wb) throws NotAuthorizedException, WorkbasketNotFoundException, InvalidArgumentException { resource.add( linkTo(methodOn(WorkbasketController.class).getWorkbasket(wb.getId())).withSelfRel()); diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketResourceWithoutLinks.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketRepresentationModelWithoutLinks.java similarity index 58% rename from rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketResourceWithoutLinks.java rename to rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketRepresentationModelWithoutLinks.java index 056bda2a1..2843049d0 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketResourceWithoutLinks.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketRepresentationModelWithoutLinks.java @@ -6,11 +6,11 @@ import pro.taskana.workbasket.api.models.Workbasket; /** EntityModel class for {@link Workbasket} but without links property. */ @JsonIgnoreProperties(value = {"links"}) -public class WorkbasketResourceWithoutLinks extends WorkbasketResource { +public class WorkbasketRepresentationModelWithoutLinks extends WorkbasketRepresentationModel { - WorkbasketResourceWithoutLinks() {} + WorkbasketRepresentationModelWithoutLinks() {} - WorkbasketResourceWithoutLinks(Workbasket workbasket) { + WorkbasketRepresentationModelWithoutLinks(Workbasket workbasket) { super(workbasket); } } diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketResource.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketResource.java deleted file mode 100644 index 465f75920..000000000 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketResource.java +++ /dev/null @@ -1,205 +0,0 @@ -package pro.taskana.rest.resource; - -import javax.validation.constraints.NotNull; -import org.springframework.hateoas.RepresentationModel; - -import pro.taskana.workbasket.api.WorkbasketType; -import pro.taskana.workbasket.api.models.Workbasket; - -/** EntityModel class for {@link Workbasket}. */ -public class WorkbasketResource extends RepresentationModel { - - private String workbasketId; - @NotNull private String key; - @NotNull private String name; - @NotNull private String domain; - @NotNull private WorkbasketType type; - private String created; // ISO-8601 - private String modified; // ISO-8601 - private String description; - private String owner; - private String custom1; - private String custom2; - private String custom3; - private String custom4; - private String orgLevel1; - private String orgLevel2; - private String orgLevel3; - private String orgLevel4; - - public WorkbasketResource() {} - - public WorkbasketResource(Workbasket workbasket) { - this.workbasketId = workbasket.getId(); - this.key = workbasket.getKey(); - this.name = workbasket.getName(); - this.domain = workbasket.getDomain(); - this.type = workbasket.getType(); - this.created = workbasket.getCreated() != null ? workbasket.getCreated().toString() : null; - this.modified = workbasket.getModified() != null ? workbasket.getModified().toString() : null; - this.description = workbasket.getDescription(); - this.owner = workbasket.getOwner(); - this.custom1 = workbasket.getCustom1(); - this.custom2 = workbasket.getCustom2(); - this.custom3 = workbasket.getCustom3(); - this.custom4 = workbasket.getCustom4(); - this.orgLevel1 = workbasket.getOrgLevel1(); - this.orgLevel2 = workbasket.getOrgLevel2(); - this.orgLevel3 = workbasket.getOrgLevel3(); - this.orgLevel4 = workbasket.getOrgLevel4(); - } - - public String getWorkbasketId() { - return workbasketId; - } - - public void setWorkbasketId(String workbasketId) { - this.workbasketId = workbasketId; - } - - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDomain() { - return domain; - } - - public void setDomain(String domain) { - this.domain = domain; - } - - public WorkbasketType getType() { - return type; - } - - public void setType(WorkbasketType type) { - this.type = type; - } - - public String getCreated() { - return created; - } - - public void setCreated(String created) { - this.created = created; - } - - public String getModified() { - return modified; - } - - public void setModified(String modified) { - this.modified = modified; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getOwner() { - return owner; - } - - public void setOwner(String owner) { - this.owner = owner; - } - - public String getCustom1() { - return custom1; - } - - public void setCustom1(String custom1) { - this.custom1 = custom1; - } - - public String getCustom2() { - return custom2; - } - - public void setCustom2(String custom2) { - this.custom2 = custom2; - } - - public String getCustom3() { - return custom3; - } - - public void setCustom3(String custom3) { - this.custom3 = custom3; - } - - public String getCustom4() { - return custom4; - } - - public void setCustom4(String custom4) { - this.custom4 = custom4; - } - - public String getOrgLevel1() { - return orgLevel1; - } - - public void setOrgLevel1(String orgLevel1) { - this.orgLevel1 = orgLevel1; - } - - public String getOrgLevel2() { - return orgLevel2; - } - - public void setOrgLevel2(String orgLevel2) { - this.orgLevel2 = orgLevel2; - } - - public String getOrgLevel3() { - return orgLevel3; - } - - public void setOrgLevel3(String orgLevel3) { - this.orgLevel3 = orgLevel3; - } - - public String getOrgLevel4() { - return orgLevel4; - } - - public void setOrgLevel4(String orgLevel4) { - this.orgLevel4 = orgLevel4; - } - - @Override - public String toString() { - return "WorkbasketResource [" - + "workbasketId= " - + this.workbasketId - + "key= " - + this.key - + "name= " - + this.name - + "domain= " - + this.domain - + "type= " - + this.type - + "owner= " - + this.owner - + "]"; - } -} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketSummaryListResource.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketSummaryListResource.java deleted file mode 100644 index 2fe7f5e41..000000000 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketSummaryListResource.java +++ /dev/null @@ -1,29 +0,0 @@ -package pro.taskana.rest.resource; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.Collection; -import org.springframework.hateoas.Link; - -/** EntityModel class for {@link WorkbasketSummaryResource} with Pagination. */ -public class WorkbasketSummaryListResource extends PagedResources { - - public WorkbasketSummaryListResource() { - super(); - } - - public WorkbasketSummaryListResource( - Collection content, PageMetadata metadata, Link... links) { - super(content, metadata, links); - } - - public WorkbasketSummaryListResource( - Collection content, PageMetadata metadata, Iterable links) { - super(content, metadata, links); - } - - @Override - @JsonProperty("workbaskets") - public Collection getContent() { - return super.getContent(); - } -} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketSummaryResource.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketSummaryRepresentationModel.java similarity index 80% rename from rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketSummaryResource.java rename to rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketSummaryRepresentationModel.java index 433a1a3bb..3da86eb1d 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketSummaryResource.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketSummaryRepresentationModel.java @@ -1,41 +1,37 @@ package pro.taskana.rest.resource; -import javax.validation.constraints.NotNull; import org.springframework.hateoas.RepresentationModel; -import org.springframework.hateoas.server.core.Relation; import pro.taskana.workbasket.api.WorkbasketType; import pro.taskana.workbasket.api.models.WorkbasketSummary; -/** EntityModel class for {@link WorkbasketSummary}. */ -@Relation(collectionRelation = "workbaskets") -public class WorkbasketSummaryResource extends RepresentationModel { +/** + * EntityModel class for {@link WorkbasketSummary}. + */ +public class WorkbasketSummaryRepresentationModel + extends RepresentationModel { - private String workbasketId; - - @NotNull private String key; - - @NotNull private String name; - - @NotNull private String domain; - - @NotNull private WorkbasketType type; - - private String description; - private String owner; - private String custom1; - private String custom2; - private String custom3; - private String custom4; - private String orgLevel1; - private String orgLevel2; - private String orgLevel3; - private String orgLevel4; + protected String workbasketId; + protected String key; + protected String name; + protected String domain; + protected WorkbasketType type; + protected String description; + protected String owner; + protected String custom1; + protected String custom2; + protected String custom3; + protected String custom4; + protected String orgLevel1; + protected String orgLevel2; + protected String orgLevel3; + protected String orgLevel4; private boolean markedForDeletion; - public WorkbasketSummaryResource() {} + public WorkbasketSummaryRepresentationModel() { + } - public WorkbasketSummaryResource(WorkbasketSummary workbasketSummary) { + public WorkbasketSummaryRepresentationModel(WorkbasketSummary workbasketSummary) { this.workbasketId = workbasketSummary.getId(); this.key = workbasketSummary.getKey(); this.name = workbasketSummary.getName(); diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketSummaryRepresentationModelAssembler.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketSummaryRepresentationModelAssembler.java new file mode 100644 index 000000000..406f8bc2b --- /dev/null +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketSummaryRepresentationModelAssembler.java @@ -0,0 +1,66 @@ +package pro.taskana.rest.resource; + +import static pro.taskana.rest.resource.TaskanaPagedModelKeys.WORKBASKETS; + +import java.util.List; +import java.util.stream.Collectors; +import org.springframework.beans.BeanUtils; +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; + +import pro.taskana.rest.Mapping; +import pro.taskana.rest.resource.links.PageLinks; +import pro.taskana.workbasket.api.WorkbasketService; +import pro.taskana.workbasket.api.models.WorkbasketSummary; +import pro.taskana.workbasket.internal.models.WorkbasketImpl; + +/** + * EntityModel assembler for {@link WorkbasketSummaryRepresentationModel}. + */ +@Component +public class WorkbasketSummaryRepresentationModelAssembler implements + RepresentationModelAssembler { + + private WorkbasketService workbasketService; + + public WorkbasketSummaryRepresentationModelAssembler() { + } + + @Autowired + public WorkbasketSummaryRepresentationModelAssembler(WorkbasketService workbasketService) { + this.workbasketService = workbasketService; + } + + @NonNull + @Override + public WorkbasketSummaryRepresentationModel toModel( + @NonNull WorkbasketSummary workbasketSummary) { + return new WorkbasketSummaryRepresentationModel(workbasketSummary); + } + + public WorkbasketSummary toEntityModel(WorkbasketSummaryRepresentationModel resource) { + WorkbasketImpl workbasket = + (WorkbasketImpl) workbasketService.newWorkbasket(resource.getKey(), resource.getDomain()); + workbasket.setId(resource.getWorkbasketId()); + BeanUtils.copyProperties(resource, workbasket); + return workbasket.asSummary(); + } + + @PageLinks(Mapping.URL_WORKBASKET) + public TaskanaPagedModel toPageModel( + List workbasketSummaries, PageMetadata pageMetadata) { + return workbasketSummaries.stream() + .map(this::toModel) + .collect( + Collectors.collectingAndThen( + Collectors.toList(), + list -> new TaskanaPagedModel<>(getKey(), list, pageMetadata))); + } + + protected TaskanaPagedModelKeys getKey() { + return WORKBASKETS; + } +} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketSummaryResourceAssembler.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketSummaryResourceAssembler.java deleted file mode 100644 index d989f6abe..000000000 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/WorkbasketSummaryResourceAssembler.java +++ /dev/null @@ -1,47 +0,0 @@ -package pro.taskana.rest.resource; - -import java.util.List; -import org.springframework.beans.BeanUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport; -import org.springframework.stereotype.Component; - -import pro.taskana.rest.Mapping; -import pro.taskana.rest.WorkbasketController; -import pro.taskana.rest.resource.PagedResources.PageMetadata; -import pro.taskana.rest.resource.links.PageLinks; -import pro.taskana.workbasket.api.WorkbasketService; -import pro.taskana.workbasket.api.models.WorkbasketSummary; -import pro.taskana.workbasket.internal.models.WorkbasketImpl; - -/** EntityModel assembler for {@link WorkbasketSummaryResource}. */ -@Component -public class WorkbasketSummaryResourceAssembler - extends RepresentationModelAssemblerSupport { - - @Autowired private WorkbasketService workbasketService; - - public WorkbasketSummaryResourceAssembler() { - super(WorkbasketController.class, WorkbasketSummaryResource.class); - } - - @PageLinks(Mapping.URL_WORKBASKET) - public WorkbasketSummaryListResource toCollectionModel( - List entities, PageMetadata pageMetadata) { - return new WorkbasketSummaryListResource( - toCollectionModel(entities).getContent(), pageMetadata); - } - - @Override - public WorkbasketSummaryResource toModel(WorkbasketSummary workbasketSummary) { - return new WorkbasketSummaryResource(workbasketSummary); - } - - public WorkbasketSummary toModel(WorkbasketSummaryResource resource) { - WorkbasketImpl workbasket = - (WorkbasketImpl) workbasketService.newWorkbasket(resource.getKey(), resource.getDomain()); - workbasket.setId(resource.getWorkbasketId()); - BeanUtils.copyProperties(resource, workbasket); - return workbasket.asSummary(); - } -} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/links/PageLinksAspect.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/links/PageLinksAspect.java index 7300034a5..b5ffa405a 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/links/PageLinksAspect.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/links/PageLinksAspect.java @@ -13,13 +13,12 @@ import org.aspectj.lang.reflect.MethodSignature; import org.springframework.context.annotation.Configuration; import org.springframework.hateoas.IanaLinkRelations; import org.springframework.hateoas.Link; +import org.springframework.hateoas.PagedModel.PageMetadata; import org.springframework.hateoas.RepresentationModel; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.util.UriComponentsBuilder; -import pro.taskana.rest.resource.PagedResources.PageMetadata; - /** * Implementation of the PageLinks annotation to generate HATEOAS Links for paged list resources. */ @@ -39,8 +38,10 @@ public class PageLinksAspect { String relativeUrl = pageLinks.value(); UriComponentsBuilder original = originalUri(relativeUrl, request); RepresentationModel resourceSupport = (RepresentationModel) joinPoint.proceed(); - resourceSupport.add(new Link(original.toUriString()).withSelfRel()); if (page != null) { + resourceSupport.add( + new Link(original.replaceQueryParam("page", page.getNumber()).toUriString()) + .withSelfRel()); resourceSupport.add( new Link(original.replaceQueryParam("page", 1).toUriString()) .withRel(IanaLinkRelations.FIRST)); @@ -57,6 +58,8 @@ public class PageLinksAspect { new Link(original.replaceQueryParam("page", page.getNumber() + 1).toUriString()) .withRel(IanaLinkRelations.NEXT)); } + } else { + resourceSupport.add(new Link(original.toUriString()).withSelfRel()); } return resourceSupport; } diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/doc/api/AbstractPagingControllerRestDocumentation.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/doc/api/AbstractPagingControllerRestDocumentation.java index e90fa0101..113082611 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/doc/api/AbstractPagingControllerRestDocumentation.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/doc/api/AbstractPagingControllerRestDocumentation.java @@ -17,7 +17,7 @@ import pro.taskana.rest.Mapping; /** Generate Rest Docu for AbstractPagingController. */ class AbstractPagingControllerRestDocumentation extends BaseRestDocumentation { - private HashMap pagingFieldDescriptionsMap = new HashMap(); + private final HashMap pagingFieldDescriptionsMap = new HashMap<>(); private FieldDescriptor[] pagingFieldDescriptors; diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/doc/api/ClassificationControllerRestDocumentation.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/doc/api/ClassificationControllerRestDocumentation.java index d2068bdb4..70924279e 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/doc/api/ClassificationControllerRestDocumentation.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/doc/api/ClassificationControllerRestDocumentation.java @@ -22,11 +22,13 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers; import pro.taskana.rest.Mapping; -/** Generate REST Dokumentation for ClassificationController. */ +/** + * Generate REST Dokumentation for ClassificationController. + */ class ClassificationControllerRestDocumentation extends BaseRestDocumentation { - private HashMap classificationFieldDescriptionsMap = - new HashMap(); + private final HashMap classificationFieldDescriptionsMap = + new HashMap<>(); private FieldDescriptor[] allClassificationsFieldDescriptors; private FieldDescriptor[] classificationFieldDescriptors; @@ -87,11 +89,6 @@ class ClassificationControllerRestDocumentation extends BaseRestDocumentation { subsectionWithPath("classifications") .description("An Array of <>"), fieldWithPath("_links.self.href").ignored(), - fieldWithPath("page").ignored(), - fieldWithPath("page.size").ignored(), - fieldWithPath("page.totalElements").ignored(), - fieldWithPath("page.totalPages").ignored(), - fieldWithPath("page.number").ignored() }; classificationFieldDescriptors = @@ -256,7 +253,7 @@ class ClassificationControllerRestDocumentation extends BaseRestDocumentation { this.mockMvc .perform( RestDocumentationRequestBuilders.get( - restHelper.toUrl(Mapping.URL_CLASSIFICATIONS) + "?domain=DOMAIN_B") + restHelper.toUrl(Mapping.URL_CLASSIFICATIONS) + "?domain=DOMAIN_B") .accept("application/hal+json") .header("Authorization", "Basic dGVhbWxlYWRfMTp0ZWFtbGVhZF8x")) .andExpect(MockMvcResultMatchers.status().isOk()) @@ -337,14 +334,13 @@ class ClassificationControllerRestDocumentation extends BaseRestDocumentation { BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream(), UTF_8)); String inputLine; - StringBuffer content = new StringBuffer(); + StringBuilder content = new StringBuilder(); while ((inputLine = in.readLine()) != null) { content.append(inputLine); } in.close(); con.disconnect(); - String originalTask = content.toString(); - String modifiedTask = originalTask; + String modifiedTask = content.toString(); this.mockMvc .perform( diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/doc/api/TaskCommentControllerRestDocumentation.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/doc/api/TaskCommentControllerRestDocumentation.java index 4e8e577d6..f2ea09b9b 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/doc/api/TaskCommentControllerRestDocumentation.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/doc/api/TaskCommentControllerRestDocumentation.java @@ -22,10 +22,11 @@ import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.result.MockMvcResultMatchers; import pro.taskana.rest.Mapping; +import pro.taskana.rest.resource.TaskanaPagedModelKeys; public class TaskCommentControllerRestDocumentation extends BaseRestDocumentation { - private HashMap taskCommentFieldDescriptionsMap = new HashMap<>(); + private final HashMap taskCommentFieldDescriptionsMap = new HashMap<>(); private FieldDescriptor[] allTaskCommentsFieldDescriptors; private FieldDescriptor[] taskCommentFieldDescriptors; @@ -81,8 +82,10 @@ public class TaskCommentControllerRestDocumentation extends BaseRestDocumentatio }; allTaskCommentsFieldDescriptors = - new FieldDescriptor[] { - subsectionWithPath("task comments").description("An Array of task comments") + new FieldDescriptor[]{ + subsectionWithPath(TaskanaPagedModelKeys.TASK_COMMENTS.getPropertyName()).description( + "An Array of task comments"), + fieldWithPath("_links.self.href").ignored() }; } diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/doc/api/TaskControllerRestDocumentation.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/doc/api/TaskControllerRestDocumentation.java index 576cff190..a9ecfa5fe 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/doc/api/TaskControllerRestDocumentation.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/doc/api/TaskControllerRestDocumentation.java @@ -25,7 +25,7 @@ import pro.taskana.rest.Mapping; /** Generate REST Documentation for the TaskController. */ class TaskControllerRestDocumentation extends BaseRestDocumentation { - private HashMap taskFieldDescriptionsMap = new HashMap(); + private final HashMap taskFieldDescriptionsMap = new HashMap<>(); private FieldDescriptor[] allTasksFieldDescriptors; private FieldDescriptor[] taskFieldDescriptors; @@ -60,10 +60,11 @@ class TaskControllerRestDocumentation extends BaseRestDocumentation { taskFieldDescriptionsMap.put("priority", "The priority of the task"); taskFieldDescriptionsMap.put("state", "he state of the task. See (...)"); taskFieldDescriptionsMap.put( - "classificationSummaryResource", + "classificationSummary", "The <> of the task"); taskFieldDescriptionsMap.put( - "workbasketSummaryResource", "The <> of the task"); + "workbasketSummary", + "The <> of the task"); taskFieldDescriptionsMap.put("businessProcessId", ""); taskFieldDescriptionsMap.put("parentBusinessProcessId", ""); taskFieldDescriptionsMap.put( @@ -112,11 +113,6 @@ class TaskControllerRestDocumentation extends BaseRestDocumentation { fieldWithPath("_links").ignored(), fieldWithPath("_links.self").ignored(), fieldWithPath("_links.self.href").ignored(), - fieldWithPath("page").ignored(), - fieldWithPath("page.size").ignored(), - fieldWithPath("page.totalElements").ignored(), - fieldWithPath("page.totalPages").ignored(), - fieldWithPath("page.number").ignored() }; taskFieldDescriptors = @@ -137,28 +133,30 @@ class TaskControllerRestDocumentation extends BaseRestDocumentation { .description(taskFieldDescriptionsMap.get("planned")) .type("String"), fieldWithPath("due").description(taskFieldDescriptionsMap.get("due")).type("String"), - fieldWithPath("name").description(taskFieldDescriptionsMap.get("name")), - fieldWithPath("creator").description(taskFieldDescriptionsMap.get("creator")), - fieldWithPath("description").description(taskFieldDescriptionsMap.get("description")), - fieldWithPath("note") - .description(taskFieldDescriptionsMap.get("note")) - .description("Some custom Note"), - fieldWithPath("priority").description(taskFieldDescriptionsMap.get("priority")), - fieldWithPath("state").description(taskFieldDescriptionsMap.get("state")), - subsectionWithPath("classificationSummaryResource") - .description(taskFieldDescriptionsMap.get("classificationSummaryResource")), - subsectionWithPath("workbasketSummaryResource") - .description(taskFieldDescriptionsMap.get("workbasketSummaryResource")), - fieldWithPath("businessProcessId") - .description(taskFieldDescriptionsMap.get("businessProcessId")), - fieldWithPath("parentBusinessProcessId") - .description(taskFieldDescriptionsMap.get("parentBusinessProcessId")), - fieldWithPath("owner").description(taskFieldDescriptionsMap.get("owner")).type("String"), - fieldWithPath("primaryObjRef.id") - .description(taskFieldDescriptionsMap.get("primaryObjRef.id")) - .type("String"), - fieldWithPath("primaryObjRef.company") - .description(taskFieldDescriptionsMap.get("primaryObjRef.company")), + fieldWithPath("name").description(taskFieldDescriptionsMap.get("name")), + fieldWithPath("creator").description(taskFieldDescriptionsMap.get("creator")), + fieldWithPath("description").description(taskFieldDescriptionsMap.get("description")), + fieldWithPath("note") + .description(taskFieldDescriptionsMap.get("note")) + .description("Some custom Note"), + fieldWithPath("priority").description(taskFieldDescriptionsMap.get("priority")), + fieldWithPath("state").description(taskFieldDescriptionsMap.get("state")), + subsectionWithPath("classificationSummary") + .description( + taskFieldDescriptionsMap.get("classificationSummary")), + subsectionWithPath("workbasketSummary") + .description(taskFieldDescriptionsMap.get("workbasketSummary")), + fieldWithPath("businessProcessId") + .description(taskFieldDescriptionsMap.get("businessProcessId")), + fieldWithPath("parentBusinessProcessId") + .description(taskFieldDescriptionsMap.get("parentBusinessProcessId")), + fieldWithPath("owner").description(taskFieldDescriptionsMap.get("owner")).type( + "String"), + fieldWithPath("primaryObjRef.id") + .description(taskFieldDescriptionsMap.get("primaryObjRef.id")) + .type("String"), + fieldWithPath("primaryObjRef.company") + .description(taskFieldDescriptionsMap.get("primaryObjRef.company")), fieldWithPath("primaryObjRef.system") .description(taskFieldDescriptionsMap.get("primaryObjRef.system")), fieldWithPath("primaryObjRef.systemInstance") @@ -240,28 +238,29 @@ class TaskControllerRestDocumentation extends BaseRestDocumentation { .description(taskFieldDescriptionsMap.get("planned")) .type("String"), fieldWithPath("due").description(taskFieldDescriptionsMap.get("due")).type("String"), - fieldWithPath("name").description(taskFieldDescriptionsMap.get("name")), - fieldWithPath("creator").description(taskFieldDescriptionsMap.get("creator")), - fieldWithPath("description").ignored(), - fieldWithPath("note") - .description(taskFieldDescriptionsMap.get("note")) - .description("Some custom Note"), - fieldWithPath("priority").description(taskFieldDescriptionsMap.get("priority")), - fieldWithPath("state").description(taskFieldDescriptionsMap.get("state")), - subsectionWithPath("classificationSummaryResource") - .description(taskFieldDescriptionsMap.get("classificationSummaryResource")), - subsectionWithPath("workbasketSummaryResource") - .description(taskFieldDescriptionsMap.get("workbasketSummaryResource")), - fieldWithPath("businessProcessId") - .description(taskFieldDescriptionsMap.get("businessProcessId")), - fieldWithPath("parentBusinessProcessId") - .description(taskFieldDescriptionsMap.get("parentBusinessProcessId")), - fieldWithPath("owner").description(taskFieldDescriptionsMap.get("owner")), - fieldWithPath("primaryObjRef.id") - .description(taskFieldDescriptionsMap.get("primaryObjRef.id")) - .type("String"), - fieldWithPath("primaryObjRef.company") - .description(taskFieldDescriptionsMap.get("primaryObjRef.company")), + fieldWithPath("name").description(taskFieldDescriptionsMap.get("name")), + fieldWithPath("creator").description(taskFieldDescriptionsMap.get("creator")), + fieldWithPath("description").ignored(), + fieldWithPath("note") + .description(taskFieldDescriptionsMap.get("note")) + .description("Some custom Note"), + fieldWithPath("priority").description(taskFieldDescriptionsMap.get("priority")), + fieldWithPath("state").description(taskFieldDescriptionsMap.get("state")), + subsectionWithPath("classificationSummary") + .description( + taskFieldDescriptionsMap.get("classificationSummary")), + subsectionWithPath("workbasketSummary") + .description(taskFieldDescriptionsMap.get("workbasketSummary")), + fieldWithPath("businessProcessId") + .description(taskFieldDescriptionsMap.get("businessProcessId")), + fieldWithPath("parentBusinessProcessId") + .description(taskFieldDescriptionsMap.get("parentBusinessProcessId")), + fieldWithPath("owner").description(taskFieldDescriptionsMap.get("owner")), + fieldWithPath("primaryObjRef.id") + .description(taskFieldDescriptionsMap.get("primaryObjRef.id")) + .type("String"), + fieldWithPath("primaryObjRef.company") + .description(taskFieldDescriptionsMap.get("primaryObjRef.company")), fieldWithPath("primaryObjRef.system") .description(taskFieldDescriptionsMap.get("primaryObjRef.system")), fieldWithPath("primaryObjRef.systemInstance") @@ -295,21 +294,21 @@ class TaskControllerRestDocumentation extends BaseRestDocumentation { }; createTaskFieldDescriptors = - new FieldDescriptor[] { - subsectionWithPath("classificationSummaryResource") - .description("The new classificationSummaryResource for the task"), - subsectionWithPath("workbasketSummaryResource") - .description("The new workbasketSummaryResource for the task"), - fieldWithPath("externalId") - .description(taskFieldDescriptionsMap.get("externalId")) - .type("String") - .optional(), - fieldWithPath("primaryObjRef.company") - .description(taskFieldDescriptionsMap.get("primaryObjRef.company")), - fieldWithPath("primaryObjRef.system") - .description(taskFieldDescriptionsMap.get("primaryObjRef.system")), - fieldWithPath("primaryObjRef.systemInstance") - .description(taskFieldDescriptionsMap.get("primaryObjRef.systemInstance")), + new FieldDescriptor[]{ + subsectionWithPath("classificationSummary") + .description("The new classificationSummary for the task"), + subsectionWithPath("workbasketSummary") + .description("The new workbasketSummary for the task"), + fieldWithPath("externalId") + .description(taskFieldDescriptionsMap.get("externalId")) + .type("String") + .optional(), + fieldWithPath("primaryObjRef.company") + .description(taskFieldDescriptionsMap.get("primaryObjRef.company")), + fieldWithPath("primaryObjRef.system") + .description(taskFieldDescriptionsMap.get("primaryObjRef.system")), + fieldWithPath("primaryObjRef.systemInstance") + .description(taskFieldDescriptionsMap.get("primaryObjRef.systemInstance")), fieldWithPath("primaryObjRef.type") .description(taskFieldDescriptionsMap.get("primaryObjRef.type")), fieldWithPath("primaryObjRef.value") @@ -554,8 +553,8 @@ class TaskControllerRestDocumentation extends BaseRestDocumentation { RestDocumentationRequestBuilders.post(restHelper.toUrl(Mapping.URL_TASKS)) .contentType("application/hal+json") .content( - "{\"classificationSummaryResource\":{\"key\":\"L11010\"}," - + "\"workbasketSummaryResource\":" + "{\"classificationSummary\":{\"key\":\"L11010\"}," + + "\"workbasketSummary\":" + "{\"workbasketId\":\"WBI:100000000000000000000000000000000004\"}," + "\"primaryObjRef\":{\"company\":\"MyCompany1\"," + "\"system\":\"MySystem1\",\"systemInstance\":\"MyInstance1\"," @@ -589,8 +588,8 @@ class TaskControllerRestDocumentation extends BaseRestDocumentation { RestDocumentationRequestBuilders.post(restHelper.toUrl(Mapping.URL_TASKS)) .contentType("application/hal+json") .content( - "{\"classificationSummaryResource\":{\"key\":\"L11010\"}," - + "\"workbasketSummaryResource\":" + "{\"classificationSummary\":{\"key\":\"L11010\"}," + + "\"workbasketSummary\":" + "{\"workbasketId\":\"WBI:100000000000000000000000000000000004\"}," + "\"primaryObjRef\":{\"company\":\"MyCompany1\"," + "\"system\":\"MySystem1\",\"systemInstance\":\"MyInstance1\"," @@ -625,8 +624,8 @@ class TaskControllerRestDocumentation extends BaseRestDocumentation { RestDocumentationRequestBuilders.post(restHelper.toUrl(Mapping.URL_TASKS)) .contentType("application/hal+json") .content( - "{\"classificationSummaryResource\":{\"key\":\"L11010\"}," - + "\"workbasketSummaryResource\":" + "{\"classificationSummary\":{\"key\":\"L11010\"}," + + "\"workbasketSummary\":" + "{\"workbasketId\":\"WBI:100000000000000000000000000000000004\"}," + "\"primaryObjRef\":{\"company\":\"MyCompany1\"," + "\"system\":\"MySystem1\",\"systemInstance\":\"MyInstance1\"," @@ -660,8 +659,8 @@ class TaskControllerRestDocumentation extends BaseRestDocumentation { RestDocumentationRequestBuilders.post(restHelper.toUrl(Mapping.URL_TASKS)) .contentType("application/hal+json") .content( - "{\"classificationSummaryResource\":{\"key\":\"L11010\"}," - + "\"workbasketSummaryResource\":" + "{\"classificationSummary\":{\"key\":\"L11010\"}," + + "\"workbasketSummary\":" + "{\"workbasketId\":\"WBI:100000000000000000000000000000000004\"}," + "\"primaryObjRef\":{\"company\":\"MyCompany1\"," + "\"system\":\"MySystem1\",\"systemInstance\":\"MyInstance1\"," @@ -673,7 +672,6 @@ class TaskControllerRestDocumentation extends BaseRestDocumentation { String content = result.getResponse().getContentAsString(); String newId = content.substring(content.indexOf("TKI:"), content.indexOf("TKI:") + 40); - this.mockMvc .perform( RestDocumentationRequestBuilders.post( @@ -695,8 +693,8 @@ class TaskControllerRestDocumentation extends BaseRestDocumentation { RestDocumentationRequestBuilders.post(restHelper.toUrl(Mapping.URL_TASKS)) .contentType("application/hal+json") .content( - "{\"classificationSummaryResource\":{\"key\":\"L11010\"}," - + "\"workbasketSummaryResource\":" + "{\"classificationSummary\":{\"key\":\"L11010\"}," + + "\"workbasketSummary\":" + "{\"workbasketId\":\"WBI:100000000000000000000000000000000004\"}," + "\"primaryObjRef\":{\"company\":\"MyCompany1\"," + "\"system\":\"MySystem1\",\"systemInstance\":\"MyInstance1\"," diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/doc/api/WorkbasketAccessItemControllerRestDocumentation.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/doc/api/WorkbasketAccessItemControllerRestDocumentation.java index b74bfaae9..80361b81c 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/doc/api/WorkbasketAccessItemControllerRestDocumentation.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/doc/api/WorkbasketAccessItemControllerRestDocumentation.java @@ -105,10 +105,6 @@ class WorkbasketAccessItemControllerRestDocumentation extends BaseRestDocumentat .description(accessItemFieldDescriptionsMap.get("accessItems.permCustom12")), fieldWithPath("_links.self.href") .description(accessItemFieldDescriptionsMap.get("_links.self.href")), - fieldWithPath("page.size").ignored(), - fieldWithPath("page.totalElements").ignored(), - fieldWithPath("page.totalPages").ignored(), - fieldWithPath("page.number").ignored() }; } diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/doc/api/WorkbasketControllerRestDocumentation.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/doc/api/WorkbasketControllerRestDocumentation.java index 12e590964..7a5191134 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/doc/api/WorkbasketControllerRestDocumentation.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/doc/api/WorkbasketControllerRestDocumentation.java @@ -20,13 +20,15 @@ import org.springframework.restdocs.payload.FieldDescriptor; import org.springframework.test.web.servlet.result.MockMvcResultMatchers; import pro.taskana.rest.Mapping; +import pro.taskana.rest.resource.TaskanaPagedModelKeys; /** Generate REST Documentatioon for the WorkbasketController. */ class WorkbasketControllerRestDocumentation extends BaseRestDocumentation { + public static final String PROPERTY_NAME = TaskanaPagedModelKeys.ACCESSITEMS.getPropertyName(); // HashMaps to store the field descriptions centrally for multiple uses - private HashMap workbasketFieldDescriptionsMap = new HashMap(); - private HashMap accessItemFieldDescriptionsMap = new HashMap(); + private final HashMap workbasketFieldDescriptionsMap = new HashMap<>(); + private final HashMap accessItemFieldDescriptionsMap = new HashMap<>(); private FieldDescriptor[] allWorkbasketsFieldDescriptors; private FieldDescriptor[] workbasketFieldDescriptors; @@ -52,12 +54,13 @@ class WorkbasketControllerRestDocumentation extends BaseRestDocumentation { workbasketFieldDescriptionsMap.put( "orgLevel1", "The first Org Level (the top one)\nThe Org Level is an association with an org " - + "hierarchie level in the organization. The values are used for monitoring " + + "hierarchy level in the organization. The values are used for monitoring " + "and statistical purposes and should reflect the responsibility of the " + "tasks in the workbasket."); workbasketFieldDescriptionsMap.put("orgLevel2", "The second Org Level"); workbasketFieldDescriptionsMap.put("orgLevel3", "The third Org Level"); workbasketFieldDescriptionsMap.put("orgLevel4", "The fourth Org Level (the lowest one)."); + workbasketFieldDescriptionsMap.put("markedForDeletion", "can this be deleted"); workbasketFieldDescriptionsMap.put( "created", "The creation timestamp of the workbasket in the system."); workbasketFieldDescriptionsMap.put( @@ -72,55 +75,52 @@ class WorkbasketControllerRestDocumentation extends BaseRestDocumentation { "_links.removeDistributionTargets.href", "Link to remove all distribution-targets from the workbasket"); workbasketFieldDescriptionsMap.put( - "_links.accessItems.href", "The Access-Items of the workbasket"); + "_links." + PROPERTY_NAME + ".href", "The Access-Items of the workbasket"); workbasketFieldDescriptionsMap.put("_links.allWorkbaskets.href", "Link to all workbaskets"); - accessItemFieldDescriptionsMap.put("accessItems.accessItemId", "Unique ID"); - accessItemFieldDescriptionsMap.put("accessItems.workbasketId", "The workbasket"); - accessItemFieldDescriptionsMap.put("accessItems.workbasketKey", "The workbasket key"); + accessItemFieldDescriptionsMap.put(PROPERTY_NAME + ".accessItemId", "Unique ID"); + accessItemFieldDescriptionsMap.put(PROPERTY_NAME + ".workbasketId", "The workbasket"); + accessItemFieldDescriptionsMap.put(PROPERTY_NAME + ".workbasketKey", "The workbasket key"); accessItemFieldDescriptionsMap.put( - "accessItems.accessId", + PROPERTY_NAME + ".accessId", "The access id, this ACL entry refers to. This could be either a userid or a " + "full qualified group id (both lower case)"); - accessItemFieldDescriptionsMap.put("accessItems.accessName", ""); + accessItemFieldDescriptionsMap.put(PROPERTY_NAME + ".accessName", ""); accessItemFieldDescriptionsMap.put( - "accessItems.permRead", "The permission to read the information about the workbasket"); + PROPERTY_NAME + ".permRead", "The permission to read the information about the workbasket"); accessItemFieldDescriptionsMap.put( - "accessItems.permOpen", "The permission to view the content (the tasks) of a workbasket"); + PROPERTY_NAME + ".permOpen", + "The permission to view the content (the tasks) of a workbasket"); accessItemFieldDescriptionsMap.put( - "accessItems.permAppend", + PROPERTY_NAME + ".permAppend", "The permission to add tasks to the workbasket (required for creation " + "and transferring of tasks)"); accessItemFieldDescriptionsMap.put( - "accessItems.permTransfer", + PROPERTY_NAME + ".permTransfer", "The permission to transfer tasks (out of the current workbasket)"); accessItemFieldDescriptionsMap.put( - "accessItems.permDistribute", "The permission to distribute tasks from the workbasket"); - accessItemFieldDescriptionsMap.put("accessItems.permCustom1", ""); - accessItemFieldDescriptionsMap.put("accessItems.permCustom2", ""); - accessItemFieldDescriptionsMap.put("accessItems.permCustom3", ""); - accessItemFieldDescriptionsMap.put("accessItems.permCustom4", ""); - accessItemFieldDescriptionsMap.put("accessItems.permCustom5", ""); - accessItemFieldDescriptionsMap.put("accessItems.permCustom6", ""); - accessItemFieldDescriptionsMap.put("accessItems.permCustom7", ""); - accessItemFieldDescriptionsMap.put("accessItems.permCustom8", ""); - accessItemFieldDescriptionsMap.put("accessItems.permCustom9", ""); - accessItemFieldDescriptionsMap.put("accessItems.permCustom10", ""); - accessItemFieldDescriptionsMap.put("accessItems.permCustom11", ""); - accessItemFieldDescriptionsMap.put("accessItems.permCustom12", ""); + PROPERTY_NAME + ".permDistribute", + "The permission to distribute tasks from the workbasket"); + accessItemFieldDescriptionsMap.put(PROPERTY_NAME + ".permCustom1", ""); + accessItemFieldDescriptionsMap.put(PROPERTY_NAME + ".permCustom2", ""); + accessItemFieldDescriptionsMap.put(PROPERTY_NAME + ".permCustom3", ""); + accessItemFieldDescriptionsMap.put(PROPERTY_NAME + ".permCustom4", ""); + accessItemFieldDescriptionsMap.put(PROPERTY_NAME + ".permCustom5", ""); + accessItemFieldDescriptionsMap.put(PROPERTY_NAME + ".permCustom6", ""); + accessItemFieldDescriptionsMap.put(PROPERTY_NAME + ".permCustom7", ""); + accessItemFieldDescriptionsMap.put(PROPERTY_NAME + ".permCustom8", ""); + accessItemFieldDescriptionsMap.put(PROPERTY_NAME + ".permCustom9", ""); + accessItemFieldDescriptionsMap.put(PROPERTY_NAME + ".permCustom10", ""); + accessItemFieldDescriptionsMap.put(PROPERTY_NAME + ".permCustom11", ""); + accessItemFieldDescriptionsMap.put(PROPERTY_NAME + ".permCustom12", ""); accessItemFieldDescriptionsMap.put( - "accessItems._links.workbasket.href", "Link to the workbasket"); + PROPERTY_NAME + "._links.workbasket.href", "Link to the workbasket"); allWorkbasketsFieldDescriptors = new FieldDescriptor[] { subsectionWithPath("workbaskets") .description("An Array of <>"), fieldWithPath("_links.self.href").ignored(), - fieldWithPath("page").ignored(), - fieldWithPath("page.size").ignored(), - fieldWithPath("page.totalElements").ignored(), - fieldWithPath("page.totalPages").ignored(), - fieldWithPath("page.number").ignored() }; workbasketFieldDescriptors = @@ -144,13 +144,15 @@ class WorkbasketControllerRestDocumentation extends BaseRestDocumentation { fieldWithPath("orgLevel2").description(workbasketFieldDescriptionsMap.get("orgLevel2")), fieldWithPath("orgLevel3").description(workbasketFieldDescriptionsMap.get("orgLevel3")), fieldWithPath("orgLevel4").description(workbasketFieldDescriptionsMap.get("orgLevel4")), + fieldWithPath("markedForDeletion").description( + workbasketFieldDescriptionsMap.get("markedForDeletion")), fieldWithPath("_links.distributionTargets.href") .description(workbasketFieldDescriptionsMap.get("_links.distributionTargets.href")), fieldWithPath("_links.removeDistributionTargets.href") .description( workbasketFieldDescriptionsMap.get("_links.removeDistributionTargets.href")), - fieldWithPath("_links.accessItems.href") - .description(workbasketFieldDescriptionsMap.get("_links.accessItems.href")), + fieldWithPath("_links." + PROPERTY_NAME + ".href") + .description(workbasketFieldDescriptionsMap.get("_links." + PROPERTY_NAME + ".href")), fieldWithPath("_links.allWorkbaskets.href") .description(workbasketFieldDescriptionsMap.get("_links.allWorkbaskets.href")), fieldWithPath("_links.self.href").ignored() @@ -165,88 +167,81 @@ class WorkbasketControllerRestDocumentation extends BaseRestDocumentation { fieldWithPath("description") .description(workbasketFieldDescriptionsMap.get("description")), fieldWithPath("owner").description(workbasketFieldDescriptionsMap.get("owner")), - fieldWithPath("domain").description(workbasketFieldDescriptionsMap.get("domain")), - fieldWithPath("type").description(workbasketFieldDescriptionsMap.get("type")), - fieldWithPath("custom1").description(workbasketFieldDescriptionsMap.get("custom1")), - fieldWithPath("custom2").description(workbasketFieldDescriptionsMap.get("custom2")), - fieldWithPath("custom3").description(workbasketFieldDescriptionsMap.get("custom3")), - fieldWithPath("custom4").description(workbasketFieldDescriptionsMap.get("custom4")), - fieldWithPath("orgLevel1").description(workbasketFieldDescriptionsMap.get("orgLevel1")), - fieldWithPath("orgLevel2").description(workbasketFieldDescriptionsMap.get("orgLevel2")), - fieldWithPath("orgLevel3").description(workbasketFieldDescriptionsMap.get("orgLevel3")), - fieldWithPath("orgLevel4").description(workbasketFieldDescriptionsMap.get("orgLevel4")), - fieldWithPath("created").ignored(), - fieldWithPath("modified").ignored(), - fieldWithPath("_links.distributionTargets.href").ignored(), - fieldWithPath("_links.removeDistributionTargets.href").ignored(), - fieldWithPath("_links.accessItems.href").ignored(), - fieldWithPath("_links.allWorkbaskets.href").ignored(), - fieldWithPath("_links.self.href").ignored() + fieldWithPath("domain").description(workbasketFieldDescriptionsMap.get("domain")), + fieldWithPath("type").description(workbasketFieldDescriptionsMap.get("type")), + fieldWithPath("custom1").description(workbasketFieldDescriptionsMap.get("custom1")), + fieldWithPath("custom2").description(workbasketFieldDescriptionsMap.get("custom2")), + fieldWithPath("custom3").description(workbasketFieldDescriptionsMap.get("custom3")), + fieldWithPath("custom4").description(workbasketFieldDescriptionsMap.get("custom4")), + fieldWithPath("orgLevel1").description(workbasketFieldDescriptionsMap.get("orgLevel1")), + fieldWithPath("orgLevel2").description(workbasketFieldDescriptionsMap.get("orgLevel2")), + fieldWithPath("orgLevel3").description(workbasketFieldDescriptionsMap.get("orgLevel3")), + fieldWithPath("orgLevel4").description(workbasketFieldDescriptionsMap.get("orgLevel4")), + fieldWithPath("markedForDeletion").description( + workbasketFieldDescriptionsMap.get("markedForDeletion")), + fieldWithPath("created").ignored(), + fieldWithPath("modified").ignored(), + fieldWithPath("_links.distributionTargets.href").ignored(), + fieldWithPath("_links.removeDistributionTargets.href").ignored(), + fieldWithPath("_links." + PROPERTY_NAME + ".href").ignored(), + fieldWithPath("_links.allWorkbaskets.href").ignored(), + fieldWithPath("_links.self.href").ignored() }; accessItemFieldDescriptors = new FieldDescriptor[] { - fieldWithPath("accessItems[].accessItemId") - .description(accessItemFieldDescriptionsMap.get("accessItems.accessItemId")), - fieldWithPath("accessItems[].workbasketId") - .description(accessItemFieldDescriptionsMap.get("accessItems.workbasketId")), - fieldWithPath("accessItems[].workbasketKey") - .description(accessItemFieldDescriptionsMap.get("accessItems.workbasketKey")), - fieldWithPath("accessItems[].accessId") - .description(accessItemFieldDescriptionsMap.get("accessItems.accessId")), - fieldWithPath("accessItems[].accessName") - .description(accessItemFieldDescriptionsMap.get("accessItems.accessName")), - fieldWithPath("accessItems[].permRead") - .description(accessItemFieldDescriptionsMap.get("accessItems.permRead")), - fieldWithPath("accessItems[].permOpen") - .description(accessItemFieldDescriptionsMap.get("accessItems.permOpen")), - fieldWithPath("accessItems[].permAppend") - .description(accessItemFieldDescriptionsMap.get("accessItems.permAppend")), - fieldWithPath("accessItems[].permTransfer") - .description(accessItemFieldDescriptionsMap.get("accessItems.permTransfer")), - fieldWithPath("accessItems[].permDistribute") - .description(accessItemFieldDescriptionsMap.get("accessItems.permDistribute")), - fieldWithPath("accessItems[].permCustom1") - .description(accessItemFieldDescriptionsMap.get("accessItems.permCustom1")), - fieldWithPath("accessItems[].permCustom2") - .description(accessItemFieldDescriptionsMap.get("accessItems.permCustom2")), - fieldWithPath("accessItems[].permCustom3") - .description(accessItemFieldDescriptionsMap.get("accessItems.permCustom3")), - fieldWithPath("accessItems[].permCustom4") - .description(accessItemFieldDescriptionsMap.get("accessItems.permCustom4")), - fieldWithPath("accessItems[].permCustom5") - .description(accessItemFieldDescriptionsMap.get("accessItems.permCustom5")), - fieldWithPath("accessItems[].permCustom6") - .description(accessItemFieldDescriptionsMap.get("accessItems.permCustom6")), - fieldWithPath("accessItems[].permCustom7") - .description(accessItemFieldDescriptionsMap.get("accessItems.permCustom7")), - fieldWithPath("accessItems[].permCustom8") - .description(accessItemFieldDescriptionsMap.get("accessItems.permCustom8")), - fieldWithPath("accessItems[].permCustom9") - .description(accessItemFieldDescriptionsMap.get("accessItems.permCustom9")), - fieldWithPath("accessItems[].permCustom10") - .description(accessItemFieldDescriptionsMap.get("accessItems.permCustom10")), - fieldWithPath("accessItems[].permCustom11") - .description(accessItemFieldDescriptionsMap.get("accessItems.permCustom11")), - fieldWithPath("accessItems[].permCustom12") - .description(accessItemFieldDescriptionsMap.get("accessItems.permCustom12")), - fieldWithPath("page.size").ignored(), - fieldWithPath("page.totalElements").ignored(), - fieldWithPath("page.totalPages").ignored(), - fieldWithPath("page.number").ignored(), + fieldWithPath(PROPERTY_NAME + "[].accessItemId") + .description(accessItemFieldDescriptionsMap.get(PROPERTY_NAME + ".accessItemId")), + fieldWithPath(PROPERTY_NAME + "[].workbasketId") + .description(accessItemFieldDescriptionsMap.get(PROPERTY_NAME + ".workbasketId")), + fieldWithPath(PROPERTY_NAME + "[].workbasketKey") + .description(accessItemFieldDescriptionsMap.get(PROPERTY_NAME + ".workbasketKey")), + fieldWithPath(PROPERTY_NAME + "[].accessId") + .description(accessItemFieldDescriptionsMap.get(PROPERTY_NAME + ".accessId")), + fieldWithPath(PROPERTY_NAME + "[].accessName") + .description(accessItemFieldDescriptionsMap.get(PROPERTY_NAME + ".accessName")), + fieldWithPath(PROPERTY_NAME + "[].permRead") + .description(accessItemFieldDescriptionsMap.get(PROPERTY_NAME + ".permRead")), + fieldWithPath(PROPERTY_NAME + "[].permOpen") + .description(accessItemFieldDescriptionsMap.get(PROPERTY_NAME + ".permOpen")), + fieldWithPath(PROPERTY_NAME + "[].permAppend") + .description(accessItemFieldDescriptionsMap.get(PROPERTY_NAME + ".permAppend")), + fieldWithPath(PROPERTY_NAME + "[].permTransfer") + .description(accessItemFieldDescriptionsMap.get(PROPERTY_NAME + ".permTransfer")), + fieldWithPath(PROPERTY_NAME + "[].permDistribute") + .description(accessItemFieldDescriptionsMap.get(PROPERTY_NAME + ".permDistribute")), + fieldWithPath(PROPERTY_NAME + "[].permCustom1") + .description(accessItemFieldDescriptionsMap.get(PROPERTY_NAME + ".permCustom1")), + fieldWithPath(PROPERTY_NAME + "[].permCustom2") + .description(accessItemFieldDescriptionsMap.get(PROPERTY_NAME + ".permCustom2")), + fieldWithPath(PROPERTY_NAME + "[].permCustom3") + .description(accessItemFieldDescriptionsMap.get(PROPERTY_NAME + ".permCustom3")), + fieldWithPath(PROPERTY_NAME + "[].permCustom4") + .description(accessItemFieldDescriptionsMap.get(PROPERTY_NAME + ".permCustom4")), + fieldWithPath(PROPERTY_NAME + "[].permCustom5") + .description(accessItemFieldDescriptionsMap.get(PROPERTY_NAME + ".permCustom5")), + fieldWithPath(PROPERTY_NAME + "[].permCustom6") + .description(accessItemFieldDescriptionsMap.get(PROPERTY_NAME + ".permCustom6")), + fieldWithPath(PROPERTY_NAME + "[].permCustom7") + .description(accessItemFieldDescriptionsMap.get(PROPERTY_NAME + ".permCustom7")), + fieldWithPath(PROPERTY_NAME + "[].permCustom8") + .description(accessItemFieldDescriptionsMap.get(PROPERTY_NAME + ".permCustom8")), + fieldWithPath(PROPERTY_NAME + "[].permCustom9") + .description(accessItemFieldDescriptionsMap.get(PROPERTY_NAME + ".permCustom9")), + fieldWithPath(PROPERTY_NAME + "[].permCustom10") + .description(accessItemFieldDescriptionsMap.get(PROPERTY_NAME + ".permCustom10")), + fieldWithPath(PROPERTY_NAME + "[].permCustom11") + .description(accessItemFieldDescriptionsMap.get(PROPERTY_NAME + ".permCustom11")), + fieldWithPath(PROPERTY_NAME + "[].permCustom12") + .description(accessItemFieldDescriptionsMap.get(PROPERTY_NAME + ".permCustom12")), fieldWithPath("_links.self.href").ignored(), fieldWithPath("_links.workbasket.href").ignored() }; allWorkbasketAccessItemsFieldDescriptors = new FieldDescriptor[] { - subsectionWithPath("accessItems") + subsectionWithPath(PROPERTY_NAME) .description("An array of <>"), - fieldWithPath("page").ignored(), - fieldWithPath("page.size").ignored(), - fieldWithPath("page.totalElements").ignored(), - fieldWithPath("page.totalPages").ignored(), - fieldWithPath("page.number").ignored(), fieldWithPath("_links.self.href").ignored(), fieldWithPath("_links.workbasket.href").ignored() }; @@ -256,7 +251,6 @@ class WorkbasketControllerRestDocumentation extends BaseRestDocumentation { subsectionWithPath("distributionTargets") .description("An array of <>"), fieldWithPath("_links.self.href").ignored(), - fieldWithPath("_links.workbasket.href").ignored() }; createWorkbasketFieldDescriptors = @@ -322,8 +316,8 @@ class WorkbasketControllerRestDocumentation extends BaseRestDocumentation { workbasketFieldDescriptionsMap.get("_links.removeDistributionTargets.href")) .type("String") .optional(), - fieldWithPath("_links.accessItems.href") - .description(workbasketFieldDescriptionsMap.get("_links.accessItems.href")) + fieldWithPath("_links." + PROPERTY_NAME + ".href") + .description(workbasketFieldDescriptionsMap.get("_links." + PROPERTY_NAME + ".href")) .type("String") .optional(), fieldWithPath("_links.allWorkbaskets.href") diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/ldap/LdapCacheTestImpl.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/ldap/LdapCacheTestImpl.java index c0d2b9a13..3090711db 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/ldap/LdapCacheTestImpl.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/ldap/LdapCacheTestImpl.java @@ -7,7 +7,7 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; -import pro.taskana.rest.resource.AccessIdResource; +import pro.taskana.rest.resource.AccessIdRepresentationModel; /** * Implementation of LdapCache used for Unit tests. @@ -16,284 +16,292 @@ import pro.taskana.rest.resource.AccessIdResource; */ public class LdapCacheTestImpl implements LdapCache { - /** - * Dictionary is a {@link Map} collection that contains {@link AccessIdResource} as key (user) and - * {@link List} as value (groups of which the user is a member) . - */ - private Map> users; - - private List accessIds = + private final List accessIds = new ArrayList<>( Arrays.asList( - new AccessIdResource("Martin, Rojas Miguel Angel", "user_1_1"), - new AccessIdResource("Zorgati, Mustapha", "user_2_1"), - new AccessIdResource("Behrendt, Maximilian", "max"), - new AccessIdResource("Bert, Ali", "teamlead_5"), - new AccessIdResource("Hagen, Holger", "teamlead_3"), - new AccessIdResource("Breier, Bernd", "user_2_2"), - new AccessIdResource("Fielmalz, Anke", "user017"), - new AccessIdResource("Mente, Maximilian", "max_mente"), - new AccessIdResource("Theke, Bernd", "user_2_3"), - new AccessIdResource("Ferrante, Elena", "elena"), - new AccessIdResource("Mueller, Simone", "simone"), - new AccessIdResource("Sirup, Aaron", "user001"), - new AccessIdResource("Nacho, recuerda", "user_1_2"), - new AccessIdResource("Lass, Ada", "user003"), - new AccessIdResource("Tion, Addi", "user004"), - new AccessIdResource("Lette, Adi", "user005"), - new AccessIdResource("Admin", "teamlead_2"), - new AccessIdResource("Native, Alter", "user006"), - new AccessIdResource("Herum, Albert", "user007"), - new AccessIdResource("Meyer, Dominik", "teamlead_1"), - new AccessIdResource("Mente, Ali", "user009"), - new AccessIdResource("Nach, Alma", "user011"), - new AccessIdResource("Gehzauch, Anders", "user012"), - new AccessIdResource("Theke, Andi", "user013"), - new AccessIdResource("Kreuz, Andreas", "user014"), - new AccessIdResource("Tiefsee, Anka", "user016"), - new AccessIdResource("Fassen, Ann", "user018"), - new AccessIdResource("Probe, Ann", "user019"), - new AccessIdResource("Bolika, Anna", "user020"), - new AccessIdResource("Ecke, Anna", "user021"), - new AccessIdResource("Hosi, Anna", "user022"), - new AccessIdResource("Kronis-Tisch, Anna", "user023"), - new AccessIdResource("Logie, Anna", "user024"), - new AccessIdResource("Luehse, Anna", "user025"), - new AccessIdResource("Nass, Anna", "user026"), - new AccessIdResource("Thalb, Anna", "user027"), - new AccessIdResource("Tomie, Anna", "user028"), - new AccessIdResource("Donnich, Anne", "user029"), - new AccessIdResource("Kaffek, Anne", "user030"), - new AccessIdResource("Thek, Anne", "user031"), - new AccessIdResource("Matoer, Anni", "user032"), - new AccessIdResource("Ragentor, Ansgar", "user033"), - new AccessIdResource("Stoteles, Ari", "user034"), - new AccessIdResource("Thmetik, Ari", "user035"), - new AccessIdResource("Nuehm, Arno", "user036"), - new AccessIdResource("Schocke, Artie", "user037"), - new AccessIdResource("Stoppel, Bart", "user038"), - new AccessIdResource("Beitung, Bea", "user039"), - new AccessIdResource("Ildich, Bea", "user040"), - new AccessIdResource("Vista, Bella", "user041"), - new AccessIdResource("Utzer, Ben", "user042"), - new AccessIdResource("Zien, Ben", "user043"), - new AccessIdResource("Stein, Bernd", "user044"), - new AccessIdResource("Deramen, Bill", "user045"), - new AccessIdResource("Honig, Bine", "user046"), - new AccessIdResource("Densatz, Bo", "user047"), - new AccessIdResource("Densee, Bo", "user048"), - new AccessIdResource("Lerwagen, Bo", "user049"), - new AccessIdResource("Tail, Bob", "user050"), - new AccessIdResource("Ketta, Bruce", "user051"), - new AccessIdResource("Terrie, Bud", "user052"), - new AccessIdResource("Biener-Haken, Cara", "user053"), - new AccessIdResource("Ass, Caro", "user054"), - new AccessIdResource("Kaffee, Caro", "user055"), - new AccessIdResource("Linger, Caro", "user056"), - new AccessIdResource("tenSaft, Caro", "user057"), - new AccessIdResource("Antheme, Chris", "user058"), - new AccessIdResource("Baum, Chris", "user059"), - new AccessIdResource("Tall, Chris", "user060"), - new AccessIdResource("Reiniger, Claas", "user061"), - new AccessIdResource("Grube, Claire", "user062"), - new AccessIdResource("Fall, Clara", "user063"), - new AccessIdResource("Korn, Clara", "user064"), - new AccessIdResource("Lenriff, Cora", "user065"), - new AccessIdResource("Schiert, Cora", "user066"), - new AccessIdResource("Hose, Cord", "user067"), - new AccessIdResource("Onbleu, Cord", "user068"), - new AccessIdResource("Umkleide, Damon", "user069"), - new AccessIdResource("Affier, Dean", "user070"), - new AccessIdResource("Orm, Dean", "user071"), - new AccessIdResource("Platz, Dennis", "user072"), - new AccessIdResource("Milch, Dick", "user073"), - new AccessIdResource("Mow, Dina", "user074"), - new AccessIdResource("Keil, Donna", "user075"), - new AccessIdResource("Littchen, Donna", "user076"), - new AccessIdResource("Wetter, Donna", "user077"), - new AccessIdResource("Was, Ed", "user078"), - new AccessIdResource("Khar, Ede", "user079"), - new AccessIdResource("Nut, Ella", "user080"), - new AccessIdResource("Stisch, Ella", "user081"), - new AccessIdResource("Diel, Emma", "user082"), - new AccessIdResource("Herdamit, Emma", "user083"), - new AccessIdResource("Mitter-Uhe, Emma", "user084"), - new AccessIdResource("Tatt, Erich", "user085"), - new AccessIdResource("Drigend, Ernie", "user086"), - new AccessIdResource("Poly, Esther", "user087"), - new AccessIdResource("Trautz, Eugen", "user088"), - new AccessIdResource("Quiert, Eva", "user089"), - new AccessIdResource("Inurlaub, Fatma", "user090"), - new AccessIdResource("Land, Finn", "user091"), - new AccessIdResource("Sternis, Finn", "user092"), - new AccessIdResource("Furt, Frank", "user093"), - new AccessIdResource("Reich, Frank", "user094"), - new AccessIdResource("Iskaner, Franz", "user095"), - new AccessIdResource("Nerr, Franziska", "user096"), - new AccessIdResource("Zafen, Friedrich", "user097"), - new AccessIdResource("Pomm, Fritz", "user098"), - new AccessIdResource("deWegs, Gera", "user099"), - new AccessIdResource("Staebe, Gitta", "user100"), - new AccessIdResource("Zend, Glenn", "user101"), - new AccessIdResource("Fisch, Grete", "user102"), - new AccessIdResource("Zucker, Gus", "user103"), - new AccessIdResource("Muhn, Hanni", "user104"), - new AccessIdResource("Fermesse, Hanno", "user105"), - new AccessIdResource("Aplast, Hans", "user106"), - new AccessIdResource("Eart, Hans", "user107"), - new AccessIdResource("Back, Hardy", "user108"), - new AccessIdResource("Beau, Harry", "user109"), - new AccessIdResource("Kraut, Heide", "user110"), - new AccessIdResource("Witzka, Heide", "user111"), - new AccessIdResource("Buchen, Hein", "user112"), - new AccessIdResource("Lichkeit, Hein", "user113"), - new AccessIdResource("Suchung, Hein", "user114"), - new AccessIdResource("Ellmann, Heinz", "user115"), - new AccessIdResource("Ketchup, Heinz", "user116"), - new AccessIdResource("Zeim, Hilde", "user117"), - new AccessIdResource("Bilien, Immo", "user118"), - new AccessIdResource("Her, Inge", "user119"), - new AccessIdResource("Wahrsam, Inge", "user120"), - new AccessIdResource("Flamm, Ingo", "user121"), - new AccessIdResource("Enzien, Ingrid", "user122"), - new AccessIdResource("Rohsch, Inken", "user123"), - new AccessIdResource("Ihr, Insa", "user124"), - new AccessIdResource("Nerda, Iska", "user125"), - new AccessIdResource("Eitz, Jens", "user126"), - new AccessIdResource("Nastik, Jim", "user127"), - new AccessIdResource("Gurt, Jo", "user128"), - new AccessIdResource("Kurrth, Jo", "user129"), - new AccessIdResource("Kolade, Joe", "user130"), - new AccessIdResource("Iter, Johann", "user131"), - new AccessIdResource("Tick, Joyce", "user132"), - new AccessIdResource("Case, Justin", "user133"), - new AccessIdResource("Time, Justin", "user134"), - new AccessIdResource("Komp, Jutta", "user135"), - new AccessIdResource("Mauer, Kai", "user136"), - new AccessIdResource("Pirinja, Kai", "user137"), - new AccessIdResource("Serpfalz, Kai", "user138"), - new AccessIdResource("Auer, Karl", "user139"), - new AccessIdResource("Ielauge, Karl", "user140"), - new AccessIdResource("Ifornjen, Karl", "user141"), - new AccessIdResource("Radi, Karl", "user142"), - new AccessIdResource("Verti, Karl", "user143"), - new AccessIdResource("Sery, Karo", "user144"), - new AccessIdResource("Lisator, Katha", "user145"), - new AccessIdResource("Flo, Kati", "user146"), - new AccessIdResource("Schenn, Knut", "user147"), - new AccessIdResource("Achse, Kurt", "user148"), - new AccessIdResource("Zepause, Kurt", "user149"), - new AccessIdResource("Zerr, Kurt", "user150"), - new AccessIdResource("Reden, Lasse", "user151"), - new AccessIdResource("Metten, Lee", "user152"), - new AccessIdResource("Arm, Lene", "user153"), - new AccessIdResource("Thur, Linnea", "user154"), - new AccessIdResource("Bonn, Lisa", "user155"), - new AccessIdResource("Sembourg, Luc", "user156"), - new AccessIdResource("Rung, Lucky", "user157"), - new AccessIdResource("Zafen, Ludwig", "user158"), - new AccessIdResource("Hauden, Lukas", "user159"), - new AccessIdResource("Hose, Lutz", "user160"), - new AccessIdResource("Tablette, Lutz", "user161"), - new AccessIdResource("Fehr, Luzie", "user162"), - new AccessIdResource("Nalyse, Magda", "user163"), - new AccessIdResource("Ehfer, Maik", "user164"), - new AccessIdResource("Sehr, Malte", "user165"), - new AccessIdResource("Thon, Mara", "user166"), - new AccessIdResource("Quark, Marga", "user167"), - new AccessIdResource("Nade, Marie", "user168"), - new AccessIdResource("Niert, Marie", "user169"), - new AccessIdResource("Neese, Mario", "user170"), - new AccessIdResource("Nette, Marion", "user171"), - new AccessIdResource("Nesium, Mark", "user172"), - new AccessIdResource("Thalle, Mark", "user173"), - new AccessIdResource("Diven, Marle", "user174"), - new AccessIdResource("Fitz, Marle", "user175"), - new AccessIdResource("Pfahl, Marta", "user176"), - new AccessIdResource("Zorn, Martin", "user177"), - new AccessIdResource("Krissmes, Mary", "user178"), - new AccessIdResource("Jess, Matt", "user179"), - new AccessIdResource("Strammer, Max", "user180"), - new AccessIdResource("Mumm, Maxi", "user181"), - new AccessIdResource("Morphose, Meta", "user182"), - new AccessIdResource("Uh, Mia", "user183"), - new AccessIdResource("Rofon, Mike", "user184"), - new AccessIdResource("Rosoft, Mike", "user185"), - new AccessIdResource("Liter, Milli", "user186"), - new AccessIdResource("Thär, Milli", "user187"), - new AccessIdResource("Welle, Mirko", "user188"), - new AccessIdResource("Thorat, Mo", "user189"), - new AccessIdResource("Thor, Moni", "user190"), - new AccessIdResource("Kinolta, Monika", "user191"), - new AccessIdResource("Mundhaar, Monika", "user192"), - new AccessIdResource("Munter, Monika", "user193"), - new AccessIdResource("Zwerg, Nat", "user194"), - new AccessIdResource("Elmine, Nick", "user195"), - new AccessIdResource("Thien, Niko", "user196"), - new AccessIdResource("Pferd, Nils", "user197"), - new AccessIdResource("Lerweise, Norma", "user198"), - new AccessIdResource("Motor, Otto", "user199"), - new AccessIdResource("Totol, Otto", "user200"), - new AccessIdResource("Nerr, Paula", "user201"), - new AccessIdResource("Imeter, Peer", "user202"), - new AccessIdResource("Serkatze, Peer", "user203"), - new AccessIdResource("Gogisch, Peter", "user204"), - new AccessIdResource("Silje, Peter", "user205"), - new AccessIdResource("Harmonie, Phil", "user206"), - new AccessIdResource("Ihnen, Philip", "user207"), - new AccessIdResource("Uto, Pia", "user208"), - new AccessIdResource("Kothek, Pina", "user209"), - new AccessIdResource("Zar, Pit", "user210"), - new AccessIdResource("Zeih, Polly", "user211"), - new AccessIdResource("Tswan, Puh", "user212"), - new AccessIdResource("Zufall, Rainer", "user213"), - new AccessIdResource("Lien, Rita", "user214"), - new AccessIdResource("Held, Roman", "user215"), - new AccessIdResource("Haar, Ross", "user216"), - new AccessIdResource("Dick, Roy", "user217"), - new AccessIdResource("Enplaner, Ruth", "user218"), - new AccessIdResource("Kommen, Ryan", "user219"), - new AccessIdResource("Philo, Sophie", "user220"), - new AccessIdResource("Matisier, Stig", "user221"), - new AccessIdResource("Loniki, Tessa", "user222"), - new AccessIdResource("Tralisch, Thea", "user223"), - new AccessIdResource("Logie, Theo", "user224"), - new AccessIdResource("Ister, Thorn", "user225"), - new AccessIdResource("Buktu, Tim", "user226"), - new AccessIdResource("Ate, Tom", "user227"), - new AccessIdResource("Pie, Udo", "user228"), - new AccessIdResource("Aloe, Vera", "user229"), - new AccessIdResource("Hausver, Walter", "user230"), - new AccessIdResource("Schuh, Wanda", "user231"), - new AccessIdResource("Rahm, Wolf", "user232"), - new AccessIdResource("businessadmin", "cn=businessadmin,ou=groups,o=taskanatest"), - new AccessIdResource("UsersGroup", "cn=usersgroup,ou=groups,o=taskanatest"), - new AccessIdResource("DevelopersGroup", "cn=developersgroup,ou=groups,o=taskanatest"), - new AccessIdResource("businessadmin", "cn=customersgroup,ou=groups,o=taskanatest"), - new AccessIdResource("user_domain_A", "cn=user_domain_a,ou=groups,o=taskanatest"), - new AccessIdResource("monitor", "cn=monitor,ou=groups,o=taskanatest"), - new AccessIdResource("user_domain_C", "cn=user_domain_c,ou=groups,o=taskanatest"), - new AccessIdResource("user_domain_D", "cn=user_domain_d,ou=groups,o=taskanatest"), - new AccessIdResource("admin", "cn=admin,ou=groups,o=taskanatest"), - new AccessIdResource( + new AccessIdRepresentationModel("Martin, Rojas Miguel Angel", "user_1_1"), + new AccessIdRepresentationModel("Zorgati, Mustapha", "user_2_1"), + new AccessIdRepresentationModel("Behrendt, Maximilian", "max"), + new AccessIdRepresentationModel("Bert, Ali", "teamlead_5"), + new AccessIdRepresentationModel("Hagen, Holger", "teamlead_3"), + new AccessIdRepresentationModel("Breier, Bernd", "user_2_2"), + new AccessIdRepresentationModel("Fielmalz, Anke", "user017"), + new AccessIdRepresentationModel("Mente, Maximilian", "max_mente"), + new AccessIdRepresentationModel("Theke, Bernd", "user_2_3"), + new AccessIdRepresentationModel("Ferrante, Elena", "elena"), + new AccessIdRepresentationModel("Mueller, Simone", "simone"), + new AccessIdRepresentationModel("Sirup, Aaron", "user001"), + new AccessIdRepresentationModel("Nacho, recuerda", "user_1_2"), + new AccessIdRepresentationModel("Lass, Ada", "user003"), + new AccessIdRepresentationModel("Tion, Addi", "user004"), + new AccessIdRepresentationModel("Lette, Adi", "user005"), + new AccessIdRepresentationModel("Admin", "teamlead_2"), + new AccessIdRepresentationModel("Native, Alter", "user006"), + new AccessIdRepresentationModel("Herum, Albert", "user007"), + new AccessIdRepresentationModel("Meyer, Dominik", "teamlead_1"), + new AccessIdRepresentationModel("Mente, Ali", "user009"), + new AccessIdRepresentationModel("Nach, Alma", "user011"), + new AccessIdRepresentationModel("Gehzauch, Anders", "user012"), + new AccessIdRepresentationModel("Theke, Andi", "user013"), + new AccessIdRepresentationModel("Kreuz, Andreas", "user014"), + new AccessIdRepresentationModel("Tiefsee, Anka", "user016"), + new AccessIdRepresentationModel("Fassen, Ann", "user018"), + new AccessIdRepresentationModel("Probe, Ann", "user019"), + new AccessIdRepresentationModel("Bolika, Anna", "user020"), + new AccessIdRepresentationModel("Ecke, Anna", "user021"), + new AccessIdRepresentationModel("Hosi, Anna", "user022"), + new AccessIdRepresentationModel("Kronis-Tisch, Anna", "user023"), + new AccessIdRepresentationModel("Logie, Anna", "user024"), + new AccessIdRepresentationModel("Luehse, Anna", "user025"), + new AccessIdRepresentationModel("Nass, Anna", "user026"), + new AccessIdRepresentationModel("Thalb, Anna", "user027"), + new AccessIdRepresentationModel("Tomie, Anna", "user028"), + new AccessIdRepresentationModel("Donnich, Anne", "user029"), + new AccessIdRepresentationModel("Kaffek, Anne", "user030"), + new AccessIdRepresentationModel("Thek, Anne", "user031"), + new AccessIdRepresentationModel("Matoer, Anni", "user032"), + new AccessIdRepresentationModel("Ragentor, Ansgar", "user033"), + new AccessIdRepresentationModel("Stoteles, Ari", "user034"), + new AccessIdRepresentationModel("Thmetik, Ari", "user035"), + new AccessIdRepresentationModel("Nuehm, Arno", "user036"), + new AccessIdRepresentationModel("Schocke, Artie", "user037"), + new AccessIdRepresentationModel("Stoppel, Bart", "user038"), + new AccessIdRepresentationModel("Beitung, Bea", "user039"), + new AccessIdRepresentationModel("Ildich, Bea", "user040"), + new AccessIdRepresentationModel("Vista, Bella", "user041"), + new AccessIdRepresentationModel("Utzer, Ben", "user042"), + new AccessIdRepresentationModel("Zien, Ben", "user043"), + new AccessIdRepresentationModel("Stein, Bernd", "user044"), + new AccessIdRepresentationModel("Deramen, Bill", "user045"), + new AccessIdRepresentationModel("Honig, Bine", "user046"), + new AccessIdRepresentationModel("Densatz, Bo", "user047"), + new AccessIdRepresentationModel("Densee, Bo", "user048"), + new AccessIdRepresentationModel("Lerwagen, Bo", "user049"), + new AccessIdRepresentationModel("Tail, Bob", "user050"), + new AccessIdRepresentationModel("Ketta, Bruce", "user051"), + new AccessIdRepresentationModel("Terrie, Bud", "user052"), + new AccessIdRepresentationModel("Biener-Haken, Cara", "user053"), + new AccessIdRepresentationModel("Ass, Caro", "user054"), + new AccessIdRepresentationModel("Kaffee, Caro", "user055"), + new AccessIdRepresentationModel("Linger, Caro", "user056"), + new AccessIdRepresentationModel("tenSaft, Caro", "user057"), + new AccessIdRepresentationModel("Antheme, Chris", "user058"), + new AccessIdRepresentationModel("Baum, Chris", "user059"), + new AccessIdRepresentationModel("Tall, Chris", "user060"), + new AccessIdRepresentationModel("Reiniger, Claas", "user061"), + new AccessIdRepresentationModel("Grube, Claire", "user062"), + new AccessIdRepresentationModel("Fall, Clara", "user063"), + new AccessIdRepresentationModel("Korn, Clara", "user064"), + new AccessIdRepresentationModel("Lenriff, Cora", "user065"), + new AccessIdRepresentationModel("Schiert, Cora", "user066"), + new AccessIdRepresentationModel("Hose, Cord", "user067"), + new AccessIdRepresentationModel("Onbleu, Cord", "user068"), + new AccessIdRepresentationModel("Umkleide, Damon", "user069"), + new AccessIdRepresentationModel("Affier, Dean", "user070"), + new AccessIdRepresentationModel("Orm, Dean", "user071"), + new AccessIdRepresentationModel("Platz, Dennis", "user072"), + new AccessIdRepresentationModel("Milch, Dick", "user073"), + new AccessIdRepresentationModel("Mow, Dina", "user074"), + new AccessIdRepresentationModel("Keil, Donna", "user075"), + new AccessIdRepresentationModel("Littchen, Donna", "user076"), + new AccessIdRepresentationModel("Wetter, Donna", "user077"), + new AccessIdRepresentationModel("Was, Ed", "user078"), + new AccessIdRepresentationModel("Khar, Ede", "user079"), + new AccessIdRepresentationModel("Nut, Ella", "user080"), + new AccessIdRepresentationModel("Stisch, Ella", "user081"), + new AccessIdRepresentationModel("Diel, Emma", "user082"), + new AccessIdRepresentationModel("Herdamit, Emma", "user083"), + new AccessIdRepresentationModel("Mitter-Uhe, Emma", "user084"), + new AccessIdRepresentationModel("Tatt, Erich", "user085"), + new AccessIdRepresentationModel("Drigend, Ernie", "user086"), + new AccessIdRepresentationModel("Poly, Esther", "user087"), + new AccessIdRepresentationModel("Trautz, Eugen", "user088"), + new AccessIdRepresentationModel("Quiert, Eva", "user089"), + new AccessIdRepresentationModel("Inurlaub, Fatma", "user090"), + new AccessIdRepresentationModel("Land, Finn", "user091"), + new AccessIdRepresentationModel("Sternis, Finn", "user092"), + new AccessIdRepresentationModel("Furt, Frank", "user093"), + new AccessIdRepresentationModel("Reich, Frank", "user094"), + new AccessIdRepresentationModel("Iskaner, Franz", "user095"), + new AccessIdRepresentationModel("Nerr, Franziska", "user096"), + new AccessIdRepresentationModel("Zafen, Friedrich", "user097"), + new AccessIdRepresentationModel("Pomm, Fritz", "user098"), + new AccessIdRepresentationModel("deWegs, Gera", "user099"), + new AccessIdRepresentationModel("Staebe, Gitta", "user100"), + new AccessIdRepresentationModel("Zend, Glenn", "user101"), + new AccessIdRepresentationModel("Fisch, Grete", "user102"), + new AccessIdRepresentationModel("Zucker, Gus", "user103"), + new AccessIdRepresentationModel("Muhn, Hanni", "user104"), + new AccessIdRepresentationModel("Fermesse, Hanno", "user105"), + new AccessIdRepresentationModel("Aplast, Hans", "user106"), + new AccessIdRepresentationModel("Eart, Hans", "user107"), + new AccessIdRepresentationModel("Back, Hardy", "user108"), + new AccessIdRepresentationModel("Beau, Harry", "user109"), + new AccessIdRepresentationModel("Kraut, Heide", "user110"), + new AccessIdRepresentationModel("Witzka, Heide", "user111"), + new AccessIdRepresentationModel("Buchen, Hein", "user112"), + new AccessIdRepresentationModel("Lichkeit, Hein", "user113"), + new AccessIdRepresentationModel("Suchung, Hein", "user114"), + new AccessIdRepresentationModel("Ellmann, Heinz", "user115"), + new AccessIdRepresentationModel("Ketchup, Heinz", "user116"), + new AccessIdRepresentationModel("Zeim, Hilde", "user117"), + new AccessIdRepresentationModel("Bilien, Immo", "user118"), + new AccessIdRepresentationModel("Her, Inge", "user119"), + new AccessIdRepresentationModel("Wahrsam, Inge", "user120"), + new AccessIdRepresentationModel("Flamm, Ingo", "user121"), + new AccessIdRepresentationModel("Enzien, Ingrid", "user122"), + new AccessIdRepresentationModel("Rohsch, Inken", "user123"), + new AccessIdRepresentationModel("Ihr, Insa", "user124"), + new AccessIdRepresentationModel("Nerda, Iska", "user125"), + new AccessIdRepresentationModel("Eitz, Jens", "user126"), + new AccessIdRepresentationModel("Nastik, Jim", "user127"), + new AccessIdRepresentationModel("Gurt, Jo", "user128"), + new AccessIdRepresentationModel("Kurrth, Jo", "user129"), + new AccessIdRepresentationModel("Kolade, Joe", "user130"), + new AccessIdRepresentationModel("Iter, Johann", "user131"), + new AccessIdRepresentationModel("Tick, Joyce", "user132"), + new AccessIdRepresentationModel("Case, Justin", "user133"), + new AccessIdRepresentationModel("Time, Justin", "user134"), + new AccessIdRepresentationModel("Komp, Jutta", "user135"), + new AccessIdRepresentationModel("Mauer, Kai", "user136"), + new AccessIdRepresentationModel("Pirinja, Kai", "user137"), + new AccessIdRepresentationModel("Serpfalz, Kai", "user138"), + new AccessIdRepresentationModel("Auer, Karl", "user139"), + new AccessIdRepresentationModel("Ielauge, Karl", "user140"), + new AccessIdRepresentationModel("Ifornjen, Karl", "user141"), + new AccessIdRepresentationModel("Radi, Karl", "user142"), + new AccessIdRepresentationModel("Verti, Karl", "user143"), + new AccessIdRepresentationModel("Sery, Karo", "user144"), + new AccessIdRepresentationModel("Lisator, Katha", "user145"), + new AccessIdRepresentationModel("Flo, Kati", "user146"), + new AccessIdRepresentationModel("Schenn, Knut", "user147"), + new AccessIdRepresentationModel("Achse, Kurt", "user148"), + new AccessIdRepresentationModel("Zepause, Kurt", "user149"), + new AccessIdRepresentationModel("Zerr, Kurt", "user150"), + new AccessIdRepresentationModel("Reden, Lasse", "user151"), + new AccessIdRepresentationModel("Metten, Lee", "user152"), + new AccessIdRepresentationModel("Arm, Lene", "user153"), + new AccessIdRepresentationModel("Thur, Linnea", "user154"), + new AccessIdRepresentationModel("Bonn, Lisa", "user155"), + new AccessIdRepresentationModel("Sembourg, Luc", "user156"), + new AccessIdRepresentationModel("Rung, Lucky", "user157"), + new AccessIdRepresentationModel("Zafen, Ludwig", "user158"), + new AccessIdRepresentationModel("Hauden, Lukas", "user159"), + new AccessIdRepresentationModel("Hose, Lutz", "user160"), + new AccessIdRepresentationModel("Tablette, Lutz", "user161"), + new AccessIdRepresentationModel("Fehr, Luzie", "user162"), + new AccessIdRepresentationModel("Nalyse, Magda", "user163"), + new AccessIdRepresentationModel("Ehfer, Maik", "user164"), + new AccessIdRepresentationModel("Sehr, Malte", "user165"), + new AccessIdRepresentationModel("Thon, Mara", "user166"), + new AccessIdRepresentationModel("Quark, Marga", "user167"), + new AccessIdRepresentationModel("Nade, Marie", "user168"), + new AccessIdRepresentationModel("Niert, Marie", "user169"), + new AccessIdRepresentationModel("Neese, Mario", "user170"), + new AccessIdRepresentationModel("Nette, Marion", "user171"), + new AccessIdRepresentationModel("Nesium, Mark", "user172"), + new AccessIdRepresentationModel("Thalle, Mark", "user173"), + new AccessIdRepresentationModel("Diven, Marle", "user174"), + new AccessIdRepresentationModel("Fitz, Marle", "user175"), + new AccessIdRepresentationModel("Pfahl, Marta", "user176"), + new AccessIdRepresentationModel("Zorn, Martin", "user177"), + new AccessIdRepresentationModel("Krissmes, Mary", "user178"), + new AccessIdRepresentationModel("Jess, Matt", "user179"), + new AccessIdRepresentationModel("Strammer, Max", "user180"), + new AccessIdRepresentationModel("Mumm, Maxi", "user181"), + new AccessIdRepresentationModel("Morphose, Meta", "user182"), + new AccessIdRepresentationModel("Uh, Mia", "user183"), + new AccessIdRepresentationModel("Rofon, Mike", "user184"), + new AccessIdRepresentationModel("Rosoft, Mike", "user185"), + new AccessIdRepresentationModel("Liter, Milli", "user186"), + new AccessIdRepresentationModel("Thär, Milli", "user187"), + new AccessIdRepresentationModel("Welle, Mirko", "user188"), + new AccessIdRepresentationModel("Thorat, Mo", "user189"), + new AccessIdRepresentationModel("Thor, Moni", "user190"), + new AccessIdRepresentationModel("Kinolta, Monika", "user191"), + new AccessIdRepresentationModel("Mundhaar, Monika", "user192"), + new AccessIdRepresentationModel("Munter, Monika", "user193"), + new AccessIdRepresentationModel("Zwerg, Nat", "user194"), + new AccessIdRepresentationModel("Elmine, Nick", "user195"), + new AccessIdRepresentationModel("Thien, Niko", "user196"), + new AccessIdRepresentationModel("Pferd, Nils", "user197"), + new AccessIdRepresentationModel("Lerweise, Norma", "user198"), + new AccessIdRepresentationModel("Motor, Otto", "user199"), + new AccessIdRepresentationModel("Totol, Otto", "user200"), + new AccessIdRepresentationModel("Nerr, Paula", "user201"), + new AccessIdRepresentationModel("Imeter, Peer", "user202"), + new AccessIdRepresentationModel("Serkatze, Peer", "user203"), + new AccessIdRepresentationModel("Gogisch, Peter", "user204"), + new AccessIdRepresentationModel("Silje, Peter", "user205"), + new AccessIdRepresentationModel("Harmonie, Phil", "user206"), + new AccessIdRepresentationModel("Ihnen, Philip", "user207"), + new AccessIdRepresentationModel("Uto, Pia", "user208"), + new AccessIdRepresentationModel("Kothek, Pina", "user209"), + new AccessIdRepresentationModel("Zar, Pit", "user210"), + new AccessIdRepresentationModel("Zeih, Polly", "user211"), + new AccessIdRepresentationModel("Tswan, Puh", "user212"), + new AccessIdRepresentationModel("Zufall, Rainer", "user213"), + new AccessIdRepresentationModel("Lien, Rita", "user214"), + new AccessIdRepresentationModel("Held, Roman", "user215"), + new AccessIdRepresentationModel("Haar, Ross", "user216"), + new AccessIdRepresentationModel("Dick, Roy", "user217"), + new AccessIdRepresentationModel("Enplaner, Ruth", "user218"), + new AccessIdRepresentationModel("Kommen, Ryan", "user219"), + new AccessIdRepresentationModel("Philo, Sophie", "user220"), + new AccessIdRepresentationModel("Matisier, Stig", "user221"), + new AccessIdRepresentationModel("Loniki, Tessa", "user222"), + new AccessIdRepresentationModel("Tralisch, Thea", "user223"), + new AccessIdRepresentationModel("Logie, Theo", "user224"), + new AccessIdRepresentationModel("Ister, Thorn", "user225"), + new AccessIdRepresentationModel("Buktu, Tim", "user226"), + new AccessIdRepresentationModel("Ate, Tom", "user227"), + new AccessIdRepresentationModel("Pie, Udo", "user228"), + new AccessIdRepresentationModel("Aloe, Vera", "user229"), + new AccessIdRepresentationModel("Hausver, Walter", "user230"), + new AccessIdRepresentationModel("Schuh, Wanda", "user231"), + new AccessIdRepresentationModel("Rahm, Wolf", "user232"), + new AccessIdRepresentationModel( + "businessadmin", "cn=businessadmin,ou=groups,o=taskanatest"), + new AccessIdRepresentationModel( + "UsersGroup", "cn=usersgroup,ou=groups,o=taskanatest"), + new AccessIdRepresentationModel( + "DevelopersGroup", "cn=developersgroup,ou=groups,o=taskanatest"), + new AccessIdRepresentationModel( + "businessadmin", "cn=customersgroup,ou=groups,o=taskanatest"), + new AccessIdRepresentationModel( + "user_domain_A", "cn=user_domain_a,ou=groups,o=taskanatest"), + new AccessIdRepresentationModel("monitor", "cn=monitor,ou=groups,o=taskanatest"), + new AccessIdRepresentationModel( + "user_domain_C", "cn=user_domain_c,ou=groups,o=taskanatest"), + new AccessIdRepresentationModel( + "user_domain_D", "cn=user_domain_d,ou=groups,o=taskanatest"), + new AccessIdRepresentationModel("admin", "cn=admin,ou=groups,o=taskanatest"), + new AccessIdRepresentationModel( "manager_domain_B", "cn=manager_domain_b,ou=groups,o=taskanatest"), - new AccessIdResource( + new AccessIdRepresentationModel( "manager_domain_C", "cn=manager_domain_c,ou=groups,o=taskanatest"), - new AccessIdResource( + new AccessIdRepresentationModel( "manager_domain_D", "cn=manager_domain_d,ou=groups,o=taskanatest"), - new AccessIdResource("teamlead_2", "cn=teamlead_2" + ",ou=groups,o=taskanatest"), - new AccessIdResource("teamlead_4", "cn=teamlead_4" + ",ou=groups,o=taskanatest"), - new AccessIdResource("team_3", "cn=team_3" + ",ou=groups,o=taskanatest"), - new AccessIdResource("team_4", "cn=team_4" + ",ou=groups,o=taskanatest"))); + new AccessIdRepresentationModel( + "teamlead_2", "cn=teamlead_2" + ",ou=groups,o=taskanatest"), + new AccessIdRepresentationModel( + "teamlead_4", "cn=teamlead_4" + ",ou=groups,o=taskanatest"), + new AccessIdRepresentationModel("team_3", "cn=team_3" + ",ou=groups,o=taskanatest"), + new AccessIdRepresentationModel("team_4", "cn=team_4" + ",ou=groups,o=taskanatest"))); + /** + * Dictionary is a {@link Map} collection that contains {@link AccessIdRepresentationModel} as key + * (user) and {@link List} as value (groups of which the user is a member) . + */ + private Map> users; @Override - public List findMatchingAccessId( + public List findMatchingAccessId( String searchFor, int maxNumberOfReturnedAccessIds) { return findAcessIdResource(searchFor, maxNumberOfReturnedAccessIds, false); } @Override - public List findGroupsOfUser( + public List findGroupsOfUser( String searchFor, int maxNumberOfReturnedAccessIds) { if (users == null) { addUsersToGroups(); @@ -302,15 +310,15 @@ public class LdapCacheTestImpl implements LdapCache { } @Override - public List validateAccessId(String accessId) { + public List validateAccessId(String accessId) { return accessIds.stream() .filter(t -> (t.getAccessId().equalsIgnoreCase(accessId.toLowerCase()))) .collect(Collectors.toList()); } - private List findAcessIdResource( + private List findAcessIdResource( String searchFor, int maxNumberOfReturnedAccessIds, boolean groupMember) { - List usersAndGroups = + List usersAndGroups = accessIds.stream() .filter( t -> @@ -318,7 +326,7 @@ public class LdapCacheTestImpl implements LdapCache { || t.getAccessId().toLowerCase().contains(searchFor.toLowerCase()))) .collect(Collectors.toList()); - List usersAndGroupsAux = new ArrayList<>(usersAndGroups); + List usersAndGroupsAux = new ArrayList<>(usersAndGroups); if (groupMember) { usersAndGroupsAux.forEach( item -> { @@ -329,18 +337,15 @@ public class LdapCacheTestImpl implements LdapCache { } usersAndGroups.sort( - (AccessIdResource a, AccessIdResource b) -> { - return a.getAccessId().compareToIgnoreCase(b.getAccessId()); - }); + (AccessIdRepresentationModel a, AccessIdRepresentationModel b) -> a.getAccessId() + .compareToIgnoreCase( + b.getAccessId())); - List result = - usersAndGroups.subList(0, Math.min(usersAndGroups.size(), maxNumberOfReturnedAccessIds)); - - return result; + return usersAndGroups.subList(0, Math.min(usersAndGroups.size(), maxNumberOfReturnedAccessIds)); } private void addUsersToGroups() { - List groups = new ArrayList<>(); + List groups = new ArrayList<>(); users = new HashMap<>(); accessIds.forEach( @@ -353,12 +358,12 @@ public class LdapCacheTestImpl implements LdapCache { }); int groupNumber = 0; - List group0 = new ArrayList<>(); - List group1 = new ArrayList<>(); - List group2 = new ArrayList<>(); - List group3 = new ArrayList<>(); + List group0 = new ArrayList<>(); + List group1 = new ArrayList<>(); + List group2 = new ArrayList<>(); + List group3 = new ArrayList<>(); - for (AccessIdResource group : groups) { + for (AccessIdRepresentationModel group : groups) { switch (groupNumber) { case 0: group0.add(group); @@ -379,7 +384,7 @@ public class LdapCacheTestImpl implements LdapCache { } int countUser = 0; - for (AccessIdResource item : accessIds) { + for (AccessIdRepresentationModel item : accessIds) { if (!item.getAccessId().contains("ou=groups")) { switch (countUser) { case 0: diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/ldap/LdapClientTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/ldap/LdapClientTest.java index 4d357efa5..d71f988a9 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/ldap/LdapClientTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/ldap/LdapClientTest.java @@ -26,7 +26,7 @@ import org.springframework.ldap.core.LdapTemplate; import pro.taskana.common.api.exceptions.InvalidArgumentException; import pro.taskana.common.api.exceptions.SystemException; -import pro.taskana.rest.resource.AccessIdResource; +import pro.taskana.rest.resource.AccessIdRepresentationModel; @ExtendWith(MockitoExtension.class) class LdapClientTest { @@ -56,8 +56,8 @@ class LdapClientTest { setUpEnvMock(); cut.init(); - AccessIdResource group = new AccessIdResource("testG", "testGId"); - AccessIdResource user = new AccessIdResource("testU", "testUId"); + AccessIdRepresentationModel group = new AccessIdRepresentationModel("testG", "testGId"); + AccessIdRepresentationModel user = new AccessIdRepresentationModel("testU", "testUId"); when(ldapTemplate.search( any(String.class), any(), anyInt(), any(), any(LdapClient.GroupContextMapper.class))) @@ -89,9 +89,9 @@ class LdapClientTest { setUpEnvMock(); cut.init(); - List result = + List result = IntStream.range(0, 100) - .mapToObj(i -> new AccessIdResource("" + i, "" + i)) + .mapToObj(i -> new AccessIdRepresentationModel("" + i, "" + i)) .collect(Collectors.toList()); assertThat(cut.getFirstPageOfaResultList(result)) diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/AccessIdControllerIntTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/AccessIdControllerIntTest.java index ac40df8a3..f6fa6a941 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/AccessIdControllerIntTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/AccessIdControllerIntTest.java @@ -19,7 +19,7 @@ import org.springframework.web.client.RestTemplate; import pro.taskana.RestHelper; import pro.taskana.TaskanaSpringBootTest; -import pro.taskana.rest.resource.AccessIdResource; +import pro.taskana.rest.resource.AccessIdRepresentationModel; @TaskanaSpringBootTest @ActiveProfiles({"test", "ldap"}) @@ -63,18 +63,18 @@ class AccessIdControllerIntTest { @Test void testGetMatches() { - ResponseEntity> response = + ResponseEntity> response = template.exchange( restHelper.toUrl(Mapping.URL_ACCESSID) + "?search-for=rig", HttpMethod.GET, restHelper.defaultRequest(), ParameterizedTypeReference.forType(AccessIdListResource.class)); - List body = response.getBody(); + List body = response.getBody(); assertThat(body).isNotNull(); assertThat(body).hasSize(2); assertThat(body) - .extracting(AccessIdResource::getName) + .extracting(AccessIdRepresentationModel::getName) .containsExactlyInAnyOrder("Schläfrig, Tim", "Eifrig, Elena"); } @@ -95,7 +95,7 @@ class AccessIdControllerIntTest { .isEqualTo(HttpStatus.BAD_REQUEST); } - static class AccessIdListResource extends ArrayList { + static class AccessIdListResource extends ArrayList { private static final long serialVersionUID = 1L; } } diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/ClassificationControllerIntTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/ClassificationControllerIntTest.java index e96bea83b..f499b876d 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/ClassificationControllerIntTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/ClassificationControllerIntTest.java @@ -19,9 +19,9 @@ import org.springframework.web.client.RestTemplate; import pro.taskana.RestHelper; import pro.taskana.TaskanaSpringBootTest; -import pro.taskana.rest.resource.ClassificationResource; -import pro.taskana.rest.resource.ClassificationSummaryListResource; -import pro.taskana.rest.resource.ClassificationSummaryResource; +import pro.taskana.rest.resource.ClassificationRepresentationModel; +import pro.taskana.rest.resource.ClassificationSummaryRepresentationModel; +import pro.taskana.rest.resource.TaskanaPagedModel; /** * Test ClassificationController. @@ -31,18 +31,23 @@ import pro.taskana.rest.resource.ClassificationSummaryResource; @TaskanaSpringBootTest class ClassificationControllerIntTest { + private static final ParameterizedTypeReference< + TaskanaPagedModel> + CLASSIFICATION_SUMMARY_PAGE_MODEL_TYPE = + new ParameterizedTypeReference< + TaskanaPagedModel>() {}; static RestTemplate template = RestHelper.TEMPLATE; @Autowired RestHelper restHelper; @Test void testGetClassification() { - ResponseEntity response = + ResponseEntity response = template.exchange( restHelper.toUrl( Mapping.URL_CLASSIFICATIONS_ID, "CLI:100000000000000000000000000000000002"), HttpMethod.GET, restHelper.defaultRequest(), - ParameterizedTypeReference.forType(ClassificationResource.class)); + ParameterizedTypeReference.forType(ClassificationRepresentationModel.class)); assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); assertThat(response.getHeaders().getContentType().toString()) .isEqualTo(MediaTypes.HAL_JSON_VALUE); @@ -50,36 +55,36 @@ class ClassificationControllerIntTest { @Test void testGetAllClassifications() { - ResponseEntity response = + ResponseEntity> response = template.exchange( restHelper.toUrl(Mapping.URL_CLASSIFICATIONS), HttpMethod.GET, restHelper.defaultRequest(), - ParameterizedTypeReference.forType(ClassificationSummaryListResource.class)); + CLASSIFICATION_SUMMARY_PAGE_MODEL_TYPE); assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); } @Test void testGetAllClassificationsFilterByCustomAttribute() { - ResponseEntity response = + ResponseEntity> response = template.exchange( restHelper.toUrl(Mapping.URL_CLASSIFICATIONS) + "?domain=DOMAIN_A&custom-1-like=RVNR", HttpMethod.GET, restHelper.defaultRequest(), - ParameterizedTypeReference.forType(ClassificationSummaryListResource.class)); + CLASSIFICATION_SUMMARY_PAGE_MODEL_TYPE); assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); assertThat(response.getBody().getContent()).hasSize(13); } @Test void testGetAllClassificationsKeepingFilters() { - ResponseEntity response = + ResponseEntity> response = template.exchange( restHelper.toUrl(Mapping.URL_CLASSIFICATIONS) + "?domain=DOMAIN_A&sort-by=key&order=asc", HttpMethod.GET, restHelper.defaultRequest(), - ParameterizedTypeReference.forType(ClassificationSummaryListResource.class)); + CLASSIFICATION_SUMMARY_PAGE_MODEL_TYPE); assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); assertThat( response @@ -94,13 +99,13 @@ class ClassificationControllerIntTest { @Test void testGetSecondPageSortedByKey() { - ResponseEntity response = + ResponseEntity> response = template.exchange( restHelper.toUrl(Mapping.URL_CLASSIFICATIONS) + "?domain=DOMAIN_A&sort-by=key&order=asc&page=2&page-size=5", HttpMethod.GET, restHelper.defaultRequest(), - ParameterizedTypeReference.forType(ClassificationSummaryListResource.class)); + CLASSIFICATION_SUMMARY_PAGE_MODEL_TYPE); assertThat(response.getBody().getContent()).hasSize(5); assertThat(response.getBody().getContent().iterator().next().getKey()).isEqualTo("L1050"); assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); @@ -111,7 +116,7 @@ class ClassificationControllerIntTest { .getHref() .endsWith( "/api/v1/classifications?" - + "domain=DOMAIN_A&sort-by=key&order=asc&page=2&page-size=5")) + + "domain=DOMAIN_A&sort-by=key&order=asc&page-size=5&page=2")) .isTrue(); assertThat(response.getBody().getLink(IanaLinkRelations.FIRST)).isNotNull(); assertThat(response.getBody().getLink(IanaLinkRelations.LAST)).isNotNull(); @@ -127,12 +132,12 @@ class ClassificationControllerIntTest { + "\"domain\":\"DOMAIN_A\",\"key\":\"NEW_CLASS\"," + "\"name\":\"new classification\",\"type\":\"TASK\"}"; - ResponseEntity responseEntity = + ResponseEntity responseEntity = template.exchange( restHelper.toUrl(Mapping.URL_CLASSIFICATIONS), HttpMethod.POST, new HttpEntity<>(newClassification, restHelper.getHeaders()), - ParameterizedTypeReference.forType(ClassificationResource.class)); + ParameterizedTypeReference.forType(ClassificationRepresentationModel.class)); assertThat(responseEntity).isNotNull(); assertThat(HttpStatus.CREATED).isEqualTo(responseEntity.getStatusCode()); @@ -147,7 +152,7 @@ class ClassificationControllerIntTest { restHelper.toUrl(Mapping.URL_CLASSIFICATIONS), HttpMethod.POST, new HttpEntity<>(newClassification, restHelper.getHeaders()), - ParameterizedTypeReference.forType(ClassificationResource.class)); + ParameterizedTypeReference.forType(ClassificationRepresentationModel.class)); assertThat(HttpStatus.CREATED).isEqualTo(responseEntity.getStatusCode()); } @@ -161,12 +166,12 @@ class ClassificationControllerIntTest { + "\"name\":\"new classification\",\"type\":\"TASK\"," + "\"parentId\":\"CLI:200000000000000000000000000000000015\"}"; - ResponseEntity responseEntity = + ResponseEntity responseEntity = template.exchange( restHelper.toUrl(Mapping.URL_CLASSIFICATIONS), HttpMethod.POST, new HttpEntity<>(newClassification, restHelper.getHeaders()), - ParameterizedTypeReference.forType(ClassificationResource.class)); + ParameterizedTypeReference.forType(ClassificationRepresentationModel.class)); assertThat(responseEntity).isNotNull(); assertThat(HttpStatus.CREATED).isEqualTo(responseEntity.getStatusCode()); @@ -181,12 +186,12 @@ class ClassificationControllerIntTest { + "\"key\":\"NEW_CLASS_P2\",\"name\":\"new classification\"," + "\"type\":\"TASK\",\"parentKey\":\"T2100\"}"; - ResponseEntity responseEntity = + ResponseEntity responseEntity = template.exchange( restHelper.toUrl(Mapping.URL_CLASSIFICATIONS), HttpMethod.POST, new HttpEntity<>(newClassification, restHelper.getHeaders()), - ParameterizedTypeReference.forType(ClassificationResource.class)); + ParameterizedTypeReference.forType(ClassificationRepresentationModel.class)); assertThat(responseEntity).isNotNull(); assertThat(HttpStatus.CREATED).isEqualTo(responseEntity.getStatusCode()); @@ -200,25 +205,26 @@ class ClassificationControllerIntTest { + "\"key\":\"NEW_CLASS_P2\",\"name\":\"new classification\"," + "\"type\":\"TASK\",\"parentKey\":\"T2100\"}"; - ResponseEntity responseEntity = + ResponseEntity responseEntity = template.exchange( restHelper.toUrl(Mapping.URL_CLASSIFICATIONS), HttpMethod.POST, new HttpEntity<>(newClassification, restHelper.getHeaders()), - ParameterizedTypeReference.forType(ClassificationResource.class)); + ParameterizedTypeReference.forType(ClassificationRepresentationModel.class)); assertThat(responseEntity).isNotNull(); assertThat(HttpStatus.CREATED).isEqualTo(responseEntity.getStatusCode()); - ResponseEntity response = + ResponseEntity> response = template.exchange( restHelper.toUrl(Mapping.URL_CLASSIFICATIONS), HttpMethod.GET, restHelper.defaultRequest(), - ParameterizedTypeReference.forType(ClassificationSummaryListResource.class)); + CLASSIFICATION_SUMMARY_PAGE_MODEL_TYPE); assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); boolean foundClassificationCreated = false; - for (ClassificationSummaryResource classification : response.getBody().getContent()) { + for (ClassificationSummaryRepresentationModel classification : + response.getBody().getContent()) { if ("NEW_CLASS_P2".equals(classification.getKey()) && "".equals(classification.getDomain()) && "T2100".equals(classification.getParentKey())) { @@ -245,7 +251,7 @@ class ClassificationControllerIntTest { restHelper.toUrl(Mapping.URL_CLASSIFICATIONS), HttpMethod.POST, new HttpEntity<>(newClassification, restHelper.getHeaders()), - ParameterizedTypeReference.forType(ClassificationResource.class)); + ParameterizedTypeReference.forType(ClassificationRepresentationModel.class)); }; assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) @@ -267,7 +273,7 @@ class ClassificationControllerIntTest { restHelper.toUrl(Mapping.URL_CLASSIFICATIONS), HttpMethod.POST, new HttpEntity<>(newClassification, restHelper.getHeaders()), - ParameterizedTypeReference.forType(ClassificationResource.class)); + ParameterizedTypeReference.forType(ClassificationRepresentationModel.class)); }; assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) @@ -279,13 +285,13 @@ class ClassificationControllerIntTest { void testGetClassificationWithSpecialCharacter() { HttpEntity request = new HttpEntity<>(restHelper.getHeadersAdmin()); - ResponseEntity response = + ResponseEntity response = template.exchange( restHelper.toUrl( Mapping.URL_CLASSIFICATIONS_ID, "CLI:100000000000000000000000000000000009"), HttpMethod.GET, request, - ParameterizedTypeReference.forType(ClassificationSummaryResource.class)); + ParameterizedTypeReference.forType(ClassificationSummaryRepresentationModel.class)); assertThat(response.getBody().getName()).isEqualTo("Zustimmungserklärung"); } @@ -294,13 +300,13 @@ class ClassificationControllerIntTest { void testDeleteClassification() { HttpEntity request = new HttpEntity<>(restHelper.getHeaders()); - ResponseEntity response = + ResponseEntity response = template.exchange( restHelper.toUrl( Mapping.URL_CLASSIFICATIONS_ID, "CLI:200000000000000000000000000000000004"), HttpMethod.DELETE, request, - ParameterizedTypeReference.forType(ClassificationSummaryResource.class)); + ParameterizedTypeReference.forType(ClassificationSummaryRepresentationModel.class)); assertThat(HttpStatus.NO_CONTENT).isEqualTo(response.getStatusCode()); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT); @@ -311,7 +317,7 @@ class ClassificationControllerIntTest { Mapping.URL_CLASSIFICATIONS_ID, "CLI:200000000000000000000000000000000004"), HttpMethod.GET, request, - ParameterizedTypeReference.forType(ClassificationSummaryResource.class)); + ParameterizedTypeReference.forType(ClassificationSummaryRepresentationModel.class)); }; assertThatThrownBy(httpCall).isInstanceOf(HttpClientErrorException.class); } diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/ClassificationDefinitionControllerIntTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/ClassificationDefinitionControllerIntTest.java index 31a6c7ce4..568c3f30c 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/ClassificationDefinitionControllerIntTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/ClassificationDefinitionControllerIntTest.java @@ -31,14 +31,19 @@ import org.springframework.web.client.RestTemplate; import pro.taskana.RestHelper; import pro.taskana.TaskanaSpringBootTest; -import pro.taskana.rest.resource.ClassificationResource; -import pro.taskana.rest.resource.ClassificationSummaryListResource; -import pro.taskana.rest.resource.ClassificationSummaryResource; +import pro.taskana.rest.resource.ClassificationRepresentationModel; +import pro.taskana.rest.resource.ClassificationSummaryRepresentationModel; +import pro.taskana.rest.resource.TaskanaPagedModel; /** Test classification definitions. */ @TaskanaSpringBootTest class ClassificationDefinitionControllerIntTest { + private static final ParameterizedTypeReference< + TaskanaPagedModel> + CLASSIFICATION_SUMMARY_PAGE_MODEL_TYPE = + new ParameterizedTypeReference< + TaskanaPagedModel>() {}; private static final Logger LOGGER = LoggerFactory.getLogger(ClassificationController.class); private static RestTemplate template; @Autowired RestHelper restHelper; @@ -51,32 +56,32 @@ class ClassificationDefinitionControllerIntTest { @Test void testExportClassifications() { - ResponseEntity response = + ResponseEntity response = template.exchange( restHelper.toUrl(Mapping.URL_CLASSIFICATIONDEFINITION) + "?domain=DOMAIN_B", HttpMethod.GET, restHelper.defaultRequest(), - ParameterizedTypeReference.forType(ClassificationResource[].class)); + ParameterizedTypeReference.forType(ClassificationRepresentationModel[].class)); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(response.getBody().length >= 5).isTrue(); assertThat(response.getBody().length <= 7).isTrue(); - assertThat(response.getBody()[0]).isInstanceOf(ClassificationResource.class); + assertThat(response.getBody()[0]).isInstanceOf(ClassificationRepresentationModel.class); } @Test void testExportClassificationsFromWrongDomain() { - ResponseEntity response = + ResponseEntity response = template.exchange( restHelper.toUrl(Mapping.URL_CLASSIFICATIONDEFINITION) + "?domain=ADdfe", HttpMethod.GET, restHelper.defaultRequest(), - ParameterizedTypeReference.forType(ClassificationResource[].class)); + ParameterizedTypeReference.forType(ClassificationRepresentationModel[].class)); assertThat(response.getBody()).isEmpty(); } @Test void testImportFilledClassification() throws IOException { - ClassificationResource classification = new ClassificationResource(); + ClassificationRepresentationModel classification = new ClassificationRepresentationModel(); classification.setClassificationId("classificationId_"); classification.setKey("key drelf"); classification.setParentId("CLI:100000000000000000000000000000000016"); @@ -110,7 +115,7 @@ class ClassificationDefinitionControllerIntTest { @Test void testFailureWhenKeyIsMissing() throws IOException { - ClassificationResource classification = new ClassificationResource(); + ClassificationRepresentationModel classification = new ClassificationRepresentationModel(); classification.setDomain("DOMAIN_A"); List clList = new ArrayList<>(); clList.add(objMapper.writeValueAsString(classification)); @@ -124,7 +129,7 @@ class ClassificationDefinitionControllerIntTest { @Test void testFailureWhenDomainIsMissing() throws IOException { - ClassificationResource classification = new ClassificationResource(); + ClassificationRepresentationModel classification = new ClassificationRepresentationModel(); classification.setKey("one"); List clList = new ArrayList<>(); clList.add(objMapper.writeValueAsString(classification)); @@ -138,7 +143,7 @@ class ClassificationDefinitionControllerIntTest { @Test void testFailureWhenUpdatingTypeOfExistingClassification() throws IOException { - ClassificationSummaryResource classification = + ClassificationSummaryRepresentationModel classification = this.getClassificationWithKeyAndDomain("T6310", ""); classification.setType("DOCUMENT"); List clList = new ArrayList<>(); @@ -153,11 +158,11 @@ class ClassificationDefinitionControllerIntTest { @Test void testImportMultipleClassifications() throws IOException { - ClassificationResource classification1 = + ClassificationRepresentationModel classification1 = this.createClassification("id1", "ImportKey1", "DOMAIN_A", null, null); final String c1 = objMapper.writeValueAsString(classification1); - ClassificationResource classification2 = + ClassificationRepresentationModel classification2 = this.createClassification( "id2", "ImportKey2", "DOMAIN_A", "CLI:100000000000000000000000000000000016", "T2000"); classification2.setCategory("MANUAL"); @@ -182,7 +187,7 @@ class ClassificationDefinitionControllerIntTest { @Test void testImportDuplicateClassification() throws IOException { - ClassificationResource classification1 = new ClassificationResource(); + ClassificationRepresentationModel classification1 = new ClassificationRepresentationModel(); classification1.setClassificationId("id1"); classification1.setKey("ImportKey3"); classification1.setDomain("DOMAIN_A"); @@ -201,7 +206,7 @@ class ClassificationDefinitionControllerIntTest { @Test void testInsertExistingClassificationWithOlderTimestamp() throws IOException { - ClassificationSummaryResource existingClassification = + ClassificationSummaryRepresentationModel existingClassification = getClassificationWithKeyAndDomain("L110107", "DOMAIN_A"); existingClassification.setName("first new Name"); List clList = new ArrayList<>(); @@ -217,16 +222,16 @@ class ClassificationDefinitionControllerIntTest { response = importRequest(clList); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT); - ClassificationSummaryResource testClassification = + ClassificationSummaryRepresentationModel testClassification = this.getClassificationWithKeyAndDomain("L110107", "DOMAIN_A"); assertThat(testClassification.getName()).isEqualTo("second new Name"); } @Test void testHookExistingChildToNewParent() throws IOException { - final ClassificationResource newClassification = + final ClassificationRepresentationModel newClassification = createClassification("new Classification", "newClass", "DOMAIN_A", null, "L11010"); - ClassificationSummaryResource existingClassification = + ClassificationSummaryRepresentationModel existingClassification = getClassificationWithKeyAndDomain("L110102", "DOMAIN_A"); existingClassification.setParentId("new Classification"); existingClassification.setParentKey("newClass"); @@ -238,11 +243,11 @@ class ClassificationDefinitionControllerIntTest { ResponseEntity response = importRequest(clList); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT); - ClassificationSummaryResource parentCl = + ClassificationSummaryRepresentationModel parentCl = getClassificationWithKeyAndDomain("L11010", "DOMAIN_A"); - ClassificationSummaryResource testNewCl = + ClassificationSummaryRepresentationModel testNewCl = getClassificationWithKeyAndDomain("newClass", "DOMAIN_A"); - ClassificationSummaryResource testExistingCl = + ClassificationSummaryRepresentationModel testExistingCl = getClassificationWithKeyAndDomain("L110102", "DOMAIN_A"); assertThat(parentCl).isNotNull(); @@ -254,18 +259,18 @@ class ClassificationDefinitionControllerIntTest { @Test void testImportParentAndChildClassification() throws IOException { - ClassificationResource classification1 = + ClassificationRepresentationModel classification1 = this.createClassification("parentId", "ImportKey6", "DOMAIN_A", null, null); final String c1 = objMapper.writeValueAsString(classification1); - ClassificationResource classification2 = + ClassificationRepresentationModel classification2 = this.createClassification("childId1", "ImportKey7", "DOMAIN_A", null, "ImportKey6"); final String c21 = objMapper.writeValueAsString(classification2); classification2 = this.createClassification("childId2", "ImportKey8", "DOMAIN_A", "parentId", null); final String c22 = objMapper.writeValueAsString(classification2); - ClassificationResource classification3 = + ClassificationRepresentationModel classification3 = this.createClassification( "grandchildId1", "ImportKey9", "DOMAIN_A", "childId1", "ImportKey7"); final String c31 = objMapper.writeValueAsString(classification3); @@ -283,11 +288,11 @@ class ClassificationDefinitionControllerIntTest { ResponseEntity response = importRequest(clList); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT); - ClassificationSummaryResource parentCl = + ClassificationSummaryRepresentationModel parentCl = getClassificationWithKeyAndDomain("ImportKey6", "DOMAIN_A"); - ClassificationSummaryResource childCl = + ClassificationSummaryRepresentationModel childCl = getClassificationWithKeyAndDomain("ImportKey7", "DOMAIN_A"); - ClassificationSummaryResource grandchildCl = + ClassificationSummaryRepresentationModel grandchildCl = getClassificationWithKeyAndDomain("ImportKey9", "DOMAIN_A"); assertThat(parentCl).isNotNull(); @@ -299,14 +304,14 @@ class ClassificationDefinitionControllerIntTest { @Test void testImportParentAndChildClassificationWithKey() throws IOException { - ClassificationResource classification1 = + ClassificationRepresentationModel classification1 = createClassification("parent", "ImportKey11", "DOMAIN_A", null, null); classification1.setCustom1("parent is correct"); String parent = objMapper.writeValueAsString(classification1); - ClassificationResource classification2 = + ClassificationRepresentationModel classification2 = createClassification("wrongParent", "ImportKey11", "DOMAIN_B", null, null); String wrongParent = objMapper.writeValueAsString(classification2); - ClassificationResource classification3 = + ClassificationRepresentationModel classification3 = createClassification("child", "ImportKey13", "DOMAIN_A", null, "ImportKey11"); String child = objMapper.writeValueAsString(classification3); @@ -318,11 +323,11 @@ class ClassificationDefinitionControllerIntTest { ResponseEntity response = importRequest(clList); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT); - ClassificationSummaryResource rightParentCl = + ClassificationSummaryRepresentationModel rightParentCl = getClassificationWithKeyAndDomain("ImportKey11", "DOMAIN_A"); - ClassificationSummaryResource wrongParentCl = + ClassificationSummaryRepresentationModel wrongParentCl = getClassificationWithKeyAndDomain("ImportKey11", "DOMAIN_B"); - ClassificationSummaryResource childCl = + ClassificationSummaryRepresentationModel childCl = getClassificationWithKeyAndDomain("ImportKey13", "DOMAIN_A"); assertThat(rightParentCl).isNotNull(); @@ -335,14 +340,14 @@ class ClassificationDefinitionControllerIntTest { @Test void testChangeParentByImportingExistingClassification() throws IOException, InterruptedException { - ClassificationSummaryResource child1 = + ClassificationSummaryRepresentationModel child1 = this.getClassificationWithKeyAndDomain("L110105", "DOMAIN_A"); assertThat(child1.getParentKey()).isEqualTo("L11010"); child1.setParentId("CLI:100000000000000000000000000000000002"); child1.setParentKey("L10303"); final String withNewParent = objMapper.writeValueAsString(child1); - ClassificationSummaryResource child2 = + ClassificationSummaryRepresentationModel child2 = this.getClassificationWithKeyAndDomain("L110107", "DOMAIN_A"); assertThat(child2.getParentKey()).isEqualTo("L11010"); child2.setParentId(""); @@ -358,11 +363,11 @@ class ClassificationDefinitionControllerIntTest { Thread.sleep(10); LOGGER.debug("Wait 10 ms to give the system a chance to update"); - ClassificationSummaryResource childWithNewParent = + ClassificationSummaryRepresentationModel childWithNewParent = this.getClassificationWithKeyAndDomain("L110105", "DOMAIN_A"); assertThat(childWithNewParent.getParentKey()).isEqualTo(child1.getParentKey()); - ClassificationSummaryResource childWithoutParent = + ClassificationSummaryRepresentationModel childWithoutParent = this.getClassificationWithKeyAndDomain("L110107", "DOMAIN_A"); assertThat(childWithoutParent.getParentId()).isEqualTo(child2.getParentId()); assertThat(childWithoutParent.getParentKey()).isEqualTo(child2.getParentKey()); @@ -370,7 +375,7 @@ class ClassificationDefinitionControllerIntTest { @Test void testFailOnImportDuplicates() throws IOException { - ClassificationSummaryResource classification = + ClassificationSummaryRepresentationModel classification = this.getClassificationWithKeyAndDomain("L110105", "DOMAIN_A"); String classificationString = objMapper.writeValueAsString(classification); @@ -384,28 +389,32 @@ class ClassificationDefinitionControllerIntTest { .isEqualTo(HttpStatus.CONFLICT); } - private ClassificationResource createClassification( + private ClassificationRepresentationModel createClassification( String id, String key, String domain, String parentId, String parentKey) { - ClassificationResource classificationResource = new ClassificationResource(); - classificationResource.setClassificationId(id); - classificationResource.setKey(key); - classificationResource.setDomain(domain); - classificationResource.setParentId(parentId); - classificationResource.setParentKey(parentKey); - return classificationResource; + ClassificationRepresentationModel classificationRepresentationModel = + new ClassificationRepresentationModel(); + classificationRepresentationModel.setClassificationId(id); + classificationRepresentationModel.setKey(key); + classificationRepresentationModel.setDomain(domain); + classificationRepresentationModel.setParentId(parentId); + classificationRepresentationModel.setParentKey(parentKey); + return classificationRepresentationModel; } - private ClassificationSummaryResource getClassificationWithKeyAndDomain( + private ClassificationSummaryRepresentationModel getClassificationWithKeyAndDomain( String key, String domain) { LOGGER.debug("Request classification with key={} in domain={}", key, domain); HttpEntity request = new HttpEntity<>(restHelper.getHeaders()); - ResponseEntity response = + ResponseEntity> response = template.exchange( restHelper.toUrl(Mapping.URL_CLASSIFICATIONS) + "?key=" + key + "&domain=" + domain, HttpMethod.GET, request, - ParameterizedTypeReference.forType(ClassificationSummaryListResource.class)); - return response.getBody().getContent().toArray(new ClassificationSummaryResource[1])[0]; + CLASSIFICATION_SUMMARY_PAGE_MODEL_TYPE); + return response + .getBody() + .getContent() + .toArray(new ClassificationSummaryRepresentationModel[1])[0]; } private ResponseEntity importRequest(List clList) throws IOException { diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/GeneralExceptionHandlingTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/GeneralExceptionHandlingTest.java index ebe4df257..d47b1a83f 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/GeneralExceptionHandlingTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/GeneralExceptionHandlingTest.java @@ -13,12 +13,18 @@ import org.springframework.web.client.RestTemplate; import pro.taskana.RestHelper; import pro.taskana.TaskanaSpringBootTest; -import pro.taskana.rest.resource.ClassificationSummaryListResource; +import pro.taskana.rest.resource.ClassificationSummaryRepresentationModel; +import pro.taskana.rest.resource.TaskanaPagedModel; /** Test general Exception Handling. */ @TaskanaSpringBootTest class GeneralExceptionHandlingTest { + private static final ParameterizedTypeReference< + TaskanaPagedModel> + CLASSIFICATION_SUMMARY_PAGE_MODEL_TYPE = + new ParameterizedTypeReference< + TaskanaPagedModel>() {}; private static RestTemplate template; @Autowired RestHelper restHelper; @@ -35,7 +41,7 @@ class GeneralExceptionHandlingTest { restHelper.toUrl(Mapping.URL_CLASSIFICATIONS_ID, "non-existing-id"), HttpMethod.DELETE, restHelper.defaultRequest(), - ParameterizedTypeReference.forType(ClassificationSummaryListResource.class)); + CLASSIFICATION_SUMMARY_PAGE_MODEL_TYPE); }; assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/TaskCommentControllerIntTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/TaskCommentControllerIntTest.java index 9463b3033..79ccf9284 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/TaskCommentControllerIntTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/TaskCommentControllerIntTest.java @@ -22,13 +22,16 @@ import org.springframework.web.client.RestTemplate; import pro.taskana.RestHelper; import pro.taskana.TaskanaSpringBootTest; -import pro.taskana.rest.resource.TaskCommentListResource; -import pro.taskana.rest.resource.TaskCommentResource; +import pro.taskana.rest.resource.TaskCommentRepresentationModel; +import pro.taskana.rest.resource.TaskanaPagedModel; /** Test TaskCommentController. */ @TaskanaSpringBootTest class TaskCommentControllerIntTest { + private static final ParameterizedTypeReference> + TASK_COMMENT_PAGE_MODEL_TYPE = + new ParameterizedTypeReference>() {}; private static RestTemplate template; @Value("${taskana.schemaName:TASKANA}") @@ -53,7 +56,7 @@ class TaskCommentControllerIntTest { urlToNonExistingTaskComment, HttpMethod.GET, new HttpEntity(restHelper.getHeadersAdmin()), - ParameterizedTypeReference.forType(TaskCommentResource.class)); + ParameterizedTypeReference.forType(TaskCommentRepresentationModel.class)); }; assertThatThrownBy(httpCall) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) @@ -73,7 +76,7 @@ class TaskCommentControllerIntTest { urlToNotVisibleTask, HttpMethod.GET, new HttpEntity(restHelper.getHeadersUser_1_1()), - ParameterizedTypeReference.forType(TaskCommentListResource.class)); + TASK_COMMENT_PAGE_MODEL_TYPE); }; assertThatThrownBy(httpCall) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) @@ -93,7 +96,7 @@ class TaskCommentControllerIntTest { urlToNotVisibleTask, HttpMethod.GET, new HttpEntity(restHelper.getHeadersUser_1_2()), - ParameterizedTypeReference.forType(TaskCommentResource.class)); + ParameterizedTypeReference.forType(TaskCommentRepresentationModel.class)); }; assertThatThrownBy(httpCall) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) @@ -104,9 +107,10 @@ class TaskCommentControllerIntTest { @Test void should_FailToCreateTaskComment_When_TaskIsNotVisible() { - TaskCommentResource taskCommentResourceToCreate = new TaskCommentResource(); - taskCommentResourceToCreate.setTaskId("TKI:000000000000000000000000000000000000"); - taskCommentResourceToCreate.setTextField("newly created task comment"); + TaskCommentRepresentationModel taskCommentRepresentationModelToCreate = + new TaskCommentRepresentationModel(); + taskCommentRepresentationModelToCreate.setTaskId("TKI:000000000000000000000000000000000000"); + taskCommentRepresentationModelToCreate.setTextField("newly created task comment"); ThrowingCallable httpCall = () -> { @@ -114,8 +118,9 @@ class TaskCommentControllerIntTest { restHelper.toUrl( Mapping.URL_TASK_GET_POST_COMMENTS, "TKI:000000000000000000000000000000000000"), HttpMethod.POST, - new HttpEntity<>(taskCommentResourceToCreate, restHelper.getHeadersUser_1_1()), - ParameterizedTypeReference.forType(TaskCommentResource.class)); + new HttpEntity<>( + taskCommentRepresentationModelToCreate, restHelper.getHeadersUser_1_1()), + ParameterizedTypeReference.forType(TaskCommentRepresentationModel.class)); }; assertThatThrownBy(httpCall) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) @@ -125,17 +130,19 @@ class TaskCommentControllerIntTest { @Test void should_FailToCreateTaskComment_When_TaskIdIsNonExisting() { - TaskCommentResource taskCommentResourceToCreate = new TaskCommentResource(); - taskCommentResourceToCreate.setTaskId("DefinatelyNotExistingId"); - taskCommentResourceToCreate.setTextField("newly created task comment"); + TaskCommentRepresentationModel taskCommentRepresentationModelToCreate = + new TaskCommentRepresentationModel(); + taskCommentRepresentationModelToCreate.setTaskId("DefinatelyNotExistingId"); + taskCommentRepresentationModelToCreate.setTextField("newly created task comment"); ThrowingCallable httpCall = () -> { template.exchange( restHelper.toUrl(Mapping.URL_TASK_GET_POST_COMMENTS, "DefinatelyNotExistingId"), HttpMethod.POST, - new HttpEntity<>(taskCommentResourceToCreate, restHelper.getHeadersAdmin()), - ParameterizedTypeReference.forType(TaskCommentResource.class)); + new HttpEntity<>( + taskCommentRepresentationModelToCreate, restHelper.getHeadersAdmin()), + ParameterizedTypeReference.forType(TaskCommentRepresentationModel.class)); }; assertThatThrownBy(httpCall) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) @@ -150,18 +157,19 @@ class TaskCommentControllerIntTest { String url = restHelper.toUrl(Mapping.URL_TASK_COMMENT, "TCI:000000000000000000000000000000000000"); - ResponseEntity getTaskCommentResponse = + ResponseEntity getTaskCommentResponse = template.exchange( url, HttpMethod.GET, new HttpEntity(restHelper.getHeadersAdmin()), - ParameterizedTypeReference.forType(TaskCommentResource.class)); + 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"); - TaskCommentResource taskCommentResourceToUpdate = getTaskCommentResponse.getBody(); - taskCommentResourceToUpdate.setModified(Instant.now().toString()); + TaskCommentRepresentationModel taskCommentRepresentationModelToUpdate = + getTaskCommentResponse.getBody(); + taskCommentRepresentationModelToUpdate.setModified(Instant.now().toString()); ThrowingCallable httpCall = () -> { @@ -169,9 +177,9 @@ class TaskCommentControllerIntTest { url, HttpMethod.PUT, new HttpEntity<>( - mapper.writeValueAsString(taskCommentResourceToUpdate), + mapper.writeValueAsString(taskCommentRepresentationModelToUpdate), restHelper.getHeadersUser_1_1()), - ParameterizedTypeReference.forType(TaskCommentResource.class)); + ParameterizedTypeReference.forType(TaskCommentRepresentationModel.class)); }; assertThatThrownBy(httpCall) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) @@ -187,18 +195,19 @@ class TaskCommentControllerIntTest { String url = restHelper.toUrl(Mapping.URL_TASK_COMMENT, "TCI:000000000000000000000000000000000000"); - ResponseEntity getTaskCommentResponse = + ResponseEntity getTaskCommentResponse = template.exchange( url, HttpMethod.GET, new HttpEntity(restHelper.getHeadersUser_1_1()), - ParameterizedTypeReference.forType(TaskCommentResource.class)); + 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"); - TaskCommentResource taskCommentResourceToUpdate = getTaskCommentResponse.getBody(); - taskCommentResourceToUpdate.setTextField("updated textfield"); + TaskCommentRepresentationModel taskCommentRepresentationModelToUpdate = + getTaskCommentResponse.getBody(); + taskCommentRepresentationModelToUpdate.setTextField("updated textfield"); ThrowingCallable httpCall = () -> { @@ -206,15 +215,15 @@ class TaskCommentControllerIntTest { url, HttpMethod.PUT, new HttpEntity<>( - mapper.writeValueAsString(taskCommentResourceToUpdate), + mapper.writeValueAsString(taskCommentRepresentationModelToUpdate), restHelper.getHeadersUser_1_2()), - ParameterizedTypeReference.forType(TaskCommentResource.class)); + ParameterizedTypeReference.forType(TaskCommentRepresentationModel.class)); }; assertThatThrownBy(httpCall) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) .isEqualTo(HttpStatus.FORBIDDEN); } - + @Test void should_FailToUpdateTaskComment_When_TaskCommentIdInResourceDoesNotMatchPathVariable() { @@ -223,19 +232,20 @@ class TaskCommentControllerIntTest { String url = restHelper.toUrl(Mapping.URL_TASK_COMMENT, "TCI:000000000000000000000000000000000000"); - ResponseEntity getTaskCommentResponse = + ResponseEntity getTaskCommentResponse = template.exchange( url, HttpMethod.GET, new HttpEntity(restHelper.getHeadersAdmin()), - ParameterizedTypeReference.forType(TaskCommentResource.class)); + 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"); - TaskCommentResource taskCommentResourceToUpdate = getTaskCommentResponse.getBody(); - taskCommentResourceToUpdate.setTextField("updated text"); - taskCommentResourceToUpdate.setTaskCommentId("DifferentTaskCommentId"); + TaskCommentRepresentationModel taskCommentRepresentationModelToUpdate = + getTaskCommentResponse.getBody(); + taskCommentRepresentationModelToUpdate.setTextField("updated text"); + taskCommentRepresentationModelToUpdate.setTaskCommentId("DifferentTaskCommentId"); ThrowingCallable httpCall = () -> { @@ -243,9 +253,9 @@ class TaskCommentControllerIntTest { url, HttpMethod.PUT, new HttpEntity<>( - mapper.writeValueAsString(taskCommentResourceToUpdate), + mapper.writeValueAsString(taskCommentRepresentationModelToUpdate), restHelper.getHeadersUser_1_1()), - ParameterizedTypeReference.forType(TaskCommentResource.class)); + ParameterizedTypeReference.forType(TaskCommentRepresentationModel.class)); }; assertThatThrownBy(httpCall) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) @@ -256,12 +266,14 @@ class TaskCommentControllerIntTest { @Test void should_FailToDeleteTaskComment_When_UserHasNoAuthorization() { - ResponseEntity getTaskCommentsBeforeDeleteionResponse = - template.exchange( - restHelper.toUrl(Mapping.URL_TASK_COMMENTS, "TKI:000000000000000000000000000000000001"), - HttpMethod.GET, - new HttpEntity(restHelper.getHeadersAdmin()), - ParameterizedTypeReference.forType(TaskCommentListResource.class)); + ResponseEntity> + getTaskCommentsBeforeDeleteionResponse = + template.exchange( + restHelper.toUrl( + Mapping.URL_TASK_COMMENTS, "TKI:000000000000000000000000000000000001"), + HttpMethod.GET, + new HttpEntity(restHelper.getHeadersAdmin()), + TASK_COMMENT_PAGE_MODEL_TYPE); assertThat(getTaskCommentsBeforeDeleteionResponse.getBody().getContent()).hasSize(2); String url = @@ -273,7 +285,7 @@ class TaskCommentControllerIntTest { url, HttpMethod.DELETE, new HttpEntity(restHelper.getHeadersUser_1_2()), - ParameterizedTypeReference.forType(TaskCommentResource.class)); + ParameterizedTypeReference.forType(TaskCommentRepresentationModel.class)); }; assertThatThrownBy(httpCall) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) @@ -291,7 +303,7 @@ class TaskCommentControllerIntTest { url, HttpMethod.DELETE, new HttpEntity(restHelper.getHeadersAdmin()), - ParameterizedTypeReference.forType(TaskCommentResource.class)); + ParameterizedTypeReference.forType(TaskCommentRepresentationModel.class)); }; assertThatThrownBy(httpCall) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/TaskControllerIntTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/TaskControllerIntTest.java index e6d31c139..7fc03cfe8 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/TaskControllerIntTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/TaskControllerIntTest.java @@ -34,10 +34,11 @@ import org.springframework.web.client.RestTemplate; import pro.taskana.RestHelper; import pro.taskana.TaskanaSpringBootTest; -import pro.taskana.rest.resource.ClassificationSummaryResource; -import pro.taskana.rest.resource.TaskResource; -import pro.taskana.rest.resource.TaskSummaryListResource; -import pro.taskana.rest.resource.WorkbasketSummaryResource; +import pro.taskana.rest.resource.ClassificationSummaryRepresentationModel; +import pro.taskana.rest.resource.TaskRepresentationModel; +import pro.taskana.rest.resource.TaskSummaryRepresentationModel; +import pro.taskana.rest.resource.TaskanaPagedModel; +import pro.taskana.rest.resource.WorkbasketSummaryRepresentationModel; import pro.taskana.sampledata.SampleDataGenerator; import pro.taskana.task.api.TaskState; import pro.taskana.task.api.models.ObjectReference; @@ -46,6 +47,9 @@ import pro.taskana.task.api.models.ObjectReference; @TaskanaSpringBootTest class TaskControllerIntTest { + private static final ParameterizedTypeReference> + TASK_SUMMARY_PAGE_MODEL_TYPE = + new ParameterizedTypeReference>() {}; private static RestTemplate template; @Value("${taskana.schemaName:TASKANA}") @@ -67,26 +71,30 @@ class TaskControllerIntTest { @Test void testGetAllTasks() { - ResponseEntity response = + ResponseEntity> response = template.exchange( restHelper.toUrl(Mapping.URL_TASKS), HttpMethod.GET, restHelper.defaultRequest(), - ParameterizedTypeReference.forType(TaskSummaryListResource.class)); - assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); + TASK_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); + assertThat((response.getBody()).getLink(IanaLinkRelations.SELF)) + .isNotNull(); assertThat(response.getBody().getContent()).hasSize(25); } @Test void testGetAllTasksByWorkbasketId() { - ResponseEntity response = + ResponseEntity> response = template.exchange( restHelper.toUrl(Mapping.URL_TASKS) + "?workbasket-id=WBI:100000000000000000000000000000000001", HttpMethod.GET, restHelper.defaultRequest(), - ParameterizedTypeReference.forType(TaskSummaryListResource.class)); - assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); + TASK_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); + assertThat((response.getBody()).getLink(IanaLinkRelations.SELF)) + .isNotNull(); assertThat(response.getBody().getContent()).hasSize(22); } @@ -98,7 +106,7 @@ class TaskControllerIntTest { Instant thirdInstant = Instant.now().minus(10, ChronoUnit.DAYS); Instant fourthInstant = Instant.now().minus(11, ChronoUnit.DAYS); - ResponseEntity response = + ResponseEntity> response = template.exchange( restHelper.toUrl(Mapping.URL_TASKS) + "?workbasket-id=WBI:100000000000000000000000000000000001" @@ -114,8 +122,10 @@ class TaskControllerIntTest { + "&sort-by=planned", HttpMethod.GET, restHelper.defaultRequest(), - ParameterizedTypeReference.forType(TaskSummaryListResource.class)); - assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); + TASK_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); + assertThat((response.getBody()).getLink(IanaLinkRelations.SELF)) + .isNotNull(); assertThat(response.getBody().getContent()).hasSize(6); } @@ -125,7 +135,7 @@ class TaskControllerIntTest { Instant plannedFromInstant = Instant.now().minus(6, ChronoUnit.DAYS); Instant plannedToInstant = Instant.now().minus(3, ChronoUnit.DAYS); - ResponseEntity response = + ResponseEntity> response = template.exchange( restHelper.toUrl(Mapping.URL_TASKS) + "?workbasket-id=WBI:100000000000000000000000000000000001" @@ -136,8 +146,10 @@ class TaskControllerIntTest { + "&sort-by=planned", HttpMethod.GET, restHelper.defaultRequest(), - ParameterizedTypeReference.forType(TaskSummaryListResource.class)); - assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); + TASK_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); + assertThat((response.getBody()).getLink(IanaLinkRelations.SELF)) + .isNotNull(); assertThat(response.getBody().getContent()).hasSize(3); } @@ -146,7 +158,7 @@ class TaskControllerIntTest { Instant plannedFromInstant = Instant.now().minus(6, ChronoUnit.DAYS); - ResponseEntity response = + ResponseEntity> response = template.exchange( restHelper.toUrl(Mapping.URL_TASKS) + "?workbasket-id=WBI:100000000000000000000000000000000001" @@ -155,27 +167,27 @@ class TaskControllerIntTest { + "&sort-by=planned", HttpMethod.GET, restHelper.defaultRequest(), - ParameterizedTypeReference.forType(TaskSummaryListResource.class)); - assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); + TASK_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); + assertThat((response.getBody()).getLink(IanaLinkRelations.SELF)) + .isNotNull(); assertThat(response.getBody().getContent()).hasSize(4); } @Test void testGetAllTasksByWorkbasketIdWithInvalidPlannedParamsCombination() { ThrowingCallable httpCall = - () -> { - template.exchange( - restHelper.toUrl(Mapping.URL_TASKS) - + "?workbasket-id=WBI:100000000000000000000000000000000001" - + "&planned=2020-01-22T09:44:47.453Z,," - + "2020-01-19T07:44:47.453Z,2020-01-19T19:44:47.453Z," - + ",2020-01-18T09:44:47.453Z" - + "&planned-from=2020-01-19T07:44:47.453Z" - + "&sort-by=planned", - HttpMethod.GET, - restHelper.defaultRequest(), - ParameterizedTypeReference.forType(TaskSummaryListResource.class)); - }; + () -> template.exchange( + restHelper.toUrl(Mapping.URL_TASKS) + + "?workbasket-id=WBI:100000000000000000000000000000000001" + + "&planned=2020-01-22T09:44:47.453Z,," + + "2020-01-19T07:44:47.453Z,2020-01-19T19:44:47.453Z," + + ",2020-01-18T09:44:47.453Z" + + "&planned-from=2020-01-19T07:44:47.453Z" + + "&sort-by=planned", + HttpMethod.GET, + restHelper.defaultRequest(), + TASK_SUMMARY_PAGE_MODEL_TYPE); assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .hasMessageContaining("400"); @@ -189,7 +201,7 @@ class TaskControllerIntTest { Instant thirdInstant = Instant.now().minus(10, ChronoUnit.DAYS); Instant fourthInstant = Instant.now().minus(11, ChronoUnit.DAYS); - ResponseEntity response = + ResponseEntity> response = template.exchange( restHelper.toUrl(Mapping.URL_TASKS) + "?workbasket-id=WBI:100000000000000000000000000000000001" @@ -205,22 +217,26 @@ class TaskControllerIntTest { + "&sort-by=due", HttpMethod.GET, restHelper.defaultRequest(), - ParameterizedTypeReference.forType(TaskSummaryListResource.class)); - assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); + TASK_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); + assertThat((response.getBody()).getLink(IanaLinkRelations.SELF)) + .isNotNull(); assertThat(response.getBody().getContent()).hasSize(6); } @Test void should_ReturnAllTasksByWildcardSearch_For_ProvidedSearchValue() { - ResponseEntity response = + ResponseEntity> response = template.exchange( restHelper.toUrl(Mapping.URL_TASKS) + "?wildcard-search-value=%99%" + "&wildcard-search-fields=NAME,custom_3,CuStOM_4", HttpMethod.GET, new HttpEntity(restHelper.getHeadersAdmin()), - ParameterizedTypeReference.forType(TaskSummaryListResource.class)); - assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); + TASK_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); + assertThat((response.getBody()).getLink(IanaLinkRelations.SELF)) + .isNotNull(); assertThat(response.getBody().getContent()).hasSize(4); } @@ -228,13 +244,11 @@ class TaskControllerIntTest { void should_ThrowException_When_ProvidingInvalidWildcardSearchParameters() { ThrowingCallable httpCall = - () -> { - template.exchange( - restHelper.toUrl(Mapping.URL_TASKS) + "?wildcard-search-value=%rt%", - HttpMethod.GET, - restHelper.defaultRequest(), - ParameterizedTypeReference.forType(TaskSummaryListResource.class)); - }; + () -> template.exchange( + restHelper.toUrl(Mapping.URL_TASKS) + "?wildcard-search-value=%rt%", + HttpMethod.GET, + restHelper.defaultRequest(), + TASK_SUMMARY_PAGE_MODEL_TYPE); assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .hasMessageContaining("400") @@ -242,14 +256,12 @@ class TaskControllerIntTest { .isEqualTo(HttpStatus.BAD_REQUEST); ThrowingCallable httpCall2 = - () -> { - template.exchange( - restHelper.toUrl(Mapping.URL_TASKS) - + "?wildcard-search-fields=NAME,CUSTOM_3,CUSTOM_4", - HttpMethod.GET, - restHelper.defaultRequest(), - ParameterizedTypeReference.forType(TaskSummaryListResource.class)); - }; + () -> template.exchange( + restHelper.toUrl(Mapping.URL_TASKS) + + "?wildcard-search-fields=NAME,CUSTOM_3,CUSTOM_4", + HttpMethod.GET, + restHelper.defaultRequest(), + TASK_SUMMARY_PAGE_MODEL_TYPE); assertThatThrownBy(httpCall2) .isInstanceOf(HttpClientErrorException.class) .hasMessageContaining("400") @@ -263,7 +275,7 @@ class TaskControllerIntTest { Instant dueFromInstant = Instant.now().minus(8, ChronoUnit.DAYS); Instant dueToInstant = Instant.now().minus(3, ChronoUnit.DAYS); - ResponseEntity response = + ResponseEntity> response = template.exchange( restHelper.toUrl(Mapping.URL_TASKS) + "?workbasket-id=WBI:100000000000000000000000000000000001" @@ -274,8 +286,10 @@ class TaskControllerIntTest { + "&sort-by=due", HttpMethod.GET, restHelper.defaultRequest(), - ParameterizedTypeReference.forType(TaskSummaryListResource.class)); - assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); + TASK_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); + assertThat((response.getBody()).getLink(IanaLinkRelations.SELF)) + .isNotNull(); assertThat(response.getBody().getContent()).hasSize(9); } @@ -284,7 +298,7 @@ class TaskControllerIntTest { Instant dueToInstant = Instant.now().minus(1, ChronoUnit.DAYS); - ResponseEntity response = + ResponseEntity> response = template.exchange( restHelper.toUrl(Mapping.URL_TASKS) + "?workbasket-id=WBI:100000000000000000000000000000000001" @@ -293,27 +307,27 @@ class TaskControllerIntTest { + "&sort-by=due", HttpMethod.GET, restHelper.defaultRequest(), - ParameterizedTypeReference.forType(TaskSummaryListResource.class)); - assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); + TASK_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); + assertThat((response.getBody()).getLink(IanaLinkRelations.SELF)) + .isNotNull(); assertThat(response.getBody().getContent()).hasSize(6); } @Test void testGetAllTasksByWorkbasketIdWithInvalidDueParamsCombination() { ThrowingCallable httpCall = - () -> { - template.exchange( - restHelper.toUrl(Mapping.URL_TASKS) - + "?workbasket-id=WBI:100000000000000000000000000000000001" - + "&due=2020-01-22T09:44:47.453Z,," - + "2020-01-19T07:44:47.453Z,2020-01-19T19:44:47.453Z," - + ",2020-01-18T09:44:47.453Z" - + "&due-from=2020-01-19T07:44:47.453Z" - + "&sort-by=planned", - HttpMethod.GET, - restHelper.defaultRequest(), - ParameterizedTypeReference.forType(TaskSummaryListResource.class)); - }; + () -> template.exchange( + restHelper.toUrl(Mapping.URL_TASKS) + + "?workbasket-id=WBI:100000000000000000000000000000000001" + + "&due=2020-01-22T09:44:47.453Z,," + + "2020-01-19T07:44:47.453Z,2020-01-19T19:44:47.453Z," + + ",2020-01-18T09:44:47.453Z" + + "&due-from=2020-01-19T07:44:47.453Z" + + "&sort-by=planned", + HttpMethod.GET, + restHelper.defaultRequest(), + TASK_SUMMARY_PAGE_MODEL_TYPE); assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .hasMessageContaining("400"); @@ -324,27 +338,31 @@ class TaskControllerIntTest { HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Basic dXNlcl8xXzI6dXNlcl8xXzI="); // user_1_2 HttpEntity request = new HttpEntity<>(headers); - ResponseEntity response = + ResponseEntity> response = template.exchange( restHelper.toUrl(Mapping.URL_TASKS) + "?workbasket-key=USER_1_2&domain=DOMAIN_A", HttpMethod.GET, request, - ParameterizedTypeReference.forType(TaskSummaryListResource.class)); - assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); + TASK_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); + assertThat((response.getBody()).getLink(IanaLinkRelations.SELF)) + .isNotNull(); assertThat(response.getBody().getContent()).hasSize(20); } @Test void testGetAllTasksByExternalId() { - ResponseEntity response = + ResponseEntity> response = template.exchange( restHelper.toUrl(Mapping.URL_TASKS) + "?external-id=ETI:000000000000000000000000000000000003," + "ETI:000000000000000000000000000000000004", HttpMethod.GET, restHelper.defaultRequest(), - ParameterizedTypeReference.forType(TaskSummaryListResource.class)); - assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); + TASK_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); + assertThat((response.getBody()).getLink(IanaLinkRelations.SELF)) + .isNotNull(); assertThat(response.getBody().getContent()).hasSize(2); } @@ -356,13 +374,11 @@ class TaskControllerIntTest { HttpEntity request = new HttpEntity<>(headers); ThrowingCallable httpCall = - () -> { - template.exchange( - restHelper.toUrl(Mapping.URL_TASKS) + "?workbasket-key=USER_1_2", - HttpMethod.GET, - request, - ParameterizedTypeReference.forType(TaskSummaryListResource.class)); - }; + () -> template.exchange( + restHelper.toUrl(Mapping.URL_TASKS) + "?workbasket-key=USER_1_2", + HttpMethod.GET, + request, + TASK_SUMMARY_PAGE_MODEL_TYPE); assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .hasMessageContaining("400"); @@ -370,46 +386,48 @@ class TaskControllerIntTest { @Test void testGetAllTasksWithAdminRole() { - ResponseEntity response = + ResponseEntity> response = template.exchange( restHelper.toUrl(Mapping.URL_TASKS), HttpMethod.GET, new HttpEntity<>(restHelper.getHeadersAdmin()), - ParameterizedTypeReference.forType(TaskSummaryListResource.class)); - assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); + TASK_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); + assertThat((response.getBody()).getLink(IanaLinkRelations.SELF)) + .isNotNull(); assertThat(response.getBody().getContent()).hasSize(73); } @Test void testGetAllTasksKeepingFilters() { - ResponseEntity response = + ResponseEntity> response = template.exchange( restHelper.toUrl(Mapping.URL_TASKS) + "?por.type=VNR&por.value=22334455&sort-by=por.value&order=desc", HttpMethod.GET, restHelper.defaultRequest(), - ParameterizedTypeReference.forType(TaskSummaryListResource.class)); - assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); + TASK_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); + assertThat((response.getBody()).getLink(IanaLinkRelations.SELF)) + .isNotNull(); assertThat( - response - .getBody() - .getRequiredLink(IanaLinkRelations.SELF) - .getHref() - .endsWith( - "/api/v1/tasks?por.type=VNR&por.value=22334455&sort-by=por.value&order=desc")) + response + .getBody() + .getRequiredLink(IanaLinkRelations.SELF) + .getHref() + .endsWith( + "/api/v1/tasks?por.type=VNR&por.value=22334455&sort-by=por.value&order=desc")) .isTrue(); } @Test void testThrowsExceptionIfInvalidFilterIsUsed() { ThrowingCallable httpCall = - () -> { - template.exchange( - restHelper.toUrl(Mapping.URL_TASKS) + "?invalid=VNR", - HttpMethod.GET, - restHelper.defaultRequest(), - ParameterizedTypeReference.forType(TaskSummaryListResource.class)); - }; + () -> template.exchange( + restHelper.toUrl(Mapping.URL_TASKS) + "?invalid=VNR", + HttpMethod.GET, + restHelper.defaultRequest(), + TASK_SUMMARY_PAGE_MODEL_TYPE); assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .hasMessageContaining("[invalid]") @@ -421,20 +439,21 @@ class TaskControllerIntTest { void testGetLastPageSortedByPorValue() { HttpEntity request = new HttpEntity<>(restHelper.getHeadersAdmin()); - ResponseEntity response = + ResponseEntity> response = template.exchange( restHelper.toUrl(Mapping.URL_TASKS) - + "?state=READY,CLAIMED&sort-by=por.value&order=desc&page=15&page-size=5", + + "?state=READY,CLAIMED&sort-by=por.value&order=desc&page-size=5&page=14", HttpMethod.GET, request, - ParameterizedTypeReference.forType(TaskSummaryListResource.class)); - assertThat(response.getBody().getContent()).hasSize(1); + TASK_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); + assertThat((response.getBody()).getContent()).hasSize(1); assertThat( - response - .getBody() - .getRequiredLink(IanaLinkRelations.LAST) - .getHref() - .contains("page=14")) + response + .getBody() + .getRequiredLink(IanaLinkRelations.LAST) + .getHref() + .contains("page=14")) .isTrue(); assertThat("TKI:100000000000000000000000000000000000") .isEqualTo(response.getBody().getContent().iterator().next().getTaskId()); @@ -447,7 +466,7 @@ class TaskControllerIntTest { .getHref() .endsWith( "/api/v1/tasks?" - + "state=READY,CLAIMED&sort-by=por.value&order=desc&page=15&page-size=5")) + + "state=READY,CLAIMED&sort-by=por.value&order=desc&page-size=5&page=14")) .isTrue(); assertThat(response.getBody().getLink(IanaLinkRelations.FIRST)).isNotNull(); @@ -466,34 +485,36 @@ class TaskControllerIntTest { headers.add("Authorization", "Basic dGVhbWxlYWRfMTp0ZWFtbGVhZF8x"); HttpEntity request = new HttpEntity<>(headers); - ResponseEntity response = + ResponseEntity> response = template.exchange( restHelper.toUrl(Mapping.URL_TASKS) + "?sort-by=due&order=desc", HttpMethod.GET, request, - ParameterizedTypeReference.forType(TaskSummaryListResource.class)); - assertThat(response.getBody().getContent()).hasSize(25); + TASK_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); + assertThat((response.getBody()).getContent()).hasSize(25); response = template.exchange( - restHelper.toUrl(Mapping.URL_TASKS) + "?sort-by=due&order=desc&page=5&page-size=5", + restHelper.toUrl(Mapping.URL_TASKS) + "?sort-by=due&order=desc&page-size=5&page=5", HttpMethod.GET, request, - ParameterizedTypeReference.forType(TaskSummaryListResource.class)); - assertThat(response.getBody().getContent()).hasSize(5); + TASK_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); + assertThat((response.getBody()).getContent()).hasSize(5); assertThat( - response.getBody().getRequiredLink(IanaLinkRelations.LAST).getHref().contains("page=5")) + response.getBody().getRequiredLink(IanaLinkRelations.LAST).getHref().contains("page=5")) .isTrue(); assertThat("TKI:000000000000000000000000000000000023") .isEqualTo(response.getBody().getContent().iterator().next().getTaskId()); assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); assertThat( - response - .getBody() - .getRequiredLink(IanaLinkRelations.SELF) - .getHref() - .endsWith("/api/v1/tasks?sort-by=due&order=desc&page=5&page-size=5")) + response + .getBody() + .getRequiredLink(IanaLinkRelations.SELF) + .getHref() + .endsWith("/api/v1/tasks?sort-by=due&order=desc&page-size=5&page=5")) .isTrue(); assertThat(response.getBody().getLink(IanaLinkRelations.FIRST)).isNotNull(); @@ -510,30 +531,31 @@ class TaskControllerIntTest { HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Basic dGVhbWxlYWRfMTp0ZWFtbGVhZF8x"); HttpEntity request = new HttpEntity<>(headers); - ResponseEntity response = + ResponseEntity> response = template.exchange( restHelper.toUrl(Mapping.URL_TASKS) + "?por.company=00&por.system=PASystem&por.instance=00&" + "por.type=VNR&por.value=22334455&sort-by=por.type&" - + "order=asc&page=2&page-size=5", + + "order=asc&page-size=5&page=2", HttpMethod.GET, request, - ParameterizedTypeReference.forType(TaskSummaryListResource.class)); - assertThat(response.getBody().getContent()).hasSize(1); - assertThat("TKI:000000000000000000000000000000000013") - .isEqualTo(response.getBody().getContent().iterator().next().getTaskId()); + TASK_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); + assertThat(response.getBody().getContent()) + .extracting(TaskSummaryRepresentationModel::getTaskId) + .containsOnly("TKI:000000000000000000000000000000000013"); assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); assertThat( - response - .getBody() - .getRequiredLink(IanaLinkRelations.SELF) - .getHref() - .endsWith( - "/api/v1/tasks?por.company=00&por.system=PASystem&por.instance=00&" - + "por.type=VNR&por.value=22334455&sort-by=por.type&order=asc&" - + "page=2&page-size=5")) + response + .getBody() + .getRequiredLink(IanaLinkRelations.SELF) + .getHref() + .endsWith( + "/api/v1/tasks?por.company=00&por.system=PASystem&por.instance=00&" + + "por.type=VNR&por.value=22334455&sort-by=por.type&order=asc&" + + "page-size=5&page=2")) .isTrue(); assertThat(response.getBody().getLink(IanaLinkRelations.FIRST)).isNotNull(); @@ -553,7 +575,7 @@ class TaskControllerIntTest { BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream(), UTF_8)); String inputLine; - StringBuffer content = new StringBuffer(); + StringBuilder content = new StringBuilder(); while ((inputLine = in.readLine()) != null) { content.append(inputLine); } @@ -613,8 +635,10 @@ class TaskControllerIntTest { String updatedTask = content.toString(); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - TaskResource originalTaskObject = mapper.readValue(originalTask, TaskResource.class); - TaskResource updatedTaskObject = mapper.readValue(updatedTask, TaskResource.class); + TaskRepresentationModel originalTaskObject = + mapper.readValue(originalTask, TaskRepresentationModel.class); + TaskRepresentationModel updatedTaskObject = + mapper.readValue(updatedTask, TaskRepresentationModel.class); assertThat(updatedTaskObject.getModified()).isNotEqualTo(originalTaskObject.getModified()); } @@ -622,13 +646,13 @@ class TaskControllerIntTest { @Test void testCreateAndDeleteTask() { - TaskResource taskResource = getTaskResourceSample(); - ResponseEntity responseCreate = + TaskRepresentationModel taskRepresentationModel = getTaskResourceSample(); + ResponseEntity responseCreate = template.exchange( restHelper.toUrl(Mapping.URL_TASKS), HttpMethod.POST, - new HttpEntity<>(taskResource, restHelper.getHeaders()), - ParameterizedTypeReference.forType(TaskResource.class)); + new HttpEntity<>(taskRepresentationModel, restHelper.getHeaders()), + ParameterizedTypeReference.forType(TaskRepresentationModel.class)); assertThat(HttpStatus.CREATED).isEqualTo(responseCreate.getStatusCode()); assertThat(responseCreate.getBody()).isNotNull(); @@ -637,7 +661,7 @@ class TaskControllerIntTest { assertThat(taskIdOfCreatedTask).isNotNull(); assertThat(taskIdOfCreatedTask.startsWith("TKI:")).isTrue(); - ResponseEntity responseDeleted = + ResponseEntity responseDeleted = template.exchange( restHelper.toUrl(Mapping.URL_TASKS_ID, taskIdOfCreatedTask), HttpMethod.DELETE, @@ -653,19 +677,17 @@ class TaskControllerIntTest { */ @Test void testCreateWithPlannedAndDueDate() { - TaskResource taskResource = getTaskResourceSample(); + TaskRepresentationModel taskRepresentationModel = getTaskResourceSample(); Instant now = Instant.now(); - taskResource.setPlanned(now.toString()); - taskResource.setDue(now.toString()); + taskRepresentationModel.setPlanned(now.toString()); + taskRepresentationModel.setDue(now.toString()); ThrowingCallable httpCall = - () -> { - template.exchange( - restHelper.toUrl(Mapping.URL_TASKS), - HttpMethod.POST, - new HttpEntity<>(taskResource, restHelper.getHeaders()), - ParameterizedTypeReference.forType(TaskResource.class)); - }; + () -> template.exchange( + restHelper.toUrl(Mapping.URL_TASKS), + HttpMethod.POST, + new HttpEntity<>(taskRepresentationModel, restHelper.getHeaders()), + ParameterizedTypeReference.forType(TaskRepresentationModel.class)); assertThatThrownBy(httpCall).isInstanceOf(HttpClientErrorException.class); } @@ -720,34 +742,34 @@ class TaskControllerIntTest { final String user_id_of_claimed_task = "user_1_2"; // retrieve task from Rest Api - ResponseEntity getTaskResponse = + ResponseEntity getTaskResponse = template.exchange( restHelper.toUrl(Mapping.URL_TASKS_ID, claimed_task_id), HttpMethod.GET, new HttpEntity<>(restHelper.getHeadersUser_1_2()), - ParameterizedTypeReference.forType(TaskResource.class)); + ParameterizedTypeReference.forType(TaskRepresentationModel.class)); assertThat(getTaskResponse.getBody()).isNotNull(); - TaskResource claimedTaskResource = getTaskResponse.getBody(); - assertThat(claimedTaskResource.getState()).isEqualTo(TaskState.CLAIMED); - assertThat(claimedTaskResource.getOwner()).isEqualTo(user_id_of_claimed_task); + TaskRepresentationModel claimedTaskRepresentationModel = getTaskResponse.getBody(); + assertThat(claimedTaskRepresentationModel.getState()).isEqualTo(TaskState.CLAIMED); + assertThat(claimedTaskRepresentationModel.getOwner()).isEqualTo(user_id_of_claimed_task); // cancel claim - ResponseEntity cancelClaimResponse = + ResponseEntity cancelClaimResponse = template.exchange( restHelper.toUrl(Mapping.URL_TASKS_ID_CLAIM, claimed_task_id), HttpMethod.DELETE, new HttpEntity<>(restHelper.getHeadersUser_1_2()), - ParameterizedTypeReference.forType(TaskResource.class)); + ParameterizedTypeReference.forType(TaskRepresentationModel.class)); assertThat(cancelClaimResponse.getBody()).isNotNull(); assertThat(cancelClaimResponse.getStatusCode().is2xxSuccessful()); - TaskResource cancelClaimedtaskResource = cancelClaimResponse.getBody(); - assertThat(cancelClaimedtaskResource.getOwner()).isNull(); - assertThat(cancelClaimedtaskResource.getClaimed()).isNull(); - assertThat(cancelClaimedtaskResource.getState()).isEqualTo(TaskState.READY); + TaskRepresentationModel cancelClaimedtaskRepresentationModel = cancelClaimResponse.getBody(); + assertThat(cancelClaimedtaskRepresentationModel.getOwner()).isNull(); + assertThat(cancelClaimedtaskRepresentationModel.getClaimed()).isNull(); + assertThat(cancelClaimedtaskRepresentationModel.getState()).isEqualTo(TaskState.READY); } @Test @@ -757,27 +779,25 @@ class TaskControllerIntTest { final String user_id_of_claimed_task = "user_1_1"; // retrieve task from Rest Api - ResponseEntity responseGet = + ResponseEntity responseGet = template.exchange( restHelper.toUrl(Mapping.URL_TASKS_ID, claimed_task_id), HttpMethod.GET, new HttpEntity<>(restHelper.getHeadersUser_1_2()), - ParameterizedTypeReference.forType(TaskResource.class)); + ParameterizedTypeReference.forType(TaskRepresentationModel.class)); assertThat(responseGet.getBody()).isNotNull(); - TaskResource theTaskResource = responseGet.getBody(); - assertThat(theTaskResource.getState()).isEqualTo(TaskState.CLAIMED); - assertThat(theTaskResource.getOwner()).isEqualTo(user_id_of_claimed_task); + TaskRepresentationModel theTaskRepresentationModel = responseGet.getBody(); + assertThat(theTaskRepresentationModel.getState()).isEqualTo(TaskState.CLAIMED); + assertThat(theTaskRepresentationModel.getOwner()).isEqualTo(user_id_of_claimed_task); // try to cancel claim ThrowingCallable httpCall = - () -> { - template.exchange( - restHelper.toUrl(Mapping.URL_TASKS_ID_CLAIM, claimed_task_id), - HttpMethod.DELETE, - new HttpEntity<>(restHelper.getHeadersUser_1_2()), - ParameterizedTypeReference.forType(TaskResource.class)); - }; + () -> template.exchange( + restHelper.toUrl(Mapping.URL_TASKS_ID_CLAIM, claimed_task_id), + HttpMethod.DELETE, + new HttpEntity<>(restHelper.getHeadersUser_1_2()), + ParameterizedTypeReference.forType(TaskRepresentationModel.class)); assertThatThrownBy(httpCall) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) .isEqualTo(HttpStatus.CONFLICT); @@ -790,33 +810,33 @@ class TaskControllerIntTest { restHelper.toUrl("/api/v1/tasks/TKI:000000000000000000000000000000000025"); // retrieve task from Rest Api - ResponseEntity responseGet = + ResponseEntity responseGet = template.exchange( taskUrlString, HttpMethod.GET, new HttpEntity<>(restHelper.getHeadersUser_1_2()), - ParameterizedTypeReference.forType(TaskResource.class)); + ParameterizedTypeReference.forType(TaskRepresentationModel.class)); assertThat(responseGet.getBody()).isNotNull(); - TaskResource theTaskResource = responseGet.getBody(); - assertThat(theTaskResource.getState()).isEqualTo(TaskState.READY); - assertThat(theTaskResource.getOwner() == null); + TaskRepresentationModel theTaskRepresentationModel = responseGet.getBody(); + assertThat(theTaskRepresentationModel.getState()).isEqualTo(TaskState.READY); + assertThat(theTaskRepresentationModel.getOwner()).isNull(); // set Owner and update Task final String anyUserName = "dummyUser"; - theTaskResource.setOwner(anyUserName); - ResponseEntity responseUpdate = + theTaskRepresentationModel.setOwner(anyUserName); + ResponseEntity responseUpdate = template.exchange( taskUrlString, HttpMethod.PUT, - new HttpEntity<>(theTaskResource, restHelper.getHeadersUser_1_2()), - ParameterizedTypeReference.forType(TaskResource.class)); + new HttpEntity<>(theTaskRepresentationModel, restHelper.getHeadersUser_1_2()), + ParameterizedTypeReference.forType(TaskRepresentationModel.class)); assertThat(responseUpdate.getBody()).isNotNull(); - TaskResource theUpdatedTaskResource = responseUpdate.getBody(); - assertThat(theUpdatedTaskResource.getState()).isEqualTo(TaskState.READY); - assertThat(theUpdatedTaskResource.getOwner()).isEqualTo(anyUserName); + TaskRepresentationModel theUpdatedTaskRepresentationModel = responseUpdate.getBody(); + assertThat(theUpdatedTaskRepresentationModel.getState()).isEqualTo(TaskState.READY); + assertThat(theUpdatedTaskRepresentationModel.getOwner()).isEqualTo(anyUserName); } @Test @@ -826,41 +846,42 @@ class TaskControllerIntTest { restHelper.toUrl("/api/v1/tasks/TKI:000000000000000000000000000000000026"); // retrieve task from Rest Api - ResponseEntity responseGet = + ResponseEntity responseGet = template.exchange( taskUrlString, HttpMethod.GET, new HttpEntity<>(restHelper.getHeadersUser_1_2()), - ParameterizedTypeReference.forType(TaskResource.class)); + ParameterizedTypeReference.forType(TaskRepresentationModel.class)); assertThat(responseGet.getBody()).isNotNull(); - TaskResource theTaskResource = responseGet.getBody(); - assertThat(theTaskResource.getState()).isEqualTo(TaskState.CLAIMED); - assertThat(theTaskResource.getOwner()).isEqualTo("user_1_1"); + TaskRepresentationModel theTaskRepresentationModel = responseGet.getBody(); + assertThat(theTaskRepresentationModel.getState()).isEqualTo(TaskState.CLAIMED); + assertThat(theTaskRepresentationModel.getOwner()).isEqualTo("user_1_1"); // set Owner and update Task final String anyUserName = "dummyuser"; - theTaskResource.setOwner(anyUserName); + theTaskRepresentationModel.setOwner(anyUserName); ThrowingCallable httpCall = - () -> { - template.exchange( - taskUrlString, - HttpMethod.PUT, - new HttpEntity<>(theTaskResource, restHelper.getHeadersUser_1_2()), - ParameterizedTypeReference.forType(TaskResource.class)); - }; + () -> template.exchange( + taskUrlString, + HttpMethod.PUT, + new HttpEntity<>(theTaskRepresentationModel, restHelper.getHeadersUser_1_2()), + ParameterizedTypeReference.forType(TaskRepresentationModel.class)); assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .hasMessageContaining("409"); } - private TaskResource getTaskResourceSample() { - ClassificationSummaryResource classificationResource = new ClassificationSummaryResource(); + private TaskRepresentationModel getTaskResourceSample() { + ClassificationSummaryRepresentationModel classificationResource = + new ClassificationSummaryRepresentationModel(); classificationResource.setKey("L11010"); - WorkbasketSummaryResource workbasketSummaryResource = new WorkbasketSummaryResource(); - workbasketSummaryResource.setWorkbasketId("WBI:100000000000000000000000000000000004"); + WorkbasketSummaryRepresentationModel workbasketSummary = + new WorkbasketSummaryRepresentationModel(); + workbasketSummary.setWorkbasketId( + "WBI:100000000000000000000000000000000004"); ObjectReference objectReference = new ObjectReference(); objectReference.setCompany("MyCompany1"); @@ -869,10 +890,11 @@ class TaskControllerIntTest { objectReference.setType("MyType1"); objectReference.setValue("00000001"); - TaskResource taskResource = new TaskResource(); - taskResource.setClassificationSummaryResource(classificationResource); - taskResource.setWorkbasketSummaryResource(workbasketSummaryResource); - taskResource.setPrimaryObjRef(objectReference); - return taskResource; + TaskRepresentationModel taskRepresentationModel = new TaskRepresentationModel(); + taskRepresentationModel.setClassificationSummary(classificationResource); + taskRepresentationModel.setWorkbasketSummary( + workbasketSummary); + taskRepresentationModel.setPrimaryObjRef(objectReference); + return taskRepresentationModel; } } diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/TaskanaEngineControllerIntTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/TaskanaEngineControllerIntTest.java index e123d9bba..9cba480f2 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/TaskanaEngineControllerIntTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/TaskanaEngineControllerIntTest.java @@ -14,7 +14,7 @@ import org.springframework.web.client.RestTemplate; import pro.taskana.RestHelper; import pro.taskana.TaskanaSpringBootTest; import pro.taskana.common.api.TaskanaRole; -import pro.taskana.rest.resource.TaskanaUserInfoResource; +import pro.taskana.rest.resource.TaskanaUserInfoRepresentationModel; /** Test TaskanaEngineController. */ @TaskanaSpringBootTest @@ -63,12 +63,12 @@ class TaskanaEngineControllerIntTest { @Test void testGetCurrentUserInfo() { - ResponseEntity response = + ResponseEntity response = template.exchange( restHelper.toUrl(Mapping.URL_CURRENT_USER), HttpMethod.GET, restHelper.defaultRequest(), - ParameterizedTypeReference.forType(TaskanaUserInfoResource.class)); + ParameterizedTypeReference.forType(TaskanaUserInfoRepresentationModel.class)); assertThat(response.getBody().getUserId()).isEqualTo("teamlead_1"); assertThat(response.getBody().getGroupIds()).contains("businessadmin"); assertThat(response.getBody().getRoles()).contains(TaskanaRole.BUSINESS_ADMIN); diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/WorkbasketAccessItemControllerIntTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/WorkbasketAccessItemControllerIntTest.java index ccdf69dc6..7ac5c1b65 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/WorkbasketAccessItemControllerIntTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/WorkbasketAccessItemControllerIntTest.java @@ -19,13 +19,19 @@ import org.springframework.web.client.RestTemplate; import pro.taskana.RestHelper; import pro.taskana.TaskanaSpringBootTest; -import pro.taskana.rest.resource.WorkbasketAccessItemListResource; +import pro.taskana.rest.resource.TaskanaPagedModel; +import pro.taskana.rest.resource.WorkbasketAccessItemRepresentationModel; /** Test WorkbasketAccessItemController. */ @TestMethodOrder(MethodOrderer.Alphanumeric.class) @TaskanaSpringBootTest class WorkbasketAccessItemControllerIntTest { + private static final ParameterizedTypeReference< + TaskanaPagedModel> + WORKBASKET_ACCESS_ITEM_PAGE_MODEL_TYPE = + new ParameterizedTypeReference< + TaskanaPagedModel>() {}; private static RestTemplate template; @Autowired RestHelper restHelper; @@ -36,24 +42,26 @@ class WorkbasketAccessItemControllerIntTest { @Test void testGetAllWorkbasketAccessItems() { - ResponseEntity response = + ResponseEntity> response = template.exchange( restHelper.toUrl(Mapping.URL_WORKBASKETACCESSITEMS), HttpMethod.GET, restHelper.defaultRequest(), - ParameterizedTypeReference.forType(WorkbasketAccessItemListResource.class)); + WORKBASKET_ACCESS_ITEM_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); } @Test void testGetWorkbasketAccessItemsKeepingFilters() { - String parameters = "?sort-by=workbasket-key&order=asc&page=1&page-size=9&access-ids=user_1_1"; - ResponseEntity response = + String parameters = "?sort-by=workbasket-key&order=asc&page-size=9&access-ids=user_1_1&page=1"; + ResponseEntity> response = template.exchange( restHelper.toUrl(Mapping.URL_WORKBASKETACCESSITEMS) + parameters, HttpMethod.GET, restHelper.defaultRequest(), - ParameterizedTypeReference.forType(WorkbasketAccessItemListResource.class)); + WORKBASKET_ACCESS_ITEM_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); assertThat( response @@ -67,14 +75,12 @@ class WorkbasketAccessItemControllerIntTest { @Test void testThrowsExceptionIfInvalidFilterIsUsed() { ThrowingCallable httpCall = - () -> { - template.exchange( - restHelper.toUrl(Mapping.URL_WORKBASKETACCESSITEMS) - + "?sort-by=workbasket-key&order=asc&page=1&page-size=9&invalid=user_1_1", - HttpMethod.GET, - restHelper.defaultRequest(), - ParameterizedTypeReference.forType(WorkbasketAccessItemListResource.class)); - }; + () -> template.exchange( + restHelper.toUrl(Mapping.URL_WORKBASKETACCESSITEMS) + + "?sort-by=workbasket-key&order=asc&page=1&page-size=9&invalid=user_1_1", + HttpMethod.GET, + restHelper.defaultRequest(), + WORKBASKET_ACCESS_ITEM_PAGE_MODEL_TYPE); assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .hasMessageContaining("[invalid]") @@ -84,13 +90,14 @@ class WorkbasketAccessItemControllerIntTest { @Test void testGetSecondPageSortedByWorkbasketKey() { - String parameters = "?sort-by=workbasket-key&order=asc&page=2&page-size=9&access-ids=user_1_1"; - ResponseEntity response = + String parameters = "?sort-by=workbasket-key&order=asc&page-size=9&access-ids=user_1_1&page=1"; + ResponseEntity> response = template.exchange( restHelper.toUrl(Mapping.URL_WORKBASKETACCESSITEMS) + parameters, HttpMethod.GET, restHelper.defaultRequest(), - ParameterizedTypeReference.forType(WorkbasketAccessItemListResource.class)); + WORKBASKET_ACCESS_ITEM_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); assertThat(response.getBody().getContent()).hasSize(1); assertThat(response.getBody().getContent().iterator().next().getAccessId()) .isEqualTo("user_1_1"); @@ -128,13 +135,11 @@ class WorkbasketAccessItemControllerIntTest { void testGetBadRequestIfTryingToDeleteAccessItemsForGroup() { String parameters = "?access-id=cn=DevelopersGroup,ou=groups,o=TaskanaTest"; ThrowingCallable httpCall = - () -> { - template.exchange( - restHelper.toUrl(Mapping.URL_WORKBASKETACCESSITEMS) + parameters, - HttpMethod.DELETE, - restHelper.defaultRequest(), - ParameterizedTypeReference.forType(Void.class)); - }; + () -> template.exchange( + restHelper.toUrl(Mapping.URL_WORKBASKETACCESSITEMS) + parameters, + HttpMethod.DELETE, + restHelper.defaultRequest(), + ParameterizedTypeReference.forType(Void.class)); assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/WorkbasketControllerIntTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/WorkbasketControllerIntTest.java index d0edaa73f..0c4fb5c18 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/WorkbasketControllerIntTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/WorkbasketControllerIntTest.java @@ -21,17 +21,26 @@ import org.springframework.web.client.RestTemplate; import pro.taskana.RestHelper; import pro.taskana.TaskanaSpringBootTest; -import pro.taskana.rest.resource.DistributionTargetListResource; -import pro.taskana.rest.resource.DistributionTargetResource; -import pro.taskana.rest.resource.WorkbasketAccessItemListResource; -import pro.taskana.rest.resource.WorkbasketResource; -import pro.taskana.rest.resource.WorkbasketSummaryListResource; +import pro.taskana.rest.resource.TaskanaPagedModel; +import pro.taskana.rest.resource.WorkbasketAccessItemRepresentationModel; +import pro.taskana.rest.resource.WorkbasketRepresentationModel; +import pro.taskana.rest.resource.WorkbasketSummaryRepresentationModel; import pro.taskana.workbasket.api.WorkbasketType; /** Test WorkbasketController. */ @TaskanaSpringBootTest class WorkbasketControllerIntTest { + private static final ParameterizedTypeReference< + TaskanaPagedModel> + WORKBASKET_ACCESS_ITEM_PAGE_MODEL_TYPE = + new ParameterizedTypeReference< + TaskanaPagedModel>() {}; + private static final ParameterizedTypeReference< + TaskanaPagedModel> + WORKBASKET_SUMMARY_PAGE_MODEL_TYPE = + new ParameterizedTypeReference< + TaskanaPagedModel>() {}; private static RestTemplate template; @Autowired RestHelper restHelper; @@ -42,12 +51,12 @@ class WorkbasketControllerIntTest { @Test void testGetWorkbasket() { - ResponseEntity response = + ResponseEntity response = template.exchange( restHelper.toUrl(Mapping.URL_WORKBASKET_ID, "WBI:100000000000000000000000000000000006"), HttpMethod.GET, restHelper.defaultRequest(), - ParameterizedTypeReference.forType(WorkbasketResource.class)); + ParameterizedTypeReference.forType(WorkbasketRepresentationModel.class)); assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); assertThat(response.getHeaders().getContentType().toString()) .isEqualTo(MediaTypes.HAL_JSON_VALUE); @@ -55,23 +64,23 @@ class WorkbasketControllerIntTest { @Test void testGetAllWorkbaskets() { - ResponseEntity response = + ResponseEntity> response = template.exchange( restHelper.toUrl(Mapping.URL_WORKBASKET), HttpMethod.GET, restHelper.defaultRequest(), - ParameterizedTypeReference.forType(WorkbasketSummaryListResource.class)); + WORKBASKET_SUMMARY_PAGE_MODEL_TYPE); assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); } @Test void testGetAllWorkbasketsBusinessAdminHasOpenPermission() { - ResponseEntity response = + ResponseEntity> response = template.exchange( restHelper.toUrl(Mapping.URL_WORKBASKET) + "?required-permission=OPEN", HttpMethod.GET, restHelper.defaultRequest(), - ParameterizedTypeReference.forType(WorkbasketSummaryListResource.class)); + WORKBASKET_SUMMARY_PAGE_MODEL_TYPE); assertThat(response.getBody().getRequiredLink(IanaLinkRelations.SELF)).isNotNull(); assertThat(response.getBody().getContent()).hasSize(3); } @@ -79,12 +88,12 @@ class WorkbasketControllerIntTest { @Test void testGetAllWorkbasketsKeepingFilters() { String parameters = "?type=PERSONAL&sort-by=key&order=desc"; - ResponseEntity response = + ResponseEntity> response = template.exchange( restHelper.toUrl(Mapping.URL_WORKBASKET) + parameters, HttpMethod.GET, restHelper.defaultRequest(), - ParameterizedTypeReference.forType(WorkbasketSummaryListResource.class)); + WORKBASKET_SUMMARY_PAGE_MODEL_TYPE); assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); assertThat( response @@ -98,13 +107,11 @@ class WorkbasketControllerIntTest { @Test void testThrowsExceptionIfInvalidFilterIsUsed() { ThrowingCallable httpCall = - () -> { - template.exchange( - restHelper.toUrl(Mapping.URL_WORKBASKET) + "?invalid=PERSONAL", - HttpMethod.GET, - restHelper.defaultRequest(), - ParameterizedTypeReference.forType(WorkbasketSummaryListResource.class)); - }; + () -> template.exchange( + restHelper.toUrl(Mapping.URL_WORKBASKET) + "?invalid=PERSONAL", + HttpMethod.GET, + restHelper.defaultRequest(), + WORKBASKET_SUMMARY_PAGE_MODEL_TYPE); assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .hasMessageContaining("[invalid]") @@ -119,21 +126,22 @@ class WorkbasketControllerIntTest { final ObjectMapper mapper = new ObjectMapper(); - ResponseEntity initialWorkbasketResourceRequestResponse = + ResponseEntity initialWorkbasketResourceRequestResponse = template.exchange( restHelper.toUrl(Mapping.URL_WORKBASKET_ID, workbasketId), HttpMethod.GET, new HttpEntity(restHelper.getHeaders()), - ParameterizedTypeReference.forType(WorkbasketResource.class)); + ParameterizedTypeReference.forType(WorkbasketRepresentationModel.class)); - WorkbasketResource workbasketResource = initialWorkbasketResourceRequestResponse.getBody(); + WorkbasketRepresentationModel workbasketRepresentationModel = + initialWorkbasketResourceRequestResponse.getBody(); - workbasketResource.setKey("GPK_KSC"); - workbasketResource.setDomain("DOMAIN_A"); - workbasketResource.setType(WorkbasketType.PERSONAL); - workbasketResource.setName("was auch immer"); - workbasketResource.setOwner("Joerg"); - workbasketResource.setModified(String.valueOf(Instant.now())); + workbasketRepresentationModel.setKey("GPK_KSC"); + workbasketRepresentationModel.setDomain("DOMAIN_A"); + workbasketRepresentationModel.setType(WorkbasketType.PERSONAL); + workbasketRepresentationModel.setName("was auch immer"); + workbasketRepresentationModel.setOwner("Joerg"); + workbasketRepresentationModel.setModified(String.valueOf(Instant.now())); ThrowingCallable httpCall = () -> { @@ -141,8 +149,9 @@ class WorkbasketControllerIntTest { restHelper.toUrl(Mapping.URL_WORKBASKET_ID, workbasketId), HttpMethod.PUT, new HttpEntity<>( - mapper.writeValueAsString(workbasketResource), restHelper.getHeaders()), - ParameterizedTypeReference.forType(WorkbasketResource.class)); + mapper.writeValueAsString(workbasketRepresentationModel), + restHelper.getHeaders()), + ParameterizedTypeReference.forType(WorkbasketRepresentationModel.class)); }; assertThatThrownBy(httpCall) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) @@ -160,7 +169,7 @@ class WorkbasketControllerIntTest { restHelper.toUrl(Mapping.URL_WORKBASKET_ID, workbasketId), HttpMethod.GET, new HttpEntity(restHelper.getHeaders()), - ParameterizedTypeReference.forType(WorkbasketResource.class)); + ParameterizedTypeReference.forType(WorkbasketRepresentationModel.class)); }; assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) @@ -171,13 +180,13 @@ class WorkbasketControllerIntTest { @Test void testGetSecondPageSortedByKey() { - String parameters = "?sort-by=key&order=desc&page=2&page-size=5"; - ResponseEntity response = + String parameters = "?sort-by=key&order=desc&page-size=5&page=2"; + ResponseEntity> response = template.exchange( restHelper.toUrl(Mapping.URL_WORKBASKET) + parameters, HttpMethod.GET, restHelper.defaultRequest(), - ParameterizedTypeReference.forType(WorkbasketSummaryListResource.class)); + WORKBASKET_SUMMARY_PAGE_MODEL_TYPE); assertThat(response.getBody().getContent()).hasSize(5); assertThat(response.getBody().getContent().iterator().next().getKey()).isEqualTo("USER_1_1"); assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); @@ -236,30 +245,30 @@ class WorkbasketControllerIntTest { Void.class); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT); - ResponseEntity response2 = + ResponseEntity> response2 = template.exchange( restHelper.toUrl( Mapping.URL_WORKBASKET_ID_DISTRIBUTION, "WBI:100000000000000000000000000000000002"), HttpMethod.GET, restHelper.defaultRequest(), - ParameterizedTypeReference.forType(DistributionTargetListResource.class)); + WORKBASKET_SUMMARY_PAGE_MODEL_TYPE); assertThat(response2.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat( response2.getBody().getContent().stream() - .map(DistributionTargetResource::getWorkbasketId) + .map(WorkbasketSummaryRepresentationModel::getWorkbasketId) .noneMatch("WBI:100000000000000000000000000000000007"::equals)) .isTrue(); } @Test void testGetWorkbasketAccessItems() { - ResponseEntity response = + ResponseEntity> response = template.exchange( restHelper.toUrl( Mapping.URL_WORKBASKET_ID_ACCESSITEMS, "WBI:100000000000000000000000000000000005"), HttpMethod.GET, restHelper.defaultRequest(), - ParameterizedTypeReference.forType(WorkbasketAccessItemListResource.class)); + WORKBASKET_ACCESS_ITEM_PAGE_MODEL_TYPE); assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); assertThat(response.getHeaders().getContentType().toString()) .isEqualTo(MediaTypes.HAL_JSON_VALUE); @@ -268,13 +277,13 @@ class WorkbasketControllerIntTest { @Test void testGetWorkbasketDistributionTargets() { - ResponseEntity response = + ResponseEntity> response = template.exchange( restHelper.toUrl( Mapping.URL_WORKBASKET_ID_DISTRIBUTION, "WBI:100000000000000000000000000000000001"), HttpMethod.GET, restHelper.defaultRequest(), - ParameterizedTypeReference.forType(DistributionTargetListResource.class)); + WORKBASKET_SUMMARY_PAGE_MODEL_TYPE); assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); assertThat(response.getHeaders().getContentType().toString()) .isEqualTo(MediaTypes.HAL_JSON_VALUE); diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/WorkbasketDefinitionControllerIntTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/WorkbasketDefinitionControllerIntTest.java index eb13c67ae..0797e5842 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/WorkbasketDefinitionControllerIntTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/WorkbasketDefinitionControllerIntTest.java @@ -38,7 +38,7 @@ import org.springframework.web.client.RestTemplate; import pro.taskana.RestHelper; import pro.taskana.TaskanaSpringBootTest; -import pro.taskana.rest.resource.WorkbasketDefinitionResource; +import pro.taskana.rest.resource.WorkbasketDefinitionRepresentationModel; import pro.taskana.sampledata.SampleDataGenerator; /** Integration tests for WorkbasketDefinitionController. */ @@ -69,16 +69,17 @@ class WorkbasketDefinitionControllerIntTest { @Test void testExportWorkbasketFromDomain() { - ResponseEntity> response = + ResponseEntity> response = executeExportRequestForDomain("DOMAIN_A"); assertThat(response.getBody()).isNotNull(); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(response.getBody().get(0)).isInstanceOf(WorkbasketDefinitionResource.class); + assertThat(response.getBody().get(0)) + .isInstanceOf(WorkbasketDefinitionRepresentationModel.class); boolean allAuthorizationsAreEmpty = true; boolean allDistributionTargetsAreEmpty = true; - for (WorkbasketDefinitionResource workbasketDefinition : response.getBody()) { + for (WorkbasketDefinitionRepresentationModel workbasketDefinition : response.getBody()) { if (allAuthorizationsAreEmpty && !workbasketDefinition.getAuthorizations().isEmpty()) { allAuthorizationsAreEmpty = false; } @@ -96,22 +97,24 @@ class WorkbasketDefinitionControllerIntTest { @Test void testExportWorkbasketsFromWrongDomain() { - ResponseEntity> response = + ResponseEntity> response = executeExportRequestForDomain("wrongDomain"); assertThat(response.getBody()).isEmpty(); } @Test void testImportEveryWorkbasketFromDomainA() throws IOException { - List wbList = executeExportRequestForDomain("DOMAIN_A").getBody(); - for (WorkbasketDefinitionResource w : wbList) { + List wbList = + executeExportRequestForDomain("DOMAIN_A").getBody(); + for (WorkbasketDefinitionRepresentationModel w : wbList) { expectStatusWhenExecutingImportRequestOfWorkbaskets(HttpStatus.NO_CONTENT, w); } } @Test void testImportWorkbasketWithoutDistributionTargets() throws IOException { - WorkbasketDefinitionResource w = executeExportRequestForDomain("DOMAIN_A").getBody().get(0); + WorkbasketDefinitionRepresentationModel w = + executeExportRequestForDomain("DOMAIN_A").getBody().get(0); w.setDistributionTargets(new HashSet<>()); this.expectStatusWhenExecutingImportRequestOfWorkbaskets(HttpStatus.NO_CONTENT, w); @@ -123,12 +126,13 @@ class WorkbasketDefinitionControllerIntTest { @Test void testImportWorkbasketWithDistributionTargetsInImportFile() throws IOException { - List wbList = executeExportRequestForDomain("DOMAIN_A").getBody(); + List wbList = + executeExportRequestForDomain("DOMAIN_A").getBody(); - WorkbasketDefinitionResource w = wbList.get(0); + WorkbasketDefinitionRepresentationModel w = wbList.get(0); w.setDistributionTargets(new HashSet<>()); String letMeBeYourDistributionTarget = w.getWorkbasket().getWorkbasketId(); - WorkbasketDefinitionResource w2 = wbList.get(1); + WorkbasketDefinitionRepresentationModel w2 = wbList.get(1); w2.setDistributionTargets(Collections.singleton(letMeBeYourDistributionTarget)); expectStatusWhenExecutingImportRequestOfWorkbaskets(HttpStatus.NO_CONTENT, w, w2); @@ -145,10 +149,11 @@ class WorkbasketDefinitionControllerIntTest { @Test void testImportWorkbasketWithDistributionTargetsInSystem() throws IOException { - List wbList = executeExportRequestForDomain("DOMAIN_A").getBody(); + List wbList = + executeExportRequestForDomain("DOMAIN_A").getBody(); wbList.removeIf(definition -> definition.getDistributionTargets().isEmpty()); - WorkbasketDefinitionResource w = wbList.get(0); + WorkbasketDefinitionRepresentationModel w = wbList.get(0); expectStatusWhenExecutingImportRequestOfWorkbaskets(HttpStatus.NO_CONTENT, w); changeWorkbasketIdOrKey(w, null, "new"); @@ -157,9 +162,10 @@ class WorkbasketDefinitionControllerIntTest { @Test void testImportWorkbasketWithDistributionTargetsNotInSystem() throws IOException { - List wbList = executeExportRequestForDomain("DOMAIN_A").getBody(); + List wbList = + executeExportRequestForDomain("DOMAIN_A").getBody(); - WorkbasketDefinitionResource w = wbList.get(0); + WorkbasketDefinitionRepresentationModel w = wbList.get(0); w.setDistributionTargets(Collections.singleton("invalidWorkbasketId")); try { expectStatusWhenExecutingImportRequestOfWorkbaskets(HttpStatus.BAD_REQUEST, w); @@ -179,7 +185,8 @@ class WorkbasketDefinitionControllerIntTest { @Test void testFailOnImportDuplicates() throws IOException { - WorkbasketDefinitionResource w = executeExportRequestForDomain("DOMAIN_A").getBody().get(0); + WorkbasketDefinitionRepresentationModel w = + executeExportRequestForDomain("DOMAIN_A").getBody().get(0); try { expectStatusWhenExecutingImportRequestOfWorkbaskets(HttpStatus.CONFLICT, w, w); fail("Expected http-Status 409"); @@ -190,14 +197,15 @@ class WorkbasketDefinitionControllerIntTest { @Test void testNoErrorWhenImportWithSameIdButDifferentKeyAndDomain() throws IOException { - List wbList = executeExportRequestForDomain("DOMAIN_A").getBody(); + List wbList = + executeExportRequestForDomain("DOMAIN_A").getBody(); - WorkbasketDefinitionResource w = wbList.get(0); - WorkbasketDefinitionResource differentLogicalId = wbList.get(1); + WorkbasketDefinitionRepresentationModel w = wbList.get(0); + WorkbasketDefinitionRepresentationModel differentLogicalId = wbList.get(1); this.changeWorkbasketIdOrKey(differentLogicalId, w.getWorkbasket().getWorkbasketId(), null); // breaks the logic but not the script- should we really allow this case? - WorkbasketDefinitionResource theDestroyer = wbList.get(2); + WorkbasketDefinitionRepresentationModel theDestroyer = wbList.get(2); theDestroyer.setDistributionTargets( Collections.singleton(differentLogicalId.getWorkbasket().getWorkbasketId())); @@ -207,7 +215,8 @@ class WorkbasketDefinitionControllerIntTest { @Test void testErrorWhenImportWithSameAccessIdAndWorkbasket() { - WorkbasketDefinitionResource w = executeExportRequestForDomain("DOMAIN_A").getBody().get(0); + WorkbasketDefinitionRepresentationModel w = + executeExportRequestForDomain("DOMAIN_A").getBody().get(0); String w1String = workbasketToString(w); w.getWorkbasket().setKey("new Key for this WB"); @@ -221,7 +230,7 @@ class WorkbasketDefinitionControllerIntTest { } private void changeWorkbasketIdOrKey( - WorkbasketDefinitionResource w, String newId, String newKey) { + WorkbasketDefinitionRepresentationModel w, String newId, String newKey) { if (newId != null && !newId.isEmpty()) { w.getWorkbasket().setWorkbasketId(newId); w.getAuthorizations().forEach(auth -> auth.setWorkbasketId(newId)); @@ -232,17 +241,18 @@ class WorkbasketDefinitionControllerIntTest { } } - private ResponseEntity> executeExportRequestForDomain( - String domain) { + private ResponseEntity> + executeExportRequestForDomain(String domain) { return template.exchange( restHelper.toUrl(Mapping.URL_WORKBASKETDEFIITIONS) + "?domain=" + domain, HttpMethod.GET, restHelper.defaultRequest(), - new ParameterizedTypeReference>() {}); + new ParameterizedTypeReference>() {}); } private void expectStatusWhenExecutingImportRequestOfWorkbaskets( - HttpStatus expectedStatus, WorkbasketDefinitionResource... workbaskets) throws IOException { + HttpStatus expectedStatus, WorkbasketDefinitionRepresentationModel... workbaskets) + throws IOException { List workbasketStrings = Arrays.stream(workbaskets).map(this::workbasketToString).collect(Collectors.toList()); expectStatusWhenExecutingImportRequestOfWorkbaskets(expectedStatus, workbasketStrings); @@ -268,9 +278,10 @@ class WorkbasketDefinitionControllerIntTest { assertThat(responseImport.getStatusCode()).isEqualTo(expectedStatus); } - private String workbasketToString(WorkbasketDefinitionResource workbasketDefinitionResource) { + private String workbasketToString( + WorkbasketDefinitionRepresentationModel workbasketDefinitionRepresentationModel) { try { - return objMapper.writeValueAsString(workbasketDefinitionResource); + return objMapper.writeValueAsString(workbasketDefinitionRepresentationModel); } catch (JsonProcessingException e) { return ""; } diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/ClassificationAssemblerTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/ClassificationAssemblerTest.java index cc064468b..671bdd1e2 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/ClassificationAssemblerTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/ClassificationAssemblerTest.java @@ -12,11 +12,11 @@ import pro.taskana.classification.api.models.Classification; import pro.taskana.classification.internal.models.ClassificationImpl; import pro.taskana.rest.Mapping; -/** Test for {@link ClassificationResourceAssembler}. */ +/** Test for {@link ClassificationRepresentationModelAssembler}. */ @TaskanaSpringBootTest class ClassificationAssemblerTest { - @Autowired ClassificationResourceAssembler classificationResourceAssembler; + @Autowired ClassificationRepresentationModelAssembler classificationRepresentationModelAssembler; @Autowired ClassificationService classificationService; @@ -46,11 +46,11 @@ class ClassificationAssemblerTest { classification.setCreated(Instant.parse("2010-01-01T12:00:00Z")); classification.setModified(Instant.parse("2011-11-11T11:00:00Z")); // when - ClassificationResource classificationResource = - classificationResourceAssembler.toModel(classification); + ClassificationRepresentationModel classificationRepresentationModel = + classificationRepresentationModelAssembler.toModel(classification); // then - testEquality(classification, classificationResource); - testLinks(classificationResource); + testEquality(classification, classificationRepresentationModel); + testLinks(classificationRepresentationModel); } @Test @@ -80,48 +80,68 @@ class ClassificationAssemblerTest { classification.setDescription("Test"); classification.setIsValidInDomain(true); - ClassificationResource classificationResource = new ClassificationResource(classification); + ClassificationRepresentationModel classificationRepresentationModel = + new ClassificationRepresentationModel(classification); // when classification = - (ClassificationImpl) classificationResourceAssembler.toModel(classificationResource); + (ClassificationImpl) + classificationRepresentationModelAssembler + .toEntityModel(classificationRepresentationModel); // then - testEquality(classification, classificationResource); + testEquality(classification, classificationRepresentationModel); } - private void testLinks(ClassificationResource resource) { + private void testLinks(ClassificationRepresentationModel resource) { assertThat(resource.getLinks()).hasSize(1); assertThat(Mapping.URL_CLASSIFICATIONS_ID.replaceAll("\\{.*}", resource.getClassificationId())) .isEqualTo(resource.getRequiredLink("self").getHref()); } private void testEquality( - Classification classification, ClassificationResource classificationResource) { + Classification classification, + ClassificationRepresentationModel classificationRepresentationModel) { assertThat(classification.getApplicationEntryPoint()) - .isEqualTo(classificationResource.getApplicationEntryPoint()); - assertThat(classification.getKey()).isEqualTo(classificationResource.getKey()); - assertThat(classification.getDomain()).isEqualTo(classificationResource.getDomain()); - assertThat(classification.getId()).isEqualTo(classificationResource.getClassificationId()); - assertThat(classification.getDescription()).isEqualTo(classificationResource.getDescription()); - assertThat(classification.getName()).isEqualTo(classificationResource.getName()); + .isEqualTo(classificationRepresentationModel.getApplicationEntryPoint()); + assertThat(classification.getKey()).isEqualTo(classificationRepresentationModel.getKey()); + assertThat(classification.getDomain()).isEqualTo(classificationRepresentationModel.getDomain()); + assertThat(classification.getId()) + .isEqualTo(classificationRepresentationModel.getClassificationId()); + assertThat(classification.getDescription()) + .isEqualTo(classificationRepresentationModel.getDescription()); + assertThat(classification.getName()).isEqualTo(classificationRepresentationModel.getName()); assertThat(classification.getServiceLevel()) - .isEqualTo(classificationResource.getServiceLevel()); - assertThat(classification.getCategory()).isEqualTo(classificationResource.getCategory()); - assertThat(classification.getCustom1()).isEqualTo(classificationResource.getCustom1()); - assertThat(classification.getCustom2()).isEqualTo(classificationResource.getCustom2()); - assertThat(classification.getCustom3()).isEqualTo(classificationResource.getCustom3()); - assertThat(classification.getCustom4()).isEqualTo(classificationResource.getCustom4()); - assertThat(classification.getCustom5()).isEqualTo(classificationResource.getCustom5()); - assertThat(classification.getCustom6()).isEqualTo(classificationResource.getCustom6()); - assertThat(classification.getCustom7()).isEqualTo(classificationResource.getCustom7()); - assertThat(classification.getCustom8()).isEqualTo(classificationResource.getCustom8()); - assertThat(classification.getParentId()).isEqualTo(classificationResource.getParentId()); - assertThat(classification.getParentKey()).isEqualTo(classificationResource.getParentKey()); - assertThat(classification.getType()).isEqualTo(classificationResource.getType()); - assertThat(classification.getPriority()).isEqualTo(classificationResource.getPriority()); + .isEqualTo(classificationRepresentationModel.getServiceLevel()); + assertThat(classification.getCategory()) + .isEqualTo(classificationRepresentationModel.getCategory()); + assertThat(classification.getCustom1()) + .isEqualTo(classificationRepresentationModel.getCustom1()); + assertThat(classification.getCustom2()) + .isEqualTo(classificationRepresentationModel.getCustom2()); + assertThat(classification.getCustom3()) + .isEqualTo(classificationRepresentationModel.getCustom3()); + assertThat(classification.getCustom4()) + .isEqualTo(classificationRepresentationModel.getCustom4()); + assertThat(classification.getCustom5()) + .isEqualTo(classificationRepresentationModel.getCustom5()); + assertThat(classification.getCustom6()) + .isEqualTo(classificationRepresentationModel.getCustom6()); + assertThat(classification.getCustom7()) + .isEqualTo(classificationRepresentationModel.getCustom7()); + assertThat(classification.getCustom8()) + .isEqualTo(classificationRepresentationModel.getCustom8()); + assertThat(classification.getParentId()) + .isEqualTo(classificationRepresentationModel.getParentId()); + assertThat(classification.getParentKey()) + .isEqualTo(classificationRepresentationModel.getParentKey()); + assertThat(classification.getType()).isEqualTo(classificationRepresentationModel.getType()); + assertThat(classification.getPriority()) + .isEqualTo(classificationRepresentationModel.getPriority()); assertThat(classification.getIsValidInDomain()) - .isEqualTo(classificationResource.getIsValidInDomain()); - assertThat(classification.getCreated()).isEqualTo(classificationResource.getCreated()); - assertThat(classification.getModified()).isEqualTo(classificationResource.getModified()); + .isEqualTo(classificationRepresentationModel.getIsValidInDomain()); + assertThat(classification.getCreated()) + .isEqualTo(classificationRepresentationModel.getCreated()); + assertThat(classification.getModified()) + .isEqualTo(classificationRepresentationModel.getModified()); } } diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/ClassificationSummaryAssemblerTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/ClassificationSummaryAssemblerTest.java index 6978ae4d6..8acc3dc28 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/ClassificationSummaryAssemblerTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/ClassificationSummaryAssemblerTest.java @@ -11,10 +11,13 @@ import pro.taskana.classification.api.ClassificationService; import pro.taskana.classification.api.models.ClassificationSummary; import pro.taskana.classification.internal.models.ClassificationImpl; -/** Test for {@link ClassificationSummaryResourceAssembler}. */ +/** Test for {@link ClassificationSummaryRepresentationModelAssembler}. */ @TaskanaSpringBootTest class ClassificationSummaryAssemblerTest { - @Autowired ClassificationSummaryResourceAssembler classificationSummaryResourceAssembler; + @Autowired + ClassificationSummaryRepresentationModelAssembler + classificationSummaryRepresentationModelAssembler; + @Autowired private ClassificationService classificationService; @Test @@ -43,8 +46,8 @@ class ClassificationSummaryAssemblerTest { classification.setModified(Instant.parse("2011-11-11T11:00:00Z")); ClassificationSummary classificationSummary = classification.asSummary(); // when - ClassificationSummaryResource resource = - classificationSummaryResourceAssembler.toModel(classification); + ClassificationSummaryRepresentationModel resource = + classificationSummaryRepresentationModelAssembler.toModel(classification); // then testEquality(classificationSummary, resource); } @@ -52,7 +55,8 @@ class ClassificationSummaryAssemblerTest { @Test void testResourceToModel() { // given - ClassificationSummaryResource resource = new ClassificationSummaryResource(); + ClassificationSummaryRepresentationModel resource = + new ClassificationSummaryRepresentationModel(); resource.setCategory("EFG"); resource.setClassificationId("2"); resource.setCustom1("custom1"); @@ -72,13 +76,14 @@ class ClassificationSummaryAssemblerTest { resource.setType("A"); // when ClassificationSummary classificationSummary = - classificationSummaryResourceAssembler.toModel(resource); + classificationSummaryRepresentationModelAssembler.toEntityModel(resource); // then testEquality(classificationSummary, resource); } private void testEquality( - ClassificationSummary classificationSummary, ClassificationSummaryResource resource) { + ClassificationSummary classificationSummary, + ClassificationSummaryRepresentationModel resource) { assertThat(resource.getKey()).isEqualTo(classificationSummary.getKey()); assertThat(resource.getDomain()).isEqualTo(classificationSummary.getDomain()); assertThat(resource.getClassificationId()).isEqualTo(classificationSummary.getId()); diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/ReportResourceTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/ReportRepresentationModelTest.java similarity index 83% rename from rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/ReportResourceTest.java rename to rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/ReportRepresentationModelTest.java index 86063c498..e25c1edb6 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/ReportResourceTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/ReportRepresentationModelTest.java @@ -23,11 +23,11 @@ import pro.taskana.monitor.api.reports.header.TimeIntervalColumnHeader; import pro.taskana.monitor.api.reports.item.DetailedMonitorQueryItem; import pro.taskana.monitor.api.reports.item.MonitorQueryItem; -/** Test for {@link ReportResourceAssembler}. */ +/** Test for {@link ReportRepresentationModelAssembler}. */ @TaskanaSpringBootTest -class ReportResourceTest { +class ReportRepresentationModelTest { - @Autowired private ReportResourceAssembler reportResourceAssembler; + @Autowired private ReportRepresentationModelAssembler reportRepresentationModelAssembler; private int daysDiff; private LocalDateTime now; @@ -48,12 +48,12 @@ class ReportResourceTest { // given WorkbasketReport report = new WorkbasketReport(headers); // when - ReportResource resource = - reportResourceAssembler.toReportResource(report, now.toInstant(ZoneOffset.UTC)); + ReportRepresentationModel resource = + reportRepresentationModelAssembler.toReportResource(report, now.toInstant(ZoneOffset.UTC)); // then // meta - ReportResource.MetaInformation meta = resource.getMeta(); + ReportRepresentationModel.MetaInformation meta = resource.getMeta(); assertEquals("WorkbasketReport", meta.getName()); assertEquals("2019-01-02T00:00:00Z", meta.getDate()); assertArrayEquals(new String[] {"WORKBASKET KEYS"}, meta.getRowDesc()); @@ -66,7 +66,7 @@ class ReportResourceTest { // sumRow assertEquals(1, resource.getSumRow().size()); - ReportResource.RowResource sumRow = resource.getSumRow().get(0); + ReportRepresentationModel.RowResource sumRow = resource.getSumRow().get(0); assertArrayEquals(new String[] {"Total"}, sumRow.getDesc()); assertTrue(sumRow.isDisplay()); assertEquals(0, sumRow.getDepth()); @@ -84,12 +84,12 @@ class ReportResourceTest { item.setKey("key"); report.addItem(item); // when - ReportResource resource = - reportResourceAssembler.toReportResource(report, now.toInstant(ZoneOffset.UTC)); + ReportRepresentationModel resource = + reportRepresentationModelAssembler.toReportResource(report, now.toInstant(ZoneOffset.UTC)); // then // meta - ReportResource.MetaInformation meta = resource.getMeta(); + ReportRepresentationModel.MetaInformation meta = resource.getMeta(); assertEquals("ClassificationReport", meta.getName()); assertEquals("2019-01-02T00:00:00Z", meta.getDate()); assertArrayEquals(new String[] {"CLASSIFICATION KEYS"}, meta.getRowDesc()); @@ -98,9 +98,9 @@ class ReportResourceTest { assertEquals("Total", meta.getTotalDesc()); // rows - List rows = resource.getRows(); + List rows = resource.getRows(); assertEquals(1, rows.size()); - ReportResource.RowResource row = rows.get(0); + ReportRepresentationModel.RowResource row = rows.get(0); assertArrayEquals(new String[] {"key"}, row.getDesc()); assertEquals(0, row.getDepth()); assertEquals(2, row.getTotal()); @@ -110,7 +110,7 @@ class ReportResourceTest { // sumRow assertEquals(1, resource.getSumRow().size()); - ReportResource.RowResource sumRow = resource.getSumRow().get(0); + ReportRepresentationModel.RowResource sumRow = resource.getSumRow().get(0); assertArrayEquals(new String[] {"Total"}, sumRow.getDesc()); assertTrue(sumRow.isDisplay()); assertEquals(0, sumRow.getDepth()); @@ -130,12 +130,12 @@ class ReportResourceTest { item.setKey("key2"); report.addItem(item); // when - ReportResource resource = - reportResourceAssembler.toReportResource(report, now.toInstant(ZoneOffset.UTC)); + ReportRepresentationModel resource = + reportRepresentationModelAssembler.toReportResource(report, now.toInstant(ZoneOffset.UTC)); // then // meta - ReportResource.MetaInformation meta = resource.getMeta(); + ReportRepresentationModel.MetaInformation meta = resource.getMeta(); assertEquals("ClassificationReport", meta.getName()); assertEquals("2019-01-02T00:00:00Z", meta.getDate()); assertArrayEquals(new String[] {"CLASSIFICATION KEYS"}, meta.getRowDesc()); @@ -144,10 +144,10 @@ class ReportResourceTest { assertEquals("Total", meta.getTotalDesc()); // rows - List rows = resource.getRows(); + List rows = resource.getRows(); assertEquals(2, rows.size()); - ReportResource.RowResource row = rows.get(0); + ReportRepresentationModel.RowResource row = rows.get(0); assertArrayEquals(new String[] {"key"}, row.getDesc()); assertEquals(0, row.getDepth()); assertTrue(row.isDisplay()); @@ -163,7 +163,7 @@ class ReportResourceTest { // sumRow assertEquals(1, resource.getSumRow().size()); - ReportResource.RowResource sumRow = resource.getSumRow().get(0); + ReportRepresentationModel.RowResource sumRow = resource.getSumRow().get(0); assertArrayEquals(new String[] {"Total"}, sumRow.getDesc()); assertEquals(0, sumRow.getDepth()); assertTrue(sumRow.isDisplay()); @@ -185,12 +185,12 @@ class ReportResourceTest { item.setAttachmentKey(null); report.addItem(item); // when - ReportResource resource = - reportResourceAssembler.toReportResource(report, now.toInstant(ZoneOffset.UTC)); + ReportRepresentationModel resource = + reportRepresentationModelAssembler.toReportResource(report, now.toInstant(ZoneOffset.UTC)); // then // meta - ReportResource.MetaInformation meta = resource.getMeta(); + ReportRepresentationModel.MetaInformation meta = resource.getMeta(); assertEquals("DetailedClassificationReport", meta.getName()); assertEquals("2019-01-02T00:00:00Z", meta.getDate()); assertArrayEquals(new String[] {"TASK CLASSIFICATION KEYS", "ATTACHMENT"}, meta.getRowDesc()); @@ -199,10 +199,10 @@ class ReportResourceTest { assertEquals("Total", meta.getTotalDesc()); // rows - List rows = resource.getRows(); + List rows = resource.getRows(); assertEquals(1 + 2, rows.size()); - ReportResource.RowResource row = rows.get(0); + ReportRepresentationModel.RowResource row = rows.get(0); assertArrayEquals(new String[] {"key", null}, row.getDesc()); assertEquals(0, row.getDepth()); assertTrue(row.isDisplay()); @@ -224,7 +224,7 @@ class ReportResourceTest { assertArrayEquals(new int[] {0, 0, 0, 0, 2}, row.getCells()); // sumRow - List sumRow = resource.getSumRow(); + List sumRow = resource.getSumRow(); assertEquals(1 + 2, sumRow.size()); row = sumRow.get(0); @@ -265,12 +265,12 @@ class ReportResourceTest { item.setKey("key2"); report.addItem(item); // when - ReportResource resource = - reportResourceAssembler.toReportResource(report, now.toInstant(ZoneOffset.UTC)); + ReportRepresentationModel resource = + reportRepresentationModelAssembler.toReportResource(report, now.toInstant(ZoneOffset.UTC)); // then // meta - ReportResource.MetaInformation meta = resource.getMeta(); + ReportRepresentationModel.MetaInformation meta = resource.getMeta(); assertEquals("DetailedClassificationReport", meta.getName()); assertEquals("2019-01-02T00:00:00Z", meta.getDate()); assertArrayEquals(new String[] {"TASK CLASSIFICATION KEYS", "ATTACHMENT"}, meta.getRowDesc()); @@ -279,10 +279,10 @@ class ReportResourceTest { assertEquals("Total", meta.getTotalDesc()); // rows - List rows = resource.getRows(); + List rows = resource.getRows(); assertEquals((1 + 2) + (1 + 1), rows.size()); - ReportResource.RowResource row = rows.get(0); + ReportRepresentationModel.RowResource row = rows.get(0); assertArrayEquals(new String[] {"key", null}, row.getDesc()); assertEquals(0, row.getDepth()); assertTrue(row.isDisplay()); @@ -319,7 +319,7 @@ class ReportResourceTest { // sumRow - List sumRow = resource.getSumRow(); + List sumRow = resource.getSumRow(); assertEquals(1 + 2, sumRow.size()); row = sumRow.get(0); diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/TaskCommentRepresentationModelAssemblerTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/TaskCommentRepresentationModelAssemblerTest.java new file mode 100644 index 000000000..0fd885588 --- /dev/null +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/TaskCommentRepresentationModelAssemblerTest.java @@ -0,0 +1,73 @@ +package pro.taskana.rest.resource; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.time.Instant; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import pro.taskana.TaskanaSpringBootTest; +import pro.taskana.task.api.TaskService; +import pro.taskana.task.api.models.TaskComment; +import pro.taskana.task.internal.models.TaskCommentImpl; + +/** Test for {@link TaskCommentRepresentationModelAssembler}. */ +@TaskanaSpringBootTest +public class TaskCommentRepresentationModelAssemblerTest { + + private final TaskCommentRepresentationModelAssembler taskCommentRepresentationModelAssembler; + private final TaskService taskService; + + @Autowired + TaskCommentRepresentationModelAssemblerTest( + TaskCommentRepresentationModelAssembler taskCommentRepresentationModelAssembler, + TaskService taskService) { + this.taskCommentRepresentationModelAssembler = taskCommentRepresentationModelAssembler; + this.taskService = taskService; + } + + @Test + void taskCommentModelToResource() { + + TaskCommentImpl taskComment = + (TaskCommentImpl) taskService.newTaskComment("TKI:000000000000000000000000000000000000"); + + taskComment.setCreator("user_1_1"); + taskComment.setTextField("this is a task comment"); + taskComment.setCreated(Instant.parse("2010-01-01T12:00:00Z")); + taskComment.setModified(Instant.parse("2011-11-11T11:00:00Z")); + + TaskCommentRepresentationModel taskCommentRepresentationModel = + taskCommentRepresentationModelAssembler.toModel(taskComment); + + testEquality(taskComment, taskCommentRepresentationModel); + } + + @Test + void taskCommentResourceToModel() { + + TaskCommentRepresentationModel taskCommentRepresentationModel = + new TaskCommentRepresentationModel(); + 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"); + + TaskComment taskComment = + taskCommentRepresentationModelAssembler.toEntityModel(taskCommentRepresentationModel); + + testEquality(taskComment, taskCommentRepresentationModel); + } + + private void testEquality( + TaskComment taskComment, TaskCommentRepresentationModel taskCommentRepresentationModel) { + + assertThat(taskComment.getTaskId()).isEqualTo(taskCommentRepresentationModel.getTaskId()); + assertThat(taskComment.getId()).isEqualTo(taskCommentRepresentationModel.getTaskCommentId()); + assertThat(taskComment.getCreator()).isEqualTo(taskCommentRepresentationModel.getCreator()); + assertThat(taskComment.getTextField()).isEqualTo(taskCommentRepresentationModel.getTextField()); + assertThat(taskComment.getCreated()).isEqualTo(taskCommentRepresentationModel.getCreated()); + assertThat(taskComment.getModified()).isEqualTo(taskCommentRepresentationModel.getModified()); + } +} diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/TaskCommentResourceAssemblerTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/TaskCommentResourceAssemblerTest.java deleted file mode 100644 index dc4cf4937..000000000 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/TaskCommentResourceAssemblerTest.java +++ /dev/null @@ -1,68 +0,0 @@ -package pro.taskana.rest.resource; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.time.Instant; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; - -import pro.taskana.TaskanaSpringBootTest; -import pro.taskana.task.api.TaskService; -import pro.taskana.task.api.models.TaskComment; -import pro.taskana.task.internal.models.TaskCommentImpl; - -/** Test for {@link TaskCommentResourceAssembler}. */ -@TaskanaSpringBootTest -public class TaskCommentResourceAssemblerTest { - - private final TaskCommentResourceAssembler taskCommentResourceAssembler; - private final TaskService taskService; - - @Autowired - TaskCommentResourceAssemblerTest( - TaskCommentResourceAssembler taskCommentResourceAssembler, TaskService taskService) { - this.taskCommentResourceAssembler = taskCommentResourceAssembler; - this.taskService = taskService; - } - - @Test - void taskCommentModelToResource() { - - TaskCommentImpl taskComment = - (TaskCommentImpl) taskService.newTaskComment("TKI:000000000000000000000000000000000000"); - - taskComment.setCreator("user_1_1"); - taskComment.setTextField("this is a task comment"); - taskComment.setCreated(Instant.parse("2010-01-01T12:00:00Z")); - taskComment.setModified(Instant.parse("2011-11-11T11:00:00Z")); - - TaskCommentResource taskCommentResource = taskCommentResourceAssembler.toModel(taskComment); - - testEquality(taskComment, taskCommentResource); - } - - @Test - void taskCommentResourceToModel() { - - TaskCommentResource taskCommentResource = new TaskCommentResource(); - taskCommentResource.setTaskId("TKI:000000000000000000000000000000000000"); - taskCommentResource.setTaskCommentId("TCI:000000000000000000000000000000000000"); - taskCommentResource.setCreator("user_1_1"); - taskCommentResource.setCreated("2010-01-01T12:00:00Z"); - taskCommentResource.setModified("2011-11-11T11:00:00Z"); - - TaskComment taskComment = taskCommentResourceAssembler.toModel(taskCommentResource); - - testEquality(taskComment, taskCommentResource); - } - - private void testEquality(TaskComment taskComment, TaskCommentResource taskCommentResource) { - - assertThat(taskComment.getTaskId()).isEqualTo(taskCommentResource.getTaskId()); - assertThat(taskComment.getId()).isEqualTo(taskCommentResource.getTaskCommentId()); - assertThat(taskComment.getCreator()).isEqualTo(taskCommentResource.getCreator()); - assertThat(taskComment.getTextField()).isEqualTo(taskCommentResource.getTextField()); - assertThat(taskComment.getCreated()).isEqualTo(taskCommentResource.getCreated()); - assertThat(taskComment.getModified()).isEqualTo(taskCommentResource.getModified()); - } -} diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/TaskResourceAssemberTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/TaskRepresentationModelAssemberTest.java similarity index 79% rename from rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/TaskResourceAssemberTest.java rename to rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/TaskRepresentationModelAssemberTest.java index a143a2e96..45a720f54 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/TaskResourceAssemberTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/TaskRepresentationModelAssemberTest.java @@ -24,30 +24,44 @@ import pro.taskana.task.internal.models.TaskImpl; import pro.taskana.workbasket.api.WorkbasketService; import pro.taskana.workbasket.api.models.Workbasket; -/** Test for {@link TaskResourceAssembler}. */ +/** + * Test for {@link TaskRepresentationModelAssembler}. + */ @TaskanaSpringBootTest -class TaskResourceAssemberTest { +class TaskRepresentationModelAssemberTest { - @Autowired TaskService taskService; - @Autowired WorkbasketService workbasketService; - @Autowired ClassificationService classificationService; - @Autowired TaskResourceAssembler taskResourceAssembler; + TaskService taskService; + WorkbasketService workbasketService; + ClassificationService classificationService; + TaskRepresentationModelAssembler taskRepresentationModelAssembler; + + @Autowired + TaskRepresentationModelAssemberTest(TaskService taskService, WorkbasketService workbasketService, + ClassificationService classificationService, + TaskRepresentationModelAssembler taskRepresentationModelAssembler) { + this.taskService = taskService; + this.workbasketService = workbasketService; + this.classificationService = classificationService; + this.taskRepresentationModelAssembler = taskRepresentationModelAssembler; + } @Test void testSimpleResourceToModel() throws InvalidArgumentException { // given ObjectReference primaryObjRef = new ObjectReference(); primaryObjRef.setId("abc"); - WorkbasketSummaryResource workbasketResource = new WorkbasketSummaryResource(); + WorkbasketSummaryRepresentationModel workbasketResource = + new WorkbasketSummaryRepresentationModel(); workbasketResource.setWorkbasketId("workbasketId"); - ClassificationSummaryResource classificationResource = new ClassificationSummaryResource(); - classificationResource.setKey("keyabc"); - classificationResource.setDomain("DOMAIN_A"); - classificationResource.setType("MANUAL"); - AttachmentResource attachement = new AttachmentResource(); - attachement.setClassificationSummary(classificationResource); + ClassificationSummaryRepresentationModel classificationSummary = + new ClassificationSummaryRepresentationModel(); + classificationSummary.setKey("keyabc"); + classificationSummary.setDomain("DOMAIN_A"); + classificationSummary.setType("MANUAL"); + AttachmentRepresentationModel attachement = new AttachmentRepresentationModel(); + attachement.setClassificationSummary(classificationSummary); attachement.setAttachmentId("attachementId"); - TaskResource resource = new TaskResource(); + TaskRepresentationModel resource = new TaskRepresentationModel(); resource.setTaskId("taskId"); resource.setExternalId("externalId"); resource.setCreated("2019-09-13T08:44:17.588Z"); @@ -62,8 +76,8 @@ class TaskResourceAssemberTest { resource.setNote("note"); resource.setPriority(123); resource.setState(TaskState.READY); - resource.setClassificationSummaryResource(classificationResource); - resource.setWorkbasketSummaryResource(workbasketResource); + resource.setClassificationSummary(classificationSummary); + resource.setWorkbasketSummary(workbasketResource); resource.setBusinessProcessId("businessProcessId"); resource.setParentBusinessProcessId("parentBusinessProcessId"); resource.setOwner("owner"); @@ -71,9 +85,9 @@ class TaskResourceAssemberTest { resource.setRead(true); resource.setTransferred(true); resource.setCustomAttributes( - Collections.singletonList(new TaskResource.CustomAttribute("abc", "def"))); + Collections.singletonList(new TaskRepresentationModel.CustomAttribute("abc", "def"))); resource.setCallbackInfo( - Collections.singletonList(new TaskResource.CustomAttribute("ghi", "jkl"))); + Collections.singletonList(new TaskRepresentationModel.CustomAttribute("ghi", "jkl"))); resource.setAttachments(Collections.singletonList(attachement)); resource.setCustom1("custom1"); resource.setCustom2("custom2"); @@ -91,7 +105,7 @@ class TaskResourceAssemberTest { resource.setCustom14("custom14"); resource.setCustom15("custom15"); // when - Task task = taskResourceAssembler.toModel(resource); + Task task = taskRepresentationModelAssembler.toEntityModel(resource); // then testEquality(task, resource); } @@ -149,13 +163,13 @@ class TaskResourceAssemberTest { task.setCustom14("custom14"); task.setCustom15("custom15"); // when - TaskResource resource = taskResourceAssembler.toModel(task); + TaskRepresentationModel resource = taskRepresentationModelAssembler.toModel(task); // then testEquality(task, resource); testLinks(resource); } - void testEquality(Task task, TaskResource resource) throws InvalidArgumentException { + void testEquality(Task task, TaskRepresentationModel resource) throws InvalidArgumentException { assertThat(resource.getTaskId()).isEqualTo(task.getId()); assertThat(resource.getExternalId()).isEqualTo(task.getExternalId()); assertThat(resource.getCreated()) @@ -176,9 +190,9 @@ class TaskResourceAssemberTest { assertThat(resource.getNote()).isEqualTo(task.getNote()); assertThat(resource.getPriority()).isEqualTo(task.getPriority()); assertThat(resource.getState()).isEqualTo(task.getState()); - assertThat(resource.getClassificationSummaryResource().getClassificationId()) + assertThat(resource.getClassificationSummary().getClassificationId()) .isEqualTo(task.getClassificationSummary().getId()); - assertThat(resource.getWorkbasketSummaryResource().getWorkbasketId()) + assertThat(resource.getWorkbasketSummary().getWorkbasketId()) .isEqualTo(task.getWorkbasketSummary().getId()); assertThat(resource.getBusinessProcessId()).isEqualTo(task.getBusinessProcessId()); assertThat(resource.getParentBusinessProcessId()).isEqualTo(task.getParentBusinessProcessId()); @@ -208,7 +222,8 @@ class TaskResourceAssemberTest { } private void testEquality( - Map customAttributes, List resourceAttributes) { + Map customAttributes, + List resourceAttributes) { assertThat(resourceAttributes).hasSize(customAttributes.size()); resourceAttributes.forEach( attribute -> @@ -216,17 +231,17 @@ class TaskResourceAssemberTest { } private void testEqualityAttachements( - List attachments, List resources) { + List attachments, List resources) { String[] objects = attachments.stream().map(Attachment::getId).toArray(String[]::new); // Anything else should be be tested in AttachementResourceAssemblerTest assertThat(resources) .hasSize(attachments.size()) - .extracting(AttachmentResource::getAttachmentId) + .extracting(AttachmentRepresentationModel::getAttachmentId) .containsOnly(objects); } - private void testLinks(TaskResource resource) { + private void testLinks(TaskRepresentationModel resource) { assertThat(resource.getLinks()).hasSize(1); assertThat(resource.getRequiredLink("self").getHref()) .isEqualTo(Mapping.URL_TASKS_ID.replaceAll("\\{.*}", resource.getTaskId())); diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/TaskSummaryAssemblerTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/TaskSummaryAssemblerTest.java index 0540b6d8f..dc68c2f9e 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/TaskSummaryAssemblerTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/TaskSummaryAssemblerTest.java @@ -23,10 +23,20 @@ import pro.taskana.workbasket.api.models.Workbasket; @TaskanaSpringBootTest class TaskSummaryAssemblerTest { - @Autowired TaskService taskService; - @Autowired TaskSummaryResourceAssembler taskSummaryResourceAssembler; - @Autowired WorkbasketService workbasketService; - @Autowired ClassificationService classificationService; + TaskService taskService; + TaskSummaryRepresentationModelAssembler taskSummaryRepresentationModelAssembler; + WorkbasketService workbasketService; + ClassificationService classificationService; + + @Autowired + TaskSummaryAssemblerTest(TaskService taskService, + TaskSummaryRepresentationModelAssembler taskSummaryRepresentationModelAssembler, + WorkbasketService workbasketService, ClassificationService classificationService) { + this.taskService = taskService; + this.taskSummaryRepresentationModelAssembler = taskSummaryRepresentationModelAssembler; + this.workbasketService = workbasketService; + this.classificationService = classificationService; + } @Test void taskSummaryToResource() { @@ -80,11 +90,12 @@ class TaskSummaryAssemblerTest { task.setCustom14("custom14"); task.setCustom15("custom15"); TaskSummaryImpl taskSummary = (TaskSummaryImpl) task.asSummary(); - TaskSummaryResource resource = this.taskSummaryResourceAssembler.toModel(taskSummary); + TaskSummaryRepresentationModel resource = + this.taskSummaryRepresentationModelAssembler.toModel(taskSummary); this.testEquality(taskSummary, resource); } - void testEquality(TaskSummaryImpl taskSummary, TaskSummaryResource resource) { + void testEquality(TaskSummaryImpl taskSummary, TaskSummaryRepresentationModel resource) { Assert.assertEquals(taskSummary.getId(), resource.getTaskId()); Assert.assertEquals(taskSummary.getExternalId(), resource.getExternalId()); Assert.assertEquals( @@ -106,14 +117,14 @@ class TaskSummaryAssemblerTest { Assert.assertEquals(taskSummary.getName(), resource.getName()); Assert.assertEquals(taskSummary.getCreator(), resource.getCreator()); Assert.assertEquals(taskSummary.getNote(), resource.getNote()); - Assert.assertEquals((long) taskSummary.getPriority(), (long) resource.getPriority()); + Assert.assertEquals(taskSummary.getPriority(), resource.getPriority()); Assert.assertEquals(taskSummary.getState(), resource.getState()); Assert.assertEquals( taskSummary.getClassificationSummary().getId(), - resource.getClassificationSummaryResource().getClassificationId()); + resource.getClassificationSummary().getClassificationId()); Assert.assertEquals( taskSummary.getWorkbasketSummary().getId(), - resource.getWorkbasketSummaryResource().getWorkbasketId()); + resource.getWorkbasketSummary().getWorkbasketId()); Assert.assertEquals(taskSummary.getBusinessProcessId(), resource.getBusinessProcessId()); Assert.assertEquals( taskSummary.getParentBusinessProcessId(), resource.getParentBusinessProcessId()); @@ -143,11 +154,12 @@ class TaskSummaryAssemblerTest { } private void testEqualityAttachments( - List attachmentSummaries, List resources) { - Assert.assertEquals((long) attachmentSummaries.size(), (long) resources.size()); + List attachmentSummaries, + List resources) { + Assert.assertEquals(attachmentSummaries.size(), resources.size()); for (int i = 0; i < resources.size(); ++i) { - AttachmentSummaryResource resource = resources.get(i); + AttachmentSummaryRepresentationModel resource = resources.get(i); AttachmentSummary attachmentSummary = attachmentSummaries.get(i); Assert.assertEquals(attachmentSummary.getId(), resource.getAttachmentId()); } diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/WorkbasketAccessItemResourceAssemblerTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/WorkbasketAccessItemRepresentationModelAssemblerTest.java similarity index 85% rename from rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/WorkbasketAccessItemResourceAssemblerTest.java rename to rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/WorkbasketAccessItemRepresentationModelAssemblerTest.java index 42b85fa97..cf60e1620 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/WorkbasketAccessItemResourceAssemblerTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/WorkbasketAccessItemRepresentationModelAssemblerTest.java @@ -10,11 +10,12 @@ import pro.taskana.workbasket.api.WorkbasketService; import pro.taskana.workbasket.api.models.WorkbasketAccessItem; import pro.taskana.workbasket.internal.models.WorkbasketAccessItemImpl; -/** Test for {@link WorkbasketAccessItemResourceAssembler}. */ +/** Test for {@link WorkbasketAccessItemRepresentationModelAssembler}. */ @TaskanaSpringBootTest -class WorkbasketAccessItemResourceAssemblerTest { +class WorkbasketAccessItemRepresentationModelAssemblerTest { - @Autowired WorkbasketAccessItemResourceAssembler workbasketAccessItemResourceAssembler; + @Autowired + WorkbasketAccessItemRepresentationModelAssembler workbasketAccessItemRepresentationModelAssembler; @Autowired WorkbasketService workbasketService; @@ -41,8 +42,8 @@ class WorkbasketAccessItemResourceAssemblerTest { accessItem.setPermCustom11(true); accessItem.setPermCustom12(true); // when - WorkbasketAccessItemResource resource = - workbasketAccessItemResourceAssembler.toModel(accessItem); + WorkbasketAccessItemRepresentationModel resource = + workbasketAccessItemRepresentationModelAssembler.toModel(accessItem); // then testEquality(accessItem, resource); } @@ -50,7 +51,8 @@ class WorkbasketAccessItemResourceAssemblerTest { @Test void workBasketAccessItemToModelPropertiesEqual() { // given - WorkbasketAccessItemResource resource = new WorkbasketAccessItemResource(); + WorkbasketAccessItemRepresentationModel resource = + new WorkbasketAccessItemRepresentationModel(); resource.setAccessId("10"); resource.setWorkbasketKey("workbasketKey"); resource.setAccessItemId("120"); @@ -73,13 +75,14 @@ class WorkbasketAccessItemResourceAssemblerTest { resource.setPermCustom11(true); resource.setPermCustom12(false); // when - WorkbasketAccessItem accessItem = workbasketAccessItemResourceAssembler.toModel(resource); + WorkbasketAccessItem accessItem = + workbasketAccessItemRepresentationModelAssembler.toEntityModel(resource); // then testEquality(accessItem, resource); } private void testEquality( - WorkbasketAccessItem accessItem, WorkbasketAccessItemResource resource) { + WorkbasketAccessItem accessItem, WorkbasketAccessItemRepresentationModel resource) { assertThat(resource.getAccessId()).isEqualTo(accessItem.getAccessId()); assertThat(resource.getWorkbasketKey()).isEqualTo(accessItem.getWorkbasketKey()); assertThat(resource.getAccessItemId()).isEqualTo(accessItem.getId()); diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/WorkbasketRepresentationModelAssemblerTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/WorkbasketRepresentationModelAssemblerTest.java new file mode 100644 index 000000000..7eb1beddf --- /dev/null +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/WorkbasketRepresentationModelAssemblerTest.java @@ -0,0 +1,144 @@ +package pro.taskana.rest.resource; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.time.Instant; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import pro.taskana.TaskanaSpringBootTest; +import pro.taskana.rest.Mapping; +import pro.taskana.workbasket.api.WorkbasketService; +import pro.taskana.workbasket.api.WorkbasketType; +import pro.taskana.workbasket.api.models.Workbasket; +import pro.taskana.workbasket.internal.models.WorkbasketImpl; + +/** Test for {@link WorkbasketRepresentationModelAssembler}. */ +@TaskanaSpringBootTest +class WorkbasketRepresentationModelAssemblerTest { + + @Autowired WorkbasketService workbasketService; + @Autowired WorkbasketRepresentationModelAssembler workbasketRepresentationModelAssembler; + + @Test + void workbasketToResource() { + // given + Workbasket workbasket = workbasketService.newWorkbasket("1", "DOMAIN_A"); + ((WorkbasketImpl) workbasket).setId("ID"); + workbasket.setType(WorkbasketType.PERSONAL); + workbasket.setName("Testbasket"); + workbasket.setOrgLevel1("Org1"); + workbasket.setOrgLevel2("Org2"); + workbasket.setOrgLevel3("Org3"); + workbasket.setOrgLevel4("Org4"); + workbasket.setDescription("A test workbasket"); + workbasket.setCustom1("1"); + workbasket.setCustom2("2"); + workbasket.setCustom3("3"); + workbasket.setCustom4("4"); + workbasket.setOwner("Lars"); + ((WorkbasketImpl) workbasket).setCreated(Instant.parse("2010-01-01T12:00:00Z")); + ((WorkbasketImpl) workbasket).setModified(Instant.parse("2010-01-01T12:00:00Z")); + // when + WorkbasketRepresentationModel resource = + workbasketRepresentationModelAssembler.toModel(workbasket); + // then + testEquality(workbasket, resource); + verifyLinks(resource); + } + + @Test + void resourceWithoutCreated() { + // given + WorkbasketRepresentationModel resource = new WorkbasketRepresentationModel(); + resource.setWorkbasketId("1"); + resource.setModified("2010-01-01T12:00:00Z"); + resource.setType(WorkbasketType.PERSONAL); + // when + Workbasket workbasket = workbasketRepresentationModelAssembler.toEntityModel(resource); + // then + testEquality(workbasket, resource); + } + + @Test + void resourceWithoutModified() { + // given + WorkbasketRepresentationModel resource = new WorkbasketRepresentationModel(); + resource.setWorkbasketId("1"); + resource.setCreated("2010-01-01T12:00:00Z"); + resource.setType(WorkbasketType.PERSONAL); + // when + Workbasket workbasket = workbasketRepresentationModelAssembler.toEntityModel(resource); + // then + testEquality(workbasket, resource); + } + + @Test + void resourceToWorkbasket() { + // given + WorkbasketRepresentationModel workbasketRepresentationModel = + new WorkbasketRepresentationModel(); + workbasketRepresentationModel.setWorkbasketId("1"); + workbasketRepresentationModel.setCreated("2010-01-01T12:00:00Z"); + workbasketRepresentationModel.setModified("2010-01-01T12:00:00Z"); + workbasketRepresentationModel.setCustom1("Custom1"); + workbasketRepresentationModel.setCustom2("Custom2"); + workbasketRepresentationModel.setCustom3("Custom3"); + workbasketRepresentationModel.setCustom4("Custom4"); + workbasketRepresentationModel.setDescription("Test Ressource"); + workbasketRepresentationModel.setDomain("DOMAIN_A"); + workbasketRepresentationModel.setKey("1"); + workbasketRepresentationModel.setName("Ressource"); + workbasketRepresentationModel.setOrgLevel1("Org1"); + workbasketRepresentationModel.setOrgLevel2("Org2"); + workbasketRepresentationModel.setOrgLevel3("Org3"); + workbasketRepresentationModel.setOrgLevel4("Org4"); + workbasketRepresentationModel.setOwner("Lars"); + workbasketRepresentationModel.setType(WorkbasketType.PERSONAL); + // when + Workbasket workbasket = + workbasketRepresentationModelAssembler.toEntityModel(workbasketRepresentationModel); + // then + testEquality(workbasket, workbasketRepresentationModel); + } + + private void verifyLinks(WorkbasketRepresentationModel workbasket) { + assertThat(workbasket.getLinks()).hasSize(5); + assertThat(workbasket.getRequiredLink("self").getHref()) + .isEqualTo(Mapping.URL_WORKBASKET_ID.replaceAll("\\{.*}", workbasket.getWorkbasketId())); + assertThat(workbasket.getRequiredLink("distributionTargets").getHref()) + .isEqualTo( + Mapping.URL_WORKBASKET_ID_DISTRIBUTION.replaceAll( + "\\{.*}", workbasket.getWorkbasketId())); + assertThat(workbasket.getRequiredLink("allWorkbaskets").getHref()) + .isEqualTo(Mapping.URL_WORKBASKET); + assertThat(workbasket.getRequiredLink("removeDistributionTargets").getHref()) + .isEqualTo( + Mapping.URL_WORKBASKET_ID_DISTRIBUTION.replaceAll( + "\\{.*}", workbasket.getWorkbasketId())); + } + + private void testEquality( + Workbasket workbasket, WorkbasketRepresentationModel workbasketRepresentationModel) { + assertThat(workbasketRepresentationModel.getWorkbasketId()).isEqualTo(workbasket.getId()); + assertThat(workbasketRepresentationModel.getKey()).isEqualTo(workbasket.getKey()); + assertThat(workbasketRepresentationModel.getCreated()) + .isEqualTo(workbasket.getCreated() == null ? null : workbasket.getCreated().toString()); + assertThat(workbasketRepresentationModel.getModified()) + .isEqualTo(workbasket.getModified() == null ? null : workbasket.getModified().toString()); + assertThat(workbasketRepresentationModel.getName()).isEqualTo(workbasket.getName()); + assertThat(workbasketRepresentationModel.getDescription()) + .isEqualTo(workbasket.getDescription()); + assertThat(workbasketRepresentationModel.getOwner()).isEqualTo(workbasket.getOwner()); + assertThat(workbasketRepresentationModel.getDomain()).isEqualTo(workbasket.getDomain()); + assertThat(workbasketRepresentationModel.getType()).isEqualTo(workbasket.getType()); + assertThat(workbasketRepresentationModel.getCustom1()).isEqualTo(workbasket.getCustom1()); + assertThat(workbasketRepresentationModel.getCustom2()).isEqualTo(workbasket.getCustom2()); + assertThat(workbasketRepresentationModel.getCustom3()).isEqualTo(workbasket.getCustom3()); + assertThat(workbasketRepresentationModel.getCustom4()).isEqualTo(workbasket.getCustom4()); + assertThat(workbasketRepresentationModel.getOrgLevel1()).isEqualTo(workbasket.getOrgLevel1()); + assertThat(workbasketRepresentationModel.getOrgLevel2()).isEqualTo(workbasket.getOrgLevel2()); + assertThat(workbasketRepresentationModel.getOrgLevel3()).isEqualTo(workbasket.getOrgLevel3()); + assertThat(workbasketRepresentationModel.getOrgLevel4()).isEqualTo(workbasket.getOrgLevel4()); + } +} diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/WorkbasketResourceAssemblerTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/WorkbasketResourceAssemblerTest.java deleted file mode 100644 index a7d245d3d..000000000 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/WorkbasketResourceAssemblerTest.java +++ /dev/null @@ -1,139 +0,0 @@ -package pro.taskana.rest.resource; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.time.Instant; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; - -import pro.taskana.TaskanaSpringBootTest; -import pro.taskana.rest.Mapping; -import pro.taskana.workbasket.api.WorkbasketService; -import pro.taskana.workbasket.api.WorkbasketType; -import pro.taskana.workbasket.api.models.Workbasket; -import pro.taskana.workbasket.internal.models.WorkbasketImpl; - -/** Test for {@link WorkbasketResourceAssembler}. */ -@TaskanaSpringBootTest -class WorkbasketResourceAssemblerTest { - - @Autowired WorkbasketService workbasketService; - @Autowired WorkbasketResourceAssembler workbasketResourceAssembler; - - @Test - void workbasketToResource() { - // given - Workbasket workbasket = workbasketService.newWorkbasket("1", "DOMAIN_A"); - ((WorkbasketImpl) workbasket).setId("ID"); - workbasket.setType(WorkbasketType.PERSONAL); - workbasket.setName("Testbasket"); - workbasket.setOrgLevel1("Org1"); - workbasket.setOrgLevel2("Org2"); - workbasket.setOrgLevel3("Org3"); - workbasket.setOrgLevel4("Org4"); - workbasket.setDescription("A test workbasket"); - workbasket.setCustom1("1"); - workbasket.setCustom2("2"); - workbasket.setCustom3("3"); - workbasket.setCustom4("4"); - workbasket.setOwner("Lars"); - ((WorkbasketImpl) workbasket).setCreated(Instant.parse("2010-01-01T12:00:00Z")); - ((WorkbasketImpl) workbasket).setModified(Instant.parse("2010-01-01T12:00:00Z")); - // when - WorkbasketResource resource = workbasketResourceAssembler.toModel(workbasket); - // then - testEquality(workbasket, resource); - verifyLinks(resource); - } - - @Test - void resourceWithoutCreated() { - // given - WorkbasketResource resource = new WorkbasketResource(); - resource.setWorkbasketId("1"); - resource.setModified("2010-01-01T12:00:00Z"); - resource.setType(WorkbasketType.PERSONAL); - // when - Workbasket workbasket = workbasketResourceAssembler.toModel(resource); - // then - testEquality(workbasket, resource); - } - - @Test - void resourceWithoutModified() { - // given - WorkbasketResource resource = new WorkbasketResource(); - resource.setWorkbasketId("1"); - resource.setCreated("2010-01-01T12:00:00Z"); - resource.setType(WorkbasketType.PERSONAL); - // when - Workbasket workbasket = workbasketResourceAssembler.toModel(resource); - // then - testEquality(workbasket, resource); - } - - @Test - void resourceToWorkbasket() { - // given - WorkbasketResource workbasketResource = new WorkbasketResource(); - workbasketResource.setWorkbasketId("1"); - workbasketResource.setCreated("2010-01-01T12:00:00Z"); - workbasketResource.setModified("2010-01-01T12:00:00Z"); - workbasketResource.setCustom1("Custom1"); - workbasketResource.setCustom2("Custom2"); - workbasketResource.setCustom3("Custom3"); - workbasketResource.setCustom4("Custom4"); - workbasketResource.setDescription("Test Ressource"); - workbasketResource.setDomain("DOMAIN_A"); - workbasketResource.setKey("1"); - workbasketResource.setName("Ressource"); - workbasketResource.setOrgLevel1("Org1"); - workbasketResource.setOrgLevel2("Org2"); - workbasketResource.setOrgLevel3("Org3"); - workbasketResource.setOrgLevel4("Org4"); - workbasketResource.setOwner("Lars"); - workbasketResource.setType(WorkbasketType.PERSONAL); - // when - Workbasket workbasket = workbasketResourceAssembler.toModel(workbasketResource); - // then - testEquality(workbasket, workbasketResource); - } - - private void verifyLinks(WorkbasketResource workbasket) { - assertThat(workbasket.getLinks()).hasSize(5); - assertThat(workbasket.getRequiredLink("self").getHref()) - .isEqualTo(Mapping.URL_WORKBASKET_ID.replaceAll("\\{.*}", workbasket.getWorkbasketId())); - assertThat(workbasket.getRequiredLink("distributionTargets").getHref()) - .isEqualTo( - Mapping.URL_WORKBASKET_ID_DISTRIBUTION.replaceAll( - "\\{.*}", workbasket.getWorkbasketId())); - assertThat(workbasket.getRequiredLink("allWorkbaskets").getHref()) - .isEqualTo(Mapping.URL_WORKBASKET); - assertThat(workbasket.getRequiredLink("removeDistributionTargets").getHref()) - .isEqualTo( - Mapping.URL_WORKBASKET_ID_DISTRIBUTION.replaceAll( - "\\{.*}", workbasket.getWorkbasketId())); - } - - private void testEquality(Workbasket workbasket, WorkbasketResource workbasketResource) { - assertThat(workbasketResource.getWorkbasketId()).isEqualTo(workbasket.getId()); - assertThat(workbasketResource.getKey()).isEqualTo(workbasket.getKey()); - assertThat(workbasketResource.getCreated()) - .isEqualTo(workbasket.getCreated() == null ? null : workbasket.getCreated().toString()); - assertThat(workbasketResource.getModified()) - .isEqualTo(workbasket.getModified() == null ? null : workbasket.getModified().toString()); - assertThat(workbasketResource.getName()).isEqualTo(workbasket.getName()); - assertThat(workbasketResource.getDescription()).isEqualTo(workbasket.getDescription()); - assertThat(workbasketResource.getOwner()).isEqualTo(workbasket.getOwner()); - assertThat(workbasketResource.getDomain()).isEqualTo(workbasket.getDomain()); - assertThat(workbasketResource.getType()).isEqualTo(workbasket.getType()); - assertThat(workbasketResource.getCustom1()).isEqualTo(workbasket.getCustom1()); - assertThat(workbasketResource.getCustom2()).isEqualTo(workbasket.getCustom2()); - assertThat(workbasketResource.getCustom3()).isEqualTo(workbasket.getCustom3()); - assertThat(workbasketResource.getCustom4()).isEqualTo(workbasket.getCustom4()); - assertThat(workbasketResource.getOrgLevel1()).isEqualTo(workbasket.getOrgLevel1()); - assertThat(workbasketResource.getOrgLevel2()).isEqualTo(workbasket.getOrgLevel2()); - assertThat(workbasketResource.getOrgLevel3()).isEqualTo(workbasket.getOrgLevel3()); - assertThat(workbasketResource.getOrgLevel4()).isEqualTo(workbasket.getOrgLevel4()); - } -} diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/WorkbasketSummaryAssemblerTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/WorkbasketSummaryAssemblerTest.java index b7b8801c8..5c640e762 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/WorkbasketSummaryAssemblerTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/WorkbasketSummaryAssemblerTest.java @@ -9,12 +9,17 @@ import pro.taskana.workbasket.api.WorkbasketService; import pro.taskana.workbasket.api.WorkbasketType; import pro.taskana.workbasket.internal.models.WorkbasketSummaryImpl; -/** Test for {@link WorkbasketSummaryResourceAssembler}. */ +/** + * Test for {@link WorkbasketSummaryRepresentationModelAssembler}. + */ @TaskanaSpringBootTest class WorkbasketSummaryAssemblerTest { - @Autowired WorkbasketSummaryResourceAssembler workbasketSummaryAssembler; - @Autowired WorkbasketService workbasketService; + @Autowired + WorkbasketSummaryRepresentationModelAssembler + workbasketSummaryRepresentationModelAssembler; + @Autowired + WorkbasketService workbasketService; @Test void workbasketSummaryToResource() { @@ -35,24 +40,37 @@ class WorkbasketSummaryAssemblerTest { workbasketSummary.setOwner("Lars"); workbasketSummary.setType(WorkbasketType.PERSONAL); // when - WorkbasketSummaryResource workbasketSummaryResource = - workbasketSummaryAssembler.toModel(workbasketSummary); + WorkbasketSummaryRepresentationModel workbasketSummaryRepresentationModel = + workbasketSummaryRepresentationModelAssembler.toModel(workbasketSummary); // then Assert.assertEquals( - workbasketSummary.getDescription(), workbasketSummaryResource.getDescription()); - Assert.assertEquals(workbasketSummary.getDomain(), workbasketSummaryResource.getDomain()); - Assert.assertEquals(workbasketSummary.getId(), workbasketSummaryResource.getWorkbasketId()); - Assert.assertEquals(workbasketSummary.getKey(), workbasketSummaryResource.getKey()); - Assert.assertEquals(workbasketSummary.getName(), workbasketSummaryResource.getName()); - Assert.assertEquals(workbasketSummary.getCustom1(), workbasketSummaryResource.getCustom1()); - Assert.assertEquals(workbasketSummary.getCustom2(), workbasketSummaryResource.getCustom2()); - Assert.assertEquals(workbasketSummary.getCustom3(), workbasketSummaryResource.getCustom3()); - Assert.assertEquals(workbasketSummary.getCustom4(), workbasketSummaryResource.getCustom4()); - Assert.assertEquals(workbasketSummary.getOrgLevel1(), workbasketSummaryResource.getOrgLevel1()); - Assert.assertEquals(workbasketSummary.getOrgLevel2(), workbasketSummaryResource.getOrgLevel2()); - Assert.assertEquals(workbasketSummary.getOrgLevel3(), workbasketSummaryResource.getOrgLevel3()); - Assert.assertEquals(workbasketSummary.getOrgLevel4(), workbasketSummaryResource.getOrgLevel4()); - Assert.assertEquals(workbasketSummary.getOwner(), workbasketSummaryResource.getOwner()); - Assert.assertEquals(workbasketSummary.getType(), workbasketSummaryResource.getType()); + workbasketSummary.getDescription(), workbasketSummaryRepresentationModel.getDescription()); + Assert.assertEquals( + workbasketSummary.getDomain(), workbasketSummaryRepresentationModel.getDomain()); + Assert.assertEquals( + workbasketSummary.getId(), workbasketSummaryRepresentationModel.getWorkbasketId()); + Assert.assertEquals(workbasketSummary.getKey(), workbasketSummaryRepresentationModel.getKey()); + Assert.assertEquals( + workbasketSummary.getName(), workbasketSummaryRepresentationModel.getName()); + Assert.assertEquals( + workbasketSummary.getCustom1(), workbasketSummaryRepresentationModel.getCustom1()); + Assert.assertEquals( + workbasketSummary.getCustom2(), workbasketSummaryRepresentationModel.getCustom2()); + Assert.assertEquals( + workbasketSummary.getCustom3(), workbasketSummaryRepresentationModel.getCustom3()); + Assert.assertEquals( + workbasketSummary.getCustom4(), workbasketSummaryRepresentationModel.getCustom4()); + Assert.assertEquals( + workbasketSummary.getOrgLevel1(), workbasketSummaryRepresentationModel.getOrgLevel1()); + Assert.assertEquals( + workbasketSummary.getOrgLevel2(), workbasketSummaryRepresentationModel.getOrgLevel2()); + Assert.assertEquals( + workbasketSummary.getOrgLevel3(), workbasketSummaryRepresentationModel.getOrgLevel3()); + Assert.assertEquals( + workbasketSummary.getOrgLevel4(), workbasketSummaryRepresentationModel.getOrgLevel4()); + Assert.assertEquals( + workbasketSummary.getOwner(), workbasketSummaryRepresentationModel.getOwner()); + Assert.assertEquals( + workbasketSummary.getType(), workbasketSummaryRepresentationModel.getType()); } } diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/security/SampleLoginModule.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/security/SampleLoginModule.java index 65b53539a..1f2492269 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/security/SampleLoginModule.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/security/SampleLoginModule.java @@ -13,7 +13,7 @@ import org.springframework.security.web.authentication.UsernamePasswordAuthentic import pro.taskana.common.internal.security.GroupPrincipal; import pro.taskana.common.internal.security.UserPrincipal; import pro.taskana.ldap.LdapCacheTestImpl; -import pro.taskana.rest.resource.AccessIdResource; +import pro.taskana.rest.resource.AccessIdRepresentationModel; /** * This class will take care of Test API calls authentification. Also see {@link WebSecurityConfig} @@ -70,9 +70,10 @@ public class SampleLoginModule extends UsernamePasswordAuthenticationFilter impl private void addGroupSubjectsDerivedFromUsername() { LdapCacheTestImpl ldapCacheTest = new LdapCacheTestImpl(); String username = nameCallback.getName().toLowerCase(); - List groups = ldapCacheTest.findGroupsOfUser(username, Integer.MAX_VALUE); + List groups = + ldapCacheTest.findGroupsOfUser(username, Integer.MAX_VALUE); groups.forEach( - (AccessIdResource group) -> { + (AccessIdRepresentationModel group) -> { if (group.getAccessId().contains("ou=groups")) { subject.getPrincipals().add(new GroupPrincipal(group.getName())); } diff --git a/web/package-lock.json b/web/package-lock.json index 913b7e874..7459f0cdf 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -7017,6 +7017,11 @@ "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.3.tgz", "integrity": "sha512-a30VEBm4PEdx1dRB7MFK7BejejvCvBronbLjht+sHuGYj8PHs7M/5Z+rt5lw551vZ7yfTCj4Vuyy3mSJytDWRQ==" }, + "hammerjs": { + "version": "2.0.8", + "resolved": "https://registry.npmjs.org/hammerjs/-/hammerjs-2.0.8.tgz", + "integrity": "sha1-BO93hiz/K7edMPdpIJWTAiK/YPE=" + }, "handle-thing": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/handle-thing/-/handle-thing-2.0.1.tgz",