backend dynamic field cleanup

This commit is contained in:
Diamantis Tziotzios 2024-01-17 10:42:46 +02:00
parent aab7571763
commit 85e299a4b8
27 changed files with 51 additions and 1503 deletions

View File

@ -1,28 +0,0 @@
package eu.eudat.configurations;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* Created by ikalyvas on 9/26/2018.
*/
@Configuration
public class ExecutorServiceConfig {
@Bean
public Executor asyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(2);
executor.setMaxPoolSize(2);
executor.setQueueCapacity(500);
executor.setThreadNamePrefix("Rules-");
executor.initialize();
return executor;
}
}

View File

@ -1,12 +0,0 @@
package eu.eudat.configurations.dynamicfunder;
import eu.eudat.configurations.dynamicfunder.entities.Configuration;
import eu.eudat.models.data.dynamicfields.DynamicField;
import java.util.List;
public interface DynamicFunderConfiguration {
Configuration getConfiguration();
List<DynamicField> getFields();
}

View File

@ -1,85 +0,0 @@
package eu.eudat.configurations.dynamicfunder;
import eu.eudat.configurations.dynamicfunder.entities.Configuration;
import eu.eudat.configurations.dynamicfunder.entities.Property;
import eu.eudat.models.data.dynamicfields.Dependency;
import eu.eudat.models.data.dynamicfields.DynamicField;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.Unmarshaller;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.LinkedList;
import java.util.List;
@Service("dynamicFunderConfiguration")
@Profile("devel")
public class DynamicFunderConfigurationDevelImpl implements DynamicFunderConfiguration {
private static final Logger logger = LoggerFactory.getLogger(DynamicFunderConfigurationDevelImpl.class);
private Configuration configuration;
private List<DynamicField> fields;
private Environment environment;
public DynamicFunderConfigurationDevelImpl(Environment environment) {
this.environment = environment;
}
@Override
public Configuration getConfiguration() {
if (this.configuration != null) return this.configuration;
String fileUrl = this.environment.getProperty("configuration.dynamicFunderUrl");
logger.info("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/FunderConfiguration.xml").openStream();
this.configuration = (Configuration) jaxbUnmarshaller.unmarshal(is);
} catch (Exception ex) {
logger.error("Cannot find in folder" + current, ex);
} finally {
try {
if (is != null) is.close();
} catch (IOException e) {
logger.warn("Warning: Could not close a stream after reading from file: " + fileUrl, e);
}
}
return this.configuration;
}
@Override
public List<DynamicField> getFields() {
if (this.fields != null) return this.fields;
Configuration configuration = this.getConfiguration();
List<DynamicField> fields = new LinkedList<>();
List<Property> 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<Dependency> 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;
}
}

View File

@ -1,86 +0,0 @@
package eu.eudat.configurations.dynamicfunder;
import eu.eudat.configurations.dynamicfunder.entities.Configuration;
import eu.eudat.configurations.dynamicfunder.entities.Property;
import eu.eudat.models.data.dynamicfields.Dependency;
import eu.eudat.models.data.dynamicfields.DynamicField;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
import jakarta.xml.bind.JAXBContext;
import jakarta.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("dynamicFunderConfiguration")
@Profile({ "production", "staging", "docker" })
public class DynamicFunderConfigurationProdImpl implements DynamicFunderConfiguration {
private static final Logger logger = LoggerFactory.getLogger(DynamicFunderConfigurationProdImpl.class);
private Configuration configuration;
private List<DynamicField> fields;
private Environment environment;
public DynamicFunderConfigurationProdImpl(Environment environment) {
this.environment = environment;
}
@Override
public Configuration getConfiguration() {
if (this.configuration != null) return this.configuration;
String fileUrl = this.environment.getProperty("configuration.dynamicFunderUrl");
logger.info("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) {
logger.error("Cannot find in folder" + current, ex);
} finally {
try {
if (is != null) is.close();
} catch (IOException e) {
logger.warn("Warning: Could not close a stream after reading from file: " + fileUrl, e);
}
}
return this.configuration;
}
@Override
public List<DynamicField> getFields() {
if (this.fields != null) return this.fields;
Configuration configuration = this.getConfiguration();
List<DynamicField> fields = new LinkedList<>();
List<Property> 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<Dependency> 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;
}
}

View File

