Create Delete EndPoind And Button ForDataset Profiles

This commit is contained in:
Diamantis Tziotzios 2019-02-06 13:10:44 +02:00
parent 86ae8e5eda
commit f3e8d20e37
13 changed files with 128 additions and 10 deletions

View File

@ -15,6 +15,7 @@ public class DatasetCriteria extends Criteria<Dataset> {
private List<UUID> dmpIds;
private List<Tag> tags;
private boolean allVersions;
private UUID profileDatasetId;
public boolean getAllVersions() {
@ -64,4 +65,12 @@ public class DatasetCriteria extends Criteria<Dataset> {
public void setTags(List<Tag> tags) {
this.tags = tags;
}
public UUID getProfileDatasetId() {
return profileDatasetId;
}
public void setProfileDatasetId(UUID profileDatasetId) {
this.profileDatasetId = profileDatasetId;
}
}

View File

@ -33,6 +33,8 @@ public class DatasetDaoImpl extends DatabaseAccess<Dataset> implements DatasetDa
builder.like(builder.upper(root.get("description")), "%" + criteria.getLike().toUpperCase() + "%")));
if (criteria.getStatus() != null)
query.where((builder, root) -> builder.equal(root.get("status"), criteria.getStatus()));
if (criteria.getProfileDatasetId() != null)
query.where((builder, root) -> builder.equal(root.get("profile").get("id"), criteria.getProfileDatasetId()));
if (criteria.getPeriodEnd() != null)
query.where((builder, root) -> builder.lessThan(root.get("created"), criteria.getPeriodEnd()));
if (criteria.getPeriodStart() != null)

View File

@ -25,6 +25,7 @@ public class DatasetProfileDaoImpl extends DatabaseAccess<DatasetProfile> implem
QueryableList<DatasetProfile> query = getDatabaseService().getQueryable(DatasetProfile.class);
if (criteria.getLike() != null && !criteria.getLike().isEmpty())
query.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + criteria.getLike().toUpperCase() + "%"));
query.where(((builder, root) -> builder.notEqual(root.get("status"), DatasetProfile.Status.DELETED.getValue())));
return query;
}

View File

@ -17,6 +17,33 @@ import java.util.UUID;
@Table(name = "\"DatasetProfile\"")
public class DatasetProfile implements DataEntity<DatasetProfile,UUID> {
public enum Status {
ACTIVE((short) 1), INACTIVE((short) 0), DELETED((short) 99);
private short value;
private Status(short value) {
this.value = value;
}
public short getValue() {
return value;
}
public static Status fromInteger(int value) {
switch (value) {
case 0:
return INACTIVE;
case 1:
return ACTIVE;
case 99:
return DELETED;
default:
throw new RuntimeException("Unsupported Dataset Profile Status");
}
}
}
@Id
@GeneratedValue
@GenericGenerator(name = "uuid2", strategy = "uuid2")

View File

@ -90,4 +90,17 @@ public class Admin extends BaseController {
datasetprofile.setLabel(profile.getLabel() + " new ");
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.models.data.admin.composite.DatasetProfile>().payload(datasetprofile));
}
@Transactional
@RequestMapping(method = RequestMethod.DELETE, value = {"{id}"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<DatasetProfile>> inactivate(@PathVariable String id, Principal principal) throws IllegalAccessException, InstantiationException {
eu.eudat.data.entities.DatasetProfile ret= AdminManager.inactivate(this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao(),this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao() , id);
if(ret!=null){
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.models.data.admin.composite.DatasetProfile>().status(ApiMessageCode.SUCCESS_MESSAGE));
}else {
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(new ResponseItem<eu.eudat.models.data.admin.composite.DatasetProfile>().status(ApiMessageCode.SUCCESS_MESSAGE));
}
}
}

View File

