Organisations filter on "Public DMPs" now exposes only the ones associated with public DMPs. (Ticket #79)

This commit is contained in:
gkolokythas 2019-05-14 14:12:31 +03:00
parent 3905f68121
commit b8559f9f52
7 changed files with 66 additions and 8 deletions

View File

@ -4,6 +4,7 @@ import eu.eudat.data.entities.Organisation;
public class OrganisationCriteria extends Criteria<Organisation> {
private String labelLike;
private Boolean isPublic;
public String getLabelLike() {
return labelLike;
@ -11,4 +12,11 @@ public class OrganisationCriteria extends Criteria<Organisation> {
public void setLabelLike(String labelLike) {
this.labelLike = labelLike;
}
public Boolean getPublic() {
return isPublic;
}
public void setPublic(Boolean aPublic) {
isPublic = aPublic;
}
}

View File

@ -3,6 +3,7 @@ package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.criteria.OrganisationCriteria;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.DMP;
import eu.eudat.data.entities.Organisation;
import eu.eudat.data.entities.UserInfo;
import eu.eudat.queryable.QueryableList;
@ -10,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import javax.persistence.criteria.JoinType;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@ -29,6 +31,9 @@ public class OrganisationDaoImpl extends DatabaseAccess<Organisation> implements
if (criteria.getLabelLike() != null) {
query.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + criteria.getLabelLike().toUpperCase() + "%"));
}
if (criteria.getPublic()) {
query.where((builder, root) -> builder.equal(root.join("dmps", JoinType.LEFT).get("status"), DMP.DMPStatus.FINALISED.getValue()));
}
return query;
}

View File

@ -51,5 +51,12 @@ public class Organisations extends BaseController {
DataTableData<Organisation> organisationDataTableData = this.organisationsManager.getPagedOrganisations(organisationsTableRequest, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<Organisation>>().payload(organisationDataTableData).status(ApiMessageCode.NO_MESSAGE));
}
@RequestMapping(method = RequestMethod.POST, value = {"/public/organisations"}, produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<DataTableData<Organisation>>> getPublicPaged(@Valid @RequestBody OrganisationsTableRequest organisationsTableRequest) throws Exception{
DataTableData<Organisation> organisationDataTableData = this.organisationsManager.getPublicPagedOrganisations(organisationsTableRequest);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<Organisation>>().payload(organisationDataTableData).status(ApiMessageCode.NO_MESSAGE));
}
}

View File

@ -2,16 +2,22 @@ package eu.eudat.logic.managers;
import eu.eudat.data.dao.criteria.OrganisationCriteria;
import eu.eudat.data.dao.entities.OrganisationDao;
import eu.eudat.data.entities.DMP;
import eu.eudat.data.query.items.table.dmp.DataManagmentPlanPublicTableRequest;
import eu.eudat.data.query.items.table.organisations.OrganisationsTableRequest;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.logic.services.operations.DatabaseRepository;
import eu.eudat.models.HintedModelFactory;
import eu.eudat.models.data.dmp.Organisation;
import eu.eudat.models.data.helpers.common.DataTableData;
import eu.eudat.models.data.listingmodels.DataManagementPlanListingModel;
import eu.eudat.models.data.security.Principal;
import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
@ -40,6 +46,22 @@ public class OrganisationsManager {
DataTableData<Organisation> organisationDataTableData = new DataTableData<>();
organisationDataTableData.setData(org);
organisationDataTableData.setTotalCount(pagedItems.count());
return organisationDataTableData;
}
public DataTableData<Organisation> getPublicPagedOrganisations(OrganisationsTableRequest organisationsTableRequest) throws Exception {
organisationsTableRequest.getCriteria().setPublic(true);
OrganisationDao organisationDao = databaseRepository.getOrganisationDao();
QueryableList<eu.eudat.data.entities.Organisation> items = organisationDao.getWithCriteria(organisationsTableRequest.getCriteria());
QueryableList<eu.eudat.data.entities.Organisation> pagedItems = PaginationManager.applyPaging(items, organisationsTableRequest);
List<Organisation> org = pagedItems.toList().stream().distinct().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList());
DataTableData<Organisation> organisationDataTableData = new DataTableData<>();
organisationDataTableData.setData(org);
organisationDataTableData.setTotalCount(pagedItems.count());
return organisationDataTableData;
}
}

View File

