Add dmp ids, organization, tags and last version (incomplete) to the elastic index

Remove_explore
George Kalampokis 4 years ago
parent 2329ad8bed
commit 9071faba38

2
.gitignore vendored

@ -38,3 +38,5 @@ dmp-frontend/.vscode/
dmp-frontend/package-lock.json dmp-frontend/package-lock.json
dmp-backend/logging/target/
ELK.Docker/shared/data-elk/

@ -13,9 +13,12 @@ public class DatasetCriteria extends Criteria {
private List<UUID> datasetTemplates; private List<UUID> datasetTemplates;
private Short status; private Short status;
private List<UUID> dmps; private List<UUID> dmps;
private List<UUID> groupIds;
private List<UUID> grants; private List<UUID> grants;
private List<UUID> collaborators; private List<UUID> collaborators;
// public List<Tag> tags; private Boolean allowAllVersions;
private List<String> organiztions;
public List<Tag> tags;
public String getLabel() { public String getLabel() {
return label; return label;
@ -49,6 +52,14 @@ public class DatasetCriteria extends Criteria {
this.dmps = dmps; this.dmps = dmps;
} }
public List<UUID> getGroupIds() {
return groupIds;
}
public void setGroupIds(List<UUID> groupIds) {
this.groupIds = groupIds;
}
public List<UUID> getGrants() { public List<UUID> getGrants() {
return grants; return grants;
} }
@ -65,11 +76,27 @@ public class DatasetCriteria extends Criteria {
this.collaborators = collaborators; this.collaborators = collaborators;
} }
/*public List<Tag> getTags() { 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; return tags;
} }
public void setTags(List<Tag> tags) { public void setTags(List<Tag> tags) {
this.tags = tags; this.tags = tags;
}*/ }
} }