@ -1,9 +1,9 @@
package eu.eudat.controllers;
import eu.eudat.data.dao.criteria.RequestItem;
import eu.eudat.data.entities.Project;
import eu.eudat.logic.managers.AdminManager;
import eu.eudat.logic.managers.DatasetProfileManager;
import eu.eudat.logic.managers.UserManager;
import eu.eudat.logic.security.claims.ClaimedAuthorities;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.data.components.commons.datafield.AutoCompleteData;
@ -12,8 +12,6 @@ import eu.eudat.models.data.helpers.common.AutoCompleteLookupItem;
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.models.data.properties.PropertiesModel;
import eu.eudat.models.data.security.Principal;
import eu.eudat.models.data.user.composite.DatasetProfile;
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
import eu.eudat.types.ApiMessageCode;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
@ -29,7 +27,6 @@ import java.util.Map;
import java.util.UUID;
import static eu.eudat.types.Authorities.ADMIN;
import static eu.eudat.types.Authorities.ANONYMOUS;
@RestController
@CrossOrigin
@ -74,4 +71,5 @@ public class DatasetProfileController extends BaseController {
List<Tuple<String, String>> items = this.datasetProfileManager.getAutocomplete(data, lookupItem.getCriteria().getLike());
return ResponseEntity.status(HttpStatus.OK).body(items);
}
}

View File

@ -1,5 +1,7 @@
package eu.eudat.logic.managers;
import eu.eudat.data.dao.entities.DatasetDao;
import eu.eudat.data.dao.entities.DatasetProfileDao;
import eu.eudat.logic.builders.entity.DatasetProfileBuilder;
import eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.ViewStyleModel;
import eu.eudat.models.data.admin.composite.DatasetProfile;
@ -10,6 +12,7 @@ import org.w3c.dom.Document;
import org.w3c.dom.Element;
import java.util.Date;
import java.util.UUID;
public class AdminManager {
@ -38,4 +41,18 @@ public class AdminManager {
datasetprofile.buildProfile(viewstyle);
return datasetprofile;
}
public static eu.eudat.data.entities.DatasetProfile inactivate(DatasetProfileDao datasetProfileRepository, DatasetDao datasetDao, String id) {
eu.eudat.data.dao.criteria.DatasetCriteria datasetsForThatDatasetProfile = new eu.eudat.data.dao.criteria.DatasetCriteria();
datasetsForThatDatasetProfile.setProfileDatasetId(UUID.fromString(id));
if ((datasetDao.getWithCriteria(datasetsForThatDatasetProfile).toList()).size() == 0) {
eu.eudat.data.entities.DatasetProfile detasetProfile = datasetProfileRepository.find(UUID.fromString(id));
detasetProfile.setStatus(eu.eudat.data.entities.DatasetProfile.Status.DELETED.getValue());
detasetProfile = datasetProfileRepository.createOrUpdate(detasetProfile);
return detasetProfile;
}
return null;
}
}

View File

@ -81,5 +81,4 @@ public class DatasetProfileManager {
jsonItems.forEach(item -> result.add(new Tuple<>(item.get(data.getAutoCompleteOptions().getValue()), item.get(data.getAutoCompleteOptions().getLabel()))));
return result;
}
}

View File

@ -41,4 +41,9 @@ export class DatasetProfileService {
clone(id: string): Observable<DatasetProfile> {
return this.http.post<DatasetProfile>(this.actionUrl + 'datasetprofile/clone/' + id, {});
}
delete(id: string): Observable<DatasetProfile> {
return this.http.delete<DatasetProfile>(this.actionUrl + id, {});
}
}

View File

