code cleanup

This commit is contained in:
Efstratios Giannopoulos 2024-01-03 16:21:39 +02:00
parent 71343c51e5
commit b87612c783
14 changed files with 20 additions and 368 deletions

View File

@ -109,6 +109,8 @@ public class AuditableAction {
public static final EventId Lock_Lookup = new EventId(17001, "Lock_Lookup");
public static final EventId Lock_Persist = new EventId(17002, "Lock_Persist");
public static final EventId Lock_Delete = new EventId(17003, "Lock_Delete");
public static final EventId Lock_IsLocked = new EventId(17004, "Lock_IsLocked");
public static final EventId Lock_UnLocked = new EventId(17005, "Lock_UnLocked");
public static final EventId Deposit_GetAvailableRepositories = new EventId(18000, "Deposit_GetAvailableRepositories");
public static final EventId Deposit_GetAccessToken = new EventId(18001, "Deposit_GetAccessToken");

View File

@ -1,60 +0,0 @@
//TODO
//package eu.eudat.controllers;
//
//import eu.eudat.elastic.criteria.DatasetCriteria;
//import eu.eudat.elastic.entities.Dataset;
//import eu.eudat.elastic.entities.Tag;
//import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
//import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
//import eu.eudat.logic.services.ApiContext;
//import eu.eudat.logic.utilities.helpers.StreamDistinctBy;
//import eu.eudat.models.data.helpers.responses.ResponseItem;
//import eu.eudat.types.ApiMessageCode;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.core.env.Environment;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.ResponseEntity;
//import org.springframework.web.bind.annotation.*;
//
//import java.io.IOException;
//import java.util.Collection;
//import java.util.List;
//import java.util.concurrent.ExecutionException;
//import java.util.stream.Collectors;
//
///**
// * Created by ikalyvas on 7/5/2018.
// */
//@RestController
//@CrossOrigin
//@RequestMapping(value = {"/api"})
//public class TagController extends BaseController {
//
//// private Repository<Dataset, TagCriteria> datasetRepository;
// private Environment environment;
//
// @Autowired
// public TagController(ApiContext apiContext, /*Repository tagRepository, */Environment environment) {
// super(apiContext);
//// this.datasetRepository = tagRepository;
// this.environment = environment;
// }
//
// @RequestMapping(method = RequestMethod.GET, value = {"/external/tags"}, produces = "application/json")
// public @ResponseBody
// ResponseEntity<ResponseItem<List<Tag>>> listExternalTagModel(
// @RequestParam(value = "query", required = false) String query, @RequestParam(value = "type", required = false) String type) throws HugeResultSet, NoURLFound, IOException, ExecutionException, InterruptedException {
// //ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query);
// /*List<Map<String, String>> remoteRepos = this.getApiContext().getOperationsContext().getRemoteFetcher().getTags(externalUrlCriteria, type);
// TagExternalSourcesModel researchersExternalSourcesModel = new TagExternalSourcesModel().fromExternalItem(remoteRepos);*/
// if (this.getApiContext().getOperationsContext().getElasticRepository().getDatasetRepository().exists()) {
// DatasetCriteria criteria = new DatasetCriteria();
// criteria.setHasTags(true);
// List<Tag> tags = this.getApiContext().getOperationsContext().getElasticRepository().getDatasetRepository().query(criteria).stream().map(Dataset::getTags).flatMap(Collection::stream).filter(StreamDistinctBy.distinctByKey(Tag::getId)).filter(tag -> tag.getName().toLowerCase().startsWith(query.toLowerCase())).collect(Collectors.toList());
//
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Tag>>().payload(tags).status(ApiMessageCode.NO_MESSAGE));
// } else {
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new ResponseItem<List<Tag>>().status(ApiMessageCode.ERROR_MESSAGE).message("Elastic Services are not available"));
// }
// }
//}

View File