@ -7,14 +7,14 @@ import java.util.Map;
import java.util.UUID; import java.util.UUID;
public class Collaborator implements ElasticEntity<Collaborator> { public class Collaborator implements ElasticEntity<Collaborator> {
private UUID id; private String id;
private String name; private String name;
public UUID getId() { public String getId() {
return id; return id;
} }
public void setId(UUID id) { public void setId(String id) {
this.id = id; this.id = id;
} }
@ -29,7 +29,7 @@ public class Collaborator implements ElasticEntity<Collaborator> {
@Override @Override
public XContentBuilder toElasticEntity(XContentBuilder builder) throws IOException { public XContentBuilder toElasticEntity(XContentBuilder builder) throws IOException {
builder.startObject(); builder.startObject();
builder.field("id", this.id.toString()); builder.field("id", this.id);
builder.field("name", this.name); builder.field("name", this.name);
builder.endObject(); builder.endObject();
return builder; return builder;

@ -17,14 +17,46 @@ import java.util.stream.Collectors;
public class Dataset implements ElasticEntity<Dataset> { public class Dataset implements ElasticEntity<Dataset> {
private static final Logger logger = LoggerFactory.getLogger(Dataset.class); 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 String id;
//private List<Tag> tags = new LinkedList<>(); private List<Tag> tags = new LinkedList<>();
private String label; private String label;
private UUID template; private UUID template;
private Short status; private Short status;
private UUID dmp; private UUID dmp;
private UUID group;
private UUID grant; private UUID grant;
private List<Collaborator> collaborators; private List<Collaborator> collaborators;
private Boolean lastVersion;
private List<Organization> organizations;
public String getId() { public String getId() {
return id; return id;
@ -34,13 +66,13 @@ public class Dataset implements ElasticEntity<Dataset> {
this.id = id; this.id = id;
} }
/*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 String getLabel() { public String getLabel() {
return label; return label;
@ -74,6 +106,14 @@ public class Dataset implements ElasticEntity<Dataset> {
this.dmp = dmp; this.dmp = dmp;
} }
public UUID getGroup() {
return group;
}
public void setGroup(UUID group) {
this.group = group;
}
public UUID getGrant() { public UUID getGrant() {
return grant; return grant;
} }
@ -90,6 +130,22 @@ public class Dataset implements ElasticEntity<Dataset> {
this.collaborators = collaborators; this.collaborators = collaborators;
} }
public Boolean getLastVersion() {
return lastVersion;
}
public void setLastVersion(Boolean lastVersion) {
this.lastVersion = lastVersion;
}
public List<Organization> getOrganizations() {
return organizations;
}
public void setOrganizations(List<Organization> organizations) {
this.organizations = organizations;
}
@Override @Override
public XContentBuilder toElasticEntity(XContentBuilder builder) throws IOException { public XContentBuilder toElasticEntity(XContentBuilder builder) throws IOException {
builder.startObject(); builder.startObject();
@ -98,26 +154,44 @@ public class Dataset implements ElasticEntity<Dataset> {
builder.field("template", this.template.toString()); builder.field("template", this.template.toString());
builder.field("status", this.status.toString()); builder.field("status", this.status.toString());
builder.field("dmp", this.dmp.toString()); builder.field("dmp", this.dmp.toString());
builder.field("group", this.group.toString());
builder.field("grant", this.grant.toString()); builder.field("grant", this.grant.toString());
builder.startArray("collaborators"); if (collaborators != null) {
this.collaborators.forEach(x -> { builder.startArray("collaborators");
try { this.collaborators.forEach(x -> {
x.toElasticEntity(builder); try {
} catch (IOException e) { x.toElasticEntity(builder);
logger.error(e.getMessage(), e); } catch (IOException e) {
} logger.error(e.getMessage(), e);
}
});
builder.endArray(); });
/*builder.startArray("tags"); builder.endArray();
this.tags.forEach(x -> { }
try { builder.field("lastVersion", this.lastVersion.toString());
x.toElasticEntity(builder); if (organizations != null) {
} catch (IOException e) { builder.startArray("organizations");
logger.error(e.getMessage(), e); this.organizations.forEach(x -> {
} try {
}); x.toElasticEntity(builder);
builder.endArray();*/ } 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();
}
builder.endObject(); builder.endObject();
return builder; return builder;
} }
@ -126,13 +200,16 @@ public class Dataset implements ElasticEntity<Dataset> {
public Dataset fromElasticEntity(Map<String, Object> fields) { public Dataset fromElasticEntity(Map<String, Object> fields) {
if (fields != null) { if (fields != null) {
this.id = (String) fields.get("id"); this.id = (String) fields.get("id");
// this.tags = ((List<Tag>) fields.get("tags")); this.tags = ((List<Tag>) fields.get("tags"));
this.label = (String) fields.get("label"); this.label = (String) fields.get("label");
this.template = UUID.fromString((String) fields.get("template")); this.template = UUID.fromString((String) fields.get("template"));
this.status = Short.valueOf((String) fields.get("status")); this.status = Short.valueOf((String) fields.get("status"));
this.dmp = UUID.fromString((String) fields.get("dmp")); this.dmp = UUID.fromString((String) fields.get("dmp"));
this.group = UUID.fromString((String) fields.get("goup"));
this.grant = UUID.fromString((String) fields.get("grant")); this.grant = UUID.fromString((String) fields.get("grant"));
this.collaborators = ((List<Collaborator>) fields.get("collaborators")); this.collaborators = ((List<Collaborator>) fields.get("collaborators"));
this.lastVersion = Boolean.parseBoolean((String) fields.get("lastVersion"));
this.organizations = (List<Organization>) fields.get("organiztions");
} }
return this; return this;
} }

@ -0,0 +1,41 @@
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<String, Object> fields) {
return null;
}
}

@ -2,6 +2,7 @@ package eu.eudat.elastic.repository;
import eu.eudat.elastic.criteria.DatasetCriteria; import eu.eudat.elastic.criteria.DatasetCriteria;
import eu.eudat.elastic.entities.Dataset; import eu.eudat.elastic.entities.Dataset;
import eu.eudat.elastic.entities.Tag;
import org.elasticsearch.client.core.CountRequest; import org.elasticsearch.client.core.CountRequest;
import org.elasticsearch.client.core.CountResponse; import org.elasticsearch.client.core.CountResponse;
import org.elasticsearch.client.indices.GetIndexRequest; import org.elasticsearch.client.indices.GetIndexRequest;
@ -16,6 +17,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.reindex.DeleteByQueryRequest;
import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -56,13 +58,13 @@ public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteri
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
CountRequest countRequest = new CountRequest("datasets"); CountRequest countRequest = new CountRequest("datasets");
countRequest.query(QueryBuilders.matchAllQuery()); countRequest.query(QueryBuilders.boolQuery().mustNot(QueryBuilders.termQuery("status.keyword", Dataset.Status.DELETED.getValue())));
CountResponse countResponse = getClient().count(countRequest, RequestOptions.DEFAULT); CountResponse countResponse = getClient().count(countRequest, RequestOptions.DEFAULT);
Long count = countResponse.getCount(); Long count = countResponse.getCount();
searchSourceBuilder.size(count.intValue()); searchSourceBuilder.size(count.intValue());
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery(); BoolQueryBuilder boolQuery = QueryBuilders.boolQuery().mustNot(QueryBuilders.termQuery("status.keyword", Dataset.Status.DELETED.getValue()));
if (criteria.getLabel() != null && !criteria.getLabel().isEmpty()) { if (criteria.getLabel() != null && !criteria.getLabel().isEmpty()) {
boolQuery = boolQuery.should(QueryBuilders.matchPhrasePrefixQuery("label", criteria.getLabel())); boolQuery = boolQuery.should(QueryBuilders.matchPhrasePrefixQuery("label", criteria.getLabel()));
} }
@ -79,6 +81,10 @@ public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteri
boolQuery = boolQuery.should(QueryBuilders.termsQuery("dmp.keyword", criteria.getDmps().stream().map(UUID::toString).collect(Collectors.toList()))); boolQuery = boolQuery.should(QueryBuilders.termsQuery("dmp.keyword", criteria.getDmps().stream().map(UUID::toString).collect(Collectors.toList())));
} }
if (criteria.getGroupIds() != null && criteria.getGroupIds().size() > 0) {
boolQuery = boolQuery.should(QueryBuilders.termsQuery("group.keyword", criteria.getGroupIds().stream().map(UUID::toString).collect(Collectors.toList())));
}
if (criteria.getGrants() != null && criteria.getGrants().size() > 0) { if (criteria.getGrants() != null && criteria.getGrants().size() > 0) {
boolQuery = boolQuery.should(QueryBuilders.termsQuery("grant.keyword", criteria.getGrants().stream().map(UUID::toString).collect(Collectors.toList()))); boolQuery = boolQuery.should(QueryBuilders.termsQuery("grant.keyword", criteria.getGrants().stream().map(UUID::toString).collect(Collectors.toList())));
} }
@ -87,6 +93,18 @@ public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteri
boolQuery = boolQuery.should(QueryBuilders.termsQuery("collaborators.id.keyword", criteria.getCollaborators().stream().map(UUID::toString).collect(Collectors.toList()))); boolQuery = boolQuery.should(QueryBuilders.termsQuery("collaborators.id.keyword", criteria.getCollaborators().stream().map(UUID::toString).collect(Collectors.toList())));
} }
if (criteria.getAllowAllVersions() != null && !criteria.getAllowAllVersions()) {
boolQuery = boolQuery.should(QueryBuilders.termQuery("lastVersion.keyword", "true"));
}
if (criteria.getCollaborators() != null && criteria.getCollaborators().size() > 0) {
boolQuery = boolQuery.should(QueryBuilders.termsQuery("organizations.id.keyword", criteria.getOrganiztions()));
}
if (criteria.getTags() != null && criteria.getTags().size() > 0) {
boolQuery = boolQuery.should(QueryBuilders.termsQuery("tags.name.keyword", criteria.getTags().stream().map(Tag::getName).collect(Collectors.toList())));
}
if (boolQuery.should().isEmpty()) { if (boolQuery.should().isEmpty()) {
boolQuery.should(QueryBuilders.matchAllQuery()); boolQuery.should(QueryBuilders.matchAllQuery());
} else { } else {
@ -104,4 +122,13 @@ public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteri
// request.indices("datasets"); // request.indices("datasets");
return this.getClient().indices().exists(request, RequestOptions.DEFAULT); return this.getClient().indices().exists(request, RequestOptions.DEFAULT);
} }
@Override
public void clear() throws IOException {
if (exists()) {
DeleteByQueryRequest delete = new DeleteByQueryRequest("datasets");
delete.setQuery(QueryBuilders.matchAllQuery());
this.getClient().deleteByQuery(delete, RequestOptions.DEFAULT);
}
}
} }

