migrate rda properties in dataset profiles definitions in db to schematics
This commit is contained in:
parent
c35bc2efed
commit
969df0357a
|
@ -0,0 +1,43 @@
|
||||||
|
package eu.eudat.controllers;
|
||||||
|
|
||||||
|
import eu.eudat.exceptions.datasetprofile.DatasetProfileNewVersionException;
|
||||||
|
import eu.eudat.logic.managers.DatasetProfileManager;
|
||||||
|
import eu.eudat.logic.security.claims.ClaimedAuthorities;
|
||||||
|
import eu.eudat.logic.services.ApiContext;
|
||||||
|
import eu.eudat.models.data.admin.composite.DatasetProfile;
|
||||||
|
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
||||||
|
import eu.eudat.models.data.security.Principal;
|
||||||
|
import eu.eudat.types.ApiMessageCode;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
|
import static eu.eudat.types.Authorities.ADMIN;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@CrossOrigin
|
||||||
|
@RequestMapping(value = {"/api/management/"})
|
||||||
|
public class ManagementController extends BaseController {
|
||||||
|
|
||||||
|
private DatasetProfileManager datasetProfileManager;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public ManagementController(ApiContext apiContext, DatasetProfileManager datasetProfileManager){
|
||||||
|
super(apiContext);
|
||||||
|
this.datasetProfileManager = datasetProfileManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
@RequestMapping(method = RequestMethod.POST, value = {"/addSchematics"})
|
||||||
|
public ResponseEntity addSchematicsInDatasetProfiles(@ClaimedAuthorities(claims = {ADMIN}) Principal principal) throws Exception {
|
||||||
|
try {
|
||||||
|
this.datasetProfileManager.addSchematicsInDatasetProfiles();
|
||||||
|
return ResponseEntity.status(HttpStatus.OK).body(null);
|
||||||
|
} catch (Exception exception) {
|
||||||
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<Void>().status(ApiMessageCode.ERROR_MESSAGE).message(exception.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -45,9 +45,17 @@ import org.springframework.web.client.RestTemplate;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
|
|
||||||
import javax.activation.MimetypesFileTypeMap;
|
import javax.activation.MimetypesFileTypeMap;
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
import javax.xml.transform.OutputKeys;
|
||||||
|
import javax.xml.transform.Transformer;
|
||||||
|
import javax.xml.transform.TransformerException;
|
||||||
|
import javax.xml.transform.TransformerFactory;
|
||||||
|
import javax.xml.transform.dom.DOMSource;
|
||||||
|
import javax.xml.transform.stream.StreamResult;
|
||||||
import javax.xml.xpath.*;
|
import javax.xml.xpath.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
@ -376,4 +384,46 @@ public class DatasetProfileManager {
|
||||||
}
|
}
|
||||||
return filteredSchematics;
|
return filteredSchematics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addSchematicsInDatasetProfiles() 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("//rdaCommonStandard");
|
||||||
|
NodeList rdaProperties = (NodeList) expr.evaluate(document, XPathConstants.NODESET);
|
||||||
|
for(int i = 0; i < rdaProperties.getLength(); i++){
|
||||||
|
Node rdaPropertyNode = rdaProperties.item(i);
|
||||||
|
String rdaProperty = rdaPropertyNode.getTextContent();
|
||||||
|
Element schematics = document.createElement("schematics");
|
||||||
|
Node fieldParent = rdaPropertyNode.getParentNode();
|
||||||
|
if(rdaProperty != null && !rdaProperty.isEmpty()){
|
||||||
|
Element schematic = document.createElement("schematic");
|
||||||
|
schematic.setTextContent(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){
|
||||||
|
|
||||||
|
}
|
||||||
|
datasetProfile.setDefinition(newDefinition);
|
||||||
|
this.databaseRepository.getDatasetProfileDao().createOrUpdate(datasetProfile);
|
||||||
|
}
|
||||||
|
catch(TransformerException ex) {
|
||||||
|
logger.error(ex.getMessage(), ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -224,6 +224,13 @@ const appRoutes: Routes = [
|
||||||
title: 'GENERAL.TITLES.INDEX-MANAGMENT'
|
title: 'GENERAL.TITLES.INDEX-MANAGMENT'
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: 'maintenance-tasks',
|
||||||
|
loadChildren: () => import('./ui/admin/maintenance-tasks/maintenance-tasks.module').then(m => m.MaintenanceTasksModule),
|
||||||
|
data: {
|
||||||
|
breadcrumb: true
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: 'login/admin',
|
path: 'login/admin',
|
||||||
loadChildren: () => import('./ui/auth/admin-login/admin-login.module').then(m => m.AdminLoginModule),
|
loadChildren: () => import('./ui/auth/admin-login/admin-login.module').then(m => m.AdminLoginModule),
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
import { Injectable } from "@angular/core";
|
||||||
|
import { BaseService } from "@common/base/base.service";
|
||||||
|
import { Observable } from "rxjs";
|
||||||
|
import { ConfigurationService } from "../configuration/configuration.service";
|
||||||
|
import { BaseHttpService } from "../http/base-http.service";
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class MaintenanceTasksService extends BaseService {
|
||||||
|
|
||||||
|
private actionUrl: string;
|
||||||
|
|
||||||
|
constructor(private http: BaseHttpService, configurationService: ConfigurationService) {
|
||||||
|
super();
|
||||||
|
this.actionUrl = configurationService.server + 'management/';
|
||||||
|
}
|
||||||
|
|
||||||
|
migrateSchematics(): Observable<void> {
|
||||||
|
return this.http.post<null>(this.actionUrl + 'addSchematics/', null);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
<div class="row root">
|
||||||
|
<mat-card class="col-md-3 offset-md-4">
|
||||||
|
<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>
|
||||||
|
</div>
|
||||||
|
</mat-card>
|
||||||
|
</div>
|
|
@ -0,0 +1,7 @@
|
||||||
|
.root {
|
||||||
|
padding-bottom: 2em;
|
||||||
|
|
||||||
|
.button {
|
||||||
|
margin: 5px;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { BaseComponent } from '@common/base/base.component';
|
||||||
|
import { takeUntil } from 'rxjs/operators';
|
||||||
|
import { UiNotificationService, SnackBarNotificationLevel } from '@app/core/services/notification/ui-notification-service';
|
||||||
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
import { MaintenanceTasksService } from '@app/core/services/maintenance-tasks/maintenance-tasks.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-maintenance-tasks',
|
||||||
|
templateUrl: './maintenance-tasks.component.html',
|
||||||
|
styleUrls: ['./maintenance-tasks.component.scss']
|
||||||
|
})
|
||||||
|
export class MaintenanceTasksComponent extends BaseComponent implements OnInit {
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private maintenanceTasksService: MaintenanceTasksService,
|
||||||
|
private uiNotificationService: UiNotificationService,
|
||||||
|
private translate: TranslateService,
|
||||||
|
private router: Router,
|
||||||
|
) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
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']));
|
||||||
|
}
|
||||||
|
|
||||||
|
onCallbackError(error: any) {
|
||||||
|
this.uiNotificationService.snackBarNotification( error, SnackBarNotificationLevel.Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
import { NgModule } from '@angular/core';
|
||||||
|
|
||||||
|
import { MaintenanceTasksRoutingModule } from './maintenance-tasks.routing';
|
||||||
|
import { MaintenanceTasksComponent } from './maintenance-tasks.component';
|
||||||
|
import { CommonUiModule } from '@common/ui/common-ui.module';
|
||||||
|
import { CommonFormsModule } from '@common/forms/common-forms.module';
|
||||||
|
import { ConfirmationDialogModule } from '@common/modules/confirmation-dialog/confirmation-dialog.module';
|
||||||
|
import { MaintenanceTasksService } from '@app/core/services/maintenance-tasks/maintenance-tasks.service';
|
||||||
|
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
declarations: [MaintenanceTasksComponent],
|
||||||
|
imports: [
|
||||||
|
CommonUiModule,
|
||||||
|
CommonFormsModule,
|
||||||
|
ConfirmationDialogModule,
|
||||||
|
MaintenanceTasksRoutingModule
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
MaintenanceTasksService
|
||||||
|
]
|
||||||
|
})
|
||||||
|
export class MaintenanceTasksModule { }
|
|
@ -0,0 +1,15 @@
|
||||||
|
import { NgModule } from '@angular/core';
|
||||||
|
import { Routes, RouterModule } from '@angular/router';
|
||||||
|
import { MaintenanceTasksComponent } from './maintenance-tasks.component';
|
||||||
|
import { AdminAuthGuard } from '@app/core/admin-auth-guard.service';
|
||||||
|
|
||||||
|
|
||||||
|
const routes: Routes = [
|
||||||
|
{ path: '', component: MaintenanceTasksComponent, canActivate: [AdminAuthGuard] },
|
||||||
|
];
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
imports: [RouterModule.forChild(routes)],
|
||||||
|
exports: [RouterModule]
|
||||||
|
})
|
||||||
|
export class MaintenanceTasksRoutingModule { }
|
Loading…
Reference in New Issue