Compare commits

...

23 Commits

Author SHA1 Message Date
Konstantinos Triantafyllou 2d40c411a7 Merge remote-tracking branch 'origin/Development' into roadmap 2022-10-05 16:23:28 +03:00
Konstantinos Triantafyllou 8e788c8f03 Update mysql client to 8.0.29 2022-07-11 13:30:36 +03:00
Konstantinos Triantafyllou f59a052805 Merge remote-tracking branch 'origin/Development' into roadmap 2022-07-11 13:11:18 +03:00
Konstantinos Triantafyllou 0c3a64bf76 Merge remote-tracking branch 'origin/Development' into roadmap 2022-06-23 15:42:46 +03:00
Konstantinos Triantafyllou b3f86c3934 Merge remote-tracking branch 'origin/Development' into roadmap 2022-06-22 10:56:17 +03:00
Konstantinos Triantafyllou 1a53d06fda Merge remote-tracking branch 'origin/Development' into roadmap 2022-06-15 15:08:15 +03:00
Konstantinos Triantafyllou fcda791ba0 Merge from Development branch 2022-06-08 10:03:55 +03:00
Konstantinos Triantafyllou 48cd6c1d49 Merge remote-tracking branch 'origin/Development' into roadmap 2022-05-31 20:49:25 +03:00
Konstantinos Triantafyllou 6380d3c231 Roadmap: Add logs. Make verified email by default true 2022-05-31 20:43:27 +03:00
Konstantinos Triantafyllou 3892017bdb Remove java 11 target from roadmap pom 2022-05-31 18:03:39 +03:00
Konstantinos Triantafyllou 5fef47b481 Roadmap: Create principal only with id. Fix a bug with users in a new version of dataset profile. 2022-05-31 17:21:57 +03:00
Konstantinos Triantafyllou f76686728a Merge remote-tracking branch 'origin/Development' into roadmap 2022-05-31 16:21:23 +03:00
Konstantinos Triantafyllou 0d7dbf3e24 Merge remote-tracking branch 'origin/Development' into roadmap 2022-05-31 16:17:03 +03:00
George Kalampokis 78b030b12e Fix issue with packaging roadmap module 2022-05-31 12:26:09 +03:00
Konstantinos Triantafyllou f8e54af4fa Comment clear method after migration 2022-05-30 14:50:10 +03:00
Konstantinos Triantafyllou d9a67626a8 Finish migration process abouts users dataset profiles and dmps 2022-05-30 11:11:28 +03:00
Konstantinos Triantafyllou d6e89cd440 Merge remote-tracking branch 'origin/Development' into roadmap 2022-05-21 00:31:12 +03:00
Konstantinos Triantafyllou 5275062b39 Complete migration process regarding Dataset Profiles and DMPs-Datasets 2022-05-21 00:30:56 +03:00
Konstantinos Triantafyllou e127e353de Create roadmap module as Standalone application 2022-05-18 14:45:24 +03:00
Konstantinos Triantafyllou 6072708d8a Commit changes before create a new module 2022-05-17 17:47:28 +03:00
Konstantinos Triantafyllou 9cb9cdb030 Create templates and DMP mapping 2022-05-11 11:29:26 +03:00
Konstantinos Triantafyllou fc7b3b01a4 DMPRoadmap: Map all entities related to template 2022-05-03 15:56:04 +03:00
Konstantinos Triantafyllou eee9faee28 Add DMP Roadmap database configuration and Template table. Make entity manager Primary and name entityManager to avoid conflicts on bean initialization. 2022-04-27 17:21:04 +03:00
45 changed files with 3750 additions and 52 deletions

1
.gitignore vendored
View File

@ -27,6 +27,7 @@ dmp-backend/data/target/
dmp-backend/queryable/target/
dmp-backend/elastic/target/
dmp-backend/queryengine/target/
dmp-backend/roadmap/target/
*.tar
*.gz
final/

View File

@ -16,7 +16,7 @@ import javax.persistence.PersistenceContext;
@Repository("databaseCtx")
public class DatabaseContext<T extends DataEntity> {
@PersistenceContext
@PersistenceContext(unitName = "entityManager")
private EntityManager entityManager;
@Autowired

View File

@ -18,6 +18,7 @@
<module>web</module>
<module>data</module>
<module>elastic</module>
<module>roadmap</module>
</modules>
<properties>
@ -346,6 +347,12 @@
</property>
</activation>
</profile>
<profile>
<id>roadmap</id>
<properties>
<packaging.type>jar</packaging.type>
</properties>
</profile>
</profiles>
</project>

View File

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>dmp-backend</artifactId>
<groupId>eu.eudat</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>roadmap</artifactId>
<properties>
<start-class>eu.eudat.migration.DMPRoadmapMigration</start-class>
</properties>
<dependencies>
<dependency>
<groupId>dmp-backend</groupId>
<artifactId>web</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.29</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}-${project.version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,35 @@
package eu.eudat.migration;
import eu.eudat.migration.services.DMPRoadmapService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.context.ConfigurableApplicationContext;
@SpringBootApplication(
scanBasePackages = "eu.eudat"
)
@ConfigurationPropertiesScan("eu.eudat.migration.properties")
public class DMPRoadmapMigration implements CommandLineRunner {
private final DMPRoadmapService service;
private static ConfigurableApplicationContext context;
@Autowired
public DMPRoadmapMigration(DMPRoadmapService service) {
this.service = service;
}
public static void main(String[] args) {
context = new SpringApplicationBuilder(DMPRoadmapMigration.class).run(args);
context.close();
}
@Override
public void run(String... args) throws Exception {
this.service.migrateUsers();
this.service.migrate();
}
}

View File

@ -0,0 +1,67 @@
package eu.eudat.migration.configuration;
import eu.eudat.migration.properties.ConfigProperties;
import eu.eudat.migration.properties.Database;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Objects;
@Configuration
@EnableJpaRepositories(
basePackages = "eu.eudat.migration.dao",
entityManagerFactoryRef = "roadmapEntityManagerFactory",
transactionManagerRef = "roadmapTransactionManager"
)
public class DMPRoadmapConfiguration {
private final Database database;
@Autowired
public DMPRoadmapConfiguration(ConfigProperties properties) {
this.database = properties.getDatabase();
}
@Bean(name = "roadmapDataSource")
public DataSource roadmapDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(Objects.requireNonNull(database.getDriver()));
dataSource.setUrl(database.getUrl());
dataSource.setUsername(database.getUsername());
dataSource.setPassword(database.getPassword());
return dataSource;
}
@Bean(name = "roadmapEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean roadmapEntityManagerFactory(@Qualifier("roadmapDataSource") DataSource roadmapDataSource) {
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(roadmapDataSource);
em.setPackagesToScan("eu.eudat.migration.entities");
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
HashMap<String, Object> properties = new HashMap<>();
properties.put("hibernate.dialect", database.getDialect());
properties.put("hibernate.hbm2ddl.auto", "none");
em.setJpaPropertyMap(properties);
return em;
}
@Bean(name = "roadmapTransactionManager")
public PlatformTransactionManager roadmapTransactionManager(@Qualifier("roadmapEntityManagerFactory") LocalContainerEntityManagerFactoryBean roadmapEntityManagerFactory) {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(roadmapEntityManagerFactory.getObject());
return transactionManager;
}
}

View File

@ -0,0 +1,18 @@
package eu.eudat.migration.dao;
import eu.eudat.migration.entities.Template;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
@ConditionalOnProperty(prefix = "roadmap", name="database.url")
public interface TemplateRepository extends JpaRepository<Template, Long> {
@Query(value = "SELECT DISTINCT (t.familyId) from Template t")
List<Long> findAllGroups();
List<Template> findAllByFamilyId(Long familyId, Sort sort);
}

View File

@ -0,0 +1,9 @@
package eu.eudat.migration.dao;
import eu.eudat.migration.entities.User;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.data.jpa.repository.JpaRepository;
@ConditionalOnProperty(prefix = "roadmap", name="database.url")
public interface UserRepository extends JpaRepository<User, Long> {
}

View File