@ -1,131 +0,0 @@
//package eu.eudat.controllers;
//
//import eu.eudat.authorization.Permission;
//import eu.eudat.commons.scope.user.UserScope;
//import eu.eudat.data.query.items.table.userinfo.UserInfoTableRequestItem;
//import eu.eudat.logic.managers.UserManager;
//import eu.eudat.logic.services.ApiContext;
//import eu.eudat.models.data.helpers.common.DataTableData;
//import eu.eudat.models.data.helpers.responses.ResponseItem;
//import eu.eudat.models.data.userinfo.UserCredential;
//import eu.eudat.models.data.userinfo.UserListingModel;
//import eu.eudat.models.data.userinfo.UserProfile;
//import eu.eudat.types.ApiMessageCode;
//import gr.cite.commons.web.authz.service.AuthorizationService;
//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 jakarta.validation.Valid;
//
//import javax.management.InvalidApplicationException;
//import java.io.IOException;
//import java.util.List;
//import java.util.Map;
//import java.util.UUID;
//
//
//
//@RestController
//@CrossOrigin
//@RequestMapping(value = "api/user")
//public class Users extends BaseController {
//
// private UserManager userManager;
// private final AuthorizationService authorizationService;
// private final UserScope userScope;
//
// @Autowired
// public Users(ApiContext apiContext, UserManager userManager, AuthorizationService authorizationService, UserScope userScope) {
// super(apiContext);
// this.userManager = userManager;
// this.authorizationService = authorizationService;
// this.userScope = userScope;
// }
//
//// @RequestMapping(method = RequestMethod.POST, value = {"/getPaged"}, consumes = "application/json", produces = "application/json")
//// public @ResponseBody
//// ResponseEntity<ResponseItem<DataTableData<UserListingModel>>> getPaged(@Valid @RequestBody UserInfoTableRequestItem userInfoTableRequestItem) throws Exception {
//// this.authorizationService.authorizeForce(Permission.AdminRole);
////
//// DataTableData<UserListingModel> dataTable = userManager.getPaged(userInfoTableRequestItem);
//// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<UserListingModel>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
//// }
//
// @Transactional
// @RequestMapping(method = RequestMethod.POST, value = {"/updateRoles"}, consumes = "application/json", produces = "application/json")
// public @ResponseBody
// ResponseEntity<ResponseItem<UserListingModel>> updateRoles(@Valid @RequestBody UserListingModel userListingModel) throws InvalidApplicationException {
// this.authorizationService.authorizeForce(Permission.AdminRole);
//
// userManager.editRoles(userListingModel);
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UserListingModel>().status(ApiMessageCode.NO_MESSAGE));
// }
//
//// @RequestMapping(method = RequestMethod.GET, value = {"/{id}"}, produces = "application/json")
//// public @ResponseBody
//// ResponseEntity<ResponseItem<UserProfile>> get(@PathVariable String id) throws Exception {
//// this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
////
//// UUID userId = id.equals("me") ? this.userScope.getUserId() : UUID.fromString(id);
//// UserProfile user = userManager.getSingle(userId);
//// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UserProfile>().payload(user).status(ApiMessageCode.NO_MESSAGE));
//// }
//
//// @RequestMapping(method = RequestMethod.GET, value = {"/{id}/emails"}, produces = "application/json")
//// public @ResponseBody
//// ResponseEntity<ResponseItem<List<UserCredential>>> getEmails(@PathVariable String id) throws Exception {
//// this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
////
//// UUID userId = id.equals("me") ? this.userScope.getUserId() : UUID.fromString(id);
//// List<UserCredential> user = userManager.getCredentials(userId);
//// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<UserCredential>>().payload(user).status(ApiMessageCode.NO_MESSAGE));
//// }
//
//// @Transactional
//// @RequestMapping(method = RequestMethod.POST, value = {"/settings"}, produces = "application/json")
//// public @ResponseBody
//// ResponseEntity<ResponseItem<UserProfile>> saveSettings(@RequestBody Map<String, Object> settings) throws IOException, InvalidApplicationException {
//// this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
////
//// userManager.updateSettings(settings);
//// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UserProfile>().status(ApiMessageCode.NO_MESSAGE));
//// }
//
//// @RequestMapping(method = RequestMethod.POST, value = {"/getCollaboratorsPaged"}, consumes = "application/json", produces = "application/json")
//// public @ResponseBody
//// ResponseEntity<ResponseItem<DataTableData<UserListingModel>>> getCollaboratorsPaged(@Valid @RequestBody UserInfoTableRequestItem userInfoTableRequestItem) throws Exception {
//// this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
////
//// DataTableData<UserListingModel> dataTable = userManager.getCollaboratorsPaged(userInfoTableRequestItem);
//// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<UserListingModel>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
//// }
//
//// @RequestMapping(method = RequestMethod.GET, value = {"/getCsv"})
//// public @ResponseBody
//// ResponseEntity exportCsv() throws Exception {
//// return userManager.exportToCsv();
//// }
//
//// @RequestMapping(method = RequestMethod.POST, value = {"/find"}, consumes = "application/json", produces = "application/json")
//// public @ResponseBody
//// ResponseEntity<ResponseItem<UserProfile>> find(@Valid @RequestBody String email) throws Exception {
//// this.authorizationService.authorizeForce(Permission.PublicRole);
//// UserProfile userProfile = userManager.getFromEmail(email);
//// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UserProfile>().payload(userProfile).status(ApiMessageCode.NO_MESSAGE));
//// }
//
//}
//
//
//
//
//
//
//
//
//
//
//

