Dmp Profile ImportDownload XML

This commit is contained in:
Diamantis Tziotzios 2019-02-25 18:53:36 +02:00
parent 4de17d5453
commit cd44392d9a
21 changed files with 651 additions and 36 deletions

View File

@ -3,7 +3,9 @@ package eu.eudat.controllers;
import eu.eudat.data.entities.DMPProfile;
import eu.eudat.data.query.items.item.dmpprofile.DataManagementPlanProfileCriteriaRequest;
import eu.eudat.data.query.items.table.dmpprofile.DataManagementPlanProfileTableRequest;
import eu.eudat.logic.managers.AdminManager;
import eu.eudat.logic.managers.DataManagementProfileManager;
import eu.eudat.logic.security.claims.ClaimedAuthorities;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.data.helpers.common.DataTableData;
import eu.eudat.models.data.helpers.responses.ResponseItem;
@ -15,10 +17,14 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;
import static eu.eudat.types.Authorities.ADMIN;
/**
* Created by ikalyvas on 3/21/2018.
*/
@ -56,4 +62,26 @@ public class DMPProfileController extends BaseController {
DataTableData<DataManagementPlanProfileListingModel> dataTable = this.dataManagementProfileManager.getPaged(this.getApiContext(), dataManagementPlanProfileTableRequest, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DataManagementPlanProfileListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
}
@RequestMapping(method = RequestMethod.GET, value = {"/getXml/{id}"}, produces = "application/json")
public @ResponseBody
ResponseEntity getXml( @RequestHeader("Content-Type") String contentType, @PathVariable String id, Principal principal) throws IllegalAccessException, InstantiationException, IOException {
if (contentType.equals("application/xml")) {
DataManagementPlanProfileListingModel dataManagementPlanProfileListingModel = this.dataManagementProfileManager.getSingle(this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpProfileDao(), id, principal);
return this.dataManagementProfileManager.getDocument(dataManagementPlanProfileListingModel,dataManagementPlanProfileListingModel.getLabel());
}else {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DataManagementPlanProfileListingModel>().status(ApiMessageCode.ERROR_MESSAGE).message("NOT AUTHORIZE"));
}
}
@RequestMapping(method = RequestMethod.POST, value = {"/upload"})
public ResponseEntity<Object> setDatasetProfileXml(@RequestParam("file") MultipartFile file,
@ClaimedAuthorities(claims = {ADMIN}) Principal principal) throws IllegalAccessException,IOException,Exception{
eu.eudat.logic.utilities.documents.xml.dmpXml.dmpProfileModel.DmpProfile dmpProfileModel = this.dataManagementProfileManager.createDmpProfileFromXml(file);
DataManagementPlanProfileListingModel dataManagementPlan = dmpProfileModel.toDmpProfileCompositeModel(file.getOriginalFilename());
this.dataManagementProfileManager.createOrUpdate(this.getApiContext(), dataManagementPlan, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<eu.eudat.data.entities.DatasetProfile>>()
.status(ApiMessageCode.SUCCESS_MESSAGE).message(""));
}
}

View File

@ -0,0 +1,19 @@
package eu.eudat.exceptions.datasetprofile;
public class DatasetProfileWithDatasetsExeption extends RuntimeException {
public DatasetProfileWithDatasetsExeption() {
}
public DatasetProfileWithDatasetsExeption(String message) {
super(message);
}
public DatasetProfileWithDatasetsExeption(String message, Throwable cause) {
super(message, cause);
}
public DatasetProfileWithDatasetsExeption(Throwable cause) {
super(cause);
}
}

View File

