use of org.rembx.jeeshop.rest.WebApplicationException in project jeeshop by remibantos.
the class Orders method find.
@GET
@Path("/{orderId}")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({ ADMIN, ADMIN_READONLY, USER })
public Order find(@PathParam("orderId") @NotNull Long orderId, @QueryParam("enhanced") Boolean enhanced) {
Order order = entityManager.find(Order.class, orderId);
if (sessionContext.isCallerInRole(USER) && !sessionContext.isCallerInRole(ADMIN)) {
User authenticatedUser = userFinder.findByLogin(sessionContext.getCallerPrincipal().getName());
if (!order.getUser().equals(authenticatedUser)) {
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}
}
if (enhanced != null && enhanced) {
orderFinder.enhanceOrder(order);
}
checkNotNull(order);
return order;
}
use of org.rembx.jeeshop.rest.WebApplicationException in project jeeshop by remibantos.
the class Catalogs method findPresentationsLocales.
@GET
@Path("/{catalogId}/presentationslocales")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({ ADMIN, STORE_ADMIN, ADMIN_READONLY })
public Set<String> findPresentationsLocales(@Context SecurityContext securityContext, @PathParam("catalogId") @NotNull Long catalogId) {
Catalog catalog = entityManager.find(Catalog.class, catalogId);
checkNotNull(catalog);
if (!isAdminUser(securityContext) && !isOwner(securityContext, catalog.getOwner()))
throw new WebApplicationException(Response.Status.FORBIDDEN);
return catalog.getPresentationByLocale().keySet();
}
use of org.rembx.jeeshop.rest.WebApplicationException 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 org.rembx.jeeshop.rest.WebApplicationException 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 org.rembx.jeeshop.rest.WebApplicationException in project jeeshop by remibantos.
the class CatalogItemFinderTest method find_NotVisibleCatalogItem_ShouldThrowForbiddenException.
@Test
public void find_NotVisibleCatalogItem_ShouldThrowForbiddenException() {
try {
instance.filterVisible(new Catalog(), null);
fail("should have thrown ex");
} catch (WebApplicationException e) {
assertEquals(Response.Status.FORBIDDEN, e.getResponse().getStatusInfo());
}
}
Aggregations