use of javax.annotation.security.RolesAllowed in project jeeshop by remibantos.
the class Catalogs method modify.
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Transactional
@RolesAllowed({ ADMIN, STORE_ADMIN })
public Catalog modify(@Context SecurityContext securityContext, Catalog catalogToModify) {
Catalog originalCatalog = entityManager.find(Catalog.class, catalogToModify.getId());
checkNotNull(originalCatalog);
if (!isAdminUser(securityContext) && !isOwner(securityContext, originalCatalog.getOwner()))
throw new WebApplicationException(Response.Status.FORBIDDEN);
if (catalogToModify.getRootCategoriesIds() != null) {
List<Category> newCategories = new ArrayList<>();
catalogToModify.getRootCategoriesIds().forEach(categoryId -> newCategories.add(entityManager.find(Category.class, categoryId)));
catalogToModify.setRootCategories(newCategories);
} else {
catalogToModify.setRootCategories(originalCatalog.getRootCategories());
}
catalogToModify.setPresentationByLocale(originalCatalog.getPresentationByLocale());
return entityManager.merge(catalogToModify);
}
use of javax.annotation.security.RolesAllowed in project jeeshop by remibantos.
the class Products method findPresentationsLocales.
@GET
@Path("/{productId}/presentationslocales")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({ ADMIN, STORE_ADMIN, ADMIN_READONLY })
public Set<String> findPresentationsLocales(@Context SecurityContext securityContext, @PathParam("productId") @NotNull Long productId) {
Product product = entityManager.find(Product.class, productId);
checkNotNull(product);
if (!isAdminUser(securityContext) && !isOwner(securityContext, product.getOwner()))
throw new WebApplicationException(Response.Status.FORBIDDEN);
return product.getPresentationByLocale().keySet();
}
use of javax.annotation.security.RolesAllowed in project jeeshop by remibantos.
the class Stores method findPresentationsLocales.
@GET
@Path("/{storeId}/presentationslocales")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({ ADMIN, STORE_ADMIN, ADMIN_READONLY })
public Set<String> findPresentationsLocales(@Context SecurityContext securityContext, @PathParam("storeId") @NotNull Long storeId) {
Store loadedStore = entityManager.find(Store.class, storeId);
checkNotNull(loadedStore);
if (!isAdminUser(securityContext) && !isOwner(securityContext, loadedStore.getOwner()))
throw new WebApplicationException(Response.Status.FORBIDDEN);
return loadedStore.getPresentationByLocale().keySet();
}
use of javax.annotation.security.RolesAllowed in project jeeshop by remibantos.
the class Categories method delete.
@DELETE
@Transactional
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({ ADMIN, STORE_ADMIN })
@Path("/{categoryId}")
public void delete(@Context SecurityContext securityContext, @PathParam("categoryId") Long categoryId) {
Category category = entityManager.find(Category.class, categoryId);
checkNotNull(category);
if (!isOwner(securityContext, category.getOwner()) && !isAdminUser(securityContext))
throw new WebApplicationException(Response.Status.FORBIDDEN);
else {
List<Category> categoryHolders = catalogItemFinder.findForeignHolder(QCategory.category, QCategory.category.childCategories, category);
for (Category categoryHolder : categoryHolders) {
categoryHolder.getChildCategories().remove(category);
}
List<Catalog> catalogHolders = catalogItemFinder.findForeignHolder(QCatalog.catalog, QCatalog.catalog.rootCategories, category);
for (Catalog catalogHolder : catalogHolders) {
catalogHolder.getRootCategories().remove(category);
}
entityManager.remove(category);
}
}
use of javax.annotation.security.RolesAllowed in project jeeshop by remibantos.
the class Discounts method findPresentationsLocales.
@GET
@Path("/{discountId}/presentationslocales")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({ ADMIN, STORE_ADMIN, ADMIN_READONLY })
public Set<String> findPresentationsLocales(@Context SecurityContext securityContext, @PathParam("discountId") @NotNull Long discountId) {
Discount discount = entityManager.find(Discount.class, discountId);
checkNotNull(discount);
if (!isAdminUser(securityContext) && !isOwner(securityContext, discount.getOwner()))
throw new WebApplicationException(Response.Status.FORBIDDEN);
return discount.getPresentationByLocale().keySet();
}
Aggregations