Search in sources :

Example 16 with Permissions

use of io.gravitee.rest.api.portal.rest.security.Permissions in project gravitee-management-rest-api by gravitee-io.

the class ApplicationAlertResource method updateAlert.

@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Permissions({ @Permission(value = RolePermission.APPLICATION_ALERT, acls = RolePermissionAction.UPDATE) })
public Response updateAlert(@PathParam("applicationId") String applicationId, @PathParam("alertId") String alertId, @Valid @NotNull(message = "Input must not be null.") AlertInput alertInput) {
    LOGGER.info("Updating alert {}", alertId);
    checkPlugins();
    final UpdateAlertTriggerEntity updateAlertTriggerEntity = alertMapper.convertToUpdate(alertInput);
    updateAlertTriggerEntity.setId(alertId);
    final AlertTriggerEntity updated = applicationAlertService.update(applicationId, updateAlertTriggerEntity);
    Alert alert = alertMapper.convert(updated);
    return Response.ok(alert).build();
}
Also used : UpdateAlertTriggerEntity(io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity) Alert(io.gravitee.rest.api.portal.rest.model.Alert) UpdateAlertTriggerEntity(io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity) AlertTriggerEntity(io.gravitee.rest.api.model.alert.AlertTriggerEntity) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Permissions(io.gravitee.rest.api.portal.rest.security.Permissions) PUT(javax.ws.rs.PUT)

Example 17 with Permissions

use of io.gravitee.rest.api.portal.rest.security.Permissions in project gravitee-management-rest-api by gravitee-io.

the class ApiRatingAnswersResource method createApiRatingAnswer.

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Permissions({ @Permission(value = RolePermission.API_RATING_ANSWER, acls = RolePermissionAction.CREATE) })
public Response createApiRatingAnswer(@PathParam("apiId") String apiId, @PathParam("ratingId") String ratingId, @Valid RatingAnswerInput ratingAnswerInput) {
    if (ratingAnswerInput == null) {
        throw new BadRequestException("Input must not be null.");
    }
    final ApiQuery apiQuery = new ApiQuery();
    apiQuery.setIds(Collections.singletonList(apiId));
    Collection<ApiEntity> userApis = apiService.findPublishedByUser(getAuthenticatedUserOrNull(), apiQuery);
    if (userApis.stream().anyMatch(a -> a.getId().equals(apiId))) {
        RatingEntity ratingEntity = ratingService.findById(ratingId);
        if (ratingEntity != null && ratingEntity.getApi().equals(apiId)) {
            NewRatingAnswerEntity ratingAnswerEntity = new NewRatingAnswerEntity();
            ratingAnswerEntity.setComment(ratingAnswerInput.getComment());
            ratingAnswerEntity.setRatingId(ratingId);
            RatingEntity updatedRating = ratingService.createAnswer(ratingAnswerEntity);
            return Response.status(Status.CREATED).entity(ratingMapper.convert(updatedRating, uriInfo)).build();
        }
        throw new RatingNotFoundException(ratingId, apiId);
    }
    throw new ApiNotFoundException(apiId);
}
Also used : ApiQuery(io.gravitee.rest.api.model.api.ApiQuery) RatingNotFoundException(io.gravitee.rest.api.service.exceptions.RatingNotFoundException) ApiNotFoundException(io.gravitee.rest.api.service.exceptions.ApiNotFoundException) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) NewRatingAnswerEntity(io.gravitee.rest.api.model.NewRatingAnswerEntity) RatingEntity(io.gravitee.rest.api.model.RatingEntity) Permissions(io.gravitee.rest.api.portal.rest.security.Permissions)

Example 18 with Permissions

use of io.gravitee.rest.api.portal.rest.security.Permissions in project gravitee-management-rest-api by gravitee-io.

the class ApplicationNotificationResource method get.

