Allow to set default dataset template when importing RDA json files
This commit is contained in:
parent
5b0a66ce06
commit
7c327949dd
|
@ -235,9 +235,9 @@ public class DMPs extends BaseController {
|
|||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = {"/upload"})
|
||||
public ResponseEntity<ResponseItem> dmpUpload(@RequestParam("file") MultipartFile[] files, Principal principal) throws Exception {
|
||||
public ResponseEntity<ResponseItem> dmpUpload(@RequestParam("file") MultipartFile[] files, @RequestParam("profiles")String[] profiles, Principal principal) throws Exception {
|
||||
if (files[0].getContentType().equals(APPLICATION_JSON.toString())) {
|
||||
this.dataManagementPlanManager.createFromRDA(files, principal);
|
||||
this.dataManagementPlanManager.createFromRDA(files, principal, profiles);
|
||||
} else if (files[0].getContentType().equals(APPLICATION_ATOM_XML.toString())) {
|
||||
this.dataManagementPlanManager.createDmpFromXml(this.getApiContext(), files, principal);
|
||||
}
|
||||
|
|
|
@ -1379,13 +1379,13 @@ public class DataManagementPlanManager {
|
|||
return dataManagementPlans;
|
||||
}
|
||||
|
||||
public List<DMP> createFromRDA(MultipartFile[] files, Principal principal) throws IOException {
|
||||
public List<DMP> createFromRDA(MultipartFile[] files, Principal principal, String[] profiles) throws IOException {
|
||||
if (principal.getId() == null) {
|
||||
throw new UnauthorisedException("No user is logged in");
|
||||
}
|
||||
List<DMP> result = new ArrayList<>();
|
||||
for (MultipartFile file: files) {
|
||||
DMP dmp = rdaManager.convertToEntity(new String(file.getBytes(), "UTF-8"));
|
||||
DMP dmp = rdaManager.convertToEntity(new String(file.getBytes(), "UTF-8"), profiles);
|
||||
dmp.setLabel(file.getOriginalFilename());
|
||||
UserInfo me = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
|
||||
dmp.setModified(new Date());
|
||||
|
|
|
@ -40,13 +40,13 @@ public class RDAManager {
|
|||
return result;
|
||||
}
|
||||
|
||||
public DMP convertToEntity(String json) throws IOException {
|
||||
public DMP convertToEntity(String json, String[] profiles) throws IOException {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"));
|
||||
|
||||
|
||||
Dmp rda = mapper.readValue(json, DMPWrap.class).getDmp();
|
||||
return dmpRDAMapper.toEntity(rda);
|
||||
return dmpRDAMapper.toEntity(rda, profiles);
|
||||
}
|
||||
|
||||
public static class DMPWrap implements Serializable {
|
||||
|
|
|
@ -134,7 +134,7 @@ public class DatasetRDAMapper {
|
|||
}
|
||||
|
||||
|
||||
public eu.eudat.data.entities.Dataset toEntity(Dataset rda) {
|
||||
public eu.eudat.data.entities.Dataset toEntity(Dataset rda, DatasetProfile defaultProfile) {
|
||||
eu.eudat.data.entities.Dataset entity = new eu.eudat.data.entities.Dataset();
|
||||
entity.setLabel(rda.getTitle());
|
||||
entity.setDescription(rda.getDescription());
|
||||
|
@ -143,6 +143,7 @@ public class DatasetRDAMapper {
|
|||
entity.setProfile(profile);
|
||||
}catch(Exception e) {
|
||||
logger.warn(e.getMessage(), e);
|
||||
entity.setProfile(defaultProfile);
|
||||
}
|
||||
try {
|
||||
Map<String, Object> properties = new HashMap<>();
|
||||
|
@ -176,7 +177,7 @@ public class DatasetRDAMapper {
|
|||
properties.put(qaIds.get(i), rda.getDataQualityAssurance().get(i));
|
||||
}*/
|
||||
List<JsonNode> qaNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.data_quality_assurance");
|
||||
if (!qaNodes.isEmpty()) {
|
||||
if (!qaNodes.isEmpty() && rda.getDataQualityAssurance() != null && !rda.getDataQualityAssurance().isEmpty()) {
|
||||
properties.put(qaNodes.get(0).get("id").asText(), rda.getDataQualityAssurance().get(0));
|
||||
}
|
||||
|
||||
|
|
|
@ -54,25 +54,33 @@ public class DmpRDAMapper {
|
|||
return rda;
|
||||
}
|
||||
|
||||
public DMP toEntity(Dmp rda) {
|
||||
public DMP toEntity(Dmp rda, String[] profiles) {
|
||||
DMP entity = new DMP();
|
||||
entity.setLabel(rda.getTitle());
|
||||
if (rda.getDmpId().getType() == DmpId.Type.DOI) {
|
||||
entity.setDoi(rda.getDmpId().getIdentifier());
|
||||
}
|
||||
if (((List<String>) rda.getAdditionalProperties().get("templates")) != null && !((List<String>) rda.getAdditionalProperties().get("templates")).isEmpty()) {
|
||||
entity.setAssociatedDmps(((List<String>) rda.getAdditionalProperties().get("templates")).stream().map(this::getProfile).collect(Collectors.toSet()));
|
||||
}
|
||||
if (entity.getAssociatedDmps() == null) {
|
||||
entity.setAssociatedDmps(new HashSet<>());
|
||||
}
|
||||
for (String profile: profiles) {
|
||||
DatasetProfile exProfile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(profile));
|
||||
entity.getAssociatedDmps().add(exProfile);
|
||||
}
|
||||
if (rda.getContributor() != null && !rda.getContributor().isEmpty()) {
|
||||
entity.setResearchers(rda.getContributor().stream().map(ContributorRDAMapper::toEntity).collect(Collectors.toSet()));
|
||||
}
|
||||
entity.setCreated(rda.getCreated());
|
||||
entity.setModified(rda.getModified());
|
||||
entity.setDescription(rda.getDescription());
|
||||
entity.setDataset(rda.getDataset().stream().map(rda1 -> datasetRDAMapper.toEntity(rda1)).collect(Collectors.toSet()));
|
||||
DatasetProfile defaultProfile = ((DatasetProfile)entity.getAssociatedDmps().toArray()[0]);
|
||||
entity.setDataset(rda.getDataset().stream().map(rda1 -> datasetRDAMapper.toEntity(rda1, defaultProfile)).collect(Collectors.toSet()));
|
||||
Map<String, Object> result = ProjectRDAMapper.toEntity(rda.getProject().get(0), apiContext);
|
||||
entity.setProject((Project) result.get("project"));
|
||||
result.entrySet().stream().filter(entry -> entry.getKey().startsWith("grant")).forEach(entry -> entity.setGrant((Grant) entry.getValue()));
|
||||
if (((List<String>) rda.getAdditionalProperties().get("templates")) != null && !((List<String>) rda.getAdditionalProperties().get("templates")).isEmpty()) {
|
||||
entity.setAssociatedDmps(((List<String>) rda.getAdditionalProperties().get("templates")).stream().map(this::getProfile).collect(Collectors.toSet()));
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
|
|
@ -123,7 +123,7 @@ export class DmpService {
|
|||
return this.httpClient.get(this.actionUrl + 'rda/' + id, { responseType: 'blob', observe: 'response' });
|
||||
}
|
||||
|
||||
public uploadXml(fileList: FileList, dmpTitle: string): Observable<any> {
|
||||
public uploadXml(fileList: FileList, dmpTitle: string, dmpProfiles: any[]): Observable<any> {
|
||||
const formData: FormData = new FormData();
|
||||
if (fileList instanceof FileList) {
|
||||
for (let i = 0; i < fileList.length; i++) {
|
||||
|
@ -132,6 +132,9 @@ export class DmpService {
|
|||
} else {
|
||||
formData.append('file', fileList);
|
||||
}
|
||||
for (let j = 0; j < dmpProfiles.length; j++) {
|
||||
formData.append('profiles', dmpProfiles[j].id);
|
||||
}
|
||||
const params = new BaseHttpParams();
|
||||
params.interceptorContext = {
|
||||
excludedInterceptors: [InterceptorType.JSONContentType]
|
||||
|
|
|
@ -240,7 +240,7 @@ export class DmpListingComponent extends BaseComponent implements OnInit, IBread
|
|||
});
|
||||
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
|
||||
if (result && result.success) {
|
||||
this.dmpService.uploadXml(result.fileList, result.dmpTitle)
|
||||
this.dmpService.uploadXml(result.fileList, result.dmpTitle, result.dmpProfiles)
|
||||
.pipe(takeUntil(this._destroyed))
|
||||
.subscribe((complete) => this.onCallbackImportComplete(),
|
||||
(error) => this.onCallbackImportFail(error.error));
|
||||
|
|
|
@ -14,6 +14,10 @@
|
|||
<mat-form-field class="col-12">
|
||||
<input class="uploadInput" [(ngModel)]="dmpTitle" matInput placeholder="{{'DMP-UPLOAD.PLACEHOLDER' | translate}}" name="uploadFileInput">
|
||||
</mat-form-field>
|
||||
<mat-form-field class="col-sm-12 col-md-8">
|
||||
<app-multiple-auto-complete required='true' [(ngModel)]="dmpProfiles" placeholder="{{'DMP-EDITOR.FIELDS.DATASET-TEMPLATES' | translate}}" [configuration]="profilesAutoCompleteConfiguration">
|
||||
</app-multiple-auto-complete>
|
||||
</mat-form-field>
|
||||
<div class="col-auto">
|
||||
<button mat-raised-button type="button" (click)="cancel()">{{'DMP-UPLOAD.ACTIONS.CANCEL' | translate}}</button>
|
||||
</div>
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
import { Component, Inject } from '@angular/core';
|
||||
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
|
||||
import { DmpService } from '../../../../core/services/dmp/dmp.service';
|
||||
import { MultipleAutoCompleteConfiguration } from '@app/library/auto-complete/multiple/multiple-auto-complete-configuration';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { Observable } from 'rxjs';
|
||||
import { DatasetProfileModel } from '@app/core/model/dataset/dataset-profile';
|
||||
import { DataTableRequest } from '@app/core/model/data-table/data-table-request';
|
||||
import { DatasetProfileCriteria } from '@app/core/query/dataset-profile/dataset-profile-criteria';
|
||||
|
||||
@Component({
|
||||
selector: 'dmp-upload-dialogue',
|
||||
|
@ -9,10 +15,20 @@ import { DmpService } from '../../../../core/services/dmp/dmp.service';
|
|||
})
|
||||
export class DmpUploadDialogue {
|
||||
dmpTitle: string;
|
||||
dmpProfiles: any[] = [];
|
||||
|
||||
profilesAutoCompleteConfiguration: MultipleAutoCompleteConfiguration = {
|
||||
filterFn: this.filterProfiles.bind(this),
|
||||
initialItems: (excludedItems: any[]) => this.filterProfiles('').pipe(map(result => result.filter(resultItem => (excludedItems || []).map(x => x.id).indexOf(resultItem.id) === -1))),
|
||||
displayFn: (item) => item['label'],
|
||||
titleFn: (item) => item['label'],
|
||||
subtitleFn: (item) => item['description']
|
||||
};
|
||||
|
||||
|
||||
constructor(
|
||||
public dialogRef: MatDialogRef<DmpUploadDialogue>,
|
||||
private _service: DmpService,
|
||||
@Inject(MAT_DIALOG_DATA) public data: any,
|
||||
) {}
|
||||
|
||||
|
@ -24,6 +40,7 @@ export class DmpUploadDialogue {
|
|||
confirm() {
|
||||
this.data.success = true;
|
||||
this.data.dmpTitle = this.dmpTitle;
|
||||
this.data.dmpProfiles = this.dmpProfiles;
|
||||
this.dialogRef.close(this.data);
|
||||
}
|
||||
|
||||
|
@ -34,4 +51,13 @@ export class DmpUploadDialogue {
|
|||
this.dmpTitle = fileList.item(0).name;
|
||||
}
|
||||
}
|
||||
|
||||
filterProfiles(value: string): Observable<DatasetProfileModel[]> {
|
||||
|
||||
const request = new DataTableRequest<DatasetProfileCriteria>(null, null, {fields: ['+label']});
|
||||
const criteria = new DatasetProfileCriteria();
|
||||
criteria.like = value;
|
||||
request.criteria = criteria;
|
||||
return this._service.searchDMPProfiles(request);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue