Search in sources :

Example 6 with Store

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);
}
Also used : Store(org.rembx.jeeshop.catalog.model.Store) Test(org.junit.jupiter.api.Test)

Example 7 with Store

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

Example 8 with 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);
}
Also used : Store(org.rembx.jeeshop.catalog.model.Store) Presentation(org.rembx.jeeshop.catalog.model.Presentation) PermitAll(javax.annotation.security.PermitAll)

Example 9 with Store

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

Example 10 with Store

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

Aggregations

Store (org.rembx.jeeshop.catalog.model.Store)18 Test (org.junit.jupiter.api.Test)13 WebApplicationException (org.rembx.jeeshop.rest.WebApplicationException)7 RolesAllowed (javax.annotation.security.RolesAllowed)3 ArrayList (java.util.ArrayList)2 PermitAll (javax.annotation.security.PermitAll)2 Transactional (javax.transaction.Transactional)2 Catalog (org.rembx.jeeshop.catalog.model.Catalog)2 Presentation (org.rembx.jeeshop.catalog.model.Presentation)1