@GET
@Produces(MediaType.APPLICATION_JSON)
@Permissions({ @Permission(value = RolePermission.APPLICATION_NOTIFICATION, acls = RolePermissionAction.READ) })
public Response get(@PathParam("applicationId") String applicationId) {
    // Does application exists ?
    applicationService.findById(applicationId);
    final PortalNotificationConfigEntity portalConfig = portalNotificationConfigService.findById(getAuthenticatedUser(), NotificationReferenceType.APPLICATION, applicationId);
    final Set<String> hooks = new HashSet<>(portalConfig.getHooks());
    genericNotificationConfigService.findByReference(NotificationReferenceType.APPLICATION, applicationId).forEach(genericNotif -> hooks.addAll(genericNotif.getHooks()));
    return Response.ok(hooks).build();
}
Also used : PortalNotificationConfigEntity(io.gravitee.rest.api.model.notification.PortalNotificationConfigEntity) HashSet(java.util.HashSet) Permissions(io.gravitee.rest.api.portal.rest.security.Permissions)

Example 19 with Permissions

use of io.gravitee.rest.api.portal.rest.security.Permissions in project gravitee-management-rest-api by gravitee-io.

the class ApplicationResource method getPictureByApplicationId.

@GET
@Path("picture")
@Produces({ MediaType.WILDCARD, MediaType.APPLICATION_JSON })
@Permissions({ @Permission(value = RolePermission.APPLICATION_DEFINITION, acls = RolePermissionAction.READ) })
public Response getPictureByApplicationId(@Context Request request, @PathParam("applicationId") String applicationId) {
    applicationService.findById(applicationId);
    InlinePictureEntity image = applicationService.getPicture(applicationId);
    return createPictureResponse(request, image);
}
Also used : InlinePictureEntity(io.gravitee.rest.api.model.InlinePictureEntity) Permissions(io.gravitee.rest.api.portal.rest.security.Permissions)

Example 20 with Permissions

use of io.gravitee.rest.api.portal.rest.security.Permissions in project gravitee-management-rest-api by gravitee-io.

the class ApplicationResource method getBackgroundByApplicationId.

@GET
@Path("background")
@Produces({ MediaType.WILDCARD, MediaType.APPLICATION_JSON })
@Permissions({ @Permission(value = RolePermission.APPLICATION_DEFINITION, acls = RolePermissionAction.READ) })
public Response getBackgroundByApplicationId(@Context Request request, @PathParam("applicationId") String applicationId) {
    applicationService.findById(applicationId);
    InlinePictureEntity image = applicationService.getBackground(applicationId);
    return createPictureResponse(request, image);
}
Also used : InlinePictureEntity(io.gravitee.rest.api.model.InlinePictureEntity) Permissions(io.gravitee.rest.api.portal.rest.security.Permissions)

Aggregations

Permissions (io.gravitee.rest.api.portal.rest.security.Permissions)20 RatingEntity (io.gravitee.rest.api.model.RatingEntity)5 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)5 ApiQuery (io.gravitee.rest.api.model.api.ApiQuery)5 ApiNotFoundException (io.gravitee.rest.api.service.exceptions.ApiNotFoundException)5 RatingNotFoundException (io.gravitee.rest.api.service.exceptions.RatingNotFoundException)4 ApplicationEntity (io.gravitee.rest.api.model.ApplicationEntity)3 MemberEntity (io.gravitee.rest.api.model.MemberEntity)3 Produces (javax.ws.rs.Produces)3 InlinePictureEntity (io.gravitee.rest.api.model.InlinePictureEntity)2 UpdateApplicationEntity (io.gravitee.rest.api.model.UpdateApplicationEntity)2 UpdateRatingEntity (io.gravitee.rest.api.model.UpdateRatingEntity)2 AlertTriggerEntity (io.gravitee.rest.api.model.alert.AlertTriggerEntity)2 ApplicationSettings (io.gravitee.rest.api.model.application.ApplicationSettings)2 OAuthClientSettings (io.gravitee.rest.api.model.application.OAuthClientSettings)2 SimpleApplicationSettings (io.gravitee.rest.api.model.application.SimpleApplicationSettings)2 PortalNotificationConfigEntity (io.gravitee.rest.api.model.notification.PortalNotificationConfigEntity)2 MembershipService (io.gravitee.rest.api.service.MembershipService)2 SinglePrimaryOwnerException (io.gravitee.rest.api.service.exceptions.SinglePrimaryOwnerException)2 Consumes (javax.ws.rs.Consumes)2