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);
}
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);
}
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);
}
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);
}
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;
}
Aggregations