From 7b12d7b46d321f52668ee65a9a1049ee7d0e92e0 Mon Sep 17 00:00:00 2001 From: Aldo Mihasi Date: Thu, 20 Apr 2023 10:12:55 +0300 Subject: [PATCH] temporarily endpoint for appending "rda." in schematic values of dataset profiles --- .../controllers/ManagementController.java | 13 ++++- .../logic/managers/DatasetProfileManager.java | 50 +++++++++++++------ .../maintenance-tasks.service.ts | 4 ++ .../maintenance-tasks.component.html | 3 +- .../maintenance-tasks.component.ts | 34 +++++++++---- dmp-frontend/src/styles.scss | 1 + 6 files changed, 79 insertions(+), 26 deletions(-) diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/ManagementController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/ManagementController.java index 45e810b23..f203c5554 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/ManagementController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/ManagementController.java @@ -35,7 +35,18 @@ public class ManagementController extends BaseController { public ResponseEntity addSchematicsInDatasetProfiles(@ClaimedAuthorities(claims = {ADMIN}) Principal principal) throws Exception { try { this.datasetProfileManager.addSchematicsInDatasetProfiles(); - return ResponseEntity.status(HttpStatus.OK).body(null); + return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE)); + } catch (Exception exception) { + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message(exception.getMessage())); + } + } + + @Transactional + @RequestMapping(method = RequestMethod.POST, value = {"/addRdaInSchematics"}) + public ResponseEntity addRdaInSchematicsInDatasetProfiles(@ClaimedAuthorities(claims = {ADMIN}) Principal principal) throws Exception { + try { + this.datasetProfileManager.addRdaInSchematicsInDatasetProfiles(); + return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE)); } catch (Exception exception) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message(exception.getMessage())); } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetProfileManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetProfileManager.java index 2f9f87d23..afb2b669b 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetProfileManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetProfileManager.java @@ -400,30 +400,52 @@ public class DatasetProfileManager { Node fieldParent = rdaPropertyNode.getParentNode(); if(rdaProperty != null && !rdaProperty.isEmpty()){ Element schematic = document.createElement("schematic"); - schematic.setTextContent(rdaProperty); + schematic.setTextContent("rda." + rdaProperty); schematics.appendChild(schematic); } fieldParent.insertBefore(schematics, rdaPropertyNode); fieldParent.removeChild(rdaPropertyNode); } - try { - DOMSource domSource = new DOMSource(document); - StringWriter writer = new StringWriter(); - StreamResult result = new StreamResult(writer); - TransformerFactory tf = TransformerFactory.newInstance(); - Transformer transformer = tf.newTransformer(); - transformer.setOutputProperty(OutputKeys.INDENT, "yes"); - transformer.transform(domSource, result); - String newDefinition = writer.toString(); - if(newDefinition != null){ + this.updateDatasetProfileXml(document, datasetProfile); + } + } + public void addRdaInSchematicsInDatasetProfiles() throws XPathExpressionException { + List datasetProfiles = this.databaseRepository.getDatasetProfileDao().getAll().toList(); + for(DatasetProfile datasetProfile: datasetProfiles){ + Document document = XmlBuilder.fromXml(datasetProfile.getDefinition()); + XPathFactory xpathFactory = XPathFactory.newInstance(); + XPath xpath = xpathFactory.newXPath(); + XPathExpression expr = xpath.compile("//schematic"); + NodeList schematics = (NodeList) expr.evaluate(document, XPathConstants.NODESET); + for (int i = 0; i < schematics.getLength(); i++) { + Node schematicNode = schematics.item(i); + String schematicRda = schematicNode.getTextContent(); + if (schematicRda != null && !schematicRda.isEmpty() && !schematicRda.startsWith("rda.")) { + schematicNode.setTextContent("rda." + schematicRda); } + } + this.updateDatasetProfileXml(document, datasetProfile); + } + } + + private void updateDatasetProfileXml(Document document, DatasetProfile datasetProfile) { + try { + DOMSource domSource = new DOMSource(document); + StringWriter writer = new StringWriter(); + StreamResult result = new StreamResult(writer); + TransformerFactory tf = TransformerFactory.newInstance(); + Transformer transformer = tf.newTransformer(); + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + transformer.transform(domSource, result); + String newDefinition = writer.toString(); + if(newDefinition != null){ datasetProfile.setDefinition(newDefinition); this.databaseRepository.getDatasetProfileDao().createOrUpdate(datasetProfile); } - catch(TransformerException ex) { - logger.error(ex.getMessage(), ex); - } + } + catch(TransformerException ex) { + logger.error(ex.getMessage(), ex); } } } diff --git a/dmp-frontend/src/app/core/services/maintenance-tasks/maintenance-tasks.service.ts b/dmp-frontend/src/app/core/services/maintenance-tasks/maintenance-tasks.service.ts index babdd7137..813ab6a35 100644 --- a/dmp-frontend/src/app/core/services/maintenance-tasks/maintenance-tasks.service.ts +++ b/dmp-frontend/src/app/core/services/maintenance-tasks/maintenance-tasks.service.ts @@ -17,4 +17,8 @@ export class MaintenanceTasksService extends BaseService { migrateSchematics(): Observable { return this.http.post(this.actionUrl + 'addSchematics/', null); } + + addRdaInSchematics(): Observable { + return this.http.post(this.actionUrl + 'addRdaInSchematics/', null); + } } \ No newline at end of file diff --git a/dmp-frontend/src/app/ui/admin/maintenance-tasks/maintenance-tasks.component.html b/dmp-frontend/src/app/ui/admin/maintenance-tasks/maintenance-tasks.component.html index f3193d329..dfc504b96 100644 --- a/dmp-frontend/src/app/ui/admin/maintenance-tasks/maintenance-tasks.component.html +++ b/dmp-frontend/src/app/ui/admin/maintenance-tasks/maintenance-tasks.component.html @@ -1,8 +1,9 @@
+
Warning: Danger zone. Irreversible actions!
-
Warning: Danger zone. Irreversible action!
+
diff --git a/dmp-frontend/src/app/ui/admin/maintenance-tasks/maintenance-tasks.component.ts b/dmp-frontend/src/app/ui/admin/maintenance-tasks/maintenance-tasks.component.ts index 54c811e25..187992cb7 100644 --- a/dmp-frontend/src/app/ui/admin/maintenance-tasks/maintenance-tasks.component.ts +++ b/dmp-frontend/src/app/ui/admin/maintenance-tasks/maintenance-tasks.component.ts @@ -27,16 +27,30 @@ export class MaintenanceTasksComponent extends BaseComponent implements OnInit { migrateSchematics(ev: Event) { (ev.srcElement as HTMLButtonElement).disabled = true; - this.maintenanceTasksService.migrateSchematics().pipe(takeUntil(this._destroyed)).subscribe( - response => { - (ev.srcElement as HTMLButtonElement).disabled = false; - this.onCallbackSuccess(); - }, - error => { - (ev.srcElement as HTMLButtonElement).disabled = false; - this.onCallbackError(error); - } - ); + this.maintenanceTasksService.migrateSchematics().pipe(takeUntil(this._destroyed)).subscribe( + response => { + (ev.srcElement as HTMLButtonElement).disabled = false; + this.onCallbackSuccess(); + }, + error => { + (ev.srcElement as HTMLButtonElement).disabled = false; + this.onCallbackError(error); + } + ); + } + + addRdaInSchematics(ev: Event) { + (ev.srcElement as HTMLButtonElement).disabled = true; + this.maintenanceTasksService.addRdaInSchematics().pipe(takeUntil(this._destroyed)).subscribe( + response => { + (ev.srcElement as HTMLButtonElement).disabled = false; + this.onCallbackSuccess(); + }, + error => { + (ev.srcElement as HTMLButtonElement).disabled = false; + this.onCallbackError(error); + } + ); } onCallbackSuccess(): void { diff --git a/dmp-frontend/src/styles.scss b/dmp-frontend/src/styles.scss index 5917892a4..fdf107b88 100644 --- a/dmp-frontend/src/styles.scss +++ b/dmp-frontend/src/styles.scss @@ -55,6 +55,7 @@ :root { --primary-color: #129d99; + --primary-color-1: #129d99; --primary-color-2: #23bcba; --primary-color-3: #00b29f; --secondary-color: #f7dd72;