@ -1,31 +0,0 @@
package eu.eudat.configurations.dynamicfunder.entities;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlElementWrapper;
import jakarta.xml.bind.annotation.XmlRootElement;
import java.util.List;
@XmlRootElement
public class Configuration {
private List<Property> configurationProperties;
private MainProperty mainExternalField;
public MainProperty getMainExternalField() {
return mainExternalField;
}
@XmlElement(name = "mainExternalField")
public void setMainExternalField(MainProperty mainExternalField) {
this.mainExternalField = mainExternalField;
}
public List<Property> getConfigurationProperties() {
return configurationProperties;
}
@XmlElementWrapper
@XmlElement(name = "property")
public void setConfigurationProperties(List<Property> configurationProperties) {
this.configurationProperties = configurationProperties;
}
}

View File

@ -1,26 +0,0 @@
package eu.eudat.configurations.dynamicfunder.entities;
import jakarta.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;
}
}

View File

@ -1,26 +0,0 @@
package eu.eudat.configurations.dynamicfunder.entities;
import jakarta.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;
}
}

View File

@ -1,103 +0,0 @@
package eu.eudat.configurations.dynamicfunder.entities;
import eu.eudat.service.remotefetcher.config.UrlConfiguration;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlElementWrapper;
import java.util.List;
public class MainProperty {
private String id;
private String name;
private String queryProperty;
private String externalFieldId;
private List<UrlConfiguration> urlConfig;
private String externalFieldLabel;
private List<Dependency> dependencies;
private Boolean required;
private List<Language> 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<Dependency> getDependencies() {
return dependencies;
}
@XmlElementWrapper
@XmlElement(name = "dependency")
public void setDependencies(List<Dependency> 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 List<UrlConfiguration> getUrlConfig() {
return urlConfig;
}
@XmlElement(name = "urlConfig")
public void setUrlConfig(List<UrlConfiguration> urlConfig) {
this.urlConfig = urlConfig;
}
public List<Language> getLanguage() {
return language;
}
@XmlElementWrapper
@XmlElement(name = "languageProperty")
public void setLanguage(List<Language> language) {
this.language = language;
}
}

View File

@ -1,91 +0,0 @@
package eu.eudat.configurations.dynamicfunder.entities;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.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<Dependency> 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<Dependency> getDependencies() {
return dependencies;
}
@XmlElementWrapper
@XmlElement(name = "dependency")
public void setDependencies(List<Dependency> 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;
}
}

View File

@ -1,15 +0,0 @@
package eu.eudat.configurations.dynamicgrant;
import eu.eudat.configurations.dynamicgrant.entities.Configuration;
import eu.eudat.models.data.dynamicfields.DynamicField;
import java.util.List;
/**
* Created by ikalyvas on 3/23/2018.
*/
public interface DynamicGrantConfiguration {
Configuration getConfiguration();
List<DynamicField> getFields();
}

View File

@ -1,93 +0,0 @@
package eu.eudat.configurations.dynamicgrant;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
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 jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.Unmarshaller;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.LinkedList;
import java.util.List;
/**
* Created by ikalyvas on 5/4/2018.
*/
@Service("dynamicGrantConfiguration")
@Profile("devel")
public class DynamicGrantConfigurationDevelImpl implements DynamicGrantConfiguration {
private static final Logger logger = LoggerFactory.getLogger(DynamicGrantConfigurationDevelImpl.class);
private Configuration configuration;
private List<DynamicField> fields;
private Environment environment;
@Autowired
public DynamicGrantConfigurationDevelImpl(Environment environment) {
this.environment = environment;
}
@Override
public Configuration getConfiguration() {
if (this.configuration != null) return this.configuration;
String fileUrl = this.environment.getProperty("configuration.dynamicGrantUrl");
logger.info("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/GrantConfiguration.xml").openStream();
this.configuration = (Configuration) jaxbUnmarshaller.unmarshal(is);
} catch (Exception ex) {
logger.error("Cannot find in folder" + current, ex);
} finally {
try {
if (is != null) is.close();
} catch (IOException e) {
logger.warn("Warning: Could not close a stream after reading from file: " + fileUrl, e);
}
}
return this.configuration;
}
@Override
public List<DynamicField> getFields() {
if (this.fields != null) return this.fields;
Configuration configuration = this.getConfiguration();
List<DynamicField> fields = new LinkedList<>();
List<Property> 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<Dependency> 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;
}
}

View File

