Fixes bug on "Search bar" not fetching published DMP and published Dataset Descriptions.

This commit is contained in:
gkolokythas 2020-01-03 16:52:27 +02:00
parent 290aa5260c
commit 0f6583ca4b
7 changed files with 98 additions and 35 deletions

View File

@ -1,6 +1,7 @@
package eu.eudat.controllers; package eu.eudat.controllers;
import eu.eudat.logic.managers.DashBoardManager; import eu.eudat.logic.managers.DashBoardManager;
import eu.eudat.logic.security.claims.ClaimedAuthorities;
import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.data.dashboard.recent.RecentActivity; import eu.eudat.models.data.dashboard.recent.RecentActivity;
import eu.eudat.models.data.dashboard.searchbar.SearchBarItem; import eu.eudat.models.data.dashboard.searchbar.SearchBarItem;
@ -8,6 +9,7 @@ import eu.eudat.models.data.dashboard.statistics.DashBoardStatistics;
import eu.eudat.models.data.helpers.responses.ResponseItem; import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.models.data.security.Principal; import eu.eudat.models.data.security.Principal;
import eu.eudat.types.ApiMessageCode; import eu.eudat.types.ApiMessageCode;
import eu.eudat.types.Authorities;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -46,7 +48,8 @@ public class DashBoardController extends BaseController {
} }
@RequestMapping(method = RequestMethod.GET, value = {"/dashboard/search"}, produces = "application/json") @RequestMapping(method = RequestMethod.GET, value = {"/dashboard/search"}, produces = "application/json")
public ResponseEntity<ResponseItem<List<SearchBarItem>>> search(@RequestParam(name = "like") String like, Principal principal) { public ResponseEntity<ResponseItem<List<SearchBarItem>>> search(@RequestParam(name = "like") String like,
@ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) {
List<SearchBarItem> searchBarItemList = dashBoardManager.searchUserData(like, principal); List<SearchBarItem> searchBarItemList = dashBoardManager.searchUserData(like, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<SearchBarItem>>().status(ApiMessageCode.NO_MESSAGE).payload(searchBarItemList)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<SearchBarItem>>().status(ApiMessageCode.NO_MESSAGE).payload(searchBarItemList));
} }

View File

