use of org.rembx.jeeshop.catalog.model.Store in project jeeshop by remibantos.
the class StoresCT method create_shouldSetupOwner_for_admin.
@Test
public void create_shouldSetupOwner_for_admin() {
tester.setAdminUser();
Store store = new Store("Superstore");
store.setOwner(TestCatalog.OWNER);
Store actualStore = tester.test_create(store);
assertThat(actualStore).isNotNull();
assertThat(actualStore.getOwner()).isEqualTo(TestCatalog.OWNER);
}
use of org.rembx.jeeshop.catalog.model.Store 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.Store in project jeeshop by remibantos.
the class Stores method findPresentationByLocale.
@Path("/{storeId}/presentations/{locale}")
@PermitAll
public PresentationResource findPresentationByLocale(@PathParam("storedId") @NotNull Long storeId, @NotNull @PathParam("locale") String locale) {
Store store = entityManager.find(Store.class, storeId);
checkNotNull(store);
Presentation presentation = store.getPresentationByLocale().get(locale);
return presentationResource.init(store, locale, presentation);
}
use of org.rembx.jeeshop.catalog.model.Store 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.Store 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);
}
}
Aggregations