no message

This commit is contained in:
annabakouli 2018-01-12 10:05:44 +02:00
parent d617ad0bb1
commit c40b24250a
8 changed files with 110 additions and 92 deletions

View File

@ -50,24 +50,25 @@ import javax.transaction.Transactional;
@RestController @RestController
@CrossOrigin @CrossOrigin
public class Datasets extends BaseController{ public class Datasets extends BaseController {
@Autowired @Autowired
public Datasets(ApiContext apiContext) { public Datasets(ApiContext apiContext) {
super(apiContext); super(apiContext);
} }
@RequestMapping(method = RequestMethod.POST, value = { "/datasets/getPaged" }, consumes = "application/json", produces="application/json") @RequestMapping(method = RequestMethod.POST, value = {"/datasets/getPaged"}, consumes = "application/json", produces = "application/json")
public @ResponseBody ResponseItem<DataTableData<DatasetListingModel>> getPaged(@RequestBody DatasetTableRequest datasetTableRequest,Principal principal) { public @ResponseBody
try { ResponseItem<DataTableData<DatasetListingModel>> getPaged(@RequestBody DatasetTableRequest datasetTableRequest, Principal principal) {
DataTableData<DatasetListingModel> dataTable = new DatasetManager().getPaged(this.getApiContext().getDatabaseRepository().getDatasetDao(), datasetTableRequest); try {
return new ResponseItem<DataTableData<DatasetListingModel>>().status(HttpStatus.OK).payload(dataTable); DataTableData<DatasetListingModel> dataTable = new DatasetManager().getPaged(this.getApiContext(), datasetTableRequest, principal);
return new ResponseItem<DataTableData<DatasetListingModel>>().status(HttpStatus.OK).payload(dataTable);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
return new ResponseItem<DataTableData<DatasetListingModel>>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage()); return new ResponseItem<DataTableData<DatasetListingModel>>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage());
} }
} }
} }

View File