@ -132,7 +132,6 @@ public class DashBoardManager {
} }
public List<SearchBarItem> searchUserData(String like, Principal principal) { public List<SearchBarItem> searchUserData(String like, Principal principal) {
RecentActivity activity = new RecentActivity();
UserInfo user = new UserInfo(); UserInfo user = new UserInfo();
user.setId(principal.getId()); user.setId(principal.getId());
DMPDao dataManagementPlanRepository = databaseRepository.getDmpDao(); DMPDao dataManagementPlanRepository = databaseRepository.getDmpDao();
@ -141,32 +140,53 @@ public class DashBoardManager {
List<Integer> roles = new LinkedList<>(); List<Integer> roles = new LinkedList<>();
List<SearchBarItem> searchBarItems = new LinkedList<>(); List<SearchBarItem> searchBarItems = new LinkedList<>();
CompletableFuture<List<SearchBarItem>> dmps = dataManagementPlanRepository.getAuthenticated(dataManagementPlanRepository.asQueryable(), principal.getId(), roles)
.withHint("dmpRecentActivity") CompletableFuture<List<SearchBarItem>> publicDmps = dataManagementPlanRepository.asQueryable()
.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + like.toUpperCase() + "%")) .where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + like.toUpperCase() + "%"))
.where((builder, root) -> builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue())) .where((builder, root) -> builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue()))
.where((builder, root) -> builder.equal(root.get("isPublic"), true))
.orderBy((builder, root) -> builder.desc(root.get("modified"))) .orderBy((builder, root) -> builder.desc(root.get("modified")))
.selectAsync(item -> new SearchBarItem(item.getId().toString(), item.getLabel(), SearchBarItemType.DMP.getValue())) .selectAsync(item -> new SearchBarItem(item.getId().toString(), item.getLabel(), SearchBarItemType.DMP.getValue(), true))
.whenComplete((dmpItems, throwable) -> searchBarItems.addAll(dmpItems)); .whenComplete((dmpItems, throwable) -> searchBarItems.addAll(dmpItems));
CompletableFuture<List<SearchBarItem>> datasets = datasetRepository.getAuthenticated(datasetRepository.asQueryable(), user, roles) CompletableFuture<List<SearchBarItem>> publicDatasets = datasetRepository.asQueryable()
.withHint("datasetRecentActivity")
.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + like.toUpperCase() + "%")) .where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + like.toUpperCase() + "%"))
.where((builder, root) -> builder.notEqual(root.get("status"), Dataset.Status.DELETED.getValue())) .where((builder, root) -> builder.equal(root.get("status"), Dataset.Status.FINALISED.getValue()))
.where((builder, root) -> builder.notEqual(root.get("status"), Dataset.Status.CANCELED.getValue())) .where((builder, root) -> builder.equal(root.get("dmp").get("isPublic"), true))
.orderBy((builder, root) -> builder.desc(root.get("modified"))) .orderBy((builder, root) -> builder.desc(root.get("modified")))
.selectAsync(item -> new SearchBarItem(item.getId().toString(), item.getLabel(), SearchBarItemType.DATASET.getValue())) .selectAsync(item -> new SearchBarItem(item.getId().toString(), item.getLabel(), SearchBarItemType.DATASET.getValue(), true))
.whenComplete((dataSetItems, throwable) -> searchBarItems.addAll(dataSetItems)); .whenComplete((dataSetItems, throwable) -> searchBarItems.addAll(dataSetItems));
CompletableFuture<List<SearchBarItem>> grants = grantRepository.getAuthenticated(grantRepository.asQueryable(), user) if (principal.getId() != null) {
.withHint("grantRecentActivity") CompletableFuture<List<SearchBarItem>> dmps = dataManagementPlanRepository.getAuthenticated(dataManagementPlanRepository.asQueryable(), principal.getId(), roles)
.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + like.toUpperCase() + "%")) .withHint("dmpRecentActivity")
.orderBy((builder, root) -> builder.desc(root.get("modified"))) .where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + like.toUpperCase() + "%"))
.selectAsync(item -> new SearchBarItem(item.getId().toString(), item.getLabel(), SearchBarItemType.GRANT.getValue())) .where((builder, root) -> builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue()))
.whenComplete((grantItems, throwable) -> searchBarItems.addAll(grantItems)); .orderBy((builder, root) -> builder.desc(root.get("modified")))
.selectAsync(item -> new SearchBarItem(item.getId().toString(), item.getLabel(), SearchBarItemType.DMP.getValue(), false))
.whenComplete((dmpItems, throwable) -> searchBarItems.addAll(dmpItems));
CompletableFuture<List<SearchBarItem>> datasets = datasetRepository.getAuthenticated(datasetRepository.asQueryable(), user, roles)
.withHint("datasetRecentActivity")
.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + like.toUpperCase() + "%"))
.where((builder, root) -> builder.notEqual(root.get("status"), Dataset.Status.DELETED.getValue()))
.where((builder, root) -> builder.notEqual(root.get("status"), Dataset.Status.CANCELED.getValue()))
.orderBy((builder, root) -> builder.desc(root.get("modified")))
.selectAsync(item -> new SearchBarItem(item.getId().toString(), item.getLabel(), SearchBarItemType.DATASET.getValue(), false))
.whenComplete((dataSetItems, throwable) -> searchBarItems.addAll(dataSetItems));
CompletableFuture<List<SearchBarItem>> grants = grantRepository.getAuthenticated(grantRepository.asQueryable(), user)
.withHint("grantRecentActivity")
.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + like.toUpperCase() + "%"))
.orderBy((builder, root) -> builder.desc(root.get("modified")))
.selectAsync(item -> new SearchBarItem(item.getId().toString(), item.getLabel(), SearchBarItemType.GRANT.getValue(), false))
.whenComplete((grantItems, throwable) -> searchBarItems.addAll(grantItems));
CompletableFuture.allOf(grants, dmps, datasets, publicDmps, publicDatasets).join();
} else {
CompletableFuture.allOf(publicDmps, publicDatasets).join();
}
CompletableFuture.allOf(grants, dmps, datasets).join();
return searchBarItems; return searchBarItems;
} }
} }

View File

