Adds delete operation on UI and backend

This commit is contained in:
Ioannis Kalyvas 2019-01-23 14:38:03 +02:00
parent 4845ba84a7
commit 3c629a9c70
6 changed files with 61 additions and 3 deletions

View File

@ -116,7 +116,6 @@ public class DMPs extends BaseController {
}catch (DMPWithDatasetsDeleteException exception){
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DMP>().status(ApiMessageCode.ERROR_MESSAGE).message(exception.getMessage()));
}
}
@RequestMapping(method = RequestMethod.POST, value = {"/dynamic"}, consumes = "application/json", produces = "application/json")

View File

@ -1,20 +1,25 @@
package eu.eudat.controllers;
import eu.eudat.data.entities.DMP;
import eu.eudat.data.query.items.item.datasetprofile.DatasetProfileAutocompleteRequest;
import eu.eudat.data.query.items.table.datasetprofile.DatasetProfileTableRequestItem;
import eu.eudat.exceptions.datamanagementplan.DMPWithDatasetsDeleteException;
import eu.eudat.logic.managers.DatasetProfileManager;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.data.datasetprofile.DatasetProfileAutocompleteItem;
import eu.eudat.models.data.datasetprofile.DatasetProfileListingModel;
import eu.eudat.models.data.helpers.common.DataTableData;
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.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.UUID;
@RestController
@ -47,5 +52,17 @@ public class DatasetProfiles extends BaseController {
List<DatasetProfileListingModel> datasetProfileTableData = DatasetProfileManager.getAll(this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao());
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<DatasetProfileListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(datasetProfileTableData));
}
@Transactional
@RequestMapping(method = RequestMethod.DELETE, value = {"/datasetprofiles/delete/{id}"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<DMP>> delete(@PathVariable UUID id, Principal principal) {
try {
new DatasetProfileManager().delete(this.getApiContext(), id);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Deleted Dataset Profile Plan"));
} catch (DMPWithDatasetsDeleteException exception) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DMP>().status(ApiMessageCode.ERROR_MESSAGE).message(exception.getMessage()));
}
}
}

View File

@ -3,6 +3,8 @@ package eu.eudat.logic.managers;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import eu.eudat.data.dao.entities.DatasetProfileDao;
import eu.eudat.data.entities.DMP;
import eu.eudat.data.entities.Dataset;
import eu.eudat.data.entities.DatasetProfile;
import eu.eudat.data.query.items.item.datasetprofile.DatasetProfileAutocompleteRequest;
import eu.eudat.data.query.items.table.datasetprofile.DatasetProfileTableRequestItem;
@ -81,4 +83,10 @@ public class DatasetProfileManager {
return result;
}
public void delete(ApiContext apiContext, UUID uuid) {
DatasetProfile datasetProfile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(uuid);
datasetProfile.setStatus(DMP.DMPStatus.DELETED.getValue());
apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(datasetProfile);
}
}

View File

@ -68,5 +68,6 @@
</div>
</mat-step>
</mat-horizontal-stepper>
<button mat-raised-button color="primary" type="button" (click)='onSubmit()' [disabled]="!form.valid">Save</button>
<button mat-raised-button color="primary" type="button" (click)='onSubmit()' [disabled]="!form.valid">{{'DATASET-PROFILE.SAVE' | translate}}</button>
<button mat-raised-button *ngIf="!isNew" color="primary" type="button" (click)="openConfirm(form.get('label').value, form.get('id').value)">{{'DATASET-PROFILE.DELETE' | translate}}</button>
</div>

View File

@ -1,4 +1,4 @@
import { AfterViewInit, Component, OnInit, ViewChild } from '@angular/core';
import { AfterViewInit, Component, OnInit, ViewChild, ViewContainerRef } from '@angular/core';
import { FormArray, FormControl, FormGroup } from '@angular/forms';
import { MatDialog, MatHorizontalStepper } from '@angular/material';
import { ActivatedRoute, Router } from '@angular/router';
@ -12,6 +12,7 @@ import { DatasetWizardModel } from '../../models/datasets/DatasetWizardModel';
import { DatasetProfileService } from '../../services/dataset-profile.service';
import { DatasetProfileAdmin } from '../../services/datasetProfileAdmin/datasetProfileAfmin.service';
import { JsonSerializer } from '../../utilities/JsonSerializer';
import { TdDialogService } from '@covalent/core';
@Component({
selector: 'app-form-component',
@ -29,6 +30,7 @@ export class FormComponent extends BaseComponent implements OnInit, AfterViewIni
private profileID: string;
private cloneId: string;
dataWizardModel: DatasetWizardModel;
isNew = true;
@ViewChild('stepper') stepper: MatHorizontalStepper;
constructor(
public datasetprofileAdmin: DatasetProfileAdmin,
@ -36,6 +38,8 @@ export class FormComponent extends BaseComponent implements OnInit, AfterViewIni
private datasetProfileAdminService: DatasetProfileAdmin,
private route: ActivatedRoute,
private router: Router,
private _dialogService: TdDialogService,
private _viewContainerRef: ViewContainerRef,
public dialog: MatDialog,
) {
super();
@ -54,6 +58,7 @@ export class FormComponent extends BaseComponent implements OnInit, AfterViewIni
this.datasetProfileService.getDatasetProfileById(this.profileID)
.pipe(takeUntil(this._destroyed))
.subscribe((data) => {
this.isNew = false;
this.dataModel = JsonSerializer.fromJSONObject(data, DatasetProfileModelAdmin);
this.form = this.dataModel.buildForm();
this.form.valueChanges
@ -74,6 +79,7 @@ export class FormComponent extends BaseComponent implements OnInit, AfterViewIni
this.datasetprofileAdmin.clone(this.cloneId)
.pipe(takeUntil(this._destroyed))
.subscribe((data) => {
this.isNew = false;
this.dataModel = JsonSerializer.fromJSONObject(data, DatasetProfileModelAdmin);
this.form = this.dataModel.buildForm();
this.form.valueChanges
@ -153,4 +159,27 @@ export class FormComponent extends BaseComponent implements OnInit, AfterViewIni
isStepActive(step: number) {
return this.stepper && this.stepper.selectedIndex === step;
}
openConfirm(dmpLabel, id): void {
this._dialogService.openConfirm({
message: 'Are you sure you want to delete the "' + dmpLabel + '"',
disableClose: true || false,
viewContainerRef: this._viewContainerRef,
title: 'Confirm',
cancelButton: 'No',
acceptButton: 'Yes'
}).afterClosed()
.pipe(takeUntil(this._destroyed))
.subscribe((accept: boolean) => {
if (accept) {
this.datasetprofileAdmin.delete(id)
.pipe(takeUntil(this._destroyed))
.subscribe(() => {
this.router.navigate(['/datasets']);
});
} else {
// DO SOMETHING ELSE
}
});
}
}

View File

@ -48,4 +48,8 @@ export class DatasetProfileAdmin {
clone(id: string): Observable<DatasetProfileModelAdmin> {
return this.http.post<DatasetProfileModelAdmin>(environment.Server + 'datasetprofile/clone/' + id, {}, { headers: this.headers });
}
delete(id: string): Observable<DatasetProfileModelAdmin> {
return this.http.delete<DatasetProfileModelAdmin>(environment.Server + 'datasetprofile/delete/' + id, { headers: this.headers });
}
}