TSK-246 Find all workbaskets, where the given key is configured as distribution target
This commit is contained in:
parent
e6218d0540
commit
43d4e9eafd
|
@ -248,4 +248,18 @@ public interface WorkbasketService {
|
|||
*/
|
||||
void deleteWorkbasket(String workbasketId)
|
||||
throws NotAuthorizedException, WorkbasketNotFoundException, WorkbasketInUseException, InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Returns the distribution sources for a given workbasket.
|
||||
*
|
||||
* @param workbasketId
|
||||
* the id of the referenced workbasket
|
||||
* @return the workbaskets that are distribution sources of the specified workbasket.
|
||||
* @throws NotAuthorizedException
|
||||
* if the current user has no read permission for the specified workbasket
|
||||
* @throws WorkbasketNotFoundException
|
||||
* if the workbasket doesn't exist
|
||||
*/
|
||||
List<WorkbasketSummary> getDistributionSources(String workbasketId)
|
||||
throws NotAuthorizedException, WorkbasketNotFoundException;
|
||||
}
|
||||
|
|
|
@ -401,6 +401,30 @@ public class WorkbasketServiceImpl implements WorkbasketService {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WorkbasketSummary> getDistributionSources(String workbasketId)
|
||||
throws NotAuthorizedException, WorkbasketNotFoundException {
|
||||
LOGGER.debug("entry to getDistributionSources(workbasketId = {})", workbasketId);
|
||||
List<WorkbasketSummary> result = new ArrayList<>();
|
||||
try {
|
||||
taskanaEngine.openConnection();
|
||||
// check that source workbasket exists
|
||||
getWorkbasket(workbasketId);
|
||||
checkAuthorizationByWorkbasketId(workbasketId, WorkbasketAuthorization.READ);
|
||||
List<WorkbasketSummaryImpl> distributionSources = workbasketMapper
|
||||
.findDistributionSources(workbasketId);
|
||||
result.addAll(distributionSources);
|
||||
return result;
|
||||
} finally {
|
||||
taskanaEngine.returnConnection();
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
int numberOfResultObjects = result.size();
|
||||
LOGGER.debug("exit from getDistributionSources(workbasketId). Returning {} resulting Objects: {} ",
|
||||
numberOfResultObjects, LoggerUtils.listToString(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDistributionTargets(String sourceWorkbasketId, List<String> targetWorkbasketIds)
|
||||
throws WorkbasketNotFoundException, NotAuthorizedException {
|
||||
|
|
|
@ -75,6 +75,22 @@ public interface WorkbasketMapper {
|
|||
@Result(property = "orgLevel4", column = "ORG_LEVEL_4")})
|
||||
List<WorkbasketSummaryImpl> findByDistributionTargets(@Param("id") String id);
|
||||
|
||||
@Select("SELECT ID, KEY, NAME, DESCRIPTION, OWNER, DOMAIN, TYPE, ORG_LEVEL_1, ORG_LEVEL_2, ORG_LEVEL_3, ORG_LEVEL_4 FROM WORKBASKET "
|
||||
+ " WHERE ID IN (SELECT SOURCE_ID FROM DISTRIBUTION_TARGETS WHERE TARGET_ID = #{id})")
|
||||
@Results(value = {
|
||||
@Result(property = "id", column = "ID"),
|
||||
@Result(property = "key", column = "KEY"),
|
||||
@Result(property = "name", column = "NAME"),
|
||||
@Result(property = "description", column = "DESCRIPTION"),
|
||||
@Result(property = "owner", column = "OWNER"),
|
||||
@Result(property = "domain", column = "DOMAIN"),
|
||||
@Result(property = "type", column = "TYPE"),
|
||||
@Result(property = "orgLevel1", column = "ORG_LEVEL_1"),
|
||||
@Result(property = "orgLevel2", column = "ORG_LEVEL_2"),
|
||||
@Result(property = "orgLevel3", column = "ORG_LEVEL_3"),
|
||||
@Result(property = "orgLevel4", column = "ORG_LEVEL_4")})
|
||||
List<WorkbasketSummaryImpl> findDistributionSources(@Param("id") String id);
|
||||
|
||||
@Select("SELECT ID, KEY, NAME, DESCRIPTION, OWNER, DOMAIN, TYPE, ORG_LEVEL_1, ORG_LEVEL_2, ORG_LEVEL_3, ORG_LEVEL_4 FROM WORKBASKET WHERE key = #{key}")
|
||||
@Results(value = {
|
||||
@Result(property = "id", column = "ID"),
|
||||
|
|
|
@ -11,7 +11,6 @@ import java.util.stream.Collectors;
|
|||
|
||||
import org.h2.store.fs.FileUtils;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
|
@ -204,19 +203,46 @@ public class DistributionTargetsAccTest extends AbstractAccTest {
|
|||
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@WithAccessId(
|
||||
userName = "user_2_2",
|
||||
groupNames = {"group_1", "group_2"})
|
||||
@Test
|
||||
public void testQueryWorkbasketsWhereGivenWorkbasketIsDistributionTarget()
|
||||
throws NotAuthorizedException, WorkbasketNotFoundException, InvalidWorkbasketException, SQLException {
|
||||
// WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
|
||||
//
|
||||
// List<WorkbasketSummary> distributionSources = workbasketService
|
||||
// .getDistributionSources("WBI:100000000000000000000000000000000004");
|
||||
//
|
||||
// assertEquals(2, distributionSources.size());
|
||||
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
|
||||
|
||||
List<WorkbasketSummary> distributionSources = workbasketService
|
||||
.getDistributionSources("WBI:100000000000000000000000000000000004");
|
||||
|
||||
assertEquals(2, distributionSources.size());
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "henry",
|
||||
groupNames = {"undefinedgroup"})
|
||||
@Test(expected = NotAuthorizedException.class)
|
||||
public void testQueryDistributionSourcesThrowsNotAuthorized()
|
||||
throws NotAuthorizedException, WorkbasketNotFoundException, InvalidWorkbasketException, SQLException {
|
||||
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
|
||||
|
||||
List<WorkbasketSummary> distributionSources = workbasketService
|
||||
.getDistributionSources("WBI:100000000000000000000000000000000004");
|
||||
|
||||
assertEquals(2, distributionSources.size());
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_2_2",
|
||||
groupNames = {"group_1", "group_2"})
|
||||
@Test(expected = WorkbasketNotFoundException.class)
|
||||
public void testQueryDistributionSourcesThrowsWorkbasketNotFound()
|
||||
throws NotAuthorizedException, WorkbasketNotFoundException, InvalidWorkbasketException, SQLException {
|
||||
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
|
||||
|
||||
List<WorkbasketSummary> distributionSources = workbasketService
|
||||
.getDistributionSources("WBI:10dasgibtsdochnicht00000000000000004");
|
||||
|
||||
assertEquals(2, distributionSources.size());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
|
|
Loading…
Reference in New Issue