@ -19,4 +19,6 @@ public interface Repository<ET extends ElasticEntity, C extends Criteria> {
List<ET> query(C criteria) throws ExecutionException, InterruptedException, IOException; List<ET> query(C criteria) throws ExecutionException, InterruptedException, IOException;
boolean exists() throws IOException; boolean exists() throws IOException;
void clear() throws IOException;
} }

@ -1,30 +1,26 @@
package eu.eudat.controllers; package eu.eudat.controllers;
import com.fasterxml.jackson.core.type.TypeReference; import eu.eudat.elastic.criteria.DatasetCriteria;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.elastic.criteria.TagCriteria; import eu.eudat.elastic.criteria.TagCriteria;
import eu.eudat.elastic.entities.Dataset; import eu.eudat.elastic.entities.Dataset;
import eu.eudat.elastic.entities.Tag;
import eu.eudat.elastic.repository.Repository; import eu.eudat.elastic.repository.Repository;
import eu.eudat.logic.proxy.config.ExternalUrlCriteria;
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet; import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
import eu.eudat.logic.proxy.config.exceptions.NoURLFound; import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.data.external.TagExternalSourcesModel;
import eu.eudat.models.data.helpers.responses.ResponseItem; import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.types.ApiMessageCode; import eu.eudat.types.ApiMessageCode;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.Collection;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
/** /**
* Created by ikalyvas on 7/5/2018. * Created by ikalyvas on 7/5/2018.
@ -46,12 +42,13 @@ public class TagController extends BaseController {
@RequestMapping(method = RequestMethod.GET, value = {"/external/tags"}, produces = "application/json") @RequestMapping(method = RequestMethod.GET, value = {"/external/tags"}, produces = "application/json")
public @ResponseBody public @ResponseBody
ResponseEntity<ResponseItem<TagExternalSourcesModel>> listExternalTagModel( ResponseEntity<ResponseItem<List<Tag>>> listExternalTagModel(
@RequestParam(value = "query", required = false) String query, @RequestParam(value = "type", required = false) String type) throws HugeResultSet, NoURLFound, IOException { @RequestParam(value = "query", required = false) String query, @RequestParam(value = "type", required = false) String type) throws HugeResultSet, NoURLFound, IOException, ExecutionException, InterruptedException {
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query); //ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query);
List<Map<String, String>> remoteRepos = this.getApiContext().getOperationsContext().getRemoteFetcher().getTags(externalUrlCriteria, type); /*List<Map<String, String>> remoteRepos = this.getApiContext().getOperationsContext().getRemoteFetcher().getTags(externalUrlCriteria, type);
TagExternalSourcesModel researchersExternalSourcesModel = new TagExternalSourcesModel().fromExternalItem(remoteRepos); TagExternalSourcesModel researchersExternalSourcesModel = new TagExternalSourcesModel().fromExternalItem(remoteRepos);*/
List<Tag> tags = this.getApiContext().getOperationsContext().getDatasetRepository().query(new DatasetCriteria()).stream().map(Dataset::getTags).flatMap(Collection::stream).collect(Collectors.toList());
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<TagExternalSourcesModel>().payload(researchersExternalSourcesModel).status(ApiMessageCode.NO_MESSAGE)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Tag>>().payload(tags).status(ApiMessageCode.NO_MESSAGE));
} }
} }

