use of org.rembx.jeeshop.catalog.model.Category 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.Category 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.Category 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.Category 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.Category in project jeeshop by remibantos.
the class CategoriesCT method modifyCategory_ShouldModifyCategoryAttributesAndPreserveChildProductsWhenNotProvided.
@Test
public void modifyCategory_ShouldModifyCategoryAttributesAndPreserveChildProductsWhenNotProvided() {
tester.setAdminUser();
Category category = new Category(tester.getFixtures().aCategoryWithProducts().getId(), "New name");
;
tester.test_modify(category);
assertThat(category.getName()).isEqualTo("New name");
assertThat(category.getChildProducts()).isNotEmpty();
}
Aggregations