@ -20,13 +20,15 @@ import { DatasetProfileEditorSectionComponent } from './editor/components/sectio
import { DatasetProfileEditorComponent } from './editor/dataset-profile-editor.component';
import { DatasetProfileCriteriaComponent } from './listing/criteria/dataset-profile.component';
import { DatasetProfileListingComponent } from './listing/dataset-profile-listing.component';
import { ConfirmationDialogModule } from '../../../library/confirmation-dialog/confirmation-dialog.module';
@NgModule({
imports: [
CommonUiModule,
CommonFormsModule,
FormattingModule,
DatasetProfileRoutingModule
DatasetProfileRoutingModule,
ConfirmationDialogModule,
],
declarations: [
DatasetProfileListingComponent,

View File

@ -42,5 +42,15 @@
</div>
</mat-step> -->
</mat-horizontal-stepper>
<button mat-raised-button color="primary" type="button" (click)='onSubmit()' [disabled]="!form.valid">Save</button>
<div class="row">
<!-- SAVE BUTTON -->
<button mat-raised-button color="primary" type="button col-auto" (click)='onSubmit()' [disabled]="!form.valid">Save</button>
<div class="col"></div>
<!-- DELETE BUTTON -->
<div class="col-auto" *ngIf="!isNew">
<button mat-raised-button (click)="delete()">
<mat-icon>delete</mat-icon>{{'DATASET-PROFILE-EDITOR.ACTIONS.DELETE' | translate}}
</button>
</div>
</div>
</div>

View File

@ -1,7 +1,7 @@
import { HttpErrorResponse } from '@angular/common/http';
import { Component, OnInit, ViewChild } from '@angular/core';
import { FormArray, FormControl, FormGroup } from '@angular/forms';
import { MatHorizontalStepper } from '@angular/material';
import { MatHorizontalStepper, MatDialog } from '@angular/material';
import { ActivatedRoute, ParamMap, Router } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { map, takeUntil } from 'rxjs/operators';
@ -14,6 +14,7 @@ import { SnackBarNotificationLevel, UiNotificationService } from '../../../../co
import { PageEditorModel } from '../admin/page-editor-model';
import { SectionEditorModel } from '../admin/section-editor-model';
import { DatasetProfileEditorModel } from './dataset-profile-editor-model';
import { ConfirmationDialogComponent } from '../../../../library/confirmation-dialog/confirmation-dialog.component';
@Component({
selector: 'app-dataset-profile-editor-component',
@ -31,13 +32,15 @@ export class DatasetProfileEditorComponent extends BaseComponent implements OnIn
dataWizardModel: DatasetWizardModel;
@ViewChild('stepper') stepper: MatHorizontalStepper;
constructor(
private datasetProfileService: DatasetProfileService,
private route: ActivatedRoute,
private router: Router,
private logger: LoggingService,
private uiNotificationService: UiNotificationService,
private language: TranslateService
private language: TranslateService,
private dialog: MatDialog
) {
super();
// this.profileID = route.snapshot.params['id'];
@ -170,4 +173,34 @@ export class DatasetProfileEditorComponent extends BaseComponent implements OnIn
this.uiNotificationService.snackBarNotification(errorResponse.message, SnackBarNotificationLevel.Warning);
// }
}
// DELETE Function
public delete(): void {
if (this.datasetProfileId && !this.isNew) {
const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
data: {
message: this.language.instant('GENERAL.CONFIRMATION-DIALOG.DELETE-ITEM'),
confirmButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CONFIRM'),
cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL')
}
});
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
if (result) {
this.datasetProfileService.delete(this.datasetProfileId)
.pipe(takeUntil(this._destroyed))
.subscribe(
complete => {
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-DATASET-PROFILE-DELETE'), SnackBarNotificationLevel.Success);
this.router.navigate(['/dataset-profiles']);
},
error => {
this.onCallbackError(error);
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-DATASET-PROFILE-DELETE'), SnackBarNotificationLevel.Success);
}
);
}
});
}
}
}

View File

@ -17,7 +17,9 @@
"SUCCESSFUL-LOGIN": "Successful Login",
"SUCCESSFUL-LOGOUT": "Successful Logout",
"UNSUCCESSFUL-LOGOUT": "Unsuccessful Logout",
"UNSUCCESSFUL-LOGIN": "Unsuccessful Login"
"UNSUCCESSFUL-LOGIN": "Unsuccessful Login",
"SUCCESSFUL-DATASET-PROFILE-DELETE":"Successful Delete this Profile",
"UNSUCCESSFUL-DATASET-PROFILE-DELETE":"Unsuccessful This Profile can not Delete"
},
"ERRORS": {
"HTTP-REQUEST-ERROR": "An Unexpected Error Has Occured"