use of org.rembx.jeeshop.rest.WebApplicationException in project jeeshop by remibantos.
the class Stores method modify.
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Transactional
@RolesAllowed({ ADMIN, STORE_ADMIN })
public Store modify(@Context SecurityContext securityContext, Store store) {
Store originalCatalog = entityManager.find(Store.class, store.getId());
checkNotNull(originalCatalog);
if (!isOwner(securityContext, originalCatalog.getOwner()) && !isAdminUser(securityContext))
throw new WebApplicationException(Response.Status.FORBIDDEN);
if (store.getCatalogsIds() != null) {
List<Catalog> catalogs = new ArrayList<>();
store.getCatalogsIds().forEach(categoryId -> catalogs.add(entityManager.find(Catalog.class, categoryId)));
store.setCatalogs(catalogs);
} else {
store.setCatalogs(originalCatalog.getCatalogs());
}
store.setPresentationByLocale(originalCatalog.getPresentationByLocale());
return entityManager.merge(store);
}
use of org.rembx.jeeshop.rest.WebApplicationException in project jeeshop by remibantos.
the class Stores method delete.
@DELETE
@Transactional
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({ ADMIN, STORE_ADMIN })
@Path("/{storeId}")
public void delete(@Context SecurityContext securityContext, @PathParam("storeId") Long storeId) {
Store store = entityManager.find(Store.class, storeId);
checkNotNull(store);
if (isOwner(securityContext, store.getOwner()) || isAdminUser(securityContext)) {
entityManager.remove(store);
} else {
throw new WebApplicationException(Response.Status.FORBIDDEN);
}
}
use of org.rembx.jeeshop.rest.WebApplicationException in project jeeshop by remibantos.
the class StoresCT method create_shouldThrowBadRequest_whenOwnerIsNull_for_admin.
@Test
public void create_shouldThrowBadRequest_whenOwnerIsNull_for_admin() {
tester.setAdminUser();
Store store = new Store("Superstore");
try {
tester.test_create(store);
fail("should have thrown an exception");
} catch (WebApplicationException e) {
assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.BAD_REQUEST);
}
}
use of org.rembx.jeeshop.rest.WebApplicationException in project jeeshop by remibantos.
the class CatalogsCT method create_shouldThrowBadRequest_whenOwnerIsNull_for_admin.
@Test
public void create_shouldThrowBadRequest_whenOwnerIsNull_for_admin() {
tester.setAdminUser();
Catalog catalog = new Catalog("Catalog");
try {
tester.test_create(catalog);
fail("should have thrown an exception");
} catch (WebApplicationException e) {
assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.BAD_REQUEST);
}
}
use of org.rembx.jeeshop.rest.WebApplicationException in project jeeshop by remibantos.
the class CatalogsCT method modifyNonManagedCatalog_ShouldThrowForbiddenException.
@Test
public void modifyNonManagedCatalog_ShouldThrowForbiddenException() {
tester.setSAnotherStoreAdminUser();
Catalog detachedCatalogToModify = new Catalog(1L, "name");
try {
tester.test_modify(detachedCatalogToModify);
fail("should have thrown ex");
} catch (WebApplicationException e) {
assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.FORBIDDEN);
}
}
Aggregations