View File

@ -2,7 +2,6 @@ package eu.eudat.controllers.v2;
import eu.eudat.audit.AuditableAction;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.authorization.OwnedResource;
import eu.eudat.authorization.Permission;
import eu.eudat.data.LockEntity;
import eu.eudat.model.Lock;
@ -10,11 +9,9 @@ import eu.eudat.model.builder.LockBuilder;
import eu.eudat.model.censorship.LockCensor;
import eu.eudat.model.persist.LockPersist;
import eu.eudat.model.result.QueryResult;
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.query.LockQuery;
import eu.eudat.query.lookup.LockLookup;
import eu.eudat.service.lock.LockService;
import eu.eudat.types.ApiMessageCode;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.auditing.AuditService;
import gr.cite.tools.data.builder.BuilderFactory;
@ -32,8 +29,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.crypto.BadPaddingException;
@ -65,7 +60,6 @@ public class LockController {
private final QueryFactory queryFactory;
private final MessageSource messageSource;
private final AuthorizationService authorizationService;
private final AuthorizationService authService;
@Autowired
@ -74,15 +68,13 @@ public class LockController {
LockService lockService,
CensorFactory censorFactory,
QueryFactory queryFactory,
MessageSource messageSource,
AuthorizationService authorizationService, AuthorizationService authService) {
MessageSource messageSource, AuthorizationService authService) {
this.builderFactory = builderFactory;
this.auditService = auditService;
this.lockService = lockService;
this.censorFactory = censorFactory;
this.queryFactory = queryFactory;
this.messageSource = messageSource;
this.authorizationService = authorizationService;
this.authService = authService;
}
@ -99,7 +91,7 @@ public class LockController {
this.auditService.track(AuditableAction.Lock_Query, "lookup", lookup);
return new QueryResult(models, count);
return new QueryResult<>(models, count);
}
@GetMapping("{id}")
@ -158,19 +150,28 @@ public class LockController {
@Transactional
@GetMapping("target/status/{id}")
public @ResponseBody Boolean getLocked(@PathVariable("id") UUID targetId) throws Exception {
this.authService.authorizeAtLeastOneForce(targetId != null ? List.of(new OwnedResource(targetId)) : null, Permission.BrowseLock);
public Boolean getLocked(@PathVariable("id") UUID targetId) throws Exception {
logger.debug(new MapLogEntry("is locked" + Lock.class.getSimpleName()).And("targetId", targetId));
this.authService.authorizeForce(Permission.BrowseLock);
return this.lockService.isLocked(targetId);
Boolean isLocked = this.lockService.isLocked(targetId);
this.auditService.track(AuditableAction.Lock_IsLocked, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("targetId", targetId)
));
return isLocked;
}
@Transactional
@DeleteMapping("target/unlock/{id}")
public @ResponseBody ResponseEntity<ResponseItem<String>> unlock(@PathVariable("id") UUID targetId) throws Exception {
this.authService.authorizeAtLeastOneForce(targetId != null ? List.of(new OwnedResource(targetId)) : null, Permission.BrowseLock);
public boolean unlock(@PathVariable("id") UUID targetId) throws Exception {
logger.debug(new MapLogEntry("unlock" + Lock.class.getSimpleName()).And("targetId", targetId));
this.authService.authorizeForce(Permission.BrowseLock);
this.lockService.unlock(targetId);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<String>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created").payload("Lock Removed"));
this.auditService.track(AuditableAction.Lock_UnLocked, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("targetId", targetId)
));
return true;
}
@DeleteMapping("{id}")
@ -182,39 +183,4 @@ public class LockController {
this.auditService.track(AuditableAction.Lock_Delete, "id", id);
}
// @Transactional
// @RequestMapping(method = RequestMethod.GET, path = "target/status/{id}")
// public @ResponseBody ResponseEntity<ResponseItem<Boolean>> getLocked(@PathVariable String id) throws Exception {
// this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
//
// boolean locked = this.lockManager.isLocked(id);
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Boolean>().status(ApiMessageCode.SUCCESS_MESSAGE).message("locked").payload(locked));
// }
//
// @Transactional
// @RequestMapping(method = RequestMethod.DELETE, path = "target/unlock/{id}")
// public @ResponseBody ResponseEntity<ResponseItem<String>> unlock(@PathVariable String id) throws Exception {
// this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
//
// this.lockManager.unlock(id);
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<String>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created").payload("Lock Removed"));
// }
//
// @Transactional
// @RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
// public @ResponseBody ResponseEntity<ResponseItem<UUID>> createOrUpdate(@RequestBody Lock lock) throws Exception {
// this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
//
// eu.eudat.data.old.Lock result = this.lockManager.createOrUpdate(lock);
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UUID>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created").payload(result.getId()));
// }
//
// @RequestMapping(method = RequestMethod.GET, path = "target/{id}")
// public @ResponseBody ResponseEntity<ResponseItem<Lock>> getSingle(@PathVariable String id) throws Exception {
// this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
//
// Lock lock = this.lockManager.getFromTarget(id);
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Lock>().status(ApiMessageCode.NO_MESSAGE).payload(lock));
// }
}