@ -63,7 +63,7 @@ export class ExternalSourcesService {
public searchDMPOrganizations(like: string): Observable<ExternalSourceItemModel[]> {
return this.http.get<ExternalSourceItemModel[]>(this.actionUrl + 'organisations' + '?query=' + like, { headers: this.headers });
}//organizationscriteria.criteria.like
}
// TODO: currently not used.
public searchDMPProfiles(like: string): Observable<ExternalSourceItemModel[]> {

View File

@ -26,4 +26,8 @@ export class OrganisationService {
public searchInternalOrganisations(dataTableRequest: DataTableRequest<OrganisationCriteria>): Observable<DataTableData<OrganizationModel>> {
return this.http.post<DataTableData<OrganizationModel>>(this.actionUrl + 'internal/organisations', dataTableRequest , { headers: this.headers });
}
public searchPublicOrganisations(dataTableRequest: DataTableRequest<OrganisationCriteria>): Observable<DataTableData<OrganizationModel>> {
return this.http.post<DataTableData<OrganizationModel>>(this.actionUrl + 'public/organisations', dataTableRequest , { headers: this.headers });
}
}

View File

@ -37,11 +37,11 @@ export class ExploreDmpFiltersComponent extends BaseCriteriaComponent implements
ProjectStateType = ProjectStateType;
projects: Observable<ProjectListingModel[]>;
profiles: Observable<DatasetProfileModel[]>;
dmpOrganisations: Observable<ExternalSourceItemModel[]>;
dmpOrganisations: Observable<OrganizationModel[]>;
projectOptions: Observable<ProjectListingModel[]>;
projectStateOptions: Observable<any[]>;
filteringOrganisationsAsync = false;
filteredOrganisations: ExternalSourceItemModel[];
filteredOrganisations: OrganizationModel[];
status: ProjectStateType;
IsChecked: boolean;
IsIndeterminate: boolean;
@ -118,7 +118,9 @@ export class ExploreDmpFiltersComponent extends BaseCriteriaComponent implements
]);
});
this.profiles = this.datasetProfileService.getDatasetProfiles();
this.dmpOrganisations = this.externalSourcesService.searchDMPOrganizations('');
const fields: Array<string> = new Array<string>();
fields.push('asc');
this.dmpOrganisations = this.organisationService.searchPublicOrganisations(new DataTableRequest<OrganisationCriteria>(0 , null, { fields: fields })).map(x => x.data);
}
ngAfterViewInit(): void {
@ -265,8 +267,13 @@ export class ExploreDmpFiltersComponent extends BaseCriteriaComponent implements
return this.datasetProfileService.getDatasetProfiles();
}
dmpOrganisationSearch(value: string): Observable<ExternalSourceItemModel[]> {
return this.externalSourcesService.searchDMPOrganizations(value);
dmpOrganisationSearch(value: string): Observable<OrganizationModel[]> {
const fields: Array<string> = new Array<string>();
fields.push('asc');
const dataTableRequest: DataTableRequest<OrganisationCriteria> = new DataTableRequest(0, null, { fields: fields });
dataTableRequest.criteria = new OrganisationCriteria();
dataTableRequest.criteria.labelLike = value;
return this.organisationService.searchPublicOrganisations(dataTableRequest).map(x => x.data);
}
removeOrganisation(organisation) {
@ -279,7 +286,12 @@ export class ExploreDmpFiltersComponent extends BaseCriteriaComponent implements
}
getOrganisations() {
return this.externalSourcesService.searchDMPOrganizations('');
const fields: Array<string> = new Array<string>();
fields.push('asc');
const dataTableRequest: DataTableRequest<OrganisationCriteria> = new DataTableRequest(0, null, { fields: fields });
dataTableRequest.criteria = new OrganisationCriteria();
dataTableRequest.criteria.labelLike = '';
return this.organisationService.searchPublicOrganisations(dataTableRequest).map(x => x.data);
}
filterProject(query: string) {
@ -309,7 +321,7 @@ export class ExploreDmpFiltersComponent extends BaseCriteriaComponent implements
dataTableRequest.criteria = new OrganisationCriteria();
dataTableRequest.criteria.labelLike = value;
return this.organisationService.searchInternalOrganisations(dataTableRequest).map(x => x.data);
return this.organisationService.searchPublicOrganisations(dataTableRequest).map(x => x.data);
}
displayLabel(value) {