Fixes bug not saving properly new External References on Dataset Description.

This commit is contained in:
gkolokythas 2019-12-13 17:10:21 +02:00
parent 3bab68265b
commit 43134fa959
12 changed files with 72 additions and 31 deletions

View File

@ -43,10 +43,10 @@ public class DataRepositories extends BaseController {
@Transactional
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<DataRepository>> create(@RequestBody eu.eudat.models.data.datarepository.DataRepositoryModel dataRepositoryModel, Principal principal) throws Exception {
ResponseEntity<ResponseItem<DataRepositoryModel>> create(@RequestBody eu.eudat.models.data.datarepository.DataRepositoryModel dataRepositoryModel, Principal principal) throws Exception {
DataRepository dataRepository = this.dataRepositoryManager.create(dataRepositoryModel, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataRepository>().payload(dataRepository).status(ApiMessageCode.SUCCESS_MESSAGE));
DataRepositoryModel dataRepositoryModel1 = new DataRepositoryModel().fromDataModel(dataRepository);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataRepositoryModel>().payload(dataRepositoryModel1).status(ApiMessageCode.SUCCESS_MESSAGE));
}
}

View File

@ -62,8 +62,9 @@ public class ExternalDatasets extends BaseController {
@Transactional
@RequestMapping(method = RequestMethod.POST, value = {"/externaldatasets"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<ExternalDataset>> create(@RequestBody eu.eudat.models.data.externaldataset.ExternalDatasetModel externalDatasetModel, Principal principal) throws Exception {
ResponseEntity<ResponseItem<ExternalDatasetListingModel>> create(@RequestBody eu.eudat.models.data.externaldataset.ExternalDatasetModel externalDatasetModel, Principal principal) throws Exception {
ExternalDataset externalDataset = this.externalDatasetManager.create(externalDatasetModel, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ExternalDataset>().payload(externalDataset).status(ApiMessageCode.SUCCESS_MESSAGE));
ExternalDatasetListingModel externalDatasetListingModel = new ExternalDatasetListingModel().fromDataModel(externalDataset);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ExternalDatasetListingModel>().payload(externalDatasetListingModel).status(ApiMessageCode.SUCCESS_MESSAGE));
}
}

View File

@ -42,10 +42,10 @@ public class Registries extends BaseController {
@Transactional
@RequestMapping(method = RequestMethod.POST, value = {"/registries"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<Registry>> create(@RequestBody RegistryModel registryModel, Principal principal) throws Exception {
ResponseEntity<ResponseItem<RegistryModel>> create(@RequestBody RegistryModel registryModel, Principal principal) throws Exception {
Registry registry = this.registryManager.create(registryModel, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Registry>().payload(registry).status(ApiMessageCode.SUCCESS_MESSAGE));
RegistryModel registryModel1 = new RegistryModel().fromDataModel(registry);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<RegistryModel>().payload(registryModel1).status(ApiMessageCode.SUCCESS_MESSAGE));
}
}

View File

@ -43,9 +43,10 @@ public class Services extends BaseController {
@Transactional
@RequestMapping(method = RequestMethod.POST, value = {"/services"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<Service>> create(@RequestBody ServiceModel serviceModel, Principal principal) throws Exception {
ResponseEntity<ResponseItem<ServiceModel>> create(@RequestBody ServiceModel serviceModel, Principal principal) throws Exception {
Service service = serviceManager.create(serviceModel, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Service>().payload(service).status(ApiMessageCode.SUCCESS_MESSAGE));
ServiceModel serviceModel1 = new ServiceModel().fromDataModel(service);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ServiceModel>().payload(serviceModel1).status(ApiMessageCode.SUCCESS_MESSAGE));
}
}

View File

@ -87,6 +87,7 @@ public class DataRepositoryModel implements DataModel<DataRepository, DataReposi
this.setName(entity.getLabel());
this.setUri(entity.getUri());
this.setId(entity.getId());
this.setPid(entity.getReference());
String source1 = entity.getReference().substring(0, entity.getReference().indexOf(":"));
if (source1.equals("dmp")) {
this.source = "Internal";

View File

@ -4,16 +4,26 @@ import eu.eudat.models.DataModel;
import eu.eudat.logic.utilities.helpers.LabelGenerator;
import java.util.Date;
import java.util.UUID;
public class DataRepository implements DataModel<eu.eudat.data.entities.DataRepository, DataRepository>, LabelGenerator {
private String id;
private String pid;
private String name;
private String uri;
private String info;
private String reference;
private String abbreviation;
private String tag;
private String source;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPid() {
return pid;
}
@ -49,6 +59,13 @@ public class DataRepository implements DataModel<eu.eudat.data.entities.DataRepo
this.reference = reference;
}
public String getAbbreviation() {
return abbreviation;
}
public void setAbbreviation(String abbreviation) {
this.abbreviation = abbreviation;
}
public String getTag() {
return tag;
}
@ -64,9 +81,11 @@ public class DataRepository implements DataModel<eu.eudat.data.entities.DataRepo
}
public DataRepository fromDataModel(eu.eudat.data.entities.DataRepository entity) {
this.id = entity.getId().toString();
this.pid = entity.getReference();
this.name = entity.getLabel();
this.uri = entity.getUri();
this.abbreviation = entity.getAbbreviation();
this.reference = entity.getReference();
String source1 = entity.getReference().substring(0, entity.getReference().indexOf(":"));
if (source1.equals("dmp")) {
@ -79,6 +98,9 @@ public class DataRepository implements DataModel<eu.eudat.data.entities.DataRepo
public eu.eudat.data.entities.DataRepository toDataModel() {
eu.eudat.data.entities.DataRepository entity = new eu.eudat.data.entities.DataRepository();
if (this.id != null) {
entity.setId(UUID.fromString(this.id));
}
entity.setReference(this.pid);
entity.setLabel(this.name);
entity.setUri(this.uri);
@ -94,6 +116,10 @@ public class DataRepository implements DataModel<eu.eudat.data.entities.DataRepo
entity.setReference(this.source.toLowerCase() + ":" + this.reference);
}
}
if (this.abbreviation != null)
entity.setAbbreviation(this.abbreviation);
return entity;
}

View File

@ -159,7 +159,7 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
this.registries = entity.getRegistries().stream().map(item -> new Registry().fromDataModel(item)).collect(Collectors.toList());
this.dataRepositories = entity.getDatasetDataRepositories().stream().map(item -> {
DataRepository dataRepository = new DataRepository().fromDataModel(item.getDataRepository());
if(item.getData()!=null) {
if (item.getData() != null) {
Map<String, Map<String, String>> data = (Map<String, Map<String, String>>) JSONValue.parse(item.getData());
Map<String, String> values = data.get("data");
dataRepository.setInfo(values.get("info"));
@ -171,7 +171,7 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
this.dmp = new DataManagementPlan().fromDataModelNoDatasets(entity.getDmp());
this.externalDatasets = entity.getDatasetExternalDatasets().stream().map(item -> {
ExternalDatasetListingModel externalDatasetListingModel = new ExternalDatasetListingModel().fromDataModel(item.getExternalDataset());
if(item.getData()!= null) {
if (item.getData() != null) {
Map<String, Map<String, String>> data = (Map<String, Map<String, String>>) JSONValue.parse(item.getData());
Map<String, String> values = data.get("data");
externalDatasetListingModel.setInfo(values.get("info"));
@ -214,10 +214,10 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
eu.eudat.data.entities.DataRepository dataRepository = dataRepositoryModel.toDataModel();
DatasetDataRepository datasetDataRepository = new DatasetDataRepository();
datasetDataRepository.setDataRepository(dataRepository);
Map<String,Map<String,String>> data = new HashMap<>();
Map<String,String> values = new HashMap<>();
values.put("info",dataRepositoryModel.getInfo());
data.put("data",values);
Map<String, Map<String, String>> data = new HashMap<>();
Map<String, String> values = new HashMap<>();
values.put("info", dataRepositoryModel.getInfo());
data.put("data", values);
datasetDataRepository.setData(JSONValue.toJSONString(data));
entity.getDatasetDataRepositories().add(datasetDataRepository);
}

View File

@ -140,6 +140,9 @@ public class ExternalDatasetListingModel implements DataModel<ExternalDataset, E
externalDataset.setReference(this.source.toLowerCase() + ":" + this.reference);
}
}
if (externalDataset.getReference() == null) {
externalDataset.setReference(this.pid);
}
externalDataset.setModified(new Date());
return externalDataset;
}

View File

@ -9,7 +9,7 @@ import java.util.UUID;
public class ExternalDatasetModel implements DataModel<ExternalDataset, ExternalDatasetModel> {
public UUID id;
public String label;
public String name;
public String abbreviation;
public Date created;
public Date modified;
@ -22,11 +22,11 @@ public class ExternalDatasetModel implements DataModel<ExternalDataset, External
this.id = id;
}
public String getLabel() {
return label;
public String getName() {
return name;
}
public void setLabel(String label) {
this.label = label;
public void setName(String name) {
this.name = name;
}
public String getAbbreviation() {
@ -60,7 +60,7 @@ public class ExternalDatasetModel implements DataModel<ExternalDataset, External
@Override
public ExternalDatasetModel fromDataModel(ExternalDataset entity) {
this.id = entity.getId();
this.label = entity.getLabel();
this.name = entity.getLabel();
this.abbreviation = entity.getAbbreviation();
this.created = entity.getCreated();
this.modified = new Date();
@ -80,7 +80,7 @@ public class ExternalDatasetModel implements DataModel<ExternalDataset, External
externalDataset.setCreated(this.created != null ? this.created : new Date());
externalDataset.setModified(new Date());
externalDataset.setId(this.id != null ? this.id : UUID.randomUUID());
externalDataset.setLabel(this.label);
externalDataset.setLabel(this.name);
externalDataset.setReference("dmp:" + externalDataset.getId());
externalDataset.setCreationUser(new UserInfo());
return externalDataset;

View File

@ -18,6 +18,7 @@ public class RegistryModel implements DataModel<Registry, RegistryModel> {
private String uri;
private Date created;
private Date modified;
private String reference;
private String tag; // Api fetching the data
private String source; // Actual harvested source
@ -70,6 +71,13 @@ public class RegistryModel implements DataModel<Registry, RegistryModel> {
this.modified = modified;
}
public String getReference() {
return reference;
}
public void setReference(String reference) {
this.reference = reference;
}
public String getTag() {
return tag;
}
@ -106,6 +114,7 @@ public class RegistryModel implements DataModel<Registry, RegistryModel> {
} else {
this.source = source1;
}
this.reference = entity.getReference();
return this;
}

View File

@ -203,7 +203,7 @@ export class ExternalServiceEditorModel {
buildForm(context: ValidationContext = null, disabled: boolean = false): FormGroup {
return new FormBuilder().group({
id: [this.id],
abbreviation: [this.abbreviation, Validators.required],
abbreviation: [this.abbreviation],
label: [this.label, Validators.required],
reference: [this.reference],
uri: [this.uri, Validators.required],
@ -246,7 +246,7 @@ export class ExternalRegistryEditorModel {
buildForm(context: ValidationContext = null, disabled: boolean = false): FormGroup {
return new FormBuilder().group({
id: [this.id],
abbreviation: [this.abbreviation, Validators.required],
abbreviation: [this.abbreviation],
label: [this.label, Validators.required],
reference: [this.reference],
uri: [this.uri, Validators.required],
@ -291,7 +291,7 @@ export class ExternalDatasetEditorModel {
buildForm(context: ValidationContext = null, disabled: boolean = false): FormGroup {
return new FormBuilder().group({
id: [this.id],
abbreviation: [this.abbreviation, Validators.required],
abbreviation: [this.abbreviation],
name: [this.name, Validators.required],
reference: [this.reference],
type: [this.type],
@ -336,7 +336,7 @@ export class ExternalDataRepositoryEditorModel {
return new FormBuilder().group({
id: [this.id],
name: [this.name, [Validators.required]],
abbreviation: [this.abbreviation, [Validators.required]],
abbreviation: [this.abbreviation],
uri: [this.uri, [Validators.required]],
info: [this.info],
reference: [this.reference],

View File

@ -139,7 +139,7 @@ export class DatasetExternalReferencesEditorComponent extends BaseComponent impl
.pipe(takeUntil(this._destroyed))
.subscribe(result => {
if (!result) { return; }
const dataRepositoryModel = new ExternalDataRepositoryEditorModel(result.id, result.name, result.pid, result.uri, result.reference);
const dataRepositoryModel = new ExternalDataRepositoryEditorModel(result.id, result.name, result.abbreviation, result.uri, result.pid, result.source);
(<FormArray>this.formGroup.get('dataRepositories')).push(dataRepositoryModel.buildForm());
});
}
@ -154,7 +154,7 @@ export class DatasetExternalReferencesEditorComponent extends BaseComponent impl
.pipe(takeUntil(this._destroyed))
.subscribe(result => {
if (!result) { return; }
const registryModel = new ExternalRegistryEditorModel(result.abbreviation, result.definition, result.id, result.label, result.reference, result.uri);
const registryModel = new ExternalRegistryEditorModel(result.abbreviation, result.definition, result.id, result.label, result.reference, result.uri, result.source);
(<FormArray>this.formGroup.get('registries')).push(registryModel.buildForm());
});
}
@ -169,7 +169,7 @@ export class DatasetExternalReferencesEditorComponent extends BaseComponent impl
.pipe(takeUntil(this._destroyed))
.subscribe(result => {
if (!result) { return; }
const externalDatasetModel = new ExternalDatasetEditorModel(result.id, result.abbreviation, result.label, result.reference);
const externalDatasetModel = new ExternalDatasetEditorModel(result.id, result.abbreviation, result.name, result.reference, result.source);
(<FormArray>this.formGroup.get('externalDatasets')).push(externalDatasetModel.buildForm());
});
}
@ -184,7 +184,7 @@ export class DatasetExternalReferencesEditorComponent extends BaseComponent impl
.pipe(takeUntil(this._destroyed))
.subscribe(result => {
if (!result) { return; }
const serviceModel = new ExternalServiceEditorModel(result.abbreviation, result.definition, result.id, result.label, result.reference, result.uri);
const serviceModel = new ExternalServiceEditorModel(result.abbreviation, result.definition, result.id, result.label, result.reference, result.uri, result.source);
(<FormArray>this.formGroup.get('services')).push(serviceModel.buildForm());
});
}