Merge branch 'Development'

This commit is contained in:
Diamantis Tziotzios 2020-01-31 18:26:27 +02:00
commit 1b4952a909
439 changed files with 8116 additions and 3512 deletions

View File

@ -1,5 +1,7 @@
package eu.eudat.data.converters; package eu.eudat.data.converters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.format.datetime.DateFormatter; import org.springframework.format.datetime.DateFormatter;
import javax.persistence.AttributeConverter; import javax.persistence.AttributeConverter;
@ -15,6 +17,7 @@ import java.util.TimeZone;
*/ */
@Converter @Converter
public class DateToUTCConverter implements AttributeConverter<Date, Date> { public class DateToUTCConverter implements AttributeConverter<Date, Date> {
private static final Logger logger = LoggerFactory.getLogger(DateToUTCConverter.class);
@Override @Override
public Date convertToDatabaseColumn(Date attribute) { public Date convertToDatabaseColumn(Date attribute) {
@ -25,7 +28,7 @@ public class DateToUTCConverter implements AttributeConverter<Date, Date> {
String date = formatterIST.format(attribute); String date = formatterIST.format(attribute);
return formatterIST.parse(date); return formatterIST.parse(date);
} catch (ParseException e) { } catch (ParseException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return null; return null;
} }
@ -39,7 +42,7 @@ public class DateToUTCConverter implements AttributeConverter<Date, Date> {
String date = formatterIST.format(dbData); String date = formatterIST.format(dbData);
return formatterIST.parse(date); return formatterIST.parse(date);
} catch (ParseException e) { } catch (ParseException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return null; return null;
} }

View File

@ -12,6 +12,8 @@ public class DataManagementPlanPublicCriteria extends Criteria<DMP> {
public List<UUID> datasetProfile; public List<UUID> datasetProfile;
private List<String> dmpOrganisations; private List<String> dmpOrganisations;
private Integer role; private Integer role;
private boolean allVersions;
private List<UUID> groupIds;
public GrantStateType getGrantStatus() { public GrantStateType getGrantStatus() {
return grantStatus; return grantStatus;
@ -47,4 +49,18 @@ public class DataManagementPlanPublicCriteria extends Criteria<DMP> {
public void setRole(Integer role) { public void setRole(Integer role) {
this.role = role; this.role = role;
} }
public boolean getAllVersions() {
return allVersions;
}
public void setAllVersions(boolean allVersions) {
this.allVersions = allVersions;
}
public List<UUID> getGroupIds() {
return groupIds;
}
public void setGroupIds(List<UUID> groupIds) {
this.groupIds = groupIds;
}
} }

View File

@ -21,6 +21,7 @@ public class DatasetCriteria extends Criteria<Dataset> {
private List<UUID> grants; private List<UUID> grants;
private List<UUID> collaborators; private List<UUID> collaborators;
private List<UUID> datasetTemplates; private List<UUID> datasetTemplates;
private List<UUID> groupIds;
public boolean getAllVersions() { public boolean getAllVersions() {
return allVersions; return allVersions;
@ -105,4 +106,11 @@ public class DatasetCriteria extends Criteria<Dataset> {
public void setDatasetTemplates(List<UUID> datasetTemplates) { public void setDatasetTemplates(List<UUID> datasetTemplates) {
this.datasetTemplates = datasetTemplates; this.datasetTemplates = datasetTemplates;
} }
public List<UUID> getGroupIds() {
return groupIds;
}
public void setGroupIds(List<UUID> groupIds) {
this.groupIds = groupIds;
}
} }

View File

@ -32,6 +32,7 @@ public class DatasetProfileCriteria extends Criteria<DatasetProfile> {
private List<UUID> groupIds; private List<UUID> groupIds;
private Short filter; private Short filter;
private UUID userId; private UUID userId;
private boolean finalized;
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; }
@ -52,4 +53,11 @@ public class DatasetProfileCriteria extends Criteria<DatasetProfile> {
public void setUserId(UUID userId) { public void setUserId(UUID userId) {
this.userId = userId; this.userId = userId;
} }
public boolean getFinalized() {
return finalized;
}
public void setFinalized(boolean finalized) {
this.finalized = finalized;
}
} }

View File

@ -6,13 +6,14 @@ import eu.eudat.data.entities.Dataset;
import eu.eudat.data.entities.UserInfo; import eu.eudat.data.entities.UserInfo;
import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.QueryableList;
import java.util.List;
import java.util.UUID; import java.util.UUID;
public interface DatasetDao extends DatabaseAccessLayer<Dataset, UUID> { public interface DatasetDao extends DatabaseAccessLayer<Dataset, UUID> {
QueryableList<Dataset> getWithCriteria(DatasetCriteria criteria); QueryableList<Dataset> getWithCriteria(DatasetCriteria criteria);
QueryableList<Dataset> getAuthenticated(QueryableList<Dataset> query, UserInfo principal); QueryableList<Dataset> getAuthenticated(QueryableList<Dataset> query, UserInfo principal, List<Integer> roles);
Dataset isPublicDataset(UUID id); Dataset isPublicDataset(UUID id);

View File

@ -13,8 +13,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;
@ -41,13 +43,15 @@ public class DatasetDaoImpl extends DatabaseAccess<Dataset> implements DatasetDa
query.where((builder, root) -> builder.greaterThan(root.get("created"), criteria.getPeriodStart())); query.where((builder, root) -> builder.greaterThan(root.get("created"), criteria.getPeriodStart()));
if (!criteria.getAllVersions()) if (!criteria.getAllVersions())
query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("dmp").get("version"), query.<String>subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.equal(externalRoot.get("dmp").get("groupId"), nestedRoot.get("dmp").get("groupId")), Arrays.asList(new SelectionField(FieldSelectionType.COMPOSITE_FIELD, "dmp:version")), String.class))); query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("dmp").get("version"), query.<String>subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.equal(externalRoot.get("dmp").get("groupId"), nestedRoot.get("dmp").get("groupId")), Arrays.asList(new SelectionField(FieldSelectionType.COMPOSITE_FIELD, "dmp:version")), String.class)));
if (criteria.getGroupIds() != null && !criteria.getGroupIds().isEmpty())
query.where((builder, root) -> root.get("dmp").get("groupId").in(criteria.getGroupIds()));
if (criteria.getDmpIds() != null && !criteria.getDmpIds().isEmpty()) if (criteria.getDmpIds() != null && !criteria.getDmpIds().isEmpty())
query.where((builder, root) -> root.get("dmp").get("id").in(criteria.getDmpIds())); query.where((builder, root) -> root.get("dmp").get("id").in(criteria.getDmpIds()));
if (criteria.getRole() != null) { /*if (criteria.getRole() != null) {
query.where((builder, root) -> builder.equal(root.join("dmp").join("users").get("role"), criteria.getRole())); query.where((builder, root) -> builder.equal(root.join("dmp").join("users").get("role"), criteria.getRole()));
} else { } else {
query.where((builder, root) -> root.join("dmp").join("users").get("role").in(UserDMP.UserDMPRoles.getAllValues())); query.where((builder, root) -> root.join("dmp").join("users").get("role").in(UserDMP.UserDMPRoles.getAllValues()));
} }*/
if (criteria.getOrganisations() != null && !criteria.getOrganisations().isEmpty()) if (criteria.getOrganisations() != null && !criteria.getOrganisations().isEmpty())
query.where((builder, root) -> root.join("dmp").join("organisations").get("reference").in(criteria.getOrganisations())); query.where((builder, root) -> root.join("dmp").join("organisations").get("reference").in(criteria.getOrganisations()));
if (criteria.getGrants() != null && !criteria.getGrants().isEmpty()) if (criteria.getGrants() != null && !criteria.getGrants().isEmpty())
@ -87,9 +91,13 @@ public class DatasetDaoImpl extends DatabaseAccess<Dataset> implements DatasetDa
} }
@Override @Override
public QueryableList<Dataset> getAuthenticated(QueryableList<Dataset> query, UserInfo principal) { public QueryableList<Dataset> getAuthenticated(QueryableList<Dataset> query, UserInfo principal, List<Integer> roles) {
if (principal.getId() == null) query.where((builder, root) -> builder.equal(root.get("isPublic"), true)); if (roles != null && !roles.isEmpty()) {
else { query.where((builder, root) -> {
Join userJoin = root.join("dmp", JoinType.LEFT).join("users", JoinType.LEFT);
return builder.and(builder.equal(userJoin.join("user", JoinType.LEFT).get("id"), principal.getId()), userJoin.get("role").in(roles));
});
} else {
query.where((builder, root) -> builder.equal(root.join("dmp", JoinType.LEFT).join("users", JoinType.LEFT).join("user", JoinType.LEFT).get("id"), principal.getId())); query.where((builder, root) -> builder.equal(root.join("dmp", JoinType.LEFT).join("users", JoinType.LEFT).join("user", JoinType.LEFT).get("id"), principal.getId()));
} }
return query; return query;

View File

@ -52,7 +52,11 @@ public class DatasetProfileDaoImpl extends DatabaseAccess<DatasetProfile> implem
builder.notEqual(root.get("id"), criteria.getUserId()))); builder.notEqual(root.get("id"), criteria.getUserId())));
} }
} }
query.where(((builder, root) -> builder.notEqual(root.get("status"), DatasetProfile.Status.DELETED.getValue()))); if (criteria.getFinalized()) {
query.where(((builder, root) -> builder.equal(root.get("status"), DatasetProfile.Status.FINALIZED.getValue())));
} else {
query.where(((builder, root) -> builder.notEqual(root.get("status"), DatasetProfile.Status.DELETED.getValue())));
}
return query; return query;
} }

View File

@ -53,7 +53,7 @@ public class GrantDaoImpl extends DatabaseAccess<Grant> implements GrantDao {
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())
query.where((builder, root) -> builder.equal(root.join("funder", JoinType.LEFT).get("reference"), criteria.getFunderReference())); query.where((builder, root) -> builder.or(builder.like(root.join("funder", JoinType.LEFT).get("reference"), "%" + criteria.getFunderReference())));
query.where((builder, root) -> builder.notEqual(root.get("status"), Grant.Status.DELETED.getValue())); query.where((builder, root) -> builder.notEqual(root.get("status"), Grant.Status.DELETED.getValue()));
return query; return query;
} }

View File

@ -281,20 +281,41 @@ public class Dataset implements DataEntity<Dataset, UUID> {
this.setLabel(entity.getLabel()); this.setLabel(entity.getLabel());
this.setProperties(entity.getProperties()); this.setProperties(entity.getProperties());
this.getDatasetDataRepositories().removeAll(this.getDatasetDataRepositories()); if (entity.getDatasetDataRepositories() == null || entity.getDatasetDataRepositories().size() < 1) {
if (entity.getDatasetDataRepositories() != null) if (this.getDatasetDataRepositories() != null) this.getDatasetDataRepositories().removeAll(this.getDatasetDataRepositories());
this.getDatasetDataRepositories().addAll(entity.getDatasetDataRepositories()); } else {
if (this.getDatasetDataRepositories() != null) {
this.getDatasetDataRepositories().removeAll(this.getDatasetDataRepositories());
} else {
this.setDatasetDataRepositories(new HashSet<>());
}
this.getDatasetDataRepositories().addAll(entity.getDatasetDataRepositories().stream().peek(item -> item.setDataset(this)).collect(Collectors.toList()));
}
this.getDatasetExternalDatasets().removeAll(this.getDatasetExternalDatasets()); if (entity.getDatasetExternalDatasets() == null || entity.getDatasetExternalDatasets().size() < 1) {
if (entity.getDatasetExternalDatasets() != null) if (this.getDatasetExternalDatasets() != null) this.getDatasetExternalDatasets().removeAll(this.getDatasetExternalDatasets());
this.getDatasetExternalDatasets().addAll(entity.getDatasetExternalDatasets()); } else {
if (this.getDatasetExternalDatasets() != null) {
this.getDatasetExternalDatasets().removeAll(this.getDatasetExternalDatasets());
} else {
this.setDatasetExternalDatasets(new HashSet<>());
}
this.getDatasetExternalDatasets().addAll(entity.getDatasetExternalDatasets().stream().peek(item -> item.setDataset(this)).collect(Collectors.toList()));
}
if (entity.getServices() == null || entity.getServices().size() < 1) {
if (this.getServices() != null) this.getServices().removeAll(this.getServices());
} else {
if (this.getServices() != null) {
this.getServices().removeAll(this.getServices());
} else {
this.setServices(new HashSet<>());
}
this.getServices().addAll(entity.getServices().stream().peek(item -> item.setDataset(this)).collect(Collectors.toList()));
}
this.setRegistries(entity.getRegistries()); this.setRegistries(entity.getRegistries());
this.getServices().removeAll(this.getServices());
if (entity.getServices() != null)
this.getServices().addAll(entity.getServices());
this.setDmp(entity.getDmp()); this.setDmp(entity.getDmp());
this.setStatus(entity.getStatus()); this.setStatus(entity.getStatus());
this.setProfile(entity.getProfile()); this.setProfile(entity.getProfile());

View File

@ -66,8 +66,8 @@ public class Funder implements DataEntity<Funder, UUID> {
} }
@Id @Id
@GeneratedValue //@GeneratedValue
@GenericGenerator(name = "uuid2", strategy = "uuid2") //@GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id; private UUID id;

View File

@ -81,8 +81,8 @@ public class Grant implements DataEntity<Grant, UUID> {
} }
@Id @Id
@GeneratedValue //@GeneratedValue
@GenericGenerator(name = "uuid2", strategy = "uuid2") //@GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id; private UUID id;

View File

@ -67,8 +67,8 @@ public class Project implements DataEntity<Project, UUID> {
} }
@Id @Id
@GeneratedValue //@GeneratedValue
@GenericGenerator(name = "uuid2", strategy = "uuid2") //@GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id; private UUID id;

View File

@ -19,8 +19,8 @@ import java.util.UUID;
public class Researcher implements DataEntity<Researcher, UUID> { public class Researcher implements DataEntity<Researcher, UUID> {
@Id @Id
@GeneratedValue /*@GeneratedValue
@GenericGenerator(name = "uuid2", strategy = "uuid2") @GenericGenerator(name = "uuid2", strategy = "uuid2")*/
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id; private UUID id;

View File

@ -3,8 +3,11 @@ package eu.eudat.data.query.definition;
import eu.eudat.data.dao.criteria.Criteria; import eu.eudat.data.dao.criteria.Criteria;
import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.QueryableList;
import eu.eudat.queryable.queryableentity.DataEntity; import eu.eudat.queryable.queryableentity.DataEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class Query<C extends Criteria<T>, T extends DataEntity> implements CriteriaQuery<C, T> { public abstract class Query<C extends Criteria<T>, T extends DataEntity> implements CriteriaQuery<C, T> {
private static final Logger logger = LoggerFactory.getLogger(Query.class);
private C criteria; private C criteria;
private QueryableList<T> query; private QueryableList<T> query;
@ -33,10 +36,8 @@ public abstract class Query<C extends Criteria<T>, T extends DataEntity> impleme
q.setCriteria(criteria); q.setCriteria(criteria);
q.setQuery(query); q.setQuery(query);
return q; return q;
} catch (InstantiationException e) { } catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace(); logger.error (e.getMessage(), e);
} catch (IllegalAccessException e) {
e.printStackTrace();
} }
return null; return null;
} }

View File

@ -5,8 +5,11 @@ import eu.eudat.data.entities.DMP;
import eu.eudat.data.query.PaginationService; import eu.eudat.data.query.PaginationService;
import eu.eudat.data.query.definition.TableQuery; import eu.eudat.data.query.definition.TableQuery;
import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.QueryableList;
import eu.eudat.queryable.types.FieldSelectionType;
import eu.eudat.queryable.types.SelectionField;
import eu.eudat.types.grant.GrantStateType; import eu.eudat.types.grant.GrantStateType;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.UUID; import java.util.UUID;
@ -33,6 +36,14 @@ public class DataManagmentPlanPublicTableRequest extends TableQuery<DataManageme
query.where((builder, root) -> root.join("associatedDmps").get("id").in(this.getCriteria().datasetProfile)); query.where((builder, root) -> root.join("associatedDmps").get("id").in(this.getCriteria().datasetProfile));
if (this.getCriteria().getDmpOrganisations() != null && !this.getCriteria().getDmpOrganisations().isEmpty()) if (this.getCriteria().getDmpOrganisations() != null && !this.getCriteria().getDmpOrganisations().isEmpty())
query.where(((builder, root) -> root.join("organisations").get("reference").in(this.getCriteria().getDmpOrganisations()))); query.where(((builder, root) -> root.join("organisations").get("reference").in(this.getCriteria().getDmpOrganisations())));
if (!this.getCriteria().getAllVersions()) {
query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("version"),
query.<String>subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.and(builder1.equal(externalRoot.get("groupId"),
nestedRoot.get("groupId")), builder1.equal(nestedRoot.get("isPublic"), true)), Arrays.asList(new SelectionField(FieldSelectionType.FIELD, "version")), String.class)));
}
if (this.getCriteria().getGroupIds() != null && !this.getCriteria().getGroupIds().isEmpty()) {
query.where((builder, root) -> root.get("groupId").in(this.getCriteria().getGroupIds()));
}
return query; return query;
} }

View File

