Merge branch 'Development' of code-repo.d4science.org:MaDgiK-CITE/argos into Development

This commit is contained in:
Konstantinos Triantafyllou 2023-04-20 15:27:53 +03:00
commit ef0816524f
6 changed files with 79 additions and 26 deletions

View File

@ -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<Void>().status(ApiMessageCode.SUCCESS_MESSAGE));
} catch (Exception exception) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<Void>().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<Void>().status(ApiMessageCode.SUCCESS_MESSAGE));
} catch (Exception exception) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<Void>().status(ApiMessageCode.ERROR_MESSAGE).message(exception.getMessage()));
}

View File

@ -400,12 +400,36 @@ 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);
}
this.updateDatasetProfileXml(document, datasetProfile);
}
}
public void addRdaInSchematicsInDatasetProfiles() throws XPathExpressionException {
List<DatasetProfile> 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();
@ -416,14 +440,12 @@ public class DatasetProfileManager {
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);
}
}
}
}

View File

@ -17,4 +17,8 @@ export class MaintenanceTasksService extends BaseService {
migrateSchematics(): Observable<void> {
return this.http.post<null>(this.actionUrl + 'addSchematics/', null);
}
addRdaInSchematics(): Observable<void> {
return this.http.post<null>(this.actionUrl + 'addRdaInSchematics/', null);
}
}

View File

@ -1,8 +1,9 @@
<div class="row root">
<mat-card class="col-md-3 offset-md-4">
<div style="color: red;">Warning: Danger zone. Irreversible actions!</div>
<div>
<div style="color: red;">Warning: Danger zone. Irreversible action!</div>
<button mat-raised-button color="primary" (click)="migrateSchematics($event)" class="lightblue-btn button">Migrate schematics</button>
<button mat-raised-button color="primary" (click)="addRdaInSchematics($event)" class="lightblue-btn button">Add rda in schematics</button>
</div>
</mat-card>
</div>

View File

@ -39,6 +39,20 @@ export class MaintenanceTasksComponent extends BaseComponent implements OnInit {
);
}
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 {
this.uiNotificationService.snackBarNotification( this.translate.instant('GENERAL.SNACK-BAR.SUCCESSFUL-UPDATE'), SnackBarNotificationLevel.Success);
this.router.navigate(['/reload']).then(() => this.router.navigate(['/maintenance-tasks']));

View File

@ -55,6 +55,7 @@
:root {
--primary-color: #129d99;
--primary-color-1: #129d99;
--primary-color-2: #23bcba;
--primary-color-3: #00b29f;
--secondary-color: #f7dd72;