@ -865,6 +865,11 @@ public class DataManagementPlanManager {
datasetDao.asQueryable().withHint(HintedModelFactory.getHint(DatasetListingModel.class)).where((builder, root) -> builder.equal(root.get("id"), dataset.getId())).getSingleAsync() datasetDao.asQueryable().withHint(HintedModelFactory.getHint(DatasetListingModel.class)).where((builder, root) -> builder.equal(root.get("id"), dataset.getId())).getSingleAsync()
.thenApplyAsync(entityDataset -> { .thenApplyAsync(entityDataset -> {
Dataset newDataset = new Dataset(); Dataset newDataset = new Dataset();
try {
this.datasetManager.updateTags(apiContext.getOperationsContext().getDatasetRepository(), new DatasetWizardModel().fromDataModel(entityDataset));
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
newDataset.update(entityDataset); newDataset.update(entityDataset);
newDataset.setDmp(newDmp); newDataset.setDmp(newDmp);
newDataset.setStatus(Dataset.Status.SAVED.getValue()); newDataset.setStatus(Dataset.Status.SAVED.getValue());
@ -918,6 +923,15 @@ public class DataManagementPlanManager {
futures.add(datasetDao.createOrUpdateAsync(item)); futures.add(datasetDao.createOrUpdateAsync(item));
return futures; return futures;
}).join(); }).join();
DatasetCriteria criteria = new DatasetCriteria();
criteria.setDmpIds(Collections.singletonList(newDmp.getId()));
datasetDao.getWithCriteria(criteria).toList().stream().max(Comparator.comparing(Dataset::getCreated)).ifPresent(dataset1 -> {
try {
datasetManager.updateTags(apiContext.getOperationsContext().getDatasetRepository(), new DatasetWizardModel().fromDataModel(dataset1));
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
});
} }
} }

