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