Add index management for admins
This commit is contained in:
parent
9071faba38
commit
818c6378c2
|
@ -66,5 +66,21 @@ public class Datasets extends BaseController {
|
|||
DataTableData<DatasetProfileListingModel> datasetProfileTableData = this.datasetManager.getDatasetProfilesUsedByDatasets(datasetProfileTableRequestItem, principal);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DatasetProfileListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(datasetProfileTableData));
|
||||
}
|
||||
|
||||
@javax.transaction.Transactional
|
||||
@RequestMapping(method = RequestMethod.POST, value = {"/index"})
|
||||
public @ResponseBody
|
||||
ResponseEntity<ResponseItem<Dataset>> generateIndex(Principal principal) throws Exception {
|
||||
this.datasetManager.generateIndex(principal);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.data.entities.Dataset>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Generated").payload(null));
|
||||
}
|
||||
|
||||
@javax.transaction.Transactional
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = {"/index"})
|
||||
public @ResponseBody
|
||||
ResponseEntity<ResponseItem<Dataset>> clearIndex(Principal principal) throws Exception {
|
||||
this.datasetManager.clearIndex(principal);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.data.entities.Dataset>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Cleared").payload(null));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -832,4 +832,29 @@ public class DatasetManager {
|
|||
|
||||
return data;
|
||||
}
|
||||
|
||||
public void generateIndex(Principal principal) {
|
||||
if (principal.getAuthorities().contains(Authorities.ADMIN.getValue())) {
|
||||
this.apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().asQueryable().toList();
|
||||
List<DatasetWizardModel> datasetWizardModels = this.apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().asQueryable().toList()
|
||||
.stream().map(dataset -> new DatasetWizardModel().fromDataModel(dataset)).collect(Collectors.toList());
|
||||
datasetWizardModels.forEach(datasetWizardModel -> {
|
||||
try {
|
||||
updateTags(apiContext.getOperationsContext().getDatasetRepository(), datasetWizardModel);
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void clearIndex(Principal principal) {
|
||||
if (principal.getAuthorities().contains(Authorities.ADMIN.getValue())) {
|
||||
try {
|
||||
this.apiContext.getOperationsContext().getDatasetRepository().clear();
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -188,6 +188,14 @@ const appRoutes: Routes = [
|
|||
title: 'GENERAL.TITLES.GUIDE-EDITOR'
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'index-managment',
|
||||
loadChildren: () => import('./ui/admin/index-managment/index-managment.module').then(m => m.IndexManagmentModule),
|
||||
data: {
|
||||
breadcrumb: true,
|
||||
title: 'GENERAL.TITLES.INDEX-MANAGMENT'
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'login/admin',
|
||||
loadChildren: () => import('./ui/auth/admin-login/admin-login.module').then(m => m.AdminLoginModule),
|
||||
|
|
|
@ -38,4 +38,12 @@ export class DatasetService {
|
|||
getDatasetProfilesUsedPaged(dataTableRequest: DataTableRequest<DatasetProfileCriteria>) {
|
||||
return this.http.post<DataTableData<DatasetListingModel>>(this.actionUrl + 'datasetProfilesUsedByDatasets/paged', dataTableRequest);
|
||||
}
|
||||
|
||||
generateIndex() {
|
||||
return this.http.post(this.actionUrl + 'index', {});
|
||||
}
|
||||
|
||||
clearIndex() {
|
||||
return this.http.delete(this.actionUrl + 'index');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
<div class="row root">
|
||||
<mat-card class="col-md-3 offset-md-4">
|
||||
<div>
|
||||
<button mat-raised-button color="primary" (click)="generateIndex($event)" class="lightblue-btn button">Generate Index</button>
|
||||
<button mat-raised-button color="primary" (click)="clearIndex($event)" class="lightblue-btn button">Clear Index</button>
|
||||
</div>
|
||||
</mat-card>
|
||||
</div>
|
|
@ -0,0 +1,8 @@
|
|||
.root {
|
||||
padding-top: 5em;
|
||||
padding-bottom: 2em;
|
||||
|
||||
.button {
|
||||
margin: 5px;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
import { Component, OnInit } from '@angular/core';
|
||||
import { DatasetService } from '@app/core/services/dataset/dataset.service';
|
||||
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';
|
||||
|
||||
@Component({
|
||||
selector: 'app-index-managment',
|
||||
templateUrl: './index-managment.component.html',
|
||||
styleUrls: ['./index-managment.component.scss']
|
||||
})
|
||||
export class IndexManagmentComponent extends BaseComponent implements OnInit {
|
||||
|
||||
constructor(
|
||||
private datasetService: DatasetService,
|
||||
private uiNotificationService: UiNotificationService,
|
||||
private translate: TranslateService,
|
||||
private router: Router,
|
||||
)
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
}
|
||||
|
||||
generateIndex(ev: Event) {
|
||||
(ev.srcElement as HTMLButtonElement).disabled = true;
|
||||
this.datasetService.generateIndex().pipe(takeUntil(this._destroyed)).subscribe(
|
||||
response => {
|
||||
(ev.srcElement as HTMLButtonElement).disabled = false;
|
||||
this.onCallbackSuccess();
|
||||
},
|
||||
error => {
|
||||
(ev.srcElement as HTMLButtonElement).disabled = false;
|
||||
this.onCallbackError(error);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
clearIndex(ev: Event) {
|
||||
(ev.srcElement as HTMLButtonElement).disabled = true;
|
||||
this.datasetService.clearIndex().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(['/index-managment']));
|
||||
}
|
||||
|
||||
onCallbackError(error: any) {
|
||||
this.uiNotificationService.snackBarNotification( error, SnackBarNotificationLevel.Error);
|
||||
//this.validateAllFormFields(this.formGroup);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
|
||||
import { IndexManagmentRoutingModule } from './index-managment.routing';
|
||||
import { IndexManagmentComponent } from './index-managment.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';
|
||||
|
||||
|
||||
@NgModule({
|
||||
declarations: [IndexManagmentComponent],
|
||||
imports: [
|
||||
CommonUiModule,
|
||||
CommonFormsModule,
|
||||
ConfirmationDialogModule,
|
||||
IndexManagmentRoutingModule
|
||||
]
|
||||
})
|
||||
export class IndexManagmentModule { }
|
|
@ -0,0 +1,15 @@
|
|||
import { NgModule } from '@angular/core';
|
||||
import { Routes, RouterModule } from '@angular/router';
|
||||
import { IndexManagmentComponent } from './index-managment.component';
|
||||
import { AdminAuthGuard } from '@app/core/admin-auth-guard.service';
|
||||
|
||||
|
||||
const routes: Routes = [
|
||||
{ path: '', component: IndexManagmentComponent, canActivate: [AdminAuthGuard] },
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [RouterModule.forChild(routes)],
|
||||
exports: [RouterModule]
|
||||
})
|
||||
export class IndexManagmentRoutingModule { }
|
Loading…
Reference in New Issue