Merge commit 'ca91c14114b8994d41fdf2b97fc6d1a4d82ffa4e'

This commit is contained in:
Diamantis Tziotzios 2021-05-19 14:22:47 +03:00
commit f5d266554b
552 changed files with 43292 additions and 6459 deletions

View File

@ -12,4 +12,4 @@ RUN mvn package
FROM openjdk:8-jre-alpine FROM openjdk:8-jre-alpine
WORKDIR /app WORKDIR /app
COPY --from=MAVEN_BUILD /build/web/target/web-1.0-SNAPSHOT.jar /app/app.jar COPY --from=MAVEN_BUILD /build/web/target/web-1.0-SNAPSHOT.jar /app/app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom" ,"-Dspring.profiles.active=${PROF}","-jar","/app.jar"] ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-Dspring.profiles.active=${PROF}", "-Dspring.config.location=/files/config/", "-jar","/app/app.jar"]

View File

@ -21,6 +21,7 @@ public class DataManagementPlanCriteria extends Criteria<DMP> {
private boolean isPublic; private boolean isPublic;
private boolean onlyPublic; private boolean onlyPublic;
private Short grantStatus; private Short grantStatus;
private boolean hasDoi;
public Date getPeriodStart() { public Date getPeriodStart() {
return periodStart; return periodStart;
@ -114,4 +115,12 @@ public class DataManagementPlanCriteria extends Criteria<DMP> {
public void setGrantStatus(Short grantStatus) { public void setGrantStatus(Short grantStatus) {
this.grantStatus = grantStatus; this.grantStatus = grantStatus;
} }
public boolean hasDoi() {
return hasDoi;
}
public void setHasDoi(boolean hasDoi) {
this.hasDoi = hasDoi;
}
} }

View File

@ -25,6 +25,7 @@ public class DatasetCriteria extends Criteria<Dataset> {
private List<UUID> groupIds; private List<UUID> groupIds;
private Boolean isPublic; private Boolean isPublic;
private Short grantStatus; private Short grantStatus;
private boolean hasDoi;
public boolean getAllVersions() { public boolean getAllVersions() {
return allVersions; return allVersions;
@ -132,4 +133,12 @@ public class DatasetCriteria extends Criteria<Dataset> {
public void setGrantStatus(Short grantStatus) { public void setGrantStatus(Short grantStatus) {
this.grantStatus = grantStatus; this.grantStatus = grantStatus;
} }
public boolean hasDoi() {
return hasDoi;
}
public void setHasDoi(boolean hasDoi) {
this.hasDoi = hasDoi;
}
} }

View File

@ -34,6 +34,7 @@ public class DatasetProfileCriteria extends Criteria<DatasetProfile> {
private UUID userId; private UUID userId;
private boolean finalized; private boolean finalized;
private Integer status; private Integer status;
private Integer role;
public boolean getAllVersions() { return allVersions; } public boolean getAllVersions() { return allVersions; }
public void setAllVersions(boolean allVersions) { this.allVersions = allVersions; } public void setAllVersions(boolean allVersions) { this.allVersions = allVersions; }
@ -69,4 +70,12 @@ public class DatasetProfileCriteria extends Criteria<DatasetProfile> {
public void setStatus(Integer status) { public void setStatus(Integer status) {
this.status = status; this.status = status;
} }
public Integer getRole() {
return role;
}
public void setRole(Integer role) {
this.role = role;
}
} }

View File

@ -0,0 +1,6 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.entities.EmailConfirmation;
public class EmailConfirmationCriteria extends Criteria<EmailConfirmation>{
}

View File

@ -4,6 +4,7 @@ import eu.eudat.data.entities.Funder;
public class FunderCriteria extends Criteria<Funder> { public class FunderCriteria extends Criteria<Funder> {
private String reference; private String reference;
private String exactReference;
public String getReference() { public String getReference() {
return reference; return reference;
@ -11,4 +12,12 @@ public class FunderCriteria extends Criteria<Funder> {
public void setReference(String reference) { public void setReference(String reference) {
this.reference = reference; this.reference = reference;
} }
public String getExactReference() {
return exactReference;
}
public void setExactReference(String exactReference) {
this.exactReference = exactReference;
}
} }

View File

@ -13,6 +13,8 @@ public class GrantCriteria extends Criteria<Grant> {
private boolean isPublic; private boolean isPublic;
private String funderId; private String funderId;
private String funderReference; private String funderReference;
private String exactReference;
private boolean isActive;
public Date getPeriodStart() { public Date getPeriodStart() {
return periodStart; return periodStart;
@ -62,4 +64,20 @@ public class GrantCriteria extends Criteria<Grant> {
public void setFunderReference(String funderReference) { public void setFunderReference(String funderReference) {
this.funderReference = funderReference; this.funderReference = funderReference;
} }
public String getExactReference() {
return exactReference;
}
public void setExactReference(String exactReference) {
this.exactReference = exactReference;
}
public boolean isActive() {
return isActive;
}
public void setActive(boolean active) {
isActive = active;
}
} }

View File

@ -1,6 +0,0 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.entities.LoginConfirmationEmail;
public class LoginConfirmationEmailCriteria extends Criteria<LoginConfirmationEmail>{
}

View File

@ -4,6 +4,7 @@ import eu.eudat.data.entities.Project;
public class ProjectCriteria extends Criteria<Project> { public class ProjectCriteria extends Criteria<Project> {
private String reference; private String reference;
private String exactReference;
public String getReference() { public String getReference() {
return reference; return reference;
@ -11,4 +12,12 @@ public class ProjectCriteria extends Criteria<Project> {
public void setReference(String reference) { public void setReference(String reference) {
this.reference = reference; this.reference = reference;
} }
public String getExactReference() {
return exactReference;
}
public void setExactReference(String exactReference) {
this.exactReference = exactReference;
}
} }

View File

@ -4,6 +4,7 @@ import eu.eudat.data.entities.Researcher;
public class ResearcherCriteria extends Criteria<Researcher> { public class ResearcherCriteria extends Criteria<Researcher> {
private String name; private String name;
private String reference;
public String getName() { public String getName() {
return name; return name;
@ -12,4 +13,12 @@ public class ResearcherCriteria extends Criteria<Researcher> {
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
public String getReference() {
return reference;
}
public void setReference(String reference) {
this.reference = reference;
}
} }

View File

@ -57,7 +57,9 @@ public class DMPDaoImpl extends DatabaseAccess<DMP> implements DMPDao {
query.where((builder, root) -> builder.equal(root.get("status"), DMP.DMPStatus.ACTIVE.getValue())); query.where((builder, root) -> builder.equal(root.get("status"), DMP.DMPStatus.ACTIVE.getValue()));
} }
} }
query.where(((builder, root) -> builder.equal(root.get("isPublic"), criteria.getIsPublic()))); if (criteria.getIsPublic()) {
query.where(((builder, root) -> builder.equal(root.get("isPublic"), criteria.getIsPublic())));
}
/*if (criteria.getRole() != null) { /*if (criteria.getRole() != null) {
if (criteria.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())) { if (criteria.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())) {
query.where((builder, root) -> builder.equal(root.join("users", JoinType.LEFT).get("role"), UserDMP.UserDMPRoles.OWNER.getValue())); query.where((builder, root) -> builder.equal(root.join("users", JoinType.LEFT).get("role"), UserDMP.UserDMPRoles.OWNER.getValue()));
@ -82,6 +84,10 @@ public class DMPDaoImpl extends DatabaseAccess<DMP> implements DMPDao {
builder.or(builder.greaterThan(root.get("grant").get("enddate"), new Date()) builder.or(builder.greaterThan(root.get("grant").get("enddate"), new Date())
, builder.isNull(root.get("grant").get("enddate")))); , builder.isNull(root.get("grant").get("enddate"))));
} }
if (criteria.hasDoi()) {
query.where((builder, root) -> builder.not(builder.isNull(root.get("doi"))));
}
query.where((builder, root) -> builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue())); query.where((builder, root) -> builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue()));
return query; return query;
} }

View File

@ -78,6 +78,10 @@ public class DatasetDaoImpl extends DatabaseAccess<Dataset> implements DatasetDa
query.where((builder, root) -> root.join("dmp", JoinType.LEFT).join("users", JoinType.LEFT).join("user", JoinType.LEFT).get("id").in(criteria.getCollaborators())); query.where((builder, root) -> root.join("dmp", JoinType.LEFT).join("users", JoinType.LEFT).join("user", JoinType.LEFT).get("id").in(criteria.getCollaborators()));
if (criteria.getDatasetTemplates() != null && !criteria.getDatasetTemplates().isEmpty()) if (criteria.getDatasetTemplates() != null && !criteria.getDatasetTemplates().isEmpty())
query.where((builder, root) -> root.get("profile").get("id").in(criteria.getDatasetTemplates())); query.where((builder, root) -> root.get("profile").get("id").in(criteria.getDatasetTemplates()));
if (criteria.hasDoi()) {
query.where((builder, root) -> builder.not(builder.isNull(root.get("dmp").get("doi"))));
}
query.where((builder, root) -> builder.notEqual(root.get("status"), Dataset.Status.DELETED.getValue())); query.where((builder, root) -> builder.notEqual(root.get("status"), Dataset.Status.DELETED.getValue()));
query.where((builder, root) -> builder.notEqual(root.get("status"), Dataset.Status.CANCELED.getValue())); query.where((builder, root) -> builder.notEqual(root.get("status"), Dataset.Status.CANCELED.getValue()));
return query; return query;

View File

@ -5,6 +5,7 @@ import eu.eudat.data.dao.criteria.DatasetProfileCriteria;
import eu.eudat.data.entities.DatasetProfile; import eu.eudat.data.entities.DatasetProfile;
import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.QueryableList;
import java.util.List;
import java.util.UUID; import java.util.UUID;
public interface DatasetProfileDao extends DatabaseAccessLayer<DatasetProfile, UUID> { public interface DatasetProfileDao extends DatabaseAccessLayer<DatasetProfile, UUID> {
@ -13,4 +14,6 @@ public interface DatasetProfileDao extends DatabaseAccessLayer<DatasetProfile, U
QueryableList<DatasetProfile> getAll(); QueryableList<DatasetProfile> getAll();
QueryableList<DatasetProfile> getAuthenticated(QueryableList<DatasetProfile> query, UUID principal, List<Integer> roles);
} }

View File

@ -3,6 +3,7 @@ package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess; import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.criteria.DatasetProfileCriteria; import eu.eudat.data.dao.criteria.DatasetProfileCriteria;
import eu.eudat.data.dao.databaselayer.service.DatabaseService; import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.DMP;
import eu.eudat.data.entities.DatasetProfile; import eu.eudat.data.entities.DatasetProfile;
import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.QueryableList;
import eu.eudat.queryable.types.FieldSelectionType; import eu.eudat.queryable.types.FieldSelectionType;
@ -11,8 +12,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.JoinType; import javax.persistence.criteria.JoinType;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -98,4 +101,18 @@ public class DatasetProfileDaoImpl extends DatabaseAccess<DatasetProfile> implem
public DatasetProfile find(UUID id, String hint) { public DatasetProfile find(UUID id, String hint) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override
public QueryableList<DatasetProfile> getAuthenticated(QueryableList<DatasetProfile> query, UUID principal, List<Integer> roles) {
if (roles != null && !roles.isEmpty()) {
query.where((builder, root) -> {
Join userJoin = root.join("users", JoinType.LEFT);
return builder.and(builder.equal(userJoin.join("user", JoinType.LEFT).get("id"), principal), userJoin.get("role").in(roles));
});
} else {
query.where((builder, root) -> builder.equal(root.join("users", JoinType.LEFT).join("user", JoinType.LEFT).get("id"), principal));
}
return query;
}
} }

View File

@ -0,0 +1,13 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.dao.criteria.EmailConfirmationCriteria;
import eu.eudat.data.entities.EmailConfirmation;
import eu.eudat.queryable.QueryableList;
import java.util.UUID;
public interface EmailConfirmationDao extends DatabaseAccessLayer<EmailConfirmation, UUID> {
QueryableList<EmailConfirmation> getWithCriteria(EmailConfirmationCriteria criteria);
}

View File

@ -0,0 +1,56 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.criteria.EmailConfirmationCriteria;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.EmailConfirmation;
import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Service("LoginConfirmationEmailDao")
public class EmailConfirmationDaoImpl extends DatabaseAccess<EmailConfirmation> implements EmailConfirmationDao {
@Autowired
public EmailConfirmationDaoImpl(DatabaseService<EmailConfirmation> databaseService) {
super(databaseService);
}
@Override
public QueryableList<EmailConfirmation> getWithCriteria(EmailConfirmationCriteria criteria) {
return null;
}
@Override
public EmailConfirmation createOrUpdate(EmailConfirmation item) {
return this.getDatabaseService().createOrUpdate(item, EmailConfirmation.class);
}
@Override
public CompletableFuture<EmailConfirmation> createOrUpdateAsync(EmailConfirmation item) {
return null;
}
@Override
public EmailConfirmation find(UUID id) {
return this.getDatabaseService().getQueryable(EmailConfirmation.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
}
@Override
public EmailConfirmation find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
@Override
public void delete(EmailConfirmation item) {
throw new UnsupportedOperationException();
}
@Override
public QueryableList<EmailConfirmation> asQueryable() {
return this.getDatabaseService().getQueryable(EmailConfirmation.class);
}
}

View File

@ -29,6 +29,8 @@ public class FunderDaoImpl extends DatabaseAccess<Funder> implements FunderDao {
builder.or(builder.like(builder.upper(root.get("definition")), "%" + criteria.getLike().toUpperCase() + "%")))); builder.or(builder.like(builder.upper(root.get("definition")), "%" + criteria.getLike().toUpperCase() + "%"))));
if (criteria.getReference() != null) if (criteria.getReference() != null)
query.where((builder, root) -> builder.like(builder.upper(root.get("reference")), "%" + criteria.getReference().toUpperCase() + "%")); query.where((builder, root) -> builder.like(builder.upper(root.get("reference")), "%" + criteria.getReference().toUpperCase() + "%"));
if (criteria.getExactReference() != null)
query.where((builder, root) -> builder.like(builder.upper(root.get("reference")), criteria.getExactReference().toUpperCase()));
query.where((builder, root) -> builder.notEqual(root.get("status"), Funder.Status.DELETED.getValue())); query.where((builder, root) -> builder.notEqual(root.get("status"), Funder.Status.DELETED.getValue()));
return query; return query;
} }

View File

@ -39,6 +39,8 @@ public class GrantDaoImpl extends DatabaseAccess<Grant> implements GrantDao {
query.where((builder, root) -> builder.greaterThan(root.get("startdate"), criteria.getPeriodStart())); query.where((builder, root) -> builder.greaterThan(root.get("startdate"), criteria.getPeriodStart()));
if (criteria.getReference() != null) if (criteria.getReference() != null)
query.where((builder, root) -> builder.like(root.get("reference"), "%" + criteria.getReference() + "%")); query.where((builder, root) -> builder.like(root.get("reference"), "%" + criteria.getReference() + "%"));
if (criteria.getExactReference() != null)
query.where((builder, root) -> builder.like(root.get("reference"), criteria.getExactReference()));
if (criteria.getGrantStateType() != null) { if (criteria.getGrantStateType() != null) {
if (criteria.getGrantStateType().equals(GrantStateType.FINISHED.getValue())) if (criteria.getGrantStateType().equals(GrantStateType.FINISHED.getValue()))
query.where((builder, root) -> builder.lessThan(root.get("enddate"), new Date())); query.where((builder, root) -> builder.lessThan(root.get("enddate"), new Date()));
@ -50,6 +52,10 @@ public class GrantDaoImpl extends DatabaseAccess<Grant> implements GrantDao {
if (criteria.isPublic()) { if (criteria.isPublic()) {
query.where((builder, root) -> builder.equal(root.join("dmps").get("status"), DMP.DMPStatus.FINALISED.getValue())).distinct(); query.where((builder, root) -> builder.equal(root.join("dmps").get("status"), DMP.DMPStatus.FINALISED.getValue())).distinct();
} }
if (criteria.isActive()) {
query.where((builder, root) -> builder.notEqual(root.join("dmps").get("status"), DMP.DMPStatus.DELETED.getValue())).distinct();
}
if (criteria.getFunderId() != null && !criteria.getFunderId().trim().isEmpty()) if (criteria.getFunderId() != null && !criteria.getFunderId().trim().isEmpty())
query.where((builder, root) -> builder.equal(root.get("funder").get("id"), UUID.fromString(criteria.getFunderId()))); query.where((builder, root) -> builder.equal(root.get("funder").get("id"), UUID.fromString(criteria.getFunderId())));
if (criteria.getFunderReference() != null && !criteria.getFunderReference().isEmpty()) if (criteria.getFunderReference() != null && !criteria.getFunderReference().isEmpty())

View File

@ -1,13 +0,0 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.dao.criteria.LoginConfirmationEmailCriteria;
import eu.eudat.data.entities.LoginConfirmationEmail;
import eu.eudat.queryable.QueryableList;
import java.util.UUID;
public interface LoginConfirmationEmailDao extends DatabaseAccessLayer<LoginConfirmationEmail, UUID> {
QueryableList<LoginConfirmationEmail> getWithCriteria(LoginConfirmationEmailCriteria criteria);
}

View File

@ -1,56 +0,0 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.criteria.LoginConfirmationEmailCriteria;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.LoginConfirmationEmail;
import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Service("LoginConfirmationEmailDao")
public class LoginConfirmationEmailDaoImpl extends DatabaseAccess<LoginConfirmationEmail> implements LoginConfirmationEmailDao {
@Autowired
public LoginConfirmationEmailDaoImpl(DatabaseService<LoginConfirmationEmail> databaseService) {
super(databaseService);
}
@Override
public QueryableList<LoginConfirmationEmail> getWithCriteria(LoginConfirmationEmailCriteria criteria) {
return null;
}
@Override
public LoginConfirmationEmail createOrUpdate(LoginConfirmationEmail item) {
return this.getDatabaseService().createOrUpdate(item, LoginConfirmationEmail.class);
}
@Override
public CompletableFuture<LoginConfirmationEmail> createOrUpdateAsync(LoginConfirmationEmail item) {
return null;
}
@Override
public LoginConfirmationEmail find(UUID id) {
return this.getDatabaseService().getQueryable(LoginConfirmationEmail.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
}
@Override
public LoginConfirmationEmail find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
@Override
public void delete(LoginConfirmationEmail item) {
throw new UnsupportedOperationException();
}
@Override
public QueryableList<LoginConfirmationEmail> asQueryable() {
return this.getDatabaseService().getQueryable(LoginConfirmationEmail.class);
}
}

View File

@ -26,13 +26,17 @@ public class OrganisationDaoImpl extends DatabaseAccess<Organisation> implements
@Override @Override
public QueryableList<Organisation> getWithCriteria(OrganisationCriteria criteria) { public QueryableList<Organisation> getWithCriteria(OrganisationCriteria criteria) {
QueryableList<Organisation> query = this.getDatabaseService().getQueryable(Organisation.class); QueryableList<Organisation> query = this.getDatabaseService().getQueryable(Organisation.class);
if (criteria.getLike() != null) if (criteria.getLabelLike() != null && criteria.getLike() != null) {
query.where((builder, root) -> builder.equal(root.get("reference"), criteria.getLike())); query.where((builder, root) -> builder.or(builder.equal(root.get("reference"), criteria.getLike()), builder.like(builder.upper(root.get("label")), "%" + criteria.getLabelLike().toUpperCase() + "%")));
if (criteria.getLabelLike() != null) { } else {
query.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + criteria.getLabelLike().toUpperCase() + "%")); if (criteria.getLike() != null)
} query.where((builder, root) -> builder.equal(root.get("reference"), criteria.getLike()));
if (criteria.getPublic() != null && criteria.getPublic()) { if (criteria.getLabelLike() != null) {
query.where((builder, root) -> builder.equal(root.join("dmps", JoinType.LEFT).get("status"), DMP.DMPStatus.FINALISED.getValue())); query.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + criteria.getLabelLike().toUpperCase() + "%"));
}
if (criteria.getPublic() != null && criteria.getPublic()) {
query.where((builder, root) -> builder.equal(root.join("dmps", JoinType.LEFT).get("status"), DMP.DMPStatus.FINALISED.getValue()));
}
} }
return query; return query;
} }
@ -64,7 +68,7 @@ public class OrganisationDaoImpl extends DatabaseAccess<Organisation> implements
} }
public QueryableList<Organisation> getAuthenticated(QueryableList<Organisation> query, UserInfo principal) { public QueryableList<Organisation> getAuthenticated(QueryableList<Organisation> query, UserInfo principal) {
query.where((builder, root) -> builder.equal(root.join("dmps").get("creator"), principal)); query.where((builder, root) -> builder.equal(root.join("dmps").join("users").get("user"), principal));
return query; return query;
} }

View File

@ -28,6 +28,8 @@ public class ProjectDaoImpl extends DatabaseAccess<Project> implements ProjectDa
builder.or(builder.like(builder.upper(root.get("description")), "%" + criteria.getLike().toUpperCase() + "%")))); builder.or(builder.like(builder.upper(root.get("description")), "%" + criteria.getLike().toUpperCase() + "%"))));
if (criteria.getReference() != null) if (criteria.getReference() != null)
query.where((builder, root) -> builder.like(root.get("reference"), "%" + criteria.getReference() + "%")); query.where((builder, root) -> builder.like(root.get("reference"), "%" + criteria.getReference() + "%"));
if (criteria.getExactReference() != null)
query.where((builder, root) -> builder.like(root.get("reference"), criteria.getExactReference()));
query.where((builder, root) -> builder.notEqual(root.get("status"), Project.Status.DELETED.getValue())); query.where((builder, root) -> builder.notEqual(root.get("status"), Project.Status.DELETED.getValue()));
return query; return query;
} }

View File

@ -27,6 +27,8 @@ public class ResearcherDaoImpl extends DatabaseAccess<Researcher> implements Res
query.where((builder, root) ->builder.or(builder.like(builder.upper(root.get("reference")), "%" + criteria.getLike().toUpperCase() + "%"))); query.where((builder, root) ->builder.or(builder.like(builder.upper(root.get("reference")), "%" + criteria.getLike().toUpperCase() + "%")));
if (criteria.getName() != null && !criteria.getName().isEmpty()) if (criteria.getName() != null && !criteria.getName().isEmpty())
query.where((builder, root) ->builder.or(builder.like(builder.upper(root.get("label")), "%" + criteria.getName().toUpperCase() + "%"))); query.where((builder, root) ->builder.or(builder.like(builder.upper(root.get("label")), "%" + criteria.getName().toUpperCase() + "%")));
if (criteria.getReference() != null && !criteria.getReference().isEmpty())
query.where((builder, root) ->builder.or(builder.like(builder.upper(root.get("reference")), criteria.getReference().toUpperCase())));
return query; return query;
} }

View File

@ -0,0 +1,13 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.entities.UserDMP;
import eu.eudat.data.entities.UserDatasetProfile;
import java.util.UUID;
/**
* Created by ikalyvas on 2/8/2018.
*/
public interface UserDatasetProfileDao extends DatabaseAccessLayer<UserDatasetProfile, UUID> {
}

View File

@ -0,0 +1,53 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.UserDMP;
import eu.eudat.data.entities.UserDatasetProfile;
import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Component("userDatasetProfileDao")
public class UserDatasetProfileDaoImpl extends DatabaseAccess<UserDatasetProfile> implements UserDatasetProfileDao {
@Autowired
public UserDatasetProfileDaoImpl(DatabaseService<UserDatasetProfile> databaseService) {
super(databaseService);
}
@Override
public UserDatasetProfile createOrUpdate(UserDatasetProfile item) {
return this.getDatabaseService().createOrUpdate(item, UserDatasetProfile.class);
}
@Override
public UserDatasetProfile find(UUID id) {
return this.getDatabaseService().getQueryable(UserDatasetProfile.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingleOrDefault();
}
@Override
public void delete(UserDatasetProfile item) {
this.getDatabaseService().delete(item);
}
@Override
public QueryableList<UserDatasetProfile> asQueryable() {
return this.getDatabaseService().getQueryable(UserDatasetProfile.class);
}
@Async
@Override
public CompletableFuture<UserDatasetProfile> createOrUpdateAsync(UserDatasetProfile item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public UserDatasetProfile find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
}

View File

@ -26,6 +26,7 @@ public class UserInfoDaoImpl extends DatabaseAccess<UserInfo> implements UserInf
@Override @Override
public QueryableList<UserInfo> getWithCriteria(UserInfoCriteria criteria) { public QueryableList<UserInfo> getWithCriteria(UserInfoCriteria criteria) {
QueryableList<UserInfo> users = this.getDatabaseService().getQueryable(UserInfo.class); QueryableList<UserInfo> users = this.getDatabaseService().getQueryable(UserInfo.class);
users.where(((builder, root) -> builder.equal(root.get("userStatus"), 0)));
if (criteria.getAppRoles() != null && !criteria.getAppRoles().isEmpty()) if (criteria.getAppRoles() != null && !criteria.getAppRoles().isEmpty())
users.where((builder, root) -> root.join("userRoles").get("role").in(criteria.getAppRoles())); users.where((builder, root) -> root.join("userRoles").get("role").in(criteria.getAppRoles()));
if (criteria.getLike() != null) if (criteria.getLike() != null)

View File

@ -34,6 +34,8 @@ public class Credential implements DataEntity<Credential, UUID> {
private Integer provider; private Integer provider;
@Column(name = "\"Public\"", nullable = false) @Column(name = "\"Public\"", nullable = false)
private String publicValue; private String publicValue;
@Column(name = "\"Email\"", nullable = false)
private String email;
@Column(name = "\"Secret\"", nullable = false) @Column(name = "\"Secret\"", nullable = false)
private String secret; private String secret;
@ -88,6 +90,14 @@ public class Credential implements DataEntity<Credential, UUID> {
this.publicValue = publicValue; this.publicValue = publicValue;
} }
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getSecret() { public String getSecret() {
return secret; return secret;
} }
@ -139,6 +149,7 @@ public class Credential implements DataEntity<Credential, UUID> {
public void update(Credential entity) { public void update(Credential entity) {
this.status = entity.status; this.status = entity.status;
this.publicValue = entity.getPublicValue(); this.publicValue = entity.getPublicValue();
this.email = entity.getEmail();
this.secret = entity.getSecret(); this.secret = entity.getSecret();
this.lastUpdateTime = new Date(); this.lastUpdateTime = new Date();
} }

View File

@ -89,6 +89,9 @@ public class DatasetProfile implements DataEntity<DatasetProfile,UUID>{
@Column(name = "\"Language\"", nullable = false) @Column(name = "\"Language\"", nullable = false)
private String language; private String language;
@OneToMany(mappedBy = "datasetProfile", fetch = FetchType.LAZY)
private Set<UserDatasetProfile> users;
public String getDescription() { public String getDescription() {
return description; return description;
@ -158,6 +161,14 @@ public class DatasetProfile implements DataEntity<DatasetProfile,UUID>{
this.language = language; this.language = language;
} }
public Set<UserDatasetProfile> getUsers() {
return users;
}
public void setUsers(Set<UserDatasetProfile> users) {
this.users = users;
}
@Override @Override
public String toString() { public String toString() {
return "DatasetProfileListingModel [id=" + id + ", label=" + label + ", dataset=" + dataset + ", definition=" + definition + ", version=" + version + ", language=" + language + "]"; return "DatasetProfileListingModel [id=" + id + ", label=" + label + ", dataset=" + dataset + ", definition=" + definition + ", version=" + version + ", language=" + language + "]";

View File

@ -10,8 +10,8 @@ import java.util.List;
import java.util.UUID; import java.util.UUID;
@Entity @Entity
@Table(name = "\"LoginConfirmationEmail\"") @Table(name = "\"EmailConfirmation\"")
public class LoginConfirmationEmail implements DataEntity<LoginConfirmationEmail, UUID> { public class EmailConfirmation implements DataEntity<EmailConfirmation, UUID> {
@Id @Id
@GeneratedValue @GeneratedValue
@ -30,6 +30,9 @@ public class LoginConfirmationEmail implements DataEntity<LoginConfirmationEmail
@Column(name = "\"userId\"", nullable = false) @Column(name = "\"userId\"", nullable = false)
private UUID userId; private UUID userId;
@Column(name = "\"data\"", nullable = false)
private String data;
@Column(name = "\"expiresAt\"", nullable = false) @Column(name = "\"expiresAt\"", nullable = false)
@Convert(converter = DateToUTCConverter.class) @Convert(converter = DateToUTCConverter.class)
@ -77,9 +80,14 @@ public class LoginConfirmationEmail implements DataEntity<LoginConfirmationEmail
this.expiresAt = expiresAt; this.expiresAt = expiresAt;
} }
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
@Override @Override
public void update(LoginConfirmationEmail entity) { public void update(EmailConfirmation entity) {
} }
@Override @Override
@ -88,7 +96,7 @@ public class LoginConfirmationEmail implements DataEntity<LoginConfirmationEmail
} }
@Override @Override
public LoginConfirmationEmail buildFromTuple(List<Tuple> tuple, List<String> fields, String base) { public EmailConfirmation buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
return null; return null;
} }
} }

View File

@ -0,0 +1,79 @@
package eu.eudat.data.entities;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.*;
import java.util.List;
import java.util.UUID;
@Entity
@Table(name = "\"UserDatasetProfile\"")
public class UserDatasetProfile implements DataEntity<UserDatasetProfile, UUID> {
@Id
@GeneratedValue
@GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "usr")
private UserInfo user;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "\"datasetProfile\"")
private DatasetProfile datasetProfile;
@Column(name = "role")
private Integer role;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public UserInfo getUser() {
return user;
}
public void setUser(UserInfo user) {
this.user = user;
}
public DatasetProfile getDatasetProfile() {
return datasetProfile;
}
public void setDatasetProfile(DatasetProfile datasetProfile) {
this.datasetProfile = datasetProfile;
}
public Integer getRole() {
return role;
}
public void setRole(Integer role) {
this.role = role;
}
@Override
public void update(UserDatasetProfile entity) {
this.role = entity.getRole();
}
@Override
public UUID getKeys() {
return this.id;
}
@Override
public UserDatasetProfile buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
String currentBase = base.isEmpty() ? "" : base + ".";
if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id");
return this;
}
}

View File

@ -15,7 +15,7 @@ import java.util.*;
@NamedEntityGraphs({ @NamedEntityGraphs({
@NamedEntityGraph( @NamedEntityGraph(
name = "userInfo", name = "userInfo",
attributeNodes = {@NamedAttributeNode("userRoles"), @NamedAttributeNode("credentials")}), attributeNodes = {@NamedAttributeNode("userRoles"), @NamedAttributeNode("credentials"), @NamedAttributeNode("additionalinfo")}),
}) })
public class UserInfo implements DataEntity<UserInfo, UUID> { public class UserInfo implements DataEntity<UserInfo, UUID> {
@ -35,6 +35,9 @@ public class UserInfo implements DataEntity<UserInfo, UUID> {
@Column(name = "usertype", nullable = false) @Column(name = "usertype", nullable = false)
private Short usertype; // 0 internal, 1 external private Short usertype; // 0 internal, 1 external
@Column(name = "userstatus", nullable = false)
private Short userStatus; // 0 active, 1 inactive
@Column(name = "verified_email", nullable = true) @Column(name = "verified_email", nullable = true)
private Boolean verified_email = null; private Boolean verified_email = null;
@ -187,6 +190,14 @@ public class UserInfo implements DataEntity<UserInfo, UUID> {
this.notifications = notifications; this.notifications = notifications;
} }
public Short getUserStatus() {
return userStatus;
}
public void setUserStatus(Short userStatus) {
this.userStatus = userStatus;
}
@Override @Override
public void update(UserInfo entity) { public void update(UserInfo entity) {
this.name = entity.getName(); this.name = entity.getName();
@ -194,6 +205,7 @@ public class UserInfo implements DataEntity<UserInfo, UUID> {
this.additionalinfo = entity.getAdditionalinfo(); this.additionalinfo = entity.getAdditionalinfo();
this.lastloggedin = entity.getLastloggedin(); this.lastloggedin = entity.getLastloggedin();
this.userRoles = entity.getUserRoles(); this.userRoles = entity.getUserRoles();
this.userStatus = entity.getUserStatus();
} }
@Override @Override

View File

@ -4,4 +4,13 @@ import java.util.UUID;
public class DatasetProfileQuery { public class DatasetProfileQuery {
private UserQuery userQuery;
public UserQuery getUserQuery() {
return userQuery;
}
public void setUserQuery(UserQuery userQuery) {
this.userQuery = userQuery;
}
} }

View File

@ -26,6 +26,7 @@ import org.elasticsearch.search.aggregations.bucket.nested.ParsedNested;
import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.IOException; import java.io.IOException;
@ -37,10 +38,12 @@ import java.util.stream.Stream;
public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteria> { public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteria> {
private final DmpRepository dmpRepository; private final DmpRepository dmpRepository;
private final Environment environment;
public DatasetRepository(RestHighLevelClient client, DmpRepository dmpRepository) { public DatasetRepository(RestHighLevelClient client, DmpRepository dmpRepository, Environment environment) {
super(client); super(client);
this.dmpRepository = dmpRepository; this.dmpRepository = dmpRepository;
this.environment = environment;
} }
@Override @Override
@ -64,7 +67,7 @@ public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteri
} }
dmp.getDatasets().add(entity); dmp.getDatasets().add(entity);
} }
IndexRequest request = new IndexRequest("dmps").id(dmp.getId().toString()).source(dmp.toElasticEntity(builder));//new IndexRequest("datasets", "doc", entity.getId()).source(entity.toElasticEntity(builder)); IndexRequest request = new IndexRequest(this.environment.getProperty("elasticsearch.index")).id(dmp.getId().toString()).source(dmp.toElasticEntity(builder));//new IndexRequest("datasets", "doc", entity.getId()).source(entity.toElasticEntity(builder));
this.getClient().index(request, RequestOptions.DEFAULT); this.getClient().index(request, RequestOptions.DEFAULT);
return entity; return entity;
} }
@ -74,7 +77,7 @@ public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteri
@Override @Override
public Dataset findDocument(String id) throws IOException { public Dataset findDocument(String id) throws IOException {
if (this.getClient() != null) { if (this.getClient() != null) {
SearchRequest searchRequest = new SearchRequest("dmps"); SearchRequest searchRequest = new SearchRequest(this.environment.getProperty("elasticsearch.index"));
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery().should(QueryBuilders.termQuery("datasets.id.keyword", id)); BoolQueryBuilder boolQuery = QueryBuilders.boolQuery().should(QueryBuilders.termQuery("datasets.id.keyword", id));
NestedQueryBuilder nestedQueryBuilder = QueryBuilders.nestedQuery( "datasets", boolQuery, ScoreMode.Avg).innerHit(new InnerHitBuilder()); NestedQueryBuilder nestedQueryBuilder = QueryBuilders.nestedQuery( "datasets", boolQuery, ScoreMode.Avg).innerHit(new InnerHitBuilder());
@ -95,7 +98,7 @@ public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteri
@Override @Override
public List<Dataset> query(DatasetCriteria criteria) throws IOException { public List<Dataset> query(DatasetCriteria criteria) throws IOException {
if (this.getClient() != null) { if (this.getClient() != null) {
SearchRequest searchRequest = new SearchRequest("dmps"); SearchRequest searchRequest = new SearchRequest(this.environment.getProperty("elasticsearch.index"));
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
/*CountRequest countRequest = new CountRequest("dmps").routing("datasets").routing("id"); /*CountRequest countRequest = new CountRequest("dmps").routing("datasets").routing("id");
@ -103,7 +106,7 @@ public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteri
CountResponse countResponse = getClient().count(countRequest, RequestOptions.DEFAULT); CountResponse countResponse = getClient().count(countRequest, RequestOptions.DEFAULT);
Long count = countResponse.getCount();*/ Long count = countResponse.getCount();*/
SearchRequest countRequest = new SearchRequest("dmps"); SearchRequest countRequest = new SearchRequest(this.environment.getProperty("elasticsearch.index"));
NestedAggregationBuilder nestedAggregationBuilder = AggregationBuilders.nested("by_dataset", "datasets"); NestedAggregationBuilder nestedAggregationBuilder = AggregationBuilders.nested("by_dataset", "datasets");
FiltersAggregationBuilder filtersAggregationBuilder = AggregationBuilders.filters("dataset_query", QueryBuilders.boolQuery().mustNot(QueryBuilders.termsQuery("datasets.status.keyword", Stream.of(Dataset.Status.DELETED.getValue(), Dataset.Status.CANCELED.getValue()).collect(Collectors.toList())))); FiltersAggregationBuilder filtersAggregationBuilder = AggregationBuilders.filters("dataset_query", QueryBuilders.boolQuery().mustNot(QueryBuilders.termsQuery("datasets.status.keyword", Stream.of(Dataset.Status.DELETED.getValue(), Dataset.Status.CANCELED.getValue()).collect(Collectors.toList()))));
nestedAggregationBuilder.subAggregation(filtersAggregationBuilder); nestedAggregationBuilder.subAggregation(filtersAggregationBuilder);
@ -193,7 +196,7 @@ public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteri
@Override @Override
public boolean exists() throws IOException { public boolean exists() throws IOException {
if (this.getClient() != null) { if (this.getClient() != null) {
GetIndexRequest request = new GetIndexRequest("dmps"); GetIndexRequest request = new GetIndexRequest(this.environment.getProperty("elasticsearch.index"));
// request.indices("datasets"); // request.indices("datasets");
return this.getClient().indices().exists(request, RequestOptions.DEFAULT); return this.getClient().indices().exists(request, RequestOptions.DEFAULT);
} }

View File

@ -26,6 +26,7 @@ import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.IOException; import java.io.IOException;
@ -37,9 +38,12 @@ import java.util.stream.Stream;
public class DmpRepository extends ElasticRepository<Dmp, DmpCriteria> { public class DmpRepository extends ElasticRepository<Dmp, DmpCriteria> {
private static final Logger logger = LoggerFactory.getLogger(DmpRepository.class); private static final Logger logger = LoggerFactory.getLogger(DmpRepository.class);
private final Environment environment;
@Autowired @Autowired
public DmpRepository(RestHighLevelClient client) { public DmpRepository(RestHighLevelClient client, Environment environment) {
super(client); super(client);
this.environment = environment;
} }
private void generateMapping() throws IOException { private void generateMapping() throws IOException {
@ -52,7 +56,7 @@ public class DmpRepository extends ElasticRepository<Dmp, DmpCriteria> {
builder.endObject(); builder.endObject();
builder.endObject(); builder.endObject();
builder.endObject(); builder.endObject();
PutMappingRequest putMappingRequest = new PutMappingRequest("dmps"); PutMappingRequest putMappingRequest = new PutMappingRequest(this.environment.getProperty("elasticsearch.index"));
putMappingRequest.source(builder); putMappingRequest.source(builder);
this.getClient().indices().putMapping(putMappingRequest, RequestOptions.DEFAULT); this.getClient().indices().putMapping(putMappingRequest, RequestOptions.DEFAULT);
} }
@ -62,7 +66,7 @@ public class DmpRepository extends ElasticRepository<Dmp, DmpCriteria> {
public Dmp createOrUpdate(Dmp entity) throws IOException { public Dmp createOrUpdate(Dmp entity) throws IOException {
if (this.getClient() != null) { if (this.getClient() != null) {
XContentBuilder builder = XContentFactory.jsonBuilder(); XContentBuilder builder = XContentFactory.jsonBuilder();
IndexRequest request = new IndexRequest("dmps").id(entity.getId().toString()).source(entity.toElasticEntity(builder)); IndexRequest request = new IndexRequest(this.environment.getProperty("elasticsearch.index")).id(entity.getId().toString()).source(entity.toElasticEntity(builder));
IndexResponse response = this.getClient().index(request, RequestOptions.DEFAULT); IndexResponse response = this.getClient().index(request, RequestOptions.DEFAULT);
return entity; return entity;
} }
@ -72,7 +76,7 @@ public class DmpRepository extends ElasticRepository<Dmp, DmpCriteria> {
@Override @Override
public Dmp findDocument(String id) throws IOException { public Dmp findDocument(String id) throws IOException {
if (this.getClient() != null) { if (this.getClient() != null) {
GetRequest request = new GetRequest("dmps", id); GetRequest request = new GetRequest(this.environment.getProperty("elasticsearch.index"), id);
GetResponse response = this.getClient().get(request, RequestOptions.DEFAULT); GetResponse response = this.getClient().get(request, RequestOptions.DEFAULT);
return new Dmp().fromElasticEntity(response.getSourceAsMap()); return new Dmp().fromElasticEntity(response.getSourceAsMap());
} }
@ -82,10 +86,10 @@ public class DmpRepository extends ElasticRepository<Dmp, DmpCriteria> {
@Override @Override
public List<Dmp> query(DmpCriteria criteria) throws IOException { public List<Dmp> query(DmpCriteria criteria) throws IOException {
if (this.getClient() != null) { if (this.getClient() != null) {
SearchRequest searchRequest = new SearchRequest("dmps"); SearchRequest searchRequest = new SearchRequest(this.environment.getProperty("elasticsearch.index"));
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
CountRequest countRequest = new CountRequest("dmps"); CountRequest countRequest = new CountRequest(this.environment.getProperty("elasticsearch.index"));
countRequest.query(QueryBuilders.boolQuery().mustNot(QueryBuilders.termsQuery(Dmp.MapKey.STATUS.getName(), Collections.singletonList(Dmp.DMPStatus.DELETED.getValue())))); countRequest.query(QueryBuilders.boolQuery().mustNot(QueryBuilders.termsQuery(Dmp.MapKey.STATUS.getName(), Collections.singletonList(Dmp.DMPStatus.DELETED.getValue()))));
CountResponse countResponse = getClient().count(countRequest, RequestOptions.DEFAULT); CountResponse countResponse = getClient().count(countRequest, RequestOptions.DEFAULT);
Long count = countResponse.getCount(); Long count = countResponse.getCount();
@ -152,7 +156,7 @@ public class DmpRepository extends ElasticRepository<Dmp, DmpCriteria> {
public boolean createIndex() { public boolean createIndex() {
try { try {
if (!this.exists()) { if (!this.exists()) {
CreateIndexRequest createIndexRequest = new CreateIndexRequest("dmps"); CreateIndexRequest createIndexRequest = new CreateIndexRequest(this.environment.getProperty("elasticsearch.index"));
this.getClient().indices().create(createIndexRequest, RequestOptions.DEFAULT); this.getClient().indices().create(createIndexRequest, RequestOptions.DEFAULT);
this.generateMapping(); this.generateMapping();
} }
@ -166,7 +170,7 @@ public class DmpRepository extends ElasticRepository<Dmp, DmpCriteria> {
@Override @Override
public boolean exists() throws IOException { public boolean exists() throws IOException {
if (this.getClient() != null) { if (this.getClient() != null) {
GetIndexRequest request = new GetIndexRequest("dmps"); GetIndexRequest request = new GetIndexRequest(this.environment.getProperty("elasticsearch.index"));
return this.getClient().indices().exists(request, RequestOptions.DEFAULT); return this.getClient().indices().exists(request, RequestOptions.DEFAULT);
} }
return false; return false;
@ -175,10 +179,10 @@ public class DmpRepository extends ElasticRepository<Dmp, DmpCriteria> {
@Override @Override
public void clear() throws IOException { public void clear() throws IOException {
if (exists()) { if (exists()) {
DeleteByQueryRequest delete = new DeleteByQueryRequest("dmps"); DeleteByQueryRequest delete = new DeleteByQueryRequest(this.environment.getProperty("elasticsearch.index"));
delete.setQuery(QueryBuilders.matchAllQuery()); delete.setQuery(QueryBuilders.matchAllQuery());
this.getClient().deleteByQuery(delete, RequestOptions.DEFAULT); this.getClient().deleteByQuery(delete, RequestOptions.DEFAULT);
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest("dmps"); DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(this.environment.getProperty("elasticsearch.index"));
this.getClient().indices().delete(deleteIndexRequest, RequestOptions.DEFAULT); this.getClient().indices().delete(deleteIndexRequest, RequestOptions.DEFAULT);
} }
} }

View File

@ -225,6 +225,38 @@
<version>1.3.1</version> <version>1.3.1</version>
</dependency> </dependency>
<!-- The client -->
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient</artifactId>
<version>0.10.0</version>
</dependency>
<!-- Hotspot JVM metrics-->
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_hotspot</artifactId>
<version>0.10.0</version>
</dependency>
<!-- Exposition HTTPServer-->
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_httpserver</artifactId>
<version>0.10.0</version>
</dependency>
<!-- Pushgateway exposition-->
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_pushgateway</artifactId>
<version>0.10.0</version>
</dependency>
<!-- Pushgateway exposition-->
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_spring_boot</artifactId>
<version>0.10.0</version>
</dependency>
</dependencies> </dependencies>

View File

@ -4,6 +4,7 @@ import eu.eudat.controllers.interceptors.RequestInterceptor;
import eu.eudat.logic.handlers.PrincipalArgumentResolver; import eu.eudat.logic.handlers.PrincipalArgumentResolver;
import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.ApiContext;
import eu.eudat.logic.services.operations.authentication.AuthenticationService; import eu.eudat.logic.services.operations.authentication.AuthenticationService;
import io.prometheus.client.spring.boot.EnablePrometheusEndpoint;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableAsync;
@ -17,6 +18,7 @@ import java.util.List;
@EnableAsync @EnableAsync
@Configuration @Configuration
@EnableScheduling @EnableScheduling
@EnablePrometheusEndpoint
public class WebMVCConfiguration extends WebMvcConfigurerAdapter { public class WebMVCConfiguration extends WebMvcConfigurerAdapter {
private ApiContext apiContext; private ApiContext apiContext;

View File

@ -1,10 +1,13 @@
package eu.eudat.controllers; package eu.eudat.controllers;
import eu.eudat.data.entities.UserDatasetProfile;
import eu.eudat.data.entities.UserInfo;
import eu.eudat.data.query.items.table.datasetprofile.DatasetProfileTableRequestItem; import eu.eudat.data.query.items.table.datasetprofile.DatasetProfileTableRequestItem;
import eu.eudat.exceptions.datasetprofile.DatasetProfileNewVersionException; import eu.eudat.exceptions.datasetprofile.DatasetProfileNewVersionException;
import eu.eudat.exceptions.datasetprofile.DatasetProfileWithDatasetsExeption; import eu.eudat.exceptions.datasetprofile.DatasetProfileWithDatasetsExeption;
import eu.eudat.logic.managers.AdminManager; import eu.eudat.logic.managers.AdminManager;
import eu.eudat.logic.managers.DatasetProfileManager; import eu.eudat.logic.managers.DatasetProfileManager;
import eu.eudat.logic.managers.MetricsManager;
import eu.eudat.logic.managers.UserManager; import eu.eudat.logic.managers.UserManager;
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader; import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
import eu.eudat.logic.security.claims.ClaimedAuthorities; import eu.eudat.logic.security.claims.ClaimedAuthorities;
@ -13,7 +16,7 @@ import eu.eudat.models.data.admin.composite.DatasetProfile;
import eu.eudat.models.data.datasetprofile.DatasetProfileListingModel; import eu.eudat.models.data.datasetprofile.DatasetProfileListingModel;
import eu.eudat.models.data.helpers.common.DataTableData; import eu.eudat.models.data.helpers.common.DataTableData;
import eu.eudat.models.data.helpers.responses.ResponseItem; import eu.eudat.models.data.helpers.responses.ResponseItem;
import org.springframework.core.env.Environment; import eu.eudat.models.data.listingmodels.UserInfoListingModel;
import eu.eudat.models.data.security.Principal; import eu.eudat.models.data.security.Principal;
import eu.eudat.models.data.user.composite.PagedDatasetProfile; import eu.eudat.models.data.user.composite.PagedDatasetProfile;
import eu.eudat.types.ApiMessageCode; import eu.eudat.types.ApiMessageCode;
@ -28,8 +31,10 @@ import javax.validation.Valid;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors;
import static eu.eudat.types.Authorities.ADMIN; import static eu.eudat.types.Authorities.ADMIN;
import static eu.eudat.types.Authorities.DATASET_PROFILE_MANAGER;
@RestController @RestController
@CrossOrigin @CrossOrigin
@ -50,34 +55,48 @@ public class Admin extends BaseController {
@Transactional @Transactional
@RequestMapping(method = RequestMethod.POST, value = {"/addDmp"}, consumes = "application/json", produces = "application/json") @RequestMapping(method = RequestMethod.POST, value = {"/addDmp"}, consumes = "application/json", produces = "application/json")
public ResponseEntity<Object> addDmp(@Valid @RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) { public ResponseEntity<Object> addDmp(@Valid @RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN ,DATASET_PROFILE_MANAGER}) Principal principal) {
//this.getLoggerService().info(principal, "Admin Added Dataset Profile"); //this.getLoggerService().info(principal, "Admin Added Dataset Profile");
DatasetProfile shortenProfile = profile.toShort(); DatasetProfile shortenProfile = profile.toShort();
eu.eudat.data.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(shortenProfile, getApiContext()); eu.eudat.data.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(shortenProfile, getApiContext());
modelDefinition.setGroupId(UUID.randomUUID()); modelDefinition.setGroupId(UUID.randomUUID());
modelDefinition.setVersion((short) 0); modelDefinition.setVersion((short) 0);
this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(modelDefinition);
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("argos_dataset_templates", 1, "total");
return ResponseEntity.status(HttpStatus.OK).body(modelDefinition.getId()); return ResponseEntity.status(HttpStatus.OK).body(modelDefinition.getId());
} }
@Transactional @Transactional
@RequestMapping(method = RequestMethod.POST, value = {"/addDmp/{id}"}, consumes = "application/json", produces = "application/json") @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}) Principal principal) { public ResponseEntity<ResponseItem<UUID>> updateDmp(@PathVariable String id, @RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN, DATASET_PROFILE_MANAGER}) Principal principal) {
DatasetProfile shortenProfile = profile.toShort(); DatasetProfile shortenProfile = profile.toShort();
eu.eudat.data.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(shortenProfile, getApiContext()); 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)); eu.eudat.data.entities.DatasetProfile datasetprofile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id));
datasetprofile.setDefinition(modelDefinition.getDefinition()); datasetprofile.setDefinition(modelDefinition.getDefinition());
Short oldStatus = datasetprofile.getStatus();
datasetprofile.setStatus(modelDefinition.getStatus()); datasetprofile.setStatus(modelDefinition.getStatus());
datasetprofile.setLabel(modelDefinition.getLabel()); datasetprofile.setLabel(modelDefinition.getLabel());
datasetprofile.setDescription(modelDefinition.getDescription()); datasetprofile.setDescription(modelDefinition.getDescription());
datasetprofile.setLanguage(modelDefinition.getLanguage()); datasetprofile.setLanguage(modelDefinition.getLanguage());
this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(datasetprofile); 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("argos_dataset_templates", 1, "active");
}
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UUID>().status(ApiMessageCode.NO_MESSAGE)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UUID>().status(ApiMessageCode.NO_MESSAGE));
} }
@Transactional @Transactional
@RequestMapping(method = RequestMethod.POST, value = {"/newVersion/{id}"}, produces = "application/json") @RequestMapping(method = RequestMethod.POST, value = {"/newVersion/{id}"}, produces = "application/json")
public ResponseEntity newVersionDatasetProfile(@PathVariable String id, @RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) throws Exception { public ResponseEntity newVersionDatasetProfile(@PathVariable String id, @RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN, DATASET_PROFILE_MANAGER}) Principal principal) throws Exception {
try { try {
eu.eudat.data.entities.DatasetProfile modelDefinition = this.datasetProfileManager.createNewVersionDatasetProfile(id, profile); eu.eudat.data.entities.DatasetProfile modelDefinition = this.datasetProfileManager.createNewVersionDatasetProfile(id, profile);
return ResponseEntity.status(HttpStatus.OK).body(modelDefinition.getId()); return ResponseEntity.status(HttpStatus.OK).body(modelDefinition.getId());
@ -87,20 +106,21 @@ public class Admin extends BaseController {
} }
@RequestMapping(method = RequestMethod.GET, value = {"/get/{id}"}, produces = "application/json") @RequestMapping(method = RequestMethod.GET, value = {"/get/{id}"}, produces = "application/json")
public ResponseEntity<ResponseItem<DatasetProfile>> get(@PathVariable String id, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) { @Transactional
public ResponseEntity<ResponseItem<DatasetProfile>> get(@PathVariable String id, @ClaimedAuthorities(claims = {ADMIN, DATASET_PROFILE_MANAGER}) Principal principal) {
eu.eudat.models.data.admin.composite.DatasetProfile datasetprofile = this.datasetProfileManager.getDatasetProfile(id); eu.eudat.models.data.admin.composite.DatasetProfile datasetprofile = this.datasetProfileManager.getDatasetProfile(id);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetProfile>().status(ApiMessageCode.NO_MESSAGE).payload(datasetprofile)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetProfile>().status(ApiMessageCode.NO_MESSAGE).payload(datasetprofile));
} }
@RequestMapping(method = RequestMethod.POST, value = {"/datasetprofiles/getPaged"}, produces = "application/json") @RequestMapping(method = RequestMethod.POST, value = {"/datasetprofiles/getPaged"}, produces = "application/json")
public @ResponseBody public @ResponseBody
ResponseEntity<ResponseItem<DataTableData<DatasetProfileListingModel>>> getPaged(@RequestBody DatasetProfileTableRequestItem datasetProfileTableRequestItem, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) throws Exception { ResponseEntity<ResponseItem<DataTableData<DatasetProfileListingModel>>> getPaged(@RequestBody DatasetProfileTableRequestItem datasetProfileTableRequestItem, @ClaimedAuthorities(claims = {ADMIN, DATASET_PROFILE_MANAGER}) Principal principal) throws Exception {
DataTableData<DatasetProfileListingModel> datasetProfileTableData = this.datasetProfileManager.getPaged(datasetProfileTableRequestItem); DataTableData<DatasetProfileListingModel> datasetProfileTableData = this.datasetProfileManager.getPaged(datasetProfileTableRequestItem, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DatasetProfileListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(datasetProfileTableData)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DatasetProfileListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(datasetProfileTableData));
} }
@RequestMapping(method = RequestMethod.POST, value = {"/preview"}, consumes = "application/json", produces = "application/json") @RequestMapping(method = RequestMethod.POST, value = {"/preview"}, consumes = "application/json", produces = "application/json")
public ResponseEntity<ResponseItem<PagedDatasetProfile>> getPreview(@RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) { public ResponseEntity<ResponseItem<PagedDatasetProfile>> getPreview(@RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN, DATASET_PROFILE_MANAGER}) Principal principal) {
eu.eudat.data.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(profile, getApiContext()); eu.eudat.data.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(profile, getApiContext());
eu.eudat.models.data.user.composite.DatasetProfile datasetProfile = userManager.generateDatasetProfileModel(modelDefinition); eu.eudat.models.data.user.composite.DatasetProfile datasetProfile = userManager.generateDatasetProfileModel(modelDefinition);
PagedDatasetProfile pagedDatasetProfile = new PagedDatasetProfile(); PagedDatasetProfile pagedDatasetProfile = new PagedDatasetProfile();
@ -110,18 +130,20 @@ public class Admin extends BaseController {
@Transactional @Transactional
@RequestMapping(method = RequestMethod.POST, value = {"/datasetprofile/clone/{id}"}, consumes = "application/json", produces = "application/json") @RequestMapping(method = RequestMethod.POST, value = {"/datasetprofile/clone/{id}"}, consumes = "application/json", produces = "application/json")
public ResponseEntity<ResponseItem<eu.eudat.models.data.admin.composite.DatasetProfile>> clone(@PathVariable String id, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) { public ResponseEntity<ResponseItem<eu.eudat.models.data.admin.composite.DatasetProfile>> clone(@PathVariable String id, @ClaimedAuthorities(claims = {ADMIN, DATASET_PROFILE_MANAGER}) Principal principal) {
eu.eudat.data.entities.DatasetProfile profile = this.datasetProfileManager.clone(id); eu.eudat.data.entities.DatasetProfile profile = this.datasetProfileManager.clone(id);
eu.eudat.models.data.admin.composite.DatasetProfile datasetprofile = AdminManager.generateDatasetProfileModel(profile); eu.eudat.models.data.admin.composite.DatasetProfile datasetprofile = AdminManager.generateDatasetProfileModel(profile);
datasetprofile.setLabel(profile.getLabel() + " new "); datasetprofile.setLabel(profile.getLabel() + " new ");
datasetprofile.setLanguage(profile.getLanguage()); datasetprofile.setLanguage(profile.getLanguage());
datasetprofile.setDescription(profile.getDescription());
//datasetProfileManager.retrieveUsers(profile, datasetprofile);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.models.data.admin.composite.DatasetProfile>().payload(datasetprofile)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.models.data.admin.composite.DatasetProfile>().payload(datasetprofile));
} }
@Transactional @Transactional
@RequestMapping(method = RequestMethod.DELETE, value = {"{id}"}, consumes = "application/json", produces = "application/json") @RequestMapping(method = RequestMethod.DELETE, value = {"{id}"}, consumes = "application/json", produces = "application/json")
public @ResponseBody public @ResponseBody
ResponseEntity<ResponseItem<DatasetProfile>> inactivate(@PathVariable String id, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) { ResponseEntity<ResponseItem<DatasetProfile>> inactivate(@PathVariable String id, @ClaimedAuthorities(claims = {ADMIN, DATASET_PROFILE_MANAGER}) Principal principal) {
try { try {
eu.eudat.data.entities.DatasetProfile ret = AdminManager.inactivate(this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao(), this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(), id); eu.eudat.data.entities.DatasetProfile ret = AdminManager.inactivate(this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao(), this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(), id);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.models.data.admin.composite.DatasetProfile>().status(ApiMessageCode.SUCCESS_MESSAGE)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.models.data.admin.composite.DatasetProfile>().status(ApiMessageCode.SUCCESS_MESSAGE));
@ -132,11 +154,13 @@ public class Admin extends BaseController {
@Transactional @Transactional
@RequestMapping(method = RequestMethod.GET, value = {"/getXml/{id}"}, produces = "application/json") @RequestMapping(method = RequestMethod.GET, value = {"/getXml/{id}"}, produces = "application/json")
public ResponseEntity getDatasetProfileXml(@PathVariable String id, @RequestHeader("Content-Type") String contentType, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) throws IllegalAccessException, IOException, InstantiationException { public ResponseEntity getDatasetProfileXml(@PathVariable String id, @RequestHeader("Content-Type") String contentType, @ClaimedAuthorities(claims = {ADMIN, DATASET_PROFILE_MANAGER}) Principal principal) throws IllegalAccessException, IOException, InstantiationException {
if (contentType.equals("application/xml")) { if (contentType.equals("application/xml")) {
eu.eudat.data.entities.DatasetProfile profile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id)); eu.eudat.data.entities.DatasetProfile profile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id));
eu.eudat.models.data.user.composite.DatasetProfile datasetProfile = userManager.generateDatasetProfileModel(profile); eu.eudat.models.data.user.composite.DatasetProfile datasetProfile = userManager.generateDatasetProfileModel(profile);
datasetProfile.setStatus(profile.getStatus()); datasetProfile.setStatus(profile.getStatus());
datasetProfile.setDescription(profile.getDescription());
datasetProfile.setLanguage(profile.getLanguage());
return this.datasetProfileManager.getDocument(datasetProfile, profile.getLabel()); return this.datasetProfileManager.getDocument(datasetProfile, profile.getLabel());
} else { } else {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<eu.eudat.models.data.admin.composite.DatasetProfile>().status(ApiMessageCode.ERROR_MESSAGE).message("NOT AUTHORIZE")); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<eu.eudat.models.data.admin.composite.DatasetProfile>().status(ApiMessageCode.ERROR_MESSAGE).message("NOT AUTHORIZE"));
@ -145,17 +169,23 @@ public class Admin extends BaseController {
@RequestMapping(method = RequestMethod.POST, value = {"/upload"}) @RequestMapping(method = RequestMethod.POST, value = {"/upload"})
public ResponseEntity<Object> setDatasetProfileXml(@RequestParam("file") MultipartFile file, public ResponseEntity<Object> setDatasetProfileXml(@RequestParam("file") MultipartFile file,
@ClaimedAuthorities(claims = {ADMIN}) Principal principal) throws IllegalAccessException, IOException { @ClaimedAuthorities(claims = {ADMIN, DATASET_PROFILE_MANAGER}) Principal principal) throws IllegalAccessException, IOException {
eu.eudat.logic.utilities.documents.xml.datasetProfileXml.datasetProfileModel.DatasetProfile datasetProfileModel = this.datasetProfileManager.createDatasetProfileFromXml(file); eu.eudat.logic.utilities.documents.xml.datasetProfileXml.datasetProfileModel.DatasetProfile datasetProfileModel = this.datasetProfileManager.createDatasetProfileFromXml(file);
eu.eudat.models.data.admin.composite.DatasetProfile datasetProfileEntity = datasetProfileModel.toAdminCompositeModel(file.getOriginalFilename()); eu.eudat.models.data.admin.composite.DatasetProfile datasetProfileEntity = datasetProfileModel.toAdminCompositeModel(file.getOriginalFilename());
eu.eudat.data.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(datasetProfileEntity, getApiContext()); eu.eudat.data.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(datasetProfileEntity, getApiContext());
this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(modelDefinition); 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);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<eu.eudat.data.entities.DatasetProfile>>() return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<eu.eudat.data.entities.DatasetProfile>>()
.status(ApiMessageCode.SUCCESS_MESSAGE).message("")); .status(ApiMessageCode.SUCCESS_MESSAGE).message(""));
} }
@RequestMapping(method = RequestMethod.GET, value = {"/getRDACommonStandards"}, produces = "application/json") @RequestMapping(method = RequestMethod.GET, value = {"/getRDACommonStandards"}, produces = "application/json")
public ResponseEntity getRDACommonStandards(@ClaimedAuthorities(claims = {ADMIN}) Principal principal) { public ResponseEntity getRDACommonStandards(@ClaimedAuthorities(claims = {ADMIN, DATASET_PROFILE_MANAGER}) Principal principal) {
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<String>>().status(ApiMessageCode.SUCCESS_MESSAGE).payload(configLoader.getRdaProperties())); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<String>>().status(ApiMessageCode.SUCCESS_MESSAGE).payload(configLoader.getRdaProperties()));
} }
} }

View File

@ -161,9 +161,9 @@ public class DMPs extends BaseController {
@RequestMapping(method = RequestMethod.GET, value = {"/versions/{id}"}, consumes = "application/json", produces = "application/json") @RequestMapping(method = RequestMethod.GET, value = {"/versions/{id}"}, consumes = "application/json", produces = "application/json")
public @ResponseBody public @ResponseBody
ResponseEntity<ResponseItem<List<VersionListingModel>>> getVersions(@PathVariable(value= "id") String groupId, ResponseEntity<ResponseItem<List<VersionListingModel>>> getVersions(@PathVariable(value= "id") String groupId, @RequestParam(value= "public") Boolean isPublic,
@ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) throws Exception { @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) throws Exception {
List<VersionListingModel> versions = this.dataManagementPlanManager.getAllVersions(groupId, principal); List<VersionListingModel> versions = this.dataManagementPlanManager.getAllVersions(groupId, principal, isPublic);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<VersionListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(versions)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<VersionListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(versions));
} }

View File

@ -247,9 +247,9 @@ public class Datasets extends BaseController {
@javax.transaction.Transactional @javax.transaction.Transactional
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json") @RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
public @ResponseBody public @ResponseBody
ResponseEntity<ResponseItem<UUID>> createOrUpdate(@RequestBody DatasetWizardModel profile, Principal principal) throws Exception { ResponseEntity<ResponseItem<DatasetWizardModel>> createOrUpdate(@RequestBody DatasetWizardModel profile, Principal principal) throws Exception {
Dataset dataset = this.datasetManager.createOrUpdate(profile, principal); DatasetWizardModel dataset = new DatasetWizardModel().fromDataModel(this.datasetManager.createOrUpdate(profile, principal));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UUID>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created").payload(dataset.getId())); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetWizardModel>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created").payload(dataset));
} }
@Transactional @Transactional
@ -280,6 +280,18 @@ public class Datasets extends BaseController {
} }
} }
@RequestMapping(method = RequestMethod.GET, value = {"/{id}/validate"}, produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<Boolean>> validate(@PathVariable(value = "id") UUID id, Principal principal) throws Exception {
try {
Dataset dataset = datasetManager.getEntitySingle(id);
datasetManager.checkDatasetValidation(dataset);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Boolean>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Valid"));
} catch (Exception datasetWizardCannotUnlockException) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<Boolean>().status(ApiMessageCode.ERROR_MESSAGE).message(datasetWizardCannotUnlockException.getMessage()));
}
}
/* /*
* Data Import * Data Import
* */ * */

View File

@ -0,0 +1,63 @@
package eu.eudat.controllers;
import eu.eudat.exceptions.emailconfirmation.HasConfirmedEmailException;
import eu.eudat.exceptions.emailconfirmation.TokenExpiredException;
import eu.eudat.logic.managers.EmailConfirmationManager;
import eu.eudat.logic.managers.MergeEmailConfirmationManager;
import eu.eudat.logic.security.CustomAuthenticationProvider;
import eu.eudat.logic.services.operations.authentication.AuthenticationService;
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.models.data.security.Principal;
import eu.eudat.models.data.userinfo.UserMergeRequestModel;
import eu.eudat.types.ApiMessageCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.transaction.Transactional;
@RestController
@CrossOrigin
@RequestMapping(value = "api/emailMergeConfirmation")
public class EmailMergeConfirmation {
private MergeEmailConfirmationManager emailConfirmationManager;
@Autowired
public EmailMergeConfirmation(MergeEmailConfirmationManager emailConfirmationManager) {
this.emailConfirmationManager = emailConfirmationManager;
}
@Transactional
@RequestMapping(method = RequestMethod.GET, value = {"/{emailToken}"})
public @ResponseBody
ResponseEntity<ResponseItem> emailConfirmation(@PathVariable(value = "emailToken") String token) {
try {
this.emailConfirmationManager.confirmEmail(token);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE));
} catch
(HasConfirmedEmailException | TokenExpiredException ex) {
if (ex instanceof TokenExpiredException) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE));
} else {
return ResponseEntity.status(HttpStatus.FOUND).body(new ResponseItem().status(ApiMessageCode.WARN_MESSAGE));
}
}
}
@Transactional
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity sendConfirmatioEmail(@RequestBody UserMergeRequestModel requestModel, Principal principal) {
try {
this.emailConfirmationManager.sendConfirmationEmail(requestModel.getEmail(), principal, requestModel.getUserId(), requestModel.getProvider());
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE));
} catch (Exception ex) {
if (ex instanceof HasConfirmedEmailException) {
return ResponseEntity.status(HttpStatus.FOUND).body(new ResponseItem().status(ApiMessageCode.WARN_MESSAGE));
}
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE));
}
}
}

View File

@ -4,6 +4,7 @@ package eu.eudat.controllers;
import eu.eudat.exceptions.security.ExpiredTokenException; import eu.eudat.exceptions.security.ExpiredTokenException;
import eu.eudat.exceptions.security.NonValidTokenException; import eu.eudat.exceptions.security.NonValidTokenException;
import eu.eudat.exceptions.security.NullEmailException; import eu.eudat.exceptions.security.NullEmailException;
import eu.eudat.logic.managers.MetricsManager;
import eu.eudat.logic.managers.UserManager; import eu.eudat.logic.managers.UserManager;
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader; import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
import eu.eudat.logic.security.CustomAuthenticationProvider; import eu.eudat.logic.security.CustomAuthenticationProvider;
@ -94,6 +95,7 @@ public class Login {
public @ResponseBody public @ResponseBody
ResponseEntity<ResponseItem<PrincipalModel>> externallogin(@RequestBody LoginInfo credentials) throws GeneralSecurityException, NullEmailException { ResponseEntity<ResponseItem<PrincipalModel>> externallogin(@RequestBody LoginInfo credentials) throws GeneralSecurityException, NullEmailException {
logger.info("Trying To Login With " + credentials.getProvider()); logger.info("Trying To Login With " + credentials.getProvider());
MetricsManager.increaseValue("argos_users", 1, "loggedin");
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<PrincipalModel>().payload(customAuthenticationProvider.authenticate(credentials)).status(ApiMessageCode.SUCCESS_MESSAGE)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<PrincipalModel>().payload(customAuthenticationProvider.authenticate(credentials)).status(ApiMessageCode.SUCCESS_MESSAGE));
} }
@ -102,6 +104,7 @@ public class Login {
public @ResponseBody public @ResponseBody
ResponseEntity<ResponseItem<PrincipalModel>> nativelogin(@RequestBody Credentials credentials) throws NullEmailException { ResponseEntity<ResponseItem<PrincipalModel>> nativelogin(@RequestBody Credentials credentials) throws NullEmailException {
logger.info(credentials.getUsername() + " Trying To Login"); logger.info(credentials.getUsername() + " Trying To Login");
MetricsManager.increaseValue("argos_users", 1, "loggedin");
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<PrincipalModel>().payload(userManager.authenticate(this.nonVerifiedUserAuthenticationService, credentials)).status(ApiMessageCode.SUCCESS_MESSAGE)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<PrincipalModel>().payload(userManager.authenticate(this.nonVerifiedUserAuthenticationService, credentials)).status(ApiMessageCode.SUCCESS_MESSAGE));
} }
@ -162,6 +165,7 @@ public class Login {
ResponseEntity<ResponseItem<Principal>> logout(Principal principal) { ResponseEntity<ResponseItem<Principal>> logout(Principal principal) {
this.nonVerifiedUserAuthenticationService.Logout(principal.getToken()); this.nonVerifiedUserAuthenticationService.Logout(principal.getToken());
logger.info(principal + " Logged Out"); logger.info(principal + " Logged Out");
MetricsManager.decreaseValue("argos_users", 1, "loggedin");
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Principal>().status(ApiMessageCode.NO_MESSAGE)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Principal>().status(ApiMessageCode.NO_MESSAGE));
} }

View File

@ -42,6 +42,13 @@ public class Organisations extends BaseController {
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Organisation>>().payload(organisations).status(ApiMessageCode.NO_MESSAGE)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Organisation>>().payload(organisations).status(ApiMessageCode.NO_MESSAGE));
} }
@RequestMapping(method = RequestMethod.POST, value = {"/general/organisations"}, produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<List<Organisation>>> listGeneralOrganisations(@RequestBody OrganisationsTableRequest organisationsTableRequest, Principal principal) throws Exception {
List<Organisation> organisations = organisationsManager.getWithExternal(organisationsTableRequest, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Organisation>>().payload(organisations).status(ApiMessageCode.NO_MESSAGE));
}
@RequestMapping(method = RequestMethod.POST, value = {"/internal/organisations"}, produces = "application/json") @RequestMapping(method = RequestMethod.POST, value = {"/internal/organisations"}, produces = "application/json")
public @ResponseBody public @ResponseBody
ResponseEntity<ResponseItem<DataTableData<Organisation>>> getPaged(@Valid @RequestBody OrganisationsTableRequest organisationsTableRequest, Principal principal) throws Exception{ ResponseEntity<ResponseItem<DataTableData<Organisation>>> getPaged(@Valid @RequestBody OrganisationsTableRequest organisationsTableRequest, Principal principal) throws Exception{

View File

@ -1,6 +1,9 @@
package eu.eudat.controllers; package eu.eudat.controllers;
import eu.eudat.logic.managers.MetricsManager;
import eu.eudat.logic.security.claims.ClaimedAuthorities;
import eu.eudat.models.data.helpers.responses.ResponseItem; import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.models.data.security.Principal;
import eu.eudat.models.data.userguide.UserGuide; import eu.eudat.models.data.userguide.UserGuide;
import eu.eudat.types.ApiMessageCode; import eu.eudat.types.ApiMessageCode;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -19,6 +22,8 @@ import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import static eu.eudat.types.Authorities.ADMIN;
@RestController @RestController
@CrossOrigin @CrossOrigin
@RequestMapping(value = {"/api/userguide/"}) @RequestMapping(value = {"/api/userguide/"})
@ -31,13 +36,18 @@ public class UserGuideController {
this.environment = environment; this.environment = environment;
} }
@RequestMapping(path = "current", method = RequestMethod.GET ) @RequestMapping(path = "{lang}", method = RequestMethod.GET )
public ResponseEntity getUserGuide() throws IOException { public ResponseEntity getUserGuide(@PathVariable(name = "lang") String lang) throws IOException {
long files = Files.list(Paths.get(this.environment.getProperty("userguide.path"))).count();
MetricsManager.calculateValue("argos_languages", (int) files, null);
Stream<Path> walk = Files.walk(Paths.get(this.environment.getProperty("userguide.path"))); Stream<Path> walk = Files.walk(Paths.get(this.environment.getProperty("userguide.path")));
List<String> result = walk.filter(Files::isRegularFile) List<String> result = walk.filter(Files::isRegularFile)
.map(Path::toString).collect(Collectors.toList()); .map(Path::toString).collect(Collectors.toList());
String fileName = result.get(0); String fileName = result.stream().filter(guide -> guide.contains("_" + lang)).findFirst().orElse(null);
if (fileName == null) {
fileName = result.stream().filter(guide -> guide.contains("_en")).findFirst().get();
}
InputStream is = new FileInputStream(fileName); InputStream is = new FileInputStream(fileName);
String[] filepath = fileName.split("\\.")[0].split("\\\\"); String[] filepath = fileName.split("\\.")[0].split("\\\\");
@ -60,7 +70,7 @@ public class UserGuideController {
@RequestMapping(value = "current", method = RequestMethod.POST) @RequestMapping(value = "current", method = RequestMethod.POST)
public @ResponseBody public @ResponseBody
ResponseEntity<ResponseItem<String>> updateGuide(@RequestBody UserGuide guide) throws Exception { ResponseEntity<ResponseItem<String>> updateGuide(@RequestBody UserGuide guide, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) throws Exception {
String fileName = this.environment.getProperty("userguide.path") + guide.getName() + ".html"; String fileName = this.environment.getProperty("userguide.path") + guide.getName() + ".html";
OutputStream os = new FileOutputStream(fileName); OutputStream os = new FileOutputStream(fileName);
os.write(guide.getHtml().getBytes()); os.write(guide.getHtml().getBytes());

View File

@ -11,6 +11,7 @@ import eu.eudat.models.data.doi.DOIRequest;
import eu.eudat.models.data.helpers.common.DataTableData; import eu.eudat.models.data.helpers.common.DataTableData;
import eu.eudat.models.data.helpers.responses.ResponseItem; import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.models.data.security.Principal; import eu.eudat.models.data.security.Principal;
import eu.eudat.models.data.userinfo.UserCredential;
import eu.eudat.models.data.userinfo.UserListingModel; import eu.eudat.models.data.userinfo.UserListingModel;
import eu.eudat.models.data.userinfo.UserProfile; import eu.eudat.models.data.userinfo.UserProfile;
import eu.eudat.types.ApiMessageCode; import eu.eudat.types.ApiMessageCode;
@ -22,6 +23,7 @@ import org.springframework.web.bind.annotation.*;
import javax.validation.Valid; import javax.validation.Valid;
import java.io.IOException; import java.io.IOException;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
@ -62,6 +64,14 @@ public class Users extends BaseController {
UserProfile user = userManager.getSingle(userId); UserProfile user = userManager.getSingle(userId);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UserProfile>().payload(user).status(ApiMessageCode.NO_MESSAGE)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UserProfile>().payload(user).status(ApiMessageCode.NO_MESSAGE));
} }
@RequestMapping(method = RequestMethod.GET, value = {"/{id}/emails"}, produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<List<UserCredential>>> getEmails(@PathVariable String id, Principal principal) throws Exception {
UUID userId = id.equals("me") ? principal.getId() : UUID.fromString(id);
List<UserCredential> user = userManager.getCredentials(userId);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<UserCredential>>().payload(user).status(ApiMessageCode.NO_MESSAGE));
}
@Transactional @Transactional
@RequestMapping(method = RequestMethod.POST, value = {"/settings"}, produces = "application/json") @RequestMapping(method = RequestMethod.POST, value = {"/settings"}, produces = "application/json")
@ -103,6 +113,20 @@ public class Users extends BaseController {
userManager.deleteDOIToken(principal); userManager.deleteDOIToken(principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UserProfile>().status(ApiMessageCode.NO_MESSAGE)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UserProfile>().status(ApiMessageCode.NO_MESSAGE));
} }
@RequestMapping(method = RequestMethod.GET, value = {"/getCsv"})
public @ResponseBody
ResponseEntity exportCsv(@ClaimedAuthorities(claims = {ADMIN}) Principal principal) throws Exception {
return userManager.exportToCsv(principal);
}
@RequestMapping(method = RequestMethod.POST, value = {"/find"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<UserProfile>> find(@Valid @RequestBody String email) throws Exception {
UserProfile userProfile = userManager.getFromEmail(email);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UserProfile>().payload(userProfile).status(ApiMessageCode.NO_MESSAGE));
}
} }

View File

@ -0,0 +1,44 @@
package eu.eudat.controllers;
import eu.eudat.data.entities.Service;
import eu.eudat.logic.managers.ServiceManager;
import eu.eudat.logic.managers.ValidationManager;
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.models.data.security.Principal;
import eu.eudat.models.data.services.ServiceModel;
import eu.eudat.types.ApiMessageCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@CrossOrigin
@RequestMapping(value = {"/api"})
public class Validation extends BaseController {
private ValidationManager validationManager;
@Autowired
public Validation(ApiContext apiContext, ValidationManager validationManager) {
super(apiContext);
this.validationManager = validationManager;
}
@RequestMapping(method = RequestMethod.GET, value = {"/external/validation"}, produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<Boolean>> validate(
@RequestParam(value = "query", required = false) String query, @RequestParam(value = "type", required = false) String type, Principal principal
) throws HugeResultSet, NoURLFound {
Boolean isValid = this.validationManager.validateIdentifier(query, type, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Boolean>().payload(isValid).status(ApiMessageCode.NO_MESSAGE));
}
}

View File

@ -30,6 +30,8 @@ public class CredentialBuilder extends Builder<Credential> {
private String externalId; private String externalId;
private String email;
public CredentialBuilder id(UUID id) { public CredentialBuilder id(UUID id) {
this.id = id; this.id = id;
return this; return this;
@ -75,6 +77,11 @@ public class CredentialBuilder extends Builder<Credential> {
return this; return this;
} }
public CredentialBuilder email(String email) {
this.email = email;
return this;
}
public Credential build() { public Credential build() {
Credential credential = new Credential(); Credential credential = new Credential();
credential.setStatus(status); credential.setStatus(status);
@ -86,6 +93,7 @@ public class CredentialBuilder extends Builder<Credential> {
credential.setUserInfo(userInfo); credential.setUserInfo(userInfo);
credential.setId(id); credential.setId(id);
credential.setExternalId(externalId); credential.setExternalId(externalId);
credential.setEmail(email);
return credential; return credential;
} }
} }

View File

@ -40,6 +40,8 @@ public class UserInfoBuilder extends Builder<UserInfo> {
private Set<UserRole> userRoles = new HashSet<>(); private Set<UserRole> userRoles = new HashSet<>();
private Short userStatus;
public UserInfoBuilder id(UUID id) { public UserInfoBuilder id(UUID id) {
this.id = id; this.id = id;
return this; return this;
@ -100,6 +102,11 @@ public class UserInfoBuilder extends Builder<UserInfo> {
return this; return this;
} }
public UserInfoBuilder userStatus(Short userStatus) {
this.userStatus = userStatus;
return this;
}
@Override @Override
public UserInfo build() { public UserInfo build() {
UserInfo userInfo = new UserInfo(); UserInfo userInfo = new UserInfo();
@ -115,6 +122,7 @@ public class UserInfoBuilder extends Builder<UserInfo> {
userInfo.setCredentials(credentials); userInfo.setCredentials(credentials);
userInfo.setDmps(dmps); userInfo.setDmps(dmps);
userInfo.setVerified_email(verified_email); userInfo.setVerified_email(verified_email);
userInfo.setUserStatus(userStatus);
return userInfo; return userInfo;
} }
} }

View File

@ -135,6 +135,8 @@ public class DashBoardManager {
dataManagementPlanCriteria.setAllVersions(false); dataManagementPlanCriteria.setAllVersions(false);
GrantCriteria grantCriteria = new GrantCriteria(); GrantCriteria grantCriteria = new GrantCriteria();
grantCriteria.setActive(true);
List<Integer> roles = new LinkedList<>(); List<Integer> roles = new LinkedList<>();
List<Dmp> finalDmps = dmps; List<Dmp> finalDmps = dmps;
CompletableFuture dmpFuture = dataManagementPlanRepository.getAuthenticated((dmps != null && !dmps.isEmpty()) ? dataManagementPlanRepository.asQueryable().where((builder, root) -> root.get("id").in(finalDmps.stream().map(Dmp::getId).collect(Collectors.toList()))) : dataManagementPlanRepository.getWithCriteria(dataManagementPlanCriteria), principal.getId(), roles).distinct().countAsync() CompletableFuture dmpFuture = dataManagementPlanRepository.getAuthenticated((dmps != null && !dmps.isEmpty()) ? dataManagementPlanRepository.asQueryable().where((builder, root) -> root.get("id").in(finalDmps.stream().map(Dmp::getId).collect(Collectors.toList()))) : dataManagementPlanRepository.getWithCriteria(dataManagementPlanCriteria), principal.getId(), roles).distinct().countAsync()

View File

@ -321,8 +321,8 @@ public class DataManagementPlanManager {
return data; return data;
} }
public List<VersionListingModel> getAllVersions(String groupId, Principal principal) { public List<VersionListingModel> getAllVersions(String groupId, Principal principal, Boolean isPublic) {
UUID principalId = principal.getId(); UUID principalId = principal != null ? principal.getId() : null;
List<VersionListingModel> versions = new ArrayList<>(); List<VersionListingModel> versions = new ArrayList<>();
QueryableList<DMP> items = null; QueryableList<DMP> items = null;
QueryableList<DMP> authItems = null; QueryableList<DMP> authItems = null;
@ -330,10 +330,10 @@ public class DataManagementPlanManager {
DataManagementPlanCriteria criteria = new DataManagementPlanCriteria(); DataManagementPlanCriteria criteria = new DataManagementPlanCriteria();
criteria.setGroupIds(Collections.singletonList(UUID.fromString(groupId))); criteria.setGroupIds(Collections.singletonList(UUID.fromString(groupId)));
criteria.setAllVersions(true); criteria.setAllVersions(true);
criteria.setIsPublic(principalId == null); criteria.setIsPublic(isPublic);
criteria.setOnlyPublic(principalId == null); criteria.setOnlyPublic(isPublic);
items = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(criteria); items = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(criteria);
if (principalId != null) { if (!isPublic) {
authItems = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getAuthenticated(items, principalId, roles); authItems = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getAuthenticated(items, principalId, roles);
} else { } else {
authItems = items; authItems = items;
@ -366,7 +366,7 @@ public class DataManagementPlanManager {
if (dbTime.toEpochMilli() != modelTime.toEpochMilli()) { if (dbTime.toEpochMilli() != modelTime.toEpochMilli()) {
throw new Exception("Another user have already edit that DMP."); throw new Exception("Another user have already edit that DMP.");
} }
List<Dataset> datasetList = new ArrayList<>(dmp1.getDataset()); List<Dataset> datasetList = dmp1.getDataset().stream().filter(dataset -> dataset.getStatus() != 99).collect(Collectors.toList());
for (Dataset dataset : datasetList) { for (Dataset dataset : datasetList) {
if (dataManagementPlan.getProfiles().stream().filter(associatedProfile -> dataset.getProfile().getId().equals(associatedProfile.getId())).findAny().orElse(null) == null) if (dataManagementPlan.getProfiles().stream().filter(associatedProfile -> dataset.getProfile().getId().equals(associatedProfile.getId())).findAny().orElse(null) == null)
throw new Exception("Dataset Template for Dataset Description is missing from the DMP."); throw new Exception("Dataset Template for Dataset Description is missing from the DMP.");
@ -375,6 +375,8 @@ public class DataManagementPlanManager {
throw new Exception("DMP is finalized, therefore cannot be edited."); throw new Exception("DMP is finalized, therefore cannot be edited.");
setNotification = true; setNotification = true;
} else {
MetricsManager.increaseValue("argos_managed_dmps", 1, "draft");
} }
DMP newDmp = dataManagementPlan.toDataModel(); DMP newDmp = dataManagementPlan.toDataModel();
@ -497,6 +499,8 @@ public class DataManagementPlanManager {
} }
if (dataManagementPlan.getStatus() == (int) DMP.DMPStatus.FINALISED.getValue() && dmp1.getStatus().equals(DMP.DMPStatus.FINALISED.getValue())) if (dataManagementPlan.getStatus() == (int) DMP.DMPStatus.FINALISED.getValue() && dmp1.getStatus().equals(DMP.DMPStatus.FINALISED.getValue()))
throw new Exception("DMP is finalized, therefore cannot be edited."); throw new Exception("DMP is finalized, therefore cannot be edited.");
} else {
MetricsManager.increaseValue("argos_managed_dmps", 1, "draft");
} }
List<Dataset> datasets = new ArrayList<>(); List<Dataset> datasets = new ArrayList<>();
DMP tempDMP = dataManagementPlan.toDataModel(); DMP tempDMP = dataManagementPlan.toDataModel();
@ -612,6 +616,7 @@ public class DataManagementPlanManager {
newDmp.setDataset(new HashSet<>(databaseRepository.getDatasetDao().getWithCriteria(criteria1).toList())); newDmp.setDataset(new HashSet<>(databaseRepository.getDatasetDao().getWithCriteria(criteria1).toList()));
this.updateIndex(newDmp); this.updateIndex(newDmp);
MetricsManager.increaseValue("argos_managed_dmps", 1, "draft");
return newDmp.getId(); return newDmp.getId();
} }
@ -623,6 +628,20 @@ public class DataManagementPlanManager {
if (apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(criteria).toList().size() > 0) if (apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(criteria).toList().size() > 0)
throw new DMPWithDatasetsDeleteException("You cannot Remove Datamanagement Plan with Datasets"); throw new DMPWithDatasetsDeleteException("You cannot Remove Datamanagement Plan with Datasets");
DMP oldDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(uuid); DMP oldDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(uuid);
switch (oldDmp.getStatus()) {
case 0:
MetricsManager.decreaseValue("argos_managed_dmps", 1, "draft");
break;
case 1:
if (oldDmp.getDoi() != null) {
MetricsManager.decreaseValue("argos_managed_dmps", 1, "doied");
}
if (oldDmp.isPublic()) {
MetricsManager.decreaseValue("argos_managed_dmps", 1, "published");
}
MetricsManager.decreaseValue("argos_managed_dmps", 1, "finalized");
break;
}
oldDmp.setStatus(DMP.DMPStatus.DELETED.getValue()); oldDmp.setStatus(DMP.DMPStatus.DELETED.getValue());
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(oldDmp); apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(oldDmp);
this.updateIndex(oldDmp); this.updateIndex(oldDmp);
@ -660,6 +679,7 @@ public class DataManagementPlanManager {
else { else {
researcher.setCreationUser(user); researcher.setCreationUser(user);
researcherRepository.createOrUpdate(researcher); researcherRepository.createOrUpdate(researcher);
MetricsManager.increaseValue("argos_researchers", 1, null);
} }
} }
} }
@ -680,7 +700,9 @@ public class DataManagementPlanManager {
} }
if (createNew) { if (createNew) {
organisation.setReference("Internal:" + UUID.randomUUID().toString()); if (organisation.getReference() == null) {
organisation.setReference("Internal:" + UUID.randomUUID().toString());
}
organisationRepository.createOrUpdate(organisation); organisationRepository.createOrUpdate(organisation);
} }
} }
@ -739,12 +761,14 @@ public class DataManagementPlanManager {
project.setType(Project.ProjectType.EXTERNAL.getValue()); project.setType(Project.ProjectType.EXTERNAL.getValue());
if (project.getId() == null) project.setId(UUID.randomUUID()); if (project.getId() == null) project.setId(UUID.randomUUID());
projectDao.createOrUpdate(project); projectDao.createOrUpdate(project);
MetricsManager.increaseValue("argos_projects", 1, null);
} }
} }
else { else {
project.setType(Project.ProjectType.EXTERNAL.getValue()); project.setType(Project.ProjectType.EXTERNAL.getValue());
if (project.getId() == null) project.setId(UUID.randomUUID()); if (project.getId() == null) project.setId(UUID.randomUUID());
projectDao.createOrUpdate(project); projectDao.createOrUpdate(project);
MetricsManager.increaseValue("argos_projects", 1, null);
} }
} }
} }
@ -821,6 +845,7 @@ public class DataManagementPlanManager {
return newDataset; return newDataset;
}).thenApplyAsync(item -> { }).thenApplyAsync(item -> {
futures.add(datasetDao.createOrUpdateAsync(item).whenComplete(((dataset1, throwable) -> { futures.add(datasetDao.createOrUpdateAsync(item).whenComplete(((dataset1, throwable) -> {
MetricsManager.increaseValue("argos_managed_dataset_descriptions", 1, "draft");
eu.eudat.elastic.entities.Dataset datasetElastic = new eu.eudat.elastic.entities.Dataset(); eu.eudat.elastic.entities.Dataset datasetElastic = new eu.eudat.elastic.entities.Dataset();
datasetElastic.setId(dataset1.getId().toString()); datasetElastic.setId(dataset1.getId().toString());
datasetElastic.setLabel(dataset1.getLabel()); datasetElastic.setLabel(dataset1.getLabel());
@ -878,6 +903,7 @@ public class DataManagementPlanManager {
dmp.setPublic(true); dmp.setPublic(true);
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(dmp); apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(dmp);
this.updateIndex(dmp); this.updateIndex(dmp);
MetricsManager.increaseValue("argos_managed_dmps", 1, "published");
DataManagementPlanCriteria criteria = new DataManagementPlanCriteria(); DataManagementPlanCriteria criteria = new DataManagementPlanCriteria();
criteria.setGroupIds(Collections.singletonList(dmp.getGroupId())); criteria.setGroupIds(Collections.singletonList(dmp.getGroupId()));
criteria.setAllVersions(true); criteria.setAllVersions(true);
@ -890,6 +916,7 @@ public class DataManagementPlanManager {
tags = elastic.getTags(); tags = elastic.getTags();
} }
this.datasetManager.updateTags(dataset, tags); this.datasetManager.updateTags(dataset, tags);
MetricsManager.increaseValue("argos_managed_dataset_descriptions", 1, "published");
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
} }
@ -908,23 +935,37 @@ public class DataManagementPlanManager {
throw new Exception("User does not have the privilege to do this action."); throw new Exception("User does not have the privilege to do this action.");
if (dmp.getStatus().equals(DMP.DMPStatus.FINALISED.getValue())) if (dmp.getStatus().equals(DMP.DMPStatus.FINALISED.getValue()))
throw new Exception("DMP is already finalized"); throw new Exception("DMP is already finalized");
dmp.setStatus(DMP.DMPStatus.FINALISED.getValue());
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(dmp);
this.updateIndex(dmp);
List<Dataset> indexDatasets = new ArrayList<>(); List<Dataset> indexDatasets = new ArrayList<>();
if (datasetsToBeFinalized != null && datasetsToBeFinalized.getUuids() != null && !datasetsToBeFinalized.getUuids().isEmpty()) { if (datasetsToBeFinalized != null && datasetsToBeFinalized.getUuids() != null && !datasetsToBeFinalized.getUuids().isEmpty()) {
apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao() List<Dataset> finalizedDatasets = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao()
.asQueryable().where((builder, root) -> root.get("id").in(datasetsToBeFinalized.getUuids())) .asQueryable().where((builder, root) -> root.get("id").in(datasetsToBeFinalized.getUuids()))
.update(root -> root.<Integer>get("status"), Dataset.Status.FINALISED.getValue()); .toList();
apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao() for (Dataset dataset: finalizedDatasets) {
Dataset.Status status = Dataset.Status.fromInteger(dataset.getStatus());
Date finalizedDate = dataset.getFinalizedAt();
dataset.setStatus(Dataset.Status.FINALISED.getValue());
dataset.setFinalizedAt(new Date());
DatasetWizardModel wizardModel = new DatasetWizardModel();
wizardModel = wizardModel.fromDataModel(dataset);
wizardModel.setDatasetProfileDefinition(this.datasetManager.getPagedProfile(wizardModel, dataset));
try {
datasetManager.createOrUpdate(wizardModel, principal);
} catch (Exception e) {
dataset.setStatus(status.getValue());
dataset.setFinalizedAt(finalizedDate);
throw e;
}
dataset.setModified(new Date());
}
/*apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao()
.asQueryable().where((builder, root) -> root.get("id").in(datasetsToBeFinalized.getUuids())) .asQueryable().where((builder, root) -> root.get("id").in(datasetsToBeFinalized.getUuids()))
.update(root -> root.<Date>get("finalizedAt"), new Date()); .update(root -> root.<Date>get("finalizedAt"), new Date());*/
List<Dataset> finalizedDatasets = dmp.getDataset().stream().filter(dataset -> datasetsToBeFinalized.getUuids().contains(dataset.getId())).collect(Collectors.toList()); //List<Dataset> finalizedDatasets = dmp.getDataset().stream().filter(dataset -> datasetsToBeFinalized.getUuids().contains(dataset.getId())).collect(Collectors.toList());
finalizedDatasets.forEach(dataset ->{ /* finalizedDatasets.forEach(dataset ->{
dataset.setStatus(Dataset.Status.FINALISED.getValue()); dataset.setStatus(Dataset.Status.FINALISED.getValue());
dataset.setFinalizedAt(new Date()); dataset.setFinalizedAt(new Date());
dataset.setModified(new Date()); dataset.setModified(new Date());
} ); } );*/
indexDatasets.addAll(finalizedDatasets); indexDatasets.addAll(finalizedDatasets);
List<UUID> datasetsToBeCanceled = new LinkedList<>(); List<UUID> datasetsToBeCanceled = new LinkedList<>();
for (Dataset dataset : dmp.getDataset()) { for (Dataset dataset : dmp.getDataset()) {
@ -955,11 +996,17 @@ public class DataManagementPlanManager {
cancelledDatasets.forEach(dataset -> dataset.setStatus(Dataset.Status.CANCELED.getValue())); cancelledDatasets.forEach(dataset -> dataset.setStatus(Dataset.Status.CANCELED.getValue()));
indexDatasets.addAll(cancelledDatasets); indexDatasets.addAll(cancelledDatasets);
} }
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
sendNotification(dmp, user, NotificationType.DMP_FINALISED);
} }
dmp.setStatus(DMP.DMPStatus.FINALISED.getValue());
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(dmp);
this.updateIndex(dmp);
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
sendNotification(dmp, user, NotificationType.DMP_FINALISED);
MetricsManager.decreaseValue("argos_managed_dmps", 1, "draft");
MetricsManager.increaseValue("argos_managed_dmps", 1, "finalized");
this.updateDatasetsIndex(indexDatasets); this.updateDatasetsIndex(indexDatasets);
MetricsManager.decreaseValue("argos_managed_dataset_descriptions", indexDatasets.size(), "draft");
MetricsManager.increaseValue("argos_managed_dataset_descriptions", indexDatasets.size(), "finalized");
} }
public void undoFinalize(UUID id, Principal principal) throws Exception { public void undoFinalize(UUID id, Principal principal) throws Exception {
@ -971,6 +1018,8 @@ public class DataManagementPlanManager {
dmp.setStatus(DMP.DMPStatus.ACTIVE.getValue()); dmp.setStatus(DMP.DMPStatus.ACTIVE.getValue());
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(dmp); apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(dmp);
this.updateIndex(dmp); this.updateIndex(dmp);
MetricsManager.decreaseValue("argos_managed_dmps", 1, "finalized");
MetricsManager.increaseValue("argos_managed_dmps", 1, "draft");
} }
public void updateUsers(UUID id, List<UserInfoListingModel> users, Principal principal) throws Exception { public void updateUsers(UUID id, List<UserInfoListingModel> users, Principal principal) throws Exception {
@ -1076,7 +1125,7 @@ public class DataManagementPlanManager {
runDatasetTemplate.setBold(true); runDatasetTemplate.setBold(true);
runDatasetTemplate.setFontSize(12); runDatasetTemplate.setFontSize(12);
XWPFParagraph externalReferencesParagraph = document.createParagraph(); /*XWPFParagraph externalReferencesParagraph = document.createParagraph();
externalReferencesParagraph.setStyle("Heading3"); externalReferencesParagraph.setStyle("Heading3");
XWPFRun externalReferencesRun = externalReferencesParagraph.createRun(); XWPFRun externalReferencesRun = externalReferencesParagraph.createRun();
externalReferencesRun.setText("External References"); externalReferencesRun.setText("External References");
@ -1104,7 +1153,7 @@ public class DataManagementPlanManager {
wordBuilder.addParagraphContent(datasetEntity.getServices().stream().map(DatasetService::getService).map(Service::getLabel).collect(Collectors.joining(", ")) wordBuilder.addParagraphContent(datasetEntity.getServices().stream().map(DatasetService::getService).map(Service::getLabel).collect(Collectors.joining(", "))
, document, ParagraphStyle.TEXT, BigInteger.ZERO); , document, ParagraphStyle.TEXT, BigInteger.ZERO);
} }
/*wordBuilder.addParagraphContent("Tags", document, ParagraphStyle.HEADER3, BigInteger.ZERO); *//*wordBuilder.addParagraphContent("Tags", document, ParagraphStyle.HEADER3, BigInteger.ZERO);
if (datasetEntity.().size() > 0) { if (datasetEntity.().size() > 0) {
wordBuilder.addParagraphContent(datasetEntity.getServices().stream().map(DatasetService::getService).map(Service::getLabel).collect(Collectors.joining(", ")) wordBuilder.addParagraphContent(datasetEntity.getServices().stream().map(DatasetService::getService).map(Service::getLabel).collect(Collectors.joining(", "))
, document, ParagraphStyle.HEADER4, BigInteger.ZERO); , document, ParagraphStyle.HEADER4, BigInteger.ZERO);
@ -1787,6 +1836,7 @@ public class DataManagementPlanManager {
dataBuilder.append(" \"publication_type\": \"datamanagementplan\",\n"); dataBuilder.append(" \"publication_type\": \"datamanagementplan\",\n");
dataBuilder.append(" \"description\": \"").append((dmp.getDescription() != null && !dmp.getDescription().isEmpty() ? dmp.getDescription() : "<p></p>")).append("\",\n"); dataBuilder.append(" \"description\": \"").append((dmp.getDescription() != null && !dmp.getDescription().isEmpty() ? dmp.getDescription() : "<p></p>")).append("\",\n");
dataBuilder.append(" \"version\": \"").append(dmp.getVersion()).append("\",\n"); dataBuilder.append(" \"version\": \"").append(dmp.getVersion()).append("\",\n");
dataBuilder.append(" \"communities\": [{\n \t\t\"identifier\": \"").append(environment.getProperty("zenodo.community")).append("\"\n \t\t}],\n");
dataBuilder.append(" \"access_right\": \""); dataBuilder.append(" \"access_right\": \"");
if (extraProperties.get("visible") == null) { if (extraProperties.get("visible") == null) {
dataBuilder.append("restricted\",\n"); dataBuilder.append("restricted\",\n");
@ -1823,7 +1873,20 @@ public class DataManagementPlanManager {
dataBuilder.append("{\n"); dataBuilder.append("{\n");
dataBuilder.append(" \t\t\"name\": \"").append(userDMP.getUser().getName()).append("\",\n"); dataBuilder.append(" \t\t\"name\": \"").append(userDMP.getUser().getName()).append("\",\n");
dataBuilder.append(" \t\t\"type\": \"").append("ProjectMember").append("\",\n"); dataBuilder.append(" \t\t\"type\": \"").append("ProjectMember").append("\",\n");
dataBuilder.append(" \t\t\"affiliation\": \"OpenDMP\"\n}"); if (dmp.getOrganisations() != null && !dmp.getOrganisations().isEmpty()) {
dataBuilder.append(" \t\t\"affiliation\": \"");
int j = 0;
for (Organisation organization: dmp.getOrganisations()) {
if (j > 0) {
dataBuilder.append(", ");
}
dataBuilder.append(organization.getLabel());
j++;
}
dataBuilder.append("\"\n}");
} else {
dataBuilder.append(" \t\t\"affiliation\": \"" + this.environment.getProperty("zenodo.affiliation") +"\"\n}");
}
i++; i++;
} }
for(Researcher researcher: dmp.getResearchers()) { for(Researcher researcher: dmp.getResearchers()) {
@ -1853,7 +1916,20 @@ public class DataManagementPlanManager {
} }
dataBuilder.append(" \"creators\": [{\n"); dataBuilder.append(" \"creators\": [{\n");
dataBuilder.append(" \t\t\"name\": \"").append(dmp.getUsers().stream().filter(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser().getName()).append("\",\n"); dataBuilder.append(" \t\t\"name\": \"").append(dmp.getUsers().stream().filter(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser().getName()).append("\",\n");
dataBuilder.append(" \t\t\"affiliation\": \"OpenDMP\"}]\n"); if (dmp.getOrganisations() != null && !dmp.getOrganisations().isEmpty()) {
dataBuilder.append(" \t\t\"affiliation\": \"");
int j = 0;
for (Organisation organization: dmp.getOrganisations()) {
if (j > 0) {
dataBuilder.append(", ");
}
dataBuilder.append(organization.getLabel());
j++;
}
dataBuilder.append("\"}]\n");
} else {
dataBuilder.append(" \t\t\"affiliation\": \"" + this.environment.getProperty("zenodo.affiliation") +"\"}]\n");
}
dataBuilder.append(" }\n").append("}"); dataBuilder.append(" }\n").append("}");
createData = dataBuilder.toString(); createData = dataBuilder.toString();
JsonNode createDataJSON = new ObjectMapper().readTree(createData); JsonNode createDataJSON = new ObjectMapper().readTree(createData);
@ -1919,16 +1995,31 @@ public class DataManagementPlanManager {
if (unpublishedUrl == null) { if (unpublishedUrl == null) {
// Second step, add the file to the entry. // Second step, add the file to the entry.
FileEnvelope file = getWordDocument(id.toString(), principal, configLoader); FileEnvelope file = getWordDocument(id.toString(), principal, configLoader);
String name = file.getFilename().substring(0, file.getFilename().length() - 5); /*String name = file.getFilename().substring(0, file.getFilename().length() - 5);
File pdfFile = datasetManager.convertToPDF(file, environment); File pdfFile = datasetManager.convertToPDF(file, environment);
String fileName = name + ".pdf"; String fileName = name + ".pdf";*/
FileSystemResource fileSystemResource = new FileSystemResource(pdfFile); FileSystemResource fileSystemResource = new FileSystemResource(file.getFile());
HttpEntity<FileSystemResource> addFileMapRequest = new HttpEntity<>(fileSystemResource, null); HttpEntity<FileSystemResource> addFileMapRequest = new HttpEntity<>(fileSystemResource, null);
String addFileUrl = links.get("bucket") + "/" + fileName + "?access_token=" + zenodoToken; String addFileUrl = links.get("bucket") + "/" + file.getFilename() + "?access_token=" + zenodoToken;
restTemplate.put(addFileUrl, addFileMapRequest); restTemplate.put(addFileUrl, addFileMapRequest);
Files.deleteIfExists(file.getFile().toPath()); Files.deleteIfExists(file.getFile().toPath());
ResponseEntity<byte[]> jsonFile = getRDAJsonDocument(id.toString(), datasetManager, principal);
UUID jsonFileUUID = UUID.randomUUID();
File tempJsonFile = new File(this.environment.getProperty("temp.temp") + jsonFileUUID.toString() + ".json");
try (FileOutputStream jsonFos = new FileOutputStream(tempJsonFile)) {
jsonFos.write(jsonFile.getBody());
jsonFos.flush();
}
fileSystemResource = new FileSystemResource(tempJsonFile);
addFileMapRequest = new HttpEntity<>(fileSystemResource, null);
String jsonFileName = jsonFile.getHeaders().get("Content-Disposition").get(0).substring(jsonFile.getHeaders().get("Content-Disposition").get(0).lastIndexOf('=') + 1);
addFileUrl = links.get("bucket") + "/" + jsonFileName + "?access_token=" + zenodoToken;
restTemplate.put(addFileUrl, addFileMapRequest);
Files.deleteIfExists(tempJsonFile.toPath());
// Third post call to Zenodo to publish the entry and return the DOI. // Third post call to Zenodo to publish the entry and return the DOI.
publishUrl = links.get("publish") + "?access_token=" + zenodoToken; publishUrl = links.get("publish") + "?access_token=" + zenodoToken;
} else { } else {
@ -1986,6 +2077,51 @@ public class DataManagementPlanManager {
} }
public long countAllDrafts() {
DataManagementPlanCriteria criteria = new DataManagementPlanCriteria();
criteria.setStatus(0);
return apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(criteria).count();
}
public long countAllFinalized() {
DataManagementPlanCriteria criteria = new DataManagementPlanCriteria();
criteria.setStatus(1);
return apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(criteria).count();
}
public long countAllPublished() {
DataManagementPlanCriteria criteria = new DataManagementPlanCriteria();
criteria.setIsPublic(true);
criteria.setOnlyPublic(true);
return apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(criteria).count();
}
public long countAllDoied() {
DataManagementPlanCriteria criteria = new DataManagementPlanCriteria();
criteria.setHasDoi(true);
return apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(criteria).count();
}
public long countAllResearchers() {
ResearcherCriteria criteria = new ResearcherCriteria();
return apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao().getWithCriteria(criteria).count();
}
public long countAllProjects() {
ProjectCriteria criteria = new ProjectCriteria();
return apiContext.getOperationsContext().getDatabaseRepository().getProjectDao().getWithCritetia(criteria).count();
}
public long countAllFunders() {
FunderCriteria criteria = new FunderCriteria();
return apiContext.getOperationsContext().getDatabaseRepository().getFunderDao().getWithCritetia(criteria).count();
}
public long countAllGrants() {
GrantCriteria criteria = new GrantCriteria();
return apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().getWithCriteria(criteria).count();
}
/*public DataTableData<DataManagementPlanListingModel> getPublicPaged(DataManagmentPlanPublicTableRequest dataManagementPlanPublicTableRequest, String fieldsGroup, Principal principal) throws Exception { /*public DataTableData<DataManagementPlanListingModel> getPublicPaged(DataManagmentPlanPublicTableRequest dataManagementPlanPublicTableRequest, String fieldsGroup, Principal principal) throws Exception {
dataManagementPlanPublicTableRequest.setQuery(databaseRepository.getDmpDao().asQueryable().withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class))); dataManagementPlanPublicTableRequest.setQuery(databaseRepository.getDmpDao().asQueryable().withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class)));
QueryableList<DMP> items = dataManagementPlanPublicTableRequest.applyCriteria(); QueryableList<DMP> items = dataManagementPlanPublicTableRequest.applyCriteria();

View File

@ -135,8 +135,8 @@ public class DataManagementProfileManager {
return null; return null;
} }
private static File convert(MultipartFile file) throws IOException { private File convert(MultipartFile file) throws IOException {
File convFile = new File(file.getOriginalFilename()); File convFile = new File(this.environment.getProperty("temp.temp") + file.getOriginalFilename());
convFile.createNewFile(); convFile.createNewFile();
FileOutputStream fos = new FileOutputStream(convFile); FileOutputStream fos = new FileOutputStream(convFile);
fos.write(file.getBytes()); fos.write(file.getBytes());

View File

@ -38,7 +38,7 @@ public class DataRepositoryManager {
public List<DataRepositoryModel> getDataRepositories(String query, String type, Principal principal) throws HugeResultSet, NoURLFound { public List<DataRepositoryModel> getDataRepositories(String query, String type, Principal principal) throws HugeResultSet, NoURLFound {
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query); ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query);
List<Map<String, Object>> remoteRepos = this.apiContext.getOperationsContext().getRemoteFetcher().getRepositories(externalUrlCriteria, type); List<Map<String, String>> remoteRepos = this.apiContext.getOperationsContext().getRemoteFetcher().getRepositories(externalUrlCriteria, type);
DataRepositoryCriteria criteria = new DataRepositoryCriteria(); DataRepositoryCriteria criteria = new DataRepositoryCriteria();
if (!query.isEmpty()) criteria.setLike(query); if (!query.isEmpty()) criteria.setLike(query);

View File

@ -83,6 +83,8 @@ import javax.xml.xpath.XPathFactory;
import java.io.*; import java.io.*;
import java.math.BigInteger; import java.math.BigInteger;
import java.nio.file.Files; import java.nio.file.Files;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.*; import java.util.*;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -349,6 +351,10 @@ public class DatasetManager {
return dataset; return dataset;
} }
public Dataset getEntitySingle(UUID id) {
return databaseRepository.getDatasetDao().find(id);
}
public PagedDatasetProfile getPagedProfile(DatasetWizardModel dataset, eu.eudat.data.entities.Dataset datasetEntity) { public PagedDatasetProfile getPagedProfile(DatasetWizardModel dataset, eu.eudat.data.entities.Dataset datasetEntity) {
eu.eudat.models.data.user.composite.DatasetProfile datasetprofile = userManager.generateDatasetProfileModel(datasetEntity.getProfile()); eu.eudat.models.data.user.composite.DatasetProfile datasetprofile = userManager.generateDatasetProfileModel(datasetEntity.getProfile());
datasetprofile.setStatus(dataset.getStatus()); datasetprofile.setStatus(dataset.getStatus());
@ -384,7 +390,7 @@ public class DatasetManager {
runDatasetTemplate.setBold(true); runDatasetTemplate.setBold(true);
runDatasetTemplate.setFontSize(12); runDatasetTemplate.setFontSize(12);
XWPFParagraph externalReferencesParagraph = document.createParagraph(); /*XWPFParagraph externalReferencesParagraph = document.createParagraph();
externalReferencesParagraph.setStyle("Heading2"); externalReferencesParagraph.setStyle("Heading2");
XWPFRun externalReferencesRun = externalReferencesParagraph.createRun(); XWPFRun externalReferencesRun = externalReferencesParagraph.createRun();
externalReferencesRun.setText("External References"); externalReferencesRun.setText("External References");
@ -411,7 +417,7 @@ public class DatasetManager {
if (datasetEntity.getServices().size() > 0) { if (datasetEntity.getServices().size() > 0) {
wordBuilder.addParagraphContent(datasetEntity.getServices().stream().map(DatasetService::getService).map(Service::getLabel).collect(Collectors.joining(", ")) wordBuilder.addParagraphContent(datasetEntity.getServices().stream().map(DatasetService::getService).map(Service::getLabel).collect(Collectors.joining(", "))
, document, ParagraphStyle.TEXT, BigInteger.ZERO); , document, ParagraphStyle.TEXT, BigInteger.ZERO);
} }*/
/*wordBuilder.addParagraphContent("Tags", document, ParagraphStyle.HEADER3, BigInteger.ZERO); /*wordBuilder.addParagraphContent("Tags", document, ParagraphStyle.HEADER3, BigInteger.ZERO);
if (datasetEntity.().size() > 0) { if (datasetEntity.().size() > 0) {
wordBuilder.addParagraphContent(datasetEntity.getServices().stream().map(DatasetService::getService).map(Service::getLabel).collect(Collectors.joining(", ")) wordBuilder.addParagraphContent(datasetEntity.getServices().stream().map(DatasetService::getService).map(Service::getLabel).collect(Collectors.joining(", "))
@ -580,11 +586,16 @@ public class DatasetManager {
if (datasetWizardModel.getId() != null) { if (datasetWizardModel.getId() != null) {
tempDataset = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().find(datasetWizardModel.getId()); tempDataset = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().find(datasetWizardModel.getId());
if (tempDataset != null) { if (tempDataset != null) {
if (datasetWizardModel.getModified().getTime() != tempDataset.getModified().getTime()) {
Instant dbTime = Instant.ofEpochMilli(tempDataset.getModified().getTime()).truncatedTo(ChronoUnit.SECONDS);
Instant modelTime = Instant.ofEpochMilli(datasetWizardModel.getModified().getTime()).truncatedTo(ChronoUnit.SECONDS);
if (modelTime.toEpochMilli() != dbTime.toEpochMilli()) {
throw new Exception("Dataset has been modified already by another user."); throw new Exception("Dataset has been modified already by another user.");
} }
sendNotification = true; sendNotification = true;
} }
} else {
MetricsManager.increaseValue("argos_managed_dataset_descriptions", 1, "draft");
} }
if (dmp.getStatus().equals(DMP.DMPStatus.FINALISED.getValue()) && datasetWizardModel.getId() != null) if (dmp.getStatus().equals(DMP.DMPStatus.FINALISED.getValue()) && datasetWizardModel.getId() != null)
throw new Exception("DMP is finalized, therefore Dataset cannot be edited."); throw new Exception("DMP is finalized, therefore Dataset cannot be edited.");
@ -646,7 +657,7 @@ public class DatasetManager {
} }
private void checkDatasetValidation(Dataset dataset) throws Exception { public void checkDatasetValidation(Dataset dataset) throws Exception {
List<String> datasetProfileValidators = new LinkedList<>(); List<String> datasetProfileValidators = new LinkedList<>();
DatasetProfile profile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(dataset.getProfile().getId()); DatasetProfile profile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(dataset.getProfile().getId());
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
@ -819,6 +830,7 @@ public class DatasetManager {
if (dataset.getStatus() != eu.eudat.data.entities.Dataset.Status.FINALISED.getValue()) if (dataset.getStatus() != eu.eudat.data.entities.Dataset.Status.FINALISED.getValue())
throw new Exception("You cannot make public a Dataset That Has not Been Finalised"); throw new Exception("You cannot make public a Dataset That Has not Been Finalised");
datasetDao.createOrUpdate(dataset); datasetDao.createOrUpdate(dataset);
MetricsManager.increaseValue("argos_managed_dataset_descriptions", 1, "published");
} }
public ResponseEntity<byte[]> getDocument(String id, VisibilityRuleService visibilityRuleService, String contentType, Principal principal) throws IllegalAccessException, IOException, InstantiationException { public ResponseEntity<byte[]> getDocument(String id, VisibilityRuleService visibilityRuleService, String contentType, Principal principal) throws IllegalAccessException, IOException, InstantiationException {
@ -907,6 +919,7 @@ public class DatasetManager {
createServicesIfTheyDontExist(entity); createServicesIfTheyDontExist(entity);
createExternalDatasetsIfTheyDontExist(entity); createExternalDatasetsIfTheyDontExist(entity);
MetricsManager.increaseValue("argos_managed_dataset_descriptions", 1, "draft");
return apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(entity); return apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(entity);
} }
@ -1062,4 +1075,28 @@ public class DatasetManager {
listingModel.setProfileLatestVersion(islast); listingModel.setProfileLatestVersion(islast);
return listingModel; return listingModel;
} }
public long countAllDraft() {
eu.eudat.data.dao.criteria.DatasetCriteria criteria = new eu.eudat.data.dao.criteria.DatasetCriteria();
criteria.setStatus(0);
return apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(criteria).count();
}
public long countAllFinalized() {
eu.eudat.data.dao.criteria.DatasetCriteria criteria = new eu.eudat.data.dao.criteria.DatasetCriteria();
criteria.setStatus(1);
return apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(criteria).count();
}
public long countAllPublic() {
eu.eudat.data.dao.criteria.DatasetCriteria criteria = new eu.eudat.data.dao.criteria.DatasetCriteria();
criteria.setIsPublic(true);
return apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(criteria).count();
}
public long countAllWithDoi() {
eu.eudat.data.dao.criteria.DatasetCriteria criteria = new eu.eudat.data.dao.criteria.DatasetCriteria();
criteria.setHasDoi(true);
return apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(criteria).count();
}
} }

View File

@ -4,6 +4,8 @@ import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath; import com.jayway.jsonpath.JsonPath;
import eu.eudat.data.dao.criteria.DatasetProfileCriteria; import eu.eudat.data.dao.criteria.DatasetProfileCriteria;
import eu.eudat.data.entities.DatasetProfile; import eu.eudat.data.entities.DatasetProfile;
import eu.eudat.data.entities.UserDatasetProfile;
import eu.eudat.data.entities.UserInfo;
import eu.eudat.data.query.items.item.datasetprofile.DatasetProfileAutocompleteRequest; import eu.eudat.data.query.items.item.datasetprofile.DatasetProfileAutocompleteRequest;
import eu.eudat.data.query.items.table.datasetprofile.DatasetProfileTableRequestItem; import eu.eudat.data.query.items.table.datasetprofile.DatasetProfileTableRequestItem;
import eu.eudat.exceptions.datasetprofile.DatasetProfileNewVersionException; import eu.eudat.exceptions.datasetprofile.DatasetProfileNewVersionException;
@ -14,13 +16,17 @@ import eu.eudat.logic.utilities.builders.XmlBuilder;
import eu.eudat.logic.utilities.documents.helpers.FileEnvelope; 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.ExportXmlBuilderDatasetProfile;
import eu.eudat.logic.utilities.documents.xml.datasetProfileXml.ImportXmlBuilderDatasetProfile; 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.components.commons.datafield.AutoCompleteData;
import eu.eudat.models.data.datasetprofile.DatasetProfileAutocompleteItem; import eu.eudat.models.data.datasetprofile.DatasetProfileAutocompleteItem;
import eu.eudat.models.data.datasetprofile.DatasetProfileListingModel; import eu.eudat.models.data.datasetprofile.DatasetProfileListingModel;
import eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.Field; import eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.Field;
import eu.eudat.models.data.externaldataset.ExternalAutocompleteFieldModel; import eu.eudat.models.data.externaldataset.ExternalAutocompleteFieldModel;
import eu.eudat.models.data.helpers.common.DataTableData; import eu.eudat.models.data.helpers.common.DataTableData;
import eu.eudat.models.data.listingmodels.UserInfoListingModel;
import eu.eudat.models.data.security.Principal;
import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.QueryableList;
import eu.eudat.types.Authorities;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -37,6 +43,7 @@ import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import javax.activation.MimetypesFileTypeMap; import javax.activation.MimetypesFileTypeMap;
import javax.transaction.Transactional;
import javax.xml.xpath.*; import javax.xml.xpath.*;
import java.io.*; import java.io.*;
import java.nio.file.Files; import java.nio.file.Files;
@ -61,6 +68,7 @@ public class DatasetProfileManager {
this.cache = new ArrayList<>(); this.cache = new ArrayList<>();
} }
@Transactional
public eu.eudat.models.data.admin.composite.DatasetProfile getDatasetProfile(String id) { 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)); eu.eudat.data.entities.DatasetProfile profile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id));
eu.eudat.models.data.admin.composite.DatasetProfile datasetprofile = AdminManager.generateDatasetProfileModel(profile); eu.eudat.models.data.admin.composite.DatasetProfile datasetprofile = AdminManager.generateDatasetProfileModel(profile);
@ -68,7 +76,8 @@ public class DatasetProfileManager {
datasetprofile.setStatus(profile.getStatus()); datasetprofile.setStatus(profile.getStatus());
datasetprofile.setDescription(profile.getDescription()); datasetprofile.setDescription(profile.getDescription());
datasetprofile.setLanguage(profile.getLanguage()); datasetprofile.setLanguage(profile.getLanguage());
datasetprofile.setUsers(new ArrayList<>());
retrieveUsers(profile, datasetprofile);
return datasetprofile; return datasetprofile;
} }
@ -83,12 +92,19 @@ public class DatasetProfileManager {
DatasetProfile profile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id)); DatasetProfile profile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id));
apiContext.getOperationsContext().getDatabaseRepository().detachEntity(profile); apiContext.getOperationsContext().getDatabaseRepository().detachEntity(profile);
profile.setId(null); profile.setId(null);
MetricsManager.increaseValue("argos_dataset_templates", 1, "total");
return profile; return profile;
} }
public DataTableData<DatasetProfileListingModel> getPaged(DatasetProfileTableRequestItem datasetProfileTableRequestItem) throws Exception { public DataTableData<DatasetProfileListingModel> getPaged(DatasetProfileTableRequestItem datasetProfileTableRequestItem, Principal principal) throws Exception {
QueryableList<DatasetProfile> items = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().getWithCriteria(datasetProfileTableRequestItem.getCriteria()); QueryableList<DatasetProfile> items = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().getWithCriteria(datasetProfileTableRequestItem.getCriteria());
QueryableList<DatasetProfile> pagedItems = PaginationManager.applyPaging(items, datasetProfileTableRequestItem); QueryableList<DatasetProfile> authItems = null;
if (principal.getAuthz().contains(Authorities.ADMIN)) {
authItems = items;
} else if (principal.getAuthz().contains(Authorities.DATASET_PROFILE_MANAGER)) {
authItems = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().getAuthenticated(items, principal.getId(), null);
}
QueryableList<DatasetProfile> pagedItems = PaginationManager.applyPaging(authItems, datasetProfileTableRequestItem);
List<DatasetProfileListingModel> datasetProfiles = pagedItems.select(item -> new DatasetProfileListingModel().fromDataModel(item)); List<DatasetProfileListingModel> datasetProfiles = pagedItems.select(item -> new DatasetProfileListingModel().fromDataModel(item));
return apiContext.getOperationsContext().getBuilderFactory().getBuilder(DataTableDataBuilder.class).data(datasetProfiles).totalCount(items.count()).build(); return apiContext.getOperationsContext().getBuilderFactory().getBuilder(DataTableDataBuilder.class).data(datasetProfiles).totalCount(items.count()).build();
} }
@ -96,6 +112,7 @@ public class DatasetProfileManager {
public List<DatasetProfileListingModel> getAll(DatasetProfileTableRequestItem tableRequestItem) throws IllegalAccessException, InstantiationException { public List<DatasetProfileListingModel> getAll(DatasetProfileTableRequestItem tableRequestItem) throws IllegalAccessException, InstantiationException {
QueryableList<DatasetProfile> items = databaseRepository.getDatasetProfileDao().getWithCriteria(tableRequestItem.getCriteria()); QueryableList<DatasetProfile> items = databaseRepository.getDatasetProfileDao().getWithCriteria(tableRequestItem.getCriteria());
List<DatasetProfileListingModel> datasetProfiles = items.select(item -> new DatasetProfileListingModel().fromDataModel(item)); List<DatasetProfileListingModel> datasetProfiles = items.select(item -> new DatasetProfileListingModel().fromDataModel(item));
return datasetProfiles; return datasetProfiles;
} }
@ -215,6 +232,7 @@ public class DatasetProfileManager {
File localFile = convert(multiPartFile); File localFile = convert(multiPartFile);
eu.eudat.logic.utilities.documents.xml.datasetProfileXml.datasetProfileModel.DatasetProfile profile = xmlBuilder.build(localFile); eu.eudat.logic.utilities.documents.xml.datasetProfileXml.datasetProfileModel.DatasetProfile profile = xmlBuilder.build(localFile);
Files.deleteIfExists(localFile.toPath()); Files.deleteIfExists(localFile.toPath());
MetricsManager.increaseValue("argos_dataset_templates", 1, "total");
return profile; return profile;
} catch (IOException e) { } catch (IOException e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
@ -222,8 +240,8 @@ public class DatasetProfileManager {
return null; return null;
} }
private static File convert(MultipartFile file) throws IOException { private File convert(MultipartFile file) throws IOException {
File convFile = new File(file.getOriginalFilename()); File convFile = new File(this.environment.getProperty("temp.temp") + file.getOriginalFilename());
convFile.createNewFile(); convFile.createNewFile();
FileOutputStream fos = new FileOutputStream(convFile); FileOutputStream fos = new FileOutputStream(convFile);
fos.write(file.getBytes()); fos.write(file.getBytes());
@ -257,4 +275,61 @@ public class DatasetProfileManager {
throw new DatasetProfileNewVersionException("Version to update not the latest."); throw new DatasetProfileNewVersionException("Version to update not the latest.");
} }
} }
public void storeDatasetProfileUsers(DatasetProfile entity, eu.eudat.models.data.admin.composite.DatasetProfile model) {
if (model.getUsers() != null && !model.getUsers().isEmpty()) {
if (entity.getUsers() == null) {
entity.setUsers(new HashSet<>());
}
model.getUsers().stream().filter(userInfoListingModel -> entity.getUsers().stream().filter(userDatasetProfile -> userDatasetProfile.getUser().getId().equals(userInfoListingModel.getId())).count() == 0).forEach(userInfoListingModel -> {
UserDatasetProfile userDatasetProfile1 = new UserDatasetProfile();
userDatasetProfile1.setDatasetProfile(entity);
UserInfo userInfo1 = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(userInfoListingModel.getId());
userDatasetProfile1.setUser(userInfo1);
userDatasetProfile1.setRole(1);
apiContext.getOperationsContext().getDatabaseRepository().getUserDatasetProfileDao().createOrUpdate(userDatasetProfile1);
});
}
if (entity.getUsers() != null && !entity.getUsers().isEmpty()) {
entity.getUsers().stream().filter(userDatasetProfile -> model.getUsers().stream().filter(userInfoListingModel -> userDatasetProfile.getUser().getId().equals(userInfoListingModel.getId())).count() == 0).forEach(userDatasetProfile -> {
userDatasetProfile.setRole(2);
apiContext.getOperationsContext().getDatabaseRepository().getUserDatasetProfileDao().createOrUpdate(userDatasetProfile);
});
}
}
@Transactional
public void retrieveUsers(DatasetProfile entity, eu.eudat.models.data.admin.composite.DatasetProfile model) {
if (entity.getUsers() != null && !entity.getUsers().isEmpty()) {
model.setUsers(entity.getUsers().stream().filter(userDatasetProfile -> userDatasetProfile.getRole() < 2).map(userDatasetProfile -> {
UserInfoListingModel userInfoListingModel = new UserInfoListingModel();
userInfoListingModel.setId(userDatasetProfile.getUser().getId());
userInfoListingModel.setName(userDatasetProfile.getUser().getName());
userInfoListingModel.setEmail(userDatasetProfile.getUser().getEmail());
userInfoListingModel.setRole(userDatasetProfile.getRole());
return userInfoListingModel;
}).collect(Collectors.toList()));
}
}
public long countAlldraft() {
DatasetProfileCriteria criteria = new DatasetProfileCriteria();
criteria.setStatus(0);
return apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().getWithCriteria(criteria).count();
}
public long countAllFinalized() {
DatasetProfileCriteria criteria = new DatasetProfileCriteria();
criteria.setStatus(1);
return apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().getWithCriteria(criteria).count();
}
@Transactional
public long countAllUsed() {
DatasetProfileCriteria criteria = new DatasetProfileCriteria();
criteria.setStatus(1);
criteria.setAllVersions(false);
List<DatasetProfile> datasetProfiles = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().getWithCriteria(criteria).toList();
return datasetProfiles.stream().filter(StreamDistinctBy.distinctByKey(DatasetProfile::getId)).filter(datasetProfile -> !datasetProfile.getDataset().isEmpty()).count();
}
} }

View File

@ -1,7 +1,7 @@
package eu.eudat.logic.managers; package eu.eudat.logic.managers;
import eu.eudat.data.entities.Credential; import eu.eudat.data.entities.Credential;
import eu.eudat.data.entities.LoginConfirmationEmail; import eu.eudat.data.entities.EmailConfirmation;
import eu.eudat.data.entities.UserInfo; import eu.eudat.data.entities.UserInfo;
import eu.eudat.data.entities.UserToken; import eu.eudat.data.entities.UserToken;
import eu.eudat.exceptions.emailconfirmation.HasConfirmedEmailException; import eu.eudat.exceptions.emailconfirmation.HasConfirmedEmailException;
@ -30,7 +30,7 @@ public class EmailConfirmationManager {
} }
public void confirmEmail(String token) throws TokenExpiredException, HasConfirmedEmailException { public void confirmEmail(String token) throws TokenExpiredException, HasConfirmedEmailException {
LoginConfirmationEmail loginConfirmationEmail = apiContext.getOperationsContext() EmailConfirmation loginConfirmationEmail = apiContext.getOperationsContext()
.getDatabaseRepository().getLoginConfirmationEmailDao().asQueryable() .getDatabaseRepository().getLoginConfirmationEmailDao().asQueryable()
.where((builder, root) -> builder.equal(root.get("token"), UUID.fromString(token))).getSingle(); .where((builder, root) -> builder.equal(root.get("token"), UUID.fromString(token))).getSingle();

View File

@ -57,7 +57,7 @@ public class ExternalDatasetManager {
// Fetch external Datasets from external sources. // Fetch external Datasets from external sources.
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query); ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query);
List<Map<String, Object>> remoteRepos = remoteFetcher.getDatasets(externalUrlCriteria, type); List<Map<String, String>> remoteRepos = remoteFetcher.getDatasets(externalUrlCriteria, type);
// Parse items from external sources to listing models. // Parse items from external sources to listing models.
ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

View File

@ -42,7 +42,7 @@ public class FunderManager {
QueryableList<eu.eudat.data.entities.Funder> authItems = apiContext.getOperationsContext().getDatabaseRepository().getFunderDao().getAuthenticated(items, userInfo); QueryableList<eu.eudat.data.entities.Funder> authItems = apiContext.getOperationsContext().getDatabaseRepository().getFunderDao().getAuthenticated(items, userInfo);
List<Funder> funders = authItems.select(item -> new eu.eudat.models.data.funder.Funder().fromDataModel(item)); List<Funder> funders = authItems.select(item -> new eu.eudat.models.data.funder.Funder().fromDataModel(item));
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(funderCriteria.getCriteria().getLike()); ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(funderCriteria.getCriteria().getLike());
List<Map<String, Object>> remoteRepos = remoteFetcher.getFunders(externalUrlCriteria); List<Map<String, String>> remoteRepos = remoteFetcher.getFunders(externalUrlCriteria);
FundersExternalSourcesModel fundersExternalSourcesModel = new FundersExternalSourcesModel().fromExternalItem(remoteRepos); FundersExternalSourcesModel fundersExternalSourcesModel = new FundersExternalSourcesModel().fromExternalItem(remoteRepos);
for (ExternalSourcesItemModel externalListingItem : fundersExternalSourcesModel) { for (ExternalSourcesItemModel externalListingItem : fundersExternalSourcesModel) {
eu.eudat.models.data.funder.Funder funder = apiContext.getOperationsContext().getBuilderFactory().getBuilder(FunderBuilder.class) eu.eudat.models.data.funder.Funder funder = apiContext.getOperationsContext().getBuilderFactory().getBuilder(FunderBuilder.class)

View File

@ -126,7 +126,7 @@ public class GrantManager {
QueryableList<eu.eudat.data.entities.Grant> authItems = apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().getAuthenticated(items, userInfo); QueryableList<eu.eudat.data.entities.Grant> authItems = apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().getAuthenticated(items, userInfo);
List<eu.eudat.models.data.grant.Grant> grants = authItems.select(item -> new Grant().fromDataModel(item)); List<eu.eudat.models.data.grant.Grant> grants = authItems.select(item -> new Grant().fromDataModel(item));
List<Map<String, Object>> remoteRepos = remoteFetcher.getGrants(externalUrlCriteria); List<Map<String, String>> remoteRepos = remoteFetcher.getGrants(externalUrlCriteria);
GrantsExternalSourcesModel grantsExternalSourcesModel = new GrantsExternalSourcesModel().fromExternalItem(remoteRepos); GrantsExternalSourcesModel grantsExternalSourcesModel = new GrantsExternalSourcesModel().fromExternalItem(remoteRepos);
for (ExternalSourcesItemModel externalListingItem : grantsExternalSourcesModel) { for (ExternalSourcesItemModel externalListingItem : grantsExternalSourcesModel) {

View File

@ -33,7 +33,7 @@ public class LicenseManager {
public List<LicenseModel> getLicenses(String query, String type) throws HugeResultSet, NoURLFound { public List<LicenseModel> getLicenses(String query, String type) throws HugeResultSet, NoURLFound {
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query); ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query);
List<Map<String, Object>> remoteRepos = this.apiContext.getOperationsContext().getRemoteFetcher().getlicenses(externalUrlCriteria, type); List<Map<String, String>> remoteRepos = this.apiContext.getOperationsContext().getRemoteFetcher().getlicenses(externalUrlCriteria, type);
DataRepositoryCriteria criteria = new DataRepositoryCriteria(); DataRepositoryCriteria criteria = new DataRepositoryCriteria();
if (!query.isEmpty()) criteria.setLike(query); if (!query.isEmpty()) criteria.setLike(query);

View File

@ -0,0 +1,113 @@
package eu.eudat.logic.managers;
import eu.eudat.data.entities.Credential;
import eu.eudat.data.entities.EmailConfirmation;
import eu.eudat.data.entities.UserDMP;
import eu.eudat.data.entities.UserInfo;
import eu.eudat.data.entities.UserToken;
import eu.eudat.exceptions.emailconfirmation.HasConfirmedEmailException;
import eu.eudat.exceptions.emailconfirmation.TokenExpiredException;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.logic.services.operations.DatabaseRepository;
import eu.eudat.models.data.security.Principal;
import eu.eudat.queryable.QueryableList;
import eu.eudat.queryable.jpa.predicates.OrderByPredicate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import javax.transaction.Transactional;
import java.io.IOException;
import java.util.*;
@Component
public class MergeEmailConfirmationManager {
private static Logger logger = LoggerFactory.getLogger(MergeEmailConfirmationManager.class);
private ApiContext apiContext;
private DatabaseRepository databaseRepository;
@Autowired
public MergeEmailConfirmationManager(ApiContext apiContext) {
this.apiContext = apiContext;
this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository();
}
@Transactional
public void confirmEmail(String token) throws TokenExpiredException, HasConfirmedEmailException {
EmailConfirmation loginConfirmationEmail = apiContext.getOperationsContext()
.getDatabaseRepository().getLoginConfirmationEmailDao().asQueryable()
.where((builder, root) -> builder.equal(root.get("token"), UUID.fromString(token))).getSingle();
if (loginConfirmationEmail.getExpiresAt().compareTo(new Date()) < 0)
throw new TokenExpiredException("Token has expired.");
UserInfo userToBeMerged = databaseRepository.getUserInfoDao().asQueryable()
.where((builder, root) -> builder.equal(root.get("id"), loginConfirmationEmail.getUserId())).getSingle();
try {
Map<String, Object> map = new ObjectMapper().readValue(loginConfirmationEmail.getData(), HashMap.class);
UUID otherUserId = UUID.fromString((String) map.get("userId"));
UserInfo user = databaseRepository.getUserInfoDao().asQueryable()
.where((builder, root) -> builder.equal(root.get("id"), otherUserId)).getSingle();
// Checks if mail is used by another user. If it is, merges the new the old.
mergeNewUserToOld(user, userToBeMerged, Integer.valueOf((String) map.get("provider")));
expireUserToken(userToBeMerged);
loginConfirmationEmail.setIsConfirmed(true);
databaseRepository.getLoginConfirmationEmailDao().createOrUpdate(loginConfirmationEmail);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
public void sendConfirmationEmail(String email, Principal principal, UUID userId, Integer provider) throws HasConfirmedEmailException {
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
if (user.getEmail() != null && !user.getEmail().equals(email)) {
apiContext.getUtilitiesService().getConfirmationEmailService().createMergeConfirmationEmail(
databaseRepository.getLoginConfirmationEmailDao(),
apiContext.getUtilitiesService().getMailService(),
email,
userId,
principal,
provider
);
}
}
@Transactional
private void mergeNewUserToOld(UserInfo newUser, UserInfo oldUser, Integer provider) {
Credential credential = databaseRepository.getCredentialDao().asQueryable().where((builder, root) -> builder.and(builder.equal(root.get("userInfo"), oldUser), builder.equal(root.get("provider"), provider))).getSingle();
credential.setUserInfo(newUser);
databaseRepository.getCredentialDao().createOrUpdate(credential);
List<UserDMP> userDmps = databaseRepository.getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("user"), oldUser)).toList();
userDmps.forEach(userDmp -> {
userDmp.setUser(newUser);
databaseRepository.getUserDmpDao().createOrUpdate(userDmp);
});
oldUser.setUserStatus((short)1);
oldUser.setEmail(null);
List<Credential> credentials = databaseRepository.getCredentialDao().asQueryable().where((builder, root) -> builder.equal(root.get("userInfo"), oldUser)).toList();
credentials.forEach(cred -> {
if (cred.getId() != credential.getId()) {
databaseRepository.getCredentialDao().delete(cred);
}
});
databaseRepository.getUserInfoDao().createOrUpdate(oldUser);
}
private void expireUserToken(UserInfo user) {
UserToken userToken = databaseRepository.getUserTokenDao().asQueryable()
.where((builder, root) -> builder.equal(root.get("user"), user))
.orderBy((builder, root) -> builder.desc(root.get("issuedAt")))
.take(1).toList().get(0);
userToken.setExpiresAt(new Date());
databaseRepository.getUserTokenDao().createOrUpdate(userToken);
}
}

View File

@ -0,0 +1,126 @@
package eu.eudat.logic.managers;
import io.prometheus.client.Gauge;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.transaction.Transactional;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Component
public class MetricsManager {
private final static Logger logger = LoggerFactory.getLogger(MetricsManager.class);
private static Map<String, Gauge> gauges = Stream.of( new Object[][]{
{"argos_managed_dmps", Gauge.build().name("argos_managed_dmps").help("Number of managed DMPs").labelNames("status").register()},
{"argos_funders", Gauge.build().name("argos_funders").help("Number of registered Funders").register()},
{"argos_grants", Gauge.build().name("argos_grants").help("Number of registered Grants").register()},
{"argos_projects", Gauge.build().name("argos_projects").help("Number of registered Projects").register()},
{"argos_researchers", Gauge.build().name("argos_researchers").help("Number of Colaborators/Researchers").register()},
{"argos_managed_dataset_descriptions", Gauge.build().name("argos_managed_dataset_descriptions").help("Number of managed Dataset Descriptions").labelNames("status").register()},
{"argos_dataset_templates", Gauge.build().name("argos_dataset_templates").help("Number of dataset Templates").labelNames("status").register()},
{"argos_users", Gauge.build().name("argos_users").help("Number of users").labelNames("type").register()},
{"argos_languages", Gauge.build().name("argos_languages").help("Number of Languages").register()},
}).collect(Collectors.toMap(data -> (String)data[0], data -> (Gauge) data[1]));
public static void increaseValue(String name, int amount, String label) {
if(label != null) {
gauges.get(name).labels(label).inc(amount);
} else {
gauges.get(name).inc(amount);
}
}
public static void decreaseValue(String name, int amount, String label) {
if(label != null) {
gauges.get(name).labels(label).dec(amount);
} else {
gauges.get(name).dec(amount);
}
}
public static Integer getValue(String name, String label) {
if(label != null) {
return Double.valueOf(gauges.get(name).labels(label).get()).intValue();
} else {
return Double.valueOf(gauges.get(name).get()).intValue();
}
}
public static void calculateValue(String name, int amount, String label) {
Integer orig = getValue(name, label);
int diff = orig - amount;
if (diff != 0) {
if (diff > 0) {
decreaseValue(name, diff, label);
} else {
increaseValue(name, Math.abs(diff), label);
}
}
}
private final DatasetManager datasetManager;
private final DataManagementPlanManager dataManagementPlanManager;
private final DatasetProfileManager datasetProfileManager;
private final UserManager userManager;
private final Environment environment;
@Autowired
public MetricsManager(DatasetManager datasetManager, DataManagementPlanManager dataManagementPlanManager, DatasetProfileManager datasetProfileManager, UserManager userManager, Environment environment) {
this.datasetManager = datasetManager;
this.dataManagementPlanManager = dataManagementPlanManager;
this.datasetProfileManager = datasetProfileManager;
this.userManager = userManager;
this.environment = environment;
}
@PostConstruct
@Transactional
@Scheduled(initialDelay = 1000 * 60 * 60, fixedDelay = 1000 * 60 * 60)
public void init() throws IOException {
logger.info("Start calculating Metrics");
calculateValue("argos_managed_dmps", (int) dataManagementPlanManager.countAllDrafts(), "draft");
calculateValue("argos_managed_dmps", (int) dataManagementPlanManager.countAllFinalized(), "finalized");
calculateValue("argos_managed_dmps", (int) dataManagementPlanManager.countAllPublished(), "published");
calculateValue("argos_managed_dmps", (int) dataManagementPlanManager.countAllDoied(), "doied");
calculateValue("argos_funders", (int) dataManagementPlanManager.countAllFunders(), null);
calculateValue("argos_grants", (int) dataManagementPlanManager.countAllGrants(), null);
calculateValue("argos_projects", (int) dataManagementPlanManager.countAllProjects(), null);
calculateValue("argos_researchers", (int) dataManagementPlanManager.countAllResearchers(), null);
calculateValue("argos_managed_dataset_descriptions", (int) datasetManager.countAllDraft(), "draft");
calculateValue("argos_managed_dataset_descriptions", (int) datasetManager.countAllFinalized(), "finalized");
calculateValue("argos_managed_dataset_descriptions", (int) datasetManager.countAllPublic(), "published");
calculateValue("argos_managed_dataset_descriptions", (int) datasetManager.countAllWithDoi(), "doied");
calculateValue("argos_dataset_templates", (int) datasetProfileManager.countAlldraft(), "total");
calculateValue("argos_dataset_templates", (int) datasetProfileManager.countAllFinalized(), "active");
calculateValue("argos_dataset_templates", (int) datasetProfileManager.countAllUsed(), "used");
calculateValue("argos_users", (int) userManager.countActiveUsers().intValue(), "loggedin");
calculateValue("argos_users", (int) userManager.countAllUsers().intValue(), "total");
long files = Files.list(Paths.get(this.environment.getProperty("userguide.path"))).count();
calculateValue("argos_languages", (int) files, null);
logger.info("Metrics calculation Completed");
}
}

View File

@ -66,9 +66,35 @@ public class OrganisationsManager {
return organisationDataTableData; return organisationDataTableData;
} }
public List<Organisation> getWithExternal(OrganisationsTableRequest organisationsTableRequest, Principal principal) throws Exception {
eu.eudat.data.entities.UserInfo userInfo = new eu.eudat.data.entities.UserInfo();
userInfo.setId(principal.getId());
OrganisationDao organisationDao = databaseRepository.getOrganisationDao();
QueryableList<eu.eudat.data.entities.Organisation> items = organisationDao.getWithCriteria(organisationsTableRequest.getCriteria());
QueryableList<eu.eudat.data.entities.Organisation> authItems = organisationDao.getAuthenticated(items, userInfo);
QueryableList<eu.eudat.data.entities.Organisation> pagedItems = PaginationManager.applyPaging(authItems, organisationsTableRequest);
List<Organisation> org = pagedItems.toList().stream().distinct().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList());
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(organisationsTableRequest.getCriteria().getLabelLike());
List<Map<String, String>> remoteRepos = apiContext.getOperationsContext().getRemoteFetcher().getOrganisations(externalUrlCriteria, null);
OrganisationsExternalSourcesModel organisationsExternalSourcesModel = new OrganisationsExternalSourcesModel().fromExternalItem(remoteRepos);
for (ExternalSourcesItemModel externalListingItem : organisationsExternalSourcesModel) {
Organisation organisation = apiContext.getOperationsContext().getBuilderFactory().getBuilder(OrganisationBuilder.class)
.name(externalListingItem.getName())
.reference(externalListingItem.getRemoteId())
.tag(externalListingItem.getTag())
.key(externalListingItem.getKey())
.build();
org.add(organisation);
}
return org;
}
public List<Organisation> getCriteriaWithExternal(String query, String type) throws HugeResultSet, NoURLFound { public List<Organisation> getCriteriaWithExternal(String query, String type) throws HugeResultSet, NoURLFound {
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query); ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query);
List<Map<String, Object>> remoteRepos = apiContext.getOperationsContext().getRemoteFetcher().getOrganisations(externalUrlCriteria, type); List<Map<String, String>> remoteRepos = apiContext.getOperationsContext().getRemoteFetcher().getOrganisations(externalUrlCriteria, type);
OrganisationsExternalSourcesModel organisationsExternalSourcesModel = new OrganisationsExternalSourcesModel().fromExternalItem(remoteRepos); OrganisationsExternalSourcesModel organisationsExternalSourcesModel = new OrganisationsExternalSourcesModel().fromExternalItem(remoteRepos);
List<Organisation> organisations = new LinkedList<>(); List<Organisation> organisations = new LinkedList<>();
for (ExternalSourcesItemModel externalListingItem : organisationsExternalSourcesModel) { for (ExternalSourcesItemModel externalListingItem : organisationsExternalSourcesModel) {

View File

@ -41,7 +41,7 @@ public class ProjectManager {
QueryableList<eu.eudat.data.entities.Project> authItems = apiContext.getOperationsContext().getDatabaseRepository().getProjectDao().getAuthenticated(items, userInfo); QueryableList<eu.eudat.data.entities.Project> authItems = apiContext.getOperationsContext().getDatabaseRepository().getProjectDao().getAuthenticated(items, userInfo);
List<Project> projects = authItems.select(item -> new Project().fromDataModel(item)); List<Project> projects = authItems.select(item -> new Project().fromDataModel(item));
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(projectCriteria.getCriteria().getLike()); ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(projectCriteria.getCriteria().getLike());
List<Map<String, Object>> remoteRepos = remoteFetcher.getProjects(externalUrlCriteria); List<Map<String, String>> remoteRepos = remoteFetcher.getProjects(externalUrlCriteria);
ProjectsExternalSourcesModel projectsExternalSourcesModel = new ProjectsExternalSourcesModel().fromExternalItem(remoteRepos); ProjectsExternalSourcesModel projectsExternalSourcesModel = new ProjectsExternalSourcesModel().fromExternalItem(remoteRepos);
for (ExternalSourcesItemModel externalListingItem : projectsExternalSourcesModel) { for (ExternalSourcesItemModel externalListingItem : projectsExternalSourcesModel) {
eu.eudat.models.data.project.Project project = apiContext.getOperationsContext().getBuilderFactory().getBuilder(ProjectBuilder.class) eu.eudat.models.data.project.Project project = apiContext.getOperationsContext().getBuilderFactory().getBuilder(ProjectBuilder.class)

View File

@ -39,7 +39,7 @@ public class RegistryManager {
public List<RegistryModel> getRegistries(String query, String type, Principal principal) throws HugeResultSet, NoURLFound { public List<RegistryModel> getRegistries(String query, String type, Principal principal) throws HugeResultSet, NoURLFound {
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query); ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query);
List<Map<String, Object>> remoteRepos = this.apiContext.getOperationsContext().getRemoteFetcher().getRegistries(externalUrlCriteria, type); List<Map<String, String>> remoteRepos = this.apiContext.getOperationsContext().getRemoteFetcher().getRegistries(externalUrlCriteria, type);
RegistryCriteria criteria = new RegistryCriteria(); RegistryCriteria criteria = new RegistryCriteria();
if (!query.isEmpty()) criteria.setLike(query); if (!query.isEmpty()) criteria.setLike(query);

View File

@ -57,7 +57,7 @@ public class ResearcherManager {
item.setTag(keyToSourceMap.get(item.getKey())); item.setTag(keyToSourceMap.get(item.getKey()));
} }
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(researcherCriteriaRequest.getCriteria().getName()); ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(researcherCriteriaRequest.getCriteria().getName());
List<Map<String, Object>> remoteRepos = remoteFetcher.getResearchers(externalUrlCriteria,null); List<Map<String, String>> remoteRepos = remoteFetcher.getResearchers(externalUrlCriteria,null);
ResearchersExternalSourcesModel researchersExternalSourcesModel = new ResearchersExternalSourcesModel().fromExternalItem(remoteRepos); ResearchersExternalSourcesModel researchersExternalSourcesModel = new ResearchersExternalSourcesModel().fromExternalItem(remoteRepos);
for (ExternalSourcesItemModel externalListingItem : researchersExternalSourcesModel) { for (ExternalSourcesItemModel externalListingItem : researchersExternalSourcesModel) {
eu.eudat.models.data.dmp.Researcher researcher = apiContext.getOperationsContext().getBuilderFactory().getBuilder(ResearcherBuilder.class) eu.eudat.models.data.dmp.Researcher researcher = apiContext.getOperationsContext().getBuilderFactory().getBuilder(ResearcherBuilder.class)

View File

@ -36,7 +36,7 @@ public class ServiceManager {
public List<ServiceModel> getServices(String query, String type, Principal principal) throws HugeResultSet, NoURLFound { public List<ServiceModel> getServices(String query, String type, Principal principal) throws HugeResultSet, NoURLFound {
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query); ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query);
List<Map<String, Object>> remoteRepos = this.apiContext.getOperationsContext().getRemoteFetcher().getServices(externalUrlCriteria, type); List<Map<String, String>> remoteRepos = this.apiContext.getOperationsContext().getRemoteFetcher().getServices(externalUrlCriteria, type);
ServiceCriteria criteria = new ServiceCriteria(); ServiceCriteria criteria = new ServiceCriteria();
if (!query.isEmpty()) criteria.setLike(query); if (!query.isEmpty()) criteria.setLike(query);

View File

@ -3,6 +3,7 @@ package eu.eudat.logic.managers;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.data.dao.criteria.DataManagementPlanCriteria; import eu.eudat.data.dao.criteria.DataManagementPlanCriteria;
import eu.eudat.data.dao.entities.UserInfoDao; import eu.eudat.data.dao.entities.UserInfoDao;
import eu.eudat.data.entities.Credential;
import eu.eudat.data.entities.DMP; import eu.eudat.data.entities.DMP;
import eu.eudat.data.entities.UserInfo; import eu.eudat.data.entities.UserInfo;
import eu.eudat.data.entities.UserRole; import eu.eudat.data.entities.UserRole;
@ -26,23 +27,39 @@ import eu.eudat.models.data.helpers.common.DataTableData;
import eu.eudat.models.data.login.Credentials; import eu.eudat.models.data.login.Credentials;
import eu.eudat.models.data.principal.PrincipalModel; import eu.eudat.models.data.principal.PrincipalModel;
import eu.eudat.models.data.security.Principal; import eu.eudat.models.data.security.Principal;
import eu.eudat.models.data.userinfo.UserCredential;
import eu.eudat.models.data.userinfo.UserListingModel; import eu.eudat.models.data.userinfo.UserListingModel;
import eu.eudat.models.data.userinfo.UserProfile; import eu.eudat.models.data.userinfo.UserProfile;
import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.QueryableList;
import eu.eudat.types.Authorities;
import org.json.JSONObject; import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.time.Instant; import java.time.Instant;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Component @Component
public class UserManager { public class UserManager {
private static final Logger logger = LoggerFactory.getLogger(UserManager.class);
private ApiContext apiContext; private ApiContext apiContext;
private ZenodoCustomProvider zenodoCustomProvider; private ZenodoCustomProvider zenodoCustomProvider;
@ -73,6 +90,19 @@ public class UserManager {
List<UserListingModel> modelUsers = pagedUsers.select(item -> new UserListingModel().fromDataModel(item)); List<UserListingModel> modelUsers = pagedUsers.select(item -> new UserListingModel().fromDataModel(item));
return apiContext.getOperationsContext().getBuilderFactory().getBuilder(DataTableDataBuilder.class).totalCount(users.count()).data(modelUsers).build(); return apiContext.getOperationsContext().getBuilderFactory().getBuilder(DataTableDataBuilder.class).totalCount(users.count()).data(modelUsers).build();
} }
public List<UserCredential> getCredentials(UUID userId) {
List<UserCredential> results = new ArrayList<>();
eu.eudat.data.entities.UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(userId);
List<Credential> credentials = apiContext.getOperationsContext().getDatabaseRepository().getCredentialDao().asQueryable().where((builder, root) -> builder.equal(root.get("userInfo"), user)).toList();
credentials.forEach(credential -> {
UserCredential userCredential = new UserCredential();
userCredential.setEmail(credential.getEmail());
userCredential.setProvider(credential.getProvider());
results.add(userCredential);
});
return results;
}
public UserProfile getSingle(UUID userId) throws Exception { public UserProfile getSingle(UUID userId) throws Exception {
eu.eudat.data.entities.UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(userId); eu.eudat.data.entities.UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(userId);
@ -100,6 +130,8 @@ public class UserManager {
apiContext.getOperationsContext().getDatabaseRepository().detachEntity(userInfo); apiContext.getOperationsContext().getDatabaseRepository().detachEntity(userInfo);
HashMap<String, Object> result = HashMap<String, Object> result =
new ObjectMapper().readValue(userInfo.getAdditionalinfo(), HashMap.class); new ObjectMapper().readValue(userInfo.getAdditionalinfo(), HashMap.class);
userInfo.setName(settings.entrySet().stream().filter(entry -> entry.getKey().equals("name")).filter(Objects::nonNull).map(entry -> entry.getValue().toString()).findFirst().orElse(userInfo.getName()));
settings.remove("name");
result.putAll(settings); result.putAll(settings);
userInfo.setAdditionalinfo(new JSONObject(result).toString()); userInfo.setAdditionalinfo(new JSONObject(result).toString());
apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao() apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao()
@ -168,4 +200,57 @@ public class UserManager {
settings.put("expirationDate", 0); settings.put("expirationDate", 0);
this.updateSettings(settings, principal); this.updateSettings(settings, principal);
} }
public ResponseEntity<byte[]> exportToCsv(Principal principal) throws IOException {
if (!principal.getAuthz().contains(Authorities.ADMIN))
throw new UnauthorisedException();
List<UserInfo> users = this.apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().asQueryable().toList();
StringBuilder resultBuilder = new StringBuilder();
resultBuilder.append("User Id").append(",").append("User Name").append(",").append("User Email").append("\n");
users.stream().forEach(user -> resultBuilder.append(user.getId().toString()).append(",")
.append(user.getName()).append(",")
.append(user.getEmail()).append("\n"));
String result = resultBuilder.toString();
String fileName = "Users_dump";//dmp.getLabel();
fileName = fileName.replaceAll("[^a-zA-Z0-9+ ]", "");
String uuid = UUID.randomUUID().toString();
File file = new File(this.environment.getProperty("temp.temp") + uuid + ".csv");
OutputStream output = new FileOutputStream(file);
try {
// mapper.writeValue(file, rdaExportModel);
output.write(result.getBytes());
output.flush();
output.close();
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
InputStream resource = new FileInputStream(file);
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentLength(file.length());
responseHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
responseHeaders.set("Content-Disposition", "attachment;filename=" + fileName + ".csv");
responseHeaders.set("Access-Control-Expose-Headers", "Content-Disposition");
responseHeaders.get("Access-Control-Expose-Headers").add("Content-Type");
byte[] content = org.apache.poi.util.IOUtils.toByteArray(resource);
resource.close();
Files.deleteIfExists(file.toPath());
return new ResponseEntity<>(content, responseHeaders, HttpStatus.OK);
}
public UserProfile getFromEmail(String email) {
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().asQueryable().where((builder, root) -> builder.equal(root.get("email"), email)).getSingle();
return new UserProfile().fromDataModel(user);
}
public Long countActiveUsers(){
return apiContext.getOperationsContext().getDatabaseRepository().getUserTokenDao().asQueryable().where(((builder, root) -> builder.greaterThan(root.get("expiresAt"), new Date()))).count();
}
public Long countAllUsers(){
return apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().asQueryable().count();
}
} }

View File

@ -0,0 +1,31 @@
package eu.eudat.logic.managers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import eu.eudat.logic.proxy.config.ExternalUrlCriteria;
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
import eu.eudat.logic.proxy.fetching.RemoteFetcher;
import eu.eudat.models.data.security.Principal;
@Component
public class ValidationManager {
private RemoteFetcher remoteFetcher;
@Autowired
public ValidationManager(RemoteFetcher remoteFetcher) {
super();
this.remoteFetcher = remoteFetcher;
}
public Boolean validateIdentifier(String identifier, String type, Principal principal) throws NoURLFound, HugeResultSet {
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(identifier);
Integer count = this.remoteFetcher.findEntries(externalUrlCriteria, type);
return principal != null && count > 0;
}
}

View File

@ -25,6 +25,7 @@ public class ExternalUrls implements Serializable {
/*TagUrls tags;*/ /*TagUrls tags;*/
FunderUrls funders; FunderUrls funders;
LicenseUrls licenses; LicenseUrls licenses;
ValidationUrls validations;
public RegistryUrls getRegistries() { public RegistryUrls getRegistries() {
@ -143,6 +144,15 @@ public class ExternalUrls implements Serializable {
public void setLicenses(LicenseUrls licenses) { public void setLicenses(LicenseUrls licenses) {
this.licenses = licenses; this.licenses = licenses;
} }
public ValidationUrls getValidations() {
return validations;
}
@XmlElement(name = "validators")
public void setValidations(ValidationUrls validations) {
this.validations = validations;
}
} }

View File

@ -15,6 +15,8 @@ public class UrlConfiguration {
private String contentType; private String contentType;
private String funderQuery; private String funderQuery;
private String firstpage; private String firstpage;
private String requestType = "GET";
private String requestBody = "";
public String getKey() { public String getKey() {
return key; return key;
@ -95,4 +97,21 @@ public class UrlConfiguration {
public void setFirstpage(String firstpage) { public void setFirstpage(String firstpage) {
this.firstpage = firstpage; this.firstpage = firstpage;
} }
public String getRequestType() {
return requestType;
}
@XmlElement(name = "request")
public void setRequestType(String requestType) {
this.requestType = requestType != null ? requestType : "GET";
}
public String getRequestBody() {
return requestBody;
}
@XmlElement(name = "requestBody")
public void setRequestBody(String requestBody) {
this.requestBody = requestBody != null ? requestBody : "";
}
} }

View File

@ -0,0 +1,36 @@
package eu.eudat.logic.proxy.config.entities;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import eu.eudat.logic.proxy.config.FetchStrategy;
import eu.eudat.logic.proxy.config.UrlConfiguration;
public class ValidationUrls {
List<UrlConfiguration> urls;
FetchStrategy fetchMode;
public List<UrlConfiguration> getUrls() {
return urls;
}
@XmlElementWrapper
@XmlElement(name = "urlConfig")
public void setUrls(List<UrlConfiguration> urls) {
this.urls = urls;
}
public FetchStrategy getFetchMode() {
return fetchMode;
}
@XmlElement(name = "fetchMode")
public void setFetchMode(FetchStrategy fetchMode) {
this.fetchMode = fetchMode;
}
}

View File

@ -1,6 +1,7 @@
package eu.eudat.logic.proxy.fetching; package eu.eudat.logic.proxy.fetching;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.jayway.jsonpath.DocumentContext; import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath; import com.jayway.jsonpath.JsonPath;
@ -141,6 +142,15 @@ public class RemoteFetcher {
FetchStrategy fetchStrategy = configLoader.getExternalUrls().getLicenses().getFetchMode(); FetchStrategy fetchStrategy = configLoader.getExternalUrls().getLicenses().getFetchMode();
return getAll(urlConfigs, fetchStrategy, externalUrlCriteria); return getAll(urlConfigs, fetchStrategy, externalUrlCriteria);
} }
public Integer findEntries(ExternalUrlCriteria externalUrlCriteria, String key) throws NoURLFound, HugeResultSet {
List<UrlConfiguration> urlConfigs =
key != null && !key.isEmpty() ? configLoader.getExternalUrls().getValidations().getUrls().stream().filter(item -> item.getKey().equals(key)).collect(Collectors.toList())
: configLoader.getExternalUrls().getValidations().getUrls();
FetchStrategy fetchStrategy = configLoader.getExternalUrls().getValidations().getFetchMode();
List<Map<String, String>> data = this.getAll(urlConfigs, fetchStrategy, externalUrlCriteria);
return data.size();
}
private List<Map<String, String>> getAll(List<UrlConfiguration> urlConfigs, FetchStrategy fetchStrategy, ExternalUrlCriteria externalUrlCriteria) throws NoURLFound, HugeResultSet { private List<Map<String, String>> getAll(List<UrlConfiguration> urlConfigs, FetchStrategy fetchStrategy, ExternalUrlCriteria externalUrlCriteria) throws NoURLFound, HugeResultSet {
@ -154,7 +164,7 @@ public class RemoteFetcher {
for (UrlConfiguration urlConfig : urlConfigs) { for (UrlConfiguration urlConfig : urlConfigs) {
ifFunderQueryExist(urlConfig, externalUrlCriteria); ifFunderQueryExist(urlConfig, externalUrlCriteria);
if (urlConfig.getType() == null || urlConfig.getType().equals("External")) { if (urlConfig.getType() == null || urlConfig.getType().equals("External")) {
results.addAll(getAllResultsFromUrl(urlConfig.getUrl(), fetchStrategy, urlConfig.getData(), urlConfig.getPaginationPath(), externalUrlCriteria, urlConfig.getLabel(), urlConfig.getKey(), urlConfig.getContentType(), urlConfig.getFirstpage())); results.addAll(getAllResultsFromUrl(urlConfig.getUrl(), fetchStrategy, urlConfig.getData(), urlConfig.getPaginationPath(), externalUrlCriteria, urlConfig.getLabel(), urlConfig.getKey(), urlConfig.getContentType(), urlConfig.getFirstpage(), urlConfig.getRequestBody(), urlConfig.getRequestType()));
} else if (urlConfig.getType() != null && urlConfig.getType().equals("Internal")) { } else if (urlConfig.getType() != null && urlConfig.getType().equals("Internal")) {
results.addAll(getAllResultsFromMockUpJson(urlConfig.getUrl(), externalUrlCriteria.getLike())); results.addAll(getAllResultsFromMockUpJson(urlConfig.getUrl(), externalUrlCriteria.getLike()));
} }
@ -223,12 +233,13 @@ public class RemoteFetcher {
return completedPath; return completedPath;
} }
private List<Map<String, String>> getAllResultsFromUrl(String path, FetchStrategy fetchStrategy, final DataUrlConfiguration jsonDataPath, final String jsonPaginationPath, ExternalUrlCriteria externalUrlCriteria, String tag, String key, String contentType, String firstPage) throws HugeResultSet { private List<Map<String, String>> getAllResultsFromUrl(String path, FetchStrategy fetchStrategy, final DataUrlConfiguration jsonDataPath, final String jsonPaginationPath, ExternalUrlCriteria externalUrlCriteria, String tag, String key, String contentType, String firstPage, String requestBody, String requestType) throws HugeResultSet {
Set<Integer> pages = new HashSet<>(); Set<Integer> pages = new HashSet<>();
String replacedPath = replaceCriteriaOnUrl(path, externalUrlCriteria, firstPage); String replacedPath = replaceCriteriaOnUrl(path, externalUrlCriteria, firstPage);
String replacedBody = replaceCriteriaOnUrl(requestBody, externalUrlCriteria, firstPage);
Results results = getResultsFromUrl(replacedPath, jsonDataPath, jsonPaginationPath, contentType); Results results = getResultsFromUrl(replacedPath, jsonDataPath, jsonPaginationPath, contentType, replacedBody, requestType);
if (fetchStrategy == FetchStrategy.FIRST) if (fetchStrategy == FetchStrategy.FIRST)
return results == null ? new LinkedList<>() : results.getResults().stream().peek(x -> x.put("tag", tag)).peek(x -> x.put("key", key)).collect(Collectors.toList()); return results == null ? new LinkedList<>() : results.getResults().stream().peek(x -> x.put("tag", tag)).peek(x -> x.put("key", key)).collect(Collectors.toList());
@ -241,7 +252,7 @@ public class RemoteFetcher {
throw new HugeResultSet("The submitted search query " + externalUrlCriteria.getLike() + " is about to return " + results.getPagination().get("count") + " results... Please submit a more detailed search query"); throw new HugeResultSet("The submitted search query " + externalUrlCriteria.getLike() + " is about to return " + results.getPagination().get("count") + " results... Please submit a more detailed search query");
Optional<Results> optionalResults = pages.parallelStream() Optional<Results> optionalResults = pages.parallelStream()
.map(page -> getResultsFromUrl(path + "&page=" + page, jsonDataPath, jsonPaginationPath, contentType)) .map(page -> getResultsFromUrl(path + "&page=" + page, jsonDataPath, jsonPaginationPath, contentType, replacedBody, requestType))
.reduce((result1, result2) -> { .reduce((result1, result2) -> {
result1.getResults().addAll(result2.getResults()); result1.getResults().addAll(result2.getResults());
return result1; return result1;
@ -253,12 +264,12 @@ public class RemoteFetcher {
} }
private Results getResultsFromUrl(String urlString, DataUrlConfiguration jsonDataPath, String jsonPaginationPath, String contentType) { private Results getResultsFromUrl(String urlString, DataUrlConfiguration jsonDataPath, String jsonPaginationPath, String contentType, String requestBody, String requestType) {
try { try {
RestTemplate restTemplate = new RestTemplate(); RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
HttpEntity<String> entity; HttpEntity<JsonNode> entity;
ResponseEntity<String> response; ResponseEntity<String> response;
/* /*
* URL url = new URL(urlString.replaceAll(" ", "%20")); * URL url = new URL(urlString.replaceAll(" ", "%20"));
@ -268,11 +279,12 @@ public class RemoteFetcher {
*/ */
if (contentType != null && !contentType.isEmpty()) { if (contentType != null && !contentType.isEmpty()) {
headers.setAccept(Collections.singletonList(MediaType.valueOf(contentType))); headers.setAccept(Collections.singletonList(MediaType.valueOf(contentType)));
headers.setContentType(MediaType.valueOf(contentType));
} }
JsonNode jsonBody = new ObjectMapper().readTree(requestBody);
entity = new HttpEntity<>("parameters", headers); entity = new HttpEntity<>(jsonBody, headers);
response = restTemplate.exchange(urlString, HttpMethod.GET, entity, String.class); response = restTemplate.exchange(urlString, HttpMethod.resolve(requestType), entity, String.class);
if (response.getStatusCode() == HttpStatus.OK) { // success if (response.getStatusCode() == HttpStatus.OK) { // success
//do here all the parsing //do here all the parsing
Results results = new Results(); Results results = new Results();
@ -333,7 +345,7 @@ public class RemoteFetcher {
externalUrlCriteria.setPath(result.get("path")); externalUrlCriteria.setPath(result.get("path"));
externalUrlCriteria.setHost(result.get("host")); externalUrlCriteria.setHost(result.get("host"));
String replacedPath = replaceCriteriaOnUrl(jsonDataPath.getUrlConfiguration().getUrl(), externalUrlCriteria, jsonDataPath.getUrlConfiguration().getFirstpage()); String replacedPath = replaceCriteriaOnUrl(jsonDataPath.getUrlConfiguration().getUrl(), externalUrlCriteria, jsonDataPath.getUrlConfiguration().getFirstpage());
return getResultsFromUrl(replacedPath, jsonDataPath.getUrlConfiguration().getData(), jsonDataPath.getUrlConfiguration().getData().getPath(), jsonDataPath.getUrlConfiguration().getContentType()); return getResultsFromUrl(replacedPath, jsonDataPath.getUrlConfiguration().getData(), jsonDataPath.getUrlConfiguration().getData().getPath(), jsonDataPath.getUrlConfiguration().getContentType(), requestBody, requestType);
}).filter(Objects::nonNull).map(results1 -> results1.results.get(0)).collect(Collectors.toList()); }).filter(Objects::nonNull).map(results1 -> results1.results.get(0)).collect(Collectors.toList());
results = new Results(multiResults, new HashMap<>(1, 1)); results = new Results(multiResults, new HashMap<>(1, 1));
} else if (jsonDataPath.getFieldsUrlConfiguration().getTypes() != null) { } else if (jsonDataPath.getFieldsUrlConfiguration().getTypes() != null) {

View File

@ -36,6 +36,8 @@ public interface DatabaseRepository {
ExternalDatasetDao getExternalDatasetDao(); ExternalDatasetDao getExternalDatasetDao();
UserDatasetProfileDao getUserDatasetProfileDao();
UserDmpDao getUserDmpDao(); UserDmpDao getUserDmpDao();
ContentDao getContentDao(); ContentDao getContentDao();
@ -46,7 +48,7 @@ public interface DatabaseRepository {
DatasetServiceDao getDatasetServiceDao(); DatasetServiceDao getDatasetServiceDao();
LoginConfirmationEmailDao getLoginConfirmationEmailDao(); EmailConfirmationDao getLoginConfirmationEmailDao();
ProjectDao getProjectDao(); ProjectDao getProjectDao();

View File

@ -27,12 +27,13 @@ public class DatabaseRepositoryImpl implements DatabaseRepository {
private UserTokenDao userTokenDao; private UserTokenDao userTokenDao;
private ExternalDatasetDao externalDatasetDao; private ExternalDatasetDao externalDatasetDao;
private UserRoleDao userRoleDao; private UserRoleDao userRoleDao;
private UserDatasetProfileDao userDatasetProfileDao;
private UserDmpDao userDmpDao; private UserDmpDao userDmpDao;
private ContentDao contentDao; private ContentDao contentDao;
private DMPProfileDao dmpProfileDao; private DMPProfileDao dmpProfileDao;
private DatasetExternalDatasetDao datasetExternalDatasetDao; private DatasetExternalDatasetDao datasetExternalDatasetDao;
private DatasetServiceDao datasetServiceDao; private DatasetServiceDao datasetServiceDao;
private LoginConfirmationEmailDao loginConfirmationEmailDao; private EmailConfirmationDao loginConfirmationEmailDao;
private ProjectDao projectDao; private ProjectDao projectDao;
private FunderDao funderDao; private FunderDao funderDao;
private LockDao lockDao; private LockDao lockDao;
@ -247,12 +248,12 @@ public class DatabaseRepositoryImpl implements DatabaseRepository {
} }
@Override @Override
public LoginConfirmationEmailDao getLoginConfirmationEmailDao() { public EmailConfirmationDao getLoginConfirmationEmailDao() {
return loginConfirmationEmailDao; return loginConfirmationEmailDao;
} }
@Autowired @Autowired
public void setLoginConfirmationEmailDao(LoginConfirmationEmailDao loginConfirmationEmailDao) { public void setLoginConfirmationEmailDao(EmailConfirmationDao loginConfirmationEmailDao) {
this.loginConfirmationEmailDao = loginConfirmationEmailDao; this.loginConfirmationEmailDao = loginConfirmationEmailDao;
} }
@ -306,6 +307,16 @@ public class DatabaseRepositoryImpl implements DatabaseRepository {
this.notificationDao = notificationDao; this.notificationDao = notificationDao;
} }
@Override
public UserDatasetProfileDao getUserDatasetProfileDao() {
return userDatasetProfileDao;
}
@Autowired
public void setUserDatasetProfileDao(UserDatasetProfileDao userDatasetProfileDao) {
this.userDatasetProfileDao = userDatasetProfileDao;
}
public <T> void detachEntity(T entity) { public <T> void detachEntity(T entity) {
this.entityManager.detach(entity); this.entityManager.detach(entity);
} }

View File

@ -54,7 +54,7 @@ public abstract class AbstractAuthenticationService implements AuthenticationSer
UserInfo userInfo = this.apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class) UserInfo userInfo = this.apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class)
.name(username).email(environment.getProperty("autouser.root.email")).created(new Date()) .name(username).email(environment.getProperty("autouser.root.email")).created(new Date())
.lastloggedin(new Date()).authorization_level((short) 1).usertype((short) 1) .lastloggedin(new Date()).authorization_level((short) 1).usertype((short) 1).userStatus((short)0)
.build(); .build();
userInfo = this.apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().createOrUpdate(userInfo); userInfo = this.apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().createOrUpdate(userInfo);
@ -111,14 +111,22 @@ public abstract class AbstractAuthenticationService implements AuthenticationSer
public Principal Touch(LoginProviderUser profile) throws NullEmailException { public Principal Touch(LoginProviderUser profile) throws NullEmailException {
UserInfo userInfo = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().asQueryable().withHint("userInfo").where((builder, root) -> builder.equal(root.get("email"), profile.getEmail())).getSingleOrDefault(); UserInfo userInfo;// = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().asQueryable().withHint("userInfo").where((builder, root) -> builder.and(builder.equal(root.get("email"), profile.getEmail()), builder.equal(root.get("userStatus"), 0))).getSingleOrDefault();
if (userInfo == null) { //if (userInfo == null) {
Optional<Credential> optionalCredential = Optional.ofNullable(apiContext.getOperationsContext().getDatabaseRepository().getCredentialDao() Optional<Credential> optionalCredential = Optional.ofNullable(apiContext.getOperationsContext().getDatabaseRepository().getCredentialDao()
.asQueryable().withHint("credentialUserInfo") .asQueryable().withHint("credentialUserInfo")
.where((builder, root) -> builder.and(builder.equal(root.get("provider"), profile.getProvider().getValue()), builder.equal(root.get("externalId"), profile.getId()))) .where((builder, root) -> builder.and(builder.equal(root.get("provider"), profile.getProvider().getValue()), builder.equal(root.get("externalId"), profile.getId())))
.getSingleOrDefault()); .getSingleOrDefault());
userInfo = optionalCredential.map(Credential::getUserInfo).orElse(null); userInfo = optionalCredential.map(Credential::getUserInfo).orElse(null);
if (userInfo != null) {
if (userInfo.getUserStatus() == 1) {
userInfo = null;
}
}
//}
if (userInfo == null) {
userInfo = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().asQueryable().withHint("userInfo").where((builder, root) -> builder.and(builder.equal(root.get("email"), profile.getEmail()), builder.equal(root.get("userStatus"), 0))).getSingleOrDefault();
} }
final Credential credential = this.apiContext.getOperationsContext().getBuilderFactory().getBuilder(CredentialBuilder.class) final Credential credential = this.apiContext.getOperationsContext().getBuilderFactory().getBuilder(CredentialBuilder.class)
@ -129,6 +137,7 @@ public abstract class AbstractAuthenticationService implements AuthenticationSer
.provider(profile.getProvider().getValue()) .provider(profile.getProvider().getValue())
.secret(profile.getSecret()) .secret(profile.getSecret())
.externalId(profile.getId()) .externalId(profile.getId())
.email(profile.getEmail())
.build(); .build();
if (userInfo == null) { if (userInfo == null) {
@ -140,11 +149,12 @@ public abstract class AbstractAuthenticationService implements AuthenticationSer
+ "\", \"expirationDate\": \"" + Instant.now().plusSeconds((profile.getZenodoExpire() != null ? profile.getZenodoExpire(): 0)).toEpochMilli() + "\", \"expirationDate\": \"" + Instant.now().plusSeconds((profile.getZenodoExpire() != null ? profile.getZenodoExpire(): 0)).toEpochMilli()
+ "\", \"zenodoRefresh\": \"" + profile.getZenodoRefresh() + "\", \"zenodoRefresh\": \"" + profile.getZenodoRefresh()
+ (profile.getProvider() == TokenValidatorFactoryImpl.LoginProvider.ZENODO ? "\", \"zenodoEmail\": \"" + profile.getEmail() : "") +"\"}}") + (profile.getProvider() == TokenValidatorFactoryImpl.LoginProvider.ZENODO ? "\", \"zenodoEmail\": \"" + profile.getEmail() : "") +"\"}}")
.authorization_level((short) 1).usertype((short) 1) .authorization_level((short) 1).usertype((short) 1).userStatus((short)0)
.build(); .build();
userInfo = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().createOrUpdate(userInfo); userInfo = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().createOrUpdate(userInfo);
credential.setPublicValue(userInfo.getName()); credential.setPublicValue(userInfo.getName());
credential.setEmail(userInfo.getEmail());
credential.setUserInfo(userInfo); credential.setUserInfo(userInfo);
apiContext.getOperationsContext().getDatabaseRepository().getCredentialDao().createOrUpdate(credential); apiContext.getOperationsContext().getDatabaseRepository().getCredentialDao().createOrUpdate(credential);
@ -181,6 +191,7 @@ public abstract class AbstractAuthenticationService implements AuthenticationSer
credential.setUserInfo(userInfo); credential.setUserInfo(userInfo);
credential.setId(UUID.randomUUID()); credential.setId(UUID.randomUUID());
credential.setPublicValue(userInfo.getName()); credential.setPublicValue(userInfo.getName());
credential.setEmail(userInfo.getEmail());
apiContext.getOperationsContext().getDatabaseRepository().getCredentialDao().createOrUpdate(credential); apiContext.getOperationsContext().getDatabaseRepository().getCredentialDao().createOrUpdate(credential);
userInfo.getCredentials().add(credential); userInfo.getCredentials().add(credential);
} }

View File

@ -1,13 +1,18 @@
package eu.eudat.logic.services.utilities; package eu.eudat.logic.services.utilities;
import eu.eudat.data.dao.entities.LoginConfirmationEmailDao; import eu.eudat.data.dao.entities.EmailConfirmationDao;
import eu.eudat.data.entities.LoginConfirmationEmail; import eu.eudat.data.entities.EmailConfirmation;
import eu.eudat.models.data.security.Principal;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
public interface ConfirmationEmailService { public interface ConfirmationEmailService {
public void createConfirmationEmail(LoginConfirmationEmailDao loginConfirmationEmailDao, MailService mailService, String email, UUID userId); public void createConfirmationEmail(EmailConfirmationDao loginConfirmationEmailDao, MailService mailService, String email, UUID userId);
public void createMergeConfirmationEmail(EmailConfirmationDao loginConfirmationEmailDao, MailService mailService, String email, UUID userId, Principal principal, Integer provider);
public CompletableFuture sentConfirmationEmail(LoginConfirmationEmail confirmationEmail, MailService mailService); public CompletableFuture sentConfirmationEmail(EmailConfirmation confirmationEmail, MailService mailService);
public CompletableFuture sentMergeConfirmationEmail(EmailConfirmation confirmationEmail, MailService mailService, String userName);
} }

View File

@ -1,14 +1,19 @@
package eu.eudat.logic.services.utilities; package eu.eudat.logic.services.utilities;
import eu.eudat.data.dao.entities.LoginConfirmationEmailDao; import com.fasterxml.jackson.core.JsonProcessingException;
import eu.eudat.data.entities.LoginConfirmationEmail; import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.data.dao.entities.EmailConfirmationDao;
import eu.eudat.data.entities.EmailConfirmation;
import eu.eudat.models.data.mail.SimpleMail; import eu.eudat.models.data.mail.SimpleMail;
import eu.eudat.models.data.security.Principal;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -24,8 +29,8 @@ public class ConfirmationEmailServiceImpl implements ConfirmationEmailService {
} }
@Override @Override
public void createConfirmationEmail(LoginConfirmationEmailDao loginConfirmationEmailDao, MailService mailService, String email, UUID userId) { public void createConfirmationEmail(EmailConfirmationDao loginConfirmationEmailDao, MailService mailService, String email, UUID userId) {
LoginConfirmationEmail confirmationEmail = new LoginConfirmationEmail(); EmailConfirmation confirmationEmail = new EmailConfirmation();
confirmationEmail.setEmail(email); confirmationEmail.setEmail(email);
confirmationEmail.setExpiresAt(Date confirmationEmail.setExpiresAt(Date
.from(new Date() .from(new Date()
@ -41,7 +46,7 @@ public class ConfirmationEmailServiceImpl implements ConfirmationEmailService {
} }
@Override @Override
public CompletableFuture sentConfirmationEmail(LoginConfirmationEmail confirmationEmail, MailService mailService) { public CompletableFuture sentConfirmationEmail(EmailConfirmation confirmationEmail, MailService mailService) {
return CompletableFuture.runAsync(() -> { return CompletableFuture.runAsync(() -> {
SimpleMail mail = new SimpleMail(); SimpleMail mail = new SimpleMail();
mail.setSubject(environment.getProperty("conf_email.subject")); mail.setSubject(environment.getProperty("conf_email.subject"));
@ -64,6 +69,31 @@ public class ConfirmationEmailServiceImpl implements ConfirmationEmailService {
return content; return content;
} }
@Override
public CompletableFuture sentMergeConfirmationEmail(EmailConfirmation confirmationEmail, MailService mailService, String userName) {
return CompletableFuture.runAsync(() -> {
SimpleMail mail = new SimpleMail();
mail.setSubject(environment.getProperty("conf_email.subject"));
mail.setContent(createMergeContent(confirmationEmail.getToken(), mailService, userName));
mail.setTo(confirmationEmail.getEmail());
try {
mailService.sendSimpleMail(mail);
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
}
});
}
private String createMergeContent(UUID confirmationToken, MailService mailService, String userName) {
String content = mailService.getMailTemplateContent("classpath:templates/email/emailMergeConfirmation.html");
content = content.replace("{userName}", userName);
content = content.replace("{confirmationToken}", confirmationToken.toString());
content = content.replace("{expiration_time}", secondsToTime(Integer.parseInt(this.environment.getProperty("conf_email.expiration_time_seconds"))));
content = content.replace("{host}", this.environment.getProperty("dmp.domain"));
return content;
}
private String secondsToTime(int seconds) { private String secondsToTime(int seconds) {
int sec = seconds % 60; int sec = seconds % 60;
int hour = seconds / 60; int hour = seconds / 60;
@ -71,4 +101,31 @@ public class ConfirmationEmailServiceImpl implements ConfirmationEmailService {
hour = hour / 60; hour = hour / 60;
return (hour + ":" + min + ":" + sec); return (hour + ":" + min + ":" + sec);
} }
@Override
public void createMergeConfirmationEmail(EmailConfirmationDao loginConfirmationEmailDao, MailService mailService,
String email, UUID userId, Principal principal, Integer provider) {
EmailConfirmation confirmationEmail = new EmailConfirmation();
confirmationEmail.setEmail(email);
confirmationEmail.setExpiresAt(Date
.from(new Date()
.toInstant()
.plusSeconds(Long.parseLong(this.environment.getProperty("conf_email.expiration_time_seconds")))
)
);
confirmationEmail.setUserId(userId);
try {
Map<String, Object> map = new HashMap<>();
map.put("userId", principal.getId());
map.put("provider", provider.toString());
confirmationEmail.setData(new ObjectMapper().writeValueAsString(map));
} catch (JsonProcessingException e) {
logger.error(e.getMessage(), e);
}
confirmationEmail.setIsConfirmed(false);
confirmationEmail.setToken(UUID.randomUUID());
confirmationEmail = loginConfirmationEmailDao.createOrUpdate(confirmationEmail);
sentMergeConfirmationEmail(confirmationEmail, mailService, principal.getName());
}
} }

View File

@ -11,10 +11,16 @@ import org.springframework.core.io.Resource;
import org.springframework.mail.javamail.JavaMailSender; import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.mail.BodyPart;
import javax.mail.Message; import javax.mail.Message;
import javax.mail.MessagingException; import javax.mail.MessagingException;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import java.io.*; import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@Service("mailService") @Service("mailService")
@ -36,9 +42,34 @@ public class MailServiceImpl implements MailService {
@Override @Override
public void sendSimpleMail(SimpleMail mail) throws MessagingException { public void sendSimpleMail(SimpleMail mail) throws MessagingException {
List<String> imageSources = parseImages(mail.getContent());
List<String> cids = new ArrayList<>();
if (!imageSources.isEmpty()) {
for (int i = 0; i < imageSources.size(); i++) {
cids.add(UUID.randomUUID().toString());
}
mail.setContent(replaceImageSources(mail.getContent(), cids));
}
MimeMultipart content = new MimeMultipart("related");
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setContent(mail.getContent(), "text/html; charset=UTF-8");
content.addBodyPart(messageBodyPart);
if (!imageSources.isEmpty()) {
for (int i =0; i < imageSources.size(); i++) {
MimeBodyPart imagePart = new MimeBodyPart();
try {
imagePart.attachFile(applicationContext.getResource(imageSources.get(i)).getFile());
imagePart.setContentID("<" + cids.get(i) + ">");
imagePart.setDisposition(MimeBodyPart.INLINE);
content.addBodyPart(imagePart);
} catch (IOException | MessagingException e) {
logger.error(e.getMessage(), e);
}
}
}
MimeMessage message = this.emailSender.createMimeMessage(); MimeMessage message = this.emailSender.createMimeMessage();
message.setSubject(mail.getSubject()); message.setSubject(mail.getSubject());
message.setText(mail.getContent(), "utf-8", "html"); message.setContent(content);
message.addRecipients(Message.RecipientType.TO, mail.getTo()); message.addRecipients(Message.RecipientType.TO, mail.getTo());
message.setFrom(env.getProperty("mail.from")); message.setFrom(env.getProperty("mail.from"));
this.emailSender.send(message); this.emailSender.send(message);
@ -66,4 +97,39 @@ public class MailServiceImpl implements MailService {
public String getMailTemplateSubject() { public String getMailTemplateSubject() {
return env.getProperty("mail.subject"); return env.getProperty("mail.subject");
} }
private List<String> parseImages(String content) {
List<String> imagePaths = new ArrayList<>();
int lastIndex = 0;
while (lastIndex != -1) {
lastIndex = content.indexOf("img src=\"", lastIndex);
if (lastIndex != -1) {
imagePaths.add(content.substring(lastIndex + 9, content.indexOf("\"", lastIndex + 9)));
lastIndex ++;
}
}
return imagePaths;
}
private String replaceImageSources(String content, List<String> cids) {
int lastIndex = 0;
int cidIndex = 0;
while (lastIndex != -1) {
lastIndex = content.indexOf("img src=\"", lastIndex);
if (lastIndex != -1) {
content = content.replace(content.substring(lastIndex + 9, content.indexOf("\"", lastIndex + 9)), "cid:" + cids.get(cidIndex));
lastIndex ++;
cidIndex ++;
}
}
return content;
}
} }

View File

@ -94,6 +94,7 @@ public class ModelBuilder {
if (type.equals("organizations")) return (FieldData<U>) new OrganizationsData().fromData(data); if (type.equals("organizations")) return (FieldData<U>) new OrganizationsData().fromData(data);
if (type.equals("datasetIdentifier")) return (FieldData<U>) new DatasetIdentifierData().fromData(data); if (type.equals("datasetIdentifier")) return (FieldData<U>) new DatasetIdentifierData().fromData(data);
if (type.equals("currency")) return (FieldData<U>) new CurrencyData().fromData(data); if (type.equals("currency")) return (FieldData<U>) new CurrencyData().fromData(data);
if (type.equals("validation")) return (FieldData<U>) new ValidationData().fromData(data);
return null; return null;
} }
@ -132,6 +133,7 @@ public class ModelBuilder {
if (type.equals("organizations")) return (FieldData<U>) new OrganizationsData().fromData(data); if (type.equals("organizations")) return (FieldData<U>) new OrganizationsData().fromData(data);
if (type.equals("datasetIdentifier")) return (FieldData<U>) new DatasetIdentifierData().fromData(data); if (type.equals("datasetIdentifier")) return (FieldData<U>) new DatasetIdentifierData().fromData(data);
if (type.equals("currency")) return (FieldData<U>) new CurrencyData().fromData(data); if (type.equals("currency")) return (FieldData<U>) new CurrencyData().fromData(data);
if (type.equals("validation")) return (FieldData<U>) new ValidationData().fromData(data);
return null; return null;
} }
} }

View File

@ -1,5 +1,6 @@
package eu.eudat.logic.utilities.documents.word; package eu.eudat.logic.utilities.documents.word;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.logic.services.forms.VisibilityRuleService; import eu.eudat.logic.services.forms.VisibilityRuleService;
@ -226,9 +227,22 @@ public class WordBuilder {
} }
private String formatter(Field field) throws IOException { private String formatter(Field field) throws IOException {
String comboboxType = null;
switch (field.getViewStyle().getRenderStyle()) { switch (field.getViewStyle().getRenderStyle()) {
case "researchers":
case "projects":
case "organizations":
case "externalDatasets":
case "dataRepositories":
case "registries":
case "services":
case "tags":
case "currency":
comboboxType = "autocomplete";
case "combobox": { case "combobox": {
String comboboxType = ((ComboBoxData) field.getData()).getType(); if (comboboxType == null) {
comboboxType = ((ComboBoxData) field.getData()).getType();
}
if (comboboxType.equals("autocomplete")) { if (comboboxType.equals("autocomplete")) {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
@ -271,13 +285,14 @@ public class WordBuilder {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
int index = 0; int index = 0;
for (Map<String, Object> map: mapList) { for (Map<String, Object> map: mapList) {
if (!map.containsKey("label") && !map.containsKey("description")) { /*if (!map.containsKey("label") && !map.containsKey("description")) {
logger.error("Value is missing the \"label\" and the \"description\" attributes"); logger.error("Value is missing the \"label\" and the \"description\" attributes");
map.put("label", "unknown Name"); map.put("label", "unknown Name");
} }*/
for (Map.Entry<String, Object> entry : map.entrySet()) { for (Map.Entry<String, Object> entry : map.entrySet()) {
if (entry.getValue() != null && (entry.getKey().equals("label") || entry.getKey().equals("description"))) { if (entry.getValue() != null && (entry.getKey().equals("label") || entry.getKey().equals("description") || entry.getKey().equals("name"))) {
sb.append(entry.getValue().toString()); sb.append(entry.getValue().toString());
break;
} }
} }
if (index != mapList.size() - 1) sb.append(", "); if (index != mapList.size() - 1) sb.append(", ");
@ -314,6 +329,23 @@ public class WordBuilder {
case "datepicker": case "datepicker":
case "textarea": case "textarea":
return field.getValue() != null ? field.getValue().toString(): ""; return field.getValue() != null ? field.getValue().toString(): "";
case "datasetIdentifier":
case "validation":
Map<String, String> identifierData;
try {
ObjectMapper mapper = new ObjectMapper();
identifierData = mapper.readValue(field.getValue().toString(), HashMap.class);
} catch (JsonParseException ex) {
identifierData = new HashMap<>();
String parsedData = field.getValue().toString().substring(1, field.getValue().toString().length() - 1);
StringTokenizer commaTokens = new StringTokenizer(parsedData, ", ");
while (commaTokens.hasMoreTokens()) {
String token = commaTokens.nextToken();
StringTokenizer equalTokens = new StringTokenizer(token, "=");
identifierData.put(equalTokens.nextToken(), equalTokens.nextToken());
}
}
return "id: " + identifierData.get("identifier") + ", Validation Type: " + identifierData.get("type");
} }
return null; return null;
} }

View File

@ -2,6 +2,7 @@ package eu.eudat.logic.utilities.documents.xml.datasetProfileXml;
import eu.eudat.models.data.admin.components.datasetprofile.Page; import eu.eudat.models.data.admin.components.datasetprofile.Page;
import eu.eudat.models.data.components.commons.ViewStyle;
import eu.eudat.models.data.components.commons.datafield.*; import eu.eudat.models.data.components.commons.datafield.*;
import eu.eudat.models.data.user.components.datasetprofile.Field; import eu.eudat.models.data.user.components.datasetprofile.Field;
import eu.eudat.models.data.user.components.datasetprofile.FieldSet; import eu.eudat.models.data.user.components.datasetprofile.FieldSet;
@ -32,6 +33,9 @@ public class ExportXmlBuilderDatasetProfile {
// root.appendChild(createPages(datasetProfile.getPages(), datasetProfile.getSections(), xmlDoc)); // root.appendChild(createPages(datasetProfile.getPages(), datasetProfile.getSections(), xmlDoc));
xmlDoc.appendChild(createPages(datasetProfile.getPages(), datasetProfile.getSections(), xmlDoc)); xmlDoc.appendChild(createPages(datasetProfile.getPages(), datasetProfile.getSections(), xmlDoc));
Element pages = (Element)xmlDoc.getFirstChild();
pages.setAttribute("description", datasetProfile.getDescription());
pages.setAttribute("language", datasetProfile.getLanguage());
String xml = XmlBuilder.generateXml(xmlDoc); String xml = XmlBuilder.generateXml(xmlDoc);
writer.write(xml); writer.write(xml);
writer.close(); writer.close();
@ -199,67 +203,120 @@ public class ExportXmlBuilderDatasetProfile {
if (field.getData() != null) { if (field.getData() != null) {
Element dataOut = element.createElement("data"); Element dataOut = element.createElement("data");
if (field.getViewStyle().getRenderStyle().equals("combobox")) { ViewStyle.Type viewStyleType = ViewStyle.Type.fromName(field.getViewStyle().getRenderStyle());
ComboBoxData comboBoxDataObject = (ComboBoxData) field.getData(); switch (viewStyleType) {
if (comboBoxDataObject.getType().equals("wordlist")) { case COMBO_BOX:
WordListData wordListDataObject = (WordListData) field.getData(); ComboBoxData comboBoxDataObject = (ComboBoxData) field.getData();
dataOut.setAttribute("label", wordListDataObject.getLabel()); if (comboBoxDataObject.getType().equals("wordlist")) {
dataOut.setAttribute("type", wordListDataObject.getType()); WordListData wordListDataObject = (WordListData) field.getData();
dataOut.setAttribute("multiList", wordListDataObject.getMultiList().toString()); dataOut.setAttribute("label", wordListDataObject.getLabel());
dataOut.setAttribute("type", wordListDataObject.getType());
dataOut.setAttribute("multiList", wordListDataObject.getMultiList().toString());
Element options = element.createElement("options");
wordListDataObject.getOptions().forEach(optionChildFor -> {
Element optionChild = element.createElement("option");
optionChild.setAttribute("label", optionChildFor.getLabel());
optionChild.setAttribute("value", optionChildFor.getValue());
options.appendChild(optionChild);
});
dataOut.appendChild(options);
} else if (comboBoxDataObject.getType().equals("autocomplete")) {
AutoCompleteData autoCompleteDataObject = (AutoCompleteData) field.getData();
dataOut.setAttribute("label", autoCompleteDataObject.getLabel());
dataOut.setAttribute("type", autoCompleteDataObject.getType());
dataOut.setAttribute("multiAutoComplete", autoCompleteDataObject.getMultiAutoComplete().toString());
for (AutoCompleteData.AutoCompleteSingleData singleData: autoCompleteDataObject.getAutoCompleteSingleDataList()) {
Element singleItem = element.createElement("autocompleteSingle");
singleItem.setAttribute("optionsRoot", singleData.getOptionsRoot());
singleItem.setAttribute("url", singleData.getUrl());
singleItem.setAttribute("autoCompleteType", Integer.toString(singleData.getAutocompleteType()));
if (singleData.getAutoCompleteOptions() != null) {
Element optionChild = element.createElement("option");
optionChild.setAttribute("label", singleData.getAutoCompleteOptions().getLabel());
optionChild.setAttribute("value", singleData.getAutoCompleteOptions().getValue());
singleItem.appendChild(optionChild);
}
dataOut.appendChild(singleItem);
}
}
break;
case BOOLEAN_DECISION:
BooleanDecisionData booleanDecisionDataObject = (BooleanDecisionData) field.getData();
dataOut.setAttribute("label", booleanDecisionDataObject.getLabel());
break;
case RADIO_BOX:
RadioBoxData radioBoxDataObject = (RadioBoxData) field.getData();
dataOut.setAttribute("label", radioBoxDataObject.getLabel());
Element options = element.createElement("options"); Element options = element.createElement("options");
wordListDataObject.getOptions().forEach(optionChildFor -> { radioBoxDataObject.getOptions().forEach(optionChildFor -> {
Element optionChild = element.createElement("option"); Element optionChild = element.createElement("option");
optionChild.setAttribute("label", optionChildFor.getLabel()); optionChild.setAttribute("label", optionChildFor.getLabel());
optionChild.setAttribute("value", optionChildFor.getValue()); optionChild.setAttribute("value", optionChildFor.getValue());
options.appendChild(optionChild); options.appendChild(optionChild);
}); });
dataOut.appendChild(options); dataOut.appendChild(options);
} else if (comboBoxDataObject.getType().equals("autocomplete")) { break;
AutoCompleteData autoCompleteDataObject = (AutoCompleteData) field.getData(); case CHECK_BOX:
dataOut.setAttribute("label", autoCompleteDataObject.getLabel()); case FREE_TEXT:
dataOut.setAttribute("type", autoCompleteDataObject.getType()); case TEXT_AREA:
dataOut.setAttribute("multiAutoComplete", autoCompleteDataObject.getMultiAutoComplete().toString()); case DATE_PICKER:
for (AutoCompleteData.AutoCompleteSingleData singleData: autoCompleteDataObject.getAutoCompleteSingleDataList()) { case DATASET_IDENTIFIER:
Element singleItem = element.createElement("autocompleteSingle"); case CURRENCY:
singleItem.setAttribute("optionsRoot", singleData.getOptionsRoot()); case TAGS:
singleItem.setAttribute("url", singleData.getUrl()); FieldData fieldDataObject = (FieldData) field.getData();
singleItem.setAttribute("autoCompleteType", Integer.toString(singleData.getAutocompleteType())); dataOut.setAttribute("label", fieldDataObject.getLabel());
if (singleData.getAutoCompleteOptions() != null) { break;
Element optionChild = element.createElement("option"); case INTERNAL_DMP_ENTRIES:
optionChild.setAttribute("label", singleData.getAutoCompleteOptions().getLabel()); InternalDmpEntitiesData internalDmpEntitiesData = (InternalDmpEntitiesData) field.getData();
optionChild.setAttribute("value", singleData.getAutoCompleteOptions().getValue()); dataOut.setAttribute("label", internalDmpEntitiesData.getLabel());
singleItem.appendChild(optionChild); dataOut.setAttribute("type", internalDmpEntitiesData.getType());
} switch (internalDmpEntitiesData.getType()) {
dataOut.appendChild(singleItem); case "researchers":
ResearchersAutoCompleteData researchersAutoCompleteData = (ResearchersAutoCompleteData) internalDmpEntitiesData;
dataOut.setAttribute("multiAutocomplete", researchersAutoCompleteData.getMultiAutoComplete().toString());
break;
case "datasets":
DatasetsAutoCompleteData datasetsAutoCompleteData = (DatasetsAutoCompleteData) internalDmpEntitiesData;
dataOut.setAttribute("multiAutocomplete", datasetsAutoCompleteData.getMultiAutoComplete().toString());
break;
case "dmps":
DMPsAutoCompleteData dmPsAutoCompleteData = (DMPsAutoCompleteData) internalDmpEntitiesData;
dataOut.setAttribute("multiAutocomplete", dmPsAutoCompleteData.getMultiAutoComplete().toString());
break;
} }
} break;
} else if (field.getViewStyle().getRenderStyle().equals("booleanDecision")) { case EXTERNAL_DATASETS:
BooleanDecisionData booleanDecisionDataObject = (BooleanDecisionData) field.getData(); ExternalDatasetsData externalDatasetsData = (ExternalDatasetsData) field.getData();
dataOut.setAttribute("label", booleanDecisionDataObject.getLabel()); dataOut.setAttribute("label", externalDatasetsData.getLabel());
} else if (field.getViewStyle().getRenderStyle().equals("radiobox")) { dataOut.setAttribute("multiAutocomplete", externalDatasetsData.getMultiAutoComplete().toString());
RadioBoxData radioBoxDataObject = (RadioBoxData) field.getData(); break;
dataOut.setAttribute("label", radioBoxDataObject.getLabel()); case DATA_REPOSITORIES:
DataRepositoriesData dataRepositoriesData = (DataRepositoriesData) field.getData();
dataOut.setAttribute("label", dataRepositoriesData.getLabel());
dataOut.setAttribute("multiAutocomplete", dataRepositoriesData.getMultiAutoComplete().toString());
break;
case ORGANIZATIONS:
OrganizationsData organizationsData = (OrganizationsData) field.getData();
dataOut.setAttribute("label", organizationsData.getLabel());
dataOut.setAttribute("multiAutocomplete", organizationsData.getMultiAutoComplete().toString());
break;
case RESEARCHERS:
ResearcherData researcherData = (ResearcherData) field.getData();
dataOut.setAttribute("label", researcherData.getLabel());
dataOut.setAttribute("multiAutocomplete", researcherData.getMultiAutoComplete().toString());
break;
case REGISTRIES:
RegistriesData registriesData = (RegistriesData) field.getData();
dataOut.setAttribute("label", registriesData.getLabel());
dataOut.setAttribute("multiAutocomplete", registriesData.getMultiAutoComplete().toString());
break;
case SERVICES:
ServicesData servicesData = (ServicesData) field.getData();
dataOut.setAttribute("label", servicesData.getLabel());
dataOut.setAttribute("multiAutocomplete", servicesData.getMultiAutoComplete().toString());
break;
Element options = element.createElement("options");
radioBoxDataObject.getOptions().forEach(optionChildFor -> {
Element optionChild = element.createElement("option");
optionChild.setAttribute("label", optionChildFor.getLabel());
optionChild.setAttribute("value", optionChildFor.getValue());
options.appendChild(optionChild);
});
dataOut.appendChild(options);
} else if (field.getViewStyle().getRenderStyle().equals("checkBox")) {
CheckBoxData checkBoxDataObject = (CheckBoxData) field.getData();
dataOut.setAttribute("label", checkBoxDataObject.getLabel());
} else if (field.getViewStyle().getRenderStyle().equals("freetext")) {
FreeTextData freeTextDataObject = (FreeTextData) field.getData();
dataOut.setAttribute("label", freeTextDataObject.getLabel());
} else if (field.getViewStyle().getRenderStyle().equals("textarea")) {
TextAreaData textAreaDataObject = (TextAreaData) field.getData();
dataOut.setAttribute("label", textAreaDataObject.getLabel());
} else if (field.getViewStyle().getRenderStyle().equals("datePicker")) {
DatePickerData datePickerDataObject = (DatePickerData) field.getData();
dataOut.setAttribute("label", datePickerDataObject.getLabel());
} }
elementField.appendChild(dataOut); elementField.appendChild(dataOut);
} }

View File

@ -1,6 +1,7 @@
package eu.eudat.logic.utilities.documents.xml.datasetProfileXml.datasetProfileModel; package eu.eudat.logic.utilities.documents.xml.datasetProfileXml.datasetProfileModel;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import java.util.LinkedList; import java.util.LinkedList;
@ -9,6 +10,9 @@ import java.util.List;
@XmlRootElement(name = "pages") @XmlRootElement(name = "pages")
public class DatasetProfile { public class DatasetProfile {
private String description;
private String language;
private List<Page> page; private List<Page> page;
@XmlElement(name = "page") @XmlElement(name = "page")
@ -20,11 +24,30 @@ public class DatasetProfile {
this.page = page; this.page = page;
} }
@XmlAttribute(name = "description")
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@XmlAttribute(name = "language")
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public eu.eudat.models.data.admin.composite.DatasetProfile toAdminCompositeModel(String label){ public eu.eudat.models.data.admin.composite.DatasetProfile toAdminCompositeModel(String label){
eu.eudat.models.data.admin.composite.DatasetProfile newDatasetEntityProfile = new eu.eudat.models.data.admin.composite.DatasetProfile(); eu.eudat.models.data.admin.composite.DatasetProfile newDatasetEntityProfile = new eu.eudat.models.data.admin.composite.DatasetProfile();
newDatasetEntityProfile.setLabel(label); newDatasetEntityProfile.setLabel(label);
newDatasetEntityProfile.setStatus(eu.eudat.data.entities.DatasetProfile.Status.SAVED.getValue()); newDatasetEntityProfile.setStatus(eu.eudat.data.entities.DatasetProfile.Status.SAVED.getValue());
newDatasetEntityProfile.setDescription(description);
newDatasetEntityProfile.setLanguage(language);
List<eu.eudat.models.data.admin.components.datasetprofile.Page> pagesDatasetEntity = new LinkedList<>(); List<eu.eudat.models.data.admin.components.datasetprofile.Page> pagesDatasetEntity = new LinkedList<>();
List<eu.eudat.models.data.admin.components.datasetprofile.Section> sectionDatasetEntity = new LinkedList<>(); List<eu.eudat.models.data.admin.components.datasetprofile.Section> sectionDatasetEntity = new LinkedList<>();
for (Page xmlPage: page) { for (Page xmlPage: page) {

View File

@ -117,7 +117,9 @@ public class Field {
fieldEntity.setViewStyle(this.viewStyle.toAdminCompositeModelSection()); fieldEntity.setViewStyle(this.viewStyle.toAdminCompositeModelSection());
FieldData data = new ModelBuilder().toFieldData(null, this.viewStyle.getRenderStyle(), (Element) this.data); FieldData data = new ModelBuilder().toFieldData(null, this.viewStyle.getRenderStyle(), (Element) this.data);
// fieldEntity.setData( data.fromXml((Element) this.data)); // fieldEntity.setData( data.fromXml((Element) this.data));
fieldEntity.setData( data.toMap((Element)this.data)); if (data != null) {
fieldEntity.setData(data.toMap((Element) this.data));
}
return fieldEntity; return fieldEntity;
} }
} }

View File

@ -3,7 +3,9 @@ package eu.eudat.models.data.admin.composite;
import eu.eudat.models.data.admin.components.datasetprofile.Page; import eu.eudat.models.data.admin.components.datasetprofile.Page;
import eu.eudat.models.data.admin.components.datasetprofile.Section; import eu.eudat.models.data.admin.components.datasetprofile.Section;
import eu.eudat.logic.utilities.builders.ModelBuilder; import eu.eudat.logic.utilities.builders.ModelBuilder;
import eu.eudat.models.data.listingmodels.UserInfoListingModel;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -16,6 +18,7 @@ public class DatasetProfile {
private Short status; private Short status;
private Short version; private Short version;
private String language; private String language;
private List<UserInfoListingModel> users;
public String getLabel() { public String getLabel() {
@ -61,6 +64,13 @@ public class DatasetProfile {
this.language = language; this.language = language;
} }
public List<UserInfoListingModel> getUsers() {
return users;
}
public void setUsers(List<UserInfoListingModel> users) {
this.users = users;
}
public void buildProfile(eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.ViewStyleModel viewStyle) { public void buildProfile(eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.ViewStyleModel viewStyle) {
this.sections = new ModelBuilder().fromViewStyleDefinition(viewStyle.getSections(), Section.class); this.sections = new ModelBuilder().fromViewStyleDefinition(viewStyle.getSections(), Section.class);
this.pages = new ModelBuilder().fromViewStyleDefinition(viewStyle.getPages(), Page.class); this.pages = new ModelBuilder().fromViewStyleDefinition(viewStyle.getPages(), Page.class);
@ -80,6 +90,7 @@ public class DatasetProfile {
shortProfile.setStatus(this.status); shortProfile.setStatus(this.status);
shortProfile.setVersion(this.version); shortProfile.setVersion(this.version);
shortProfile.setLanguage(this.language); shortProfile.setLanguage(this.language);
shortProfile.setUsers(new ArrayList<>());
return shortProfile; return shortProfile;
} }
} }

View File

@ -20,4 +20,44 @@ public class ViewStyle {
this.cssClass = cssClass; this.cssClass = cssClass;
} }
public enum Type {
COMBO_BOX("combobox"),
BOOLEAN_DECISION("booleanDecision"),
RADIO_BOX("radiobox"),
INTERNAL_DMP_ENTRIES("internalDmpEntities"),
CHECK_BOX("checkBox"),
FREE_TEXT("freetext"),
TEXT_AREA("textarea"),
DATE_PICKER("datePicker"),
EXTERNAL_DATASETS("externalDatasets"),
DATA_REPOSITORIES("dataRepositories"),
REGISTRIES("registries"),
SERVICES("services"),
TAGS("tags"),
RESEARCHERS("researchers"),
ORGANIZATIONS("organizations"),
DATASET_IDENTIFIER("datasetIdentifier"),
CURRENCY("currency"),
VALIDATION("validation");
private final String name;
Type(String name) {
this.name = name;
}
public String getName() {
return name;
}
public static Type fromName(String name) {
for (Type type: Type.values()) {
if (name.equals(type.getName())) {
return type;
}
}
throw new IllegalArgumentException("View Style Type [" + name + "] is not valid");
}
}
} }

View File

@ -95,14 +95,14 @@ public class AutoCompleteData extends ComboBoxData<AutoCompleteData> {
this.autoCompleteSingleDataList.add(new AutoCompleteSingleData()); this.autoCompleteSingleDataList.add(new AutoCompleteSingleData());
this.mapFromXml(item, this.autoCompleteSingleDataList.get(0)); this.mapFromXml(item, this.autoCompleteSingleDataList.get(0));
} }
this.multiAutoComplete = Boolean.parseBoolean(item.getAttribute("multiAutoComplete")); this.multiAutoComplete = Boolean.parseBoolean(item.getAttribute("multiAutocomplete"));
return this; return this;
} }
private void mapFromXml(Element item, AutoCompleteSingleData singleData) { private void mapFromXml(Element item, AutoCompleteSingleData singleData) {
singleData.url = item.getAttribute("url"); singleData.url = item.getAttribute("url");
singleData.optionsRoot = item.getAttribute("optionsRoot"); singleData.optionsRoot = item.getAttribute("optionsRoot");
this.multiAutoComplete = Boolean.parseBoolean(item.getAttribute("multiAutoComplete")); this.multiAutoComplete = Boolean.parseBoolean(item.getAttribute("multiAutocomplete"));
if (item.getAttribute("autoCompleteType") == null || item.getAttribute("autoCompleteType").equals("") ) { if (item.getAttribute("autoCompleteType") == null || item.getAttribute("autoCompleteType").equals("") ) {
singleData.autocompleteType = AutocompleteType.UNCACHED.getValue(); singleData.autocompleteType = AutocompleteType.UNCACHED.getValue();
} else { } else {
@ -173,7 +173,7 @@ public class AutoCompleteData extends ComboBoxData<AutoCompleteData> {
dataMap.put("label", item != null ? item.getAttribute("label") : ""); dataMap.put("label", item != null ? item.getAttribute("label") : "");
//dataMap.put("url", item != null ? item.getAttribute("url") : ""); //dataMap.put("url", item != null ? item.getAttribute("url") : "");
dataMap.put("type", item != null ? item.getAttribute("type") : "autocomplete"); dataMap.put("type", item != null ? item.getAttribute("type") : "autocomplete");
dataMap.put("multiAutoComplete", item != null ? Boolean.valueOf(item.getAttribute("multiAutoComplete")) : false); dataMap.put("multiAutoComplete", item != null ? Boolean.valueOf(item.getAttribute("multiAutocomplete")) : false);
List<Map<String, Object>> autoCompletes = new ArrayList<>(); List<Map<String, Object>> autoCompletes = new ArrayList<>();
NodeList autoCompleteSingles = item.getChildNodes(); NodeList autoCompleteSingles = item.getChildNodes();
for (int i = 0; i < autoCompleteSingles.getLength(); i++) { for (int i = 0; i < autoCompleteSingles.getLength(); i++) {

View File

@ -53,6 +53,7 @@ public class DMPsAutoCompleteData extends InternalDmpEntitiesData<DMPsAutoComple
HashMap dataMap = new HashMap(); HashMap dataMap = new HashMap();
dataMap.put("label", item != null ? item.getAttribute("label") : ""); dataMap.put("label", item != null ? item.getAttribute("label") : "");
dataMap.put("type", item != null ? item.getAttribute("type") : "dmps"); dataMap.put("type", item != null ? item.getAttribute("type") : "dmps");
dataMap.put("multiAutoComplete", item != null ? Boolean.parseBoolean(item.getAttribute("multiAutocomplete")) : false);
return dataMap; return dataMap;
} }

View File

@ -7,10 +7,21 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class DataRepositoriesData extends FieldData<DataRepositoriesData> { public class DataRepositoriesData extends FieldData<DataRepositoriesData> {
private Boolean multiAutoComplete;
public Boolean getMultiAutoComplete() {
return multiAutoComplete;
}
public void setMultiAutoComplete(Boolean multiAutoComplete) {
this.multiAutoComplete = multiAutoComplete;
}
@Override @Override
public DataRepositoriesData fromData(Object data) { public DataRepositoriesData fromData(Object data) {
if (data != null) { if (data != null) {
this.setLabel((String) ((Map<String, Object>) data).get("label")); this.setLabel((String) ((Map<String, Object>) data).get("label"));
this.setMultiAutoComplete(((Map<String, Object>) data).get("multiAutoComplete") != null && !((Map<String, Object>) data).get("multiAutoComplete").toString().isEmpty()? Boolean.parseBoolean(((Map<String, Object>) data).get("multiAutoComplete").toString()) : false);
} }
return this; return this;
} }
@ -24,19 +35,24 @@ public class DataRepositoriesData extends FieldData<DataRepositoriesData> {
public Element toXml(Document doc) { public Element toXml(Document doc) {
Element root = doc.createElement("data"); Element root = doc.createElement("data");
root.setAttribute("label", this.getLabel()); root.setAttribute("label", this.getLabel());
if (this.getMultiAutoComplete() != null) {
root.setAttribute("multiAutoComplete", this.getMultiAutoComplete().toString());
}
return root; return root;
} }
@Override @Override
public DataRepositoriesData fromXml(Element item) { public DataRepositoriesData fromXml(Element item) {
this.setLabel(item != null ? item.getAttribute("label") : ""); this.setLabel(item != null ? item.getAttribute("label") : "");
this.setMultiAutoComplete(Boolean.parseBoolean(item.getAttribute("multiAutoComplete")));
return this; return this;
} }
@Override @Override
public Map<String, Object> toMap(Element item) { public Map<String, Object> toMap(Element item) {
HashMap dataMap = new HashMap(); HashMap dataMap = new HashMap();
dataMap.put("label", item != null ? item.getAttribute("label") : ""); dataMap.put("label", item != null && item.getAttributes().getLength() > 0? item.getAttribute("label") : "");
dataMap.put("multiAutoComplete", item != null && item.getAttributes().getLength() > 0 ? item.getAttribute("multiAutocomplete") : false);
return dataMap; return dataMap;
} }
} }

View File

@ -53,6 +53,7 @@ public class DatasetsAutoCompleteData extends InternalDmpEntitiesData<DatasetsAu
HashMap dataMap = new HashMap(); HashMap dataMap = new HashMap();
dataMap.put("label", item != null ? item.getAttribute("label") : ""); dataMap.put("label", item != null ? item.getAttribute("label") : "");
dataMap.put("type", item != null ? item.getAttribute("type") : "datasets"); dataMap.put("type", item != null ? item.getAttribute("type") : "datasets");
dataMap.put("multiAutoComplete", item != null ? Boolean.parseBoolean(item.getAttribute("multiAutocomplete")) : false);
return dataMap; return dataMap;
} }

View File

@ -7,10 +7,21 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class ExternalDatasetsData extends FieldData<ExternalDatasetsData> { public class ExternalDatasetsData extends FieldData<ExternalDatasetsData> {
private Boolean multiAutoComplete;
public Boolean getMultiAutoComplete() {
return multiAutoComplete;
}
public void setMultiAutoComplete(Boolean multiAutoComplete) {
this.multiAutoComplete = multiAutoComplete;
}
@Override @Override
public ExternalDatasetsData fromData(Object data) { public ExternalDatasetsData fromData(Object data) {
if (data != null) { if (data != null) {
this.setLabel((String) ((Map<String, Object>) data).get("label")); this.setLabel((String) ((Map<String, Object>) data).get("label"));
this.setMultiAutoComplete(((Map<String, Object>) data).get("multiAutoComplete") != null && !((Map<String, Object>) data).get("multiAutoComplete").toString().isEmpty()? Boolean.parseBoolean( ((Map<String, Object>) data).get("multiAutoComplete").toString()) : false);
} }
return this; return this;
} }
@ -24,19 +35,24 @@ public class ExternalDatasetsData extends FieldData<ExternalDatasetsData> {
public Element toXml(Document doc) { public Element toXml(Document doc) {
Element root = doc.createElement("data"); Element root = doc.createElement("data");
root.setAttribute("label", this.getLabel()); root.setAttribute("label", this.getLabel());
if (this.getMultiAutoComplete() != null) {
root.setAttribute("multiAutoComplete", this.getMultiAutoComplete().toString());
}
return root; return root;
} }
@Override @Override
public ExternalDatasetsData fromXml(Element item) { public ExternalDatasetsData fromXml(Element item) {
this.setLabel(item != null ? item.getAttribute("label") : ""); this.setLabel(item != null ? item.getAttribute("label") : "");
this.setMultiAutoComplete(Boolean.parseBoolean(item.getAttribute("multiAutoComplete")));
return this; return this;
} }
@Override @Override
public Map<String, Object> toMap(Element item) { public Map<String, Object> toMap(Element item) {
HashMap dataMap = new HashMap(); HashMap dataMap = new HashMap();
dataMap.put("label", item != null ? item.getAttribute("label") : ""); dataMap.put("label", item != null && item.getAttributes().getLength() > 0? item.getAttribute("label") : "");
dataMap.put("multiAutoComplete", item != null && item.getAttributes().getLength() > 0? Boolean.parseBoolean(item.getAttribute("multiAutocomplete")) : false);
return dataMap; return dataMap;
} }
} }

View File

@ -7,10 +7,21 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class OrganizationsData extends FieldData<OrganizationsData> { public class OrganizationsData extends FieldData<OrganizationsData> {
private Boolean multiAutoComplete;
public Boolean getMultiAutoComplete() {
return multiAutoComplete;
}
public void setMultiAutoComplete(Boolean multiAutoComplete) {
this.multiAutoComplete = multiAutoComplete;
}
@Override @Override
public OrganizationsData fromData(Object data) { public OrganizationsData fromData(Object data) {
if (data != null) { if (data != null) {
this.setLabel((String) ((Map<String, Object>) data).get("label")); this.setLabel((String) ((Map<String, Object>) data).get("label"));
this.setMultiAutoComplete(((Map<String, Object>) data).get("multiAutoComplete") != null && !((Map<String, Object>) data).get("multiAutoComplete").toString().isEmpty()? Boolean.parseBoolean( ((Map<String, Object>) data).get("multiAutoComplete").toString()) : false);
} }
return this; return this;
} }
@ -24,19 +35,24 @@ public class OrganizationsData extends FieldData<OrganizationsData> {
public Element toXml(Document doc) { public Element toXml(Document doc) {
Element root = doc.createElement("data"); Element root = doc.createElement("data");
root.setAttribute("label", this.getLabel()); root.setAttribute("label", this.getLabel());
if (this.getMultiAutoComplete() != null) {
root.setAttribute("multiAutoComplete", this.getMultiAutoComplete().toString());
}
return root; return root;
} }
@Override @Override
public OrganizationsData fromXml(Element item) { public OrganizationsData fromXml(Element item) {
this.setLabel(item != null ? item.getAttribute("label") : ""); this.setLabel(item != null ? item.getAttribute("label") : "");
this.setMultiAutoComplete(Boolean.parseBoolean(item.getAttribute("multiAutoComplete")));
return this; return this;
} }
@Override @Override
public Map<String, Object> toMap(Element item) { public Map<String, Object> toMap(Element item) {
HashMap dataMap = new HashMap(); HashMap dataMap = new HashMap();
dataMap.put("label", item != null ? item.getAttribute("label") : ""); dataMap.put("label", item != null && item.getAttributes().getLength() > 0? item.getAttribute("label") : "");
dataMap.put("multiAutoComplete", item != null && item.getAttributes().getLength() > 0? Boolean.parseBoolean(item.getAttribute("multiAutocomplete")) : false);
return dataMap; return dataMap;
} }
} }

View File

@ -118,7 +118,28 @@ public class RadioBoxData extends FieldData<RadioBoxData> {
public Map<String, Object> toMap(Element item) { public Map<String, Object> toMap(Element item) {
HashMap dataMap = new HashMap(); HashMap dataMap = new HashMap();
dataMap.put("label", item != null ? item.getAttribute("label") : ""); dataMap.put("label", item != null ? item.getAttribute("label") : "");
dataMap.put("options", item != null ? item.getAttribute("options") : ""); Element optionsElement = (Element) item.getElementsByTagName("options").item(0);
List<Map<String,String>> option =new LinkedList<>();
if (optionsElement != null) {
NodeList optionElements = optionsElement.getChildNodes();
for (int temp = 0; temp < optionElements.getLength(); temp++) {
Node optionElement = optionElements.item(temp);
if (optionElement.getNodeType() == Node.ELEMENT_NODE) {
option.add(optionToMap((Element) optionElement));
}
}
}
dataMap.put("options", option != null ? option : null);
return dataMap;
}
private Map<String, String> optionToMap(Element item){
HashMap dataMap = new HashMap();
dataMap.put("label",item.getAttribute("label"));
dataMap.put("value",item.getAttribute("value"));
return dataMap; return dataMap;
} }
} }

View File

@ -7,10 +7,21 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class RegistriesData extends FieldData<RegistriesData> { public class RegistriesData extends FieldData<RegistriesData> {
private Boolean multiAutoComplete;
public Boolean getMultiAutoComplete() {
return multiAutoComplete;
}
public void setMultiAutoComplete(Boolean multiAutoComplete) {
this.multiAutoComplete = multiAutoComplete;
}
@Override @Override
public RegistriesData fromData(Object data) { public RegistriesData fromData(Object data) {
if (data != null) { if (data != null) {
this.setLabel((String) ((Map<String, Object>) data).get("label")); this.setLabel((String) ((Map<String, Object>) data).get("label"));
this.setMultiAutoComplete(((Map<String, Object>) data).get("multiAutoComplete") != null && !((Map<String, Object>) data).get("multiAutoComplete").toString().isEmpty()?Boolean.parseBoolean( ((Map<String, Object>) data).get("multiAutoComplete").toString()): false);
} }
return this; return this;
} }
@ -24,19 +35,24 @@ public class RegistriesData extends FieldData<RegistriesData> {
public Element toXml(Document doc) { public Element toXml(Document doc) {
Element root = doc.createElement("data"); Element root = doc.createElement("data");
root.setAttribute("label", this.getLabel()); root.setAttribute("label", this.getLabel());
if (this.getMultiAutoComplete() != null) {
root.setAttribute("multiAutoComplete", this.getMultiAutoComplete().toString());
}
return root; return root;
} }
@Override @Override
public RegistriesData fromXml(Element item) { public RegistriesData fromXml(Element item) {
this.setLabel(item != null ? item.getAttribute("label") : ""); this.setLabel(item != null ? item.getAttribute("label") : "");
this.setMultiAutoComplete(Boolean.parseBoolean(item.getAttribute("multiAutoComplete")));
return this; return this;
} }
@Override @Override
public Map<String, Object> toMap(Element item) { public Map<String, Object> toMap(Element item) {
HashMap dataMap = new HashMap(); HashMap dataMap = new HashMap();
dataMap.put("label", item != null ? item.getAttribute("label") : ""); dataMap.put("label", item != null && item.getAttributes().getLength() > 0? item.getAttribute("label") : "");
dataMap.put("multiAutoComplete", item != null && item.getAttributes().getLength() > 0? Boolean.parseBoolean(item.getAttribute("multiAutocomplete")) : false);
return dataMap; return dataMap;
} }
} }

View File

@ -7,10 +7,21 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class ResearcherData extends FieldData<ResearcherData> { public class ResearcherData extends FieldData<ResearcherData> {
private Boolean multiAutoComplete;
public Boolean getMultiAutoComplete() {
return multiAutoComplete;
}
public void setMultiAutoComplete(Boolean multiAutoComplete) {
this.multiAutoComplete = multiAutoComplete;
}
@Override @Override
public ResearcherData fromData(Object data) { public ResearcherData fromData(Object data) {
if (data != null) { if (data != null) {
this.setLabel((String) ((Map<String, Object>) data).get("label")); this.setLabel((String) ((Map<String, Object>) data).get("label"));
this.setMultiAutoComplete(((Map<String, Object>) data).get("multiAutoComplete") != null && !((Map<String, Object>) data).get("multiAutoComplete").toString().isEmpty()? Boolean.parseBoolean( ((Map<String, Object>) data).get("multiAutoComplete").toString()) : false);
} }
return this; return this;
} }
@ -24,19 +35,24 @@ public class ResearcherData extends FieldData<ResearcherData> {
public Element toXml(Document doc) { public Element toXml(Document doc) {
Element root = doc.createElement("data"); Element root = doc.createElement("data");
root.setAttribute("label", this.getLabel()); root.setAttribute("label", this.getLabel());
if (this.getMultiAutoComplete() != null) {
root.setAttribute("multiAutoComplete", this.getMultiAutoComplete().toString());
}
return root; return root;
} }
@Override @Override
public ResearcherData fromXml(Element item) { public ResearcherData fromXml(Element item) {
this.setLabel(item != null ? item.getAttribute("label") : ""); this.setLabel(item != null ? item.getAttribute("label") : "");
this.setMultiAutoComplete(Boolean.parseBoolean(item.getAttribute("multiAutoComplete")));
return this; return this;
} }
@Override @Override
public Map<String, Object> toMap(Element item) { public Map<String, Object> toMap(Element item) {
HashMap dataMap = new HashMap(); HashMap dataMap = new HashMap();
dataMap.put("label", item != null ? item.getAttribute("label") : ""); dataMap.put("label", item != null && item.getAttributes().getLength() > 0 ? item.getAttribute("label") : "");
dataMap.put("multiAutoComplete", item != null && item.getAttributes().getLength() > 0 ? Boolean.parseBoolean(item.getAttribute("multiAutocomplete")) : false);
return dataMap; return dataMap;
} }
} }

View File

@ -19,7 +19,7 @@ public class ResearchersAutoCompleteData extends InternalDmpEntitiesData<Researc
@Override @Override
public Element toXml(Document doc) { public Element toXml(Document doc) {
Element root = super.toXml(doc); Element root = super.toXml(doc);
root.setAttribute("multiAutoComplete", this.multiAutoComplete.toString()); root.setAttribute("multiAutoComplete", this.multiAutoComplete != null ? this.multiAutoComplete.toString() : "false");
return root; return root;
} }
@ -36,7 +36,7 @@ public class ResearchersAutoCompleteData extends InternalDmpEntitiesData<Researc
public ResearchersAutoCompleteData fromData(Object data) { public ResearchersAutoCompleteData fromData(Object data) {
super.fromData(data); super.fromData(data);
if (data != null) { if (data != null) {
this.multiAutoComplete = (Boolean) ((Map<Boolean, Object>) data).get("multiAutoComplete"); this.multiAutoComplete = Boolean.parseBoolean(((Map<Boolean, Object>) data).get("multiAutoComplete").toString());
} }
return this; return this;
@ -53,7 +53,7 @@ public class ResearchersAutoCompleteData extends InternalDmpEntitiesData<Researc
HashMap dataMap = new HashMap(); HashMap dataMap = new HashMap();
dataMap.put("label", item != null ? item.getAttribute("label") : ""); dataMap.put("label", item != null ? item.getAttribute("label") : "");
dataMap.put("type", item != null ? item.getAttribute("type") : "researchers"); dataMap.put("type", item != null ? item.getAttribute("type") : "researchers");
dataMap.put("multiAutoComplete", item != null ? Boolean.parseBoolean(item.getAttribute("multiAutocomplete")) : false);
return dataMap; return dataMap;
} }
} }

View File

@ -7,10 +7,21 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class ServicesData extends FieldData<ServicesData> { public class ServicesData extends FieldData<ServicesData> {
private Boolean multiAutoComplete;
public Boolean getMultiAutoComplete() {
return multiAutoComplete;
}
public void setMultiAutoComplete(Boolean multiAutoComplete) {
this.multiAutoComplete = multiAutoComplete;
}
@Override @Override
public ServicesData fromData(Object data) { public ServicesData fromData(Object data) {
if (data != null) { if (data != null) {
this.setLabel((String) ((Map<String, Object>) data).get("label")); this.setLabel((String) ((Map<String, Object>) data).get("label"));
this.setMultiAutoComplete(((Map<String, Object>) data).get("multiAutoComplete") != null && !((Map<String, Object>) data).get("multiAutoComplete").toString().isEmpty()? Boolean.parseBoolean( ((Map<String, Object>) data).get("multiAutoComplete").toString()) : false);
} }
return this; return this;
} }
@ -24,19 +35,24 @@ public class ServicesData extends FieldData<ServicesData> {
public Element toXml(Document doc) { public Element toXml(Document doc) {
Element root = doc.createElement("data"); Element root = doc.createElement("data");
root.setAttribute("label", this.getLabel()); root.setAttribute("label", this.getLabel());
if (this.getMultiAutoComplete() != null) {
root.setAttribute("multiAutoComplete", this.getMultiAutoComplete().toString());
}
return root; return root;
} }
@Override @Override
public ServicesData fromXml(Element item) { public ServicesData fromXml(Element item) {
this.setLabel(item != null ? item.getAttribute("label") : ""); this.setLabel(item != null ? item.getAttribute("label") : "");
this.setMultiAutoComplete(Boolean.parseBoolean(item.getAttribute("multiAutoComplete")));
return this; return this;
} }
@Override @Override
public Map<String, Object> toMap(Element item) { public Map<String, Object> toMap(Element item) {
HashMap dataMap = new HashMap(); HashMap dataMap = new HashMap();
dataMap.put("label", item != null ? item.getAttribute("label") : ""); dataMap.put("label", item != null && item.getAttributes().getLength() > 0? item.getAttribute("label") : "");
dataMap.put("multiAutoComplete", item != null && item.getAttributes().getLength() > 0? Boolean.parseBoolean(item.getAttribute("multiAutocomplete")) : false);
return dataMap; return dataMap;
} }
} }

View File

@ -0,0 +1,42 @@
package eu.eudat.models.data.components.commons.datafield;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import java.util.HashMap;
import java.util.Map;
public class ValidationData extends FieldData<ValidationData> {
@Override
public ValidationData fromData(Object data) {
if (data != null) {
this.setLabel((String) ((Map<String, Object>) data).get("label"));
}
return this;
}
@Override
public Object toData() {
return null;
}
@Override
public Element toXml(Document doc) {
Element root = doc.createElement("data");
root.setAttribute("label", this.getLabel());
return root;
}
@Override
public ValidationData fromXml(Element item) {
this.setLabel(item != null ? item.getAttribute("label") : "");
return this;
}
@Override
public Map<String, Object> toMap(Element item) {
HashMap dataMap = new HashMap();
dataMap.put("label", item != null ? item.getAttribute("label") : "");
return dataMap;
}
}

View File

@ -79,7 +79,7 @@ public class WordListData extends ComboBoxData<WordListData> {
} }
} }
Object multiList1 = ((Map<String, Object>) data).get("multiList"); Object multiList1 = ((Map<String, Object>) data).get("multiList");
this.multiList = multiList1 instanceof String ? Boolean.parseBoolean((String) multiList1) : (Boolean) multiList1; this.multiList = multiList1 != null && (multiList1 instanceof String ? Boolean.parseBoolean((String) multiList1) : (Boolean) multiList1);
} }
return this; return this;
} }

View File

@ -295,7 +295,7 @@ public class DataManagementPlanEditorModel implements DataModel<DMP, DataManagem
grant.setAbbreviation(""); grant.setAbbreviation("");
grant.setLabel(this.grant.getLabel()); grant.setLabel(this.grant.getLabel());
grant.setType(Grant.GrantType.INTERNAL.getValue()); grant.setType(Grant.GrantType.INTERNAL.getValue());
grant.setReference("dmp:" + grant.getId()); grant.setReference("dmp:" + (this.grant.getReference() != null ? this.grant.getReference() : grant.getId()));
grant.setUri(""); grant.setUri("");
grant.setDefinition(""); grant.setDefinition("");
grant.setCreated(new Date()); grant.setCreated(new Date());
@ -319,7 +319,7 @@ public class DataManagementPlanEditorModel implements DataModel<DMP, DataManagem
funder.setId(UUID.randomUUID()); funder.setId(UUID.randomUUID());
funder.setLabel(this.funder.getLabel()); funder.setLabel(this.funder.getLabel());
funder.setType(Funder.FunderType.INTERNAL.getValue()); funder.setType(Funder.FunderType.INTERNAL.getValue());
funder.setReference("dmp:" + funder.getId()); funder.setReference("dmp:" + (this.funder.getReference() != null ? this.funder.getReference() : funder.getId()));
funder.setDefinition(""); funder.setDefinition("");
funder.setCreated(new Date()); funder.setCreated(new Date());
funder.setStatus(Funder.Status.ACTIVE.getValue()); funder.setStatus(Funder.Status.ACTIVE.getValue());
@ -341,7 +341,7 @@ public class DataManagementPlanEditorModel implements DataModel<DMP, DataManagem
project.setAbbreviation(""); project.setAbbreviation("");
project.setLabel(this.project.getLabel()); project.setLabel(this.project.getLabel());
project.setType(Project.ProjectType.INTERNAL.getValue()); project.setType(Project.ProjectType.INTERNAL.getValue());
project.setReference("dmp:" + project.getId()); project.setReference("dmp:" + (this.project.getReference() != null ? this.project.getReference() : project.getId()));
project.setUri(""); project.setUri("");
project.setDefinition(""); project.setDefinition("");
project.setCreated(new Date()); project.setCreated(new Date());

View File

@ -196,7 +196,7 @@ public class DataManagementPlanNewVersionModel implements DataModel<DMP, DataMan
grant.setAbbreviation(""); grant.setAbbreviation("");
grant.setLabel(this.grant.getLabel()); grant.setLabel(this.grant.getLabel());
grant.setType(eu.eudat.data.entities.Grant.GrantType.INTERNAL.getValue()); grant.setType(eu.eudat.data.entities.Grant.GrantType.INTERNAL.getValue());
grant.setReference("dmp:" + grant.getId()); grant.setReference("dmp:" + (this.grant.getReference() != null ? this.grant.getReference() : grant.getId()));
grant.setUri(""); grant.setUri("");
grant.setDefinition(""); grant.setDefinition("");
grant.setCreated(new Date()); grant.setCreated(new Date());
@ -220,7 +220,7 @@ public class DataManagementPlanNewVersionModel implements DataModel<DMP, DataMan
funder.setId(UUID.randomUUID()); funder.setId(UUID.randomUUID());
funder.setLabel(this.funder.getLabel()); funder.setLabel(this.funder.getLabel());
funder.setType(Funder.FunderType.INTERNAL.getValue()); funder.setType(Funder.FunderType.INTERNAL.getValue());
funder.setReference("dmp:" + funder.getId()); funder.setReference("dmp:" + (this.funder.getReference() != null ? this.funder.getReference() : funder.getId()));
funder.setDefinition(""); funder.setDefinition("");
funder.setCreated(new Date()); funder.setCreated(new Date());
funder.setStatus(Funder.Status.ACTIVE.getValue()); funder.setStatus(Funder.Status.ACTIVE.getValue());
@ -242,7 +242,7 @@ public class DataManagementPlanNewVersionModel implements DataModel<DMP, DataMan
project.setAbbreviation(""); project.setAbbreviation("");
project.setLabel(this.project.getLabel()); project.setLabel(this.project.getLabel());
project.setType(Project.ProjectType.INTERNAL.getValue()); project.setType(Project.ProjectType.INTERNAL.getValue());
project.setReference("dmp:" + project.getId()); project.setReference("dmp:" + (this.project.getReference() != null ? this.project.getReference() : project.getId()));
project.setUri(""); project.setUri("");
project.setDefinition(""); project.setDefinition("");
project.setCreated(new Date()); project.setCreated(new Date());

View File

@ -4,6 +4,7 @@ import eu.eudat.models.DataModel;
import eu.eudat.logic.utilities.helpers.LabelGenerator; import eu.eudat.logic.utilities.helpers.LabelGenerator;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
public class Organisation implements DataModel<eu.eudat.data.entities.Organisation, Organisation>, LabelGenerator { public class Organisation implements DataModel<eu.eudat.data.entities.Organisation, Organisation>, LabelGenerator {
@ -80,7 +81,7 @@ public class Organisation implements DataModel<eu.eudat.data.entities.Organisati
public eu.eudat.data.entities.Organisation toDataModel() { public eu.eudat.data.entities.Organisation toDataModel() {
eu.eudat.data.entities.Organisation organisationEntity = new eu.eudat.data.entities.Organisation(); eu.eudat.data.entities.Organisation organisationEntity = new eu.eudat.data.entities.Organisation();
if (this.key != null && this.reference != null) { if (this.key != null && this.reference != null) {
if ((this.key + ":").equals(this.reference.substring(0, this.key.length() + 1))) { if (this.reference.startsWith(this.key + ":")) {
organisationEntity.setReference(this.reference); organisationEntity.setReference(this.reference);
} else { } else {
organisationEntity.setReference(this.key + ":" + this.reference); organisationEntity.setReference(this.key + ":" + this.reference);
@ -95,6 +96,20 @@ public class Organisation implements DataModel<eu.eudat.data.entities.Organisati
organisationEntity.setStatus((short) this.status); organisationEntity.setStatus((short) this.status);
return organisationEntity; return organisationEntity;
} }
public static Organisation fromMap(HashMap<String, Object> map) {
Organisation model = new Organisation();
if (map != null) {
model.id = (String) map.get("id");
model.key = (String) map.get("key");
model.label = (String) map.get("label");
model.name = (String) map.get("name");
model.reference = (String) map.get("reference");
model.status = (int) map.get("status");
model.tag = (String) map.get("tag");
}
return model;
}
@Override @Override
public String generateLabel() { public String generateLabel() {

Some files were not shown because too many files have changed in this diff Show More