@ -4,17 +4,27 @@ import eu.eudat.data.dao.entities.DMPProfileDao;
import eu.eudat.data.entities.DMPProfile;
import eu.eudat.data.query.items.item.dmpprofile.DataManagementPlanProfileCriteriaRequest;
import eu.eudat.data.query.items.table.dmpprofile.DataManagementPlanProfileTableRequest;
import eu.eudat.logic.utilities.documents.helpers.FileEnvelope;
import eu.eudat.logic.utilities.documents.xml.dmpXml.ExportXmlBuilderDmpProfile;
import eu.eudat.logic.utilities.documents.xml.dmpXml.ImportXmlBuilderDmpProfile;
import eu.eudat.models.data.helpers.common.DataTableData;
import eu.eudat.models.data.listingmodels.DataManagementPlanProfileListingModel;
import eu.eudat.models.data.security.Principal;
import eu.eudat.queryable.QueryableList;
import eu.eudat.logic.services.ApiContext;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import javax.activation.MimetypesFileTypeMap;
import java.io.*;
import java.nio.file.Files;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import org.springframework.http.*;
import org.springframework.web.multipart.MultipartFile;
/**
* Created by ikalyvas on 3/21/2018.
*/
@ -57,4 +67,57 @@ public class DataManagementProfileManager {
DMPProfile dmpProfile = dataManagementPlanProfileListingModel.toDataModel();
apiContext.getOperationsContext().getDatabaseRepository().getDmpProfileDao().createOrUpdate(dmpProfile);
}
public ResponseEntity<byte[]> getDocument(DataManagementPlanProfileListingModel dmpProfile, String label) throws IllegalAccessException, IOException, InstantiationException {
FileEnvelope envelope = getXmlDocument(dmpProfile, label);
InputStream resource = new FileInputStream(envelope.getFile());
System.out.println("Mime Type of " + envelope.getFilename() + " is " +
new MimetypesFileTypeMap().getContentType(envelope.getFile()));
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentLength(envelope.getFile().length());
responseHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
responseHeaders.set("Content-Disposition", "attachment;filename=" + envelope.getFilename() + ".xml");
responseHeaders.set("Access-Control-Expose-Headers", "Content-Disposition");
responseHeaders.get("Access-Control-Expose-Headers").add("Content-Type");
byte[] content = org.apache.poi.util.IOUtils.toByteArray(resource);
resource.close();
Files.deleteIfExists(envelope.getFile().toPath());
return new ResponseEntity<>(content,
responseHeaders,
HttpStatus.OK);
}
public FileEnvelope getXmlDocument(DataManagementPlanProfileListingModel dmpProfile, String label) throws InstantiationException, IllegalAccessException, IOException {
ExportXmlBuilderDmpProfile xmlBuilder = new ExportXmlBuilderDmpProfile();
File file = xmlBuilder.build(dmpProfile);
FileEnvelope fileEnvelope = new FileEnvelope();
fileEnvelope.setFile(file);
fileEnvelope.setFilename(label);
return fileEnvelope;
}
public eu.eudat.logic.utilities.documents.xml.dmpXml.dmpProfileModel.DmpProfile createDmpProfileFromXml(MultipartFile multiPartFile) {
ImportXmlBuilderDmpProfile xmlBuilder = new ImportXmlBuilderDmpProfile();
try {
return xmlBuilder.build(convert(multiPartFile));
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
private static File convert(MultipartFile file) throws IOException {
File convFile = new File(file.getOriginalFilename());
convFile.createNewFile();
FileOutputStream fos = new FileOutputStream(convFile);
fos.write(file.getBytes());
fos.close();
return convFile;
}
}

View File

@ -0,0 +1,55 @@
package eu.eudat.logic.utilities.documents.xml.dmpXml;
import eu.eudat.logic.utilities.builders.XmlBuilder;
import eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.DataManagementPlanProfile;
import eu.eudat.models.data.listingmodels.DataManagementPlanProfileListingModel;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.UUID;
public class ExportXmlBuilderDmpProfile {
public File build(DataManagementPlanProfileListingModel dmpProfile) throws IOException {
File xmlFile = new File(UUID.randomUUID() + ".xml");
BufferedWriter writer = new BufferedWriter(new FileWriter(xmlFile, true));
Document xmlDoc = XmlBuilder.getDocument();
Element root = xmlDoc.createElement("root");
Element definition = xmlDoc.createElement("definition");
// Element root = xmlDoc.createElement(dmpProfile.getLabel());
definition.appendChild(createDefinition(dmpProfile.getDefinition(), xmlDoc));
root.appendChild(definition);
xmlDoc.appendChild(root);
String xml = XmlBuilder.generateXml(xmlDoc);
writer.write(xml);
writer.close();
return xmlFile;
}
public Element createDefinition(DataManagementPlanProfile dmpDefinition, Document element) {
Element fields = element.createElement("fieldSets");
dmpDefinition.getFields().forEach(item -> {
Element field = element.createElement("field");
field.setAttribute("id", "" + item.getId());
field.setAttribute("type", "" + item.getType());
field.setAttribute("dataType", "" + item.getDataType());
field.setAttribute("required", "" + item.getRequired());
field.setAttribute("label", "" + item.getLabel());
if(item.getValue()!=null) {
Element value = element.createElement("value");
value.setAttribute("value", ""+item.getValue());
field.appendChild(value);
}
fields.appendChild(field);
});
return fields;
}
}

View File

@ -0,0 +1,27 @@
package eu.eudat.logic.utilities.documents.xml.dmpXml;
import eu.eudat.logic.utilities.documents.xml.dmpXml.dmpProfileModel.DmpProfile;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import java.io.File;
import java.io.IOException;
public class ImportXmlBuilderDmpProfile {
public DmpProfile build(File xmlFile) throws IOException {
DmpProfile dmpProfile = new DmpProfile();
JAXBContext jaxbContext = null;
try {
jaxbContext = JAXBContext.newInstance(DmpProfile.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
dmpProfile = (DmpProfile) unmarshaller.unmarshal(xmlFile);
} catch (JAXBException e) {
e.printStackTrace();
}
return dmpProfile;
}
}

View File

@ -0,0 +1,23 @@
package eu.eudat.logic.utilities.documents.xml.dmpXml.dmpProfileModel;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "datatype")
public class DMPProfileFieldDataType {
private int datatype;
@XmlAttribute(name = "datatype")
public int getDatatype() {
return datatype;
}
public void setDatatype(int datatype) {
this.datatype = datatype;
}
public eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.types.DMPProfileFieldDataType toDmpProfileCompositeModel() {
return eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.types.DMPProfileFieldDataType.fromInteger(datatype);
}
}

View File

@ -0,0 +1,26 @@
package eu.eudat.logic.utilities.documents.xml.dmpXml.dmpProfileModel;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "type")
public class DMPProfileType {
private int type;
@XmlAttribute(name = "type")
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.types.DMPProfileType toDmpProfileCompositeModel() {
return eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.types.DMPProfileType.fromInteger(type);
}
}

