Skip to content

Commit

Permalink
APPNG-2442 Working implementation of the feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
dheuvels committed Jul 9, 2022
1 parent 1bf4f96 commit 9834346
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 11 deletions.
3 changes: 3 additions & 0 deletions application-home/conf/datasources/ds-sites.xml
Expand Up @@ -161,6 +161,9 @@
<field name="host" type="text">
<label>host</label>
</field>
<field name="hostAliases" type="longtext" binding="hostAliases">
<label>hostAliases</label>
</field>
<field name="domain" type="text">
<label>domain</label>
</field>
Expand Down
5 changes: 3 additions & 2 deletions application-home/dictionary/manager-messages.properties
Expand Up @@ -351,8 +351,9 @@ 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 names of site "{0}"!
site.hostalias.exists=Hostname aliases overlap with names of site "{0}"!
site.host.exists=Hostname overlaps with hostnames of site "{0}"!
site.hostalias.exists=Hostname aliases overlap with hostnames of site "{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.
site.properties=Site properties
Expand Down
3 changes: 2 additions & 1 deletion application-home/dictionary/manager-messages_de.properties
Expand Up @@ -293,7 +293,8 @@ site.domain.exists=Eine andere Seite mit dieser Domäne existiert bereits!
site.edit=Site {0}
site.grant=Zugriff für Sites erlauben
site.host.exists=Dieser Hostname wird bereits als Name von der Seite "{0}" benutzt!
site.hostalias.exists=Einer dieser Alias Hostnamen wird bereits als Name von der Seite "{0}" benutzt!
site.hostalias.exists=Einer der Alias Hostnamen wird bereits als Name von der Seite "{0}" benutzt!
site.hostalias.invalid=Alias Hostname "{0}" ist kein valider Hostname.
site.name.exists=Eine andere Seite mit diesem Namen existiert bereits!
site.not.exists=Die angeforderte Site existiert nicht.
site.properties=Site Einstellungen
Expand Down
35 changes: 29 additions & 6 deletions src/main/java/org/appng/application/manager/form/SiteForm.java
Expand Up @@ -15,6 +15,7 @@
*/
package org.appng.application.manager.form;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand All @@ -23,15 +24,24 @@
import java.util.stream.Collectors;
import javax.validation.Valid;

import org.appng.api.Environment;
import org.appng.api.FieldProcessor;
import org.appng.api.FormValidator;
import org.appng.api.Options;
import org.appng.api.Request;
import org.appng.api.model.Application;
import org.appng.api.model.Site;
import org.appng.application.manager.MessageConstants;
import org.appng.core.domain.SiteImpl;
import org.appng.core.domain.ValidationPatterns;

/**
* Bindclass used for creating/updating a {@link SiteImpl}.
*
* @author Matthias Müller
*
*/
public class SiteForm {
public class SiteForm implements FormValidator {

private SiteImpl site;
private String template;
Expand Down Expand Up @@ -61,15 +71,19 @@ public void setTemplate(String template) {
this.template = template;
}

private List<String> _getHostAliases() {
return site.getHostNames().stream().filter(hn -> !site.getHost().equals(hn)).sorted()
.collect(Collectors.toList());
}

public String getHostAliases() {
List<String> hostAliases = site.getHostNames().stream().sorted().filter(
p -> !site.getHost().equals(p)).collect(Collectors.toList()
);
return String.join(System.lineSeparator(), hostAliases);
return String.join(System.lineSeparator(), _getHostAliases());
}

public void setHostAliases(String hostAliases) {
Set<String> hostnames = new HashSet<>();
Set<String> hostnames = new HashSet<String>();
hostnames.add(site.getHost());

Pattern splitPattern = Pattern.compile("^[ \t]*(.+?)[ \t]*$", Pattern.MULTILINE);
Matcher splitMatcher = splitPattern.matcher(hostAliases);
while(splitMatcher.find()) {
Expand All @@ -78,4 +92,13 @@ public void setHostAliases(String hostAliases) {
site.setHostNames(hostnames);
}

public void validate(Site site, Application application, Environment environment, Options options, Request request,
FieldProcessor fp) {
for (String name : _getHostAliases()) {
if (! Pattern.matches(ValidationPatterns.HOST_PATTERN, name))
fp.addErrorMessage(fp.getField("hostAliases"),
request.getMessage(MessageConstants.SITE_HOSTALIAS_INVALID, name));
}
}

}
Expand Up @@ -1091,9 +1091,11 @@ private void checkSite(Request request, Site site, FieldProcessor fp, Site curre
if (site.getId() == ovlSite.getId()) continue;
else {
if (ovlSite.getHostNames().contains(site.getHost()))
fp.addErrorMessage(fp.getField("site.host"), request.getMessage(MessageConstants.SITE_HOST_EXISTS, ovlSite.getName()));
fp.addErrorMessage(fp.getField("site.host"), request.getMessage(MessageConstants.SITE_HOST_EXISTS,
ovlSite.getName()));
else
fp.addErrorMessage(fp.getField("hostAliases"), request.getMessage(MessageConstants.SITE_HOSTALIAS_EXISTS, ovlSite.getName()));
fp.addErrorMessage(fp.getField("hostAliases"), request.getMessage(MessageConstants.SITE_HOSTALIAS_EXISTS,
ovlSite.getName()));
}
}
if (!siteRepository.isUnique(site.getId(), "domain", site.getDomain())) {
Expand Down

0 comments on commit 9834346

Please sign in to comment.