@ -1,93 +0,0 @@
package eu.eudat.configurations.dynamicgrant;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
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 jakarta.xml.bind.JAXBContext;
import jakarta.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;
/**
* Created by ikalyvas on 3/23/2018.
*/
@Service("dynamicGrantConfiguration")
@Profile({ "production", "staging", "docker" })
public class DynamicGrantConfigurationProdImpl implements DynamicGrantConfiguration {
private static final Logger logger = LoggerFactory.getLogger(DynamicGrantConfigurationProdImpl.class);
private Configuration configuration;
private List<DynamicField> fields;
private Environment environment;
@Autowired
public DynamicGrantConfigurationProdImpl(Environment environment) {
this.environment = environment;
}
@Override
public Configuration getConfiguration() {
if (this.configuration != null) return this.configuration;
String fileUrl = this.environment.getProperty("configuration.dynamicGrantUrl");
logger.info("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) {
logger.error("Cannot find in folder" + current, ex);
} finally {
try {
if (is != null) is.close();
} catch (IOException e) {
logger.warn("Warning: Could not close a stream after reading from file: " + fileUrl, e);
}
}
return this.configuration;
}
@Override
public List<DynamicField> getFields() {
if (this.fields != null) return this.fields;
Configuration configuration = this.getConfiguration();
List<DynamicField> fields = new LinkedList<>();
List<Property> 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<Dependency> 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;
}
}

View File

@ -1,34 +0,0 @@
package eu.eudat.configurations.dynamicgrant.entities;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlElementWrapper;
import jakarta.xml.bind.annotation.XmlRootElement;
import java.util.List;
/**
* Created by ikalyvas on 3/23/2018.
*/
@XmlRootElement
public class Configuration {
private List<Property> configurationProperties;
private MainProperty mainExternalField;
public MainProperty getMainExternalField() {
return mainExternalField;
}
@XmlElement(name = "mainExternalField")
public void setMainExternalField(MainProperty mainExternalField) {
this.mainExternalField = mainExternalField;
}
public List<Property> getConfigurationProperties() {
return configurationProperties;
}
@XmlElementWrapper
@XmlElement(name = "property")
public void setConfigurationProperties(List<Property> configurationProperties) {
this.configurationProperties = configurationProperties;
}
}

View File

@ -1,29 +0,0 @@
package eu.eudat.configurations.dynamicgrant.entities;
import jakarta.xml.bind.annotation.XmlElement;
/**
* Created by ikalyvas on 3/23/2018.
*/
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;
}
}

View File

@ -1,29 +0,0 @@
package eu.eudat.configurations.dynamicgrant.entities;
import jakarta.xml.bind.annotation.XmlElement;
/**
* Created by ikalyvas on 3/28/2018.
*/
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;
}
}

View File

@ -1,106 +0,0 @@
package eu.eudat.configurations.dynamicgrant.entities;
import eu.eudat.service.remotefetcher.config.UrlConfiguration;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlElementWrapper;
import java.util.List;
/**
* Created by ikalyvas on 3/28/2018.
*/
public class MainProperty {
private String id;
private String name;
private String queryProperty;
private String externalFieldId;
private List<UrlConfiguration> urlConfig;
private String externalFieldLabel;
private List<Dependency> dependencies;
private Boolean required;
private List<Language> 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<Dependency> getDependencies() {
return dependencies;
}
@XmlElementWrapper
@XmlElement(name = "dependency")
public void setDependencies(List<Dependency> 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 List<UrlConfiguration> getUrlConfig() {
return urlConfig;
}
@XmlElement(name = "urlConfig")
public void setUrlConfig(List<UrlConfiguration> urlConfig) {
this.urlConfig = urlConfig;
}
public List<Language> getLanguage() {
return language;
}
@XmlElementWrapper
@XmlElement(name = "languageProperty")
public void setLanguage(List<Language> language) {
this.language = language;
}
}

View File

@ -1,93 +0,0 @@
package eu.eudat.configurations.dynamicgrant.entities;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlElementWrapper;
import java.util.List;
/**
* Created by ikalyvas on 3/23/2018.
*/
public class Property {
private String id;
private String name;
private String sourceUrl;
private String queryProperty;
private String externalFieldId;
private String externalFieldLabel;
private List<Dependency> 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<Dependency> getDependencies() {
return dependencies;
}
@XmlElementWrapper
@XmlElement(name = "dependency")
public void setDependencies(List<Dependency> 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;
}
}

View File

@ -1,12 +0,0 @@
package eu.eudat.configurations.dynamicproject;
import eu.eudat.configurations.dynamicproject.entities.Configuration;
import eu.eudat.models.data.dynamicfields.DynamicField;
import java.util.List;
public interface DynamicProjectConfiguration {
Configuration getConfiguration();
List<DynamicField> getFields();
}

View File

@ -1,87 +0,0 @@
package eu.eudat.configurations.dynamicproject;
import eu.eudat.configurations.dynamicproject.entities.Configuration;
import eu.eudat.configurations.dynamicproject.entities.Property;
import eu.eudat.models.data.dynamicfields.Dependency;
import eu.eudat.models.data.dynamicfields.DynamicField;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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 jakarta.xml.bind.JAXBContext;
import jakarta.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 static final Logger logger = LoggerFactory.getLogger(DynamicProjectConfigurationDevelImpl.class);
private Configuration configuration;
private List<DynamicField> 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");
logger.info("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) {
logger.error("Cannot find in folder" + current, ex);
} finally {
try {
if (is != null) is.close();
} catch (IOException e) {
logger.warn("Warning: Could not close a stream after reading from file: " + fileUrl, e);
}
}
return this.configuration;
}
@Override
public List<DynamicField> getFields() {
if (this.fields != null) return this.fields;
Configuration configuration = this.getConfiguration();
List<DynamicField> fields = new LinkedList<>();
List<Property> 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<Dependency> 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;
}
}