@ -1,17 +1,16 @@
package eu.eudat.models.data.dashboard.searchbar; package eu.eudat.models.data.dashboard.searchbar;
/**
* Created by ikalyvas on 7/26/2018.
*/
public class SearchBarItem { public class SearchBarItem {
private String id; private String id;
private String label; private String label;
private int type; private int type;
private boolean isPublished;
public SearchBarItem(String id, String label, int type) { public SearchBarItem(String id, String label, int type, boolean isPublished) {
this.id = id; this.id = id;
this.label = label; this.label = label;
this.type = type; this.type = type;
this.isPublished = isPublished;
} }
public String getId() { public String getId() {
@ -37,4 +36,12 @@ public class SearchBarItem {
public void setType(int type) { public void setType(int type) {
this.type = type; this.type = type;
} }
public boolean getIsPublished() {
return isPublished;
}
public void setPublished(boolean published) {
isPublished = published;
}
} }

View File

@ -4,4 +4,5 @@ export interface SearchBarItem {
id: string; id: string;
label: string; label: string;
type: SearchBarType; type: SearchBarType;
isPublished: boolean;
} }

View File

@ -8,7 +8,7 @@
<mat-option *ngFor="let option of (filteredOptions | async)" [value]="option" class="option"> <mat-option *ngFor="let option of (filteredOptions | async)" [value]="option" class="option">
<span>{{ option.label }}</span> <span>{{ option.label }}</span>
<br /> <br />
<small>{{ transformType(option.type) }}</small> <small>{{ transformType(option.type, option.isPublished) }}</small>
</mat-option> </mat-option>
</mat-autocomplete> </mat-autocomplete>
</form> </form>

View File

@ -1,5 +1,5 @@
import {mergeMap, distinctUntilChanged, debounceTime} from 'rxjs/operators'; import { mergeMap, distinctUntilChanged, debounceTime } from 'rxjs/operators';
import { Component, OnInit } from "@angular/core"; import { Component, OnInit } from "@angular/core";
import { AuthService } from '../../../core/services/auth/auth.service'; import { AuthService } from '../../../core/services/auth/auth.service';
import { FormControl } from "@angular/forms"; import { FormControl } from "@angular/forms";
@ -7,6 +7,7 @@ import { SearchBarService } from '../../../core/services/search-bar/search-bar.s
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { Observable } from "rxjs"; import { Observable } from "rxjs";
import { SearchBarItem } from "../../../core/model/dashboard/search-bar-item"; import { SearchBarItem } from "../../../core/model/dashboard/search-bar-item";
import { TranslateService } from "@ngx-translate/core";
export enum SearchBarType { export enum SearchBarType {
Dataset = 0, Dataset = 0,
@ -24,12 +25,17 @@ export class SearchComponent implements OnInit {
public searchControl = new FormControl(); public searchControl = new FormControl();
filteredOptions: Observable<SearchBarItem[]>; filteredOptions: Observable<SearchBarItem[]>;
constructor(private authentication: AuthService, private router: Router, private searchBarService: SearchBarService) {} constructor(
private authentication: AuthService,
private router: Router,
private searchBarService: SearchBarService,
private language: TranslateService
) { }
ngOnInit() { ngOnInit() {
this.filteredOptions = this.searchControl.valueChanges.pipe(debounceTime(500),distinctUntilChanged(),mergeMap(x => { this.filteredOptions = this.searchControl.valueChanges.pipe(debounceTime(500), distinctUntilChanged(), mergeMap(x => {
return this.searchBarService.search(x); return this.searchBarService.search(x);
}),); }));
} }
public isAuthenticated(): boolean { public isAuthenticated(): boolean {
@ -40,16 +46,36 @@ export class SearchComponent implements OnInit {
this.search = false; this.search = false;
this.searchControl.patchValue(null); this.searchControl.patchValue(null);
const selectedSearchBarItem = event.option.value; const selectedSearchBarItem = event.option.value;
if (selectedSearchBarItem.type === SearchBarType.Dataset) { this.router.navigate(['datasets/edit/' + selectedSearchBarItem.id]); } if (!selectedSearchBarItem.isPublished) {
if (selectedSearchBarItem.type === SearchBarType.Grant) { this.router.navigate(['plans/grant/' + selectedSearchBarItem.id]); } if (selectedSearchBarItem.type === SearchBarType.Dataset) { this.router.navigate(['datasets/edit/' + selectedSearchBarItem.id]); }
if (selectedSearchBarItem.type === SearchBarType.Dmp) { this.router.navigate(['plans/overview/' + selectedSearchBarItem.id]); } if (selectedSearchBarItem.type === SearchBarType.Grant) { this.router.navigate(['plans/grant/' + selectedSearchBarItem.id]); }
if (selectedSearchBarItem.type === SearchBarType.Dmp) { this.router.navigate(['plans/overview/' + selectedSearchBarItem.id]); }
} else {
if (selectedSearchBarItem.type === SearchBarType.Dataset) { this.router.navigate(['datasets/publicEdit/' + selectedSearchBarItem.id]); }
if (selectedSearchBarItem.type === SearchBarType.Dmp) { this.router.navigate(['explore-plans/overview/' + selectedSearchBarItem.id]); }
}
} }
transformType(type) { transformType(type, isPublished) {
let subtitle: string;
switch (type) { switch (type) {
case SearchBarType.Dataset: return 'Dataset'; case SearchBarType.Dataset: {
case SearchBarType.Dmp: return 'DMP'; subtitle = this.language.instant('NAV-BAR.SEARCH.DATASET');
case SearchBarType.Grant: return 'Grant'; break;
}
case SearchBarType.Dmp: {
subtitle = this.language.instant('NAV-BAR.SEARCH.DMP');
break;
}
case SearchBarType.Grant: {
subtitle = this.language.instant('NAV-BAR.SEARCH.GRANT');
break;
}
}
if (isPublished) {
return subtitle + " - " + this.language.instant('NAV-BAR.SEARCH.PUBLISHED')
} else {
return subtitle;
} }
} }
} }

View File

@ -175,7 +175,13 @@
"DATASET-TEMPLATES": "DATASET TEMPLATES", "DATASET-TEMPLATES": "DATASET TEMPLATES",
"TEMPLATE": "TEMPLATE", "TEMPLATE": "TEMPLATE",
"DMP-TEMPLATES": "DMP TEMPLATES", "DMP-TEMPLATES": "DMP TEMPLATES",
"USERS-BREADCRUMB": "USERS" "USERS-BREADCRUMB": "USERS",
"SEARCH": {
"DATASET": "Dataset Description",
"DMP": "DMP",
"GRANT": "Grant",
"PUBLISHED": "Published"
}
}, },
"SIDE-BAR": { "SIDE-BAR": {
"GENERAL": "GENERAL", "GENERAL": "GENERAL",