Fixed and Improved Dataset indexing

This commit is contained in:
George Kalampokis 2020-03-13 18:33:58 +02:00
parent 1a06bb98c6
commit 33539788f9
6 changed files with 31 additions and 16 deletions

View File

@ -36,7 +36,9 @@ public class Collaborator implements ElasticEntity<Collaborator> {
} }
@Override @Override
public Collaborator fromElasticEntity(Map<String, Object> fields) { public Collaborator fromElasticEntity(Map fields) {
return null; this.id = (String) fields.get("id");
this.name = (String) fields.get("name");
return this;
} }
} }

View File

@ -5,10 +5,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.util.LinkedList; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -202,16 +199,22 @@ 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")); 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.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.group = UUID.fromString((String) fields.get("group"));
this.grant = UUID.fromString((String) fields.get("grant")); this.grant = UUID.fromString((String) fields.get("grant"));
this.collaborators = ((List<Collaborator>) fields.get("collaborators")); 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.lastVersion = Boolean.parseBoolean((String) fields.get("lastVersion"));
this.organizations = (List<Organization>) fields.get("organiztions"); if (fields.get("organizations") != null) {
this.organizations = ((List<HashMap>) fields.get("organizations")).stream().map(hashMap -> new Organization().fromElasticEntity(hashMap)).collect(Collectors.toList());
}
} }
return this; return this;
} }

View File

@ -35,7 +35,9 @@ public class Organization implements ElasticEntity<Organization> {
} }
@Override @Override
public Organization fromElasticEntity(Map<String, Object> fields) { public Organization fromElasticEntity(Map fields) {
return null; this.id = (String) fields.get("id");
this.name = (String) fields.get("name");
return this;
} }
} }

View File

@ -39,7 +39,9 @@ public class Tag implements ElasticEntity {
} }
@Override @Override
public Object fromElasticEntity(Map fields) { public Tag fromElasticEntity(Map fields) {
return null; this.id = (String) fields.get("id");
this.name = (String) fields.get("name");
return this;
} }
} }

View File

@ -33,6 +33,7 @@ import eu.eudat.models.data.datasetImport.DatasetImportPagedDatasetProfile;
import eu.eudat.models.data.datasetprofile.DatasetProfileListingModel; import eu.eudat.models.data.datasetprofile.DatasetProfileListingModel;
import eu.eudat.models.data.datasetwizard.DatasetWizardModel; import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
import eu.eudat.models.data.dmp.AssociatedProfile; import eu.eudat.models.data.dmp.AssociatedProfile;
import eu.eudat.models.data.dmp.DataManagementPlan;
import eu.eudat.models.data.helpers.common.DataTableData; import eu.eudat.models.data.helpers.common.DataTableData;
import eu.eudat.models.data.listingmodels.DatasetListingModel; import eu.eudat.models.data.listingmodels.DatasetListingModel;
import eu.eudat.models.data.security.Principal; import eu.eudat.models.data.security.Principal;
@ -489,6 +490,7 @@ public class DatasetManager {
Dataset dataset1 = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(dataset); Dataset dataset1 = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(dataset);
datasetWizardModel.setId(dataset1.getId()); datasetWizardModel.setId(dataset1.getId());
datasetWizardModel.setDmp(new DataManagementPlan().fromDataModel(dataset1.getDmp()));
updateTags(apiContext.getOperationsContext().getDatasetRepository(), datasetWizardModel); updateTags(apiContext.getOperationsContext().getDatasetRepository(), datasetWizardModel);
if (sendNotification) { if (sendNotification) {
if (dataset1.getStatus() != Dataset.Status.FINALISED.getValue()) { if (dataset1.getStatus() != Dataset.Status.FINALISED.getValue()) {

View File

@ -15,6 +15,7 @@ import eu.eudat.models.data.dmp.DataManagementPlan;
import eu.eudat.models.data.security.Principal; import eu.eudat.models.data.security.Principal;
import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.QueryableList;
import java.io.IOException;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -47,9 +48,12 @@ public class DatasetWizardManager {
return; return;
} }
public void delete(ApiContext apiContext, UUID uuid) { public void delete(ApiContext apiContext, UUID uuid) throws IOException {
Dataset oldDataset = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().find(uuid); Dataset oldDataset = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().find(uuid);
oldDataset.setStatus(DMP.DMPStatus.DELETED.getValue()); eu.eudat.elastic.entities.Dataset oldDatasetElasitc = apiContext.getOperationsContext().getDatasetRepository().findDocument(uuid.toString());
oldDataset.setStatus(Dataset.Status.DELETED.getValue());
oldDatasetElasitc.setStatus(oldDataset.getStatus());
apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(oldDataset); apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(oldDataset);
apiContext.getOperationsContext().getDatasetRepository().createOrUpdate(oldDatasetElasitc);
} }
} }