View File

@ -1,90 +0,0 @@
package eu.eudat.configurations.dynamicproject;
import eu.eudat.configurations.dynamicproject.entities.Configuration;
import eu.eudat.configurations.dynamicproject.entities.Property;
import eu.eudat.models.data.dynamicfields.Dependency;
import eu.eudat.models.data.dynamicfields.DynamicField;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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 jakarta.xml.bind.JAXBContext;
import jakarta.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", "docker" })
public class DynamicProjectConfigurationProdImpl implements DynamicProjectConfiguration{
private static final Logger logger = LoggerFactory.getLogger(DynamicProjectConfigurationProdImpl.class);
private Configuration configuration;
private List<DynamicField> 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");
logger.info("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) {
logger.error("Cannot find in folder" + current, ex);
} finally {
try {
if (is != null) is.close();
} catch (IOException e) {
logger.warn("Warning: Could not close a stream after reading from file: " + fileUrl, e);
}
}
return this.configuration;
}
@Override
public List<DynamicField> getFields() {
if (this.fields != null) return this.fields;
Configuration configuration = this.getConfiguration();
List<DynamicField> fields = new LinkedList<>();
List<Property> 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<Dependency> 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;
}
}

View File

@ -1,32 +0,0 @@
package eu.eudat.configurations.dynamicproject.entities;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlElementWrapper;
import jakarta.xml.bind.annotation.XmlRootElement;
import java.util.List;
@XmlRootElement
public class Configuration {
private List<Property> configurationProperties;
private MainProperty mainExternalField;
public MainProperty getMainExternalField() {
return mainExternalField;
}
@XmlElement(name = "mainExternalField")
public void setMainExternalField(MainProperty mainExternalField) {
this.mainExternalField = mainExternalField;
}
public List<Property> getConfigurationProperties() {
return configurationProperties;
}
@XmlElementWrapper
@XmlElement(name = "property")
public void setConfigurationProperties(List<Property> configurationProperties) {
this.configurationProperties = configurationProperties;
}
}

View File

@ -1,26 +0,0 @@
package eu.eudat.configurations.dynamicproject.entities;
import jakarta.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;
}
}

View File

@ -1,26 +0,0 @@
package eu.eudat.configurations.dynamicproject.entities;
import jakarta.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;
}
}

View File

@ -1,103 +0,0 @@
package eu.eudat.configurations.dynamicproject.entities;
import eu.eudat.service.remotefetcher.config.UrlConfiguration;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlElementWrapper;
import java.util.List;
public class MainProperty {
private String id;
private String name;
private String queryProperty;
private String externalFieldId;
private List<UrlConfiguration> urlConfig;
private String externalFieldLabel;
private List<Dependency> dependencies;
private Boolean required;
private List<Language> 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<Dependency> getDependencies() {
return dependencies;
}
@XmlElementWrapper
@XmlElement(name = "dependency")
public void setDependencies(List<Dependency> 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 List<UrlConfiguration> getUrlConfig() {
return urlConfig;
}
@XmlElement(name = "urlConfig")
public void setUrlConfig(List<UrlConfiguration> urlConfig) {
this.urlConfig = urlConfig;
}
public List<Language> getLanguage() {
return language;
}
@XmlElementWrapper
@XmlElement(name = "languageProperty")
public void setLanguage(List<Language> language) {
this.language = language;
}
}

View File

@ -1,91 +0,0 @@
package eu.eudat.configurations.dynamicproject.entities;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.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<Dependency> 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<Dependency> getDependencies() {
return dependencies;
}
@XmlElementWrapper
@XmlElement(name = "dependency")
public void setDependencies(List<Dependency> 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;
}
}

