TSK-323: REST WB-Resources and key-filtering applied.

This commit is contained in:
Marcel Lengl 2018-02-21 12:39:46 +01:00 committed by Holger Hagen
parent cdb9f0b44e
commit ad2bbc4449
7 changed files with 233 additions and 23 deletions

View File

@ -24,7 +24,9 @@ import pro.taskana.TaskanaEngine;
import pro.taskana.WorkbasketService;
import pro.taskana.configuration.TaskanaEngineConfiguration;
import pro.taskana.rest.resource.mapper.ClassificationMapper;
import pro.taskana.rest.resource.mapper.WorkbasketAccessItemMapper;
import pro.taskana.rest.resource.mapper.WorkbasketDefinitionMapper;
import pro.taskana.rest.resource.mapper.WorkbasketMapper;
import pro.taskana.rest.resource.mapper.WorkbasketSummaryMapper;
import pro.taskana.sampledata.SampleDataGenerator;
@ -62,6 +64,16 @@ public class RestApplication {
return new WorkbasketSummaryMapper();
}
@Bean
public WorkbasketMapper getWorkbasketMapper() {
return new WorkbasketMapper();
}
@Bean
public WorkbasketAccessItemMapper getWorkbasketAccessItemMapper() {
return new WorkbasketAccessItemMapper();
}
@Bean
public WorkbasketDefinitionMapper getWorkbasketDefinitionMapper() {
return new WorkbasketDefinitionMapper();

View File

@ -28,7 +28,11 @@ import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.impl.WorkbasketAuthorization;
import pro.taskana.impl.WorkbasketType;
import pro.taskana.rest.resource.WorkbasketAccessItemResource;
import pro.taskana.rest.resource.WorkbasketResource;
import pro.taskana.rest.resource.WorkbasketSummaryResource;
import pro.taskana.rest.resource.mapper.WorkbasketAccessItemMapper;
import pro.taskana.rest.resource.mapper.WorkbasketMapper;
import pro.taskana.rest.resource.mapper.WorkbasketSummaryMapper;
@RestController
@ -49,12 +53,20 @@ public class WorkbasketController {
@Autowired
private WorkbasketSummaryMapper workbasketSummaryMapper;
@Autowired
private WorkbasketMapper workbasketMapper;
@Autowired
private WorkbasketAccessItemMapper workbasketAccessItemMapper;
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<List<WorkbasketSummaryResource>> getWorkbaskets(
@RequestParam(value = "sortBy", defaultValue = "name", required = false) String sortBy,
@RequestParam(value = "order", defaultValue = "asc", required = false) String order,
@RequestParam(value = "name", required = false) String name,
@RequestParam(value = "nameLike", required = false) String nameLike,
@RequestParam(value = "key", required = false) String key,
@RequestParam(value = "keyLike", required = false) String keyLike,
@RequestParam(value = "descLike", required = false) String descLike,
@RequestParam(value = "owner", required = false) String owner,
@RequestParam(value = "ownerLike", required = false) String ownerLike,
@ -65,7 +77,7 @@ public class WorkbasketController {
WorkbasketQuery query = workbasketService.createWorkbasketQuery();
try {
addSortingToQuery(query, sortBy, order);
addAttributeFilter(query, name, nameLike, descLike, owner, ownerLike, type);
addAttributeFilter(query, name, nameLike, key, keyLike, descLike, owner, ownerLike, type);
addAuthorizationFilter(query, requiredPermission);
workbasketsSummary = query.list();
} catch (InvalidArgumentException e) {
@ -79,11 +91,11 @@ public class WorkbasketController {
.collect(Collectors.toList()), HttpStatus.OK);
}
@RequestMapping(value = "/{workbasketid}")
public ResponseEntity<Workbasket> getWorkbasket(@PathVariable(value = "workbasketid") String workbasketId) {
@RequestMapping(value = "/{workbasketId}")
public ResponseEntity<WorkbasketResource> getWorkbasket(@PathVariable(value = "workbasketId") String workbasketId) {
try {
Workbasket workbasket = workbasketService.getWorkbasket(workbasketId);
return new ResponseEntity<>(workbasket, HttpStatus.OK);
return new ResponseEntity<>(workbasketMapper.toResource(workbasket), HttpStatus.OK);
} catch (WorkbasketNotFoundException e) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
} catch (NotAuthorizedException e) {
@ -92,22 +104,23 @@ public class WorkbasketController {
}
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<Workbasket> createWorkbasket(@RequestBody Workbasket workbasket) {
public ResponseEntity<WorkbasketResource> createWorkbasket(@RequestBody Workbasket workbasket) {
Workbasket createdWorkbasket;
try {
createdWorkbasket = workbasketService.createWorkbasket(workbasket);
return new ResponseEntity<>(createdWorkbasket, HttpStatus.CREATED);
return new ResponseEntity<>(workbasketMapper.toResource(createdWorkbasket), HttpStatus.CREATED);
} catch (InvalidWorkbasketException e) {
return new ResponseEntity<>(HttpStatus.CONFLICT);
}
}
@RequestMapping(value = "/{workbasketkey}", method = RequestMethod.PUT)
public ResponseEntity<Workbasket> updateWorkbasket(@PathVariable(value = "workbasketkey") String workbasketKey,
@RequestMapping(value = "/{workbasketKey}", method = RequestMethod.PUT)
public ResponseEntity<WorkbasketResource> updateWorkbasket(
@PathVariable(value = "workbasketKey") String workbasketKey,
@RequestBody Workbasket workbasket) {
try {
Workbasket updatedWorkbasket = workbasketService.updateWorkbasket(workbasket);
return new ResponseEntity<>(updatedWorkbasket, HttpStatus.OK);
return new ResponseEntity<>(workbasketMapper.toResource(updatedWorkbasket), HttpStatus.OK);
} catch (InvalidWorkbasketException e) {
return new ResponseEntity<>(HttpStatus.CONFLICT);
} catch (WorkbasketNotFoundException e) {
@ -117,30 +130,32 @@ public class WorkbasketController {
}
}
@RequestMapping(value = "/{workbasketkey}/authorizations", method = RequestMethod.GET)
public ResponseEntity<List<WorkbasketAccessItem>> getWorkbasketAuthorizations(
@PathVariable(value = "workbasketkey") String workbasketKey) {
@RequestMapping(value = "/{workbasketKey}/authorizations", method = RequestMethod.GET)
public ResponseEntity<List<WorkbasketAccessItemResource>> getWorkbasketAuthorizations(
@PathVariable(value = "workbasketKey") String workbasketKey) {
List<WorkbasketAccessItem> wbAuthorizations = workbasketService.getWorkbasketAuthorizations(workbasketKey);
return new ResponseEntity<>(wbAuthorizations, HttpStatus.OK);
return new ResponseEntity<>(wbAuthorizations.stream()
.map(accItem -> workbasketAccessItemMapper.toResource(accItem))
.collect(Collectors.toList()), HttpStatus.OK);
}
@RequestMapping(value = "/authorizations", method = RequestMethod.POST)
public ResponseEntity<WorkbasketAccessItem> createWorkbasketAuthorization(
public ResponseEntity<WorkbasketAccessItemResource> createWorkbasketAuthorization(
@RequestBody WorkbasketAccessItem workbasketAccessItem) {
workbasketAccessItem = workbasketService.createWorkbasketAuthorization(workbasketAccessItem);
return new ResponseEntity<>(workbasketAccessItem, HttpStatus.OK);
return new ResponseEntity<>(workbasketAccessItemMapper.toResource(workbasketAccessItem), HttpStatus.OK);
}
@RequestMapping(value = "/authorizations/{authid}", method = RequestMethod.PUT)
public ResponseEntity<WorkbasketAccessItem> updateWorkbasketAuthorization(
@PathVariable(value = "authid") String authId,
@RequestMapping(value = "/authorizations/{authId}", method = RequestMethod.PUT)
public ResponseEntity<WorkbasketAccessItemResource> updateWorkbasketAuthorization(
@PathVariable(value = "authId") String authId,
@RequestBody WorkbasketAccessItem workbasketAccessItem) throws InvalidArgumentException {
workbasketAccessItem = workbasketService.updateWorkbasketAuthorization(workbasketAccessItem);
return new ResponseEntity<>(workbasketAccessItem, HttpStatus.OK);
return new ResponseEntity<>(workbasketAccessItemMapper.toResource(workbasketAccessItem), HttpStatus.OK);
}
@RequestMapping(value = "/authorizations/{authid}", method = RequestMethod.DELETE)
public ResponseEntity<?> deleteWorkbasketAuthorization(@PathVariable(value = "authid") String authId) {
@RequestMapping(value = "/authorizations/{authId}", method = RequestMethod.DELETE)
public ResponseEntity<?> deleteWorkbasketAuthorization(@PathVariable(value = "authId") String authId) {
workbasketService.deleteWorkbasketAuthorization(authId);
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}
@ -257,12 +272,17 @@ public class WorkbasketController {
private void addAttributeFilter(WorkbasketQuery query,
String name, String nameLike,
String key, String keyLike,
String descLike, String owner,
String ownerLike, String type) throws InvalidArgumentException {
if (name != null)
query.nameIn(name);
if (nameLike != null)
query.nameLike(LIKE + nameLike + LIKE);
if (key != null)
query.keyIn(key);
if (keyLike != null)
query.keyLike(LIKE + keyLike + LIKE);
if (owner != null)
query.ownerIn(owner);
if (ownerLike != null)
@ -273,14 +293,17 @@ public class WorkbasketController {
switch (type) {
case "PERSONAL":
query.typeIn(WorkbasketType.PERSONAL);
break;
case "GROUP":
query.typeIn(WorkbasketType.GROUP);
break;
case "CLEARANCE":
query.typeIn(WorkbasketType.CLEARANCE);
break;
case "TOPIC":
query.typeIn(WorkbasketType.TOPIC);
break;
}
}
}
}

View File

@ -0,0 +1,62 @@
package pro.taskana.rest.resource;
import javax.validation.constraints.NotNull;
import org.springframework.hateoas.ResourceSupport;
public class WorkbasketAccessItemResource extends ResourceSupport {
public String id;
@NotNull
public String workbasketKey;
@NotNull
public String accessId;
public boolean permRead;
public boolean permOpen;
public boolean permAppend;
public boolean permTransfer;
public boolean permDistribute;
public boolean permCustom1;
public boolean permCustom2;
public boolean permCustom3;
public boolean permCustom4;
public boolean permCustom5;
public boolean permCustom6;
public boolean permCustom7;
public boolean permCustom8;
public boolean permCustom9;
public boolean permCustom10;
public boolean permCustom11;
public boolean permCustom12;
public WorkbasketAccessItemResource(String id, String workbasketKey, String accessId, boolean permRead,
boolean permOpen, boolean permAppend, boolean permTransfer, boolean permDistribute, boolean permCustom1,
boolean permCustom2, boolean permCustom3, boolean permCustom4, boolean permCustom5, boolean permCustom6,
boolean permCustom7, boolean permCustom8, boolean permCustom9, boolean permCustom10, boolean permCustom11,
boolean permCustom12) {
super();
this.id = id;
this.workbasketKey = workbasketKey;
this.accessId = accessId;
this.permRead = permRead;
this.permOpen = permOpen;
this.permAppend = permAppend;
this.permTransfer = permTransfer;
this.permDistribute = permDistribute;
this.permCustom1 = permCustom1;
this.permCustom2 = permCustom2;
this.permCustom3 = permCustom3;
this.permCustom4 = permCustom4;
this.permCustom5 = permCustom5;
this.permCustom6 = permCustom6;
this.permCustom7 = permCustom7;
this.permCustom8 = permCustom8;
this.permCustom9 = permCustom9;
this.permCustom10 = permCustom10;
this.permCustom11 = permCustom11;
this.permCustom12 = permCustom12;
}
}

View File

@ -0,0 +1,62 @@
package pro.taskana.rest.resource;
import java.time.Instant;
import javax.validation.constraints.NotNull;
import org.springframework.hateoas.ResourceSupport;
import pro.taskana.impl.WorkbasketType;
public class WorkbasketResource extends ResourceSupport {
public String id;
@NotNull
public String key;
@NotNull
public String name;
@NotNull
public String domain;
@NotNull
public WorkbasketType type;
public Instant created;
public Instant modified;
public String description;
public String owner;
public String custom1;
public String custom2;
public String custom3;
public String custom4;
public String orgLevel1;
public String orgLevel2;
public String orgLevel3;
public String orgLevel4;
public WorkbasketResource(String id, String key, String name, String domain, WorkbasketType type, Instant created,
Instant modified, String description, String owner, String custom1, String custom2, String custom3,
String custom4, String orgLevel1, String orgLevel2, String orgLevel3, String orgLevel4) {
super();
this.id = id;
this.key = key;
this.name = name;
this.domain = domain;
this.type = type;
this.created = created;
this.modified = modified;
this.description = description;
this.owner = owner;
this.custom1 = custom1;
this.custom2 = custom2;
this.custom3 = custom3;
this.custom4 = custom4;
this.orgLevel1 = orgLevel1;
this.orgLevel2 = orgLevel2;
this.orgLevel3 = orgLevel3;
this.orgLevel4 = orgLevel4;
}
}

View File

@ -44,5 +44,4 @@ public class WorkbasketSummaryResource extends ResourceSupport {
this.orgLevel3 = orgLevel3;
this.orgLevel4 = orgLevel4;
}
}

View File

@ -0,0 +1,29 @@
package pro.taskana.rest.resource.mapper;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
import pro.taskana.WorkbasketAccessItem;
import pro.taskana.rest.WorkbasketController;
import pro.taskana.rest.resource.WorkbasketAccessItemResource;
public class WorkbasketAccessItemMapper {
public WorkbasketAccessItemResource toResource(WorkbasketAccessItem wbAccItem) {
WorkbasketAccessItemResource resource = new WorkbasketAccessItemResource(wbAccItem.getId(),
wbAccItem.getWorkbasketKey(),
wbAccItem.getAccessId(), wbAccItem.isPermRead(), wbAccItem.isPermOpen(), wbAccItem.isPermAppend(),
wbAccItem.isPermTransfer(),
wbAccItem.isPermDistribute(), wbAccItem.isPermCustom1(), wbAccItem.isPermCustom2(),
wbAccItem.isPermCustom3(), wbAccItem.isPermCustom4(),
wbAccItem.isPermCustom5(), wbAccItem.isPermCustom6(), wbAccItem.isPermCustom7(), wbAccItem.isPermCustom8(),
wbAccItem.isPermCustom9(),
wbAccItem.isPermCustom10(), wbAccItem.isPermCustom11(), wbAccItem.isPermCustom12());
// Add self-decription link to hateoas
resource.add(
linkTo(methodOn(WorkbasketController.class).getWorkbasketAuthorizations(wbAccItem.getWorkbasketKey()))
.withSelfRel());
return resource;
}
}

View File

@ -0,0 +1,23 @@
package pro.taskana.rest.resource.mapper;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
import pro.taskana.Workbasket;
import pro.taskana.rest.WorkbasketController;
import pro.taskana.rest.resource.WorkbasketResource;
public class WorkbasketMapper {
public WorkbasketResource toResource(Workbasket wb) {
WorkbasketResource resource = new WorkbasketResource(wb.getId(), wb.getKey(), wb.getName(), wb.getDomain(),
wb.getType(), wb.getCreated(),
wb.getModified(), wb.getDescription(), wb.getOwner(), wb.getCustom1(), wb.getCustom2(), wb.getCustom3(),
wb.getCustom4(),
wb.getOrgLevel1(), wb.getOrgLevel2(), wb.getOrgLevel3(), wb.getOrgLevel4());
// Add self-decription link to hateoas
resource.add(linkTo(methodOn(WorkbasketController.class).getWorkbasket(wb.getId())).withSelfRel());
return resource;
}
}