diff --git a/dmp-backend/web/src/main/java/eu/eudat/configurations/dynamicproject/DynamicProjectConfiguration.java b/dmp-backend/web/src/main/java/eu/eudat/configurations/dynamicproject/DynamicProjectConfiguration.java new file mode 100644 index 000000000..2008a37f7 --- /dev/null +++ b/dmp-backend/web/src/main/java/eu/eudat/configurations/dynamicproject/DynamicProjectConfiguration.java @@ -0,0 +1,12 @@ +package eu.eudat.configurations.dynamicproject; + +import eu.eudat.configurations.dynamicgrant.entities.Configuration; +import eu.eudat.models.data.dynamicfields.DynamicField; + +import java.util.List; + +public interface DynamicProjectConfiguration { + Configuration getConfiguration(); + + List getFields(); +} diff --git a/dmp-backend/web/src/main/java/eu/eudat/configurations/dynamicproject/DynamicProjectConfigurationDevelImpl.java b/dmp-backend/web/src/main/java/eu/eudat/configurations/dynamicproject/DynamicProjectConfigurationDevelImpl.java new file mode 100644 index 000000000..d2585fb34 --- /dev/null +++ b/dmp-backend/web/src/main/java/eu/eudat/configurations/dynamicproject/DynamicProjectConfigurationDevelImpl.java @@ -0,0 +1,85 @@ +package eu.eudat.configurations.dynamicproject; + +import eu.eudat.configurations.dynamicgrant.entities.Configuration; +import eu.eudat.configurations.dynamicgrant.entities.Property; +import eu.eudat.models.data.dynamicfields.Dependency; +import eu.eudat.models.data.dynamicfields.DynamicField; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Profile; +import org.springframework.core.env.Environment; +import org.springframework.stereotype.Service; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Unmarshaller; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.LinkedList; +import java.util.List; + +@Service("dynamicProjectConfiguration") +@Profile("devel") +public class DynamicProjectConfigurationDevelImpl implements DynamicProjectConfiguration{ + + private Configuration configuration; + private List fields; + private Environment environment; + + @Autowired + public DynamicProjectConfigurationDevelImpl(Environment environment) { + this.environment = environment; + } + + @Override + public Configuration getConfiguration() { + if (this.configuration != null) return this.configuration; + String fileUrl = this.environment.getProperty("configuration.dynamicProjectUrl"); + System.out.println("Loaded also config file: " + fileUrl); + String current = null; + InputStream is = null; + try { + current = new java.io.File(".").getCanonicalPath(); + + JAXBContext jaxbContext = JAXBContext.newInstance(Configuration.class); + Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); + is = new URL("file:///"+current + "/web/src/main/resources/ProjectConfiguration.xml").openStream(); + this.configuration = (Configuration) jaxbUnmarshaller.unmarshal(is); + } catch (Exception ex) { + ex.printStackTrace(); + System.out.println("Cannot find in folder" + current); + } finally { + try { + if (is != null) is.close(); + } catch (IOException e) { + System.out.println("Warning: Could not close a stream after reading from file: " + fileUrl); + } + } + return this.configuration; + } + + @Override + public List getFields() { + if (this.fields != null) return this.fields; + Configuration configuration = this.getConfiguration(); + List fields = new LinkedList<>(); + List properties = configuration.getConfigurationProperties(); + properties.stream().forEach(item -> { + DynamicField dynamicField = new DynamicField(); + dynamicField.setId(item.getId()); + dynamicField.setName(item.getName()); + dynamicField.setQueryProperty(item.getQueryProperty()); + dynamicField.setRequired(item.getRequired()); + List dependencies = new LinkedList<>(); + item.getDependencies().stream().forEach(dependency -> { + Dependency modelDependency = new Dependency(); + modelDependency.setId(dependency.getId()); + modelDependency.setQueryProperty(dependency.getQueryProperty()); + dependencies.add(modelDependency); + }); + dynamicField.setDependencies(dependencies); + fields.add(dynamicField); + }); + this.fields = fields; + return fields; + } +} diff --git a/dmp-backend/web/src/main/java/eu/eudat/configurations/dynamicproject/DynamicProjectConfigurationProdImpl.java b/dmp-backend/web/src/main/java/eu/eudat/configurations/dynamicproject/DynamicProjectConfigurationProdImpl.java new file mode 100644 index 000000000..7c196fe07 --- /dev/null +++ b/dmp-backend/web/src/main/java/eu/eudat/configurations/dynamicproject/DynamicProjectConfigurationProdImpl.java @@ -0,0 +1,88 @@ +package eu.eudat.configurations.dynamicproject; + +import eu.eudat.configurations.dynamicgrant.entities.Configuration; +import eu.eudat.configurations.dynamicgrant.entities.Property; +import eu.eudat.models.data.dynamicfields.Dependency; +import eu.eudat.models.data.dynamicfields.DynamicField; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Profile; +import org.springframework.core.env.Environment; +import org.springframework.stereotype.Service; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Unmarshaller; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.nio.file.Paths; +import java.util.LinkedList; +import java.util.List; + +@Service("dynamicProjectConfiguration") +@Profile({ "production", "staging" }) +public class DynamicProjectConfigurationProdImpl implements DynamicProjectConfiguration{ + + private Configuration configuration; + + private List fields; + + private Environment environment; + + @Autowired + public DynamicProjectConfigurationProdImpl(Environment environment) { + this.environment = environment; + } + + @Override + public Configuration getConfiguration() { + if (this.configuration != null) return this.configuration; + String fileUrl = this.environment.getProperty("configuration.dynamicProjectUrl"); + System.out.println("Loaded also config file: " + fileUrl); + String current = null; + InputStream is = null; + try { + current = new java.io.File(".").getCanonicalPath(); + + JAXBContext jaxbContext = JAXBContext.newInstance(Configuration.class); + Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); + is = new URL(Paths.get(fileUrl).toUri().toURL().toString()).openStream(); + this.configuration = (Configuration) jaxbUnmarshaller.unmarshal(is); + } catch (Exception ex) { + ex.printStackTrace(); + System.out.println("Cannot find in folder" + current); + } finally { + try { + if (is != null) is.close(); + } catch (IOException e) { + System.out.println("Warning: Could not close a stream after reading from file: " + fileUrl); + } + } + return this.configuration; + } + + @Override + public List getFields() { + if (this.fields != null) return this.fields; + Configuration configuration = this.getConfiguration(); + List fields = new LinkedList<>(); + List properties = configuration.getConfigurationProperties(); + properties.stream().forEach(item -> { + DynamicField dynamicField = new DynamicField(); + dynamicField.setId(item.getId()); + dynamicField.setName(item.getName()); + dynamicField.setQueryProperty(item.getQueryProperty()); + dynamicField.setRequired(item.getRequired()); + List dependencies = new LinkedList<>(); + item.getDependencies().stream().forEach(dependency -> { + Dependency modelDependency = new Dependency(); + modelDependency.setId(dependency.getId()); + modelDependency.setQueryProperty(dependency.getQueryProperty()); + dependencies.add(modelDependency); + }); + dynamicField.setDependencies(dependencies); + fields.add(dynamicField); + }); + this.fields = fields; + return fields; + } +} diff --git a/dmp-backend/web/src/main/java/eu/eudat/configurations/dynamicproject/entities/Configuration.java b/dmp-backend/web/src/main/java/eu/eudat/configurations/dynamicproject/entities/Configuration.java new file mode 100644 index 000000000..ac09b4ad0 --- /dev/null +++ b/dmp-backend/web/src/main/java/eu/eudat/configurations/dynamicproject/entities/Configuration.java @@ -0,0 +1,32 @@ +package eu.eudat.configurations.dynamicproject.entities; + + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.List; + +@XmlRootElement +public class Configuration { + private List configurationProperties; + private MainProperty mainExternalField; + + public MainProperty getMainExternalField() { + return mainExternalField; + } + + @XmlElement(name = "mainExternalField") + public void setMainExternalField(MainProperty mainExternalField) { + this.mainExternalField = mainExternalField; + } + + public List getConfigurationProperties() { + return configurationProperties; + } + + @XmlElementWrapper + @XmlElement(name = "property") + public void setConfigurationProperties(List configurationProperties) { + this.configurationProperties = configurationProperties; + } +} diff --git a/dmp-backend/web/src/main/java/eu/eudat/configurations/dynamicproject/entities/Dependency.java b/dmp-backend/web/src/main/java/eu/eudat/configurations/dynamicproject/entities/Dependency.java new file mode 100644 index 000000000..f5a320b3f --- /dev/null +++ b/dmp-backend/web/src/main/java/eu/eudat/configurations/dynamicproject/entities/Dependency.java @@ -0,0 +1,26 @@ +package eu.eudat.configurations.dynamicproject.entities; + +import javax.xml.bind.annotation.XmlElement; + +public class Dependency { + private String id; + private String queryProperty; + + public String getId() { + return id; + } + + public String getQueryProperty() { + return queryProperty; + } + + @XmlElement(name = "id") + public void setId(String id) { + this.id = id; + } + + @XmlElement(name = "queryProperty") + public void setQueryProperty(String queryProperty) { + this.queryProperty = queryProperty; + } +} diff --git a/dmp-backend/web/src/main/java/eu/eudat/configurations/dynamicproject/entities/Language.java b/dmp-backend/web/src/main/java/eu/eudat/configurations/dynamicproject/entities/Language.java new file mode 100644 index 000000000..3039a96c9 --- /dev/null +++ b/dmp-backend/web/src/main/java/eu/eudat/configurations/dynamicproject/entities/Language.java @@ -0,0 +1,26 @@ +package eu.eudat.configurations.dynamicproject.entities; + +import javax.xml.bind.annotation.XmlElement; + +public class Language { + private String key; + private String languageKey; + + public String getKey() { + return key; + } + + @XmlElement(name = "key") + public void setKey(String key) { + this.key = key; + } + + public String getLanguageKey() { + return languageKey; + } + + @XmlElement(name = "languageKey") + public void setLanguageKey(String languageKey) { + this.languageKey = languageKey; + } +} diff --git a/dmp-backend/web/src/main/java/eu/eudat/configurations/dynamicproject/entities/MainProperty.java b/dmp-backend/web/src/main/java/eu/eudat/configurations/dynamicproject/entities/MainProperty.java new file mode 100644 index 000000000..3eab4f3b5 --- /dev/null +++ b/dmp-backend/web/src/main/java/eu/eudat/configurations/dynamicproject/entities/MainProperty.java @@ -0,0 +1,103 @@ +package eu.eudat.configurations.dynamicproject.entities; + +import eu.eudat.logic.proxy.config.UrlConfiguration; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import java.util.List; + +public class MainProperty { + private String id; + private String name; + private String queryProperty; + private String externalFieldId; + private UrlConfiguration urlConfig; + private String externalFieldLabel; + private List dependencies; + private Boolean required; + private List language; + + + public String getId() { + return id; + } + + @XmlElement(name = "id") + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + @XmlElement(name = "name") + public void setName(String name) { + this.name = name; + } + + public String getExternalFieldId() { + return externalFieldId; + } + + @XmlElement(name = "externalFieldId") + public void setExternalFieldId(String externalFieldId) { + this.externalFieldId = externalFieldId; + } + + public String getExternalFieldLabel() { + return externalFieldLabel; + } + + @XmlElement(name = "externalFieldLabel") + public void setExternalFieldLabel(String externalFieldLabel) { + this.externalFieldLabel = externalFieldLabel; + } + + public List getDependencies() { + return dependencies; + } + + @XmlElementWrapper + @XmlElement(name = "dependency") + public void setDependencies(List dependencies) { + this.dependencies = dependencies; + } + + public Boolean getRequired() { + return required; + } + + @XmlElement(name = "required") + public void setRequired(Boolean required) { + this.required = required; + } + + public String getQueryProperty() { + return queryProperty; + } + + @XmlElement(name = "queryProperty") + public void setQueryProperty(String queryProperty) { + this.queryProperty = queryProperty; + } + + public UrlConfiguration getUrlConfig() { + return urlConfig; + } + + @XmlElement(name = "urlConfig") + public void setUrlConfig(UrlConfiguration urlConfig) { + this.urlConfig = urlConfig; + } + + public List getLanguage() { + return language; + } + + @XmlElementWrapper + @XmlElement(name = "languageProperty") + public void setLanguage(List language) { + this.language = language; + } +} diff --git a/dmp-backend/web/src/main/java/eu/eudat/configurations/dynamicproject/entities/Property.java b/dmp-backend/web/src/main/java/eu/eudat/configurations/dynamicproject/entities/Property.java new file mode 100644 index 000000000..8dc4f4ae9 --- /dev/null +++ b/dmp-backend/web/src/main/java/eu/eudat/configurations/dynamicproject/entities/Property.java @@ -0,0 +1,91 @@ +package eu.eudat.configurations.dynamicproject.entities; + + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import java.util.List; + +public class Property { + private String id; + private String name; + private String sourceUrl; + private String queryProperty; + private String externalFieldId; + private String externalFieldLabel; + private List dependencies; + private Boolean required; + + + public String getId() { + return id; + } + + @XmlElement(name = "id") + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + @XmlElement(name = "name") + public void setName(String name) { + this.name = name; + } + + public String getSourceUrl() { + return sourceUrl; + } + + @XmlElement(name = "sourceUrl") + public void setSourceUrl(String sourceUrl) { + this.sourceUrl = sourceUrl; + } + + public String getExternalFieldId() { + return externalFieldId; + } + + @XmlElement(name = "externalFieldId") + public void setExternalFieldId(String externalFieldId) { + this.externalFieldId = externalFieldId; + } + + public String getExternalFieldLabel() { + return externalFieldLabel; + } + + @XmlElement(name = "externalFieldLabel") + public void setExternalFieldLabel(String externalFieldLabel) { + this.externalFieldLabel = externalFieldLabel; + } + + public List getDependencies() { + return dependencies; + } + + @XmlElementWrapper + @XmlElement(name = "dependency") + public void setDependencies(List dependencies) { + this.dependencies = dependencies; + } + + public Boolean getRequired() { + return required; + } + + @XmlElement(name = "required") + public void setRequired(Boolean required) { + this.required = required; + } + + public String getQueryProperty() { + return queryProperty; + } + + @XmlElement(name = "queryProperty") + public void setQueryProperty(String queryProperty) { + this.queryProperty = queryProperty; + } +}