Search in sources :

Example 1 with Catalog

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);
}
Also used : Category(org.rembx.jeeshop.catalog.model.Category) ArrayList(java.util.ArrayList) Catalog(org.rembx.jeeshop.catalog.model.Catalog) RolesAllowed(javax.annotation.security.RolesAllowed)

Example 2 with 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);
    }
}
Also used : Category(org.rembx.jeeshop.catalog.model.Category) ArrayList(java.util.ArrayList) Catalog(org.rembx.jeeshop.catalog.model.Catalog) PermitAll(javax.annotation.security.PermitAll)

Example 3 with Catalog

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();
}
Also used : Catalog(org.rembx.jeeshop.catalog.model.Catalog) RolesAllowed(javax.annotation.security.RolesAllowed)

Example 4 with 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(@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);
    }
}
Also used : Category(org.rembx.jeeshop.catalog.model.Category) ArrayList(java.util.ArrayList) Catalog(org.rembx.jeeshop.catalog.model.Catalog) PermitAll(javax.annotation.security.PermitAll)

Example 5 with Catalog

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();
}
Also used : WebApplicationException(org.rembx.jeeshop.rest.WebApplicationException) Catalog(org.rembx.jeeshop.catalog.model.Catalog) RolesAllowed(javax.annotation.security.RolesAllowed)

Aggregations

Catalog (org.rembx.jeeshop.catalog.model.Catalog)22 Test (org.junit.jupiter.api.Test)10 TestCatalog (org.rembx.jeeshop.catalog.test.TestCatalog)10 WebApplicationException (org.rembx.jeeshop.rest.WebApplicationException)9 RolesAllowed (javax.annotation.security.RolesAllowed)7 ArrayList (java.util.ArrayList)6 PermitAll (javax.annotation.security.PermitAll)4 Category (org.rembx.jeeshop.catalog.model.Category)4 Transactional (javax.transaction.Transactional)3 Store (org.rembx.jeeshop.catalog.model.Store)2 Test (org.junit.Test)1 Presentation (org.rembx.jeeshop.catalog.model.Presentation)1