Browse Source

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

Remove_explore
George Kalampokis 2 years ago
parent
commit
9071faba38
  1. 2
      .gitignore
  2. 33
      dmp-backend/elastic/src/main/java/eu/eudat/elastic/criteria/DatasetCriteria.java
  3. 8
      dmp-backend/elastic/src/main/java/eu/eudat/elastic/entities/Collaborator.java
  4. 123
      dmp-backend/elastic/src/main/java/eu/eudat/elastic/entities/Dataset.java
  5. 41
      dmp-backend/elastic/src/main/java/eu/eudat/elastic/entities/Organization.java
  6. 31
      dmp-backend/elastic/src/main/java/eu/eudat/elastic/repository/DatasetRepository.java
  7. 2
      dmp-backend/elastic/src/main/java/eu/eudat/elastic/repository/Repository.java
  8. 27
      dmp-backend/web/src/main/java/eu/eudat/controllers/TagController.java
  9. 14
      dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java
  10. 54
      dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java
  11. 18
      dmp-frontend/src/app/ui/dataset/dataset-wizard/external-references/dataset-external-references-editor.component.html
  12. 18
      dmp-frontend/src/app/ui/dataset/dataset-wizard/external-references/dataset-external-references-editor.component.ts
  13. 4
      dmp-frontend/src/app/ui/dataset/listing/criteria/dataset-criteria.component.ts
  14. 3
      dmp-frontend/src/app/ui/dataset/listing/dataset-listing.component.ts

2
.gitignore

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

33
dmp-backend/elastic/src/main/java/eu/eudat/elastic/criteria/DatasetCriteria.java

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

8
dmp-backend/elastic/src/main/java/eu/eudat/elastic/entities/Collaborator.java

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

123
dmp-backend/elastic/src/main/java/eu/eudat/elastic/entities/Dataset.java

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

41
dmp-backend/elastic/src/main/java/eu/eudat/elastic/entities/Organization.java

@ -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;
}
}

31
dmp-backend/elastic/src/main/java/eu/eudat/elastic/repository/DatasetRepository.java

@ -2,6 +2,7 @@ package eu.eudat.elastic.repository;
import eu.eudat.elastic.criteria.DatasetCriteria;
import eu.eudat.elastic.entities.Dataset;
import eu.eudat.elastic.entities.Tag;
import org.elasticsearch.client.core.CountRequest;
import org.elasticsearch.client.core.CountResponse;
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.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.reindex.DeleteByQueryRequest;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -56,13 +58,13 @@ public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteri
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
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);
Long count = countResponse.getCount();
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()) {
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())));
}
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) {
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())));
}
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()) {
boolQuery.should(QueryBuilders.matchAllQuery());
} else {
@ -104,4 +122,13 @@ public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteri
// request.indices("datasets");
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);
}
}
}

2
dmp-backend/elastic/src/main/java/eu/eudat/elastic/repository/Repository.java

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

27
dmp-backend/web/src/main/java/eu/eudat/controllers/TagController.java