@ -14,6 +14,7 @@ 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.criteria.DatasetCriteria;
import eu.eudat.elastic.entities.Collaborator; import eu.eudat.elastic.entities.Collaborator;
import eu.eudat.elastic.entities.Organization;
import eu.eudat.elastic.repository.DatasetRepository; import eu.eudat.elastic.repository.DatasetRepository;
import eu.eudat.exceptions.security.UnauthorisedException; import eu.eudat.exceptions.security.UnauthorisedException;
import eu.eudat.logic.builders.BuilderFactory; import eu.eudat.logic.builders.BuilderFactory;
@ -37,6 +38,7 @@ import eu.eudat.models.data.listingmodels.DatasetListingModel;
import eu.eudat.models.data.security.Principal; import eu.eudat.models.data.security.Principal;
import eu.eudat.models.data.user.composite.PagedDatasetProfile; import eu.eudat.models.data.user.composite.PagedDatasetProfile;
import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.QueryableList;
import eu.eudat.types.Authorities;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph; import org.apache.poi.xwpf.usermodel.XWPFParagraph;
@ -111,9 +113,13 @@ public class DatasetManager {
if (datasetTableRequest.getCriteria().getStatus() != null) { if (datasetTableRequest.getCriteria().getStatus() != null) {
datasetCriteria.setStatus(datasetTableRequest.getCriteria().getStatus().shortValue()); datasetCriteria.setStatus(datasetTableRequest.getCriteria().getStatus().shortValue());
} }
datasetCriteria.setDmps(datasetTableRequest.getCriteria().getGroupIds()); datasetCriteria.setDmps(datasetTableRequest.getCriteria().getDmpIds());
datasetCriteria.setGroupIds(datasetTableRequest.getCriteria().getGroupIds());
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.setOrganiztions(datasetTableRequest.getCriteria().getOrganisations());
datasetCriteria.setTags(datasetTableRequest.getCriteria().getTags());
List<eu.eudat.elastic.entities.Dataset> datasets; List<eu.eudat.elastic.entities.Dataset> datasets;
try { try {
datasets = datasetRepository.exists() ? datasets = datasetRepository.exists() ?
@ -263,10 +269,13 @@ public class DatasetManager {
boolean latestVersion = profile.getVersion().toString().equals(datasetEntity.getProfile().getVersion().toString()); boolean latestVersion = profile.getVersion().toString().equals(datasetEntity.getProfile().getVersion().toString());
dataset.setIsProfileLatestVersion(latestVersion); dataset.setIsProfileLatestVersion(latestVersion);
//dataset.setTags(datasetElastic.getTags()); if (datasetElastic != null && datasetElastic.getTags() != null && !datasetElastic.getTags().isEmpty()) {
if (datasetElastic != null && datasetElastic.getLabel() != null && !datasetElastic.getLabel().isEmpty()) { dataset.setTags(datasetElastic.getTags());
dataset.setLabel(datasetElastic.getLabel());
} }
/*if (datasetElastic != null && datasetElastic.getLabel() != null && !datasetElastic.getLabel().isEmpty()) {
dataset.setLabel(datasetElastic.getLabel());
}*/
return dataset; return dataset;
} }
@ -548,23 +557,38 @@ public class DatasetManager {
dataset.setProperties(jobject.toString()); dataset.setProperties(jobject.toString());
} }
private void updateTags(DatasetRepository datasetRepository, DatasetWizardModel datasetWizardModel) throws IOException { public void updateTags(DatasetRepository datasetRepository, DatasetWizardModel datasetWizardModel) throws IOException {
// 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());
// dataset.setTags(datasetWizardModel.getTags()); dataset.setTags(datasetWizardModel.getTags());
dataset.setLabel(datasetWizardModel.getLabel()); dataset.setLabel(datasetWizardModel.getLabel());
dataset.setTemplate(datasetWizardModel.getProfile()); dataset.setTemplate(datasetWizardModel.getProfile());
dataset.setStatus(datasetWizardModel.getStatus()); dataset.setStatus(datasetWizardModel.getStatus());
dataset.setDmp(datasetWizardModel.getDmp().getGroupId()); dataset.setDmp(datasetWizardModel.getDmp().getId());
dataset.setGroup(datasetWizardModel.getDmp().getGroupId());
dataset.setGrant(datasetWizardModel.getDmp().getGrant().getId()); dataset.setGrant(datasetWizardModel.getDmp().getGrant().getId());
dataset.setCollaborators(datasetWizardModel.getDmp().getUsers().stream().map(user -> { dataset.setCollaborators(datasetWizardModel.getDmp().getUsers().stream().map(user -> {
Collaborator collaborator = new Collaborator(); Collaborator collaborator = new Collaborator();
collaborator.setId(user.getId()); collaborator.setId(user.getId().toString());
collaborator.setName(user.getName()); collaborator.setName(user.getName());
return collaborator; return collaborator;
}).collect(Collectors.toList())); }).collect(Collectors.toList()));
datasetRepository.createOrUpdate(dataset); DataManagementPlanCriteria dmpCriteria = new DataManagementPlanCriteria();
dmpCriteria.setAllVersions(true);
dmpCriteria.setGroupIds(Collections.singletonList(datasetWizardModel.getDmp().getGroupId()));
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(dmpCriteria).toList().stream()
.max(Comparator.comparing(DMP::getVersion)).ifPresent(dmp -> dataset.setLastVersion(dmp.getId().equals(datasetWizardModel.getDmp().getId())));
if (dataset.getLastVersion() == null) {
dataset.setLastVersion(true);
}
dataset.setOrganizations(datasetWizardModel.getDmp().getOrganisations().stream().map(org -> {
Organization organization = new Organization();
organization.setId(org.getId());
organization.setName(org.getName());
return organization;
}).collect(Collectors.toList()));
datasetRepository.createOrUpdate(dataset);
// } // }
} }
@ -773,10 +797,12 @@ public class DatasetManager {
// Now at latest version. // Now at latest version.
dataset.setIsProfileLatestVersion(true); dataset.setIsProfileLatestVersion(true);
//dataset.setTags(datasetElastic.getTags()); if (datasetElastic != null && datasetElastic.getTags() != null && !datasetElastic.getTags().isEmpty()) {
if (datasetElastic != null && datasetElastic.getLabel() != null && !datasetElastic.getLabel().isEmpty()) { dataset.setTags(datasetElastic.getTags());
dataset.setLabel(datasetElastic.getLabel());
} }
/*if (datasetElastic != null && datasetElastic.getLabel() != null && !datasetElastic.getLabel().isEmpty()) {
dataset.setLabel(datasetElastic.getLabel());
}*/
return dataset; return dataset;
} }

