Fixed DMP import(xml) and move the import button to a better place

This commit is contained in:
George Kalampokis 2020-03-03 11:16:02 +02:00
parent bf60e661ab
commit e243126bf9
19 changed files with 315 additions and 46 deletions

View File

@ -39,12 +39,15 @@ import eu.eudat.models.data.dmp.*;
import eu.eudat.models.data.dynamicfields.DynamicFieldWithValue;
import eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.DataManagementPlanProfile;
import eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.Field;
import eu.eudat.models.data.funder.FunderDMPEditorModel;
import eu.eudat.models.data.grant.GrantDMPEditorModel;
import eu.eudat.models.data.helpermodels.Tuple;
import eu.eudat.models.data.helpers.common.DataTableData;
import eu.eudat.models.data.listingmodels.DataManagementPlanListingModel;
import eu.eudat.models.data.listingmodels.DataManagementPlanOverviewModel;
import eu.eudat.models.data.listingmodels.DatasetListingModel;
import eu.eudat.models.data.listingmodels.UserInfoListingModel;
import eu.eudat.models.data.project.ProjectDMPEditorModel;
import eu.eudat.models.data.rda.RDAExportModel;
import eu.eudat.models.data.security.Principal;
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
@ -753,9 +756,11 @@ public class DataManagementPlanManager {
if (newDmp.getGrant() != null) {
Grant grant = newDmp.getGrant();
GrantCriteria criteria = new GrantCriteria();
criteria.setReference(grant.getReference());
eu.eudat.data.entities.Grant grantEntity = grantDao.getWithCriteria(criteria).getSingleOrDefault();
if (grantEntity != null) grant.setId(grantEntity.getId());
if (grant.getReference() != null) {
criteria.setReference(grant.getReference());
eu.eudat.data.entities.Grant grantEntity = grantDao.getWithCriteria(criteria).getSingleOrDefault();
if (grantEntity != null) grant.setId(grantEntity.getId());
}
else {
grant.setType(Grant.GrantType.EXTERNAL.getValue());
grant.setCreationUser(null);
@ -768,9 +773,11 @@ public class DataManagementPlanManager {
if (newDmp.getGrant().getFunder() != null) {
Funder funder = newDmp.getGrant().getFunder();
FunderCriteria criteria = new FunderCriteria();
criteria.setReference(funder.getReference());
eu.eudat.data.entities.Funder funderEntity = funderDao.getWithCritetia(criteria).getSingleOrDefault();
if (funderEntity != null) funder.setId(funderEntity.getId());
if (funder.getReference() != null) {
criteria.setReference(funder.getReference());
eu.eudat.data.entities.Funder funderEntity = funderDao.getWithCritetia(criteria).getSingleOrDefault();
if (funderEntity != null) funder.setId(funderEntity.getId());
}
else {
funderDao.createOrUpdate(funder);
}
@ -781,9 +788,11 @@ public class DataManagementPlanManager {
if (newDmp.getProject() != null) {
Project project = newDmp.getProject();
ProjectCriteria criteria = new ProjectCriteria();
criteria.setReference(project.getReference());
eu.eudat.data.entities.Project projectEntity = projectDao.getWithCritetia(criteria).getSingleOrDefault();
if (projectEntity != null) project.setId(projectEntity.getId());
if (project.getReference() != null) {
criteria.setReference(project.getReference());
eu.eudat.data.entities.Project projectEntity = projectDao.getWithCritetia(criteria).getSingleOrDefault();
if (projectEntity != null) project.setId(projectEntity.getId());
}
else {
project.setType(Project.ProjectType.EXTERNAL.getValue());
if (project.getId() == null) project.setId(UUID.randomUUID());
@ -820,19 +829,19 @@ public class DataManagementPlanManager {
}
private void assignGrandUserIfInternal(DMP dmp, UserInfo user) {
if (dmp.getGrant().getCreationUser() == null && dmp.getGrant().getReference().startsWith("dmp:")) {
if (dmp.getGrant().getCreationUser() == null && (dmp.getGrant().getReference() != null && dmp.getGrant().getReference().startsWith("dmp:"))) {
dmp.getGrant().setCreationUser(user);
}
}
private void assignFunderUserIfInternal(DMP dmp, UserInfo user) {
if (dmp.getGrant().getFunder().getCreationUser() == null && dmp.getGrant().getFunder().getReference().startsWith("dmp:")) {
if (dmp.getGrant().getFunder().getCreationUser() == null && ( dmp.getGrant().getFunder().getReference() != null && dmp.getGrant().getFunder().getReference().startsWith("dmp:"))) {
dmp.getGrant().getFunder().setCreationUser(user);
}
}
private void assignProjectUserIfInternal(DMP dmp, UserInfo user) {
if (dmp.getProject().getCreationUser() == null && dmp.getProject().getReference().startsWith("dmp:")) {
if (dmp.getProject().getCreationUser() == null && (dmp.getProject().getReference() != null && dmp.getProject().getReference().startsWith("dmp:"))) {
dmp.getProject().setCreationUser(user);
}
}
@ -992,6 +1001,10 @@ public class DataManagementPlanManager {
for (Dataset dataset : datasets) {
Element datasetElement = xmlDoc.createElement("dataset");
Element datsetProfileElement = xmlDoc.createElement("profile");
datasetElement.setAttribute("name", dataset.getLabel());
datasetElement.appendChild(datsetProfileElement);
datsetProfileElement.setTextContent(dataset.getProfile().getId().toString());
DatasetWizardModel datasetWizardModel = new DatasetWizardModel();
Map<String, Object> properties = new HashMap<>();
@ -1108,7 +1121,7 @@ public class DataManagementPlanManager {
// TODO Iterate through the list of dataManagementPlans.
// Creates new dataManagementPlan to fill it with the data model that was parsed from the xml.
// Creates properties.
DataManagementPlan dm = new DataManagementPlan();
DataManagementPlanEditorModel dm = new DataManagementPlanEditorModel();
DataManagementPlanProfile dmpProfile = new DataManagementPlanProfile();
List<Field> fieldList = new LinkedList<>();
@ -1122,12 +1135,29 @@ public class DataManagementPlanManager {
/*Tuple tuple = new Tuple();
tuple.setId(dataManagementPlans.get(0).getDmpProfile().getDmpProfileId());
tuple.setLabel(dataManagementPlans.get(0).getDmpProfile().getDmpProfileName());*/
eu.eudat.models.data.funder.Funder funder = new eu.eudat.models.data.funder.Funder();
FunderImportModels funderImport = dataManagementPlans.get(0).getFunderImportModels();
funder.setId(funderImport.getId());
funder.setLabel(funderImport.getLabel());
FunderDMPEditorModel funderEditor = new FunderDMPEditorModel();
funderEditor.setExistFunder(funder);
eu.eudat.models.data.grant.Grant grant = new eu.eudat.models.data.grant.Grant();
GrantImportModels grantImport = dataManagementPlans.get(0).getGrantImport();
grant.setId(grantImport.getId());
grant.setLabel(grantImport.getLabel());
grant.setAbbreviation(grantImport.getAbbreviation());
grant.setDescription(grantImport.getDescription());
GrantDMPEditorModel grantEditor = new GrantDMPEditorModel();
grantEditor.setExistGrant(grant);
eu.eudat.models.data.project.Project project = new eu.eudat.models.data.project.Project();
ProjectImportModels projectImport = dataManagementPlans.get(0).getProjectImportModels();
project.setId(projectImport.getId());
project.setLabel(projectImport.getLabel());
ProjectDMPEditorModel projectEditor = new ProjectDMPEditorModel();
projectEditor.setExistProject(project);
List<eu.eudat.models.data.dmp.AssociatedProfile> associatedProfiles = new LinkedList<>();
for (AssociatedProfileImportModels a : dataManagementPlans.get(0).getProfilesImportModels()) {
AssociatedProfile associatedProfile = new AssociatedProfile();
@ -1155,7 +1185,9 @@ public class DataManagementPlanManager {
// Sets properties.
dm.setLabel(files[0].getOriginalFilename()); // Sets label.
dm.setGrant(grant); //Sets grant property.
dm.setGrant(grantEditor); //Sets grant property.
dm.setFunder(funderEditor);
dm.setProject(projectEditor);
dm.setDescription(dataManagementPlans.get(0).getDescriptionImport()); // Sets description property.
dm.setProfiles(associatedProfiles);
dm.setOrganisations(organisations); // Sets organisations property.
@ -1165,6 +1197,41 @@ public class DataManagementPlanManager {
dm.setDefinition(dmpProfile);
//createOrUpdate(apiContext, dm, principal);
DMP dmp = this.createOrUpdate(apiContext, dm, principal);
if (dmp.getOrganisations() == null) {
dmp.setOrganisations(new HashSet<>());
}
if (dmp.getResearchers() == null) {
dmp.setResearchers(new HashSet<>());
}
if (dmp.getDataset() == null) {
dmp.setDataset(new HashSet<>());
}
if (dmp.getUsers() == null) {
dmp.setUsers(new HashSet<>());
}
if (dmp.getAssociatedDmps() == null) {
dmp.setAssociatedDmps(new HashSet<>());
}
List<DatasetListingModel> datasets = new LinkedList<>();
for (DatasetImportModels das: dataManagementPlans.get(0).getDatasetImportModels()) {
eu.eudat.data.entities.Dataset dataset = new eu.eudat.data.entities.Dataset();
dataset.setLabel(das.getName());
dataset.setProfile(databaseRepository.getDatasetProfileDao().find(das.getProfile()));
dataset.setProperties(new ObjectMapper().writeValueAsString(das.getFieldImportModels()));
dataset.setStatus((short) 0);
dataset.setRegistries(new HashSet<>());
dataset.setDatasetDataRepositories(new HashSet<>());
dataset.setServices(new HashSet<>());
dataset.setDatasetExternalDatasets(new HashSet<>());
dataset.setDmp(dmp);
DatasetWizardModel datasetWizard = new DatasetWizardModel();
datasetWizard.setDatasetProfileDefinition(this.datasetManager.getPagedProfile(datasetWizard, dataset));
datasetWizard.fromDataModel(dataset);
this.datasetManager.createOrUpdate(datasetWizard, principal);
// datasets.add(new DatasetListingModel().fromDataModel(dataset));
}
logger.info(dm.toString());
}

View File

@ -1,9 +1,46 @@
package eu.eudat.models.data.dmp;
import eu.eudat.models.data.dmp.adpter.PageAdapter;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@XmlRootElement(name = "dataset")
public class DatasetImportModels {
private String name;
private UUID profile;
private HashMap<String, String> fieldImportModels;
@XmlAttribute(name ="name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public UUID getProfile() {
return profile;
}
public void setProfile(UUID profile) {
this.profile = profile;
}
@XmlJavaTypeAdapter(PageAdapter.class)
@XmlElement(name = "pages")
public HashMap<String, String> getFieldImportModels() {
return fieldImportModels;
}
public void setFieldImportModels(HashMap<String, String> fieldImportModels) {
this.fieldImportModels = fieldImportModels;
}
}

View File

@ -10,7 +10,9 @@ public class DmpImportModel {
private String description;
private String dmpName;
private DmpProfileImportModel profile;
private FunderImportModels funderImportModels;
private GrantImportModels grantImportModels;
private ProjectImportModels projectImportModels;
private List<AssociatedProfileImportModels> profilesImportModels;
private List<OrganisationImportModel> organisationImportModels;
private List<ResearcherImportModels> researchersImportModels;
@ -46,6 +48,22 @@ public class DmpImportModel {
this.grantImportModels = grantImportModels;
}
@XmlElement(name = "funder")
public FunderImportModels getFunderImportModels() {
return funderImportModels;
}
public void setFunderImportModels(FunderImportModels funderImportModels) {
this.funderImportModels = funderImportModels;
}
@XmlElement(name = "project")
public ProjectImportModels getProjectImportModels() {
return projectImportModels;
}
public void setProjectImportModels(ProjectImportModels projectImportModels) {
this.projectImportModels = projectImportModels;
}
@XmlElementWrapper(name="organisations")
@XmlElement(name = "organisation")
public List<OrganisationImportModel> getOrganisationImportModels() {

View File

@ -0,0 +1,27 @@
package eu.eudat.models.data.dmp;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "field")
public class FieldImportModels {
private String id;
private String value;
@XmlAttribute(name = "id")
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
@XmlElement(name = "value")
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}

View File

@ -0,0 +1,28 @@
package eu.eudat.models.data.dmp;
import com.sun.xml.internal.txw2.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.UUID;
@XmlRootElement(name = "funder")
public class FunderImportModels {
private UUID id;
private String label;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
}

View File

@ -0,0 +1,26 @@
package eu.eudat.models.data.dmp;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.UUID;
@XmlRootElement(name = "project")
public class ProjectImportModels {
private UUID id;
private String label;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
}

View File

@ -0,0 +1,37 @@
package eu.eudat.models.data.dmp.adpter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import java.util.HashMap;
import java.util.Map;
public class PageAdapter extends XmlAdapter<Object, HashMap<String, String>> {
private static final Logger logger = LoggerFactory.getLogger(PageAdapter.class);
@Override
public HashMap<String, String> unmarshal(Object v) throws Exception {
Element data = (Element)v;
HashMap<String, String> result = new HashMap<>();
generateMap(data, result, "field");
logger.info(result.toString());
return result;
}
private void generateMap(Node root, Map<String, String> result, String target) {
for (int i = 0; i < root.getChildNodes().getLength(); i++) {
if (((Element)root).getTagName().equals(target)) {
result.put(((Element) root).getAttribute("id"), root.getFirstChild().getFirstChild() != null ? root.getFirstChild().getFirstChild().getNodeValue() : "");
} else {
generateMap(root.getChildNodes().item(i), result, target);
}
}
}
@Override
public Object marshal(HashMap<String, String> v) throws Exception {
return null;
}
}

View File

@ -20,7 +20,7 @@ import { PeopleTabComponent } from '@app/ui/dmp/editor/people-tab/people-tab.com
import { InvitationAcceptedComponent } from '@app/ui/dmp/invitation/accepted/dmp-invitation-accepted.component';
import { DmpInvitationDialogComponent } from '@app/ui/dmp/invitation/dmp-invitation.component';
import { DmpCriteriaComponent } from '@app/ui/dmp/listing/criteria/dmp-criteria.component';
import { DmpUploadDialogue } from '@app/ui/dmp/listing/criteria/upload-dialogue/dmp-upload-dialogue.component';
import { DmpUploadDialogue } from '@app/ui/dmp/listing/upload-dialogue/dmp-upload-dialogue.component';
import { DmpListingComponent } from '@app/ui/dmp/listing/dmp-listing.component';
import { DmpListingItemComponent } from '@app/ui/dmp/listing/listing-item/dmp-listing-item.component';
import { DmpOverviewModule } from '@app/ui/dmp/overview/dmp-overview.module';

View File

@ -83,14 +83,6 @@
</div>
<!-- End of Related Organization Filter -->
<!-- Import Button -->
<div class="col-10 import">
<button class="importButton lightblue-btn" mat-raised-button color="primary"
(click)="fileSave($event)" type="button col-auto">
{{'DMP-UPLOAD.ACTIONS.IMPORT' | translate}}
</button>
</div>
</div>
</div>
</div>

View File

@ -28,10 +28,7 @@
margin-bottom: 12px;
}
.import {
margin: 10px;
padding: 0px;
}
.filters {
border: 1px solid #e4e4e4;

View File

@ -15,7 +15,6 @@ import { GrantService } from '@app/core/services/grant/grant.service';
import { OrganisationService } from '@app/core/services/organisation/organisation.service';
import { UserService } from '@app/core/services/user/user.service';
import { MultipleAutoCompleteConfiguration } from '@app/library/auto-complete/multiple/multiple-auto-complete-configuration';
import { DmpUploadDialogue } from '@app/ui/dmp/listing/criteria/upload-dialogue/dmp-upload-dialogue.component';
import { BaseCriteriaComponent } from '@app/ui/misc/criteria/base-criteria.component';
import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model';
import { TranslateService } from '@ngx-translate/core';
@ -173,20 +172,5 @@ export class DmpCriteriaComponent extends BaseCriteriaComponent implements OnIni
return this.dmpService.getDatasetProfilesUsedPaged(datasetTemplateRequestItem).pipe(map(x => x.data));
}
fileSave(event) {
const dialogRef = this.dialog.open(DmpUploadDialogue, {
data: {
fileList: FileList,
success: Boolean,
dmpTitle: String
}
});
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
if (result && result.success) {
this.dmpService.uploadXml(result.fileList, result.dmpTitle)
.pipe(takeUntil(this._destroyed))
.subscribe();
}
});
}
}

View File

@ -15,6 +15,15 @@
<!-- <p class="card-category">{{'DMP-LISTING.SUBTITLE' | translate}}</p> -->
</div>
<div class="row ml-auto p-2">
<!-- Import Button -->
<button mat-icon-button [matMenuTriggerFor]="actionsMenu" class="ml-auto more-icon" (click)="$event.stopImmediatePropagation();">
<mat-icon class="more-horiz">more_horiz</mat-icon>
</button>
<mat-menu #actionsMenu="matMenu" xPosition="before">
<button mat-menu-item (click)="fileSave($event)">
<mat-icon>cloud_upload</mat-icon> {{'DMP-UPLOAD.ACTIONS.IMPORT' | translate}}
</button>
</mat-menu>
<!-- <button mat-raised-button color="primary" class="text-uppercase lightblue-btn m-1" [routerLink]="grantId ? ['/plans/new/grant/', grantId] : ['./new']"> -->
<button mat-raised-button color="primary" class="text-uppercase lightblue-btn m-1" [routerLink]="['./new']">
<mat-icon>add</mat-icon> {{'DMP-LISTING.ACTIONS.NEW' | translate}}

View File

@ -59,6 +59,20 @@
color: #089dbb !important;
}
.import {
margin: 10px;
padding: 0px;
}
.more-horiz {
font-size: 28px;
color: #aaaaaa;
}
.more-icon :hover {
color: #00b29f;
}
// .bot-paginator {
// margin-top: auto;
// }

View File

@ -19,6 +19,9 @@ import { TranslateService } from '@ngx-translate/core';
import { Observable, of as observableOf } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { GrantService } from "@app/core/services/grant/grant.service";
import { DmpUploadDialogue } from './upload-dialogue/dmp-upload-dialogue.component';
import { UiNotificationService, SnackBarNotificationLevel } from '@app/core/services/notification/ui-notification-service';
@Component({
selector: 'app-dmp-listing-component',
@ -48,7 +51,8 @@ export class DmpListingComponent extends BaseComponent implements OnInit, IBread
private dialog: MatDialog,
public enumUtils: EnumUtils,
private language: TranslateService,
private grantService: GrantService
private grantService: GrantService,
private uiNotificationService: UiNotificationService
) {
super();
}
@ -211,6 +215,33 @@ export class DmpListingComponent extends BaseComponent implements OnInit, IBread
}
});
}
fileSave(event) {
const dialogRef = this.dialog.open(DmpUploadDialogue, {
data: {
fileList: FileList,
success: Boolean,
dmpTitle: String
}
});
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
if (result && result.success) {
this.dmpService.uploadXml(result.fileList, result.dmpTitle)
.pipe(takeUntil(this._destroyed))
.subscribe((complete) => this.onCallbackImportComplete(),
(error) => this.onCallbackImportFail(error.error));
}
});
}
private onCallbackImportComplete() {
this.uiNotificationService.snackBarNotification(this.language.instant('DMP-UPLOAD.UPLOAD-SUCCESS'), SnackBarNotificationLevel.Success);
this.router.navigate(['/reload']).then(() => this.router.navigate(['/plans']));
}
private onCallbackImportFail(error: string) {
this.uiNotificationService.snackBarNotification(error, SnackBarNotificationLevel.Error);
}
}
// export class DmpDataSource extends DataSource<DmpListingModel> {

View File

@ -1,6 +1,6 @@
import { Component, Inject } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { DmpService } from '../../../../../core/services/dmp/dmp.service';
import { DmpService } from '../../../../core/services/dmp/dmp.service';
@Component({
selector: 'dmp-upload-dialogue',

View File

@ -441,6 +441,7 @@
"DMP-UPLOAD": {
"TITLE": "Import Data Management Plan",
"UPLOAD-BUTTON": "Upload",
"UPLOAD-SUCCESS": "Import was Successfull",
"ACTIONS": {
"IMPORT": "Import",
"CANCEL": "Cancel"

View File

@ -439,6 +439,7 @@
"DMP-UPLOAD": {
"TITLE": "Importar Plan de Gestión de Datos",
"UPLOAD-BUTTON": "Subir",
"UPLOAD-SUCCESS": "Import was Successfull",
"ACTIONS": {
"IMPORT": "Importar",
"CANCEL": "Cancelar"