cleanup unused code

This commit is contained in:
Bernaldo Mihasi 2023-02-21 11:41:07 +02:00
parent 8b34d55706
commit e22e348330
5 changed files with 2 additions and 180 deletions

View File

@ -9,12 +9,10 @@ import eu.eudat.data.entities.DMP;
import eu.eudat.data.entities.Dataset; import eu.eudat.data.entities.Dataset;
import eu.eudat.data.query.items.table.datasetprofile.DatasetProfileTableRequestItem; import eu.eudat.data.query.items.table.datasetprofile.DatasetProfileTableRequestItem;
import eu.eudat.data.query.items.table.dmp.DataManagementPlanTableRequest; import eu.eudat.data.query.items.table.dmp.DataManagementPlanTableRequest;
import eu.eudat.data.query.items.table.dmp.DataManagmentPlanPublicTableRequest;
import eu.eudat.exceptions.datamanagementplan.DMPNewVersionException; import eu.eudat.exceptions.datamanagementplan.DMPNewVersionException;
import eu.eudat.exceptions.datamanagementplan.DMPWithDatasetsDeleteException; import eu.eudat.exceptions.datamanagementplan.DMPWithDatasetsDeleteException;
import eu.eudat.exceptions.security.UnauthorisedException; import eu.eudat.exceptions.security.UnauthorisedException;
import eu.eudat.logic.managers.DataManagementPlanManager; import eu.eudat.logic.managers.DataManagementPlanManager;
import eu.eudat.logic.managers.DatasetManager;
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader; import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
import eu.eudat.logic.security.claims.ClaimedAuthorities; import eu.eudat.logic.security.claims.ClaimedAuthorities;
import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.ApiContext;
@ -152,7 +150,7 @@ public class DMPs extends BaseController {
@RequestMapping(method = RequestMethod.GET, value = {"/publicOverview/{id}"}) @RequestMapping(method = RequestMethod.GET, value = {"/publicOverview/{id}"})
public @ResponseBody public @ResponseBody
ResponseEntity getOverviewSinglePublic(@PathVariable String id, @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) throws Exception { ResponseEntity<ResponseItem<DataManagementPlanOverviewModel>> getOverviewSinglePublic(@PathVariable String id, @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) throws Exception {
// try { // try {
DataManagementPlanOverviewModel dataManagementPlan = this.dataManagementPlanManager.getOverviewSingle(id, principal, true); DataManagementPlanOverviewModel dataManagementPlan = this.dataManagementPlanManager.getOverviewSingle(id, principal, true);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlanOverviewModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlanOverviewModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan));
@ -321,21 +319,6 @@ public class DMPs extends BaseController {
} }
} }
/*
* DOI Generation
* */
@RequestMapping(method = RequestMethod.POST, value = {"/createZenodoDoi/{id}"})
public ResponseEntity<ResponseItem<String>> createZenodoDoi(@PathVariable String id, Principal principal) {
try {
String zenodoDOI = this.dataManagementPlanManager.createZenodoDoi(UUID.fromString(id), principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<String>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully created DOI for Data Datamanagement Plan in question.").payload(zenodoDOI));
} catch (Exception e) {
logger.error(e.getMessage(), e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<String>().status(ApiMessageCode.ERROR_MESSAGE).message("Failed to create DOI for the Data Management Plan: " + e.getMessage()));
}
}
/* /*
* Data Index * Data Index
* */ * */

View File

@ -117,7 +117,7 @@ public class Datasets extends BaseController {
@RequestMapping(method = RequestMethod.GET, value = {"/publicOverview/{id}"}) @RequestMapping(method = RequestMethod.GET, value = {"/publicOverview/{id}"})
public @ResponseBody public @ResponseBody
ResponseEntity getOverviewSinglePublic(@PathVariable String id, @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) throws Exception { ResponseEntity<ResponseItem<DatasetOverviewModel>> getOverviewSinglePublic(@PathVariable String id, @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) throws Exception {
// try { // try {
DatasetOverviewModel dataset = this.datasetManager.getOverviewSingle(id, principal, true); DatasetOverviewModel dataset = this.datasetManager.getOverviewSingle(id, principal, true);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetOverviewModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataset)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetOverviewModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataset));

View File

@ -1064,9 +1064,6 @@ public class DataManagementPlanManager {
}); });
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId()); UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
sendNotification(dmp, user, NotificationType.DMP_PUBLISH); sendNotification(dmp, user, NotificationType.DMP_PUBLISH);
// if (dmp.getDois() != null && !dmp.getDois().isEmpty()) {
// this.createZenodoDoi(dmp.getId(), principal, true);
// }
} }
@Transactional @Transactional
@ -2067,74 +2064,6 @@ public class DataManagementPlanManager {
} }
} }
public String createZenodoDoi(UUID id, Principal principal) throws Exception {
return this.createZenodoDoi(id, principal, false);
}
public String createZenodoDoi(UUID id, Principal principal, boolean update) throws Exception {
DMP dmp = this.apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(id);
if (!isUserOwnerOfDmp(dmp, principal))
throw new Exception("User is not authorized to invoke this action");
if (!dmp.getStatus().equals(DMP.DMPStatus.FINALISED.getValue()))
throw new Exception("DMP is not finalized");
/*if (dmp.getDoi() != null)
throw new Exception("DMP already has a DOI");*/
FileEnvelope file = getWordDocument(id.toString(), principal, configLoader);
String name = file.getFilename().substring(0, file.getFilename().length() - 5);
File pdfFile = PDFUtils.convertToPDF(file, environment);
String fileName = name + ".pdf";
ResponseEntity<byte[]> jsonFile;
try {
jsonFile = getRDAJsonDocument(id.toString(), principal);
} catch (Exception e) {
throw e;
}
String previousDOI = this.getPreviousDOI(dmp.getGroupId(), dmp.getId(), "Zenodo");
File supportingFilesZip = this.createSupportingFilesZip(dmp);
DMPDepositModel dmpDepositModel = DMPToDepositMapper.fromDMP(dmp, pdfFile, fileName, jsonFile, supportingFilesZip, previousDOI);
String zenodoToken = "";
try {
if (this.userManager.isDOITokenValid(principal)) {
zenodoToken = principal.getZenodoToken();
}
} catch (NonValidTokenException e) {
zenodoToken = this.environment.getProperty("zenodo.access_token");
}
String finalDoi = null;
for(RepositoryDeposit repo: this.repositoriesDeposit) { //temp
if(repo.getConfiguration().getRepositoryId().equals("Zenodo")) {
finalDoi = repo.deposit(dmpDepositModel, zenodoToken);
if (finalDoi != null) {
EntityDoi doiEntity = new EntityDoi();
doiEntity.setId(UUID.randomUUID());
doiEntity.setEntityType(EntityDoi.EntityType.DMP);
doiEntity.setDoi(finalDoi);
doiEntity.setRepositoryId("Zenodo");
Date now = new Date();
doiEntity.setCreatedAt(now);
doiEntity.setUpdatedAt(now);
doiEntity.setEntityId(dmp);
apiContext.getOperationsContext().getDatabaseRepository().getEntityDoiDao().createOrUpdate(doiEntity);
dmp.getDois().add(doiEntity);
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(dmp);
}
}
}
if(supportingFilesZip != null) {
Files.deleteIfExists(supportingFilesZip.toPath());
}
Files.deleteIfExists(pdfFile.toPath());
Files.deleteIfExists(file.getFile().toPath());
return finalDoi;
}
public Doi createDoi(DepositRequest depositRequest, Principal principal) throws Exception { public Doi createDoi(DepositRequest depositRequest, Principal principal) throws Exception {
DMP dmp = this.apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(UUID.fromString(depositRequest.getDmpId())); DMP dmp = this.apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(UUID.fromString(depositRequest.getDmpId()));
if (!isUserOwnerOfDmp(dmp, principal)) if (!isUserOwnerOfDmp(dmp, principal))

View File

@ -114,10 +114,6 @@ export class DmpService {
return this.http.post<DmpModel>(`${this.actionUrl}updateusers/${id}`, users, { headers: this.headers }); return this.http.post<DmpModel>(`${this.actionUrl}updateusers/${id}`, users, { headers: this.headers });
} }
getDoi(id: string): Observable<string> {
return this.http.post<string>(this.actionUrl + 'createZenodoDoi/' + id, { headers: this.headers });
}
getDynamicField(requestItem: RequestItem<DynamicFieldGrantCriteria>): any { getDynamicField(requestItem: RequestItem<DynamicFieldGrantCriteria>): any {
return this.http.post<any>(this.actionUrl + 'dynamic', requestItem, { headers: this.headers }); return this.http.post<any>(this.actionUrl + 'dynamic', requestItem, { headers: this.headers });
} }

View File

@ -838,90 +838,4 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit {
// return url; // return url;
// } // }
// getDoi(dmp: DmpOverviewModel) {
// this.userService.hasDOIToken().subscribe(response => {
// this.hasDOIToken = true;
// this.showConfirmationDOIDialog(dmp);
// }, error => {
// this.hasDOIToken = false;
// this.showErrorConfirmationDOIDialog(error.error.message, dmp);
// });
// }
// showConfirmationDOIDialog(dmp: DmpOverviewModel) {
// const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
// maxWidth: '600px',
// restoreFocus: false,
// data: {
// message: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ZENODO-DOI', { 'username': this.hasDOIToken ? this.authentication.current().zenodoEmail : 'default' }),
// 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.dmpService.getDoi(dmp.id)
// .pipe(takeUntil(this._destroyed))
// .subscribe(
// complete => {
// this.onDOICallbackSuccess();
// this.dmp.doi = complete;
// },
// error => this.onDeleteCallbackError(error)
// );
// }
// });
// }
// showErrorConfirmationDOIDialog(message: string, dmp: DmpOverviewModel) {
// const dialogRef = this.dialog.open(MultipleChoiceDialogComponent, {
// maxWidth: '600px',
// restoreFocus: false,
// data: {
// message: message ? this.language.instant(message) : this.language.instant('GENERAL.ERRORS.HTTP-REQUEST-ERROR'),
// titles: [this.language.instant('DMP-OVERVIEW.MULTIPLE-DIALOG.ZENODO-LOGIN'), this.language.instant('DMP-OVERVIEW.MULTIPLE-DIALOG.USE-DEFAULT')]
// }
// });
// dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
// switch (result) {
// case 0:
// // this.authentication.logout();
// // this.router.navigate(['/login/external/zenodo']);
// this.showOauth2Dialog(this.getAccessUrl(), dmp);
// break;
// case 1:
// this.showConfirmationDOIDialog(dmp);
// break;
// }
// });
// }
// showOauth2Dialog(url: string, dmp: DmpOverviewModel) {
// this.oauth2DialogService.login(url)
// .pipe(takeUntil(this._destroyed))
// .subscribe(result => {
// if (result !== undefined) {
// if (result.oauthCode !== undefined && result.oauthCode !== null && !this.oauthLock) {
// this.userService.registerDOIToken(result.oauthCode, this.configurationService.app + 'oauth2')
// .pipe(takeUntil(this._destroyed))
// .subscribe(() => {
// this.hasDOIToken = true;
// this.showConfirmationDOIDialog(dmp);
// });
// this.oauthLock = true;
// }
// } else {
// this.oauthLock = false;
// }
// });
// }
// onDOICallbackSuccess(): void {
// this.uiNotificationService.snackBarNotification(this.language.instant('DMP-EDITOR.SNACK-BAR.SUCCESSFUL-DOI'), SnackBarNotificationLevel.Success);
// }
// onDOICallbackError(error) {
// this.uiNotificationService.snackBarNotification(error.error.message ? error.error.message : this.language.instant('DMP-EDITOR.SNACK-BAR.UNSUCCESSFUL-DOI'), SnackBarNotificationLevel.Error);
// }
} }