@ -146,8 +146,22 @@
<h4 class="col-auto">{{'DATASET-EDITOR.FIELDS.TAGS' | translate}}</h4> <h4 class="col-auto">{{'DATASET-EDITOR.FIELDS.TAGS' | translate}}</h4>
</div> </div>
</div> </div>
<app-external-item-listing *ngIf="formGroup.get('tags') && tagsTemplate && externalSourcesConfiguration" [options]="externalSourcesConfiguration.tags" placeholder="{{'DATASET-EDITOR.FIELDS.TAGS' | translate}}" [parentTemplate]='tagsTemplate' [formArray]="formGroup.get('tags')" [autoCompleteConfiguration]="tagsAutoCompleteConfiguration" (onItemChange)="tagsOnItemChange($event)"> <!-- <app-external-item-listing *ngIf="formGroup.get('tags') && tagsTemplate && externalSourcesConfiguration" [options]="externalSourcesConfiguration.tags" placeholder="{{'DATASET-EDITOR.FIELDS.TAGS' | translate}}" [parentTemplate]='tagsTemplate' [formArray]="formGroup.get('tags')" [autoCompleteConfiguration]="tagsAutoCompleteConfiguration" (onItemChange)="tagsOnItemChange($event)">
</app-external-item-listing> </app-external-item-listing> -->
<mat-form-field>
<mat-chip-list #chipList>
<mat-chip *ngFor="let tag of formGroup.get('tags').value"
[removable]="true" (removed)="removeTag(tag)">
{{tag.name}}
<mat-icon matChipRemove *ngIf="true">cancel</mat-icon>
</mat-chip>
<input matInput placeholder="{{'DATASET-EDITOR.FIELDS.TAGS' | translate}}"
[matChipInputFor]="chipList"
[matChipInputSeparatorKeyCodes]="separatorKeysCodes"
[matChipInputAddOnBlur]="true"
(matChipInputTokenEnd)="addTag($event)">
</mat-chip-list>
</mat-form-field>
<ng-template #tagsTemplate let-suggestion let-i="index" let-callback="function"> <ng-template #tagsTemplate let-suggestion let-i="index" let-callback="function">
<div class="col-12 row align-items-center"> <div class="col-12 row align-items-center">

