Adds "Role" filter on Published DMPs and Published Dataset Description on backend. (Issue #175)

This commit is contained in:
gkolokythas 2019-09-26 18:33:41 +03:00
parent 0c4c818acd
commit f00633ea71
8 changed files with 48 additions and 6 deletions

View File

@ -11,6 +11,7 @@ public class DataManagementPlanPublicCriteria extends Criteria<DMP> {
private List<UUID> grants;
public List<UUID> datasetProfile;
private List<String> dmpOrganisations;
private Integer role;
public GrantStateType getGrantStatus() {
return grantStatus;
@ -39,4 +40,11 @@ public class DataManagementPlanPublicCriteria extends Criteria<DMP> {
public void setDmpOrganisations(List<String> dmpOrganisations) {
this.dmpOrganisations = dmpOrganisations;
}
public Integer getRole() {
return role;
}
public void setRole(Integer role) {
this.role = role;
}
}

View File

@ -17,6 +17,7 @@ public class DatasetPublicCriteria extends Criteria<Dataset>{
private List<String> dmpOrganisations;
private List<Tag> tags;
private List<UUID> dmpIds;
private Integer role;
public GrantStateType getGrantStatus() {
return grantStatus;
@ -59,4 +60,11 @@ public class DatasetPublicCriteria extends Criteria<Dataset>{
public void setDmpIds(List<UUID> dmpIds) {
this.dmpIds = dmpIds;
}
public Integer getRole() {
return role;
}
public void setRole(Integer role) {
this.role = role;
}
}

View File

@ -45,6 +45,7 @@ public class DatasetPublicTableRequest extends TableQuery<DatasetPublicCriteria,
.where(((builder, root) -> root.get("profile").get("id").in(this.getCriteria().getDatasetProfile())));
if (this.getCriteria().getDmpOrganisations() != null && !this.getCriteria().getDmpOrganisations().isEmpty()) query
.where(((builder, root) -> root.join("dmp").join("organisations").get("reference").in(this.getCriteria().getDmpOrganisations())));
query.where((builder, root) -> builder.notEqual(root.get("status"), Dataset.Status.DELETED.getValue()));
return query;
}

View File

@ -218,8 +218,10 @@ public class DMPs extends BaseController {
@RequestMapping(method = RequestMethod.POST, value = {"/public/paged"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<DataTableData<DataManagementPlanListingModel>>> getPublicPaged(@RequestBody DataManagmentPlanPublicTableRequest dmpTableRequest, @RequestParam String fieldsGroup) throws Exception {
DataTableData<DataManagementPlanListingModel> dmp = this.dataManagementPlanManager.getPaged(dmpTableRequest, fieldsGroup);
ResponseEntity<ResponseItem<DataTableData<DataManagementPlanListingModel>>> getPublicPaged(@RequestBody DataManagmentPlanPublicTableRequest dmpTableRequest,
@ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal,
@RequestParam String fieldsGroup) throws Exception {
DataTableData<DataManagementPlanListingModel> dmp = this.dataManagementPlanManager.getPublicPaged(dmpTableRequest, fieldsGroup, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DataManagementPlanListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dmp));
}

View File

@ -46,7 +46,8 @@ public class Datasets extends BaseController {
@RequestMapping(method = RequestMethod.POST, value = {"/public/paged"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<DataTableData<DatasetListingModel>>> getPublicPaged(@RequestBody DatasetPublicTableRequest datasetTableRequest, @ClaimedAuthorities(claims = {Authorities.ANONYMOUS}) Principal principal) throws Exception {
ResponseEntity<ResponseItem<DataTableData<DatasetListingModel>>> getPublicPaged(@RequestBody DatasetPublicTableRequest datasetTableRequest,
@ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) throws Exception {
DataTableData<DatasetListingModel> dataTable = this.datasetManager.getPaged(datasetTableRequest, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DatasetListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
}

View File

@ -37,13 +37,17 @@ public final class PrincipalArgumentResolver implements HandlerMethodArgumentRes
public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer modelAndViewContainer, NativeWebRequest nativeWebRequest, WebDataBinderFactory webDataBinderFactory) throws Exception {
String token = nativeWebRequest.getHeader("AuthToken");
Boolean checkMailNull = ((ServletWebRequest) nativeWebRequest).getRequest().getRequestURI().startsWith("/api/emailConfirmation");
boolean checkMailNull = ((ServletWebRequest) nativeWebRequest).getRequest().getRequestURI().startsWith("/api/emailConfirmation");
AuthenticationService authenticationService = checkMailNull ? this.nonVerifiedUserAuthenticationService : this.verifiedUserAuthenticationService;
Optional<Annotation> claimsAnnotation = Arrays.stream(methodParameter.getParameterAnnotations()).filter(annotation -> annotation.annotationType().equals(ClaimedAuthorities.class)).findAny();
List<Authorities> claimList = claimsAnnotation.map(annotation -> Arrays.asList(((ClaimedAuthorities) annotation).claims())).orElse(Authorities.all());
if (claimList.size() == 1 && claimList.get(0).equals(Authorities.ANONYMOUS))
if (claimList.size() == 1 && claimList.get(0).equals(Authorities.ANONYMOUS)) {
return new Principal();
} else if (claimList.contains(Authorities.ANONYMOUS) && token == null) {
return new Principal();
}
if (token == null) throw new UnauthorisedException("Authentication Information Is Missing");
UUID authToken;
try {

View File

@ -59,6 +59,8 @@ import org.springframework.web.multipart.MultipartFile;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.JoinType;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
@ -128,9 +130,16 @@ public class DataManagementPlanManager {
return dataTable;
}
public DataTableData<DataManagementPlanListingModel> getPaged(DataManagmentPlanPublicTableRequest dataManagementPlanPublicTableRequest, String fieldsGroup) throws Exception {
public DataTableData<DataManagementPlanListingModel> getPublicPaged(DataManagmentPlanPublicTableRequest dataManagementPlanPublicTableRequest, String fieldsGroup, Principal principal) throws Exception {
dataManagementPlanPublicTableRequest.setQuery(databaseRepository.getDmpDao().asQueryable().withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class)));
QueryableList<DMP> items = dataManagementPlanPublicTableRequest.applyCriteria();
if (principal.getId() != null && dataManagementPlanPublicTableRequest.getCriteria().getRole() != null) {
items.where((builder, root) -> {
Join userJoin = root.join("users", JoinType.LEFT);
return builder.and(builder.equal(userJoin.join("user", JoinType.LEFT).get("id"), principal.getId()), builder.equal(userJoin.get("role"), dataManagementPlanPublicTableRequest.getCriteria().getRole()));
});
}
QueryableList<DMP> pagedItems = PaginationManager.applyPaging(items, dataManagementPlanPublicTableRequest);
DataTableData<DataManagementPlanListingModel> dataTable = new DataTableData<>();

View File

@ -46,6 +46,8 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import javax.activation.MimetypesFileTypeMap;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.JoinType;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
@ -141,6 +143,13 @@ public class DatasetManager {
} else
items.where((builder, root) -> root.get("id").in(new UUID[]{UUID.randomUUID()}));
}
if (principal.getId() != null && datasetTableRequest.getCriteria().getRole() != null) {
items.where((builder, root) -> {
Join userJoin = root.join("dmp", JoinType.LEFT).join("users", JoinType.LEFT);
return builder.and(builder.equal(userJoin.join("user", JoinType.LEFT).get("id"), principal.getId()), builder.equal(userJoin.get("role"), datasetTableRequest.getCriteria().getRole()));
});
}
String[] strings = new String[1];
strings[0] = "-dmp:publishedAt|join|";
datasetTableRequest.getOrderings().setFields(strings);