diff --git a/dmp-backend/src/main/java/eu/eudat/controllers/Datasets.java b/dmp-backend/src/main/java/eu/eudat/controllers/Datasets.java index 2225edf79..e4ab1728a 100644 --- a/dmp-backend/src/main/java/eu/eudat/controllers/Datasets.java +++ b/dmp-backend/src/main/java/eu/eudat/controllers/Datasets.java @@ -50,24 +50,25 @@ import javax.transaction.Transactional; @RestController @CrossOrigin -public class Datasets extends BaseController{ +public class Datasets extends BaseController { - @Autowired - public Datasets(ApiContext apiContext) { - super(apiContext); - } + @Autowired + public Datasets(ApiContext apiContext) { + super(apiContext); + } - @RequestMapping(method = RequestMethod.POST, value = { "/datasets/getPaged" }, consumes = "application/json", produces="application/json") - public @ResponseBody ResponseItem> getPaged(@RequestBody DatasetTableRequest datasetTableRequest,Principal principal) { - try { - DataTableData dataTable = new DatasetManager().getPaged(this.getApiContext().getDatabaseRepository().getDatasetDao(), datasetTableRequest); - return new ResponseItem>().status(HttpStatus.OK).payload(dataTable); + @RequestMapping(method = RequestMethod.POST, value = {"/datasets/getPaged"}, consumes = "application/json", produces = "application/json") + public @ResponseBody + ResponseItem> getPaged(@RequestBody DatasetTableRequest datasetTableRequest, Principal principal) { + try { + DataTableData dataTable = new DatasetManager().getPaged(this.getApiContext(), datasetTableRequest, principal); + return new ResponseItem>().status(HttpStatus.OK).payload(dataTable); + + } catch (Exception ex) { + ex.printStackTrace(); + return new ResponseItem>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage()); + } + } - } catch (Exception ex) { - ex.printStackTrace(); - return new ResponseItem>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage()); - } - } - } diff --git a/dmp-backend/src/main/java/eu/eudat/dao/entities/DMPDao.java b/dmp-backend/src/main/java/eu/eudat/dao/entities/DMPDao.java index 84fc13355..aec2b76db 100644 --- a/dmp-backend/src/main/java/eu/eudat/dao/entities/DMPDao.java +++ b/dmp-backend/src/main/java/eu/eudat/dao/entities/DMPDao.java @@ -25,6 +25,7 @@ public interface DMPDao { DMP find(UUID id); Long count(); + QueryableList getAuthenticated(QueryableList query,UserInfo principal); diff --git a/dmp-backend/src/main/java/eu/eudat/dao/entities/DMPDaoImpl.java b/dmp-backend/src/main/java/eu/eudat/dao/entities/DMPDaoImpl.java index 5dece2fa0..4fd8f8842 100644 --- a/dmp-backend/src/main/java/eu/eudat/dao/entities/DMPDaoImpl.java +++ b/dmp-backend/src/main/java/eu/eudat/dao/entities/DMPDaoImpl.java @@ -65,7 +65,7 @@ public class DMPDaoImpl implements DMPDao { @Override public QueryableList getUserDmps(DatasetWizardAutocompleteRequest datasetWizardAutocompleteRequest, UserInfo userInfo) { - QueryableList query = databaseService.getQueryable(DMP.class).where((builder, root) -> builder.equal(root.get("creator"),userInfo)); + QueryableList query = databaseService.getQueryable(DMP.class).where((builder, root) -> builder.or(builder.equal(root.get("creator"),userInfo),builder.isMember(userInfo,root.get("users")))); if(datasetWizardAutocompleteRequest.getCriteria().getLike()!=null&&!datasetWizardAutocompleteRequest.getCriteria().getLike().isEmpty()){ query.where((builder, root) -> builder.like(root.get("label"),"%"+datasetWizardAutocompleteRequest.getCriteria().getLike()+"%")); } diff --git a/dmp-backend/src/main/java/eu/eudat/dao/entities/DatasetDao.java b/dmp-backend/src/main/java/eu/eudat/dao/entities/DatasetDao.java index a1f1bc63a..8a5765ede 100644 --- a/dmp-backend/src/main/java/eu/eudat/dao/entities/DatasetDao.java +++ b/dmp-backend/src/main/java/eu/eudat/dao/entities/DatasetDao.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.UUID; import eu.eudat.dao.Dao; +import eu.eudat.entities.DMP; import eu.eudat.entities.Dataset; import eu.eudat.entities.Project; import eu.eudat.entities.UserInfo; @@ -27,5 +28,6 @@ public interface DatasetDao { Long count(); + QueryableList getAuthenticated(QueryableList query, UserInfo principal); } \ No newline at end of file diff --git a/dmp-backend/src/main/java/eu/eudat/dao/entities/DatasetDaoImpl.java b/dmp-backend/src/main/java/eu/eudat/dao/entities/DatasetDaoImpl.java index c68de4818..df8a0f946 100644 --- a/dmp-backend/src/main/java/eu/eudat/dao/entities/DatasetDaoImpl.java +++ b/dmp-backend/src/main/java/eu/eudat/dao/entities/DatasetDaoImpl.java @@ -27,32 +27,40 @@ import org.springframework.stereotype.Component; @Component("datasetDao") public class DatasetDaoImpl implements DatasetDao { - @Autowired - DatabaseService databaseService; + @Autowired + DatabaseService databaseService; - @Override - public QueryableList getWithCriteria(DatasetCriteria criteria) { - QueryableList query = databaseService.getQueryable(Dataset.class,Dataset.getHints()); - if(criteria.getLike()!=null&&!criteria.getLike().isEmpty())query.where((builder, root) -> builder.like(root.get("label"),"%"+criteria.getLike()+"%")); - if(criteria.getStatus()!=null)query.where((builder, root) -> builder.equal(root.get("status"),criteria.getStatus())); - if(criteria.getPeriodEnd()!=null)query.where((builder, root) -> builder.lessThan(root.get("created"),criteria.getPeriodEnd())); - if(criteria.getPeriodStart()!=null)query.where((builder, root) -> builder.greaterThan(root.get("created"),criteria.getPeriodStart())); - return query; - } + @Override + public QueryableList getWithCriteria(DatasetCriteria criteria) { + QueryableList query = databaseService.getQueryable(Dataset.class, Dataset.getHints()); + if (criteria.getLike() != null && !criteria.getLike().isEmpty()) + query.where((builder, root) -> builder.like(root.get("label"), "%" + criteria.getLike() + "%")); + if (criteria.getStatus() != null) + query.where((builder, root) -> builder.equal(root.get("status"), criteria.getStatus())); + if (criteria.getPeriodEnd() != null) + query.where((builder, root) -> builder.lessThan(root.get("created"), criteria.getPeriodEnd())); + if (criteria.getPeriodStart() != null) + query.where((builder, root) -> builder.greaterThan(root.get("created"), criteria.getPeriodStart())); + return query; + } - @Override - public Dataset createOrUpdate(Dataset item) { - return databaseService.createOrUpdate(item,Dataset.class); - } + @Override + public Dataset createOrUpdate(Dataset item) { + return databaseService.createOrUpdate(item, Dataset.class); + } - @Override - public Dataset find(UUID id) { - return databaseService.getQueryable(Dataset.class).where((builder, root) -> builder.equal((root.get("id")),id)).toList().get(0); - } - - public Long count(){ - return this.databaseService.count(Dataset.class); - } + @Override + public Dataset find(UUID id) { + return databaseService.getQueryable(Dataset.class).where((builder, root) -> builder.equal((root.get("id")), id)).toList().get(0); + } + public Long count() { + return this.databaseService.count(Dataset.class); + } + @Override + public QueryableList getAuthenticated(QueryableList query, UserInfo principal) { + query.where((builder, root) -> builder.or(builder.equal(root.get("dmp").get("creator"), principal), builder.isMember(principal, root.get("dmp").get("users")))); + return query; + } } diff --git a/dmp-backend/src/main/java/eu/eudat/managers/DataManagementPlanManager.java b/dmp-backend/src/main/java/eu/eudat/managers/DataManagementPlanManager.java index 0b093633a..1aaa72f53 100644 --- a/dmp-backend/src/main/java/eu/eudat/managers/DataManagementPlanManager.java +++ b/dmp-backend/src/main/java/eu/eudat/managers/DataManagementPlanManager.java @@ -26,7 +26,8 @@ import eu.eudat.utilities.builders.DomainModelConverter; public class DataManagementPlanManager { public DataTableData getPaged(ApiContext apiContext, DataManagementPlanTableRequest dataManagementPlanTableRequest, Principal principal) throws IllegalAccessException, InstantiationException { - UserInfo userInfo = apiContext.getDatabaseRepository().getUserInfoDao().find(principal.getId()); + UserInfo userInfo = new UserInfo(); + userInfo.setId(principal.getId()); QueryableList items = apiContext.getDatabaseRepository().getDmpDao().getWithCriteria(dataManagementPlanTableRequest.getCriteria()); QueryableList authItems = apiContext.getDatabaseRepository().getDmpDao().getAuthenticated(items, userInfo); QueryableList pagedItems = PaginationManager.applyPaging(authItems, dataManagementPlanTableRequest); diff --git a/dmp-backend/src/main/java/eu/eudat/managers/DatasetManager.java b/dmp-backend/src/main/java/eu/eudat/managers/DatasetManager.java index 433a45981..d5d652171 100644 --- a/dmp-backend/src/main/java/eu/eudat/managers/DatasetManager.java +++ b/dmp-backend/src/main/java/eu/eudat/managers/DatasetManager.java @@ -1,6 +1,7 @@ package eu.eudat.managers; import eu.eudat.dao.entities.*; +import eu.eudat.entities.UserInfo; import eu.eudat.models.criteria.DataRepositoryCriteria; import eu.eudat.models.criteria.RegistryCriteria; import eu.eudat.models.criteria.ServiceCriteria; @@ -11,6 +12,7 @@ import eu.eudat.models.helpers.DataTableData; import eu.eudat.models.listingmodels.DatasetListingModel; import eu.eudat.models.project.Project; import eu.eudat.models.project.ProjectTableRequest; +import eu.eudat.models.security.Principal; import eu.eudat.queryable.QueryableList; import eu.eudat.services.ApiContext; import eu.eudat.utilities.builders.DomainModelConverter; @@ -25,9 +27,12 @@ import java.util.UUID; */ public class DatasetManager { - public DataTableData getPaged(DatasetDao datatasetRepository, DatasetTableRequest datasetTableRequest) throws IllegalAccessException, InstantiationException{ - QueryableList items = datatasetRepository.getWithCriteria(datasetTableRequest.getCriteria()); - QueryableList pagedItems = PaginationManager.applyPaging( items ,datasetTableRequest); + public DataTableData getPaged(ApiContext apiContext, DatasetTableRequest datasetTableRequest, Principal principal) throws IllegalAccessException, InstantiationException{ + UserInfo userInfo = new UserInfo(); + userInfo.setId(principal.getId()); + QueryableList items = apiContext.getDatabaseRepository().getDatasetDao().getWithCriteria(datasetTableRequest.getCriteria()); + QueryableList authItems = apiContext.getDatabaseRepository().getDatasetDao().getAuthenticated(items,userInfo); + QueryableList pagedItems = PaginationManager.applyPaging( authItems ,datasetTableRequest); if(datasetTableRequest.getWithHint())pagedItems.withHint("datasetFullyDetailed"); List datasets = new DomainModelConverter().fromDataModel( pagedItems.toList(), DatasetListingModel.class); DataTableData dataTable = new DataTableData(); diff --git a/dmp-backend/src/main/java/eu/eudat/managers/ProjectManager.java b/dmp-backend/src/main/java/eu/eudat/managers/ProjectManager.java index 91f707a48..011c8b6b1 100644 --- a/dmp-backend/src/main/java/eu/eudat/managers/ProjectManager.java +++ b/dmp-backend/src/main/java/eu/eudat/managers/ProjectManager.java @@ -23,56 +23,56 @@ import eu.eudat.utilities.builders.DomainModelConverter; public class ProjectManager { - public DataTableData getPaged(ProjectDao projectRepository, ProjectTableRequest projectTableRequest) throws IllegalAccessException, InstantiationException{ - QueryableList items = projectRepository.getWithCriteria(projectTableRequest.getCriteria()); - QueryableList pagedItems = PaginationManager.applyPaging(items,projectTableRequest); - List projects = new DomainModelConverter().fromDataModel(pagedItems.toList(), eu.eudat.models.project.Project.class); - DataTableData dataTable = new DataTableData(); - dataTable.setData(projects); - dataTable.setTotalCount(items.count()); - return dataTable; - } - - public eu.eudat.models.project.Project getSingle(ProjectDao projectRepository, String id) throws InstantiationException, IllegalAccessException{ - eu.eudat.models.project.Project project = new eu.eudat.models.project.Project(); - project.fromDataModel(projectRepository.find(UUID.fromString(id))); - return project; - } + public DataTableData getPaged(ProjectDao projectRepository, ProjectTableRequest projectTableRequest) throws IllegalAccessException, InstantiationException { + QueryableList items = projectRepository.getWithCriteria(projectTableRequest.getCriteria()); + QueryableList pagedItems = PaginationManager.applyPaging(items, projectTableRequest); + List projects = new DomainModelConverter().fromDataModel(pagedItems.toList(), eu.eudat.models.project.Project.class); + DataTableData dataTable = new DataTableData(); + dataTable.setData(projects); + dataTable.setTotalCount(items.count()); + return dataTable; + } - public eu.eudat.entities.Project inactivate(ProjectDao projectRepository,String id) throws InstantiationException, IllegalAccessException{ - eu.eudat.entities.Project project = projectRepository.find(UUID.fromString(id)); - project.setStatus(Project.Status.DELETED.getValue()); - project = projectRepository.createOrUpdate(project); - return project; - } + public eu.eudat.models.project.Project getSingle(ProjectDao projectRepository, String id) throws InstantiationException, IllegalAccessException { + eu.eudat.models.project.Project project = new eu.eudat.models.project.Project(); + project.fromDataModel(projectRepository.find(UUID.fromString(id))); + return project; + } - public List getCriteriaWithExternal(ProjectDao projectRepository, ProjectCriteriaRequest projectCriteria,RemoteFetcher remoteFetcher) throws IllegalAccessException, InstantiationException, HugeResultSet, NoURLFound { - QueryableList items = projectRepository.getWithCriteria(projectCriteria.getCriteria()); - List projects = new DomainModelConverter().fromDataModel(items.toList(), eu.eudat.models.project.Project.class); - List> remoteRepos = remoteFetcher.getProjects(projectCriteria.getCriteria().getLike()); - ProjectsExternalSourcesModel projectsExternalSourcesModel = new ProjectsExternalSourcesModel().fromExternalItem(remoteRepos); - for(ExternalSourcesItemModel externalListingItem:projectsExternalSourcesModel){ - eu.eudat.models.project.Project project = new eu.eudat.models.project.Project(); - project.setReference(externalListingItem.getRemoteId()); - project.setLabel(externalListingItem.getName()); - project.setDescription(externalListingItem.getDescription()); - project.setUri(externalListingItem.getUri()); - project.setAbbreviation(externalListingItem.getAbbreviation()); - project.setStatus((short)0); - projects.add(project); - } - return projects; - } + public eu.eudat.entities.Project inactivate(ProjectDao projectRepository, String id) throws InstantiationException, IllegalAccessException { + eu.eudat.entities.Project project = projectRepository.find(UUID.fromString(id)); + project.setStatus(Project.Status.DELETED.getValue()); + project = projectRepository.createOrUpdate(project); + return project; + } - public List getCriteria(ProjectDao projectRepository, ProjectCriteriaRequest projectCriteria,RemoteFetcher remoteFetcher) throws IllegalAccessException, InstantiationException, HugeResultSet, NoURLFound { - QueryableList items = projectRepository.getWithCriteria(projectCriteria.getCriteria()); - List projects = new DomainModelConverter().fromDataModel(items.toList(), eu.eudat.models.project.Project.class); - return projects; - } + public List getCriteriaWithExternal(ProjectDao projectRepository, ProjectCriteriaRequest projectCriteria, RemoteFetcher remoteFetcher) throws IllegalAccessException, InstantiationException, HugeResultSet, NoURLFound { + QueryableList items = projectRepository.getWithCriteria(projectCriteria.getCriteria()); + List projects = new DomainModelConverter().fromDataModel(items.toList(), eu.eudat.models.project.Project.class); + List> remoteRepos = remoteFetcher.getProjects(projectCriteria.getCriteria().getLike()); + ProjectsExternalSourcesModel projectsExternalSourcesModel = new ProjectsExternalSourcesModel().fromExternalItem(remoteRepos); + for (ExternalSourcesItemModel externalListingItem : projectsExternalSourcesModel) { + eu.eudat.models.project.Project project = new eu.eudat.models.project.Project(); + project.setReference(externalListingItem.getRemoteId()); + project.setLabel(externalListingItem.getName()); + project.setDescription(externalListingItem.getDescription()); + project.setUri(externalListingItem.getUri()); + project.setAbbreviation(externalListingItem.getAbbreviation()); + project.setStatus((short) 0); + projects.add(project); + } + return projects; + } - public static void createOrUpdate(ProjectDao projectRepository, UserInfoDao userInfoRepository, eu.eudat.models.project.Project project, Principal principal){ - eu.eudat.entities.Project projectEntity = project.toDataModel(); - projectEntity.setCreationUser(userInfoRepository.find(principal.getId())); - projectRepository.createOrUpdate(projectEntity); - } + public List getCriteria(ProjectDao projectRepository, ProjectCriteriaRequest projectCriteria, RemoteFetcher remoteFetcher) throws IllegalAccessException, InstantiationException, HugeResultSet, NoURLFound { + QueryableList items = projectRepository.getWithCriteria(projectCriteria.getCriteria()); + List projects = new DomainModelConverter().fromDataModel(items.toList(), eu.eudat.models.project.Project.class); + return projects; + } + + public static void createOrUpdate(ProjectDao projectRepository, UserInfoDao userInfoRepository, eu.eudat.models.project.Project project, Principal principal) { + eu.eudat.entities.Project projectEntity = project.toDataModel(); + projectEntity.setCreationUser(userInfoRepository.find(principal.getId())); + projectRepository.createOrUpdate(projectEntity); + } }