@ -22,6 +22,9 @@ import { BaseComponent } from '@common/base/base.component';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { takeUntil } from 'rxjs/operators'; import { takeUntil } from 'rxjs/operators';
import { ENTER, COMMA } from '@angular/cdk/keycodes';
import { MatChipInputEvent } from '@angular/material/chips';
import { isNullOrUndefined } from 'util';
@Component({ @Component({
selector: 'app-dataset-external-references-editor-component', selector: 'app-dataset-external-references-editor-component',
@ -33,6 +36,8 @@ export class DatasetExternalReferencesEditorComponent extends BaseComponent impl
@Input() formGroup: FormGroup = null; @Input() formGroup: FormGroup = null;
@Input() viewOnly = false; @Input() viewOnly = false;
readonly separatorKeysCodes: number[] = [ENTER, COMMA];
externalDatasetAutoCompleteConfiguration: SingleAutoCompleteConfiguration = { externalDatasetAutoCompleteConfiguration: SingleAutoCompleteConfiguration = {
filterFn: this.searchDatasetExternalDatasets.bind(this), filterFn: this.searchDatasetExternalDatasets.bind(this),
initialItems: (type) => this.searchDatasetExternalDatasets('', type),//.filter(resultItem => (excludedItems || []).map(x => x.id).indexOf(resultItem.id) === -1), initialItems: (type) => this.searchDatasetExternalDatasets('', type),//.filter(resultItem => (excludedItems || []).map(x => x.id).indexOf(resultItem.id) === -1),
@ -228,4 +233,17 @@ export class DatasetExternalReferencesEditorComponent extends BaseComponent impl
requestItem.criteria.type = type; requestItem.criteria.type = type;
return this.externalSourcesService.searchDatasetTags(requestItem); return this.externalSourcesService.searchDatasetTags(requestItem);
} }
removeTag(tag: any) {
console.log((<FormArray>this.formGroup.get('tags')).value);
(<FormArray>this.formGroup.get('tags')).removeAt(((<FormArray>this.formGroup.get('tags')).value as any[]).indexOf(tag));
}
addTag(ev: MatChipInputEvent) {
console.log((<FormArray>this.formGroup.get('tags')).value);
if (ev.value !== '' && isNullOrUndefined(((<FormArray>this.formGroup.get('tags')).value as ExternalTagEditorModel[]).find(tag => tag.name === ev.value))) {
(<FormArray>this.formGroup.get('tags')).push(new ExternalTagEditorModel('',ev.value).buildForm());
}
ev.input.value='';
}
} }

@ -158,6 +158,9 @@ export class DatasetCriteriaComponent extends BaseCriteriaComponent implements O
this.formGroup.get('allVersions').valueChanges this.formGroup.get('allVersions').valueChanges
.pipe(takeUntil(this._destroyed)) .pipe(takeUntil(this._destroyed))
.subscribe(x => this.controlModified()); .subscribe(x => this.controlModified());
this.formGroup.get('tags').valueChanges
.pipe(takeUntil(this._destroyed))
.subscribe(x => this.controlModified());
// if (this.criteria == null) { this.criteria = {}; } // if (this.criteria == null) { this.criteria = {}; }
} }
@ -170,6 +173,7 @@ export class DatasetCriteriaComponent extends BaseCriteriaComponent implements O
this.formGroup.get('collaborators').patchValue(criteria.collaborators); this.formGroup.get('collaborators').patchValue(criteria.collaborators);
this.formGroup.get('datasetTemplates').patchValue(criteria.datasetTemplates); this.formGroup.get('datasetTemplates').patchValue(criteria.datasetTemplates);
this.formGroup.get('allVersions').patchValue(criteria.allVersions); this.formGroup.get('allVersions').patchValue(criteria.allVersions);
this.formGroup.get('tags').patchValue(criteria.tags);
// this.criteria = criteria; // this.criteria = criteria;
} }

@ -16,6 +16,7 @@ import { BaseComponent } from '@common/base/base.component';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { Observable, of as observableOf } from 'rxjs'; import { Observable, of as observableOf } from 'rxjs';
import { takeUntil } from 'rxjs/operators'; import { takeUntil } from 'rxjs/operators';
import { ExternalTagEditorModel } from '../dataset-wizard/dataset-wizard-editor.model';
@Component({ @Component({
selector: 'app-dataset-listing-component', selector: 'app-dataset-listing-component',
@ -105,7 +106,7 @@ export class DatasetListingComponent extends BaseComponent implements OnInit, IB
role: value.role role: value.role
} }
if (value.tags) { if (value.tags) {
request.criteria.tags = value.tags.map(x => x.id); request.criteria.tags = value.tags.map(x => (<ExternalTagEditorModel>x));
} }
if (value.collaborators) { if (value.collaborators) {
request.criteria.collaborators = value.collaborators.map(x => x.id); request.criteria.collaborators = value.collaborators.map(x => x.id);

Loading…
Cancel
Save