@ -0,0 +1,106 @@
package eu.eudat.migration.entities;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import javax.persistence.*;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
@Entity
@Table(name = "answers")
public class Answer {
@Id
private Long id;
private String text;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "user_id")
private User user;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "question_id")
private Question question;
@Column(name = "created_at")
@Temporal(TemporalType.TIMESTAMP)
private Date createdAt;
@Column(name = "updated_at")
@Temporal(TemporalType.TIMESTAMP)
private Date updatedAt;
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(name = "answers_question_options",
joinColumns = {@JoinColumn(name = "answer_id")},
inverseJoinColumns = {@JoinColumn(name = "question_option_id")}
)
@LazyCollection(LazyCollectionOption.FALSE)
private Set<QuestionOption> questionOptions = new HashSet<>();
@Override
public String toString() {
return "Answer{" +
"id=" + id +
", text='" + text + '\'' +
", user=" + user +
", question=" + question +
", createdAt=" + createdAt +
", updatedAt=" + updatedAt +
", questionOptions=" + questionOptions +
'}';
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public Question getQuestion() {
return question;
}
public void setQuestion(Question question) {
this.question = question;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Date getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
public Set<QuestionOption> getQuestionOptions() {
return questionOptions;
}
public void setQuestionOptions(Set<QuestionOption> questionOptions) {
this.questionOptions = questionOptions;
}
}

View File

@ -0,0 +1,149 @@
package eu.eudat.migration.entities;
import javax.persistence.*;
import java.util.Date;
@Entity
@Table(name = "api_clients")
public class ApiClient {
@Id
private Long id;
private String name;
private String description;
private String homepage;
@Column(name = "contact_name")
private String contactName;
@Column(name = "contact_email")
private String contactEmail;
@Column(name = "client_id")
private String clientId;
@Column(name = "client_secret")
private String clientSecret;
@Column(name = "last_access")
@Temporal(TemporalType.TIMESTAMP)
private Date lastAccess;
@Column(name = "created_at")
@Temporal(TemporalType.TIMESTAMP)
private Date createdAt;
@Column(name = "updated_at")
@Temporal(TemporalType.TIMESTAMP)
private Date updatedAt;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "org_id")
private Organization organization;
@Override
public String toString() {
return "ApiClient{" +
"id=" + id +
", name='" + name + '\'' +
", description='" + description + '\'' +
", homepage='" + homepage + '\'' +
", contactName='" + contactName + '\'' +
", contactEmail='" + contactEmail + '\'' +
", clientId='" + clientId + '\'' +
", clientSecret='" + clientSecret + '\'' +
", lastAccess=" + lastAccess +
", createdAt=" + createdAt +
", updatedAt=" + updatedAt +
", organization=" + organization +
'}';
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getHomepage() {
return homepage;
}
public void setHomepage(String homepage) {
this.homepage = homepage;
}
public String getContactName() {
return contactName;
}
public void setContactName(String contactName) {
this.contactName = contactName;
}
public String getContactEmail() {
return contactEmail;
}
public void setContactEmail(String contactEmail) {
this.contactEmail = contactEmail;
}
public String getClientId() {
return clientId;
}
public void setClientId(String clientId) {
this.clientId = clientId;
}
public String getClientSecret() {
return clientSecret;
}
public void setClientSecret(String clientSecret) {
this.clientSecret = clientSecret;
}
public Date getLastAccess() {
return lastAccess;
}
public void setLastAccess(Date lastAccess) {
this.lastAccess = lastAccess;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Date getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
public Organization getOrganization() {
return organization;
}
public void setOrganization(Organization organization) {
this.organization = organization;
}
}

View File

@ -0,0 +1,119 @@
package eu.eudat.migration.entities;
import eu.eudat.migration.utils.ArrayTypeConverter;
import eu.eudat.migration.utils.JsonTypeConverter;
import javax.persistence.*;
import java.util.Arrays;
import java.util.Date;
import java.util.Map;
@Entity
@Table(name = "conditions")
@SuppressWarnings("JpaAttributeTypeInspection")
public class Condition {
@Id
private Long id;
@Column(name = "option_list")
@Convert(converter = ArrayTypeConverter.class)
private String[] optionList;
@Column(name = "action_type")
private ActionType actionType;
private Long number;
@Column(name = "remove_data")
@Convert(converter = ArrayTypeConverter.class)
private String[] removeData;
@Column(name = "webhook_data")
@Convert(converter = JsonTypeConverter.class)
private Map<String, Object> webhookData;
@Column(name = "created_at")
@Temporal(TemporalType.TIMESTAMP)
private Date createdAt;
@Column(name = "updated_at")
@Temporal(TemporalType.TIMESTAMP)
private Date updatedAt;
public enum ActionType {
REMOVE,
ADD_WEBHOOK
}
@Override
public String toString() {
return "Condition{" +
"id=" + id +
", optionList=" + Arrays.toString(optionList) +
", actionType=" + actionType +
", number=" + number +
", removeData=" + Arrays.toString(removeData) +
", webhookData=" + webhookData +
", createdAt=" + createdAt +
", updatedAt=" + updatedAt +
'}';
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String[] getOptionList() {
return optionList;
}
public void setOptionList(String[] optionList) {
this.optionList = optionList;
}
public ActionType getActionType() {
return actionType;
}
public void setActionType(ActionType actionType) {
this.actionType = actionType;
}
public Long getNumber() {
return number;
}
public void setNumber(Long number) {
this.number = number;
}
public String[] getRemoveData() {
return removeData;
}
public void setRemoveData(String[] removeData) {
this.removeData = removeData;
}
public Map<String, Object> getWebhookData() {
return webhookData;
}
public void setWebhookData(Map<String, Object> webhookData) {
this.webhookData = webhookData;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Date getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
}

View File

@ -0,0 +1,71 @@
package eu.eudat.migration.entities;
import javax.persistence.*;
import java.util.Date;
@Entity
@Table(name = "guidances")
public class Guidance {
@Id
private long id;
private String text;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "guidance_group_id")
private GuidanceGroup guidanceGroup;
@Column(name = "created_at")
@Temporal(TemporalType.TIMESTAMP)
private Date createdAt;
@Column(name = "updated_at")
@Temporal(TemporalType.TIMESTAMP)
private Date updatedAt;
private Boolean published;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public GuidanceGroup getGuidanceGroup() {
return guidanceGroup;
}
public void setGuidanceGroup(GuidanceGroup guidanceGroup) {
this.guidanceGroup = guidanceGroup;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Date getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
public Boolean getPublished() {
return published;
}
public void setPublished(Boolean published) {
this.published = published;
}
}

View File

@ -0,0 +1,82 @@
package eu.eudat.migration.entities;
import javax.persistence.*;
import java.util.Date;
@Entity
@Table(name = "guidance_groups")
public class GuidanceGroup {
@Id
private Long id;
private String name;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "org_id")
private Organization organization;
@Column(name = "created_at")
@Temporal(TemporalType.TIMESTAMP)
private Date createdAt;
@Column(name = "updated_at")
@Temporal(TemporalType.TIMESTAMP)
private Date updatedAt;
@Column(name = "optional_subset")
private Boolean optionalSubset;
private Boolean published;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Organization getOrganization() {
return organization;
}
public void setOrganization(Organization organization) {
this.organization = organization;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Date getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
public Boolean getOptionalSubset() {
return optionalSubset;
}
public void setOptionalSubset(Boolean optionalSubset) {
this.optionalSubset = optionalSubset;
}
public Boolean getPublished() {
return published;
}
public void setPublished(Boolean published) {
this.published = published;
}
}

View File

@ -0,0 +1,75 @@
package eu.eudat.migration.entities;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "languages")
public class Language {
@Id
private Long id;
private String abbreviation;
private String description;
private String name;
@Column(name = "default_language")
private Boolean defaultLanguage;
@Override
public String toString() {
return "Language{" +
"id=" + id +
", abbreviation='" + abbreviation + '\'' +
", description='" + description + '\'' +
", name='" + name + '\'' +
", defaultLanguage=" + defaultLanguage +
'}';
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getAbbreviation() {
return abbreviation;
}
public void setAbbreviation(String abbreviation) {
this.abbreviation = abbreviation;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Boolean getDefaultLanguage() {
return defaultLanguage;
}
public void setDefaultLanguage(Boolean defaultLanguage) {
this.defaultLanguage = defaultLanguage;
}
}

View File

@ -0,0 +1,274 @@
package eu.eudat.migration.entities;
import eu.eudat.migration.utils.JsonTypeConverter;
import eu.eudat.migration.utils.OrganizationTypeConverter;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Entity
@Table(name = "orgs")
@SuppressWarnings("JpaAttributeTypeInspection")
public class Organization {
@Id
private Long id;
private String name;
private String abbreviation;
@Column(name = "target_url")
private String targetUrl;
@Column(name = "created_at")
@Temporal(TemporalType.TIMESTAMP)
private Date createdAt;
@Column(name = "updated_at")
@Temporal(TemporalType.TIMESTAMP)
private Date updatedAt;
@Column(name = "is_other")
private Boolean isOther;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "region_id")
private Region region;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "language_id")
private Language language;
@Column(name = "logo_uid")
private String logoUid;
@Column(name = "logo_name")
private String logoName;
@Column(name = "contact_email")
private String contactEmail;
@Column(name = "org_type")
@Convert(converter = OrganizationTypeConverter.class)
private Type orgType;
@Convert(converter = JsonTypeConverter.class)
private Map<String, Object> links;
@Column(name = "feedback_enabled")
private Boolean feedbackEnabled;
@Column(name = "feedback_msg")
private String feedbackMsg;
@Column(name = "contact_name")
private String contactName;
@Column(name = "helpdesk_email")
private String helpdeskEmail;
private Boolean managed;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "org_id")
@LazyCollection(LazyCollectionOption.FALSE)
private List<User> users = new ArrayList<>();
public enum Type {
INSTITUTION,
FUNDER,
ORGANIZATION,
RESEARCH_INSTITUTE,
PROJECT,
SCHOOL
}
@Override
public String toString() {
return "Organization{" +
"id=" + id +
", name='" + name + '\'' +
", abbreviation='" + abbreviation + '\'' +
", targetUrl='" + targetUrl + '\'' +
", createdAt=" + createdAt +
", updatedAt=" + updatedAt +
", isOther=" + isOther +
", region=" + region +
", language=" + language +
", logoUid='" + logoUid + '\'' +
", logoName='" + logoName + '\'' +
", contactEmail='" + contactEmail + '\'' +
", orgType=" + orgType +
", links='" + links + '\'' +
", feedbackEnabled=" + feedbackEnabled +
", feedbackMsg='" + feedbackMsg + '\'' +
", contactName='" + contactName + '\'' +
", helpdeskEmail='" + helpdeskEmail + '\'' +
", managed=" + managed +
'}';
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAbbreviation() {
return abbreviation;
}
public void setAbbreviation(String abbreviation) {
this.abbreviation = abbreviation;
}
public String getTargetUrl() {
return targetUrl;
}
public void setTargetUrl(String targetUrl) {
this.targetUrl = targetUrl;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Date getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
public Boolean getIsOther() {
return isOther;
}
public void setIsOther(Boolean isOther) {
this.isOther = isOther;
}
public Region getRegion() {
return region;
}
public void setRegion(Region regionId) {
this.region = regionId;
}
public Language getLanguage() {
return language;
}
public void setLanguage(Language languageId) {
this.language = languageId;
}
public String getLogoUid() {
return logoUid;
}
public void setLogoUid(String logoUid) {
this.logoUid = logoUid;
}
public String getLogoName() {
return logoName;
}
public void setLogoName(String logoName) {
this.logoName = logoName;
}
public String getContactEmail() {
return contactEmail;
}
public void setContactEmail(String contactEmail) {
this.contactEmail = contactEmail;
}
public Type getOrgType() {
return orgType;
}
public void setOrgType(Type orgType) {
this.orgType = orgType;
}
public Map<String, Object> getLinks() {
return links;
}
public void setLinks(Map<String, Object> links) {
this.links = links;
}
public Boolean getFeedbackEnabled() {
return feedbackEnabled;
}
public void setFeedbackEnabled(Boolean feedbackEnabled) {
this.feedbackEnabled = feedbackEnabled;
}
public String getFeedbackMsg() {
return feedbackMsg;
}
public void setFeedbackMsg(String feedbackMsg) {
this.feedbackMsg = feedbackMsg;
}
public String getContactName() {
return contactName;
}
public void setContactName(String contactName) {
this.contactName = contactName;
}
public String getHelpdeskEmail() {
return helpdeskEmail;
}
public void setHelpdeskEmail(String helpdeskEmail) {
this.helpdeskEmail = helpdeskEmail;
}
public Boolean getManaged() {
return managed;
}
public void setManaged(Boolean managed) {
this.managed = managed;
}
public List<User> getUsers() {
return users;
}
public void setUsers(List<User> users) {
this.users = users;
}
}

View File

@ -0,0 +1,61 @@
package eu.eudat.migration.entities;
import javax.persistence.*;
import java.util.Date;
@Entity
@Table(name = "perms")
public class Perm {
@Id
private Long id;
private String name;
@Column(name = "created_at")
@Temporal(TemporalType.TIMESTAMP)
private Date createdAt;
@Column(name = "updated_at")
@Temporal(TemporalType.TIMESTAMP)
private Date updatedAt;
@Override
public String toString() {
return "Perm{" +
"id=" + id +
", name='" + name + '\'' +
", createdAt=" + createdAt +
", updatedAt=" + updatedAt +
'}';
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Date getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
}

View File

@ -0,0 +1,147 @@
package eu.eudat.migration.entities;
import eu.eudat.models.data.admin.components.datasetprofile.Section;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
@Entity
@Table(name = "phases")
public class Phase {
@Id
private Long id;
private String title;
private String description;
private Long number;
@Column(name = "created_at")
@Temporal(TemporalType.TIMESTAMP)
private Date createdAt;
@Column(name = "updated_at")
@Temporal(TemporalType.TIMESTAMP)
private Date updatedAt;
private Boolean modifiable;
@Column(name = "versionable_id")
private String versionableId;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "phase_id")
@OrderBy("number")
@LazyCollection(LazyCollectionOption.FALSE)
private List<RoadmapSection> sections = new ArrayList<>();
@Override
public String toString() {
return "Phase{" +
"id=" + id +
", title='" + title + '\'' +
", description='" + description + '\'' +
", number=" + number +
", createdAt=" + createdAt +
", updatedAt=" + updatedAt +
", modifiable=" + modifiable +
", versionableId='" + versionableId + '\'' +
", sections=" + sections +
'}';
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Long getNumber() {
return number;
}
public void setNumber(Long number) {
this.number = number;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Date getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
public Boolean getModifiable() {
return modifiable;
}
public void setModifiable(Boolean modifiable) {
this.modifiable = modifiable;
}
public String getVersionableId() {
return versionableId;
}
public void setVersionableId(String versionableId) {
this.versionableId = versionableId;
}
public List<RoadmapSection> getSections() {
return sections;
}
public void setSections(List<RoadmapSection> sections) {
this.sections = sections;
}
public List<Section> buildSections(String pageId) {
return sections.stream().map(s -> {
Section section = new Section();
section.setId(String.valueOf(UUID.randomUUID()));
section.setPage(pageId);
section.setTitle(s.getTitle());
section.setDescription(s.getDescription());
section.setOrdinal(Math.toIntExact(s.getNumber()) - 1);
section.setDefaultVisibility(true);
section.setMultiplicity(false);
section.setSections(new ArrayList<>());
section.setFieldSets(s.buildFieldSets(s.getQuestions()));
return section;
}).collect(Collectors.toList());
}
}

View File

@ -0,0 +1,417 @@
package eu.eudat.migration.entities;
import eu.eudat.models.data.admin.composite.DatasetProfile;
import eu.eudat.models.data.datasetprofile.DatasetProfileOverviewModel;
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
import eu.eudat.models.data.dmp.AssociatedProfile;
import eu.eudat.models.data.dmp.DataManagementPlan;
import eu.eudat.models.data.dmp.DataManagementPlanEditorModel;
import eu.eudat.models.data.dmp.Organisation;
import eu.eudat.models.data.funder.FunderDMPEditorModel;
import eu.eudat.models.data.grant.GrantDMPEditorModel;
import eu.eudat.models.data.project.ProjectDMPEditorModel;
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import javax.persistence.*;
import java.util.*;
@Entity
@Table(name = "plans")
public class Plan {
@Id
private Long id;
private String title;
@Column(name = "created_at")
@Temporal(TemporalType.TIMESTAMP)
private Date createdAt;
@Column(name = "updated_at")
@Temporal(TemporalType.TIMESTAMP)
private Date updatedAt;
private String identifier;
private String description;
private Visibility visibility;
@Column(name = "feedback_requested")
private Boolean feedbackRequested;
private Boolean complete;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "org_id")
private Organization organization;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "funder_id")
private Organization funder;
@Column(name = "start_date")
@Temporal(TemporalType.TIMESTAMP)
private Date startDate;
@Column(name = "end_date")
@Temporal(TemporalType.TIMESTAMP)
private Date endDate;
@Column(name = "grant_id")
private Long grantId;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "api_client_id")
private ApiClient apiClient;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "research_domain_id")
private ResearchDomain researchDomain;
@Column(name = "ethical_issues")
private Boolean ethicalIssues;
@Column(name = "ethical_issues_description")
private String ethicalIssuesDescription;
@Column(name = "ethical_issues_report")
private String ethicalIssuesReport;
@Column(name = "funding_status")
private FundingStatus fundingStatus;
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(name = "roles",
joinColumns = {@JoinColumn(name = "plan_id")},
inverseJoinColumns = {@JoinColumn(name = "user_id")}
)
@LazyCollection(LazyCollectionOption.FALSE)
private Set<User> users = new HashSet<>();
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "plan_id")
@LazyCollection(LazyCollectionOption.FALSE)
private Set<Answer> answers = new HashSet<>();
public enum Visibility {
ORGANIZATION,
PUBLIC,
TEST,
PRIVATE
}
public enum FundingStatus {
PLANNED,
FUNDED,
DENIED
}
@Override
public String toString() {
return "Plan{" +
"id=" + id +
", title='" + title + '\'' +
", createdAt=" + createdAt +
", updatedAt=" + updatedAt +
", identifier='" + identifier + '\'' +
", description='" + description + '\'' +
", visibility=" + visibility +
", feedbackRequested=" + feedbackRequested +
", complete=" + complete +
", organization=" + organization +
", funder=" + funder +
", startDate=" + startDate +
", endDate=" + endDate +
", grantId=" + grantId +
", apiClient=" + apiClient +
", researchDomain=" + researchDomain +
", ethicalIssues=" + ethicalIssues +
", ethicalIssuesDescription='" + ethicalIssuesDescription + '\'' +
", ethicalIssuesReport='" + ethicalIssuesReport + '\'' +
", fundingStatus=" + fundingStatus +
", users=" + users +
", answers=" + answers +
'}';
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Date getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
public String getIdentifier() {
return identifier;
}
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Visibility getVisibility() {
return visibility;
}
public void setVisibility(Visibility visibility) {
this.visibility = visibility;
}
public Boolean getFeedbackRequested() {
return feedbackRequested;
}
public void setFeedbackRequested(Boolean feedbackRequested) {
this.feedbackRequested = feedbackRequested;
}
public Boolean getComplete() {
return complete;
}
public void setComplete(Boolean complete) {
this.complete = complete;
}
public Organization getOrganization() {
return organization;
}
public void setOrganization(Organization organization) {
this.organization = organization;
}
public Organization getFunder() {
return funder;
}
public void setFunder(Organization funder) {
this.funder = funder;
}
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
public Date getEndDate() {
return endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
public Long getGrantId() {
return grantId;
}
public void setGrantId(Long grantId) {
this.grantId = grantId;
}
public ApiClient getApiClient() {
return apiClient;
}
public void setApiClient(ApiClient apiClient) {
this.apiClient = apiClient;
}
public ResearchDomain getResearchDomain() {
return researchDomain;
}
public void setResearchDomain(ResearchDomain researchDomain) {
this.researchDomain = researchDomain;
}
public Boolean getEthicalIssues() {
return ethicalIssues;
}
public void setEthicalIssues(Boolean ethicalIssues) {
this.ethicalIssues = ethicalIssues;
}
public String getEthicalIssuesDescription() {
return ethicalIssuesDescription;
}
public void setEthicalIssuesDescription(String ethicalIssuesDescription) {
this.ethicalIssuesDescription = ethicalIssuesDescription;
}
public String getEthicalIssuesReport() {
return ethicalIssuesReport;
}
public void setEthicalIssuesReport(String ethicalIssuesReport) {
this.ethicalIssuesReport = ethicalIssuesReport;
}
public FundingStatus getFundingStatus() {
return fundingStatus;
}
public void setFundingStatus(FundingStatus fundingStatus) {
this.fundingStatus = fundingStatus;
}
public Set<User> getUsers() {
return users;
}
public void setUsers(Set<User> users) {
this.users = users;
}
public Set<Answer> getAnswers() {
return answers;
}
public void setAnswers(Set<Answer> answers) {
this.answers = answers;
}
public DataManagementPlanEditorModel buildDMP(UUID profileId, String profileLabel,
eu.eudat.migration.properties.Entity funder,
eu.eudat.migration.properties.Entity grant) {
DataManagementPlanEditorModel dmpModel = new DataManagementPlanEditorModel();
dmpModel.setAssociatedUsers(new ArrayList<>());
dmpModel.setDatasets(new ArrayList<>());
dmpModel.setDatasetsToBeFinalized(new ArrayList<>());
dmpModel.setDescription(getDescription());
dmpModel.setDynamicFields(new ArrayList<>());
dmpModel.setExtraProperties(buildExtraProperties());
dmpModel.setFunder(buildFunder(funder));
dmpModel.setGrant(buildGrant(grant));
dmpModel.setLabel(getTitle());
dmpModel.setOrganisations(buildOrganizations());
dmpModel.setProfiles(buildProfiles(profileId, profileLabel));
dmpModel.setProject(buildProject());
dmpModel.setResearchers(new ArrayList<>());
dmpModel.setStatus(0);
return dmpModel;
}
public Map<String, Object> buildExtraProperties() {
Map<String, Object> properties = new HashMap<>();
properties.put("costs", new ArrayList<>());
properties.put("language", "en");
properties.put("publicDate", getCreatedAt());
properties.put("visible", getVisibility() == Visibility.PUBLIC);
return properties;
}
public FunderDMPEditorModel buildFunder(eu.eudat.migration.properties.Entity defaultFunder) {
FunderDMPEditorModel funder = new FunderDMPEditorModel();
if(getFunder() != null) {
funder.setLabel(getFunder().getName());
funder.setReference(getFunder().getAbbreviation());
} else {
funder.setLabel(defaultFunder.getLabel());
funder.setReference(defaultFunder.getReference());
}
return funder;
}
public GrantDMPEditorModel buildGrant(eu.eudat.migration.properties.Entity defaultGrant) {
GrantDMPEditorModel grant = new GrantDMPEditorModel();
if(getGrantId() != null) {
grant.setLabel(getGrantId().toString());
grant.setReference(getGrantId().toString());
grant.setDescription(getGrantId().toString());
} else {
grant.setLabel(defaultGrant.getLabel());
grant.setReference(defaultGrant.getReference());
grant.setDescription(defaultGrant.getDescription());
}
return grant;
}
public List<Organisation> buildOrganizations() {
if(getOrganization() != null) {
Organisation organisation = new Organisation();
organisation.setLabel(getOrganization().getName());
organisation.setReference("Internal:" + getOrganization().getAbbreviation());
organisation.setKey("Internal");
return Collections.singletonList(organisation);
} else {
return new ArrayList<>();
}
}
public List<AssociatedProfile> buildProfiles(UUID id, String label) {
AssociatedProfile profile = new AssociatedProfile();
profile.setId(id);
profile.setLabel(label);
return Collections.singletonList(profile);
}
public ProjectDMPEditorModel buildProject() {
return new ProjectDMPEditorModel();
}
public DatasetWizardModel buildDataset(UUID profileId, String profileLabel, DataManagementPlan dmp, PagedDatasetProfile pagedDatasetProfile) {
DatasetWizardModel datasetModel = new DatasetWizardModel();
datasetModel.setDataRepositories(new ArrayList<>());
buildPagedDatasetProfile(pagedDatasetProfile);
datasetModel.setDatasetProfileDefinition(pagedDatasetProfile);
datasetModel.setDescription(this.getDescription());
datasetModel.setDmp(dmp);
datasetModel.setExternalDatasets(new ArrayList<>());
datasetModel.setLabel(this.getTitle());
DatasetProfileOverviewModel profile = new DatasetProfileOverviewModel();
profile.setId(profileId);
profile.setLabel(profileLabel);
datasetModel.setProfile(profile);
datasetModel.setRegistries(new ArrayList<>());
datasetModel.setServices(new ArrayList<>());
datasetModel.setTags(new ArrayList<>());
return datasetModel;
}
public void buildPagedDatasetProfile(PagedDatasetProfile pagedDatasetProfile) {
pagedDatasetProfile.getPages().forEach(page -> {
page.getSections().forEach(section -> {
section.getCompositeFields().forEach(compositeField -> {
compositeField.getFields().forEach(field -> {
Long questionId = Question.fieldsQuestionsMap.get(field.getId());
if( questionId != null) {
Optional<Answer> optionalAnswer = answers.stream().filter(answer -> answer.getQuestion().getId().equals(questionId)).findFirst();
optionalAnswer.ifPresent(answer -> {
if(answer.getQuestion().getQuestionFormat().getOptionBased()) {
/* TODO check with real data */
field.setValue(answer.getText());
} else {
field.setValue(answer.getText());
}
});
}
});
});
});
});
}
}

View File

@ -0,0 +1,248 @@
package eu.eudat.migration.entities;
import eu.eudat.models.data.admin.components.datasetprofile.Field;
import eu.eudat.models.data.components.commons.DefaultValue;
import eu.eudat.models.data.components.commons.Visibility;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import javax.persistence.*;
import java.util.*;
import java.util.stream.Collectors;
@Entity
@Table(name = "questions")
public class Question {
public static Map<String, Long> fieldsQuestionsMap = new HashMap<>();
@Id
private Long id;
private String text;
@Column(name = "default_value")
private String defaultValue;
private Long number;
@Column(name = "created_at")
@Temporal(TemporalType.TIMESTAMP)
private Date createdAt;
@Column(name = "updated_at")
@Temporal(TemporalType.TIMESTAMP)
private Date updatedAt;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "question_format_id")
private QuestionFormat questionFormat;
@Column(name = "option_comment_display")
private Boolean optionCommentDisplay;
private Boolean modifiable;
@Column(name = "versionable_id")
private String versionableId;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "question_id")
@OrderBy("number")
@LazyCollection(LazyCollectionOption.FALSE)
private List<QuestionOption> options = new ArrayList<>();
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "question_id")
@OrderBy("number")
@LazyCollection(LazyCollectionOption.FALSE)
private List<Condition> conditions = new ArrayList<>();
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(name = "questions_themes",
joinColumns = {@JoinColumn(name = "question_id")},
inverseJoinColumns = {@JoinColumn(name = "theme_id")}
)
@LazyCollection(LazyCollectionOption.FALSE)
private Set<Theme> themes = new HashSet<>();
@Override
public String toString() {
return "Question{" +
"id=" + id +
", text='" + text + '\'' +
", defaultValue='" + defaultValue + '\'' +
", number=" + number +
", createdAt=" + createdAt +
", updatedAt=" + updatedAt +
", questionFormat=" + questionFormat +
", optionCommentDisplay=" + optionCommentDisplay +
", modifiable=" + modifiable +
", versionableId='" + versionableId + '\'' +
", options=" + options +
", conditions=" + conditions +
'}';
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public String getDefaultValue() {
return defaultValue;
}
public void setDefaultValue(String defaultValue) {
this.defaultValue = defaultValue;
}
public Long getNumber() {
return number;
}
public void setNumber(Long number) {
this.number = number;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Date getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
public QuestionFormat getQuestionFormat() {
return questionFormat;
}
public void setQuestionFormat(QuestionFormat questionFormat) {
this.questionFormat = questionFormat;
}
public Boolean getOptionCommentDisplay() {
return optionCommentDisplay;
}
public void setOptionCommentDisplay(Boolean optionCommentDisplay) {
this.optionCommentDisplay = optionCommentDisplay;
}
public Boolean getModifiable() {
return modifiable;
}
public void setModifiable(Boolean modifiable) {
this.modifiable = modifiable;
}
public String getVersionableId() {
return versionableId;
}
public void setVersionableId(String versionableId) {
this.versionableId = versionableId;
}
public List<QuestionOption> getOptions() {
return options;
}
public void setOptions(List<QuestionOption> options) {
this.options = options;
}
public List<Condition> getConditions() {
return conditions;
}
public void setConditions(List<Condition> conditions) {
this.conditions = conditions;
}
public Set<Theme> getThemes() {
return themes;
}
public void setThemes(Set<Theme> themes) {
this.themes = themes;
}
public String buildDescription() {
StringBuilder sb = new StringBuilder();
themes.forEach(theme -> {
if(theme.getTitle() != null) {
sb.append("<b>").append(theme.getTitle()).append("</b><br>");
}
if(theme.getDescription() != null) {
sb.append("<p>").append(theme.getDescription()).append("</p>");
}
if(theme.getGuidances().size() > 0) {
theme.getGuidances().forEach(guidance -> {
sb.append("<b>").append(guidance.getGuidanceGroup().getName()).append("</b><br>");
sb.append("<p>").append(guidance.getText()).append("</p>");
});
}
});
return sb.toString();
}
public List<Field> buildFields() {
Field field = new Field();
field.setId(String.valueOf(UUID.randomUUID()));
field.setOrdinal(0);
field.setDefaultValue(this.buildDefaultValue());
field.setValue(field.getDefaultValue().getValue());
field.setValidations(this.buildValidators());
field.setVisible(this.buildVisibility());
field.setViewStyle(this.getQuestionFormat().buildViewStyle());
field.setData(this.buildData());
fieldsQuestionsMap.put(field.getId(), getId());
return Collections.singletonList(field);
}
private DefaultValue buildDefaultValue() {
DefaultValue defaultValue = new DefaultValue();
defaultValue.setType("String");
defaultValue.setValue((this.defaultValue != null)?this.defaultValue :"");
return defaultValue;
}
private List<Integer> buildValidators() {
return Collections.singletonList((int) Field.ValidationType.REQUIRED.getValue());
}
private Visibility buildVisibility() {
Visibility visibility = new Visibility();
visibility.setRules(new ArrayList<>());
visibility.setStyle("");
return visibility;
}
private Map<String, Object> buildData() {
Map<String, Object> object = new HashMap<>();
object.put("label", "");
if(this.getQuestionFormat().getOptionBased()) {
object.put("options", this.getOptions().stream().map(questionOption -> {
Map<String, Object> option = new HashMap<>();
option.put(questionOption.getText(), questionOption.getText());
return option;
}).collect(Collectors.toList()));
}
if(this.getQuestionFormat().getFormattype() == QuestionFormat.FormatType.DROPDOWN ||
this.getQuestionFormat().getFormattype() == QuestionFormat.FormatType.MULTI_SELECT) {
object.put("type", "wordlist");
object.put("multiList", this.getQuestionFormat().getFormattype() == QuestionFormat.FormatType.MULTI_SELECT);
}
return object;
}
}

View File

@ -0,0 +1,134 @@
package eu.eudat.migration.entities;
import eu.eudat.models.data.components.commons.ViewStyle;
import javax.persistence.*;
import java.util.Date;
@Entity
@Table(name = "question_formats")
public class QuestionFormat {
@Id
private Long id;
private String title;
private String description;
@Column(name = "created_at")
@Temporal(TemporalType.TIMESTAMP)
private Date createdAt;
@Column(name = "updated_at")
@Temporal(TemporalType.TIMESTAMP)
private Date updatedAt;
@Column(name = "option_based")
private Boolean optionBased;
private FormatType formattype;
public enum FormatType {
TEXTAREA,
TEXT_FIELD,
RADIOBUTTON,
CHECKBOX,
DROPDOWN,
MULTI_SELECT,
DATE,
RDA_METADATA
}
@Override
public String toString() {
return "QuestionFormat{" +
"id=" + id +
", title='" + title + '\'' +
", description='" + description + '\'' +
", createdAt=" + createdAt +
", updatedAt=" + updatedAt +
", optionBased=" + optionBased +
", formattype=" + formattype +
'}';
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Date getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
public Boolean getOptionBased() {
return optionBased;
}
public void setOptionBased(Boolean optionBased) {
this.optionBased = optionBased;
}
public FormatType getFormattype() {
return formattype;
}
public void setFormattype(FormatType formattype) {
this.formattype = formattype;
}
public ViewStyle buildViewStyle() {
ViewStyle viewStyle = new ViewStyle();
viewStyle.setCssClass("");
switch (formattype) {
case TEXT_FIELD:
viewStyle.setRenderStyle("freetext");
break;
case TEXTAREA:
viewStyle.setRenderStyle("richTextarea");
break;
case CHECKBOX:
viewStyle.setRenderStyle("checkBox");
break;
case RADIOBUTTON:
viewStyle.setRenderStyle("radiobox");
break;
case DATE:
viewStyle.setRenderStyle("datePicker");
break;
case DROPDOWN:
case MULTI_SELECT:
viewStyle.setRenderStyle("combobox");
break;
default:
break;
}
return viewStyle;
}
}

View File

@ -0,0 +1,93 @@
package eu.eudat.migration.entities;
import javax.persistence.*;
import java.util.Date;
@Entity
@Table(name = "question_options")
public class QuestionOption {
@Id
private Long id;
private String text;
private Long number;
@Column(name = "is_default")
private Boolean isDefault;
@Column(name = "created_at")
@Temporal(TemporalType.TIMESTAMP)
private Date createdAt;
@Column(name = "updated_at")
@Temporal(TemporalType.TIMESTAMP)
private Date updatedAt;
@Column(name = "versionable_id")
private String versionableId;
@Override
public String toString() {
return "QuestionOption{" +
"id=" + id +
", text='" + text + '\'' +
", number=" + number +
", isDefault=" + isDefault +
", createdAt=" + createdAt +
", updatedAt=" + updatedAt +
", versionableId='" + versionableId + '\'' +
'}';
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public Long getNumber() {
return number;
}
public void setNumber(Long number) {
this.number = number;
}
public Boolean getDefault() {
return isDefault;
}
public void setDefault(Boolean aDefault) {
isDefault = aDefault;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Date getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
public String getVersionableId() {
return versionableId;
}
public void setVersionableId(String versionableId) {
this.versionableId = versionableId;
}
}

View File

@ -0,0 +1,73 @@
package eu.eudat.migration.entities;
import javax.persistence.*;
@Entity
@Table(name = "regions")
public class Region {
@Id
private Long id;
private String abbreviation;
private String description;
private String name;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "super_region_id")
private Region superRegion;
@Override
public String toString() {
return "Region{" +
"id=" + id +
", abbreviation='" + abbreviation + '\'' +
", description='" + description + '\'' +
", name='" + name + '\'' +
", superRegion=" + superRegion +
'}';
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getAbbreviation() {
return abbreviation;
}
public void setAbbreviation(String abbreviation) {
this.abbreviation = abbreviation;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Region getSuperRegion() {
return superRegion;
}
public void setSuperRegion(Region superRegion) {
this.superRegion = superRegion;
}
}

View File

@ -0,0 +1,85 @@
package eu.eudat.migration.entities;
import javax.persistence.*;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
@Entity
@Table(name = "research_domains")
public class ResearchDomain {
@Id
private Long id;
private String identifier;
private String label;
@OneToMany(fetch = FetchType.EAGER)
@JoinColumn(name = "parent_id")
private Set<ResearchDomain> subFields = new HashSet<>();
@Column(name = "created_at")
@Temporal(TemporalType.TIMESTAMP)
private Date createdAt;
@Column(name = "updated_at")
@Temporal(TemporalType.TIMESTAMP)
private Date updatedAt;
@Override
public String toString() {
return "ResearchDomain{" +
"id=" + id +
", identifier='" + identifier + '\'' +
", label='" + label + '\'' +
", subFields=" + subFields +
", createdAt=" + createdAt +
", updatedAt=" + updatedAt +
'}';
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getIdentifier() {
return identifier;
}
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public Set<ResearchDomain> getSubFields() {
return subFields;
}
public void setSubFields(Set<ResearchDomain> subFields) {
this.subFields = subFields;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Date getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
}

View File

@ -0,0 +1,148 @@
package eu.eudat.migration.entities;
import eu.eudat.models.data.admin.components.datasetprofile.FieldSet;
import eu.eudat.models.data.components.commons.Multiplicity;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import javax.persistence.*;
import java.util.*;
import java.util.stream.Collectors;
@Entity
@Table(name = "sections")
public class RoadmapSection {
@Id
private Long id;
private String title;
private String description;
private Long number;
@Column(name = "created_at")
@Temporal(TemporalType.TIMESTAMP)
private Date createdAt;
@Column(name = "updated_at")
@Temporal(TemporalType.TIMESTAMP)
private Date updatedAt;
private Boolean modifiable;
@Column(name = "versionable_id")
private String versionableId;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "section_id")
@OrderBy("number")
@LazyCollection(LazyCollectionOption.FALSE)
private List<Question> questions = new ArrayList<>();
@Override
public String toString() {
return "Section{" +
"id=" + id +
", title='" + title + '\'' +
", description='" + description + '\'' +
", number=" + number +
", createdAt=" + createdAt +
", updatedAt=" + updatedAt +
", modifiable=" + modifiable +
", versionableId='" + versionableId + '\'' +
", questions=" + questions +
'}';
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Long getNumber() {
return number;
}
public void setNumber(Long number) {
this.number = number;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Date getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
public Boolean getModifiable() {
return modifiable;
}
public void setModifiable(Boolean modifiable) {
this.modifiable = modifiable;
}
public String getVersionableId() {
return versionableId;
}
public void setVersionableId(String versionableId) {
this.versionableId = versionableId;
}
public List<Question> getQuestions() {
return questions;
}
public void setQuestions(List<Question> questions) {
this.questions = questions;
}
public List<FieldSet> buildFieldSets(List<Question> questions) {
return questions.stream().map(question -> {
FieldSet fieldSet = new FieldSet();
fieldSet.setId(String.valueOf(UUID.randomUUID()));
fieldSet.setTitle(question.getText());
fieldSet.setDescription(question.buildDescription());
fieldSet.setOrdinal(Math.toIntExact(question.getNumber()) - 1);
fieldSet.setMultiplicity(this.buildMultiplicity());
fieldSet.setHasCommentField(question.getOptionCommentDisplay());
fieldSet.setFields(question.buildFields());
return fieldSet;
}).collect(Collectors.toList());
}
private Multiplicity buildMultiplicity() {
Multiplicity multiplicity = new Multiplicity();
multiplicity.setPlaceholder("");
return multiplicity;
}
}

View File

@ -0,0 +1,254 @@
package eu.eudat.migration.entities;
import eu.eudat.migration.utils.JsonTypeConverter;
import eu.eudat.models.data.admin.components.datasetprofile.Page;
import eu.eudat.models.data.admin.components.datasetprofile.Section;
import eu.eudat.models.data.admin.composite.DatasetProfile;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import javax.persistence.*;
import java.util.*;
@Entity
@Table(name = "templates")
@SuppressWarnings("JpaAttributeTypeInspection")
public class Template {
@Id
private Long id;
private String title;
private String description;
private Boolean published;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "org_id")
private Organization organization;
private String locale;
@Column(name = "is_default")
private Boolean isDefault;
@Column(name = "created_at")
@Temporal(TemporalType.TIMESTAMP)
private Date createdAt;
@Column(name = "updated_at")
@Temporal(TemporalType.TIMESTAMP)
private Date updatedAt;
private Short version;
private Visibility visibility;
@Column(name = "customization_of")
private Long customizationOf;
@Column(name = "family_id")
private Long familyId;
private Boolean archived;
@Convert(converter = JsonTypeConverter.class)
private Map<String, Object> links;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "template_id")
@OrderBy("number")
@LazyCollection(LazyCollectionOption.FALSE)
private List<Phase> phases = new ArrayList<>();
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "template_id")
@LazyCollection(LazyCollectionOption.FALSE)
private Set<Plan> plans = new HashSet<>();
public enum Visibility {
ORGANIZATION,
PUBLIC
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Boolean getPublished() {
return published;
}
public void setPublished(Boolean published) {
this.published = published;
}
public Organization getOrganization() {
return organization;
}
public void setOrganization(Organization organization) {
this.organization = organization;
}
public String getLocale() {
return locale;
}
public void setLocale(String locale) {
this.locale = locale;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Date getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
public Short getVersion() {
return version;
}
public void setVersion(Short version) {
this.version = version;
}
public Visibility getVisibility() {
return visibility;
}
public void setVisibility(Visibility visibility) {
this.visibility = visibility;
}
public Long getCustomizationOf() {
return customizationOf;
}
public void setCustomizationOf(Long customizationOf) {
this.customizationOf = customizationOf;
}
public Long getFamilyId() {
return familyId;
}
public void setFamilyId(Long familyId) {
this.familyId = familyId;
}
public Boolean getArchived() {
return archived;
}
public void setArchived(Boolean archived) {
this.archived = archived;
}
public Map<String, Object> getLinks() {
return links;
}
public void setLinks(Map<String, Object> links) {
this.links = links;
}
public Boolean getDefault() {
return isDefault;
}
public void setDefault(Boolean aDefault) {
isDefault = aDefault;
}
public List<Phase> getPhases() {
return phases;
}
public void setPhases(List<Phase> phases) {
this.phases = phases;
}
public Set<Plan> getPlans() {
return plans;
}
public void setPlans(Set<Plan> plans) {
this.plans = plans;
}
@Override
public String toString() {
return "Template{" +
"id=" + id +
", title='" + title + '\'' +
", description='" + description + '\'' +
", published=" + published +
", organization=" + organization +
", locale='" + locale + '\'' +
", isDefault=" + isDefault +
", createdAt=" + createdAt +
", updatedAt=" + updatedAt +
", version=" + version +
", visibility=" + visibility +
", customizationOf=" + customizationOf +
", familyId=" + familyId +
", archived=" + archived +
", links=" + links +
", phases=" + phases +
", plans=" + plans +
'}';
}
public DatasetProfile buildDatasetProfile() {
DatasetProfile datasetProfile = new DatasetProfile();
datasetProfile.setLabel(this.getTitle());
datasetProfile.setDescription(this.getDescription());
datasetProfile.setLanguage(this.getLocale());
datasetProfile.setStatus((short) 1);
datasetProfile.setVersion(getVersion());
datasetProfile.setUsers(new ArrayList<>());
this.buildPages(datasetProfile);
return datasetProfile;
}
public void buildPages(DatasetProfile datasetProfile) {
List<Page> pages = new ArrayList<>();
List<Section> sections = new ArrayList<>();
this.getPhases().forEach(phase -> {
Page page = new Page();
page.setId(String.valueOf(UUID.randomUUID()));
page.setOrdinal(Math.toIntExact(phase.getNumber()) - 1);
page.setTitle(phase.getTitle());
pages.add(page);
sections.addAll(phase.buildSections(page.getId()));
});
datasetProfile.setPages(pages);
datasetProfile.setSections(sections);
}
}

View File

@ -0,0 +1,107 @@
package eu.eudat.migration.entities;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import javax.persistence.*;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
@Entity
@Table(name = "themes")
public class Theme {
@Id
private long id;
private String title;
private String description;
@Column(name = "created_at")
@Temporal(TemporalType.TIMESTAMP)
private Date createdAt;
@Column(name = "updated_at")
@Temporal(TemporalType.TIMESTAMP)
private Date updatedAt;
private String locale;
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(name = "themes_in_guidance",
joinColumns = {@JoinColumn(name = "theme_id")},
inverseJoinColumns = {@JoinColumn(name = "guidance_id")}
)
@LazyCollection(LazyCollectionOption.FALSE)
private Set<Guidance> guidances = new HashSet<>();
@Override
public String toString() {
return "Theme{" +
"id=" + id +
", title='" + title + '\'' +
", description='" + description + '\'' +
", createdAt=" + createdAt +
", updatedAt=" + updatedAt +
", locale='" + locale + '\'' +
'}';
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Date getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
public String getLocale() {
return locale;
}
public void setLocale(String locale) {
this.locale = locale;
}
public Set<Guidance> getGuidances() {
return guidances;
}
public void setGuidances(Set<Guidance> guidances) {
this.guidances = guidances;
}
}

View File

@ -0,0 +1,145 @@
package eu.eudat.migration.entities;
import eu.eudat.data.entities.UserInfo;
import eu.eudat.data.entities.UserToken;
import eu.eudat.logic.builders.entity.UserTokenBuilder;
import eu.eudat.logic.services.ApiContext;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import javax.persistence.*;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
@Entity
@Table(name = "users")
public class User {
@Id
private Long id;
private String firstname;
private String surname;
private String email;
@Column(name = "created_at")
@Temporal(TemporalType.TIMESTAMP)
private Date createdAt;
@Column(name = "updated_at")
@Temporal(TemporalType.TIMESTAMP)
private Date updatedAt;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "org_id")
private Organization organization;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "language_id")
private Language language;
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(name = "users_perms",
joinColumns = {@JoinColumn(name = "user_id")},
inverseJoinColumns = {@JoinColumn(name = "perm_id")}
)
@LazyCollection(LazyCollectionOption.FALSE)
private Set<Perm> perms = new HashSet<>();
@Override
public String toString() {
return "User{" +
"id=" + id +
", firstname='" + firstname + '\'' +
", surname='" + surname + '\'' +
", email='" + email + '\'' +
", createdAt=" + createdAt +
", updatedAt=" + updatedAt +
", organization=" + organization +
", language=" + language +
", perms=" + perms +
'}';
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Date getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
public Organization getOrganization() {
return organization;
}
public void setOrganization(Organization organization) {
this.organization = organization;
}
public Language getLanguage() {
return language;
}
public void setLanguage(Language language) {
this.language = language;
}
public Set<Perm> getPerms() {
return perms;
}
public void setPerms(Set<Perm> perms) {
this.perms = perms;
}
public UserInfo buildUserInfo() {
UserInfo userInfo = new UserInfo();
userInfo.setEmail(getEmail());
userInfo.setName(getFirstname() + " " + getSurname());
userInfo.setUsertype((short) 0);
userInfo.setUserStatus((short) 0);
userInfo.setAuthorization_level((short) 1);
userInfo.setVerified_email(true);
userInfo.setCreated(getCreatedAt());
return userInfo;
}
}

View File

@ -0,0 +1,32 @@
package eu.eudat.migration.properties;
public class Argos {
private String url;
private String username;
private String password;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}

View File

@ -0,0 +1,25 @@
package eu.eudat.migration.properties;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "roadmap")
public class ConfigProperties {
private Database database;
private DefaultEntities entities;
public Database getDatabase() {
return database;
}
public void setDatabase(Database database) {
this.database = database;
}
public DefaultEntities getEntities() {
return entities;
}
public void setEntities(DefaultEntities entities) {
this.entities = entities;
}
}

View File

@ -0,0 +1,49 @@
package eu.eudat.migration.properties;
public class Database {
private String driver;
private String url;
private String username;
private String password;
private String dialect;
public String getDriver() {
return driver;
}
public void setDriver(String driver) {
this.driver = driver;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getDialect() {
return dialect;
}
public void setDialect(String dialect) {
this.dialect = dialect;
}
}

View File

@ -0,0 +1,31 @@
package eu.eudat.migration.properties;
public class DefaultEntities {
private Entity funder;
private Entity grant;
private User user;
public Entity getFunder() {
return funder;
}
public void setFunder(Entity funder) {
this.funder = funder;
}
public Entity getGrant() {
return grant;
}
public void setGrant(Entity grant) {
this.grant = grant;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
}

View File

@ -0,0 +1,31 @@
package eu.eudat.migration.properties;
public class Entity {
public String reference;
public String label;
public String description;
public String getReference() {
return reference;
}
public void setReference(String reference) {
this.reference = reference;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}

View File

@ -0,0 +1,22 @@
package eu.eudat.migration.properties;
public class User {
private String email;
private String name;
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -0,0 +1,156 @@
package eu.eudat.migration.services;
import eu.eudat.controllers.Datasets;
import eu.eudat.data.entities.UserInfo;
import eu.eudat.data.entities.UserRole;
import eu.eudat.data.entities.UserToken;
import eu.eudat.logic.builders.entity.UserTokenBuilder;
import eu.eudat.logic.managers.AdminManager;
import eu.eudat.logic.managers.DataManagementPlanManager;
import eu.eudat.logic.managers.DatasetProfileManager;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.logic.services.operations.authentication.NonVerifiedUserEmailAuthenticationService;
import eu.eudat.models.data.admin.composite.DatasetProfile;
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
import eu.eudat.models.data.dmp.DataManagementPlan;
import eu.eudat.models.data.dmp.DataManagementPlanEditorModel;
import eu.eudat.models.data.listingmodels.UserInfoListingModel;
import eu.eudat.models.data.security.Principal;
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
import eu.eudat.queryable.QueryableList;
import eu.eudat.types.Authorities;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.io.IOException;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
@Service
public class ArgosService {
private final ApiContext context;
private final NonVerifiedUserEmailAuthenticationService authenticationService;
private final DataManagementPlanManager dataManagementPlanManager;
private final DatasetProfileManager datasetProfileManager;
private final Datasets datasets;
@Autowired
public ArgosService(ApiContext context,
NonVerifiedUserEmailAuthenticationService authenticationService,
DatasetProfileManager datasetProfileManager,
DataManagementPlanManager dataManagementPlanManager,
Datasets datasets) {
this.context = context;
this.authenticationService = authenticationService;
this.datasetProfileManager = datasetProfileManager;
this.dataManagementPlanManager = dataManagementPlanManager;
this.datasets = datasets;
}
/**
* Auth methods
*/
@Transactional
public UserInfo getUserInfo(String email) {
QueryableList<UserInfo> query = context.getOperationsContext().getDatabaseRepository().getUserInfoDao().asQueryable();
query.where((builder, root) -> builder.equal(root.get("email"), email));
return query.getSingleOrDefault();
}
@Transactional
public void createUserInfo(UserInfo userInfo) {
if (getUserInfo(userInfo.getEmail()) == null) {
context.getOperationsContext().getDatabaseRepository().getUserInfoDao().createOrUpdate(userInfo);
}
}
public Principal login(UserInfo userInfo) {
Principal principal = new Principal();
principal.setId(userInfo.getId());
return principal;
}
@Transactional
public void assignRole(UserInfo userInfo, Authorities authority) {
QueryableList<UserRole> query = context.getOperationsContext().getDatabaseRepository().getUserRoleDao().asQueryable();
query.where((builder, root) -> builder.equal(root.get("userInfo").get("id"), userInfo.getId()));
if(query.getSingleOrDefault() == null) {
UserRole role = new UserRole();
role.setUserInfo(userInfo);
role.setRole(authority.getValue());
context.getOperationsContext().getDatabaseRepository().getUserRoleDao().createOrUpdate(role);
}
}
/**
* Dataset Profiles
*/
@Transactional
public UUID createDatasetProfile(DatasetProfile datasetProfile, Principal principal) {
return this.datasetProfileManager.addDmp(datasetProfile, principal, false).getId();
}
@Transactional
public UUID createNewVersionDatasetProfile(UUID id, DatasetProfile datasetProfile) throws Exception {
return this.datasetProfileManager.createNewVersionDatasetProfile(id.toString(), datasetProfile, false).getId();
}
@Transactional
public void deleteDatasetProfile(UUID id) {
AdminManager.inactivate(context.getOperationsContext().getDatabaseRepository().getDatasetProfileDao(), context.getOperationsContext().getDatabaseRepository().getDatasetDao(), id.toString());
}
/**
* DMP methods
* @return
*/
@Transactional
public DataManagementPlan createDMP(DataManagementPlanEditorModel model, Principal principal) throws Exception {
return new eu.eudat.models.data.dmp.DataManagementPlan().
fromDataModel(this.dataManagementPlanManager.createOrUpdate(model, principal));
}
@Transactional
public void updateUsers(UUID id, List<UserInfoListingModel> users, Principal principal) throws Exception {
this.dataManagementPlanManager.updateUsers(id, users, principal);
}
@Transactional
public void deleteDMP(UUID id) {
try {
this.dataManagementPlanManager.delete(id);
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Dataset Methods
*/
@Transactional
public PagedDatasetProfile getDataset(UUID id) {
return Objects.requireNonNull(this.datasets.getSingle(id.toString()).getBody()).getPayload();
}
@Transactional
public DatasetWizardModel createDataset(DatasetWizardModel model, Principal principal) throws Exception {
return Objects.requireNonNull(this.datasets.createOrUpdate(model, principal).getBody()).getPayload();
}
@Transactional
public void deleteDataset(UUID id, Principal principal) {
try {
this.datasets.delete(id, principal);
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,168 @@
package eu.eudat.migration.services;
import eu.eudat.data.entities.UserInfo;
import eu.eudat.migration.dao.TemplateRepository;
import eu.eudat.migration.dao.UserRepository;
import eu.eudat.migration.entities.Perm;
import eu.eudat.migration.entities.Plan;
import eu.eudat.migration.entities.Template;
import eu.eudat.migration.entities.User;
import eu.eudat.migration.properties.ConfigProperties;
import eu.eudat.migration.properties.DefaultEntities;
import eu.eudat.models.data.admin.composite.DatasetProfile;
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
import eu.eudat.models.data.dmp.DataManagementPlan;
import eu.eudat.models.data.dmp.DataManagementPlanEditorModel;
import eu.eudat.models.data.listingmodels.UserInfoListingModel;
import eu.eudat.models.data.security.Principal;
import eu.eudat.types.Authorities;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Service
public class DMPRoadmapService {
private static final Logger logger = LoggerFactory.getLogger(DMPRoadmapService.class);
/**
* DMPRoadmap Repositories
*/
private final TemplateRepository templateRepository;
private final UserRepository userRepository;
/**
* Default Entities
*/
private final DefaultEntities defaultEntities;
/**
* Services
*/
private final ArgosService argosService;
/**
* Metadata
*/
private final List<UUID> datasetProfiles = new ArrayList<>();
private final List<UUID> dmps = new ArrayList<>();
private final List<UUID> datasets = new ArrayList<>();
private Principal principal;
@Autowired
public DMPRoadmapService(TemplateRepository templateRepository, UserRepository userRepository, ArgosService argosService, ConfigProperties properties) {
this.templateRepository = templateRepository;
this.userRepository = userRepository;
this.defaultEntities = properties.getEntities();
this.argosService = argosService;
}
public void migrateUsers() {
this.argosService.createUserInfo(Objects.requireNonNull(defaultUser()));
List<User> users = this.userRepository.findAll();
users.forEach(user -> {
logger.info("Create user with email: " + user.getEmail());
this.argosService.createUserInfo(user.buildUserInfo());
});
}
public void migrate() {
try {
List<UserInfo> users = this.userRepository.findAll().stream().filter(user ->
user.getPerms().stream().map(Perm::getName).collect(Collectors.toList()).contains("modify_templates")).map(user ->
this.argosService.getUserInfo(user.getEmail())
).collect(Collectors.toList());
UserInfo userInfo = this.argosService.getUserInfo(users.size() > 0 ? users.get(0).getEmail() : defaultEntities.getUser().getEmail());
for (Long group : templateRepository.findAllGroups()) {
List<Template> templates = templateRepository.findAllByFamilyId(group, Sort.by(Sort.Direction.ASC, "version"));
UUID id = null;
for (Template template : templates) {
this.argosService.assignRole(userInfo, Authorities.DATASET_PROFILE_MANAGER);
this.principal = this.argosService.login(userInfo);
DatasetProfile datasetProfile = template.buildDatasetProfile();
if (id == null) {
if (users.size() > 1) {
datasetProfile.setUsers(users.subList(1, users.size()).stream().map(info -> {
UserInfoListingModel model = new UserInfoListingModel();
model.setId(info.getId());
return model;
}).collect(Collectors.toList()));
}
logger.info("Create Dataset Profile with label: " + datasetProfile.getLabel());
id = this.argosService.createDatasetProfile(datasetProfile, principal);
} else {
if (users.size() > 0) {
datasetProfile.setUsers(users.stream().map(info -> {
UserInfoListingModel model = new UserInfoListingModel();
model.setId(info.getId());
return model;
}).collect(Collectors.toList()));
} else {
datasetProfile.setUsers(Stream.of(userInfo).map(info -> {
UserInfoListingModel model = new UserInfoListingModel();
model.setId(info.getId());
return model;
}).collect(Collectors.toList()));
}
logger.info("Create a new version of Dataset Profiles with label: " + datasetProfile.getLabel());
id = this.argosService.createNewVersionDatasetProfile(id, datasetProfile);
}
this.datasetProfiles.add(id);
for (Plan plan : template.getPlans()) {
DataManagementPlanEditorModel dataManagementPlanEditorModel = plan.buildDMP(id, datasetProfile.getLabel(), defaultEntities.getFunder(), defaultEntities.getGrant());
List<UserInfo> collaborators = plan.getUsers().stream().map(user -> this.argosService.getUserInfo(user.getEmail())).collect(Collectors.toList());
Principal principal = this.principal;
if (collaborators.size() > 0) {
principal = this.argosService.login(collaborators.get(0));
}
logger.info("Create DMP and its Dataset with label: " + dataManagementPlanEditorModel.getLabel());
DataManagementPlan dmp = this.argosService.createDMP(dataManagementPlanEditorModel, principal);
this.dmps.add(dmp.getId());
if (collaborators.size() > 1) {
List<UserInfoListingModel> modelList = collaborators.subList(1, collaborators.size()).stream().map(user -> {
UserInfoListingModel model = new UserInfoListingModel();
model.setId(user.getId());
return model;
}).collect(Collectors.toList());
this.argosService.updateUsers(dmp.getId(), modelList, principal);
}
DatasetWizardModel dataset = plan.buildDataset(id, datasetProfile.getLabel(), dmp, this.argosService.getDataset(id));
dataset = this.argosService.createDataset(dataset, principal);
this.datasets.add(dataset.getId());
}
}
}
} catch (Exception e) {
logger.error("Migration Failed. All data will be deleted.");
this.clear();
}
}
public void clear() {
logger.info("Deleting Datasets");
this.datasets.forEach(id -> this.argosService.deleteDataset(id, this.principal));
logger.info("Deleting DMPs");
this.dmps.forEach(this.argosService::deleteDMP);
logger.info("Deleting Dataset Profiles");
this.datasetProfiles.forEach(this.argosService::deleteDatasetProfile);
}
private UserInfo defaultUser() {
eu.eudat.migration.properties.User user = defaultEntities.getUser();
if (user != null && user.getEmail() != null && user.getName() != null) {
UserInfo userInfo = new UserInfo();
userInfo.setEmail(user.getEmail());
userInfo.setName(user.getName());
userInfo.setUsertype((short) 0);
userInfo.setUserStatus((short) 0);
userInfo.setAuthorization_level((short) 1);
userInfo.setVerified_email(false);
userInfo.setCreated(new Date());
return userInfo;
}
return null;
}
}

View File

@ -0,0 +1,18 @@
package eu.eudat.migration.utils;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
@Converter
public class ArrayTypeConverter implements AttributeConverter<String[], String> {
@Override
public String convertToDatabaseColumn(String[] strings) {
return strings != null?String.join(",", strings):null;
}
@Override
public String[] convertToEntityAttribute(String string) {
return string != null?string.split(","):null;
}
}

View File

@ -0,0 +1,30 @@
package eu.eudat.migration.utils;
import com.fasterxml.jackson.databind.ObjectMapper;
import javax.persistence.AttributeConverter;
import java.util.Map;
public class JsonTypeConverter implements AttributeConverter<Map<String, Object>, String> {
ObjectMapper objectMapper = new ObjectMapper();
@Override
public String convertToDatabaseColumn(Map<String, Object> customerInfo) {
try {
return objectMapper.writeValueAsString(customerInfo);
} catch (Exception e) {
return null;
}
}
@Override
public Map<String, Object> convertToEntityAttribute(String customerInfoJSON) {
try {
return objectMapper.readValue(customerInfoJSON, Map.class);
} catch (Exception e) {
return null;
}
}
}

View File

@ -0,0 +1,54 @@
package eu.eudat.migration.utils;
import eu.eudat.migration.entities.Organization;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
@Converter
public class OrganizationTypeConverter implements AttributeConverter<Organization.Type, Integer> {
@Override
public Integer convertToDatabaseColumn(Organization.Type type) {
if (type == null)
return null;
switch (type) {
case INSTITUTION:
return 1;
case FUNDER:
return 2;
case ORGANIZATION:
return 3;
case RESEARCH_INSTITUTE:
return 4;
case PROJECT:
return 5;
case SCHOOL:
return 6;
default:
throw new IllegalArgumentException(type + " not supported.");
}
}
@Override
public Organization.Type convertToEntityAttribute(Integer type) {
if (type == null)
return null;
switch (type) {
case 1:
return Organization.Type.INSTITUTION;
case 2:
return Organization.Type.FUNDER;
case 3:
return Organization.Type.ORGANIZATION;
case 4:
return Organization.Type.RESEARCH_INSTITUTE;
case 5:
return Organization.Type.PROJECT;
case 6:
return Organization.Type.SCHOOL;
default:
throw new IllegalArgumentException(type + " not supported.");
}
}
}

View File

@ -0,0 +1,17 @@
#################### DMP ROADMAP DATABASE CONFIGURATION (Postgres or MySQL) Last Database Migration: 15-03-2022 ##########
#roadmap.database.driver=org.postgresql.Driver
roadmap.database.driver=com.mysql.jdbc.Driver
roadmap.database.url=jdbc:mysql://localhost:3306/dmp
roadmap.database.username=dmp
roadmap.database.password=dmp
roadmap.database.dialect=org.hibernate.dialect.MySQL5Dialect
#roadmap.database.dialect=org.hibernate.dialect.PostgreSQL92Dialect
## Default entities ##
roadmap.entities.funder.reference=no_funder
roadmap.entities.funder.label=No funder
roadmap.entities.grant.reference=no_grant
roadmap.entities.grant.label=No grant
roadmap.entities.grant.description=No grant available
roadmap.entities.user.email=dmp@roadmap.com
roadmap.entities.user.name=DMP Roadmap

View File

@ -191,7 +191,82 @@
<version>3.0.0-M2</version>
</dependency>
</dependencies>
<profiles>
<profile>
<id>devel</id>
<build>
<finalName>${project.artifactId}-${project.version}</finalName>
<resources>
<resource>
<directory>src/main/ui-resources</directory>
<excludes>
<exclude>node_modules/**</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<properties>
<start-class>eu.eudat.EuDatApplication</start-class>
</properties>
</profile>
<profile>
<id>production</id>
<build>
<finalName>${project.artifactId}-${project.version}</finalName>
<resources>
<resource>
<directory>src/main/ui-resources</directory>
<excludes>
<exclude>node_modules/**</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<properties>
<start-class>eu.eudat.EuDatApplication</start-class>
</properties>
</profile>
</profiles>
<build>
<finalName>${project.artifactId}-${project.version}</finalName>
<resources>

View File

@ -7,6 +7,7 @@ import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.*;
import org.springframework.core.env.Environment;
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.JpaVendorAdapter;
@ -29,12 +30,14 @@ public class DevelDatabaseConfiguration {
private Environment env;
@Bean
@Primary
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource());
em.setPackagesToScan(new String[]{"eu.eudat.data.entities"});
JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
em.setPersistenceUnitName("entityManager");
em.setJpaProperties(additionalProperties());
return em;
}
@ -53,6 +56,7 @@ public class DevelDatabaseConfiguration {
}
@Bean
@Primary
public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(emf);

View File

@ -1,10 +1,7 @@
package eu.eudat.configurations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.context.annotation.*;
import org.springframework.core.env.Environment;
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
@ -32,18 +29,20 @@ public class ProductionDatabaseConfiguration {
private Environment env;
@Bean
@Primary
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource());
em.setPackagesToScan(new String[]{"eu.eudat.data.entities"});
JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
em.setPersistenceUnitName("entityManager");
em.setJpaProperties(additionalProperties());
return em;
}
@Bean
@Primary
public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(env.getProperty("database.driver-class-name"));
@ -54,6 +53,7 @@ public class ProductionDatabaseConfiguration {
}
@Bean
@Primary
public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(emf);

View File

@ -32,7 +32,6 @@ import javax.validation.Valid;
import java.io.IOException;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import static eu.eudat.types.Authorities.ADMIN;
import static eu.eudat.types.Authorities.DATASET_PROFILE_MANAGER;
@ -59,42 +58,14 @@ public class Admin extends BaseController {
@Transactional
@RequestMapping(method = RequestMethod.POST, value = {"/addDmp"}, consumes = "application/json", produces = "application/json")
public ResponseEntity<Object> addDmp(@Valid @RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN ,DATASET_PROFILE_MANAGER}) Principal principal) {
//this.getLoggerService().info(principal, "Admin Added Dataset Profile");
DatasetProfile shortenProfile = profile.toShort();
eu.eudat.data.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(shortenProfile, getApiContext());
modelDefinition.setGroupId(UUID.randomUUID());
modelDefinition.setVersion((short) 0);
eu.eudat.data.entities.DatasetProfile datasetProfile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(modelDefinition);
UserDatasetProfile userDatasetProfile = new UserDatasetProfile();
userDatasetProfile.setDatasetProfile(datasetProfile);
UserInfo userInfo = getApiContext().getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
userDatasetProfile.setUser(userInfo);
userDatasetProfile.setRole(0);
getApiContext().getOperationsContext().getDatabaseRepository().getUserDatasetProfileDao().createOrUpdate(userDatasetProfile);
datasetProfileManager.storeDatasetProfileUsers(datasetProfile, profile);
metricsManager.increaseValue(MetricNames.DATASET_TEMPLATE, 1, MetricsManager.datasetTemplateStatus.get(datasetProfile.getStatus()) );
return ResponseEntity.status(HttpStatus.OK).body(modelDefinition.getId());
eu.eudat.data.entities.DatasetProfile datasetProfile = this.datasetProfileManager.addDmp(profile, principal);
return ResponseEntity.status(HttpStatus.OK).body(datasetProfile.getId());
}
@Transactional
@RequestMapping(method = RequestMethod.POST, value = {"/addDmp/{id}"}, consumes = "application/json", produces = "application/json")
public ResponseEntity<ResponseItem<UUID>> updateDmp(@PathVariable String id, @RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN, DATASET_PROFILE_MANAGER}) Principal principal) {
DatasetProfile shortenProfile = profile.toShort();
eu.eudat.data.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(shortenProfile, getApiContext());
eu.eudat.data.entities.DatasetProfile datasetprofile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id));
datasetprofile.setDefinition(modelDefinition.getDefinition());
Short oldStatus = datasetprofile.getStatus();
datasetprofile.setStatus(modelDefinition.getStatus());
datasetprofile.setLabel(modelDefinition.getLabel());
datasetprofile.setDescription(modelDefinition.getDescription());
datasetprofile.setLanguage(modelDefinition.getLanguage());
eu.eudat.data.entities.DatasetProfile datasetProfile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(datasetprofile);
datasetProfileManager.storeDatasetProfileUsers(datasetProfile, profile);
if (datasetProfile.getStatus() == 1 && oldStatus == 0) {
metricsManager.increaseValue(MetricNames.DATASET_TEMPLATE, 1, MetricNames.ACTIVE);
}
this.datasetProfileManager.updateDmp(id, profile);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UUID>().status(ApiMessageCode.NO_MESSAGE));
}

View File

@ -16,7 +16,6 @@ import eu.eudat.logic.utilities.builders.XmlBuilder;
import eu.eudat.logic.utilities.documents.helpers.FileEnvelope;
import eu.eudat.logic.utilities.documents.xml.datasetProfileXml.ExportXmlBuilderDatasetProfile;
import eu.eudat.logic.utilities.documents.xml.datasetProfileXml.ImportXmlBuilderDatasetProfile;
import eu.eudat.logic.utilities.helpers.StreamDistinctBy;
import eu.eudat.models.data.components.commons.datafield.AutoCompleteData;
import eu.eudat.models.data.datasetprofile.DatasetProfileAutocompleteItem;
import eu.eudat.models.data.datasetprofile.DatasetProfileListingModel;
@ -34,10 +33,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.http.*;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
@ -50,7 +46,6 @@ import javax.xml.xpath.*;
import java.io.*;
import java.nio.file.Files;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
@ -73,6 +68,51 @@ public class DatasetProfileManager {
this.metricsManager = metricsManager;
}
public DatasetProfile addDmp(eu.eudat.models.data.admin.composite.DatasetProfile profile, Principal principal) {
return this.addDmp(profile, principal, true);
}
public DatasetProfile addDmp(eu.eudat.models.data.admin.composite.DatasetProfile profile, Principal principal, boolean email) {
//this.getLoggerService().info(principal, "Admin Added Dataset Profile");
eu.eudat.models.data.admin.composite.DatasetProfile shortenProfile = profile.toShort();
eu.eudat.data.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(shortenProfile, apiContext);
modelDefinition.setGroupId(UUID.randomUUID());
modelDefinition.setVersion((short) 0);
eu.eudat.data.entities.DatasetProfile datasetProfile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(modelDefinition);
UserDatasetProfile userDatasetProfile = new UserDatasetProfile();
userDatasetProfile.setDatasetProfile(datasetProfile);
UserInfo userInfo = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
userDatasetProfile.setUser(userInfo);
userDatasetProfile.setRole(0);
apiContext.getOperationsContext().getDatabaseRepository().getUserDatasetProfileDao().createOrUpdate(userDatasetProfile);
storeDatasetProfileUsers(datasetProfile, profile, email);
metricsManager.increaseValue(MetricNames.DATASET_TEMPLATE, 1, MetricsManager.datasetTemplateStatus.get(datasetProfile.getStatus()) );
return datasetProfile;
}
public DatasetProfile updateDmp(String id, eu.eudat.models.data.admin.composite.DatasetProfile profile) {
return this.updateDmp(id, profile, true);
}
public DatasetProfile updateDmp(String id, eu.eudat.models.data.admin.composite.DatasetProfile profile, boolean email) {
eu.eudat.models.data.admin.composite.DatasetProfile shortenProfile = profile.toShort();
eu.eudat.data.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(shortenProfile, apiContext);
eu.eudat.data.entities.DatasetProfile datasetprofile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id));
datasetprofile.setDefinition(modelDefinition.getDefinition());
Short oldStatus = datasetprofile.getStatus();
datasetprofile.setStatus(modelDefinition.getStatus());
datasetprofile.setLabel(modelDefinition.getLabel());
datasetprofile.setDescription(modelDefinition.getDescription());
datasetprofile.setLanguage(modelDefinition.getLanguage());
eu.eudat.data.entities.DatasetProfile datasetProfile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(datasetprofile);
storeDatasetProfileUsers(datasetProfile, profile, email);
if (datasetProfile.getStatus() == 1 && oldStatus == 0) {
metricsManager.increaseValue(MetricNames.DATASET_TEMPLATE, 1, MetricNames.ACTIVE);
}
return datasetProfile;
}
@Transactional
public eu.eudat.models.data.admin.composite.DatasetProfile getDatasetProfile(String id) {
eu.eudat.data.entities.DatasetProfile profile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id));
@ -270,6 +310,10 @@ public class DatasetProfileManager {
}
public eu.eudat.data.entities.DatasetProfile createNewVersionDatasetProfile(String id, eu.eudat.models.data.admin.composite.DatasetProfile profile) throws Exception {
return this.createNewVersionDatasetProfile(id, profile, true);
}
public eu.eudat.data.entities.DatasetProfile createNewVersionDatasetProfile(String id, eu.eudat.models.data.admin.composite.DatasetProfile profile, boolean email) throws Exception {
// Getting the DatasetProfile which we will create its new version.
eu.eudat.data.entities.DatasetProfile oldDatasetProfile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id));
@ -291,14 +335,14 @@ public class DatasetProfileManager {
// modelDefinition.setLanguage(oldDatasetProfile.getLanguage());
apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(modelDefinition);
eu.eudat.data.entities.DatasetProfile datasetProfile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(modelDefinition);
this.storeDatasetProfileUsers(datasetProfile, profile);
this.storeDatasetProfileUsers(datasetProfile, profile, email);
return modelDefinition;
} else {
throw new DatasetProfileNewVersionException("Version to update not the latest.");
}
}
public void storeDatasetProfileUsers(DatasetProfile entity, eu.eudat.models.data.admin.composite.DatasetProfile model) {
public void storeDatasetProfileUsers(DatasetProfile entity, eu.eudat.models.data.admin.composite.DatasetProfile model, boolean email) {
if (model.getUsers() != null && !model.getUsers().isEmpty()) {
if (entity.getUsers() == null) {
entity.setUsers(new HashSet<>());
@ -312,14 +356,18 @@ public class DatasetProfileManager {
userDatasetProfile1.setUser(userInfo1);
userDatasetProfile1.setRole(1);
apiContext.getOperationsContext().getDatabaseRepository().getUserDatasetProfileDao().createOrUpdate(userDatasetProfile1);
sendJoinMail(userDatasetProfile1);
if(email) {
sendJoinMail(userDatasetProfile1);
}
});
entity.getUsers().stream().filter(userDatasetProfile -> model.getUsers().stream()
.filter(userInfoListingModel -> userDatasetProfile.getUser().getId().equals(userInfoListingModel.getId())).count() > 0
&& userDatasetProfile.getRole() == 2).forEach(userDatasetProfile -> {
userDatasetProfile.setRole(1);
apiContext.getOperationsContext().getDatabaseRepository().getUserDatasetProfileDao().createOrUpdate(userDatasetProfile);
sendJoinMail(userDatasetProfile);
if(email) {
sendJoinMail(userDatasetProfile);
}
});
}
if (entity.getUsers() != null && !entity.getUsers().isEmpty()) {

View File

@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@Service("databaseRepository")
@ -40,6 +41,7 @@ public class DatabaseRepositoryImpl implements DatabaseRepository {
private NotificationDao notificationDao;
private FileUploadDao fileUploadDao;
@PersistenceContext(unitName = "entityManager")
private EntityManager entityManager;
@Autowired
@ -192,11 +194,6 @@ public class DatabaseRepositoryImpl implements DatabaseRepository {
this.userRoleDao = userRoleDao;
}
@Autowired
public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager;
}
@Override
public UserDmpDao getUserDmpDao() {
return userDmpDao;