@ -1,6 +1,8 @@
package eu.eudat.elastic.entities; package eu.eudat.elastic.entities;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.util.LinkedList; import java.util.LinkedList;
@ -11,6 +13,7 @@ import java.util.Map;
* Created by ikalyvas on 7/5/2018. * Created by ikalyvas on 7/5/2018.
*/ */
public class Dataset implements ElasticEntity<Dataset> { public class Dataset implements ElasticEntity<Dataset> {
private static final Logger logger = LoggerFactory.getLogger(Dataset.class);
private String id; private String id;
private List<Tag> tags = new LinkedList<>(); private List<Tag> tags = new LinkedList<>();
@ -40,7 +43,7 @@ public class Dataset implements ElasticEntity<Dataset> {
try { try {
x.toElasticEntity(builder); x.toElasticEntity(builder);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
}); });
builder.endArray(); builder.endArray();

View File

@ -6,6 +6,8 @@ import eu.eudat.elastic.entities.ElasticEntity;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.client.RestClient; import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.client.RestHighLevelClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
@ -13,6 +15,7 @@ import java.io.IOException;
* Created by ikalyvas on 7/5/2018. * Created by ikalyvas on 7/5/2018.
*/ */
public abstract class ElasticRepository<T extends ElasticEntity,C extends Criteria> implements Repository<T,C> { public abstract class ElasticRepository<T extends ElasticEntity,C extends Criteria> implements Repository<T,C> {
private static final Logger logger = LoggerFactory.getLogger(ElasticRepository.class);
private RestHighLevelClient client; private RestHighLevelClient client;
public RestHighLevelClient getClient() { public RestHighLevelClient getClient() {
@ -29,7 +32,7 @@ public abstract class ElasticRepository<T extends ElasticEntity,C extends Criter
try { try {
item = mapper.readValue(value, tClass); item = mapper.readValue(value, tClass);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return item; return item;
} }

View File

@ -28,14 +28,14 @@ import java.util.Map;
* Created by ikalyvas on 5/30/2018. * Created by ikalyvas on 5/30/2018.
*/ */
@Service("logger") //@Service("logger")
public class HttpRemoteLogger extends AbstractBatchLogger implements Logger { public class HttpRemoteLogger extends AbstractBatchLogger implements Logger {
private RestTemplate rest; private RestTemplate rest;
private HttpHeaders headers; private HttpHeaders headers;
private Environment environment; private Environment environment;
@Autowired //@Autowired
public HttpRemoteLogger(Environment environment) { public HttpRemoteLogger(Environment environment) {
super(environment); super(environment);
this.rest = new RestTemplate(); this.rest = new RestTemplate();

View File

@ -7,6 +7,8 @@ import eu.eudat.queryable.jpa.predicates.*;
import eu.eudat.queryable.queryableentity.DataEntity; import eu.eudat.queryable.queryableentity.DataEntity;
import eu.eudat.queryable.types.FieldSelectionType; import eu.eudat.queryable.types.FieldSelectionType;
import eu.eudat.queryable.types.SelectionField; import eu.eudat.queryable.types.SelectionField;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
@ -18,6 +20,7 @@ import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class QueryableHibernateList<T extends DataEntity> implements QueryableList<T> { public class QueryableHibernateList<T extends DataEntity> implements QueryableList<T> {
private static final Logger logger = LoggerFactory.getLogger(QueryableHibernateList.class);
private Collector collector = new Collector(); private Collector collector = new Collector();
private EntityManager manager; private EntityManager manager;
@ -264,7 +267,7 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
try { try {
return (T) this.tClass.newInstance().buildFromTuple(groupedResults.get(x.get("id")), this.fields, ""); return (T) this.tClass.newInstance().buildFromTuple(groupedResults.get(x.get("id")), this.fields, "");
} catch (InstantiationException | IllegalAccessException e) { } catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return null; return null;
}).collect(Collectors.toList())); }).collect(Collectors.toList()));

View File

@ -2,6 +2,8 @@ package eu.eudat.cache;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cache.CacheManager; import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.guava.GuavaCache; import org.springframework.cache.guava.GuavaCache;
@ -17,6 +19,7 @@ import java.util.concurrent.TimeUnit;
@Component @Component
@EnableCaching @EnableCaching
public class ResponsesCache { public class ResponsesCache {
private static final Logger logger = LoggerFactory.getLogger(ResponsesCache.class);
public static long HOW_MANY = 30; public static long HOW_MANY = 30;
public static TimeUnit TIME_UNIT = TimeUnit.MINUTES; public static TimeUnit TIME_UNIT = TimeUnit.MINUTES;
@ -24,7 +27,7 @@ public class ResponsesCache {
@Bean @Bean
public CacheManager cacheManager() { public CacheManager cacheManager() {
System.out.print("Loading ResponsesCache..."); logger.info("Loading ResponsesCache...");
SimpleCacheManager simpleCacheManager = new SimpleCacheManager(); SimpleCacheManager simpleCacheManager = new SimpleCacheManager();
List<GuavaCache> caches = new ArrayList<GuavaCache>(); List<GuavaCache> caches = new ArrayList<GuavaCache>();
caches.add(new GuavaCache("repositories", CacheBuilder.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build())); caches.add(new GuavaCache("repositories", CacheBuilder.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build()));
@ -38,7 +41,7 @@ public class ResponsesCache {
caches.add(new GuavaCache("researchers", CacheBuilder.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build())); caches.add(new GuavaCache("researchers", CacheBuilder.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build()));
caches.add(new GuavaCache("externalDatasets", CacheBuilder.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build())); caches.add(new GuavaCache("externalDatasets", CacheBuilder.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build()));
simpleCacheManager.setCaches(caches); simpleCacheManager.setCaches(caches);
System.out.println("OK"); logger.info("OK");
return simpleCacheManager; return simpleCacheManager;
} }

View File

@ -37,6 +37,6 @@ public class WebMVCConfiguration extends WebMvcConfigurerAdapter {
@Override @Override
public void addInterceptors(InterceptorRegistry registry) { public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new RequestInterceptor(this.apiContext.getHelpersService().getLoggerService())); // registry.addInterceptor(new RequestInterceptor(this.apiContext.getHelpersService().getLoggerService()));
} }
} }

View File

@ -4,6 +4,8 @@ import eu.eudat.configurations.dynamicfunder.entities.Configuration;
import eu.eudat.configurations.dynamicfunder.entities.Property; import eu.eudat.configurations.dynamicfunder.entities.Property;
import eu.eudat.models.data.dynamicfields.Dependency; import eu.eudat.models.data.dynamicfields.Dependency;
import eu.eudat.models.data.dynamicfields.DynamicField; import eu.eudat.models.data.dynamicfields.DynamicField;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Profile; import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -19,6 +21,7 @@ import java.util.List;
@Service("dynamicFunderConfiguration") @Service("dynamicFunderConfiguration")
@Profile("devel") @Profile("devel")
public class DynamicFunderConfigurationDevelImpl implements DynamicFunderConfiguration { public class DynamicFunderConfigurationDevelImpl implements DynamicFunderConfiguration {
private static final Logger logger = LoggerFactory.getLogger(DynamicFunderConfigurationDevelImpl.class);
private Configuration configuration; private Configuration configuration;
private List<DynamicField> fields; private List<DynamicField> fields;
@ -32,7 +35,7 @@ public class DynamicFunderConfigurationDevelImpl implements DynamicFunderConfigu
public Configuration getConfiguration() { public Configuration getConfiguration() {
if (this.configuration != null) return this.configuration; if (this.configuration != null) return this.configuration;
String fileUrl = this.environment.getProperty("configuration.dynamicFunderUrl"); String fileUrl = this.environment.getProperty("configuration.dynamicFunderUrl");
System.out.println("Loaded also config file: " + fileUrl); logger.info("Loaded also config file: " + fileUrl);
String current = null; String current = null;
InputStream is = null; InputStream is = null;
try { try {
@ -43,13 +46,12 @@ public class DynamicFunderConfigurationDevelImpl implements DynamicFunderConfigu
is = new URL("file:///"+ current + "/web/src/main/resources/FunderConfiguration.xml").openStream(); is = new URL("file:///"+ current + "/web/src/main/resources/FunderConfiguration.xml").openStream();
this.configuration = (Configuration) jaxbUnmarshaller.unmarshal(is); this.configuration = (Configuration) jaxbUnmarshaller.unmarshal(is);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); logger.error("Cannot find in folder" + current, ex);
System.out.println("Cannot find in folder" + current);
} finally { } finally {
try { try {
if (is != null) is.close(); if (is != null) is.close();
} catch (IOException e) { } catch (IOException e) {
System.out.println("Warning: Could not close a stream after reading from file: " + fileUrl); logger.warn("Warning: Could not close a stream after reading from file: " + fileUrl, e);
} }
} }
return this.configuration; return this.configuration;

View File

@ -4,6 +4,8 @@ import eu.eudat.configurations.dynamicfunder.entities.Configuration;
import eu.eudat.configurations.dynamicfunder.entities.Property; import eu.eudat.configurations.dynamicfunder.entities.Property;
import eu.eudat.models.data.dynamicfields.Dependency; import eu.eudat.models.data.dynamicfields.Dependency;
import eu.eudat.models.data.dynamicfields.DynamicField; import eu.eudat.models.data.dynamicfields.DynamicField;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Profile; import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -20,6 +22,7 @@ import java.util.List;
@Service("dynamicFunderConfiguration") @Service("dynamicFunderConfiguration")
@Profile({ "production", "staging" }) @Profile({ "production", "staging" })
public class DynamicFunderConfigurationProdImpl implements DynamicFunderConfiguration { public class DynamicFunderConfigurationProdImpl implements DynamicFunderConfiguration {
private static final Logger logger = LoggerFactory.getLogger(DynamicFunderConfigurationProdImpl.class);
private Configuration configuration; private Configuration configuration;
private List<DynamicField> fields; private List<DynamicField> fields;
@ -33,7 +36,7 @@ public class DynamicFunderConfigurationProdImpl implements DynamicFunderConfigur
public Configuration getConfiguration() { public Configuration getConfiguration() {
if (this.configuration != null) return this.configuration; if (this.configuration != null) return this.configuration;
String fileUrl = this.environment.getProperty("configuration.dynamicFunderUrl"); String fileUrl = this.environment.getProperty("configuration.dynamicFunderUrl");
System.out.println("Loaded also config file: " + fileUrl); logger.info("Loaded also config file: " + fileUrl);
String current = null; String current = null;
InputStream is = null; InputStream is = null;
try { try {
@ -44,13 +47,12 @@ public class DynamicFunderConfigurationProdImpl implements DynamicFunderConfigur
is = new URL(Paths.get(fileUrl).toUri().toURL().toString()).openStream(); is = new URL(Paths.get(fileUrl).toUri().toURL().toString()).openStream();
this.configuration = (Configuration) jaxbUnmarshaller.unmarshal(is); this.configuration = (Configuration) jaxbUnmarshaller.unmarshal(is);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); logger.error("Cannot find in folder" + current, ex);
System.out.println("Cannot find in folder" + current);
} finally { } finally {
try { try {
if (is != null) is.close(); if (is != null) is.close();
} catch (IOException e) { } catch (IOException e) {
System.out.println("Warning: Could not close a stream after reading from file: " + fileUrl); logger.warn("Warning: Could not close a stream after reading from file: " + fileUrl, e);
} }
} }
return this.configuration; return this.configuration;

View File

@ -4,6 +4,8 @@ import eu.eudat.configurations.dynamicgrant.entities.Configuration;
import eu.eudat.configurations.dynamicgrant.entities.Property; import eu.eudat.configurations.dynamicgrant.entities.Property;
import eu.eudat.models.data.dynamicfields.Dependency; import eu.eudat.models.data.dynamicfields.Dependency;
import eu.eudat.models.data.dynamicfields.DynamicField; import eu.eudat.models.data.dynamicfields.DynamicField;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile; import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
@ -24,6 +26,7 @@ import java.util.List;
@Service("dynamicGrantConfiguration") @Service("dynamicGrantConfiguration")
@Profile("devel") @Profile("devel")
public class DynamicGrantConfigurationDevelImpl implements DynamicGrantConfiguration { public class DynamicGrantConfigurationDevelImpl implements DynamicGrantConfiguration {
private static final Logger logger = LoggerFactory.getLogger(DynamicGrantConfigurationDevelImpl.class);
private Configuration configuration; private Configuration configuration;
@ -40,7 +43,7 @@ public class DynamicGrantConfigurationDevelImpl implements DynamicGrantConfigura
public Configuration getConfiguration() { public Configuration getConfiguration() {
if (this.configuration != null) return this.configuration; if (this.configuration != null) return this.configuration;
String fileUrl = this.environment.getProperty("configuration.dynamicGrantUrl"); String fileUrl = this.environment.getProperty("configuration.dynamicGrantUrl");
System.out.println("Loaded also config file: " + fileUrl); logger.info("Loaded also config file: " + fileUrl);
String current = null; String current = null;
InputStream is = null; InputStream is = null;
try { try {
@ -51,13 +54,12 @@ public class DynamicGrantConfigurationDevelImpl implements DynamicGrantConfigura
is = new URL("file:///"+ current + "/web/src/main/resources/GrantConfiguration.xml").openStream(); is = new URL("file:///"+ current + "/web/src/main/resources/GrantConfiguration.xml").openStream();
this.configuration = (Configuration) jaxbUnmarshaller.unmarshal(is); this.configuration = (Configuration) jaxbUnmarshaller.unmarshal(is);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); logger.error("Cannot find in folder" + current, ex);
System.out.println("Cannot find in folder" + current);
} finally { } finally {
try { try {
if (is != null) is.close(); if (is != null) is.close();
} catch (IOException e) { } catch (IOException e) {
System.out.println("Warning: Could not close a stream after reading from file: " + fileUrl); logger.warn("Warning: Could not close a stream after reading from file: " + fileUrl, e);
} }
} }
return this.configuration; return this.configuration;

View File

@ -4,6 +4,8 @@ import eu.eudat.configurations.dynamicgrant.entities.Configuration;
import eu.eudat.configurations.dynamicgrant.entities.Property; import eu.eudat.configurations.dynamicgrant.entities.Property;
import eu.eudat.models.data.dynamicfields.Dependency; import eu.eudat.models.data.dynamicfields.Dependency;
import eu.eudat.models.data.dynamicfields.DynamicField; import eu.eudat.models.data.dynamicfields.DynamicField;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile; import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
@ -24,6 +26,7 @@ import java.util.List;
@Service("dynamicGrantConfiguration") @Service("dynamicGrantConfiguration")
@Profile({ "production", "staging" }) @Profile({ "production", "staging" })
public class DynamicGrantConfigurationProdImpl implements DynamicGrantConfiguration { public class DynamicGrantConfigurationProdImpl implements DynamicGrantConfiguration {
private static final Logger logger = LoggerFactory.getLogger(DynamicGrantConfigurationProdImpl.class);
private Configuration configuration; private Configuration configuration;
@ -40,7 +43,7 @@ public class DynamicGrantConfigurationProdImpl implements DynamicGrantConfigurat
public Configuration getConfiguration() { public Configuration getConfiguration() {
if (this.configuration != null) return this.configuration; if (this.configuration != null) return this.configuration;
String fileUrl = this.environment.getProperty("configuration.dynamicGrantUrl"); String fileUrl = this.environment.getProperty("configuration.dynamicGrantUrl");
System.out.println("Loaded also config file: " + fileUrl); logger.info("Loaded also config file: " + fileUrl);
String current = null; String current = null;
InputStream is = null; InputStream is = null;
try { try {
@ -51,13 +54,12 @@ public class DynamicGrantConfigurationProdImpl implements DynamicGrantConfigurat
is = new URL(Paths.get(fileUrl).toUri().toURL().toString()).openStream(); is = new URL(Paths.get(fileUrl).toUri().toURL().toString()).openStream();
this.configuration = (Configuration) jaxbUnmarshaller.unmarshal(is); this.configuration = (Configuration) jaxbUnmarshaller.unmarshal(is);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); logger.error("Cannot find in folder" + current, ex);
System.out.println("Cannot find in folder" + current);
} finally { } finally {
try { try {
if (is != null) is.close(); if (is != null) is.close();
} catch (IOException e) { } catch (IOException e) {
System.out.println("Warning: Could not close a stream after reading from file: " + fileUrl); logger.warn("Warning: Could not close a stream after reading from file: " + fileUrl, e);
} }
} }
return this.configuration; return this.configuration;

View File

@ -4,6 +4,8 @@ import eu.eudat.configurations.dynamicproject.entities.Configuration;
import eu.eudat.configurations.dynamicproject.entities.Property; import eu.eudat.configurations.dynamicproject.entities.Property;
import eu.eudat.models.data.dynamicfields.Dependency; import eu.eudat.models.data.dynamicfields.Dependency;
import eu.eudat.models.data.dynamicfields.DynamicField; import eu.eudat.models.data.dynamicfields.DynamicField;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile; import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
@ -20,6 +22,7 @@ import java.util.List;
@Service("dynamicProjectConfiguration") @Service("dynamicProjectConfiguration")
@Profile("devel") @Profile("devel")
public class DynamicProjectConfigurationDevelImpl implements DynamicProjectConfiguration{ public class DynamicProjectConfigurationDevelImpl implements DynamicProjectConfiguration{
private static final Logger logger = LoggerFactory.getLogger(DynamicProjectConfigurationDevelImpl.class);
private Configuration configuration; private Configuration configuration;
private List<DynamicField> fields; private List<DynamicField> fields;
@ -34,7 +37,7 @@ public class DynamicProjectConfigurationDevelImpl implements DynamicProjectConfi
public Configuration getConfiguration() { public Configuration getConfiguration() {
if (this.configuration != null) return this.configuration; if (this.configuration != null) return this.configuration;
String fileUrl = this.environment.getProperty("configuration.dynamicProjectUrl"); String fileUrl = this.environment.getProperty("configuration.dynamicProjectUrl");
System.out.println("Loaded also config file: " + fileUrl); logger.info("Loaded also config file: " + fileUrl);
String current = null; String current = null;
InputStream is = null; InputStream is = null;
try { try {
@ -45,13 +48,12 @@ public class DynamicProjectConfigurationDevelImpl implements DynamicProjectConfi
is = new URL("file:///"+ current + "/web/src/main/resources/ProjectConfiguration.xml").openStream(); is = new URL("file:///"+ current + "/web/src/main/resources/ProjectConfiguration.xml").openStream();
this.configuration = (Configuration) jaxbUnmarshaller.unmarshal(is); this.configuration = (Configuration) jaxbUnmarshaller.unmarshal(is);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); logger.error("Cannot find in folder" + current, ex);
System.out.println("Cannot find in folder" + current);
} finally { } finally {
try { try {
if (is != null) is.close(); if (is != null) is.close();
} catch (IOException e) { } catch (IOException e) {
System.out.println("Warning: Could not close a stream after reading from file: " + fileUrl); logger.warn("Warning: Could not close a stream after reading from file: " + fileUrl, e);
} }
} }
return this.configuration; return this.configuration;

View File

@ -4,6 +4,8 @@ import eu.eudat.configurations.dynamicproject.entities.Configuration;
import eu.eudat.configurations.dynamicproject.entities.Property; import eu.eudat.configurations.dynamicproject.entities.Property;
import eu.eudat.models.data.dynamicfields.Dependency; import eu.eudat.models.data.dynamicfields.Dependency;
import eu.eudat.models.data.dynamicfields.DynamicField; import eu.eudat.models.data.dynamicfields.DynamicField;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile; import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
@ -21,6 +23,7 @@ import java.util.List;
@Service("dynamicProjectConfiguration") @Service("dynamicProjectConfiguration")
@Profile({ "production", "staging" }) @Profile({ "production", "staging" })
public class DynamicProjectConfigurationProdImpl implements DynamicProjectConfiguration{ public class DynamicProjectConfigurationProdImpl implements DynamicProjectConfiguration{
private static final Logger logger = LoggerFactory.getLogger(DynamicProjectConfigurationProdImpl.class);
private Configuration configuration; private Configuration configuration;
@ -37,7 +40,7 @@ public class DynamicProjectConfigurationProdImpl implements DynamicProjectConfig
public Configuration getConfiguration() { public Configuration getConfiguration() {
if (this.configuration != null) return this.configuration; if (this.configuration != null) return this.configuration;
String fileUrl = this.environment.getProperty("configuration.dynamicProjectUrl"); String fileUrl = this.environment.getProperty("configuration.dynamicProjectUrl");
System.out.println("Loaded also config file: " + fileUrl); logger.info("Loaded also config file: " + fileUrl);
String current = null; String current = null;
InputStream is = null; InputStream is = null;
try { try {
@ -48,13 +51,12 @@ public class DynamicProjectConfigurationProdImpl implements DynamicProjectConfig
is = new URL(Paths.get(fileUrl).toUri().toURL().toString()).openStream(); is = new URL(Paths.get(fileUrl).toUri().toURL().toString()).openStream();
this.configuration = (Configuration) jaxbUnmarshaller.unmarshal(is); this.configuration = (Configuration) jaxbUnmarshaller.unmarshal(is);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); logger.error("Cannot find in folder" + current, ex);
System.out.println("Cannot find in folder" + current);
} finally { } finally {
try { try {
if (is != null) is.close(); if (is != null) is.close();
} catch (IOException e) { } catch (IOException e) {
System.out.println("Warning: Could not close a stream after reading from file: " + fileUrl); logger.warn("Warning: Could not close a stream after reading from file: " + fileUrl, e);
} }
} }
return this.configuration; return this.configuration;

View File

@ -42,7 +42,7 @@ public class Admin extends BaseController {
private ConfigLoader configLoader; private ConfigLoader configLoader;
@Autowired @Autowired
public Admin(ApiContext apiContext, DatasetProfileManager datasetProfileManager, UserManager userManager, Logger logger, ConfigLoader configLoader) { public Admin(ApiContext apiContext, DatasetProfileManager datasetProfileManager, UserManager userManager/*, Logger logger*/, ConfigLoader configLoader) {
super(apiContext); super(apiContext);
this.datasetProfileManager = datasetProfileManager; this.datasetProfileManager = datasetProfileManager;
this.userManager = userManager; this.userManager = userManager;

View File

@ -9,7 +9,7 @@ import org.springframework.web.bind.annotation.InitBinder;
public abstract class BaseController { public abstract class BaseController {
private Logger logger; /*private Logger logger;*/
private ApiContext apiContext; private ApiContext apiContext;
@ -17,9 +17,9 @@ public abstract class BaseController {
return apiContext; return apiContext;
} }
public Logger getLoggerService() { /*public Logger getLoggerService() {
return logger; return logger;
} }*/
public BaseController(ApiContext apiContext) { public BaseController(ApiContext apiContext) {

View File

@ -5,6 +5,8 @@ import eu.eudat.models.data.ContactEmail.ContactEmailModel;
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.types.ApiMessageCode; import eu.eudat.types.ApiMessageCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -15,6 +17,7 @@ import javax.transaction.Transactional;
@CrossOrigin @CrossOrigin
@RequestMapping(value = "api/contactEmail") @RequestMapping(value = "api/contactEmail")
public class ContactEmail { public class ContactEmail {
private static final Logger logger = LoggerFactory.getLogger(ContactEmail.class);
private ContactEmailManager contactEmailManager; private ContactEmailManager contactEmailManager;
@ -31,7 +34,7 @@ public class ContactEmail {
this.contactEmailManager.sendContactEmail(contactEmailModel, principal); this.contactEmailManager.sendContactEmail(contactEmailModel, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE));
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); logger.error(ex.getMessage(), ex);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message(ex.getMessage())); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message(ex.getMessage()));
} }
} }

View File

@ -29,6 +29,8 @@ import eu.eudat.models.data.security.Principal;
import eu.eudat.query.DMPQuery; import eu.eudat.query.DMPQuery;
import eu.eudat.types.ApiMessageCode; import eu.eudat.types.ApiMessageCode;
import eu.eudat.types.Authorities; import eu.eudat.types.Authorities;
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.HttpHeaders;
@ -55,6 +57,7 @@ import java.util.UUID;
@CrossOrigin @CrossOrigin
@RequestMapping(value = {"/api/dmps/"}) @RequestMapping(value = {"/api/dmps/"})
public class DMPs extends BaseController { public class DMPs extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(DMPs.class);
private DynamicGrantConfiguration dynamicGrantConfiguration; private DynamicGrantConfiguration dynamicGrantConfiguration;
private Environment environment; private Environment environment;
@ -95,7 +98,7 @@ public class DMPs extends BaseController {
if (contentType.equals("application/xml") || contentType.equals("application/msword")) { if (contentType.equals("application/xml") || contentType.equals("application/msword")) {
return this.dataManagementPlanManager.getDocument(id, contentType, principal, this.configLoader); return this.dataManagementPlanManager.getDocument(id, contentType, principal, this.configLoader);
} else { } else {
eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan = this.dataManagementPlanManager.getSingle(id, principal, this.dynamicGrantConfiguration); eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan = this.dataManagementPlanManager.getSingle(id, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlan>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlan>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan));
} }
} }
@ -110,14 +113,18 @@ public class DMPs extends BaseController {
@RequestMapping(method = RequestMethod.GET, value = {"rda/{id}"}) @RequestMapping(method = RequestMethod.GET, value = {"rda/{id}"})
public @ResponseBody public @ResponseBody
ResponseEntity getRDAJsonDocument(@PathVariable String id, @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) throws IOException { ResponseEntity getRDAJsonDocument(@PathVariable String id, @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) throws IOException {
return this.dataManagementPlanManager.getRDAJsonDocument(id, principal); return this.dataManagementPlanManager.getRDAJsonDocument(id, datasetManager, principal);
} }
@RequestMapping(method = RequestMethod.GET, value = {"/overview/{id}"}) @RequestMapping(method = RequestMethod.GET, value = {"/overview/{id}"})
public @ResponseBody public @ResponseBody
ResponseEntity getOverviewSingle(@PathVariable String id, Principal principal) throws IllegalAccessException, InstantiationException { ResponseEntity getOverviewSingle(@PathVariable String id, Principal principal) {
DataManagementPlanOverviewModel dataManagementPlan = this.dataManagementPlanManager.getOverviewSingle(id, principal); try {
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlanOverviewModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan)); DataManagementPlanOverviewModel dataManagementPlan = this.dataManagementPlanManager.getOverviewSingle(id, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlanOverviewModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan));
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ResponseItem<DataManagementPlanOverviewModel>().status(ApiMessageCode.ERROR_MESSAGE));
}
} }
@RequestMapping(method = RequestMethod.GET, value = {"/public/{id}"}) @RequestMapping(method = RequestMethod.GET, value = {"/public/{id}"})
@ -195,7 +202,7 @@ public class DMPs extends BaseController {
String name = file.getName().substring(0, file.getName().length() - 5); String name = file.getName().substring(0, file.getName().length() - 5);
File pdffile = datasetManager.convertToPDF(file, environment, name); File pdffile = datasetManager.convertToPDF(file, environment, name);
InputStream resource = new FileInputStream(pdffile); InputStream resource = new FileInputStream(pdffile);
System.out.println("Mime Type of " + file.getName() + " is " + logger.info("Mime Type of " + file.getName() + " is " +
new MimetypesFileTypeMap().getContentType(file)); new MimetypesFileTypeMap().getContentType(file));
HttpHeaders responseHeaders = new HttpHeaders(); HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentLength(pdffile.length()); responseHeaders.setContentLength(pdffile.length());
@ -269,7 +276,7 @@ public class DMPs extends BaseController {
String zenodoDOI = this.dataManagementPlanManager.createZenodoDoi(UUID.fromString(id), principal, configLoader); String zenodoDOI = this.dataManagementPlanManager.createZenodoDoi(UUID.fromString(id), principal, configLoader);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<String>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully created DOI for Data Datamanagement Plan in question.").payload(zenodoDOI)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<String>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully created DOI for Data Datamanagement Plan in question.").payload(zenodoDOI));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<String>().status(ApiMessageCode.ERROR_MESSAGE).message(e.getMessage())); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<String>().status(ApiMessageCode.ERROR_MESSAGE).message(e.getMessage()));
} }
} }

View File

@ -1,6 +1,7 @@
package eu.eudat.controllers; package eu.eudat.controllers;
import eu.eudat.logic.managers.DashBoardManager; import eu.eudat.logic.managers.DashBoardManager;
import eu.eudat.logic.security.claims.ClaimedAuthorities;
import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.data.dashboard.recent.RecentActivity; import eu.eudat.models.data.dashboard.recent.RecentActivity;
import eu.eudat.models.data.dashboard.searchbar.SearchBarItem; import eu.eudat.models.data.dashboard.searchbar.SearchBarItem;
@ -8,6 +9,7 @@ import eu.eudat.models.data.dashboard.statistics.DashBoardStatistics;
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.types.ApiMessageCode; import eu.eudat.types.ApiMessageCode;
import eu.eudat.types.Authorities;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -46,7 +48,8 @@ public class DashBoardController extends BaseController {
} }
@RequestMapping(method = RequestMethod.GET, value = {"/dashboard/search"}, produces = "application/json") @RequestMapping(method = RequestMethod.GET, value = {"/dashboard/search"}, produces = "application/json")
public ResponseEntity<ResponseItem<List<SearchBarItem>>> search(@RequestParam(name = "like") String like, Principal principal) { public ResponseEntity<ResponseItem<List<SearchBarItem>>> search(@RequestParam(name = "like") String like,
@ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) {
List<SearchBarItem> searchBarItemList = dashBoardManager.searchUserData(like, principal); List<SearchBarItem> searchBarItemList = dashBoardManager.searchUserData(like, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<SearchBarItem>>().status(ApiMessageCode.NO_MESSAGE).payload(searchBarItemList)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<SearchBarItem>>().status(ApiMessageCode.NO_MESSAGE).payload(searchBarItemList));
} }

View File

@ -43,10 +43,10 @@ public class DataRepositories extends BaseController {
@Transactional @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<DataRepository>> create(@RequestBody eu.eudat.models.data.datarepository.DataRepositoryModel dataRepositoryModel, Principal principal) throws Exception { ResponseEntity<ResponseItem<DataRepositoryModel>> create(@RequestBody eu.eudat.models.data.datarepository.DataRepositoryModel dataRepositoryModel, Principal principal) throws Exception {
DataRepository dataRepository = this.dataRepositoryManager.create(dataRepositoryModel, principal); DataRepository dataRepository = this.dataRepositoryManager.create(dataRepositoryModel, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataRepository>().payload(dataRepository).status(ApiMessageCode.SUCCESS_MESSAGE)); DataRepositoryModel dataRepositoryModel1 = new DataRepositoryModel().fromDataModel(dataRepository);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataRepositoryModel>().payload(dataRepositoryModel1).status(ApiMessageCode.SUCCESS_MESSAGE));
} }
} }

View File

@ -19,6 +19,8 @@ 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;
import org.apache.poi.util.IOUtils; import org.apache.poi.util.IOUtils;
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.HttpHeaders;
@ -44,6 +46,7 @@ import static eu.eudat.types.Authorities.ANONYMOUS;
@CrossOrigin @CrossOrigin
@RequestMapping(value = {"api/datasetwizard"}) @RequestMapping(value = {"api/datasetwizard"})
public class DatasetWizardController extends BaseController { public class DatasetWizardController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(DatasetWizardController.class);
private Environment environment; private Environment environment;
private DatasetManager datasetManager; private DatasetManager datasetManager;
@ -191,7 +194,7 @@ public class DatasetWizardController extends BaseController {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).message("Import was unsuccessful.")); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).message("Import was unsuccessful."));
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).message("Import was unsuccessful.")); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).message("Import was unsuccessful."));
} }
} }

View File

@ -36,7 +36,11 @@ public class EmailConfirmation {
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE));
} catch } catch
(HasConfirmedEmailException | TokenExpiredException ex) { (HasConfirmedEmailException | TokenExpiredException ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE)); 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));
}
} }
} }
@ -48,6 +52,9 @@ public class EmailConfirmation {
this.emailConfirmationManager.sendConfirmationEmail(email, principal); this.emailConfirmationManager.sendConfirmationEmail(email, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE));
} catch (Exception ex) { } 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)); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE));
} }
} }

View File

@ -62,8 +62,9 @@ public class ExternalDatasets extends BaseController {
@Transactional @Transactional
@RequestMapping(method = RequestMethod.POST, value = {"/externaldatasets"}, consumes = "application/json", produces = "application/json") @RequestMapping(method = RequestMethod.POST, value = {"/externaldatasets"}, consumes = "application/json", produces = "application/json")
public @ResponseBody public @ResponseBody
ResponseEntity<ResponseItem<ExternalDataset>> create(@RequestBody eu.eudat.models.data.externaldataset.ExternalDatasetModel externalDatasetModel, Principal principal) throws Exception { ResponseEntity<ResponseItem<ExternalDatasetListingModel>> create(@RequestBody eu.eudat.models.data.externaldataset.ExternalDatasetModel externalDatasetModel, Principal principal) throws Exception {
ExternalDataset externalDataset = this.externalDatasetManager.create(externalDatasetModel, principal); ExternalDataset externalDataset = this.externalDatasetManager.create(externalDatasetModel, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ExternalDataset>().payload(externalDataset).status(ApiMessageCode.SUCCESS_MESSAGE)); ExternalDatasetListingModel externalDatasetListingModel = new ExternalDatasetListingModel().fromDataModel(externalDataset);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ExternalDatasetListingModel>().payload(externalDatasetListingModel).status(ApiMessageCode.SUCCESS_MESSAGE));
} }
} }

View File

@ -0,0 +1,58 @@
package eu.eudat.controllers;
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.models.data.security.Principal;
import eu.eudat.types.ApiMessageCode;
import org.springframework.beans.factory.annotation.Autowired;
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.web.bind.annotation.*;
import java.io.*;
import java.util.UUID;
@RestController
@CrossOrigin
@RequestMapping(value = {"/api/language/"})
public class LanguageController {
Environment environment;
@Autowired
public LanguageController(Environment environment) {
this.environment = environment;
}
@RequestMapping(value = "{lang}", method = RequestMethod.GET)
public ResponseEntity getLanguage(@PathVariable String lang) throws IOException {
String fileName = this.environment.getProperty("language.path") + lang + ".json";
InputStream is = new FileInputStream(fileName);
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentLength(is.available());
responseHeaders.setContentType(MediaType.APPLICATION_JSON);
responseHeaders.set("Content-Disposition", "attachment;filename=" + fileName);
responseHeaders.set("Access-Control-Expose-Headers", "Content-Disposition");
responseHeaders.get("Access-Control-Expose-Headers").add("Content-Type");
byte[] content = new byte[is.available()];
is.read(content);
is.close();
return new ResponseEntity<>(content, responseHeaders, HttpStatus.OK);
}
@RequestMapping(value = "update/{lang}", method = RequestMethod.POST)
public @ResponseBody
ResponseEntity<ResponseItem<String>> updateLang(@PathVariable String lang, @RequestBody String json) throws Exception {
String fileName = this.environment.getProperty("language.path") + lang + ".json";
OutputStream os = new FileOutputStream(fileName);
os.write(json.getBytes());
os.close();
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<String>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Updated").payload("Updated"));
}
}

View File

