2016-11-25 15:42:29 +01:00
|
|
|
package org.gcube.smartgears.configuration.application;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.LinkedHashSet;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import javax.xml.bind.annotation.XmlElement;
|
|
|
|
import javax.xml.bind.annotation.XmlElementRef;
|
|
|
|
import javax.xml.bind.annotation.XmlRootElement;
|
|
|
|
|
|
|
|
import org.gcube.common.validator.ValidationError;
|
|
|
|
import org.gcube.common.validator.Validator;
|
|
|
|
import org.gcube.common.validator.ValidatorFactory;
|
|
|
|
import org.gcube.common.validator.annotations.IsValid;
|
|
|
|
import org.gcube.common.validator.annotations.NotNull;
|
2022-03-17 17:17:15 +01:00
|
|
|
import org.gcube.smartgears.configuration.ProxyAddress;
|
|
|
|
import org.gcube.smartgears.persistence.PersistenceWriter;
|
2016-11-25 15:42:29 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The configuration of a managed app.
|
|
|
|
* <p>
|
|
|
|
* Includes the list of its client services.
|
|
|
|
*
|
|
|
|
* @author Fabio Simeoni
|
2021-02-22 09:49:18 +01:00
|
|
|
* @author Luca Frosini (ISTI - CNR)
|
2016-11-25 15:42:29 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
@XmlRootElement(name="application")
|
|
|
|
public class DefaultApplicationConfiguration implements ApplicationConfiguration {
|
|
|
|
|
|
|
|
String context;
|
2019-01-16 15:37:56 +01:00
|
|
|
|
2016-11-25 15:42:29 +01:00
|
|
|
@XmlElement(name="name" , required=true)
|
|
|
|
@NotNull
|
|
|
|
String name;
|
|
|
|
|
|
|
|
@XmlElement(name="group", required=true)
|
|
|
|
@NotNull
|
|
|
|
String group;
|
|
|
|
|
|
|
|
@XmlElement(name="version", required=true)
|
|
|
|
@NotNull
|
|
|
|
String version;
|
|
|
|
|
|
|
|
@XmlElement(name="description")
|
|
|
|
String description="";
|
|
|
|
|
2019-01-16 15:37:56 +01:00
|
|
|
@IsValid
|
|
|
|
ProxyAddress proxyAddress;
|
|
|
|
|
2016-11-25 15:42:29 +01:00
|
|
|
@XmlElementRef
|
|
|
|
Set<Exclude> excludes= new LinkedHashSet<Exclude>();
|
2018-12-10 18:36:19 +01:00
|
|
|
|
|
|
|
@XmlElementRef
|
|
|
|
Set<Include> includes= new LinkedHashSet<Include>();
|
2022-03-17 17:17:15 +01:00
|
|
|
|
2016-11-25 15:42:29 +01:00
|
|
|
@NotNull @IsValid
|
2022-03-17 17:17:15 +01:00
|
|
|
private PersistenceWriter persistenceManager;
|
2016-11-25 15:42:29 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Set<Exclude> excludes() {
|
|
|
|
return excludes;
|
|
|
|
}
|
2019-01-16 15:37:56 +01:00
|
|
|
|
2016-11-25 15:42:29 +01:00
|
|
|
|
2018-12-10 18:36:19 +01:00
|
|
|
@Override
|
|
|
|
public Set<Include> includes() {
|
|
|
|
return includes;
|
|
|
|
}
|
|
|
|
|
2016-11-25 15:42:29 +01:00
|
|
|
public DefaultApplicationConfiguration() {}
|
2022-03-17 17:17:15 +01:00
|
|
|
|
2016-11-25 15:42:29 +01:00
|
|
|
@Override
|
|
|
|
public String name() {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String context() {
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ApplicationConfiguration context(String context) {
|
|
|
|
this.context=context;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2019-01-16 15:37:56 +01:00
|
|
|
public ProxyAddress proxyAddress() {
|
|
|
|
return proxyAddress;
|
|
|
|
}
|
|
|
|
|
2016-11-25 15:42:29 +01:00
|
|
|
@Override
|
|
|
|
public ApplicationConfiguration excludes(Exclude ... excludes) {
|
|
|
|
this.excludes=new HashSet<Exclude>(Arrays.asList(excludes));
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2018-12-10 18:36:19 +01:00
|
|
|
@Override
|
|
|
|
public ApplicationConfiguration includes(Include... includes) {
|
|
|
|
this.includes=new HashSet<Include>(Arrays.asList(includes));
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2016-11-25 15:42:29 +01:00
|
|
|
@Override
|
|
|
|
public ApplicationConfiguration name(String name) {
|
|
|
|
this.name=name;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String serviceClass() {
|
|
|
|
return group;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ApplicationConfiguration serviceClass(String group) {
|
|
|
|
this.group=group;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String version() {
|
|
|
|
return version;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ApplicationConfiguration version(String version) {
|
|
|
|
this.version=version;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String description() {
|
|
|
|
return description;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ApplicationConfiguration description(String description) {
|
|
|
|
this.description=description;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2019-01-16 15:37:56 +01:00
|
|
|
@Override
|
|
|
|
public boolean proxied() {
|
|
|
|
return proxyAddress!=null;
|
|
|
|
}
|
2016-11-25 15:42:29 +01:00
|
|
|
|
|
|
|
@Override
|
2022-03-17 17:17:15 +01:00
|
|
|
public PersistenceWriter persistence() {
|
2016-11-25 15:42:29 +01:00
|
|
|
return persistenceManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-03-17 17:17:15 +01:00
|
|
|
public ApplicationConfiguration persistence(PersistenceWriter manager) {
|
2016-11-25 15:42:29 +01:00
|
|
|
this.persistenceManager=manager;
|
|
|
|
return this;
|
|
|
|
}
|
2019-01-16 15:37:56 +01:00
|
|
|
|
2016-11-25 15:42:29 +01:00
|
|
|
@Override
|
2019-01-16 15:37:56 +01:00
|
|
|
public ApplicationConfiguration proxyAddress(ProxyAddress proxyaddress) {
|
|
|
|
this.proxyAddress = proxyaddress;
|
2016-11-25 15:42:29 +01:00
|
|
|
return this;
|
|
|
|
}
|
2022-03-17 17:17:15 +01:00
|
|
|
|
2016-11-25 15:42:29 +01:00
|
|
|
@Override
|
|
|
|
public void validate() {
|
|
|
|
|
|
|
|
List<String> msgs = new ArrayList<String>();
|
|
|
|
|
|
|
|
Validator validator = ValidatorFactory.validator();
|
|
|
|
|
|
|
|
for (ValidationError error : validator.validate(this))
|
|
|
|
msgs.add(error.toString());
|
|
|
|
|
2018-12-10 18:36:19 +01:00
|
|
|
if (!this.excludes().isEmpty() && !this.includes().isEmpty())
|
|
|
|
msgs.add("exclude tags and includes tags are mutually exclusive");
|
|
|
|
|
2016-11-25 15:42:29 +01:00
|
|
|
if (!msgs.isEmpty())
|
|
|
|
throw new IllegalStateException("invalid configuration: "+msgs);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void merge(ApplicationConfiguration config) {
|
2022-03-17 17:17:15 +01:00
|
|
|
|
2016-11-25 15:42:29 +01:00
|
|
|
if (config.persistence()!=null)
|
|
|
|
persistence(config.persistence());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-03-21 11:17:07 +01:00
|
|
|
|
2016-11-25 15:42:29 +01:00
|
|
|
|
|
|
|
}
|