@ -25,6 +25,7 @@ public interface DMPDao {
DMP find(UUID id); DMP find(UUID id);
Long count(); Long count();
QueryableList<DMP> getAuthenticated(QueryableList<DMP> query,UserInfo principal); QueryableList<DMP> getAuthenticated(QueryableList<DMP> query,UserInfo principal);

View File

@ -65,7 +65,7 @@ public class DMPDaoImpl implements DMPDao {
@Override @Override
public QueryableList<DMP> getUserDmps(DatasetWizardAutocompleteRequest datasetWizardAutocompleteRequest, UserInfo userInfo) { public QueryableList<DMP> getUserDmps(DatasetWizardAutocompleteRequest datasetWizardAutocompleteRequest, UserInfo userInfo) {
QueryableList<DMP> query = databaseService.getQueryable(DMP.class).where((builder, root) -> builder.equal(root.get("creator"),userInfo)); QueryableList<DMP> 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()){ if(datasetWizardAutocompleteRequest.getCriteria().getLike()!=null&&!datasetWizardAutocompleteRequest.getCriteria().getLike().isEmpty()){
query.where((builder, root) -> builder.like(root.get("label"),"%"+datasetWizardAutocompleteRequest.getCriteria().getLike()+"%")); query.where((builder, root) -> builder.like(root.get("label"),"%"+datasetWizardAutocompleteRequest.getCriteria().getLike()+"%"));
} }

View File

@ -4,6 +4,7 @@ import java.util.List;
import java.util.UUID; import java.util.UUID;
import eu.eudat.dao.Dao; import eu.eudat.dao.Dao;
import eu.eudat.entities.DMP;
import eu.eudat.entities.Dataset; import eu.eudat.entities.Dataset;
import eu.eudat.entities.Project; import eu.eudat.entities.Project;
import eu.eudat.entities.UserInfo; import eu.eudat.entities.UserInfo;
@ -27,5 +28,6 @@ public interface DatasetDao {
Long count(); Long count();
QueryableList<Dataset> getAuthenticated(QueryableList<Dataset> query, UserInfo principal);
} }

View File

@ -27,32 +27,40 @@ import org.springframework.stereotype.Component;
@Component("datasetDao") @Component("datasetDao")
public class DatasetDaoImpl implements DatasetDao { public class DatasetDaoImpl implements DatasetDao {
@Autowired @Autowired
DatabaseService<Dataset> databaseService; DatabaseService<Dataset> databaseService;
@Override @Override
public QueryableList<Dataset> getWithCriteria(DatasetCriteria criteria) { public QueryableList<Dataset> getWithCriteria(DatasetCriteria criteria) {
QueryableList<Dataset> query = databaseService.getQueryable(Dataset.class,Dataset.getHints()); QueryableList<Dataset> 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.getLike() != null && !criteria.getLike().isEmpty())
if(criteria.getStatus()!=null)query.where((builder, root) -> builder.equal(root.get("status"),criteria.getStatus())); query.where((builder, root) -> builder.like(root.get("label"), "%" + criteria.getLike() + "%"));
if(criteria.getPeriodEnd()!=null)query.where((builder, root) -> builder.lessThan(root.get("created"),criteria.getPeriodEnd())); if (criteria.getStatus() != null)
if(criteria.getPeriodStart()!=null)query.where((builder, root) -> builder.greaterThan(root.get("created"),criteria.getPeriodStart())); query.where((builder, root) -> builder.equal(root.get("status"), criteria.getStatus()));
return query; 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 @Override
public Dataset createOrUpdate(Dataset item) { public Dataset createOrUpdate(Dataset item) {
return databaseService.createOrUpdate(item,Dataset.class); return databaseService.createOrUpdate(item, Dataset.class);
} }
@Override @Override
public Dataset find(UUID id) { public Dataset find(UUID id) {
return databaseService.getQueryable(Dataset.class).where((builder, root) -> builder.equal((root.get("id")),id)).toList().get(0); 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);
}
public Long count() {
return this.databaseService.count(Dataset.class);
}
@Override
public QueryableList<Dataset> getAuthenticated(QueryableList<Dataset> 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;
}
} }

View File

@ -26,7 +26,8 @@ import eu.eudat.utilities.builders.DomainModelConverter;
public class DataManagementPlanManager { public class DataManagementPlanManager {
public DataTableData<DataManagementPlanListingModel> getPaged(ApiContext apiContext, DataManagementPlanTableRequest dataManagementPlanTableRequest, Principal principal) throws IllegalAccessException, InstantiationException { public DataTableData<DataManagementPlanListingModel> 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<DMP> items = apiContext.getDatabaseRepository().getDmpDao().getWithCriteria(dataManagementPlanTableRequest.getCriteria()); QueryableList<DMP> items = apiContext.getDatabaseRepository().getDmpDao().getWithCriteria(dataManagementPlanTableRequest.getCriteria());
QueryableList<DMP> authItems = apiContext.getDatabaseRepository().getDmpDao().getAuthenticated(items, userInfo); QueryableList<DMP> authItems = apiContext.getDatabaseRepository().getDmpDao().getAuthenticated(items, userInfo);
QueryableList<DMP> pagedItems = PaginationManager.applyPaging(authItems, dataManagementPlanTableRequest); QueryableList<DMP> pagedItems = PaginationManager.applyPaging(authItems, dataManagementPlanTableRequest);

View File

@ -1,6 +1,7 @@
package eu.eudat.managers; package eu.eudat.managers;
import eu.eudat.dao.entities.*; import eu.eudat.dao.entities.*;
import eu.eudat.entities.UserInfo;
import eu.eudat.models.criteria.DataRepositoryCriteria; import eu.eudat.models.criteria.DataRepositoryCriteria;
import eu.eudat.models.criteria.RegistryCriteria; import eu.eudat.models.criteria.RegistryCriteria;
import eu.eudat.models.criteria.ServiceCriteria; 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.listingmodels.DatasetListingModel;
import eu.eudat.models.project.Project; import eu.eudat.models.project.Project;
import eu.eudat.models.project.ProjectTableRequest; import eu.eudat.models.project.ProjectTableRequest;
import eu.eudat.models.security.Principal;
import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.QueryableList;
import eu.eudat.services.ApiContext; import eu.eudat.services.ApiContext;
import eu.eudat.utilities.builders.DomainModelConverter; import eu.eudat.utilities.builders.DomainModelConverter;
@ -25,9 +27,12 @@ import java.util.UUID;
*/ */
public class DatasetManager { public class DatasetManager {
public DataTableData<DatasetListingModel> getPaged(DatasetDao datatasetRepository, DatasetTableRequest datasetTableRequest) throws IllegalAccessException, InstantiationException{ public DataTableData<DatasetListingModel> getPaged(ApiContext apiContext, DatasetTableRequest datasetTableRequest, Principal principal) throws IllegalAccessException, InstantiationException{
QueryableList<eu.eudat.entities.Dataset> items = datatasetRepository.getWithCriteria(datasetTableRequest.getCriteria()); UserInfo userInfo = new UserInfo();
QueryableList<eu.eudat.entities.Dataset> pagedItems = PaginationManager.applyPaging( items ,datasetTableRequest); userInfo.setId(principal.getId());
QueryableList<eu.eudat.entities.Dataset> items = apiContext.getDatabaseRepository().getDatasetDao().getWithCriteria(datasetTableRequest.getCriteria());
QueryableList<eu.eudat.entities.Dataset> authItems = apiContext.getDatabaseRepository().getDatasetDao().getAuthenticated(items,userInfo);
QueryableList<eu.eudat.entities.Dataset> pagedItems = PaginationManager.applyPaging( authItems ,datasetTableRequest);
if(datasetTableRequest.getWithHint())pagedItems.withHint("datasetFullyDetailed"); if(datasetTableRequest.getWithHint())pagedItems.withHint("datasetFullyDetailed");
List<DatasetListingModel> datasets = new DomainModelConverter<eu.eudat.entities.Dataset, DatasetListingModel>().fromDataModel( pagedItems.toList(), DatasetListingModel.class); List<DatasetListingModel> datasets = new DomainModelConverter<eu.eudat.entities.Dataset, DatasetListingModel>().fromDataModel( pagedItems.toList(), DatasetListingModel.class);
DataTableData<DatasetListingModel> dataTable = new DataTableData<DatasetListingModel>(); DataTableData<DatasetListingModel> dataTable = new DataTableData<DatasetListingModel>();

View File

@ -23,56 +23,56 @@ import eu.eudat.utilities.builders.DomainModelConverter;
public class ProjectManager { public class ProjectManager {
public DataTableData<eu.eudat.models.project.Project> getPaged(ProjectDao projectRepository, ProjectTableRequest projectTableRequest) throws IllegalAccessException, InstantiationException{ public DataTableData<eu.eudat.models.project.Project> getPaged(ProjectDao projectRepository, ProjectTableRequest projectTableRequest) throws IllegalAccessException, InstantiationException {
QueryableList<eu.eudat.entities.Project> items = projectRepository.getWithCriteria(projectTableRequest.getCriteria()); QueryableList<eu.eudat.entities.Project> items = projectRepository.getWithCriteria(projectTableRequest.getCriteria());
QueryableList<eu.eudat.entities.Project> pagedItems = PaginationManager.applyPaging(items,projectTableRequest); QueryableList<eu.eudat.entities.Project> pagedItems = PaginationManager.applyPaging(items, projectTableRequest);
List<eu.eudat.models.project.Project> projects = new DomainModelConverter<eu.eudat.entities.Project, Project>().fromDataModel(pagedItems.toList(), eu.eudat.models.project.Project.class); List<eu.eudat.models.project.Project> projects = new DomainModelConverter<eu.eudat.entities.Project, Project>().fromDataModel(pagedItems.toList(), eu.eudat.models.project.Project.class);
DataTableData<eu.eudat.models.project.Project> dataTable = new DataTableData<eu.eudat.models.project.Project>(); DataTableData<eu.eudat.models.project.Project> dataTable = new DataTableData<eu.eudat.models.project.Project>();
dataTable.setData(projects); dataTable.setData(projects);
dataTable.setTotalCount(items.count()); dataTable.setTotalCount(items.count());
return dataTable; return dataTable;
} }
public eu.eudat.models.project.Project getSingle(ProjectDao projectRepository, String id) throws InstantiationException, IllegalAccessException{ 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(); eu.eudat.models.project.Project project = new eu.eudat.models.project.Project();
project.fromDataModel(projectRepository.find(UUID.fromString(id))); project.fromDataModel(projectRepository.find(UUID.fromString(id)));
return project; return project;
} }
public eu.eudat.entities.Project inactivate(ProjectDao projectRepository,String id) throws InstantiationException, IllegalAccessException{ public eu.eudat.entities.Project inactivate(ProjectDao projectRepository, String id) throws InstantiationException, IllegalAccessException {
eu.eudat.entities.Project project = projectRepository.find(UUID.fromString(id)); eu.eudat.entities.Project project = projectRepository.find(UUID.fromString(id));
project.setStatus(Project.Status.DELETED.getValue()); project.setStatus(Project.Status.DELETED.getValue());
project = projectRepository.createOrUpdate(project); project = projectRepository.createOrUpdate(project);
return project; return project;
} }
public List<eu.eudat.models.project.Project> getCriteriaWithExternal(ProjectDao projectRepository, ProjectCriteriaRequest projectCriteria,RemoteFetcher remoteFetcher) throws IllegalAccessException, InstantiationException, HugeResultSet, NoURLFound { public List<eu.eudat.models.project.Project> getCriteriaWithExternal(ProjectDao projectRepository, ProjectCriteriaRequest projectCriteria, RemoteFetcher remoteFetcher) throws IllegalAccessException, InstantiationException, HugeResultSet, NoURLFound {
QueryableList<eu.eudat.entities.Project> items = projectRepository.getWithCriteria(projectCriteria.getCriteria()); QueryableList<eu.eudat.entities.Project> items = projectRepository.getWithCriteria(projectCriteria.getCriteria());
List<eu.eudat.models.project.Project> projects = new DomainModelConverter<eu.eudat.entities.Project, Project>().fromDataModel(items.toList(), eu.eudat.models.project.Project.class); List<eu.eudat.models.project.Project> projects = new DomainModelConverter<eu.eudat.entities.Project, Project>().fromDataModel(items.toList(), eu.eudat.models.project.Project.class);
List<Map<String,String>> remoteRepos = remoteFetcher.getProjects(projectCriteria.getCriteria().getLike()); List<Map<String, String>> remoteRepos = remoteFetcher.getProjects(projectCriteria.getCriteria().getLike());
ProjectsExternalSourcesModel projectsExternalSourcesModel = new ProjectsExternalSourcesModel().fromExternalItem(remoteRepos); ProjectsExternalSourcesModel projectsExternalSourcesModel = new ProjectsExternalSourcesModel().fromExternalItem(remoteRepos);
for(ExternalSourcesItemModel externalListingItem:projectsExternalSourcesModel){ for (ExternalSourcesItemModel externalListingItem : projectsExternalSourcesModel) {
eu.eudat.models.project.Project project = new eu.eudat.models.project.Project(); eu.eudat.models.project.Project project = new eu.eudat.models.project.Project();
project.setReference(externalListingItem.getRemoteId()); project.setReference(externalListingItem.getRemoteId());
project.setLabel(externalListingItem.getName()); project.setLabel(externalListingItem.getName());
project.setDescription(externalListingItem.getDescription()); project.setDescription(externalListingItem.getDescription());
project.setUri(externalListingItem.getUri()); project.setUri(externalListingItem.getUri());
project.setAbbreviation(externalListingItem.getAbbreviation()); project.setAbbreviation(externalListingItem.getAbbreviation());
project.setStatus((short)0); project.setStatus((short) 0);
projects.add(project); projects.add(project);
} }
return projects; return projects;
} }
public List<eu.eudat.models.project.Project> getCriteria(ProjectDao projectRepository, ProjectCriteriaRequest projectCriteria,RemoteFetcher remoteFetcher) throws IllegalAccessException, InstantiationException, HugeResultSet, NoURLFound { public List<eu.eudat.models.project.Project> getCriteria(ProjectDao projectRepository, ProjectCriteriaRequest projectCriteria, RemoteFetcher remoteFetcher) throws IllegalAccessException, InstantiationException, HugeResultSet, NoURLFound {
QueryableList<eu.eudat.entities.Project> items = projectRepository.getWithCriteria(projectCriteria.getCriteria()); QueryableList<eu.eudat.entities.Project> items = projectRepository.getWithCriteria(projectCriteria.getCriteria());
List<eu.eudat.models.project.Project> projects = new DomainModelConverter<eu.eudat.entities.Project, Project>().fromDataModel(items.toList(), eu.eudat.models.project.Project.class); List<eu.eudat.models.project.Project> projects = new DomainModelConverter<eu.eudat.entities.Project, Project>().fromDataModel(items.toList(), eu.eudat.models.project.Project.class);
return projects; return projects;
} }
public static void createOrUpdate(ProjectDao projectRepository, UserInfoDao userInfoRepository, eu.eudat.models.project.Project project, Principal principal){ public static void createOrUpdate(ProjectDao projectRepository, UserInfoDao userInfoRepository, eu.eudat.models.project.Project project, Principal principal) {
eu.eudat.entities.Project projectEntity = project.toDataModel(); eu.eudat.entities.Project projectEntity = project.toDataModel();
projectEntity.setCreationUser(userInfoRepository.find(principal.getId())); projectEntity.setCreationUser(userInfoRepository.find(principal.getId()));
projectRepository.createOrUpdate(projectEntity); projectRepository.createOrUpdate(projectEntity);
} }
} }