@ -1,6 +1,6 @@
package eu.eudat.controllers; package eu.eudat.controllers;
import eu.eudat.core.logger.Logger;
import eu.eudat.exceptions.security.NullEmailException; import eu.eudat.exceptions.security.NullEmailException;
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;
@ -28,6 +28,8 @@ import eu.eudat.models.data.login.Credentials;
import eu.eudat.models.data.login.LoginInfo; import eu.eudat.models.data.login.LoginInfo;
import eu.eudat.models.data.security.Principal; import eu.eudat.models.data.security.Principal;
import eu.eudat.types.ApiMessageCode; import eu.eudat.types.ApiMessageCode;
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.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -42,6 +44,7 @@ import java.security.GeneralSecurityException;
@CrossOrigin @CrossOrigin
@RequestMapping(value = "api/auth") @RequestMapping(value = "api/auth")
public class Login { public class Login {
private static final Logger logger = LoggerFactory.getLogger(Login.class);
private CustomAuthenticationProvider customAuthenticationProvider; private CustomAuthenticationProvider customAuthenticationProvider;
private AuthenticationService nonVerifiedUserAuthenticationService; private AuthenticationService nonVerifiedUserAuthenticationService;
@ -53,13 +56,13 @@ public class Login {
private ConfigurableProviderTokenValidator configurableProviderTokenValidator; private ConfigurableProviderTokenValidator configurableProviderTokenValidator;
private ConfigLoader configLoader; private ConfigLoader configLoader;
private Logger logger; // private Logger logger;
private UserManager userManager; private UserManager userManager;
@Autowired @Autowired
public Login(CustomAuthenticationProvider customAuthenticationProvider, AuthenticationService nonVerifiedUserAuthenticationService, public Login(CustomAuthenticationProvider customAuthenticationProvider, AuthenticationService nonVerifiedUserAuthenticationService,
TwitterTokenValidator twitterTokenValidator, LinkedInTokenValidator linkedInTokenValidator, B2AccessTokenValidator b2AccessTokenValidator, TwitterTokenValidator twitterTokenValidator, LinkedInTokenValidator linkedInTokenValidator, B2AccessTokenValidator b2AccessTokenValidator,
ORCIDTokenValidator orcidTokenValidator, OpenAIRETokenValidator openAIRETokenValidator, ConfigurableProviderTokenValidator configurableProviderTokenValidator, ConfigLoader configLoader, UserManager userManager, Logger logger) { ORCIDTokenValidator orcidTokenValidator, OpenAIRETokenValidator openAIRETokenValidator, ConfigurableProviderTokenValidator configurableProviderTokenValidator, ConfigLoader configLoader, UserManager userManager/*, Logger logger*/) {
this.customAuthenticationProvider = customAuthenticationProvider; this.customAuthenticationProvider = customAuthenticationProvider;
this.nonVerifiedUserAuthenticationService = nonVerifiedUserAuthenticationService; this.nonVerifiedUserAuthenticationService = nonVerifiedUserAuthenticationService;
this.twitterTokenValidator = twitterTokenValidator; this.twitterTokenValidator = twitterTokenValidator;
@ -69,7 +72,7 @@ public class Login {
this.openAIRETokenValidator = openAIRETokenValidator; this.openAIRETokenValidator = openAIRETokenValidator;
this.configurableProviderTokenValidator = configurableProviderTokenValidator; this.configurableProviderTokenValidator = configurableProviderTokenValidator;
this.configLoader = configLoader; this.configLoader = configLoader;
this.logger = logger; // this.logger = logger;
this.userManager = userManager; this.userManager = userManager;
} }
@ -77,7 +80,7 @@ public class Login {
@RequestMapping(method = RequestMethod.POST, value = {"/externallogin"}, consumes = "application/json", produces = "application/json") @RequestMapping(method = RequestMethod.POST, value = {"/externallogin"}, consumes = "application/json", produces = "application/json")
public @ResponseBody public @ResponseBody
ResponseEntity<ResponseItem<Principal>> externallogin(@RequestBody LoginInfo credentials) throws GeneralSecurityException, NullEmailException { ResponseEntity<ResponseItem<Principal>> externallogin(@RequestBody LoginInfo credentials) throws GeneralSecurityException, NullEmailException {
this.logger.info(credentials, "Trying To Login With " + credentials.getProvider()); logger.info("Trying To Login With " + credentials.getProvider());
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Principal>().payload(customAuthenticationProvider.authenticate(credentials)).status(ApiMessageCode.SUCCESS_MESSAGE)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Principal>().payload(customAuthenticationProvider.authenticate(credentials)).status(ApiMessageCode.SUCCESS_MESSAGE));
} }
@ -85,7 +88,7 @@ public class Login {
@RequestMapping(method = RequestMethod.POST, value = {"/nativelogin"}, consumes = "application/json", produces = "application/json") @RequestMapping(method = RequestMethod.POST, value = {"/nativelogin"}, consumes = "application/json", produces = "application/json")
public @ResponseBody public @ResponseBody
ResponseEntity<ResponseItem<Principal>> nativelogin(@RequestBody Credentials credentials) throws NullEmailException { ResponseEntity<ResponseItem<Principal>> nativelogin(@RequestBody Credentials credentials) throws NullEmailException {
this.logger.info(credentials.getUsername(), "Trying To Login"); logger.info(credentials.getUsername() + " Trying To Login");
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Principal>().payload(userManager.authenticate(this.nonVerifiedUserAuthenticationService, credentials)).status(ApiMessageCode.SUCCESS_MESSAGE)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Principal>().payload(userManager.authenticate(this.nonVerifiedUserAuthenticationService, credentials)).status(ApiMessageCode.SUCCESS_MESSAGE));
} }
@ -128,7 +131,7 @@ public class Login {
@RequestMapping(method = RequestMethod.POST, value = {"/me"}, consumes = "application/json", produces = "application/json") @RequestMapping(method = RequestMethod.POST, value = {"/me"}, consumes = "application/json", produces = "application/json")
public @ResponseBody public @ResponseBody
ResponseEntity<ResponseItem<Principal>> authMe(Principal principal) throws NullEmailException { ResponseEntity<ResponseItem<Principal>> authMe(Principal principal) throws NullEmailException {
this.logger.info(principal, "Getting Me"); logger.info(principal + " Getting Me");
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Principal>().payload(this.nonVerifiedUserAuthenticationService.Touch(principal.getToken())).status(ApiMessageCode.NO_MESSAGE)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Principal>().payload(this.nonVerifiedUserAuthenticationService.Touch(principal.getToken())).status(ApiMessageCode.NO_MESSAGE));
} }
@ -137,7 +140,7 @@ public class Login {
public @ResponseBody public @ResponseBody
ResponseEntity<ResponseItem<Principal>> logout(Principal principal) { ResponseEntity<ResponseItem<Principal>> logout(Principal principal) {
this.nonVerifiedUserAuthenticationService.Logout(principal.getToken()); this.nonVerifiedUserAuthenticationService.Logout(principal.getToken());
this.logger.info(principal, "Logged Out"); logger.info(principal + " Logged Out");
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

@ -2,12 +2,10 @@ package eu.eudat.controllers;
import eu.eudat.data.query.items.table.organisations.OrganisationsTableRequest; import eu.eudat.data.query.items.table.organisations.OrganisationsTableRequest;
import eu.eudat.logic.managers.OrganisationsManager; import eu.eudat.logic.managers.OrganisationsManager;
import eu.eudat.logic.proxy.config.ExternalUrlCriteria;
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet; import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
import eu.eudat.logic.proxy.config.exceptions.NoURLFound; import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.data.dmp.Organisation; import eu.eudat.models.data.dmp.Organisation;
import eu.eudat.models.data.external.OrganisationsExternalSourcesModel;
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;
@ -19,7 +17,6 @@ import org.springframework.web.bind.annotation.*;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.List; import java.util.List;
import java.util.Map;
@RestController @RestController
@ -28,6 +25,8 @@ import java.util.Map;
public class Organisations extends BaseController { public class Organisations extends BaseController {
private OrganisationsManager organisationsManager; private OrganisationsManager organisationsManager;
private ApiContext apiContext;
@Autowired @Autowired
public Organisations(ApiContext apiContext, OrganisationsManager organisationsManager) { public Organisations(ApiContext apiContext, OrganisationsManager organisationsManager) {
super(apiContext); super(apiContext);
@ -36,13 +35,11 @@ public class Organisations extends BaseController {
@RequestMapping(method = RequestMethod.GET, value = {"/external/organisations"}, produces = "application/json") @RequestMapping(method = RequestMethod.GET, value = {"/external/organisations"}, produces = "application/json")
public @ResponseBody public @ResponseBody
ResponseEntity<ResponseItem<OrganisationsExternalSourcesModel>> listExternalOrganisations( ResponseEntity<ResponseItem<List<Organisation>>> listExternalOrganisations(
@RequestParam(value = "query", required = false) String query, @RequestParam(value = "type", required = false) String type @RequestParam(value = "query", required = false) String query, @RequestParam(value = "type", required = false) String type
) throws HugeResultSet, NoURLFound { ) throws HugeResultSet, NoURLFound {
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query); List<Organisation> organisations = organisationsManager.getCriteriaWithExternal(query, type);
List<Map<String, String>> remoteRepos = this.getApiContext().getOperationsContext().getRemoteFetcher().getOrganisations(externalUrlCriteria, type); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Organisation>>().payload(organisations).status(ApiMessageCode.NO_MESSAGE));
OrganisationsExternalSourcesModel organisationsExternalSourcesModel = new OrganisationsExternalSourcesModel().fromExternalItem(remoteRepos);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<OrganisationsExternalSourcesModel>().payload(organisationsExternalSourcesModel).status(ApiMessageCode.NO_MESSAGE));
} }
@RequestMapping(method = RequestMethod.POST, value = {"/internal/organisations"}, produces = "application/json") @RequestMapping(method = RequestMethod.POST, value = {"/internal/organisations"}, produces = "application/json")

View File

@ -3,11 +3,13 @@ package eu.eudat.controllers;
import eu.eudat.data.entities.Funder; import eu.eudat.data.entities.Funder;
import eu.eudat.data.entities.Project; import eu.eudat.data.entities.Project;
import eu.eudat.logic.managers.*; import eu.eudat.logic.managers.DatasetManager;
import eu.eudat.logic.managers.QuickWizardManager;
import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.data.datasetwizard.DatasetWizardModel; import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
import eu.eudat.models.data.dmp.DataManagementPlan; import eu.eudat.models.data.dmp.DataManagementPlan;
import eu.eudat.models.data.helpers.responses.ResponseItem; import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.models.data.quickwizard.DatasetCreateWizardModel;
import eu.eudat.models.data.quickwizard.DatasetDescriptionQuickWizardModel; import eu.eudat.models.data.quickwizard.DatasetDescriptionQuickWizardModel;
import eu.eudat.models.data.quickwizard.QuickWizardModel; import eu.eudat.models.data.quickwizard.QuickWizardModel;
import eu.eudat.models.data.security.Principal; import eu.eudat.models.data.security.Principal;
@ -16,7 +18,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import eu.eudat.models.data.quickwizard.DatasetCreateWizardModel;
import javax.transaction.Transactional; import javax.transaction.Transactional;
import javax.validation.Valid; import javax.validation.Valid;
@ -47,7 +48,6 @@ public class QuickWizardController extends BaseController {
if (quickWizard.getFunder() == null) { if (quickWizard.getFunder() == null) {
throw new Exception("Funder is a mandatory entity"); throw new Exception("Funder is a mandatory entity");
} else if (quickWizard.getFunder().getExistFunder() == null && quickWizard.getFunder().getLabel() == null) { } else if (quickWizard.getFunder().getExistFunder() == null && quickWizard.getFunder().getLabel() == null) {
// funderEntity = null;
throw new Exception("Funder is a mandatory entity"); throw new Exception("Funder is a mandatory entity");
} else if (quickWizard.getFunder().getExistFunder() == null && quickWizard.getFunder().getLabel() != null) { } else if (quickWizard.getFunder().getExistFunder() == null && quickWizard.getFunder().getLabel() != null) {
funderEntity = this.quickWizardManager.createOrUpdate(quickWizard.getFunder().toDataFunder(), principal); funderEntity = this.quickWizardManager.createOrUpdate(quickWizard.getFunder().toDataFunder(), principal);
@ -57,7 +57,11 @@ public class QuickWizardController extends BaseController {
eu.eudat.data.entities.Grant grantEntity; eu.eudat.data.entities.Grant grantEntity;
//Create Grant //Create Grant
if (quickWizard.getGrant().getExistGrant() == null) { if (quickWizard.getGrant() == null) {
throw new Exception("Grant is a mandatory entity");
} else if (quickWizard.getGrant().getExistGrant() == null && quickWizard.getGrant().getLabel() == null) {
throw new Exception("Grant is a mandatory entity");
} else if (quickWizard.getGrant().getExistGrant() == null) {
grantEntity = this.quickWizardManager.createOrUpdate(quickWizard.getGrant().toDataGrant(), principal); grantEntity = this.quickWizardManager.createOrUpdate(quickWizard.getGrant().toDataGrant(), principal);
} else { } else {
grantEntity = quickWizard.getGrant().getExistGrant().toDataModel(); grantEntity = quickWizard.getGrant().getExistGrant().toDataModel();
@ -68,17 +72,15 @@ public class QuickWizardController extends BaseController {
if (quickWizard.getProject().getExistProject() == null if (quickWizard.getProject().getExistProject() == null
&& quickWizard.getProject().getLabel() == null) { && quickWizard.getProject().getLabel() == null) {
projectEntity = null; projectEntity = null;
} else if (quickWizard.getProject().getExistProject() == null && quickWizard.getProject().getLabel() != null){ } else if (quickWizard.getProject().getExistProject() == null && quickWizard.getProject().getLabel() != null) {
projectEntity = this.quickWizardManager.createOrUpdate(quickWizard.getProject().toDataProject(), principal); projectEntity = this.quickWizardManager.createOrUpdate(quickWizard.getProject().toDataProject(), principal);
} else { } else {
projectEntity = quickWizard.getProject().getExistProject().toDataModel(); projectEntity = quickWizard.getProject().getExistProject().toDataModel();
} }
//Create Dmp //Create Dmp
eu.eudat.data.entities.DMP dmpEntity = this.quickWizardManager.createOrUpdate( DataManagementPlan dataManagementPlan = quickWizard.getDmp().toDataDmp(grantEntity, projectEntity, principal);
quickWizard.getDmp().toDataDmp(grantEntity, projectEntity, principal), eu.eudat.data.entities.DMP dmpEntity = this.quickWizardManager.createOrUpdate(dataManagementPlan, funderEntity, principal);
funderEntity,
principal);
//Create Datasets //Create Datasets
quickWizard.getDmp().setId(dmpEntity.getId()); quickWizard.getDmp().setId(dmpEntity.getId());

View File

@ -42,10 +42,10 @@ public class Registries extends BaseController {
@Transactional @Transactional
@RequestMapping(method = RequestMethod.POST, value = {"/registries"}, consumes = "application/json", produces = "application/json") @RequestMapping(method = RequestMethod.POST, value = {"/registries"}, consumes = "application/json", produces = "application/json")
public @ResponseBody public @ResponseBody
ResponseEntity<ResponseItem<Registry>> create(@RequestBody RegistryModel registryModel, Principal principal) throws Exception { ResponseEntity<ResponseItem<RegistryModel>> create(@RequestBody RegistryModel registryModel, Principal principal) throws Exception {
Registry registry = this.registryManager.create(registryModel, principal); Registry registry = this.registryManager.create(registryModel, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Registry>().payload(registry).status(ApiMessageCode.SUCCESS_MESSAGE)); RegistryModel registryModel1 = new RegistryModel().fromDataModel(registry);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<RegistryModel>().payload(registryModel1).status(ApiMessageCode.SUCCESS_MESSAGE));
} }
} }

View File

@ -43,9 +43,10 @@ public class Services extends BaseController {
@Transactional @Transactional
@RequestMapping(method = RequestMethod.POST, value = {"/services"}, consumes = "application/json", produces = "application/json") @RequestMapping(method = RequestMethod.POST, value = {"/services"}, consumes = "application/json", produces = "application/json")
public @ResponseBody public @ResponseBody
ResponseEntity<ResponseItem<Service>> create(@RequestBody ServiceModel serviceModel, Principal principal) throws Exception { ResponseEntity<ResponseItem<ServiceModel>> create(@RequestBody ServiceModel serviceModel, Principal principal) throws Exception {
Service service = serviceManager.create(serviceModel, principal); Service service = serviceManager.create(serviceModel, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Service>().payload(service).status(ApiMessageCode.SUCCESS_MESSAGE)); ServiceModel serviceModel1 = new ServiceModel().fromDataModel(service);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ServiceModel>().payload(serviceModel1).status(ApiMessageCode.SUCCESS_MESSAGE));
} }
} }

View File

@ -4,11 +4,12 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter; import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.SerializationFeature;
import eu.eudat.core.logger.Logger;
import eu.eudat.core.models.exception.ApiExceptionLoggingModel; import eu.eudat.core.models.exception.ApiExceptionLoggingModel;
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.types.ApiMessageCode; import eu.eudat.types.ApiMessageCode;
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.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ControllerAdvice;
@ -27,13 +28,14 @@ import java.util.Map;
@ControllerAdvice @ControllerAdvice
@Priority(5) @Priority(5)
public class ControllerErrorHandler { public class ControllerErrorHandler {
private static final Logger logger = LoggerFactory.getLogger(ControllerErrorHandler.class);
private Logger logger; // private Logger logger;
@Autowired /*@Autowired
public ControllerErrorHandler(Logger logger) { public ControllerErrorHandler(Logger logger) {
this.logger = logger; this.logger = logger;
} }*/
@ExceptionHandler(Exception.class) @ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.BAD_REQUEST) @ResponseStatus(HttpStatus.BAD_REQUEST)
@ -49,12 +51,11 @@ public class ControllerErrorHandler {
exceptionMap.put("exception", json); exceptionMap.put("exception", json);
apiExceptionLoggingModel.setData(ow.writeValueAsString(exceptionMap)); apiExceptionLoggingModel.setData(ow.writeValueAsString(exceptionMap));
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
apiExceptionLoggingModel.setMessage(ex.getMessage()); apiExceptionLoggingModel.setMessage(ex.getMessage());
apiExceptionLoggingModel.setType(LoggingType.ERROR); apiExceptionLoggingModel.setType(LoggingType.ERROR);
ex.printStackTrace(); logger.error(ex.getMessage(), ex);
this.logger.error(apiExceptionLoggingModel);
return new ResponseItem<Exception>().message(ex.getMessage()).status(ApiMessageCode.DEFAULT_ERROR_MESSAGE); return new ResponseItem<Exception>().message(ex.getMessage()).status(ApiMessageCode.DEFAULT_ERROR_MESSAGE);
} }
} }

View File

@ -1,7 +1,8 @@
package eu.eudat.controllers.controllerhandler; package eu.eudat.controllers.controllerhandler;
import eu.eudat.core.logger.Logger;
import eu.eudat.exceptions.security.UnauthorisedException; import eu.eudat.exceptions.security.UnauthorisedException;
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.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
@ -18,19 +19,19 @@ import javax.annotation.Priority;
@ControllerAdvice @ControllerAdvice
@Priority(4) @Priority(4)
public class ControllerUnauthorisedHandler { public class ControllerUnauthorisedHandler {
private static final Logger logger = LoggerFactory.getLogger(ControllerUnauthorisedHandler.class);
private Logger logger; // private Logger logger;
@Autowired @Autowired
public ControllerUnauthorisedHandler(Logger logger) { public ControllerUnauthorisedHandler(/*Logger logger*/) {
this.logger = logger; // this.logger = logger;
} }
@ExceptionHandler(UnauthorisedException.class) @ExceptionHandler(UnauthorisedException.class)
@ResponseStatus(HttpStatus.UNAUTHORIZED) @ResponseStatus(HttpStatus.UNAUTHORIZED)
@ResponseBody @ResponseBody
public void processValidationError(UnauthorisedException ex) { public void processValidationError(UnauthorisedException ex) {
this.logger.error(ex, ex.getMessage()); logger.error(ex.getMessage(), ex);
return; return;
} }
} }

View File

@ -2,6 +2,8 @@ package eu.eudat.controllers.interceptors;
import eu.eudat.logic.services.helpers.LoggerService; import eu.eudat.logic.services.helpers.LoggerService;
import eu.eudat.types.WarningLevel; import eu.eudat.types.WarningLevel;
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.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
@ -15,19 +17,19 @@ import java.util.Date;
*/ */
@Component @Component
public class RequestInterceptor extends HandlerInterceptorAdapter { public class RequestInterceptor extends HandlerInterceptorAdapter {
private static final Logger logger = LoggerFactory.getLogger(RequestInterceptor.class);
private LoggerService loggerService; // private LoggerService loggerService;
@Autowired @Autowired
public RequestInterceptor(LoggerService loggerService) { public RequestInterceptor(/*LoggerService loggerService*/) {
this.loggerService = loggerService; // this.loggerService = loggerService;
} }
@Override @Override
public boolean preHandle(HttpServletRequest request, public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception { HttpServletResponse response, Object handler) throws Exception {
String reqUri = request.getRequestURI(); String reqUri = request.getRequestURI();
this.loggerService.log("Call to " + reqUri + " method: " + request.getMethod() + " at: " + new Date(), WarningLevel.INFO); logger.info("Call to " + reqUri + " method: " + request.getMethod() + " at: " + new Date(), WarningLevel.INFO);
return super.preHandle(request, response, handler); return super.preHandle(request, response, handler);
} }
} }

View File

@ -7,9 +7,7 @@ import eu.eudat.logic.builders.model.criteria.RegistryCriteriaBuilder;
import eu.eudat.logic.builders.model.models.*; import eu.eudat.logic.builders.model.models.*;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/**
* Created by ikalyvas on 2/15/2018.
*/
@Service("builderFactory") @Service("builderFactory")
public class BuilderFactoryImpl implements BuilderFactory { public class BuilderFactoryImpl implements BuilderFactory {
@ -29,6 +27,7 @@ public class BuilderFactoryImpl implements BuilderFactory {
if (tClass.equals(ResearcherBuilder.class)) return (T) new ResearcherBuilder(); if (tClass.equals(ResearcherBuilder.class)) return (T) new ResearcherBuilder();
if (tClass.equals(ExternalDatasetCriteriaBuilder.class)) return (T) new ExternalDatasetCriteriaBuilder(); if (tClass.equals(ExternalDatasetCriteriaBuilder.class)) return (T) new ExternalDatasetCriteriaBuilder();
if (tClass.equals(RecentActivityDataBuilder.class)) return (T) new RecentActivityDataBuilder(); if (tClass.equals(RecentActivityDataBuilder.class)) return (T) new RecentActivityDataBuilder();
if (tClass.equals(OrganisationBuilder.class)) return (T) new OrganisationBuilder();
return null; return null;
} }

View File

@ -17,6 +17,7 @@ public class FunderBuilder extends Builder<Funder> {
private Date modified; private Date modified;
private Integer type; private Integer type;
private String source; private String source;
private String key;
public FunderBuilder id(UUID id) { public FunderBuilder id(UUID id) {
this.id = id; this.id = id;
@ -63,6 +64,11 @@ public class FunderBuilder extends Builder<Funder> {
return this; return this;
} }
public FunderBuilder key(String key) {
this.key = key;
return this;
}
@Override @Override
public Funder build() { public Funder build() {
Funder funder = new Funder(); Funder funder = new Funder();
@ -75,6 +81,7 @@ public class FunderBuilder extends Builder<Funder> {
funder.setModified(modified); funder.setModified(modified);
funder.setType(type); funder.setType(type);
funder.setSource(source); funder.setSource(source);
funder.setKey(key);
return funder; return funder;
} }
} }

View File

@ -9,9 +9,6 @@ import java.util.Date;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
/**
* Created by ikalyvas on 2/15/2018.
*/
public class GrantBuilder extends Builder<Grant> { public class GrantBuilder extends Builder<Grant> {
private UUID id; private UUID id;
@ -44,6 +41,8 @@ public class GrantBuilder extends Builder<Grant> {
private String source; private String source;
private String key;
public GrantBuilder id(UUID id) { public GrantBuilder id(UUID id) {
this.id = id; this.id = id;
return this; return this;
@ -119,6 +118,11 @@ public class GrantBuilder extends Builder<Grant> {
return this; return this;
} }
public GrantBuilder key(String key) {
this.key = key;
return this;
}
@Override @Override
public Grant build() { public Grant build() {
Grant grant = new Grant(); Grant grant = new Grant();
@ -137,6 +141,7 @@ public class GrantBuilder extends Builder<Grant> {
grant.setCreationUser(creationUser); grant.setCreationUser(creationUser);
grant.setStartDate(startDate); grant.setStartDate(startDate);
grant.setSource(source); grant.setSource(source);
grant.setKey(key);
return grant; return grant;
} }
} }

View File

@ -0,0 +1,88 @@
package eu.eudat.logic.builders.model.models;
import eu.eudat.logic.builders.Builder;
import eu.eudat.models.data.dmp.Organisation;
public class OrganisationBuilder extends Builder<Organisation> {
private String label;
private String name;
private String id;
private String reference;
private int status;
private String tag;
private String key;
public String getLabel() {
return label;
}
public OrganisationBuilder label(String label) {
this.label = label;
return this;
}
public String getName() {
return name;
}
public OrganisationBuilder name(String name) {
this.name = name;
return this;
}
public String getId() {
return id;
}
public OrganisationBuilder id(String id) {
this.id = id;
return this;
}
public String getReference() { return reference; }
public OrganisationBuilder reference(String reference) {
this.reference = reference;
return this;
}
public int getStatus() {
return status;
}
public OrganisationBuilder status(int status) {
this.status = status;
return this;
}
public String getTag() {
return tag;
}
public OrganisationBuilder tag(String tag) {
this.tag = tag;
return this;
}
public String getKey() {
return key;
}
public OrganisationBuilder key(String key) {
this.key = key;
return this;
}
@Override
public Organisation build() {
Organisation Organisation = new Organisation();
Organisation.setId(id);
Organisation.setReference(reference);
Organisation.setLabel(label);
Organisation.setName(name);
Organisation.setStatus(status);
Organisation.setTag(tag);
Organisation.setKey(key);
return Organisation;
}
}

View File

@ -28,6 +28,7 @@ public class ProjectBuilder extends Builder<Project> {
private Date modified; private Date modified;
private String description; private String description;
private String source; private String source;
private String key;
public ProjectBuilder id(UUID id) { public ProjectBuilder id(UUID id) {
this.id = id; this.id = id;
@ -109,6 +110,11 @@ public class ProjectBuilder extends Builder<Project> {
return this; return this;
} }
public ProjectBuilder key(String key) {
this.key = key;
return this;
}
@Override @Override
public Project build() { public Project build() {
Project project = new Project(); Project project = new Project();
@ -127,6 +133,7 @@ public class ProjectBuilder extends Builder<Project> {
project.setCreationUser(creationUser); project.setCreationUser(creationUser);
project.setStartDate(startDate); project.setStartDate(startDate);
project.setSource(source); project.setSource(source);
project.setKey(key);
return project; return project;
} }
} }

View File

@ -3,15 +3,14 @@ package eu.eudat.logic.builders.model.models;
import eu.eudat.logic.builders.Builder; import eu.eudat.logic.builders.Builder;
import eu.eudat.models.data.dmp.Researcher; import eu.eudat.models.data.dmp.Researcher;
/**
* Created by ikalyvas on 3/6/2018.
*/
public class ResearcherBuilder extends Builder<Researcher> { public class ResearcherBuilder extends Builder<Researcher> {
private String label; private String label;
private String name; private String name;
private String id; private String id;
private String reference;
private int status; private int status;
private String tag; private String tag;
private String key;
public String getLabel() { public String getLabel() {
return label; return label;
@ -40,6 +39,13 @@ public class ResearcherBuilder extends Builder<Researcher> {
return this; return this;
} }
public String getReference() { return reference; }
public ResearcherBuilder reference(String reference) {
this.reference = reference;
return this;
}
public int getStatus() { public int getStatus() {
return status; return status;
} }
@ -58,14 +64,25 @@ public class ResearcherBuilder extends Builder<Researcher> {
return this; return this;
} }
public String getKey() {
return key;
}
public ResearcherBuilder key(String key) {
this.key = key;
return this;
}
@Override @Override
public Researcher build() { public Researcher build() {
Researcher researcher = new Researcher(); Researcher researcher = new Researcher();
researcher.setId(id); researcher.setId(id);
researcher.setReference(reference);
researcher.setLabel(label); researcher.setLabel(label);
researcher.setName(name); researcher.setName(name);
researcher.setStatus(status); researcher.setStatus(status);
researcher.setTag(tag); researcher.setTag(tag);
researcher.setKey(key);
return researcher; return researcher;
} }
} }

View File

@ -80,7 +80,7 @@ public class DashBoardManager {
List<Integer> roles = new LinkedList<>(); List<Integer> roles = new LinkedList<>();
CompletableFuture dmpFuture = dataManagementPlanRepository.getAuthenticated(dataManagementPlanRepository.getWithCriteria(dataManagementPlanCriteria), principal.getId(), roles).countAsync() CompletableFuture dmpFuture = dataManagementPlanRepository.getAuthenticated(dataManagementPlanRepository.getWithCriteria(dataManagementPlanCriteria), principal.getId(), roles).countAsync()
.whenComplete((dmpsStats, throwable) -> statistics.setTotalDataManagementPlanCount(dmpsStats)); .whenComplete((dmpsStats, throwable) -> statistics.setTotalDataManagementPlanCount(dmpsStats));
CompletableFuture datasetFuture = datasetRepository.getAuthenticated(datasetRepository.getWithCriteria(datasetCriteria), user).countAsync() CompletableFuture datasetFuture = datasetRepository.getAuthenticated(datasetRepository.getWithCriteria(datasetCriteria), user, roles).countAsync()
.whenComplete((datasetsStats, throwable) -> statistics.setTotalDataSetCount(datasetsStats)); .whenComplete((datasetsStats, throwable) -> statistics.setTotalDataSetCount(datasetsStats));
CompletableFuture grantFuture = grantRepository.getAuthenticated(grantRepository.getWithCriteria(grantCriteria), user).countAsync() CompletableFuture grantFuture = grantRepository.getAuthenticated(grantRepository.getWithCriteria(grantCriteria), user).countAsync()
.whenComplete((grantsStats, throwable) -> statistics.setTotalGrantCount(grantsStats)); .whenComplete((grantsStats, throwable) -> statistics.setTotalGrantCount(grantsStats));
@ -113,7 +113,7 @@ public class DashBoardManager {
.selectAsync(item -> recentActivityDataBuilder.label(item.getLabel()).timestamp(item.getModified()).id(item.getId().toString()).build()) .selectAsync(item -> recentActivityDataBuilder.label(item.getLabel()).timestamp(item.getModified()).id(item.getId().toString()).build())
.whenComplete((dmpActivities, throwable) -> activity.setRecentDmpActivities(dmpActivities)); .whenComplete((dmpActivities, throwable) -> activity.setRecentDmpActivities(dmpActivities));
CompletableFuture<List<RecentActivityData>> datasets = datasetRepository.getAuthenticated(datasetRepository.getWithCriteria(datasetCriteria), user) CompletableFuture<List<RecentActivityData>> datasets = datasetRepository.getAuthenticated(datasetRepository.getWithCriteria(datasetCriteria), user, roles)
.withHint("datasetRecentActivity") .withHint("datasetRecentActivity")
.orderBy((builder, root) -> builder.desc(root.get("modified"))) .orderBy((builder, root) -> builder.desc(root.get("modified")))
.take(numberofactivities) .take(numberofactivities)
@ -132,7 +132,6 @@ public class DashBoardManager {
} }
public List<SearchBarItem> searchUserData(String like, Principal principal) { public List<SearchBarItem> searchUserData(String like, Principal principal) {
RecentActivity activity = new RecentActivity();
UserInfo user = new UserInfo(); UserInfo user = new UserInfo();
user.setId(principal.getId()); user.setId(principal.getId());
DMPDao dataManagementPlanRepository = databaseRepository.getDmpDao(); DMPDao dataManagementPlanRepository = databaseRepository.getDmpDao();
@ -141,29 +140,53 @@ public class DashBoardManager {
List<Integer> roles = new LinkedList<>(); List<Integer> roles = new LinkedList<>();
List<SearchBarItem> searchBarItems = new LinkedList<>(); List<SearchBarItem> searchBarItems = new LinkedList<>();
CompletableFuture<List<SearchBarItem>> dmps = dataManagementPlanRepository.getAuthenticated(dataManagementPlanRepository.asQueryable(), principal.getId(), roles)
.withHint("dmpRecentActivity") CompletableFuture<List<SearchBarItem>> publicDmps = dataManagementPlanRepository.asQueryable()
.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + like.toUpperCase() + "%")) .where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + like.toUpperCase() + "%"))
.where((builder, root) -> builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue()))
.where((builder, root) -> builder.equal(root.get("isPublic"), true))
.orderBy((builder, root) -> builder.desc(root.get("modified"))) .orderBy((builder, root) -> builder.desc(root.get("modified")))
.selectAsync(item -> new SearchBarItem(item.getId().toString(), item.getLabel(), SearchBarItemType.DMP.getValue())) .selectAsync(item -> new SearchBarItem(item.getId().toString(), item.getLabel(), SearchBarItemType.DMP.getValue(), true))
.whenComplete((dmpItems, throwable) -> searchBarItems.addAll(dmpItems)); .whenComplete((dmpItems, throwable) -> searchBarItems.addAll(dmpItems));
CompletableFuture<List<SearchBarItem>> datasets = datasetRepository.getAuthenticated(datasetRepository.asQueryable(), user) CompletableFuture<List<SearchBarItem>> publicDatasets = datasetRepository.asQueryable()
.withHint("datasetRecentActivity")
.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + like.toUpperCase() + "%")) .where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + like.toUpperCase() + "%"))
.where((builder, root) -> builder.equal(root.get("status"), Dataset.Status.FINALISED.getValue()))
.where((builder, root) -> builder.equal(root.get("dmp").get("isPublic"), true))
.orderBy((builder, root) -> builder.desc(root.get("modified"))) .orderBy((builder, root) -> builder.desc(root.get("modified")))
.selectAsync(item -> new SearchBarItem(item.getId().toString(), item.getLabel(), SearchBarItemType.DATASET.getValue())) .selectAsync(item -> new SearchBarItem(item.getId().toString(), item.getLabel(), SearchBarItemType.DATASET.getValue(), true))
.whenComplete((dataSetItems, throwable) -> searchBarItems.addAll(dataSetItems)); .whenComplete((dataSetItems, throwable) -> searchBarItems.addAll(dataSetItems));
CompletableFuture<List<SearchBarItem>> grants = grantRepository.getAuthenticated(grantRepository.asQueryable(), user) if (principal.getId() != null) {
.withHint("grantRecentActivity") CompletableFuture<List<SearchBarItem>> dmps = dataManagementPlanRepository.getAuthenticated(dataManagementPlanRepository.asQueryable(), principal.getId(), roles)
.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + like.toUpperCase() + "%")) .withHint("dmpRecentActivity")
.orderBy((builder, root) -> builder.desc(root.get("modified"))) .where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + like.toUpperCase() + "%"))
.selectAsync(item -> new SearchBarItem(item.getId().toString(), item.getLabel(), SearchBarItemType.GRANT.getValue())) .where((builder, root) -> builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue()))
.whenComplete((grantItems, throwable) -> searchBarItems.addAll(grantItems)); .orderBy((builder, root) -> builder.desc(root.get("modified")))
.selectAsync(item -> new SearchBarItem(item.getId().toString(), item.getLabel(), SearchBarItemType.DMP.getValue(), false))
.whenComplete((dmpItems, throwable) -> searchBarItems.addAll(dmpItems));
CompletableFuture<List<SearchBarItem>> datasets = datasetRepository.getAuthenticated(datasetRepository.asQueryable(), user, roles)
.withHint("datasetRecentActivity")
.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + like.toUpperCase() + "%"))
.where((builder, root) -> builder.notEqual(root.get("status"), Dataset.Status.DELETED.getValue()))
.where((builder, root) -> builder.notEqual(root.get("status"), Dataset.Status.CANCELED.getValue()))
.orderBy((builder, root) -> builder.desc(root.get("modified")))
.selectAsync(item -> new SearchBarItem(item.getId().toString(), item.getLabel(), SearchBarItemType.DATASET.getValue(), false))
.whenComplete((dataSetItems, throwable) -> searchBarItems.addAll(dataSetItems));
CompletableFuture<List<SearchBarItem>> grants = grantRepository.getAuthenticated(grantRepository.asQueryable(), user)
.withHint("grantRecentActivity")
.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + like.toUpperCase() + "%"))
.orderBy((builder, root) -> builder.desc(root.get("modified")))
.selectAsync(item -> new SearchBarItem(item.getId().toString(), item.getLabel(), SearchBarItemType.GRANT.getValue(), false))
.whenComplete((grantItems, throwable) -> searchBarItems.addAll(grantItems));
CompletableFuture.allOf(grants, dmps, datasets, publicDmps, publicDatasets).join();
} else {
CompletableFuture.allOf(publicDmps, publicDatasets).join();
}
CompletableFuture.allOf(grants, dmps, datasets).join();
return searchBarItems; return searchBarItems;
} }
} }

