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)
@RolesAllowed(ADMIN)
public Catalog modify(Catalog catalog) {
Catalog originalCatalog = entityManager.find(Catalog.class, catalog.getId());
checkNotNull(originalCatalog);
if (catalog.getRootCategoriesIds() != null) {
List<Category> newCategories = new ArrayList<>();
catalog.getRootCategoriesIds().forEach(categoryId -> newCategories.add(entityManager.find(Category.class, categoryId)));
catalog.setRootCategories(newCategories);
} else {
catalog.setRootCategories(originalCatalog.getRootCategories());
}
catalog.setPresentationByLocale(originalCatalog.getPresentationByLocale());
return entityManager.merge(catalog);
}
use of org.rembx.jeeshop.catalog.model.Catalog in project jeeshop by remibantos.
the class Catalogs method findCategories.
@GET
@Path("/{catalogId}/categories")
@Produces(MediaType.APPLICATION_JSON)
@PermitAll
public List<Category> findCategories(@PathParam("catalogId") @NotNull Long catalogId, @QueryParam("locale") String locale) {
Catalog catalog = entityManager.find(Catalog.class, catalogId);
checkNotNull(catalog);
List<Category> rootCategories = catalog.getRootCategories();
if (rootCategories.isEmpty()) {
return new ArrayList<>();
}
if (isAdminUser(sessionContext)) {
return rootCategories;
} else {
return catalogItemFinder.findVisibleCatalogItems(category, rootCategories, locale);
}
}
use of org.rembx.jeeshop.catalog.model.Catalog in project jeeshop by remibantos.
the class Catalogs method findPresentationsLocales.
@GET
@Path("/{catalogId}/presentationslocales")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({ ADMIN, ADMIN_READONLY })
public Set<String> findPresentationsLocales(@PathParam("catalogId") @NotNull Long catalogId) {
Catalog catalog = entityManager.find(Catalog.class, catalogId);
checkNotNull(catalog);
return catalog.getPresentationByLocale().keySet();
}
use of org.rembx.jeeshop.catalog.model.Catalog in project jeeshop by remibantos.
the class Catalogs method findCategories.
@GET
@Path("/{catalogId}/categories")
@Produces(MediaType.APPLICATION_JSON)
@PermitAll
public List<Category> findCategories(@Context SecurityContext securityContext, @PathParam("catalogId") @NotNull Long catalogId, @QueryParam("locale") String locale) {
Catalog catalog = entityManager.find(Catalog.class, catalogId);
checkNotNull(catalog);
List<Category> rootCategories = catalog.getRootCategories();
if (rootCategories.isEmpty()) {
return new ArrayList<>();
}
if (isAdminUser(securityContext) || isOwner(securityContext, catalog.getOwner())) {
return rootCategories;
} else {
return catalogItemFinder.findVisibleCatalogItems(category, rootCategories, locale);
}
}
use of org.rembx.jeeshop.catalog.model.Catalog 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();
}
Aggregations