Commit 1b4952a9 authored by Diamantis Tziotzios's avatar Diamantis Tziotzios

Merge branch 'Development'

parents 3ada5a0d f5de71d0
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())));
}
}
query.where(((builder, root) -> builder.notEqual(root.get("status"), DatasetProfile.Status.DELETED.getValue())));
if (criteria.getFinalized()) {
query.where(((builder, root) -> builder.equal(root.get("status"), DatasetProfile.Status.FINALIZED.getValue())));
} else {
query.where(((builder, root) -> builder.notEqual(root.get("status"), DatasetProfile.Status.DELETED.getValue())));
}
return query;
}
......
......@@ -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());
this.getDatasetDataRepositories().removeAll(this.getDatasetDataRepositories());
if (entity.getDatasetDataRepositories() != null)
this.getDatasetDataRepositories().addAll(entity.getDatasetDataRepositories());
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());
} 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());
} else {
this.setDatasetExternalDatasets(new HashSet<>());
}
this.getDatasetExternalDatasets().addAll(entity.getDatasetExternalDatasets().stream().peek(item -> item.setDataset(this)).collect(Collectors.toList()));
}
this.getDatasetExternalDatasets().removeAll(this.getDatasetExternalDatasets());
if (entity.getDatasetExternalDatasets() != null)
this.getDatasetExternalDatasets().addAll(entity.getDatasetExternalDatasets());
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;
}
......
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;