Search in sources :

Example 1 with ReadableCatalog

use of com.salesmanager.shop.model.catalog.catalog.ReadableCatalog in project shopizer by shopizer-ecommerce.

the class CatalogApi method addCatalogEntry.

@PostMapping(value = "/private/catalog/{id}")
@ResponseStatus(HttpStatus.OK)
@ApiOperation(httpMethod = "POST", value = "Add catalog entry to catalog", notes = "", response = ReadableCatalogCategoryEntry.class)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public ReadableCatalogCategoryEntry addCatalogEntry(@PathVariable Long id, @RequestBody @Valid PersistableCatalogCategoryEntry catalogEntry, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) {
    ReadableCatalog c = catalogFacade.getCatalog(id, merchantStore, language);
    if (c == null) {
        throw new ResourceNotFoundException("Catalog id [" + id + "] not found");
    }
    catalogEntry.setCatalog(c.getCode());
    return catalogFacade.addCatalogEntry(catalogEntry, merchantStore, language);
}
Also used : ReadableCatalog(com.salesmanager.shop.model.catalog.catalog.ReadableCatalog) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException)

Example 2 with ReadableCatalog

use of com.salesmanager.shop.model.catalog.catalog.ReadableCatalog in project shopizer by shopizer-ecommerce.

the class CatalogFacadeImpl method saveCatalog.

@Override
public ReadableCatalog saveCatalog(PersistableCatalog catalog, MerchantStore store, Language language) {
    Validate.notNull(catalog, "Catalog cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(language, "Language cannot be null");
    Catalog catalogToSave = persistableCatalogMapper.convert(catalog, store, language);
    boolean existByCode = uniqueCatalog(catalog.getCode(), store);
    if (existByCode) {
        throw new OperationNotAllowedException("Catalog [" + catalog.getCode() + "] already exists");
    }
    catalogService.saveOrUpdate(catalogToSave, store);
    Catalog savedCatalog = catalogService.getByCode(catalogToSave.getCode(), store).get();
    return readableCatalogMapper.convert(savedCatalog, store, language);
}
Also used : OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ReadableCatalog(com.salesmanager.shop.model.catalog.catalog.ReadableCatalog) Catalog(com.salesmanager.core.model.catalog.catalog.Catalog) PersistableCatalog(com.salesmanager.shop.model.catalog.catalog.PersistableCatalog)

Example 3 with ReadableCatalog

use of com.salesmanager.shop.model.catalog.catalog.ReadableCatalog in project shopizer by shopizer-ecommerce.

the class CatalogFacadeImpl method getCatalog.

@Override
public ReadableCatalog getCatalog(Long id, MerchantStore store, Language language) {
    Validate.notNull(id, "Catalog id cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Catalog catalog = catalogService.getById(id, store).orElseThrow(() -> new ResourceNotFoundException("Catalog with id [" + id + "] not found"));
    return readableCatalogMapper.convert(catalog, store, language);
}
Also used : ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableCatalog(com.salesmanager.shop.model.catalog.catalog.ReadableCatalog) Catalog(com.salesmanager.core.model.catalog.catalog.Catalog) PersistableCatalog(com.salesmanager.shop.model.catalog.catalog.PersistableCatalog)

Example 4 with ReadableCatalog

use of com.salesmanager.shop.model.catalog.catalog.ReadableCatalog in project shopizer by shopizer-ecommerce.

the class CatalogFacadeImpl method getCatalog.

@Override
public ReadableCatalog getCatalog(String code, MerchantStore store, Language language) {
    Validate.notNull(code, "Catalog code cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(language, "Language cannot be null");
    Catalog catalog = catalogService.getByCode(code, store).orElseThrow(() -> new ResourceNotFoundException("Catalog with code [" + code + "] not found"));
    return readableCatalogMapper.convert(catalog, store, language);
}
Also used : ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableCatalog(com.salesmanager.shop.model.catalog.catalog.ReadableCatalog) Catalog(com.salesmanager.core.model.catalog.catalog.Catalog) PersistableCatalog(com.salesmanager.shop.model.catalog.catalog.PersistableCatalog)

Example 5 with ReadableCatalog

use of com.salesmanager.shop.model.catalog.catalog.ReadableCatalog in project shopizer by shopizer-ecommerce.

the class ReadableCatalogMapper method merge.

@Override
public ReadableCatalog merge(Catalog source, ReadableCatalog destination, MerchantStore store, Language language) {
    if (destination == null) {
        destination = new ReadableCatalog();
    }
    if (isPositive(source.getId())) {
        destination.setId(source.getId());
    }
    destination.setCode(source.getCode());
    destination.setDefaultCatalog(source.isDefaultCatalog());
    destination.setVisible(source.isVisible());
    Optional<ReadableMerchantStore> readableStore = Optional.ofNullable(source.getMerchantStore()).map(MerchantStore::getCode).map(code -> storeFacade.getByCode(code, language));
    readableStore.ifPresent(destination::setStore);
    destination.setDefaultCatalog(source.isDefaultCatalog());
    Optional<String> formattedCreationDate = Optional.ofNullable(source.getAuditSection()).map(AuditSection::getDateCreated).map(DateUtil::formatDate);
    formattedCreationDate.ifPresent(destination::setCreationDate);
    if (CollectionUtils.isNotEmpty(source.getEntry())) {
        // hierarchy temp object
        Map<Long, ReadableCategory> hierarchy = new HashMap<Long, ReadableCategory>();
        source.getEntry().forEach(entry -> {
            processCategory(entry.getCategory(), store, language, hierarchy, new HashMap<>());
        });
        destination.setCategory(new ArrayList<>(hierarchy.values()));
    }
    return destination;
}
Also used : ReadableMerchantStore(com.salesmanager.shop.model.store.ReadableMerchantStore) HashMap(java.util.HashMap) DateUtil(com.salesmanager.shop.utils.DateUtil) ReadableCatalog(com.salesmanager.shop.model.catalog.catalog.ReadableCatalog) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory)

Aggregations

ReadableCatalog (com.salesmanager.shop.model.catalog.catalog.ReadableCatalog)5 Catalog (com.salesmanager.core.model.catalog.catalog.Catalog)3 PersistableCatalog (com.salesmanager.shop.model.catalog.catalog.PersistableCatalog)3 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)3 ReadableCategory (com.salesmanager.shop.model.catalog.category.ReadableCategory)1 ReadableMerchantStore (com.salesmanager.shop.model.store.ReadableMerchantStore)1 OperationNotAllowedException (com.salesmanager.shop.store.api.exception.OperationNotAllowedException)1 DateUtil (com.salesmanager.shop.utils.DateUtil)1 HashMap (java.util.HashMap)1