Skip to content

Commit

Permalink
Adding �@UserConstraint annotation to FunctionCatalogResource
Browse files Browse the repository at this point in the history
  • Loading branch information
Davide Zerbetto committed May 24, 2024
1 parent b0964f6 commit 4f36dcf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
*/
package it.eng.knowage.knowageapi.resource;

import static it.eng.spagobi.commons.constants.CommunityFunctionalityConstants.CREATE_COCKPIT_FUNCTIONALITY;
import static it.eng.spagobi.commons.constants.CommunityFunctionalityConstants.CREATE_SELF_SERVICE_COCKPIT;
import static it.eng.spagobi.commons.constants.CommunityFunctionalityConstants.FUNCTIONS_CATALOG_MANAGEMENT;
import static it.eng.spagobi.commons.constants.CommunityFunctionalityConstants.FUNCTIONS_CATALOG_USAGE;

import java.util.List;
import java.util.Optional;
import java.util.UUID;
Expand All @@ -40,6 +45,7 @@
import org.springframework.validation.annotation.Validated;

import it.eng.knowage.boot.error.KnowageRuntimeException;
import it.eng.knowage.boot.interceptor.UserConstraint;
import it.eng.knowage.features.Feature;
import it.eng.knowage.knowageapi.resource.dto.FunctionCompleteDTO;
import it.eng.knowage.knowageapi.resource.dto.FunctionDTO;
Expand All @@ -62,6 +68,7 @@ public class FunctionCatalogResource {
@GET
@Path("/")
@Produces(MediaType.APPLICATION_JSON + "; charset=UTF-8")
@UserConstraint(functionalities = { FUNCTIONS_CATALOG_MANAGEMENT, FUNCTIONS_CATALOG_USAGE, CREATE_COCKPIT_FUNCTIONALITY, CREATE_SELF_SERVICE_COCKPIT })
public List<FunctionDTO> getAll(@QueryParam("s") @DefaultValue("") String searchString) {
try {
return api.find(searchString);
Expand All @@ -74,6 +81,7 @@ public List<FunctionDTO> getAll(@QueryParam("s") @DefaultValue("") String search
@GET
@Path("/completelist")
@Produces(MediaType.APPLICATION_JSON + "; charset=UTF-8")
@UserConstraint(functionalities = { FUNCTIONS_CATALOG_MANAGEMENT, FUNCTIONS_CATALOG_USAGE, CREATE_COCKPIT_FUNCTIONALITY, CREATE_SELF_SERVICE_COCKPIT })
public List<FunctionCompleteDTO> getAllComplete(@QueryParam("s") @DefaultValue("") String searchString) {
try {
return api.findComplete(searchString);
Expand All @@ -86,6 +94,7 @@ public List<FunctionCompleteDTO> getAllComplete(@QueryParam("s") @DefaultValue("
@GET
@Path("/{id}")
@Produces(MediaType.APPLICATION_JSON + "; charset=UTF-8")
@UserConstraint(functionalities = { FUNCTIONS_CATALOG_MANAGEMENT, FUNCTIONS_CATALOG_USAGE, CREATE_COCKPIT_FUNCTIONALITY, CREATE_SELF_SERVICE_COCKPIT })
public FunctionCompleteDTO get(@PathParam("id") UUID id) {
try {
return api.get(id);
Expand All @@ -100,6 +109,7 @@ public FunctionCompleteDTO get(@PathParam("id") UUID id) {
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON + "; charset=UTF-8")
@FeatureFlag(Feature.EDIT_FUNCTIONS_CATALOG)
@UserConstraint(functionalities = { FUNCTIONS_CATALOG_MANAGEMENT, FUNCTIONS_CATALOG_USAGE })
public Response create(FunctionCompleteDTO function) {
try {
FunctionCompleteDTO create = api.create(function);
Expand All @@ -115,6 +125,7 @@ public Response create(FunctionCompleteDTO function) {
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON + "; charset=UTF-8")
@FeatureFlag(Feature.EDIT_FUNCTIONS_CATALOG)
@UserConstraint(functionalities = { FUNCTIONS_CATALOG_MANAGEMENT, FUNCTIONS_CATALOG_USAGE })
public Response createWithNewUuid(FunctionCompleteDTO function) {
try {
function.setId(UUID.randomUUID());
Expand All @@ -132,6 +143,7 @@ public Response createWithNewUuid(FunctionCompleteDTO function) {
@DELETE
@Path("/{id}")
@Consumes(MediaType.APPLICATION_JSON)
@UserConstraint(functionalities = { FUNCTIONS_CATALOG_MANAGEMENT, FUNCTIONS_CATALOG_USAGE })
public Response delete(@PathParam("id") UUID id) {
try {
api.delete(id);
Expand All @@ -147,6 +159,7 @@ public Response delete(@PathParam("id") UUID id) {
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON + "; charset=UTF-8")
@FeatureFlag(Feature.EDIT_FUNCTIONS_CATALOG)
@UserConstraint(functionalities = { FUNCTIONS_CATALOG_MANAGEMENT, FUNCTIONS_CATALOG_USAGE })
public Response update(FunctionCompleteDTO function) {
try {
FunctionCompleteDTO ret = api.update(function);
Expand Down

0 comments on commit 4f36dcf

Please sign in to comment.