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
@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<DataTableData<DatasetListingModel>> getPaged(@RequestBody DatasetTableRequest datasetTableRequest,Principal principal) {
try {
DataTableData<DatasetListingModel> dataTable = new DatasetManager().getPaged(this.getApiContext().getDatabaseRepository().getDatasetDao(), datasetTableRequest);
return new ResponseItem<DataTableData<DatasetListingModel>>().status(HttpStatus.OK).payload(dataTable);
@RequestMapping(method = RequestMethod.POST, value = {"/datasets/getPaged"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseItem<DataTableData<DatasetListingModel>> getPaged(@RequestBody DatasetTableRequest datasetTableRequest, Principal principal) {
try {
DataTableData<DatasetListingModel> dataTable = new DatasetManager().getPaged(this.getApiContext(), datasetTableRequest, principal);
return new ResponseItem<DataTableData<DatasetListingModel>>().status(HttpStatus.OK).payload(dataTable);
} catch (Exception ex) {
ex.printStackTrace();
return new ResponseItem<DataTableData<DatasetListingModel>>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage());
}
}
} catch (Exception ex) {
ex.printStackTrace();
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);
Long count();
QueryableList<DMP> getAuthenticated(QueryableList<DMP> query,UserInfo principal);

View File

@ -65,7 +65,7 @@ public class DMPDaoImpl implements DMPDao {
@Override
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()){
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 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<Dataset> getAuthenticated(QueryableList<Dataset> query, UserInfo principal);
}

View File

@ -27,32 +27,40 @@ import org.springframework.stereotype.Component;
@Component("datasetDao")
public class DatasetDaoImpl implements DatasetDao {
@Autowired
DatabaseService<Dataset> databaseService;
@Autowired
DatabaseService<Dataset> databaseService;
@Override
public QueryableList<Dataset> getWithCriteria(DatasetCriteria criteria) {
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.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<Dataset> getWithCriteria(DatasetCriteria criteria) {
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.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<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 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> authItems = apiContext.getDatabaseRepository().getDmpDao().getAuthenticated(items, userInfo);
QueryableList<DMP> pagedItems = PaginationManager.applyPaging(authItems, dataManagementPlanTableRequest);

View File

@ -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<DatasetListingModel> getPaged(DatasetDao datatasetRepository, DatasetTableRequest datasetTableRequest) throws IllegalAccessException, InstantiationException{
QueryableList<eu.eudat.entities.Dataset> items = datatasetRepository.getWithCriteria(datasetTableRequest.getCriteria());
QueryableList<eu.eudat.entities.Dataset> pagedItems = PaginationManager.applyPaging( items ,datasetTableRequest);
public DataTableData<DatasetListingModel> getPaged(ApiContext apiContext, DatasetTableRequest datasetTableRequest, Principal principal) throws IllegalAccessException, InstantiationException{
UserInfo userInfo = new UserInfo();
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");
List<DatasetListingModel> datasets = new DomainModelConverter<eu.eudat.entities.Dataset, DatasetListingModel>().fromDataModel( pagedItems.toList(), DatasetListingModel.class);
DataTableData<DatasetListingModel> dataTable = new DataTableData<DatasetListingModel>();

View File

@ -23,56 +23,56 @@ import eu.eudat.utilities.builders.DomainModelConverter;
public class ProjectManager {
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> 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);
DataTableData<eu.eudat.models.project.Project> dataTable = new DataTableData<eu.eudat.models.project.Project>();
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<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> 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);
DataTableData<eu.eudat.models.project.Project> dataTable = new DataTableData<eu.eudat.models.project.Project>();
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<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());
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());
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<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());
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;
}
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());
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());
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<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());
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;
}
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);
}
}