diff --git a/.gitignore b/.gitignore index 68711a876..670c07133 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,5 @@ dmp-frontend/.vscode/ dmp-frontend/package-lock.json +dmp-backend/logging/target/ +ELK.Docker/shared/data-elk/ diff --git a/dmp-backend/elastic/src/main/java/eu/eudat/elastic/criteria/DatasetCriteria.java b/dmp-backend/elastic/src/main/java/eu/eudat/elastic/criteria/DatasetCriteria.java index 51cb10558..1896b7ca8 100644 --- a/dmp-backend/elastic/src/main/java/eu/eudat/elastic/criteria/DatasetCriteria.java +++ b/dmp-backend/elastic/src/main/java/eu/eudat/elastic/criteria/DatasetCriteria.java @@ -13,9 +13,12 @@ public class DatasetCriteria extends Criteria { private List datasetTemplates; private Short status; private List dmps; + private List groupIds; private List grants; private List collaborators; -// public List tags; + private Boolean allowAllVersions; + private List organiztions; + public List tags; public String getLabel() { return label; @@ -49,6 +52,14 @@ public class DatasetCriteria extends Criteria { this.dmps = dmps; } + public List getGroupIds() { + return groupIds; + } + + public void setGroupIds(List groupIds) { + this.groupIds = groupIds; + } + public List getGrants() { return grants; } @@ -65,11 +76,27 @@ public class DatasetCriteria extends Criteria { this.collaborators = collaborators; } - /*public List getTags() { + public Boolean getAllowAllVersions() { + return allowAllVersions; + } + + public void setAllowAllVersions(Boolean allowAllVersions) { + this.allowAllVersions = allowAllVersions; + } + + public List getOrganiztions() { + return organiztions; + } + + public void setOrganiztions(List organiztions) { + this.organiztions = organiztions; + } + + public List getTags() { return tags; } public void setTags(List tags) { this.tags = tags; - }*/ + } } diff --git a/dmp-backend/elastic/src/main/java/eu/eudat/elastic/entities/Collaborator.java b/dmp-backend/elastic/src/main/java/eu/eudat/elastic/entities/Collaborator.java index 6f9ad9e60..0bae37a7e 100644 --- a/dmp-backend/elastic/src/main/java/eu/eudat/elastic/entities/Collaborator.java +++ b/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 { - 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 { @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; diff --git a/dmp-backend/elastic/src/main/java/eu/eudat/elastic/entities/Dataset.java b/dmp-backend/elastic/src/main/java/eu/eudat/elastic/entities/Dataset.java index 62578a76c..fce4725eb 100644 --- a/dmp-backend/elastic/src/main/java/eu/eudat/elastic/entities/Dataset.java +++ b/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 { 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 tags = new LinkedList<>(); + private List tags = new LinkedList<>(); private String label; private UUID template; private Short status; private UUID dmp; + private UUID group; private UUID grant; private List collaborators; + private Boolean lastVersion; + private List organizations; public String getId() { return id; @@ -34,13 +66,13 @@ public class Dataset implements ElasticEntity { this.id = id; } - /*public List getTags() { + public List getTags() { return tags; } public void setTags(List tags) { this.tags = tags; - }*/ + } public String getLabel() { return label; @@ -74,6 +106,14 @@ public class Dataset implements ElasticEntity { 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 { this.collaborators = collaborators; } + public Boolean getLastVersion() { + return lastVersion; + } + + public void setLastVersion(Boolean lastVersion) { + this.lastVersion = lastVersion; + } + + public List getOrganizations() { + return organizations; + } + + public void setOrganizations(List organizations) { + this.organizations = organizations; + } + @Override public XContentBuilder toElasticEntity(XContentBuilder builder) throws IOException { builder.startObject(); @@ -98,26 +154,44 @@ public class Dataset implements ElasticEntity { 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); - } + 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.startArray("tags"); - this.tags.forEach(x -> { - try { - x.toElasticEntity(builder); - } catch (IOException e) { - logger.error(e.getMessage(), e); - } - }); - builder.endArray();*/ + }); + 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 { public Dataset fromElasticEntity(Map fields) { if (fields != null) { this.id = (String) fields.get("id"); -// this.tags = ((List) fields.get("tags")); + this.tags = ((List) 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) fields.get("collaborators")); + this.lastVersion = Boolean.parseBoolean((String) fields.get("lastVersion")); + this.organizations = (List) fields.get("organiztions"); } return this; } diff --git a/dmp-backend/elastic/src/main/java/eu/eudat/elastic/entities/Organization.java b/dmp-backend/elastic/src/main/java/eu/eudat/elastic/entities/Organization.java new file mode 100644 index 000000000..4400d4528 --- /dev/null +++ b/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 { + 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) { + return null; + } +} diff --git a/dmp-backend/elastic/src/main/java/eu/eudat/elastic/repository/DatasetRepository.java b/dmp-backend/elastic/src/main/java/eu/eudat/elastic/repository/DatasetRepository.java index 257ffabf1..7013423ba 100644 --- a/dmp-backend/elastic/src/main/java/eu/eudat/elastic/repository/DatasetRepository.java +++ b/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 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 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 { List query(C criteria) throws ExecutionException, InterruptedException, IOException; boolean exists() throws IOException; + + void clear() throws IOException; } diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/TagController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/TagController.java index 4f1bad5cf..87f47f03b 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/TagController.java +++ b/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> 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> remoteRepos = this.getApiContext().getOperationsContext().getRemoteFetcher().getTags(externalUrlCriteria, type); - TagExternalSourcesModel researchersExternalSourcesModel = new TagExternalSourcesModel().fromExternalItem(remoteRepos); + ResponseEntity>> 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> remoteRepos = this.getApiContext().getOperationsContext().getRemoteFetcher().getTags(externalUrlCriteria, type); + TagExternalSourcesModel researchersExternalSourcesModel = new TagExternalSourcesModel().fromExternalItem(remoteRepos);*/ + List 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().payload(researchersExternalSourcesModel).status(ApiMessageCode.NO_MESSAGE)); + return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().payload(tags).status(ApiMessageCode.NO_MESSAGE)); } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java index c42649e4a..6fffa599b 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java +++ b/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); + } + }); } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java index 4fdc54750..9ce9242a9 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java +++ b/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 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; } diff --git a/dmp-frontend/src/app/ui/dataset/dataset-wizard/external-references/dataset-external-references-editor.component.html b/dmp-frontend/src/app/ui/dataset/dataset-wizard/external-references/dataset-external-references-editor.component.html index 7f2d0a72f..606d25a32 100644 --- a/dmp-frontend/src/app/ui/dataset/dataset-wizard/external-references/dataset-external-references-editor.component.html +++ b/dmp-frontend/src/app/ui/dataset/dataset-wizard/external-references/dataset-external-references-editor.component.html @@ -146,8 +146,22 @@

{{'DATASET-EDITOR.FIELDS.TAGS' | translate}}

- - + + + + + {{tag.name}} + cancel + + + +
diff --git a/dmp-frontend/src/app/ui/dataset/dataset-wizard/external-references/dataset-external-references-editor.component.ts b/dmp-frontend/src/app/ui/dataset/dataset-wizard/external-references/dataset-external-references-editor.component.ts index 52d127d83..7cb9c36c2 100644 --- a/dmp-frontend/src/app/ui/dataset/dataset-wizard/external-references/dataset-external-references-editor.component.ts +++ b/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((this.formGroup.get('tags')).value); + (this.formGroup.get('tags')).removeAt(((this.formGroup.get('tags')).value as any[]).indexOf(tag)); + } + + addTag(ev: MatChipInputEvent) { + console.log((this.formGroup.get('tags')).value); + if (ev.value !== '' && isNullOrUndefined(((this.formGroup.get('tags')).value as ExternalTagEditorModel[]).find(tag => tag.name === ev.value))) { + (this.formGroup.get('tags')).push(new ExternalTagEditorModel('',ev.value).buildForm()); + } + ev.input.value=''; + } } diff --git a/dmp-frontend/src/app/ui/dataset/listing/criteria/dataset-criteria.component.ts b/dmp-frontend/src/app/ui/dataset/listing/criteria/dataset-criteria.component.ts index 5aacdca71..ff25e65ab 100644 --- a/dmp-frontend/src/app/ui/dataset/listing/criteria/dataset-criteria.component.ts +++ b/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; } diff --git a/dmp-frontend/src/app/ui/dataset/listing/dataset-listing.component.ts b/dmp-frontend/src/app/ui/dataset/listing/dataset-listing.component.ts index af9aceece..5c433745b 100644 --- a/dmp-frontend/src/app/ui/dataset/listing/dataset-listing.component.ts +++ b/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 => (x)); } if (value.collaborators) { request.criteria.collaborators = value.collaborators.map(x => x.id);