Adds Dmp Import functionality.
This commit is contained in:
parent
ab8022d133
commit
6ab752b99c
|
@ -11,10 +11,12 @@ import eu.eudat.data.query.items.table.dmp.DataManagementPlanTableRequest;
|
|||
import eu.eudat.exceptions.datamanagementplan.DMPWithDatasetsDeleteException;
|
||||
import eu.eudat.logic.managers.DataManagementPlanManager;
|
||||
import eu.eudat.logic.managers.DatasetManager;
|
||||
import eu.eudat.logic.managers.FileManager;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.logic.services.forms.VisibilityRuleService;
|
||||
import eu.eudat.logic.utilities.documents.helpers.FileEnvelope;
|
||||
import eu.eudat.models.data.dmp.DataManagementPlan;
|
||||
import eu.eudat.models.data.files.ContentFile;
|
||||
import eu.eudat.models.data.helpermodels.Tuple;
|
||||
import eu.eudat.models.data.helpers.common.DataTableData;
|
||||
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
||||
|
@ -30,9 +32,11 @@ import org.springframework.http.MediaType;
|
|||
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.activation.MimetypesFileTypeMap;
|
||||
import javax.validation.Valid;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -170,5 +174,12 @@ public class DMPs extends BaseController {
|
|||
responseHeaders,
|
||||
HttpStatus.OK);
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = {"/upload"})
|
||||
public ResponseEntity<ResponseItem> dmpXmlUpload(@RequestParam("file") MultipartFile[] files, Principal principal) throws IOException, JAXBException, Exception {
|
||||
this.dataManagementPlanManager.createDmpFromXml(this.getApiContext(), files, principal);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List>()
|
||||
.status(ApiMessageCode.SUCCESS_MESSAGE).message("Bravo Giorgo"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,5 +47,4 @@ public class FileController extends BaseController {
|
|||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + resource.getFilename() + "." + type + "\"")
|
||||
.body(resource);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ import eu.eudat.configurations.dynamicproject.entities.Property;
|
|||
import eu.eudat.data.dao.criteria.*;
|
||||
import eu.eudat.data.dao.entities.*;
|
||||
import eu.eudat.data.entities.*;
|
||||
import eu.eudat.data.entities.Organisation;
|
||||
import eu.eudat.data.entities.Researcher;
|
||||
import eu.eudat.data.query.items.item.dmp.DataManagementPlanCriteriaRequest;
|
||||
import eu.eudat.data.query.items.table.dmp.DataManagementPlanTableRequest;
|
||||
import eu.eudat.exceptions.datamanagementplan.DMPWithDatasetsDeleteException;
|
||||
|
@ -19,8 +21,7 @@ import eu.eudat.logic.utilities.documents.word.WordBuilder;
|
|||
import eu.eudat.logic.utilities.documents.xml.ExportXmlBuilder;
|
||||
import eu.eudat.models.HintedModelFactory;
|
||||
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
|
||||
import eu.eudat.models.data.dmp.DataManagementPlan;
|
||||
import eu.eudat.models.data.dmp.DataManagementPlanNewVersionModel;
|
||||
import eu.eudat.models.data.dmp.*;
|
||||
import eu.eudat.models.data.dynamicfields.DynamicFieldWithValue;
|
||||
import eu.eudat.models.data.helpermodels.Tuple;
|
||||
import eu.eudat.models.data.helpers.common.DataTableData;
|
||||
|
@ -35,10 +36,16 @@ import org.springframework.core.env.Environment;
|
|||
import org.springframework.http.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import javax.activation.MimetypesFileTypeMap;
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import java.io.*;
|
||||
import java.math.BigInteger;
|
||||
import java.net.URL;
|
||||
|
@ -107,12 +114,21 @@ public class DataManagementPlanManager {
|
|||
wordBuilder.addParagraphContent(dmpEntity.getDescription(), document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||
|
||||
wordBuilder.addParagraphContent("Organisations", document, ParagraphStyle.HEADER2, BigInteger.ZERO);
|
||||
wordBuilder.addParagraphContent(dmpEntity.getOrganisations().stream().map(x -> x.getLabel()).collect(Collectors.joining(","))
|
||||
, document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||
if (dmpEntity.getOrganisations().size() > 0) {
|
||||
wordBuilder.addParagraphContent(dmpEntity.getOrganisations().stream().map(x -> x.getLabel()).collect(Collectors.joining(", "))
|
||||
, document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||
}
|
||||
|
||||
wordBuilder.addParagraphContent("Researchers", document, ParagraphStyle.HEADER2, BigInteger.ZERO);
|
||||
wordBuilder.addParagraphContent(dmpEntity.getResearchers().stream().map(x -> x.getLabel()).collect(Collectors.joining(","))
|
||||
, document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||
if (dmpEntity.getResearchers().size() > 0) {
|
||||
wordBuilder.addParagraphContent(dmpEntity.getResearchers().stream().map(x -> x.getLabel()).collect(Collectors.joining(", "))
|
||||
, document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||
}
|
||||
|
||||
/*wordBuilder.addParagraphContent("DMP Profile", document, ParagraphStyle.HEADER2, BigInteger.ZERO);
|
||||
if (dmpEntity.getProfile() != null){
|
||||
wordBuilder.addParagraphContent(dmpEntity.getProfile().getLabel(), document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||
}*/
|
||||
|
||||
wordBuilder.addParagraphContent("Datasets", document, ParagraphStyle.TITLE, BigInteger.ZERO);
|
||||
dmpEntity.getDataset().stream().forEach(datasetEntity -> {
|
||||
|
@ -133,7 +149,9 @@ public class DataManagementPlanManager {
|
|||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
File exportFile = new File(dmpEntity.getLabel() + ".docx");
|
||||
String fileName = dmpEntity.getLabel();
|
||||
fileName = fileName.replaceAll("[^a-zA-Z0-9+ ]", "");
|
||||
File exportFile = new File( fileName + ".docx");
|
||||
FileOutputStream out = new FileOutputStream(exportFile);
|
||||
document.write(out);
|
||||
out.close();
|
||||
|
@ -322,7 +340,6 @@ public class DataManagementPlanManager {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private void copyDatasets(DMP newDmp, DatasetDao datasetDao) {
|
||||
List<CompletableFuture<Dataset>> futures = new LinkedList<>();
|
||||
for (Dataset dataset : newDmp.getDataset()) {
|
||||
|
@ -387,32 +404,62 @@ public class DataManagementPlanManager {
|
|||
ExportXmlBuilder xmlBuilder = new ExportXmlBuilder();
|
||||
eu.eudat.data.entities.DMP dmp = dmpRepository.find(UUID.fromString(id));
|
||||
List<Dataset> datasets = dmp.getDataset().stream().collect(Collectors.toList());
|
||||
File xmlFile = new File(dmp.getLabel() + ".xml");
|
||||
String fileName = dmp.getLabel();
|
||||
fileName = fileName.replaceAll("[^a-zA-Z0-9+ ]", "");
|
||||
File xmlFile = new File(fileName + ".xml");
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(xmlFile, true));
|
||||
Document xmlDoc = XmlBuilder.getDocument();
|
||||
Element root = xmlDoc.createElement("root");
|
||||
Element dmpElement = xmlDoc.createElement("dmp");
|
||||
Element dmpDescription = xmlDoc.createElement("description");
|
||||
dmpDescription.setTextContent(dmp.getDescription());
|
||||
dmpElement.appendChild(dmpDescription);
|
||||
Element dmpName = xmlDoc.createElement("dmpName");
|
||||
dmpName.setTextContent(dmp.getLabel());
|
||||
dmpElement.appendChild(dmpName);
|
||||
Element projectName = xmlDoc.createElement("projectName");
|
||||
projectName.setTextContent(dmp.getProject().getLabel());
|
||||
dmpElement.appendChild(projectName);
|
||||
|
||||
DMPProfile dmpProfile = dmp.getProfile();
|
||||
Element dmpProfileElement = xmlDoc.createElement("dmpProfile");
|
||||
Element dmpProfileName = xmlDoc.createElement("dmpProfileName");
|
||||
if (!(dmpProfile == null)){
|
||||
dmpProfileName.setTextContent(dmpProfile.getLabel());
|
||||
dmpProfileElement.appendChild(dmpProfileName);
|
||||
Element dmpProfileId = xmlDoc.createElement("dmpProfileId");
|
||||
dmpProfileId.setTextContent(dmpProfile.getId().toString());
|
||||
dmpProfileElement.appendChild(dmpProfileId);
|
||||
}
|
||||
dmpElement.appendChild(dmpProfileElement);
|
||||
|
||||
Element project = xmlDoc.createElement("project");
|
||||
Element label = xmlDoc.createElement("label");
|
||||
label.setTextContent(dmp.getProject().getLabel());
|
||||
project.appendChild(label);
|
||||
Element projectId = xmlDoc.createElement("id");
|
||||
projectId.setTextContent(dmp.getProject().getId().toString());
|
||||
project.appendChild(projectId);
|
||||
dmpElement.appendChild(project);
|
||||
Element organisationsElement = xmlDoc.createElement("organisations");
|
||||
for (Organisation organisation : dmp.getOrganisations()) {
|
||||
Element organisationElement = xmlDoc.createElement("organisation");
|
||||
organisationElement.setAttribute("name", organisation.getLabel());
|
||||
organisationElement.setAttribute("reference", organisation.getReference());
|
||||
Element organisationNameElement = xmlDoc.createElement("name");
|
||||
organisationNameElement.setTextContent(organisation.getLabel());
|
||||
Element organisationReferenceElement = xmlDoc.createElement("reference");
|
||||
organisationReferenceElement.setTextContent(organisation.getReference());
|
||||
organisationElement.appendChild(organisationNameElement);
|
||||
organisationElement.appendChild(organisationReferenceElement);
|
||||
organisationsElement.appendChild(organisationElement);
|
||||
}
|
||||
dmpElement.appendChild(organisationsElement);
|
||||
|
||||
Element researchersElement = xmlDoc.createElement("researchers");
|
||||
for (Researcher researcher : dmp.getResearchers()) {
|
||||
Element researcherElement = xmlDoc.createElement("organisation");
|
||||
researcherElement.setAttribute("name", researcher.getLabel());
|
||||
researcherElement.setAttribute("reference", researcher.getReference());
|
||||
organisationsElement.appendChild(researcherElement);
|
||||
Element researcherElement = xmlDoc.createElement("researcher");
|
||||
Element researcherNameElement = xmlDoc.createElement("name");
|
||||
researcherNameElement.setTextContent(researcher.getLabel());
|
||||
Element researcherReferenceElement = xmlDoc.createElement("reference");
|
||||
researcherReferenceElement.setTextContent(researcher.getReference());
|
||||
researcherElement.appendChild(researcherNameElement);
|
||||
researcherElement.appendChild(researcherReferenceElement);
|
||||
researchersElement.appendChild(researcherElement);
|
||||
}
|
||||
dmpElement.appendChild(researchersElement);
|
||||
Element datasetsElement = xmlDoc.createElement("datasets");
|
||||
|
@ -432,9 +479,33 @@ public class DataManagementPlanManager {
|
|||
datasetElement.appendChild(xmlBuilder.createPages(pagedDatasetProfile.getPages(), visibilityRuleService, xmlDoc));
|
||||
datasetsElement.appendChild(datasetElement);
|
||||
}
|
||||
Element profiles = xmlDoc.createElement("profiles");
|
||||
// Get DatasetProfiles from dmp to add to XML.
|
||||
if (dmp.getAssociatedDmps() != null && !dmp.getAssociatedDmps().isEmpty()) {
|
||||
Document viewStyleDoc = XmlBuilder.fromXml(dmp.getAssociatedDmps());
|
||||
Element item = (Element) viewStyleDoc.getElementsByTagName("profiles").item(0);
|
||||
if (item != null) {
|
||||
NodeList associatedProfilesElement = item.getChildNodes();
|
||||
for (int temp = 0; temp < associatedProfilesElement.getLength(); temp++) {
|
||||
Node associatedProfileElement = associatedProfilesElement.item(temp);
|
||||
if (associatedProfileElement.getNodeType() == Node.ELEMENT_NODE) {
|
||||
Element profile = xmlDoc.createElement("profile");
|
||||
Element profileLabel = xmlDoc.createElement("profilelabel");
|
||||
Node labelNode = associatedProfileElement.getAttributes().item(0);
|
||||
profileLabel.setTextContent(labelNode.getNodeValue());
|
||||
profile.appendChild(profileLabel);
|
||||
Element profileId = xmlDoc.createElement("profileId");
|
||||
Node idNode = associatedProfileElement.getAttributes().item(1);
|
||||
profileId.setTextContent(idNode.getNodeValue());
|
||||
profile.appendChild(profileId);
|
||||
profiles.appendChild(profile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
dmpElement.appendChild(profiles);
|
||||
dmpElement.appendChild(datasetsElement);
|
||||
root.appendChild(dmpElement);
|
||||
xmlDoc.appendChild(root);
|
||||
xmlDoc.appendChild(dmpElement);
|
||||
String xml = XmlBuilder.generateXml(xmlDoc);
|
||||
writer.write(xml);
|
||||
writer.close();
|
||||
|
@ -474,4 +545,65 @@ public class DataManagementPlanManager {
|
|||
responseHeaders,
|
||||
HttpStatus.OK);
|
||||
}
|
||||
|
||||
public List<DmpImportModel> createDmpFromXml( ApiContext apiContext, MultipartFile[] files, Principal principal) throws IOException, JAXBException, Exception {
|
||||
List<DmpImportModel> dataManagementPlans = new ArrayList<>();
|
||||
// Jaxb approach.
|
||||
JAXBContext jaxbContext;
|
||||
|
||||
for (MultipartFile multipartFile : Arrays.asList(files)){ // Gets one item from the array.
|
||||
try{
|
||||
InputStream in = multipartFile.getInputStream(); // Transforms item to InputStream.
|
||||
jaxbContext = JAXBContext.newInstance(DmpImportModel.class);
|
||||
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
|
||||
DmpImportModel dmpImportModel = (DmpImportModel)jaxbUnmarshaller.unmarshal(in);
|
||||
System.out.println(dmpImportModel.getDmpNameImport());
|
||||
dataManagementPlans.add(dmpImportModel);
|
||||
}
|
||||
catch (IOException | JAXBException ex){
|
||||
ex.printStackTrace();
|
||||
}
|
||||
// TODO Iterate through the list of dataManagmentPlans.
|
||||
// Creates new dataManagmentPlan to fill it with the data model that was parsed from the xml.
|
||||
// Creates properties.
|
||||
DataManagementPlan dm = new DataManagementPlan();
|
||||
Tuple tuple = new Tuple();
|
||||
tuple.setId(dataManagementPlans.get(0).getDmpProfile().getDmpProfileId());
|
||||
tuple.setLabel(dataManagementPlans.get(0).getDmpProfile().getDmpProfileName());
|
||||
eu.eudat.models.data.project.Project project = new eu.eudat.models.data.project.Project();
|
||||
ProjectImportModels projectImport = dataManagementPlans.get(0).getProjectImport();
|
||||
project.setId(projectImport.getId());
|
||||
project.setLabel(projectImport.getLabel());
|
||||
project.setAbbreviation(projectImport.getAbbreviation());
|
||||
project.setDescription(projectImport.getDescription());
|
||||
List<eu.eudat.models.data.dmp.AssociatedProfile> associatedProfiles = new LinkedList<>();
|
||||
for(AssociatedProfileImportModels a : dataManagementPlans.get(0).getProfilesImportModels()) {
|
||||
AssociatedProfile associatedProfile = new AssociatedProfile();
|
||||
associatedProfile.setId(a.getId());
|
||||
associatedProfile.setLabel(a.getLabel());
|
||||
associatedProfiles.add(associatedProfile);
|
||||
}
|
||||
List< eu.eudat.models.data.dmp.Organisation > organisations = new ArrayList<>();
|
||||
List<eu.eudat.models.data.dmp.Researcher> researchers = new LinkedList<>();
|
||||
List<eu.eudat.models.data.userinfo.UserInfo> associatedUsers = new LinkedList<>();
|
||||
List<DynamicFieldWithValue> dynamicFields = new LinkedList<>();
|
||||
|
||||
// Sets properties.
|
||||
dm.setLabel(files[0].getOriginalFilename()); // Sets label.
|
||||
dm.setProject(project); //Sets project property.
|
||||
dm.setDescription(dataManagementPlans.get(0).getDescriptionImport()); // Sets description property.
|
||||
dm.setProfiles(associatedProfiles);
|
||||
dm.setOrganisations(organisations); // Sets organisations property.
|
||||
dm.setResearchers(researchers); // Sets researchers property.
|
||||
dm.setAssociatedUsers(associatedUsers); // Sets associatedUsers property.
|
||||
dm.setDynamicFields(dynamicFields); // Sets dynamicFields property.
|
||||
dm.setProfile(tuple);
|
||||
|
||||
createOrUpdate(apiContext, dm, principal);
|
||||
|
||||
System.out.println(dm);
|
||||
}
|
||||
|
||||
return dataManagementPlans;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package eu.eudat.models.data.dmp;
|
||||
|
||||
import java.util.UUID;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "profile")
|
||||
public class AssociatedProfileImportModels {
|
||||
private UUID id;
|
||||
private String label;
|
||||
|
||||
@XmlElement(name = "profileId")
|
||||
public UUID getId() { return id; }
|
||||
public void setId(UUID id) { this.id = id; }
|
||||
|
||||
@XmlElement(name = "profilelabel")
|
||||
public String getLabel() { return label; }
|
||||
public void setLabel(String label) { this.label = label; }
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package eu.eudat.models.data.dmp;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "dataset")
|
||||
public class DatasetImportModels {
|
||||
|
||||
private String name;
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
package eu.eudat.models.data.dmp;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.util.List;
|
||||
|
||||
@XmlRootElement(name = "dmp")
|
||||
public class DmpImportModel {
|
||||
private String description;
|
||||
private String dmpName;
|
||||
private DmpProfileImportModel profile;
|
||||
private ProjectImportModels projectImportModels;
|
||||
private List<AssociatedProfileImportModels> profilesImportModels;
|
||||
private List<OrganisationImportModel> organisationImportModels;
|
||||
private List<ResearcherImportModels> researchersImportModels;
|
||||
private List<UserInfoImportModels> associatedUsersImportModels;
|
||||
private List<DynamicFieldWithValueImportModels> dynamicFieldsImportModels;
|
||||
private List<DatasetImportModels> datasetImportModels;
|
||||
|
||||
@XmlElement(name = "description")
|
||||
public String getDescriptionImport() {
|
||||
return description;
|
||||
}
|
||||
public void setDescriptionImport(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@XmlElement(name = "dmpName")
|
||||
public String getDmpNameImport() {
|
||||
return dmpName;
|
||||
}
|
||||
public void setDmpNameImport(String dmpName) {
|
||||
this.dmpName = dmpName;
|
||||
}
|
||||
|
||||
@XmlElement(name = "dmpProfile")
|
||||
public DmpProfileImportModel getDmpProfile() { return profile; }
|
||||
public void setDmpProfile(DmpProfileImportModel profile) { this.profile = profile; }
|
||||
|
||||
@XmlElement(name = "project")
|
||||
public ProjectImportModels getProjectImport() {
|
||||
return projectImportModels;
|
||||
}
|
||||
public void setProjectImport(ProjectImportModels projectImportModels) {
|
||||
this.projectImportModels = projectImportModels;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name="organisations")
|
||||
@XmlElement(name = "organisation")
|
||||
public List<OrganisationImportModel> getOrganisationImportModels() {
|
||||
return organisationImportModels;
|
||||
}
|
||||
public void setOrganisationImportModels(List<OrganisationImportModel> organisationImportModels) {
|
||||
this.organisationImportModels = organisationImportModels;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name="profiles")
|
||||
@XmlElement(name = "profile")
|
||||
public List<AssociatedProfileImportModels> getProfilesImportModels() {
|
||||
return profilesImportModels;
|
||||
}
|
||||
public void setProfilesImportModels(List<AssociatedProfileImportModels> profilesImportModels) {
|
||||
this.profilesImportModels = profilesImportModels;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name="researchers")
|
||||
@XmlElement(name = "researcher")
|
||||
public List<ResearcherImportModels> getResearchersImportModels() {
|
||||
return researchersImportModels;
|
||||
}
|
||||
public void setResearchersImportModels(List<ResearcherImportModels> researchersImportModels) {
|
||||
this.researchersImportModels = researchersImportModels;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name="UserInfos")
|
||||
@XmlElement(name = "UserInfo")
|
||||
public List<UserInfoImportModels> getAssociatedUsersImportModels() {
|
||||
return associatedUsersImportModels;
|
||||
}
|
||||
public void setAssociatedUsersImportModels(List<UserInfoImportModels> associatedUsersImportModels) {
|
||||
this.associatedUsersImportModels = associatedUsersImportModels;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name="dynamicFieldWithValues")
|
||||
@XmlElement(name = "dynamicFieldWithValue")
|
||||
public List<DynamicFieldWithValueImportModels> getDynamicFieldsImportModels() {
|
||||
return dynamicFieldsImportModels;
|
||||
}
|
||||
public void setDynamicFieldsImportModels(List<DynamicFieldWithValueImportModels> dynamicFieldsImportModels) {
|
||||
this.dynamicFieldsImportModels = dynamicFieldsImportModels;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name="datasets")
|
||||
@XmlElement(name = "dataset")
|
||||
public List<DatasetImportModels> getDatasetImportModels() { return datasetImportModels; }
|
||||
public void setDatasetImportModels(List<DatasetImportModels> datasetImportModels) { this.datasetImportModels = datasetImportModels; }
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package eu.eudat.models.data.dmp;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.util.UUID;
|
||||
|
||||
@XmlRootElement(name = "dmpProfile")
|
||||
public class DmpProfileImportModel {
|
||||
|
||||
private String dmpProfileName;
|
||||
private UUID dmpProfileId;
|
||||
|
||||
@XmlElement(name = "dmpProfileName")
|
||||
public String getDmpProfileName() { return dmpProfileName; }
|
||||
public void setDmpProfileName(String dmpProfileName) { this.dmpProfileName = dmpProfileName; }
|
||||
|
||||
@XmlElement(name = "dmpProfileId")
|
||||
public UUID getDmpProfileId() { return dmpProfileId; }
|
||||
public void setDmpProfileId(UUID dmpProfileId) { this.dmpProfileId = dmpProfileId; }
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package eu.eudat.models.data.dmp;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "dynamicFieldWithValue")
|
||||
public class DynamicFieldWithValueImportModels {
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package eu.eudat.models.data.dmp;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "organisation")
|
||||
public class OrganisationImportModel {
|
||||
private String source;
|
||||
private String name;
|
||||
private String id;
|
||||
|
||||
@XmlElement(name = "source")
|
||||
public String getOrganaisationSourceImport() {
|
||||
return source;
|
||||
}
|
||||
public void setOrganaisationSourceImport(String source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
@XmlElement(name = "name")
|
||||
public String getOrganaisationNameImport() {
|
||||
return name;
|
||||
}
|
||||
public void setOrganaisationNameImport(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@XmlElement(name = "id")
|
||||
public String getOrganaisationIdImport() {
|
||||
return id;
|
||||
}
|
||||
public void setOrganaisationIdImport(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
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;
|
||||
private String abbreviation;
|
||||
private String description;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public String getAbbreviation() {
|
||||
return abbreviation;
|
||||
}
|
||||
public void setAbbreviation(String abbreviation) {
|
||||
this.abbreviation = abbreviation;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package eu.eudat.models.data.dmp;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "researcher")
|
||||
public class ResearcherImportModels {
|
||||
private String label;
|
||||
private String name;
|
||||
private String id;
|
||||
private int status;
|
||||
|
||||
@XmlElement(name = "label")
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
@XmlElement(name = "name")
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@XmlElement(name = "id")
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@XmlElement(name = "status")
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package eu.eudat.models.data.dmp;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "userInfo")
|
||||
public class UserInfoImportModels {
|
||||
}
|
|
@ -12,6 +12,9 @@ import { DatasetProfileCriteria } from '../../query/dataset-profile/dataset-prof
|
|||
import { DmpCriteria } from '../../query/dmp/dmp-criteria';
|
||||
import { RequestItem } from '../../query/request-item';
|
||||
import { BaseHttpService } from '../http/base-http.service';
|
||||
import { ContentType } from '@angular/http/src/enums';
|
||||
import { BaseHttpParams } from '../../../common/http/base-http-params';
|
||||
import { InterceptorType } from '../../../common/http/interceptors/interceptor-type';
|
||||
|
||||
@Injectable()
|
||||
export class DmpService {
|
||||
|
@ -31,7 +34,6 @@ export class DmpService {
|
|||
else {
|
||||
return this.http.post<DataTableData<DmpListingModel>>(this.actionUrl + 'paged?fieldsGroup=' + fieldsGroup, dataTableRequest, { headers: this.headers });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
getSingle(id: String): Observable<DmpModel> {
|
||||
|
@ -41,6 +43,7 @@ export class DmpService {
|
|||
unlock(id: String): Observable<DmpModel> {
|
||||
return this.http.get<DmpModel>(this.actionUrl + id + '/unlock', { headers: this.headers });
|
||||
}
|
||||
|
||||
createDmp(dataManagementPlanModel: DmpModel): Observable<DmpModel> {
|
||||
return this.http.post<DmpModel>(this.actionUrl, dataManagementPlanModel, { headers: this.headers });
|
||||
}
|
||||
|
@ -83,4 +86,21 @@ export class DmpService {
|
|||
let headerPdf: HttpHeaders = this.headers.set('Content-Type', 'application/pdf')
|
||||
return this.httpClient.get(this.actionUrl + 'getPDF/' + id, { responseType: 'blob', observe: 'response', headers: headerPdf });
|
||||
}
|
||||
|
||||
public uploadXml(fileList: FileList, dmpTitle: string): Observable<ContentType> {
|
||||
const formData: FormData = new FormData();
|
||||
//formData.append('file', fileList[0], dmpTitle);
|
||||
if (fileList instanceof FileList) {
|
||||
for (let i = 0; i < fileList.length; i++) {
|
||||
formData.append('file', fileList[i], dmpTitle);
|
||||
}
|
||||
} else {
|
||||
formData.append('file', fileList);
|
||||
}
|
||||
const params = new BaseHttpParams();
|
||||
params.interceptorContext = {
|
||||
excludedInterceptors: [InterceptorType.JSONContentType]
|
||||
};
|
||||
return this.http.post(this.actionUrl + 'upload', formData, { params: params });
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,23 @@
|
|||
<div class="dmp-criteria">
|
||||
<mat-card class="mat-card">
|
||||
<mat-card-header>
|
||||
<mat-card-header class="row">
|
||||
<mat-card-title>
|
||||
<h4>{{'CRITERIA.FILTERS'| translate}}</h4>
|
||||
</mat-card-title>
|
||||
<div class="col"></div>
|
||||
<button class="uploadButton" mat-raised-button color="primary" (click)="fileSave($event)" type="button col-auto">
|
||||
{{'DMP-UPLOAD.UPLOAD-BUTTON' | translate}}
|
||||
</button>
|
||||
</mat-card-header>
|
||||
<div class="row">
|
||||
<mat-form-field class="col-md-6">
|
||||
<input matInput placeholder="{{'CRITERIA.DMP.LIKE'| translate}}" name="projectCriteriaLike" [formControl]="formGroup.get('like')" (ngModelChange)="controlModified()">
|
||||
<input matInput placeholder="{{'CRITERIA.DMP.LIKE'| translate}}" name="projectCriteriaLike" [formControl]="formGroup.get('like')"
|
||||
(ngModelChange)="controlModified()">
|
||||
<mat-error *ngIf="formGroup.get('like').hasError('backendError')">{{formGroup.get('like').getError('backendError').message}}</mat-error>
|
||||
</mat-form-field>
|
||||
<mat-form-field *ngIf="showProject" class="col-md-6">
|
||||
<app-multiple-auto-complete [formControl]="formGroup.get('projects')" placeholder="{{'CRITERIA.DMP.PROJECTS' | translate}}" [configuration]="projectAutoCompleteConfiguration">
|
||||
<app-multiple-auto-complete [formControl]="formGroup.get('projects')" placeholder="{{'CRITERIA.DMP.PROJECTS' | translate}}"
|
||||
[configuration]="projectAutoCompleteConfiguration">
|
||||
</app-multiple-auto-complete>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
|
|
|
@ -7,4 +7,12 @@
|
|||
mat-card {
|
||||
padding-bottom: 0px;
|
||||
}
|
||||
|
||||
.hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.uploadButton {
|
||||
float: right;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,9 @@ import { MultipleAutoCompleteConfiguration } from '../../../../library/auto-comp
|
|||
import { RequestItem } from '../../../../core/query/request-item';
|
||||
import { BaseCriteriaComponent } from '../../../misc/criteria/base-criteria.component';
|
||||
import { DataTableRequest } from '../../../../core/model/data-table/data-table-request';
|
||||
import { DmpService } from '../../../../core/services/dmp/dmp.service';
|
||||
import { MatDialog } from '@angular/material';
|
||||
import { DmpUploadDialogue } from './upload-dialogue/dmp-upload-dialogue.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-dmp-criteria-component',
|
||||
|
@ -21,6 +24,9 @@ export class DmpCriteriaComponent extends BaseCriteriaComponent implements OnIni
|
|||
|
||||
@Input() showProject: boolean;
|
||||
filteringProjectsAsync = false;
|
||||
sizeError = false;
|
||||
maxFileSize: number = 1048576;
|
||||
|
||||
filteredProjects: ProjectListingModel[];
|
||||
public formGroup = new FormBuilder().group({
|
||||
like: new FormControl(),
|
||||
|
@ -36,7 +42,9 @@ export class DmpCriteriaComponent extends BaseCriteriaComponent implements OnIni
|
|||
constructor(
|
||||
public language: TranslateService,
|
||||
public projectService: ProjectService,
|
||||
public formBuilder: FormBuilder
|
||||
private dmpService: DmpService,
|
||||
public formBuilder: FormBuilder,
|
||||
private dialog: MatDialog
|
||||
) {
|
||||
super(new ValidationErrorModel());
|
||||
}
|
||||
|
@ -79,4 +87,22 @@ export class DmpCriteriaComponent extends BaseCriteriaComponent implements OnIni
|
|||
projectRequestItem.criteria.like = query;
|
||||
return this.projectService.getPaged(projectRequestItem, "autocomplete").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) {
|
||||
console.log(result.fileList[0]);
|
||||
this.dmpService.uploadXml(result.fileList, result.dmpTitle)
|
||||
.pipe(takeUntil(this._destroyed))
|
||||
.subscribe();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
<div class="confirmation-dialog">
|
||||
<div class="confirmation-message">
|
||||
<div class="row">
|
||||
<div class="col-auto">
|
||||
{{'DMP-UPLOAD.TITLE' | translate}}
|
||||
</div>
|
||||
<div class="uploadButton">
|
||||
<button mat-raised-button color="primary" (click)="fileInput.click()" type="button col-auto">
|
||||
{{'DMP-UPLOAD.UPLOAD-BUTTON' | translate}}
|
||||
</button>
|
||||
<input class="hidden" #fileInput type="file" (change)="uploadFile($event)">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<mat-form-field class="col">
|
||||
<input class="uploadInput" [(ngModel)]="dmpTitle" matInput placeholder="DMP Name" name="uploadFileInput">
|
||||
</mat-form-field>
|
||||
<div class="row">
|
||||
<div class="col-auto">
|
||||
<button mat-raised-button color="primary" type="button" (click)="cancel()">{{'DMP-UPLOAD.ACTIONS.CANCEL' | translate}}</button>
|
||||
</div>
|
||||
<div class="col"></div>
|
||||
<div class="col-auto">
|
||||
<button mat-raised-button color="primary" type="button" (click)="confirm()" [disabled]="data.fileList.length === 0">{{'DMP-UPLOAD.ACTIONS.IMPORT' | translate}}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,21 @@
|
|||
.confirmation-dialog {
|
||||
.confirmation-message {
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
|
||||
.hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.uploadButton {
|
||||
float: right;
|
||||
}
|
||||
|
||||
.col-md-6 {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
margin: -4px;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
import { Component, Inject } from '@angular/core';
|
||||
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
|
||||
import { DmpService } from '../../../../../core/services/dmp/dmp.service';
|
||||
|
||||
@Component({
|
||||
selector: 'dmp-upload-dialogue',
|
||||
templateUrl: './dmp-upload-dialogue.component.html',
|
||||
styleUrls: ['./dmp-upload-dialogue.component.scss']
|
||||
})
|
||||
export class DmpUploadDialogue {
|
||||
dmpTitle: string;
|
||||
|
||||
|
||||
constructor(
|
||||
public dialogRef: MatDialogRef<DmpUploadDialogue>,
|
||||
@Inject(MAT_DIALOG_DATA) public data: any,
|
||||
) {}
|
||||
|
||||
cancel() {
|
||||
this.data.success = false;
|
||||
this.dialogRef.close(this.data);
|
||||
}
|
||||
|
||||
confirm() {
|
||||
this.data.success = true;
|
||||
this.data.dmpTitle = this.dmpTitle;
|
||||
this.dialogRef.close(this.data);
|
||||
}
|
||||
|
||||
uploadFile(event) {
|
||||
const fileList: FileList = event.target.files
|
||||
this.data.fileList = fileList;
|
||||
if (this.data.fileList.length > 0) {
|
||||
this.dmpTitle = fileList.item(0).name;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue