Added Delete action on Projects , Datasets and Datamanagement Plans

This commit is contained in:
Ioannis Kalyvas 2018-11-30 16:57:20 +02:00
parent 68559314f3
commit 4845ba84a7
21 changed files with 144 additions and 40 deletions

View File

@ -41,6 +41,7 @@ public class DatasetDaoImpl extends DatabaseAccess<Dataset> implements DatasetDa
query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("dmp").get("version"), query.<String>subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.equal(externalRoot.get("dmp").get("groupId"), nestedRoot.get("dmp").get("groupId")), Arrays.asList(new SelectionField(FieldSelectionType.COMPOSITE_FIELD, "dmp:version")), String.class)));
if (criteria.getDmpIds() != null && !criteria.getDmpIds().isEmpty())
query.where((builder, root) -> root.get("dmp").get("id").in(criteria.getDmpIds()));
query.where(((builder, root) -> builder.notEqual(root.get("status"), Dataset.Status.DELETED.getValue())));
return query;
}

View File

@ -17,6 +17,8 @@ import java.util.UUID;
public class DataRepository implements Serializable, DataEntity<DataRepository,UUID> {
@Id
@GeneratedValue
@GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id;

View File

@ -48,7 +48,7 @@ public class DynamicProjectConfigurationDevelImpl implements DynamicProjectConfi
JAXBContext jaxbContext = JAXBContext.newInstance(Configuration.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
is = new URL("file:///"+current + "/web/src/main/resources/ProjectConfiguration.xml").openStream();
is = new URL("file:///"+current + "/dmp-backend/web/src/main/resources/ProjectConfiguration.xml").openStream();
this.configuration = (Configuration) jaxbUnmarshaller.unmarshal(is);
} catch (Exception ex) {
ex.printStackTrace();

View File

@ -7,6 +7,7 @@ import eu.eudat.data.dao.criteria.RequestItem;
import eu.eudat.data.entities.DMP;
import eu.eudat.data.query.items.item.dmp.DataManagementPlanCriteriaRequest;
import eu.eudat.data.query.items.table.dmp.DataManagementPlanTableRequest;
import eu.eudat.exceptions.datamanagementplan.DMPWithDatasetsDeleteException;
import eu.eudat.logic.managers.DataManagementPlanManager;
import eu.eudat.logic.managers.DatasetManager;
import eu.eudat.logic.services.ApiContext;
@ -109,8 +110,13 @@ public class DMPs extends BaseController {
@RequestMapping(method = RequestMethod.DELETE, value = {"/delete/{id}"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<DMP>> delete(@PathVariable UUID id, Principal principal) {
DataManagementPlanManager.delete(this.getApiContext(), id);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Deleted Dataset"));
try{
DataManagementPlanManager.delete(this.getApiContext(), id);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Deleted Datamanagement Plan"));
}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,11 +1,9 @@
package eu.eudat.controllers;
import eu.eudat.data.entities.DMP;
import eu.eudat.data.entities.Dataset;
import eu.eudat.data.query.items.item.dataset.DatasetWizardAutocompleteRequest;
import eu.eudat.data.query.items.item.datasetprofile.DatasetProfileWizardAutocompleteRequest;
import eu.eudat.exceptions.datasetwizard.DatasetWizardCannotUnlockException;
import eu.eudat.logic.managers.DataManagementPlanManager;
import eu.eudat.logic.managers.DatasetManager;
import eu.eudat.logic.managers.DatasetWizardManager;
import eu.eudat.logic.security.claims.ClaimedAuthorities;
@ -28,7 +26,10 @@ import org.springframework.web.bind.annotation.*;
import javax.activation.MimetypesFileTypeMap;
import javax.transaction.Transactional;
import java.io.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.UUID;
@ -125,8 +126,16 @@ public class DatasetWizardController extends BaseController {
try {
new DatasetWizardManager().unlock(this.getApiContext(), id);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Dataset>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Unlocked"));
}catch (DatasetWizardCannotUnlockException datasetWizardCannotUnlockException ){
} catch (DatasetWizardCannotUnlockException datasetWizardCannotUnlockException) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<Dataset>().status(ApiMessageCode.ERROR_MESSAGE).message(datasetWizardCannotUnlockException.getMessage()));
}
}
@Transactional
@RequestMapping(method = RequestMethod.DELETE, value = {"/delete/{id}"}, produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<Dataset>> delete(@PathVariable(value = "id") UUID id, Principal principal) throws Exception {
new DatasetWizardManager().delete(this.getApiContext(), id);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Dataset>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Deleted"));
}
}

View File

@ -3,6 +3,7 @@ package eu.eudat.controllers;
import eu.eudat.data.entities.Project;
import eu.eudat.data.query.items.item.project.ProjectCriteriaRequest;
import eu.eudat.data.query.items.table.project.ProjectTableRequest;
import eu.eudat.exceptions.project.ProjectWithDMPsDeleteException;
import eu.eudat.logic.managers.ProjectManager;
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
@ -25,8 +26,8 @@ import java.io.IOException;
import java.text.ParseException;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import static eu.eudat.types.Authorities.ADMIN;
import static eu.eudat.types.Authorities.ANONYMOUS;
@ -95,5 +96,16 @@ public class Projects extends BaseController {
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ProjectsExternalSourcesModel>().payload(projectsExternalSourcesModel).status(ApiMessageCode.SUCCESS_MESSAGE));
}
@Transactional
@RequestMapping(method = RequestMethod.DELETE, value = {"/delete/{id}"}, produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<Project>> delete(@PathVariable(value = "id") UUID id, Principal principal) throws Exception {
try{
new ProjectManager().delete(this.getApiContext(), id);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Project>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Unlocked"));
}catch (ProjectWithDMPsDeleteException exception){
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Project>().status(ApiMessageCode.ERROR_MESSAGE).message(exception.getMessage()));
}
}
}

View File

@ -0,0 +1,22 @@
package eu.eudat.exceptions.datamanagementplan;
/**
* Created by ikalyvas on 2/5/2018.
*/
public class DMPWithDatasetsDeleteException extends RuntimeException {
public DMPWithDatasetsDeleteException() {
super();
}
public DMPWithDatasetsDeleteException(String message, Throwable cause) {
super(message, cause);
}
public DMPWithDatasetsDeleteException(String message) {
super(message);
}
public DMPWithDatasetsDeleteException(Throwable cause) {
super(cause);
}
}

View File

@ -1,22 +0,0 @@
package eu.eudat.exceptions.datamanagementplan;
/**
* Created by ikalyvas on 2/5/2018.
*/
public class DMPWithDatasetsException extends RuntimeException {
public DMPWithDatasetsException() {
super();
}
public DMPWithDatasetsException(String message, Throwable cause) {
super(message, cause);
}
public DMPWithDatasetsException(String message) {
super(message);
}
public DMPWithDatasetsException(Throwable cause) {
super(cause);
}
}

View File

@ -0,0 +1,22 @@
package eu.eudat.exceptions.project;
/**
* Created by ikalyvas on 11/30/2018.
*/
public class ProjectWithDMPsDeleteException extends RuntimeException {
public ProjectWithDMPsDeleteException() {
super();
}
public ProjectWithDMPsDeleteException(String message, Throwable cause) {
super(message, cause);
}
public ProjectWithDMPsDeleteException(String message) {
super(message);
}
public ProjectWithDMPsDeleteException(Throwable cause) {
super(cause);
}
}

View File

@ -10,7 +10,7 @@ import eu.eudat.data.dao.entities.*;
import eu.eudat.data.entities.*;
import eu.eudat.data.query.items.item.dmp.DataManagementPlanCriteriaRequest;
import eu.eudat.data.query.items.table.dmp.DataManagementPlanTableRequest;
import eu.eudat.exceptions.datamanagementplan.DMPWithDatasetsException;
import eu.eudat.exceptions.datamanagementplan.DMPWithDatasetsDeleteException;
import eu.eudat.exceptions.security.UnauthorisedException;
import eu.eudat.logic.builders.entity.UserInfoBuilder;
import eu.eudat.logic.services.ApiContext;
@ -263,10 +263,10 @@ public class DataManagementPlanManager {
copyDatasets(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao());
}
public static void delete(ApiContext apiContext, UUID uuid) throws DMPWithDatasetsException {
public static void delete(ApiContext apiContext, UUID uuid) throws DMPWithDatasetsDeleteException {
DMP oldDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(uuid);
if (oldDmp.getDataset().size() > 0)
throw new DMPWithDatasetsException("You cannot Remove Datamanagement Plan with Datasets");
throw new DMPWithDatasetsDeleteException("You cannot Remove Datamanagement Plan with Datasets");
oldDmp.setStatus(DMP.DMPStatus.DELETED.getValue());
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(oldDmp);
}

View File

@ -46,4 +46,10 @@ public class DatasetWizardManager {
apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(dataset);
return;
}
public void delete(ApiContext apiContext, UUID uuid) {
Dataset oldDataset = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().find(uuid);
oldDataset.setStatus(DMP.DMPStatus.DELETED.getValue());
apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(oldDataset);
}
}

View File

@ -1,5 +1,6 @@
package eu.eudat.logic.managers;
import eu.eudat.exceptions.project.ProjectWithDMPsDeleteException;
import eu.eudat.logic.builders.entity.ContentBuilder;
import eu.eudat.logic.builders.model.models.ProjectBuilder;
import eu.eudat.data.dao.entities.ContentDao;
@ -125,4 +126,12 @@ public class ProjectManager {
projectEntity.setCreationUser(userInfoRepository.find(principal.getId()));
projectRepository.createOrUpdate(projectEntity);
}
public void delete(ApiContext apiContext, UUID uuid) {
eu.eudat.data.entities.Project oldProject = apiContext.getOperationsContext().getDatabaseRepository().getProjectDao().find(uuid);
if (oldProject.getDmps().size() > 0)
throw new ProjectWithDMPsDeleteException("You cannot Remove Projects with DMPs");
oldProject.setStatus(DMP.DMPStatus.DELETED.getValue());
apiContext.getOperationsContext().getDatabaseRepository().getProjectDao().createOrUpdate(oldProject);
}
}

View File

@ -31,7 +31,7 @@ public class DevelConfigLoader implements ConfigLoader {
JAXBContext jaxbContext = JAXBContext.newInstance(ExternalUrls.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
is = new URL("file:///"+current+"/web/src/main/resources/ExternalUrls.xml").openStream();
is = new URL("file:///"+current+"/dmp-backend/web/src/main/resources/ExternalUrls.xml").openStream();
externalUrls = (ExternalUrls) jaxbUnmarshaller.unmarshal(is);
} catch (Exception ex) {

View File

@ -15,6 +15,8 @@
</button>
</div>
<div *ngIf="this.datasetProfileDefinitionModel || this.datasetWizardModel?.datasetProfileDefinition">
<button mat-raised-button color="primary" *ngIf="!isNew" style="margin-top: 15px;margin-bottom: 15px;margin-right: 15px;"
(click)="openConfirm(formGroup.get('label').value, formGroup.get('id').value)" type="button">{{ 'DATASET-WIZARD.ACTIONS.DELETE' | translate }}</button>
<button mat-raised-button color="primary" *ngIf="datasetWizardModel&&datasetWizardModel?.status != 1 && !viewOnly" style="margin-top: 15px;margin-bottom: 15px;margin-right: 15px;" (click)="save();" type="button">{{
'DATASET-WIZARD.ACTIONS.SAVE' | translate }}</button>
<button mat-raised-button color="primary" *ngIf="datasetWizardModel&&datasetWizardModel?.status != 1 && !viewOnly" style="margin-top: 15px;margin-bottom: 15px;margin-right: 15px;" (click)="saveFinalize();" type="button">{{

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, FormGroup } from '@angular/forms';
import { MatDialog, MatSnackBar, MatStepper } from '@angular/material';
import { ActivatedRoute, Params, Router } from '@angular/router';
@ -41,6 +41,7 @@ import { DataRepositoryReferencedModelHelperComponent } from '../dataset-referen
import { ExternalDatasetReferencedModelHelperComponent } from '../dataset-referenced-models-helper/externalDataset/externaldataset-referenced-model-helper.component';
import { RegistryReferencedModelHelperComponent } from '../dataset-referenced-models-helper/registry/registry-referenced-model-helper.component';
import { ServicesReferencedModelHelperComponent } from '../dataset-referenced-models-helper/services/services-referenced-model-helper.component';
import { TdDialogService } from '@covalent/core';
@Component({
selector: 'app-dataset-wizard-component',
@ -96,6 +97,8 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, Aft
public externalSourcesService: ExternalSourcesService,
public dataManagementPlanService: DataManagementPlanService,
public dialog: MatDialog,
private _dialogService: TdDialogService,
private _viewContainerRef: ViewContainerRef,
public externalSourcesConfigurationService: ExternalSourcesConfigurationService
) {
super();
@ -515,4 +518,27 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, Aft
isActiveStep(index: number) {
return this.stepper.selectedIndex === index;
}
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.datasetWizardService.delete(id)
.pipe(takeUntil(this._destroyed))
.subscribe(() => {
this.router.navigate(['/datasets']);
});
} else {
// DO SOMETHING ELSE
}
});
}
}

View File

@ -40,6 +40,10 @@ export class DatasetWizardService {
return this.http.get<DatasetWizardModel>(this.actionUrl + 'getSingle/' + id, { headers: this.headers });
}
public delete(id: string): Observable<DatasetWizardModel> {
return this.http.delete<DatasetWizardModel>(this.actionUrl + 'delete/' + id, { headers: this.headers });
}
createDataset(datasetModel: DatasetWizardModel): Observable<DatasetWizardModel> {
return this.http.post<DatasetWizardModel>(this.actionUrl + 'createOrUpdate', datasetModel, { headers: this.headers });
}

View File

@ -50,4 +50,8 @@ export class ProjectService {
inactivate(id: String): Observable<ProjectModel> {
return this.http.delete<ProjectModel>(this.actionUrl + 'inactivate/' + id, { headers: this.headers });
}
public delete(id: string): Observable<ProjectModel> {
return this.http.delete<ProjectModel>(this.actionUrl + 'delete' + id, { headers: this.headers });
}
}

View File

@ -80,6 +80,6 @@ export class DataManagementPlanCriteriaComponent extends BaseCriteriaComponent i
const projectRequestItem: RequestItem<ProjectCriteria> = new RequestItem();
projectRequestItem.criteria = new ProjectCriteria();
projectRequestItem.criteria.like = query;
return this.projectService.getWithExternal(projectRequestItem);
return this.projectService.get(projectRequestItem);
}
}

View File

@ -9,9 +9,9 @@
<div>
<div class="card-form">
<div class="form-row">
<i class="material-icons">email</i>
<i class="material-icons">person</i>
<mat-form-field color="accent">
<input type="text" [(ngModel)]="credential.username" matInput placeholder="Email address" />
<input type="text" [(ngModel)]="credential.username" matInput placeholder="Username" />
</mat-form-field>
</div>
<div class="form-row">

View File

@ -88,7 +88,7 @@
width: 100%;
padding: 25px;
border-radius: 3px;
background: linear-gradient(60deg, #aeb5b4, #9d9799);
background: linear-gradient(60deg, #ec407a, #d81b60);
box-shadow: 0 4px 20px 0px rgba(0, 0, 0, 0.14), 0 7px 10px -5px rgba(49, 46, 47, 0.4);
display: flex;
flex-direction: column;
@ -144,5 +144,5 @@
}
.card-footer button {
color: #0c0b0b;
color: #e91e63;
}

View File

@ -100,6 +100,7 @@
"ACTIONS": {
"NEXT": "Next",
"BACK": "Back",
"DELETE": "Delete",
"GO-TO-PROJECT": "Go to Dataset Project",
"GO-TO-DMP": "Go to Dataset DMP",
"SAVE": "Save",