View File

@ -2,7 +2,6 @@ package eu.eudat.controllers;
import eu.eudat.authorization.Permission;
import eu.eudat.configurations.dynamicgrant.DynamicGrantConfiguration;
import eu.eudat.criteria.DMPCriteria;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.dao.criteria.DynamicFieldsCriteria;
@ -65,17 +64,15 @@ import static org.springframework.http.MediaType.*;
public class DMPs extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(DMPs.class);
private DynamicGrantConfiguration dynamicGrantConfiguration;
private Environment environment;
private DataManagementPlanManager dataManagementPlanManager;
private ConfigLoader configLoader;
private final AuthorizationService authorizationService;
@Autowired
public DMPs(ApiContext apiContext, DynamicGrantConfiguration dynamicGrantConfiguration, Environment environment,
public DMPs(ApiContext apiContext, Environment environment,
DataManagementPlanManager dataManagementPlanManager, ConfigLoader configLoader, AuthorizationService authorizationService) {
super(apiContext);
this.dynamicGrantConfiguration = dynamicGrantConfiguration;
this.environment = environment;
this.dataManagementPlanManager = dataManagementPlanManager;
this.configLoader = configLoader;
@ -168,14 +165,14 @@ public class DMPs extends BaseController {
// }
}
@RequestMapping(method = RequestMethod.POST, value = {"/dynamic"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<List<Tuple<String, String>>>> getWithCriteria(@RequestBody RequestItem<DynamicFieldsCriteria> criteriaRequestItem) throws InstantiationException, IllegalAccessException {
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
List<Tuple<String, String>> dataTable = this.dataManagementPlanManager.getDynamicFields(criteriaRequestItem.getCriteria().getId(), this.dynamicGrantConfiguration, criteriaRequestItem.getCriteria());
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Tuple<String, String>>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
}
// @RequestMapping(method = RequestMethod.POST, value = {"/dynamic"}, consumes = "application/json", produces = "application/json")
// public @ResponseBody
// ResponseEntity<ResponseItem<List<Tuple<String, String>>>> getWithCriteria(@RequestBody RequestItem<DynamicFieldsCriteria> criteriaRequestItem) throws InstantiationException, IllegalAccessException {
// this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
//
// List<Tuple<String, String>> dataTable = this.dataManagementPlanManager.getDynamicFields(criteriaRequestItem.getCriteria().getId(), this.dynamicGrantConfiguration, criteriaRequestItem.getCriteria());
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Tuple<String, String>>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
// }
@RequestMapping(method = RequestMethod.GET, value = {"/versions/{id}"}, consumes = "application/json", produces = "application/json")
public @ResponseBody

View File

@ -6,8 +6,6 @@ import eu.eudat.commons.XmlHandlingService;
import eu.eudat.commons.enums.*;
import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.commons.types.dmpblueprint.*;
import eu.eudat.configurations.dynamicgrant.DynamicGrantConfiguration;
import eu.eudat.configurations.dynamicgrant.entities.Property;
import eu.eudat.data.*;
import eu.eudat.data.dao.criteria.*;
import eu.eudat.data.dao.entities.*;
@ -366,48 +364,48 @@ public class DataManagementPlanManager {
return datamanagementPlan;
}
public List<Tuple<String, String>> getDynamicFields(String id, DynamicGrantConfiguration dynamicGrantConfiguration, DynamicFieldsCriteria criteria) throws IllegalAccessException, InstantiationException {
List<Tuple<String, String>> result = new LinkedList<>();
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<String> entity = new HttpEntity<>("parameters", headers);
Property property = dynamicGrantConfiguration.getConfiguration().getConfigurationProperties().stream()
.filter(item -> item.getId().equals(id)).findFirst().orElse(null);
StringBuilder stringBuilder = new StringBuilder();
if (criteria.getLike() != null) stringBuilder.append("?search=" + criteria.getLike());
if (property.getDependencies() != null && !property.getDependencies().isEmpty() && criteria.getDynamicFields() != null && !criteria.getDynamicFields().isEmpty()) {
property.getDependencies().stream().forEach(item -> {
DynamicFieldsCriteria.DynamicFieldDependencyCriteria dependencyCriteria = criteria.getDynamicFields().stream().filter(dfield -> dfield.getProperty().equals(item.getId()))
.findFirst().orElse(null);
if (dependencyCriteria != null) {
if (criteria.getLike() != null || property.getDependencies().indexOf(item) > 0)
stringBuilder.append("&");
stringBuilder.append(item.getQueryProperty() + "=" + dependencyCriteria.getValue());
}
});
ResponseEntity<ArrayList> response = restTemplate.exchange(property.getSourceUrl() + stringBuilder.toString(), HttpMethod.GET, entity, ArrayList.class);
response.getBody().forEach(item -> {
Tuple<String, String> tuple = new Tuple<>();
tuple.setId((String) (((Map<String, Object>) item).get(property.getExternalFieldId())));
tuple.setLabel((String) (((Map<String, Object>) item).get(property.getExternalFieldLabel())));
result.add(tuple);
});
} else {
ResponseEntity<ArrayList> response = restTemplate.exchange(property.getSourceUrl() + stringBuilder.toString(), HttpMethod.GET, entity, ArrayList.class);
response.getBody().forEach(item -> {
Tuple<String, String> tuple = new Tuple<>();
tuple.setId((String) (((Map<String, Object>) item).get(property.getExternalFieldId())));
tuple.setLabel((String) (((Map<String, Object>) item).get(property.getExternalFieldLabel())));
result.add(tuple);
});
}
return result;
}
// public List<Tuple<String, String>> getDynamicFields(String id, DynamicGrantConfiguration dynamicGrantConfiguration, DynamicFieldsCriteria criteria) throws IllegalAccessException, InstantiationException {
// List<Tuple<String, String>> result = new LinkedList<>();
// RestTemplate restTemplate = new RestTemplate();
// HttpHeaders headers = new HttpHeaders();
// headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
// headers.setContentType(MediaType.APPLICATION_JSON);
// HttpEntity<String> entity = new HttpEntity<>("parameters", headers);
//
// Property property = dynamicGrantConfiguration.getConfiguration().getConfigurationProperties().stream()
// .filter(item -> item.getId().equals(id)).findFirst().orElse(null);
// StringBuilder stringBuilder = new StringBuilder();
// if (criteria.getLike() != null) stringBuilder.append("?search=" + criteria.getLike());
// if (property.getDependencies() != null && !property.getDependencies().isEmpty() && criteria.getDynamicFields() != null && !criteria.getDynamicFields().isEmpty()) {
// property.getDependencies().stream().forEach(item -> {
// DynamicFieldsCriteria.DynamicFieldDependencyCriteria dependencyCriteria = criteria.getDynamicFields().stream().filter(dfield -> dfield.getProperty().equals(item.getId()))
// .findFirst().orElse(null);
// if (dependencyCriteria != null) {
// if (criteria.getLike() != null || property.getDependencies().indexOf(item) > 0)
// stringBuilder.append("&");
// stringBuilder.append(item.getQueryProperty() + "=" + dependencyCriteria.getValue());
// }
// });
//
// ResponseEntity<ArrayList> response = restTemplate.exchange(property.getSourceUrl() + stringBuilder.toString(), HttpMethod.GET, entity, ArrayList.class);
// response.getBody().forEach(item -> {
// Tuple<String, String> tuple = new Tuple<>();
// tuple.setId((String) (((Map<String, Object>) item).get(property.getExternalFieldId())));
// tuple.setLabel((String) (((Map<String, Object>) item).get(property.getExternalFieldLabel())));
// result.add(tuple);
// });
//
// } else {
// ResponseEntity<ArrayList> response = restTemplate.exchange(property.getSourceUrl() + stringBuilder.toString(), HttpMethod.GET, entity, ArrayList.class);
// response.getBody().forEach(item -> {
// Tuple<String, String> tuple = new Tuple<>();
// tuple.setId((String) (((Map<String, Object>) item).get(property.getExternalFieldId())));
// tuple.setLabel((String) (((Map<String, Object>) item).get(property.getExternalFieldLabel())));
// result.add(tuple);
// });
// }
// return result;
// }
public DataTableData<DatasetProfileListingModel> getDatasetProfilesUsedByDMP(DatasetProfileTableRequestItem datasetProfileTableRequestItem) throws InvalidApplicationException {
datasetProfileTableRequestItem.getCriteria().setFilter(DatasetProfileCriteria.DatasetProfileFilter.DMPs.getValue());