View File

@ -1,9 +0,0 @@
package eu.eudat.exceptions.datasetprofile;
public class DatasetProfileNewVersionException extends RuntimeException {
public DatasetProfileNewVersionException(String message) {
super(message);
}
}

View File

@ -1,19 +0,0 @@
package eu.eudat.exceptions.datasetprofile;
public class DatasetProfileWithDatasetsExeption extends RuntimeException {
public DatasetProfileWithDatasetsExeption() {
}
public DatasetProfileWithDatasetsExeption(String message) {
super(message);
}
public DatasetProfileWithDatasetsExeption(String message, Throwable cause) {
super(message, cause);
}
public DatasetProfileWithDatasetsExeption(Throwable cause) {
super(cause);
}
}

View File

@ -1,9 +0,0 @@
package eu.eudat.exceptions.descriptiontemplate;
public class DescriptionTemplatesWithTypeException extends RuntimeException {
public DescriptionTemplatesWithTypeException(String message) {
super(message);
}
}

View File

@ -1,18 +0,0 @@
package eu.eudat.exceptions.dmpblueprint;
public class DmpBlueprintUsedException extends RuntimeException {
public DmpBlueprintUsedException() {
}
public DmpBlueprintUsedException(String message) {
super(message);
}
public DmpBlueprintUsedException(String message, Throwable cause) {
super(message, cause);
}
public DmpBlueprintUsedException(Throwable cause) {
super(cause);
}
}

View File

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

View File

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

View File

@ -1,8 +0,0 @@
package eu.eudat.exceptions.security;
public class ExpiredTokenException extends Exception {
public ExpiredTokenException(String message) {
super(message);
}
}

View File

@ -1,11 +0,0 @@
package eu.eudat.exceptions.security;
public class NonValidTokenException extends Exception {
private static final long serialVersionUID = -2834659827755141154L;
public NonValidTokenException(String msg) {
super(msg);
}
}

View File

@ -1,8 +0,0 @@
package eu.eudat.exceptions.security;
public class NullEmailException extends RuntimeException {
public NullEmailException() {
super();
}
}

View File

@ -660,6 +660,7 @@ permissions:
BrowseLock:
roles:
- User
- Admin
clients: [ ]
allowAnonymous: false
allowAuthenticated: false