TSK-162 Implement WorkbasketService.getDistributionTargets() method

This commit is contained in:
BerndBreier 2018-01-23 10:43:40 +01:00 committed by Marcel Lengl
parent 4f321d47c2
commit aa1003405d
5 changed files with 22 additions and 19 deletions

View File

@ -46,12 +46,13 @@ public class DbSchemaCreator {
runner.setStopOnError(true);
runner.setLogWriter(logWriter);
runner.setErrorLogWriter(errorLogWriter);
if (!isSchemaPreexisting(runner)) {
runner.runScript(new InputStreamReader(this.getClass().getResourceAsStream(DB_SCHEMA)));
try {
if (!isSchemaPreexisting(runner)) {
runner.runScript(new InputStreamReader(this.getClass().getResourceAsStream(DB_SCHEMA)));
}
} finally {
runner.closeConnection();
}
runner.closeConnection();
LOGGER.debug(outWriter.toString());
if (!errorWriter.toString().trim().isEmpty()) {
LOGGER.error(errorWriter.toString());

View File

@ -222,6 +222,8 @@ public class TaskanaEngineImpl implements TaskanaEngine {
String databaseProductName;
try (Connection con = taskanaEngineConfiguration.getDatasource().getConnection()) {
databaseProductName = con.getMetaData().getDatabaseProductName();
databaseProductName = con.getMetaData()
.getDatabaseProductName();
if (databaseProductName.contains("DB2")) {
configuration.setDatabaseId("db2");
} else if (databaseProductName.contains("H2")) {

View File

@ -108,7 +108,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
for (String accessId : CurrentUserContext.getAccessIds()) {
workbaskets.addAll(workbasketMapper.findByPermission(permissions, accessId));
}
result = new ArrayList<WorkbasketSummary>();
result = new ArrayList<>();
result.addAll(workbaskets);
return result;
} finally {
@ -135,7 +135,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
} finally {
taskanaEngine.returnConnection();
if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = workbaskets == null ? 0 : workbaskets.size();
int numberOfResultObjects = workbaskets.size();
LOGGER.debug("exit from getWorkbaskets(). Returning {} resulting Objects: {} ", numberOfResultObjects,
LoggerUtils.listToString(workbaskets));
}
@ -388,7 +388,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
} finally {
taskanaEngine.returnConnection();
if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = result == null ? 0 : result.size();
int numberOfResultObjects = result.size();
LOGGER.debug("exit from getDistributionTargets(workbasketId). Returning {} resulting Objects: {} ",
numberOfResultObjects, LoggerUtils.listToString(result));
}
@ -427,7 +427,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
taskanaEngine.returnConnection();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("setDistributionTargets set {} distribution targets to source workbasket {} ",
targetWorkbasketIds.size(), sourceWorkbasketId);
targetWorkbasketIds == null ? 0 : targetWorkbasketIds.size(), sourceWorkbasketId);
}
}
@ -526,7 +526,8 @@ public class WorkbasketServiceImpl implements WorkbasketService {
List<String> accessIds = CurrentUserContext.getAccessIds();
LOGGER.debug("checkAuthorization: Verifying that {} has the permission {} on workbasket {}",
CurrentUserContext.getUserid(), workbasketAuthorization.name(), workbasketKey);
CurrentUserContext.getUserid(),
workbasketAuthorization == null ? "null" : workbasketAuthorization.name(), workbasketKey);
List<WorkbasketAccessItem> accessItems;

View File

@ -193,6 +193,7 @@ public class WorkbasketServiceImplIntAutocommitTest {
workbasket2 = workBasketService.createWorkbasket(workbasket2);
createWorkbasketWithSecurity(workbasket2, "Elena", true, true, false, false);
List<String> distTargets = new ArrayList<>(Arrays.asList(workbasket0.getId(), workbasket1.getId()));
Thread.sleep(20L);
workBasketService.setDistributionTargets(workbasket2.getId(), distTargets);
String id3 = IdGenerator.generateWithPrefix("TWB");
@ -202,6 +203,7 @@ public class WorkbasketServiceImplIntAutocommitTest {
createWorkbasketWithSecurity(workbasket3, "Elena", true, true, false, false);
List<String> newDistTargets = new ArrayList<>(Arrays.asList(workbasket3.getId()));
Thread.sleep(20L);
workBasketService.setDistributionTargets(workbasket2.getId(), newDistTargets);
Workbasket foundBasket = workBasketService.getWorkbasket(workbasket2.getId());
@ -210,10 +212,8 @@ public class WorkbasketServiceImplIntAutocommitTest {
Assert.assertEquals(1, distributionTargets.size());
Assert.assertEquals(id3, distributionTargets.get(0).getId());
// Question: should we update the modfied timestamp on the source workbasket if we change its
// distributiontargets?
// Assert.assertNotEquals(workBasketService.getWorkbasket(id2).getCreated(),
// workBasketService.getWorkbasket(id2).getModified());
Assert.assertNotEquals(workBasketService.getWorkbasket(id2).getCreated(),
workBasketService.getWorkbasket(id2).getModified());
Assert.assertEquals(workBasketService.getWorkbasket(id1).getCreated(),
workBasketService.getWorkbasket(id1).getModified());
Assert.assertEquals(workBasketService.getWorkbasket(id3).getCreated(),

View File

@ -186,7 +186,6 @@ public class WorkbasketServiceImplIntExplicitTest {
String id2 = IdGenerator.generateWithPrefix("TWB");
Workbasket workbasket2 = createTestWorkbasket(id2, "key2", "novatec", "Hyperbasket", WorkbasketType.GROUP);
//
workbasket2 = workBasketService.createWorkbasket(workbasket2);
createWorkbasketWithSecurity(workbasket2, "Elena", true, true, false, false);
@ -221,6 +220,7 @@ public class WorkbasketServiceImplIntExplicitTest {
createWorkbasketWithSecurity(workbasket2, "Elena", true, true, false, false);
List<String> distTargets = new ArrayList<>(Arrays.asList(workbasket0.getId(), workbasket1.getId()));
Thread.sleep(20L);
workBasketService.setDistributionTargets(workbasket2.getId(), distTargets);
String id3 = IdGenerator.generateWithPrefix("TWB");
@ -230,6 +230,7 @@ public class WorkbasketServiceImplIntExplicitTest {
createWorkbasketWithSecurity(workbasket3, "Elena", true, true, false, false);
List<String> newDistTargets = new ArrayList<>(Arrays.asList(workbasket3.getId()));
Thread.sleep(20L);
workBasketService.setDistributionTargets(workbasket2.getId(), newDistTargets);
Workbasket foundBasket = workBasketService.getWorkbasket(workbasket2.getId());
@ -237,10 +238,8 @@ public class WorkbasketServiceImplIntExplicitTest {
List<WorkbasketSummary> distributionTargets = workBasketService.getDistributionTargets(foundBasket.getId());
Assert.assertEquals(1, distributionTargets.size());
Assert.assertEquals(workbasket3.getId(), distributionTargets.get(0).getId());
// Question: should we update the modfied timestamp on the source workbasket if we change its
// distributiontargets?
// Assert.assertNotEquals(workBasketService.getWorkbasket(id2).getCreated(),
// workBasketService.getWorkbasket(id2).getModified());
Assert.assertNotEquals(workBasketService.getWorkbasket(id2).getCreated(),
workBasketService.getWorkbasket(id2).getModified());
Assert.assertEquals(workBasketService.getWorkbasket(id1).getCreated(),
workBasketService.getWorkbasket(id1).getModified());
Assert.assertEquals(workBasketService.getWorkbasket(id3).getCreated(),