remove old elastic
This commit is contained in:
parent
f0264eefb9
commit
1324029804
|
@ -4,11 +4,10 @@ import eu.eudat.commons.enums.IsActive;
|
||||||
import eu.eudat.data.DescriptionEntity;
|
import eu.eudat.data.DescriptionEntity;
|
||||||
import eu.eudat.data.DescriptionReferenceEntity;
|
import eu.eudat.data.DescriptionReferenceEntity;
|
||||||
import eu.eudat.data.DescriptionTagEntity;
|
import eu.eudat.data.DescriptionTagEntity;
|
||||||
import eu.eudat.data.UserDescriptionTemplateEntity;
|
|
||||||
import eu.eudat.query.DescriptionQuery;
|
import eu.eudat.query.DescriptionQuery;
|
||||||
import eu.eudat.query.DescriptionReferenceQuery;
|
import eu.eudat.query.DescriptionReferenceQuery;
|
||||||
import eu.eudat.query.DescriptionTagQuery;
|
import eu.eudat.query.DescriptionTagQuery;
|
||||||
import eu.eudat.query.UserDescriptionTemplateQuery;
|
import eu.eudat.service.elastic.ElasticService;
|
||||||
import gr.cite.tools.data.deleter.Deleter;
|
import gr.cite.tools.data.deleter.Deleter;
|
||||||
import gr.cite.tools.data.deleter.DeleterFactory;
|
import gr.cite.tools.data.deleter.DeleterFactory;
|
||||||
import gr.cite.tools.data.query.QueryFactory;
|
import gr.cite.tools.data.query.QueryFactory;
|
||||||
|
@ -22,6 +21,7 @@ import org.springframework.context.annotation.Scope;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.management.InvalidApplicationException;
|
import javax.management.InvalidApplicationException;
|
||||||
|
import java.io.IOException;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
@ -39,34 +39,36 @@ public class DescriptionDeleter implements Deleter {
|
||||||
protected final QueryFactory queryFactory;
|
protected final QueryFactory queryFactory;
|
||||||
|
|
||||||
protected final DeleterFactory deleterFactory;
|
protected final DeleterFactory deleterFactory;
|
||||||
|
protected final ElasticService elasticService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public DescriptionDeleter(
|
public DescriptionDeleter(
|
||||||
EntityManager entityManager,
|
EntityManager entityManager,
|
||||||
QueryFactory queryFactory,
|
QueryFactory queryFactory,
|
||||||
DeleterFactory deleterFactory
|
DeleterFactory deleterFactory,
|
||||||
) {
|
ElasticService elasticService) {
|
||||||
this.entityManager = entityManager;
|
this.entityManager = entityManager;
|
||||||
this.queryFactory = queryFactory;
|
this.queryFactory = queryFactory;
|
||||||
this.deleterFactory = deleterFactory;
|
this.deleterFactory = deleterFactory;
|
||||||
|
this.elasticService = elasticService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteAndSaveByIds(List<UUID> ids) throws InvalidApplicationException {
|
public void deleteAndSaveByIds(List<UUID> ids, boolean disableElastic) throws InvalidApplicationException, IOException {
|
||||||
logger.debug(new MapLogEntry("collecting to delete").And("count", Optional.ofNullable(ids).map(List::size).orElse(0)).And("ids", ids));
|
logger.debug(new MapLogEntry("collecting to delete").And("count", Optional.ofNullable(ids).map(List::size).orElse(0)).And("ids", ids));
|
||||||
List<DescriptionEntity> data = this.queryFactory.query(DescriptionQuery.class).ids(ids).collect();
|
List<DescriptionEntity> data = this.queryFactory.query(DescriptionQuery.class).ids(ids).collect();
|
||||||
logger.trace("retrieved {} items", Optional.ofNullable(data).map(List::size).orElse(0));
|
logger.trace("retrieved {} items", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||||
this.deleteAndSave(data);
|
this.deleteAndSave(data, disableElastic);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteAndSave(List<DescriptionEntity> data) throws InvalidApplicationException {
|
public void deleteAndSave(List<DescriptionEntity> data, boolean disableElastic) throws InvalidApplicationException, IOException {
|
||||||
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
|
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||||
this.delete(data);
|
this.delete(data, disableElastic);
|
||||||
logger.trace("saving changes");
|
logger.trace("saving changes");
|
||||||
this.entityManager.flush();
|
this.entityManager.flush();
|
||||||
logger.trace("changes saved");
|
logger.trace("changes saved");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(List<DescriptionEntity> data) throws InvalidApplicationException {
|
public void delete(List<DescriptionEntity> data, boolean disableElastic) throws InvalidApplicationException, IOException {
|
||||||
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
|
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||||
if (data == null || data.isEmpty())
|
if (data == null || data.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
@ -94,6 +96,8 @@ public class DescriptionDeleter implements Deleter {
|
||||||
logger.trace("updating item");
|
logger.trace("updating item");
|
||||||
this.entityManager.merge(item);
|
this.entityManager.merge(item);
|
||||||
logger.trace("updated item");
|
logger.trace("updated item");
|
||||||
|
|
||||||
|
if (!disableElastic) this.elasticService.deleteDescription(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import eu.eudat.data.*;
|
||||||
import eu.eudat.model.DmpDescriptionTemplate;
|
import eu.eudat.model.DmpDescriptionTemplate;
|
||||||
import eu.eudat.model.DmpReference;
|
import eu.eudat.model.DmpReference;
|
||||||
import eu.eudat.query.*;
|
import eu.eudat.query.*;
|
||||||
|
import eu.eudat.service.elastic.ElasticService;
|
||||||
import gr.cite.tools.data.deleter.Deleter;
|
import gr.cite.tools.data.deleter.Deleter;
|
||||||
import gr.cite.tools.data.deleter.DeleterFactory;
|
import gr.cite.tools.data.deleter.DeleterFactory;
|
||||||
import gr.cite.tools.data.query.QueryFactory;
|
import gr.cite.tools.data.query.QueryFactory;
|
||||||
|
@ -18,11 +19,11 @@ import org.springframework.context.annotation.Scope;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.management.InvalidApplicationException;
|
import javax.management.InvalidApplicationException;
|
||||||
|
import java.io.IOException;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||||
|
@ -35,34 +36,36 @@ public class DmpDeleter implements Deleter {
|
||||||
protected final QueryFactory queryFactory;
|
protected final QueryFactory queryFactory;
|
||||||
|
|
||||||
protected final DeleterFactory deleterFactory;
|
protected final DeleterFactory deleterFactory;
|
||||||
|
protected final ElasticService elasticService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public DmpDeleter(
|
public DmpDeleter(
|
||||||
EntityManager entityManager,
|
EntityManager entityManager,
|
||||||
QueryFactory queryFactory,
|
QueryFactory queryFactory,
|
||||||
DeleterFactory deleterFactory
|
DeleterFactory deleterFactory,
|
||||||
) {
|
ElasticService elasticService) {
|
||||||
this.entityManager = entityManager;
|
this.entityManager = entityManager;
|
||||||
this.queryFactory = queryFactory;
|
this.queryFactory = queryFactory;
|
||||||
this.deleterFactory = deleterFactory;
|
this.deleterFactory = deleterFactory;
|
||||||
|
this.elasticService = elasticService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteAndSaveByIds(List<UUID> ids) throws InvalidApplicationException {
|
public void deleteAndSaveByIds(List<UUID> ids, boolean disableElastic) throws InvalidApplicationException, IOException {
|
||||||
logger.debug(new MapLogEntry("collecting to delete").And("count", Optional.ofNullable(ids).map(List::size).orElse(0)).And("ids", ids));
|
logger.debug(new MapLogEntry("collecting to delete").And("count", Optional.ofNullable(ids).map(List::size).orElse(0)).And("ids", ids));
|
||||||
List<DmpEntity> data = this.queryFactory.query(DmpQuery.class).ids(ids).collect();
|
List<DmpEntity> data = this.queryFactory.query(DmpQuery.class).ids(ids).collect();
|
||||||
logger.trace("retrieved {} items", Optional.ofNullable(data).map(List::size).orElse(0));
|
logger.trace("retrieved {} items", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||||
this.deleteAndSave(data);
|
this.deleteAndSave(data, disableElastic);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteAndSave(List<DmpEntity> data) throws InvalidApplicationException {
|
public void deleteAndSave(List<DmpEntity> data, boolean disableElastic) throws InvalidApplicationException, IOException {
|
||||||
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
|
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||||
this.delete(data);
|
this.delete(data, disableElastic);
|
||||||
logger.trace("saving changes");
|
logger.trace("saving changes");
|
||||||
this.entityManager.flush();
|
this.entityManager.flush();
|
||||||
logger.trace("changes saved");
|
logger.trace("changes saved");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(List<DmpEntity> data) throws InvalidApplicationException {
|
public void delete(List<DmpEntity> data, boolean disableElastic) throws InvalidApplicationException, IOException {
|
||||||
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
|
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||||
if (data == null || data.isEmpty())
|
if (data == null || data.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
@ -96,6 +99,8 @@ public class DmpDeleter implements Deleter {
|
||||||
logger.trace("updating item");
|
logger.trace("updating item");
|
||||||
this.entityManager.merge(item);
|
this.entityManager.merge(item);
|
||||||
logger.trace("updated item");
|
logger.trace("updated item");
|
||||||
|
|
||||||
|
if (!disableElastic) this.elasticService.deleteDmp(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -177,7 +177,7 @@ public class DmpQuery extends QueryBase<DmpEntity> {
|
||||||
if (userId != null || usePublic ) {
|
if (userId != null || usePublic ) {
|
||||||
predicates.add(queryContext.CriteriaBuilder.or(
|
predicates.add(queryContext.CriteriaBuilder.or(
|
||||||
usePublic ? queryContext.CriteriaBuilder.and(
|
usePublic ? queryContext.CriteriaBuilder.and(
|
||||||
queryContext.CriteriaBuilder.equal(queryContext.Root.get(DmpEntity._status), DmpStatus.FINALISED),
|
queryContext.CriteriaBuilder.equal(queryContext.Root.get(DmpEntity._status), DmpStatus.Finalized),
|
||||||
queryContext.CriteriaBuilder.equal(queryContext.Root.get(DmpEntity._accessType), DmpAccessType.Public)
|
queryContext.CriteriaBuilder.equal(queryContext.Root.get(DmpEntity._accessType), DmpAccessType.Public)
|
||||||
)
|
)
|
||||||
: queryContext.CriteriaBuilder.or(), //Creates a false query
|
: queryContext.CriteriaBuilder.or(), //Creates a false query
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class QueryUtilsServiceImpl implements QueryUtilsService {
|
||||||
.filterFunc((subQueryRoot, cb) -> cb.or(
|
.filterFunc((subQueryRoot, cb) -> cb.or(
|
||||||
usePublic ? cb.and(
|
usePublic ? cb.and(
|
||||||
cb.equal(subQueryRoot.get(DmpEntity._accessType), DmpAccessType.Public),
|
cb.equal(subQueryRoot.get(DmpEntity._accessType), DmpAccessType.Public),
|
||||||
cb.equal(subQueryRoot.get(DmpEntity._status), DmpStatus.FINALISED),
|
cb.equal(subQueryRoot.get(DmpEntity._status), DmpStatus.Finalized),
|
||||||
cb.equal(subQueryRoot.get(DmpEntity._isActive), IsActive.Active)
|
cb.equal(subQueryRoot.get(DmpEntity._isActive), IsActive.Active)
|
||||||
): cb.or(), //Creates a false query
|
): cb.or(), //Creates a false query
|
||||||
userId != null ? cb.in(subQueryRoot.get(DmpEntity._id)).value(this.buildDmpUserAuthZSubQuery(query, criteriaBuilder, userId)) : cb.or() //Creates a false query
|
userId != null ? cb.in(subQueryRoot.get(DmpEntity._id)).value(this.buildDmpUserAuthZSubQuery(query, criteriaBuilder, userId)) : cb.or() //Creates a false query
|
||||||
|
@ -51,7 +51,7 @@ public class QueryUtilsServiceImpl implements QueryUtilsService {
|
||||||
.filterFunc((subQueryRoot, cb) ->
|
.filterFunc((subQueryRoot, cb) ->
|
||||||
usePublic ? cb.and(
|
usePublic ? cb.and(
|
||||||
cb.equal(subQueryRoot.get(DmpEntity._accessType), DmpAccessType.Public),
|
cb.equal(subQueryRoot.get(DmpEntity._accessType), DmpAccessType.Public),
|
||||||
cb.equal(subQueryRoot.get(DmpEntity._status), DmpStatus.FINALISED),
|
cb.equal(subQueryRoot.get(DmpEntity._status), DmpStatus.Finalized),
|
||||||
cb.equal(subQueryRoot.get(DmpEntity._isActive), IsActive.Active)
|
cb.equal(subQueryRoot.get(DmpEntity._isActive), IsActive.Active)
|
||||||
): cb.or() //Creates a false query
|
): cb.or() //Creates a false query
|
||||||
)
|
)
|
||||||
|
|
|
@ -9,13 +9,14 @@ import gr.cite.tools.exception.MyValidationException;
|
||||||
import gr.cite.tools.fieldset.FieldSet;
|
import gr.cite.tools.fieldset.FieldSet;
|
||||||
|
|
||||||
import javax.management.InvalidApplicationException;
|
import javax.management.InvalidApplicationException;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public interface DescriptionService {
|
public interface DescriptionService {
|
||||||
|
|
||||||
Description persist(DescriptionPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException;
|
Description persist(DescriptionPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException;
|
||||||
|
|
||||||
void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException;
|
void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException, IOException;
|
||||||
|
|
||||||
void clone(UUID dmpId, UUID descriptionId) throws InvalidApplicationException;
|
void clone(UUID dmpId, UUID descriptionId) throws InvalidApplicationException;
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.management.InvalidApplicationException;
|
import javax.management.InvalidApplicationException;
|
||||||
|
import java.io.IOException;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
@ -133,12 +134,12 @@ public class DescriptionServiceImpl implements DescriptionService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException {
|
public void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException, IOException {
|
||||||
logger.debug("deleting description: {}", id);
|
logger.debug("deleting description: {}", id);
|
||||||
|
|
||||||
this.authorizationService.authorizeForce(Permission.DeleteDescription);
|
this.authorizationService.authorizeForce(Permission.DeleteDescription);
|
||||||
|
|
||||||
this.deleterFactory.deleter(DescriptionDeleter.class).deleteAndSaveByIds(List.of(id));
|
this.deleterFactory.deleter(DescriptionDeleter.class).deleteAndSaveByIds(List.of(id), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -18,6 +18,7 @@ import org.springframework.http.ResponseEntity;
|
||||||
import javax.management.InvalidApplicationException;
|
import javax.management.InvalidApplicationException;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
import javax.xml.transform.TransformerException;
|
import javax.xml.transform.TransformerException;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@ -29,7 +30,7 @@ public interface DmpService {
|
||||||
|
|
||||||
Dmp persist(DmpPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JsonProcessingException;
|
Dmp persist(DmpPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JsonProcessingException;
|
||||||
|
|
||||||
void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException;
|
void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException, IOException;
|
||||||
|
|
||||||
Dmp createNewVersion(NewVersionDmpPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException;
|
Dmp createNewVersion(NewVersionDmpPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException;
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,7 @@ import org.springframework.stereotype.Service;
|
||||||
import javax.management.InvalidApplicationException;
|
import javax.management.InvalidApplicationException;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
import javax.xml.transform.TransformerException;
|
import javax.xml.transform.TransformerException;
|
||||||
|
import java.io.IOException;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
@ -134,12 +135,12 @@ public class DmpServiceImpl implements DmpService {
|
||||||
return this.builderFactory.builder(DmpBuilder.class).authorize(AuthorizationFlags.OwnerOrPermissionOrMemberOrPublic).build(BaseFieldSet.build(fields, Dmp._id, Dmp._hash), data);
|
return this.builderFactory.builder(DmpBuilder.class).authorize(AuthorizationFlags.OwnerOrPermissionOrMemberOrPublic).build(BaseFieldSet.build(fields, Dmp._id, Dmp._hash), data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException {
|
public void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException, IOException {
|
||||||
logger.debug("deleting dmp: {}", id);
|
logger.debug("deleting dmp: {}", id);
|
||||||
|
|
||||||
this.authorizationService.authorizeForce(Permission.DeleteDmp);
|
this.authorizationService.authorizeForce(Permission.DeleteDmp);
|
||||||
|
|
||||||
this.deleterFactory.deleter(DmpDeleter.class).deleteAndSaveByIds(List.of(id));
|
this.deleterFactory.deleter(DmpDeleter.class).deleteAndSaveByIds(List.of(id), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -31,11 +31,6 @@
|
||||||
<artifactId>queryable</artifactId>
|
<artifactId>queryable</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>eu.eudat</groupId>
|
|
||||||
<artifactId>elastic</artifactId>
|
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.swagger</groupId>
|
<groupId>io.swagger</groupId>
|
||||||
<artifactId>swagger-annotations</artifactId>
|
<artifactId>swagger-annotations</artifactId>
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package eu.eudat.data.dao.criteria;
|
package eu.eudat.data.dao.criteria;
|
||||||
|
|
||||||
import eu.eudat.data.DescriptionEntity;
|
import eu.eudat.data.DescriptionEntity;
|
||||||
import eu.eudat.elastic.entities.Tag;
|
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -13,7 +12,7 @@ public class DatasetCriteria extends Criteria<DescriptionEntity> {
|
||||||
private Date periodStart;
|
private Date periodStart;
|
||||||
private Date periodEnd;
|
private Date periodEnd;
|
||||||
private List<UUID> dmpIds;
|
private List<UUID> dmpIds;
|
||||||
private List<Tag> tags;
|
// private List<Tag> tags; //TODO
|
||||||
private boolean allVersions;
|
private boolean allVersions;
|
||||||
private UUID profileDatasetId;
|
private UUID profileDatasetId;
|
||||||
private List<String> organisations;
|
private List<String> organisations;
|
||||||
|
@ -61,12 +60,12 @@ public class DatasetCriteria extends Criteria<DescriptionEntity> {
|
||||||
this.dmpIds = dmpIds;
|
this.dmpIds = dmpIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Tag> getTags() {
|
// public List<Tag> getTags() {
|
||||||
return tags;
|
// return tags;
|
||||||
}
|
// }
|
||||||
public void setTags(List<Tag> tags) {
|
// public void setTags(List<Tag> tags) {
|
||||||
this.tags = tags;
|
// this.tags = tags;
|
||||||
}
|
// }
|
||||||
|
|
||||||
public UUID getProfileDatasetId() {
|
public UUID getProfileDatasetId() {
|
||||||
return profileDatasetId;
|
return profileDatasetId;
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package eu.eudat.data.dao.criteria;
|
package eu.eudat.data.dao.criteria;
|
||||||
|
|
||||||
import eu.eudat.data.DescriptionEntity;
|
import eu.eudat.data.DescriptionEntity;
|
||||||
import eu.eudat.elastic.entities.Tag;
|
|
||||||
import eu.eudat.types.grant.GrantStateType;
|
import eu.eudat.types.grant.GrantStateType;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -15,7 +14,7 @@ public class DatasetPublicCriteria extends Criteria<DescriptionEntity>{
|
||||||
private List<UUID> grants;
|
private List<UUID> grants;
|
||||||
private List<UUID> datasetProfile;
|
private List<UUID> datasetProfile;
|
||||||
private List<String> dmpOrganisations;
|
private List<String> dmpOrganisations;
|
||||||
private List<Tag> tags;
|
// private List<Tag> tags; TODO:
|
||||||
private List<UUID> dmpIds;
|
private List<UUID> dmpIds;
|
||||||
private Integer role;
|
private Integer role;
|
||||||
|
|
||||||
|
@ -47,12 +46,12 @@ public class DatasetPublicCriteria extends Criteria<DescriptionEntity>{
|
||||||
this.dmpOrganisations = dmpOrganisations;
|
this.dmpOrganisations = dmpOrganisations;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Tag> getTags() {
|
// public List<Tag> getTags() {
|
||||||
return tags;
|
// return tags;
|
||||||
}
|
// }
|
||||||
public void setTags(List<Tag> tags) {
|
// public void setTags(List<Tag> tags) {
|
||||||
this.tags = tags;
|
// this.tags = tags;
|
||||||
}
|
// }
|
||||||
|
|
||||||
public List<UUID> getDmpIds() {
|
public List<UUID> getDmpIds() {
|
||||||
return dmpIds;
|
return dmpIds;
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<parent>
|
|
||||||
<artifactId>dmp-backend</artifactId>
|
|
||||||
<groupId>eu.eudat</groupId>
|
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<artifactId>elastic</artifactId>
|
|
||||||
|
|
||||||
</project>
|
|
|
@ -1,7 +0,0 @@
|
||||||
package eu.eudat.elastic.criteria;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by ikalyvas on 7/5/2018.
|
|
||||||
*/
|
|
||||||
public abstract class Criteria {
|
|
||||||
}
|
|
|
@ -1,156 +0,0 @@
|
||||||
package eu.eudat.elastic.criteria;
|
|
||||||
|
|
||||||
import eu.eudat.elastic.entities.Tag;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by ikalyvas on 7/5/2018.
|
|
||||||
*/
|
|
||||||
public class DatasetCriteria extends Criteria {
|
|
||||||
private String like;
|
|
||||||
private List<UUID> datasetTemplates;
|
|
||||||
private Short status;
|
|
||||||
private List<UUID> dmps;
|
|
||||||
private List<UUID> groupIds;
|
|
||||||
private List<UUID> grants;
|
|
||||||
private List<UUID> collaborators;
|
|
||||||
private Boolean allowAllVersions;
|
|
||||||
private List<String> organiztions;
|
|
||||||
private Boolean hasTags;
|
|
||||||
private List<Tag> tags;
|
|
||||||
private boolean isPublic;
|
|
||||||
private Short grantStatus;
|
|
||||||
private int offset;
|
|
||||||
private int size;
|
|
||||||
private List<SortCriteria> sortCriteria;
|
|
||||||
|
|
||||||
public String getLike() {
|
|
||||||
return like;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLike(String like) {
|
|
||||||
this.like = like;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<UUID> getDatasetTemplates() {
|
|
||||||
return datasetTemplates;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDatasetTemplates(List<UUID> datasetTemplates) {
|
|
||||||
this.datasetTemplates = datasetTemplates;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Short getStatus() {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStatus(Short status) {
|
|
||||||
this.status = status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<UUID> getDmps() {
|
|
||||||
return dmps;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDmps(List<UUID> dmps) {
|
|
||||||
this.dmps = dmps;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<UUID> getGroupIds() {
|
|
||||||
return groupIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGroupIds(List<UUID> groupIds) {
|
|
||||||
this.groupIds = groupIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<UUID> getGrants() {
|
|
||||||
return grants;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGrants(List<UUID> grants) {
|
|
||||||
this.grants = grants;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<UUID> getCollaborators() {
|
|
||||||
return collaborators;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCollaborators(List<UUID> collaborators) {
|
|
||||||
this.collaborators = collaborators;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean getAllowAllVersions() {
|
|
||||||
return allowAllVersions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAllowAllVersions(Boolean allowAllVersions) {
|
|
||||||
this.allowAllVersions = allowAllVersions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getOrganiztions() {
|
|
||||||
return organiztions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOrganiztions(List<String> organiztions) {
|
|
||||||
this.organiztions = organiztions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Tag> getTags() {
|
|
||||||
return tags;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTags(List<Tag> tags) {
|
|
||||||
this.tags = tags;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isPublic() {
|
|
||||||
return isPublic;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPublic(boolean aPublic) {
|
|
||||||
isPublic = aPublic;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Short getGrantStatus() {
|
|
||||||
return grantStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGrantStatus(Short grantStatus) {
|
|
||||||
this.grantStatus = grantStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getOffset() {
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOffset(int offset) {
|
|
||||||
this.offset = offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSize() {
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSize(int size) {
|
|
||||||
this.size = size;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<SortCriteria> getSortCriteria() {
|
|
||||||
return sortCriteria;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSortCriteria(List<SortCriteria> sortCriteria) {
|
|
||||||
this.sortCriteria = sortCriteria;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean getHasTags() {
|
|
||||||
return hasTags;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHasTags(Boolean hasTags) {
|
|
||||||
this.hasTags = hasTags;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,134 +0,0 @@
|
||||||
package eu.eudat.elastic.criteria;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class DmpCriteria extends Criteria {
|
|
||||||
private String like;
|
|
||||||
private Short status;
|
|
||||||
private List<UUID> templates;
|
|
||||||
private List<UUID> grants;
|
|
||||||
private List<UUID> collaborators;
|
|
||||||
private List<Integer> roles;
|
|
||||||
private List<UUID> organizations;
|
|
||||||
private boolean isPublic;
|
|
||||||
private List<UUID> groupIds;
|
|
||||||
private boolean allowAllVersions;
|
|
||||||
private Short grantStatus;
|
|
||||||
private int offset;
|
|
||||||
private Integer size;
|
|
||||||
private List<SortCriteria> sortCriteria;
|
|
||||||
|
|
||||||
|
|
||||||
public String getLike() {
|
|
||||||
return like;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLike(String like) {
|
|
||||||
this.like = like;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Short getStatus() {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStatus(Short status) {
|
|
||||||
this.status = status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<UUID> getTemplates() {
|
|
||||||
return templates;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTemplates(List<UUID> templates) {
|
|
||||||
this.templates = templates;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<UUID> getGrants() {
|
|
||||||
return grants;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGrants(List<UUID> grants) {
|
|
||||||
this.grants = grants;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<UUID> getCollaborators() {
|
|
||||||
return collaborators;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCollaborators(List<UUID> collaborators) {
|
|
||||||
this.collaborators = collaborators;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Integer> getRoles() {
|
|
||||||
return roles;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRoles(List<Integer> roles) {
|
|
||||||
this.roles = roles;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<UUID> getOrganizations() {
|
|
||||||
return organizations;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOrganizations(List<UUID> organizations) {
|
|
||||||
this.organizations = organizations;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isPublic() {
|
|
||||||
return isPublic;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPublic(boolean aPublic) {
|
|
||||||
isPublic = aPublic;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<UUID> getGroupIds() {
|
|
||||||
return groupIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGroupIds(List<UUID> groupIds) {
|
|
||||||
this.groupIds = groupIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isAllowAllVersions() {
|
|
||||||
return allowAllVersions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAllowAllVersions(boolean allowAllVersions) {
|
|
||||||
this.allowAllVersions = allowAllVersions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Short getGrantStatus() {
|
|
||||||
return grantStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGrantStatus(Short grantStatus) {
|
|
||||||
this.grantStatus = grantStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getOffset() {
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOffset(int offset) {
|
|
||||||
this.offset = offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getSize() {
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSize(Integer size) {
|
|
||||||
this.size = size;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<SortCriteria> getSortCriteria() {
|
|
||||||
return sortCriteria;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSortCriteria(List<SortCriteria> sortCriteria) {
|
|
||||||
this.sortCriteria = sortCriteria;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
package eu.eudat.elastic.criteria;
|
|
||||||
|
|
||||||
public class SortCriteria {
|
|
||||||
public enum OrderByType {
|
|
||||||
ASC, DESC
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum ColumnType {
|
|
||||||
COUNT, COLUMN, JOIN_COLUMN
|
|
||||||
}
|
|
||||||
|
|
||||||
private String fieldName;
|
|
||||||
private OrderByType orderByType;
|
|
||||||
private ColumnType columnType;
|
|
||||||
|
|
||||||
public String getFieldName() {
|
|
||||||
return fieldName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFieldName(String fieldName) {
|
|
||||||
this.fieldName = fieldName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OrderByType getOrderByType() {
|
|
||||||
return orderByType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOrderByType(OrderByType orderByType) {
|
|
||||||
this.orderByType = orderByType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ColumnType getColumnType() {
|
|
||||||
return columnType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setColumnType(ColumnType columnType) {
|
|
||||||
this.columnType = columnType;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
package eu.eudat.elastic.criteria;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by ikalyvas on 7/5/2018.
|
|
||||||
*/
|
|
||||||
public class TagCriteria extends Criteria {
|
|
||||||
}
|
|
|
@ -1,54 +0,0 @@
|
||||||
package eu.eudat.elastic.entities;
|
|
||||||
|
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class Collaborator implements ElasticEntity<Collaborator> {
|
|
||||||
private String id;
|
|
||||||
private String name;
|
|
||||||
private int role;
|
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(String id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getRole() {
|
|
||||||
return role;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRole(int role) {
|
|
||||||
this.role = role;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public XContentBuilder toElasticEntity(XContentBuilder builder) throws IOException {
|
|
||||||
builder.startObject();
|
|
||||||
builder.field("id", this.id);
|
|
||||||
builder.field("name", this.name);
|
|
||||||
builder.field("role", this.role);
|
|
||||||
builder.endObject();
|
|
||||||
return builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collaborator fromElasticEntity(Map fields) {
|
|
||||||
this.id = (String) fields.get("id");
|
|
||||||
this.name = (String) fields.get("name");
|
|
||||||
this.role = (int) fields.get("role");
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,334 +0,0 @@
|
||||||
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.time.Instant;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by ikalyvas on 7/5/2018.
|
|
||||||
*/
|
|
||||||
public class Dataset implements ElasticEntity<Dataset> {
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(Dataset.class);
|
|
||||||
|
|
||||||
public enum Status {
|
|
||||||
SAVED((short) 0), FINALISED((short) 1), CANCELED((short) 2), DELETED((short) 99),;
|
|
||||||
|
|
||||||
private short value;
|
|
||||||
|
|
||||||
private Status(short value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public short getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Status fromInteger(int value) {
|
|
||||||
switch (value) {
|
|
||||||
case 0:
|
|
||||||
return SAVED;
|
|
||||||
case 1:
|
|
||||||
return FINALISED;
|
|
||||||
case 2:
|
|
||||||
return CANCELED;
|
|
||||||
case 99:
|
|
||||||
return DELETED;
|
|
||||||
default:
|
|
||||||
throw new RuntimeException("Unsupported Dataset Status");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String id;
|
|
||||||
private List<Tag> tags = new LinkedList<>();
|
|
||||||
private String label;
|
|
||||||
private String description;
|
|
||||||
private UUID template;
|
|
||||||
private Short status;
|
|
||||||
private UUID dmp;
|
|
||||||
private UUID group;
|
|
||||||
private UUID grant;
|
|
||||||
private List<Collaborator> collaborators;
|
|
||||||
private Boolean lastVersion;
|
|
||||||
private Boolean lastPublicVersion;
|
|
||||||
private List<Organization> organizations;
|
|
||||||
private Boolean isPublic;
|
|
||||||
private Short grantStatus;
|
|
||||||
private String formData;
|
|
||||||
private Date created;
|
|
||||||
private Date modified;
|
|
||||||
private Date finalizedAt;
|
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(String id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Tag> getTags() {
|
|
||||||
return tags;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTags(List<Tag> tags) {
|
|
||||||
this.tags = tags;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLabel() {
|
|
||||||
return label;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLabel(String label) {
|
|
||||||
this.label = label;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription() {
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDescription(String description) {
|
|
||||||
this.description = description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getTemplate() {
|
|
||||||
return template;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTemplate(UUID template) {
|
|
||||||
this.template = template;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Short getStatus() {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStatus(Short status) {
|
|
||||||
this.status = status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getDmp() {
|
|
||||||
return dmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDmp(UUID dmp) {
|
|
||||||
this.dmp = dmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getGroup() {
|
|
||||||
return group;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGroup(UUID group) {
|
|
||||||
this.group = group;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getGrant() {
|
|
||||||
return grant;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGrant(UUID grant) {
|
|
||||||
this.grant = grant;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Collaborator> getCollaborators() {
|
|
||||||
return collaborators;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCollaborators(List<Collaborator> collaborators) {
|
|
||||||
this.collaborators = collaborators;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean getLastVersion() {
|
|
||||||
return lastVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLastVersion(Boolean lastVersion) {
|
|
||||||
this.lastVersion = lastVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean getLastPublicVersion() {
|
|
||||||
return lastPublicVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLastPublicVersion(Boolean lastPublicVersion) {
|
|
||||||
this.lastPublicVersion = lastPublicVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Organization> getOrganizations() {
|
|
||||||
return organizations;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOrganizations(List<Organization> organizations) {
|
|
||||||
this.organizations = organizations;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean getPublic() {
|
|
||||||
return isPublic;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPublic(Boolean aPublic) {
|
|
||||||
isPublic = aPublic;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Short getGrantStatus() {
|
|
||||||
return grantStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGrantStatus(Short grantStatus) {
|
|
||||||
this.grantStatus = grantStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFormData() {
|
|
||||||
return formData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFormData(String formData) {
|
|
||||||
this.formData = formData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getCreated() {
|
|
||||||
return created;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCreated(Date created) {
|
|
||||||
this.created = created;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getModified() {
|
|
||||||
return modified;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setModified(Date modified) {
|
|
||||||
this.modified = modified;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getFinalizedAt() {
|
|
||||||
return finalizedAt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFinalizedAt(Date finalizedAt) {
|
|
||||||
this.finalizedAt = finalizedAt;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public XContentBuilder toElasticEntity(XContentBuilder builder) throws IOException {
|
|
||||||
builder.startObject();
|
|
||||||
builder.field("id", this.id);
|
|
||||||
builder.field("label", this.label);
|
|
||||||
builder.field("description", this.description);
|
|
||||||
builder.field("template", this.template.toString());
|
|
||||||
builder.field("status", this.status.toString());
|
|
||||||
builder.field("dmp", this.dmp.toString());
|
|
||||||
builder.field("created", this.created);
|
|
||||||
builder.field("modified", this.modified);
|
|
||||||
builder.field("finalizedAt", this.finalizedAt);
|
|
||||||
if (this.group != null) {
|
|
||||||
builder.field("group", this.group.toString());
|
|
||||||
}
|
|
||||||
if (this.grant != null) {
|
|
||||||
builder.field("grant", this.grant.toString());
|
|
||||||
}
|
|
||||||
if (collaborators != null) {
|
|
||||||
builder.startArray("collaborators");
|
|
||||||
this.collaborators.forEach(x -> {
|
|
||||||
try {
|
|
||||||
x.toElasticEntity(builder);
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.error(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
builder.endArray();
|
|
||||||
}
|
|
||||||
builder.field("lastVersion", this.lastVersion.toString());
|
|
||||||
builder.field("lastPublicVersion", this.lastPublicVersion.toString());
|
|
||||||
if (organizations != null) {
|
|
||||||
builder.startArray("organizations");
|
|
||||||
this.organizations.forEach(x -> {
|
|
||||||
try {
|
|
||||||
x.toElasticEntity(builder);
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.error(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
builder.endArray();
|
|
||||||
}
|
|
||||||
if (this.tags != null) {
|
|
||||||
builder.startArray("tags");
|
|
||||||
this.tags.forEach(x -> {
|
|
||||||
try {
|
|
||||||
x.toElasticEntity(builder);
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.error(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
builder.endArray();
|
|
||||||
}
|
|
||||||
if (this.isPublic != null) {
|
|
||||||
builder.field("public", this.isPublic.toString());
|
|
||||||
}
|
|
||||||
if (this.grantStatus != null) {
|
|
||||||
builder.field("grantStatus", this.grantStatus.toString());
|
|
||||||
}
|
|
||||||
builder.field("formData", this.formData);
|
|
||||||
builder.endObject();
|
|
||||||
return builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Dataset fromElasticEntity(Map<String, Object> fields) {
|
|
||||||
if (fields != null) {
|
|
||||||
if (fields.size() == 1) {
|
|
||||||
if (fields.containsKey("id")) {
|
|
||||||
this.id = (String) fields.get("id");
|
|
||||||
} else if (fields.containsKey("tags")) {
|
|
||||||
this.tags = ((List<HashMap>) fields.get("tags")).stream().map(hashMap -> new Tag().fromElasticEntity(hashMap)).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
}else if (fields.size() > 1) {
|
|
||||||
this.id = (String) fields.get("id");
|
|
||||||
if (fields.get("tags") != null) {
|
|
||||||
this.tags = ((List<HashMap>) fields.get("tags")).stream().map(hashMap -> new Tag().fromElasticEntity(hashMap)).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
this.label = (String) fields.get("label");
|
|
||||||
this.description = (String) fields.get("description");
|
|
||||||
this.template = UUID.fromString((String) fields.get("template"));
|
|
||||||
this.status = Short.valueOf((String) fields.get("status"));
|
|
||||||
this.dmp = UUID.fromString((String) fields.get("dmp"));
|
|
||||||
this.group = UUID.fromString((String) fields.get("group"));
|
|
||||||
if (fields.get("grant") != null) {
|
|
||||||
this.grant = UUID.fromString((String) fields.get("grant"));
|
|
||||||
}
|
|
||||||
if (fields.get("created") != null)
|
|
||||||
this.created = Date.from(Instant.parse((String) fields.get("created")));
|
|
||||||
if (fields.get("modified") != null)
|
|
||||||
this.modified = Date.from(Instant.parse((String) fields.get("modified")));
|
|
||||||
if (fields.get("finalizedAt") != null)
|
|
||||||
this.finalizedAt = Date.from(Instant.parse((String) fields.get("finalizedAt")));
|
|
||||||
if (fields.get("collaborators") != null) {
|
|
||||||
this.collaborators = ((List<HashMap>) fields.get("collaborators")).stream().map(hashMap -> new Collaborator().fromElasticEntity(hashMap)).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
this.lastVersion = Boolean.parseBoolean((String) fields.get("lastVersion"));
|
|
||||||
this.lastPublicVersion = Boolean.parseBoolean((String) fields.get("lastPublicVersion"));
|
|
||||||
if (fields.get("organizations") != null) {
|
|
||||||
this.organizations = ((List<HashMap>) fields.get("organizations")).stream().map(hashMap -> new Organization().fromElasticEntity(hashMap)).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
if (fields.get("public") != null) {
|
|
||||||
this.isPublic = Boolean.valueOf((String) fields.get("public"));
|
|
||||||
}
|
|
||||||
if (fields.get("grantStatus") != null) {
|
|
||||||
this.grantStatus = Short.valueOf((String) fields.get("grantStatus"));
|
|
||||||
}
|
|
||||||
this.formData = (String) fields.get("formData");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,68 +0,0 @@
|
||||||
package eu.eudat.elastic.entities;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class DatasetTempalate implements ElasticEntity<DatasetTempalate> {
|
|
||||||
private UUID id;
|
|
||||||
private String name;
|
|
||||||
private Map<String, Object> data;
|
|
||||||
|
|
||||||
public UUID getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(UUID id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, Object> getData() {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setData(Map<String, Object> data) {
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public XContentBuilder toElasticEntity(XContentBuilder builder) throws IOException {
|
|
||||||
builder.startObject();
|
|
||||||
builder.field("id", this.id.toString());
|
|
||||||
builder.field("name", this.name);
|
|
||||||
if(this.data != null) {
|
|
||||||
builder.field("data", new ObjectMapper().writeValueAsString(this.data));
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
builder.field("data", "");
|
|
||||||
}
|
|
||||||
builder.endObject();
|
|
||||||
return builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DatasetTempalate fromElasticEntity(Map<String, Object> fields) {
|
|
||||||
this.id = UUID.fromString((String) fields.get("id"));
|
|
||||||
this.name = (String) fields.get("name");
|
|
||||||
try {
|
|
||||||
this.data = new ObjectMapper().readValue((String) fields.get("data"), new TypeReference<Map<String, Object>>() {});
|
|
||||||
}
|
|
||||||
catch (Exception e){
|
|
||||||
this.data = new HashMap<>();
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,382 +0,0 @@
|
||||||
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.time.Instant;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class Dmp implements ElasticEntity<Dmp> {
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(Dmp.class);
|
|
||||||
|
|
||||||
public enum DMPStatus {
|
|
||||||
ACTIVE((short) 0), FINALISED((short) 1),DELETED((short) 99);
|
|
||||||
|
|
||||||
private short value;
|
|
||||||
|
|
||||||
private DMPStatus(short value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public short getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static DMPStatus fromInteger(short value) {
|
|
||||||
switch (value) {
|
|
||||||
case 0:
|
|
||||||
return ACTIVE;
|
|
||||||
case 1:
|
|
||||||
return FINALISED;
|
|
||||||
case 99:
|
|
||||||
return DELETED;
|
|
||||||
default:
|
|
||||||
throw new RuntimeException("Unsupported DMP Status");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private UUID id;
|
|
||||||
private String label;
|
|
||||||
private String description;
|
|
||||||
private UUID groupId;
|
|
||||||
private Short status;
|
|
||||||
private List<DatasetTempalate> templates;
|
|
||||||
private List<Collaborator> collaborators;
|
|
||||||
private List<Organization> organizations;
|
|
||||||
private Boolean lastVersion;
|
|
||||||
private Boolean lastPublicVersion;
|
|
||||||
private Boolean isPublic;
|
|
||||||
private List<Dataset> datasets;
|
|
||||||
private UUID grant;
|
|
||||||
private Short grantStatus;
|
|
||||||
private Date created;
|
|
||||||
private Date modified;
|
|
||||||
private Date finalizedAt;
|
|
||||||
private Date publishedAt;
|
|
||||||
private List<Doi> dois;
|
|
||||||
|
|
||||||
public UUID getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(UUID id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLabel() {
|
|
||||||
return label;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLabel(String label) {
|
|
||||||
this.label = label;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription() {
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDescription(String description) {
|
|
||||||
this.description = description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getGroupId() {
|
|
||||||
return groupId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGroupId(UUID groupId) {
|
|
||||||
this.groupId = groupId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Short getStatus() {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStatus(Short status) {
|
|
||||||
this.status = status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<DatasetTempalate> getTemplates() {
|
|
||||||
return templates;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTemplates(List<DatasetTempalate> templates) {
|
|
||||||
this.templates = templates;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Collaborator> getCollaborators() {
|
|
||||||
return collaborators;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCollaborators(List<Collaborator> collaborators) {
|
|
||||||
this.collaborators = collaborators;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Organization> getOrganizations() {
|
|
||||||
return organizations;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOrganizations(List<Organization> organizations) {
|
|
||||||
this.organizations = organizations;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean getLastVersion() {
|
|
||||||
return lastVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLastVersion(Boolean lastVersion) {
|
|
||||||
this.lastVersion = lastVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean getLastPublicVersion() {
|
|
||||||
return lastPublicVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLastPublicVersion(Boolean lastPublicVersion) {
|
|
||||||
this.lastPublicVersion = lastPublicVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean getPublic() {
|
|
||||||
return isPublic;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPublic(Boolean aPublic) {
|
|
||||||
isPublic = aPublic;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Dataset> getDatasets() {
|
|
||||||
return datasets;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDatasets(List<Dataset> datasets) {
|
|
||||||
this.datasets = datasets;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getGrant() {
|
|
||||||
return grant;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGrant(UUID grant) {
|
|
||||||
this.grant = grant;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Short getGrantStatus() {
|
|
||||||
return grantStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGrantStatus(Short grantStatus) {
|
|
||||||
this.grantStatus = grantStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getCreated() {
|
|
||||||
return created;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCreated(Date created) {
|
|
||||||
this.created = created;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getModified() {
|
|
||||||
return modified;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setModified(Date modified) {
|
|
||||||
this.modified = modified;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getFinalizedAt() {
|
|
||||||
return finalizedAt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFinalizedAt(Date finalizedAt) {
|
|
||||||
this.finalizedAt = finalizedAt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getPublishedAt() {
|
|
||||||
return publishedAt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPublishedAt(Date publishedAt) {
|
|
||||||
this.publishedAt = publishedAt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Doi> getDois() {
|
|
||||||
return dois;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDois(List<Doi> dois) {
|
|
||||||
this.dois = dois;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public XContentBuilder toElasticEntity(XContentBuilder builder) throws IOException {
|
|
||||||
builder.startObject();
|
|
||||||
if (this.id != null) {
|
|
||||||
builder.field(MapKey.ID.getName(), this.id.toString());
|
|
||||||
}
|
|
||||||
builder.field(MapKey.LABEL.getName(), this.label);
|
|
||||||
builder.field(MapKey.DESCRIPTION.getName(), this.description);
|
|
||||||
if (this.groupId != null) {
|
|
||||||
builder.field(MapKey.GROUPID.getName(), this.groupId.toString());
|
|
||||||
}
|
|
||||||
builder.field(MapKey.STATUS.getName(), this.status);
|
|
||||||
if (this.templates != null && !this.templates.isEmpty()) {
|
|
||||||
builder.startArray(MapKey.TEMPLATES.getName());
|
|
||||||
this.templates.forEach(template -> {
|
|
||||||
try {
|
|
||||||
template.toElasticEntity(builder);
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.error(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
builder.endArray();
|
|
||||||
}
|
|
||||||
if (this.collaborators != null && !this.collaborators.isEmpty()) {
|
|
||||||
builder.startArray(MapKey.COLLABORATORS.getName());
|
|
||||||
this.collaborators.forEach(collaborator -> {
|
|
||||||
try {
|
|
||||||
collaborator.toElasticEntity(builder);
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.error(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
builder.endArray();
|
|
||||||
}
|
|
||||||
if (this.organizations != null && !this.organizations.isEmpty()) {
|
|
||||||
builder.startArray(MapKey.ORGANIZATIONS.getName());
|
|
||||||
this.organizations.forEach(organization -> {
|
|
||||||
try {
|
|
||||||
organization.toElasticEntity(builder);
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.error(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
builder.endArray();
|
|
||||||
}
|
|
||||||
builder.field(MapKey.LASTVERSION.getName(), this.lastVersion);
|
|
||||||
builder.field(MapKey.LASTPUBLICVERSION.getName(), this.lastPublicVersion);
|
|
||||||
builder.field(MapKey.ISPUBLIC.getName(), this.isPublic);
|
|
||||||
if (datasets != null && !this.datasets.isEmpty()) {
|
|
||||||
builder.startArray(MapKey.DATASETS.getName());
|
|
||||||
this.datasets.forEach(dataset -> {
|
|
||||||
try {
|
|
||||||
if (dataset != null) {
|
|
||||||
dataset.toElasticEntity(builder);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
builder.endArray();
|
|
||||||
}
|
|
||||||
if (this.grant != null) {
|
|
||||||
builder.field(MapKey.GRANT.getName(), this.grant.toString());
|
|
||||||
}
|
|
||||||
builder.field(MapKey.GRANTSTATUS.getName(), this.grantStatus);
|
|
||||||
builder.field(MapKey.CREATED.getName(), this.created);
|
|
||||||
builder.field(MapKey.MODIFIED.getName(), this.modified);
|
|
||||||
builder.field(MapKey.FINALIZEDAT.getName(), this.finalizedAt);
|
|
||||||
builder.field(MapKey.PUBLISHEDAT.getName(), this.publishedAt);
|
|
||||||
if (this.dois != null && !this.dois.isEmpty()) {
|
|
||||||
builder.startArray(MapKey.DOIS.getName());
|
|
||||||
this.dois.forEach(doi -> {
|
|
||||||
try {
|
|
||||||
doi.toElasticEntity(builder);
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.error(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
builder.endArray();
|
|
||||||
}
|
|
||||||
builder.endObject();
|
|
||||||
return builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Dmp fromElasticEntity(Map<String, Object> fields) {
|
|
||||||
if (fields == null || fields.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
this.id = UUID.fromString((String) fields.get(MapKey.ID.getName()));
|
|
||||||
if (fields.size() > 1) {
|
|
||||||
this.label = (String) fields.get(MapKey.LABEL.getName());
|
|
||||||
this.description = (String) fields.get(MapKey.DESCRIPTION.getName());
|
|
||||||
if (fields.get(MapKey.GROUPID.getName()) != null) {
|
|
||||||
this.groupId = UUID.fromString((String) fields.get(MapKey.GROUPID.getName()));
|
|
||||||
}
|
|
||||||
this.status = Short.valueOf(fields.get(MapKey.STATUS.getName()).toString());
|
|
||||||
if (fields.get(MapKey.TEMPLATES.getName()) != null) {
|
|
||||||
this.templates = ((List<HashMap<String, Object>>) fields.get(MapKey.TEMPLATES.getName())).stream().map(hashMap -> new DatasetTempalate().fromElasticEntity(hashMap)).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
if (fields.get(MapKey.COLLABORATORS.getName()) != null) {
|
|
||||||
this.collaborators = ((List<HashMap<String, Object>>) fields.get(MapKey.COLLABORATORS.getName())).stream().map(map -> new Collaborator().fromElasticEntity(map)).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
if (fields.get(MapKey.ORGANIZATIONS.getName()) != null) {
|
|
||||||
this.organizations = ((List<HashMap<String, Object>>) fields.get(MapKey.ORGANIZATIONS.getName())).stream().map(map -> new Organization().fromElasticEntity(map)).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
this.lastVersion = (Boolean) fields.get(MapKey.LASTVERSION.getName());
|
|
||||||
this.lastPublicVersion = (Boolean) fields.get(MapKey.LASTPUBLICVERSION.getName());
|
|
||||||
this.isPublic = (Boolean) fields.get(MapKey.ISPUBLIC.getName());
|
|
||||||
if (fields.get(MapKey.DATASETS.getName()) != null) {
|
|
||||||
this.datasets = ((List<HashMap<String, Object>>) fields.get(MapKey.DATASETS.getName())).stream().map(map -> new Dataset().fromElasticEntity(map)).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
if (fields.containsKey(MapKey.GRANT.getName()) && fields.get(MapKey.GRANT.getName()) != null) {
|
|
||||||
this.grant = UUID.fromString((String) fields.get(MapKey.GRANT.getName()));
|
|
||||||
}
|
|
||||||
if (fields.get(MapKey.GRANTSTATUS.getName()) != null) {
|
|
||||||
this.grantStatus = Short.valueOf(fields.get(MapKey.GRANTSTATUS.getName()).toString());
|
|
||||||
}
|
|
||||||
if (fields.containsKey(MapKey.CREATED.getName())) {
|
|
||||||
this.created = Date.from(Instant.parse(fields.get(MapKey.CREATED.getName()).toString()));
|
|
||||||
}
|
|
||||||
if (fields.containsKey(MapKey.MODIFIED.getName())) {
|
|
||||||
this.modified = Date.from(Instant.parse(fields.get(MapKey.MODIFIED.getName()).toString()));
|
|
||||||
}
|
|
||||||
if (fields.get(MapKey.FINALIZEDAT.getName()) != null) {
|
|
||||||
this.finalizedAt = Date.from(Instant.parse(fields.get(MapKey.FINALIZEDAT.getName()).toString()));
|
|
||||||
}
|
|
||||||
if (fields.get(MapKey.PUBLISHEDAT.getName()) != null) {
|
|
||||||
this.publishedAt = Date.from(Instant.parse(fields.get(MapKey.PUBLISHEDAT.getName()).toString()));
|
|
||||||
}
|
|
||||||
if (fields.get(MapKey.DOIS.getName()) != null) {
|
|
||||||
this.dois = ((List<HashMap<String, Object>>) fields.get(MapKey.DOIS.getName())).stream().map(map -> new Doi().fromElasticEntity(map)).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum MapKey {
|
|
||||||
ID ("id"),
|
|
||||||
LABEL ("label"),
|
|
||||||
DESCRIPTION ("description"),
|
|
||||||
GROUPID ("groupId"),
|
|
||||||
STATUS ("status"),
|
|
||||||
TEMPLATES ("templates"),
|
|
||||||
COLLABORATORS ("collaborators"),
|
|
||||||
ORGANIZATIONS ("organizations"),
|
|
||||||
LASTVERSION ("lastVersion"),
|
|
||||||
LASTPUBLICVERSION ("lastPublicVersion"),
|
|
||||||
ISPUBLIC ("isPublic"),
|
|
||||||
DATASETS ("datasets"),
|
|
||||||
GRANT ("grant"),
|
|
||||||
GRANTSTATUS ("grantStatus"),
|
|
||||||
CREATED ("created"),
|
|
||||||
MODIFIED ("modified"),
|
|
||||||
FINALIZEDAT ("finalizedAt"),
|
|
||||||
PUBLISHEDAT ("publishedAt"),
|
|
||||||
DOIS ("dois");
|
|
||||||
|
|
||||||
private final String name;
|
|
||||||
|
|
||||||
private MapKey(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,65 +0,0 @@
|
||||||
package eu.eudat.elastic.entities;
|
|
||||||
|
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class Doi implements ElasticEntity<Doi>{
|
|
||||||
private UUID id;
|
|
||||||
private String repositoryId;
|
|
||||||
private String doi;
|
|
||||||
private UUID dmp;
|
|
||||||
|
|
||||||
public UUID getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
public void setId(UUID id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRepositoryId() {
|
|
||||||
return repositoryId;
|
|
||||||
}
|
|
||||||
public void setRepositoryId(String repositoryId) {
|
|
||||||
this.repositoryId = repositoryId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDoi() {
|
|
||||||
return doi;
|
|
||||||
}
|
|
||||||
public void setDoi(String doi) {
|
|
||||||
this.doi = doi;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getDmp() {
|
|
||||||
return dmp;
|
|
||||||
}
|
|
||||||
public void setDmp(UUID dmp) {
|
|
||||||
this.dmp = dmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public XContentBuilder toElasticEntity(XContentBuilder builder) throws IOException {
|
|
||||||
builder.startObject();
|
|
||||||
builder.field("id", this.id.toString());
|
|
||||||
builder.field("repositoryId", this.repositoryId);
|
|
||||||
builder.field("doi", this.doi);
|
|
||||||
builder.field("dmp", this.dmp.toString());
|
|
||||||
builder.endObject();
|
|
||||||
return builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Doi fromElasticEntity(Map<String, Object> fields) {
|
|
||||||
if (fields == null || fields.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
this.id = UUID.fromString((String) fields.get("id"));
|
|
||||||
this.repositoryId = (String) fields.get("repositoryId");
|
|
||||||
this.doi = (String) fields.get("doi");
|
|
||||||
this.dmp = UUID.fromString((String) fields.get("dmp"));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
package eu.eudat.elastic.entities;
|
|
||||||
|
|
||||||
import org.elasticsearch.common.document.DocumentField;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by ikalyvas on 7/5/2018.
|
|
||||||
*/
|
|
||||||
public interface ElasticEntity<T> {
|
|
||||||
XContentBuilder toElasticEntity(XContentBuilder builder) throws IOException;
|
|
||||||
T fromElasticEntity(Map<String, Object> fields);
|
|
||||||
}
|
|
|
@ -1,43 +0,0 @@
|
||||||
package eu.eudat.elastic.entities;
|
|
||||||
|
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class Organization implements ElasticEntity<Organization> {
|
|
||||||
private String id;
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(String id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public XContentBuilder toElasticEntity(XContentBuilder builder) throws IOException {
|
|
||||||
builder.startObject();
|
|
||||||
builder.field("id", this.id);
|
|
||||||
builder.field("name", this.name);
|
|
||||||
builder.endObject();
|
|
||||||
return builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Organization fromElasticEntity(Map fields) {
|
|
||||||
this.id = (String) fields.get("id");
|
|
||||||
this.name = (String) fields.get("name");
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,55 +0,0 @@
|
||||||
package eu.eudat.elastic.entities;
|
|
||||||
|
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by ikalyvas on 7/5/2018.
|
|
||||||
*/
|
|
||||||
public class Tag implements ElasticEntity {
|
|
||||||
|
|
||||||
private String id;
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
public Tag() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Tag(String id, String name) {
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(String id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public XContentBuilder toElasticEntity(XContentBuilder builder) throws IOException {
|
|
||||||
builder.startObject();
|
|
||||||
builder.field("id", this.id);
|
|
||||||
builder.field("name", this.name);
|
|
||||||
builder.endObject();
|
|
||||||
return builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Tag fromElasticEntity(Map fields) {
|
|
||||||
this.id = (String) fields.get("id");
|
|
||||||
this.name = (String) fields.get("name");
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,345 +0,0 @@
|
||||||
package eu.eudat.elastic.repository;
|
|
||||||
|
|
||||||
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
||||||
import eu.eudat.elastic.criteria.DatasetCriteria;
|
|
||||||
import eu.eudat.elastic.entities.Dataset;
|
|
||||||
import eu.eudat.elastic.entities.Dmp;
|
|
||||||
import eu.eudat.elastic.entities.Tag;
|
|
||||||
import org.apache.lucene.search.join.ScoreMode;
|
|
||||||
import org.elasticsearch.action.index.IndexRequest;
|
|
||||||
import org.elasticsearch.action.search.SearchRequest;
|
|
||||||
import org.elasticsearch.action.search.SearchResponse;
|
|
||||||
import org.elasticsearch.client.RequestOptions;
|
|
||||||
import org.elasticsearch.client.RestHighLevelClient;
|
|
||||||
import org.elasticsearch.client.indices.GetIndexRequest;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
|
||||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
|
||||||
import org.elasticsearch.index.query.InnerHitBuilder;
|
|
||||||
import org.elasticsearch.index.query.NestedQueryBuilder;
|
|
||||||
import org.elasticsearch.index.query.QueryBuilders;
|
|
||||||
import org.elasticsearch.search.SearchHits;
|
|
||||||
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
|
||||||
import org.elasticsearch.search.aggregations.bucket.filter.FiltersAggregationBuilder;
|
|
||||||
import org.elasticsearch.search.aggregations.bucket.filter.ParsedFilters;
|
|
||||||
import org.elasticsearch.search.aggregations.bucket.nested.NestedAggregationBuilder;
|
|
||||||
import org.elasticsearch.search.aggregations.bucket.nested.ParsedNested;
|
|
||||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
|
||||||
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
|
|
||||||
import org.elasticsearch.search.sort.SortBuilder;
|
|
||||||
import org.elasticsearch.search.sort.SortBuilders;
|
|
||||||
import org.elasticsearch.search.sort.SortOrder;
|
|
||||||
import org.springframework.core.env.Environment;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
@Service("datasetRepository")
|
|
||||||
public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteria> {
|
|
||||||
|
|
||||||
private final DmpRepository dmpRepository;
|
|
||||||
private final Environment environment;
|
|
||||||
|
|
||||||
public DatasetRepository(ElasticsearchClient client, DmpRepository dmpRepository, Environment environment) {
|
|
||||||
super(client, environment);
|
|
||||||
this.dmpRepository = dmpRepository;
|
|
||||||
this.environment = environment;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Dataset createOrUpdate(Dataset entity) throws IOException {
|
|
||||||
// if (this.getClient() != null) {
|
|
||||||
// XContentBuilder builder = XContentFactory.jsonBuilder();
|
|
||||||
// Dmp dmp = this.dmpRepository.findDocument(entity.getDmp().toString());
|
|
||||||
// if (dmp != null) {
|
|
||||||
// boolean found = false;
|
|
||||||
// if (dmp.getDatasets() != null && !dmp.getDatasets().isEmpty()) {
|
|
||||||
// for (int i = 0; i < dmp.getDatasets().size(); i++) {
|
|
||||||
// if (dmp.getDatasets().get(i).getId().equals(entity.getId())) {
|
|
||||||
// dmp.getDatasets().set(i, entity);
|
|
||||||
// found = true;
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// if (!found) {
|
|
||||||
// if (dmp.getDatasets() == null) {
|
|
||||||
// dmp.setDatasets(new ArrayList<>());
|
|
||||||
// }
|
|
||||||
// dmp.getDatasets().add(entity);
|
|
||||||
// }
|
|
||||||
// IndexRequest request = new IndexRequest(this.environment.getProperty("elasticsearch.index")).id(dmp.getId().toString()).source(dmp.toElasticEntity(builder));//new IndexRequest("datasets", "doc", entity.getId()).source(entity.toElasticEntity(builder));
|
|
||||||
// this.getClient().index(request, RequestOptions.DEFAULT).index();
|
|
||||||
// }
|
|
||||||
// return entity;
|
|
||||||
// }
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Dataset findDocument(String id) throws IOException {
|
|
||||||
// if (this.getClient() != null) {
|
|
||||||
// SearchRequest searchRequest = new SearchRequest(this.environment.getProperty("elasticsearch.index"));
|
|
||||||
// SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
|
||||||
// BoolQueryBuilder boolQuery = QueryBuilders.boolQuery().should(QueryBuilders.termQuery("datasets.id.keyword", id));
|
|
||||||
// NestedQueryBuilder nestedQueryBuilder = QueryBuilders.nestedQuery( "datasets", boolQuery, ScoreMode.Avg).innerHit(new InnerHitBuilder());
|
|
||||||
// searchSourceBuilder.query(nestedQueryBuilder);
|
|
||||||
// searchRequest.source(searchSourceBuilder);
|
|
||||||
// SearchResponse response = this.getClient().search(searchRequest, RequestOptions.DEFAULT);
|
|
||||||
// return ((Stream<Dataset>)Arrays.stream(response.getHits().getHits())
|
|
||||||
// .map(hit -> hit.getInnerHits().values()).flatMap(Collection::stream)
|
|
||||||
// .map(SearchHits::getHits).flatMap(Arrays::stream)
|
|
||||||
// .map(x -> new Dataset().fromElasticEntity(this.transformFromString(x.getSourceAsString(), Map.class)))).findFirst().orElse(null);
|
|
||||||
//// GetRequest request = new GetRequest("datasets", id);
|
|
||||||
//// GetResponse response = this.getClient().get(request, RequestOptions.DEFAULT);
|
|
||||||
//// return new Dataset().fromElasticEntity(response.getSourceAsMap());
|
|
||||||
// }
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Dataset> query(DatasetCriteria criteria) throws IOException {
|
|
||||||
// if (this.getClient() != null) {
|
|
||||||
// SearchRequest searchRequest = new SearchRequest(this.environment.getProperty("elasticsearch.index"));
|
|
||||||
// SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
|
||||||
//
|
|
||||||
// /*CountRequest countRequest = new CountRequest("dmps").routing("datasets").routing("id");
|
|
||||||
// countRequest.query(QueryBuilders.boolQuery().mustNot(QueryBuilders.termsQuery("datasets.status.keyword", Stream.of(Dataset.Status.DELETED.getValue(), Dataset.Status.CANCELED.getValue()).collect(Collectors.toList()))));
|
|
||||||
// CountResponse countResponse = getClient().count(countRequest, RequestOptions.DEFAULT);
|
|
||||||
// Long count = countResponse.getCount();*/
|
|
||||||
//
|
|
||||||
// SearchRequest countRequest = new SearchRequest(this.environment.getProperty("elasticsearch.index"));
|
|
||||||
// NestedAggregationBuilder nestedAggregationBuilder = AggregationBuilders.nested("by_dataset", "datasets");
|
|
||||||
// FiltersAggregationBuilder filtersAggregationBuilder = AggregationBuilders.filters("dataset_query", QueryBuilders.boolQuery().mustNot(QueryBuilders.termsQuery("datasets.status.keyword", Stream.of(Dataset.Status.DELETED.getValue(), Dataset.Status.CANCELED.getValue()).collect(Collectors.toList()))));
|
|
||||||
// nestedAggregationBuilder.subAggregation(filtersAggregationBuilder);
|
|
||||||
// SearchSourceBuilder countSourceBuilder = new SearchSourceBuilder();
|
|
||||||
// countSourceBuilder.aggregation(nestedAggregationBuilder);
|
|
||||||
// countRequest.source(countSourceBuilder);
|
|
||||||
// SearchResponse countResponse = getClient().search(countRequest, RequestOptions.DEFAULT);
|
|
||||||
// Long count = ((ParsedFilters)((ParsedNested)countResponse.getAggregations().asMap().get("by_dataset")).getAggregations().get("dataset_query")).getBuckets().get(0).getDocCount();
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// searchSourceBuilder.size(count.intValue());
|
|
||||||
//
|
|
||||||
// List<SortBuilder> sortBuilders = new ArrayList<>();
|
|
||||||
// BoolQueryBuilder boolQuery = createBoolQuery(criteria);
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// if (criteria.getSortCriteria() != null && !criteria.getSortCriteria().isEmpty()) {
|
|
||||||
// criteria.getSortCriteria().forEach(sortCriteria -> {
|
|
||||||
// switch(sortCriteria.getColumnType()) {
|
|
||||||
// case COLUMN:
|
|
||||||
// sortBuilders.add(SortBuilders.fieldSort("datasets." + sortCriteria.getFieldName()).order(SortOrder.fromString(sortCriteria.getOrderByType().name())));
|
|
||||||
// break;
|
|
||||||
// case JOIN_COLUMN:
|
|
||||||
// List<String> fields = Arrays.asList(sortCriteria.getFieldName().split(":"));
|
|
||||||
// fields.stream().filter(name -> !name.startsWith("dmp")).forEach(field -> {
|
|
||||||
// sortBuilders.add(SortBuilders.fieldSort(field).order(SortOrder.fromString(sortCriteria.getOrderByType().name())));
|
|
||||||
// });
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// NestedQueryBuilder nestedQueryBuilder = QueryBuilders.nestedQuery("datasets", boolQuery, ScoreMode.Avg).innerHit(new InnerHitBuilder().setFetchSourceContext(new FetchSourceContext(true, new String[]{"datasets.tags"}, null)).setSize(this.environment.getProperty("elasticsearch.innerHitsSize", Integer.class)));
|
|
||||||
// searchSourceBuilder.query(nestedQueryBuilder)/*.from(criteria.getOffset())*/.fetchSource("datasets.tags", null);
|
|
||||||
// /*if (criteria.getSize() > 0) {
|
|
||||||
// searchSourceBuilder.size(criteria.getSize());
|
|
||||||
// }*/
|
|
||||||
// sortBuilders.forEach(searchSourceBuilder::sort);
|
|
||||||
// searchRequest.source(searchSourceBuilder);
|
|
||||||
// SearchResponse response = this.getClient().search(searchRequest, RequestOptions.DEFAULT);
|
|
||||||
// return ((Stream<Dataset>)Arrays.stream(response.getHits().getHits())
|
|
||||||
// .map(hit -> hit.getInnerHits().values()).flatMap(Collection::stream)
|
|
||||||
// .map(SearchHits::getHits).flatMap(Arrays::stream)
|
|
||||||
// .map(x -> new Dataset().fromElasticEntity(this.transformFromString(x.getSourceAsString(), Map.class)))).collect(Collectors.toList());
|
|
||||||
// }
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Dataset> queryIds(DatasetCriteria criteria) throws IOException {
|
|
||||||
// if (this.getClient() != null) {
|
|
||||||
// SearchRequest searchRequest = new SearchRequest(this.environment.getProperty("elasticsearch.index"));
|
|
||||||
// SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
|
||||||
//
|
|
||||||
// /*CountRequest countRequest = new CountRequest("dmps").routing("datasets").routing("id");
|
|
||||||
// countRequest.query(QueryBuilders.boolQuery().mustNot(QueryBuilders.termsQuery("datasets.status.keyword", Stream.of(Dataset.Status.DELETED.getValue(), Dataset.Status.CANCELED.getValue()).collect(Collectors.toList()))));
|
|
||||||
// CountResponse countResponse = getClient().count(countRequest, RequestOptions.DEFAULT);
|
|
||||||
// Long count = countResponse.getCount();*/
|
|
||||||
//
|
|
||||||
// SearchRequest countRequest = new SearchRequest(this.environment.getProperty("elasticsearch.index"));
|
|
||||||
// NestedAggregationBuilder nestedAggregationBuilder = AggregationBuilders.nested("by_dataset", "datasets");
|
|
||||||
// FiltersAggregationBuilder filtersAggregationBuilder = AggregationBuilders.filters("dataset_query", QueryBuilders.boolQuery().mustNot(QueryBuilders.termsQuery("datasets.status.keyword", Stream.of(Dataset.Status.DELETED.getValue(), Dataset.Status.CANCELED.getValue()).collect(Collectors.toList()))));
|
|
||||||
// nestedAggregationBuilder.subAggregation(filtersAggregationBuilder);
|
|
||||||
// SearchSourceBuilder countSourceBuilder = new SearchSourceBuilder();
|
|
||||||
// countSourceBuilder.aggregation(nestedAggregationBuilder);
|
|
||||||
// countRequest.source(countSourceBuilder);
|
|
||||||
// SearchResponse countResponse = getClient().search(countRequest, RequestOptions.DEFAULT);
|
|
||||||
// Long count = ((ParsedFilters)((ParsedNested)countResponse.getAggregations().asMap().get("by_dataset")).getAggregations().get("dataset_query")).getBuckets().get(0).getDocCount();
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// searchSourceBuilder.size(count.intValue());
|
|
||||||
//
|
|
||||||
// List<SortBuilder> sortBuilders = new ArrayList<>();
|
|
||||||
// BoolQueryBuilder boolQuery = createBoolQuery(criteria);
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// if (criteria.getSortCriteria() != null && !criteria.getSortCriteria().isEmpty()) {
|
|
||||||
// criteria.getSortCriteria().forEach(sortCriteria -> {
|
|
||||||
// switch(sortCriteria.getColumnType()) {
|
|
||||||
// case COLUMN:
|
|
||||||
// sortBuilders.add(SortBuilders.fieldSort("datasets." + sortCriteria.getFieldName()).order(SortOrder.fromString(sortCriteria.getOrderByType().name())));
|
|
||||||
// break;
|
|
||||||
// case JOIN_COLUMN:
|
|
||||||
// List<String> fields = Arrays.asList(sortCriteria.getFieldName().split(":"));
|
|
||||||
// fields.stream().filter(name -> !name.startsWith("dmp")).forEach(field -> {
|
|
||||||
// sortBuilders.add(SortBuilders.fieldSort(field).order(SortOrder.fromString(sortCriteria.getOrderByType().name())));
|
|
||||||
// });
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// NestedQueryBuilder nestedQueryBuilder = QueryBuilders.nestedQuery("datasets", boolQuery, ScoreMode.None).innerHit(new InnerHitBuilder().setFetchSourceContext(new FetchSourceContext(true, new String[]{"datasets.id"}, null)).setSize(this.environment.getProperty("elasticsearch.innerHitsSize", Integer.class)));
|
|
||||||
// searchSourceBuilder.query(nestedQueryBuilder)/*.from(criteria.getOffset()).size(criteria.getSize())*/.fetchSource("datasets.id", null);
|
|
||||||
// sortBuilders.forEach(searchSourceBuilder::sort);
|
|
||||||
// searchRequest.source(searchSourceBuilder);
|
|
||||||
// SearchResponse response = this.getClient().search(searchRequest, RequestOptions.DEFAULT);
|
|
||||||
// return ((Stream<Dataset>)Arrays.stream(response.getHits().getHits())
|
|
||||||
// .map(hit -> hit.getInnerHits().values()).flatMap(Collection::stream)
|
|
||||||
// .map(SearchHits::getHits).flatMap(Arrays::stream)
|
|
||||||
// .map(x -> new Dataset().fromElasticEntity(this.transformFromString(x.getSourceAsString(), Map.class)))).collect(Collectors.toList());
|
|
||||||
// }
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Long count(DatasetCriteria criteria) throws IOException {
|
|
||||||
// if (this.getClient() != null) {
|
|
||||||
// //CountRequest countRequest = new CountRequest(this.environment.getProperty("elasticsearch.index"));
|
|
||||||
//
|
|
||||||
// SearchRequest countRequest = new SearchRequest(this.environment.getProperty("elasticsearch.index"));
|
|
||||||
// BoolQueryBuilder boolQuery = createBoolQuery(criteria);
|
|
||||||
// NestedAggregationBuilder nestedAggregationBuilder = AggregationBuilders.nested("by_dataset", "datasets");
|
|
||||||
// FiltersAggregationBuilder filtersAggregationBuilder = AggregationBuilders.filters("dataset_query", boolQuery);
|
|
||||||
// nestedAggregationBuilder.subAggregation(filtersAggregationBuilder);
|
|
||||||
// SearchSourceBuilder countSourceBuilder = new SearchSourceBuilder();
|
|
||||||
// countSourceBuilder.aggregation(nestedAggregationBuilder);
|
|
||||||
// countRequest.source(countSourceBuilder);
|
|
||||||
// SearchResponse countResponse = getClient().search(countRequest, RequestOptions.DEFAULT);
|
|
||||||
// return ((ParsedFilters)((ParsedNested)countResponse.getAggregations().asMap().get("by_dataset")).getAggregations().get("dataset_query")).getBuckets().get(0).getDocCount();
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// /*NestedQueryBuilder nestedQueryBuilder = QueryBuilders.nestedQuery("datasets", boolQuery, ScoreMode.None).innerHit(new InnerHitBuilder());
|
|
||||||
// countRequest.query(nestedQueryBuilder);
|
|
||||||
// CountResponse response = this.getClient().count(countRequest, RequestOptions.DEFAULT);
|
|
||||||
// return response.getCount();*/
|
|
||||||
// }
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private BoolQueryBuilder createBoolQuery(DatasetCriteria criteria) {
|
|
||||||
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery().mustNot(QueryBuilders.termsQuery("datasets.status", Stream.of(Dataset.Status.DELETED.getValue(), Dataset.Status.CANCELED.getValue()).collect(Collectors.toList())));
|
|
||||||
if (criteria.isPublic()) {
|
|
||||||
boolQuery = boolQuery.should(QueryBuilders.termQuery("datasets.public", "true"));
|
|
||||||
boolQuery = boolQuery.should(QueryBuilders.termQuery("datasets.status", Dataset.Status.FINALISED.getValue()));
|
|
||||||
boolQuery = boolQuery.should(QueryBuilders.termQuery("datasets.lastPublicVersion", "true"));
|
|
||||||
}
|
|
||||||
if (criteria.getLike() != null && !criteria.getLike().isEmpty()) {
|
|
||||||
boolQuery = boolQuery.should(QueryBuilders.queryStringQuery(criteria.getLike()).allowLeadingWildcard(true).fields(Stream.of(new Object[][]{
|
|
||||||
{"datasets.label", 1.0f},
|
|
||||||
{"datasets.description", 1.0f},
|
|
||||||
{"datasets.formData", 1.0f}
|
|
||||||
}).collect(Collectors.toMap(data -> (String) data[0], data -> (Float) data[1]))));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (criteria.getDatasetTemplates() != null && criteria.getDatasetTemplates().size() > 0) {
|
|
||||||
criteria.setDatasetTemplates(criteria.getDatasetTemplates().stream().filter(Objects::nonNull).collect(Collectors.toList()));
|
|
||||||
boolQuery = boolQuery.should(QueryBuilders.termsQuery("datasets.template", criteria.getDatasetTemplates().stream().map(UUID::toString).collect(Collectors.toList())));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (criteria.getStatus() != null) {
|
|
||||||
boolQuery = boolQuery.should(QueryBuilders.termQuery("datasets.status", criteria.getStatus().toString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (criteria.getDmps() != null && criteria.getDmps().size() > 0) {
|
|
||||||
criteria.setDmps(criteria.getDmps().stream().filter(Objects::nonNull).collect(Collectors.toList()));
|
|
||||||
boolQuery = boolQuery.should(QueryBuilders.termsQuery("datasets.dmp", criteria.getDmps().stream().map(UUID::toString).collect(Collectors.toList())));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (criteria.getGroupIds() != null && criteria.getGroupIds().size() > 0) {
|
|
||||||
criteria.setGroupIds(criteria.getGroupIds().stream().filter(Objects::nonNull).collect(Collectors.toList()));
|
|
||||||
boolQuery = boolQuery.should(QueryBuilders.termsQuery("datasets.group", criteria.getGroupIds().stream().map(UUID::toString).collect(Collectors.toList())));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (criteria.getGrants() != null && criteria.getGrants().size() > 0) {
|
|
||||||
criteria.setGrants(criteria.getGrants().stream().filter(Objects::nonNull).collect(Collectors.toList()));
|
|
||||||
boolQuery = boolQuery.should(QueryBuilders.termsQuery("datasets.grant", criteria.getGrants().stream().map(UUID::toString).collect(Collectors.toList())));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (criteria.getGrantStatus() != null) {
|
|
||||||
boolQuery = boolQuery.should(QueryBuilders.termQuery("datasets.grantStatus", criteria.getGrantStatus().toString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (criteria.getCollaborators() != null && criteria.getCollaborators().size() > 0) {
|
|
||||||
criteria.setCollaborators(criteria.getCollaborators().stream().filter(Objects::nonNull).collect(Collectors.toList()));
|
|
||||||
boolQuery = boolQuery.should(QueryBuilders.termsQuery("datasets.collaborators.id.keyword", criteria.getCollaborators().stream().map(UUID::toString).collect(Collectors.toList())));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!criteria.isPublic()) {
|
|
||||||
if (criteria.getAllowAllVersions() != null && !criteria.getAllowAllVersions()) {
|
|
||||||
boolQuery = boolQuery.should(QueryBuilders.termQuery("datasets.lastVersion", "true"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (criteria.getOrganiztions() != null && criteria.getOrganiztions().size() > 0) {
|
|
||||||
criteria.setOrganiztions(criteria.getOrganiztions().stream().filter(Objects::nonNull).collect(Collectors.toList()));
|
|
||||||
boolQuery = boolQuery.should(QueryBuilders.termsQuery("datasets.organizations.id", criteria.getOrganiztions()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (criteria.getTags() != null && criteria.getTags().size() > 0) {
|
|
||||||
criteria.setTags(criteria.getTags().stream().filter(Objects::nonNull).collect(Collectors.toList()));
|
|
||||||
boolQuery = boolQuery.should(QueryBuilders.termsQuery("datasets.tags.name", criteria.getTags().stream().map(Tag::getName).collect(Collectors.toList())));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (criteria.getHasTags() != null) {
|
|
||||||
boolQuery = criteria.getHasTags() == true ? boolQuery.should(QueryBuilders.existsQuery("datasets.tags.id")) : boolQuery.mustNot(QueryBuilders.existsQuery("datasets.tags.id"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (boolQuery.should().isEmpty() && boolQuery.mustNot().isEmpty()) {
|
|
||||||
boolQuery.should(QueryBuilders.matchAllQuery());
|
|
||||||
} else {
|
|
||||||
boolQuery.minimumShouldMatch(boolQuery.should().size());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return boolQuery;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean exists() throws IOException {
|
|
||||||
// if (this.getClient() != null) {
|
|
||||||
// GetIndexRequest request = new GetIndexRequest(this.environment.getProperty("elasticsearch.index"));
|
|
||||||
//// request.indices("datasets");
|
|
||||||
// return this.getClient().indices().exists(request, RequestOptions.DEFAULT);
|
|
||||||
// }
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clear() throws IOException {
|
|
||||||
//DON'T
|
|
||||||
/* if (exists()) {
|
|
||||||
DeleteByQueryRequest delete = new DeleteByQueryRequest("datasets");
|
|
||||||
delete.setQuery(QueryBuilders.matchAllQuery());
|
|
||||||
this.getClient().deleteByQuery(delete, RequestOptions.DEFAULT);
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,233 +0,0 @@
|
||||||
package eu.eudat.elastic.repository;
|
|
||||||
|
|
||||||
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
||||||
import eu.eudat.elastic.criteria.DmpCriteria;
|
|
||||||
import eu.eudat.elastic.entities.Dmp;
|
|
||||||
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
|
|
||||||
import org.elasticsearch.action.get.GetRequest;
|
|
||||||
import org.elasticsearch.action.get.GetResponse;
|
|
||||||
import org.elasticsearch.action.index.IndexRequest;
|
|
||||||
import org.elasticsearch.action.index.IndexResponse;
|
|
||||||
import org.elasticsearch.action.search.SearchRequest;
|
|
||||||
import org.elasticsearch.action.search.SearchResponse;
|
|
||||||
import org.elasticsearch.client.RequestOptions;
|
|
||||||
import org.elasticsearch.client.RestHighLevelClient;
|
|
||||||
import org.elasticsearch.client.core.CountRequest;
|
|
||||||
import org.elasticsearch.client.core.CountResponse;
|
|
||||||
import org.elasticsearch.client.indices.CreateIndexRequest;
|
|
||||||
import org.elasticsearch.client.indices.GetIndexRequest;
|
|
||||||
import org.elasticsearch.client.indices.PutMappingRequest;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
|
||||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
|
||||||
import org.elasticsearch.index.query.QueryBuilders;
|
|
||||||
import org.elasticsearch.index.reindex.DeleteByQueryRequest;
|
|
||||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
|
||||||
import org.elasticsearch.search.sort.SortBuilder;
|
|
||||||
import org.elasticsearch.search.sort.SortBuilders;
|
|
||||||
import org.elasticsearch.search.sort.SortOrder;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.core.env.Environment;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
@Service("dmpRepository")
|
|
||||||
public class DmpRepository extends ElasticRepository<Dmp, DmpCriteria> {
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(DmpRepository.class);
|
|
||||||
|
|
||||||
private final Environment environment;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public DmpRepository(ElasticsearchClient client, Environment environment) {
|
|
||||||
super(client, environment);
|
|
||||||
this.environment = environment;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void generateMapping() throws IOException {
|
|
||||||
// if (this.getClient() != null) {
|
|
||||||
// XContentBuilder builder = XContentFactory.jsonBuilder();
|
|
||||||
// builder.startObject();
|
|
||||||
// builder.startObject("properties");
|
|
||||||
// builder.startObject("datasets");
|
|
||||||
// builder.field("type", "nested");
|
|
||||||
// builder.endObject();
|
|
||||||
// builder.endObject();
|
|
||||||
// builder.endObject();
|
|
||||||
// PutMappingRequest putMappingRequest = new PutMappingRequest(this.environment.getProperty("elasticsearch.index"));
|
|
||||||
// putMappingRequest.source(builder);
|
|
||||||
// this.getClient().indices().putMapping(putMappingRequest, RequestOptions.DEFAULT);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Dmp createOrUpdate(Dmp entity) throws IOException {
|
|
||||||
// if (this.getClient() != null) {
|
|
||||||
// XContentBuilder builder = XContentFactory.jsonBuilder();
|
|
||||||
// IndexRequest request = new IndexRequest(this.environment.getProperty("elasticsearch.index")).id(entity.getId().toString()).source(entity.toElasticEntity(builder));
|
|
||||||
// IndexResponse response = this.getClient().index(request, RequestOptions.DEFAULT);
|
|
||||||
// return entity;
|
|
||||||
// }
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Dmp findDocument(String id) throws IOException {
|
|
||||||
// if (this.getClient() != null) {
|
|
||||||
// GetRequest request = new GetRequest(this.environment.getProperty("elasticsearch.index"), id);
|
|
||||||
// GetResponse response = this.getClient().get(request, RequestOptions.DEFAULT);
|
|
||||||
// return new Dmp().fromElasticEntity(response.getSourceAsMap());
|
|
||||||
// }
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Dmp> query(DmpCriteria criteria) throws IOException {
|
|
||||||
// if (this.getClient() != null) {
|
|
||||||
// SearchRequest searchRequest = new SearchRequest(this.environment.getProperty("elasticsearch.index"));
|
|
||||||
// SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
|
||||||
//
|
|
||||||
// CountRequest countRequest = new CountRequest(this.environment.getProperty("elasticsearch.index"));
|
|
||||||
// countRequest.query(QueryBuilders.boolQuery().mustNot(QueryBuilders.termsQuery(Dmp.MapKey.STATUS.getName(), Collections.singletonList(Dmp.DMPStatus.DELETED.getValue()))));
|
|
||||||
// CountResponse countResponse = getClient().count(countRequest, RequestOptions.DEFAULT);
|
|
||||||
// Long count = countResponse.getCount();
|
|
||||||
//
|
|
||||||
// searchSourceBuilder.size(count.intValue());
|
|
||||||
//
|
|
||||||
// List<SortBuilder> sortBuilders = new ArrayList<>();
|
|
||||||
// BoolQueryBuilder boolQuery = createBoolQuery(criteria);
|
|
||||||
//
|
|
||||||
// if (criteria.getSortCriteria() != null && !criteria.getSortCriteria().isEmpty()) {
|
|
||||||
// criteria.getSortCriteria().forEach(sortCriteria -> {
|
|
||||||
// switch(sortCriteria.getColumnType()) {
|
|
||||||
// case COLUMN:
|
|
||||||
// sortBuilders.add(SortBuilders.fieldSort(sortCriteria.getFieldName()).order(SortOrder.fromString(sortCriteria.getOrderByType().name())));
|
|
||||||
// break;
|
|
||||||
// case JOIN_COLUMN:
|
|
||||||
// List<String> fields = Arrays.asList(sortCriteria.getFieldName().split(":"));
|
|
||||||
// fields.forEach(field -> {
|
|
||||||
// sortBuilders.add(SortBuilders.fieldSort(sortCriteria.getFieldName()).order(SortOrder.fromString(sortCriteria.getOrderByType().name())));
|
|
||||||
// });
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// searchSourceBuilder.query(boolQuery).from(criteria.getOffset()).fetchSource("id", null);
|
|
||||||
// if (criteria.getSize() != null && criteria.getSize() > 0) {
|
|
||||||
// searchSourceBuilder.size(criteria.getSize());
|
|
||||||
// }
|
|
||||||
// sortBuilders.forEach(searchSourceBuilder::sort);
|
|
||||||
// searchRequest.source(searchSourceBuilder);
|
|
||||||
// SearchResponse response = this.getClient().search(searchRequest, RequestOptions.DEFAULT);
|
|
||||||
// return Arrays.stream(response.getHits().getHits()).map(x -> new Dmp().fromElasticEntity((Map<String, Object>) this.transformFromString(x.getSourceAsString(), Map.class))).collect(Collectors.toList());
|
|
||||||
// }
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Long count(DmpCriteria criteria) throws IOException {
|
|
||||||
// if (this.getClient() != null) {
|
|
||||||
// CountRequest countRequest = new CountRequest(this.environment.getProperty("elasticsearch.index"));
|
|
||||||
//
|
|
||||||
// BoolQueryBuilder boolQuery = createBoolQuery(criteria);
|
|
||||||
//
|
|
||||||
// countRequest.query(boolQuery);
|
|
||||||
// CountResponse response = this.getClient().count(countRequest, RequestOptions.DEFAULT);
|
|
||||||
// return response.getCount();
|
|
||||||
// }
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private BoolQueryBuilder createBoolQuery(DmpCriteria criteria) {
|
|
||||||
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery().mustNot(QueryBuilders.termsQuery(Dmp.MapKey.STATUS.getName(), Collections.singletonList(Dmp.DMPStatus.DELETED.getValue())));
|
|
||||||
if (criteria.isPublic()) {
|
|
||||||
boolQuery = boolQuery.should(QueryBuilders.termQuery(Dmp.MapKey.ISPUBLIC.getName(), true));
|
|
||||||
boolQuery = boolQuery.should(QueryBuilders.termQuery(Dmp.MapKey.STATUS.getName(), Dmp.DMPStatus.FINALISED.getValue()));
|
|
||||||
}
|
|
||||||
if (criteria.getLike() != null && !criteria.getLike().isEmpty()) {
|
|
||||||
boolQuery = boolQuery.should(QueryBuilders.queryStringQuery(criteria.getLike()).fields(Stream.of(new Object[][]{
|
|
||||||
{Dmp.MapKey.LABEL.getName(), 1.0f},
|
|
||||||
{Dmp.MapKey.DESCRIPTION.getName(), 1.0f}
|
|
||||||
}).collect(Collectors.toMap(data -> (String) data[0], data -> (Float) data[1]))));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (criteria.getTemplates() != null && criteria.getTemplates().size() > 0) {
|
|
||||||
boolQuery = boolQuery.should(QueryBuilders.termsQuery(Dmp.MapKey.TEMPLATES.getName() + ".id.keyword", criteria.getTemplates().stream().map(UUID::toString).collect(Collectors.toList())));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (criteria.getStatus() != null) {
|
|
||||||
boolQuery = boolQuery.should(QueryBuilders.termQuery(Dmp.MapKey.STATUS.getName(), criteria.getStatus().intValue()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (criteria.getGroupIds() != null && criteria.getGroupIds().size() > 0) {
|
|
||||||
boolQuery = boolQuery.should(QueryBuilders.termsQuery(Dmp.MapKey.GROUPID.getName(), criteria.getGroupIds().stream().map(UUID::toString).collect(Collectors.toList())));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (criteria.getGrants() != null && criteria.getGrants().size() > 0) {
|
|
||||||
boolQuery = boolQuery.should(QueryBuilders.termsQuery(Dmp.MapKey.GRANT.getName() + ".keyword", criteria.getGrants().stream().map(UUID::toString).collect(Collectors.toList())));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (criteria.getCollaborators() != null && criteria.getCollaborators().size() > 0) {
|
|
||||||
boolQuery = boolQuery.should(QueryBuilders.termsQuery(Dmp.MapKey.COLLABORATORS.getName() + ".id.keyword", criteria.getCollaborators().stream().filter(Objects::nonNull).map(UUID::toString).collect(Collectors.toList())));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!criteria.isAllowAllVersions()) {
|
|
||||||
boolQuery = boolQuery.should(QueryBuilders.termQuery(criteria.isPublic() ? Dmp.MapKey.LASTPUBLICVERSION.getName() : Dmp.MapKey.LASTVERSION.getName(), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (criteria.getOrganizations() != null && criteria.getOrganizations().size() > 0) {
|
|
||||||
boolQuery = boolQuery.should(QueryBuilders.termsQuery(Dmp.MapKey.ORGANIZATIONS.getName() + ".id.keyword", criteria.getOrganizations().stream().map(UUID::toString).collect(Collectors.toList())));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (criteria.getGrantStatus() != null) {
|
|
||||||
boolQuery = boolQuery.should(QueryBuilders.termQuery(Dmp.MapKey.GRANTSTATUS.getName(), criteria.getGrantStatus()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (boolQuery.should().isEmpty() && boolQuery.mustNot().isEmpty()) {
|
|
||||||
boolQuery = boolQuery.should(QueryBuilders.matchAllQuery());
|
|
||||||
} else {
|
|
||||||
boolQuery.minimumShouldMatch(boolQuery.should().size());
|
|
||||||
}
|
|
||||||
return boolQuery;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean createIndex() {
|
|
||||||
try {
|
|
||||||
// if (!this.exists()) {
|
|
||||||
// CreateIndexRequest createIndexRequest = new CreateIndexRequest(this.environment.getProperty("elasticsearch.index"));
|
|
||||||
// this.getClient().indices().create(createIndexRequest, RequestOptions.DEFAULT);
|
|
||||||
// this.generateMapping();
|
|
||||||
// }
|
|
||||||
return true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error(e.getMessage(), e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean exists() throws IOException {
|
|
||||||
// if (this.getClient() != null) {
|
|
||||||
// GetIndexRequest request = new GetIndexRequest(this.environment.getProperty("elasticsearch.index"));
|
|
||||||
// return this.getClient().indices().exists(request, RequestOptions.DEFAULT);
|
|
||||||
// }
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clear() throws IOException {
|
|
||||||
// if (exists()) {
|
|
||||||
// DeleteByQueryRequest delete = new DeleteByQueryRequest(this.environment.getProperty("elasticsearch.index"));
|
|
||||||
// delete.setQuery(QueryBuilders.matchAllQuery());
|
|
||||||
// this.getClient().deleteByQuery(delete, RequestOptions.DEFAULT);
|
|
||||||
// DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(this.environment.getProperty("elasticsearch.index"));
|
|
||||||
// this.getClient().indices().delete(deleteIndexRequest, RequestOptions.DEFAULT);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,52 +0,0 @@
|
||||||
package eu.eudat.elastic.repository;
|
|
||||||
|
|
||||||
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import eu.eudat.elastic.criteria.Criteria;
|
|
||||||
import eu.eudat.elastic.entities.ElasticEntity;
|
|
||||||
import org.elasticsearch.client.RequestOptions;
|
|
||||||
import org.elasticsearch.client.RestHighLevelClient;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.core.env.Environment;
|
|
||||||
|
|
||||||
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 ElasticsearchClient client;
|
|
||||||
|
|
||||||
public ElasticsearchClient getClient() {
|
|
||||||
return client;
|
|
||||||
}
|
|
||||||
public ElasticRepository(ElasticsearchClient client, Environment environment) {
|
|
||||||
try {
|
|
||||||
if (!Boolean.TRUE.equals(environment.getProperty("elastic.enabled", boolean.class))){
|
|
||||||
logger.warn("Unable to connect to Elastic Services");
|
|
||||||
this.client = null;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (client.ping().value()) {
|
|
||||||
this.client = client;
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.warn("Unable to connect to Elastic Services");
|
|
||||||
logger.error(e.getMessage(), e);
|
|
||||||
this.client = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> T transformFromString(String value, Class<T> tClass) {
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
|
||||||
T item = null;
|
|
||||||
try {
|
|
||||||
item = mapper.readValue(value, tClass);
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.error(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
package eu.eudat.elastic.repository;
|
|
||||||
|
|
||||||
import eu.eudat.elastic.criteria.Criteria;
|
|
||||||
import eu.eudat.elastic.entities.ElasticEntity;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by ikalyvas on 7/5/2018.
|
|
||||||
*/
|
|
||||||
public interface Repository<ET extends ElasticEntity, C extends Criteria> {
|
|
||||||
|
|
||||||
ET createOrUpdate(ET entity) throws IOException;
|
|
||||||
|
|
||||||
ET findDocument(String id) throws IOException;
|
|
||||||
|
|
||||||
List<ET> query(C criteria) throws ExecutionException, InterruptedException, IOException;
|
|
||||||
|
|
||||||
Long count(C criteria) throws ExecutionException, InterruptedException, IOException;
|
|
||||||
|
|
||||||
boolean exists() throws IOException;
|
|
||||||
|
|
||||||
void clear() throws IOException;
|
|
||||||
}
|
|
|
@ -17,7 +17,6 @@
|
||||||
<module>queryable</module>
|
<module>queryable</module>
|
||||||
<module>web</module>
|
<module>web</module>
|
||||||
<module>data</module>
|
<module>data</module>
|
||||||
<module>elastic</module>
|
|
||||||
<module>core</module>
|
<module>core</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
|
|
|
@ -31,11 +31,6 @@
|
||||||
<artifactId>queryable</artifactId>
|
<artifactId>queryable</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>eu.eudat</groupId>
|
|
||||||
<artifactId>elastic</artifactId>
|
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>gr.cite.opendmp</groupId>
|
<groupId>gr.cite.opendmp</groupId>
|
||||||
<artifactId>repositorydepositbase</artifactId>
|
<artifactId>repositorydepositbase</artifactId>
|
||||||
|
|
|
@ -375,7 +375,7 @@ public class DMPs extends BaseController {
|
||||||
ResponseEntity<ResponseItem<DescriptionEntity>> generateIndex() throws Exception {
|
ResponseEntity<ResponseItem<DescriptionEntity>> generateIndex() throws Exception {
|
||||||
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
|
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
|
||||||
|
|
||||||
this.dataManagementPlanManager.generateIndex();
|
//this.dataManagementPlanManager.generateIndex(); //TODO
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DescriptionEntity>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Generated").payload(null));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DescriptionEntity>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Generated").payload(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -385,7 +385,7 @@ public class DMPs extends BaseController {
|
||||||
ResponseEntity<ResponseItem<DescriptionEntity>> clearIndex() throws Exception {
|
ResponseEntity<ResponseItem<DescriptionEntity>> clearIndex() throws Exception {
|
||||||
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
|
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
|
||||||
|
|
||||||
this.dataManagementPlanManager.clearIndex();
|
//this.dataManagementPlanManager.clearIndex(); //TODO
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DescriptionEntity>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Cleared").payload(null));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DescriptionEntity>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Cleared").payload(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -274,7 +274,7 @@ public class Datasets extends BaseController {
|
||||||
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
|
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
|
||||||
|
|
||||||
DatasetWizardModel dataset = new DatasetWizardModel().fromDataModel(this.datasetManager.createOrUpdate(profile));
|
DatasetWizardModel dataset = new DatasetWizardModel().fromDataModel(this.datasetManager.createOrUpdate(profile));
|
||||||
dataset.setTags(profile.getTags());
|
// dataset.setTags(profile.getTags()); //TODO
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetWizardModel>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created").payload(dataset));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetWizardModel>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created").payload(dataset));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,7 +367,7 @@ public class Datasets extends BaseController {
|
||||||
ResponseEntity<ResponseItem<DescriptionEntity>> clearIndex() throws Exception {
|
ResponseEntity<ResponseItem<DescriptionEntity>> clearIndex() throws Exception {
|
||||||
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
|
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
|
||||||
|
|
||||||
this.datasetManager.clearIndex();
|
//this.datasetManager.clearIndex(); //TODO
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DescriptionEntity>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Cleared").payload(null));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DescriptionEntity>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Cleared").payload(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,59 +1,60 @@
|
||||||
package eu.eudat.controllers;
|
//TODO
|
||||||
|
//package eu.eudat.controllers;
|
||||||
import eu.eudat.elastic.criteria.DatasetCriteria;
|
//
|
||||||
import eu.eudat.elastic.entities.Dataset;
|
//import eu.eudat.elastic.criteria.DatasetCriteria;
|
||||||
import eu.eudat.elastic.entities.Tag;
|
//import eu.eudat.elastic.entities.Dataset;
|
||||||
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
|
//import eu.eudat.elastic.entities.Tag;
|
||||||
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
|
//import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
//import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
|
||||||
import eu.eudat.logic.utilities.helpers.StreamDistinctBy;
|
//import eu.eudat.logic.services.ApiContext;
|
||||||
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
//import eu.eudat.logic.utilities.helpers.StreamDistinctBy;
|
||||||
import eu.eudat.types.ApiMessageCode;
|
//import eu.eudat.models.data.helpers.responses.ResponseItem;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
//import eu.eudat.types.ApiMessageCode;
|
||||||
import org.springframework.core.env.Environment;
|
//import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
//import org.springframework.core.env.Environment;
|
||||||
import org.springframework.http.ResponseEntity;
|
//import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.web.bind.annotation.*;
|
//import org.springframework.http.ResponseEntity;
|
||||||
|
//import org.springframework.web.bind.annotation.*;
|
||||||
import java.io.IOException;
|
//
|
||||||
import java.util.Collection;
|
//import java.io.IOException;
|
||||||
import java.util.List;
|
//import java.util.Collection;
|
||||||
import java.util.concurrent.ExecutionException;
|
//import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
//import java.util.concurrent.ExecutionException;
|
||||||
|
//import java.util.stream.Collectors;
|
||||||
/**
|
//
|
||||||
* Created by ikalyvas on 7/5/2018.
|
///**
|
||||||
*/
|
// * Created by ikalyvas on 7/5/2018.
|
||||||
@RestController
|
// */
|
||||||
@CrossOrigin
|
//@RestController
|
||||||
@RequestMapping(value = {"/api"})
|
//@CrossOrigin
|
||||||
public class TagController extends BaseController {
|
//@RequestMapping(value = {"/api"})
|
||||||
|
//public class TagController extends BaseController {
|
||||||
// private Repository<Dataset, TagCriteria> datasetRepository;
|
//
|
||||||
private Environment environment;
|
//// private Repository<Dataset, TagCriteria> datasetRepository;
|
||||||
|
// private Environment environment;
|
||||||
@Autowired
|
//
|
||||||
public TagController(ApiContext apiContext, /*Repository tagRepository, */Environment environment) {
|
// @Autowired
|
||||||
super(apiContext);
|
// public TagController(ApiContext apiContext, /*Repository tagRepository, */Environment environment) {
|
||||||
// this.datasetRepository = tagRepository;
|
// super(apiContext);
|
||||||
this.environment = environment;
|
//// this.datasetRepository = tagRepository;
|
||||||
}
|
// this.environment = environment;
|
||||||
|
// }
|
||||||
@RequestMapping(method = RequestMethod.GET, value = {"/external/tags"}, produces = "application/json")
|
//
|
||||||
public @ResponseBody
|
// @RequestMapping(method = RequestMethod.GET, value = {"/external/tags"}, produces = "application/json")
|
||||||
ResponseEntity<ResponseItem<List<Tag>>> listExternalTagModel(
|
// public @ResponseBody
|
||||||
@RequestParam(value = "query", required = false) String query, @RequestParam(value = "type", required = false) String type) throws HugeResultSet, NoURLFound, IOException, ExecutionException, InterruptedException {
|
// ResponseEntity<ResponseItem<List<Tag>>> listExternalTagModel(
|
||||||
//ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query);
|
// @RequestParam(value = "query", required = false) String query, @RequestParam(value = "type", required = false) String type) throws HugeResultSet, NoURLFound, IOException, ExecutionException, InterruptedException {
|
||||||
/*List<Map<String, String>> remoteRepos = this.getApiContext().getOperationsContext().getRemoteFetcher().getTags(externalUrlCriteria, type);
|
// //ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query);
|
||||||
TagExternalSourcesModel researchersExternalSourcesModel = new TagExternalSourcesModel().fromExternalItem(remoteRepos);*/
|
// /*List<Map<String, String>> remoteRepos = this.getApiContext().getOperationsContext().getRemoteFetcher().getTags(externalUrlCriteria, type);
|
||||||
if (this.getApiContext().getOperationsContext().getElasticRepository().getDatasetRepository().exists()) {
|
// TagExternalSourcesModel researchersExternalSourcesModel = new TagExternalSourcesModel().fromExternalItem(remoteRepos);*/
|
||||||
DatasetCriteria criteria = new DatasetCriteria();
|
// if (this.getApiContext().getOperationsContext().getElasticRepository().getDatasetRepository().exists()) {
|
||||||
criteria.setHasTags(true);
|
// DatasetCriteria criteria = new DatasetCriteria();
|
||||||
List<Tag> tags = this.getApiContext().getOperationsContext().getElasticRepository().getDatasetRepository().query(criteria).stream().map(Dataset::getTags).flatMap(Collection::stream).filter(StreamDistinctBy.distinctByKey(Tag::getId)).filter(tag -> tag.getName().toLowerCase().startsWith(query.toLowerCase())).collect(Collectors.toList());
|
// criteria.setHasTags(true);
|
||||||
|
// List<Tag> tags = this.getApiContext().getOperationsContext().getElasticRepository().getDatasetRepository().query(criteria).stream().map(Dataset::getTags).flatMap(Collection::stream).filter(StreamDistinctBy.distinctByKey(Tag::getId)).filter(tag -> tag.getName().toLowerCase().startsWith(query.toLowerCase())).collect(Collectors.toList());
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Tag>>().payload(tags).status(ApiMessageCode.NO_MESSAGE));
|
//
|
||||||
} else {
|
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Tag>>().payload(tags).status(ApiMessageCode.NO_MESSAGE));
|
||||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new ResponseItem<List<Tag>>().status(ApiMessageCode.ERROR_MESSAGE).message("Elastic Services are not available"));
|
// } else {
|
||||||
}
|
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new ResponseItem<List<Tag>>().status(ApiMessageCode.ERROR_MESSAGE).message("Elastic Services are not available"));
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//}
|
||||||
|
|
|
@ -30,6 +30,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.management.InvalidApplicationException;
|
import javax.management.InvalidApplicationException;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
|
@ -117,7 +118,7 @@ public class DescriptionController {
|
||||||
|
|
||||||
@DeleteMapping("{id}")
|
@DeleteMapping("{id}")
|
||||||
@Transactional
|
@Transactional
|
||||||
public void Delete(@PathVariable("id") UUID id) throws MyForbiddenException, InvalidApplicationException {
|
public void Delete(@PathVariable("id") UUID id) throws MyForbiddenException, InvalidApplicationException, IOException {
|
||||||
logger.debug(new MapLogEntry("retrieving" + Description.class.getSimpleName()).And("id", id));
|
logger.debug(new MapLogEntry("retrieving" + Description.class.getSimpleName()).And("id", id));
|
||||||
|
|
||||||
this.descriptionService.deleteAndSave(id);
|
this.descriptionService.deleteAndSave(id);
|
||||||
|
|
|
@ -40,6 +40,7 @@ import org.springframework.web.bind.annotation.*;
|
||||||
import javax.management.InvalidApplicationException;
|
import javax.management.InvalidApplicationException;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
import javax.xml.transform.TransformerException;
|
import javax.xml.transform.TransformerException;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
|
@ -128,7 +129,7 @@ public class DmpController {
|
||||||
|
|
||||||
@DeleteMapping("{id}")
|
@DeleteMapping("{id}")
|
||||||
@Transactional
|
@Transactional
|
||||||
public void Delete(@PathVariable("id") UUID id) throws MyForbiddenException, InvalidApplicationException {
|
public void Delete(@PathVariable("id") UUID id) throws MyForbiddenException, InvalidApplicationException, IOException {
|
||||||
logger.debug(new MapLogEntry("retrieving" + Dmp.class.getSimpleName()).And("id", id));
|
logger.debug(new MapLogEntry("retrieving" + Dmp.class.getSimpleName()).And("id", id));
|
||||||
|
|
||||||
this.dmpService.deleteAndSave(id);
|
this.dmpService.deleteAndSave(id);
|
||||||
|
|
|
@ -124,33 +124,33 @@ public class DashBoardManager {
|
||||||
UserInfo user = new UserInfo();
|
UserInfo user = new UserInfo();
|
||||||
user.setId(this.userScope.getUserId());
|
user.setId(this.userScope.getUserId());
|
||||||
DatasetCriteria datasetCriteria = new DatasetCriteria();
|
DatasetCriteria datasetCriteria = new DatasetCriteria();
|
||||||
if (apiContext.getOperationsContext().getElasticRepository().getDatasetRepository() != null) {
|
// if (apiContext.getOperationsContext().getElasticRepository().getDatasetRepository() != null) { //TODO
|
||||||
try {
|
// try {
|
||||||
eu.eudat.elastic.criteria.DatasetCriteria datasetElasticCriteria = new eu.eudat.elastic.criteria.DatasetCriteria();
|
// eu.eudat.elastic.criteria.DatasetCriteria datasetElasticCriteria = new eu.eudat.elastic.criteria.DatasetCriteria();
|
||||||
datasetElasticCriteria.setAllowAllVersions(false);
|
// datasetElasticCriteria.setAllowAllVersions(false);
|
||||||
datasetElasticCriteria.setPublic(false);
|
// datasetElasticCriteria.setPublic(false);
|
||||||
datasetElasticCriteria.setCollaborators(Collections.singletonList(this.userScope.getUserId()));
|
// datasetElasticCriteria.setCollaborators(Collections.singletonList(this.userScope.getUserId()));
|
||||||
datasets = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().count(datasetElasticCriteria);
|
// datasets = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().count(datasetElasticCriteria);
|
||||||
}catch (Exception e) {
|
// }catch (Exception e) {
|
||||||
logger.warn(e.getMessage(), e);
|
// logger.warn(e.getMessage(), e);
|
||||||
datasets = null;
|
// datasets = null;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
datasetCriteria.setAllVersions(false);
|
datasetCriteria.setAllVersions(false);
|
||||||
datasetCriteria.setIsPublic(false);
|
datasetCriteria.setIsPublic(false);
|
||||||
DataManagementPlanCriteria dataManagementPlanCriteria = new DataManagementPlanCriteria();
|
DataManagementPlanCriteria dataManagementPlanCriteria = new DataManagementPlanCriteria();
|
||||||
if (apiContext.getOperationsContext().getElasticRepository().getDmpRepository() != null) {
|
// if (apiContext.getOperationsContext().getElasticRepository().getDmpRepository() != null) { //TODO
|
||||||
try {
|
// try {
|
||||||
eu.eudat.elastic.criteria.DmpCriteria dmpElasticCriteria = new eu.eudat.elastic.criteria.DmpCriteria();
|
// eu.eudat.elastic.criteria.DmpCriteria dmpElasticCriteria = new eu.eudat.elastic.criteria.DmpCriteria();
|
||||||
dmpElasticCriteria.setAllowAllVersions(false);
|
// dmpElasticCriteria.setAllowAllVersions(false);
|
||||||
dmpElasticCriteria.setPublic(false);
|
// dmpElasticCriteria.setPublic(false);
|
||||||
dmpElasticCriteria.setCollaborators(Collections.singletonList(this.userScope.getUserId()));
|
// dmpElasticCriteria.setCollaborators(Collections.singletonList(this.userScope.getUserId()));
|
||||||
dmps = apiContext.getOperationsContext().getElasticRepository().getDmpRepository().count(dmpElasticCriteria);
|
// dmps = apiContext.getOperationsContext().getElasticRepository().getDmpRepository().count(dmpElasticCriteria);
|
||||||
}catch (Exception e) {
|
// }catch (Exception e) {
|
||||||
logger.warn(e.getMessage(), e);
|
// logger.warn(e.getMessage(), e);
|
||||||
dmps = null;
|
// dmps = null;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
dataManagementPlanCriteria.setAllVersions(false);
|
dataManagementPlanCriteria.setAllVersions(false);
|
||||||
dataManagementPlanCriteria.setOnlyPublic(false);
|
dataManagementPlanCriteria.setOnlyPublic(false);
|
||||||
dataManagementPlanCriteria.setIsPublic(false);
|
dataManagementPlanCriteria.setIsPublic(false);
|
||||||
|
|
|
@ -27,18 +27,11 @@ import eu.eudat.data.query.items.table.datasetprofile.DatasetProfileTableRequest
|
||||||
import eu.eudat.data.query.items.table.dmp.DataManagementPlanTableRequest;
|
import eu.eudat.data.query.items.table.dmp.DataManagementPlanTableRequest;
|
||||||
import eu.eudat.depositinterface.models.DMPDepositModel;
|
import eu.eudat.depositinterface.models.DMPDepositModel;
|
||||||
import eu.eudat.depositinterface.repository.RepositoryDeposit;
|
import eu.eudat.depositinterface.repository.RepositoryDeposit;
|
||||||
import eu.eudat.elastic.criteria.DmpCriteria;
|
|
||||||
import eu.eudat.elastic.entities.Collaborator;
|
|
||||||
import eu.eudat.elastic.entities.Dmp;
|
|
||||||
import eu.eudat.elastic.entities.Organization;
|
|
||||||
import eu.eudat.elastic.entities.Tag;
|
|
||||||
import eu.eudat.exceptions.datamanagementplan.DMPNewVersionException;
|
import eu.eudat.exceptions.datamanagementplan.DMPNewVersionException;
|
||||||
import eu.eudat.exceptions.datamanagementplan.DMPWithDatasetsDeleteException;
|
import eu.eudat.exceptions.datamanagementplan.DMPWithDatasetsDeleteException;
|
||||||
import eu.eudat.exceptions.security.ForbiddenException;
|
import eu.eudat.exceptions.security.ForbiddenException;
|
||||||
import eu.eudat.exceptions.security.UnauthorisedException;
|
import eu.eudat.exceptions.security.UnauthorisedException;
|
||||||
import eu.eudat.logic.builders.entity.UserInfoBuilder;
|
import eu.eudat.logic.builders.entity.UserInfoBuilder;
|
||||||
import eu.eudat.logic.mapper.elastic.DmpMapper;
|
|
||||||
import eu.eudat.logic.mapper.elastic.criteria.DmpCriteriaMapper;
|
|
||||||
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
|
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
|
||||||
import eu.eudat.model.mapper.deposit.DMPToDepositMapper;
|
import eu.eudat.model.mapper.deposit.DMPToDepositMapper;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
import eu.eudat.logic.services.ApiContext;
|
||||||
|
@ -162,29 +155,29 @@ public class DataManagementPlanManager {
|
||||||
|
|
||||||
public DataTableData<DataManagementPlanListingModel> getPaged(DataManagementPlanTableRequest dataManagementPlanTableRequest, String fieldsGroup) throws Exception {
|
public DataTableData<DataManagementPlanListingModel> getPaged(DataManagementPlanTableRequest dataManagementPlanTableRequest, String fieldsGroup) throws Exception {
|
||||||
UUID principalID = userScope.getUserIdSafe();
|
UUID principalID = userScope.getUserIdSafe();
|
||||||
List<Dmp> dmps = null;
|
// List<Dmp> dmps = null;
|
||||||
QueryableList<DMP> items = null;
|
QueryableList<DMP> items = null;
|
||||||
QueryableList<DMP> authItems = null;
|
QueryableList<DMP> authItems = null;
|
||||||
Long totalData = 0L;
|
Long totalData = 0L;
|
||||||
if (apiContext.getOperationsContext().getElasticRepository().getDmpRepository() != null) {
|
// if (apiContext.getOperationsContext().getElasticRepository().getDmpRepository() != null) { //TODO
|
||||||
try {
|
// try {
|
||||||
DmpCriteria criteria = DmpCriteriaMapper.toElasticCriteria(dataManagementPlanTableRequest.getCriteria(), principalID);
|
// DmpCriteria criteria = DmpCriteriaMapper.toElasticCriteria(dataManagementPlanTableRequest.getCriteria(), principalID);
|
||||||
criteria.setOffset(dataManagementPlanTableRequest.getOffset());
|
// criteria.setOffset(dataManagementPlanTableRequest.getOffset());
|
||||||
criteria.setSize(dataManagementPlanTableRequest.getLength());
|
// criteria.setSize(dataManagementPlanTableRequest.getLength());
|
||||||
criteria.setSortCriteria(DmpCriteriaMapper.toElasticSorting(dataManagementPlanTableRequest.getOrderings()));
|
// criteria.setSortCriteria(DmpCriteriaMapper.toElasticSorting(dataManagementPlanTableRequest.getOrderings()));
|
||||||
|
//
|
||||||
dmps = apiContext.getOperationsContext().getElasticRepository().getDmpRepository().query(criteria);
|
// dmps = apiContext.getOperationsContext().getElasticRepository().getDmpRepository().query(criteria);
|
||||||
if (dmps != null && !dmps.isEmpty()) {
|
// if (dmps != null && !dmps.isEmpty()) {
|
||||||
List<Dmp> finalDmps = dmps;
|
// List<Dmp> finalDmps = dmps;
|
||||||
items = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().asQueryable().where((builder, root) -> root.get("id").in(finalDmps.stream().map(Dmp::getId).collect(Collectors.toList())));
|
// items = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().asQueryable().where((builder, root) -> root.get("id").in(finalDmps.stream().map(Dmp::getId).collect(Collectors.toList())));
|
||||||
PaginationManager.applyOrder(items, dataManagementPlanTableRequest);
|
// PaginationManager.applyOrder(items, dataManagementPlanTableRequest);
|
||||||
totalData = apiContext.getOperationsContext().getElasticRepository().getDmpRepository().count(criteria);
|
// totalData = apiContext.getOperationsContext().getElasticRepository().getDmpRepository().count(criteria);
|
||||||
}
|
// }
|
||||||
} catch (Exception ex) {
|
// } catch (Exception ex) {
|
||||||
logger.warn(ex.getMessage(), ex);
|
// logger.warn(ex.getMessage(), ex);
|
||||||
items = null;
|
// items = null;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (items == null) {
|
if (items == null) {
|
||||||
items = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(dataManagementPlanTableRequest.getCriteria());
|
items = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(dataManagementPlanTableRequest.getCriteria());
|
||||||
|
@ -197,12 +190,12 @@ public class DataManagementPlanManager {
|
||||||
} else {
|
} else {
|
||||||
authItems = items;
|
authItems = items;
|
||||||
}
|
}
|
||||||
if (dmps == null) {
|
// if (dmps == null) {
|
||||||
totalData = authItems.count();
|
totalData = authItems.count();
|
||||||
items = PaginationManager.applyPaging(authItems, dataManagementPlanTableRequest);
|
items = PaginationManager.applyPaging(authItems, dataManagementPlanTableRequest);
|
||||||
} else {
|
// } else {
|
||||||
items = authItems;
|
// items = authItems;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -632,7 +625,7 @@ public class DataManagementPlanManager {
|
||||||
UUID dmpId = newDmp.getId();
|
UUID dmpId = newDmp.getId();
|
||||||
newDmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
|
newDmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
|
||||||
|
|
||||||
this.updateIndex(newDmp);
|
//this.updateIndex(newDmp); //TODO
|
||||||
|
|
||||||
if (setNotification) {
|
if (setNotification) {
|
||||||
if (newDmp.getStatus() != DMP.DMPStatus.FINALISED.getValue()) {
|
if (newDmp.getStatus() != DMP.DMPStatus.FINALISED.getValue()) {
|
||||||
|
@ -697,7 +690,7 @@ public class DataManagementPlanManager {
|
||||||
UUID dmpId = result.getId();
|
UUID dmpId = result.getId();
|
||||||
result.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
|
result.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
|
||||||
|
|
||||||
this.updateIndex(result);
|
//this.updateIndex(result); //TODO
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -868,7 +861,7 @@ public class DataManagementPlanManager {
|
||||||
UUID dmpId = newDmp.getId();
|
UUID dmpId = newDmp.getId();
|
||||||
newDmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
|
newDmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
|
||||||
|
|
||||||
this.updateIndex(newDmp);
|
//this.updateIndex(newDmp); //TODO
|
||||||
metricsManager.increaseValue(MetricNames.DMP, 1, MetricNames.DRAFT);
|
metricsManager.increaseValue(MetricNames.DMP, 1, MetricNames.DRAFT);
|
||||||
|
|
||||||
return newDmp.getId();
|
return newDmp.getId();
|
||||||
|
@ -899,7 +892,7 @@ public class DataManagementPlanManager {
|
||||||
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(oldDmp);
|
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(oldDmp);
|
||||||
UUID dmpId = oldDmp.getId();
|
UUID dmpId = oldDmp.getId();
|
||||||
oldDmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
|
oldDmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
|
||||||
this.updateIndex(oldDmp);
|
// this.updateIndex(oldDmp); //TODO
|
||||||
DataManagementPlanCriteria criteria1 = new DataManagementPlanCriteria();
|
DataManagementPlanCriteria criteria1 = new DataManagementPlanCriteria();
|
||||||
criteria1.setAllVersions(true);
|
criteria1.setAllVersions(true);
|
||||||
criteria1.setGroupIds(Collections.singletonList(oldDmp.getGroupId()));
|
criteria1.setGroupIds(Collections.singletonList(oldDmp.getGroupId()));
|
||||||
|
@ -907,22 +900,23 @@ public class DataManagementPlanManager {
|
||||||
try {
|
try {
|
||||||
UUID tdmpId = dmp.getId();
|
UUID tdmpId = dmp.getId();
|
||||||
dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), tdmpId)).toList()));
|
dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), tdmpId)).toList()));
|
||||||
this.updateIndex(dmp);
|
//this.updateIndex(dmp); //TODO
|
||||||
} catch (IOException | InvalidApplicationException e) {
|
} catch (InvalidApplicationException e) {
|
||||||
logger.error(e.getMessage(), e);
|
logger.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
for (DescriptionEntity descriptionEntity : dmp.getDataset()) {
|
for (DescriptionEntity descriptionEntity : dmp.getDataset()) {
|
||||||
try {
|
//TODO
|
||||||
List<Tag> tags = new ArrayList<>();
|
// try {
|
||||||
eu.eudat.elastic.entities.Dataset elastic = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(descriptionEntity.getId().toString());
|
// List<Tag> tags = new ArrayList<>();
|
||||||
if (elastic != null) {
|
// eu.eudat.elastic.entities.Dataset elastic = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(descriptionEntity.getId().toString());
|
||||||
tags = elastic.getTags();
|
// if (elastic != null) {
|
||||||
}
|
// tags = elastic.getTags();
|
||||||
//descriptionEntity.setDmpId(dmp.getId()); //TODO
|
// }
|
||||||
this.datasetManager.updateTags(descriptionEntity, tags);
|
// //descriptionEntity.setDmpId(dmp.getId()); //TODO
|
||||||
} catch (Exception e) {
|
// this.datasetManager.updateTags(descriptionEntity, tags);
|
||||||
logger.error(e.getMessage(), e);
|
// } catch (Exception e) {
|
||||||
}
|
// logger.error(e.getMessage(), e);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1044,19 +1038,20 @@ public class DataManagementPlanManager {
|
||||||
List<CompletableFuture<DescriptionEntity>> futures = new LinkedList<>();
|
List<CompletableFuture<DescriptionEntity>> futures = new LinkedList<>();
|
||||||
for (DescriptionEntity descriptionEntity : newDmp.getDataset()) {
|
for (DescriptionEntity descriptionEntity : newDmp.getDataset()) {
|
||||||
DescriptionEntity tempDescriptionEntity = datasetDao.find(descriptionEntity.getId());
|
DescriptionEntity tempDescriptionEntity = datasetDao.find(descriptionEntity.getId());
|
||||||
try {
|
|
||||||
List<Tag> tags = new ArrayList<>();
|
|
||||||
eu.eudat.elastic.entities.Dataset elastic = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(descriptionEntity.getId().toString());
|
|
||||||
if (elastic != null) {
|
|
||||||
tags = elastic.getTags();
|
|
||||||
}
|
|
||||||
//TODO
|
//TODO
|
||||||
//UUID dmpId = tempDescriptionEntity.getDmpId();
|
// try {
|
||||||
//tempDescriptionEntity.getDmp().setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
|
// List<Tag> tags = new ArrayList<>();
|
||||||
this.datasetManager.updateTags(tempDescriptionEntity, tags);
|
// eu.eudat.elastic.entities.Dataset elastic = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(descriptionEntity.getId().toString());
|
||||||
} catch (Exception e) {
|
// if (elastic != null) {
|
||||||
logger.error(e.getMessage(), e);
|
// tags = elastic.getTags();
|
||||||
}
|
// }
|
||||||
|
// //TODO
|
||||||
|
// //UUID dmpId = tempDescriptionEntity.getDmpId();
|
||||||
|
// //tempDescriptionEntity.getDmp().setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
|
||||||
|
// this.datasetManager.updateTags(tempDescriptionEntity, tags);
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// logger.error(e.getMessage(), e);
|
||||||
|
// }
|
||||||
datasetDao.asQueryable().withHint(HintedModelFactory.getHint(DatasetListingModel.class)).where((builder, root) -> builder.equal(root.get("id"), descriptionEntity.getId())).getSingleAsync()
|
datasetDao.asQueryable().withHint(HintedModelFactory.getHint(DatasetListingModel.class)).where((builder, root) -> builder.equal(root.get("id"), descriptionEntity.getId())).getSingleAsync()
|
||||||
.thenApplyAsync(entityDataset -> {
|
.thenApplyAsync(entityDataset -> {
|
||||||
DescriptionEntity newDescriptionEntity = new DescriptionEntity();
|
DescriptionEntity newDescriptionEntity = new DescriptionEntity();
|
||||||
|
@ -1120,51 +1115,52 @@ public class DataManagementPlanManager {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
metricsManager.increaseValue(MetricNames.DATASET, 1, MetricNames.DRAFT);
|
metricsManager.increaseValue(MetricNames.DATASET, 1, MetricNames.DRAFT);
|
||||||
eu.eudat.elastic.entities.Dataset datasetElastic = new eu.eudat.elastic.entities.Dataset();
|
//TODO
|
||||||
datasetElastic.setId(dataset1.getId().toString());
|
// eu.eudat.elastic.entities.Dataset datasetElastic = new eu.eudat.elastic.entities.Dataset();
|
||||||
datasetElastic.setLabel(dataset1.getLabel());
|
// datasetElastic.setId(dataset1.getId().toString());
|
||||||
datasetElastic.setDescription(dataset1.getDescription());
|
// datasetElastic.setLabel(dataset1.getLabel());
|
||||||
datasetElastic.setTemplate(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(dataset1.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId());
|
// datasetElastic.setDescription(dataset1.getDescription());
|
||||||
datasetElastic.setDmp(dmp.getId());
|
// datasetElastic.setTemplate(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(dataset1.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId());
|
||||||
datasetElastic.setStatus(dataset1.getStatus().getValue());
|
// datasetElastic.setDmp(dmp.getId());
|
||||||
datasetElastic.setGroup(dmp.getGroupId());
|
// datasetElastic.setStatus(dataset1.getStatus().getValue());
|
||||||
if(this.dmpBlueprintService.fieldInBlueprint(dmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) {
|
// datasetElastic.setGroup(dmp.getGroupId());
|
||||||
datasetElastic.setGrant(dmp.getGrant().getId());
|
// if(this.dmpBlueprintService.fieldInBlueprint(dmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) {
|
||||||
}
|
// datasetElastic.setGrant(dmp.getGrant().getId());
|
||||||
if (dmp.getUsers() != null) {
|
// }
|
||||||
datasetElastic.setCollaborators(dmp.getUsers().stream().map(user -> {
|
// if (dmp.getUsers() != null) {
|
||||||
Collaborator collaborator = new Collaborator();
|
// datasetElastic.setCollaborators(dmp.getUsers().stream().map(user -> {
|
||||||
collaborator.setId(user.getId().toString());
|
// Collaborator collaborator = new Collaborator();
|
||||||
collaborator.setRole(user.getRole());
|
// collaborator.setId(user.getId().toString());
|
||||||
// collaborator.setName(user.getUser().getName());
|
// collaborator.setRole(user.getRole());
|
||||||
return collaborator;
|
// // collaborator.setName(user.getUser().getName());
|
||||||
}).collect(Collectors.toList()));
|
// return collaborator;
|
||||||
}
|
// }).collect(Collectors.toList()));
|
||||||
datasetElastic.setLastVersion(true);
|
// }
|
||||||
datasetElastic.setLastPublicVersion(false);
|
// datasetElastic.setLastVersion(true);
|
||||||
if (dmp.getOrganisations() != null) {
|
// datasetElastic.setLastPublicVersion(false);
|
||||||
datasetElastic.setOrganizations(dmp.getOrganisations().stream().map(org -> {
|
// if (dmp.getOrganisations() != null) {
|
||||||
Organization organization = new Organization();
|
// datasetElastic.setOrganizations(dmp.getOrganisations().stream().map(org -> {
|
||||||
organization.setId(org.getId().toString());
|
// Organization organization = new Organization();
|
||||||
organization.setName(org.getLabel());
|
// organization.setId(org.getId().toString());
|
||||||
return organization;
|
// organization.setName(org.getLabel());
|
||||||
}).collect(Collectors.toList()));
|
// return organization;
|
||||||
}
|
// }).collect(Collectors.toList()));
|
||||||
datasetElastic.setPublic(dmp.isPublic());
|
// }
|
||||||
if(this.dmpBlueprintService.fieldInBlueprint(dmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) {
|
// datasetElastic.setPublic(dmp.isPublic());
|
||||||
datasetElastic.setGrantStatus(dmp.getGrant().getStatus());
|
// if(this.dmpBlueprintService.fieldInBlueprint(dmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) {
|
||||||
}
|
// datasetElastic.setGrantStatus(dmp.getGrant().getStatus());
|
||||||
|
// }
|
||||||
try {
|
//
|
||||||
eu.eudat.elastic.entities.Dataset oldDatasetElastic = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(descriptionEntity.getId().toString());
|
// try {
|
||||||
if (oldDatasetElastic != null) {
|
// eu.eudat.elastic.entities.Dataset oldDatasetElastic = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(descriptionEntity.getId().toString());
|
||||||
datasetElastic.setTags(oldDatasetElastic.getTags());
|
// if (oldDatasetElastic != null) {
|
||||||
}
|
// datasetElastic.setTags(oldDatasetElastic.getTags());
|
||||||
datasetElastic.setFormData(this.datasetManager.getWordDocumentText(dataset1));
|
// }
|
||||||
apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().createOrUpdate(datasetElastic);
|
// datasetElastic.setFormData(this.datasetManager.getWordDocumentText(dataset1));
|
||||||
} catch (Exception e) {
|
// apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().createOrUpdate(datasetElastic);
|
||||||
logger.error(e.getMessage(), e);
|
// } catch (Exception e) {
|
||||||
}
|
// logger.error(e.getMessage(), e);
|
||||||
|
// }
|
||||||
})));
|
})));
|
||||||
return futures;
|
return futures;
|
||||||
}).join();
|
}).join();
|
||||||
|
@ -1183,27 +1179,28 @@ public class DataManagementPlanManager {
|
||||||
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(dmp);
|
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(dmp);
|
||||||
UUID dmpId = dmp.getId();
|
UUID dmpId = dmp.getId();
|
||||||
dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
|
dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
|
||||||
this.updateIndex(dmp);
|
//this.updateIndex(dmp); //TODO
|
||||||
metricsManager.increaseValue(MetricNames.DMP, 1, MetricNames.PUBLISHED);
|
metricsManager.increaseValue(MetricNames.DMP, 1, MetricNames.PUBLISHED);
|
||||||
DataManagementPlanCriteria criteria = new DataManagementPlanCriteria();
|
DataManagementPlanCriteria criteria = new DataManagementPlanCriteria();
|
||||||
criteria.setGroupIds(Collections.singletonList(dmp.getGroupId()));
|
criteria.setGroupIds(Collections.singletonList(dmp.getGroupId()));
|
||||||
criteria.setAllVersions(true);
|
criteria.setAllVersions(true);
|
||||||
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(criteria).toList().stream().forEach(dmp1 -> {
|
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(criteria).toList().stream().forEach(dmp1 -> {
|
||||||
dmp1.getDataset().forEach(dataset -> {
|
dmp1.getDataset().forEach(dataset -> {
|
||||||
try {
|
|
||||||
List<Tag> tags = new ArrayList<>();
|
|
||||||
eu.eudat.elastic.entities.Dataset elastic = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(dataset.getId().toString());
|
|
||||||
if (elastic != null) {
|
|
||||||
tags = elastic.getTags();
|
|
||||||
}
|
|
||||||
//TODO
|
//TODO
|
||||||
//UUID tmdmpId = dataset.getDmpId();
|
// try {
|
||||||
//dataset.getDmp().setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), tmdmpId)).toList()));
|
// List<Tag> tags = new ArrayList<>();
|
||||||
this.datasetManager.updateTags(dataset, tags);
|
// eu.eudat.elastic.entities.Dataset elastic = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(dataset.getId().toString());
|
||||||
metricsManager.increaseValue(MetricNames.DATASET, 1, MetricNames.PUBLISHED);
|
// if (elastic != null) {
|
||||||
} catch (Exception e) {
|
// tags = elastic.getTags();
|
||||||
logger.error(e.getMessage(), e);
|
// }
|
||||||
}
|
// //TODO
|
||||||
|
// //UUID tmdmpId = dataset.getDmpId();
|
||||||
|
// //dataset.getDmp().setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), tmdmpId)).toList()));
|
||||||
|
// this.datasetManager.updateTags(dataset, tags);
|
||||||
|
// metricsManager.increaseValue(MetricNames.DATASET, 1, MetricNames.PUBLISHED);
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// logger.error(e.getMessage(), e);
|
||||||
|
// }
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(this.userScope.getUserId());
|
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(this.userScope.getUserId());
|
||||||
|
@ -1283,12 +1280,12 @@ public class DataManagementPlanManager {
|
||||||
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(dmp);
|
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(dmp);
|
||||||
UUID dmpId = dmp.getId();
|
UUID dmpId = dmp.getId();
|
||||||
dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
|
dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
|
||||||
this.updateIndex(dmp);
|
//this.updateIndex(dmp); //TODO
|
||||||
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(this.userScope.getUserId());
|
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(this.userScope.getUserId());
|
||||||
sendNotification(dmp, user, NotificationType.DMP_FINALISED);
|
sendNotification(dmp, user, NotificationType.DMP_FINALISED);
|
||||||
metricsManager.decreaseValue(MetricNames.DMP, 1, MetricNames.DRAFT);
|
metricsManager.decreaseValue(MetricNames.DMP, 1, MetricNames.DRAFT);
|
||||||
metricsManager.increaseValue(MetricNames.DMP, 1, MetricNames.FINALIZED);
|
metricsManager.increaseValue(MetricNames.DMP, 1, MetricNames.FINALIZED);
|
||||||
this.updateDatasetsIndex(indexDescriptionEntities);
|
//this.updateDatasetsIndex(indexDescriptionEntities); //TODO
|
||||||
metricsManager.decreaseValue(MetricNames.DATASET, indexDescriptionEntities.size(), MetricNames.DRAFT);
|
metricsManager.decreaseValue(MetricNames.DATASET, indexDescriptionEntities.size(), MetricNames.DRAFT);
|
||||||
metricsManager.increaseValue(MetricNames.DATASET, indexDescriptionEntities.size(), MetricNames.FINALIZED);
|
metricsManager.increaseValue(MetricNames.DATASET, indexDescriptionEntities.size(), MetricNames.FINALIZED);
|
||||||
}
|
}
|
||||||
|
@ -1307,7 +1304,7 @@ public class DataManagementPlanManager {
|
||||||
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(dmp);
|
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(dmp);
|
||||||
UUID dmpId = dmp.getId();
|
UUID dmpId = dmp.getId();
|
||||||
dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
|
dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
|
||||||
this.updateIndex(dmp);
|
//this.updateIndex(dmp); //TODO
|
||||||
metricsManager.decreaseValue(MetricNames.DMP, 1, MetricNames.FINALIZED);
|
metricsManager.decreaseValue(MetricNames.DMP, 1, MetricNames.FINALIZED);
|
||||||
metricsManager.increaseValue(MetricNames.DMP, 1, MetricNames.DRAFT);
|
metricsManager.increaseValue(MetricNames.DMP, 1, MetricNames.DRAFT);
|
||||||
}
|
}
|
||||||
|
@ -2287,11 +2284,12 @@ public class DataManagementPlanManager {
|
||||||
}
|
}
|
||||||
databaseRepository.getDmpDao().createOrUpdate(dmp);
|
databaseRepository.getDmpDao().createOrUpdate(dmp);
|
||||||
assignUser(dmp, me);
|
assignUser(dmp, me);
|
||||||
if (this.apiContext.getOperationsContext().getElasticRepository().getDmpRepository().getClient() != null) {
|
//TODO
|
||||||
UUID dmpId = dmp.getId();
|
// if (this.apiContext.getOperationsContext().getElasticRepository().getDmpRepository().getClient() != null) {
|
||||||
dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
|
// UUID dmpId = dmp.getId();
|
||||||
this.updateIndex(dmp);
|
// dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
|
||||||
}
|
// this.updateIndex(dmp);
|
||||||
|
// }
|
||||||
dmp.getDataset().forEach(dataset -> {
|
dmp.getDataset().forEach(dataset -> {
|
||||||
dataset.setStatus(DescriptionStatus.Draft);
|
dataset.setStatus(DescriptionStatus.Draft);
|
||||||
dataset.setCreatedAt(Instant.now());
|
dataset.setCreatedAt(Instant.now());
|
||||||
|
@ -2313,19 +2311,20 @@ public class DataManagementPlanManager {
|
||||||
} catch (InvalidApplicationException e) {
|
} catch (InvalidApplicationException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
try {
|
//TODO
|
||||||
List<Tag> tags = new ArrayList<>();
|
// try {
|
||||||
eu.eudat.elastic.entities.Dataset elastic = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(dataset.getId().toString());
|
// List<Tag> tags = new ArrayList<>();
|
||||||
DatasetWizardModel datasetWizardModel = new DatasetWizardModel().fromDataModel(dataset);
|
// eu.eudat.elastic.entities.Dataset elastic = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(dataset.getId().toString());
|
||||||
if (elastic != null) {
|
// DatasetWizardModel datasetWizardModel = new DatasetWizardModel().fromDataModel(dataset);
|
||||||
tags = elastic.getTags();
|
// if (elastic != null) {
|
||||||
datasetWizardModel.setTags(tags);
|
// tags = elastic.getTags();
|
||||||
}
|
// datasetWizardModel.setTags(tags);
|
||||||
datasetManager.getTagsFromProfile(datasetWizardModel, dataset);
|
// }
|
||||||
datasetManager.updateTags(dataset, datasetWizardModel.getTags());
|
// datasetManager.getTagsFromProfile(datasetWizardModel, dataset);
|
||||||
} catch (Exception e) {
|
// datasetManager.updateTags(dataset, datasetWizardModel.getTags());
|
||||||
logger.error(e.getMessage(), e);
|
// } catch (Exception e) {
|
||||||
}
|
// logger.error(e.getMessage(), e);
|
||||||
|
// }
|
||||||
});
|
});
|
||||||
result.add(dmp);
|
result.add(dmp);
|
||||||
}
|
}
|
||||||
|
@ -2387,61 +2386,61 @@ public class DataManagementPlanManager {
|
||||||
UUID dmpId = dmp.getId();
|
UUID dmpId = dmp.getId();
|
||||||
dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
|
dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
|
||||||
}
|
}
|
||||||
this.updateIndex(dmp);
|
// this.updateIndex(dmp); //TODO
|
||||||
} catch (IOException | InvalidApplicationException e) {
|
} catch (InvalidApplicationException e) {
|
||||||
logger.error(e.getMessage(), e);
|
logger.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateDatasetsIndex(List<DescriptionEntity> descriptionEntities) {
|
// private void updateDatasetsIndex(List<DescriptionEntity> descriptionEntities) {
|
||||||
descriptionEntities.forEach(dataset -> {
|
// descriptionEntities.forEach(dataset -> {
|
||||||
List<Tag> tags = new ArrayList<>();
|
// List<Tag> tags = new ArrayList<>();
|
||||||
eu.eudat.elastic.entities.Dataset elastic = null;
|
// eu.eudat.elastic.entities.Dataset elastic = null;
|
||||||
try {
|
// try {
|
||||||
elastic = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(dataset.getId().toString());
|
// elastic = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(dataset.getId().toString());
|
||||||
if (elastic != null) {
|
// if (elastic != null) {
|
||||||
tags = elastic.getTags();
|
// tags = elastic.getTags();
|
||||||
}
|
// }
|
||||||
//TODO
|
// //TODO
|
||||||
//UUID dmpId = dataset.getDmpId();
|
// //UUID dmpId = dataset.getDmpId();
|
||||||
//dataset.getDmp().setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
|
// //dataset.getDmp().setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
|
||||||
this.datasetManager.updateTags(dataset, tags);
|
// this.datasetManager.updateTags(dataset, tags);
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
logger.error(e.getMessage(), e);
|
// logger.error(e.getMessage(), e);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
});
|
// public void updateIndex(DMP dmp) throws IOException, InvalidApplicationException {
|
||||||
}
|
// DmpMapper mapper = new DmpMapper(apiContext, datasetManager);
|
||||||
|
// Dmp elastic = mapper.toElastic(dmp);
|
||||||
|
// apiContext.getOperationsContext().getElasticRepository().getDmpRepository().createOrUpdate(elastic);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void generateIndex() throws InvalidApplicationException {
|
||||||
|
// if (this.authorizationService.authorize(Permission.AdminRole)) {
|
||||||
|
// if (apiContext.getOperationsContext().getElasticRepository().getDmpRepository().createIndex()) {
|
||||||
|
// List<DMP> dmps = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().asQueryable().toList();
|
||||||
|
// dmps.forEach(dmp -> {
|
||||||
|
// try {
|
||||||
|
// UUID dmpId = dmp.getId();
|
||||||
|
// dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
|
||||||
|
// this.updateIndex(dmp);
|
||||||
|
// } catch (IOException | InvalidApplicationException e) {
|
||||||
|
// logger.error(e.getMessage(), e);
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
public void updateIndex(DMP dmp) throws IOException, InvalidApplicationException {
|
// public void clearIndex() throws IOException {
|
||||||
DmpMapper mapper = new DmpMapper(apiContext, datasetManager);
|
// if (this.authorizationService.authorize(Permission.AdminRole)) {
|
||||||
Dmp elastic = mapper.toElastic(dmp);
|
// apiContext.getOperationsContext().getElasticRepository().getDmpRepository().clear();
|
||||||
apiContext.getOperationsContext().getElasticRepository().getDmpRepository().createOrUpdate(elastic);
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
public void generateIndex() throws InvalidApplicationException {
|
|
||||||
if (this.authorizationService.authorize(Permission.AdminRole)) {
|
|
||||||
if (apiContext.getOperationsContext().getElasticRepository().getDmpRepository().createIndex()) {
|
|
||||||
List<DMP> dmps = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().asQueryable().toList();
|
|
||||||
dmps.forEach(dmp -> {
|
|
||||||
try {
|
|
||||||
UUID dmpId = dmp.getId();
|
|
||||||
dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
|
|
||||||
this.updateIndex(dmp);
|
|
||||||
} catch (IOException | InvalidApplicationException e) {
|
|
||||||
logger.error(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clearIndex() throws IOException {
|
|
||||||
if (this.authorizationService.authorize(Permission.AdminRole)) {
|
|
||||||
apiContext.getOperationsContext().getElasticRepository().getDmpRepository().clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Data Checkup
|
* Data Checkup
|
||||||
|
|
|
@ -10,6 +10,7 @@ import eu.eudat.commons.enums.IsActive;
|
||||||
import eu.eudat.commons.scope.user.UserScope;
|
import eu.eudat.commons.scope.user.UserScope;
|
||||||
import eu.eudat.data.DescriptionEntity;
|
import eu.eudat.data.DescriptionEntity;
|
||||||
import eu.eudat.data.DescriptionTemplateEntity;
|
import eu.eudat.data.DescriptionTemplateEntity;
|
||||||
|
import eu.eudat.data.TagEntity;
|
||||||
import eu.eudat.data.dao.criteria.*;
|
import eu.eudat.data.dao.criteria.*;
|
||||||
import eu.eudat.data.dao.entities.DataRepositoryDao;
|
import eu.eudat.data.dao.entities.DataRepositoryDao;
|
||||||
import eu.eudat.data.dao.entities.DatasetDao;
|
import eu.eudat.data.dao.entities.DatasetDao;
|
||||||
|
@ -22,15 +23,10 @@ import eu.eudat.data.old.*;
|
||||||
import eu.eudat.data.query.items.table.dataset.DatasetPublicTableRequest;
|
import eu.eudat.data.query.items.table.dataset.DatasetPublicTableRequest;
|
||||||
import eu.eudat.data.query.items.table.dataset.DatasetTableRequest;
|
import eu.eudat.data.query.items.table.dataset.DatasetTableRequest;
|
||||||
import eu.eudat.data.query.items.table.datasetprofile.DatasetProfileTableRequestItem;
|
import eu.eudat.data.query.items.table.datasetprofile.DatasetProfileTableRequestItem;
|
||||||
import eu.eudat.elastic.criteria.DatasetCriteria;
|
|
||||||
import eu.eudat.elastic.entities.Tag;
|
|
||||||
import eu.eudat.elastic.repository.DatasetRepository;
|
|
||||||
import eu.eudat.exceptions.security.ForbiddenException;
|
import eu.eudat.exceptions.security.ForbiddenException;
|
||||||
import eu.eudat.exceptions.security.UnauthorisedException;
|
import eu.eudat.exceptions.security.UnauthorisedException;
|
||||||
import eu.eudat.logic.builders.BuilderFactory;
|
import eu.eudat.logic.builders.BuilderFactory;
|
||||||
import eu.eudat.logic.builders.entity.UserInfoBuilder;
|
import eu.eudat.logic.builders.entity.UserInfoBuilder;
|
||||||
import eu.eudat.logic.mapper.elastic.DatasetMapper;
|
|
||||||
import eu.eudat.logic.mapper.elastic.criteria.DmpCriteriaMapper;
|
|
||||||
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
|
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
import eu.eudat.logic.services.ApiContext;
|
||||||
import eu.eudat.logic.services.forms.VisibilityRuleService;
|
import eu.eudat.logic.services.forms.VisibilityRuleService;
|
||||||
|
@ -113,7 +109,7 @@ public class DatasetManager {
|
||||||
|
|
||||||
private ApiContext apiContext;
|
private ApiContext apiContext;
|
||||||
private DatabaseRepository databaseRepository;
|
private DatabaseRepository databaseRepository;
|
||||||
private DatasetRepository datasetRepository;
|
// private DatasetRepository datasetRepository;
|
||||||
private BuilderFactory builderFactory;
|
private BuilderFactory builderFactory;
|
||||||
private UserManager userManager;
|
private UserManager userManager;
|
||||||
private ConfigLoader configLoader;
|
private ConfigLoader configLoader;
|
||||||
|
@ -129,7 +125,7 @@ public class DatasetManager {
|
||||||
FileManager fileManager, UserScope userScope, AuthorizationService authorizationService, QueryFactory queryFactory) {
|
FileManager fileManager, UserScope userScope, AuthorizationService authorizationService, QueryFactory queryFactory) {
|
||||||
this.apiContext = apiContext;
|
this.apiContext = apiContext;
|
||||||
this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository();
|
this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository();
|
||||||
this.datasetRepository = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository();
|
// this.datasetRepository = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository();
|
||||||
this.builderFactory = apiContext.getOperationsContext().getBuilderFactory();
|
this.builderFactory = apiContext.getOperationsContext().getBuilderFactory();
|
||||||
this.userManager = userManager;
|
this.userManager = userManager;
|
||||||
this.configLoader = configLoader;
|
this.configLoader = configLoader;
|
||||||
|
@ -142,63 +138,65 @@ public class DatasetManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataTableData<DatasetListingModel> getPaged(DatasetTableRequest datasetTableRequest) throws Exception {
|
public DataTableData<DatasetListingModel> getPaged(DatasetTableRequest datasetTableRequest) throws Exception {
|
||||||
DatasetCriteria datasetCriteria = new DatasetCriteria();
|
//TODO
|
||||||
datasetCriteria.setLike(datasetTableRequest.getCriteria().getLike());
|
// DatasetCriteria datasetCriteria = new DatasetCriteria();
|
||||||
datasetCriteria.setDatasetTemplates(datasetTableRequest.getCriteria().getDatasetTemplates());
|
// datasetCriteria.setLike(datasetTableRequest.getCriteria().getLike());
|
||||||
if (datasetTableRequest.getCriteria().getStatus() != null) {
|
// datasetCriteria.setDatasetTemplates(datasetTableRequest.getCriteria().getDatasetTemplates());
|
||||||
datasetCriteria.setStatus(datasetTableRequest.getCriteria().getStatus().shortValue());
|
// if (datasetTableRequest.getCriteria().getStatus() != null) {
|
||||||
}
|
// datasetCriteria.setStatus(datasetTableRequest.getCriteria().getStatus().shortValue());
|
||||||
datasetCriteria.setDmps(datasetTableRequest.getCriteria().getDmpIds());
|
// }
|
||||||
datasetCriteria.setGroupIds(datasetTableRequest.getCriteria().getGroupIds());
|
// datasetCriteria.setDmps(datasetTableRequest.getCriteria().getDmpIds());
|
||||||
datasetCriteria.setGrants(datasetTableRequest.getCriteria().getGrants());
|
// datasetCriteria.setGroupIds(datasetTableRequest.getCriteria().getGroupIds());
|
||||||
datasetCriteria.setCollaborators(datasetTableRequest.getCriteria().getCollaborators());
|
// datasetCriteria.setGrants(datasetTableRequest.getCriteria().getGrants());
|
||||||
datasetCriteria.setAllowAllVersions(datasetTableRequest.getCriteria().getAllVersions());
|
// datasetCriteria.setCollaborators(datasetTableRequest.getCriteria().getCollaborators());
|
||||||
datasetCriteria.setOrganiztions(datasetTableRequest.getCriteria().getOrganisations());
|
// datasetCriteria.setAllowAllVersions(datasetTableRequest.getCriteria().getAllVersions());
|
||||||
datasetCriteria.setTags(datasetTableRequest.getCriteria().getTags());
|
// datasetCriteria.setOrganiztions(datasetTableRequest.getCriteria().getOrganisations());
|
||||||
if (datasetTableRequest.getCriteria().getIsPublic() != null) {
|
// datasetCriteria.setTags(datasetTableRequest.getCriteria().getTags());
|
||||||
datasetCriteria.setPublic(datasetTableRequest.getCriteria().getIsPublic());
|
// if (datasetTableRequest.getCriteria().getIsPublic() != null) {
|
||||||
}
|
// datasetCriteria.setPublic(datasetTableRequest.getCriteria().getIsPublic());
|
||||||
|
// }
|
||||||
if (!datasetCriteria.isPublic()) {
|
//
|
||||||
if (datasetCriteria.getCollaborators() == null) {
|
// if (!datasetCriteria.isPublic()) {
|
||||||
datasetCriteria.setSortCriteria(new ArrayList<>());
|
// if (datasetCriteria.getCollaborators() == null) {
|
||||||
}
|
// datasetCriteria.setSortCriteria(new ArrayList<>());
|
||||||
datasetCriteria.getCollaborators().add(this.userScope.getUserId());
|
// }
|
||||||
}
|
// datasetCriteria.getCollaborators().add(this.userScope.getUserId());
|
||||||
if (datasetTableRequest.getCriteria().getGrantStatus() != null) {
|
// }
|
||||||
datasetCriteria.setGrantStatus(datasetTableRequest.getCriteria().getGrantStatus());
|
// if (datasetTableRequest.getCriteria().getGrantStatus() != null) {
|
||||||
}
|
// datasetCriteria.setGrantStatus(datasetTableRequest.getCriteria().getGrantStatus());
|
||||||
if (datasetTableRequest.getOrderings() != null) {
|
// }
|
||||||
datasetCriteria.setSortCriteria(DmpCriteriaMapper.toElasticSorting(datasetTableRequest.getOrderings()));
|
// if (datasetTableRequest.getOrderings() != null) {
|
||||||
}
|
// datasetCriteria.setSortCriteria(DmpCriteriaMapper.toElasticSorting(datasetTableRequest.getOrderings()));
|
||||||
datasetCriteria.setOffset(datasetTableRequest.getOffset());
|
// }
|
||||||
datasetCriteria.setSize(datasetTableRequest.getLength());
|
// datasetCriteria.setOffset(datasetTableRequest.getOffset());
|
||||||
List<eu.eudat.elastic.entities.Dataset> datasets;
|
// datasetCriteria.setSize(datasetTableRequest.getLength());
|
||||||
try {
|
// List<eu.eudat.elastic.entities.Dataset> datasets;
|
||||||
datasets = datasetRepository.exists() ?
|
// try {
|
||||||
datasetRepository.queryIds(datasetCriteria) : null;
|
// datasets = datasetRepository.exists() ?
|
||||||
} catch (Exception ex) {
|
// datasetRepository.queryIds(datasetCriteria) : null;
|
||||||
logger.warn(ex.getMessage(), ex);
|
// } catch (Exception ex) {
|
||||||
datasets = null;
|
// logger.warn(ex.getMessage(), ex);
|
||||||
}
|
// datasets = null;
|
||||||
|
// }
|
||||||
|
|
||||||
UserInfo userInfo = builderFactory.getBuilder(UserInfoBuilder.class).id(this.userScope.getUserIdSafe()).build();
|
UserInfo userInfo = builderFactory.getBuilder(UserInfoBuilder.class).id(this.userScope.getUserIdSafe()).build();
|
||||||
// QueryableList<eu.eudat.data.Dataset> items = databaseRepository.getDatasetDao().getWithCriteria(datasetTableRequest.getCriteria()).withHint(HintedModelFactory.getHint(DatasetListingModel.class));
|
// QueryableList<eu.eudat.data.Dataset> items = databaseRepository.getDatasetDao().getWithCriteria(datasetTableRequest.getCriteria()).withHint(HintedModelFactory.getHint(DatasetListingModel.class));
|
||||||
QueryableList<DescriptionEntity> items;
|
QueryableList<DescriptionEntity> items;
|
||||||
if (datasets != null) {
|
//TODO
|
||||||
|
// if (datasets != null) {
|
||||||
if (!datasets.isEmpty()) {
|
//
|
||||||
//items = databaseRepository.getDatasetDao().asQueryable().withHint(HintedModelFactory.getHint(DatasetListingModel.class));
|
// if (!datasets.isEmpty()) {
|
||||||
final List<UUID> datasetIds = datasets.stream().map(datasetE -> UUID.fromString(datasetE.getId())).distinct().collect(Collectors.toList());
|
// //items = databaseRepository.getDatasetDao().asQueryable().withHint(HintedModelFactory.getHint(DatasetListingModel.class));
|
||||||
items = databaseRepository.getDatasetDao().filterFromElastic(datasetTableRequest.getCriteria(), datasetIds).withHint(HintedModelFactory.getHint(DatasetListingModel.class));//.withFields(Collections.singletonList("id"));
|
// final List<UUID> datasetIds = datasets.stream().map(datasetE -> UUID.fromString(datasetE.getId())).distinct().collect(Collectors.toList());
|
||||||
//items.where((builder, root) -> root.get("id").in(datasetIds));
|
// items = databaseRepository.getDatasetDao().filterFromElastic(datasetTableRequest.getCriteria(), datasetIds).withHint(HintedModelFactory.getHint(DatasetListingModel.class));//.withFields(Collections.singletonList("id"));
|
||||||
} else {
|
// //items.where((builder, root) -> root.get("id").in(datasetIds));
|
||||||
|
// } else {
|
||||||
|
// items = databaseRepository.getDatasetDao().getWithCriteria(datasetTableRequest.getCriteria()).withHint(HintedModelFactory.getHint(DatasetListingModel.class));//.withFields(Collections.singletonList("id"));
|
||||||
|
// //items.where((builder, root) -> root.get("id").in(new UUID[]{UUID.randomUUID()}));
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
items = databaseRepository.getDatasetDao().getWithCriteria(datasetTableRequest.getCriteria()).withHint(HintedModelFactory.getHint(DatasetListingModel.class));//.withFields(Collections.singletonList("id"));
|
items = databaseRepository.getDatasetDao().getWithCriteria(datasetTableRequest.getCriteria()).withHint(HintedModelFactory.getHint(DatasetListingModel.class));//.withFields(Collections.singletonList("id"));
|
||||||
//items.where((builder, root) -> root.get("id").in(new UUID[]{UUID.randomUUID()}));
|
// }
|
||||||
}
|
|
||||||
} else {
|
|
||||||
items = databaseRepository.getDatasetDao().getWithCriteria(datasetTableRequest.getCriteria()).withHint(HintedModelFactory.getHint(DatasetListingModel.class));//.withFields(Collections.singletonList("id"));
|
|
||||||
}
|
|
||||||
List<Integer> roles = new LinkedList<>();
|
List<Integer> roles = new LinkedList<>();
|
||||||
QueryableList<DescriptionEntity> pagedItems;
|
QueryableList<DescriptionEntity> pagedItems;
|
||||||
QueryableList<DescriptionEntity> authItems;
|
QueryableList<DescriptionEntity> authItems;
|
||||||
|
@ -237,39 +235,41 @@ public class DatasetManager {
|
||||||
|
|
||||||
public DataTableData<DatasetListingModel> getPaged(DatasetPublicTableRequest datasetTableRequest) throws Exception {
|
public DataTableData<DatasetListingModel> getPaged(DatasetPublicTableRequest datasetTableRequest) throws Exception {
|
||||||
Long count = 0L;
|
Long count = 0L;
|
||||||
DatasetCriteria datasetCriteria = new DatasetCriteria();
|
//TODO
|
||||||
datasetCriteria.setLike(datasetTableRequest.getCriteria().getLike());
|
// DatasetCriteria datasetCriteria = new DatasetCriteria();
|
||||||
datasetCriteria.setDatasetTemplates(datasetTableRequest.getCriteria().getDatasetProfile());
|
// datasetCriteria.setLike(datasetTableRequest.getCriteria().getLike());
|
||||||
datasetCriteria.setDmps(datasetTableRequest.getCriteria().getDmpIds());
|
// datasetCriteria.setDatasetTemplates(datasetTableRequest.getCriteria().getDatasetProfile());
|
||||||
datasetCriteria.setGrants(datasetTableRequest.getCriteria().getGrants());
|
// datasetCriteria.setDmps(datasetTableRequest.getCriteria().getDmpIds());
|
||||||
if (datasetTableRequest.getOrderings() != null) {
|
// datasetCriteria.setGrants(datasetTableRequest.getCriteria().getGrants());
|
||||||
datasetCriteria.setSortCriteria(DmpCriteriaMapper.toElasticSorting(datasetTableRequest.getOrderings()));
|
// if (datasetTableRequest.getOrderings() != null) {
|
||||||
}
|
// datasetCriteria.setSortCriteria(DmpCriteriaMapper.toElasticSorting(datasetTableRequest.getOrderings()));
|
||||||
datasetCriteria.setOffset(datasetTableRequest.getOffset());
|
// }
|
||||||
datasetCriteria.setSize(datasetTableRequest.getLength());
|
// datasetCriteria.setOffset(datasetTableRequest.getOffset());
|
||||||
List<eu.eudat.elastic.entities.Dataset> datasets;
|
// datasetCriteria.setSize(datasetTableRequest.getLength());
|
||||||
try {
|
// List<eu.eudat.elastic.entities.Dataset> datasets;
|
||||||
datasets = datasetRepository.exists() ?
|
// try {
|
||||||
datasetRepository.queryIds(datasetCriteria) : new LinkedList<>();
|
// datasets = datasetRepository.exists() ?
|
||||||
count = datasetRepository.exists() ? datasetRepository.count(datasetCriteria) : 0L;
|
// datasetRepository.queryIds(datasetCriteria) : new LinkedList<>();
|
||||||
} catch (Exception ex) {
|
// count = datasetRepository.exists() ? datasetRepository.count(datasetCriteria) : 0L;
|
||||||
logger.warn(ex.getMessage());
|
// } catch (Exception ex) {
|
||||||
datasets = null;
|
// logger.warn(ex.getMessage());
|
||||||
}
|
// datasets = null;
|
||||||
|
// }
|
||||||
/*datasetTableRequest.setQuery(databaseRepository.getDatasetDao().asQueryable().withHint(HintedModelFactory.getHint(DatasetListingModel.class)));
|
/*datasetTableRequest.setQuery(databaseRepository.getDatasetDao().asQueryable().withHint(HintedModelFactory.getHint(DatasetListingModel.class)));
|
||||||
QueryableList<Dataset> items = datasetTableRequest.applyCriteria();*/
|
QueryableList<Dataset> items = datasetTableRequest.applyCriteria();*/
|
||||||
QueryableList<DescriptionEntity> items;
|
QueryableList<DescriptionEntity> items;
|
||||||
if (datasets != null) {
|
//TODO
|
||||||
if (!datasets.isEmpty()) {
|
// if (datasets != null) {
|
||||||
items = databaseRepository.getDatasetDao().asQueryable().withHint(HintedModelFactory.getHint(DatasetListingModel.class));
|
// if (!datasets.isEmpty()) {
|
||||||
List<eu.eudat.elastic.entities.Dataset> finalDatasets = datasets;
|
// items = databaseRepository.getDatasetDao().asQueryable().withHint(HintedModelFactory.getHint(DatasetListingModel.class));
|
||||||
items.where((builder, root) -> root.get("id").in(finalDatasets.stream().map(x -> UUID.fromString(x.getId())).collect(Collectors.toList())));
|
// List<eu.eudat.elastic.entities.Dataset> finalDatasets = datasets;
|
||||||
} else
|
// items.where((builder, root) -> root.get("id").in(finalDatasets.stream().map(x -> UUID.fromString(x.getId())).collect(Collectors.toList())));
|
||||||
|
// } else
|
||||||
|
// items = datasetTableRequest.applyCriteria();
|
||||||
|
// items.where((builder, root) -> root.get("id").in(new UUID[]{UUID.randomUUID()}));
|
||||||
|
// } else {
|
||||||
items = datasetTableRequest.applyCriteria();
|
items = datasetTableRequest.applyCriteria();
|
||||||
items.where((builder, root) -> root.get("id").in(new UUID[]{UUID.randomUUID()}));
|
// }
|
||||||
} else {
|
|
||||||
items = datasetTableRequest.applyCriteria();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.userScope.isSet() && datasetTableRequest.getCriteria().getRole() != null) {
|
if (this.userScope.isSet() && datasetTableRequest.getCriteria().getRole() != null) {
|
||||||
items.where((builder, root) -> {
|
items.where((builder, root) -> {
|
||||||
|
@ -344,17 +344,17 @@ public class DatasetManager {
|
||||||
boolean latestVersion = profile.getVersion().toString().equals(this.queryFactory.query(DescriptionTemplateQuery.class).ids(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId()).first().getVersion());
|
boolean latestVersion = profile.getVersion().toString().equals(this.queryFactory.query(DescriptionTemplateQuery.class).ids(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId()).first().getVersion());
|
||||||
dataset.setIsProfileLatestVersion(latestVersion);
|
dataset.setIsProfileLatestVersion(latestVersion);
|
||||||
|
|
||||||
eu.eudat.elastic.entities.Dataset datasetElastic;
|
// eu.eudat.elastic.entities.Dataset datasetElastic; //TODO
|
||||||
try {
|
// try {
|
||||||
datasetElastic = datasetRepository.exists() ?
|
// datasetElastic = datasetRepository.exists() ?
|
||||||
datasetRepository.findDocument(id) : new eu.eudat.elastic.entities.Dataset();
|
// datasetRepository.findDocument(id) : new eu.eudat.elastic.entities.Dataset();
|
||||||
} catch (Exception ex) {
|
// } catch (Exception ex) {
|
||||||
logger.warn(ex.getMessage());
|
// logger.warn(ex.getMessage());
|
||||||
datasetElastic = null;
|
// datasetElastic = null;
|
||||||
}
|
// }
|
||||||
if (datasetElastic != null && datasetElastic.getTags() != null && !datasetElastic.getTags().isEmpty()) {
|
// if (datasetElastic != null && datasetElastic.getTags() != null && !datasetElastic.getTags().isEmpty()) {
|
||||||
dataset.setTags(datasetElastic.getTags());
|
// dataset.setTags(datasetElastic.getTags());
|
||||||
}
|
// }
|
||||||
|
|
||||||
/*if (datasetElastic != null && datasetElastic.getLabel() != null && !datasetElastic.getLabel().isEmpty()) {
|
/*if (datasetElastic != null && datasetElastic.getLabel() != null && !datasetElastic.getLabel().isEmpty()) {
|
||||||
dataset.setLabel(datasetElastic.getLabel());
|
dataset.setLabel(datasetElastic.getLabel());
|
||||||
|
@ -630,9 +630,9 @@ public class DatasetManager {
|
||||||
DescriptionEntity descriptionEntity = datasetWizardModel.toDataModel();
|
DescriptionEntity descriptionEntity = datasetWizardModel.toDataModel();
|
||||||
// descriptionEntity.setDmpId(dmp.getId()); //TODO
|
// descriptionEntity.setDmpId(dmp.getId()); //TODO
|
||||||
descriptionEntity.setProperties(propertiesModelToString(datasetWizardModel.getDatasetProfileDefinition()));
|
descriptionEntity.setProperties(propertiesModelToString(datasetWizardModel.getDatasetProfileDefinition()));
|
||||||
if (this.apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().getClient() != null) {
|
// if (this.apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().getClient() != null) {
|
||||||
this.getTagsFromProfile(datasetWizardModel, descriptionEntity);
|
// this.getTagsFromProfile(datasetWizardModel, descriptionEntity);
|
||||||
}
|
// } //TODO
|
||||||
if (datasetWizardModel.getStatus() == DescriptionStatus.Finalized) {
|
if (datasetWizardModel.getStatus() == DescriptionStatus.Finalized) {
|
||||||
String failedField = checkDatasetValidation(descriptionEntity);
|
String failedField = checkDatasetValidation(descriptionEntity);
|
||||||
if (failedField != null) {
|
if (failedField != null) {
|
||||||
|
@ -658,7 +658,7 @@ public class DatasetManager {
|
||||||
UUID dmpId = this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntity1.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId();
|
UUID dmpId = this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntity1.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId();
|
||||||
DMP dmp1 = databaseRepository.getDmpDao().find(dmpId);
|
DMP dmp1 = databaseRepository.getDmpDao().find(dmpId);
|
||||||
dmp1.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
|
dmp1.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
|
||||||
updateTags(descriptionEntity1, datasetWizardModel.getTags());
|
//updateTags(descriptionEntity1, datasetWizardModel.getTags()); //TODO
|
||||||
if (sendNotification) {
|
if (sendNotification) {
|
||||||
if (descriptionEntity1.getStatus() != DescriptionStatus.Finalized) {
|
if (descriptionEntity1.getStatus() != DescriptionStatus.Finalized) {
|
||||||
this.sendNotification(descriptionEntity1, dmp1, userInfo, NotificationType.DATASET_MODIFIED);
|
this.sendNotification(descriptionEntity1, dmp1, userInfo, NotificationType.DATASET_MODIFIED);
|
||||||
|
@ -812,7 +812,7 @@ public class DatasetManager {
|
||||||
return jobject.toString();
|
return jobject.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateTags(DescriptionEntity descriptionEntityEntity, List<Tag> tags) throws Exception {
|
public void updateTags(DescriptionEntity descriptionEntityEntity, List<TagEntity> tags) throws Exception {
|
||||||
// if (datasetWizardModel.getTags() != null && !datasetWizardModel.getTags().isEmpty()) {
|
// if (datasetWizardModel.getTags() != null && !datasetWizardModel.getTags().isEmpty()) {
|
||||||
/*eu.eudat.elastic.entities.Dataset dataset = new eu.eudat.elastic.entities.Dataset();
|
/*eu.eudat.elastic.entities.Dataset dataset = new eu.eudat.elastic.entities.Dataset();
|
||||||
dataset.setId(datasetWizardModel.getId().toString());
|
dataset.setId(datasetWizardModel.getId().toString());
|
||||||
|
@ -867,9 +867,9 @@ public class DatasetManager {
|
||||||
dataset.setPublic(datasetWizardModel.getDmp().getPublic());
|
dataset.setPublic(datasetWizardModel.getDmp().getPublic());
|
||||||
dataset.setGrantStatus(datasetWizardModel.getDmp().getGrant().getStatus());
|
dataset.setGrantStatus(datasetWizardModel.getDmp().getGrant().getStatus());
|
||||||
dataset.setFormData(this.getWordDocumentText(datasetWizardModel));*/
|
dataset.setFormData(this.getWordDocumentText(datasetWizardModel));*/
|
||||||
DatasetMapper mapper = new DatasetMapper(apiContext, this);
|
// DatasetMapper mapper = new DatasetMapper(apiContext, this); //TODO
|
||||||
eu.eudat.elastic.entities.Dataset dataset = mapper.toElastic(descriptionEntityEntity, tags);
|
// eu.eudat.elastic.entities.Dataset dataset = mapper.toElastic(descriptionEntityEntity, tags);
|
||||||
apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().createOrUpdate(dataset);
|
// apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().createOrUpdate(dataset);
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1042,7 +1042,7 @@ public class DatasetManager {
|
||||||
UserInfo userInfo = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(this.userScope.getUserId()).build();
|
UserInfo userInfo = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(this.userScope.getUserId()).build();
|
||||||
entity.setDmpDescriptionTemplateId(userInfo.getId());
|
entity.setDmpDescriptionTemplateId(userInfo.getId());
|
||||||
|
|
||||||
updateTagsXmlImportDataset(apiContext.getOperationsContext().getElasticRepository().getDatasetRepository(), entity);
|
updateTagsXmlImportDataset(entity);
|
||||||
createRegistriesIfTheyDontExist(apiContext.getOperationsContext().getDatabaseRepository().getRegistryDao(), entity);
|
createRegistriesIfTheyDontExist(apiContext.getOperationsContext().getDatabaseRepository().getRegistryDao(), entity);
|
||||||
createDataRepositoriesIfTheyDontExist(apiContext.getOperationsContext().getDatabaseRepository().getDataRepositoryDao(), entity);
|
createDataRepositoriesIfTheyDontExist(apiContext.getOperationsContext().getDatabaseRepository().getDataRepositoryDao(), entity);
|
||||||
createServicesIfTheyDontExist(entity);
|
createServicesIfTheyDontExist(entity);
|
||||||
|
@ -1052,7 +1052,7 @@ public class DatasetManager {
|
||||||
return apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(entity);
|
return apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateTagsXmlImportDataset(DatasetRepository datasetRepository, DescriptionEntity descriptionEntity) throws IOException {
|
public void updateTagsXmlImportDataset(DescriptionEntity descriptionEntity) throws IOException {
|
||||||
// TODO: When tags functionality return.
|
// TODO: When tags functionality return.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1090,78 +1090,68 @@ public class DatasetManager {
|
||||||
List<DescriptionEntity> descriptionEntityEntities = new ArrayList<>(this.apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().asQueryable().toList());
|
List<DescriptionEntity> descriptionEntityEntities = new ArrayList<>(this.apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().asQueryable().toList());
|
||||||
descriptionEntityEntities.forEach(datasetEntity -> {
|
descriptionEntityEntities.forEach(datasetEntity -> {
|
||||||
try {
|
try {
|
||||||
eu.eudat.elastic.entities.Dataset dataset = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(datasetEntity.getId().toString());
|
|
||||||
UUID dmpId = this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(datasetEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId();
|
UUID dmpId = this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(datasetEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId();
|
||||||
DMP dmp = databaseRepository.getDmpDao().find(dmpId);
|
DMP dmp = databaseRepository.getDmpDao().find(dmpId);
|
||||||
dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
|
dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
|
||||||
updateTags(datasetEntity, dataset != null ? dataset.getTags() : null);
|
// eu.eudat.elastic.entities.Dataset dataset = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(datasetEntity.getId().toString()); //TODO
|
||||||
|
// updateTags(datasetEntity, dataset != null ? dataset.getTags() : null);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error(e.getMessage(), e);
|
logger.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//TODO
|
||||||
public void clearIndex() {
|
// public void getTagsFromProfile(DatasetWizardModel wizardModel, DescriptionEntity descriptionEntity) throws IOException, InvalidApplicationException {
|
||||||
if (this.authorizationService.authorize(Permission.AdminRole)) {
|
//// descriptionEntity.setDescriptionTemplateId(descriptionEntity.getDescriptionTemplateId()); //TODO
|
||||||
try {
|
// wizardModel.setDatasetProfileDefinition(this.getPagedProfile(wizardModel, descriptionEntity));
|
||||||
this.apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().clear();
|
// ObjectMapper mapper = new ObjectMapper();
|
||||||
} catch (IOException e) {
|
// String json = mapper.writeValueAsString(wizardModel.getDatasetProfileDefinition());
|
||||||
logger.error(e.getMessage(), e);
|
// JsonNode propertiesJson = mapper.readTree(json);
|
||||||
}
|
// DatasetCriteria criteria = new DatasetCriteria();
|
||||||
}
|
// criteria.setHasTags(true);
|
||||||
}
|
// List<Tag> tags = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().query(criteria).stream().map(eu.eudat.elastic.entities.Dataset::getTags).flatMap(Collection::stream).filter(StreamDistinctBy.distinctByKey(Tag::getId)).collect(Collectors.toList());
|
||||||
|
// Set<JsonNode> tagNodes = new HashSet<>();
|
||||||
public void getTagsFromProfile(DatasetWizardModel wizardModel, DescriptionEntity descriptionEntity) throws IOException, InvalidApplicationException {
|
// tagNodes.addAll(JsonSearcher.findNodes(propertiesJson, "renderStyle", "tags", true));
|
||||||
// descriptionEntity.setDescriptionTemplateId(descriptionEntity.getDescriptionTemplateId()); //TODO
|
// tagNodes.addAll(JsonSearcher.findNodes(propertiesJson, "schematics", "rda.dataset.keyword"));
|
||||||
wizardModel.setDatasetProfileDefinition(this.getPagedProfile(wizardModel, descriptionEntity));
|
// if(wizardModel.getTags() == null){
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
// wizardModel.setTags(new ArrayList<>());
|
||||||
String json = mapper.writeValueAsString(wizardModel.getDatasetProfileDefinition());
|
// }
|
||||||
JsonNode propertiesJson = mapper.readTree(json);
|
// if (!tagNodes.isEmpty()) {
|
||||||
DatasetCriteria criteria = new DatasetCriteria();
|
// tagNodes.forEach(node -> {
|
||||||
criteria.setHasTags(true);
|
// JsonNode value = node.get("value");
|
||||||
List<Tag> tags = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().query(criteria).stream().map(eu.eudat.elastic.entities.Dataset::getTags).flatMap(Collection::stream).filter(StreamDistinctBy.distinctByKey(Tag::getId)).collect(Collectors.toList());
|
// if (!value.toString().equals("\"\"") && !value.toString().equals("null")) {
|
||||||
Set<JsonNode> tagNodes = new HashSet<>();
|
// if (value.toString().startsWith("[")) {
|
||||||
tagNodes.addAll(JsonSearcher.findNodes(propertiesJson, "renderStyle", "tags", true));
|
// String stringValue = value.toString().replaceAll("=", ":");
|
||||||
tagNodes.addAll(JsonSearcher.findNodes(propertiesJson, "schematics", "rda.dataset.keyword"));
|
// JSONArray values = new JSONArray(stringValue);
|
||||||
if(wizardModel.getTags() == null){
|
// values.iterator().forEachRemaining(element -> {
|
||||||
wizardModel.setTags(new ArrayList<>());
|
// Map<String, Object> data = ((JSONObject) element).toMap();
|
||||||
}
|
// this.addTag(tags, wizardModel.getTags(), data.get("id").toString(), data.get("name").toString());
|
||||||
if (!tagNodes.isEmpty()) {
|
// });
|
||||||
tagNodes.forEach(node -> {
|
// } else {
|
||||||
JsonNode value = node.get("value");
|
// List<String> values = Arrays.asList(value.textValue().split(", "));
|
||||||
if (!value.toString().equals("\"\"") && !value.toString().equals("null")) {
|
// List<Tag> tagValues = values.stream().map(stringValue -> new Tag(stringValue, stringValue)).collect(Collectors.toList());
|
||||||
if (value.toString().startsWith("[")) {
|
// tagValues.iterator().forEachRemaining(tag -> {
|
||||||
String stringValue = value.toString().replaceAll("=", ":");
|
// this.addTag(tags, wizardModel.getTags(), tag.getId(), tag.getName());
|
||||||
JSONArray values = new JSONArray(stringValue);
|
// });
|
||||||
values.iterator().forEachRemaining(element -> {
|
// }
|
||||||
Map<String, Object> data = ((JSONObject) element).toMap();
|
// }
|
||||||
this.addTag(tags, wizardModel.getTags(), data.get("id").toString(), data.get("name").toString());
|
// });
|
||||||
});
|
// }
|
||||||
} else {
|
// }
|
||||||
List<String> values = Arrays.asList(value.textValue().split(", "));
|
//
|
||||||
List<Tag> tagValues = values.stream().map(stringValue -> new Tag(stringValue, stringValue)).collect(Collectors.toList());
|
// private void addTag(List<Tag> srcTags, List<Tag> dstTags, String id, String name) {
|
||||||
tagValues.iterator().forEachRemaining(tag -> {
|
// Tag tag = new Tag();
|
||||||
this.addTag(tags, wizardModel.getTags(), tag.getId(), tag.getName());
|
// if(srcTags.stream().anyMatch(intag -> intag.getName().equals(name))) {
|
||||||
});
|
// tag = srcTags.stream().filter(intag -> intag.getName().equals(name)).findFirst().get();
|
||||||
}
|
// } else {
|
||||||
}
|
// tag.setName(name);
|
||||||
});
|
// tag.setId(id);
|
||||||
}
|
// }
|
||||||
}
|
// if (dstTags.stream().noneMatch(intag -> intag.getName().equals(name))) {
|
||||||
|
// dstTags.add(tag);
|
||||||
private void addTag(List<Tag> srcTags, List<Tag> dstTags, String id, String name) {
|
// }
|
||||||
Tag tag = new Tag();
|
// }
|
||||||
if(srcTags.stream().anyMatch(intag -> intag.getName().equals(name))) {
|
|
||||||
tag = srcTags.stream().filter(intag -> intag.getName().equals(name)).findFirst().get();
|
|
||||||
} else {
|
|
||||||
tag.setName(name);
|
|
||||||
tag.setId(id);
|
|
||||||
}
|
|
||||||
if (dstTags.stream().noneMatch(intag -> intag.getName().equals(name))) {
|
|
||||||
dstTags.add(tag);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
private DatasetListingModel mapModel(DescriptionEntity item) {
|
private DatasetListingModel mapModel(DescriptionEntity item) {
|
||||||
|
|
|
@ -65,12 +65,12 @@ public class DatasetWizardManager {
|
||||||
|
|
||||||
public void delete(ApiContext apiContext, UUID uuid) throws IOException, InvalidApplicationException {
|
public void delete(ApiContext apiContext, UUID uuid) throws IOException, InvalidApplicationException {
|
||||||
DescriptionEntity oldDescriptionEntity = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().find(uuid);
|
DescriptionEntity oldDescriptionEntity = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().find(uuid);
|
||||||
eu.eudat.elastic.entities.Dataset oldDatasetElasitc = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(uuid.toString());
|
// eu.eudat.elastic.entities.Dataset oldDatasetElasitc = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(uuid.toString()); //TODO
|
||||||
oldDescriptionEntity.setIsActive(IsActive.Inactive);
|
oldDescriptionEntity.setIsActive(IsActive.Inactive);
|
||||||
apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(oldDescriptionEntity);
|
apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(oldDescriptionEntity);
|
||||||
if (oldDatasetElasitc != null && uuid != null && oldDatasetElasitc.getId()!= null) {
|
// if (oldDatasetElasitc != null && uuid != null && oldDatasetElasitc.getId()!= null) {
|
||||||
oldDatasetElasitc.setStatus(oldDescriptionEntity.getStatus().getValue());
|
// oldDatasetElasitc.setStatus(oldDescriptionEntity.getStatus().getValue());
|
||||||
apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().createOrUpdate(oldDatasetElasitc);
|
// apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().createOrUpdate(oldDatasetElasitc);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,7 +129,7 @@ public class InvitationsManager {
|
||||||
invitation.setAcceptedInvitation(true);
|
invitation.setAcceptedInvitation(true);
|
||||||
apiContext.getOperationsContext().getDatabaseRepository().getInvitationDao().createOrUpdate(invitation);
|
apiContext.getOperationsContext().getDatabaseRepository().getInvitationDao().createOrUpdate(invitation);
|
||||||
datamanagementPlan.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), datamanagementPlan.getId())).toList()));
|
datamanagementPlan.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), datamanagementPlan.getId())).toList()));
|
||||||
dataManagementPlanManager.updateIndex(datamanagementPlan);
|
//dataManagementPlanManager.updateIndex(datamanagementPlan); //TODO
|
||||||
return datamanagementPlan.getId();
|
return datamanagementPlan.getId();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -154,7 +154,7 @@ public class InvitationsManager {
|
||||||
invitation.setAcceptedInvitation(true);
|
invitation.setAcceptedInvitation(true);
|
||||||
apiContext.getOperationsContext().getDatabaseRepository().getInvitationDao().createOrUpdate(invitation);
|
apiContext.getOperationsContext().getDatabaseRepository().getInvitationDao().createOrUpdate(invitation);
|
||||||
datamanagementPlan.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), datamanagementPlan.getId())).toList()));
|
datamanagementPlan.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), datamanagementPlan.getId())).toList()));
|
||||||
dataManagementPlanManager.updateIndex(datamanagementPlan);
|
// dataManagementPlanManager.updateIndex(datamanagementPlan); //TODo
|
||||||
return datamanagementPlan.getId();
|
return datamanagementPlan.getId();
|
||||||
}
|
}
|
||||||
return invitation.getDmp().getId();
|
return invitation.getDmp().getId();
|
||||||
|
|
|
@ -5,10 +5,6 @@ import eu.eudat.data.CredentialEntity;
|
||||||
import eu.eudat.data.old.EmailConfirmation;
|
import eu.eudat.data.old.EmailConfirmation;
|
||||||
import eu.eudat.data.old.UserDMP;
|
import eu.eudat.data.old.UserDMP;
|
||||||
import eu.eudat.data.old.UserInfo;
|
import eu.eudat.data.old.UserInfo;
|
||||||
import eu.eudat.elastic.criteria.DmpCriteria;
|
|
||||||
import eu.eudat.elastic.entities.Collaborator;
|
|
||||||
import eu.eudat.elastic.entities.Dmp;
|
|
||||||
import eu.eudat.elastic.repository.DmpRepository;
|
|
||||||
import eu.eudat.exceptions.emailconfirmation.HasConfirmedEmailException;
|
import eu.eudat.exceptions.emailconfirmation.HasConfirmedEmailException;
|
||||||
import eu.eudat.exceptions.emailconfirmation.TokenExpiredException;
|
import eu.eudat.exceptions.emailconfirmation.TokenExpiredException;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
import eu.eudat.logic.services.ApiContext;
|
||||||
|
@ -32,14 +28,14 @@ public class MergeEmailConfirmationManager {
|
||||||
private static Logger logger = LoggerFactory.getLogger(MergeEmailConfirmationManager.class);
|
private static Logger logger = LoggerFactory.getLogger(MergeEmailConfirmationManager.class);
|
||||||
private ApiContext apiContext;
|
private ApiContext apiContext;
|
||||||
private DatabaseRepository databaseRepository;
|
private DatabaseRepository databaseRepository;
|
||||||
private DmpRepository dmpRepository;
|
// private DmpRepository dmpRepository;
|
||||||
private final UserScope userScope;
|
private final UserScope userScope;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public MergeEmailConfirmationManager(ApiContext apiContext, UserScope userScope) {
|
public MergeEmailConfirmationManager(ApiContext apiContext, UserScope userScope) {
|
||||||
this.apiContext = apiContext;
|
this.apiContext = apiContext;
|
||||||
this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository();
|
this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository();
|
||||||
this.dmpRepository = apiContext.getOperationsContext().getElasticRepository().getDmpRepository();
|
// this.dmpRepository = apiContext.getOperationsContext().getElasticRepository().getDmpRepository();
|
||||||
this.userScope = userScope;
|
this.userScope = userScope;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,38 +93,40 @@ public class MergeEmailConfirmationManager {
|
||||||
userDmp.setUser(newUser);
|
userDmp.setUser(newUser);
|
||||||
databaseRepository.getUserDmpDao().createOrUpdate(userDmp);
|
databaseRepository.getUserDmpDao().createOrUpdate(userDmp);
|
||||||
});
|
});
|
||||||
try {
|
//TODO
|
||||||
DmpCriteria dmpCriteria = new DmpCriteria();
|
// try {
|
||||||
dmpCriteria.setCollaborators(Collections.singletonList(oldUser.getId()));
|
//
|
||||||
List<Dmp> elasticDmpsIds = dmpRepository.query(dmpCriteria);
|
// DmpCriteria dmpCriteria = new DmpCriteria();
|
||||||
for(Dmp dmpId: elasticDmpsIds){
|
// dmpCriteria.setCollaborators(Collections.singletonList(oldUser.getId()));
|
||||||
Dmp dmp = dmpRepository.findDocument(dmpId.getId().toString());
|
// List<Dmp> elasticDmpsIds = dmpRepository.query(dmpCriteria);
|
||||||
if(dmp.getDatasets() != null) {
|
// for(Dmp dmpId: elasticDmpsIds){
|
||||||
dmp.getDatasets().forEach(dataset -> {
|
// Dmp dmp = dmpRepository.findDocument(dmpId.getId().toString());
|
||||||
if(dataset.getCollaborators() != null) {
|
// if(dmp.getDatasets() != null) {
|
||||||
for (Collaborator collaborator : dataset.getCollaborators()) {
|
// dmp.getDatasets().forEach(dataset -> {
|
||||||
if (collaborator.getId().equals(oldUser.getId().toString())) {
|
// if(dataset.getCollaborators() != null) {
|
||||||
collaborator.setId(newUser.getId().toString());
|
// for (Collaborator collaborator : dataset.getCollaborators()) {
|
||||||
collaborator.setName(newUser.getName());
|
// if (collaborator.getId().equals(oldUser.getId().toString())) {
|
||||||
}
|
// collaborator.setId(newUser.getId().toString());
|
||||||
}
|
// collaborator.setName(newUser.getName());
|
||||||
}
|
// }
|
||||||
});
|
// }
|
||||||
}
|
// }
|
||||||
if(dmp.getCollaborators() != null) {
|
// });
|
||||||
for (Collaborator collaborator : dmp.getCollaborators()) {
|
// }
|
||||||
if (collaborator.getId().equals(oldUser.getId().toString())) {
|
// if(dmp.getCollaborators() != null) {
|
||||||
collaborator.setId(newUser.getId().toString());
|
// for (Collaborator collaborator : dmp.getCollaborators()) {
|
||||||
collaborator.setName(newUser.getName());
|
// if (collaborator.getId().equals(oldUser.getId().toString())) {
|
||||||
}
|
// collaborator.setId(newUser.getId().toString());
|
||||||
}
|
// collaborator.setName(newUser.getName());
|
||||||
}
|
// }
|
||||||
dmpRepository.createOrUpdate(dmp);
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// dmpRepository.createOrUpdate(dmp);
|
||||||
catch (IOException e){
|
// }
|
||||||
logger.warn("Warning: Could not fetch dmps from elastic.", e);
|
// }
|
||||||
}
|
// catch (IOException e){
|
||||||
|
// logger.warn("Warning: Could not fetch dmps from elastic.", e);
|
||||||
|
// }
|
||||||
oldUser.setUserStatus((short)1);
|
oldUser.setUserStatus((short)1);
|
||||||
oldUser.setEmail(null);
|
oldUser.setEmail(null);
|
||||||
List<CredentialEntity> credentials = databaseRepository.getCredentialDao().asQueryable().where((builder, root) -> builder.equal(root.get("userId"), oldUser.getId())).toList();
|
List<CredentialEntity> credentials = databaseRepository.getCredentialDao().asQueryable().where((builder, root) -> builder.equal(root.get("userId"), oldUser.getId())).toList();
|
||||||
|
|
|
@ -5,8 +5,6 @@ import eu.eudat.data.dao.criteria.FunderCriteria;
|
||||||
import eu.eudat.data.dao.criteria.GrantCriteria;
|
import eu.eudat.data.dao.criteria.GrantCriteria;
|
||||||
import eu.eudat.data.dao.criteria.ProjectCriteria;
|
import eu.eudat.data.dao.criteria.ProjectCriteria;
|
||||||
import eu.eudat.data.old.*;
|
import eu.eudat.data.old.*;
|
||||||
import eu.eudat.elastic.entities.Dmp;
|
|
||||||
import eu.eudat.logic.mapper.elastic.DmpMapper;
|
|
||||||
import eu.eudat.logic.services.ApiContext;
|
import eu.eudat.logic.services.ApiContext;
|
||||||
import eu.eudat.logic.services.operations.DatabaseRepository;
|
import eu.eudat.logic.services.operations.DatabaseRepository;
|
||||||
import eu.eudat.models.data.dmp.DataManagementPlan;
|
import eu.eudat.models.data.dmp.DataManagementPlan;
|
||||||
|
@ -71,16 +69,16 @@ public class QuickWizardManager {
|
||||||
if (dataManagementPlan.getAssociatedUsers().size() == 0)
|
if (dataManagementPlan.getAssociatedUsers().size() == 0)
|
||||||
assignUser(newDmp, user, apiContext);
|
assignUser(newDmp, user, apiContext);
|
||||||
|
|
||||||
this.updateIndex(dmpret);
|
// this.updateIndex(dmpret);
|
||||||
|
|
||||||
return dmpret;
|
return dmpret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateIndex(DMP dmp) throws IOException, InvalidApplicationException {
|
// private void updateIndex(DMP dmp) throws IOException, InvalidApplicationException {
|
||||||
DmpMapper mapper = new DmpMapper(apiContext, datasetManager);
|
// DmpMapper mapper = new DmpMapper(apiContext, datasetManager);
|
||||||
Dmp elastic = mapper.toElastic(dmp);
|
// Dmp elastic = mapper.toElastic(dmp);
|
||||||
apiContext.getOperationsContext().getElasticRepository().getDmpRepository().createOrUpdate(elastic);
|
// apiContext.getOperationsContext().getElasticRepository().getDmpRepository().createOrUpdate(elastic);
|
||||||
}
|
// }
|
||||||
|
|
||||||
private void assignUser(DMP dmp, UserInfo userInfo, ApiContext apiContext) {
|
private void assignUser(DMP dmp, UserInfo userInfo, ApiContext apiContext) {
|
||||||
UserDMP userDMP = new UserDMP();
|
UserDMP userDMP = new UserDMP();
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
package eu.eudat.logic.mapper.elastic;
|
|
||||||
|
|
||||||
import eu.eudat.data.old.UserInfo;
|
|
||||||
import eu.eudat.elastic.entities.Collaborator;
|
|
||||||
|
|
||||||
public class CollaboratorMapper {
|
|
||||||
|
|
||||||
public static Collaborator toElastic(UserInfo user, Integer role) {
|
|
||||||
Collaborator elastic = new Collaborator();
|
|
||||||
elastic.setId(user.getId().toString());
|
|
||||||
elastic.setName(user.getName());
|
|
||||||
elastic.setRole(role);
|
|
||||||
return elastic;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,83 +0,0 @@
|
||||||
package eu.eudat.logic.mapper.elastic;
|
|
||||||
|
|
||||||
import eu.eudat.data.DescriptionEntity;
|
|
||||||
import eu.eudat.elastic.entities.Dataset;
|
|
||||||
import eu.eudat.elastic.entities.Tag;
|
|
||||||
import eu.eudat.logic.managers.DatasetManager;
|
|
||||||
import eu.eudat.logic.services.ApiContext;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class DatasetMapper {
|
|
||||||
|
|
||||||
private final ApiContext apiContext;
|
|
||||||
private final DatasetManager datasetManager;
|
|
||||||
|
|
||||||
public DatasetMapper(ApiContext apiContext, DatasetManager datasetManager) {
|
|
||||||
this.apiContext = apiContext;
|
|
||||||
this.datasetManager = datasetManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Dataset toElastic(DescriptionEntity descriptionEntity, List<Tag> tags) throws Exception {
|
|
||||||
//TODO
|
|
||||||
// if (descriptionEntity.getDescriptionTemplateId() == null) {
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
Dataset elastic = new Dataset();
|
|
||||||
// elastic.setId(descriptionEntity.getId().toString());
|
|
||||||
// if (tags != null && !tags.isEmpty()) {
|
|
||||||
// DatasetCriteria criteria = new DatasetCriteria();
|
|
||||||
// criteria.setTags(tags);
|
|
||||||
// criteria.setHasTags(true);
|
|
||||||
// List<Tag> tags1 = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().query(criteria).stream().map(eu.eudat.elastic.entities.Dataset::getTags).flatMap(Collection::stream)
|
|
||||||
// .filter(StreamDistinctBy.distinctByKey(Tag::getId)).filter(tag -> tags.stream().anyMatch(tag1 -> tag1.getName().equals(tag.getName()))).collect(Collectors.toList());
|
|
||||||
// if (tags1.isEmpty()) {
|
|
||||||
// tags.forEach(tag -> tag.setId(UUID.randomUUID().toString()));
|
|
||||||
// elastic.setTags(tags);
|
|
||||||
// } else {
|
|
||||||
// if (tags1.size() < tags.size()) {
|
|
||||||
// tags.stream().filter(tag -> tag.getId() == null || tag.getId().equals("")).forEach(tag -> tags1.add(new Tag(UUID.randomUUID().toString(), tag.getName())));
|
|
||||||
// }
|
|
||||||
// elastic.setTags(tags1);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// elastic.setLabel(descriptionEntity.getLabel());
|
|
||||||
// elastic.setDescription(descriptionEntity.getDescription());
|
|
||||||
// elastic.setTemplate(descriptionEntity.getProfile().getId());
|
|
||||||
// elastic.setStatus(descriptionEntity.getStatus());
|
|
||||||
// elastic.setDmp(descriptionEntity.getDmp().getId());
|
|
||||||
// elastic.setGroup(descriptionEntity.getDmp().getGroupId());
|
|
||||||
// if (descriptionEntity.getDmp().getGrant() != null) {
|
|
||||||
// elastic.setGrant(descriptionEntity.getDmp().getGrant().getId());
|
|
||||||
// }
|
|
||||||
// elastic.setCreated(descriptionEntity.getCreated());
|
|
||||||
// elastic.setModified(descriptionEntity.getModified());
|
|
||||||
// elastic.setFinalizedAt(descriptionEntity.getFinalizedAt());
|
|
||||||
// if (descriptionEntity.getDmp().getUsers() != null) {
|
|
||||||
// elastic.setCollaborators(descriptionEntity.getDmp().getUsers().stream().map(user -> CollaboratorMapper.toElastic(user.getUser(), user.getRole())).collect(Collectors.toList()));
|
|
||||||
// }
|
|
||||||
// DataManagementPlanCriteria dmpCriteria = new DataManagementPlanCriteria();
|
|
||||||
// dmpCriteria.setAllVersions(true);
|
|
||||||
// dmpCriteria.setGroupIds(Collections.singletonList(descriptionEntity.getDmp().getGroupId()));
|
|
||||||
// apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(dmpCriteria).toList().stream()
|
|
||||||
// .max(Comparator.comparing(DMP::getVersion)).ifPresent(dmp -> elastic.setLastVersion(dmp.getId().equals(descriptionEntity.getDmp().getId())));
|
|
||||||
// apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(dmpCriteria).toList().stream().filter(DMP::isPublic)
|
|
||||||
// .max(Comparator.comparing(DMP::getVersion)).ifPresent(dmp -> elastic.setLastPublicVersion(dmp.getId().equals(descriptionEntity.getDmp().getId())));
|
|
||||||
// if (elastic.getLastVersion() == null) {
|
|
||||||
// elastic.setLastVersion(true);
|
|
||||||
// }
|
|
||||||
// if (elastic.getLastPublicVersion() == null) {
|
|
||||||
// elastic.setLastPublicVersion(false);
|
|
||||||
// }
|
|
||||||
// if (descriptionEntity.getDmp().getOrganisations() != null) {
|
|
||||||
// elastic.setOrganizations(descriptionEntity.getDmp().getOrganisations().stream().map(OrganizationMapper::toElastic).collect(Collectors.toList()));
|
|
||||||
// }
|
|
||||||
// elastic.setPublic(descriptionEntity.getDmp().isPublic());
|
|
||||||
// if (descriptionEntity.getDmp().getGrant() != null) {
|
|
||||||
// elastic.setGrantStatus(descriptionEntity.getDmp().getGrant().getStatus());
|
|
||||||
// }
|
|
||||||
// elastic.setFormData(datasetManager.getWordDocumentText(descriptionEntity));
|
|
||||||
|
|
||||||
return elastic;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
package eu.eudat.logic.mapper.elastic;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import eu.eudat.data.old.DMPDatasetProfile;
|
|
||||||
import eu.eudat.elastic.entities.DatasetTempalate;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class DatasetTemplateMapper {
|
|
||||||
|
|
||||||
public static DatasetTempalate toElastic(DMPDatasetProfile profile) {
|
|
||||||
DatasetTempalate elastic = new DatasetTempalate();
|
|
||||||
elastic.setId(profile.getDatasetprofile().getId());
|
|
||||||
elastic.setName(profile.getDatasetprofile().getLabel());
|
|
||||||
try {
|
|
||||||
elastic.setData(new ObjectMapper().readValue(profile.getData(), new TypeReference<Map<String, Object>>() {}));
|
|
||||||
}
|
|
||||||
catch (Exception e){
|
|
||||||
elastic.setData(new HashMap<>());
|
|
||||||
}
|
|
||||||
return elastic;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,92 +0,0 @@
|
||||||
package eu.eudat.logic.mapper.elastic;
|
|
||||||
|
|
||||||
import eu.eudat.data.dao.criteria.DataManagementPlanCriteria;
|
|
||||||
import eu.eudat.data.old.DMP;
|
|
||||||
import eu.eudat.elastic.entities.Dataset;
|
|
||||||
import eu.eudat.elastic.entities.Dmp;
|
|
||||||
import eu.eudat.elastic.entities.Tag;
|
|
||||||
import eu.eudat.logic.managers.DatasetManager;
|
|
||||||
import eu.eudat.logic.services.ApiContext;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import javax.management.InvalidApplicationException;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class DmpMapper {
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(DmpMapper.class);
|
|
||||||
|
|
||||||
private final ApiContext apiContext;
|
|
||||||
private final DatasetManager datasetManager;
|
|
||||||
private final DatasetMapper datasetMapper;
|
|
||||||
|
|
||||||
public DmpMapper(ApiContext apiContext, DatasetManager datasetManager) {
|
|
||||||
this.apiContext = apiContext;
|
|
||||||
this.datasetManager = datasetManager;
|
|
||||||
this.datasetMapper = new DatasetMapper(apiContext, datasetManager);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Dmp toElastic(DMP dmp) throws InvalidApplicationException {
|
|
||||||
Dmp elastic = new Dmp();
|
|
||||||
elastic.setId(dmp.getId());
|
|
||||||
elastic.setGroupId(dmp.getGroupId());
|
|
||||||
if (dmp.getUsers() != null) {
|
|
||||||
elastic.setCollaborators(dmp.getUsers().stream().map(user -> CollaboratorMapper.toElastic(user.getUser(), user.getRole())).collect(Collectors.toList()));
|
|
||||||
}
|
|
||||||
elastic.setDescription(dmp.getDescription());
|
|
||||||
if (dmp.getGrant() != null) {
|
|
||||||
elastic.setGrant(dmp.getGrant().getId());
|
|
||||||
}
|
|
||||||
elastic.setLabel(dmp.getLabel());
|
|
||||||
elastic.setPublic(dmp.isPublic());
|
|
||||||
elastic.setStatus(dmp.getStatus());
|
|
||||||
elastic.setCreated(dmp.getCreated());
|
|
||||||
elastic.setModified(dmp.getModified());
|
|
||||||
elastic.setFinalizedAt(dmp.getFinalizedAt());
|
|
||||||
elastic.setPublishedAt(dmp.getPublishedAt());
|
|
||||||
DataManagementPlanCriteria dmpCriteria = new DataManagementPlanCriteria();
|
|
||||||
dmpCriteria.setAllVersions(true);
|
|
||||||
dmpCriteria.setGroupIds(Collections.singletonList(dmp.getGroupId()));
|
|
||||||
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(dmpCriteria).toList().stream()
|
|
||||||
.max(Comparator.comparing(DMP::getVersion)).ifPresent(dmp1 -> elastic.setLastVersion(dmp1.getId().equals(dmp.getId())));
|
|
||||||
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(dmpCriteria).toList().stream().filter(DMP::isPublic)
|
|
||||||
.max(Comparator.comparing(DMP::getVersion)).ifPresent(dmp1 -> elastic.setLastPublicVersion(dmp1.getId().equals(dmp.getId())));
|
|
||||||
if (elastic.getLastVersion() == null) {
|
|
||||||
elastic.setLastVersion(false);
|
|
||||||
}
|
|
||||||
if (elastic.getLastPublicVersion() == null) {
|
|
||||||
elastic.setLastPublicVersion(false);
|
|
||||||
}
|
|
||||||
if (dmp.getDataset() != null) {
|
|
||||||
|
|
||||||
elastic.setDatasets(dmp.getDataset().stream().filter(dataset -> dataset.getId() != null).map(dataset -> {
|
|
||||||
List<Tag> tags = null;
|
|
||||||
try {
|
|
||||||
Dataset dataset1 = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(dataset.getId().toString());
|
|
||||||
if (dataset1 != null) {
|
|
||||||
tags = dataset1.getTags();
|
|
||||||
}
|
|
||||||
//dataset.setDmpId(dmp.getId()); //TODO
|
|
||||||
return datasetMapper.toElastic(dataset, tags);
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}).filter(Objects::nonNull).collect(Collectors.toList()));
|
|
||||||
}
|
|
||||||
if (dmp.getAssociatedDmps() != null) {
|
|
||||||
elastic.setTemplates(dmp.getAssociatedDmps().stream().map(DatasetTemplateMapper::toElastic).collect(Collectors.toList()));
|
|
||||||
}
|
|
||||||
if (dmp.getOrganisations() != null) {
|
|
||||||
elastic.setOrganizations(dmp.getOrganisations().stream().map(OrganizationMapper::toElastic).collect(Collectors.toList()));
|
|
||||||
}
|
|
||||||
if (dmp.getGrant() != null) {
|
|
||||||
elastic.setGrantStatus(dmp.getGrant().getStatus());
|
|
||||||
}
|
|
||||||
return elastic;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
package eu.eudat.logic.mapper.elastic;
|
|
||||||
|
|
||||||
import eu.eudat.data.old.Organisation;
|
|
||||||
import eu.eudat.elastic.entities.Organization;
|
|
||||||
|
|
||||||
public class OrganizationMapper {
|
|
||||||
|
|
||||||
public static Organization toElastic(Organisation organisation) {
|
|
||||||
Organization elastic = new Organization();
|
|
||||||
elastic.setId(organisation.getId().toString());
|
|
||||||
elastic.setName(organisation.getLabel());
|
|
||||||
return elastic;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,59 +0,0 @@
|
||||||
package eu.eudat.logic.mapper.elastic.criteria;
|
|
||||||
|
|
||||||
import eu.eudat.data.dao.criteria.DataManagementPlanCriteria;
|
|
||||||
import eu.eudat.data.old.Grant;
|
|
||||||
import eu.eudat.data.query.definition.helpers.ColumnOrderings;
|
|
||||||
import eu.eudat.data.query.definition.helpers.Ordering;
|
|
||||||
import eu.eudat.elastic.criteria.DmpCriteria;
|
|
||||||
import eu.eudat.elastic.criteria.SortCriteria;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class DmpCriteriaMapper {
|
|
||||||
|
|
||||||
public static DmpCriteria toElasticCriteria(DataManagementPlanCriteria criteria, UUID principalID) {
|
|
||||||
DmpCriteria elastic = new DmpCriteria();
|
|
||||||
|
|
||||||
elastic.setAllowAllVersions(criteria.getAllVersions());
|
|
||||||
elastic.setCollaborators(criteria.getCollaborators());
|
|
||||||
if (criteria.getGrants() != null) {
|
|
||||||
elastic.setGrants(criteria.getGrants().stream().map(Grant::getId).collect(Collectors.toList()));
|
|
||||||
}
|
|
||||||
elastic.setGroupIds(criteria.getGroupIds());
|
|
||||||
elastic.setLike(criteria.getLike());
|
|
||||||
if (criteria.getOrganisations() != null) {
|
|
||||||
elastic.setOrganizations(criteria.getOrganisations().stream().map(UUID::fromString).collect(Collectors.toList()));
|
|
||||||
}
|
|
||||||
elastic.setPublic(criteria.getIsPublic());
|
|
||||||
if (!elastic.isPublic()) {
|
|
||||||
elastic.setCollaborators(Collections.singletonList(principalID));
|
|
||||||
}
|
|
||||||
if (criteria.getRole() != null) {
|
|
||||||
elastic.setRoles(Collections.singletonList(criteria.getRole()));
|
|
||||||
}
|
|
||||||
if (criteria.getStatus() != null) {
|
|
||||||
elastic.setStatus(criteria.getStatus().shortValue());
|
|
||||||
}
|
|
||||||
elastic.setTemplates(criteria.getDatasetTemplates());
|
|
||||||
elastic.setGrantStatus(criteria.getGrantStatus());
|
|
||||||
return elastic;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<SortCriteria> toElasticSorting(ColumnOrderings columnOrderings) {
|
|
||||||
List<SortCriteria> sortCriteria = new ArrayList<>();
|
|
||||||
if (columnOrderings.getFieldOrderings() != null && !columnOrderings.getFieldOrderings().isEmpty()) {
|
|
||||||
for (Ordering ordering: columnOrderings.getFieldOrderings()) {
|
|
||||||
SortCriteria sortCriteria1 = new SortCriteria();
|
|
||||||
sortCriteria1.setFieldName(ordering.getFieldName() + (ordering.getFieldName().contains("label") ?".keyword" : ""));
|
|
||||||
sortCriteria1.setColumnType(ordering.getColumnType() != null ? SortCriteria.ColumnType.valueOf(ordering.getColumnType().name()): SortCriteria.ColumnType.COLUMN);
|
|
||||||
sortCriteria1.setOrderByType(SortCriteria.OrderByType.valueOf(ordering.getOrderByType().name()));
|
|
||||||
sortCriteria.add(sortCriteria1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sortCriteria;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -6,7 +6,7 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import eu.eudat.data.DescriptionEntity;
|
import eu.eudat.data.DescriptionEntity;
|
||||||
import eu.eudat.data.DescriptionTemplateEntity;
|
import eu.eudat.data.DescriptionTemplateEntity;
|
||||||
import eu.eudat.elastic.entities.Tag;
|
import eu.eudat.data.TagEntity;
|
||||||
import eu.eudat.logic.managers.DatasetManager;
|
import eu.eudat.logic.managers.DatasetManager;
|
||||||
import eu.eudat.logic.managers.DatasetProfileManager;
|
import eu.eudat.logic.managers.DatasetProfileManager;
|
||||||
import eu.eudat.logic.managers.LicenseManager;
|
import eu.eudat.logic.managers.LicenseManager;
|
||||||
|
@ -270,13 +270,13 @@ public class PrefillingMapper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<Tag> parseTags(String value) throws JsonProcessingException {
|
private static List<TagEntity> parseTags(String value) throws JsonProcessingException {
|
||||||
if (value == null || value.isEmpty())
|
if (value == null || value.isEmpty())
|
||||||
return new LinkedList<>();
|
return new LinkedList<>();
|
||||||
String[] rawTags = value.split(", ");
|
String[] rawTags = value.split(", ");
|
||||||
List<Tag> parsedTags = new LinkedList<>();
|
List<TagEntity> parsedTags = new LinkedList<>();
|
||||||
for (String rawTag : rawTags) {
|
for (String rawTag : rawTags) {
|
||||||
parsedTags.add(new Tag(rawTag, rawTag));
|
parsedTags.add(new TagEntity());
|
||||||
}
|
}
|
||||||
return parsedTags;
|
return parsedTags;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
package eu.eudat.logic.services.operations;
|
|
||||||
|
|
||||||
import eu.eudat.elastic.repository.DatasetRepository;
|
|
||||||
import eu.eudat.elastic.repository.DmpRepository;
|
|
||||||
|
|
||||||
public interface ElasticRepository {
|
|
||||||
|
|
||||||
DatasetRepository getDatasetRepository();
|
|
||||||
|
|
||||||
DmpRepository getDmpRepository();
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
package eu.eudat.logic.services.operations;
|
|
||||||
|
|
||||||
import eu.eudat.elastic.repository.DatasetRepository;
|
|
||||||
import eu.eudat.elastic.repository.DmpRepository;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service("elasticRepository")
|
|
||||||
public class ElasticRepositoryImpl implements ElasticRepository {
|
|
||||||
|
|
||||||
private final DatasetRepository datasetRepository;
|
|
||||||
private final DmpRepository dmpRepository;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public ElasticRepositoryImpl(DatasetRepository datasetRepository, DmpRepository dmpRepository) {
|
|
||||||
this.datasetRepository = datasetRepository;
|
|
||||||
this.dmpRepository = dmpRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DatasetRepository getDatasetRepository() {
|
|
||||||
return datasetRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DmpRepository getDmpRepository() {
|
|
||||||
return dmpRepository;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,7 +1,5 @@
|
||||||
package eu.eudat.logic.services.operations;
|
package eu.eudat.logic.services.operations;
|
||||||
|
|
||||||
import eu.eudat.elastic.repository.DatasetRepository;
|
|
||||||
import eu.eudat.elastic.repository.DmpRepository;
|
|
||||||
import eu.eudat.logic.builders.BuilderFactory;
|
import eu.eudat.logic.builders.BuilderFactory;
|
||||||
import eu.eudat.logic.proxy.fetching.RemoteFetcher;
|
import eu.eudat.logic.proxy.fetching.RemoteFetcher;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
@ -21,5 +19,5 @@ public interface OperationsContext {
|
||||||
|
|
||||||
// FileStorageService getFileStorageService();
|
// FileStorageService getFileStorageService();
|
||||||
|
|
||||||
ElasticRepository getElasticRepository();
|
// ElasticRepository getElasticRepository();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package eu.eudat.logic.services.operations;
|
package eu.eudat.logic.services.operations;
|
||||||
|
|
||||||
import eu.eudat.elastic.repository.DatasetRepository;
|
|
||||||
import eu.eudat.elastic.repository.DmpRepository;
|
|
||||||
import eu.eudat.logic.builders.BuilderFactory;
|
import eu.eudat.logic.builders.BuilderFactory;
|
||||||
import eu.eudat.logic.proxy.fetching.RemoteFetcher;
|
import eu.eudat.logic.proxy.fetching.RemoteFetcher;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -19,17 +17,17 @@ public class OperationsContextImpl implements OperationsContext {
|
||||||
private final RemoteFetcher remoteFetcher;
|
private final RemoteFetcher remoteFetcher;
|
||||||
private final BuilderFactory builderFactory;
|
private final BuilderFactory builderFactory;
|
||||||
// private final FileStorageService fileStorageService;
|
// private final FileStorageService fileStorageService;
|
||||||
private final ElasticRepository elasticRepository;
|
// private final ElasticRepository elasticRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public OperationsContextImpl(DatabaseRepository databaseRepository, ApplicationContext applicationContext, RemoteFetcher remoteFetcher
|
public OperationsContextImpl(DatabaseRepository databaseRepository, ApplicationContext applicationContext, RemoteFetcher remoteFetcher
|
||||||
, BuilderFactory builderFactory, /*FileStorageService fileStorageService,*/ ElasticRepository elasticRepository) {
|
, BuilderFactory builderFactory/*FileStorageService fileStorageService, ElasticRepository elasticRepository*/) {
|
||||||
this.databaseRepository = databaseRepository;
|
this.databaseRepository = databaseRepository;
|
||||||
this.applicationContext = applicationContext;
|
this.applicationContext = applicationContext;
|
||||||
this.remoteFetcher = remoteFetcher;
|
this.remoteFetcher = remoteFetcher;
|
||||||
this.builderFactory = builderFactory;
|
this.builderFactory = builderFactory;
|
||||||
// this.fileStorageService = fileStorageService;
|
// this.fileStorageService = fileStorageService;
|
||||||
this.elasticRepository = elasticRepository;
|
// this.elasticRepository = elasticRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -57,8 +55,8 @@ public class OperationsContextImpl implements OperationsContext {
|
||||||
// return fileStorageService;
|
// return fileStorageService;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public ElasticRepository getElasticRepository() {
|
// public ElasticRepository getElasticRepository() {
|
||||||
return elasticRepository;
|
// return elasticRepository;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,6 @@ package eu.eudat.models.data.datasetwizard;
|
||||||
|
|
||||||
import eu.eudat.commons.enums.DescriptionStatus;
|
import eu.eudat.commons.enums.DescriptionStatus;
|
||||||
import eu.eudat.data.DescriptionEntity;
|
import eu.eudat.data.DescriptionEntity;
|
||||||
import eu.eudat.data.DescriptionTemplateEntity;
|
|
||||||
import eu.eudat.data.old.*;
|
|
||||||
import eu.eudat.elastic.entities.Tag;
|
|
||||||
import eu.eudat.models.DataModel;
|
import eu.eudat.models.DataModel;
|
||||||
import eu.eudat.models.data.dataset.DataRepository;
|
import eu.eudat.models.data.dataset.DataRepository;
|
||||||
import eu.eudat.models.data.dataset.Registry;
|
import eu.eudat.models.data.dataset.Registry;
|
||||||
|
@ -13,11 +10,10 @@ import eu.eudat.models.data.datasetprofile.DatasetProfileOverviewModel;
|
||||||
import eu.eudat.models.data.dmp.DataManagementPlan;
|
import eu.eudat.models.data.dmp.DataManagementPlan;
|
||||||
import eu.eudat.models.data.externaldataset.ExternalDatasetListingModel;
|
import eu.eudat.models.data.externaldataset.ExternalDatasetListingModel;
|
||||||
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
|
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
|
||||||
import net.minidev.json.JSONValue;
|
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.*;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
||||||
public class DatasetWizardModel implements DataModel<DescriptionEntity, DatasetWizardModel> {
|
public class DatasetWizardModel implements DataModel<DescriptionEntity, DatasetWizardModel> {
|
||||||
|
@ -35,7 +31,7 @@ public class DatasetWizardModel implements DataModel<DescriptionEntity, DatasetW
|
||||||
private List<Registry> registries;
|
private List<Registry> registries;
|
||||||
private List<Service> services;
|
private List<Service> services;
|
||||||
private List<DataRepository> dataRepositories;
|
private List<DataRepository> dataRepositories;
|
||||||
private List<Tag> tags;
|
// private List<Tag> tags; //TODO
|
||||||
private List<ExternalDatasetListingModel> externalDatasets;
|
private List<ExternalDatasetListingModel> externalDatasets;
|
||||||
private DatasetProfileOverviewModel profile;
|
private DatasetProfileOverviewModel profile;
|
||||||
private Boolean isProfileLatestVersion;
|
private Boolean isProfileLatestVersion;
|
||||||
|
@ -147,12 +143,12 @@ public class DatasetWizardModel implements DataModel<DescriptionEntity, DatasetW
|
||||||
this.externalDatasets = externalDatasets;
|
this.externalDatasets = externalDatasets;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Tag> getTags() {
|
// public List<Tag> getTags() {
|
||||||
return tags;
|
// return tags;
|
||||||
}
|
// }
|
||||||
public void setTags(List<Tag> tags) {
|
// public void setTags(List<Tag> tags) {
|
||||||
this.tags = tags;
|
// this.tags = tags;
|
||||||
}
|
// }
|
||||||
|
|
||||||
public Boolean getIsProfileLatestVersion() {
|
public Boolean getIsProfileLatestVersion() {
|
||||||
return isProfileLatestVersion;
|
return isProfileLatestVersion;
|
||||||
|
|
|
@ -6,8 +6,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
import eu.eudat.commons.enums.IsActive;
|
import eu.eudat.commons.enums.IsActive;
|
||||||
import eu.eudat.data.DescriptionEntity;
|
import eu.eudat.data.DescriptionEntity;
|
||||||
import eu.eudat.data.DescriptionTemplateEntity;
|
import eu.eudat.data.DescriptionTemplateEntity;
|
||||||
import eu.eudat.elastic.criteria.DatasetCriteria;
|
import eu.eudat.data.TagEntity;
|
||||||
import eu.eudat.elastic.entities.Tag;
|
|
||||||
import eu.eudat.logic.managers.DatasetManager;
|
import eu.eudat.logic.managers.DatasetManager;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
import eu.eudat.logic.services.ApiContext;
|
||||||
import eu.eudat.logic.utilities.helpers.StreamDistinctBy;
|
import eu.eudat.logic.utilities.helpers.StreamDistinctBy;
|
||||||
|
@ -153,10 +152,11 @@ public class DatasetRDAMapper {
|
||||||
for (int i = 0; i < keywordNodes.size(); i++) {
|
for (int i = 0; i < keywordNodes.size(); i++) {
|
||||||
rda.setAdditionalProperty("keyword" + (i + 1), keywordNodes.get(i).get("id").asText());
|
rda.setAdditionalProperty("keyword" + (i + 1), keywordNodes.get(i).get("id").asText());
|
||||||
}
|
}
|
||||||
} else if (apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().exists()) {
|
|
||||||
List<String> tags = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(descriptionEntity.getId().toString()).getTags().stream().map(Tag::getName).collect(Collectors.toList());
|
|
||||||
rda.setKeyword(tags);
|
|
||||||
}
|
}
|
||||||
|
// else if (apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().exists()) { //TODO
|
||||||
|
// List<String> tags = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(descriptionEntity.getId().toString()).getTags().stream().map(Tag::getName).collect(Collectors.toList());
|
||||||
|
// rda.setKeyword(tags);
|
||||||
|
// }
|
||||||
List<JsonNode> personalDataNodes = JsonSearcher.findNodes(datasetDescriptionObj, "schematics", "rda.dataset.personal_data");
|
List<JsonNode> personalDataNodes = JsonSearcher.findNodes(datasetDescriptionObj, "schematics", "rda.dataset.personal_data");
|
||||||
if (!personalDataNodes.isEmpty()) {
|
if (!personalDataNodes.isEmpty()) {
|
||||||
try{
|
try{
|
||||||
|
@ -362,27 +362,28 @@ public class DatasetRDAMapper {
|
||||||
// if (keywordIds.size() < rda.getKeyword().size()) {
|
// if (keywordIds.size() < rda.getKeyword().size()) {
|
||||||
// takeAll = true;
|
// takeAll = true;
|
||||||
// }
|
// }
|
||||||
DatasetCriteria criteria = new DatasetCriteria();
|
//TODO
|
||||||
criteria.setHasTags(true);
|
// DatasetCriteria criteria = new DatasetCriteria();
|
||||||
List<Tag> tags = this.apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().query(criteria).stream().map(eu.eudat.elastic.entities.Dataset::getTags).flatMap(Collection::stream).filter(StreamDistinctBy.distinctByKey(Tag::getId)).collect(Collectors.toList());
|
// criteria.setHasTags(true);
|
||||||
if(!rda.getKeyword().isEmpty()){
|
// List<Tag> tags = this.apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().query(criteria).stream().map(eu.eudat.elastic.entities.Dataset::getTags).flatMap(Collection::stream).filter(StreamDistinctBy.distinctByKey(Tag::getId)).collect(Collectors.toList());
|
||||||
List<Tag> templateTags = tags.stream().filter(tag -> rda.getKeyword().contains(tag.getName())).collect(Collectors.toList());
|
// if(!rda.getKeyword().isEmpty()){
|
||||||
if(!templateTags.isEmpty()) {
|
// List<Tag> templateTags = tags.stream().filter(tag -> rda.getKeyword().contains(tag.getName())).collect(Collectors.toList());
|
||||||
properties.put(keywordIds.get(0), mapper.writeValueAsString(templateTags));
|
// if(!templateTags.isEmpty()) {
|
||||||
}
|
// properties.put(keywordIds.get(0), mapper.writeValueAsString(templateTags));
|
||||||
// for (int i = 0; i < keywordIds.size(); i++) {
|
|
||||||
// //if (takeAll) {
|
|
||||||
// List<String> tags = new ArrayList<>();
|
|
||||||
// for (String keyword : rda.getKeyword()) {
|
|
||||||
// tags.add(mapper.writeValueAsString(toTagEntity(keyword)));
|
|
||||||
// }
|
// }
|
||||||
// properties.put(keywordIds.get(i), tags);
|
//// for (int i = 0; i < keywordIds.size(); i++) {
|
||||||
// } else {
|
//// //if (takeAll) {
|
||||||
// properties.put(keywordIds.get(i), mapper.writeValueAsString(toTagEntity(rda.getKeyword().get(i))));
|
//// List<String> tags = new ArrayList<>();
|
||||||
|
//// for (String keyword : rda.getKeyword()) {
|
||||||
|
//// tags.add(mapper.writeValueAsString(toTagEntity(keyword)));
|
||||||
|
//// }
|
||||||
|
//// properties.put(keywordIds.get(i), tags);
|
||||||
|
//// } else {
|
||||||
|
//// properties.put(keywordIds.get(i), mapper.writeValueAsString(toTagEntity(rda.getKeyword().get(i))));
|
||||||
|
//// }
|
||||||
|
//// properties.put(keywordIds.get(i), rda.getKeyword().get(i));
|
||||||
|
//// }
|
||||||
// }
|
// }
|
||||||
// properties.put(keywordIds.get(i), rda.getKeyword().get(i));
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<JsonNode> personalDataNodes = JsonSearcher.findNodes(datasetDescriptionObj, "schematics", "rda.dataset.personal_data");
|
List<JsonNode> personalDataNodes = JsonSearcher.findNodes(datasetDescriptionObj, "schematics", "rda.dataset.personal_data");
|
||||||
|
@ -415,10 +416,10 @@ public class DatasetRDAMapper {
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Tag toTagEntity(String name) {
|
private static TagEntity toTagEntity(String name) {
|
||||||
Tag tag = new Tag();
|
TagEntity tag = new TagEntity();
|
||||||
tag.setId("");
|
tag.setId(UUID.randomUUID());
|
||||||
tag.setName(name);
|
tag.setLabel(name);
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package eu.eudat.models.rda.mapper;
|
package eu.eudat.models.rda.mapper;
|
||||||
|
|
||||||
|
import eu.eudat.commons.enums.IsActive;
|
||||||
import eu.eudat.data.DescriptionTemplateEntity;
|
import eu.eudat.data.DescriptionTemplateEntity;
|
||||||
import eu.eudat.data.EntityDoiEntity;
|
import eu.eudat.data.EntityDoiEntity;
|
||||||
import eu.eudat.data.old.*;
|
import eu.eudat.data.old.*;
|
||||||
|
@ -123,7 +124,7 @@ public class DmpRDAMapper {
|
||||||
rda.getContributor().addAll(dmp.getResearchers().stream().map(ContributorRDAMapper::toRDA).collect(Collectors.toList()));
|
rda.getContributor().addAll(dmp.getResearchers().stream().map(ContributorRDAMapper::toRDA).collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
// rda.getContributor().addAll(dmp.getUsers().stream().map(ContributorRDAMapper::toRDA).collect(Collectors.toList()));
|
// rda.getContributor().addAll(dmp.getUsers().stream().map(ContributorRDAMapper::toRDA).collect(Collectors.toList()));
|
||||||
rda.setDataset(dmp.getDataset().stream().filter(dataset -> dataset.getStatus().getValue() != eu.eudat.elastic.entities.Dmp.DMPStatus.DELETED.getValue()).map(dataset -> datasetRDAMapper.toRDA(dataset, rda)).collect(Collectors.toList()));
|
rda.setDataset(dmp.getDataset().stream().filter(dataset -> dataset.getIsActive() != IsActive.Inactive).map(dataset -> datasetRDAMapper.toRDA(dataset, rda)).collect(Collectors.toList()));
|
||||||
if (dmp.getProject() != null) {
|
if (dmp.getProject() != null) {
|
||||||
rda.setProject(Collections.singletonList(ProjectRDAMapper.toRDA(dmp.getProject(), dmp.getGrant())));
|
rda.setProject(Collections.singletonList(ProjectRDAMapper.toRDA(dmp.getProject(), dmp.getGrant())));
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,17 +2,12 @@ package eu.eudat.models.rda.mapper;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import eu.eudat.elastic.entities.Dataset;
|
import eu.eudat.data.TagEntity;
|
||||||
import eu.eudat.elastic.entities.Tag;
|
|
||||||
import eu.eudat.logic.services.ApiContext;
|
|
||||||
import eu.eudat.logic.utilities.json.JavaToJson;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class KeywordRDAMapper {
|
public class KeywordRDAMapper {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(KeywordRDAMapper.class);
|
private static final Logger logger = LoggerFactory.getLogger(KeywordRDAMapper.class);
|
||||||
private static final ObjectMapper mapper = new ObjectMapper();
|
private static final ObjectMapper mapper = new ObjectMapper();
|
||||||
|
@ -20,8 +15,8 @@ public class KeywordRDAMapper {
|
||||||
public static List<String> toRDA(String value) {
|
public static List<String> toRDA(String value) {
|
||||||
if (!value.isEmpty() && !value.equals("null")) {
|
if (!value.isEmpty() && !value.equals("null")) {
|
||||||
try {
|
try {
|
||||||
Tag tag = mapper.readValue(value, Tag.class);
|
TagEntity tag = mapper.readValue(value, TagEntity.class);
|
||||||
return new ArrayList<>(Collections.singletonList(tag.getName()));
|
return new ArrayList<>(Collections.singletonList(tag.getLabel()));
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
logger.warn(e.getMessage() + ". Attempting to parse it as a String since its a new tag.");
|
logger.warn(e.getMessage() + ". Attempting to parse it as a String since its a new tag.");
|
||||||
return new ArrayList<>(Collections.singletonList(value));
|
return new ArrayList<>(Collections.singletonList(value));
|
||||||
|
|
|
@ -2,7 +2,6 @@ package eu.eudat.publicapi.criteria.dataset;
|
||||||
|
|
||||||
import eu.eudat.data.dao.criteria.Criteria;
|
import eu.eudat.data.dao.criteria.Criteria;
|
||||||
import eu.eudat.data.DescriptionEntity;
|
import eu.eudat.data.DescriptionEntity;
|
||||||
import eu.eudat.elastic.entities.Tag;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -23,8 +22,8 @@ public class DatasetPublicCriteria extends Criteria<DescriptionEntity> {
|
||||||
private List<UUID> datasetTemplates;
|
private List<UUID> datasetTemplates;
|
||||||
@ApiModelProperty(value = "dmpOrganisations", name = "dmpOrganisations", dataType = "List<String>", example = "[]")
|
@ApiModelProperty(value = "dmpOrganisations", name = "dmpOrganisations", dataType = "List<String>", example = "[]")
|
||||||
private List<String> dmpOrganisations;
|
private List<String> dmpOrganisations;
|
||||||
@ApiModelProperty(value = "tags", name = "tags", dataType = "List<Tag>", example = "[]")
|
// @ApiModelProperty(value = "tags", name = "tags", dataType = "List<Tag>", example = "[]")
|
||||||
private List<Tag> tags;
|
// private List<Tag> tags; //TODO
|
||||||
@ApiModelProperty(value = "dmpIds", name = "dmpIds", dataType = "List<UUID>", example = "[]")
|
@ApiModelProperty(value = "dmpIds", name = "dmpIds", dataType = "List<UUID>", example = "[]")
|
||||||
private List<UUID> dmpIds;
|
private List<UUID> dmpIds;
|
||||||
@ApiModelProperty(value = "groupIds", name = "groupIds", dataType = "List<UUID>", example = "[]")
|
@ApiModelProperty(value = "groupIds", name = "groupIds", dataType = "List<UUID>", example = "[]")
|
||||||
|
@ -74,12 +73,12 @@ public class DatasetPublicCriteria extends Criteria<DescriptionEntity> {
|
||||||
this.dmpOrganisations = dmpOrganisations;
|
this.dmpOrganisations = dmpOrganisations;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Tag> getTags() {
|
// public List<Tag> getTags() {
|
||||||
return tags;
|
// return tags;
|
||||||
}
|
// }
|
||||||
public void setTags(List<Tag> tags) {
|
// public void setTags(List<Tag> tags) {
|
||||||
this.tags = tags;
|
// this.tags = tags;
|
||||||
}
|
// }
|
||||||
|
|
||||||
public List<UUID> getDmpIds() {
|
public List<UUID> getDmpIds() {
|
||||||
return dmpIds;
|
return dmpIds;
|
||||||
|
|
|
@ -1,55 +0,0 @@
|
||||||
package eu.eudat.publicapi.criteria.mapper;
|
|
||||||
|
|
||||||
import eu.eudat.data.query.definition.helpers.ColumnOrderings;
|
|
||||||
import eu.eudat.data.query.definition.helpers.Ordering;
|
|
||||||
import eu.eudat.elastic.criteria.DmpCriteria;
|
|
||||||
import eu.eudat.elastic.criteria.SortCriteria;
|
|
||||||
import eu.eudat.publicapi.criteria.dmp.DataManagementPlanPublicCriteria;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class DmpPublicCriteriaMapper {
|
|
||||||
|
|
||||||
public static DmpCriteria toElasticCriteria(DataManagementPlanPublicCriteria criteria) {
|
|
||||||
DmpCriteria elastic = new DmpCriteria();
|
|
||||||
|
|
||||||
elastic.setPublic(true);
|
|
||||||
elastic.setLike(criteria.getLike());
|
|
||||||
elastic.setAllowAllVersions(criteria.getAllVersions());
|
|
||||||
if(criteria.getDatasetTemplates() != null) {
|
|
||||||
elastic.setTemplates(criteria.getDatasetTemplates());
|
|
||||||
}
|
|
||||||
if (criteria.getGrants() != null) {
|
|
||||||
elastic.setGrants(criteria.getGrants());
|
|
||||||
}
|
|
||||||
if (criteria.getCollaborators() != null) {
|
|
||||||
elastic.setCollaborators(criteria.getCollaborators());
|
|
||||||
}
|
|
||||||
if (criteria.getDmpOrganisations() != null) {
|
|
||||||
elastic.setOrganizations(criteria.getDmpOrganisations().stream().map(UUID::fromString).collect(Collectors.toList()));
|
|
||||||
}
|
|
||||||
if(criteria.getGroupIds() != null) {
|
|
||||||
elastic.setGroupIds(criteria.getGroupIds());
|
|
||||||
}
|
|
||||||
|
|
||||||
return elastic;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<SortCriteria> toElasticSorting(ColumnOrderings columnOrderings) {
|
|
||||||
List<SortCriteria> sortCriteria = new ArrayList<>();
|
|
||||||
if (columnOrderings.getFieldOrderings() != null && !columnOrderings.getFieldOrderings().isEmpty()) {
|
|
||||||
for (Ordering ordering: columnOrderings.getFieldOrderings()) {
|
|
||||||
SortCriteria sortCriteria1 = new SortCriteria();
|
|
||||||
sortCriteria1.setFieldName(ordering.getFieldName() + (ordering.getFieldName().contains("label") ?".keyword" : ""));
|
|
||||||
sortCriteria1.setColumnType(ordering.getColumnType() != null ? SortCriteria.ColumnType.valueOf(ordering.getColumnType().name()): SortCriteria.ColumnType.COLUMN);
|
|
||||||
sortCriteria1.setOrderByType(SortCriteria.OrderByType.valueOf(ordering.getOrderByType().name()));
|
|
||||||
sortCriteria.add(sortCriteria1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sortCriteria;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -6,9 +6,6 @@ import eu.eudat.commons.types.descriptiontemplate.DefinitionEntity;
|
||||||
import eu.eudat.data.DescriptionEntity;
|
import eu.eudat.data.DescriptionEntity;
|
||||||
import eu.eudat.data.DescriptionTemplateEntity;
|
import eu.eudat.data.DescriptionTemplateEntity;
|
||||||
import eu.eudat.data.query.definition.helpers.ColumnOrderings;
|
import eu.eudat.data.query.definition.helpers.ColumnOrderings;
|
||||||
import eu.eudat.elastic.criteria.DatasetCriteria;
|
|
||||||
import eu.eudat.elastic.repository.DatasetRepository;
|
|
||||||
import eu.eudat.exceptions.security.ForbiddenException;
|
|
||||||
import eu.eudat.logic.managers.PaginationManager;
|
import eu.eudat.logic.managers.PaginationManager;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
import eu.eudat.logic.services.ApiContext;
|
||||||
import eu.eudat.logic.services.operations.DatabaseRepository;
|
import eu.eudat.logic.services.operations.DatabaseRepository;
|
||||||
|
@ -16,12 +13,10 @@ import eu.eudat.commons.types.xml.XmlBuilder;
|
||||||
import eu.eudat.models.HintedModelFactory;
|
import eu.eudat.models.HintedModelFactory;
|
||||||
import eu.eudat.models.data.helpers.common.DataTableData;
|
import eu.eudat.models.data.helpers.common.DataTableData;
|
||||||
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
|
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
|
||||||
import eu.eudat.publicapi.criteria.mapper.DmpPublicCriteriaMapper;
|
|
||||||
import eu.eudat.publicapi.models.listingmodels.DatasetPublicListingModel;
|
import eu.eudat.publicapi.models.listingmodels.DatasetPublicListingModel;
|
||||||
import eu.eudat.publicapi.models.overviewmodels.DatasetPublicModel;
|
import eu.eudat.publicapi.models.overviewmodels.DatasetPublicModel;
|
||||||
import eu.eudat.queryable.QueryableList;
|
import eu.eudat.queryable.QueryableList;
|
||||||
import eu.eudat.types.grant.GrantStateType;
|
import eu.eudat.types.grant.GrantStateType;
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -38,65 +33,65 @@ public class DatasetPublicManager {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(DatasetPublicManager.class);
|
private static final Logger logger = LoggerFactory.getLogger(DatasetPublicManager.class);
|
||||||
|
|
||||||
private DatabaseRepository databaseRepository;
|
private DatabaseRepository databaseRepository;
|
||||||
private DatasetRepository datasetRepository;
|
// private DatasetRepository datasetRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public DatasetPublicManager(ApiContext apiContext){
|
public DatasetPublicManager(ApiContext apiContext){
|
||||||
this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository();
|
this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository();
|
||||||
this.datasetRepository = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository();
|
// this.datasetRepository = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository();
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataTableData<DatasetPublicListingModel> getPublicPaged(eu.eudat.publicapi.request.dataset.DatasetPublicTableRequest datasetTableRequest) throws Exception {
|
public DataTableData<DatasetPublicListingModel> getPublicPaged(eu.eudat.publicapi.request.dataset.DatasetPublicTableRequest datasetTableRequest) throws Exception {
|
||||||
Long count = 0L;
|
Long count = 0L;
|
||||||
DatasetCriteria datasetCriteria = new DatasetCriteria();
|
// DatasetCriteria datasetCriteria = new DatasetCriteria();
|
||||||
datasetCriteria.setPublic(true);
|
// datasetCriteria.setPublic(true);
|
||||||
datasetCriteria.setLike(datasetTableRequest.getCriteria().getLike());
|
// datasetCriteria.setLike(datasetTableRequest.getCriteria().getLike());
|
||||||
datasetCriteria.setDatasetTemplates(datasetTableRequest.getCriteria().getDatasetTemplates());
|
// datasetCriteria.setDatasetTemplates(datasetTableRequest.getCriteria().getDatasetTemplates());
|
||||||
datasetCriteria.setDmps(datasetTableRequest.getCriteria().getDmpIds());
|
// datasetCriteria.setDmps(datasetTableRequest.getCriteria().getDmpIds());
|
||||||
datasetCriteria.setGrants(datasetTableRequest.getCriteria().getGrants());
|
// datasetCriteria.setGrants(datasetTableRequest.getCriteria().getGrants());
|
||||||
datasetCriteria.setCollaborators(datasetTableRequest.getCriteria().getCollaborators());
|
// datasetCriteria.setCollaborators(datasetTableRequest.getCriteria().getCollaborators());
|
||||||
datasetCriteria.setAllowAllVersions(datasetTableRequest.getCriteria().getAllVersions());
|
// datasetCriteria.setAllowAllVersions(datasetTableRequest.getCriteria().getAllVersions());
|
||||||
datasetCriteria.setOrganiztions(datasetTableRequest.getCriteria().getDmpOrganisations());
|
// datasetCriteria.setOrganiztions(datasetTableRequest.getCriteria().getDmpOrganisations());
|
||||||
if(datasetTableRequest.getCriteria().getTags() != null && !datasetTableRequest.getCriteria().getTags().isEmpty()){
|
// if(datasetTableRequest.getCriteria().getTags() != null && !datasetTableRequest.getCriteria().getTags().isEmpty()){
|
||||||
datasetCriteria.setHasTags(true);
|
// datasetCriteria.setHasTags(true);
|
||||||
datasetCriteria.setTags(datasetTableRequest.getCriteria().getTags());
|
// datasetCriteria.setTags(datasetTableRequest.getCriteria().getTags());
|
||||||
}
|
// }
|
||||||
datasetCriteria.setGroupIds(datasetTableRequest.getCriteria().getGroupIds());
|
// datasetCriteria.setGroupIds(datasetTableRequest.getCriteria().getGroupIds());
|
||||||
datasetCriteria.setGrantStatus(GrantStateType.ONGOING.getValue().shortValue()); // grant status ongoing
|
// datasetCriteria.setGrantStatus(GrantStateType.ONGOING.getValue().shortValue()); // grant status ongoing
|
||||||
datasetCriteria.setStatus(DescriptionStatus.Finalized.getValue()); // dataset status finalized
|
// datasetCriteria.setStatus(DescriptionStatus.Finalized.getValue()); // dataset status finalized
|
||||||
if (datasetTableRequest.getOrderings() != null) {
|
// if (datasetTableRequest.getOrderings() != null) {
|
||||||
datasetCriteria.setSortCriteria(DmpPublicCriteriaMapper.toElasticSorting(datasetTableRequest.getOrderings()));
|
// datasetCriteria.setSortCriteria(DmpPublicCriteriaMapper.toElasticSorting(datasetTableRequest.getOrderings()));
|
||||||
}
|
// }
|
||||||
datasetCriteria.setOffset(datasetTableRequest.getOffset());
|
// datasetCriteria.setOffset(datasetTableRequest.getOffset());
|
||||||
datasetCriteria.setSize(datasetTableRequest.getLength());
|
// datasetCriteria.setSize(datasetTableRequest.getLength());
|
||||||
List<eu.eudat.elastic.entities.Dataset> datasets;
|
// List<eu.eudat.elastic.entities.Dataset> datasets;
|
||||||
try {
|
// try {
|
||||||
datasets = datasetRepository.exists() ?
|
//// datasets = datasetRepository.exists() ?
|
||||||
datasetRepository.queryIds(datasetCriteria) : new LinkedList<>();
|
//// datasetRepository.queryIds(datasetCriteria) : new LinkedList<>();
|
||||||
if(datasetTableRequest.getCriteria().getPeriodStart() != null)
|
// if(datasetTableRequest.getCriteria().getPeriodStart() != null)
|
||||||
datasets = datasets.stream().filter(dataset -> dataset.getCreated().after(datasetTableRequest.getCriteria().getPeriodStart())).collect(Collectors.toList());
|
// datasets = datasets.stream().filter(dataset -> dataset.getCreated().after(datasetTableRequest.getCriteria().getPeriodStart())).collect(Collectors.toList());
|
||||||
if(datasetTableRequest.getCriteria().getPeriodEnd() != null)
|
// if(datasetTableRequest.getCriteria().getPeriodEnd() != null)
|
||||||
datasets = datasets.stream().filter(dataset -> dataset.getCreated().before(datasetTableRequest.getCriteria().getPeriodEnd())).collect(Collectors.toList());
|
// datasets = datasets.stream().filter(dataset -> dataset.getCreated().before(datasetTableRequest.getCriteria().getPeriodEnd())).collect(Collectors.toList());
|
||||||
count = (long) datasets.size();
|
// count = (long) datasets.size();
|
||||||
} catch (Exception ex) {
|
// } catch (Exception ex) {
|
||||||
logger.warn(ex.getMessage());
|
// logger.warn(ex.getMessage());
|
||||||
datasets = null;
|
// datasets = null;
|
||||||
}
|
// }
|
||||||
/*datasetTableRequest.setQuery(databaseRepository.getDatasetDao().asQueryable().withHint(HintedModelFactory.getHint(DatasetPublicListingModel.class)));
|
/*datasetTableRequest.setQuery(databaseRepository.getDatasetDao().asQueryable().withHint(HintedModelFactory.getHint(DatasetPublicListingModel.class)));
|
||||||
QueryableList<Dataset> items = datasetTableRequest.applyCriteria();*/
|
QueryableList<Dataset> items = datasetTableRequest.applyCriteria();*/
|
||||||
datasetTableRequest.setQuery(databaseRepository.getDatasetDao().asQueryable().withHint(HintedModelFactory.getHint(DatasetPublicListingModel.class)));
|
datasetTableRequest.setQuery(databaseRepository.getDatasetDao().asQueryable().withHint(HintedModelFactory.getHint(DatasetPublicListingModel.class)));
|
||||||
QueryableList<DescriptionEntity> items;
|
QueryableList<DescriptionEntity> items;
|
||||||
if (datasets != null) {
|
// if (datasets != null) {
|
||||||
if (!datasets.isEmpty()) {
|
// if (!datasets.isEmpty()) {
|
||||||
items = databaseRepository.getDatasetDao().asQueryable().withHint(HintedModelFactory.getHint(DatasetPublicListingModel.class));
|
// items = databaseRepository.getDatasetDao().asQueryable().withHint(HintedModelFactory.getHint(DatasetPublicListingModel.class));
|
||||||
List<eu.eudat.elastic.entities.Dataset> finalDatasets = datasets;
|
// List<eu.eudat.elastic.entities.Dataset> finalDatasets = datasets;
|
||||||
items.where((builder, root) -> root.get("id").in(finalDatasets.stream().map(x -> UUID.fromString(x.getId())).collect(Collectors.toList())));
|
// items.where((builder, root) -> root.get("id").in(finalDatasets.stream().map(x -> UUID.fromString(x.getId())).collect(Collectors.toList())));
|
||||||
} else
|
// } else
|
||||||
|
// items = datasetTableRequest.applyCriteria();
|
||||||
|
// //items.where((builder, root) -> root.get("id").in(new UUID[]{UUID.randomUUID()}));
|
||||||
|
// } else {
|
||||||
items = datasetTableRequest.applyCriteria();
|
items = datasetTableRequest.applyCriteria();
|
||||||
//items.where((builder, root) -> root.get("id").in(new UUID[]{UUID.randomUUID()}));
|
// }
|
||||||
} else {
|
|
||||||
items = datasetTableRequest.applyCriteria();
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> strings = new ArrayList<>();
|
List<String> strings = new ArrayList<>();
|
||||||
strings.add("-dmp:publishedAt|join|");
|
strings.add("-dmp:publishedAt|join|");
|
||||||
|
|
|
@ -2,9 +2,6 @@ package eu.eudat.publicapi.models.overviewmodels;
|
||||||
|
|
||||||
import eu.eudat.commons.enums.DescriptionStatus;
|
import eu.eudat.commons.enums.DescriptionStatus;
|
||||||
import eu.eudat.data.DescriptionEntity;
|
import eu.eudat.data.DescriptionEntity;
|
||||||
import eu.eudat.data.DescriptionTemplateEntity;
|
|
||||||
import eu.eudat.data.old.*;
|
|
||||||
import eu.eudat.elastic.entities.Tag;
|
|
||||||
import eu.eudat.models.DataModel;
|
import eu.eudat.models.DataModel;
|
||||||
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
|
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
|
||||||
import eu.eudat.publicapi.models.datasetprofile.DatasetProfilePublicModel;
|
import eu.eudat.publicapi.models.datasetprofile.DatasetProfilePublicModel;
|
||||||
|
@ -13,10 +10,8 @@ import eu.eudat.publicapi.models.datasetwizard.ExternalDatasetPublicListingModel
|
||||||
import eu.eudat.publicapi.models.datasetwizard.RegistryPublicModel;
|
import eu.eudat.publicapi.models.datasetwizard.RegistryPublicModel;
|
||||||
import eu.eudat.publicapi.models.datasetwizard.ServicePublicModel;
|
import eu.eudat.publicapi.models.datasetwizard.ServicePublicModel;
|
||||||
import eu.eudat.publicapi.models.listingmodels.DataManagementPlanPublicListingModel;
|
import eu.eudat.publicapi.models.listingmodels.DataManagementPlanPublicListingModel;
|
||||||
import net.minidev.json.JSONValue;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class DatasetPublicModel implements DataModel<DescriptionEntity, DatasetPublicModel> {
|
public class DatasetPublicModel implements DataModel<DescriptionEntity, DatasetPublicModel> {
|
||||||
private UUID id;
|
private UUID id;
|
||||||
|
@ -31,7 +26,7 @@ public class DatasetPublicModel implements DataModel<DescriptionEntity, DatasetP
|
||||||
private List<RegistryPublicModel> registries;
|
private List<RegistryPublicModel> registries;
|
||||||
private List<ServicePublicModel> services;
|
private List<ServicePublicModel> services;
|
||||||
private List<DataRepositoryPublicModel> dataRepositories;
|
private List<DataRepositoryPublicModel> dataRepositories;
|
||||||
private List<Tag> tags;
|
// private List<Tag> tags; //TODO
|
||||||
private List<ExternalDatasetPublicListingModel> externalDatasets;
|
private List<ExternalDatasetPublicListingModel> externalDatasets;
|
||||||
private DatasetProfilePublicModel profile;
|
private DatasetProfilePublicModel profile;
|
||||||
private Date modifiedAt;
|
private Date modifiedAt;
|
||||||
|
@ -134,12 +129,12 @@ public class DatasetPublicModel implements DataModel<DescriptionEntity, DatasetP
|
||||||
this.externalDatasets = externalDatasets;
|
this.externalDatasets = externalDatasets;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Tag> getTags() {
|
// public List<Tag> getTags() {
|
||||||
return tags;
|
// return tags;
|
||||||
}
|
// }
|
||||||
public void setTags(List<Tag> tags) {
|
// public void setTags(List<Tag> tags) {
|
||||||
this.tags = tags;
|
// this.tags = tags;
|
||||||
}
|
// }
|
||||||
|
|
||||||
public Date getModifiedAt() {
|
public Date getModifiedAt() {
|
||||||
return modifiedAt;
|
return modifiedAt;
|
||||||
|
|
Loading…
Reference in New Issue