use of org.rembx.jeeshop.catalog.model.Catalog 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.catalog.model.Catalog in project jeeshop by remibantos.
the class CatalogsCT method modifyUnknownCatalog_ShouldThrowNotFoundException.
@Test
public void modifyUnknownCatalog_ShouldThrowNotFoundException() {
tester.setStoreAdminUser();
Catalog detachedCatalogToModify = new Catalog(9999L, null);
try {
tester.test_modify(detachedCatalogToModify);
fail("should have thrown ex");
} catch (WebApplicationException e) {
assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.NOT_FOUND);
}
}
use of org.rembx.jeeshop.catalog.model.Catalog in project jeeshop by remibantos.
the class CatalogsCT method find_withIdOfVisibleCatalog_ShouldReturnExpectedCatalog.
@Test
public void find_withIdOfVisibleCatalog_ShouldReturnExpectedCatalog() {
tester.setStoreAdminUser();
Catalog catalog = localService.find(tester.getSecurityContext(), tester.getFixtures().getCatalogId(), null);
assertThat(catalog).isNotNull();
assertThat(catalog.isVisible()).isTrue();
}
use of org.rembx.jeeshop.catalog.model.Catalog 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());
}
}
use of org.rembx.jeeshop.catalog.model.Catalog in project jeeshop by remibantos.
the class CatalogsCT method delete_shouldThrowForbidden_for_store_admin.
@Test
public void delete_shouldThrowForbidden_for_store_admin() {
try {
tester.setStoreAdminUser();
Catalog catalog = new Catalog("catalog");
catalog.setOwner("test@test.org");
tester.test_delete(catalog);
fail("Should have throw an exception");
} catch (WebApplicationException e) {
assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.FORBIDDEN);
}
}
Aggregations