use of org.rembx.jeeshop.catalog.model.Catalog in project jeeshop by remibantos.
the class Catalogs method delete.
@DELETE
@Transactional
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({ ADMIN, STORE_ADMIN })
@Path("/{catalogId}")
public void delete(@Context SecurityContext securityContext, @PathParam("catalogId") Long catalogId) {
Catalog loadedCatalog = entityManager.find(Catalog.class, catalogId);
checkNotNull(loadedCatalog);
if (isAdminUser(securityContext) || isOwner(securityContext, loadedCatalog.getOwner()))
entityManager.remove(loadedCatalog);
else
throw new WebApplicationException(Response.Status.FORBIDDEN);
}
use of org.rembx.jeeshop.catalog.model.Catalog 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.catalog.model.Catalog in project jeeshop by remibantos.
the class Stores method findCatalogs.
@GET
@Path("/{storeId}/catalogs")
@Produces(MediaType.APPLICATION_JSON)
@PermitAll
public List<Catalog> findCatalogs(@Context SecurityContext securityContext, @PathParam("storeId") @NotNull Long storeId, @QueryParam("locale") String locale) {
Store loadedStore = entityManager.find(Store.class, storeId);
checkNotNull(loadedStore);
List<Catalog> catalogs = loadedStore.getCatalogs();
if (catalogs.isEmpty()) {
return new ArrayList<>();
}
if (isAdminUser(securityContext) || isOwner(securityContext, loadedStore.getOwner())) {
return catalogs;
} else {
return catalogItemFinder.findVisibleCatalogItems(catalog, catalogs, locale);
}
}
use of org.rembx.jeeshop.catalog.model.Catalog in project jeeshop by remibantos.
the class CatalogsCT method create_shouldSetupOwner_for_store_admin.
@Test
public void create_shouldSetupOwner_for_store_admin() {
tester.setStoreAdminUser();
Catalog catalog = new Catalog("Catalog");
Catalog actualCatalog = tester.test_create(catalog);
assertThat(actualCatalog).isNotNull();
assertThat(actualCatalog.getOwner()).isEqualTo(TestCatalog.OWNER);
}
use of org.rembx.jeeshop.catalog.model.Catalog 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);
}
}
Aggregations