View File

@ -0,0 +1,33 @@
package eu.eudat.logic.utilities.documents.xml.dmpXml.dmpProfileModel;
import eu.eudat.data.entities.DMPProfile;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Date;
import java.util.UUID;
@XmlRootElement(name = "root")
public class DmpProfile {
private DmpProfileDefinition dmpProfileDefinition;
@XmlElement(name = "definition")
public DmpProfileDefinition getDmpProfileDefinition() {
return dmpProfileDefinition;
}
public void setDmpProfileDefinition(DmpProfileDefinition dmpProfileDefinition) {
this.dmpProfileDefinition = dmpProfileDefinition;
}
public eu.eudat.models.data.listingmodels.DataManagementPlanProfileListingModel toDmpProfileCompositeModel(String label) {
eu.eudat.models.data.listingmodels.DataManagementPlanProfileListingModel dmpProfileModel = new eu.eudat.models.data.listingmodels.DataManagementPlanProfileListingModel();
dmpProfileModel.setLabel(label);
dmpProfileModel.setStatus(DMPProfile.Status.SAVED.getValue());
dmpProfileModel.setCreated(new Date());
dmpProfileModel.setModified(new Date());
dmpProfileModel.setDefinition(this.dmpProfileDefinition.toDmpProfileCompositeModel());
return dmpProfileModel;
}
}

View File

@ -0,0 +1,36 @@
package eu.eudat.logic.utilities.documents.xml.dmpXml.dmpProfileModel;
import eu.eudat.logic.utilities.documents.xml.dmpXml.dmpProfileModel.FieldSets;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.LinkedList;
import java.util.List;
@XmlRootElement(name = "definition")
public class DmpProfileDefinition {
private FieldSets fieldSets;
@XmlElement(name = "fieldSets")
public FieldSets getFieldSets() {
return fieldSets;
}
public void setFieldSets(FieldSets fieldSets) {
this.fieldSets = fieldSets;
}
public eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.DataManagementPlanProfile toDmpProfileCompositeModel() {
eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.DataManagementPlanProfile dmpProfileDefinitionModel = new eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.DataManagementPlanProfile();
List<eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.Field> dmpProfileDefinitionFields = new LinkedList<>();
for (Field field:this.fieldSets.fields) {
dmpProfileDefinitionFields.add(field.toDmpProfileCompositeModel());
}
dmpProfileDefinitionModel.setFields(dmpProfileDefinitionFields);
return dmpProfileDefinitionModel;
}
}

