Search in sources :

Example 1 with DateUtil

use of com.salesmanager.shop.utils.DateUtil 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)1 ReadableCategory (com.salesmanager.shop.model.catalog.category.ReadableCategory)1 ReadableMerchantStore (com.salesmanager.shop.model.store.ReadableMerchantStore)1 DateUtil (com.salesmanager.shop.utils.DateUtil)1 HashMap (java.util.HashMap)1