TSK-227: REST - Workbasket ID for Controller instead of KEY.

This commit is contained in:
Marcel Lengl 2018-02-21 17:17:48 +01:00
parent c065590711
commit 36974006af
8 changed files with 94 additions and 49 deletions

View File

@ -613,7 +613,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
// delete workbasket and sub-tables // delete workbasket and sub-tables
distributionTargetMapper.deleteAllDistributionTargetsBySourceId(wb.getId()); distributionTargetMapper.deleteAllDistributionTargetsBySourceId(wb.getId());
distributionTargetMapper.deleteAllDistributionTargetsByTargetId(wb.getId()); distributionTargetMapper.deleteAllDistributionTargetsByTargetId(wb.getId());
workbasketAccessMapper.deleteAllForWorkbasketkey(wb.getKey()); workbasketAccessMapper.deleteAllForWorkbasketId(wb.getId());
workbasketMapper.delete(workbasketId); workbasketMapper.delete(workbasketId);
} finally { } finally {
taskanaEngine.returnConnection(); taskanaEngine.returnConnection();

View File

@ -43,33 +43,6 @@ public interface WorkbasketAccessMapper {
@Result(property = "permCustom12", column = "PERM_CUSTOM_12")}) @Result(property = "permCustom12", column = "PERM_CUSTOM_12")})
WorkbasketAccessItemImpl findById(@Param("id") String id); WorkbasketAccessItemImpl findById(@Param("id") String id);
// @Select("SELECT ID, WORKBASKET_ID, ACCESS_ID, PERM_READ, PERM_OPEN, PERM_APPEND, PERM_TRANSFER, PERM_DISTRIBUTE,
// PERM_CUSTOM_1, PERM_CUSTOM_2, PERM_CUSTOM_3, PERM_CUSTOM_4, PERM_CUSTOM_5, PERM_CUSTOM_6, PERM_CUSTOM_7,
// PERM_CUSTOM_8, PERM_CUSTOM_9, PERM_CUSTOM_10, PERM_CUSTOM_11, PERM_CUSTOM_12 "
// + "FROM WORKBASKET_ACCESS_LIST WHERE ACCESS_ID = #{accessId}")
// @Results(value = {
// @Result(property = "id", column = "ID"),
// @Result(property = "workbasketId", column = "WORKBASKET_ID"),
// @Result(property = "accessId", column = "ACCESS_ID"),
// @Result(property = "permRead", column = "PERM_READ"),
// @Result(property = "permOpen", column = "PERM_OPEN"),
// @Result(property = "permAppend", column = "PERM_APPEND"),
// @Result(property = "permTransfer", column = "PERM_TRANSFER"),
// @Result(property = "permDistribute", column = "PERM_DISTRIBUTE"),
// @Result(property = "permCustom1", column = "PERM_CUSTOM_1"),
// @Result(property = "permCustom2", column = "PERM_CUSTOM_2"),
// @Result(property = "permCustom3", column = "PERM_CUSTOM_3"),
// @Result(property = "permCustom4", column = "PERM_CUSTOM_4"),
// @Result(property = "permCustom5", column = "PERM_CUSTOM_5"),
// @Result(property = "permCustom6", column = "PERM_CUSTOM_6"),
// @Result(property = "permCustom7", column = "PERM_CUSTOM_7"),
// @Result(property = "permCustom8", column = "PERM_CUSTOM_8"),
// @Result(property = "permCustom9", column = "PERM_CUSTOM_9"),
// @Result(property = "permCustom10", column = "PERM_CUSTOM_10"),
// @Result(property = "permCustom11", column = "PERM_CUSTOM_11"),
// @Result(property = "permCustom12", column = "PERM_CUSTOM_12")})
// List<WorkbasketAccessItemImpl> findByAccessId(@Param("accessId") String accessId);
@Select("SELECT ID, WORKBASKET_ID, ACCESS_ID, PERM_READ, PERM_OPEN, PERM_APPEND, PERM_TRANSFER, PERM_DISTRIBUTE, PERM_CUSTOM_1, PERM_CUSTOM_2, PERM_CUSTOM_3, PERM_CUSTOM_4, PERM_CUSTOM_5, PERM_CUSTOM_6, PERM_CUSTOM_7, PERM_CUSTOM_8, PERM_CUSTOM_9, PERM_CUSTOM_10, PERM_CUSTOM_11, PERM_CUSTOM_12 " @Select("SELECT ID, WORKBASKET_ID, ACCESS_ID, PERM_READ, PERM_OPEN, PERM_APPEND, PERM_TRANSFER, PERM_DISTRIBUTE, PERM_CUSTOM_1, PERM_CUSTOM_2, PERM_CUSTOM_3, PERM_CUSTOM_4, PERM_CUSTOM_5, PERM_CUSTOM_6, PERM_CUSTOM_7, PERM_CUSTOM_8, PERM_CUSTOM_9, PERM_CUSTOM_10, PERM_CUSTOM_11, PERM_CUSTOM_12 "
+ "FROM WORKBASKET_ACCESS_LIST WHERE WORKBASKET_ID = #{id}") + "FROM WORKBASKET_ACCESS_LIST WHERE WORKBASKET_ID = #{id}")
@Results(value = { @Results(value = {
@ -108,7 +81,7 @@ public interface WorkbasketAccessMapper {
void delete(@Param("id") String id); void delete(@Param("id") String id);
@Delete("DELETE FROM WORKBASKET_ACCESS_LIST where WORKBASKET_ID = #{workbasketId}") @Delete("DELETE FROM WORKBASKET_ACCESS_LIST where WORKBASKET_ID = #{workbasketId}")
void deleteAllForWorkbasketkey(@Param("workbasketId") String workbasketId); void deleteAllForWorkbasketId(@Param("workbasketId") String workbasketId);
@Select("<script>SELECT MAX(PERM_READ) AS P_READ, MAX(PERM_OPEN) AS P_OPEN, MAX(PERM_APPEND) AS P_APPEND, MAX(PERM_TRANSFER) AS P_TRANSFER, MAX(PERM_DISTRIBUTE) AS P_DISTRIBUTE, MAX(PERM_CUSTOM_1) AS P_CUSTOM_1, MAX(PERM_CUSTOM_2) AS P_CUSTOM_2, MAX(PERM_CUSTOM_3) AS P_CUSTOM_3, MAX(PERM_CUSTOM_4) AS P_CUSTOM_4, MAX(PERM_CUSTOM_5) AS P_CUSTOM_5, MAX(PERM_CUSTOM_6) AS P_CUSTOM_6, MAX(PERM_CUSTOM_7) AS P_CUSTOM_7, MAX(PERM_CUSTOM_8) AS P_CUSTOM_8, MAX(PERM_CUSTOM_9) AS P_CUSTOM_9, MAX(PERM_CUSTOM_10) AS P_CUSTOM_10, MAX(PERM_CUSTOM_11) AS P_CUSTOM_11, MAX(PERM_CUSTOM_12) AS P_CUSTOM_12 " @Select("<script>SELECT MAX(PERM_READ) AS P_READ, MAX(PERM_OPEN) AS P_OPEN, MAX(PERM_APPEND) AS P_APPEND, MAX(PERM_TRANSFER) AS P_TRANSFER, MAX(PERM_DISTRIBUTE) AS P_DISTRIBUTE, MAX(PERM_CUSTOM_1) AS P_CUSTOM_1, MAX(PERM_CUSTOM_2) AS P_CUSTOM_2, MAX(PERM_CUSTOM_3) AS P_CUSTOM_3, MAX(PERM_CUSTOM_4) AS P_CUSTOM_4, MAX(PERM_CUSTOM_5) AS P_CUSTOM_5, MAX(PERM_CUSTOM_6) AS P_CUSTOM_6, MAX(PERM_CUSTOM_7) AS P_CUSTOM_7, MAX(PERM_CUSTOM_8) AS P_CUSTOM_8, MAX(PERM_CUSTOM_9) AS P_CUSTOM_9, MAX(PERM_CUSTOM_10) AS P_CUSTOM_10, MAX(PERM_CUSTOM_11) AS P_CUSTOM_11, MAX(PERM_CUSTOM_12) AS P_CUSTOM_12 "
+ "FROM WORKBASKET_ACCESS_LIST " + "FROM WORKBASKET_ACCESS_LIST "

View File

@ -123,7 +123,7 @@ public interface WorkbasketMapper {
@Select("<script>SELECT W.ID, W.KEY, W.NAME, W.DESCRIPTION, W.OWNER, W.DOMAIN, W.TYPE, W.ORG_LEVEL_1, W.ORG_LEVEL_2, W.ORG_LEVEL_3, W.ORG_LEVEL_4 FROM WORKBASKET AS W " @Select("<script>SELECT W.ID, W.KEY, W.NAME, W.DESCRIPTION, W.OWNER, W.DOMAIN, W.TYPE, W.ORG_LEVEL_1, W.ORG_LEVEL_2, W.ORG_LEVEL_3, W.ORG_LEVEL_4 FROM WORKBASKET AS W "
+ "INNER JOIN WORKBASKET_ACCESS_LIST AS ACL " + "INNER JOIN WORKBASKET_ACCESS_LIST AS ACL "
+ "ON (W.KEY = ACL.WORKBASKET_KEY AND ACL.ACCESS_ID = #{accessId}) " + "ON (W.ID = ACL.WORKBASKET_ID AND ACL.ACCESS_ID = #{accessId}) "
+ "WHERE <foreach collection='authorizations' item='authorization' separator=' AND '>" + "WHERE <foreach collection='authorizations' item='authorization' separator=' AND '>"
+ "<if test=\"authorization.name() == 'OPEN'\">PERM_OPEN</if>" + "<if test=\"authorization.name() == 'OPEN'\">PERM_OPEN</if>"
+ "<if test=\"authorization.name() == 'READ'\">PERM_READ</if>" + "<if test=\"authorization.name() == 'READ'\">PERM_READ</if>"

View File

@ -516,7 +516,7 @@ public class WorkbasketServiceImplTest {
verify(taskQueryMock, times(1)).list(); verify(taskQueryMock, times(1)).list();
verify(distributionTargetMapperMock, times(1)).deleteAllDistributionTargetsBySourceId(wb.getId()); verify(distributionTargetMapperMock, times(1)).deleteAllDistributionTargetsBySourceId(wb.getId());
verify(distributionTargetMapperMock, times(1)).deleteAllDistributionTargetsByTargetId(wb.getId()); verify(distributionTargetMapperMock, times(1)).deleteAllDistributionTargetsByTargetId(wb.getId());
verify(workbasketAccessMapperMock, times(1)).deleteAllForWorkbasketkey(wb.getKey()); verify(workbasketAccessMapperMock, times(1)).deleteAllForWorkbasketId(wb.getId());
verify(workbasketMapperMock, times(1)).delete(wb.getId()); verify(workbasketMapperMock, times(1)).delete(wb.getId());
verify(taskanaEngineImplMock, times(1)).returnConnection(); verify(taskanaEngineImplMock, times(1)).returnConnection();
verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock, verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock,

View File

@ -124,36 +124,47 @@ public class WorkbasketController {
} }
@RequestMapping(method = RequestMethod.POST) @RequestMapping(method = RequestMethod.POST)
public ResponseEntity<WorkbasketResource> createWorkbasket(@RequestBody Workbasket workbasket) { public ResponseEntity<WorkbasketResource> createWorkbasket(@RequestBody WorkbasketResource workbasketResource) {
Workbasket createdWorkbasket;
try { try {
createdWorkbasket = workbasketService.createWorkbasket(workbasket); Workbasket workbasket = workbasketMapper.toModel(workbasketResource);
return new ResponseEntity<>(workbasketMapper.toResource(createdWorkbasket), HttpStatus.CREATED); workbasket = workbasketService.createWorkbasket(workbasket);
return new ResponseEntity<>(workbasketMapper.toResource(workbasket), HttpStatus.CREATED);
} catch (InvalidWorkbasketException e) { } catch (InvalidWorkbasketException e) {
return new ResponseEntity<>(HttpStatus.PRECONDITION_FAILED); return new ResponseEntity<>(HttpStatus.PRECONDITION_FAILED);
} }
} }
@RequestMapping(value = "/{workbasketKey}", method = RequestMethod.PUT) @RequestMapping(value = "/{workbasketId}", method = RequestMethod.PUT)
public ResponseEntity<WorkbasketResource> updateWorkbasket( public ResponseEntity<WorkbasketResource> updateWorkbasket(
@PathVariable(value = "workbasketKey") String workbasketKey, @PathVariable(value = "workbasketId") String workbasketId,
@RequestBody Workbasket workbasket) { @RequestBody WorkbasketResource workbasketResource) {
ResponseEntity<WorkbasketResource> result;
try { try {
Workbasket updatedWorkbasket = workbasketService.updateWorkbasket(workbasket); if (workbasketId.equals(workbasketResource.workbasketId)) {
return new ResponseEntity<>(workbasketMapper.toResource(updatedWorkbasket), HttpStatus.OK); Workbasket workbasket = workbasketMapper.toModel(workbasketResource);
} catch (InvalidWorkbasketException e) { workbasket = workbasketService.updateWorkbasket(workbasket);
return new ResponseEntity<>(HttpStatus.PRECONDITION_FAILED); result = ResponseEntity.ok(workbasketMapper.toResource(workbasket));
} catch (WorkbasketNotFoundException e) { } else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND); throw new InvalidWorkbasketException(
} catch (NotAuthorizedException e) { "Target-WB-ID('" + workbasketId
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); + "') is not identical with the WB-ID of to object which should be updated. ID=('"
+ workbasketResource.getId() + "')");
} }
} catch (InvalidWorkbasketException e) {
result = new ResponseEntity<>(HttpStatus.PRECONDITION_FAILED);
} catch (WorkbasketNotFoundException e) {
result = new ResponseEntity<>(HttpStatus.NOT_FOUND);
} catch (NotAuthorizedException e) {
result = new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
} }
@RequestMapping(value = "/{workbasketKey}/authorizations", method = RequestMethod.GET) return result;
}
@RequestMapping(value = "/{workbasketId}/authorizations", method = RequestMethod.GET)
public ResponseEntity<List<WorkbasketAccessItemResource>> getWorkbasketAuthorizations( public ResponseEntity<List<WorkbasketAccessItemResource>> getWorkbasketAuthorizations(
@PathVariable(value = "workbasketKey") String workbasketKey) { @PathVariable(value = "workbasketId") String workbasketId) {
List<WorkbasketAccessItem> wbAuthorizations = workbasketService.getWorkbasketAuthorizations(workbasketKey); List<WorkbasketAccessItem> wbAuthorizations = workbasketService.getWorkbasketAuthorizations(workbasketId);
return new ResponseEntity<>(wbAuthorizations.stream() return new ResponseEntity<>(wbAuthorizations.stream()
.map(accItem -> workbasketAccessItemMapper.toResource(accItem)) .map(accItem -> workbasketAccessItemMapper.toResource(accItem))
.collect(Collectors.toList()), HttpStatus.OK); .collect(Collectors.toList()), HttpStatus.OK);
@ -161,7 +172,8 @@ public class WorkbasketController {
@RequestMapping(value = "/authorizations", method = RequestMethod.POST) @RequestMapping(value = "/authorizations", method = RequestMethod.POST)
public ResponseEntity<WorkbasketAccessItemResource> createWorkbasketAuthorization( public ResponseEntity<WorkbasketAccessItemResource> createWorkbasketAuthorization(
@RequestBody WorkbasketAccessItem workbasketAccessItem) { @RequestBody WorkbasketAccessItemResource workbasketAccessItemResource) {
WorkbasketAccessItem workbasketAccessItem = workbasketAccessItemMapper.toModel(workbasketAccessItemResource);
workbasketAccessItem = workbasketService.createWorkbasketAuthorization(workbasketAccessItem); workbasketAccessItem = workbasketService.createWorkbasketAuthorization(workbasketAccessItem);
return new ResponseEntity<>(workbasketAccessItemMapper.toResource(workbasketAccessItem), HttpStatus.OK); return new ResponseEntity<>(workbasketAccessItemMapper.toResource(workbasketAccessItem), HttpStatus.OK);
} }
@ -169,7 +181,8 @@ public class WorkbasketController {
@RequestMapping(value = "/authorizations/{authId}", method = RequestMethod.PUT) @RequestMapping(value = "/authorizations/{authId}", method = RequestMethod.PUT)
public ResponseEntity<WorkbasketAccessItemResource> updateWorkbasketAuthorization( public ResponseEntity<WorkbasketAccessItemResource> updateWorkbasketAuthorization(
@PathVariable(value = "authId") String authId, @PathVariable(value = "authId") String authId,
@RequestBody WorkbasketAccessItem workbasketAccessItem) throws InvalidArgumentException { @RequestBody WorkbasketAccessItemResource workbasketAccessItemResource) throws InvalidArgumentException {
WorkbasketAccessItem workbasketAccessItem = workbasketAccessItemMapper.toModel(workbasketAccessItemResource);
workbasketAccessItem = workbasketService.updateWorkbasketAuthorization(workbasketAccessItem); workbasketAccessItem = workbasketService.updateWorkbasketAuthorization(workbasketAccessItem);
return new ResponseEntity<>(workbasketAccessItemMapper.toResource(workbasketAccessItem), HttpStatus.OK); return new ResponseEntity<>(workbasketAccessItemMapper.toResource(workbasketAccessItem), HttpStatus.OK);
} }

View File

@ -37,7 +37,8 @@ public class WorkbasketResource extends ResourceSupport {
public String orgLevel3; public String orgLevel3;
public String orgLevel4; public String orgLevel4;
public WorkbasketResource(String workbasketId, String key, String name, String domain, WorkbasketType type, Instant created, public WorkbasketResource(String workbasketId, String key, String name, String domain, WorkbasketType type,
Instant created,
Instant modified, String description, String owner, String custom1, String custom2, String custom3, Instant modified, String description, String owner, String custom1, String custom2, String custom3,
String custom4, String orgLevel1, String orgLevel2, String orgLevel3, String orgLevel4) { String custom4, String orgLevel1, String orgLevel2, String orgLevel3, String orgLevel4) {
super(); super();

View File

@ -3,12 +3,19 @@ package pro.taskana.rest.resource.mapper;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo; import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn; import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
import org.springframework.beans.factory.annotation.Autowired;
import pro.taskana.WorkbasketAccessItem; import pro.taskana.WorkbasketAccessItem;
import pro.taskana.WorkbasketService;
import pro.taskana.impl.WorkbasketAccessItemImpl;
import pro.taskana.rest.WorkbasketController; import pro.taskana.rest.WorkbasketController;
import pro.taskana.rest.resource.WorkbasketAccessItemResource; import pro.taskana.rest.resource.WorkbasketAccessItemResource;
public class WorkbasketAccessItemMapper { public class WorkbasketAccessItemMapper {
@Autowired
private WorkbasketService workbasketService;
public WorkbasketAccessItemResource toResource(WorkbasketAccessItem wbAccItem) { public WorkbasketAccessItemResource toResource(WorkbasketAccessItem wbAccItem) {
WorkbasketAccessItemResource resource = new WorkbasketAccessItemResource(wbAccItem.getId(), WorkbasketAccessItemResource resource = new WorkbasketAccessItemResource(wbAccItem.getId(),
wbAccItem.getWorkbasketId(), wbAccItem.getWorkbasketId(),
@ -26,4 +33,28 @@ public class WorkbasketAccessItemMapper {
.withSelfRel()); .withSelfRel());
return resource; return resource;
} }
public WorkbasketAccessItem toModel(WorkbasketAccessItemResource wbAccItemRecource) {
WorkbasketAccessItemImpl wbAccItemModel = (WorkbasketAccessItemImpl) workbasketService
.newWorkbasketAccessItem(wbAccItemRecource.workbasketId, wbAccItemRecource.accessId);
wbAccItemModel.setId(wbAccItemRecource.accessItemId);
wbAccItemModel.setPermRead(wbAccItemRecource.permRead);
wbAccItemModel.setPermOpen(wbAccItemRecource.permOpen);
wbAccItemModel.setPermAppend(wbAccItemRecource.permAppend);
wbAccItemModel.setPermTransfer(wbAccItemRecource.permTransfer);
wbAccItemModel.setPermDistribute(wbAccItemRecource.permDistribute);
wbAccItemModel.setPermCustom1(wbAccItemRecource.permCustom1);
wbAccItemModel.setPermCustom2(wbAccItemRecource.permCustom2);
wbAccItemModel.setPermCustom3(wbAccItemRecource.permCustom3);
wbAccItemModel.setPermCustom4(wbAccItemRecource.permCustom4);
wbAccItemModel.setPermCustom5(wbAccItemRecource.permCustom5);
wbAccItemModel.setPermCustom6(wbAccItemRecource.permCustom6);
wbAccItemModel.setPermCustom7(wbAccItemRecource.permCustom7);
wbAccItemModel.setPermCustom8(wbAccItemRecource.permCustom8);
wbAccItemModel.setPermCustom9(wbAccItemRecource.permCustom9);
wbAccItemModel.setPermCustom10(wbAccItemRecource.permCustom10);
wbAccItemModel.setPermCustom11(wbAccItemRecource.permCustom11);
wbAccItemModel.setPermCustom12(wbAccItemRecource.permCustom12);
return wbAccItemModel;
}
} }

View File

@ -3,12 +3,19 @@ package pro.taskana.rest.resource.mapper;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo; import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn; import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
import org.springframework.beans.factory.annotation.Autowired;
import pro.taskana.Workbasket; import pro.taskana.Workbasket;
import pro.taskana.WorkbasketService;
import pro.taskana.impl.WorkbasketImpl;
import pro.taskana.rest.WorkbasketController; import pro.taskana.rest.WorkbasketController;
import pro.taskana.rest.resource.WorkbasketResource; import pro.taskana.rest.resource.WorkbasketResource;
public class WorkbasketMapper { public class WorkbasketMapper {
@Autowired
private WorkbasketService workbasketService;
public WorkbasketResource toResource(Workbasket wb) { public WorkbasketResource toResource(Workbasket wb) {
WorkbasketResource resource = new WorkbasketResource(wb.getId(), wb.getKey(), wb.getName(), wb.getDomain(), WorkbasketResource resource = new WorkbasketResource(wb.getId(), wb.getKey(), wb.getName(), wb.getDomain(),
wb.getType(), wb.getCreated(), wb.getType(), wb.getCreated(),
@ -20,4 +27,24 @@ public class WorkbasketMapper {
resource.add(linkTo(methodOn(WorkbasketController.class).getWorkbasket(wb.getId())).withSelfRel()); resource.add(linkTo(methodOn(WorkbasketController.class).getWorkbasket(wb.getId())).withSelfRel());
return resource; return resource;
} }
public Workbasket toModel(WorkbasketResource wbResource) {
WorkbasketImpl wbModel = (WorkbasketImpl) workbasketService.newWorkbasket(wbResource.key, wbResource.domain);
wbModel.setId(wbResource.workbasketId);
wbModel.setName(wbResource.name);
wbModel.setType(wbResource.type);
wbModel.setCreated(wbResource.created);
wbModel.setModified(wbResource.modified);
wbModel.setDescription(wbResource.description);
wbModel.setOwner(wbResource.owner);
wbModel.setCustom1(wbResource.custom1);
wbModel.setCustom2(wbResource.custom2);
wbModel.setCustom3(wbResource.custom3);
wbModel.setCustom4(wbResource.custom4);
wbModel.setOrgLevel1(wbResource.orgLevel1);
wbModel.setOrgLevel2(wbResource.orgLevel2);
wbModel.setOrgLevel3(wbResource.orgLevel3);
wbModel.setOrgLevel4(wbResource.orgLevel4);
return wbModel;
}
} }