Adds Dataset import functionality (Ticket #70)

This commit is contained in:
gkolokythas 2019-04-15 12:34:12 +03:00
parent 92b027280d
commit c577d6f53b
26 changed files with 1029 additions and 22 deletions

View File

@ -27,9 +27,11 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.activation.MimetypesFileTypeMap;
import javax.transaction.Transactional;
import javax.xml.bind.JAXBException;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@ -87,7 +89,7 @@ public class DatasetWizardController extends BaseController {
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentLength(file.length());
responseHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
responseHeaders.set("Content-Disposition", "attachment;filename=" + file.getName() + ".docx");
responseHeaders.set("Content-Disposition", "attachment;filename=" + file.getName());
responseHeaders.set("Access-Control-Expose-Headers", "Content-Disposition");
responseHeaders.get("Access-Control-Expose-Headers").add("Content-Type");
byte[] content = IOUtils.toByteArray(resource);
@ -176,4 +178,20 @@ public class DatasetWizardController extends BaseController {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<Dataset>().status(ApiMessageCode.ERROR_MESSAGE).message(datasetWizardCannotUnlockException.getMessage()));
}
}
@RequestMapping(method = RequestMethod.POST, value = {"/upload"})
public ResponseEntity<ResponseItem> datasetXmlImport(@RequestParam("file") MultipartFile file, @RequestParam("dmpId") String dmpId, @RequestParam("datasetProfileId") String datasetProfileId, Principal principal) {
try {
Dataset dataset = this.datasetManager.createDatasetFromXml(file, dmpId, datasetProfileId, principal);
if (dataset != null){
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE));
}
else {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).message("Import was unsuccessful."));
}
} catch (Exception e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).message("Import was unsuccessful."));
}
}
}

View File

