Merge branch 'Development'
This commit is contained in:
commit
1b4952a909
|
@ -1,5 +1,7 @@
|
|||
package eu.eudat.data.converters;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.format.datetime.DateFormatter;
|
||||
|
||||
import javax.persistence.AttributeConverter;
|
||||
|
@ -15,6 +17,7 @@ import java.util.TimeZone;
|
|||
*/
|
||||
@Converter
|
||||
public class DateToUTCConverter implements AttributeConverter<Date, Date> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DateToUTCConverter.class);
|
||||
|
||||
@Override
|
||||
public Date convertToDatabaseColumn(Date attribute) {
|
||||
|
@ -25,7 +28,7 @@ public class DateToUTCConverter implements AttributeConverter<Date, Date> {
|
|||
String date = formatterIST.format(attribute);
|
||||
return formatterIST.parse(date);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -39,7 +42,7 @@ public class DateToUTCConverter implements AttributeConverter<Date, Date> {
|
|||
String date = formatterIST.format(dbData);
|
||||
return formatterIST.parse(date);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@ public class DataManagementPlanPublicCriteria extends Criteria<DMP> {
|
|||
public List<UUID> datasetProfile;
|
||||
private List<String> dmpOrganisations;
|
||||
private Integer role;
|
||||
private boolean allVersions;
|
||||
private List<UUID> groupIds;
|
||||
|
||||
public GrantStateType getGrantStatus() {
|
||||
return grantStatus;
|
||||
|
@ -47,4 +49,18 @@ public class DataManagementPlanPublicCriteria extends Criteria<DMP> {
|
|||
public void setRole(Integer 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ public class DatasetCriteria extends Criteria<Dataset> {
|
|||
private List<UUID> grants;
|
||||
private List<UUID> collaborators;
|
||||
private List<UUID> datasetTemplates;
|
||||
private List<UUID> groupIds;
|
||||
|
||||
public boolean getAllVersions() {
|
||||
return allVersions;
|
||||
|
@ -105,4 +106,11 @@ public class DatasetCriteria extends Criteria<Dataset> {
|
|||
public void setDatasetTemplates(List<UUID> datasetTemplates) {
|
||||
this.datasetTemplates = datasetTemplates;
|
||||
}
|
||||
|
||||
public List<UUID> getGroupIds() {
|
||||
return groupIds;
|
||||
}
|
||||
public void setGroupIds(List<UUID> groupIds) {
|
||||
this.groupIds = groupIds;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ public class DatasetProfileCriteria extends Criteria<DatasetProfile> {
|
|||
private List<UUID> groupIds;
|
||||
private Short filter;
|
||||
private UUID userId;
|
||||
private boolean finalized;
|
||||
|
||||
public boolean getAllVersions() { return allVersions; }
|
||||
public void setAllVersions(boolean allVersions) { this.allVersions = allVersions; }
|
||||
|
@ -52,4 +53,11 @@ public class DatasetProfileCriteria extends Criteria<DatasetProfile> {
|
|||
public void setUserId(UUID userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public boolean getFinalized() {
|
||||
return finalized;
|
||||
}
|
||||
public void setFinalized(boolean finalized) {
|
||||
this.finalized = finalized;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,13 +6,14 @@ import eu.eudat.data.entities.Dataset;
|
|||
import eu.eudat.data.entities.UserInfo;
|
||||
import eu.eudat.queryable.QueryableList;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface DatasetDao extends DatabaseAccessLayer<Dataset, UUID> {
|
||||
|
||||
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);
|
||||
|
||||
|
|
|
@ -13,8 +13,10 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.persistence.criteria.Join;
|
||||
import javax.persistence.criteria.JoinType;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
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()));
|
||||
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)));
|
||||
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())
|
||||
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()));
|
||||
} else {
|
||||
query.where((builder, root) -> root.join("dmp").join("users").get("role").in(UserDMP.UserDMPRoles.getAllValues()));
|
||||
}
|
||||
}*/
|
||||
if (criteria.getOrganisations() != null && !criteria.getOrganisations().isEmpty())
|
||||
query.where((builder, root) -> root.join("dmp").join("organisations").get("reference").in(criteria.getOrganisations()));
|
||||
if (criteria.getGrants() != null && !criteria.getGrants().isEmpty())
|
||||
|
@ -87,9 +91,13 @@ public class DatasetDaoImpl extends DatabaseAccess<Dataset> implements DatasetDa
|
|||
}
|
||||
|
||||
@Override
|
||||
public QueryableList<Dataset> getAuthenticated(QueryableList<Dataset> query, UserInfo principal) {
|
||||
if (principal.getId() == null) query.where((builder, root) -> builder.equal(root.get("isPublic"), true));
|
||||
else {
|
||||
public QueryableList<Dataset> getAuthenticated(QueryableList<Dataset> query, UserInfo principal, List<Integer> roles) {
|
||||
if (roles != null && !roles.isEmpty()) {
|
||||
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()));
|
||||
}
|
||||
return query;
|
||||
|
|
|
@ -52,7 +52,11 @@ public class DatasetProfileDaoImpl extends DatabaseAccess<DatasetProfile> implem
|
|||
builder.notEqual(root.get("id"), criteria.getUserId())));
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ public class GrantDaoImpl extends DatabaseAccess<Grant> implements GrantDao {
|
|||
if (criteria.getFunderId() != null && !criteria.getFunderId().trim().isEmpty())
|
||||
query.where((builder, root) -> builder.equal(root.get("funder").get("id"), UUID.fromString(criteria.getFunderId())));
|
||||
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()));
|
||||
return query;
|
||||
}
|
||||
|
|
|
@ -281,20 +281,41 @@ public class Dataset implements DataEntity<Dataset, UUID> {
|
|||
this.setLabel(entity.getLabel());
|
||||
this.setProperties(entity.getProperties());
|
||||
|
||||
if (entity.getDatasetDataRepositories() == null || entity.getDatasetDataRepositories().size() < 1) {
|
||||
if (this.getDatasetDataRepositories() != null) this.getDatasetDataRepositories().removeAll(this.getDatasetDataRepositories());
|
||||
} else {
|
||||
if (this.getDatasetDataRepositories() != null) {
|
||||
this.getDatasetDataRepositories().removeAll(this.getDatasetDataRepositories());
|
||||
if (entity.getDatasetDataRepositories() != null)
|
||||
this.getDatasetDataRepositories().addAll(entity.getDatasetDataRepositories());
|
||||
} else {
|
||||
this.setDatasetDataRepositories(new HashSet<>());
|
||||
}
|
||||
this.getDatasetDataRepositories().addAll(entity.getDatasetDataRepositories().stream().peek(item -> item.setDataset(this)).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
if (entity.getDatasetExternalDatasets() == null || entity.getDatasetExternalDatasets().size() < 1) {
|
||||
if (this.getDatasetExternalDatasets() != null) this.getDatasetExternalDatasets().removeAll(this.getDatasetExternalDatasets());
|
||||
} else {
|
||||
if (this.getDatasetExternalDatasets() != null) {
|
||||
this.getDatasetExternalDatasets().removeAll(this.getDatasetExternalDatasets());
|
||||
if (entity.getDatasetExternalDatasets() != null)
|
||||
this.getDatasetExternalDatasets().addAll(entity.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.getServices().removeAll(this.getServices());
|
||||
if (entity.getServices() != null)
|
||||
this.getServices().addAll(entity.getServices());
|
||||
|
||||
this.setDmp(entity.getDmp());
|
||||
this.setStatus(entity.getStatus());
|
||||
this.setProfile(entity.getProfile());
|
||||
|
|
|
@ -66,8 +66,8 @@ public class Funder implements DataEntity<Funder, UUID> {
|
|||
}
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@GenericGenerator(name = "uuid2", strategy = "uuid2")
|
||||
//@GeneratedValue
|
||||
//@GenericGenerator(name = "uuid2", strategy = "uuid2")
|
||||
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
||||
private UUID id;
|
||||
|
||||
|
|
|
@ -81,8 +81,8 @@ public class Grant implements DataEntity<Grant, UUID> {
|
|||
}
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@GenericGenerator(name = "uuid2", strategy = "uuid2")
|
||||
//@GeneratedValue
|
||||
//@GenericGenerator(name = "uuid2", strategy = "uuid2")
|
||||
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
||||
private UUID id;
|
||||
|
||||
|
|
|
@ -67,8 +67,8 @@ public class Project implements DataEntity<Project, UUID> {
|
|||
}
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@GenericGenerator(name = "uuid2", strategy = "uuid2")
|
||||
//@GeneratedValue
|
||||
//@GenericGenerator(name = "uuid2", strategy = "uuid2")
|
||||
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
||||
private UUID id;
|
||||
|
||||
|
|
|
@ -19,8 +19,8 @@ import java.util.UUID;
|
|||
public class Researcher implements DataEntity<Researcher, UUID> {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@GenericGenerator(name = "uuid2", strategy = "uuid2")
|
||||
/*@GeneratedValue
|
||||
@GenericGenerator(name = "uuid2", strategy = "uuid2")*/
|
||||
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
||||
private UUID id;
|
||||
|
||||
|
|
|
@ -3,8 +3,11 @@ package eu.eudat.data.query.definition;
|
|||
import eu.eudat.data.dao.criteria.Criteria;
|
||||
import eu.eudat.queryable.QueryableList;
|
||||
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> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(Query.class);
|
||||
private C criteria;
|
||||
private QueryableList<T> query;
|
||||
|
||||
|
@ -33,10 +36,8 @@ public abstract class Query<C extends Criteria<T>, T extends DataEntity> impleme
|
|||
q.setCriteria(criteria);
|
||||
q.setQuery(query);
|
||||
return q;
|
||||
} catch (InstantiationException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
logger.error (e.getMessage(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -5,8 +5,11 @@ import eu.eudat.data.entities.DMP;
|
|||
import eu.eudat.data.query.PaginationService;
|
||||
import eu.eudat.data.query.definition.TableQuery;
|
||||
import eu.eudat.queryable.QueryableList;
|
||||
import eu.eudat.queryable.types.FieldSelectionType;
|
||||
import eu.eudat.queryable.types.SelectionField;
|
||||
import eu.eudat.types.grant.GrantStateType;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
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));
|
||||
if (this.getCriteria().getDmpOrganisations() != null && !this.getCriteria().getDmpOrganisations().isEmpty())
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package eu.eudat.elastic.entities;
|
||||
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
|
@ -11,6 +13,7 @@ import java.util.Map;
|
|||
* Created by ikalyvas on 7/5/2018.
|
||||
*/
|
||||
public class Dataset implements ElasticEntity<Dataset> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(Dataset.class);
|
||||
|
||||
private String id;
|
||||
private List<Tag> tags = new LinkedList<>();
|
||||
|
@ -40,7 +43,7 @@ public class Dataset implements ElasticEntity<Dataset> {
|
|||
try {
|
||||
x.toElasticEntity(builder);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
});
|
||||
builder.endArray();
|
||||
|
|
|
@ -6,6 +6,8 @@ import eu.eudat.elastic.entities.ElasticEntity;
|
|||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.client.RestClient;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -13,6 +15,7 @@ import java.io.IOException;
|
|||
* Created by ikalyvas on 7/5/2018.
|
||||
*/
|
||||
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;
|
||||
|
||||
public RestHighLevelClient getClient() {
|
||||
|
@ -29,7 +32,7 @@ public abstract class ElasticRepository<T extends ElasticEntity,C extends Criter
|
|||
try {
|
||||
item = mapper.readValue(value, tClass);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
|
|
@ -28,14 +28,14 @@ import java.util.Map;
|
|||
* Created by ikalyvas on 5/30/2018.
|
||||
*/
|
||||
|
||||
@Service("logger")
|
||||
//@Service("logger")
|
||||
public class HttpRemoteLogger extends AbstractBatchLogger implements Logger {
|
||||
|
||||
private RestTemplate rest;
|
||||
private HttpHeaders headers;
|
||||
private Environment environment;
|
||||
|
||||
@Autowired
|
||||
//@Autowired
|
||||
public HttpRemoteLogger(Environment environment) {
|
||||
super(environment);
|
||||
this.rest = new RestTemplate();
|
||||
|
|
|
@ -7,6 +7,8 @@ import eu.eudat.queryable.jpa.predicates.*;
|
|||
import eu.eudat.queryable.queryableentity.DataEntity;
|
||||
import eu.eudat.queryable.types.FieldSelectionType;
|
||||
import eu.eudat.queryable.types.SelectionField;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
@ -18,6 +20,7 @@ import java.util.concurrent.CompletableFuture;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
public class QueryableHibernateList<T extends DataEntity> implements QueryableList<T> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(QueryableHibernateList.class);
|
||||
|
||||
private Collector collector = new Collector();
|
||||
private EntityManager manager;
|
||||
|
@ -264,7 +267,7 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
|
|||
try {
|
||||
return (T) this.tClass.newInstance().buildFromTuple(groupedResults.get(x.get("id")), this.fields, "");
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return null;
|
||||
}).collect(Collectors.toList()));
|
||||
|
|
|
@ -2,6 +2,8 @@ package eu.eudat.cache;
|
|||
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.cache.guava.GuavaCache;
|
||||
|
@ -17,6 +19,7 @@ import java.util.concurrent.TimeUnit;
|
|||
@Component
|
||||
@EnableCaching
|
||||
public class ResponsesCache {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ResponsesCache.class);
|
||||
|
||||
public static long HOW_MANY = 30;
|
||||
public static TimeUnit TIME_UNIT = TimeUnit.MINUTES;
|
||||
|
@ -24,7 +27,7 @@ public class ResponsesCache {
|
|||
|
||||
@Bean
|
||||
public CacheManager cacheManager() {
|
||||
System.out.print("Loading ResponsesCache...");
|
||||
logger.info("Loading ResponsesCache...");
|
||||
SimpleCacheManager simpleCacheManager = new SimpleCacheManager();
|
||||
List<GuavaCache> caches = new ArrayList<GuavaCache>();
|
||||
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("externalDatasets", CacheBuilder.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build()));
|
||||
simpleCacheManager.setCaches(caches);
|
||||
System.out.println("OK");
|
||||
logger.info("OK");
|
||||
return simpleCacheManager;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,6 @@ public class WebMVCConfiguration extends WebMvcConfigurerAdapter {
|
|||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(new RequestInterceptor(this.apiContext.getHelpersService().getLoggerService()));
|
||||
// registry.addInterceptor(new RequestInterceptor(this.apiContext.getHelpersService().getLoggerService()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ import eu.eudat.configurations.dynamicfunder.entities.Configuration;
|
|||
import eu.eudat.configurations.dynamicfunder.entities.Property;
|
||||
import eu.eudat.models.data.dynamicfields.Dependency;
|
||||
import eu.eudat.models.data.dynamicfields.DynamicField;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -19,6 +21,7 @@ import java.util.List;
|
|||
@Service("dynamicFunderConfiguration")
|
||||
@Profile("devel")
|
||||
public class DynamicFunderConfigurationDevelImpl implements DynamicFunderConfiguration {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DynamicFunderConfigurationDevelImpl.class);
|
||||
|
||||
private Configuration configuration;
|
||||
private List<DynamicField> fields;
|
||||
|
@ -32,7 +35,7 @@ public class DynamicFunderConfigurationDevelImpl implements DynamicFunderConfigu
|
|||
public Configuration getConfiguration() {
|
||||
if (this.configuration != null) return this.configuration;
|
||||
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;
|
||||
InputStream is = null;
|
||||
try {
|
||||
|
@ -43,13 +46,12 @@ public class DynamicFunderConfigurationDevelImpl implements DynamicFunderConfigu
|
|||
is = new URL("file:///"+ current + "/web/src/main/resources/FunderConfiguration.xml").openStream();
|
||||
this.configuration = (Configuration) jaxbUnmarshaller.unmarshal(is);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
System.out.println("Cannot find in folder" + current);
|
||||
logger.error("Cannot find in folder" + current, ex);
|
||||
} finally {
|
||||
try {
|
||||
if (is != null) is.close();
|
||||
} 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;
|
||||
|
|
|
@ -4,6 +4,8 @@ import eu.eudat.configurations.dynamicfunder.entities.Configuration;
|
|||
import eu.eudat.configurations.dynamicfunder.entities.Property;
|
||||
import eu.eudat.models.data.dynamicfields.Dependency;
|
||||
import eu.eudat.models.data.dynamicfields.DynamicField;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -20,6 +22,7 @@ import java.util.List;
|
|||
@Service("dynamicFunderConfiguration")
|
||||
@Profile({ "production", "staging" })
|
||||
public class DynamicFunderConfigurationProdImpl implements DynamicFunderConfiguration {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DynamicFunderConfigurationProdImpl.class);
|
||||
|
||||
private Configuration configuration;
|
||||
private List<DynamicField> fields;
|
||||
|
@ -33,7 +36,7 @@ public class DynamicFunderConfigurationProdImpl implements DynamicFunderConfigur
|
|||
public Configuration getConfiguration() {
|
||||
if (this.configuration != null) return this.configuration;
|
||||
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;
|
||||
InputStream is = null;
|
||||
try {
|
||||
|
@ -44,13 +47,12 @@ public class DynamicFunderConfigurationProdImpl implements DynamicFunderConfigur
|
|||
is = new URL(Paths.get(fileUrl).toUri().toURL().toString()).openStream();
|
||||
this.configuration = (Configuration) jaxbUnmarshaller.unmarshal(is);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
System.out.println("Cannot find in folder" + current);
|
||||
logger.error("Cannot find in folder" + current, ex);
|
||||
} finally {
|
||||
try {
|
||||
if (is != null) is.close();
|
||||
} 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;
|
||||
|
|
|
@ -4,6 +4,8 @@ import eu.eudat.configurations.dynamicgrant.entities.Configuration;
|
|||
import eu.eudat.configurations.dynamicgrant.entities.Property;
|
||||
import eu.eudat.models.data.dynamicfields.Dependency;
|
||||
import eu.eudat.models.data.dynamicfields.DynamicField;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
@ -24,6 +26,7 @@ import java.util.List;
|
|||
@Service("dynamicGrantConfiguration")
|
||||
@Profile("devel")
|
||||
public class DynamicGrantConfigurationDevelImpl implements DynamicGrantConfiguration {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DynamicGrantConfigurationDevelImpl.class);
|
||||
|
||||
private Configuration configuration;
|
||||
|
||||
|
@ -40,7 +43,7 @@ public class DynamicGrantConfigurationDevelImpl implements DynamicGrantConfigura
|
|||
public Configuration getConfiguration() {
|
||||
if (this.configuration != null) return this.configuration;
|
||||
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;
|
||||
InputStream is = null;
|
||||
try {
|
||||
|
@ -51,13 +54,12 @@ public class DynamicGrantConfigurationDevelImpl implements DynamicGrantConfigura
|
|||
is = new URL("file:///"+ current + "/web/src/main/resources/GrantConfiguration.xml").openStream();
|
||||
this.configuration = (Configuration) jaxbUnmarshaller.unmarshal(is);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
System.out.println("Cannot find in folder" + current);
|
||||
logger.error("Cannot find in folder" + current, ex);
|
||||
} finally {
|
||||
try {
|
||||
if (is != null) is.close();
|
||||
} 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;
|
||||
|
|
|
@ -4,6 +4,8 @@ import eu.eudat.configurations.dynamicgrant.entities.Configuration;
|
|||
import eu.eudat.configurations.dynamicgrant.entities.Property;
|
||||
import eu.eudat.models.data.dynamicfields.Dependency;
|
||||
import eu.eudat.models.data.dynamicfields.DynamicField;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
@ -24,6 +26,7 @@ import java.util.List;
|
|||
@Service("dynamicGrantConfiguration")
|
||||
@Profile({ "production", "staging" })
|
||||
public class DynamicGrantConfigurationProdImpl implements DynamicGrantConfiguration {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DynamicGrantConfigurationProdImpl.class);
|
||||
|
||||
private Configuration configuration;
|
||||
|
||||
|
@ -40,7 +43,7 @@ public class DynamicGrantConfigurationProdImpl implements DynamicGrantConfigurat
|
|||
public Configuration getConfiguration() {
|
||||
if (this.configuration != null) return this.configuration;
|
||||
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;
|
||||
InputStream is = null;
|
||||
try {
|
||||
|
@ -51,13 +54,12 @@ public class DynamicGrantConfigurationProdImpl implements DynamicGrantConfigurat
|
|||
is = new URL(Paths.get(fileUrl).toUri().toURL().toString()).openStream();
|
||||
this.configuration = (Configuration) jaxbUnmarshaller.unmarshal(is);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
System.out.println("Cannot find in folder" + current);
|
||||
logger.error("Cannot find in folder" + current, ex);
|
||||
} finally {
|
||||
try {
|
||||
if (is != null) is.close();
|
||||
} 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;
|
||||
|
|
|
@ -4,6 +4,8 @@ import eu.eudat.configurations.dynamicproject.entities.Configuration;
|
|||
import eu.eudat.configurations.dynamicproject.entities.Property;
|
||||
import eu.eudat.models.data.dynamicfields.Dependency;
|
||||
import eu.eudat.models.data.dynamicfields.DynamicField;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
@ -20,6 +22,7 @@ import java.util.List;
|
|||
@Service("dynamicProjectConfiguration")
|
||||
@Profile("devel")
|
||||
public class DynamicProjectConfigurationDevelImpl implements DynamicProjectConfiguration{
|
||||
private static final Logger logger = LoggerFactory.getLogger(DynamicProjectConfigurationDevelImpl.class);
|
||||
|
||||
private Configuration configuration;
|
||||
private List<DynamicField> fields;
|
||||
|
@ -34,7 +37,7 @@ public class DynamicProjectConfigurationDevelImpl implements DynamicProjectConfi
|
|||
public Configuration getConfiguration() {
|
||||
if (this.configuration != null) return this.configuration;
|
||||
String fileUrl = this.environment.getProperty("configuration.dynamicProjectUrl");
|
||||
System.out.println("Loaded also config file: " + fileUrl);
|
||||
logger.info("Loaded also config file: " + fileUrl);
|
||||
String current = null;
|
||||
InputStream is = null;
|
||||
try {
|
||||
|
@ -45,13 +48,12 @@ public class DynamicProjectConfigurationDevelImpl implements DynamicProjectConfi
|
|||
is = new URL("file:///"+ current + "/web/src/main/resources/ProjectConfiguration.xml").openStream();
|
||||
this.configuration = (Configuration) jaxbUnmarshaller.unmarshal(is);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
System.out.println("Cannot find in folder" + current);
|
||||
logger.error("Cannot find in folder" + current, ex);
|
||||
} finally {
|
||||
try {
|
||||
if (is != null) is.close();
|
||||
} 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;
|
||||
|
|
|
@ -4,6 +4,8 @@ import eu.eudat.configurations.dynamicproject.entities.Configuration;
|
|||
import eu.eudat.configurations.dynamicproject.entities.Property;
|
||||
import eu.eudat.models.data.dynamicfields.Dependency;
|
||||
import eu.eudat.models.data.dynamicfields.DynamicField;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
@ -21,6 +23,7 @@ import java.util.List;
|
|||
@Service("dynamicProjectConfiguration")
|
||||
@Profile({ "production", "staging" })
|
||||
public class DynamicProjectConfigurationProdImpl implements DynamicProjectConfiguration{
|
||||
private static final Logger logger = LoggerFactory.getLogger(DynamicProjectConfigurationProdImpl.class);
|
||||
|
||||
private Configuration configuration;
|
||||
|
||||
|
@ -37,7 +40,7 @@ public class DynamicProjectConfigurationProdImpl implements DynamicProjectConfig
|
|||
public Configuration getConfiguration() {
|
||||
if (this.configuration != null) return this.configuration;
|
||||
String fileUrl = this.environment.getProperty("configuration.dynamicProjectUrl");
|
||||
System.out.println("Loaded also config file: " + fileUrl);
|
||||
logger.info("Loaded also config file: " + fileUrl);
|
||||
String current = null;
|
||||
InputStream is = null;
|
||||
try {
|
||||
|
@ -48,13 +51,12 @@ public class DynamicProjectConfigurationProdImpl implements DynamicProjectConfig
|
|||
is = new URL(Paths.get(fileUrl).toUri().toURL().toString()).openStream();
|
||||
this.configuration = (Configuration) jaxbUnmarshaller.unmarshal(is);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
System.out.println("Cannot find in folder" + current);
|
||||
logger.error("Cannot find in folder" + current, ex);
|
||||
} finally {
|
||||
try {
|
||||
if (is != null) is.close();
|
||||
} 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;
|
||||
|
|
|
@ -42,7 +42,7 @@ public class Admin extends BaseController {
|
|||
private ConfigLoader configLoader;
|
||||
|
||||
@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);
|
||||
this.datasetProfileManager = datasetProfileManager;
|
||||
this.userManager = userManager;
|
||||
|
|
|
@ -9,7 +9,7 @@ import org.springframework.web.bind.annotation.InitBinder;
|
|||
|
||||
public abstract class BaseController {
|
||||
|
||||
private Logger logger;
|
||||
/*private Logger logger;*/
|
||||
|
||||
private ApiContext apiContext;
|
||||
|
||||
|
@ -17,9 +17,9 @@ public abstract class BaseController {
|
|||
return apiContext;
|
||||
}
|
||||
|
||||
public Logger getLoggerService() {
|
||||
/*public Logger getLoggerService() {
|
||||
return logger;
|
||||
}
|
||||
}*/
|
||||
|
||||
public BaseController(ApiContext apiContext) {
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@ import eu.eudat.models.data.ContactEmail.ContactEmailModel;
|
|||
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
||||
import eu.eudat.models.data.security.Principal;
|
||||
import eu.eudat.types.ApiMessageCode;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
@ -15,6 +17,7 @@ import javax.transaction.Transactional;
|
|||
@CrossOrigin
|
||||
@RequestMapping(value = "api/contactEmail")
|
||||
public class ContactEmail {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ContactEmail.class);
|
||||
|
||||
private ContactEmailManager contactEmailManager;
|
||||
|
||||
|
@ -31,7 +34,7 @@ public class ContactEmail {
|
|||
this.contactEmailManager.sendContactEmail(contactEmailModel, principal);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE));
|
||||
} 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()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@ import eu.eudat.models.data.security.Principal;
|
|||
import eu.eudat.query.DMPQuery;
|
||||
import eu.eudat.types.ApiMessageCode;
|
||||
import eu.eudat.types.Authorities;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
|
@ -55,6 +57,7 @@ import java.util.UUID;
|
|||
@CrossOrigin
|
||||
@RequestMapping(value = {"/api/dmps/"})
|
||||
public class DMPs extends BaseController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DMPs.class);
|
||||
|
||||
private DynamicGrantConfiguration dynamicGrantConfiguration;
|
||||
private Environment environment;
|
||||
|
@ -95,7 +98,7 @@ public class DMPs extends BaseController {
|
|||
if (contentType.equals("application/xml") || contentType.equals("application/msword")) {
|
||||
return this.dataManagementPlanManager.getDocument(id, contentType, principal, this.configLoader);
|
||||
} 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));
|
||||
}
|
||||
}
|
||||
|
@ -110,14 +113,18 @@ public class DMPs extends BaseController {
|
|||
@RequestMapping(method = RequestMethod.GET, value = {"rda/{id}"})
|
||||
public @ResponseBody
|
||||
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}"})
|
||||
public @ResponseBody
|
||||
ResponseEntity getOverviewSingle(@PathVariable String id, Principal principal) throws IllegalAccessException, InstantiationException {
|
||||
ResponseEntity getOverviewSingle(@PathVariable String id, Principal principal) {
|
||||
try {
|
||||
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}"})
|
||||
|
@ -195,7 +202,7 @@ public class DMPs extends BaseController {
|
|||
String name = file.getName().substring(0, file.getName().length() - 5);
|
||||
File pdffile = datasetManager.convertToPDF(file, environment, name);
|
||||
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));
|
||||
HttpHeaders responseHeaders = new HttpHeaders();
|
||||
responseHeaders.setContentLength(pdffile.length());
|
||||
|
@ -269,7 +276,7 @@ public class DMPs extends BaseController {
|
|||
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));
|
||||
} 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()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package eu.eudat.controllers;
|
||||
|
||||
import eu.eudat.logic.managers.DashBoardManager;
|
||||
import eu.eudat.logic.security.claims.ClaimedAuthorities;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.models.data.dashboard.recent.RecentActivity;
|
||||
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.security.Principal;
|
||||
import eu.eudat.types.ApiMessageCode;
|
||||
import eu.eudat.types.Authorities;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
@ -46,7 +48,8 @@ public class DashBoardController extends BaseController {
|
|||
}
|
||||
|
||||
@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);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<SearchBarItem>>().status(ApiMessageCode.NO_MESSAGE).payload(searchBarItemList));
|
||||
}
|
||||
|
|
|
@ -43,10 +43,10 @@ public class DataRepositories extends BaseController {
|
|||
@Transactional
|
||||
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
|
||||
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);
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,8 @@ import eu.eudat.models.data.security.Principal;
|
|||
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
|
||||
import eu.eudat.types.ApiMessageCode;
|
||||
import org.apache.poi.util.IOUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
|
@ -44,6 +46,7 @@ import static eu.eudat.types.Authorities.ANONYMOUS;
|
|||
@CrossOrigin
|
||||
@RequestMapping(value = {"api/datasetwizard"})
|
||||
public class DatasetWizardController extends BaseController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DatasetWizardController.class);
|
||||
|
||||
private Environment environment;
|
||||
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."));
|
||||
}
|
||||
} 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."));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,11 @@ public class EmailConfirmation {
|
|||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE));
|
||||
} catch
|
||||
(HasConfirmedEmailException | TokenExpiredException ex) {
|
||||
if (ex instanceof TokenExpiredException) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE));
|
||||
} else {
|
||||
return ResponseEntity.status(HttpStatus.FOUND).body(new ResponseItem().status(ApiMessageCode.WARN_MESSAGE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,6 +52,9 @@ public class EmailConfirmation {
|
|||
this.emailConfirmationManager.sendConfirmationEmail(email, principal);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE));
|
||||
} catch (Exception ex) {
|
||||
if (ex instanceof HasConfirmedEmailException) {
|
||||
return ResponseEntity.status(HttpStatus.FOUND).body(new ResponseItem().status(ApiMessageCode.WARN_MESSAGE));
|
||||
}
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,8 +62,9 @@ public class ExternalDatasets extends BaseController {
|
|||
@Transactional
|
||||
@RequestMapping(method = RequestMethod.POST, value = {"/externaldatasets"}, consumes = "application/json", produces = "application/json")
|
||||
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);
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"));
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package eu.eudat.controllers;
|
||||
|
||||
import eu.eudat.core.logger.Logger;
|
||||
|
||||
import eu.eudat.exceptions.security.NullEmailException;
|
||||
import eu.eudat.logic.managers.UserManager;
|
||||
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.security.Principal;
|
||||
import eu.eudat.types.ApiMessageCode;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
@ -42,6 +44,7 @@ import java.security.GeneralSecurityException;
|
|||
@CrossOrigin
|
||||
@RequestMapping(value = "api/auth")
|
||||
public class Login {
|
||||
private static final Logger logger = LoggerFactory.getLogger(Login.class);
|
||||
|
||||
private CustomAuthenticationProvider customAuthenticationProvider;
|
||||
private AuthenticationService nonVerifiedUserAuthenticationService;
|
||||
|
@ -53,13 +56,13 @@ public class Login {
|
|||
private ConfigurableProviderTokenValidator configurableProviderTokenValidator;
|
||||
private ConfigLoader configLoader;
|
||||
|
||||
private Logger logger;
|
||||
// private Logger logger;
|
||||
|
||||
private UserManager userManager;
|
||||
@Autowired
|
||||
public Login(CustomAuthenticationProvider customAuthenticationProvider, AuthenticationService nonVerifiedUserAuthenticationService,
|
||||
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.nonVerifiedUserAuthenticationService = nonVerifiedUserAuthenticationService;
|
||||
this.twitterTokenValidator = twitterTokenValidator;
|
||||
|
@ -69,7 +72,7 @@ public class Login {
|
|||
this.openAIRETokenValidator = openAIRETokenValidator;
|
||||
this.configurableProviderTokenValidator = configurableProviderTokenValidator;
|
||||
this.configLoader = configLoader;
|
||||
this.logger = logger;
|
||||
// this.logger = logger;
|
||||
this.userManager = userManager;
|
||||
}
|
||||
|
||||
|
@ -77,7 +80,7 @@ public class Login {
|
|||
@RequestMapping(method = RequestMethod.POST, value = {"/externallogin"}, consumes = "application/json", produces = "application/json")
|
||||
public @ResponseBody
|
||||
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));
|
||||
}
|
||||
|
||||
|
@ -85,7 +88,7 @@ public class Login {
|
|||
@RequestMapping(method = RequestMethod.POST, value = {"/nativelogin"}, consumes = "application/json", produces = "application/json")
|
||||
public @ResponseBody
|
||||
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));
|
||||
}
|
||||
|
||||
|
@ -128,7 +131,7 @@ public class Login {
|
|||
@RequestMapping(method = RequestMethod.POST, value = {"/me"}, consumes = "application/json", produces = "application/json")
|
||||
public @ResponseBody
|
||||
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));
|
||||
}
|
||||
|
||||
|
@ -137,7 +140,7 @@ public class Login {
|
|||
public @ResponseBody
|
||||
ResponseEntity<ResponseItem<Principal>> logout(Principal principal) {
|
||||
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));
|
||||
}
|
||||
|
||||
|
|
|
@ -2,12 +2,10 @@ package eu.eudat.controllers;
|
|||
|
||||
import eu.eudat.data.query.items.table.organisations.OrganisationsTableRequest;
|
||||
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.NoURLFound;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
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.responses.ResponseItem;
|
||||
import eu.eudat.models.data.security.Principal;
|
||||
|
@ -19,7 +17,6 @@ import org.springframework.web.bind.annotation.*;
|
|||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@RestController
|
||||
|
@ -28,6 +25,8 @@ import java.util.Map;
|
|||
public class Organisations extends BaseController {
|
||||
|
||||
private OrganisationsManager organisationsManager;
|
||||
private ApiContext apiContext;
|
||||
|
||||
@Autowired
|
||||
public Organisations(ApiContext apiContext, OrganisationsManager organisationsManager) {
|
||||
super(apiContext);
|
||||
|
@ -36,13 +35,11 @@ public class Organisations extends BaseController {
|
|||
|
||||
@RequestMapping(method = RequestMethod.GET, value = {"/external/organisations"}, produces = "application/json")
|
||||
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
|
||||
) throws HugeResultSet, NoURLFound {
|
||||
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query);
|
||||
List<Map<String, String>> remoteRepos = this.getApiContext().getOperationsContext().getRemoteFetcher().getOrganisations(externalUrlCriteria, type);
|
||||
OrganisationsExternalSourcesModel organisationsExternalSourcesModel = new OrganisationsExternalSourcesModel().fromExternalItem(remoteRepos);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<OrganisationsExternalSourcesModel>().payload(organisationsExternalSourcesModel).status(ApiMessageCode.NO_MESSAGE));
|
||||
List<Organisation> organisations = organisationsManager.getCriteriaWithExternal(query, type);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Organisation>>().payload(organisations).status(ApiMessageCode.NO_MESSAGE));
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = {"/internal/organisations"}, produces = "application/json")
|
||||
|
|
|
@ -3,11 +3,13 @@ package eu.eudat.controllers;
|
|||
|
||||
import eu.eudat.data.entities.Funder;
|
||||
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.models.data.datasetwizard.DatasetWizardModel;
|
||||
import eu.eudat.models.data.dmp.DataManagementPlan;
|
||||
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.QuickWizardModel;
|
||||
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.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import eu.eudat.models.data.quickwizard.DatasetCreateWizardModel;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
import javax.validation.Valid;
|
||||
|
@ -47,7 +48,6 @@ public class QuickWizardController extends BaseController {
|
|||
if (quickWizard.getFunder() == null) {
|
||||
throw new Exception("Funder is a mandatory entity");
|
||||
} else if (quickWizard.getFunder().getExistFunder() == null && quickWizard.getFunder().getLabel() == null) {
|
||||
// funderEntity = null;
|
||||
throw new Exception("Funder is a mandatory entity");
|
||||
} else if (quickWizard.getFunder().getExistFunder() == null && quickWizard.getFunder().getLabel() != null) {
|
||||
funderEntity = this.quickWizardManager.createOrUpdate(quickWizard.getFunder().toDataFunder(), principal);
|
||||
|
@ -57,7 +57,11 @@ public class QuickWizardController extends BaseController {
|
|||
|
||||
eu.eudat.data.entities.Grant grantEntity;
|
||||
//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);
|
||||
} else {
|
||||
grantEntity = quickWizard.getGrant().getExistGrant().toDataModel();
|
||||
|
@ -68,17 +72,15 @@ public class QuickWizardController extends BaseController {
|
|||
if (quickWizard.getProject().getExistProject() == null
|
||||
&& quickWizard.getProject().getLabel() == 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);
|
||||
} else {
|
||||
projectEntity = quickWizard.getProject().getExistProject().toDataModel();
|
||||
}
|
||||
|
||||
//Create Dmp
|
||||
eu.eudat.data.entities.DMP dmpEntity = this.quickWizardManager.createOrUpdate(
|
||||
quickWizard.getDmp().toDataDmp(grantEntity, projectEntity, principal),
|
||||
funderEntity,
|
||||
principal);
|
||||
DataManagementPlan dataManagementPlan = quickWizard.getDmp().toDataDmp(grantEntity, projectEntity, principal);
|
||||
eu.eudat.data.entities.DMP dmpEntity = this.quickWizardManager.createOrUpdate(dataManagementPlan, funderEntity, principal);
|
||||
|
||||
//Create Datasets
|
||||
quickWizard.getDmp().setId(dmpEntity.getId());
|
||||
|
|
|
@ -42,10 +42,10 @@ public class Registries extends BaseController {
|
|||
@Transactional
|
||||
@RequestMapping(method = RequestMethod.POST, value = {"/registries"}, consumes = "application/json", produces = "application/json")
|
||||
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);
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -43,9 +43,10 @@ public class Services extends BaseController {
|
|||
@Transactional
|
||||
@RequestMapping(method = RequestMethod.POST, value = {"/services"}, consumes = "application/json", produces = "application/json")
|
||||
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);
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,11 +4,12 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
|||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.ObjectWriter;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import eu.eudat.core.logger.Logger;
|
||||
import eu.eudat.core.models.exception.ApiExceptionLoggingModel;
|
||||
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
||||
import eu.eudat.models.data.security.Principal;
|
||||
import eu.eudat.types.ApiMessageCode;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
|
@ -27,13 +28,14 @@ import java.util.Map;
|
|||
@ControllerAdvice
|
||||
@Priority(5)
|
||||
public class ControllerErrorHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ControllerErrorHandler.class);
|
||||
|
||||
private Logger logger;
|
||||
// private Logger logger;
|
||||
|
||||
@Autowired
|
||||
/*@Autowired
|
||||
public ControllerErrorHandler(Logger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
}*/
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
|
@ -49,12 +51,11 @@ public class ControllerErrorHandler {
|
|||
exceptionMap.put("exception", json);
|
||||
apiExceptionLoggingModel.setData(ow.writeValueAsString(exceptionMap));
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
apiExceptionLoggingModel.setMessage(ex.getMessage());
|
||||
apiExceptionLoggingModel.setType(LoggingType.ERROR);
|
||||
ex.printStackTrace();
|
||||
this.logger.error(apiExceptionLoggingModel);
|
||||
logger.error(ex.getMessage(), ex);
|
||||
return new ResponseItem<Exception>().message(ex.getMessage()).status(ApiMessageCode.DEFAULT_ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package eu.eudat.controllers.controllerhandler;
|
||||
|
||||
import eu.eudat.core.logger.Logger;
|
||||
import eu.eudat.exceptions.security.UnauthorisedException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
@ -18,19 +19,19 @@ import javax.annotation.Priority;
|
|||
@ControllerAdvice
|
||||
@Priority(4)
|
||||
public class ControllerUnauthorisedHandler {
|
||||
|
||||
private Logger logger;
|
||||
private static final Logger logger = LoggerFactory.getLogger(ControllerUnauthorisedHandler.class);
|
||||
// private Logger logger;
|
||||
|
||||
@Autowired
|
||||
public ControllerUnauthorisedHandler(Logger logger) {
|
||||
this.logger = logger;
|
||||
public ControllerUnauthorisedHandler(/*Logger logger*/) {
|
||||
// this.logger = logger;
|
||||
}
|
||||
|
||||
@ExceptionHandler(UnauthorisedException.class)
|
||||
@ResponseStatus(HttpStatus.UNAUTHORIZED)
|
||||
@ResponseBody
|
||||
public void processValidationError(UnauthorisedException ex) {
|
||||
this.logger.error(ex, ex.getMessage());
|
||||
logger.error(ex.getMessage(), ex);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package eu.eudat.controllers.interceptors;
|
|||
|
||||
import eu.eudat.logic.services.helpers.LoggerService;
|
||||
import eu.eudat.types.WarningLevel;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
||||
|
@ -15,19 +17,19 @@ import java.util.Date;
|
|||
*/
|
||||
@Component
|
||||
public class RequestInterceptor extends HandlerInterceptorAdapter {
|
||||
|
||||
private LoggerService loggerService;
|
||||
private static final Logger logger = LoggerFactory.getLogger(RequestInterceptor.class);
|
||||
// private LoggerService loggerService;
|
||||
|
||||
@Autowired
|
||||
public RequestInterceptor(LoggerService loggerService) {
|
||||
this.loggerService = loggerService;
|
||||
public RequestInterceptor(/*LoggerService loggerService*/) {
|
||||
// this.loggerService = loggerService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request,
|
||||
HttpServletResponse response, Object handler) throws Exception {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,9 +7,7 @@ import eu.eudat.logic.builders.model.criteria.RegistryCriteriaBuilder;
|
|||
import eu.eudat.logic.builders.model.models.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 2/15/2018.
|
||||
*/
|
||||
|
||||
@Service("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(ExternalDatasetCriteriaBuilder.class)) return (T) new ExternalDatasetCriteriaBuilder();
|
||||
if (tClass.equals(RecentActivityDataBuilder.class)) return (T) new RecentActivityDataBuilder();
|
||||
if (tClass.equals(OrganisationBuilder.class)) return (T) new OrganisationBuilder();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ public class FunderBuilder extends Builder<Funder> {
|
|||
private Date modified;
|
||||
private Integer type;
|
||||
private String source;
|
||||
private String key;
|
||||
|
||||
public FunderBuilder id(UUID id) {
|
||||
this.id = id;
|
||||
|
@ -63,6 +64,11 @@ public class FunderBuilder extends Builder<Funder> {
|
|||
return this;
|
||||
}
|
||||
|
||||
public FunderBuilder key(String key) {
|
||||
this.key = key;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Funder build() {
|
||||
Funder funder = new Funder();
|
||||
|
@ -75,6 +81,7 @@ public class FunderBuilder extends Builder<Funder> {
|
|||
funder.setModified(modified);
|
||||
funder.setType(type);
|
||||
funder.setSource(source);
|
||||
funder.setKey(key);
|
||||
return funder;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,9 +9,6 @@ import java.util.Date;
|
|||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 2/15/2018.
|
||||
*/
|
||||
public class GrantBuilder extends Builder<Grant> {
|
||||
|
||||
private UUID id;
|
||||
|
@ -44,6 +41,8 @@ public class GrantBuilder extends Builder<Grant> {
|
|||
|
||||
private String source;
|
||||
|
||||
private String key;
|
||||
|
||||
public GrantBuilder id(UUID id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
|
@ -119,6 +118,11 @@ public class GrantBuilder extends Builder<Grant> {
|
|||
return this;
|
||||
}
|
||||
|
||||
public GrantBuilder key(String key) {
|
||||
this.key = key;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Grant build() {
|
||||
Grant grant = new Grant();
|
||||
|
@ -137,6 +141,7 @@ public class GrantBuilder extends Builder<Grant> {
|
|||
grant.setCreationUser(creationUser);
|
||||
grant.setStartDate(startDate);
|
||||
grant.setSource(source);
|
||||
grant.setKey(key);
|
||||
return grant;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -28,6 +28,7 @@ public class ProjectBuilder extends Builder<Project> {
|
|||
private Date modified;
|
||||
private String description;
|
||||
private String source;
|
||||
private String key;
|
||||
|
||||
public ProjectBuilder id(UUID id) {
|
||||
this.id = id;
|
||||
|
@ -109,6 +110,11 @@ public class ProjectBuilder extends Builder<Project> {
|
|||
return this;
|
||||
}
|
||||
|
||||
public ProjectBuilder key(String key) {
|
||||
this.key = key;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Project build() {
|
||||
Project project = new Project();
|
||||
|
@ -127,6 +133,7 @@ public class ProjectBuilder extends Builder<Project> {
|
|||
project.setCreationUser(creationUser);
|
||||
project.setStartDate(startDate);
|
||||
project.setSource(source);
|
||||
project.setKey(key);
|
||||
return project;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,15 +3,14 @@ package eu.eudat.logic.builders.model.models;
|
|||
import eu.eudat.logic.builders.Builder;
|
||||
import eu.eudat.models.data.dmp.Researcher;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 3/6/2018.
|
||||
*/
|
||||
public class ResearcherBuilder extends Builder<Researcher> {
|
||||
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;
|
||||
|
@ -40,6 +39,13 @@ public class ResearcherBuilder extends Builder<Researcher> {
|
|||
return this;
|
||||
}
|
||||
|
||||
public String getReference() { return reference; }
|
||||
|
||||
public ResearcherBuilder reference(String reference) {
|
||||
this.reference = reference;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
@ -58,14 +64,25 @@ public class ResearcherBuilder extends Builder<Researcher> {
|
|||
return this;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public ResearcherBuilder key(String key) {
|
||||
this.key = key;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Researcher build() {
|
||||
Researcher researcher = new Researcher();
|
||||
researcher.setId(id);
|
||||
researcher.setReference(reference);
|
||||
researcher.setLabel(label);
|
||||
researcher.setName(name);
|
||||
researcher.setStatus(status);
|
||||
researcher.setTag(tag);
|
||||
researcher.setKey(key);
|
||||
return researcher;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ public class DashBoardManager {
|
|||
List<Integer> roles = new LinkedList<>();
|
||||
CompletableFuture dmpFuture = dataManagementPlanRepository.getAuthenticated(dataManagementPlanRepository.getWithCriteria(dataManagementPlanCriteria), principal.getId(), roles).countAsync()
|
||||
.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));
|
||||
CompletableFuture grantFuture = grantRepository.getAuthenticated(grantRepository.getWithCriteria(grantCriteria), user).countAsync()
|
||||
.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())
|
||||
.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")
|
||||
.orderBy((builder, root) -> builder.desc(root.get("modified")))
|
||||
.take(numberofactivities)
|
||||
|
@ -132,7 +132,6 @@ public class DashBoardManager {
|
|||
}
|
||||
|
||||
public List<SearchBarItem> searchUserData(String like, Principal principal) {
|
||||
RecentActivity activity = new RecentActivity();
|
||||
UserInfo user = new UserInfo();
|
||||
user.setId(principal.getId());
|
||||
DMPDao dataManagementPlanRepository = databaseRepository.getDmpDao();
|
||||
|
@ -141,29 +140,53 @@ public class DashBoardManager {
|
|||
|
||||
List<Integer> roles = new LinkedList<>();
|
||||
List<SearchBarItem> searchBarItems = new LinkedList<>();
|
||||
|
||||
CompletableFuture<List<SearchBarItem>> publicDmps = dataManagementPlanRepository.asQueryable()
|
||||
.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")))
|
||||
.selectAsync(item -> new SearchBarItem(item.getId().toString(), item.getLabel(), SearchBarItemType.DMP.getValue(), true))
|
||||
.whenComplete((dmpItems, throwable) -> searchBarItems.addAll(dmpItems));
|
||||
|
||||
CompletableFuture<List<SearchBarItem>> publicDatasets = datasetRepository.asQueryable()
|
||||
.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")))
|
||||
.selectAsync(item -> new SearchBarItem(item.getId().toString(), item.getLabel(), SearchBarItemType.DATASET.getValue(), true))
|
||||
.whenComplete((dataSetItems, throwable) -> searchBarItems.addAll(dataSetItems));
|
||||
|
||||
if (principal.getId() != null) {
|
||||
CompletableFuture<List<SearchBarItem>> dmps = dataManagementPlanRepository.getAuthenticated(dataManagementPlanRepository.asQueryable(), principal.getId(), roles)
|
||||
.withHint("dmpRecentActivity")
|
||||
.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + like.toUpperCase() + "%"))
|
||||
.where((builder, root) -> builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue()))
|
||||
.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(), false))
|
||||
.whenComplete((dmpItems, throwable) -> searchBarItems.addAll(dmpItems));
|
||||
|
||||
CompletableFuture<List<SearchBarItem>> datasets = datasetRepository.getAuthenticated(datasetRepository.asQueryable(), user)
|
||||
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()))
|
||||
.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()))
|
||||
.selectAsync(item -> new SearchBarItem(item.getId().toString(), item.getLabel(), SearchBarItemType.GRANT.getValue(), false))
|
||||
.whenComplete((grantItems, throwable) -> searchBarItems.addAll(grantItems));
|
||||
|
||||
CompletableFuture.allOf(grants, dmps, datasets).join();
|
||||
return searchBarItems;
|
||||
CompletableFuture.allOf(grants, dmps, datasets, publicDmps, publicDatasets).join();
|
||||
} else {
|
||||
CompletableFuture.allOf(publicDmps, publicDatasets).join();
|
||||
}
|
||||
|
||||
return searchBarItems;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package eu.eudat.logic.managers;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import eu.eudat.configurations.dynamicgrant.DynamicGrantConfiguration;
|
||||
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.XWPFRun;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
|
@ -68,15 +71,14 @@ import javax.xml.bind.JAXBException;
|
|||
import javax.xml.bind.Unmarshaller;
|
||||
import java.io.*;
|
||||
import java.math.BigInteger;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
public class DataManagementPlanManager {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DataManagementPlanManager.class);
|
||||
|
||||
private ApiContext apiContext;
|
||||
private DatasetManager datasetManager;
|
||||
|
@ -105,7 +107,6 @@ public class DataManagementPlanManager {
|
|||
|
||||
CompletableFuture itemsFuture;
|
||||
if (fieldsGroup.equals("listing")) {
|
||||
|
||||
itemsFuture = pagedItems.withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class))
|
||||
.selectAsync(item -> {
|
||||
item.setDataset(
|
||||
|
@ -119,15 +120,17 @@ public class DataManagementPlanManager {
|
|||
return new DataManagementPlanListingModel().fromDataModelDatasets(item);
|
||||
})
|
||||
.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 {
|
||||
itemsFuture = pagedItems
|
||||
.selectAsync(item -> new DataManagementPlanListingModel().fromDataModelAssociatedProfiles(item))
|
||||
.whenComplete((resultList, throwable) -> dataTable.setData(resultList));
|
||||
}
|
||||
|
||||
CompletableFuture countFuture = authItems.countAsync().whenComplete((count, throwable) ->
|
||||
dataTable.setTotalCount(count)
|
||||
);
|
||||
CompletableFuture countFuture = authItems.countAsync().whenComplete((count, throwable) -> dataTable.setTotalCount(count));
|
||||
CompletableFuture.allOf(itemsFuture, countFuture).join();
|
||||
return dataTable;
|
||||
}
|
||||
|
@ -311,7 +314,7 @@ public class DataManagementPlanManager {
|
|||
try {
|
||||
wordBuilder.build(document, pagedDatasetProfile, visibilityRuleService);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
// Page break at the end of the Dataset.
|
||||
XWPFParagraph parBreakDataset = document.createParagraph();
|
||||
|
@ -341,34 +344,31 @@ public class DataManagementPlanManager {
|
|||
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));
|
||||
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())) {
|
||||
if (!dataManagementPlanEntity.isPublic()) {
|
||||
throw new UnauthorisedException();
|
||||
eu.eudat.models.data.dmp.DataManagementPlan datamanagementPlan = new eu.eudat.models.data.dmp.DataManagementPlan();
|
||||
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;
|
||||
// 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)
|
||||
datamanagementPlan.getDynamicFields().forEach(item -> {
|
||||
if (dmpProperties != null && dataManagementPlan.getDynamicFields() != null)
|
||||
dataManagementPlan.getDynamicFields().forEach(item -> {
|
||||
Map<String, String> properties = (Map<String, String>) dmpProperties.get(item.getId());
|
||||
if (properties != null)
|
||||
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));
|
||||
if (dataManagementPlanEntity.getStatus() == DMP.DMPStatus.DELETED.getValue()) {
|
||||
throw new Exception("DMP is deleted.");
|
||||
}
|
||||
if (dataManagementPlanEntity.getUsers()
|
||||
.stream().filter(userInfo -> userInfo.getUser().getId() == principal.getId())
|
||||
.collect(Collectors.toList()).size() == 0)
|
||||
|
@ -478,10 +478,13 @@ public class DataManagementPlanManager {
|
|||
if (dataManagementPlan.getId() != null) {
|
||||
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());
|
||||
for (Dataset dataset : datasetList) {
|
||||
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()))
|
||||
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.setDmp(dmp);
|
||||
userDMP.setUser(userInfo);
|
||||
|
@ -576,7 +579,9 @@ public class DataManagementPlanManager {
|
|||
|
||||
public void newVersion(UUID uuid, DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
|
||||
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();
|
||||
LinkedList<UUID> list = new LinkedList<>();
|
||||
list.push(oldDmp.getGroupId());
|
||||
|
@ -587,7 +592,6 @@ public class DataManagementPlanManager {
|
|||
|
||||
if (latestVersionDMP.get(0).getVersion().equals(oldDmp.getVersion())) {
|
||||
DMP newDmp = dataManagementPlan.toDataModel();
|
||||
|
||||
UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
|
||||
createOrganisationsIfTheyDontExist(newDmp, databaseRepository.getOrganisationDao());
|
||||
createResearchersIfTheyDontExist(newDmp, databaseRepository.getResearcherDao(), user);
|
||||
|
@ -644,7 +648,6 @@ public class DataManagementPlanManager {
|
|||
databaseRepository.getGrantDao().createOrUpdate(newDmp.getGrant());
|
||||
newDmp = databaseRepository.getDmpDao().createOrUpdate(newDmp);
|
||||
|
||||
// Assign creator.
|
||||
assignUser(newDmp, user);
|
||||
copyDatasets(newDmp, databaseRepository.getDatasetDao());
|
||||
}
|
||||
|
@ -696,6 +699,7 @@ public class DataManagementPlanManager {
|
|||
if (grantEntity != null) grant.setId(grantEntity.getId());
|
||||
else {
|
||||
grant.setType(Grant.GrantType.EXTERNAL.getValue());
|
||||
grant.setCreationUser(null);
|
||||
grantDao.createOrUpdate(grant);
|
||||
}
|
||||
}
|
||||
|
@ -723,6 +727,7 @@ public class DataManagementPlanManager {
|
|||
if (projectEntity != null) project.setId(projectEntity.getId());
|
||||
else {
|
||||
project.setType(Project.ProjectType.EXTERNAL.getValue());
|
||||
if (project.getId() == null) project.setId(UUID.randomUUID());
|
||||
projectDao.createOrUpdate(project);
|
||||
}
|
||||
}
|
||||
|
@ -785,11 +790,12 @@ public class DataManagementPlanManager {
|
|||
if (newDataset.getDatasetDataRepositories() != null) {
|
||||
newDataset.setDatasetDataRepositories(newDataset.getDatasetDataRepositories().stream().map(item -> {
|
||||
DataRepository dataRepository = new DataRepository();
|
||||
dataRepository.setId(item.getId());
|
||||
dataRepository.setId(item.getDataRepository().getId());
|
||||
|
||||
DatasetDataRepository datasetDataRepository = new DatasetDataRepository();
|
||||
datasetDataRepository.setDataRepository(dataRepository);
|
||||
datasetDataRepository.setDataset(newDataset);
|
||||
datasetDataRepository.setData(item.getData());
|
||||
return datasetDataRepository;
|
||||
}).collect(Collectors.toSet()));
|
||||
}
|
||||
|
@ -797,10 +803,11 @@ public class DataManagementPlanManager {
|
|||
if (newDataset.getDatasetExternalDatasets() != null) {
|
||||
newDataset.setDatasetExternalDatasets(newDataset.getDatasetExternalDatasets().stream().map(item -> {
|
||||
ExternalDataset externalDataset = new ExternalDataset();
|
||||
externalDataset.setId(item.getId());
|
||||
externalDataset.setId(item.getExternalDataset().getId());
|
||||
DatasetExternalDataset datasetExternalDataset = new DatasetExternalDataset();
|
||||
datasetExternalDataset.setExternalDataset(externalDataset);
|
||||
datasetExternalDataset.setDataset(newDataset);
|
||||
datasetExternalDataset.setData(item.getData());
|
||||
return datasetExternalDataset;
|
||||
}).collect(Collectors.toSet()));
|
||||
}
|
||||
|
@ -820,6 +827,7 @@ public class DataManagementPlanManager {
|
|||
DatasetService datasetService = new DatasetService();
|
||||
datasetService.setService(service);
|
||||
datasetService.setDataset(newDataset);
|
||||
datasetService.setData(item.getData());
|
||||
return datasetService;
|
||||
}).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();
|
||||
VisibilityRuleService visibilityRuleService = utilitiesService.getVisibilityRuleService();
|
||||
eu.eudat.data.entities.DMP dmp = databaseRepository.getDmpDao().find(UUID.fromString(id));
|
||||
|
@ -868,14 +876,34 @@ public class DataManagementPlanManager {
|
|||
}
|
||||
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 label = xmlDoc.createElement("label");
|
||||
label.setTextContent(dmp.getGrant().getLabel());
|
||||
grant.appendChild(label);
|
||||
Element grantLabel = xmlDoc.createElement("label");
|
||||
Element grantId = xmlDoc.createElement("id");
|
||||
grantLabel.setTextContent(dmp.getGrant().getLabel());
|
||||
grantId.setTextContent(dmp.getGrant().getId().toString());
|
||||
grant.appendChild(grantLabel);
|
||||
grant.appendChild(grantId);
|
||||
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");
|
||||
for (Organisation organisation : dmp.getOrganisations()) {
|
||||
Element organisationElement = xmlDoc.createElement("organisation");
|
||||
|
@ -944,20 +972,21 @@ public class DataManagementPlanManager {
|
|||
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));
|
||||
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();
|
||||
RDAExportModel rdaExportModel = new RDAExportModel().fromDataModel(dmp);
|
||||
RDAExportModel rdaExportModel = new RDAExportModel().fromDataModel(dmp, datasetManager);
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
String fileName = dmp.getLabel();
|
||||
fileName = fileName.replaceAll("[^a-zA-Z0-9+ ]", "");
|
||||
File file = new File(fileName);
|
||||
try {
|
||||
mapper.writeValue(file, rdaExportModel);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
InputStream resource = new FileInputStream(file);
|
||||
|
@ -1015,7 +1044,7 @@ public class DataManagementPlanManager {
|
|||
DmpImportModel dmpImportModel = (DmpImportModel) jaxbUnmarshaller.unmarshal(in);
|
||||
dataManagementPlans.add(dmpImportModel);
|
||||
} catch (IOException | JAXBException ex) {
|
||||
ex.printStackTrace();
|
||||
logger.error(ex.getMessage(), ex);
|
||||
}
|
||||
// TODO Iterate through the list of dataManagementPlans.
|
||||
// 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);
|
||||
|
||||
System.out.println(dm);
|
||||
logger.info(dm.toString());
|
||||
}
|
||||
|
||||
return dataManagementPlans;
|
||||
|
|
|
@ -21,6 +21,8 @@ import eu.eudat.models.data.listingmodels.DataManagementPlanProfileListingModel;
|
|||
import eu.eudat.models.data.security.Principal;
|
||||
import eu.eudat.queryable.QueryableList;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -43,6 +45,7 @@ import org.w3c.dom.Element;
|
|||
*/
|
||||
@Component
|
||||
public class DataManagementProfileManager {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DataManagementProfileManager.class);
|
||||
|
||||
private ApiContext apiContext;
|
||||
private DatabaseRepository databaseRepository;
|
||||
|
@ -93,7 +96,7 @@ public class DataManagementProfileManager {
|
|||
public ResponseEntity<byte[]> getDocument(DataManagementPlanProfileListingModel dmpProfile, String label) throws IllegalAccessException, IOException, InstantiationException {
|
||||
FileEnvelope envelope = getXmlDocument(dmpProfile, label);
|
||||
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()));
|
||||
HttpHeaders responseHeaders = new HttpHeaders();
|
||||
responseHeaders.setContentLength(envelope.getFile().length());
|
||||
|
@ -124,7 +127,7 @@ public class DataManagementProfileManager {
|
|||
try {
|
||||
return xmlBuilder.build(convert(multiPartFile));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -36,6 +36,8 @@ import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
|||
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFRun;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
|
@ -73,6 +75,7 @@ import java.util.zip.ZipInputStream;
|
|||
|
||||
@Component
|
||||
public class DatasetManager {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DatasetManager.class);
|
||||
|
||||
private ApiContext apiContext;
|
||||
private DatabaseRepository databaseRepository;
|
||||
|
@ -109,7 +112,9 @@ public class DatasetManager {
|
|||
} else
|
||||
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);
|
||||
DataTableData<DatasetListingModel> dataTable = new DataTableData<DatasetListingModel>();
|
||||
|
||||
|
@ -172,7 +177,7 @@ public class DatasetManager {
|
|||
return dataTable;
|
||||
}
|
||||
|
||||
public DatasetWizardModel getSingle(String id) throws InstantiationException, IllegalAccessException, IOException {
|
||||
public DatasetWizardModel getSingle(String id) {
|
||||
DatasetWizardModel dataset = new DatasetWizardModel();
|
||||
eu.eudat.data.entities.Dataset datasetEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class));
|
||||
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 {
|
||||
FileEnvelope envelope = getXmlDocument(id, visibilityRuleService);
|
||||
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()));
|
||||
HttpHeaders responseHeaders = new HttpHeaders();
|
||||
responseHeaders.setContentLength(envelope.getFile().length());
|
||||
|
@ -572,7 +577,7 @@ public class DatasetManager {
|
|||
DatasetImportPagedDatasetProfile datasetImport = (DatasetImportPagedDatasetProfile) jaxbUnmarshaller.unmarshal(in);
|
||||
importModel = datasetImport;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
// Checks if XML datasetProfileId GroupId matches the one selected.
|
||||
|
@ -583,7 +588,7 @@ public class DatasetManager {
|
|||
throw new Exception();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@ import eu.eudat.models.data.externaldataset.ExternalAutocompleteFieldModel;
|
|||
import eu.eudat.models.data.helpers.common.DataTableData;
|
||||
import eu.eudat.queryable.QueryableList;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -41,6 +43,7 @@ import java.io.*;
|
|||
|
||||
@Component
|
||||
public class DatasetProfileManager {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DatasetProfileManager.class);
|
||||
|
||||
private ApiContext apiContext;
|
||||
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 {
|
||||
FileEnvelope envelope = getXmlDocument(datasetProfile, label);
|
||||
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()));
|
||||
HttpHeaders responseHeaders = new HttpHeaders();
|
||||
responseHeaders.setContentLength(envelope.getFile().length());
|
||||
|
@ -151,7 +154,7 @@ public class DatasetProfileManager {
|
|||
try {
|
||||
return xmlBuilder.build(convert(multiPartFile));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@ import eu.eudat.models.data.user.composite.PagedDatasetProfile;
|
|||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.http.*;
|
||||
|
@ -36,6 +38,7 @@ import java.util.zip.ZipInputStream;
|
|||
*/
|
||||
@Service
|
||||
public class DocumentManager {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DocumentManager.class);
|
||||
|
||||
private ApiContext context;
|
||||
private DatasetManager datasetManager;
|
||||
|
@ -104,12 +107,12 @@ public class DocumentManager {
|
|||
|
||||
Map mediaResult = new RestTemplate().getForObject(environment.getProperty("pdf.converter.url") +
|
||||
"/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")) {
|
||||
Thread.sleep(500);
|
||||
mediaResult = new RestTemplate().getForObject(environment.getProperty("pdf.converter.url") +
|
||||
"api/v1/" + queueResult.get("id"), Map.class);
|
||||
System.out.println("Polling");
|
||||
logger.info("Polling");
|
||||
}
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
restTemplate.getMessageConverters().add(new ByteArrayHttpMessageConverter());
|
||||
|
|
|
@ -34,20 +34,21 @@ public class EmailConfirmationManager {
|
|||
.getDatabaseRepository().getLoginConfirmationEmailDao().asQueryable()
|
||||
.where((builder, root) -> builder.equal(root.get("token"), UUID.fromString(token))).getSingle();
|
||||
|
||||
if (loginConfirmationEmail.getExpiresAt().compareTo(new Date()) < 0)
|
||||
throw new TokenExpiredException("Token has expired.");
|
||||
|
||||
UserInfo user = databaseRepository.getUserInfoDao().asQueryable()
|
||||
.where((builder, root) -> builder.equal(root.get("id"), loginConfirmationEmail.getUserId())).getSingle();
|
||||
|
||||
if (user.getEmail() != null)
|
||||
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);
|
||||
|
||||
// Checks if mail is used by another user. If it is, merges the new the old.
|
||||
Long existingUsers = databaseRepository.getUserInfoDao().asQueryable().where((builder, root) -> builder.equal(root.get("email"), loginConfirmationEmail.getEmail())).count();
|
||||
if (existingUsers > 0) {
|
||||
UserInfo oldUser = databaseRepository.getUserInfoDao().asQueryable().where((builder, root) -> builder.equal(root.get("email"), loginConfirmationEmail.getEmail())).getSingle();
|
||||
if (oldUser != null) {
|
||||
mergeNewUserToOld(user, oldUser);
|
||||
expireUserToken(user);
|
||||
databaseRepository.getLoginConfirmationEmailDao().createOrUpdate(loginConfirmationEmail);
|
||||
|
|
|
@ -3,6 +3,7 @@ package eu.eudat.logic.managers;
|
|||
import eu.eudat.data.query.items.item.funder.FunderCriteriaRequest;
|
||||
import eu.eudat.logic.builders.model.models.FunderBuilder;
|
||||
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.NoURLFound;
|
||||
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)
|
||||
.reference(externalListingItem.getRemoteId()).label(externalListingItem.getName())
|
||||
.status(eu.eudat.data.entities.Funder.Status.fromInteger(0))
|
||||
.key(externalListingItem.getKey())
|
||||
.source(externalListingItem.getTag())
|
||||
.build();
|
||||
if (externalListingItem.getSource() != null) {
|
||||
funder.setSource(externalListingItem.getSource());
|
||||
|
|
|
@ -109,21 +109,24 @@ public class GrantManager {
|
|||
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();
|
||||
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.setReference(grantCriteria.getCriteria().getFunderReference());
|
||||
Funder funder = apiContext.getOperationsContext().getDatabaseRepository().getFunderDao().getWithCritetia(funderCriteria).getSingleOrDefault();
|
||||
if (funder != null) {
|
||||
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:");
|
||||
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);
|
||||
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);
|
||||
|
||||
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)
|
||||
.reference(externalListingItem.getRemoteId()).label(externalListingItem.getName())
|
||||
.description(externalListingItem.getDescription()).uri(externalListingItem.getUri())
|
||||
.key(externalListingItem.getKey())
|
||||
.abbreviation(externalListingItem.getAbbreviation()).status(eu.eudat.data.entities.Grant.Status.fromInteger(0))
|
||||
.source(externalListingItem.getTag())
|
||||
.build();
|
||||
|
|
|
@ -1,24 +1,25 @@
|
|||
package eu.eudat.logic.managers;
|
||||
|
||||
import eu.eudat.data.dao.criteria.OrganisationCriteria;
|
||||
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.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.operations.DatabaseRepository;
|
||||
import eu.eudat.models.HintedModelFactory;
|
||||
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.listingmodels.DataManagementPlanListingModel;
|
||||
import eu.eudat.models.data.security.Principal;
|
||||
import eu.eudat.queryable.QueryableList;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
|
@ -64,4 +65,21 @@ public class OrganisationsManager {
|
|||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ public class ProjectManager {
|
|||
.reference(externalListingItem.getRemoteId()).label(externalListingItem.getName())
|
||||
.description(externalListingItem.getDescription()).uri(externalListingItem.getUri())
|
||||
.abbreviation(externalListingItem.getAbbreviation()).status(eu.eudat.data.entities.Project.Status.fromInteger(0))
|
||||
.key(externalListingItem.getKey())
|
||||
.source(externalListingItem.getTag())
|
||||
.build();
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import org.springframework.stereotype.Component;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.util.UUID;
|
||||
|
||||
@Component
|
||||
public class QuickWizardManager {
|
||||
|
@ -109,6 +110,7 @@ public class QuickWizardManager {
|
|||
eu.eudat.data.entities.Project projectEntity = databaseRepository.getProjectDao().getWithCritetia(criteria).getSingleOrDefault();
|
||||
if (projectEntity != null) project.setId(projectEntity.getId());
|
||||
else {
|
||||
if (project.getId() == null) project.setId(UUID.randomUUID());
|
||||
project.setType(Project.ProjectType.EXTERNAL.getValue());
|
||||
databaseRepository.getProjectDao().createOrUpdate(project);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ package eu.eudat.logic.managers;
|
|||
import eu.eudat.logic.builders.model.models.ResearcherBuilder;
|
||||
import eu.eudat.data.entities.Researcher;
|
||||
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.ResearchersExternalSourcesModel;
|
||||
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.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
@ -28,11 +29,13 @@ public class ResearcherManager {
|
|||
|
||||
private ApiContext apiContext;
|
||||
private RemoteFetcher remoteFetcher;
|
||||
private ConfigLoader configLoader;
|
||||
|
||||
@Autowired
|
||||
public ResearcherManager(ApiContext apiContext) {
|
||||
public ResearcherManager(ApiContext apiContext, ConfigLoader configLoader) {
|
||||
this.apiContext = apiContext;
|
||||
this.remoteFetcher = apiContext.getOperationsContext().getRemoteFetcher();
|
||||
this.configLoader = configLoader;
|
||||
}
|
||||
|
||||
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());
|
||||
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));
|
||||
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());
|
||||
List<Map<String, String>> remoteRepos = remoteFetcher.getResearchers(externalUrlCriteria,null);
|
||||
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)
|
||||
.label(externalListingItem.getAbbreviation())
|
||||
.id(externalListingItem.getId())
|
||||
.reference(externalListingItem.getRemoteId())
|
||||
.name(externalListingItem.getName())
|
||||
.tag(externalListingItem.getTag())
|
||||
.key(externalListingItem.getKey())
|
||||
.build();
|
||||
researchers.add(researcher);
|
||||
}
|
||||
|
|
|
@ -5,10 +5,12 @@ import eu.eudat.logic.security.customproviders.ConfigurableProvider.entities.Con
|
|||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface ConfigLoader {
|
||||
ExternalUrls getExternalUrls();
|
||||
List<String> getRdaProperties();
|
||||
XWPFDocument getDocument();
|
||||
ConfigurableProviders getConfigurableProviders();
|
||||
Map<String, String> getKeyToSourceMap();
|
||||
}
|
||||
|
|
|
@ -5,73 +5,81 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||
import eu.eudat.logic.proxy.config.ExternalUrls;
|
||||
import eu.eudat.logic.security.customproviders.ConfigurableProvider.entities.ConfigurableProviders;
|
||||
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.context.annotation.Profile;
|
||||
import org.springframework.core.env.Environment;
|
||||
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.Unmarshaller;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
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.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service("configLoader")
|
||||
@Profile("devel")
|
||||
public class DevelConfigLoader implements ConfigLoader {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DevelConfigLoader.class);
|
||||
|
||||
private ExternalUrls externalUrls;
|
||||
private List<String> rdaProperties;
|
||||
private XWPFDocument document;
|
||||
private ConfigurableProviders configurableProviders;
|
||||
private Map<String, String> keyToSourceMap;
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
private void setExternalUrls() {
|
||||
String fileUrl = this.environment.getProperty("configuration.externalUrls");
|
||||
System.out.println("Loaded also config file: " + fileUrl);
|
||||
String current = null;
|
||||
logger.info("Loaded also config file: " + fileUrl);
|
||||
InputStream is = null;
|
||||
try {
|
||||
current = new java.io.File(".").getCanonicalPath();
|
||||
|
||||
JAXBContext jaxbContext = JAXBContext.newInstance(ExternalUrls.class);
|
||||
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
|
||||
is = new URL("file:///" + current + fileUrl).openStream();
|
||||
is = getClass().getClassLoader().getResource(fileUrl).openStream();
|
||||
externalUrls = (ExternalUrls) jaxbUnmarshaller.unmarshal(is);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
System.out.println("Cannot find in folder" + current);
|
||||
logger.error("Cannot find resource in classpath", ex);
|
||||
} finally {
|
||||
try {
|
||||
if (is != null) is.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Warning: Could not close a stream after reading from file: " + fileUrl);
|
||||
} catch (IOException | NullPointerException e) {
|
||||
logger.warn("Warning: Could not close a stream after reading from file: " + fileUrl, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setRdaProperties() {
|
||||
String filePath = environment.getProperty("configuration.rda");
|
||||
String current = null;
|
||||
BufferedReader reader;
|
||||
List<String> rdaList = new LinkedList<>();
|
||||
try {
|
||||
current = new java.io.File(".").getCanonicalPath();
|
||||
reader = new BufferedReader(new FileReader(current + filePath));
|
||||
reader = new BufferedReader(new FileReader(getClass().getClassLoader().getResource(filePath).getFile()));
|
||||
String line = reader.readLine();
|
||||
while (line != null) {
|
||||
rdaList.add(line);
|
||||
line = reader.readLine();
|
||||
}
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException | NullPointerException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
rdaProperties = rdaList;
|
||||
|
@ -79,43 +87,63 @@ public class DevelConfigLoader implements ConfigLoader {
|
|||
|
||||
private void setDocument() {
|
||||
String filePath = environment.getProperty("configuration.h2020template");
|
||||
String current = null;
|
||||
InputStream is = null;
|
||||
try {
|
||||
current = new java.io.File(".").getCanonicalPath();
|
||||
is = new URL("file:///" + current + filePath).openStream();
|
||||
is = getClass().getClassLoader().getResource(filePath).openStream();
|
||||
this.document = new XWPFDocument(is);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException | NullPointerException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
} finally {
|
||||
try {
|
||||
if (is != null) is.close();
|
||||
} 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 current = null;
|
||||
InputStream is = null;
|
||||
try {
|
||||
current = new java.io.File(".").getCanonicalPath();
|
||||
is = new URL("file:///" + current + filePath).openStream();
|
||||
is = getClass().getClassLoader().getResource(filePath).openStream();
|
||||
ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
this.configurableProviders = mapper.readValue(is, ConfigurableProviders.class);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException | NullPointerException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
} finally {
|
||||
try {
|
||||
if (is != null) is.close();
|
||||
} 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() {
|
||||
this.setExternalUrls();
|
||||
return externalUrls;
|
||||
|
@ -135,4 +163,52 @@ public class DevelConfigLoader implements ConfigLoader {
|
|||
this.setConfigurableProviders();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,55 +4,68 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||
import eu.eudat.logic.proxy.config.ExternalUrls;
|
||||
import eu.eudat.logic.security.customproviders.ConfigurableProvider.entities.ConfigurableProviders;
|
||||
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.context.annotation.Profile;
|
||||
import org.springframework.core.env.Environment;
|
||||
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.Unmarshaller;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
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.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service("configLoader")
|
||||
@Profile({ "production", "staging" })
|
||||
public class ProductionConfigLoader implements ConfigLoader {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ProductionConfigLoader.class);
|
||||
|
||||
private ExternalUrls externalUrls;
|
||||
private List<String> rdaProperties;
|
||||
private XWPFDocument document;
|
||||
private ConfigurableProviders configurableProviders;
|
||||
private Map<String, String> keyToSourceMap;
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
private void setExternalUrls() {
|
||||
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;
|
||||
try {
|
||||
current = new java.io.File(".").getCanonicalPath();
|
||||
|
||||
JAXBContext jaxbContext = JAXBContext.newInstance(ExternalUrls.class);
|
||||
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
|
||||
is = new URL(Paths.get(fileUrl).toUri().toURL().toString()).openStream();
|
||||
externalUrls = (ExternalUrls) jaxbUnmarshaller.unmarshal(is);
|
||||
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
System.out.println("Cannot find in folder" + current);
|
||||
logger.error("Cannot find in folder" + current, ex);
|
||||
} finally {
|
||||
try {
|
||||
if (is != null) is.close();
|
||||
} 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();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
rdaProperties = rdaList;
|
||||
|
@ -78,27 +91,63 @@ public class ProductionConfigLoader implements ConfigLoader {
|
|||
|
||||
private void setDocument() {
|
||||
String filePath = environment.getProperty("configuration.h2020template");
|
||||
String current = null;
|
||||
InputStream is = null;
|
||||
try {
|
||||
current = new java.io.File(".").getCanonicalPath();
|
||||
InputStream is = new URL(Paths.get(filePath).toUri().toURL().toString()).openStream();
|
||||
is = new URL(Paths.get(filePath).toUri().toURL().toString()).openStream();
|
||||
this.document = new XWPFDocument(is);
|
||||
} 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 current = null;
|
||||
InputStream is = null;
|
||||
try {
|
||||
current = new java.io.File(".").getCanonicalPath();
|
||||
InputStream is = new URL(Paths.get(filePath).toUri().toURL().toString()).openStream();
|
||||
File tempFile = new File(filePath);
|
||||
if (tempFile.exists()) {
|
||||
is = new URL(Paths.get(filePath).toUri().toURL().toString()).openStream();
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
this.configurableProviders = objectMapper.readValue(is, ConfigurableProviders.class);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} else {
|
||||
this.configurableProviders = new ConfigurableProviders();
|
||||
}
|
||||
} catch (IOException 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
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() {
|
||||
|
@ -120,4 +169,52 @@ public class ProductionConfigLoader implements ConfigLoader {
|
|||
this.setConfigurableProviders();
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -8,6 +8,8 @@ import eu.eudat.logic.proxy.config.*;
|
|||
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
|
||||
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
|
||||
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.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -25,6 +27,7 @@ import java.util.stream.Collectors;
|
|||
|
||||
@Service
|
||||
public class RemoteFetcher {
|
||||
private static final Logger logger = LoggerFactory.getLogger(RemoteFetcher.class);
|
||||
|
||||
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 {
|
||||
|
||||
if (urlConfigs == null || urlConfigs.isEmpty())
|
||||
throw new NoURLFound("No Repository urls found in configuration");
|
||||
List<Map<String, String>> results = new LinkedList<>();
|
||||
|
||||
if (urlConfigs == null || urlConfigs.isEmpty()) return results;
|
||||
// throw new NoURLFound("No Repository urls found in configuration");
|
||||
|
||||
urlConfigs.sort(Comparator.comparing(UrlConfiguration::getOrdinal));
|
||||
List<Map<String, String>> results = new LinkedList<>();
|
||||
for (UrlConfiguration urlConfig : urlConfigs) {
|
||||
ifFunderQueryExist(urlConfig, externalUrlCriteria);
|
||||
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")) {
|
||||
results.addAll(getAllResultsFromMockUpJson(urlConfig.getUrl(), externalUrlCriteria.getLike()));
|
||||
}
|
||||
|
@ -138,7 +142,7 @@ public class RemoteFetcher {
|
|||
|
||||
private void ifFunderQueryExist(UrlConfiguration urlConfiguration, ExternalUrlCriteria externalUrlCriteria) {
|
||||
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()));
|
||||
}
|
||||
else {
|
||||
|
@ -162,7 +166,7 @@ public class RemoteFetcher {
|
|||
try {
|
||||
funderId = URLEncoder.encode(externalUrlCriteria.getFunderId(), "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
completedPath = completedPath.replace("{funderId}", funderId);
|
||||
}
|
||||
|
@ -178,19 +182,19 @@ public class RemoteFetcher {
|
|||
if (externalUrlCriteria.getPageSize() != null) {
|
||||
completedPath = completedPath.replace("{pageSize}", externalUrlCriteria.getPageSize());
|
||||
} else {
|
||||
completedPath = completedPath.replace("{pageSize}", "10");
|
||||
completedPath = completedPath.replace("{pageSize}", "60");
|
||||
}
|
||||
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<>();
|
||||
|
||||
String replacedPath = replaceCriteriaOnUrl(path, externalUrlCriteria, firstPage);
|
||||
|
||||
Results results = getResultsFromUrl(replacedPath, jsonDataPath, jsonPaginationPath, contentType);
|
||||
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
|
||||
for (int i = 2; i <= results.getPagination().get("pages"); i++)
|
||||
|
@ -209,7 +213,7 @@ public class RemoteFetcher {
|
|||
Results remainingResults = optionalResults.orElseGet(Results::new);
|
||||
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()
|
||||
+ "[" + jsonDataPath.getFieldsUrlConfiguration().getName() + "," + jsonDataPath.getFieldsUrlConfiguration().getDescription()
|
||||
+ "," + 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)))
|
||||
.collect(Collectors.toList());
|
||||
return results;
|
||||
}
|
||||
} catch (MalformedURLException e1) {
|
||||
e1.printStackTrace();
|
||||
logger.error(e1.getMessage(), e1);
|
||||
} //maybe print smth...
|
||||
catch (IOException e2) {
|
||||
e2.printStackTrace();
|
||||
logger.error(e2.getMessage(), e2);
|
||||
} //maybe print smth...
|
||||
catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
logger.error(exception.getMessage(), exception);
|
||||
} //maybe print smth...
|
||||
finally {
|
||||
}
|
||||
|
@ -270,10 +274,9 @@ public class RemoteFetcher {
|
|||
String filePath = Paths.get(path).toUri().toURL().toString();
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
internalResults = mapper.readValue(new File(filePath), new TypeReference<List<Map<String, Object>>>(){});
|
||||
searchListMap(internalResults, query);
|
||||
return internalResults;
|
||||
return searchListMap(internalResults, query);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
return new LinkedList<>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@ import eu.eudat.exceptions.security.UnauthorisedException;
|
|||
import eu.eudat.models.data.login.LoginInfo;
|
||||
import eu.eudat.models.data.security.Principal;
|
||||
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.stereotype.Component;
|
||||
|
||||
|
@ -14,6 +16,7 @@ import java.security.GeneralSecurityException;
|
|||
|
||||
@Component
|
||||
public class CustomAuthenticationProvider {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CustomAuthenticationProvider.class);
|
||||
|
||||
|
||||
@Autowired
|
||||
|
@ -25,14 +28,13 @@ public class CustomAuthenticationProvider {
|
|||
Principal principal = this.tokenValidatorFactory.getProvider(credentials.getProvider()).validateToken(credentials);
|
||||
return principal;
|
||||
} catch (NonValidTokenException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("Could not validate a user by his token! Reason: " + e.getMessage());
|
||||
logger.error("Could not validate a user by his token! Reason: " + e.getMessage(), e);
|
||||
throw new UnauthorisedException("Token validation failed - Not a valid token");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
throw new UnauthorisedException("IO Exeption");
|
||||
} catch (NullEmailException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
throw new NullEmailException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package eu.eudat.logic.services.helpers;
|
|||
|
||||
import eu.eudat.exceptions.files.TempFileNotFoundException;
|
||||
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.core.env.Environment;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
@ -22,6 +24,7 @@ import java.util.UUID;
|
|||
*/
|
||||
@Service("fileStorageService")
|
||||
public class FileStorageServiceImpl implements FileStorageService {
|
||||
private static final Logger logger = LoggerFactory.getLogger(FileStorageServiceImpl.class);
|
||||
|
||||
private Environment environment;
|
||||
|
||||
|
@ -68,7 +71,7 @@ public class FileStorageServiceImpl implements FileStorageService {
|
|||
Files.createDirectory(Paths.get(environment.getProperty("files.storage.final")));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,5 +9,5 @@ public interface HelpersService {
|
|||
|
||||
MessageSource getMessageSource();
|
||||
|
||||
LoggerService getLoggerService();
|
||||
// LoggerService getLoggerService();
|
||||
}
|
||||
|
|
|
@ -11,12 +11,12 @@ import org.springframework.stereotype.Service;
|
|||
public class HelpersServiceImpl implements HelpersService {
|
||||
|
||||
private MessageSource messageSource;
|
||||
private LoggerService loggerService;
|
||||
// private LoggerService loggerService;
|
||||
|
||||
@Autowired
|
||||
public HelpersServiceImpl(MessageSource messageSource, LoggerService loggerService) {
|
||||
public HelpersServiceImpl(MessageSource messageSource/*, LoggerService loggerService*/) {
|
||||
this.messageSource = messageSource;
|
||||
this.loggerService = loggerService;
|
||||
// this.loggerService = loggerService;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -24,8 +24,8 @@ public class HelpersServiceImpl implements HelpersService {
|
|||
return messageSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
/*@Override
|
||||
public LoggerService getLoggerService() {
|
||||
return loggerService;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import java.util.Map;
|
|||
/**
|
||||
* Created by ikalyvas on 3/1/2018.
|
||||
*/
|
||||
@Service("loggerService")
|
||||
//@Service("loggerService")
|
||||
public class LoggerServiceImpl implements LoggerService {
|
||||
private Logger logger;
|
||||
private WarningLevel level;
|
||||
|
@ -22,7 +22,7 @@ public class LoggerServiceImpl implements LoggerService {
|
|||
this.level = level;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
// @Autowired
|
||||
public LoggerServiceImpl(Logger logger) {
|
||||
this.logger = logger;
|
||||
this.options.put(WarningLevel.DEBUG, (log, message) -> log.debug(message));
|
||||
|
|
|
@ -15,12 +15,15 @@ import eu.eudat.models.data.loginprovider.LoginProviderUser;
|
|||
import eu.eudat.models.data.security.Principal;
|
||||
import eu.eudat.types.Authorities;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public abstract class AbstractAuthenticationService implements AuthenticationService {
|
||||
private static final Logger logger = LoggerFactory.getLogger(AbstractAuthenticationService.class);
|
||||
|
||||
protected ApiContext apiContext;
|
||||
protected Environment environment;
|
||||
|
@ -86,7 +89,7 @@ public abstract class AbstractAuthenticationService implements AuthenticationSer
|
|||
try {
|
||||
credential = this.autoCreateUser(credentials.getUsername(), credentials.getSecret());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
package eu.eudat.logic.services.utilities;
|
||||
|
||||
import eu.eudat.core.logger.Logger;
|
||||
import eu.eudat.data.dao.entities.LoginConfirmationEmailDao;
|
||||
import eu.eudat.data.entities.LoginConfirmationEmail;
|
||||
import eu.eudat.models.data.mail.SimpleMail;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -13,11 +14,12 @@ import java.util.concurrent.CompletableFuture;
|
|||
|
||||
@Service("ConfirmationEmailService")
|
||||
public class ConfirmationEmailServiceImpl implements ConfirmationEmailService {
|
||||
private Logger logger;
|
||||
private static final Logger logger = LoggerFactory.getLogger(ConfirmationEmailServiceImpl.class);
|
||||
//private Logger logger;
|
||||
private Environment environment;
|
||||
|
||||
public ConfirmationEmailServiceImpl(Logger logger, Environment environment) {
|
||||
this.logger = logger;
|
||||
public ConfirmationEmailServiceImpl(/*Logger logger,*/ Environment environment) {
|
||||
// this.logger = logger;
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
|
@ -48,8 +50,7 @@ public class ConfirmationEmailServiceImpl implements ConfirmationEmailService {
|
|||
try {
|
||||
mailService.sendSimpleMail(mail);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
this.logger.error(ex, ex.getMessage());
|
||||
logger.error(ex.getMessage(), ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package eu.eudat.logic.services.utilities;
|
||||
|
||||
import eu.eudat.core.logger.Logger;
|
||||
import eu.eudat.core.models.exception.ApiExceptionLoggingModel;
|
||||
import eu.eudat.data.dao.entities.DMPDao;
|
||||
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.UserInfo;
|
||||
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.core.env.Environment;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
@ -25,13 +26,13 @@ import java.util.stream.Collectors;
|
|||
|
||||
@Service("invitationService")
|
||||
public class InvitationServiceImpl implements InvitationService {
|
||||
|
||||
private Logger logger;
|
||||
private static final Logger logger = LoggerFactory.getLogger(InvitationServiceImpl.class);
|
||||
// private Logger logger;
|
||||
private Environment environment;
|
||||
|
||||
@Autowired
|
||||
public InvitationServiceImpl(Logger logger, Environment environment) {
|
||||
this.logger = logger;
|
||||
public InvitationServiceImpl(/*Logger logger,*/ Environment environment) {
|
||||
// this.logger = logger;
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
|
@ -75,8 +76,7 @@ public class InvitationServiceImpl implements InvitationService {
|
|||
try {
|
||||
mailService.sendSimpleMail(mail);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
this.logger.error(ex, ex.getMessage());
|
||||
logger.error(ex.getMessage(), ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package eu.eudat.logic.services.utilities;
|
|||
|
||||
import eu.eudat.models.data.mail.SimpleMail;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
@ -17,6 +19,7 @@ import java.io.*;
|
|||
|
||||
@Service("mailService")
|
||||
public class MailServiceImpl implements MailService {
|
||||
private static final Logger logger = LoggerFactory.getLogger(MailServiceImpl.class);
|
||||
|
||||
private Environment env;
|
||||
|
||||
|
@ -54,7 +57,7 @@ public class MailServiceImpl implements MailService {
|
|||
IOUtils.copy(inputStream, writer, "UTF-8");
|
||||
return writer.toString();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ import eu.eudat.models.data.components.commons.datafield.*;
|
|||
import eu.eudat.models.data.entities.xmlmodels.modeldefinition.DatabaseModelDefinition;
|
||||
import eu.eudat.logic.utilities.interfaces.ModelDefinition;
|
||||
import eu.eudat.logic.utilities.interfaces.ViewStyleDefinition;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
@ -12,15 +14,16 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
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) {
|
||||
List<T> list = new LinkedList<T>();
|
||||
for (U item : items) {
|
||||
try {
|
||||
list.add(item.toDatabaseDefinition(clazz.newInstance()));
|
||||
} catch (InstantiationException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
|
@ -32,9 +35,9 @@ public class ModelBuilder {
|
|||
try {
|
||||
list.add(item.toDatabaseDefinition(clazz.newInstance()));
|
||||
} catch (InstantiationException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
|
@ -48,9 +51,9 @@ public class ModelBuilder {
|
|||
modelItem.fromDatabaseDefinition(item);
|
||||
list.add(modelItem);
|
||||
} catch (InstantiationException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package eu.eudat.logic.utilities.builders;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
|
@ -21,6 +23,7 @@ import java.io.StringWriter;
|
|||
|
||||
|
||||
public class XmlBuilder {
|
||||
private static final Logger logger = LoggerFactory.getLogger(XmlBuilder.class);
|
||||
|
||||
public static Document getDocument() {
|
||||
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
|
||||
|
@ -31,7 +34,7 @@ public class XmlBuilder {
|
|||
return doc;
|
||||
} catch (ParserConfigurationException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +51,7 @@ public class XmlBuilder {
|
|||
return writer.toString();
|
||||
} catch (TransformerException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -63,7 +66,7 @@ public class XmlBuilder {
|
|||
return doc;
|
||||
} catch (ParserConfigurationException | SAXException | IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.CTLvl;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STNumberFormat;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class WordBuilder {
|
||||
private static final Logger logger = LoggerFactory.getLogger(WordBuilder.class);
|
||||
|
||||
private Map<ParagraphStyle, ApplierWithValue<XWPFDocument, String, XWPFParagraph>> options = new HashMap<>();
|
||||
private CTAbstractNum cTAbstractNum;
|
||||
|
@ -132,13 +134,13 @@ public class WordBuilder {
|
|||
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 -> {
|
||||
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);
|
||||
sections.forEach(section -> {
|
||||
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);
|
||||
compositeFields.forEach(compositeField -> {
|
||||
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);
|
||||
fields.forEach(field -> {
|
||||
if (visibilityRuleService.isElementVisible(field.getId())) {
|
||||
|
@ -187,7 +189,7 @@ public class WordBuilder {
|
|||
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
||||
number.setVal(BigInteger.valueOf(indent));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -202,7 +204,7 @@ public class WordBuilder {
|
|||
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();
|
||||
|
||||
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()) {
|
||||
case "combobox": {
|
||||
String comboboxType = ((ComboBoxData) field.getData()).getType();
|
||||
|
@ -232,7 +234,7 @@ public class WordBuilder {
|
|||
Map<String, String> map = new HashMap<>();
|
||||
if (!field.getValue().equals("")) {
|
||||
try {
|
||||
JSONArray jsonarray = new JSONArray(field.getValue());
|
||||
JSONArray jsonarray = new JSONArray(field.getValue().toString());
|
||||
for (int i = 0; i < jsonarray.length(); i++) {
|
||||
JSONObject jsonobject = jsonarray.getJSONObject(i);
|
||||
String id = jsonobject.getString("id");
|
||||
|
@ -241,37 +243,39 @@ public class WordBuilder {
|
|||
map.put(id, label);
|
||||
}
|
||||
}
|
||||
} catch (Exception e){
|
||||
Map<String, String> exMap = mapper.readValue(field.getValue(), new TypeReference<Map<String, String>>() {
|
||||
} catch (Exception e) {
|
||||
Map<String, String> exMap = mapper.readValue(field.getValue().toString(), new TypeReference<Map<String, String>>() {
|
||||
});
|
||||
return exMap.get("label");
|
||||
}
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int index = 0;
|
||||
for (Map.Entry<String, String> entry : map.entrySet()) {
|
||||
sb.append("\n");
|
||||
sb.append(entry.getValue());
|
||||
if (index != map.size() - 1) sb.append(", ");
|
||||
index++;
|
||||
}
|
||||
return sb.toString();
|
||||
} else if (comboboxType.equals("wordlist")) {
|
||||
return field.getValue();
|
||||
return field.getValue().toString();
|
||||
}
|
||||
}
|
||||
case "booleanDecision":
|
||||
if (field.getValue() != null && field.getValue().equals("true")) return "Yes";
|
||||
else return "No";
|
||||
case "radiobox":
|
||||
return field.getValue();
|
||||
return field.getValue().toString();
|
||||
case "checkBox":
|
||||
CheckBoxData data = (CheckBoxData) field.getData();
|
||||
if (field.getValue() == null || field.getValue().equals("false")) return null;
|
||||
return data.getLabel();
|
||||
case "freetext":
|
||||
return field.getValue();
|
||||
return field.getValue().toString();
|
||||
case "textarea":
|
||||
return field.getValue();
|
||||
return field.getValue().toString();
|
||||
case "datepicker":
|
||||
return field.getValue();
|
||||
return field.getValue().toString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -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.composite.DatasetProfilePage;
|
||||
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.Element;
|
||||
|
||||
|
@ -17,9 +19,6 @@ import java.io.IOException;
|
|||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 3/5/2018.
|
||||
*/
|
||||
public class ExportXmlBuilder {
|
||||
|
||||
public File build(PagedDatasetProfile pagedDatasetProfile, UUID datasetProfileId, VisibilityRuleService visibilityRuleService) throws IOException {
|
||||
|
@ -49,7 +48,7 @@ public class ExportXmlBuilder {
|
|||
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");
|
||||
sections.forEach(section -> {
|
||||
Element elementSection = element.createElement("section");
|
||||
|
@ -62,7 +61,7 @@ public class ExportXmlBuilder {
|
|||
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");
|
||||
compositeFields.forEach(compositeField -> {
|
||||
if (visibilityRuleService.isElementVisible(compositeField.getId()) && hasVisibleFields(compositeField, visibilityRuleService)) {
|
||||
|
@ -86,15 +85,25 @@ public class ExportXmlBuilder {
|
|||
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");
|
||||
fields.forEach(field -> {
|
||||
if (visibilityRuleService.isElementVisible(field.getId())) {
|
||||
Element elementField = element.createElement("field");
|
||||
elementField.setAttribute("id", field.getId());
|
||||
if (field.getValue() != null && !field.getValue().isEmpty()) {
|
||||
if (field.getValue() != null) {
|
||||
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);
|
||||
}
|
||||
elementFields.appendChild(elementField);
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package eu.eudat.logic.utilities.documents.xml.datasetProfileXml;
|
||||
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.JAXBException;
|
||||
|
@ -7,6 +9,7 @@ import javax.xml.bind.Unmarshaller;
|
|||
import java.io.*;
|
||||
|
||||
public class ImportXmlBuilderDatasetProfile {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ImportXmlBuilderDatasetProfile.class);
|
||||
|
||||
public DatasetProfile build(File xmlFile) throws IOException {
|
||||
DatasetProfile datasetProfile = new DatasetProfile();
|
||||
|
@ -16,7 +19,7 @@ public class ImportXmlBuilderDatasetProfile {
|
|||
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
|
||||
datasetProfile = (DatasetProfile) unmarshaller.unmarshal(xmlFile);
|
||||
} catch (JAXBException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
return datasetProfile;
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package eu.eudat.logic.utilities.documents.xml.dmpXml;
|
||||
|
||||
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.JAXBException;
|
||||
|
@ -9,6 +11,7 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
|
||||
public class ImportXmlBuilderDmpProfile {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ImportXmlBuilderDmpProfile.class);
|
||||
|
||||
public DmpProfile build(File xmlFile) throws IOException {
|
||||
DmpProfile dmpProfile = new DmpProfile();
|
||||
|
@ -18,7 +21,7 @@ public class ImportXmlBuilderDmpProfile {
|
|||
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
|
||||
dmpProfile = (DmpProfile) unmarshaller.unmarshal(xmlFile);
|
||||
} catch (JAXBException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
return dmpProfile;
|
||||
|
|
|
@ -1,16 +1,20 @@
|
|||
package eu.eudat.models;
|
||||
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class HintedModelFactory {
|
||||
private static final Logger logger = LoggerFactory.getLogger(HintedModelFactory.class);
|
||||
|
||||
public static <T extends DataModel> String getHint(Class<T> clazz) {
|
||||
try {
|
||||
return clazz.newInstance().getHint();
|
||||
} catch (InstantiationException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
return null;
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
package eu.eudat.models.data.dashboard.searchbar;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 7/26/2018.
|
||||
*/
|
||||
public class SearchBarItem {
|
||||
private String id;
|
||||
private String label;
|
||||
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.label = label;
|
||||
this.type = type;
|
||||
this.isPublished = isPublished;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
|
@ -37,4 +36,12 @@ public class SearchBarItem {
|
|||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public boolean getIsPublished() {
|
||||
return isPublished;
|
||||
}
|
||||
|
||||
public void setPublished(boolean published) {
|
||||
isPublished = published;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package eu.eudat.models.data.datarepository;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import eu.eudat.data.entities.DataRepository;
|
||||
import eu.eudat.data.entities.UserInfo;
|
||||
import eu.eudat.models.DataModel;
|
||||
|
@ -8,13 +7,9 @@ import eu.eudat.models.DataModel;
|
|||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 9/3/2018.
|
||||
*/
|
||||
public class DataRepositoryModel implements DataModel<DataRepository, DataRepositoryModel> {
|
||||
private UUID id;
|
||||
@JsonProperty("name")
|
||||
private String label;
|
||||
private String name;
|
||||
private String pid;
|
||||
private String abbreviation;
|
||||
private String uri;
|
||||
|
@ -30,11 +25,11 @@ public class DataRepositoryModel implements DataModel<DataRepository, DataReposi
|
|||
this.id = id;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getPid() {
|
||||
|
@ -89,9 +84,10 @@ public class DataRepositoryModel implements DataModel<DataRepository, DataReposi
|
|||
@Override
|
||||
public DataRepositoryModel fromDataModel(DataRepository entity) {
|
||||
this.setAbbreviation(entity.getAbbreviation());
|
||||
this.setLabel(entity.getLabel());
|
||||
this.setName(entity.getLabel());
|
||||
this.setUri(entity.getUri());
|
||||
this.setId(entity.getId());
|
||||
this.setPid(entity.getReference());
|
||||
String source1 = entity.getReference().substring(0, entity.getReference().indexOf(":"));
|
||||
if (source1.equals("dmp")) {
|
||||
this.source = "Internal";
|
||||
|
@ -108,11 +104,15 @@ public class DataRepositoryModel implements DataModel<DataRepository, DataReposi
|
|||
dataRepository.setAbbreviation(this.abbreviation);
|
||||
dataRepository.setCreated(this.created != null ? this.created : new Date());
|
||||
dataRepository.setModified(new Date());
|
||||
dataRepository.setLabel(this.label);
|
||||
dataRepository.setLabel(this.name);
|
||||
if (this.source != null) {
|
||||
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 + ":" + this.id);
|
||||
dataRepository.setReference(this.source + ":" + dataRepository.getId());
|
||||
}
|
||||
} else {
|
||||
dataRepository.setReference("dmp:" + dataRepository.getId());
|
||||
}
|
||||
dataRepository.setUri(this.uri);
|
||||
dataRepository.setStatus((short) 0);
|
||||
|
|
|
@ -4,16 +4,26 @@ import eu.eudat.models.DataModel;
|
|||
import eu.eudat.logic.utilities.helpers.LabelGenerator;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
public class DataRepository implements DataModel<eu.eudat.data.entities.DataRepository, DataRepository>, LabelGenerator {
|
||||
private String id;
|
||||
private String pid;
|
||||
private String label;
|
||||
private String name;
|
||||
private String uri;
|
||||
private String info;
|
||||
private String reference;
|
||||
private String abbreviation;
|
||||
private String tag;
|
||||
private String source;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
@ -21,11 +31,11 @@ public class DataRepository implements DataModel<eu.eudat.data.entities.DataRepo
|
|||
this.pid = pid;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getUri() {
|
||||
|
@ -49,6 +59,13 @@ public class DataRepository implements DataModel<eu.eudat.data.entities.DataRepo
|
|||
this.reference = reference;
|
||||
}
|
||||
|
||||
public String getAbbreviation() {
|
||||
return abbreviation;
|
||||
}
|
||||
public void setAbbreviation(String abbreviation) {
|
||||
this.abbreviation = abbreviation;
|
||||
}
|
||||
|
||||
public String getTag() {
|
||||
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) {
|
||||
this.id = entity.getId().toString();
|
||||
this.pid = entity.getReference();
|
||||
this.label = entity.getLabel();
|
||||
this.name = entity.getLabel();
|
||||
this.uri = entity.getUri();
|
||||
this.abbreviation = entity.getAbbreviation();
|
||||
this.reference = entity.getReference();
|
||||
String source1 = entity.getReference().substring(0, entity.getReference().indexOf(":"));
|
||||
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() {
|
||||
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.setLabel(this.label);
|
||||
entity.setLabel(this.name);
|
||||
entity.setUri(this.uri);
|
||||
entity.setCreated(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);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.abbreviation != null)
|
||||
entity.setAbbreviation(this.abbreviation);
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateLabel() {
|
||||
return this.getLabel();
|
||||
return this.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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.dataRepositories = entity.getDatasetDataRepositories().stream().map(item -> {
|
||||
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, String> values = data.get("data");
|
||||
dataRepository.setInfo(values.get("info"));
|
||||
|
@ -171,7 +171,7 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
|
|||
this.dmp = new DataManagementPlan().fromDataModelNoDatasets(entity.getDmp());
|
||||
this.externalDatasets = entity.getDatasetExternalDatasets().stream().map(item -> {
|
||||
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, String> values = data.get("data");
|
||||
externalDatasetListingModel.setInfo(values.get("info"));
|
||||
|
@ -214,10 +214,10 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
|
|||
eu.eudat.data.entities.DataRepository dataRepository = dataRepositoryModel.toDataModel();
|
||||
DatasetDataRepository datasetDataRepository = new DatasetDataRepository();
|
||||
datasetDataRepository.setDataRepository(dataRepository);
|
||||
Map<String,Map<String,String>> data = new HashMap<>();
|
||||
Map<String,String> values = new HashMap<>();
|
||||
values.put("info",dataRepositoryModel.getInfo());
|
||||
data.put("data",values);
|
||||
Map<String, Map<String, String>> data = new HashMap<>();
|
||||
Map<String, String> values = new HashMap<>();
|
||||
values.put("info", dataRepositoryModel.getInfo());
|
||||
data.put("data", values);
|
||||
datasetDataRepository.setData(JSONValue.toJSONString(data));
|
||||
entity.getDatasetDataRepositories().add(datasetDataRepository);
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
|
|||
private String description;
|
||||
private List<DatasetListingModel> datasets;
|
||||
private List<AssociatedProfile> profiles;
|
||||
private eu.eudat.models.data.grant.Grant grant;
|
||||
private Grant grant;
|
||||
private List<Organisation> organisations;
|
||||
private List<Researcher> researchers;
|
||||
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.researchers = entity.getResearchers().stream().map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList());
|
||||
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.grant = new Grant();
|
||||
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);
|
||||
}
|
||||
}
|
||||
if (entity.isPublic()) {
|
||||
this.datasets = entity.getDataset().stream()
|
||||
.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.created = entity.getCreated();
|
||||
this.description = entity.getDescription();
|
||||
|
|
|
@ -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.researchers = entity.getResearchers().stream().map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList());
|
||||
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.grant = new GrantDMPEditorModel();
|
||||
this.properties = entity.getProperties() != null ? new org.json.JSONObject(entity.getProperties()).toMap() : null;
|
||||
this.grant.getExistGrant().fromDataModel(entity.getGrant());
|
||||
this.grant.getExistGrant().setSource("");
|
||||
this.creator = new eu.eudat.models.data.userinfo.UserInfo();
|
||||
this.groupId = entity.getGroupId();
|
||||
this.lockable = entity.getDataset().stream().findAny().isPresent();
|
||||
|
@ -278,10 +279,11 @@ public class DataManagementPlanEditorModel implements DataModel<DMP, DataManagem
|
|||
dataManagementPlanEntity.setGrant(this.grant.getExistGrant().toDataModel());
|
||||
else {
|
||||
Grant grant = new Grant();
|
||||
grant.setId(UUID.randomUUID());
|
||||
grant.setAbbreviation("");
|
||||
grant.setLabel(this.grant.getLabel());
|
||||
grant.setType(Grant.GrantType.INTERNAL.getValue());
|
||||
grant.setReference("dmp:" + this.grant.getLabel());
|
||||
grant.setReference("dmp:" + grant.getId());
|
||||
grant.setUri("");
|
||||
grant.setDefinition("");
|
||||
grant.setCreated(new Date());
|
||||
|
@ -302,9 +304,10 @@ public class DataManagementPlanEditorModel implements DataModel<DMP, DataManagem
|
|||
} else {
|
||||
if (this.funder.getLabel() != null) {
|
||||
Funder funder = new Funder();
|
||||
funder.setId(UUID.randomUUID());
|
||||
funder.setLabel(this.funder.getLabel());
|
||||
funder.setType(Funder.FunderType.INTERNAL.getValue());
|
||||
funder.setReference("dmp:" + this.funder.getLabel());
|
||||
funder.setReference("dmp:" + funder.getId());
|
||||
funder.setDefinition("");
|
||||
funder.setCreated(new Date());
|
||||
funder.setStatus(Funder.Status.ACTIVE.getValue());
|
||||
|
@ -322,10 +325,11 @@ public class DataManagementPlanEditorModel implements DataModel<DMP, DataManagem
|
|||
dataManagementPlanEntity.setProject(this.project.getExistProject().toDataModel());
|
||||
else {
|
||||
Project project = new Project();
|
||||
project.setId(UUID.randomUUID());
|
||||
project.setAbbreviation("");
|
||||
project.setLabel(this.project.getLabel());
|
||||
project.setType(Project.ProjectType.INTERNAL.getValue());
|
||||
project.setReference("dmp:" + this.project.getLabel());
|
||||
project.setReference("dmp:" + project.getId());
|
||||
project.setUri("");
|
||||
project.setDefinition("");
|
||||
project.setCreated(new Date());
|
||||
|
|
|
@ -182,10 +182,11 @@ public class DataManagementPlanNewVersionModel implements DataModel<DMP, DataMan
|
|||
entity.setGrant(this.grant.getExistGrant().toDataModel());
|
||||
else {
|
||||
eu.eudat.data.entities.Grant grant = new eu.eudat.data.entities.Grant();
|
||||
grant.setId(UUID.randomUUID());
|
||||
grant.setAbbreviation("");
|
||||
grant.setLabel(this.grant.getLabel());
|
||||
grant.setType(eu.eudat.data.entities.Grant.GrantType.INTERNAL.getValue());
|
||||
grant.setReference("dmp:" + this.grant.getLabel());
|
||||
grant.setReference("dmp:" + grant.getId());
|
||||
grant.setUri("");
|
||||
grant.setDefinition("");
|
||||
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) {
|
||||
entity.getGrant().setFunder(null);
|
||||
}
|
||||
else if (this.funder != null && this.funder.getExistFunder() == null && this.funder.getLabel() == null) {
|
||||
entity.getGrant().setFunder(null);
|
||||
}
|
||||
else {
|
||||
if (this.funder == null) {
|
||||
// dataManagementPlanEntity.getGrant().setFunder(null);
|
||||
throw new Exception("Funder is a mandatory entity");
|
||||
} else if (this.funder.getExistFunder() == null && this.funder.getLabel() == null) {
|
||||
// dataManagementPlanEntity.getGrant().setFunder(null);
|
||||
throw new Exception("Funder is a mandatory entity");
|
||||
} else {
|
||||
if (this.funder.getLabel() != null) {
|
||||
Funder funder = new Funder();
|
||||
funder.setId(UUID.randomUUID());
|
||||
funder.setLabel(this.funder.getLabel());
|
||||
funder.setType(Funder.FunderType.INTERNAL.getValue());
|
||||
funder.setReference("dmp:" + this.funder.getLabel());
|
||||
funder.setReference("dmp:" + funder.getId());
|
||||
funder.setDefinition("");
|
||||
funder.setCreated(new Date());
|
||||
funder.setStatus(Funder.Status.ACTIVE.getValue());
|
||||
funder.setModified(new Date());
|
||||
|
||||
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().getFunder().setType(Funder.FunderType.EXTERNAL.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -226,10 +228,11 @@ public class DataManagementPlanNewVersionModel implements DataModel<DMP, DataMan
|
|||
entity.setProject(this.project.getExistProject().toDataModel());
|
||||
else {
|
||||
Project project = new Project();
|
||||
project.setId(UUID.randomUUID());
|
||||
project.setAbbreviation("");
|
||||
project.setLabel(this.project.getLabel());
|
||||
project.setType(Project.ProjectType.INTERNAL.getValue());
|
||||
project.setReference("dmp:" + this.project.getLabel());
|
||||
project.setReference("dmp:" + project.getId());
|
||||
project.setUri("");
|
||||
project.setDefinition("");
|
||||
project.setCreated(new Date());
|
||||
|
|
|
@ -9,8 +9,10 @@ public class Organisation implements DataModel<eu.eudat.data.entities.Organisati
|
|||
private String label;
|
||||
private String name;
|
||||
private String id;
|
||||
private String reference;
|
||||
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() {
|
||||
return label;
|
||||
|
@ -33,6 +35,13 @@ public class Organisation implements DataModel<eu.eudat.data.entities.Organisati
|
|||
this.id = id;
|
||||
}
|
||||
|
||||
public String getReference() {
|
||||
return reference;
|
||||
}
|
||||
public void setReference(String reference) {
|
||||
this.reference = reference;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
@ -47,26 +56,30 @@ public class Organisation implements DataModel<eu.eudat.data.entities.Organisati
|
|||
this.tag = tag;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Organisation fromDataModel(eu.eudat.data.entities.Organisation entity) {
|
||||
this.id = entity.getReference();
|
||||
this.id = entity.getId().toString();
|
||||
this.name = entity.getLabel();
|
||||
this.label = entity.getUri();
|
||||
if (entity.getReference().contains(":cristin")) {
|
||||
this.tag = "cristin";
|
||||
} else {
|
||||
this.tag = entity.getReference().substring(0, entity.getReference().indexOf(":"));
|
||||
}
|
||||
this.reference = entity.getReference();
|
||||
this.key = entity.getReference().substring(0, entity.getReference().indexOf(":"));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public eu.eudat.data.entities.Organisation toDataModel() {
|
||||
eu.eudat.data.entities.Organisation organisationEntity = new eu.eudat.data.entities.Organisation();
|
||||
if (this.tag.equals(this.id.substring(0, this.tag.length()))) {
|
||||
organisationEntity.setReference(this.id);
|
||||
if ((this.key + ":").equals(this.reference.substring(0, this.key.length() + 1))) {
|
||||
organisationEntity.setReference(this.reference);
|
||||
} else {
|
||||
organisationEntity.setReference(this.tag + ":" + this.id);
|
||||
organisationEntity.setReference(this.key + ":" + this.reference);
|
||||
}
|
||||
organisationEntity.setLabel(this.name);
|
||||
organisationEntity.setUri(this.label);
|
||||
|
|
|
@ -2,20 +2,25 @@ package eu.eudat.models.data.dmp;
|
|||
|
||||
import eu.eudat.models.DataModel;
|
||||
import eu.eudat.logic.utilities.helpers.LabelGenerator;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
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 name;
|
||||
private String id;
|
||||
private String reference;
|
||||
private int status;
|
||||
private String tag;
|
||||
private String key;
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
@ -23,7 +28,6 @@ public class Researcher implements DataModel<eu.eudat.data.entities.Researcher,
|
|||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
@ -31,15 +35,20 @@ public class Researcher implements DataModel<eu.eudat.data.entities.Researcher,
|
|||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getReference() {
|
||||
return reference;
|
||||
}
|
||||
public void setReference(String reference) {
|
||||
this.reference = reference;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
@ -47,38 +56,61 @@ public class Researcher implements DataModel<eu.eudat.data.entities.Researcher,
|
|||
public String getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
public void setTag(String tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Researcher fromDataModel(eu.eudat.data.entities.Researcher entity) {
|
||||
this.id = entity.getReference();
|
||||
this.id = entity.getId().toString();
|
||||
this.label = entity.getUri();
|
||||
this.name = entity.getLabel();
|
||||
this.status = entity.getStatus();
|
||||
|
||||
if (entity.getReference().contains(":cristin")) {
|
||||
this.tag = "cristin";
|
||||
} else {
|
||||
this.reference = entity.getReference();
|
||||
String source = entity.getReference().substring(0, entity.getReference().indexOf(":"));
|
||||
if (source.equals("dmp"))
|
||||
this.tag = "Internal";
|
||||
this.key = "Internal";
|
||||
else
|
||||
this.tag = source;
|
||||
}
|
||||
this.key = source;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public eu.eudat.data.entities.Researcher toDataModel() {
|
||||
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()))) {
|
||||
researcher.setReference(this.id);
|
||||
} else {
|
||||
researcher.setReference(this.tag + ":" + this.id);
|
||||
if (this.id == null) {
|
||||
this.id = UUID.randomUUID().toString();
|
||||
}
|
||||
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.setUri(this.label);
|
||||
researcher.setCreated(new Date());
|
||||
|
@ -108,6 +140,6 @@ public class Researcher implements DataModel<eu.eudat.data.entities.Researcher,
|
|||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id.hashCode();
|
||||
return reference.hashCode();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ public class ExternalSourcesItemModel {
|
|||
private String abbreviation;
|
||||
private String tag;
|
||||
private String source;
|
||||
private String key;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
|
@ -74,4 +75,11 @@ public class ExternalSourcesItemModel {
|
|||
public void setSource(String source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ public class FundersExternalSourcesModel extends ExternalListingItem<FundersExte
|
|||
model.setDescription(item.get("description"));
|
||||
model.setSource(item.get("source"));
|
||||
model.setTag(item.get("tag"));
|
||||
model.setKey(item.get("key"));
|
||||
this.add(model);
|
||||
}
|
||||
return this;
|
||||
|
|
|
@ -14,6 +14,7 @@ public class GrantsExternalSourcesModel extends ExternalListingItem<GrantsExtern
|
|||
model.setName(item.get("name"));
|
||||
model.setDescription(item.get("description"));
|
||||
model.setTag(item.get("tag"));
|
||||
model.setKey(item.get("key"));
|
||||
this.add(model);
|
||||
}
|
||||
return this;
|
||||
|
|
|
@ -11,10 +11,11 @@ public class OrganisationsExternalSourcesModel extends ExternalListingItem<Organ
|
|||
public OrganisationsExternalSourcesModel fromExternalItem(List<Map<String, String>> values) {
|
||||
for (Map<String, String> item : values) {
|
||||
ExternalSourcesItemModel model = new ExternalSourcesItemModel();
|
||||
model.setId(item.get("pid"));
|
||||
model.setRemoteId(item.get("pid"));
|
||||
model.setUri(item.get("uri"));
|
||||
model.setName(item.get("name"));
|
||||
model.setTag(item.get("tag"));
|
||||
model.setKey(item.get("key"));
|
||||
this.add(model);
|
||||
}
|
||||
return this;
|
||||
|
|
|
@ -2,12 +2,15 @@ package eu.eudat.models.data.external;
|
|||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ProjectsExternalSourcesModel extends ExternalListingItem<ProjectsExternalSourcesModel> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ProjectsExternalSourcesModel.class);
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@Override
|
||||
|
@ -51,10 +54,17 @@ public class ProjectsExternalSourcesModel extends ExternalListingItem<ProjectsEx
|
|||
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);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
|
|
|
@ -9,10 +9,11 @@ public class ResearchersExternalSourcesModel extends ExternalListingItem<Researc
|
|||
public ResearchersExternalSourcesModel fromExternalItem(List<Map<String, String>> values) {
|
||||
for (Map<String, String> item : values) {
|
||||
ExternalSourcesItemModel model = new ExternalSourcesItemModel();
|
||||
model.setId(item.get("pid"));
|
||||
model.setRemoteId(item.get("pid"));
|
||||
model.setUri(item.get("uri"));
|
||||
model.setName(item.get("name"));
|
||||
model.setTag(item.get("tag"));
|
||||
model.setKey(item.get("key"));
|
||||
this.add(model);
|
||||
}
|
||||
return this;
|
||||
|
|
|
@ -140,6 +140,9 @@ public class ExternalDatasetListingModel implements DataModel<ExternalDataset, E
|
|||
externalDataset.setReference(this.source.toLowerCase() + ":" + this.reference);
|
||||
}
|
||||
}
|
||||
if (externalDataset.getReference() == null) {
|
||||
externalDataset.setReference(this.pid);
|
||||
}
|
||||
externalDataset.setModified(new Date());
|
||||
return externalDataset;
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue