diff --git a/application-home/dictionary/manager-messages.properties b/application-home/dictionary/manager-messages.properties
index ce5a41c..c4ddc76 100644
--- a/application-home/dictionary/manager-messages.properties
+++ b/application-home/dictionary/manager-messages.properties
@@ -351,8 +351,10 @@ site.deleted=Site has been deleted.
site.domain.exists=A different site with this domain already exists!
site.edit=Site {0}
site.grant=Grant access to sites
-site.host.exists=Hostname overlaps with hostnames of site "{0}"!
-site.hostalias.exists=Hostname aliases overlap with hostnames of site "{0}"!
+site.host.inUse=Hostname ''{0}'' is used by site ''{1}''!
+site.host.isAlias=Hostname ''{0}'' is used as an alias by site ''{1}''!
+site.hostalias.isHostname=Hostname alias ''{0}'' is the hostname for site ''{1}''!
+site.hostalias.inUse=The following aliases are used by site ''{1}'': {0}
site.hostalias.invalid=Hostname alias "{0}" is not a valid hostname.
site.name.exists=A different site with this name already exists!
site.not.exists=Site does not exist.
diff --git a/pom.xml b/pom.xml
index a164ce6..a85a3a0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -21,7 +21,7 @@
org.appng
appng-application-parent
- 1.24.6-SNAPSHOT
+ 1.25.0-SNAPSHOT
diff --git a/src/main/java/org/appng/application/manager/service/ManagerService.java b/src/main/java/org/appng/application/manager/service/ManagerService.java
index 5f4ebe5..f11d211 100644
--- a/src/main/java/org/appng/application/manager/service/ManagerService.java
+++ b/src/main/java/org/appng/application/manager/service/ManagerService.java
@@ -32,6 +32,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.TimeZone;
@@ -39,9 +40,11 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
+import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import org.apache.commons.collections.comparators.ComparatorChain;
+import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.appng.api.ApplicationException;
@@ -119,6 +122,7 @@
import org.appng.core.xml.repository.Packages;
import org.appng.forms.FormUpload;
import org.appng.persistence.repository.SearchQuery;
+import org.appng.xml.platform.FieldDef;
import org.appng.xml.platform.Label;
import org.appng.xml.platform.Option;
import org.appng.xml.platform.Selection;
@@ -1085,19 +1089,32 @@ private void checkSite(Request request, Site site, FieldProcessor fp, Site curre
if (fp.hasField("site.name") && !siteRepository.isUnique(site.getId(), "name", site.getName())) {
fp.addErrorMessage(fp.getField("site.name"), request.getMessage(MessageConstants.SITE_NAME_EXISTS));
}
- Set hostnames = new HashSet(site.getHostAliases());
+ Set hostnames = new HashSet<>(site.getHostAliases());
hostnames.add(site.getHost());
List hostOverlapSites = siteRepository.findSitesForHostNames(hostnames);
for (SiteImpl ovlpSite : hostOverlapSites) {
- if (site.getId() == ovlpSite.getId())
- continue;
- else {
- if (ovlpSite.getHost().equals(site.getHost()) || ovlpSite.getHostAliases().contains(site.getHost()))
- fp.addErrorMessage(fp.getField("site.host"),
- request.getMessage(MessageConstants.SITE_HOST_EXISTS, ovlpSite.getName()));
- else
- fp.addErrorMessage(fp.getField("hostAliases"),
- request.getMessage(MessageConstants.SITE_HOSTALIAS_EXISTS, ovlpSite.getName()));
+ if (!Objects.equals(site.getId(), ovlpSite.getId())) {
+ FieldDef field = fp.getField("site.host");
+ Object arg = site.getHost();
+ String messageKey;
+ if (ovlpSite.getHost().equals(site.getHost())) {
+ messageKey = MessageConstants.SITE_HOST_IN_USE;
+ } else if (ovlpSite.getHostAliases().contains(site.getHost())) {
+ messageKey = MessageConstants.SITE_HOST_IS_ALIAS;
+ } else {
+ field = fp.getField("hostAliases");
+ if (site.getHostAliases().contains(ovlpSite.getHost())) {
+ messageKey = MessageConstants.SITE_HOSTALIAS_IS_HOSTNAME;
+ arg = ovlpSite.getHost();
+ } else {
+ messageKey = MessageConstants.SITE_HOSTALIAS_IN_USE;
+ Stream aliasesInUse = CollectionUtils
+ .intersection(site.getHostAliases(), ovlpSite.getHostAliases()).stream()
+ .map(s -> String.format("'%s'", s));
+ arg = StringUtils.join(aliasesInUse.iterator(), ", ");
+ }
+ }
+ fp.addErrorMessage(field, request.getMessage(messageKey, arg, ovlpSite.getName()));
}
}
if (!siteRepository.isUnique(site.getId(), "domain", site.getDomain())) {
diff --git a/src/test/java/org/appng/application/manager/business/SitesTest.java b/src/test/java/org/appng/application/manager/business/SitesTest.java
index b896b33..41b1e6c 100644
--- a/src/test/java/org/appng/application/manager/business/SitesTest.java
+++ b/src/test/java/org/appng/application/manager/business/SitesTest.java
@@ -16,19 +16,13 @@
package org.appng.application.manager.business;
import java.io.IOException;
-import java.net.URL;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
+import java.util.Set;
import org.appng.api.FieldProcessor;
import org.appng.api.Platform;
import org.appng.api.ProcessingException;
-import org.appng.api.model.Property;
-import org.appng.api.model.Site.SiteState;
import org.appng.api.support.CallableAction;
import org.appng.api.support.CallableDataSource;
-import org.appng.api.support.PropertyHolder;
import org.appng.application.manager.form.PropertyForm;
import org.appng.application.manager.form.SiteForm;
import org.appng.core.domain.PropertyImpl;
@@ -37,10 +31,10 @@
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
-import org.mockito.Mockito;
-import org.springframework.context.support.GenericApplicationContext;
import org.springframework.test.context.ContextConfiguration;
+import com.google.common.collect.Sets;
+
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@ContextConfiguration(inheritInitializers = false, initializers = SitesTest.class)
public class SitesTest extends AbstractTest {
@@ -55,14 +49,6 @@ public class SitesTest extends AbstractTest {
public void testCreateSite01() throws Exception {
propertyRepository.save(new PropertyImpl("platform." + Platform.Property.MESSAGING_ENABLED, null, "false"));
- SiteImpl siteToCreate = new SiteImpl();
- SiteForm siteForm = new SiteForm(siteToCreate);
- siteToCreate.setName("site1");
- siteToCreate.setHost("hostname1.domain.tld");
- siteToCreate.setHostAliases(new HashSet<>(Arrays.asList("doppeltes", "lottchen")));
- siteToCreate.setDomain("https://hostname1.domain.tld");
- siteToCreate.setActive(true);
-
// prepares using appNG >= 1.19.1
PropertyForm form = new PropertyForm();
form.getProperty().setName(Platform.Property.MESSAGING_ENABLED);
@@ -70,6 +56,8 @@ public void testCreateSite01() throws Exception {
getAction("propertyEvent", "create-platform-property").withParam(FORM_ACTION, "create-platform-property")
.getCallableAction(form).perform();
+ SiteForm siteForm = getSiteForm("site1", "hostname1.domain.tld", "https://hostname1.domain.tld",
+ Sets.newHashSet("doppeltes", "lottchen"));
CallableAction callableAction = getAction(SITE_EVENT, "create").withParam(FORM_ACTION, "create")
.getCallableAction(siteForm);
@@ -90,13 +78,8 @@ public void testCreateSite02ValidationFail() throws Exception {
@Test
public void testCreateSite03NameDuplicateFail() throws Exception {
- SiteImpl siteToCreate = new SiteImpl();
- SiteForm siteForm = new SiteForm(siteToCreate);
- siteToCreate.setName("site1");
- siteToCreate.setHost("other-hostname.domain.tld");
- siteToCreate.setDomain("https://other-hostname.domain.tld");
- siteToCreate.setActive(true);
-
+ SiteForm siteForm = getSiteForm("site1", "other-hostname.domain.tld", "https://other-hostname.domain.tld",
+ null);
CallableAction callableAction = getAction(SITE_EVENT, "create").withParam(FORM_ACTION, "create")
.getCallableAction(siteForm);
callableAction.perform();
@@ -105,13 +88,7 @@ public void testCreateSite03NameDuplicateFail() throws Exception {
@Test
public void testCreateSite04HostDuplicateFail() throws Exception {
- SiteImpl siteToCreate = new SiteImpl();
- SiteForm siteForm = new SiteForm(siteToCreate);
- siteToCreate.setName("other-site");
- siteToCreate.setHost("lottchen");
- siteToCreate.setDomain("https://other-hostname.domain.tld");
- siteToCreate.setActive(true);
-
+ SiteForm siteForm = getSiteForm("other-site", "lottchen", "https://other-hostname.domain.tld", null);
CallableAction callableAction = getAction(SITE_EVENT, "create").withParam(FORM_ACTION, "create")
.getCallableAction(siteForm);
callableAction.perform();
@@ -120,14 +97,18 @@ public void testCreateSite04HostDuplicateFail() throws Exception {
@Test
public void testCreateSite05AliasDuplicateFail() throws Exception {
- SiteImpl siteToCreate = new SiteImpl();
- SiteForm siteForm = new SiteForm(siteToCreate);
- siteToCreate.setName("other-site");
- siteToCreate.setHost("other-hostname.domain.tld");
- siteToCreate.setHostAliases(new HashSet<>(Arrays.asList("", "hostname1.domain.tld")));
- siteToCreate.setDomain("https://other-hostname.domain.tld");
- siteToCreate.setActive(true);
+ SiteForm siteForm = getSiteForm("other-site", "other-hostname.domain.tld", "https://other-hostname.domain.tld",
+ Sets.newHashSet("", "hostname1.domain.tld"));
+ CallableAction callableAction = getAction(SITE_EVENT, "create").withParam(FORM_ACTION, "create")
+ .getCallableAction(siteForm);
+ callableAction.perform();
+ validate(callableAction.getAction());
+ }
+ @Test
+ public void testCreateSite06AliasDuplicateFail() throws Exception {
+ SiteForm siteForm = getSiteForm("other-site", "other-hostname.domain.tld", "https://other-hostname.domain.tld",
+ Sets.newHashSet("doppeltes", "lottchen"));
CallableAction callableAction = getAction(SITE_EVENT, "create").withParam(FORM_ACTION, "create")
.getCallableAction(siteForm);
callableAction.perform();
@@ -161,10 +142,8 @@ public void testShowSite() throws Exception {
@Test
public void testShowSites() throws Exception {
createSite();
-
CallableDataSource siteDatasource = getDataSource("sites").getCallableDataSource();
siteDatasource.perform("test");
-
validate(siteDatasource.getDatasource());
}
@@ -177,6 +156,18 @@ public void testShowSitesFiltered() throws Exception {
validate(siteDatasource.getDatasource());
}
+ private SiteForm getSiteForm(String name, String host, String domain, Set aliases) {
+ SiteImpl siteToCreate = new SiteImpl();
+ siteToCreate.setName(name);
+ siteToCreate.setHost(host);
+ if (null != aliases) {
+ siteToCreate.setHostAliases(aliases);
+ }
+ siteToCreate.setDomain(domain);
+ siteToCreate.setActive(true);
+ return new SiteForm(siteToCreate);
+ }
+
private void createSite() {
SiteImpl realSite = new SiteImpl();
realSite.setName("site2");
diff --git a/src/test/resources/xml/SitesTest-testCreateSite03NameDuplicateFail.xml b/src/test/resources/xml/SitesTest-testCreateSite03NameDuplicateFail.xml
index 57b09e3..1c1e866 100644
--- a/src/test/resources/xml/SitesTest-testCreateSite03NameDuplicateFail.xml
+++ b/src/test/resources/xml/SitesTest-testCreateSite03NameDuplicateFail.xml
@@ -1,113 +1,114 @@
-
- Create site
-
-
-
-
- create
-
-
-
-
-
-
- Field must not be empty
-
-
- Enter at most 64 characters
-
-
- Please enter a valid name, which may only consist of letters, numbers and hyphens
-
-
-
- A different site with this name already exists!
-
-
-
-
-
-
- Field must not be empty
-
-
- Please enter a valid host (examples: localhost example.com some.example.com)
-
-
-
-
-
-
-
-
-
-
- Field must not be empty
-
-
- Please enter a valid domain (examples: http://www.example.com example.com localhost:8080)
-
-
-
-
-
-
-
- Enter at most 8192 characters
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Failed to create the site.
-
-
-
-
-
- Template
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- false
-
-
- false
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
+
+ Create site
+
+
+
+
+ create
+
+
+
+
+
+
+ Field must not be empty
+
+
+ Enter at most 64 characters
+
+
+ Please enter a valid name, which may only consist of letters, numbers and hyphens
+
+
+
+ A different site with this name already exists!
+
+
+
+
+
+
+ Field must not be empty
+
+
+ Please enter a valid host (examples: localhost example.com some.example.com)
+
+
+
+
+
+
+
+
+
+
+ Field must not be empty
+
+
+ Please enter a valid domain (examples: http://www.example.com example.com localhost:8080)
+
+
+
+
+
+
+
+ Enter at most 8192 characters
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Failed to create the site.
+
+
+
+
+
+ Template
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ false
+
+
+ false
+
+
+
+
+
+
+
+
+
+
diff --git a/src/test/resources/xml/SitesTest-testCreateSite04HostDuplicateFail.xml b/src/test/resources/xml/SitesTest-testCreateSite04HostDuplicateFail.xml
index 0db1002..422898b 100644
--- a/src/test/resources/xml/SitesTest-testCreateSite04HostDuplicateFail.xml
+++ b/src/test/resources/xml/SitesTest-testCreateSite04HostDuplicateFail.xml
@@ -1,113 +1,114 @@
-
- Create site
-
-
-
-
- create
-
-
-
-
-
-
- Field must not be empty
-
-
- Enter at most 64 characters
-
-
- Please enter a valid name, which may only consist of letters, numbers and hyphens
-
-
-
-
-
-
-
- Field must not be empty
-
-
- Please enter a valid host (examples: localhost example.com some.example.com)
-
-
-
- Hostname overlaps with hostnames of site "site1"!
-
-
-
-
-
-
-
-
-
- Field must not be empty
-
-
- Please enter a valid domain (examples: http://www.example.com example.com localhost:8080)
-
-
-
-
-
-
-
- Enter at most 8192 characters
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Failed to create the site.
-
-
-
-
-
- Template
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- false
-
-
- false
-
-
-
-
-
-
-
-
-
+
+ Create site
+
+
+
+
+ create
+
+
+
+
+
+
+ Field must not be empty
+
+
+ Enter at most 64 characters
+
+
+ Please enter a valid name, which may only consist of letters, numbers and hyphens
+
+
+
+
+
+
+
+ Field must not be empty
+
+
+ Please enter a valid host (examples: localhost example.com some.example.com)
+
+
+
+ Hostname 'lottchen' is used as an alias by site 'site1'!
+
+
+
+
+
+
+
+
+
+ Field must not be empty
+
+
+ Please enter a valid domain (examples: http://www.example.com example.com localhost:8080)
+
+
+
+
+
+
+
+ Enter at most 8192 characters
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Failed to create the site.
+
+
+
+
+
+ Template
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ false
+
+
+ false
+
+
+
+
+
+
+
+
+
diff --git a/src/test/resources/xml/SitesTest-testCreateSite05AliasDuplicateFail.xml b/src/test/resources/xml/SitesTest-testCreateSite05AliasDuplicateFail.xml
index cb8ef81..90a24fd 100644
--- a/src/test/resources/xml/SitesTest-testCreateSite05AliasDuplicateFail.xml
+++ b/src/test/resources/xml/SitesTest-testCreateSite05AliasDuplicateFail.xml
@@ -1,113 +1,114 @@
-
- Create site
-
-
-
-
- create
-
-
-
-
-
-
- Field must not be empty
-
-
- Enter at most 64 characters
-
-
- Please enter a valid name, which may only consist of letters, numbers and hyphens
-
-
-
-
-
-
-
- Field must not be empty
-
-
- Please enter a valid host (examples: localhost example.com some.example.com)
-
-
-
-
-
-
- Hostname aliases overlap with hostnames of site "site1"!
-
-
-
-
-
-
- Field must not be empty
-
-
- Please enter a valid domain (examples: http://www.example.com example.com localhost:8080)
-
-
-
-
-
-
-
- Enter at most 8192 characters
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Failed to create the site.
-
-
-
-
-
- Template
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- false
-
-
- false
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
+
+ Create site
+
+
+
+
+ create
+
+
+
+
+
+
+ Field must not be empty
+
+
+ Enter at most 64 characters
+
+
+ Please enter a valid name, which may only consist of letters, numbers and hyphens
+
+
+
+
+
+
+
+ Field must not be empty
+
+
+ Please enter a valid host (examples: localhost example.com some.example.com)
+
+
+
+
+
+
+ Hostname alias 'hostname1.domain.tld' is the hostname for site 'site1'!
+
+
+
+
+
+
+ Field must not be empty
+
+
+ Please enter a valid domain (examples: http://www.example.com example.com localhost:8080)
+
+
+
+
+
+
+
+ Enter at most 8192 characters
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Failed to create the site.
+
+
+
+
+
+ Template
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ false
+
+
+ false
+
+
+
+
+
+
+
+
+
+
diff --git a/src/test/resources/xml/SitesTest-testCreateSite06AliasDuplicateFail.xml b/src/test/resources/xml/SitesTest-testCreateSite06AliasDuplicateFail.xml
new file mode 100644
index 0000000..d84dfad
--- /dev/null
+++ b/src/test/resources/xml/SitesTest-testCreateSite06AliasDuplicateFail.xml
@@ -0,0 +1,114 @@
+
+
+
+ Create site
+
+
+
+
+ create
+
+
+
+
+
+
+ Field must not be empty
+
+
+ Enter at most 64 characters
+
+
+ Please enter a valid name, which may only consist of letters, numbers and hyphens
+
+
+
+
+
+
+
+ Field must not be empty
+
+
+ Please enter a valid host (examples: localhost example.com some.example.com)
+
+
+
+
+
+
+ The following aliases are used by site 'site1': 'lottchen', 'doppeltes'
+
+
+
+
+
+
+ Field must not be empty
+
+
+ Please enter a valid domain (examples: http://www.example.com example.com localhost:8080)
+
+
+
+
+
+
+
+ Enter at most 8192 characters
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Failed to create the site.
+
+
+
+
+
+ Template
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ false
+
+
+ false
+
+
+
+
+
+
+
+
+
+