@ -20,10 +20,12 @@ import eu.eudat.logic.utilities.documents.types.ParagraphStyle;
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.datasetImport.*;
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
import eu.eudat.models.data.helpers.common.DataTableData;
import eu.eudat.models.data.listingmodels.DatasetListingModel;
import eu.eudat.models.data.security.Principal;
import eu.eudat.models.data.user.composite.DatasetProfilePage;
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
import eu.eudat.queryable.QueryableList;
import org.apache.commons.io.IOUtils;
@ -41,6 +43,12 @@ import org.springframework.util.LinkedMultiValueMap;
import org.springframework.web.client.RestTemplate;
import javax.activation.MimetypesFileTypeMap;
import javax.mail.Multipart;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.math.BigInteger;
import java.net.URL;
@ -228,7 +236,7 @@ public class DatasetManager {
PagedDatasetProfile pagedDatasetProfile = getPagedProfile(dataset, datasetEntity);
visibilityRuleService.setProperties(properties);
visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules());
File file = xmlBuilder.build(pagedDatasetProfile, visibilityRuleService);
File file = xmlBuilder.build(pagedDatasetProfile, datasetEntity.getProfile().getId(), visibilityRuleService);
FileEnvelope fileEnvelope = new FileEnvelope();
fileEnvelope.setFile(file);
fileEnvelope.setFilename(datasetEntity.getLabel());
@ -415,4 +423,77 @@ public class DatasetManager {
HttpStatus.OK);
}
public eu.eudat.data.entities.Dataset createDatasetFromXml(MultipartFile importFile, String dmpId, String datasetProfileId, Principal principal) throws JAXBException, IOException {
DatasetImportPagedDatasetProfile importModel = new DatasetImportPagedDatasetProfile();
JAXBContext jaxbContext;
// Parses XML into DatasetImport Model.
try {
InputStream in = importFile.getInputStream();
jaxbContext = JAXBContext.newInstance(DatasetImportPagedDatasetProfile.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
DatasetImportPagedDatasetProfile datasetImport = (DatasetImportPagedDatasetProfile)jaxbUnmarshaller.unmarshal(in);
importModel = datasetImport;
} catch (IOException e) {
e.printStackTrace();
}
// Checks if XML datasetProfileId GroupId matches the one selected.
try {
eu.eudat.data.entities.DatasetProfile importDatasetProfile = databaseRepository.getDatasetProfileDao().find(UUID.fromString(importModel.getDatasetProfileId()));
eu.eudat.data.entities.DatasetProfile latestVersionDatasetProfile = databaseRepository.getDatasetProfileDao().find(UUID.fromString(datasetProfileId));
if (latestVersionDatasetProfile.getGroupId() != importDatasetProfile.getGroupId()) {
throw new Exception();
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
// Creates the Hash Map to place the values of the data set.
Map<String, String> importMap = importModel.getPages().stream()
.flatMap(s -> s.getSections().getSection().stream()
.flatMap(cFields -> cFields.getCompositeFields().stream()
.flatMap(cField -> cField.getCompositeField().stream()
.filter(Objects::nonNull)
.flatMap(fields -> fields.getFields().stream()
.flatMap(field -> field.getField().stream()
.filter(f -> f.getValue() != null)
)))))
.collect(Collectors.toMap(DatasetImportField::getId, DatasetImportField::getValue));
// Transforms map into json file.
JSONObject jsonDatasetProperties = new JSONObject(importMap);
// Creates the entity data set to save.
eu.eudat.data.entities.Dataset entity = new Dataset();
entity.setProperties(jsonDatasetProperties.toString());
entity.setLabel(importFile.getOriginalFilename());
DMP dmp = new DMP();
dmp.setId(UUID.fromString(dmpId));
entity.setDmp(dmp);
entity.setStatus((short) 0);
entity.setPublic(false);
entity.setCreated(new Date());
entity.setModified(new Date());
DatasetProfile profile = new DatasetProfile();
profile.setId(UUID.fromString(datasetProfileId));
entity.setProfile(profile);
UserInfo userInfo = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
entity.setCreator(userInfo);
updateTagsXmlImportDataset(apiContext.getOperationsContext().getDatasetRepository(), entity);
createRegistriesIfTheyDontExist(apiContext.getOperationsContext().getDatabaseRepository().getRegistryDao(), entity);
createDataRepositoriesIfTheyDontExist(apiContext.getOperationsContext().getDatabaseRepository().getDataRepositoryDao(), entity);
createServicesIfTheyDontExist(entity);
createExternalDatasetsIfTheyDontExist(entity);
return apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(entity);
}
public void updateTagsXmlImportDataset(DatasetRepository datasetRepository, Dataset dataset) throws IOException {
// TODO: When tags functionality return.
}
}

View File

@ -22,12 +22,15 @@ import java.util.UUID;
*/
public class ExportXmlBuilder {
public File build(PagedDatasetProfile pagedDatasetProfile, VisibilityRuleService visibilityRuleService) throws IOException {
public File build(PagedDatasetProfile pagedDatasetProfile, UUID datasetProfileId, VisibilityRuleService visibilityRuleService) 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 datasetProfile = xmlDoc.createElement("datasetProfileId");
datasetProfile.setTextContent(datasetProfileId.toString());
root.appendChild(datasetProfile);
root.appendChild(createPages(pagedDatasetProfile.getPages(), visibilityRuleService, xmlDoc));
xmlDoc.appendChild(root);
String xml = XmlBuilder.generateXml(xmlDoc);
@ -51,13 +54,9 @@ public class ExportXmlBuilder {
sections.forEach(section -> {
Element elementSection = element.createElement("section");
if (visibilityRuleService.isElementVisible(section.getId())) {
Element elementInnerSections = element.createElement("sections");
Element compositeFields = element.createElement("composite-field");
elementInnerSections.appendChild(createSections(section.getSections(), visibilityRuleService, element));
compositeFields.appendChild(createCompositeFields(section.getCompositeFields(), visibilityRuleService, element));
elementSection.appendChild(elementInnerSections);
elementSection.appendChild(createSections(section.getSections(), visibilityRuleService, element));
elementSection.appendChild(createCompositeFields(section.getCompositeFields(), visibilityRuleService, element));
elementSections.appendChild(elementSection);
elementSections.appendChild(compositeFields);
}
});
return elementSections;
@ -94,7 +93,9 @@ public class ExportXmlBuilder {
Element elementField = element.createElement("field");
elementField.setAttribute("id", field.getId());
if (field.getValue() != null && !field.getValue().isEmpty()) {
elementField.setTextContent(field.getValue());
Element valueField = element.createElement("value");
valueField.setTextContent(field.getValue());
elementField.appendChild(valueField);
}
elementFields.appendChild(elementField);
}

View File

@ -0,0 +1,20 @@
package eu.eudat.models.data.datasetImport;
public class DatasetImportDefaultValue {
private String type;
private String value;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}

View File

@ -0,0 +1,124 @@
package eu.eudat.models.data.datasetImport;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;
import java.util.List;
import java.util.stream.Collectors;
@XmlRootElement(name = "field")
public class DatasetImportField implements Comparable{
private String id;
private Integer ordinal;
private String value;
private DatasetImportViewStyle viewStyle;
private String datatype;
private String numbering;
private int page;
private DatasetImportDefaultValue defaultValue;
private DatasetImportMultiplicity multiplicity;
private Object data;
private List<DatasetImportFields> multiplicityItems;
private List<eu.eudat.models.data.admin.components.datasetprofile.Field.ValidationType> validations;
private DatasetImportVisibility visible;
public List<DatasetImportFields> getMultiplicityItems() {
return multiplicityItems;
}
public void setMultiplicityItems(List<DatasetImportFields> multiplicityItems) {
this.multiplicityItems = multiplicityItems;
}
@XmlAttribute(name = "id")
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public int getOrdinal() {
return ordinal;
}
public void setOrdinal(Integer ordinal) {
this.ordinal = ordinal;
}
@XmlElement(name = "value")
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public DatasetImportViewStyle getViewStyle() {
return viewStyle;
}
public void setViewStyle(DatasetImportViewStyle viewStyle) {
this.viewStyle = viewStyle;
}
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
public DatasetImportDefaultValue getDefaultValue() {
return defaultValue;
}
public void setDefaultValue(DatasetImportDefaultValue defaultValue) {
this.defaultValue = defaultValue;
}
public String getDatatype() {
return datatype;
}
public void setDatatype(String datatype) {
this.datatype = datatype;
}
public DatasetImportMultiplicity getMultiplicity() {
return multiplicity;
}
public void setMultiplicity(DatasetImportMultiplicity multiplicity) {
this.multiplicity = multiplicity;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
public DatasetImportVisibility getVisible() {
return visible;
}
public void setVisible(DatasetImportVisibility visible) {
this.visible = visible;
}
public List<Integer> getValidations() {
return this.validations.stream().map(item -> (int) item.getValue()).collect(Collectors.toList());
}
public void setValidations(List<Integer> validations) {
this.validations = eu.eudat.models.data.admin.components.datasetprofile.Field.ValidationType.fromIntegers(validations);
}
public String getNumbering() {
return numbering;
}
public void setNumbering(String numbering) {
this.numbering = numbering;
}
@Override
public int compareTo(Object o) {
return this.ordinal.compareTo(((DatasetImportField) o).getOrdinal());
}
}

View File

@ -0,0 +1,120 @@
package eu.eudat.models.data.datasetImport;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Collections;
import java.util.List;
@XmlRootElement(name = "composite-field")
public class DatasetImportFieldSet implements Comparable{
//@XmlAttribute(name = "id")
private String id;
private Integer ordinal;
private String title;
private String numbering;
private String description;
private String extendedDescription;
private String additionalInformation;
private DatasetImportMultiplicity multiplicity;
private List<DatasetImportFields> fields;
private List<DatasetImportFieldSets> compositeFields;
private boolean hasCommentField;
private String commentFieldValue;
@XmlElement(name = "fields")
public List<DatasetImportFields> getFields() {
//Collections.sort(this.fields);
return fields;
}
public void setFields(List<DatasetImportFields> fields) {
this.fields = fields;
}
@XmlElement(name = "title")
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
@XmlElement(name = "description")
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getExtendedDescription() { return extendedDescription; }
public void setExtendedDescription(String extendedDescription) {
this.extendedDescription = extendedDescription;
}
@XmlAttribute(name = "id")
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public int getOrdinal() {
return ordinal;
}
public void setOrdinal(Integer ordinal) {
this.ordinal = ordinal;
}
public DatasetImportMultiplicity getMultiplicity() {
return multiplicity;
}
public void setMultiplicity(DatasetImportMultiplicity multiplicity) {
this.multiplicity = multiplicity;
}
@XmlElement(name = "composite-fields")
public List<DatasetImportFieldSets> getcompositeFields() {
//if (compositeFields != null) Collections.sort(compositeFields);
return compositeFields;
}
public void setcompositeFields(List<DatasetImportFieldSets> compositeFields) {
this.compositeFields = compositeFields;
}
public String getNumbering() {
return numbering;
}
public void setNumbering(String numbering) {
this.numbering = numbering;
}
public void setHasCommentField(boolean hasCommentField) {
this.hasCommentField = hasCommentField;
}
public boolean getHasCommentField() {
return hasCommentField;
}
public String getCommentFieldValue() {
return commentFieldValue;
}
public void setCommentFieldValue(String commentFieldValue) {
this.commentFieldValue = commentFieldValue;
}
public String getAdditionalInformation() {
return additionalInformation;
}
public void setAdditionalInformation(String additionalInformation) {
this.additionalInformation = additionalInformation;
}
@Override
public int compareTo(Object o) {
return this.ordinal.compareTo(((DatasetImportFieldSet) o).getOrdinal());
}
}

View File

@ -0,0 +1,25 @@
package eu.eudat.models.data.datasetImport;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Collections;
import java.util.List;
@XmlRootElement(name = "composite-fields")
public class DatasetImportFieldSets implements Comparable {
private List<DatasetImportFieldSet> compositeField;
@XmlElement(name = "composite-field")
public List<DatasetImportFieldSet> getCompositeField() {
//Collections.sort(this.compositeField);
return compositeField;
}
public void setCompositeField(List<DatasetImportFieldSet> compositeField) {
this.compositeField = compositeField;
}
@Override
public int compareTo(Object o) {
return 0;
}
}

View File

@ -0,0 +1,22 @@
package eu.eudat.models.data.datasetImport;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.List;
@XmlRootElement(name = "fields")
public class DatasetImportFields implements Comparable{
private List<DatasetImportField> field;
@XmlElement(name = "field")
public List<DatasetImportField> getField() {
return field;
}
public void setField(List<DatasetImportField> field) {
this.field = field;
}
@Override
public int compareTo(Object o) { return 0; }
}

View File

@ -0,0 +1,20 @@
package eu.eudat.models.data.datasetImport;
public class DatasetImportMultiplicity {
private int min;
private int max;
public int getMin() {
return min;
}
public void setMin(int min) {
this.min = min;
}
public int getMax() {
return max;
}
public void setMax(int max) {
this.max = max;
}
}

View File

@ -0,0 +1,35 @@
package eu.eudat.models.data.datasetImport;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.List;
@XmlRootElement(name = "page")
public class DatasetImportPage {
private Integer ordinal;
private String title;
private DatasetImportSections sections;
public Integer getOrdinal() {
return ordinal;
}
public void setOrdinal(Integer ordinal) {
this.ordinal = ordinal;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
@XmlElement(name = "sections")
public DatasetImportSections getSections() {
return sections;
}
public void setSections(DatasetImportSections sections) {
this.sections = sections;
}
}

View File

@ -0,0 +1,33 @@
package eu.eudat.models.data.datasetImport;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.List;
@XmlRootElement(name = "root")
public class DatasetImportPagedDatasetProfile {
private String datasetProfileId;
private List<DatasetImportPage> pages;
private List<DatasetImportRule> rules;
private int status;
@XmlElement(name = "datasetProfileId")
public String getDatasetProfileId() {
return datasetProfileId;
}
public void setDatasetProfileId(String datasetProfileId) {
this.datasetProfileId = datasetProfileId;
}
@XmlElementWrapper(name="pages")
@XmlElement(name = "page")
public List<DatasetImportPage> getPages() { return pages; }
public void setPages(List<DatasetImportPage> pages) { this.pages = pages; }
public List<DatasetImportRule> getRules() { return rules; }
public void setRules(List<DatasetImportRule> rules) { this.rules = rules; }
public int getStatus() { return status; }
public void setStatus(int status) { this.status = status; }
}

View File

@ -0,0 +1,44 @@
package eu.eudat.models.data.datasetImport;
public class DatasetImportRule {
private String ruleType;
private String target;
private String ruleStyle;
private String value;
private String valueType;
public String getRuleType() {
return ruleType;
}
public void setRuleType(String ruleType) {
this.ruleType = ruleType;
}
public String getTarget() {
return target;
}
public void setTarget(String target) {
this.target = target;
}
public String getRuleStyle() {
return ruleStyle;
}
public void setRuleStyle(String ruleStyle) {
this.ruleStyle = ruleStyle;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getValueType() {
return valueType;
}
public void setValueType(String valueType) {
this.valueType = valueType;
}
}

View File

@ -0,0 +1,92 @@
package eu.eudat.models.data.datasetImport;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Collections;
import java.util.List;
@XmlRootElement(name = "section")
public class DatasetImportSection implements Comparable{
private List<DatasetImportSections> sections;
private List<DatasetImportFieldSets> compositeFields;
private Boolean defaultVisibility;
private String numbering;
private String page;
private Integer ordinal;
private String id;
private String title;
private String description;
@XmlElement(name = "sections")
public List<DatasetImportSections> getSections() {
//Collections.sort(sections);
return sections;
}
public void setSections(List<DatasetImportSections> sections) {
this.sections = sections;
}
//@XmlElementWrapper(name="composite-field")
@XmlElement(name = "composite-fields")
public List<DatasetImportFieldSets> getCompositeFields() {
//Collections.sort(compositeFields);
return compositeFields;
}
public void setCompositeFields(List<DatasetImportFieldSets> compositeFields) {
this.compositeFields = compositeFields;
}
public Boolean getDefaultVisibility() {
return defaultVisibility;
}
public void setDefaultVisibility(Boolean defaultVisibility) {
this.defaultVisibility = defaultVisibility;
}
public String getPage() {
return page;
}
public void setPage(String page) {
this.page = page;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public int getOrdinal() {
return ordinal;
}
public void setOrdinal(int ordinal) {
this.ordinal = ordinal;
}
public String getNumbering() {
return numbering;
}
public void setNumbering(String numbering) {
this.numbering = numbering;
}
@Override
public int compareTo(Object o) {
return this.ordinal.compareTo(((DatasetImportSection) o).getOrdinal()); }
}

View File

@ -0,0 +1,19 @@
package eu.eudat.models.data.datasetImport;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Collections;
import java.util.List;
@XmlRootElement(name = "sections")
public class DatasetImportSections{
private List<DatasetImportSection> section;
@XmlElement(name = "section")
public List<DatasetImportSection> getSection() {
return section;
}
public void setSection(List<DatasetImportSection> section) {
this.section = section;
}
}

View File

@ -0,0 +1,20 @@
package eu.eudat.models.data.datasetImport;
public class DatasetImportViewStyle {
private String renderStyle;
private String cssClass;
public String getRenderStyle() {
return renderStyle;
}
public void setRenderStyle(String renderStyle) {
this.renderStyle = renderStyle;
}
public String getCssClass() {
return cssClass;
}
public void setCssClass(String cssClass) {
this.cssClass = cssClass;
}
}

View File

@ -0,0 +1,22 @@
package eu.eudat.models.data.datasetImport;
import java.util.List;
public class DatasetImportVisibility {
private List<DatasetImportRule> rules;
private String style;
public List<DatasetImportRule> getRules() {
return rules;
}
public void setRules(List<DatasetImportRule> rules) {
this.rules = rules;
}
public String getStyle() {
return style;
}
public void setStyle(String style) {
this.style = style;
}
}

View File

@ -10,6 +10,9 @@ import { DmpModel } from '../../model/dmp/dmp';
import { DatasetProfileCriteria } from '../../query/dataset-profile/dataset-profile-criteria';
import { DmpCriteria } from '../../query/dmp/dmp-criteria';
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 DatasetWizardService {
@ -66,4 +69,23 @@ export class DatasetWizardService {
unlock(id: String): Observable<DatasetWizardModel> {
return this.http.get<DatasetWizardModel>(this.actionUrl + id + '/unlock', { headers: this.headers });
}
public uploadXml(fileList: FileList, datasetTitle: string, dmpId: string, datasetProfileId: string): Observable<ContentType> {
const formData: FormData = new FormData();
if (fileList instanceof FileList) {
for (let i = 0; i < fileList.length; i++) {
formData.append('file', fileList[i], datasetTitle);
}
} else {
formData.append('file', fileList);
}
formData.append('dmpId', dmpId);
formData.append('datasetProfileId', datasetProfileId);
const params = new BaseHttpParams();
params.interceptorContext = {
excludedInterceptors: [InterceptorType.JSONContentType]
};
return this.http.post(this.actionUrl + 'upload', formData, { params: params });
}
}

View File

@ -17,6 +17,7 @@ import { DatasetRoutingModule } from './dataset.routing';
import { DatasetCriteriaComponent } from './listing/criteria/dataset-criteria.component';
import { DatasetListingComponent } from './listing/dataset-listing.component';
import { DatasetCopyDialogueComponent } from './dataset-wizard/dataset-copy-dialogue/dataset-copy-dialogue.component';
import { DatasetUploadDialogue } from './listing/criteria/dataset-upload-dialogue/dataset-upload-dialogue.component';
@NgModule({
imports: [
@ -39,14 +40,16 @@ import { DatasetCopyDialogueComponent } from './dataset-wizard/dataset-copy-dial
DatasetExternalDatasetDialogEditorComponent,
DatasetExternalRegistryDialogEditorComponent,
DatasetExternalServiceDialogEditorComponent,
DatasetCopyDialogueComponent
DatasetCopyDialogueComponent,
DatasetUploadDialogue
],
entryComponents: [
DatasetExternalDataRepositoryDialogEditorComponent,
DatasetExternalDatasetDialogEditorComponent,
DatasetExternalRegistryDialogEditorComponent,
DatasetExternalServiceDialogEditorComponent,
DatasetCopyDialogueComponent
DatasetCopyDialogueComponent,
DatasetUploadDialogue
]
})
export class DatasetModule { }

View File

@ -4,6 +4,10 @@
<mat-card-title>
<h4>{{'CRITERIA.FILTERS'| translate}}</h4>
</mat-card-title>
<div class="col"></div>
<button class="importButton" mat-raised-button color="primary" (click)="fileImport($event)" type="button col-auto">
{{'DATASET-UPLOAD.ACTIONS.IMPORT' | translate}}
</button>
</mat-card-header>
<div class="row">
<mat-form-field class="col-md-3">

View File

@ -15,6 +15,15 @@ import { DataTableRequest } from '../../../../core/model/data-table/data-table-r
import { DataTableData } from '../../../../core/model/data-table/data-table-data';
import { DmpListingModel } from '../../../../core/model/dmp/dmp-listing';
import { Input } from '@angular/core';
import { MatDialog, MatSnackBar } from '@angular/material';
import { DatasetUploadDialogue } from './dataset-upload-dialogue/dataset-upload-dialogue.component';
import { takeUntil } from 'rxjs/operators';
import { reserveSlots } from '@angular/core/src/render3/instructions';
import { DatasetWizardService } from '../../../../core/services/dataset-wizard/dataset-wizard.service';
import { ViewChild } from '@angular/core';
import { UiNotificationService, SnackBarNotificationLevel } from '../../../../core/services/notification/ui-notification-service';
import { Router } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
@Component({
selector: 'app-dataset-criteria-component',
@ -46,7 +55,13 @@ export class DatasetCriteriaComponent extends BaseCriteriaComponent implements O
constructor(
private externalSourcesService: ExternalSourcesService,
public enumUtils: EnumUtils,
public dmpService: DmpService
public dmpService: DmpService,
public datasetWizardService: DatasetWizardService,
private dialog: MatDialog,
private snackBar: MatSnackBar,
private uiNotificationService: UiNotificationService,
private router: Router,
private language: TranslateService,
) {
super(new ValidationErrorModel());
}
@ -60,10 +75,6 @@ export class DatasetCriteriaComponent extends BaseCriteriaComponent implements O
this.criteria = criteria;
}
onCallbackError(error: any) {
this.setErrorModel(error.error);
}
controlModified(): void {
this.clearErrorModel();
if (this.refreshCallback != null &&
@ -92,4 +103,38 @@ export class DatasetCriteriaComponent extends BaseCriteriaComponent implements O
dmpDataTableRequest.criteria.like = value;
return this.dmpService.getPaged(dmpDataTableRequest, "autocomplete");
}
fileImport(event) {
const dialogRef = this.dialog.open(DatasetUploadDialogue, {
data: {
fileList: FileList,
success: Boolean,
datasetTitle: String,
dmpId: String,
datasetProfileId: String,
dmpSearchEnabled: this.dmpSearchEnabled,
criteria: this.criteria
}
});
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
if (result && result.success) {
this.datasetWizardService.uploadXml(result.fileList, result.datasetTitle, result.dmpId, result.datasetProfileId)
.pipe(takeUntil(this._destroyed))
.subscribe(
complete => this.onCallbackSuccess(),
error => this.onCallbackError(error)
);
}
})
}
onCallbackSuccess(): void {
this.uiNotificationService.snackBarNotification(this.language.instant('DATASET-UPLOAD.SNACK-BAR.SUCCESSFUL-CREATION'), SnackBarNotificationLevel.Success);
this.router.navigate(['/plans']);
}
onCallbackError(error: any) {
this.uiNotificationService.snackBarNotification(this.language.instant('DATASET-UPLOAD.SNACK-BAR.UNSUCCESSFUL'), SnackBarNotificationLevel.Success);
}
}

View File

@ -0,0 +1,42 @@
<div class="confirmation-dialog">
<div class="row">
<div class="confirmation-message col align-self-center">
<h4>{{'DATASET-UPLOAD.TITLE' | translate}}</h4>
</div>
<div class="col-auto">
<button mat-icon-button class="col-auto" (click)="fileInput.click()" type="button">
<mat-icon color="primary">attach_file</mat-icon>
</button>
<input class="hidden" #fileInput type="file" (change)="uploadFile($event)" accept="text/xml">
</div>
</div>
<div class="row">
<mat-form-field class="col-12">
<input class="uploadInput" [(ngModel)]="datasetTitle" [disabled]="disableDatasetName()" matInput placeholder="{{'DATASET-UPLOAD.PLACEHOLDER' | translate}}"
name="uploadFileInput">
</mat-form-field>
<mat-form-field class="col-12">
<app-single-auto-complete [required]="true" [(ngModel)]="dmp" (ngModelChange)="controlModified()" placeholder="{{'CRITERIA.DMP.LIKE' | translate}}"
[configuration]="dmpAutoCompleteConfiguration" [disabled]="disableDmpSearch()">
</app-single-auto-complete>
</mat-form-field>
<mat-form-field class="col-md-12">
<mat-select placeholder=" {{'DATASET-UPLOAD.DATASET-PROFILE.SELECT'| translate}}" [required]="true" [(value)]="datasetProfile"
[disabled]="disableDatasetProfile()">
<mat-option *ngFor="let datasetProfile of availableProfiles" [value]="datasetProfile">
{{datasetProfile.label}}
</mat-option>
</mat-select>
</mat-form-field>
<div class="col-auto">
<button mat-raised-button color="primary" type="button" (click)="cancel()">{{'DATASET-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]="disableButton()">{{'DATASET-UPLOAD.ACTIONS.IMPORT' | translate}}</button>
</div>
</div>
</div>

View File

@ -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;
}
}

View File

@ -0,0 +1,157 @@
import { Component, Inject, OnInit } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
import { Observable } from 'rxjs';
import { DataTableData } from '../../../../../core/model/data-table/data-table-data';
import { DmpListingModel } from '../../../../../core/model/dmp/dmp-listing';
import { DataTableRequest } from '../../../../../core/model/data-table/data-table-request';
import { DmpCriteria } from '../../../../../core/query/dmp/dmp-criteria';
import { DmpService } from '../../../../../core/services/dmp/dmp.service';
import { ValidationErrorModel } from '../../../../../common/forms/validation/error-model/validation-error-model';
import { BaseCriteriaComponent } from '../../../../misc/criteria/base-criteria.component';
import { DmpModel } from '../../../../../core/model/dmp/dmp';
import { DatasetProfileModel } from '../../../../../core/model/dataset/dataset-profile';
import { takeUntil } from 'rxjs/operators';
import { DatasetWizardService } from '../../../../../core/services/dataset-wizard/dataset-wizard.service';
import { RequestItem } from '../../../../../core/query/request-item';
import { DatasetProfileCriteria } from '../../../../../core/query/dataset-profile/dataset-profile-criteria';
import { DatasetCriteria } from '../../../../../core/query/dataset/dataset-criteria';
import { DatasetCriteriaComponent } from '../dataset-criteria.component';
@Component({
selector: 'dataset-upload-dialogue',
templateUrl: './dataset-upload-dialogue.component.html',
styleUrls: ['./dataset-upload-dialogue.component.scss']
})
export class DatasetUploadDialogue extends BaseCriteriaComponent implements OnInit {
public dialogueCriteria: any;
datasetTitle: string;
dmp: DmpModel;
datasetProfile: DatasetProfileModel;
availableProfiles: DatasetProfileModel[] = [];
dmpAutoCompleteConfiguration = {
filterFn: (x, excluded) => this.filterDmps(x).map(x => x.data),
initialItems: (extraData) => this.filterDmps('').map(x => x.data),
displayFn: (item) => item['label'],
titleFn: (item) => item['label']
};
constructor(
public dialogRef: MatDialogRef<DatasetUploadDialogue>,
public dmpService: DmpService,
private datasetWizardService: DatasetWizardService,
@Inject(MAT_DIALOG_DATA) public data: any,
) { super(new ValidationErrorModel()); }
ngOnInit() {
super.ngOnInit();
if (this.dialogueCriteria == null) { this.dialogueCriteria = {}; }
if (!this.data.dmpSearchEnabled) {
this.dialogueCriteria = this.data.criteria;
this.dmp = this.dialogueCriteria.dmpIds[0];
this.loadDatasetProfiles();
}
}
cancel() {
this.data.success = false;
this.dialogRef.close(this.data)
}
confirm() {
this.data.success = true;
this.data.datasetTitle = this.datasetTitle;
this.data.dmpId = this.dmp.id;
this.data.datasetProfileId = this.datasetProfile.id;
this.dialogRef.close(this.data);
}
uploadFile(event) {
const fileList: FileList = event.target.files
this.data.fileList = fileList;
if (this.data.fileList.length > 0) {
this.datasetTitle = fileList.item(0).name;
}
}
filterDmps(value: string): Observable<DataTableData<DmpListingModel>> {
const fields: Array<string> = new Array<string>();
fields.push('asc');
const dmpDataTableRequest: DataTableRequest<DmpCriteria> = new DataTableRequest(0, null, { fields: fields });
dmpDataTableRequest.criteria = new DmpCriteria();
dmpDataTableRequest.criteria.like = value;
return this.dmpService.getPaged(dmpDataTableRequest, "autocomplete");
}
controlModified(): void {
this.loadDatasetProfiles();
if (!this.dmp) {
this.availableProfiles = [];
}
this.clearErrorModel();
if (this.refreshCallback != null &&
(this.dialogueCriteria.like == null || this.dialogueCriteria.like.length === 0 || this.dialogueCriteria.like.length > 2)
) {
this.refreshCallback();
}
}
loadDatasetProfiles() {
const datasetProfileRequestItem: RequestItem<DatasetProfileCriteria> = new RequestItem();
datasetProfileRequestItem.criteria = new DatasetProfileCriteria();
if (this.dmp) {
datasetProfileRequestItem.criteria.id = this.dmp.id;
}
if (datasetProfileRequestItem.criteria.id) {
this.datasetWizardService.getAvailableProfiles(datasetProfileRequestItem)
.pipe(takeUntil(this._destroyed))
.subscribe(items => {
this.availableProfiles = items;
if (this.availableProfiles.length === 1) {
this.datasetProfile = this.availableProfiles[0];
}
});
}
}
setCriteriaDialogue(criteria: DatasetCriteria): void {
this.dialogueCriteria = criteria;
}
disableButton() {
if (!(this.data.fileList.length > 0) || !this.dmp) {
return true;
}
else {
return false;
}
}
disableDatasetName() {
if (!(this.data.fileList.length > 0)) {
return true;
}
else {
return false;
}
}
disableDmpSearch() {
if (!(this.data.fileList.length > 0) || !this.data.dmpSearchEnabled) {
return true;
}
else {
return false;
}
}
disableDatasetProfile() {
if (!this.dmp || (!this.data.dmpSearchEnabled && !(this.data.fileList.length > 0)) || (!this.data.dmpSearchEnabled && this.availableProfiles.length === 1)) {
return true;
}
else {
return false;
}
}
}

View File

@ -79,10 +79,10 @@ export class DatasetListingComponent extends BaseComponent implements OnInit, IB
this.router.navigate(['/datasets/edit/' + rowId]);
}
getDefaultCriteria(dmpId: any = null): DatasetCriteria {
getDefaultCriteria(dmp: any = null): DatasetCriteria {
const defaultCriteria = new DatasetCriteria();
if (dmpId != null) {
defaultCriteria.dmpIds.push(dmpId);
if (dmp != null) {
defaultCriteria.dmpIds.push(dmp);
}
return defaultCriteria;
}

View File

@ -12,7 +12,7 @@
</div>
<div class="row">
<mat-form-field class="col-12">
<input class="uploadInput" [(ngModel)]="dmpTitle" matInput placeholder="DMP Name" name="uploadFileInput">
<input class="uploadInput" [(ngModel)]="dmpTitle" matInput placeholder="{{'DMP-UPLOADPLACEHOLDER' | translate}}" name="uploadFileInput">
</mat-form-field>
<div class="col-auto">
<button mat-raised-button color="primary" type="button" (click)="cancel()">{{'DMP-UPLOAD.ACTIONS.CANCEL' | translate}}</button>

View File

@ -224,7 +224,8 @@
"ACTIONS": {
"IMPORT": "Import",
"CANCEL": "Cancel"
}
},
"PLACEHOLDER": "DMP title"
},
"DATASET-WIZARD": {
"TITLE": {
@ -327,6 +328,22 @@
"VIEW-VERSIONS": "All Dataset Versions"
}
},
"DATASET-UPLOAD": {
"TITLE": "Import Dataset",
"UPLOAD-BUTTON": "Upload",
"ACTIONS": {
"IMPORT": "Import",
"CANCEL": "Cancel"
},
"PLACEHOLDER": "Dataset title",
"DATASET-PROFILE": {
"SELECT": "Select Dataset Profile"
},
"SNACK-BAR": {
"SUCCESSFUL-CREATION" : "Imported Successfully",
"UNSUCCESSFUL" : "Something went wrong"
}
},
"DMP-PROFILE-EDITOR": {
"TITLE": {
"NEW": "New DMP Profile",