Allow to update Dataset Templates by uploading dataset Template .xml files (ref #7793)

This commit is contained in:
George Kalampokis 2022-05-25 14:50:00 +03:00
parent 912a3cc095
commit 3aff6ac90e
1 changed files with 16 additions and 10 deletions

View File

@ -167,12 +167,15 @@ public class Admin extends BaseController {
}
}
@RequestMapping(method = RequestMethod.POST, value = {"/upload"})
@RequestMapping(method = RequestMethod.POST, value = {"/upload", "/upload/{id}"})
public ResponseEntity<Object> setDatasetProfileXml(@RequestParam("file") MultipartFile file,
@ClaimedAuthorities(claims = {ADMIN, DATASET_PROFILE_MANAGER}) Principal principal) throws IllegalAccessException, IOException {
@PathVariable(value = "id") String id,
@ClaimedAuthorities(claims = {ADMIN, DATASET_PROFILE_MANAGER}) Principal principal) throws Exception {
eu.eudat.logic.utilities.documents.xml.datasetProfileXml.datasetProfileModel.DatasetProfile datasetProfileModel = this.datasetProfileManager.createDatasetProfileFromXml(file);
eu.eudat.models.data.admin.composite.DatasetProfile datasetProfileEntity = datasetProfileModel.toAdminCompositeModel(file.getOriginalFilename());
eu.eudat.data.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(datasetProfileEntity, getApiContext());
eu.eudat.data.entities.DatasetProfile modelDefinition;
if (id == null) {
modelDefinition = AdminManager.generateViewStyleDefinition(datasetProfileEntity, getApiContext());
eu.eudat.data.entities.DatasetProfile datasetProfile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(modelDefinition);
UserDatasetProfile userDatasetProfile = new UserDatasetProfile();
userDatasetProfile.setDatasetProfile(datasetProfile);
@ -180,6 +183,9 @@ public class Admin extends BaseController {
userDatasetProfile.setUser(userInfo);
userDatasetProfile.setRole(0);
getApiContext().getOperationsContext().getDatabaseRepository().getUserDatasetProfileDao().createOrUpdate(userDatasetProfile);
} else {
modelDefinition = datasetProfileManager.createNewVersionDatasetProfile(id, datasetProfileEntity);
}
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<eu.eudat.data.entities.DatasetProfile>>()
.status(ApiMessageCode.SUCCESS_MESSAGE).message(""));
}