View File

@ -0,0 +1,90 @@
package eu.eudat.logic.utilities.documents.xml.dmpXml.dmpProfileModel;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;
import java.util.UUID;
@XmlRootElement(name = "field")
public class Field {
private String id;
private String label;
private int dataType;
private boolean required;
private int type;
// private Object value;
@XmlAttribute(name = "id")
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
@XmlAttribute(name = "label")
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
@XmlAttribute(name = "dataType")
public int getDataType() {
return dataType;
}
public void setDataType(int dataType) {
this.dataType = dataType;
}
@XmlAttribute(name = "required")
public boolean isRequired() {
return required;
}
public void setRequired(boolean required) {
this.required = required;
}
@XmlAttribute(name = "type")
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
// @XmlValue
// public Object getValue() {
// return value;
// }
//
// public void setValue(Object value) {
// this.value = value;
// }
public eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.Field toDmpProfileCompositeModel() {
eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.Field field = new eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.Field();
field.setId(UUID.fromString(this.id));
field.setDataType(eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.types.DMPProfileFieldDataType.fromInteger(this.dataType));
field.setLabel(this.label);
field.setRequired(this.required);
field.setType(eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.types.DMPProfileType.fromInteger(this.type));
// field.setValue(this.value);
return field;
}
}

View File

@ -0,0 +1,22 @@
package eu.eudat.logic.utilities.documents.xml.dmpXml.dmpProfileModel;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.LinkedList;
import java.util.List;
@XmlRootElement(name = "fieldSets")
public class FieldSets {
List<Field> fields;
@XmlElement(name = "field")
public List<Field> getField() {
return fields;
}
public void setField(List<Field> fields) {
this.fields = fields;
}
}

View File

@ -81,6 +81,7 @@ public class DataManagementPlanProfileListingModel implements DataModel<DMPProfi
this.definition = new DataManagementPlanProfile().fromXml(XmlBuilder.fromXml(entity.getDefinition()).getDocumentElement());
this.modified = entity.getModified();
this.label = entity.getLabel();
this.status = entity.getStatus();
return this;
}

View File