View File

@ -1,5 +1,6 @@
package eu.eudat.logic.managers; package eu.eudat.logic.managers;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.configurations.dynamicgrant.DynamicGrantConfiguration; import eu.eudat.configurations.dynamicgrant.DynamicGrantConfiguration;
import eu.eudat.configurations.dynamicgrant.entities.Property; import eu.eudat.configurations.dynamicgrant.entities.Property;
@ -49,6 +50,8 @@ import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph; import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun; import org.apache.poi.xwpf.usermodel.XWPFRun;
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.core.io.FileSystemResource; import org.springframework.core.io.FileSystemResource;
@ -68,15 +71,14 @@ import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller; import javax.xml.bind.Unmarshaller;
import java.io.*; import java.io.*;
import java.math.BigInteger; import java.math.BigInteger;
import java.net.URL;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths;
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;
@Component @Component
public class DataManagementPlanManager { public class DataManagementPlanManager {
private static final Logger logger = LoggerFactory.getLogger(DataManagementPlanManager.class);
private ApiContext apiContext; private ApiContext apiContext;
private DatasetManager datasetManager; private DatasetManager datasetManager;
@ -105,7 +107,6 @@ public class DataManagementPlanManager {
CompletableFuture itemsFuture; CompletableFuture itemsFuture;
if (fieldsGroup.equals("listing")) { if (fieldsGroup.equals("listing")) {
itemsFuture = pagedItems.withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class)) itemsFuture = pagedItems.withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class))
.selectAsync(item -> { .selectAsync(item -> {
item.setDataset( item.setDataset(
@ -119,15 +120,17 @@ public class DataManagementPlanManager {
return new DataManagementPlanListingModel().fromDataModelDatasets(item); return new DataManagementPlanListingModel().fromDataModelDatasets(item);
}) })
.whenComplete((resultList, throwable) -> dataTable.setData(resultList)); .whenComplete((resultList, throwable) -> dataTable.setData(resultList));
} else if (fieldsGroup.equals("autocomplete")) {
itemsFuture = pagedItems
.selectAsync(item -> new DataManagementPlanListingModel().fromDataModelAutoComplete(item))
.whenComplete((resultList, throwable) -> dataTable.setData(resultList));
} else { } else {
itemsFuture = pagedItems itemsFuture = pagedItems
.selectAsync(item -> new DataManagementPlanListingModel().fromDataModelAssociatedProfiles(item)) .selectAsync(item -> new DataManagementPlanListingModel().fromDataModelAssociatedProfiles(item))
.whenComplete((resultList, throwable) -> dataTable.setData(resultList)); .whenComplete((resultList, throwable) -> dataTable.setData(resultList));
} }
CompletableFuture countFuture = authItems.countAsync().whenComplete((count, throwable) -> CompletableFuture countFuture = authItems.countAsync().whenComplete((count, throwable) -> dataTable.setTotalCount(count));
dataTable.setTotalCount(count)
);
CompletableFuture.allOf(itemsFuture, countFuture).join(); CompletableFuture.allOf(itemsFuture, countFuture).join();
return dataTable; return dataTable;
} }
@ -311,7 +314,7 @@ public class DataManagementPlanManager {
try { try {
wordBuilder.build(document, pagedDatasetProfile, visibilityRuleService); wordBuilder.build(document, pagedDatasetProfile, visibilityRuleService);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
// Page break at the end of the Dataset. // Page break at the end of the Dataset.
XWPFParagraph parBreakDataset = document.createParagraph(); XWPFParagraph parBreakDataset = document.createParagraph();
@ -341,34 +344,31 @@ public class DataManagementPlanManager {
return this.datasetManager.convertToPDF(file, environment, fileName); return this.datasetManager.convertToPDF(file, environment, fileName);
}*/ }*/
public eu.eudat.models.data.dmp.DataManagementPlan getSingle(String id, Principal principal, DynamicGrantConfiguration dynamicGrantConfiguration) throws InstantiationException, IllegalAccessException { public eu.eudat.models.data.dmp.DataManagementPlan getSingle(String id, Principal principal) {
DMP dataManagementPlanEntity = databaseRepository.getDmpDao().find(UUID.fromString(id)); DMP dataManagementPlanEntity = databaseRepository.getDmpDao().find(UUID.fromString(id));
if (dataManagementPlanEntity.getUsers().stream().filter(userInfo -> userInfo.getUser().getId() == principal.getId()).collect(Collectors.toList()).size() == 0) if (dataManagementPlanEntity.getUsers().stream().noneMatch(userInfo -> userInfo.getUser().getId() == principal.getId())) {
throw new UnauthorisedException(); if (!dataManagementPlanEntity.isPublic()) {
eu.eudat.models.data.dmp.DataManagementPlan datamanagementPlan = new eu.eudat.models.data.dmp.DataManagementPlan(); throw new UnauthorisedException();
datamanagementPlan.fromDataModel(dataManagementPlanEntity); }
}
eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan = new eu.eudat.models.data.dmp.DataManagementPlan();
dataManagementPlan.fromDataModel(dataManagementPlanEntity);
Map dmpProperties = dataManagementPlanEntity.getDmpProperties() != null ? new org.json.JSONObject(dataManagementPlanEntity.getDmpProperties()).toMap() : null; Map dmpProperties = dataManagementPlanEntity.getDmpProperties() != null ? new org.json.JSONObject(dataManagementPlanEntity.getDmpProperties()).toMap() : null;
// datamanagementPlan.setDynamicFields(dynamicGrantConfiguration.getFields().stream().map(item -> {
// DynamicFieldWithValue fieldWithValue = new DynamicFieldWithValue();
// fieldWithValue.setId(item.getId());
// fieldWithValue.setDependencies(item.getDependencies());
// fieldWithValue.setName(item.getName());
// fieldWithValue.setQueryProperty(item.getQueryProperty());
// fieldWithValue.setRequired(item.getRequired());
// return fieldWithValue;
// }).collect(Collectors.toList()));
if (dmpProperties != null && datamanagementPlan.getDynamicFields() != null) if (dmpProperties != null && dataManagementPlan.getDynamicFields() != null)
datamanagementPlan.getDynamicFields().forEach(item -> { dataManagementPlan.getDynamicFields().forEach(item -> {
Map<String, String> properties = (Map<String, String>) dmpProperties.get(item.getId()); Map<String, String> properties = (Map<String, String>) dmpProperties.get(item.getId());
if (properties != null) if (properties != null)
item.setValue(new Tuple<>(properties.get("id"), properties.get("label"))); item.setValue(new Tuple<>(properties.get("id"), properties.get("label")));
}); });
return datamanagementPlan; return dataManagementPlan;
} }
public DataManagementPlanOverviewModel getOverviewSingle(String id, Principal principal) throws InstantiationException, IllegalAccessException { public DataManagementPlanOverviewModel getOverviewSingle(String id, Principal principal) throws Exception {
DMP dataManagementPlanEntity = databaseRepository.getDmpDao().find(UUID.fromString(id)); DMP dataManagementPlanEntity = databaseRepository.getDmpDao().find(UUID.fromString(id));
if (dataManagementPlanEntity.getStatus() == DMP.DMPStatus.DELETED.getValue()) {
throw new Exception("DMP is deleted.");
}
if (dataManagementPlanEntity.getUsers() if (dataManagementPlanEntity.getUsers()
.stream().filter(userInfo -> userInfo.getUser().getId() == principal.getId()) .stream().filter(userInfo -> userInfo.getUser().getId() == principal.getId())
.collect(Collectors.toList()).size() == 0) .collect(Collectors.toList()).size() == 0)
@ -478,10 +478,13 @@ public class DataManagementPlanManager {
if (dataManagementPlan.getId() != null) { if (dataManagementPlan.getId() != null) {
DMP dmp1 = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(dataManagementPlan.getId()); DMP dmp1 = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(dataManagementPlan.getId());
if (!isUserOwnerOfDmp(dmp1, principal)) {
throw new Exception("User not being the creator is not authorized to edit this DMP.");
}
List<Dataset> datasetList = new ArrayList<>(dmp1.getDataset()); List<Dataset> datasetList = new ArrayList<>(dmp1.getDataset());
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 Dataest Description is missing from the DMP."); throw new Exception("Dataset Template for Dataset Description is missing from the DMP.");
} }
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.");
@ -566,7 +569,7 @@ public class DataManagementPlanManager {
} }
public void assignUser(DMP dmp, UserInfo userInfo) { private void assignUser(DMP dmp, UserInfo userInfo) {
UserDMP userDMP = new UserDMP(); UserDMP userDMP = new UserDMP();
userDMP.setDmp(dmp); userDMP.setDmp(dmp);
userDMP.setUser(userInfo); userDMP.setUser(userInfo);
@ -576,7 +579,9 @@ public class DataManagementPlanManager {
public void newVersion(UUID uuid, DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception { public void newVersion(UUID uuid, DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
DMP oldDmp = databaseRepository.getDmpDao().find(uuid); DMP oldDmp = databaseRepository.getDmpDao().find(uuid);
if (!isUserOwnerOfDmp(oldDmp, principal)) {
throw new Exception("User not being the creator is not authorized to perform this action.");
}
DataManagementPlanCriteria criteria = new DataManagementPlanCriteria(); DataManagementPlanCriteria criteria = new DataManagementPlanCriteria();
LinkedList<UUID> list = new LinkedList<>(); LinkedList<UUID> list = new LinkedList<>();
list.push(oldDmp.getGroupId()); list.push(oldDmp.getGroupId());
@ -587,7 +592,6 @@ public class DataManagementPlanManager {
if (latestVersionDMP.get(0).getVersion().equals(oldDmp.getVersion())) { if (latestVersionDMP.get(0).getVersion().equals(oldDmp.getVersion())) {
DMP newDmp = dataManagementPlan.toDataModel(); DMP newDmp = dataManagementPlan.toDataModel();
UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build(); UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
createOrganisationsIfTheyDontExist(newDmp, databaseRepository.getOrganisationDao()); createOrganisationsIfTheyDontExist(newDmp, databaseRepository.getOrganisationDao());
createResearchersIfTheyDontExist(newDmp, databaseRepository.getResearcherDao(), user); createResearchersIfTheyDontExist(newDmp, databaseRepository.getResearcherDao(), user);
@ -644,7 +648,6 @@ public class DataManagementPlanManager {
databaseRepository.getGrantDao().createOrUpdate(newDmp.getGrant()); databaseRepository.getGrantDao().createOrUpdate(newDmp.getGrant());
newDmp = databaseRepository.getDmpDao().createOrUpdate(newDmp); newDmp = databaseRepository.getDmpDao().createOrUpdate(newDmp);
// Assign creator.
assignUser(newDmp, user); assignUser(newDmp, user);
copyDatasets(newDmp, databaseRepository.getDatasetDao()); copyDatasets(newDmp, databaseRepository.getDatasetDao());
} }
@ -696,6 +699,7 @@ public class DataManagementPlanManager {
if (grantEntity != null) grant.setId(grantEntity.getId()); if (grantEntity != null) grant.setId(grantEntity.getId());
else { else {
grant.setType(Grant.GrantType.EXTERNAL.getValue()); grant.setType(Grant.GrantType.EXTERNAL.getValue());
grant.setCreationUser(null);
grantDao.createOrUpdate(grant); grantDao.createOrUpdate(grant);
} }
} }
@ -723,6 +727,7 @@ public class DataManagementPlanManager {
if (projectEntity != null) project.setId(projectEntity.getId()); if (projectEntity != null) project.setId(projectEntity.getId());
else { else {
project.setType(Project.ProjectType.EXTERNAL.getValue()); project.setType(Project.ProjectType.EXTERNAL.getValue());
if (project.getId() == null) project.setId(UUID.randomUUID());
projectDao.createOrUpdate(project); projectDao.createOrUpdate(project);
} }
} }
@ -785,11 +790,12 @@ public class DataManagementPlanManager {
if (newDataset.getDatasetDataRepositories() != null) { if (newDataset.getDatasetDataRepositories() != null) {
newDataset.setDatasetDataRepositories(newDataset.getDatasetDataRepositories().stream().map(item -> { newDataset.setDatasetDataRepositories(newDataset.getDatasetDataRepositories().stream().map(item -> {
DataRepository dataRepository = new DataRepository(); DataRepository dataRepository = new DataRepository();
dataRepository.setId(item.getId()); dataRepository.setId(item.getDataRepository().getId());
DatasetDataRepository datasetDataRepository = new DatasetDataRepository(); DatasetDataRepository datasetDataRepository = new DatasetDataRepository();
datasetDataRepository.setDataRepository(dataRepository); datasetDataRepository.setDataRepository(dataRepository);
datasetDataRepository.setDataset(newDataset); datasetDataRepository.setDataset(newDataset);
datasetDataRepository.setData(item.getData());
return datasetDataRepository; return datasetDataRepository;
}).collect(Collectors.toSet())); }).collect(Collectors.toSet()));
} }
@ -797,10 +803,11 @@ public class DataManagementPlanManager {
if (newDataset.getDatasetExternalDatasets() != null) { if (newDataset.getDatasetExternalDatasets() != null) {
newDataset.setDatasetExternalDatasets(newDataset.getDatasetExternalDatasets().stream().map(item -> { newDataset.setDatasetExternalDatasets(newDataset.getDatasetExternalDatasets().stream().map(item -> {
ExternalDataset externalDataset = new ExternalDataset(); ExternalDataset externalDataset = new ExternalDataset();
externalDataset.setId(item.getId()); externalDataset.setId(item.getExternalDataset().getId());
DatasetExternalDataset datasetExternalDataset = new DatasetExternalDataset(); DatasetExternalDataset datasetExternalDataset = new DatasetExternalDataset();
datasetExternalDataset.setExternalDataset(externalDataset); datasetExternalDataset.setExternalDataset(externalDataset);
datasetExternalDataset.setDataset(newDataset); datasetExternalDataset.setDataset(newDataset);
datasetExternalDataset.setData(item.getData());
return datasetExternalDataset; return datasetExternalDataset;
}).collect(Collectors.toSet())); }).collect(Collectors.toSet()));
} }
@ -820,6 +827,7 @@ public class DataManagementPlanManager {
DatasetService datasetService = new DatasetService(); DatasetService datasetService = new DatasetService();
datasetService.setService(service); datasetService.setService(service);
datasetService.setDataset(newDataset); datasetService.setDataset(newDataset);
datasetService.setData(item.getData());
return datasetService; return datasetService;
}).collect(Collectors.toSet())); }).collect(Collectors.toSet()));
} }
@ -833,7 +841,7 @@ public class DataManagementPlanManager {
} }
} }
public FileEnvelope getXmlDocument(String id, Principal principal) throws InstantiationException, IllegalAccessException, IOException { private FileEnvelope getXmlDocument(String id, Principal principal) throws InstantiationException, IllegalAccessException, IOException {
ExportXmlBuilder xmlBuilder = new ExportXmlBuilder(); ExportXmlBuilder xmlBuilder = new ExportXmlBuilder();
VisibilityRuleService visibilityRuleService = utilitiesService.getVisibilityRuleService(); VisibilityRuleService visibilityRuleService = utilitiesService.getVisibilityRuleService();
eu.eudat.data.entities.DMP dmp = databaseRepository.getDmpDao().find(UUID.fromString(id)); eu.eudat.data.entities.DMP dmp = databaseRepository.getDmpDao().find(UUID.fromString(id));
@ -868,14 +876,34 @@ public class DataManagementPlanManager {
} }
dmpElement.appendChild(dmpProfileElement); dmpElement.appendChild(dmpProfileElement);
// Funder.
Element funder = xmlDoc.createElement("funder");
Element funderLabel = xmlDoc.createElement("label");
Element funderId = xmlDoc.createElement("id");
funderLabel.setTextContent(dmp.getGrant().getFunder().getLabel());
funderId.setTextContent(dmp.getGrant().getFunder().getId().toString());
funder.appendChild(funderLabel);
funder.appendChild(funderId);
dmpElement.appendChild(funder);
// Grant.
Element grant = xmlDoc.createElement("grant"); Element grant = xmlDoc.createElement("grant");
Element label = xmlDoc.createElement("label"); Element grantLabel = xmlDoc.createElement("label");
label.setTextContent(dmp.getGrant().getLabel());
grant.appendChild(label);
Element grantId = xmlDoc.createElement("id"); Element grantId = xmlDoc.createElement("id");
grantLabel.setTextContent(dmp.getGrant().getLabel());
grantId.setTextContent(dmp.getGrant().getId().toString()); grantId.setTextContent(dmp.getGrant().getId().toString());
grant.appendChild(grantLabel);
grant.appendChild(grantId); grant.appendChild(grantId);
dmpElement.appendChild(grant); dmpElement.appendChild(grant);
// Project.
Element project = xmlDoc.createElement("project");
Element projectLabel = xmlDoc.createElement("label");
Element projectId = xmlDoc.createElement("id");
projectLabel.setTextContent(dmp.getProject().getLabel());
projectId.setTextContent(dmp.getProject().getId().toString());
project.appendChild(projectLabel);
project.appendChild(projectId);
dmpElement.appendChild(project);
Element organisationsElement = xmlDoc.createElement("organisations"); Element organisationsElement = xmlDoc.createElement("organisations");
for (Organisation organisation : dmp.getOrganisations()) { for (Organisation organisation : dmp.getOrganisations()) {
Element organisationElement = xmlDoc.createElement("organisation"); Element organisationElement = xmlDoc.createElement("organisation");
@ -944,20 +972,21 @@ public class DataManagementPlanManager {
return fileEnvelope; return fileEnvelope;
} }
public ResponseEntity<byte[]> getRDAJsonDocument(String id, Principal principal) throws IOException { public ResponseEntity<byte[]> getRDAJsonDocument(String id, DatasetManager datasetManager, Principal principal) throws IOException {
eu.eudat.data.entities.DMP dmp = databaseRepository.getDmpDao().find(UUID.fromString(id)); eu.eudat.data.entities.DMP dmp = databaseRepository.getDmpDao().find(UUID.fromString(id));
if (!dmp.isPublic() && dmp.getUsers().stream().filter(userInfo -> userInfo.getUser().getId() == principal.getId()).collect(Collectors.toList()).size() == 0) if (!dmp.isPublic() && dmp.getUsers().stream().noneMatch(userInfo -> userInfo.getUser().getId() == principal.getId()))
throw new UnauthorisedException(); throw new UnauthorisedException();
RDAExportModel rdaExportModel = new RDAExportModel().fromDataModel(dmp); RDAExportModel rdaExportModel = new RDAExportModel().fromDataModel(dmp, datasetManager);
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
String fileName = dmp.getLabel(); String fileName = dmp.getLabel();
fileName = fileName.replaceAll("[^a-zA-Z0-9+ ]", ""); fileName = fileName.replaceAll("[^a-zA-Z0-9+ ]", "");
File file = new File(fileName); File file = new File(fileName);
try { try {
mapper.writeValue(file, rdaExportModel); mapper.writeValue(file, rdaExportModel);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
InputStream resource = new FileInputStream(file); InputStream resource = new FileInputStream(file);
@ -1015,7 +1044,7 @@ public class DataManagementPlanManager {
DmpImportModel dmpImportModel = (DmpImportModel) jaxbUnmarshaller.unmarshal(in); DmpImportModel dmpImportModel = (DmpImportModel) jaxbUnmarshaller.unmarshal(in);
dataManagementPlans.add(dmpImportModel); dataManagementPlans.add(dmpImportModel);
} catch (IOException | JAXBException ex) { } catch (IOException | JAXBException ex) {
ex.printStackTrace(); logger.error(ex.getMessage(), ex);
} }
// TODO Iterate through the list of dataManagementPlans. // TODO Iterate through the list of dataManagementPlans.
// Creates new dataManagementPlan to fill it with the data model that was parsed from the xml. // Creates new dataManagementPlan to fill it with the data model that was parsed from the xml.
@ -1078,7 +1107,7 @@ public class DataManagementPlanManager {
//createOrUpdate(apiContext, dm, principal); //createOrUpdate(apiContext, dm, principal);
System.out.println(dm); logger.info(dm.toString());
} }
return dataManagementPlans; return dataManagementPlans;

View File

@ -21,6 +21,8 @@ import eu.eudat.models.data.listingmodels.DataManagementPlanProfileListingModel;
import eu.eudat.models.data.security.Principal; import eu.eudat.models.data.security.Principal;
import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.QueryableList;
import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.ApiContext;
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.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -43,6 +45,7 @@ import org.w3c.dom.Element;
*/ */
@Component @Component
public class DataManagementProfileManager { public class DataManagementProfileManager {
private static final Logger logger = LoggerFactory.getLogger(DataManagementProfileManager.class);
private ApiContext apiContext; private ApiContext apiContext;
private DatabaseRepository databaseRepository; private DatabaseRepository databaseRepository;
@ -93,7 +96,7 @@ public class DataManagementProfileManager {
public ResponseEntity<byte[]> getDocument(DataManagementPlanProfileListingModel dmpProfile, String label) throws IllegalAccessException, IOException, InstantiationException { public ResponseEntity<byte[]> getDocument(DataManagementPlanProfileListingModel dmpProfile, String label) throws IllegalAccessException, IOException, InstantiationException {
FileEnvelope envelope = getXmlDocument(dmpProfile, label); FileEnvelope envelope = getXmlDocument(dmpProfile, label);
InputStream resource = new FileInputStream(envelope.getFile()); InputStream resource = new FileInputStream(envelope.getFile());
System.out.println("Mime Type of " + envelope.getFilename() + " is " + logger.info("Mime Type of " + envelope.getFilename() + " is " +
new MimetypesFileTypeMap().getContentType(envelope.getFile())); new MimetypesFileTypeMap().getContentType(envelope.getFile()));
HttpHeaders responseHeaders = new HttpHeaders(); HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentLength(envelope.getFile().length()); responseHeaders.setContentLength(envelope.getFile().length());
@ -124,7 +127,7 @@ public class DataManagementProfileManager {
try { try {
return xmlBuilder.build(convert(multiPartFile)); return xmlBuilder.build(convert(multiPartFile));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return null; return null;
} }

View File

@ -36,6 +36,8 @@ import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph; import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun; import org.apache.poi.xwpf.usermodel.XWPFRun;
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.core.io.FileSystemResource; import org.springframework.core.io.FileSystemResource;
@ -73,6 +75,7 @@ import java.util.zip.ZipInputStream;
@Component @Component
public class DatasetManager { public class DatasetManager {
private static final Logger logger = LoggerFactory.getLogger(DatasetManager.class);
private ApiContext apiContext; private ApiContext apiContext;
private DatabaseRepository databaseRepository; private DatabaseRepository databaseRepository;
@ -109,7 +112,9 @@ public class DatasetManager {
} else } else
items.where((builder, root) -> root.get("id").in(new UUID[]{UUID.randomUUID()})); items.where((builder, root) -> root.get("id").in(new UUID[]{UUID.randomUUID()}));
} }
QueryableList<eu.eudat.data.entities.Dataset> authItems = databaseRepository.getDatasetDao().getAuthenticated(items, userInfo); List<Integer> roles = new LinkedList<>();
if (datasetTableRequest.getCriteria().getRole() != null) roles.add(datasetTableRequest.getCriteria().getRole());
QueryableList<eu.eudat.data.entities.Dataset> authItems = databaseRepository.getDatasetDao().getAuthenticated(items, userInfo, roles);
QueryableList<eu.eudat.data.entities.Dataset> pagedItems = PaginationManager.applyPaging(authItems, datasetTableRequest); QueryableList<eu.eudat.data.entities.Dataset> pagedItems = PaginationManager.applyPaging(authItems, datasetTableRequest);
DataTableData<DatasetListingModel> dataTable = new DataTableData<DatasetListingModel>(); DataTableData<DatasetListingModel> dataTable = new DataTableData<DatasetListingModel>();
@ -172,7 +177,7 @@ public class DatasetManager {
return dataTable; return dataTable;
} }
public DatasetWizardModel getSingle(String id) throws InstantiationException, IllegalAccessException, IOException { public DatasetWizardModel getSingle(String id) {
DatasetWizardModel dataset = new DatasetWizardModel(); DatasetWizardModel dataset = new DatasetWizardModel();
eu.eudat.data.entities.Dataset datasetEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class)); eu.eudat.data.entities.Dataset datasetEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class));
eu.eudat.elastic.entities.Dataset datasetElastic; eu.eudat.elastic.entities.Dataset datasetElastic;
@ -542,7 +547,7 @@ public class DatasetManager {
public ResponseEntity<byte[]> getDocument(String id, VisibilityRuleService visibilityRuleService, String contentType) throws IllegalAccessException, IOException, InstantiationException { public ResponseEntity<byte[]> getDocument(String id, VisibilityRuleService visibilityRuleService, String contentType) throws IllegalAccessException, IOException, InstantiationException {
FileEnvelope envelope = getXmlDocument(id, visibilityRuleService); FileEnvelope envelope = getXmlDocument(id, visibilityRuleService);
InputStream resource = new FileInputStream(envelope.getFile()); InputStream resource = new FileInputStream(envelope.getFile());
System.out.println("Mime Type of " + envelope.getFilename() + " is " + logger.info("Mime Type of " + envelope.getFilename() + " is " +
new MimetypesFileTypeMap().getContentType(envelope.getFile())); new MimetypesFileTypeMap().getContentType(envelope.getFile()));
HttpHeaders responseHeaders = new HttpHeaders(); HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentLength(envelope.getFile().length()); responseHeaders.setContentLength(envelope.getFile().length());
@ -572,7 +577,7 @@ public class DatasetManager {
DatasetImportPagedDatasetProfile datasetImport = (DatasetImportPagedDatasetProfile) jaxbUnmarshaller.unmarshal(in); DatasetImportPagedDatasetProfile datasetImport = (DatasetImportPagedDatasetProfile) jaxbUnmarshaller.unmarshal(in);
importModel = datasetImport; importModel = datasetImport;
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
// Checks if XML datasetProfileId GroupId matches the one selected. // Checks if XML datasetProfileId GroupId matches the one selected.
@ -583,7 +588,7 @@ public class DatasetManager {
throw new Exception(); throw new Exception();
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
return null; return null;
} }

View File

@ -22,6 +22,8 @@ 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.queryable.QueryableList; import eu.eudat.queryable.QueryableList;
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.http.*; import org.springframework.http.*;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -41,6 +43,7 @@ import java.io.*;
@Component @Component
public class DatasetProfileManager { public class DatasetProfileManager {
private static final Logger logger = LoggerFactory.getLogger(DatasetProfileManager.class);
private ApiContext apiContext; private ApiContext apiContext;
private DatabaseRepository databaseRepository; private DatabaseRepository databaseRepository;
@ -119,7 +122,7 @@ public class DatasetProfileManager {
public ResponseEntity<byte[]> getDocument(eu.eudat.models.data.user.composite.DatasetProfile datasetProfile, String label) throws IllegalAccessException, IOException, InstantiationException { public ResponseEntity<byte[]> getDocument(eu.eudat.models.data.user.composite.DatasetProfile datasetProfile, String label) throws IllegalAccessException, IOException, InstantiationException {
FileEnvelope envelope = getXmlDocument(datasetProfile, label); FileEnvelope envelope = getXmlDocument(datasetProfile, label);
InputStream resource = new FileInputStream(envelope.getFile()); InputStream resource = new FileInputStream(envelope.getFile());
System.out.println("Mime Type of " + envelope.getFilename() + " is " + logger.info("Mime Type of " + envelope.getFilename() + " is " +
new MimetypesFileTypeMap().getContentType(envelope.getFile())); new MimetypesFileTypeMap().getContentType(envelope.getFile()));
HttpHeaders responseHeaders = new HttpHeaders(); HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentLength(envelope.getFile().length()); responseHeaders.setContentLength(envelope.getFile().length());
@ -151,7 +154,7 @@ public class DatasetProfileManager {
try { try {
return xmlBuilder.build(convert(multiPartFile)); return xmlBuilder.build(convert(multiPartFile));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return null; return null;
} }

View File

@ -13,6 +13,8 @@ import eu.eudat.models.data.user.composite.PagedDatasetProfile;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.json.JSONObject; import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.FileSystemResource;
import org.springframework.http.*; import org.springframework.http.*;
@ -36,6 +38,7 @@ import java.util.zip.ZipInputStream;
*/ */
@Service @Service
public class DocumentManager { public class DocumentManager {
private static final Logger logger = LoggerFactory.getLogger(DocumentManager.class);
private ApiContext context; private ApiContext context;
private DatasetManager datasetManager; private DatasetManager datasetManager;
@ -104,12 +107,12 @@ public class DocumentManager {
Map mediaResult = new RestTemplate().getForObject(environment.getProperty("pdf.converter.url") + Map mediaResult = new RestTemplate().getForObject(environment.getProperty("pdf.converter.url") +
"/api/v1/" + queueResult.get("id"), Map.class); "/api/v1/" + queueResult.get("id"), Map.class);
System.out.println("Status: " + mediaResult.get("status")); logger.info("Status: " + mediaResult.get("status"));
while (!mediaResult.get("status").equals("finished")) { while (!mediaResult.get("status").equals("finished")) {
Thread.sleep(500); Thread.sleep(500);
mediaResult = new RestTemplate().getForObject(environment.getProperty("pdf.converter.url") + mediaResult = new RestTemplate().getForObject(environment.getProperty("pdf.converter.url") +
"api/v1/" + queueResult.get("id"), Map.class); "api/v1/" + queueResult.get("id"), Map.class);
System.out.println("Polling"); logger.info("Polling");
} }
RestTemplate restTemplate = new RestTemplate(); RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new ByteArrayHttpMessageConverter()); restTemplate.getMessageConverters().add(new ByteArrayHttpMessageConverter());

View File

@ -34,20 +34,21 @@ public class EmailConfirmationManager {
.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();
if (loginConfirmationEmail.getExpiresAt().compareTo(new Date()) < 0)
throw new TokenExpiredException("Token has expired.");
UserInfo user = databaseRepository.getUserInfoDao().asQueryable() UserInfo user = databaseRepository.getUserInfoDao().asQueryable()
.where((builder, root) -> builder.equal(root.get("id"), loginConfirmationEmail.getUserId())).getSingle(); .where((builder, root) -> builder.equal(root.get("id"), loginConfirmationEmail.getUserId())).getSingle();
if (user.getEmail() != null) if (user.getEmail() != null)
throw new HasConfirmedEmailException("User already has confirmed his Email."); throw new HasConfirmedEmailException("User already has confirmed his Email.");
if (loginConfirmationEmail.getExpiresAt().compareTo(new Date()) < 0)
throw new TokenExpiredException("Token has expired.");
loginConfirmationEmail.setIsConfirmed(true); loginConfirmationEmail.setIsConfirmed(true);
// Checks if mail is used by another user. If it is, merges the new the old. // Checks if mail is used by another user. If it is, merges the new the old.
UserInfo oldUser = databaseRepository.getUserInfoDao().asQueryable().where((builder, root) -> builder.equal(root.get("email"), loginConfirmationEmail.getEmail())).getSingle(); Long existingUsers = databaseRepository.getUserInfoDao().asQueryable().where((builder, root) -> builder.equal(root.get("email"), loginConfirmationEmail.getEmail())).count();
if (oldUser != null) { if (existingUsers > 0) {
UserInfo oldUser = databaseRepository.getUserInfoDao().asQueryable().where((builder, root) -> builder.equal(root.get("email"), loginConfirmationEmail.getEmail())).getSingle();
mergeNewUserToOld(user, oldUser); mergeNewUserToOld(user, oldUser);
expireUserToken(user); expireUserToken(user);
databaseRepository.getLoginConfirmationEmailDao().createOrUpdate(loginConfirmationEmail); databaseRepository.getLoginConfirmationEmailDao().createOrUpdate(loginConfirmationEmail);

View File

@ -3,6 +3,7 @@ package eu.eudat.logic.managers;
import eu.eudat.data.query.items.item.funder.FunderCriteriaRequest; import eu.eudat.data.query.items.item.funder.FunderCriteriaRequest;
import eu.eudat.logic.builders.model.models.FunderBuilder; import eu.eudat.logic.builders.model.models.FunderBuilder;
import eu.eudat.logic.proxy.config.ExternalUrlCriteria; import eu.eudat.logic.proxy.config.ExternalUrlCriteria;
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet; import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
import eu.eudat.logic.proxy.config.exceptions.NoURLFound; import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
import eu.eudat.logic.proxy.fetching.RemoteFetcher; import eu.eudat.logic.proxy.fetching.RemoteFetcher;
@ -47,6 +48,8 @@ public class FunderManager {
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)
.reference(externalListingItem.getRemoteId()).label(externalListingItem.getName()) .reference(externalListingItem.getRemoteId()).label(externalListingItem.getName())
.status(eu.eudat.data.entities.Funder.Status.fromInteger(0)) .status(eu.eudat.data.entities.Funder.Status.fromInteger(0))
.key(externalListingItem.getKey())
.source(externalListingItem.getTag())
.build(); .build();
if (externalListingItem.getSource() != null) { if (externalListingItem.getSource() != null) {
funder.setSource(externalListingItem.getSource()); funder.setSource(externalListingItem.getSource());

View File

@ -109,21 +109,24 @@ public class GrantManager {
public List<eu.eudat.models.data.grant.Grant> getCriteriaWithExternal(GrantCriteriaRequest grantCriteria, Principal principal) throws HugeResultSet, NoURLFound { public List<eu.eudat.models.data.grant.Grant> getCriteriaWithExternal(GrantCriteriaRequest grantCriteria, Principal principal) throws HugeResultSet, NoURLFound {
eu.eudat.data.entities.UserInfo userInfo = new eu.eudat.data.entities.UserInfo(); eu.eudat.data.entities.UserInfo userInfo = new eu.eudat.data.entities.UserInfo();
userInfo.setId(principal.getId()); userInfo.setId(principal.getId());
if (grantCriteria.getCriteria().getFunderReference() != null && !grantCriteria.getCriteria().getFunderReference().trim().isEmpty()) { /*if (grantCriteria.getCriteria().getFunderReference() != null && !grantCriteria.getCriteria().getFunderReference().trim().isEmpty()) {
FunderCriteria funderCriteria = new FunderCriteria(); FunderCriteria funderCriteria = new FunderCriteria();
funderCriteria.setReference(grantCriteria.getCriteria().getFunderReference()); funderCriteria.setReference(grantCriteria.getCriteria().getFunderReference());
Funder funder = apiContext.getOperationsContext().getDatabaseRepository().getFunderDao().getWithCritetia(funderCriteria).getSingleOrDefault(); Funder funder = apiContext.getOperationsContext().getDatabaseRepository().getFunderDao().getWithCritetia(funderCriteria).getSingleOrDefault();
if (funder != null) { if (funder != null) {
grantCriteria.getCriteria().setFunderId(funder.getId().toString()); grantCriteria.getCriteria().setFunderId(funder.getId().toString());
} }
}*/
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(grantCriteria.getCriteria().getLike());
if (grantCriteria.getCriteria().getFunderReference() != null) {
externalUrlCriteria.setFunderId(grantCriteria.getCriteria().getFunderReference());
grantCriteria.getCriteria().setFunderReference(null);
} }
grantCriteria.getCriteria().setReference("dmp:"); grantCriteria.getCriteria().setReference("dmp:");
QueryableList<eu.eudat.data.entities.Grant> items = apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().getWithCriteria(grantCriteria.getCriteria()); QueryableList<eu.eudat.data.entities.Grant> items = apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().getWithCriteria(grantCriteria.getCriteria());
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));
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(grantCriteria.getCriteria().getLike());
if (grantCriteria.getCriteria().getFunderReference() != null) externalUrlCriteria.setFunderId(grantCriteria.getCriteria().getFunderReference());
List<Map<String, String>> remoteRepos = remoteFetcher.getGrants(externalUrlCriteria); List<Map<String, String>> remoteRepos = remoteFetcher.getGrants(externalUrlCriteria);
GrantsExternalSourcesModel grantsExternalSourcesModel = new GrantsExternalSourcesModel().fromExternalItem(remoteRepos); GrantsExternalSourcesModel grantsExternalSourcesModel = new GrantsExternalSourcesModel().fromExternalItem(remoteRepos);
@ -131,6 +134,7 @@ public class GrantManager {
eu.eudat.models.data.grant.Grant grant = apiContext.getOperationsContext().getBuilderFactory().getBuilder(GrantBuilder.class) eu.eudat.models.data.grant.Grant grant = apiContext.getOperationsContext().getBuilderFactory().getBuilder(GrantBuilder.class)
.reference(externalListingItem.getRemoteId()).label(externalListingItem.getName()) .reference(externalListingItem.getRemoteId()).label(externalListingItem.getName())
.description(externalListingItem.getDescription()).uri(externalListingItem.getUri()) .description(externalListingItem.getDescription()).uri(externalListingItem.getUri())
.key(externalListingItem.getKey())
.abbreviation(externalListingItem.getAbbreviation()).status(eu.eudat.data.entities.Grant.Status.fromInteger(0)) .abbreviation(externalListingItem.getAbbreviation()).status(eu.eudat.data.entities.Grant.Status.fromInteger(0))
.source(externalListingItem.getTag()) .source(externalListingItem.getTag())
.build(); .build();

View File

@ -1,24 +1,25 @@
package eu.eudat.logic.managers; package eu.eudat.logic.managers;
import eu.eudat.data.dao.criteria.OrganisationCriteria;
import eu.eudat.data.dao.entities.OrganisationDao; import eu.eudat.data.dao.entities.OrganisationDao;
import eu.eudat.data.entities.DMP;
import eu.eudat.data.query.items.table.dmp.DataManagmentPlanPublicTableRequest;
import eu.eudat.data.query.items.table.organisations.OrganisationsTableRequest; import eu.eudat.data.query.items.table.organisations.OrganisationsTableRequest;
import eu.eudat.logic.builders.model.models.OrganisationBuilder;
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.services.ApiContext; import eu.eudat.logic.services.ApiContext;
import eu.eudat.logic.services.operations.DatabaseRepository; import eu.eudat.logic.services.operations.DatabaseRepository;
import eu.eudat.models.HintedModelFactory;
import eu.eudat.models.data.dmp.Organisation; import eu.eudat.models.data.dmp.Organisation;
import eu.eudat.models.data.external.ExternalSourcesItemModel;
import eu.eudat.models.data.external.OrganisationsExternalSourcesModel;
import eu.eudat.models.data.helpers.common.DataTableData; import eu.eudat.models.data.helpers.common.DataTableData;
import eu.eudat.models.data.listingmodels.DataManagementPlanListingModel;
import eu.eudat.models.data.security.Principal; import eu.eudat.models.data.security.Principal;
import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Component @Component
@ -64,4 +65,21 @@ public class OrganisationsManager {
return organisationDataTableData; return organisationDataTableData;
} }
public List<Organisation> getCriteriaWithExternal(String query, String type) throws HugeResultSet, NoURLFound {
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query);
List<Map<String, String>> remoteRepos = apiContext.getOperationsContext().getRemoteFetcher().getOrganisations(externalUrlCriteria, type);
OrganisationsExternalSourcesModel organisationsExternalSourcesModel = new OrganisationsExternalSourcesModel().fromExternalItem(remoteRepos);
List<Organisation> organisations = new LinkedList<>();
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();
organisations.add(organisation);
}
return organisations.stream().distinct().collect(Collectors.toList());
}
} }

View File

@ -48,6 +48,7 @@ public class ProjectManager {
.reference(externalListingItem.getRemoteId()).label(externalListingItem.getName()) .reference(externalListingItem.getRemoteId()).label(externalListingItem.getName())
.description(externalListingItem.getDescription()).uri(externalListingItem.getUri()) .description(externalListingItem.getDescription()).uri(externalListingItem.getUri())
.abbreviation(externalListingItem.getAbbreviation()).status(eu.eudat.data.entities.Project.Status.fromInteger(0)) .abbreviation(externalListingItem.getAbbreviation()).status(eu.eudat.data.entities.Project.Status.fromInteger(0))
.key(externalListingItem.getKey())
.source(externalListingItem.getTag()) .source(externalListingItem.getTag())
.build(); .build();

View File

@ -13,6 +13,7 @@ import org.springframework.stereotype.Component;
import java.io.IOException; import java.io.IOException;
import java.text.ParseException; import java.text.ParseException;
import java.util.UUID;
@Component @Component
public class QuickWizardManager { public class QuickWizardManager {
@ -109,6 +110,7 @@ public class QuickWizardManager {
eu.eudat.data.entities.Project projectEntity = databaseRepository.getProjectDao().getWithCritetia(criteria).getSingleOrDefault(); eu.eudat.data.entities.Project projectEntity = databaseRepository.getProjectDao().getWithCritetia(criteria).getSingleOrDefault();
if (projectEntity != null) project.setId(projectEntity.getId()); if (projectEntity != null) project.setId(projectEntity.getId());
else { else {
if (project.getId() == null) project.setId(UUID.randomUUID());
project.setType(Project.ProjectType.EXTERNAL.getValue()); project.setType(Project.ProjectType.EXTERNAL.getValue());
databaseRepository.getProjectDao().createOrUpdate(project); databaseRepository.getProjectDao().createOrUpdate(project);
} }

View File

@ -3,6 +3,8 @@ package eu.eudat.logic.managers;
import eu.eudat.logic.builders.model.models.ResearcherBuilder; import eu.eudat.logic.builders.model.models.ResearcherBuilder;
import eu.eudat.data.entities.Researcher; import eu.eudat.data.entities.Researcher;
import eu.eudat.logic.proxy.config.ExternalUrlCriteria; import eu.eudat.logic.proxy.config.ExternalUrlCriteria;
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
import eu.eudat.logic.utilities.helpers.ListHelper;
import eu.eudat.models.data.external.ExternalSourcesItemModel; import eu.eudat.models.data.external.ExternalSourcesItemModel;
import eu.eudat.models.data.external.ResearchersExternalSourcesModel; import eu.eudat.models.data.external.ResearchersExternalSourcesModel;
import eu.eudat.data.query.items.item.researcher.ResearcherCriteriaRequest; import eu.eudat.data.query.items.item.researcher.ResearcherCriteriaRequest;
@ -17,7 +19,6 @@ import org.springframework.stereotype.Component;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -28,11 +29,13 @@ public class ResearcherManager {
private ApiContext apiContext; private ApiContext apiContext;
private RemoteFetcher remoteFetcher; private RemoteFetcher remoteFetcher;
private ConfigLoader configLoader;
@Autowired @Autowired
public ResearcherManager(ApiContext apiContext) { public ResearcherManager(ApiContext apiContext, ConfigLoader configLoader) {
this.apiContext = apiContext; this.apiContext = apiContext;
this.remoteFetcher = apiContext.getOperationsContext().getRemoteFetcher(); this.remoteFetcher = apiContext.getOperationsContext().getRemoteFetcher();
this.configLoader = configLoader;
} }
public Researcher create(eu.eudat.models.data.researcher.Researcher researcher, Principal principal) throws Exception { public Researcher create(eu.eudat.models.data.researcher.Researcher researcher, Principal principal) throws Exception {
@ -46,6 +49,13 @@ public class ResearcherManager {
QueryableList<eu.eudat.data.entities.Researcher> items = apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao().getWithCriteria(researcherCriteriaRequest.getCriteria()); QueryableList<eu.eudat.data.entities.Researcher> items = apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao().getWithCriteria(researcherCriteriaRequest.getCriteria());
items.where((builder, root) -> builder.equal(root.get("creationUser").get("id"), principal.getId())); items.where((builder, root) -> builder.equal(root.get("creationUser").get("id"), principal.getId()));
List<eu.eudat.models.data.dmp.Researcher> researchers = items.select(item -> new eu.eudat.models.data.dmp.Researcher().fromDataModel(item)); List<eu.eudat.models.data.dmp.Researcher> researchers = items.select(item -> new eu.eudat.models.data.dmp.Researcher().fromDataModel(item));
Map<String, String> keyToSourceMap = configLoader.getKeyToSourceMap();
for (eu.eudat.models.data.dmp.Researcher item : researchers) {
if (item.getKey().equals("Internal"))
item.setTag(item.getKey());
else
item.setTag(keyToSourceMap.get(item.getKey()));
}
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(researcherCriteriaRequest.getCriteria().getName()); ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(researcherCriteriaRequest.getCriteria().getName());
List<Map<String, String>> 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);
@ -53,8 +63,10 @@ public class ResearcherManager {
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)
.label(externalListingItem.getAbbreviation()) .label(externalListingItem.getAbbreviation())
.id(externalListingItem.getId()) .id(externalListingItem.getId())
.reference(externalListingItem.getRemoteId())
.name(externalListingItem.getName()) .name(externalListingItem.getName())
.tag(externalListingItem.getTag()) .tag(externalListingItem.getTag())
.key(externalListingItem.getKey())
.build(); .build();
researchers.add(researcher); researchers.add(researcher);
} }

View File

@ -5,10 +5,12 @@ import eu.eudat.logic.security.customproviders.ConfigurableProvider.entities.Con
import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFDocument;
import java.util.List; import java.util.List;
import java.util.Map;
public interface ConfigLoader { public interface ConfigLoader {
ExternalUrls getExternalUrls(); ExternalUrls getExternalUrls();
List<String> getRdaProperties(); List<String> getRdaProperties();
XWPFDocument getDocument(); XWPFDocument getDocument();
ConfigurableProviders getConfigurableProviders(); ConfigurableProviders getConfigurableProviders();
Map<String, String> getKeyToSourceMap();
} }

View File

@ -5,73 +5,81 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.logic.proxy.config.ExternalUrls; import eu.eudat.logic.proxy.config.ExternalUrls;
import eu.eudat.logic.security.customproviders.ConfigurableProvider.entities.ConfigurableProviders; import eu.eudat.logic.security.customproviders.ConfigurableProvider.entities.ConfigurableProviders;
import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFDocument;
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.context.annotation.Profile; import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller; import javax.xml.bind.Unmarshaller;
import java.io.BufferedReader; import javax.xml.parsers.DocumentBuilder;
import java.io.FileReader; import javax.xml.parsers.DocumentBuilderFactory;
import java.io.IOException; import javax.xml.parsers.ParserConfigurationException;
import java.io.InputStream; import javax.xml.xpath.XPath;
import java.net.URL; import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import java.io.*;
import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service("configLoader") @Service("configLoader")
@Profile("devel") @Profile("devel")
public class DevelConfigLoader implements ConfigLoader { public class DevelConfigLoader implements ConfigLoader {
private static final Logger logger = LoggerFactory.getLogger(DevelConfigLoader.class);
private ExternalUrls externalUrls; private ExternalUrls externalUrls;
private List<String> rdaProperties; private List<String> rdaProperties;
private XWPFDocument document; private XWPFDocument document;
private ConfigurableProviders configurableProviders; private ConfigurableProviders configurableProviders;
private Map<String, String> keyToSourceMap;
@Autowired @Autowired
private Environment environment; private Environment environment;
private void setExternalUrls() { private void setExternalUrls() {
String fileUrl = this.environment.getProperty("configuration.externalUrls"); String fileUrl = this.environment.getProperty("configuration.externalUrls");
System.out.println("Loaded also config file: " + fileUrl); logger.info("Loaded also config file: " + fileUrl);
String current = null;
InputStream is = null; InputStream is = null;
try { try {
current = new java.io.File(".").getCanonicalPath();
JAXBContext jaxbContext = JAXBContext.newInstance(ExternalUrls.class); JAXBContext jaxbContext = JAXBContext.newInstance(ExternalUrls.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
is = new URL("file:///" + current + fileUrl).openStream(); is = getClass().getClassLoader().getResource(fileUrl).openStream();
externalUrls = (ExternalUrls) jaxbUnmarshaller.unmarshal(is); externalUrls = (ExternalUrls) jaxbUnmarshaller.unmarshal(is);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); logger.error("Cannot find resource in classpath", ex);
System.out.println("Cannot find in folder" + current);
} finally { } finally {
try { try {
if (is != null) is.close(); if (is != null) is.close();
} catch (IOException e) { } catch (IOException | NullPointerException e) {
System.out.println("Warning: Could not close a stream after reading from file: " + fileUrl); logger.warn("Warning: Could not close a stream after reading from file: " + fileUrl, e);
} }
} }
} }
private void setRdaProperties() { private void setRdaProperties() {
String filePath = environment.getProperty("configuration.rda"); String filePath = environment.getProperty("configuration.rda");
String current = null;
BufferedReader reader; BufferedReader reader;
List<String> rdaList = new LinkedList<>(); List<String> rdaList = new LinkedList<>();
try { try {
current = new java.io.File(".").getCanonicalPath(); reader = new BufferedReader(new FileReader(getClass().getClassLoader().getResource(filePath).getFile()));
reader = new BufferedReader(new FileReader(current + filePath));
String line = reader.readLine(); String line = reader.readLine();
while (line != null) { while (line != null) {
rdaList.add(line); rdaList.add(line);
line = reader.readLine(); line = reader.readLine();
} }
reader.close(); reader.close();
} catch (IOException e) { } catch (IOException | NullPointerException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
rdaProperties = rdaList; rdaProperties = rdaList;
@ -79,43 +87,63 @@ public class DevelConfigLoader implements ConfigLoader {
private void setDocument() { private void setDocument() {
String filePath = environment.getProperty("configuration.h2020template"); String filePath = environment.getProperty("configuration.h2020template");
String current = null;
InputStream is = null; InputStream is = null;
try { try {
current = new java.io.File(".").getCanonicalPath(); is = getClass().getClassLoader().getResource(filePath).openStream();
is = new URL("file:///" + current + filePath).openStream();
this.document = new XWPFDocument(is); this.document = new XWPFDocument(is);
} catch (IOException e) { } catch (IOException | NullPointerException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} finally { } finally {
try { try {
if (is != null) is.close(); if (is != null) is.close();
} catch (IOException e) { } catch (IOException e) {
System.out.println("Warning: Could not close a stream after reading from file: " + filePath); logger.warn("Warning: Could not close a stream after reading from file: " + filePath, e);
} }
} }
} }
public void setConfigurableProviders() { private void setConfigurableProviders() {
String filePath = environment.getProperty("configuration.configurable_login_providers"); String filePath = environment.getProperty("configuration.configurable_login_providers");
String current = null;
InputStream is = null; InputStream is = null;
try { try {
current = new java.io.File(".").getCanonicalPath(); is = getClass().getClassLoader().getResource(filePath).openStream();
is = new URL("file:///" + current + filePath).openStream();
ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
this.configurableProviders = mapper.readValue(is, ConfigurableProviders.class); this.configurableProviders = mapper.readValue(is, ConfigurableProviders.class);
} catch (IOException e) { } catch (IOException | NullPointerException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} finally { } finally {
try { try {
if (is != null) is.close(); if (is != null) is.close();
} catch (IOException e) { } catch (IOException e) {
System.out.println("Warning: Could not close a stream after reading from file: " + filePath); logger.warn("Warning: Could not close a stream after reading from file: " + filePath, e);
} }
} }
} }
private void setKeyToSourceMap() {
String filePath = this.environment.getProperty("configuration.externalUrls");
logger.info("Loaded also config file: " + filePath);
Document doc = getXmlDocumentFromFilePath(filePath);
if (doc == null) {
this.keyToSourceMap = null;
return;
}
String xpathExpression = "//key";
Map<String, String> keysToSourceMap = new HashMap<>();
List<String> keys = getXmlValuesFromXPath(doc, xpathExpression);
keys = keys.stream().distinct().collect(Collectors.toList());
for (String key : keys) {
String sourceExpression = String.format("//urlConfig[key='%s']/label", key);
List<String> sources = getXmlValuesFromXPath(doc, sourceExpression);
if (sources.size() != 0) {
keysToSourceMap.put(key, sources.get(0));
}
}
this.keyToSourceMap = keysToSourceMap;
}
public ExternalUrls getExternalUrls() { public ExternalUrls getExternalUrls() {
this.setExternalUrls(); this.setExternalUrls();
return externalUrls; return externalUrls;
@ -135,4 +163,52 @@ public class DevelConfigLoader implements ConfigLoader {
this.setConfigurableProviders(); this.setConfigurableProviders();
return configurableProviders; return configurableProviders;
} }
public Map<String, String> getKeyToSourceMap() {
this.setKeyToSourceMap();
return keyToSourceMap;
}
private Document getXmlDocumentFromFilePath(String filePath) {
InputStream is = null;
Document doc;
try {
is = getClass().getClassLoader().getResource(filePath).openStream();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
doc = documentBuilder.parse(is);
return doc;
} catch (IOException | ParserConfigurationException | SAXException | NullPointerException e) {
logger.error(e.getMessage(), e);
} finally {
try {
if (is != null) {
is.close();
}
} catch (IOException e) {
logger.warn("Warning: Could not close a stream after reading from file: " + filePath, e);
}
}
return null;
}
private List<String> getXmlValuesFromXPath(Document doc, String expression) {
XPath xPath = XPathFactory.newInstance().newXPath();
NodeList nodeList = null;
List<String> values = new LinkedList<>();
try {
nodeList = (NodeList) xPath.compile(expression).evaluate(doc, XPathConstants.NODESET);
} catch (XPathExpressionException e) {
logger.error(e.getMessage(), e);
}
if (nodeList != null) {
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
if (node.hasChildNodes()) {
values.add(nodeList.item(i).getChildNodes().item(0).getNodeValue());
}
}
}
return values;
}
} }

View File

@ -4,55 +4,68 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.logic.proxy.config.ExternalUrls; import eu.eudat.logic.proxy.config.ExternalUrls;
import eu.eudat.logic.security.customproviders.ConfigurableProvider.entities.ConfigurableProviders; import eu.eudat.logic.security.customproviders.ConfigurableProvider.entities.ConfigurableProviders;
import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFDocument;
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.context.annotation.Profile; import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller; import javax.xml.bind.Unmarshaller;
import java.io.BufferedReader; import javax.xml.parsers.DocumentBuilder;
import java.io.FileReader; import javax.xml.parsers.DocumentBuilderFactory;
import java.io.IOException; import javax.xml.parsers.ParserConfigurationException;
import java.io.InputStream; import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import java.io.*;
import java.net.URL; import java.net.URL;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service("configLoader") @Service("configLoader")
@Profile({ "production", "staging" }) @Profile({ "production", "staging" })
public class ProductionConfigLoader implements ConfigLoader { public class ProductionConfigLoader implements ConfigLoader {
private static final Logger logger = LoggerFactory.getLogger(ProductionConfigLoader.class);
private ExternalUrls externalUrls; private ExternalUrls externalUrls;
private List<String> rdaProperties; private List<String> rdaProperties;
private XWPFDocument document; private XWPFDocument document;
private ConfigurableProviders configurableProviders; private ConfigurableProviders configurableProviders;
private Map<String, String> keyToSourceMap;
@Autowired @Autowired
private Environment environment; private Environment environment;
private void setExternalUrls() { private void setExternalUrls() {
String fileUrl = this.environment.getProperty("configuration.externalUrls"); String fileUrl = this.environment.getProperty("configuration.externalUrls");
System.out.println("Loaded also config file: " + fileUrl); logger.info("Loaded also config file: " + fileUrl);
String current = null; String current = null;
InputStream is = null; InputStream is = null;
try { try {
current = new java.io.File(".").getCanonicalPath(); current = new java.io.File(".").getCanonicalPath();
JAXBContext jaxbContext = JAXBContext.newInstance(ExternalUrls.class); JAXBContext jaxbContext = JAXBContext.newInstance(ExternalUrls.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
is = new URL(Paths.get(fileUrl).toUri().toURL().toString()).openStream(); is = new URL(Paths.get(fileUrl).toUri().toURL().toString()).openStream();
externalUrls = (ExternalUrls) jaxbUnmarshaller.unmarshal(is); externalUrls = (ExternalUrls) jaxbUnmarshaller.unmarshal(is);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); logger.error("Cannot find in folder" + current, ex);
System.out.println("Cannot find in folder" + current);
} finally { } finally {
try { try {
if (is != null) is.close(); if (is != null) is.close();
} catch (IOException e) { } catch (IOException e) {
System.out.println("Warning: Could not close a stream after reading from file: " + fileUrl); logger.warn("Warning: Could not close a stream after reading from file: " + fileUrl, e);
} }
} }
} }
@ -70,7 +83,7 @@ public class ProductionConfigLoader implements ConfigLoader {
} }
reader.close(); reader.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
rdaProperties = rdaList; rdaProperties = rdaList;
@ -78,28 +91,64 @@ public class ProductionConfigLoader implements ConfigLoader {
private void setDocument() { private void setDocument() {
String filePath = environment.getProperty("configuration.h2020template"); String filePath = environment.getProperty("configuration.h2020template");
String current = null; InputStream is = null;
try { try {
current = new java.io.File(".").getCanonicalPath(); is = new URL(Paths.get(filePath).toUri().toURL().toString()).openStream();
InputStream is = new URL(Paths.get(filePath).toUri().toURL().toString()).openStream();
this.document = new XWPFDocument(is); this.document = new XWPFDocument(is);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} finally {
try {
if (is != null) is.close();
} catch (IOException e) {
logger.warn("Warning: Could not close a stream after reading from file: " + filePath, e);
}
} }
} }
public void setConfigurableProviders() { private void setConfigurableProviders() {
String filePath = environment.getProperty("configuration.configurable_login_providers"); String filePath = environment.getProperty("configuration.configurable_login_providers");
String current = null; InputStream is = null;
try { try {
current = new java.io.File(".").getCanonicalPath(); File tempFile = new File(filePath);
InputStream is = new URL(Paths.get(filePath).toUri().toURL().toString()).openStream(); if (tempFile.exists()) {
ObjectMapper objectMapper = new ObjectMapper(); is = new URL(Paths.get(filePath).toUri().toURL().toString()).openStream();
this.configurableProviders = objectMapper.readValue(is, ConfigurableProviders.class); ObjectMapper objectMapper = new ObjectMapper();
this.configurableProviders = objectMapper.readValue(is, ConfigurableProviders.class);
} else {
this.configurableProviders = new ConfigurableProviders();
}
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} finally {
try {
if (is != null) is.close();
} catch (IOException e) {
logger.warn("Warning: Could not close a stream after reading from file: " + filePath, e);
}
} }
} }
private void setKeyToSourceMap() {
String filePath = this.environment.getProperty("configuration.externalUrls");
logger.info("Loaded also config file: " + filePath);
Document doc = getXmlDocumentFromFilePath(filePath);
if (doc == null) {
this.keyToSourceMap = null;
return;
}
String xpathExpression = "//key";
Map<String, String> keysToSourceMap = new HashMap<>();
List<String> keys = getXmlValuesFromXPath(doc, xpathExpression);
keys = keys.stream().distinct().collect(Collectors.toList());
for (String key : keys) {
String sourceExpression = String.format("//urlConfig[key='%s']/label", key);
List<String> sources = getXmlValuesFromXPath(doc, sourceExpression);
if (sources.size() != 0) {
keysToSourceMap.put(key, sources.get(0));
}
}
this.keyToSourceMap = keysToSourceMap;
}
public ExternalUrls getExternalUrls() { public ExternalUrls getExternalUrls() {
this.setExternalUrls(); this.setExternalUrls();
@ -120,4 +169,52 @@ public class ProductionConfigLoader implements ConfigLoader {
this.setConfigurableProviders(); this.setConfigurableProviders();
return configurableProviders; return configurableProviders;
} }
public Map<String, String> getKeyToSourceMap() {
this.setKeyToSourceMap();
return keyToSourceMap;
}
private Document getXmlDocumentFromFilePath(String filePath) {
InputStream is = null;
Document doc;
try {
is = new URL(Paths.get(filePath).toUri().toURL().toString()).openStream();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
doc = documentBuilder.parse(is);
return doc;
} catch (IOException | ParserConfigurationException | SAXException e) {
logger.error(e.getMessage(), e);
} finally {
try {
if (is != null) {
is.close();
}
} catch (IOException e) {
logger.warn("Warning: Could not close a stream after reading from file: " + filePath, e);
}
}
return null;
}
private List<String> getXmlValuesFromXPath(Document doc, String expression) {
XPath xPath = XPathFactory.newInstance().newXPath();
NodeList nodeList = null;
List<String> values = new LinkedList<>();
try {
nodeList = (NodeList) xPath.compile(expression).evaluate(doc, XPathConstants.NODESET);
} catch (XPathExpressionException e) {
logger.error(e.getMessage(), e);
}
if (nodeList != null) {
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
if (node.hasChildNodes()) {
values.add(nodeList.item(i).getChildNodes().item(0).getNodeValue());
}
}
}
return values;
}
} }

View File

@ -8,6 +8,8 @@ import eu.eudat.logic.proxy.config.*;
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader; import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet; import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
import eu.eudat.logic.proxy.config.exceptions.NoURLFound; import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
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.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -25,6 +27,7 @@ import java.util.stream.Collectors;
@Service @Service
public class RemoteFetcher { public class RemoteFetcher {
private static final Logger logger = LoggerFactory.getLogger(RemoteFetcher.class);
private ConfigLoader configLoader; private ConfigLoader configLoader;
@ -120,15 +123,16 @@ public class RemoteFetcher {
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 {
if (urlConfigs == null || urlConfigs.isEmpty()) List<Map<String, String>> results = new LinkedList<>();
throw new NoURLFound("No Repository urls found in configuration");
if (urlConfigs == null || urlConfigs.isEmpty()) return results;
// throw new NoURLFound("No Repository urls found in configuration");
urlConfigs.sort(Comparator.comparing(UrlConfiguration::getOrdinal)); urlConfigs.sort(Comparator.comparing(UrlConfiguration::getOrdinal));
List<Map<String, String>> results = new LinkedList<>();
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.getContentType(), urlConfig.getFirstpage())); results.addAll(getAllResultsFromUrl(urlConfig.getUrl(), fetchStrategy, urlConfig.getData(), urlConfig.getPaginationPath(), externalUrlCriteria, urlConfig.getLabel(), urlConfig.getKey(), urlConfig.getContentType(), urlConfig.getFirstpage()));
} 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()));
} }
@ -138,7 +142,7 @@ public class RemoteFetcher {
private void ifFunderQueryExist(UrlConfiguration urlConfiguration, ExternalUrlCriteria externalUrlCriteria) { private void ifFunderQueryExist(UrlConfiguration urlConfiguration, ExternalUrlCriteria externalUrlCriteria) {
if (urlConfiguration.getFunderQuery() != null) { if (urlConfiguration.getFunderQuery() != null) {
if (externalUrlCriteria.getFunderId() != null && urlConfiguration.getFunderQuery().startsWith("dmp:")) { if (externalUrlCriteria.getFunderId() != null && !urlConfiguration.getFunderQuery().startsWith("dmp:")) {
urlConfiguration.setUrl(urlConfiguration.getUrl().replace("{funderQuery}", urlConfiguration.getFunderQuery())); urlConfiguration.setUrl(urlConfiguration.getUrl().replace("{funderQuery}", urlConfiguration.getFunderQuery()));
} }
else { else {
@ -162,7 +166,7 @@ public class RemoteFetcher {
try { try {
funderId = URLEncoder.encode(externalUrlCriteria.getFunderId(), "UTF-8"); funderId = URLEncoder.encode(externalUrlCriteria.getFunderId(), "UTF-8");
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
completedPath = completedPath.replace("{funderId}", funderId); completedPath = completedPath.replace("{funderId}", funderId);
} }
@ -178,19 +182,19 @@ public class RemoteFetcher {
if (externalUrlCriteria.getPageSize() != null) { if (externalUrlCriteria.getPageSize() != null) {
completedPath = completedPath.replace("{pageSize}", externalUrlCriteria.getPageSize()); completedPath = completedPath.replace("{pageSize}", externalUrlCriteria.getPageSize());
} else { } else {
completedPath = completedPath.replace("{pageSize}", "10"); completedPath = completedPath.replace("{pageSize}", "60");
} }
return completedPath; return completedPath;
} }
private List<Map<String, String>> getAllResultsFromUrl(String path, FetchStrategy fetchStrategy, final DataUrlConfiguration jsonDataPath, final String jsonPaginationPath, ExternalUrlCriteria externalUrlCriteria, 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) throws HugeResultSet {
Set<Integer> pages = new HashSet<>(); Set<Integer> pages = new HashSet<>();
String replacedPath = replaceCriteriaOnUrl(path, externalUrlCriteria, firstPage); String replacedPath = replaceCriteriaOnUrl(path, externalUrlCriteria, firstPage);
Results results = getResultsFromUrl(replacedPath, jsonDataPath, jsonPaginationPath, contentType); Results results = getResultsFromUrl(replacedPath, jsonDataPath, jsonPaginationPath, contentType);
if (fetchStrategy == FetchStrategy.FIRST) if (fetchStrategy == FetchStrategy.FIRST)
return results == null ? new LinkedList<>() : results.getResults().stream().peek(x -> x.put("tag", 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());
if (results != null && results.getPagination() != null && results.getPagination().get("pages") != null) //if has more pages, add them to the pages set if (results != null && results.getPagination() != null && results.getPagination().get("pages") != null) //if has more pages, add them to the pages set
for (int i = 2; i <= results.getPagination().get("pages"); i++) for (int i = 2; i <= results.getPagination().get("pages"); i++)
@ -209,7 +213,7 @@ public class RemoteFetcher {
Results remainingResults = optionalResults.orElseGet(Results::new); Results remainingResults = optionalResults.orElseGet(Results::new);
remainingResults.getResults().addAll(results.getResults()); remainingResults.getResults().addAll(results.getResults());
return remainingResults.getResults().stream().peek(x -> x.put("tag", key)).collect(Collectors.toList()); return remainingResults.getResults().stream().peek(x -> x.put("tag", tag)).collect(Collectors.toList());
} }
@ -243,20 +247,20 @@ public class RemoteFetcher {
results = new Results(jsonContext.read(jsonDataPath.getPath() results = new Results(jsonContext.read(jsonDataPath.getPath()
+ "[" + jsonDataPath.getFieldsUrlConfiguration().getName() + "," + jsonDataPath.getFieldsUrlConfiguration().getDescription() + "[" + jsonDataPath.getFieldsUrlConfiguration().getName() + "," + jsonDataPath.getFieldsUrlConfiguration().getDescription()
+ "," + jsonDataPath.getFieldsUrlConfiguration().getUri() + "," + jsonDataPath.getFieldsUrlConfiguration().getId() + "]"), + "," + jsonDataPath.getFieldsUrlConfiguration().getUri() + "," + jsonDataPath.getFieldsUrlConfiguration().getId() + "]"),
jsonContext.read(jsonPaginationPath)); new HashMap<>(1, 1));
} }
results.results = results.results.stream().map(e -> e.entrySet().stream().collect(Collectors.toMap(x -> this.transformKey(jsonDataPath,x.getKey()), Map.Entry::getValue))) results.results = results.results.stream().map(e -> e.entrySet().stream().collect(Collectors.toMap(x -> this.transformKey(jsonDataPath,x.getKey()), Map.Entry::getValue)))
.collect(Collectors.toList()); .collect(Collectors.toList());
return results; return results;
} }
} catch (MalformedURLException e1) { } catch (MalformedURLException e1) {
e1.printStackTrace(); logger.error(e1.getMessage(), e1);
} //maybe print smth... } //maybe print smth...
catch (IOException e2) { catch (IOException e2) {
e2.printStackTrace(); logger.error(e2.getMessage(), e2);
} //maybe print smth... } //maybe print smth...
catch (Exception exception) { catch (Exception exception) {
exception.printStackTrace(); logger.error(exception.getMessage(), exception);
} //maybe print smth... } //maybe print smth...
finally { finally {
} }
@ -270,10 +274,9 @@ public class RemoteFetcher {
String filePath = Paths.get(path).toUri().toURL().toString(); String filePath = Paths.get(path).toUri().toURL().toString();
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
internalResults = mapper.readValue(new File(filePath), new TypeReference<List<Map<String, Object>>>(){}); internalResults = mapper.readValue(new File(filePath), new TypeReference<List<Map<String, Object>>>(){});
searchListMap(internalResults, query); return searchListMap(internalResults, query);
return internalResults;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
return new LinkedList<>(); return new LinkedList<>();
} }
} }

View File

@ -6,6 +6,8 @@ import eu.eudat.exceptions.security.UnauthorisedException;
import eu.eudat.models.data.login.LoginInfo; import eu.eudat.models.data.login.LoginInfo;
import eu.eudat.models.data.security.Principal; import eu.eudat.models.data.security.Principal;
import eu.eudat.logic.security.validators.TokenValidatorFactory; import eu.eudat.logic.security.validators.TokenValidatorFactory;
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.stereotype.Component; import org.springframework.stereotype.Component;
@ -14,6 +16,7 @@ import java.security.GeneralSecurityException;
@Component @Component
public class CustomAuthenticationProvider { public class CustomAuthenticationProvider {
private static final Logger logger = LoggerFactory.getLogger(CustomAuthenticationProvider.class);
@Autowired @Autowired
@ -25,14 +28,13 @@ public class CustomAuthenticationProvider {
Principal principal = this.tokenValidatorFactory.getProvider(credentials.getProvider()).validateToken(credentials); Principal principal = this.tokenValidatorFactory.getProvider(credentials.getProvider()).validateToken(credentials);
return principal; return principal;
} catch (NonValidTokenException e) { } catch (NonValidTokenException e) {
e.printStackTrace(); logger.error("Could not validate a user by his token! Reason: " + e.getMessage(), e);
System.out.println("Could not validate a user by his token! Reason: " + e.getMessage());
throw new UnauthorisedException("Token validation failed - Not a valid token"); throw new UnauthorisedException("Token validation failed - Not a valid token");
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
throw new UnauthorisedException("IO Exeption"); throw new UnauthorisedException("IO Exeption");
} catch (NullEmailException e) { } catch (NullEmailException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
throw new NullEmailException(); throw new NullEmailException();
} }
} }

View File

@ -2,6 +2,8 @@ package eu.eudat.logic.services.helpers;
import eu.eudat.exceptions.files.TempFileNotFoundException; import eu.eudat.exceptions.files.TempFileNotFoundException;
import eu.eudat.models.data.files.ContentFile; import eu.eudat.models.data.files.ContentFile;
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.core.io.Resource; import org.springframework.core.io.Resource;
@ -22,6 +24,7 @@ import java.util.UUID;
*/ */
@Service("fileStorageService") @Service("fileStorageService")
public class FileStorageServiceImpl implements FileStorageService { public class FileStorageServiceImpl implements FileStorageService {
private static final Logger logger = LoggerFactory.getLogger(FileStorageServiceImpl.class);
private Environment environment; private Environment environment;
@ -68,7 +71,7 @@ public class FileStorageServiceImpl implements FileStorageService {
Files.createDirectory(Paths.get(environment.getProperty("files.storage.final"))); Files.createDirectory(Paths.get(environment.getProperty("files.storage.final")));
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
} }

View File

@ -9,5 +9,5 @@ public interface HelpersService {
MessageSource getMessageSource(); MessageSource getMessageSource();
LoggerService getLoggerService(); // LoggerService getLoggerService();
} }

View File

@ -11,12 +11,12 @@ import org.springframework.stereotype.Service;
public class HelpersServiceImpl implements HelpersService { public class HelpersServiceImpl implements HelpersService {
private MessageSource messageSource; private MessageSource messageSource;
private LoggerService loggerService; // private LoggerService loggerService;
@Autowired @Autowired
public HelpersServiceImpl(MessageSource messageSource, LoggerService loggerService) { public HelpersServiceImpl(MessageSource messageSource/*, LoggerService loggerService*/) {
this.messageSource = messageSource; this.messageSource = messageSource;
this.loggerService = loggerService; // this.loggerService = loggerService;
} }
@Override @Override
@ -24,8 +24,8 @@ public class HelpersServiceImpl implements HelpersService {
return messageSource; return messageSource;
} }
@Override /*@Override
public LoggerService getLoggerService() { public LoggerService getLoggerService() {
return loggerService; return loggerService;
} }*/
} }

View File

@ -12,7 +12,7 @@ import java.util.Map;
/** /**
* Created by ikalyvas on 3/1/2018. * Created by ikalyvas on 3/1/2018.
*/ */
@Service("loggerService") //@Service("loggerService")
public class LoggerServiceImpl implements LoggerService { public class LoggerServiceImpl implements LoggerService {
private Logger logger; private Logger logger;
private WarningLevel level; private WarningLevel level;
@ -22,7 +22,7 @@ public class LoggerServiceImpl implements LoggerService {
this.level = level; this.level = level;
} }
@Autowired // @Autowired
public LoggerServiceImpl(Logger logger) { public LoggerServiceImpl(Logger logger) {
this.logger = logger; this.logger = logger;
this.options.put(WarningLevel.DEBUG, (log, message) -> log.debug(message)); this.options.put(WarningLevel.DEBUG, (log, message) -> log.debug(message));

View File

@ -15,12 +15,15 @@ import eu.eudat.models.data.loginprovider.LoginProviderUser;
import eu.eudat.models.data.security.Principal; import eu.eudat.models.data.security.Principal;
import eu.eudat.types.Authorities; import eu.eudat.types.Authorities;
import org.json.JSONObject; import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.*; import java.util.*;
public abstract class AbstractAuthenticationService implements AuthenticationService { public abstract class AbstractAuthenticationService implements AuthenticationService {
private static final Logger logger = LoggerFactory.getLogger(AbstractAuthenticationService.class);
protected ApiContext apiContext; protected ApiContext apiContext;
protected Environment environment; protected Environment environment;
@ -86,7 +89,7 @@ public abstract class AbstractAuthenticationService implements AuthenticationSer
try { try {
credential = this.autoCreateUser(credentials.getUsername(), credentials.getSecret()); credential = this.autoCreateUser(credentials.getUsername(), credentials.getSecret());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
return null; return null;
} }
} }

View File

@ -1,9 +1,10 @@
package eu.eudat.logic.services.utilities; package eu.eudat.logic.services.utilities;
import eu.eudat.core.logger.Logger;
import eu.eudat.data.dao.entities.LoginConfirmationEmailDao; import eu.eudat.data.dao.entities.LoginConfirmationEmailDao;
import eu.eudat.data.entities.LoginConfirmationEmail; import eu.eudat.data.entities.LoginConfirmationEmail;
import eu.eudat.models.data.mail.SimpleMail; import eu.eudat.models.data.mail.SimpleMail;
import org.slf4j.Logger;
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;
@ -13,11 +14,12 @@ import java.util.concurrent.CompletableFuture;
@Service("ConfirmationEmailService") @Service("ConfirmationEmailService")
public class ConfirmationEmailServiceImpl implements ConfirmationEmailService { public class ConfirmationEmailServiceImpl implements ConfirmationEmailService {
private Logger logger; private static final Logger logger = LoggerFactory.getLogger(ConfirmationEmailServiceImpl.class);
//private Logger logger;
private Environment environment; private Environment environment;
public ConfirmationEmailServiceImpl(Logger logger, Environment environment) { public ConfirmationEmailServiceImpl(/*Logger logger,*/ Environment environment) {
this.logger = logger; // this.logger = logger;
this.environment = environment; this.environment = environment;
} }
@ -48,8 +50,7 @@ public class ConfirmationEmailServiceImpl implements ConfirmationEmailService {
try { try {
mailService.sendSimpleMail(mail); mailService.sendSimpleMail(mail);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); logger.error(ex.getMessage(), ex);
this.logger.error(ex, ex.getMessage());
} }
}); });
} }

View File

@ -1,6 +1,5 @@
package eu.eudat.logic.services.utilities; package eu.eudat.logic.services.utilities;
import eu.eudat.core.logger.Logger;
import eu.eudat.core.models.exception.ApiExceptionLoggingModel; import eu.eudat.core.models.exception.ApiExceptionLoggingModel;
import eu.eudat.data.dao.entities.DMPDao; import eu.eudat.data.dao.entities.DMPDao;
import eu.eudat.data.dao.entities.InvitationDao; import eu.eudat.data.dao.entities.InvitationDao;
@ -8,6 +7,8 @@ import eu.eudat.data.entities.DMP;
import eu.eudat.data.entities.Invitation; import eu.eudat.data.entities.Invitation;
import eu.eudat.data.entities.UserInfo; import eu.eudat.data.entities.UserInfo;
import eu.eudat.models.data.mail.SimpleMail; import eu.eudat.models.data.mail.SimpleMail;
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.HttpStatus; import org.springframework.http.HttpStatus;
@ -25,13 +26,13 @@ import java.util.stream.Collectors;
@Service("invitationService") @Service("invitationService")
public class InvitationServiceImpl implements InvitationService { public class InvitationServiceImpl implements InvitationService {
private static final Logger logger = LoggerFactory.getLogger(InvitationServiceImpl.class);
private Logger logger; // private Logger logger;
private Environment environment; private Environment environment;
@Autowired @Autowired
public InvitationServiceImpl(Logger logger, Environment environment) { public InvitationServiceImpl(/*Logger logger,*/ Environment environment) {
this.logger = logger; // this.logger = logger;
this.environment = environment; this.environment = environment;
} }
@ -75,8 +76,7 @@ public class InvitationServiceImpl implements InvitationService {
try { try {
mailService.sendSimpleMail(mail); mailService.sendSimpleMail(mail);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); logger.error(ex.getMessage(), ex);
this.logger.error(ex, ex.getMessage());
} }
}); });
} }

View File

@ -2,6 +2,8 @@ package eu.eudat.logic.services.utilities;
import eu.eudat.models.data.mail.SimpleMail; import eu.eudat.models.data.mail.SimpleMail;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
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.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
@ -17,6 +19,7 @@ import java.io.*;
@Service("mailService") @Service("mailService")
public class MailServiceImpl implements MailService { public class MailServiceImpl implements MailService {
private static final Logger logger = LoggerFactory.getLogger(MailServiceImpl.class);
private Environment env; private Environment env;
@ -54,7 +57,7 @@ public class MailServiceImpl implements MailService {
IOUtils.copy(inputStream, writer, "UTF-8"); IOUtils.copy(inputStream, writer, "UTF-8");
return writer.toString(); return writer.toString();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return ""; return "";
} }

View File

@ -5,6 +5,8 @@ import eu.eudat.models.data.components.commons.datafield.*;
import eu.eudat.models.data.entities.xmlmodels.modeldefinition.DatabaseModelDefinition; import eu.eudat.models.data.entities.xmlmodels.modeldefinition.DatabaseModelDefinition;
import eu.eudat.logic.utilities.interfaces.ModelDefinition; import eu.eudat.logic.utilities.interfaces.ModelDefinition;
import eu.eudat.logic.utilities.interfaces.ViewStyleDefinition; import eu.eudat.logic.utilities.interfaces.ViewStyleDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import java.util.LinkedList; import java.util.LinkedList;
@ -12,15 +14,16 @@ import java.util.List;
import java.util.Map; import java.util.Map;
public class ModelBuilder { public class ModelBuilder {
private static final Logger logger = LoggerFactory.getLogger(ModelBuilder.class);
public <U extends ModelDefinition<T>, T extends DatabaseModelDefinition> List<T> toModelDefinition(List<U> items, Class<T> clazz) { public <U extends ModelDefinition<T>, T extends DatabaseModelDefinition> List<T> toModelDefinition(List<U> items, Class<T> clazz) {
List<T> list = new LinkedList<T>(); List<T> list = new LinkedList<T>();
for (U item : items) { for (U item : items) {
try { try {
list.add(item.toDatabaseDefinition(clazz.newInstance())); list.add(item.toDatabaseDefinition(clazz.newInstance()));
} catch (InstantiationException e) { } catch (InstantiationException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
} }
return list; return list;
@ -32,9 +35,9 @@ public class ModelBuilder {
try { try {
list.add(item.toDatabaseDefinition(clazz.newInstance())); list.add(item.toDatabaseDefinition(clazz.newInstance()));
} catch (InstantiationException e) { } catch (InstantiationException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
} }
return list; return list;
@ -48,9 +51,9 @@ public class ModelBuilder {
modelItem.fromDatabaseDefinition(item); modelItem.fromDatabaseDefinition(item);
list.add(modelItem); list.add(modelItem);
} catch (InstantiationException e) { } catch (InstantiationException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
} }
return list; return list;

View File

@ -1,5 +1,7 @@
package eu.eudat.logic.utilities.builders; package eu.eudat.logic.utilities.builders;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.Node; import org.w3c.dom.Node;
@ -21,6 +23,7 @@ import java.io.StringWriter;
public class XmlBuilder { public class XmlBuilder {
private static final Logger logger = LoggerFactory.getLogger(XmlBuilder.class);
public static Document getDocument() { public static Document getDocument() {
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
@ -31,7 +34,7 @@ public class XmlBuilder {
return doc; return doc;
} catch (ParserConfigurationException e) { } catch (ParserConfigurationException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); logger.error(e.getMessage(), e);
return null; return null;
} }
} }
@ -48,7 +51,7 @@ public class XmlBuilder {
return writer.toString(); return writer.toString();
} catch (TransformerException e) { } catch (TransformerException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); logger.error(e.getMessage(), e);
return null; return null;
} }
} }
@ -63,7 +66,7 @@ public class XmlBuilder {
return doc; return doc;
} catch (ParserConfigurationException | SAXException | IOException e) { } catch (ParserConfigurationException | SAXException | IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); logger.error(e.getMessage(), e);
return null; return null;
} }
} }

View File

@ -19,15 +19,17 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTAbstractNum;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDecimalNumber; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDecimalNumber;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLvl; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLvl;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STNumberFormat; import org.openxmlformats.schemas.wordprocessingml.x2006.main.STNumberFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
public class WordBuilder { public class WordBuilder {
private static final Logger logger = LoggerFactory.getLogger(WordBuilder.class);
private Map<ParagraphStyle, ApplierWithValue<XWPFDocument, String, XWPFParagraph>> options = new HashMap<>(); private Map<ParagraphStyle, ApplierWithValue<XWPFDocument, String, XWPFParagraph>> options = new HashMap<>();
private CTAbstractNum cTAbstractNum; private CTAbstractNum cTAbstractNum;
@ -132,13 +134,13 @@ public class WordBuilder {
return document; return document;
} }
public void createPages(List<DatasetProfilePage> datasetProfilePages, XWPFDocument mainDocumentPart, Boolean createListing, VisibilityRuleService visibilityRuleService) { private void createPages(List<DatasetProfilePage> datasetProfilePages, XWPFDocument mainDocumentPart, Boolean createListing, VisibilityRuleService visibilityRuleService) {
datasetProfilePages.forEach(item -> { datasetProfilePages.forEach(item -> {
createSections(item.getSections(), mainDocumentPart, ParagraphStyle.HEADER4, 0, createListing, visibilityRuleService); createSections(item.getSections(), mainDocumentPart, ParagraphStyle.HEADER4, 0, createListing, visibilityRuleService);
}); });
} }
public void createSections(List<Section> sections, XWPFDocument mainDocumentPart, ParagraphStyle style, Integer indent, Boolean createListing, VisibilityRuleService visibilityRuleService) { private void createSections(List<Section> sections, XWPFDocument mainDocumentPart, ParagraphStyle style, Integer indent, Boolean createListing, VisibilityRuleService visibilityRuleService) {
if (createListing) this.addListing(mainDocumentPart, indent, false, true); if (createListing) this.addListing(mainDocumentPart, indent, false, true);
sections.forEach(section -> { sections.forEach(section -> {
if (visibilityRuleService.isElementVisible(section.getId())) { if (visibilityRuleService.isElementVisible(section.getId())) {
@ -153,7 +155,7 @@ public class WordBuilder {
}); });
} }
public void createCompositeFields(List<FieldSet> compositeFields, XWPFDocument mainDocumentPart, Integer indent, Boolean createListing, VisibilityRuleService visibilityRuleService) { private void createCompositeFields(List<FieldSet> compositeFields, XWPFDocument mainDocumentPart, Integer indent, Boolean createListing, VisibilityRuleService visibilityRuleService) {
if (createListing) this.addListing(mainDocumentPart, indent, true, true); if (createListing) this.addListing(mainDocumentPart, indent, true, true);
compositeFields.forEach(compositeField -> { compositeFields.forEach(compositeField -> {
if (visibilityRuleService.isElementVisible(compositeField.getId()) && hasVisibleFields(compositeField, visibilityRuleService)) { if (visibilityRuleService.isElementVisible(compositeField.getId()) && hasVisibleFields(compositeField, visibilityRuleService)) {
@ -177,7 +179,7 @@ public class WordBuilder {
}); });
} }
public void createFields(List<Field> fields, XWPFDocument mainDocumentPart, Integer indent, Boolean createListing, VisibilityRuleService visibilityRuleService) { private void createFields(List<Field> fields, XWPFDocument mainDocumentPart, Integer indent, Boolean createListing, VisibilityRuleService visibilityRuleService) {
if (createListing) this.addListing(mainDocumentPart, indent, false, false); if (createListing) this.addListing(mainDocumentPart, indent, false, false);
fields.forEach(field -> { fields.forEach(field -> {
if (visibilityRuleService.isElementVisible(field.getId())) { if (visibilityRuleService.isElementVisible(field.getId())) {
@ -187,7 +189,7 @@ public class WordBuilder {
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl(); CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
number.setVal(BigInteger.valueOf(indent)); number.setVal(BigInteger.valueOf(indent));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
} }
} }
@ -202,7 +204,7 @@ public class WordBuilder {
return paragraph; return paragraph;
} }
public void addListing(XWPFDocument document, int indent, Boolean question, Boolean hasIndication) { private void addListing(XWPFDocument document, int indent, Boolean question, Boolean hasIndication) {
CTLvl cTLvl = this.cTAbstractNum.addNewLvl(); CTLvl cTLvl = this.cTAbstractNum.addNewLvl();
String textLevel = ""; String textLevel = "";
@ -222,7 +224,7 @@ public class WordBuilder {
} }
} }
public String formatter(Field field) throws IOException { private String formatter(Field field) throws IOException {
switch (field.getViewStyle().getRenderStyle()) { switch (field.getViewStyle().getRenderStyle()) {
case "combobox": { case "combobox": {
String comboboxType = ((ComboBoxData) field.getData()).getType(); String comboboxType = ((ComboBoxData) field.getData()).getType();
@ -232,7 +234,7 @@ public class WordBuilder {
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
if (!field.getValue().equals("")) { if (!field.getValue().equals("")) {
try { try {
JSONArray jsonarray = new JSONArray(field.getValue()); JSONArray jsonarray = new JSONArray(field.getValue().toString());
for (int i = 0; i < jsonarray.length(); i++) { for (int i = 0; i < jsonarray.length(); i++) {
JSONObject jsonobject = jsonarray.getJSONObject(i); JSONObject jsonobject = jsonarray.getJSONObject(i);
String id = jsonobject.getString("id"); String id = jsonobject.getString("id");
@ -241,37 +243,39 @@ public class WordBuilder {
map.put(id, label); map.put(id, label);
} }
} }
} catch (Exception e){ } catch (Exception e) {
Map<String, String> exMap = mapper.readValue(field.getValue(), new TypeReference<Map<String, String>>() { Map<String, String> exMap = mapper.readValue(field.getValue().toString(), new TypeReference<Map<String, String>>() {
}); });
return exMap.get("label"); return exMap.get("label");
} }
} }
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
int index = 0;
for (Map.Entry<String, String> entry : map.entrySet()) { for (Map.Entry<String, String> entry : map.entrySet()) {
sb.append("\n");
sb.append(entry.getValue()); sb.append(entry.getValue());
if (index != map.size() - 1) sb.append(", ");
index++;
} }
return sb.toString(); return sb.toString();
} else if (comboboxType.equals("wordlist")) { } else if (comboboxType.equals("wordlist")) {
return field.getValue(); return field.getValue().toString();
} }
} }
case "booleanDecision": case "booleanDecision":
if (field.getValue() != null && field.getValue().equals("true")) return "Yes"; if (field.getValue() != null && field.getValue().equals("true")) return "Yes";
else return "No"; else return "No";
case "radiobox": case "radiobox":
return field.getValue(); return field.getValue().toString();
case "checkBox": case "checkBox":
CheckBoxData data = (CheckBoxData) field.getData(); CheckBoxData data = (CheckBoxData) field.getData();
if (field.getValue() == null || field.getValue().equals("false")) return null; if (field.getValue() == null || field.getValue().equals("false")) return null;
return data.getLabel(); return data.getLabel();
case "freetext": case "freetext":
return field.getValue(); return field.getValue().toString();
case "textarea": case "textarea":
return field.getValue(); return field.getValue().toString();
case "datepicker": case "datepicker":
return field.getValue(); return field.getValue().toString();
} }
return null; return null;
} }

View File

@ -7,6 +7,8 @@ import eu.eudat.models.data.user.components.datasetprofile.FieldSet;
import eu.eudat.models.data.user.components.datasetprofile.Section; import eu.eudat.models.data.user.components.datasetprofile.Section;
import eu.eudat.models.data.user.composite.DatasetProfilePage; import eu.eudat.models.data.user.composite.DatasetProfilePage;
import eu.eudat.models.data.user.composite.PagedDatasetProfile; import eu.eudat.models.data.user.composite.PagedDatasetProfile;
import org.json.JSONArray;
import org.json.JSONException;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
@ -17,9 +19,6 @@ import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
/**
* Created by ikalyvas on 3/5/2018.
*/
public class ExportXmlBuilder { public class ExportXmlBuilder {
public File build(PagedDatasetProfile pagedDatasetProfile, UUID datasetProfileId, VisibilityRuleService visibilityRuleService) throws IOException { public File build(PagedDatasetProfile pagedDatasetProfile, UUID datasetProfileId, VisibilityRuleService visibilityRuleService) throws IOException {
@ -49,7 +48,7 @@ public class ExportXmlBuilder {
return pages; return pages;
} }
public Element createSections(List<Section> sections, VisibilityRuleService visibilityRuleService, Document element) { private Element createSections(List<Section> sections, VisibilityRuleService visibilityRuleService, Document element) {
Element elementSections = element.createElement("sections"); Element elementSections = element.createElement("sections");
sections.forEach(section -> { sections.forEach(section -> {
Element elementSection = element.createElement("section"); Element elementSection = element.createElement("section");
@ -62,7 +61,7 @@ public class ExportXmlBuilder {
return elementSections; return elementSections;
} }
public Element createCompositeFields(List<FieldSet> compositeFields, VisibilityRuleService visibilityRuleService, Document element) { private Element createCompositeFields(List<FieldSet> compositeFields, VisibilityRuleService visibilityRuleService, Document element) {
Element elementComposites = element.createElement("composite-fields"); Element elementComposites = element.createElement("composite-fields");
compositeFields.forEach(compositeField -> { compositeFields.forEach(compositeField -> {
if (visibilityRuleService.isElementVisible(compositeField.getId()) && hasVisibleFields(compositeField, visibilityRuleService)) { if (visibilityRuleService.isElementVisible(compositeField.getId()) && hasVisibleFields(compositeField, visibilityRuleService)) {
@ -86,15 +85,25 @@ public class ExportXmlBuilder {
return elementComposites; return elementComposites;
} }
public Element createFields(List<Field> fields, VisibilityRuleService visibilityRuleService, Document element) { private Element createFields(List<Field> fields, VisibilityRuleService visibilityRuleService, Document element) {
Element elementFields = element.createElement("fields"); Element elementFields = element.createElement("fields");
fields.forEach(field -> { fields.forEach(field -> {
if (visibilityRuleService.isElementVisible(field.getId())) { if (visibilityRuleService.isElementVisible(field.getId())) {
Element elementField = element.createElement("field"); Element elementField = element.createElement("field");
elementField.setAttribute("id", field.getId()); elementField.setAttribute("id", field.getId());
if (field.getValue() != null && !field.getValue().isEmpty()) { if (field.getValue() != null) {
Element valueField = element.createElement("value"); Element valueField = element.createElement("value");
valueField.setTextContent(field.getValue()); try {
JSONArray jsonArray = new JSONArray(field.getValue().toString());
StringBuilder sb = new StringBuilder();
for (int i = 0; i < jsonArray.length(); i++) {
sb.append(jsonArray.getJSONObject(i).get("label").toString());
if (i != jsonArray.length() - 1) sb.append(", ");
}
valueField.setTextContent(sb.toString());
} catch (JSONException ex) {
valueField.setTextContent(field.getValue().toString());
}
elementField.appendChild(valueField); elementField.appendChild(valueField);
} }
elementFields.appendChild(elementField); elementFields.appendChild(elementField);

View File

@ -1,5 +1,7 @@
package eu.eudat.logic.utilities.documents.xml.datasetProfileXml; package eu.eudat.logic.utilities.documents.xml.datasetProfileXml;
import eu.eudat.logic.utilities.documents.xml.datasetProfileXml.datasetProfileModel.DatasetProfile; import eu.eudat.logic.utilities.documents.xml.datasetProfileXml.datasetProfileModel.DatasetProfile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException; import javax.xml.bind.JAXBException;
@ -7,6 +9,7 @@ import javax.xml.bind.Unmarshaller;
import java.io.*; import java.io.*;
public class ImportXmlBuilderDatasetProfile { public class ImportXmlBuilderDatasetProfile {
private static final Logger logger = LoggerFactory.getLogger(ImportXmlBuilderDatasetProfile.class);
public DatasetProfile build(File xmlFile) throws IOException { public DatasetProfile build(File xmlFile) throws IOException {
DatasetProfile datasetProfile = new DatasetProfile(); DatasetProfile datasetProfile = new DatasetProfile();
@ -16,7 +19,7 @@ public class ImportXmlBuilderDatasetProfile {
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
datasetProfile = (DatasetProfile) unmarshaller.unmarshal(xmlFile); datasetProfile = (DatasetProfile) unmarshaller.unmarshal(xmlFile);
} catch (JAXBException e) { } catch (JAXBException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return datasetProfile; return datasetProfile;

View File

@ -1,6 +1,8 @@
package eu.eudat.logic.utilities.documents.xml.dmpXml; package eu.eudat.logic.utilities.documents.xml.dmpXml;
import eu.eudat.logic.utilities.documents.xml.dmpXml.dmpProfileModel.DmpProfile; import eu.eudat.logic.utilities.documents.xml.dmpXml.dmpProfileModel.DmpProfile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException; import javax.xml.bind.JAXBException;
@ -9,6 +11,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
public class ImportXmlBuilderDmpProfile { public class ImportXmlBuilderDmpProfile {
private static final Logger logger = LoggerFactory.getLogger(ImportXmlBuilderDmpProfile.class);
public DmpProfile build(File xmlFile) throws IOException { public DmpProfile build(File xmlFile) throws IOException {
DmpProfile dmpProfile = new DmpProfile(); DmpProfile dmpProfile = new DmpProfile();
@ -18,7 +21,7 @@ public class ImportXmlBuilderDmpProfile {
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
dmpProfile = (DmpProfile) unmarshaller.unmarshal(xmlFile); dmpProfile = (DmpProfile) unmarshaller.unmarshal(xmlFile);
} catch (JAXBException e) { } catch (JAXBException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return dmpProfile; return dmpProfile;

View File

@ -1,16 +1,20 @@
package eu.eudat.models; package eu.eudat.models;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class HintedModelFactory { public class HintedModelFactory {
private static final Logger logger = LoggerFactory.getLogger(HintedModelFactory.class);
public static <T extends DataModel> String getHint(Class<T> clazz) { public static <T extends DataModel> String getHint(Class<T> clazz) {
try { try {
return clazz.newInstance().getHint(); return clazz.newInstance().getHint();
} catch (InstantiationException e) { } catch (InstantiationException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
return null; return null;
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
return null; return null;
} }
} }

View File

@ -1,17 +1,16 @@
package eu.eudat.models.data.dashboard.searchbar; package eu.eudat.models.data.dashboard.searchbar;
/**
* Created by ikalyvas on 7/26/2018.
*/
public class SearchBarItem { public class SearchBarItem {
private String id; private String id;
private String label; private String label;
private int type; private int type;
private boolean isPublished;
public SearchBarItem(String id, String label, int type) { public SearchBarItem(String id, String label, int type, boolean isPublished) {
this.id = id; this.id = id;
this.label = label; this.label = label;
this.type = type; this.type = type;
this.isPublished = isPublished;
} }
public String getId() { public String getId() {
@ -37,4 +36,12 @@ public class SearchBarItem {
public void setType(int type) { public void setType(int type) {
this.type = type; this.type = type;
} }
public boolean getIsPublished() {
return isPublished;
}
public void setPublished(boolean published) {
isPublished = published;
}
} }

View File

@ -1,6 +1,5 @@
package eu.eudat.models.data.datarepository; package eu.eudat.models.data.datarepository;
import com.fasterxml.jackson.annotation.JsonProperty;
import eu.eudat.data.entities.DataRepository; import eu.eudat.data.entities.DataRepository;
import eu.eudat.data.entities.UserInfo; import eu.eudat.data.entities.UserInfo;
import eu.eudat.models.DataModel; import eu.eudat.models.DataModel;
@ -8,13 +7,9 @@ import eu.eudat.models.DataModel;
import java.util.Date; import java.util.Date;
import java.util.UUID; import java.util.UUID;
/**
* Created by ikalyvas on 9/3/2018.
*/
public class DataRepositoryModel implements DataModel<DataRepository, DataRepositoryModel> { public class DataRepositoryModel implements DataModel<DataRepository, DataRepositoryModel> {
private UUID id; private UUID id;
@JsonProperty("name") private String name;
private String label;
private String pid; private String pid;
private String abbreviation; private String abbreviation;
private String uri; private String uri;
@ -30,11 +25,11 @@ public class DataRepositoryModel implements DataModel<DataRepository, DataReposi
this.id = id; this.id = id;
} }
public String getLabel() { public String getName() {
return label; return name;
} }
public void setLabel(String label) { public void setName(String name) {
this.label = label; this.name = name;
} }
public String getPid() { public String getPid() {
@ -89,9 +84,10 @@ public class DataRepositoryModel implements DataModel<DataRepository, DataReposi
@Override @Override
public DataRepositoryModel fromDataModel(DataRepository entity) { public DataRepositoryModel fromDataModel(DataRepository entity) {
this.setAbbreviation(entity.getAbbreviation()); this.setAbbreviation(entity.getAbbreviation());
this.setLabel(entity.getLabel()); this.setName(entity.getLabel());
this.setUri(entity.getUri()); this.setUri(entity.getUri());
this.setId(entity.getId()); this.setId(entity.getId());
this.setPid(entity.getReference());
String source1 = entity.getReference().substring(0, entity.getReference().indexOf(":")); String source1 = entity.getReference().substring(0, entity.getReference().indexOf(":"));
if (source1.equals("dmp")) { if (source1.equals("dmp")) {
this.source = "Internal"; this.source = "Internal";
@ -108,11 +104,15 @@ public class DataRepositoryModel implements DataModel<DataRepository, DataReposi
dataRepository.setAbbreviation(this.abbreviation); dataRepository.setAbbreviation(this.abbreviation);
dataRepository.setCreated(this.created != null ? this.created : new Date()); dataRepository.setCreated(this.created != null ? this.created : new Date());
dataRepository.setModified(new Date()); dataRepository.setModified(new Date());
dataRepository.setLabel(this.label); dataRepository.setLabel(this.name);
if (this.source.equals("Internal") || this.source.equals(this.id.toString().substring(0, this.source.length()))) { if (this.source != null) {
dataRepository.setReference(this.id.toString()); if (this.source.equals("Internal") || this.source.equals(this.id.toString().substring(0, this.source.length()))) {
dataRepository.setReference(this.id.toString());
} else {
dataRepository.setReference(this.source + ":" + dataRepository.getId());
}
} else { } else {
dataRepository.setReference(this.source + ":" + this.id); dataRepository.setReference("dmp:" + dataRepository.getId());
} }
dataRepository.setUri(this.uri); dataRepository.setUri(this.uri);
dataRepository.setStatus((short) 0); dataRepository.setStatus((short) 0);

View File

@ -4,16 +4,26 @@ 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.UUID;
public class DataRepository implements DataModel<eu.eudat.data.entities.DataRepository, DataRepository>, LabelGenerator { public class DataRepository implements DataModel<eu.eudat.data.entities.DataRepository, DataRepository>, LabelGenerator {
private String id;
private String pid; private String pid;
private String label; private String name;
private String uri; private String uri;
private String info; private String info;
private String reference; private String reference;
private String abbreviation;
private String tag; private String tag;
private String source; private String source;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPid() { public String getPid() {
return pid; return pid;
} }
@ -21,11 +31,11 @@ public class DataRepository implements DataModel<eu.eudat.data.entities.DataRepo
this.pid = pid; this.pid = pid;
} }
public String getLabel() { public String getName() {
return label; return name;
} }
public void setLabel(String label) { public void setName(String name) {
this.label = label; this.name = name;
} }
public String getUri() { public String getUri() {
@ -49,6 +59,13 @@ public class DataRepository implements DataModel<eu.eudat.data.entities.DataRepo
this.reference = reference; this.reference = reference;
} }
public String getAbbreviation() {
return abbreviation;
}
public void setAbbreviation(String abbreviation) {
this.abbreviation = abbreviation;
}
public String getTag() { public String getTag() {
return tag; return tag;
} }
@ -64,9 +81,11 @@ public class DataRepository implements DataModel<eu.eudat.data.entities.DataRepo
} }
public DataRepository fromDataModel(eu.eudat.data.entities.DataRepository entity) { public DataRepository fromDataModel(eu.eudat.data.entities.DataRepository entity) {
this.id = entity.getId().toString();
this.pid = entity.getReference(); this.pid = entity.getReference();
this.label = entity.getLabel(); this.name = entity.getLabel();
this.uri = entity.getUri(); this.uri = entity.getUri();
this.abbreviation = entity.getAbbreviation();
this.reference = entity.getReference(); this.reference = entity.getReference();
String source1 = entity.getReference().substring(0, entity.getReference().indexOf(":")); String source1 = entity.getReference().substring(0, entity.getReference().indexOf(":"));
if (source1.equals("dmp")) { if (source1.equals("dmp")) {
@ -79,8 +98,11 @@ public class DataRepository implements DataModel<eu.eudat.data.entities.DataRepo
public eu.eudat.data.entities.DataRepository toDataModel() { public eu.eudat.data.entities.DataRepository toDataModel() {
eu.eudat.data.entities.DataRepository entity = new eu.eudat.data.entities.DataRepository(); eu.eudat.data.entities.DataRepository entity = new eu.eudat.data.entities.DataRepository();
if (this.id != null) {
entity.setId(UUID.fromString(this.id));
}
entity.setReference(this.pid); entity.setReference(this.pid);
entity.setLabel(this.label); entity.setLabel(this.name);
entity.setUri(this.uri); entity.setUri(this.uri);
entity.setCreated(new Date()); entity.setCreated(new Date());
entity.setModified(new Date()); entity.setModified(new Date());
@ -94,12 +116,16 @@ public class DataRepository implements DataModel<eu.eudat.data.entities.DataRepo
entity.setReference(this.source.toLowerCase() + ":" + this.reference); entity.setReference(this.source.toLowerCase() + ":" + this.reference);
} }
} }
if (this.abbreviation != null)
entity.setAbbreviation(this.abbreviation);
return entity; return entity;
} }
@Override @Override
public String generateLabel() { public String generateLabel() {
return this.getLabel(); return this.getName();
} }
@Override @Override

View File

@ -159,7 +159,7 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
this.registries = entity.getRegistries().stream().map(item -> new Registry().fromDataModel(item)).collect(Collectors.toList()); this.registries = entity.getRegistries().stream().map(item -> new Registry().fromDataModel(item)).collect(Collectors.toList());
this.dataRepositories = entity.getDatasetDataRepositories().stream().map(item -> { this.dataRepositories = entity.getDatasetDataRepositories().stream().map(item -> {
DataRepository dataRepository = new DataRepository().fromDataModel(item.getDataRepository()); DataRepository dataRepository = new DataRepository().fromDataModel(item.getDataRepository());
if(item.getData()!=null) { if (item.getData() != null) {
Map<String, Map<String, String>> data = (Map<String, Map<String, String>>) JSONValue.parse(item.getData()); Map<String, Map<String, String>> data = (Map<String, Map<String, String>>) JSONValue.parse(item.getData());
Map<String, String> values = data.get("data"); Map<String, String> values = data.get("data");
dataRepository.setInfo(values.get("info")); dataRepository.setInfo(values.get("info"));
@ -171,7 +171,7 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
this.dmp = new DataManagementPlan().fromDataModelNoDatasets(entity.getDmp()); this.dmp = new DataManagementPlan().fromDataModelNoDatasets(entity.getDmp());
this.externalDatasets = entity.getDatasetExternalDatasets().stream().map(item -> { this.externalDatasets = entity.getDatasetExternalDatasets().stream().map(item -> {
ExternalDatasetListingModel externalDatasetListingModel = new ExternalDatasetListingModel().fromDataModel(item.getExternalDataset()); ExternalDatasetListingModel externalDatasetListingModel = new ExternalDatasetListingModel().fromDataModel(item.getExternalDataset());
if(item.getData()!= null) { if (item.getData() != null) {
Map<String, Map<String, String>> data = (Map<String, Map<String, String>>) JSONValue.parse(item.getData()); Map<String, Map<String, String>> data = (Map<String, Map<String, String>>) JSONValue.parse(item.getData());
Map<String, String> values = data.get("data"); Map<String, String> values = data.get("data");
externalDatasetListingModel.setInfo(values.get("info")); externalDatasetListingModel.setInfo(values.get("info"));
@ -214,10 +214,10 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
eu.eudat.data.entities.DataRepository dataRepository = dataRepositoryModel.toDataModel(); eu.eudat.data.entities.DataRepository dataRepository = dataRepositoryModel.toDataModel();
DatasetDataRepository datasetDataRepository = new DatasetDataRepository(); DatasetDataRepository datasetDataRepository = new DatasetDataRepository();
datasetDataRepository.setDataRepository(dataRepository); datasetDataRepository.setDataRepository(dataRepository);
Map<String,Map<String,String>> data = new HashMap<>(); Map<String, Map<String, String>> data = new HashMap<>();
Map<String,String> values = new HashMap<>(); Map<String, String> values = new HashMap<>();
values.put("info",dataRepositoryModel.getInfo()); values.put("info", dataRepositoryModel.getInfo());
data.put("data",values); data.put("data", values);
datasetDataRepository.setData(JSONValue.toJSONString(data)); datasetDataRepository.setData(JSONValue.toJSONString(data));
entity.getDatasetDataRepositories().add(datasetDataRepository); entity.getDatasetDataRepositories().add(datasetDataRepository);
} }

View File

@ -28,7 +28,7 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
private String description; private String description;
private List<DatasetListingModel> datasets; private List<DatasetListingModel> datasets;
private List<AssociatedProfile> profiles; private List<AssociatedProfile> profiles;
private eu.eudat.models.data.grant.Grant grant; private Grant grant;
private List<Organisation> organisations; private List<Organisation> organisations;
private List<Researcher> researchers; private List<Researcher> researchers;
private List<UserListingModel> associatedUsers; private List<UserListingModel> associatedUsers;
@ -218,7 +218,7 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
this.organisations = entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList()); this.organisations = entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList());
this.researchers = entity.getResearchers().stream().map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList()); this.researchers = entity.getResearchers().stream().map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList());
this.version = entity.getVersion(); this.version = entity.getVersion();
this.groupId = this.groupId == null ? null : this.groupId; this.groupId = this.groupId == null ? null : entity.getGroupId();
this.label = entity.getLabel(); this.label = entity.getLabel();
this.grant = new Grant(); this.grant = new Grant();
this.properties = entity.getProperties() != null ? new org.json.JSONObject(entity.getProperties()).toMap() : null; this.properties = entity.getProperties() != null ? new org.json.JSONObject(entity.getProperties()).toMap() : null;
@ -243,9 +243,15 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
this.profiles.add(associatedProfile); this.profiles.add(associatedProfile);
} }
} }
this.datasets = entity.getDataset().stream() if (entity.isPublic()) {
.filter(dataset -> !dataset.getStatus().equals(Dataset.Status.DELETED.getValue()) && !dataset.getStatus().equals(Dataset.Status.CANCELED.getValue())) this.datasets = entity.getDataset().stream()
.map(x-> new DatasetListingModel().fromDataModel(x)).collect(Collectors.toList()); .filter(dataset -> !dataset.getStatus().equals(Dataset.Status.DELETED.getValue()) && !dataset.getStatus().equals(Dataset.Status.CANCELED.getValue()) && !dataset.getStatus().equals(Dataset.Status.SAVED.getValue()))
.map(x-> new DatasetListingModel().fromDataModel(x)).collect(Collectors.toList());
} else {
this.datasets = entity.getDataset().stream()
.filter(dataset -> !dataset.getStatus().equals(Dataset.Status.DELETED.getValue()) && !dataset.getStatus().equals(Dataset.Status.CANCELED.getValue()))
.map(x-> new DatasetListingModel().fromDataModel(x)).collect(Collectors.toList());
}
this.modified = entity.getModified(); this.modified = entity.getModified();
this.created = entity.getCreated(); this.created = entity.getCreated();
this.description = entity.getDescription(); this.description = entity.getDescription();

View File

@ -218,11 +218,12 @@ public class DataManagementPlanEditorModel implements DataModel<DMP, DataManagem
this.organisations = entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList()); this.organisations = entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList());
this.researchers = entity.getResearchers().stream().map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList()); this.researchers = entity.getResearchers().stream().map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList());
this.version = entity.getVersion(); this.version = entity.getVersion();
this.groupId = this.groupId == null ? null : this.groupId; this.groupId = this.groupId == null ? null : entity.getGroupId();
this.label = entity.getLabel(); this.label = entity.getLabel();
this.grant = new GrantDMPEditorModel(); this.grant = new GrantDMPEditorModel();
this.properties = entity.getProperties() != null ? new org.json.JSONObject(entity.getProperties()).toMap() : null; this.properties = entity.getProperties() != null ? new org.json.JSONObject(entity.getProperties()).toMap() : null;
this.grant.getExistGrant().fromDataModel(entity.getGrant()); this.grant.getExistGrant().fromDataModel(entity.getGrant());
this.grant.getExistGrant().setSource("");
this.creator = new eu.eudat.models.data.userinfo.UserInfo(); this.creator = new eu.eudat.models.data.userinfo.UserInfo();
this.groupId = entity.getGroupId(); this.groupId = entity.getGroupId();
this.lockable = entity.getDataset().stream().findAny().isPresent(); this.lockable = entity.getDataset().stream().findAny().isPresent();
@ -278,10 +279,11 @@ public class DataManagementPlanEditorModel implements DataModel<DMP, DataManagem
dataManagementPlanEntity.setGrant(this.grant.getExistGrant().toDataModel()); dataManagementPlanEntity.setGrant(this.grant.getExistGrant().toDataModel());
else { else {
Grant grant = new Grant(); Grant grant = new Grant();
grant.setId(UUID.randomUUID());
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:" + this.grant.getLabel()); grant.setReference("dmp:" + grant.getId());
grant.setUri(""); grant.setUri("");
grant.setDefinition(""); grant.setDefinition("");
grant.setCreated(new Date()); grant.setCreated(new Date());
@ -302,9 +304,10 @@ public class DataManagementPlanEditorModel implements DataModel<DMP, DataManagem
} else { } else {
if (this.funder.getLabel() != null) { if (this.funder.getLabel() != null) {
Funder funder = new Funder(); Funder funder = new Funder();
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:" + this.funder.getLabel()); funder.setReference("dmp:" + 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());
@ -322,10 +325,11 @@ public class DataManagementPlanEditorModel implements DataModel<DMP, DataManagem
dataManagementPlanEntity.setProject(this.project.getExistProject().toDataModel()); dataManagementPlanEntity.setProject(this.project.getExistProject().toDataModel());
else { else {
Project project = new Project(); Project project = new Project();
project.setId(UUID.randomUUID());
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:" + this.project.getLabel()); project.setReference("dmp:" + project.getId());
project.setUri(""); project.setUri("");
project.setDefinition(""); project.setDefinition("");
project.setCreated(new Date()); project.setCreated(new Date());

View File

@ -182,10 +182,11 @@ public class DataManagementPlanNewVersionModel implements DataModel<DMP, DataMan
entity.setGrant(this.grant.getExistGrant().toDataModel()); entity.setGrant(this.grant.getExistGrant().toDataModel());
else { else {
eu.eudat.data.entities.Grant grant = new eu.eudat.data.entities.Grant(); eu.eudat.data.entities.Grant grant = new eu.eudat.data.entities.Grant();
grant.setId(UUID.randomUUID());
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:" + this.grant.getLabel()); grant.setReference("dmp:" + grant.getId());
grant.setUri(""); grant.setUri("");
grant.setDefinition(""); grant.setDefinition("");
grant.setCreated(new Date()); grant.setCreated(new Date());
@ -197,27 +198,28 @@ public class DataManagementPlanNewVersionModel implements DataModel<DMP, DataMan
} }
} }
if(this.funder == null && this.funder.getExistFunder() == null && this.funder.getLabel() == null) { if (this.funder == null) {
entity.getGrant().setFunder(null); // dataManagementPlanEntity.getGrant().setFunder(null);
} throw new Exception("Funder is a mandatory entity");
else if (this.funder != null && this.funder.getExistFunder() == null && this.funder.getLabel() == null) { } else if (this.funder.getExistFunder() == null && this.funder.getLabel() == null) {
entity.getGrant().setFunder(null); // dataManagementPlanEntity.getGrant().setFunder(null);
} throw new Exception("Funder is a mandatory entity");
else { } else {
if (this.funder.getLabel() != null) { if (this.funder.getLabel() != null) {
Funder funder = new Funder(); Funder funder = new Funder();
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:" + this.funder.getLabel()); funder.setReference("dmp:" + 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());
funder.setModified(new Date()); funder.setModified(new Date());
entity.getGrant().setFunder(funder); entity.getGrant().setFunder(funder);
} } else if (this.funder.getExistFunder() != null && this.funder.getLabel() == null){
else if (this.funder.getExistFunder() != null && this.funder.getLabel() == null){
entity.getGrant().setFunder(this.funder.getExistFunder().toDataModel()); entity.getGrant().setFunder(this.funder.getExistFunder().toDataModel());
entity.getGrant().getFunder().setType(Funder.FunderType.EXTERNAL.getValue());
} }
} }
@ -226,10 +228,11 @@ public class DataManagementPlanNewVersionModel implements DataModel<DMP, DataMan
entity.setProject(this.project.getExistProject().toDataModel()); entity.setProject(this.project.getExistProject().toDataModel());
else { else {
Project project = new Project(); Project project = new Project();
project.setId(UUID.randomUUID());
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:" + this.project.getLabel()); project.setReference("dmp:" + project.getId());
project.setUri(""); project.setUri("");
project.setDefinition(""); project.setDefinition("");
project.setCreated(new Date()); project.setCreated(new Date());

View File

@ -9,8 +9,10 @@ public class Organisation implements DataModel<eu.eudat.data.entities.Organisati
private String label; private String label;
private String name; private String name;
private String id; private String id;
private String reference;
private int status; private int status;
private String tag; private String tag; // how the external source is displayed. ex: "Cristin".
private String key; // the external source. ex: "cristin".
public String getLabel() { public String getLabel() {
return label; return label;
@ -33,6 +35,13 @@ public class Organisation implements DataModel<eu.eudat.data.entities.Organisati
this.id = id; this.id = id;
} }
public String getReference() {
return reference;
}
public void setReference(String reference) {
this.reference = reference;
}
public int getStatus() { public int getStatus() {
return status; return status;
} }
@ -47,26 +56,30 @@ public class Organisation implements DataModel<eu.eudat.data.entities.Organisati
this.tag = tag; this.tag = tag;
} }
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
@Override @Override
public Organisation fromDataModel(eu.eudat.data.entities.Organisation entity) { public Organisation fromDataModel(eu.eudat.data.entities.Organisation entity) {
this.id = entity.getReference(); this.id = entity.getId().toString();
this.name = entity.getLabel(); this.name = entity.getLabel();
this.label = entity.getUri(); this.label = entity.getUri();
if (entity.getReference().contains(":cristin")) { this.reference = entity.getReference();
this.tag = "cristin"; this.key = entity.getReference().substring(0, entity.getReference().indexOf(":"));
} else {
this.tag = entity.getReference().substring(0, entity.getReference().indexOf(":"));
}
return this; return this;
} }
@Override @Override
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.tag.equals(this.id.substring(0, this.tag.length()))) { if ((this.key + ":").equals(this.reference.substring(0, this.key.length() + 1))) {
organisationEntity.setReference(this.id); organisationEntity.setReference(this.reference);
} else { } else {
organisationEntity.setReference(this.tag + ":" + this.id); organisationEntity.setReference(this.key + ":" + this.reference);
} }
organisationEntity.setLabel(this.name); organisationEntity.setLabel(this.name);
organisationEntity.setUri(this.label); organisationEntity.setUri(this.label);

View File

@ -2,20 +2,25 @@ package eu.eudat.models.data.dmp;
import eu.eudat.models.DataModel; import eu.eudat.models.DataModel;
import eu.eudat.logic.utilities.helpers.LabelGenerator; import eu.eudat.logic.utilities.helpers.LabelGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date; import java.util.Date;
import java.util.UUID;
public class Researcher implements DataModel<eu.eudat.data.entities.Researcher, Researcher>, LabelGenerator { public class Researcher implements DataModel<eu.eudat.data.entities.Researcher, Researcher>, LabelGenerator {
private static final Logger logger = LoggerFactory.getLogger(Researcher.class);
private String label; private String label;
private String name; private String name;
private String id; private String id;
private String reference;
private int status; private int status;
private String tag; private String tag;
private String key;
public String getLabel() { public String getLabel() {
return label; return label;
} }
public void setLabel(String label) { public void setLabel(String label) {
this.label = label; this.label = label;
} }
@ -23,7 +28,6 @@ public class Researcher implements DataModel<eu.eudat.data.entities.Researcher,
public String getName() { public String getName() {
return name; return name;
} }
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
@ -31,15 +35,20 @@ public class Researcher implements DataModel<eu.eudat.data.entities.Researcher,
public String getId() { public String getId() {
return id; return id;
} }
public void setId(String id) { public void setId(String id) {
this.id = id; this.id = id;
} }
public String getReference() {
return reference;
}
public void setReference(String reference) {
this.reference = reference;
}
public int getStatus() { public int getStatus() {
return status; return status;
} }
public void setStatus(int status) { public void setStatus(int status) {
this.status = status; this.status = status;
} }
@ -47,38 +56,61 @@ public class Researcher implements DataModel<eu.eudat.data.entities.Researcher,
public String getTag() { public String getTag() {
return tag; return tag;
} }
public void setTag(String tag) { public void setTag(String tag) {
this.tag = tag; this.tag = tag;
} }
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
@Override @Override
public Researcher fromDataModel(eu.eudat.data.entities.Researcher entity) { public Researcher fromDataModel(eu.eudat.data.entities.Researcher entity) {
this.id = entity.getReference(); this.id = entity.getId().toString();
this.label = entity.getUri(); this.label = entity.getUri();
this.name = entity.getLabel(); this.name = entity.getLabel();
this.status = entity.getStatus(); this.status = entity.getStatus();
this.reference = entity.getReference();
if (entity.getReference().contains(":cristin")) { String source = entity.getReference().substring(0, entity.getReference().indexOf(":"));
this.tag = "cristin"; if (source.equals("dmp"))
} else { this.key = "Internal";
String source = entity.getReference().substring(0, entity.getReference().indexOf(":")); else
if (source.equals("dmp")) this.key = source;
this.tag = "Internal";
else
this.tag = source;
}
return this; return this;
} }
@Override @Override
public eu.eudat.data.entities.Researcher toDataModel() { public eu.eudat.data.entities.Researcher toDataModel() {
eu.eudat.data.entities.Researcher researcher = new eu.eudat.data.entities.Researcher(); eu.eudat.data.entities.Researcher researcher = new eu.eudat.data.entities.Researcher();
if (this.tag.equals("Internal") || this.tag.equals(this.id.substring(0, this.tag.length()))) { if (this.id == null) {
researcher.setReference(this.id); this.id = UUID.randomUUID().toString();
} else {
researcher.setReference(this.tag + ":" + this.id);
} }
researcher.setId(UUID.fromString(this.id));
if (this.key != null) {
if (this.key.toLowerCase().equals("internal")) {
if (this.reference != null && "dmp".equals(this.reference.substring(0, 3))) {
researcher.setReference(this.reference);
} else {
researcher.setReference("dmp:" + this.id);
}
} else {
if ((this.key + ":").equals(this.reference.substring(0, this.key.length() + 1))) {
researcher.setReference(this.reference);
} else {
researcher.setReference(this.key + ":" + this.reference);
}
}
} else {
try {
throw new Exception("Researcher has no key value");
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
researcher.setLabel(this.name); researcher.setLabel(this.name);
researcher.setUri(this.label); researcher.setUri(this.label);
researcher.setCreated(new Date()); researcher.setCreated(new Date());
@ -108,6 +140,6 @@ public class Researcher implements DataModel<eu.eudat.data.entities.Researcher,
@Override @Override
public int hashCode() { public int hashCode() {
return id.hashCode(); return reference.hashCode();
} }
} }

View File

@ -11,6 +11,7 @@ public class ExternalSourcesItemModel {
private String abbreviation; private String abbreviation;
private String tag; private String tag;
private String source; private String source;
private String key;
public String getId() { public String getId() {
return id; return id;
@ -74,4 +75,11 @@ public class ExternalSourcesItemModel {
public void setSource(String source) { public void setSource(String source) {
this.source = source; this.source = source;
} }
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
} }

View File

@ -15,6 +15,7 @@ public class FundersExternalSourcesModel extends ExternalListingItem<FundersExte
model.setDescription(item.get("description")); model.setDescription(item.get("description"));
model.setSource(item.get("source")); model.setSource(item.get("source"));
model.setTag(item.get("tag")); model.setTag(item.get("tag"));
model.setKey(item.get("key"));
this.add(model); this.add(model);
} }
return this; return this;

View File

@ -14,6 +14,7 @@ public class GrantsExternalSourcesModel extends ExternalListingItem<GrantsExtern
model.setName(item.get("name")); model.setName(item.get("name"));
model.setDescription(item.get("description")); model.setDescription(item.get("description"));
model.setTag(item.get("tag")); model.setTag(item.get("tag"));
model.setKey(item.get("key"));
this.add(model); this.add(model);
} }
return this; return this;

View File

@ -11,10 +11,11 @@ public class OrganisationsExternalSourcesModel extends ExternalListingItem<Organ
public OrganisationsExternalSourcesModel fromExternalItem(List<Map<String, String>> values) { public OrganisationsExternalSourcesModel fromExternalItem(List<Map<String, String>> values) {
for (Map<String, String> item : values) { for (Map<String, String> item : values) {
ExternalSourcesItemModel model = new ExternalSourcesItemModel(); ExternalSourcesItemModel model = new ExternalSourcesItemModel();
model.setId(item.get("pid")); model.setRemoteId(item.get("pid"));
model.setUri(item.get("uri")); model.setUri(item.get("uri"));
model.setName(item.get("name")); model.setName(item.get("name"));
model.setTag(item.get("tag")); model.setTag(item.get("tag"));
model.setKey(item.get("key"));
this.add(model); this.add(model);
} }
return this; return this;

View File

@ -2,12 +2,15 @@ package eu.eudat.models.data.external;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class ProjectsExternalSourcesModel extends ExternalListingItem<ProjectsExternalSourcesModel> { public class ProjectsExternalSourcesModel extends ExternalListingItem<ProjectsExternalSourcesModel> {
private static final Logger logger = LoggerFactory.getLogger(ProjectsExternalSourcesModel.class);
private static final ObjectMapper mapper = new ObjectMapper(); private static final ObjectMapper mapper = new ObjectMapper();
@Override @Override
@ -51,10 +54,17 @@ public class ProjectsExternalSourcesModel extends ExternalListingItem<ProjectsEx
model.setTag(item.get("tag")); model.setTag(item.get("tag"));
} }
JsonNode key = node.get("key");
if (key != null && !key.isNull() && key.isObject()) {
model.setKey(node.get("key").get("$").asText());
} else {
model.setKey(item.get("key"));
}
this.add(model); this.add(model);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
} }
return this; return this;

View File

@ -9,10 +9,11 @@ public class ResearchersExternalSourcesModel extends ExternalListingItem<Researc
public ResearchersExternalSourcesModel fromExternalItem(List<Map<String, String>> values) { public ResearchersExternalSourcesModel fromExternalItem(List<Map<String, String>> values) {
for (Map<String, String> item : values) { for (Map<String, String> item : values) {
ExternalSourcesItemModel model = new ExternalSourcesItemModel(); ExternalSourcesItemModel model = new ExternalSourcesItemModel();
model.setId(item.get("pid")); model.setRemoteId(item.get("pid"));
model.setUri(item.get("uri")); model.setUri(item.get("uri"));
model.setName(item.get("name")); model.setName(item.get("name"));
model.setTag(item.get("tag")); model.setTag(item.get("tag"));
model.setKey(item.get("key"));
this.add(model); this.add(model);
} }
return this; return this;

View File

@ -140,6 +140,9 @@ public class ExternalDatasetListingModel implements DataModel<ExternalDataset, E
externalDataset.setReference(this.source.toLowerCase() + ":" + this.reference); externalDataset.setReference(this.source.toLowerCase() + ":" + this.reference);
} }
} }
if (externalDataset.getReference() == null) {
externalDataset.setReference(this.pid);
}
externalDataset.setModified(new Date()); externalDataset.setModified(new Date());
return externalDataset; return externalDataset;
} }

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