diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/entities/Dataset.java b/dmp-backend/data/src/main/java/eu/eudat/data/entities/Dataset.java index 53bc5af63..4e695cd87 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/entities/Dataset.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/entities/Dataset.java @@ -81,13 +81,11 @@ public class Dataset implements DataEntity { @Column(name = "\"Label\"") private String label; - @ManyToOne(fetch = FetchType.LAZY) // @Cascade(value=org.hibernate.annotations.CascadeType.ALL) @JoinColumn(name = "\"DMP\"", nullable = false) private DMP dmp; - @Column(name = "\"Uri\"") private String uri; @@ -95,7 +93,6 @@ public class Dataset implements DataEntity { @Column(name = "\"Properties\"", columnDefinition = "xml", nullable = true) private String properties; - @ManyToOne(fetch = FetchType.LAZY) //@Cascade(value=org.hibernate.annotations.CascadeType.ALL) @JoinColumn(name = "\"Profile\"", nullable = true) @@ -112,18 +109,15 @@ public class Dataset implements DataEntity { ) private Set registries; - @OneToMany(mappedBy = "dataset", cascade = CascadeType.ALL, orphanRemoval = true) private Set datasetDataRepositories; - @OneToMany(mappedBy = "dataset", cascade = CascadeType.ALL, orphanRemoval = true) private Set services; @OneToMany(mappedBy = "dataset", cascade = CascadeType.ALL, orphanRemoval = true) private Set datasetExternalDatasets; - @Column(name = "\"Status\"", nullable = false) private Short status; diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/entities/DatasetProfile.java b/dmp-backend/data/src/main/java/eu/eudat/data/entities/DatasetProfile.java index a78f5598f..d8e3393da 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/entities/DatasetProfile.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/entities/DatasetProfile.java @@ -15,7 +15,7 @@ import java.util.UUID; @Entity @Table(name = "\"DatasetProfile\"") -public class DatasetProfile implements DataEntity { +public class DatasetProfile implements DataEntity{ public enum Status { SAVED((short) 0), FINALIZED((short) 1), DELETED((short) 99); @@ -142,7 +142,7 @@ public class DatasetProfile implements DataEntity { @Override public String toString() { - return "DatasetProfileListingModel [id=" + id + ", label=" + label + ", dataset=" + dataset + ", definition=" + definition + "]"; + return "DatasetProfileListingModel [id=" + id + ", label=" + label + ", dataset=" + dataset + ", definition=" + definition + ", version=" + version + "]"; } @Override diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetWizardController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetWizardController.java index 741c8ce06..9b84ab024 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetWizardController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetWizardController.java @@ -194,4 +194,11 @@ public class DatasetWizardController extends BaseController { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).message("Import was unsuccessful.")); } } + + @RequestMapping(method = RequestMethod.GET, value = {"profile/{id}"}, produces = "application/json") + public @ResponseBody + ResponseEntity getSingleProfileUpdate(@PathVariable String id, @ClaimedAuthorities(claims = {ANONYMOUS}) Principal principal) throws IllegalAccessException, IOException, InstantiationException { + DatasetWizardModel dataset = this.datasetManager.datasetUpdateProfile(id); + return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).payload(dataset)); + } } 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 bddcc150f..90f4e66bd 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 @@ -1,9 +1,6 @@ package eu.eudat.logic.managers; -import eu.eudat.data.dao.criteria.DataRepositoryCriteria; -import eu.eudat.data.dao.criteria.ExternalDatasetCriteria; -import eu.eudat.data.dao.criteria.RegistryCriteria; -import eu.eudat.data.dao.criteria.ServiceCriteria; +import eu.eudat.data.dao.criteria.*; import eu.eudat.data.dao.entities.*; import eu.eudat.data.entities.*; import eu.eudat.data.query.items.table.dataset.DatasetPublicTableRequest; @@ -22,6 +19,7 @@ import eu.eudat.logic.utilities.documents.xml.ExportXmlBuilder; import eu.eudat.models.HintedModelFactory; import eu.eudat.models.data.datasetImport.*; import eu.eudat.models.data.datasetwizard.DatasetWizardModel; +import eu.eudat.models.data.dmp.AssociatedProfile; import eu.eudat.models.data.helpers.common.DataTableData; import eu.eudat.models.data.listingmodels.DatasetListingModel; import eu.eudat.models.data.security.Principal; @@ -168,6 +166,44 @@ public class DatasetManager { } dataset.setDatasetProfileDefinition(getPagedProfile(dataset, datasetEntity)); dataset.fromDataModel(datasetEntity); + + // Creates the Criteria to get all version of DatasetProfile in question. + DatasetProfileCriteria profileCriteria = new DatasetProfileCriteria(); + UUID profileId = datasetEntity.getProfile().getGroupId(); + List uuidList = new LinkedList<>(); + uuidList.add(profileId); + profileCriteria.setGroupIds(uuidList); + profileCriteria.setAllVersions(true); + List items = databaseRepository.getDatasetProfileDao().getWithCriteria(profileCriteria) + .orderBy(((builder, root) -> builder.asc(root.get("version")))) + .toList(); + + // Search if the Dataset needs dataset Profile update depending on his DMP associated profiles. + AssociatedProfile associatedProfile = new AssociatedProfile(); + boolean y = true; + // Start the Dataset Profile List from the latest to the earliest. + for (int x=(items.size()-1); x>=0; x--) { + associatedProfile.setId(items.get(x).getId()); + // Check if Dmp contains this profile. + for(AssociatedProfile p : dataset.getDmp().getProfiles() ) { + if (p.getId().toString().equals(associatedProfile.getId().toString())) { + Short latestVersion = items.get(x).getVersion(); + if (latestVersion.equals(datasetEntity.getProfile().getVersion())) { + dataset.setIsProfileLatestVersion(true); + y = false; + break; + } else { + dataset.setIsProfileLatestVersion(false); + y = false; + break; + } + } + } + if (!y){ + break; + } + } + dataset.setTags(datasetElastic.getTags()); return dataset; } @@ -255,7 +291,7 @@ public class DatasetManager { HttpEntity> requestEntity = new HttpEntity>( map, headers); - byte[] queueResult = new RestTemplate().postForObject("http://localhost:3000/convert/office" + byte[] queueResult = new RestTemplate().postForObject(environment.getProperty("pdf.converter.url") + "convert/office" , requestEntity, byte[].class); File resultPdf = new File(environment.getProperty("configuration.exportUrl") + label + ".pdf"); @@ -496,4 +532,51 @@ public class DatasetManager { // TODO: When tags functionality return. } + public DatasetWizardModel datasetUpdateProfile(String id) { + DatasetWizardModel dataset = new DatasetWizardModel(); + eu.eudat.data.entities.Dataset datasetEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class)); + eu.eudat.elastic.entities.Dataset datasetElastic; + try{ + datasetElastic = datasetRepository.exists() ? + datasetRepository.findDocument(id) : new eu.eudat.elastic.entities.Dataset(); + } + catch (Exception ex){ + datasetElastic = new eu.eudat.elastic.entities.Dataset(); + } + dataset.setDatasetProfileDefinition(getPagedProfile(dataset, datasetEntity)); + dataset.fromDataModel(datasetEntity); + + // Creates the Criteria to get all version of DatasetProfile in question. + DatasetProfileCriteria profileCriteria = new DatasetProfileCriteria(); + UUID profileId = datasetEntity.getProfile().getGroupId(); + List uuidList = new LinkedList<>(); + uuidList.add(profileId); + profileCriteria.setGroupIds(uuidList); + + // Gets the latest version of the datasetProfile. + eu.eudat.data.entities.DatasetProfile item = databaseRepository.getDatasetProfileDao().getWithCriteria(profileCriteria).getSingle(); + + // Sets the latest version of dataet Profile to the Dataset in question. + dataset.setDatasetProfileDefinition(getLatestDatasetProfile(datasetEntity, item)); + dataset.setProfile(item.getId()); + + // Now at latest version. + dataset.setIsProfileLatestVersion(true); + + dataset.setTags(datasetElastic.getTags()); + return dataset; + } + + public PagedDatasetProfile getLatestDatasetProfile(Dataset datasetEntity, DatasetProfile profile) { + eu.eudat.models.data.user.composite.DatasetProfile datasetprofile = userManager.generateDatasetProfileModel(profile); + datasetprofile.setStatus(datasetEntity.getStatus()); + if (datasetEntity.getProperties() != null) { + JSONObject jobject = new JSONObject(datasetEntity.getProperties()); + Map properties = jobject.toMap(); + datasetprofile.fromJsonObject(properties); + } + PagedDatasetProfile pagedDatasetProfile = new PagedDatasetProfile(); + pagedDatasetProfile.buildPagedDatasetProfile(datasetprofile); + return pagedDatasetProfile; + } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/datasetwizard/DatasetWizardModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/datasetwizard/DatasetWizardModel.java index ac695a83c..106652337 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/datasetwizard/DatasetWizardModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/datasetwizard/DatasetWizardModel.java @@ -33,11 +33,11 @@ public class DatasetWizardModel implements DataModel tags; private List externalDatasets; private UUID profile; + private Boolean isProfileLatestVersion; public UUID getId() { return id; } - public void setId(UUID id) { this.id = id; } @@ -45,7 +45,6 @@ public class DatasetWizardModel implements DataModel getRegistries() { return registries; } - public void setRegistries(List registries) { this.registries = registries; } @@ -117,7 +108,6 @@ public class DatasetWizardModel implements DataModel getServices() { return services; } - public void setServices(List services) { this.services = services; } @@ -125,7 +115,6 @@ public class DatasetWizardModel implements DataModel getDataRepositories() { return dataRepositories; } - public void setDataRepositories(List dataRepositories) { this.dataRepositories = dataRepositories; } @@ -133,7 +122,6 @@ public class DatasetWizardModel implements DataModel getExternalDatasets() { return externalDatasets; } - public void setExternalDatasets(List externalDatasets) { this.externalDatasets = externalDatasets; } @@ -149,11 +136,17 @@ public class DatasetWizardModel implements DataModel getTags() { return tags; } - public void setTags(List tags) { this.tags = tags; } + public Boolean getIsProfileLatestVersion() { + return isProfileLatestVersion; + } + public void setIsProfileLatestVersion(Boolean profileLatestVersion) { + isProfileLatestVersion = profileLatestVersion; + } + @Override public DatasetWizardModel fromDataModel(Dataset entity) { this.id = entity.getId(); @@ -178,7 +171,7 @@ public class DatasetWizardModel implements DataModel { ExternalDatasetListingModel externalDatasetListingModel = new ExternalDatasetListingModel().fromDataModel(item.getExternalDataset()); - if(item.getData()!=null) { + if(item.getData()!= null) { Map> data = (Map>) JSONValue.parse(item.getData()); Map values = data.get("data"); externalDatasetListingModel.setInfo(values.get("info")); diff --git a/dmp-frontend/src/app/core/model/dataset/dataset-wizard.ts b/dmp-frontend/src/app/core/model/dataset/dataset-wizard.ts index 10e705dc7..088fa12b1 100644 --- a/dmp-frontend/src/app/core/model/dataset/dataset-wizard.ts +++ b/dmp-frontend/src/app/core/model/dataset/dataset-wizard.ts @@ -21,4 +21,5 @@ export interface DatasetWizardModel { tags?: TagModel[]; externalDatasets?: ExternalDatasetModel[]; profile?: DatasetProfileModel; + isProfileLatestVersion?: Boolean; } diff --git a/dmp-frontend/src/app/core/services/dataset-wizard/dataset-wizard.service.ts b/dmp-frontend/src/app/core/services/dataset-wizard/dataset-wizard.service.ts index f0bfd9680..b08009aad 100644 --- a/dmp-frontend/src/app/core/services/dataset-wizard/dataset-wizard.service.ts +++ b/dmp-frontend/src/app/core/services/dataset-wizard/dataset-wizard.service.ts @@ -88,4 +88,8 @@ export class DatasetWizardService { }; return this.http.post(this.actionUrl + 'upload', formData, { params: params }); } + + public updateDatasetProfile(id: String): Observable { + return this.http.get(this.actionUrl + "profile/"+ id, { headers: this.headers }); + } } diff --git a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard-editor.model.ts b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard-editor.model.ts index 2cc3948af..b87673359 100644 --- a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard-editor.model.ts +++ b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard-editor.model.ts @@ -28,6 +28,7 @@ export class DatasetWizardEditorModel { public dmp: DmpModel; public datasetProfileDefinition: DatasetDescriptionFormEditorModel; public validationErrorModel: ValidationErrorModel = new ValidationErrorModel(); + public isProfileLatestVersion: Boolean; fromModel(item: DatasetWizardModel): DatasetWizardEditorModel { this.id = item.id; @@ -41,9 +42,9 @@ export class DatasetWizardEditorModel { if (item.dataRepositories) { this.dataRepositories = item.dataRepositories.map(x => new ExternalDataRepositoryEditorModel().fromModel(x)); } if (item.externalDatasets) { this.externalDatasets = item.externalDatasets.map(x => new ExternalDatasetEditorModel().fromModel(x)); } this.dmp = item.dmp; - this.profile = item.profile; if (item.datasetProfileDefinition) { this.datasetProfileDefinition = new DatasetDescriptionFormEditorModel().fromModel(item.datasetProfileDefinition); } this.tags = item.tags; + this.isProfileLatestVersion = item.isProfileLatestVersion; return this; } @@ -321,4 +322,4 @@ export class ExternalDataRepositoryEditorModel { // name: [this.name] // }); // } -// } \ No newline at end of file +// } diff --git a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.html b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.html index 95c5d446f..d131f7818 100644 --- a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.html +++ b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.html @@ -41,7 +41,10 @@ (click)="downloadDOCX();" type="button">{{ 'DATASET-WIZARD.ACTIONS.DOWNLOAD-DOCX' | translate }} +
+
diff --git a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.scss b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.scss index 545c569b1..5c53329ef 100644 --- a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.scss +++ b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.scss @@ -39,4 +39,9 @@ margin-bottom: 15px; margin-right: 15px; } + .updateDatasetProfile { + margin-top: 15px; + margin-bottom: 15px; + margin-right: 15px; + } } diff --git a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts index eeb57551b..1c72063d0 100644 --- a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts +++ b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts @@ -56,6 +56,7 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr availableProfiles: DatasetProfileModel[] = []; itemId: string; publicId: string; + profileUpdateId: string; downloadDocumentId: string; isLinear = false; @@ -121,6 +122,7 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr const dmpId = params['dmpId']; const newDmpId = queryParams['newDmpId']; this.publicId = params['publicId']; + this.profileUpdateId = params['updateId']; this.itemId ? this.downloadDocumentId = this.itemId : this.downloadDocumentId = this.publicId @@ -130,6 +132,7 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr .pipe(takeUntil(this._destroyed)) .subscribe(data => { this.datasetWizardModel = new DatasetWizardEditorModel().fromModel(data); + this.needsUpdate(); this.breadCrumbs = Observable.of([ { parentComponentName: null, @@ -274,8 +277,40 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr } }); this.publicMode = true; - } - else { + } else if (this.profileUpdateId != null) { + this.datasetWizardService.updateDatasetProfile(this.profileUpdateId) + .pipe(takeUntil(this._destroyed)) + .subscribe(data => { + this.datasetWizardModel = new DatasetWizardEditorModel().fromModel(data); + this.needsUpdate(); + this.breadCrumbs = Observable.of([ + { + parentComponentName: null, + label: 'Datasets', + url: '/datasets', + notFoundResolver: [ + { + parentComponentName: null, + label: this.datasetWizardModel.dmp.project.label, + url: '/projects/edit/' + this.datasetWizardModel.dmp.project.id + }, + { + parentComponentName: null, + label: this.datasetWizardModel.dmp.label, + url: '/plans/edit/' + this.datasetWizardModel.dmp.id, + }, + ] + }]); + this.formGroup = this.datasetWizardModel.buildForm(); + this.editMode = this.datasetWizardModel.status === DatasetStatus.Draft; + if (this.datasetWizardModel.status === 1) { + this.formGroup.disable(); + this.viewOnly = true; + } + // if (this.viewOnly) { this.formGroup.disable(); } // For future use, to make Dataset edit like DMP. + this.loadDatasetProfiles(); + }); + } else { this.datasetWizardModel = new DatasetWizardEditorModel(); this.formGroup = this.datasetWizardModel.buildForm(); this.editMode = this.datasetWizardModel.status === DatasetStatus.Draft; @@ -535,4 +570,30 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr } }); } + + needsUpdate() { + if (this.datasetWizardModel.isProfileLatestVersion) { + return false; + } + else { + return true + } + } + + openUpdateDatasetProfileDialogue() { + const dialogRef = this.dialog.open(ConfirmationDialogComponent, { + data: { + message: this.language.instant('DATASET-EDITOR.VERSION-DIALOG.QUESTION'), + confirmButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CONFIRM'), + cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL') + } + }); + dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => { + if (result) { + this.profileUpdateId = this.itemId; + this.uiNotificationService.snackBarNotification("Profile changed, WOW!", SnackBarNotificationLevel.Success); + this.router.navigate(['/datasets/profileupdate/' + this.profileUpdateId]); + } + }); + } } diff --git a/dmp-frontend/src/app/ui/dataset/dataset.routing.ts b/dmp-frontend/src/app/ui/dataset/dataset.routing.ts index 7dd765e67..b21150984 100644 --- a/dmp-frontend/src/app/ui/dataset/dataset.routing.ts +++ b/dmp-frontend/src/app/ui/dataset/dataset.routing.ts @@ -54,7 +54,6 @@ const routes: Routes = [ breadcrumb: true }, }, - { path: 'copy/:id', component: DatasetWizardComponent, @@ -62,6 +61,14 @@ const routes: Routes = [ data: { breadcrumb: true }, + }, + { + path: 'profileupdate/:updateId', + component: DatasetWizardComponent, + canActivate: [AuthGuard], + data: { + breadcrumb: true + }, } ]; 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 d054abfcf..3449707ed 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 @@ -121,8 +121,8 @@ export class DatasetCriteriaComponent extends BaseCriteriaComponent implements O this.datasetWizardService.uploadXml(result.fileList, result.datasetTitle, result.dmpId, result.datasetProfileId) .pipe(takeUntil(this._destroyed)) .subscribe( - complete => this.onCallbackSuccess(), - error => this.onCallbackError(error) + complete => this.onCallbackSuccess(), + error => this.onCallbackError(error) ); } }) diff --git a/dmp-frontend/src/assets/i18n/en.json b/dmp-frontend/src/assets/i18n/en.json index aaf290d55..69d7870dd 100644 --- a/dmp-frontend/src/assets/i18n/en.json +++ b/dmp-frontend/src/assets/i18n/en.json @@ -258,7 +258,8 @@ "DOWNLOAD-PDF": "Download PDF", "DOWNLOAD-XML": "Download XML", "DOWNLOAD-DOCX": "Download DOCX", - "COPY-DATASET": "Copy Dataset" + "COPY-DATASET": "Copy Dataset", + "UPDATE-DATASET-PROFILE": "Update Profile" }, "UPLOAD": { "UPLOAD-XML": "Import", @@ -493,6 +494,9 @@ "SAVE": "Save", "CANCEL": "Cancel", "DELETE": "Delete" + }, + "VERSION-DIALOG": { + "QUESTION": "It seems your Dataset Profile is outdated. Do you want to update it to the latest version?" } }, "DATASET-CREATE-WIZARD": {