@ -1,30 +1,26 @@
package eu.eudat.controllers;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.elastic.criteria.DatasetCriteria;
import eu.eudat.elastic.criteria.TagCriteria;
import eu.eudat.elastic.entities.Dataset;
import eu.eudat.elastic.entities.Tag;
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.NoURLFound;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.data.external.TagExternalSourcesModel;
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.types.ApiMessageCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Collection;
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.
@ -46,12 +42,13 @@ public class TagController extends BaseController {
@RequestMapping(method = RequestMethod.GET, value = {"/external/tags"}, produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<TagExternalSourcesModel>> listExternalTagModel(
@RequestParam(value = "query", required = false) String query, @RequestParam(value = "type", required = false) String type) throws HugeResultSet, NoURLFound, IOException {
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query);
List<Map<String, String>> remoteRepos = this.getApiContext().getOperationsContext().getRemoteFetcher().getTags(externalUrlCriteria, type);
TagExternalSourcesModel researchersExternalSourcesModel = new TagExternalSourcesModel().fromExternalItem(remoteRepos);
ResponseEntity<ResponseItem<List<Tag>>> listExternalTagModel(
@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);
/*List<Map<String, String>> remoteRepos = this.getApiContext().getOperationsContext().getRemoteFetcher().getTags(externalUrlCriteria, type);
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));
}
}

14
dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java

@ -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()
.thenApplyAsync(entityDataset -> {
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.setDmp(newDmp);
newDataset.setStatus(Dataset.Status.SAVED.getValue());
@ -918,6 +923,15 @@ public class DataManagementPlanManager {
futures.add(datasetDao.createOrUpdateAsync(item));
return futures;
}).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);
}
});
}
}

54
dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java

@ -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.elastic.criteria.DatasetCriteria;
import eu.eudat.elastic.entities.Collaborator;
import eu.eudat.elastic.entities.Organization;
import eu.eudat.elastic.repository.DatasetRepository;
import eu.eudat.exceptions.security.UnauthorisedException;
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.user.composite.PagedDatasetProfile;
import eu.eudat.queryable.QueryableList;
import eu.eudat.types.Authorities;
import org.apache.commons.io.IOUtils;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
@ -111,9 +113,13 @@ public class DatasetManager {
if (datasetTableRequest.getCriteria().getStatus() != null) {
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.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;
try {
datasets = datasetRepository.exists() ?
@ -263,10 +269,13 @@ public class DatasetManager {
boolean latestVersion = profile.getVersion().toString().equals(datasetEntity.getProfile().getVersion().toString());
dataset.setIsProfileLatestVersion(latestVersion);
//dataset.setTags(datasetElastic.getTags());
if (datasetElastic != null && datasetElastic.getLabel() != null && !datasetElastic.getLabel().isEmpty()) {
dataset.setLabel(datasetElastic.getLabel());
if (datasetElastic != null && datasetElastic.getTags() != null && !datasetElastic.getTags().isEmpty()) {
dataset.setTags(datasetElastic.getTags());
}
/*if (datasetElastic != null && datasetElastic.getLabel() != null && !datasetElastic.getLabel().isEmpty()) {
dataset.setLabel(datasetElastic.getLabel());
}*/
return dataset;
}
@ -548,23 +557,38 @@ public class DatasetManager {
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()) {
eu.eudat.elastic.entities.Dataset dataset = new eu.eudat.elastic.entities.Dataset();
dataset.setId(datasetWizardModel.getId().toString());
// dataset.setTags(datasetWizardModel.getTags());
eu.eudat.elastic.entities.Dataset dataset = new eu.eudat.elastic.entities.Dataset();
dataset.setId(datasetWizardModel.getId().toString());
dataset.setTags(datasetWizardModel.getTags());
dataset.setLabel(datasetWizardModel.getLabel());
dataset.setTemplate(datasetWizardModel.getProfile());
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.setCollaborators(datasetWizardModel.getDmp().getUsers().stream().map(user -> {
Collaborator collaborator = new Collaborator();
collaborator.setId(user.getId());
collaborator.setId(user.getId().toString());
collaborator.setName(user.getName());
return collaborator;
}).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.
dataset.setIsProfileLatestVersion(true);
//dataset.setTags(datasetElastic.getTags());
if (datasetElastic != null && datasetElastic.getLabel() != null && !datasetElastic.getLabel().isEmpty()) {
dataset.setLabel(datasetElastic.getLabel());
if (datasetElastic != null && datasetElastic.getTags() != null && !datasetElastic.getTags().isEmpty()) {
dataset.setTags(datasetElastic.getTags());
}
/*if (datasetElastic != null && datasetElastic.getLabel() != null && !datasetElastic.getLabel().isEmpty()) {
dataset.setLabel(datasetElastic.getLabel());
}*/
return dataset;
}

18
dmp-frontend/src/app/ui/dataset/dataset-wizard/external-references/dataset-external-references-editor.component.html

@ -146,8 +146,22 @@
<h4 class="col-auto">{{'DATASET-EDITOR.FIELDS.TAGS' | translate}}</h4>
</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>
<!-- <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> -->
<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">
<div class="col-12 row align-items-center">

18
dmp-frontend/src/app/ui/dataset/dataset-wizard/external-references/dataset-external-references-editor.component.ts

@ -22,6 +22,9 @@ import { BaseComponent } from '@common/base/base.component';
import { TranslateService } from '@ngx-translate/core';
import { Observable } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { ENTER, COMMA } from '@angular/cdk/keycodes';
import { MatChipInputEvent } from '@angular/material/chips';
import { isNullOrUndefined } from 'util';
@Component({
selector: 'app-dataset-external-references-editor-component',
@ -33,6 +36,8 @@ export class DatasetExternalReferencesEditorComponent extends BaseComponent impl
@Input() formGroup: FormGroup = null;
@Input() viewOnly = false;
readonly separatorKeysCodes: number[] = [ENTER, COMMA];
externalDatasetAutoCompleteConfiguration: SingleAutoCompleteConfiguration = {
filterFn: this.searchDatasetExternalDatasets.bind(this),
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;
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='';
}
}

4
dmp-frontend/src/app/ui/dataset/listing/criteria/dataset-criteria.component.ts

@ -158,6 +158,9 @@ export class DatasetCriteriaComponent extends BaseCriteriaComponent implements O
this.formGroup.get('allVersions').valueChanges
.pipe(takeUntil(this._destroyed))
.subscribe(x => this.controlModified());
this.formGroup.get('tags').valueChanges
.pipe(takeUntil(this._destroyed))
.subscribe(x => this.controlModified());
// 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('datasetTemplates').patchValue(criteria.datasetTemplates);
this.formGroup.get('allVersions').patchValue(criteria.allVersions);
this.formGroup.get('tags').patchValue(criteria.tags);
// this.criteria = criteria;
}

3
dmp-frontend/src/app/ui/dataset/listing/dataset-listing.component.ts

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

Loading…
Cancel
Save