Delete Dataset Profile + Status +Error Code

This commit is contained in:
Diamantis Tziotzios 2019-02-25 18:49:26 +02:00
parent 5302024a0b
commit b6c09565c8
4 changed files with 27 additions and 20 deletions

View File

@ -2,7 +2,7 @@ package eu.eudat.controllers;
import eu.eudat.core.logger.Logger;
import eu.eudat.data.query.items.table.datasetprofile.DatasetProfileTableRequestItem;
import eu.eudat.exceptions.datamanagementplan.DMPWithDatasetsDeleteException;
import eu.eudat.exceptions.datasetprofile.DatasetProfileWithDatasetsExeption;
import eu.eudat.logic.managers.AdminManager;
import eu.eudat.logic.managers.DatasetProfileManager;
import eu.eudat.logic.managers.UserManager;
@ -37,7 +37,7 @@ public class Admin extends BaseController {
DatasetProfileManager datasetProfileManager;
@Autowired
public Admin(ApiContext apiContext,DatasetProfileManager datasetProfileManager, Logger logger) {
public Admin(ApiContext apiContext, DatasetProfileManager datasetProfileManager, Logger logger) {
super(apiContext);
this.datasetProfileManager = datasetProfileManager;
}
@ -81,7 +81,7 @@ public class Admin extends BaseController {
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DatasetProfileListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(datasetProfileTableData));
}
@RequestMapping(method = RequestMethod.POST, value = {"/preview"}, consumes = "application/json",produces = "application/json")
@RequestMapping(method = RequestMethod.POST, value = {"/preview"}, consumes = "application/json", produces = "application/json")
public ResponseEntity<ResponseItem<PagedDatasetProfile>> getPreview(@RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) {
eu.eudat.data.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(profile, getApiContext());
eu.eudat.models.data.user.composite.DatasetProfile datasetProfile = UserManager.generateDatasetProfileModel(modelDefinition);
@ -92,34 +92,34 @@ public class Admin extends BaseController {
@org.springframework.transaction.annotation.Transactional
@RequestMapping(method = RequestMethod.POST, value = {"/datasetprofile/clone/{id}"}, consumes = "application/json", produces = "application/json")
public ResponseEntity<ResponseItem<eu.eudat.models.data.admin.composite.DatasetProfile>> clone(@PathVariable String id, @ClaimedAuthorities(claims = {ADMIN})Principal principal) {
public ResponseEntity<ResponseItem<eu.eudat.models.data.admin.composite.DatasetProfile>> clone(@PathVariable String id, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) {
eu.eudat.data.entities.DatasetProfile profile = this.datasetProfileManager.clone(this.getApiContext(), id);
eu.eudat.models.data.admin.composite.DatasetProfile datasetprofile = AdminManager.generateDatasetProfileModel(profile);
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 {
try{
eu.eudat.data.entities.DatasetProfile ret= AdminManager.inactivate(this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao(),this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao() , id);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.models.data.admin.composite.DatasetProfile>().status(ApiMessageCode.SUCCESS_MESSAGE));
}catch (DMPWithDatasetsDeleteException exception) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<eu.eudat.models.data.admin.composite.DatasetProfile>().status(ApiMessageCode.ERROR_MESSAGE).message(exception.getMessage()));
ResponseEntity<ResponseItem<DatasetProfile>> inactivate(@PathVariable String id, Principal principal){
try {
eu.eudat.data.entities.DatasetProfile ret = AdminManager.inactivate(this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao(), this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(), id);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.models.data.admin.composite.DatasetProfile>().status(ApiMessageCode.SUCCESS_MESSAGE));
} catch (DatasetProfileWithDatasetsExeption exception) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<eu.eudat.models.data.admin.composite.DatasetProfile>().status(ApiMessageCode.UNSUCCESS_DELETE).message(exception.getMessage()));
}
}
@Transactional
@RequestMapping(method = RequestMethod.GET, value = {"/getXml/{id}"}, produces = "application/json")
public ResponseEntity getDatasetProfileXml(@PathVariable String id, @RequestHeader("Content-Type") String contentType, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) throws IllegalAccessException, IOException, InstantiationException {
if(contentType.equals("application/xml")){
if (contentType.equals("application/xml")) {
eu.eudat.data.entities.DatasetProfile profile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id));
eu.eudat.models.data.user.composite.DatasetProfile datasetProfile = UserManager.generateDatasetProfileModel(profile);
datasetProfile.setStatus(profile.getStatus());
return this.datasetProfileManager.getDocument(datasetProfile,profile.getLabel());
}else {
return this.datasetProfileManager.getDocument(datasetProfile, profile.getLabel());
} else {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<eu.eudat.models.data.admin.composite.DatasetProfile>().status(ApiMessageCode.ERROR_MESSAGE).message("NOT AUTHORIZE"));
}
}
@ -127,7 +127,7 @@ public class Admin extends BaseController {
@RequestMapping(method = RequestMethod.POST, value = {"/upload"})
public ResponseEntity<Object> setDatasetProfileXml(@RequestParam("file") MultipartFile file,
@ClaimedAuthorities(claims = {ADMIN}) Principal principal) throws IllegalAccessException,IOException{
@ClaimedAuthorities(claims = {ADMIN}) Principal principal) throws IllegalAccessException, IOException {
eu.eudat.logic.utilities.documents.xml.datasetProfileXml.datasetProfileModel.DatasetProfile datasetProfileModel = this.datasetProfileManager.createDatasetProfileFromXml(file);
eu.eudat.models.data.admin.composite.DatasetProfile datasetProfileEntity = datasetProfileModel.toAdminCompositeModel(file.getOriginalFilename());
eu.eudat.data.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(datasetProfileEntity, getApiContext());

View File

@ -1,7 +1,8 @@
package eu.eudat.types;
public enum ApiMessageCode {
NO_MESSAGE(0), SUCCESS_MESSAGE(200), WARN_MESSAGE(300), ERROR_MESSAGE(400), DEFAULT_ERROR_MESSAGE(444),VALIDATION_MESSAGE(445);;
NO_MESSAGE(0), SUCCESS_MESSAGE(200), WARN_MESSAGE(300), ERROR_MESSAGE(400),
DEFAULT_ERROR_MESSAGE(444), VALIDATION_MESSAGE(445), UNSUCCESS_DELETE(674);
private Integer value;
@ -25,6 +26,8 @@ public enum ApiMessageCode {
return ERROR_MESSAGE;
case 444:
return DEFAULT_ERROR_MESSAGE;
case 674:
return UNSUCCESS_DELETE;
default:
throw new RuntimeException("Unsupported Api Message Code");
}

View File

@ -47,8 +47,8 @@ export class DatasetProfileService {
}
delete(id: string, data): Observable<DatasetProfile> {
return this.http.post<DatasetProfile>(this.actionUrl + 'addDmp/' + id, data);
//return this.http.delete<DatasetProfile>(this.actionUrl + id, {});
//return this.http.post<DatasetProfile>(this.actionUrl + 'addDmp/' + id, data);
return this.http.delete<DatasetProfile>(this.actionUrl + id, {});
}

View File

@ -204,7 +204,7 @@ export class DatasetProfileEditorComponent extends BaseComponent implements OnIn
});
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
if (result) {
this.form.get('status').setValue(DatasetProfileEnum.DELETED);
//this.form.get('status').setValue(DatasetProfileEnum.DELETED);
this.datasetProfileService.delete(this.datasetProfileId, this.form.value)
.pipe(takeUntil(this._destroyed))
.subscribe(
@ -214,7 +214,11 @@ export class DatasetProfileEditorComponent extends BaseComponent implements OnIn
},
error => {
this.onCallbackError(error);
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-DATASET-PROFILE-DELETE'), SnackBarNotificationLevel.Success);
if (error.error.statusCode == 674) {
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-DATASET-PROFILE-DELETE'), SnackBarNotificationLevel.Error);
} else {
this.uiNotificationService.snackBarNotification(this.language.instant(error.message), SnackBarNotificationLevel.Error);
}
}
);
}