@ -2,11 +2,11 @@ import { HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { environment } from '../../../../environments/environment';
import { RequestItem } from '../../query/request-item';
import { DataTableData } from '../../model/data-table/data-table-data';
import { DataTableRequest } from '../../model/data-table/data-table-request';
import { ProjectListingModel } from '../../model/project/project-listing';
import { ProjectCriteria } from '../../query/project/project-criteria';
import { RequestItem } from '../../query/request-item';
import { BaseHttpService } from '../http/base-http.service';

View File

@ -7,6 +7,7 @@ import { DmpProfileRoutingModule } from "./dmp-profile.routing";
import { DmpProfileEditorComponent } from "./editor/dmp-profile-editor.component";
import { DmpProfileCriteriaComponent } from "./listing/criteria/dmp-profile-criteria.component";
import { DmpProfileListingComponent } from "./listing/dmp-profile-listing.component";
import { DialodConfirmationUploadDmpProfiles } from "./listing/criteria/dialog-confirmation-upload-profile/dialog-confirmation-upload-profiles.component";
@NgModule({
imports: [
@ -19,7 +20,11 @@ import { DmpProfileListingComponent } from "./listing/dmp-profile-listing.compon
declarations: [
DmpProfileEditorComponent,
DmpProfileListingComponent,
DmpProfileCriteriaComponent
DmpProfileCriteriaComponent,
DialodConfirmationUploadDmpProfiles
],
entryComponents: [
DialodConfirmationUploadDmpProfiles
]
})
export class DmpProfileModule { }

View File

@ -12,54 +12,81 @@
<mat-card-content>
<div class="row">
<mat-form-field class="col-12">
<input matInput placeholder="{{'DMP-PROFILE-EDITOR.FIELDS.LABEL' | translate}}" type="text" name="label" formControlName="label" required>
<mat-error *ngIf="formGroup.get('label').hasError('backendError')">{{formGroup.get('label').getError('backendError').message}}</mat-error>
<mat-error *ngIf="formGroup.get('label').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<input matInput placeholder="{{'DMP-PROFILE-EDITOR.FIELDS.LABEL' | translate}}" type="text"
name="label" formControlName="label" required>
<mat-error *ngIf="formGroup.get('label').hasError('backendError')">
{{formGroup.get('label').getError('backendError').message}}</mat-error>
<mat-error *ngIf="formGroup.get('label').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
<h4 class="col-12">{{'DMP-PROFILE-EDITOR.FIELDS.TITLE' | translate}}</h4>
<div class="col-12">
<div class="row" *ngFor="let fieldFormGroup of formGroup.get('definition').get('fields')['controls'];let i=index">
<div class="row"
*ngFor="let fieldFormGroup of formGroup.get('definition').get('fields')['controls'];let i=index">
<mat-form-field class="col">
<input matInput placeholder="{{'DMP-PROFILE-EDITOR.FIELDS.LABEL' | translate}}" type="text" name="label" [formControl]="fieldFormGroup.get('label')" required>
<mat-error *ngIf="fieldFormGroup.get('label').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="fieldFormGroup.get('label').hasError('backendError')">{{fieldFormGroup.get('label').getError('backendError').message}}</mat-error>
<input matInput placeholder="{{'DMP-PROFILE-EDITOR.FIELDS.LABEL' | translate}}"
type="text" name="label" [formControl]="fieldFormGroup.get('label')" required>
<mat-error *ngIf="fieldFormGroup.get('label').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="fieldFormGroup.get('label').hasError('backendError')">
{{fieldFormGroup.get('label').getError('backendError').message}}</mat-error>
</mat-form-field>
<mat-form-field class="col">
<mat-select placeholder="{{'DMP-PROFILE-EDITOR.FIELDS.TYPE' | translate}}" [formControl]="fieldFormGroup.get('type')" required>
<mat-option *ngFor="let fieldType of getDMPProfileFieldTypeValues()" [value]="fieldType">{{
<mat-select placeholder="{{'DMP-PROFILE-EDITOR.FIELDS.TYPE' | translate}}"
[formControl]="fieldFormGroup.get('type')" required>
<mat-option *ngFor="let fieldType of getDMPProfileFieldTypeValues()"
[value]="fieldType">{{
getDMPProfileFieldTypeWithLanguage(fieldType) | translate}}</mat-option>
</mat-select>
<mat-error *ngIf="fieldFormGroup.get('type').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="fieldFormGroup.get('type').hasError('backendError')">{{fieldFormGroup.get('type').getError('backendError').message}}</mat-error>
<mat-error *ngIf="fieldFormGroup.get('type').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="fieldFormGroup.get('type').hasError('backendError')">
{{fieldFormGroup.get('type').getError('backendError').message}}</mat-error>
</mat-form-field>
<mat-form-field class="col">
<mat-select placeholder="{{'DMP-PROFILE-EDITOR.FIELDS.DATATYPE' | translate}}" [formControl]="fieldFormGroup.get('dataType')" required>
<mat-option *ngFor="let fieldDataType of getDMPProfileFieldDataTypeValues()" [value]="fieldDataType">{{
<mat-select placeholder="{{'DMP-PROFILE-EDITOR.FIELDS.DATATYPE' | translate}}"
[formControl]="fieldFormGroup.get('dataType')" required>
<mat-option *ngFor="let fieldDataType of getDMPProfileFieldDataTypeValues()"
[value]="fieldDataType">{{
getDMPProfileFieldDataTypeWithLanguage(fieldDataType) | translate}}</mat-option>
</mat-select>
<mat-error *ngIf="fieldFormGroup.get('dataType').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="fieldFormGroup.get('dataType').hasError('backendError')">{{fieldFormGroup.get('dataType').getError('backendError').message}}</mat-error>
<mat-error *ngIf="fieldFormGroup.get('dataType').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="fieldFormGroup.get('dataType').hasError('backendError')">
{{fieldFormGroup.get('dataType').getError('backendError').message}}</mat-error>
</mat-form-field>
<div class="centered-row-item col-auto">
<mat-checkbox [formControl]="fieldFormGroup.get('required')">{{'DMP-PROFILE-EDITOR.FIELDS.REQUIRED' | translate}}</mat-checkbox>
<mat-checkbox [formControl]="fieldFormGroup.get('required')">
{{'DMP-PROFILE-EDITOR.FIELDS.REQUIRED' | translate}}</mat-checkbox>
</div>
<div class="centered-row-item col-auto"><button mat-icon-button type="button" (click)="removeField(i)">
<div class="centered-row-item col-auto"><button mat-icon-button type="button"
(click)="removeField(i)" [disabled]="viewOnly">
<mat-icon class="mat-24">delete</mat-icon>
</button>
</div>
</div>
<button mat-icon-button class="col-auto" color="primary" type="button" (click)="addField()">
<button mat-icon-button class="col-auto" color="primary" type="button" (click)="addField()"
[disabled]="viewOnly">
<mat-icon class="mat-24">add</mat-icon>
</button>
</div>
</div>
<div class="col-12">
<div class="row">
<div class="col-auto"><button mat-raised-button color="primary" (click)="cancel()"
type="button">{{'DMP-PROFILE-EDITOR.ACTIONS.CANCEL' | translate}}</button></div>
<div class="col"></div>
<div class="col-auto" *ngIf="!isNew"><button mat-raised-button color="primary" type="button" (click)="delete()">{{'DMP-PROFILE-EDITOR.ACTIONS.DELETE' | translate}}</button></div>
<div class="col-auto"><button mat-raised-button color="primary" (click)="cancel()" type="button">{{'DMP-PROFILE-EDITOR.ACTIONS.CANCEL' | translate}}</button></div>
<div class="col-auto"><button mat-raised-button color="primary" type="submit">{{'DMP-PROFILE-EDITOR.ACTIONS.SAVE' | translate}}</button></div>
<div class="col-auto" *ngIf="!isNew"><button mat-raised-button color="primary" type="button"
(click)="delete()">{{'DMP-PROFILE-EDITOR.ACTIONS.DELETE' | translate}}</button></div>
<button mat-raised-button *ngIf="formGroup.get('status').value!=1" class="col-auto"
color="primary" (click)="finalize()" [disabled]="!formGroup.valid"
type="button">{{'DMP-PROFILE-EDITOR.ACTIONS.FINALIZE' | translate }}</button>
<button mat-raised-button *ngIf="formGroup.get('status').value==1" class="col-auto"
color="primary" (click)="downloadXML()"
type="button">{{'DMP-PROFILE-EDITOR.ACTIONS.DOWNLOAD-XML' | translate }}</button>
<div class="col-auto" *ngIf="!viewOnly"><button mat-raised-button color="primary"
type="submit">{{'DMP-PROFILE-EDITOR.ACTIONS.SAVE' | translate}}</button></div>
</div>
</div>
</mat-card-content>

View File

@ -2,18 +2,19 @@ import { AfterViewInit, Component } from '@angular/core';
import { AbstractControl, FormArray, FormControl, FormGroup } from '@angular/forms';
import { ActivatedRoute, Params, Router } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import * as FileSaver from 'file-saver';
import { takeUntil } from 'rxjs/operators';
import { environment } from '../../../../../environments/environment';
import { ValidationErrorModel } from '../../../../common/forms/validation/error-model/validation-error-model';
import { BaseComponent } from '../../../../core/common/base/base.component';
import { DmpProfileFieldDataType } from '../../../../core/common/enum/dmp-profile-field-type';
import { DmpProfileStatus } from '../../../../core/common/enum/dmp-profile-status';
import { DmpProfileType } from '../../../../core/common/enum/dmp-profile-type';
import { DmpProfile } from '../../../../core/model/dmp-profile/dmp-profile';
import { DmpProfileService } from '../../../../core/services/dmp/dmp-profile.service';
import { SnackBarNotificationLevel, UiNotificationService } from '../../../../core/services/notification/ui-notification-service';
import { EnumUtils } from '../../../../core/services/utilities/enum-utils.service';
import { DmpProfileEditorModel, DmpProfileFieldEditorModel } from './dmp-profile-editor.model';
import { DmpProfileStatus } from '../../../../core/common/enum/dmp-profile-status';
@Component({
selector: 'app-dmp-profile-editor-component',
@ -23,9 +24,11 @@ import { DmpProfileStatus } from '../../../../core/common/enum/dmp-profile-statu
export class DmpProfileEditorComponent extends BaseComponent implements AfterViewInit {
isNew = true;
viewOnly = false;
dmpProfileModel: DmpProfileEditorModel;
formGroup: FormGroup = null;
host = environment.Server;
dmpProfileId: string;
constructor(
private dmpProfileService: DmpProfileService,
@ -42,15 +45,19 @@ export class DmpProfileEditorComponent extends BaseComponent implements AfterVie
this.route.params
.pipe(takeUntil(this._destroyed))
.subscribe((params: Params) => {
const itemId = params['id'];
this.dmpProfileId = params['id'];
if (itemId != null) {
if (this.dmpProfileId != null) {
this.isNew = false;
this.dmpProfileService.getSingle(itemId).map(data => data as DmpProfile)
this.dmpProfileService.getSingle(this.dmpProfileId).map(data => data as DmpProfile)
.pipe(takeUntil(this._destroyed))
.subscribe(data => {
this.dmpProfileModel = new DmpProfileEditorModel().fromModel(data);
this.formGroup = this.dmpProfileModel.buildForm();
if (this.dmpProfileModel.status == DmpProfileStatus.Finalized) {
this.formGroup.disable();
this.viewOnly = true
}
});
} else {
this.dmpProfileModel = new DmpProfileEditorModel();
@ -182,4 +189,41 @@ export class DmpProfileEditorComponent extends BaseComponent implements AfterVie
error => this.onCallbackError(error)
);
}
finalize() {
//const data = this.form.value;
this.formGroup.get('status').setValue(DmpProfileStatus.Finalized);
this.onSubmit();
}
downloadXML(): void {
this.dmpProfileService.downloadXML(this.dmpProfileId)
.pipe(takeUntil(this._destroyed))
.subscribe(response => {
const blob = new Blob([response.body], { type: 'application/xml' });
const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
FileSaver.saveAs(blob, filename);
});
}
getFilenameFromContentDispositionHeader(header: string): string {
const regex: RegExp = new RegExp(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/g);
const matches = header.match(regex);
let filename: string;
for (let i = 0; i < matches.length; i++) {
const match = matches[i];
if (match.includes('filename="')) {
filename = match.substring(10, match.length - 1);
break;
} else if (match.includes('filename=')) {
filename = match.substring(9);
break;
}
}
return filename;
}
}

View File

@ -0,0 +1,23 @@
<div class="confirmation-dialog">
<div class="row">
<div class="confirmation-message col">
<h4>{{ data.message }}</h4>
</div>
<div class="col-auto">
<input class="hidden" type="file" #imgFileInput (change)="selectXML($event)" accept="text/xml" />
<button mat-raised-button class="col-auto" color="{{btnColore}}" (click)="imgFileInput.click()"
type="button">{{ 'DMP-PROFILE-LISTING.UPLOAD.UPLOAD-XML-IMPORT' | translate }}</button>
</div>
</div>
<div class="row">
<mat-form-field class="col-12">
<input matInput placeholder="{{'DMP-PROFILE-LISTING.UPLOAD.UPLOAD-XML-NAME'| translate}}"
name="datasetProfileName" [(ngModel)]="data.name">
</mat-form-field>
<div class="col-auto"><button mat-raised-button color="primary" type="button"
(click)="cancel()">{{ data.cancelButton }}</button></div>
<div class="col"></div>
<div class="col-auto"><button mat-raised-button color="primary" type="button"
(click)="confirm()" [disabled]="!hasProfile()">{{ data.confirmButton }}</button></div>
</div>
</div>

View File

@ -0,0 +1,53 @@
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
import { Inject, Component } from '@angular/core';
@Component({
selector: 'app-dialog-confirmation-upload',
templateUrl: './dialog-confirmation-upload-profiles.component.html',
styleUrls: ['./dialog-confirmation-upload-profiles.component.scss']
})
export class DialodConfirmationUploadDmpProfiles {
sizeError = false;
btnColore:String="primary";
selectFile =false;
maxFileSize: number = 1048576;
constructor(
public dialogRef: MatDialogRef<DialodConfirmationUploadDmpProfiles>,
@Inject(MAT_DIALOG_DATA) public data: any
) { }
selectXML(event) {
const file: FileList = event.target.files;
const size: number = file[0].size; // Get file size.
this.sizeError = size > this.maxFileSize; // Checks if file size is valid.
const formdata: FormData = new FormData();
if (!this.sizeError) {
this.data.file = file;
this.selectFile=true;
this.btnColore="primary";
}else{
this.btnColore="warn";
}
this.data.name = file[0].name;
}
cancel() {
this.data.sucsess = false;
this.dialogRef.close(this.data);
}
confirm() {
this.data.name = this.data.name;
this.data.sucsess = true;
this.dialogRef.close(this.data);
}
hasProfile():boolean{
return (this.selectFile && !this.sizeError);
}
}

View File

@ -1,9 +1,18 @@
<div class="dmp-criteria">
<mat-card class="mat-card">
<div class="row">
<mat-form-field class="col-md-6">
<input matInput placeholder=" {{'CRITERIA.DMP.LIKE'| translate}}" name="projectCriteriaLike" [(ngModel)]="criteria.like" (ngModelChange)="controlModified()">
<input matInput placeholder=" {{'CRITERIA.DMP.LIKE'| translate}}" name="projectCriteriaLike"
[(ngModel)]="criteria.like" (ngModelChange)="controlModified()">
</mat-form-field>
<div class="col"></div>
<div class="col-auto">
<!-- imgFileInput.click() && -->
<button mat-raised-button class="col-auto" color="primary" (click)="openDialog()"
type="button">{{ 'DMP-PROFILE-LISTING.UPLOAD.UPLOAD-XML' | translate }}</button>
</div>
</div>
</mat-card>
</div>

View File

@ -4,6 +4,11 @@ import { ProjectListingModel } from '../../../../../core/model/project/project-l
import { DmpCriteria } from '../../../../../core/query/dmp/dmp-criteria';
import { DmpProfileCriteria } from '../../../../../core/query/dmp/dmp-profile-criteria';
import { BaseCriteriaComponent } from '../../../../misc/criteria/base-criteria.component';
import { DialodConfirmationUploadDmpProfiles } from './dialog-confirmation-upload-profile/dialog-confirmation-upload-profiles.component';
import { MatDialog } from '@angular/material';
import { TranslateService } from '@ngx-translate/core';
import { takeUntil } from 'rxjs/operators';
import { DmpProfileService } from '../../../../../core/services/dmp/dmp-profile.service';
@Component({
selector: 'app-dmp-profile-criteria-component',
@ -17,8 +22,10 @@ export class DmpProfileCriteriaComponent extends BaseCriteriaComponent implement
public criteria: DmpProfileCriteria = new DmpProfileCriteria();
filteringProjectsAsync = false;
filteredProjects: ProjectListingModel[];
constructor(
private dmpProfileService: DmpProfileService,
private dialog: MatDialog,
private language: TranslateService
) {
super(new ValidationErrorModel());
}
@ -44,4 +51,25 @@ export class DmpProfileCriteriaComponent extends BaseCriteriaComponent implement
this.refreshCallback();
}
}
openDialog(): void {
const dialogRef = this.dialog.open(DialodConfirmationUploadDmpProfiles, {
data: {
message: this.language.instant('DMP-PROFILE-LISTING.UPLOAD.UPLOAD-XML-FILE-TITLE'),
confirmButton: this.language.instant('DMP-PROFILE-LISTING.UPLOAD.UPLOAD-XML'),
cancelButton: this.language.instant('DMP-PROFILE-LISTING.UPLOAD.UPLOAD-XML-FILE-CANCEL'),
name: this.language.instant('DMP-PROFILE-LISTING.UPLOAD.UPLOAD-XML-NAME'),
file: FileList,
sucsess: false
}
});
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(data => {
if (data.sucsess && data.name != null && data.file != null) {
this.dmpProfileService.uploadFile(data.file, data.name)
.pipe(takeUntil(this._destroyed))
.subscribe();
}
});
}
}