diff --git a/lib/taskana-core/src/main/java/pro/taskana/ClassificationService.java b/lib/taskana-core/src/main/java/pro/taskana/ClassificationService.java index a62cad65a..9cb0572be 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/ClassificationService.java +++ b/lib/taskana-core/src/main/java/pro/taskana/ClassificationService.java @@ -4,6 +4,7 @@ import pro.taskana.exceptions.ClassificationAlreadyExistException; import pro.taskana.exceptions.ClassificationInUseException; import pro.taskana.exceptions.ClassificationNotFoundException; import pro.taskana.exceptions.ConcurrencyException; +import pro.taskana.exceptions.DomainNotFoundException; import pro.taskana.exceptions.NotAuthorizedException; /** @@ -67,9 +68,12 @@ public interface ClassificationService { * if the current user is not member of role BUSINESS_ADMIN or ADMIN * @throws ClassificationNotFoundException * if the current parentId is not NULL/EMPTY and can not be found. + * @throws DomainNotFoundException + * if the domain does not exist in the configuration */ Classification createClassification(Classification classification) - throws ClassificationAlreadyExistException, NotAuthorizedException, ClassificationNotFoundException; + throws ClassificationAlreadyExistException, NotAuthorizedException, ClassificationNotFoundException, + DomainNotFoundException; /** * Updates a Classification. diff --git a/lib/taskana-core/src/main/java/pro/taskana/impl/ClassificationServiceImpl.java b/lib/taskana-core/src/main/java/pro/taskana/impl/ClassificationServiceImpl.java index fcfe55c2a..7f7198653 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/impl/ClassificationServiceImpl.java +++ b/lib/taskana-core/src/main/java/pro/taskana/impl/ClassificationServiceImpl.java @@ -20,6 +20,7 @@ import pro.taskana.exceptions.ClassificationAlreadyExistException; import pro.taskana.exceptions.ClassificationInUseException; import pro.taskana.exceptions.ClassificationNotFoundException; import pro.taskana.exceptions.ConcurrencyException; +import pro.taskana.exceptions.DomainNotFoundException; import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.exceptions.NotAuthorizedToQueryWorkbasketException; import pro.taskana.exceptions.SystemException; @@ -50,9 +51,14 @@ public class ClassificationServiceImpl implements ClassificationService { @Override public Classification createClassification(Classification classification) - throws ClassificationAlreadyExistException, NotAuthorizedException, ClassificationNotFoundException { + throws ClassificationAlreadyExistException, NotAuthorizedException, ClassificationNotFoundException, + DomainNotFoundException { LOGGER.debug("entry to createClassification(classification = {})", classification); taskanaEngine.checkRoleMembership(TaskanaRole.BUSINESS_ADMIN, TaskanaRole.ADMIN); + if (!taskanaEngine.domainExists(classification.getDomain()) && !"".equals(classification.getDomain())) { + throw new DomainNotFoundException(classification.getDomain(), + "Domain " + classification.getDomain() + " does not exist in the configuration."); + } ClassificationImpl classificationImpl; final boolean isClassificationExisting; try { @@ -227,10 +233,6 @@ public class ClassificationServiceImpl implements ClassificationService { classification.setParentId(""); } - if (classification.getDomain() == null) { - classification.setDomain(""); - } - if (classification.getDomain().isEmpty()) { classification.setIsValidInDomain(false); } diff --git a/lib/taskana-core/src/test/java/acceptance/classification/CreateClassificationAccTest.java b/lib/taskana-core/src/test/java/acceptance/classification/CreateClassificationAccTest.java index c17f70eac..4f7eb565f 100644 --- a/lib/taskana-core/src/test/java/acceptance/classification/CreateClassificationAccTest.java +++ b/lib/taskana-core/src/test/java/acceptance/classification/CreateClassificationAccTest.java @@ -12,6 +12,7 @@ import pro.taskana.Classification; import pro.taskana.ClassificationService; import pro.taskana.exceptions.ClassificationAlreadyExistException; import pro.taskana.exceptions.ClassificationNotFoundException; +import pro.taskana.exceptions.DomainNotFoundException; import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.security.JAASRunner; import pro.taskana.security.WithAccessId; @@ -34,7 +35,8 @@ public class CreateClassificationAccTest extends AbstractAccTest { groupNames = {"group_1", "businessadmin"}) @Test public void testCreateRootClassification() - throws ClassificationAlreadyExistException, ClassificationNotFoundException, NotAuthorizedException { + throws ClassificationAlreadyExistException, ClassificationNotFoundException, NotAuthorizedException, + DomainNotFoundException { long amountOfClassificationsBefore = classificationService.createClassificationQuery().count(); Classification classification = classificationService.newClassification("Key0", "", "TASK"); classification.setIsValidInDomain(true); @@ -57,18 +59,20 @@ public class CreateClassificationAccTest extends AbstractAccTest { groupNames = {"group_1", "businessadmin"}) @Test public void testCreateClassificationWithRootCopy() - throws ClassificationAlreadyExistException, ClassificationNotFoundException, NotAuthorizedException { + throws ClassificationAlreadyExistException, ClassificationNotFoundException, NotAuthorizedException, + DomainNotFoundException { long amountOfClassificationsBefore = classificationService.createClassificationQuery().count(); - Classification classification = classificationService.newClassification("Key1", "Dummy-Domain", "TASK"); + Classification classification = classificationService.newClassification("Key1", "DOMAIN_A", "TASK"); classification.setIsValidInDomain(true); classification = classificationService.createClassification(classification); // Check returning one is the "original" - assertNotNull(classification.getId()); - assertNotNull(classification.getCreated()); - assertNotNull(classification.getModified()); - assertThat(classification.getIsValidInDomain(), equalTo(true)); - assertThat(classification.getDomain(), equalTo("Dummy-Domain")); + Classification createdClassification = classificationService.getClassification(classification.getId()); + assertNotNull(createdClassification.getId()); + assertNotNull(createdClassification.getCreated()); + assertNotNull(createdClassification.getModified()); + assertThat(createdClassification.getIsValidInDomain(), equalTo(true)); + assertThat(createdClassification.getDomain(), equalTo("DOMAIN_A")); // Check 2 new created long amountOfClassificationsAfter = classificationService.createClassificationQuery().count(); @@ -96,12 +100,13 @@ public class CreateClassificationAccTest extends AbstractAccTest { groupNames = {"group_1", "businessadmin"}) @Test public void testCreateClassificationWithInvalidValues() - throws ClassificationAlreadyExistException, NotAuthorizedException, ClassificationNotFoundException { + throws ClassificationAlreadyExistException, NotAuthorizedException, ClassificationNotFoundException, + DomainNotFoundException { long amountOfClassificationsBefore = classificationService.createClassificationQuery().count(); // Check key NULL try { - Classification classification = classificationService.newClassification(null, "Dummy-Domain", "TASK"); + Classification classification = classificationService.newClassification(null, "DOMAIN_A", "TASK"); classification = classificationService.createClassification(classification); } catch (IllegalStateException e) { // nothing to do @@ -109,23 +114,12 @@ public class CreateClassificationAccTest extends AbstractAccTest { // Check invalid ServiceLevel try { - Classification classification = classificationService.newClassification("Key2", "Domain", "TASK"); + Classification classification = classificationService.newClassification("Key2", "DOMAIN_B", "TASK"); classification.setServiceLevel("abc"); classification = classificationService.createClassification(classification); } catch (IllegalArgumentException e) { // nothing to do } - - // Check domain NULL will be replaced "" - Classification classification = classificationService.newClassification("Key2", null, "TASK"); - classification = classificationService.createClassification(classification); - long amountOfClassificationsAfter = classificationService.createClassificationQuery().count(); - assertThat(amountOfClassificationsAfter, equalTo(amountOfClassificationsBefore + 1)); - assertThat(classification.getDomain(), equalTo("")); - assertThat(classification.getParentId(), equalTo("")); - assertThat(classification.getIsValidInDomain(), equalTo(false)); - assertNotNull(classification.getCreated()); - assertNotNull(classification.getModified()); } @WithAccessId( @@ -133,18 +127,31 @@ public class CreateClassificationAccTest extends AbstractAccTest { groupNames = {"group_1", "businessadmin"}) @Test(expected = ClassificationAlreadyExistException.class) public void testCreateClassificationAlreadyExisting() - throws ClassificationAlreadyExistException, NotAuthorizedException, ClassificationNotFoundException { + throws ClassificationAlreadyExistException, NotAuthorizedException, ClassificationNotFoundException, + DomainNotFoundException { Classification classification = classificationService.newClassification("Key3", "", "TASK"); classification = classificationService.createClassification(classification); classification = classificationService.createClassification(classification); } + @WithAccessId( + userName = "teamlead_1", + groupNames = {"group_1", "businessadmin"}) + @Test(expected = DomainNotFoundException.class) + public void testCreateClassificationInUnknownDomain() + throws ClassificationAlreadyExistException, NotAuthorizedException, ClassificationNotFoundException, + DomainNotFoundException { + Classification classification = classificationService.newClassification("Key3", "UNKNOWN_DOMAIN", "TASK"); + classification = classificationService.createClassification(classification); + } + @WithAccessId( userName = "teamlead_1", groupNames = {"group_1", "businessadmin"}) @Test(expected = ClassificationNotFoundException.class) public void testCreateClassificationWithInvalidParent() - throws ClassificationAlreadyExistException, NotAuthorizedException, ClassificationNotFoundException { + throws ClassificationAlreadyExistException, NotAuthorizedException, ClassificationNotFoundException, + DomainNotFoundException { Classification classification = classificationService.newClassification("Key4", "", "TASK"); classification.setParentId("ID WHICH CANT BE FOUND"); classification = classificationService.createClassification(classification); diff --git a/lib/taskana-core/src/test/java/pro/taskana/impl/ClassificationServiceImplTest.java b/lib/taskana-core/src/test/java/pro/taskana/impl/ClassificationServiceImplTest.java index cc32daba4..cd3add222 100644 --- a/lib/taskana-core/src/test/java/pro/taskana/impl/ClassificationServiceImplTest.java +++ b/lib/taskana-core/src/test/java/pro/taskana/impl/ClassificationServiceImplTest.java @@ -26,6 +26,7 @@ import pro.taskana.Classification; import pro.taskana.exceptions.ClassificationAlreadyExistException; import pro.taskana.exceptions.ClassificationNotFoundException; import pro.taskana.exceptions.ConcurrencyException; +import pro.taskana.exceptions.DomainNotFoundException; import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.mappings.ClassificationMapper; @@ -60,10 +61,12 @@ public class ClassificationServiceImplTest { @Test(expected = ClassificationAlreadyExistException.class) public void testCreateClassificationAlreadyExisting() - throws ClassificationAlreadyExistException, ClassificationNotFoundException, NotAuthorizedException { + throws ClassificationAlreadyExistException, ClassificationNotFoundException, NotAuthorizedException, + DomainNotFoundException { Classification classification = createDummyClassification(); doReturn(classification).when(classificationMapperMock).findByKeyAndDomain(classification.getKey(), classification.getDomain()); + doReturn(true).when(taskanaEngineImplMock).domainExists(any()); try { cutSpy.createClassification(classification); @@ -73,6 +76,7 @@ public class ClassificationServiceImplTest { classification.getDomain()); verify(taskanaEngineImplMock, times(1)).returnConnection(); verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any()); + verify(taskanaEngineImplMock, times(1)).domainExists(any()); verifyNoMoreInteractions(classificationMapperMock, taskanaEngineImplMock, classificationQueryImplMock); throw e; } @@ -80,12 +84,14 @@ public class ClassificationServiceImplTest { @Test(expected = ClassificationNotFoundException.class) public void testCreateClassificationParentNotExisting() - throws ClassificationAlreadyExistException, ClassificationNotFoundException, NotAuthorizedException { + throws ClassificationAlreadyExistException, ClassificationNotFoundException, NotAuthorizedException, + DomainNotFoundException { Classification classification = createDummyClassification(); classification.setParentId("NOT EXISTING ID"); doReturn(null).when(classificationMapperMock).findByKeyAndDomain(classification.getKey(), classification.getDomain()); doReturn(null).when(classificationMapperMock).findById(classification.getParentId()); + doReturn(true).when(taskanaEngineImplMock).domainExists(any()); try { cutSpy.createClassification(classification); @@ -97,6 +103,7 @@ public class ClassificationServiceImplTest { verify(cutSpy, times(1)).getClassification(classification.getParentId()); verify(classificationMapperMock, times(1)).findById(classification.getParentId()); verify(taskanaEngineImplMock, times(2)).returnConnection(); + verify(taskanaEngineImplMock, times(1)).domainExists(any()); verifyNoMoreInteractions(classificationMapperMock, taskanaEngineImplMock, classificationQueryImplMock); throw e; } @@ -105,7 +112,7 @@ public class ClassificationServiceImplTest { @Test public void testCreateClassificationInOwnDomainButExistingInRoot() throws ClassificationAlreadyExistException, ClassificationNotFoundException, InterruptedException, - NotAuthorizedException { + NotAuthorizedException, DomainNotFoundException { Instant beforeTimestamp = Instant.now(); Thread.sleep(10L); Classification classification = createDummyClassification(); @@ -114,6 +121,7 @@ public class ClassificationServiceImplTest { doReturn(null).when(classificationMapperMock).findByKeyAndDomain(classification.getKey(), classification.getDomain()); doReturn(classification).when(classificationMapperMock).findByKeyAndDomain(classification.getKey(), ""); + doReturn(true).when(taskanaEngineImplMock).domainExists(any()); classification = cutSpy.createClassification(classification); @@ -124,6 +132,7 @@ public class ClassificationServiceImplTest { verify(classificationMapperMock, times(1)).insert(any()); verify(taskanaEngineImplMock, times(2)).returnConnection(); verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any()); + verify(taskanaEngineImplMock, times(1)).domainExists(any()); verifyNoMoreInteractions(classificationMapperMock, taskanaEngineImplMock, classificationQueryImplMock); Thread.sleep(15); assertThat(classification.getCreated().toString().substring(0, 10), equalTo(todaysDate)); @@ -135,13 +144,15 @@ public class ClassificationServiceImplTest { @Test public void testCreateClassificationInOwnDomainAndCopyInRootDomain() - throws ClassificationAlreadyExistException, NotAuthorizedException, ClassificationNotFoundException { + throws ClassificationAlreadyExistException, NotAuthorizedException, ClassificationNotFoundException, + DomainNotFoundException { Classification classification = createDummyClassification(); String domain = classification.getDomain(); String key = classification.getKey(); doReturn(null).when(classificationMapperMock).findByKeyAndDomain(classification.getKey(), classification.getDomain()); doReturn(null).when(classificationMapperMock).findByKeyAndDomain(classification.getKey(), ""); + doReturn(true).when(taskanaEngineImplMock).domainExists(any()); classification = cutSpy.createClassification(classification); @@ -151,6 +162,7 @@ public class ClassificationServiceImplTest { verify(classificationMapperMock, times(2)).insert(any()); verify(taskanaEngineImplMock, times(2)).returnConnection(); verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any()); + verify(taskanaEngineImplMock, times(1)).domainExists(any()); verifyNoMoreInteractions(classificationMapperMock, taskanaEngineImplMock, classificationQueryImplMock); assertThat(classification.getCreated().toString().substring(0, 10), equalTo(todaysDate)); assertThat(classification.getDomain(), equalTo(domain)); @@ -159,7 +171,8 @@ public class ClassificationServiceImplTest { @Test public void testCreateClassificationIntoRootDomain() - throws ClassificationAlreadyExistException, NotAuthorizedException, ClassificationNotFoundException { + throws ClassificationAlreadyExistException, NotAuthorizedException, ClassificationNotFoundException, + DomainNotFoundException { ClassificationImpl classification = (ClassificationImpl) createDummyClassification(); classification.setDomain(""); doReturn(null).when(classificationMapperMock).findByKeyAndDomain(classification.getKey(), @@ -173,6 +186,7 @@ public class ClassificationServiceImplTest { verify(classificationMapperMock, times(1)).insert(classification); verify(taskanaEngineImplMock, times(1)).returnConnection(); verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any()); + verify(taskanaEngineImplMock, times(1)).domainExists(any()); verifyNoMoreInteractions(classificationMapperMock, taskanaEngineImplMock, classificationQueryImplMock); assertThat(classification.getCreated().toString().substring(0, 10), equalTo(todaysDate)); } @@ -286,7 +300,7 @@ public class ClassificationServiceImplTest { classificationImpl.setDescription("A DUMMY FOR TESTING A SERVICE"); classificationImpl.setName("SERVICE-DUMMY"); classificationImpl.setCategory("dummy-category"); - classificationImpl.setDomain("test-domain"); + classificationImpl.setDomain("DOMAIN_A"); classificationImpl.setServiceLevel("P2D"); classificationImpl.setId("ID: 1"); classificationImpl.setKey("ABC111"); diff --git a/lib/taskana-core/src/test/java/pro/taskana/impl/integration/ClassificationServiceImplIntAutoCommitTest.java b/lib/taskana-core/src/test/java/pro/taskana/impl/integration/ClassificationServiceImplIntAutoCommitTest.java index 55ef10e43..79bc4407c 100644 --- a/lib/taskana-core/src/test/java/pro/taskana/impl/integration/ClassificationServiceImplIntAutoCommitTest.java +++ b/lib/taskana-core/src/test/java/pro/taskana/impl/integration/ClassificationServiceImplIntAutoCommitTest.java @@ -33,6 +33,7 @@ import pro.taskana.configuration.TaskanaEngineConfiguration; import pro.taskana.exceptions.ClassificationAlreadyExistException; import pro.taskana.exceptions.ClassificationNotFoundException; import pro.taskana.exceptions.ConcurrencyException; +import pro.taskana.exceptions.DomainNotFoundException; import pro.taskana.exceptions.InvalidArgumentException; import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.impl.ClassificationImpl; @@ -76,7 +77,7 @@ public class ClassificationServiceImplIntAutoCommitTest { @Test public void testInsertClassifications() throws Exception { - final String domain = "test-domain"; + final String domain = "DOMAIN_A"; final String key = "dummy-key"; ClassificationImpl expectedClassification; Classification actualClassification; @@ -125,16 +126,16 @@ public class ClassificationServiceImplIntAutoCommitTest { } // new classification but root existing - expectedClassification = (ClassificationImpl) this.createDummyClassificationWithUniqueKey(domain + "_2", + expectedClassification = (ClassificationImpl) this.createDummyClassificationWithUniqueKey("DOMAIN_B", "type1"); expectedClassification.setKey(key); classificationService.createClassification(expectedClassification); - actualClassification = classificationService.getClassification(key, domain + "_2"); + actualClassification = classificationService.getClassification(key, "DOMAIN_B"); assertThat(actualClassification, not(equalTo(null))); assertThat(actualClassification.getCreated(), not(equalTo(null))); assertThat(actualClassification.getId(), not(equalTo(null))); assertThat(actualClassification.getKey(), equalTo(key)); - assertThat(actualClassification.getDomain(), equalTo(domain + "_2")); + assertThat(actualClassification.getDomain(), equalTo("DOMAIN_B")); assertThat(actualClassification.getId(), startsWith(ID_PREFIX_CLASSIFICATION)); // verify that Classification rootResults = classificationService.getClassification(key, ""); @@ -154,7 +155,8 @@ public class ClassificationServiceImplIntAutoCommitTest { @Test public void testFindAllClassifications() - throws ClassificationAlreadyExistException, NotAuthorizedException, ClassificationNotFoundException { + throws ClassificationAlreadyExistException, NotAuthorizedException, ClassificationNotFoundException, + DomainNotFoundException { Classification classification0 = this.createDummyClassificationWithUniqueKey("", "type1"); classificationService.createClassification(classification0); Classification classification1 = this.createDummyClassificationWithUniqueKey("", "type1"); @@ -169,9 +171,9 @@ public class ClassificationServiceImplIntAutoCommitTest { @Test public void testModifiedClassification() throws ClassificationAlreadyExistException, ClassificationNotFoundException, NotAuthorizedException, - ConcurrencyException { + ConcurrencyException, DomainNotFoundException { String description = "TEST SOMETHING"; - Classification classification = this.createDummyClassificationWithUniqueKey("domain1", "type1"); + Classification classification = this.createDummyClassificationWithUniqueKey("DOMAIN_A", "type1"); classification.setDescription(""); classification = classificationService.createClassification(classification); classification.setDescription("TEST SOMETHING"); @@ -184,8 +186,8 @@ public class ClassificationServiceImplIntAutoCommitTest { @Test public void testInsertAndClassificationMapper() throws NotAuthorizedException, ClassificationAlreadyExistException, ClassificationNotFoundException, - InvalidArgumentException { - Classification classification = this.createDummyClassificationWithUniqueKey("UNIQUE-DOMAIN", "type1"); + InvalidArgumentException, DomainNotFoundException { + Classification classification = this.createDummyClassificationWithUniqueKey("DOMAIN_A", "type1"); classification = classificationService.createClassification(classification); List list = classificationService.createClassificationQuery() @@ -199,8 +201,8 @@ public class ClassificationServiceImplIntAutoCommitTest { @Test public void testUpdateAndClassificationMapper() throws NotAuthorizedException, ClassificationAlreadyExistException, ClassificationNotFoundException, - ConcurrencyException { - Classification classification = this.createDummyClassificationWithUniqueKey("UNIQUE-DOMAIN", "type1"); + ConcurrencyException, DomainNotFoundException { + Classification classification = this.createDummyClassificationWithUniqueKey("DOMAIN_A", "type1"); classification = classificationService.createClassification(classification); classification.setDescription("description"); classification = classificationService.updateClassification(classification); @@ -221,29 +223,31 @@ public class ClassificationServiceImplIntAutoCommitTest { @Test public void testFindWithClassificationMapperDomainAndCategory() - throws ClassificationAlreadyExistException, NotAuthorizedException, ClassificationNotFoundException { - Classification classification1 = this.createDummyClassificationWithUniqueKey("domain1", "type1"); + throws ClassificationAlreadyExistException, NotAuthorizedException, ClassificationNotFoundException, + DomainNotFoundException { + Classification classification1 = this.createDummyClassificationWithUniqueKey("DOMAIN_A", "type1"); classification1.setCategory("category1"); classificationService.createClassification(classification1); - Classification classification2 = this.createDummyClassificationWithUniqueKey("domain2", "type1"); + Classification classification2 = this.createDummyClassificationWithUniqueKey("DOMAIN_B", "type1"); classification2.setCategory("category1"); classificationService.createClassification(classification2); - Classification classification3 = this.createDummyClassificationWithUniqueKey("domain1", "type1"); + Classification classification3 = this.createDummyClassificationWithUniqueKey("DOMAIN_A", "type1"); classification3.setCategory("category2"); classificationService.createClassification(classification3); List list = classificationService.createClassificationQuery() .categoryIn("category1") - .domainIn("domain1") + .domainIn("DOMAIN_A") .list(); Assert.assertEquals(1, list.size()); - list = classificationService.createClassificationQuery().domainIn("domain1", "domain3").list(); + list = classificationService.createClassificationQuery().domainIn("DOMAIN_A", "DOMAIN_C").list(); Assert.assertEquals(2, list.size()); } @Test public void testFindWithClassificationMapperCustomAndCategory() - throws ClassificationAlreadyExistException, NotAuthorizedException, ClassificationNotFoundException { + throws ClassificationAlreadyExistException, NotAuthorizedException, ClassificationNotFoundException, + DomainNotFoundException { Classification classification1 = this.createDummyClassificationWithUniqueKey("", "type1"); classification1.setDescription("DESC1"); classification1.setCategory("category1"); @@ -281,7 +285,7 @@ public class ClassificationServiceImplIntAutoCommitTest { @Test public void testFindWithClassificationMapperPriorityTypeAndParent() throws ClassificationAlreadyExistException, NumberFormatException, NotAuthorizedException, - ClassificationNotFoundException { + ClassificationNotFoundException, DomainNotFoundException { Classification classification = this.createDummyClassificationWithUniqueKey("", "type1"); classification.setPriority(Integer.decode("5")); classificationService.createClassification(classification); @@ -315,7 +319,8 @@ public class ClassificationServiceImplIntAutoCommitTest { @Test public void testFindWithClassificationMapperServiceLevelNameAndDescription() - throws ClassificationAlreadyExistException, NotAuthorizedException, ClassificationNotFoundException { + throws ClassificationAlreadyExistException, NotAuthorizedException, ClassificationNotFoundException, + DomainNotFoundException { int all = 0; Classification classification = this.createDummyClassificationWithUniqueKey("", "type1"); classification.setServiceLevel("P1D"); @@ -354,11 +359,11 @@ public class ClassificationServiceImplIntAutoCommitTest { @Test public void testDefaultSettingsWithClassificationMapper() throws NotAuthorizedException, ClassificationAlreadyExistException, ClassificationNotFoundException, - ConcurrencyException { - Classification classification = this.createDummyClassificationWithUniqueKey("UNIQUE-DOMAIN", "type1"); + ConcurrencyException, DomainNotFoundException { + Classification classification = this.createDummyClassificationWithUniqueKey("DOMAIN_A", "type1"); classification = classificationService.createClassification(classification); - Classification classification1 = this.createDummyClassificationWithUniqueKey("UNIQUE-DOMAIN", "type1"); + Classification classification1 = this.createDummyClassificationWithUniqueKey("DOMAIN_A", "type1"); classification1 = classificationService.createClassification(classification1); classification1.setParentId(classification.getId()); @@ -382,7 +387,7 @@ public class ClassificationServiceImplIntAutoCommitTest { list = classificationService.createClassificationQuery().createdWithin(today()).list(); Assert.assertEquals(4, list.size()); - list = classificationService.createClassificationQuery().domainIn("domain1").validInDomainEquals(false).list(); + list = classificationService.createClassificationQuery().domainIn("DOMAIN_C").validInDomainEquals(false).list(); Assert.assertEquals(0, list.size()); list = classificationService.createClassificationQuery() diff --git a/lib/taskana-core/src/test/java/pro/taskana/impl/integration/ClassificationServiceImplIntExplicitTest.java b/lib/taskana-core/src/test/java/pro/taskana/impl/integration/ClassificationServiceImplIntExplicitTest.java index 65df2333c..583def1ee 100644 --- a/lib/taskana-core/src/test/java/pro/taskana/impl/integration/ClassificationServiceImplIntExplicitTest.java +++ b/lib/taskana-core/src/test/java/pro/taskana/impl/integration/ClassificationServiceImplIntExplicitTest.java @@ -33,6 +33,7 @@ import pro.taskana.configuration.TaskanaEngineConfiguration; import pro.taskana.exceptions.ClassificationAlreadyExistException; import pro.taskana.exceptions.ClassificationNotFoundException; import pro.taskana.exceptions.ConcurrencyException; +import pro.taskana.exceptions.DomainNotFoundException; import pro.taskana.exceptions.InvalidArgumentException; import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.impl.ClassificationImpl; @@ -78,11 +79,11 @@ public class ClassificationServiceImplIntExplicitTest { @Test public void testInsertClassification() throws SQLException, ClassificationNotFoundException, ClassificationAlreadyExistException, - NotAuthorizedException { + NotAuthorizedException, DomainNotFoundException { Connection connection = dataSource.getConnection(); taskanaEngineImpl.setConnection(connection); - final String domain = "test-domain"; + final String domain = "DOMAIN_A"; final String key = "dummy-key"; ClassificationImpl expectedClassification; Classification actualClassification; @@ -136,15 +137,15 @@ public class ClassificationServiceImplIntExplicitTest { // new classification but root existing expectedClassification = (ClassificationImpl) this.createNewClassificationWithUniqueKey("", "t1"); expectedClassification.setKey(key); - expectedClassification.setDomain(domain + "_2"); + expectedClassification.setDomain("DOMAIN_B"); classificationService.createClassification(expectedClassification); connection.commit(); - actualClassification = classificationService.getClassification(key, domain + "_2"); + actualClassification = classificationService.getClassification(key, "DOMAIN_B"); assertThat(actualClassification, not(equalTo(null))); assertThat(actualClassification.getCreated(), not(equalTo(null))); assertThat(actualClassification.getId(), not(equalTo(null))); assertThat(actualClassification.getKey(), equalTo(key)); - assertThat(actualClassification.getDomain(), equalTo(domain + "_2")); + assertThat(actualClassification.getDomain(), equalTo("DOMAIN_B")); assertThat(actualClassification.getId(), startsWith(ID_PREFIX_CLASSIFICATION)); Classification rootResult = classificationService.getClassification(key, ""); assertThat(rootResult, not(equalTo(null))); @@ -165,7 +166,7 @@ public class ClassificationServiceImplIntExplicitTest { @Test public void testFindAllClassifications() throws SQLException, ClassificationAlreadyExistException, NotAuthorizedException, - ClassificationNotFoundException { + ClassificationNotFoundException, DomainNotFoundException { Connection connection = dataSource.getConnection(); taskanaEngineImpl.setConnection(connection); Classification classification0 = this.createNewClassificationWithUniqueKey("", "t1"); @@ -183,11 +184,11 @@ public class ClassificationServiceImplIntExplicitTest { @Test public void testModifiedClassification() throws SQLException, ClassificationAlreadyExistException, ClassificationNotFoundException, - NotAuthorizedException, ConcurrencyException { + NotAuthorizedException, ConcurrencyException, DomainNotFoundException { Connection connection = dataSource.getConnection(); taskanaEngineImpl.setConnection(connection); - Classification classification = this.createNewClassificationWithUniqueKey("novatec", "t1"); + Classification classification = this.createNewClassificationWithUniqueKey("DOMAIN_A", "t1"); connection.commit(); classification = classificationService.createClassification(classification); @@ -203,10 +204,10 @@ public class ClassificationServiceImplIntExplicitTest { @Test public void testInsertAndClassificationQuery() throws SQLException, ClassificationAlreadyExistException, NotAuthorizedException, - ClassificationNotFoundException { + ClassificationNotFoundException, DomainNotFoundException { Connection connection = dataSource.getConnection(); taskanaEngineImpl.setConnection(connection); - Classification classification = this.createNewClassificationWithUniqueKey("UNIQUE-DOMAIN", "t1"); + Classification classification = this.createNewClassificationWithUniqueKey("DOMAIN_A", "t1"); classificationService.createClassification(classification); List list = classificationService.createClassificationQuery() .validInDomainEquals(Boolean.TRUE) @@ -217,10 +218,11 @@ public class ClassificationServiceImplIntExplicitTest { @Test public void testUpdateAndClassificationQuery() throws NotAuthorizedException, SQLException, - ClassificationAlreadyExistException, ClassificationNotFoundException, ConcurrencyException { + ClassificationAlreadyExistException, ClassificationNotFoundException, ConcurrencyException, + DomainNotFoundException { Connection connection = dataSource.getConnection(); taskanaEngineImpl.setConnection(connection); - Classification classification = this.createNewClassificationWithUniqueKey("UNIQUE-DOMAIN", "t1"); + Classification classification = this.createNewClassificationWithUniqueKey("DOMAIN_A", "t1"); classification.setDescription(""); classification = classificationService.createClassification(classification); classification.setDescription("description"); @@ -247,26 +249,26 @@ public class ClassificationServiceImplIntExplicitTest { @Test public void testFindWithClassificationMapperDomainAndCategory() throws SQLException, ClassificationAlreadyExistException, NotAuthorizedException, - ClassificationNotFoundException { + ClassificationNotFoundException, DomainNotFoundException { Connection connection = dataSource.getConnection(); taskanaEngineImpl.setConnection(connection); - Classification classification1 = this.createNewClassificationWithUniqueKey("domain1", "t1"); + Classification classification1 = this.createNewClassificationWithUniqueKey("DOMAIN_A", "t1"); classification1.setCategory("category1"); classificationService.createClassification(classification1); - Classification classification2 = this.createNewClassificationWithUniqueKey("domain2", "t1"); + Classification classification2 = this.createNewClassificationWithUniqueKey("DOMAIN_B", "t1"); classification2.setCategory("category1"); classificationService.createClassification(classification2); - Classification classification3 = this.createNewClassificationWithUniqueKey("domain1", "t1"); + Classification classification3 = this.createNewClassificationWithUniqueKey("DOMAIN_A", "t1"); classification3.setCategory("category2"); classificationService.createClassification(classification3); List list = classificationService.createClassificationQuery() .categoryIn("category1") - .domainIn("domain1") + .domainIn("DOMAIN_A") .list(); Assert.assertEquals(1, list.size()); - list = classificationService.createClassificationQuery().domainIn("domain1", "domain3").list(); + list = classificationService.createClassificationQuery().domainIn("DOMAIN_A", "domain3").list(); Assert.assertEquals(2, list.size()); connection.commit(); } @@ -274,7 +276,7 @@ public class ClassificationServiceImplIntExplicitTest { @Test public void testFindWithClassificationMapperCustomAndCategory() throws SQLException, ClassificationAlreadyExistException, NotAuthorizedException, - ClassificationNotFoundException { + ClassificationNotFoundException, DomainNotFoundException { Connection connection = dataSource.getConnection(); taskanaEngineImpl.setConnection(connection); Classification classification1 = this.createNewClassificationWithUniqueKey("", "t1"); @@ -315,7 +317,7 @@ public class ClassificationServiceImplIntExplicitTest { @Test public void testFindWithClassificationMapperPriorityTypeAndParent() throws SQLException, ClassificationAlreadyExistException, NotAuthorizedException, - ClassificationNotFoundException { + ClassificationNotFoundException, DomainNotFoundException { Connection connection = dataSource.getConnection(); taskanaEngineImpl.setConnection(connection); Classification classification = this.createNewClassificationWithUniqueKey("", "type1"); @@ -352,7 +354,7 @@ public class ClassificationServiceImplIntExplicitTest { @Test public void testFindWithClassificationMapperServiceLevelNameAndDescription() throws NotAuthorizedException, SQLException, ClassificationAlreadyExistException, - ClassificationNotFoundException { + ClassificationNotFoundException, DomainNotFoundException { Connection connection = dataSource.getConnection(); taskanaEngineImpl.setConnection(connection); int all = 0; @@ -394,13 +396,13 @@ public class ClassificationServiceImplIntExplicitTest { @Test public void testDefaultSettingsWithClassificationQuery() throws NotAuthorizedException, SQLException, ClassificationAlreadyExistException, ClassificationNotFoundException, InvalidArgumentException, - ConcurrencyException { + ConcurrencyException, DomainNotFoundException { Connection connection = dataSource.getConnection(); taskanaEngineImpl.setConnection(connection); - Classification classification = this.createNewClassificationWithUniqueKey("UNIQUE-DOMAIN", "type1"); + Classification classification = this.createNewClassificationWithUniqueKey("DOMAIN_A", "type1"); classification = classificationService.createClassification(classification); - Classification classification1 = this.createNewClassificationWithUniqueKey("UNIQUE-DOMAIN", "type1"); + Classification classification1 = this.createNewClassificationWithUniqueKey("DOMAIN_A", "type1"); classification1 = classificationService.createClassification(classification1); classification1.setParentId(classification.getId()); classification1 = classificationService.updateClassification(classification1); @@ -418,7 +420,7 @@ public class ClassificationServiceImplIntExplicitTest { Assert.assertEquals(2, list.size()); list = classificationService.createClassificationQuery().createdWithin(today()).list(); Assert.assertEquals(4, list.size()); - list = classificationService.createClassificationQuery().domainIn("domain1").validInDomainEquals(false).list(); + list = classificationService.createClassificationQuery().domainIn("DOMAIN_C").validInDomainEquals(false).list(); Assert.assertEquals(0, list.size()); list = classificationService.createClassificationQuery() .keyIn(classification1.getKey()) diff --git a/lib/taskana-core/src/test/java/pro/taskana/impl/integration/TaskServiceImplIntAutocommitTest.java b/lib/taskana-core/src/test/java/pro/taskana/impl/integration/TaskServiceImplIntAutocommitTest.java index 3e8ca02c6..390c5df6a 100644 --- a/lib/taskana-core/src/test/java/pro/taskana/impl/integration/TaskServiceImplIntAutocommitTest.java +++ b/lib/taskana-core/src/test/java/pro/taskana/impl/integration/TaskServiceImplIntAutocommitTest.java @@ -301,7 +301,7 @@ public class TaskServiceImplIntAutocommitTest { workbasketService = taskanaEngine.getWorkbasketService(); ClassificationImpl classification = (ClassificationImpl) classificationService.newClassification("KEY", - "test-domain", "t1"); + "DOMAIN_A", "t1"); classification.setCategory("Test Classification"); classification.setName("Transfert-Task Classification"); classificationService.createClassification(classification); 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 319392406..30ed5d05b 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 @@ -25,6 +25,7 @@ import pro.taskana.ClassificationSummary; import pro.taskana.exceptions.ClassificationAlreadyExistException; import pro.taskana.exceptions.ClassificationNotFoundException; import pro.taskana.exceptions.ConcurrencyException; +import pro.taskana.exceptions.DomainNotFoundException; import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.rest.resource.ClassificationResource; import pro.taskana.rest.resource.mapper.ClassificationMapper; @@ -58,7 +59,7 @@ public class ClassificationController { @Transactional(readOnly = true, rollbackFor = Exception.class) public ResponseEntity getClassification(@PathVariable String classificationId) throws ClassificationNotFoundException, NotAuthorizedException, ClassificationAlreadyExistException, - ConcurrencyException { + ConcurrencyException, DomainNotFoundException { Classification classification = classificationService.getClassification(classificationId); return ResponseEntity.status(HttpStatus.OK).body(classificationMapper.toResource(classification)); } @@ -67,7 +68,7 @@ public class ClassificationController { @Transactional(readOnly = true, rollbackFor = Exception.class) public ResponseEntity getClassification(@PathVariable String classificationKey, @PathVariable String domain) throws ClassificationNotFoundException, NotAuthorizedException, - ClassificationAlreadyExistException, ConcurrencyException { + ClassificationAlreadyExistException, ConcurrencyException, DomainNotFoundException { Classification classification = classificationService.getClassification(classificationKey, domain); return ResponseEntity.status(HttpStatus.OK).body(classificationMapper.toResource(classification)); } @@ -86,7 +87,7 @@ public class ClassificationController { public ResponseEntity createClassification( @RequestBody ClassificationResource resource) throws NotAuthorizedException, ClassificationNotFoundException, ClassificationAlreadyExistException, - ConcurrencyException { + ConcurrencyException, DomainNotFoundException { Classification classification = classificationMapper.toModel(resource); classification = classificationService.createClassification(classification); return ResponseEntity.status(HttpStatus.CREATED).body(classificationMapper.toResource(classification)); @@ -96,7 +97,7 @@ public class ClassificationController { @Transactional(rollbackFor = Exception.class) public ResponseEntity updateClassification(@RequestBody ClassificationResource resource) throws NotAuthorizedException, ClassificationNotFoundException, ConcurrencyException, - ClassificationAlreadyExistException { + ClassificationAlreadyExistException, DomainNotFoundException { Classification classification = classificationMapper.toModel(resource); classification = classificationService.updateClassification(classification); return ResponseEntity.status(HttpStatus.OK).body(classificationMapper.toResource(classification)); 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 88aaf88ca..77c5b9aba 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 @@ -24,6 +24,7 @@ import pro.taskana.ClassificationSummary; import pro.taskana.exceptions.ClassificationAlreadyExistException; import pro.taskana.exceptions.ClassificationNotFoundException; import pro.taskana.exceptions.ConcurrencyException; +import pro.taskana.exceptions.DomainNotFoundException; import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.rest.resource.ClassificationResource; import pro.taskana.rest.resource.mapper.ClassificationMapper; @@ -45,7 +46,7 @@ public class ClassificationDefinitionController { @Transactional(readOnly = true, rollbackFor = Exception.class) public ResponseEntity> getClassifications( @RequestParam(required = false) String domain) throws ClassificationNotFoundException, NotAuthorizedException, - ClassificationAlreadyExistException, ConcurrencyException { + ClassificationAlreadyExistException, ConcurrencyException, DomainNotFoundException { ClassificationQuery query = classificationService.createClassificationQuery(); List summaries = domain != null ? query.domainIn(domain).list() : query.list(); List export = new ArrayList<>(); @@ -62,7 +63,8 @@ public class ClassificationDefinitionController { @Transactional(rollbackFor = Exception.class) public ResponseEntity importClassifications( @RequestBody List classificationResources) throws NotAuthorizedException, - ClassificationNotFoundException, ConcurrencyException, ClassificationAlreadyExistException { + ClassificationNotFoundException, ConcurrencyException, ClassificationAlreadyExistException, + DomainNotFoundException { Map systemIds = classificationService.createClassificationQuery() .list() .stream() diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/mapper/ClassificationMapper.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/mapper/ClassificationMapper.java index 55675b754..3dea54bf4 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/mapper/ClassificationMapper.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/mapper/ClassificationMapper.java @@ -14,6 +14,7 @@ import pro.taskana.ClassificationService; import pro.taskana.exceptions.ClassificationAlreadyExistException; import pro.taskana.exceptions.ClassificationNotFoundException; import pro.taskana.exceptions.ConcurrencyException; +import pro.taskana.exceptions.DomainNotFoundException; import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.impl.ClassificationImpl; import pro.taskana.rest.ClassificationController; @@ -29,7 +30,7 @@ public class ClassificationMapper { ClassificationService classificationService; public ClassificationResource toResource(Classification classification) throws ClassificationNotFoundException, - NotAuthorizedException, ClassificationAlreadyExistException, ConcurrencyException { + NotAuthorizedException, ClassificationAlreadyExistException, ConcurrencyException, DomainNotFoundException { ClassificationResource resource = new ClassificationResource(); BeanUtils.copyProperties(classification, resource); // need to be set by hand, because they are named different, or have different types @@ -52,7 +53,7 @@ public class ClassificationMapper { private ClassificationResource addLinks(ClassificationResource resource, Classification classification) throws ClassificationNotFoundException, NotAuthorizedException, ClassificationAlreadyExistException, - ConcurrencyException { + ConcurrencyException, DomainNotFoundException { resource.add( linkTo(methodOn(ClassificationController.class).getClassification(classification.getId())) .withSelfRel()); diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/mapper/ClassificationMapperTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/mapper/ClassificationMapperTest.java index 603ba0fb4..c9a43227e 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/mapper/ClassificationMapperTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/mapper/ClassificationMapperTest.java @@ -15,6 +15,7 @@ import pro.taskana.ClassificationService; import pro.taskana.exceptions.ClassificationAlreadyExistException; import pro.taskana.exceptions.ClassificationNotFoundException; import pro.taskana.exceptions.ConcurrencyException; +import pro.taskana.exceptions.DomainNotFoundException; import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.impl.ClassificationImpl; import pro.taskana.rest.RestConfiguration; @@ -36,7 +37,7 @@ public class ClassificationMapperTest { @Test public void classificationToResource() throws ClassificationNotFoundException, NotAuthorizedException, - ClassificationAlreadyExistException, ConcurrencyException { + ClassificationAlreadyExistException, ConcurrencyException, DomainNotFoundException { // given ClassificationImpl classification = (ClassificationImpl) classificationService.newClassification("DOMAIN_A", "1", "A");