Search in sources :

Example 1 with ReadableMerchantStore

use of com.salesmanager.shop.model.store.ReadableMerchantStore in project shopizer by shopizer-ecommerce.

the class StoreFacadeImpl method getMerchantStoresByCriteria.

private ReadableMerchantStoreList getMerchantStoresByCriteria(MerchantStoreCriteria criteria, Language language) {
    try {
        GenericEntityList<MerchantStore> stores = Optional.ofNullable(merchantStoreService.getByCriteria(criteria)).orElseThrow(() -> new ResourceNotFoundException("Criteria did not match any store"));
        ReadableMerchantStoreList storeList = new ReadableMerchantStoreList();
        storeList.setData((List<ReadableMerchantStore>) stores.getList().stream().map(s -> convertMerchantStoreToReadableMerchantStore(language, s)).collect(Collectors.toList()));
        storeList.setTotalPages(stores.getTotalPages());
        storeList.setRecordsTotal(stores.getTotalCount());
        storeList.setNumber(stores.getList().size());
        return storeList;
    } catch (ServiceException e) {
        throw new ServiceRuntimeException(e);
    }
}
Also used : MerchantConfigEntity(com.salesmanager.shop.model.store.MerchantConfigEntity) ReadableMerchantStoreList(com.salesmanager.shop.model.store.ReadableMerchantStoreList) PersistableMerchantStorePopulator(com.salesmanager.shop.populator.store.PersistableMerchantStorePopulator) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ReadableBrand(com.salesmanager.shop.model.store.ReadableBrand) CollectionUtils(org.apache.commons.collections4.CollectionUtils) LanguageService(com.salesmanager.core.business.services.reference.language.LanguageService) ArrayList(java.util.ArrayList) ServiceException(com.salesmanager.core.business.exception.ServiceException) ZoneService(com.salesmanager.core.business.services.reference.zone.ZoneService) Inject(javax.inject.Inject) Language(com.salesmanager.core.model.reference.language.Language) PersistableBrand(com.salesmanager.shop.model.store.PersistableBrand) MerchantStoreCriteria(com.salesmanager.core.model.merchant.MerchantStoreCriteria) HttpServletRequest(javax.servlet.http.HttpServletRequest) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Service(org.springframework.stereotype.Service) Qualifier(org.springframework.beans.factory.annotation.Qualifier) GenericEntityList(com.salesmanager.core.model.common.GenericEntityList) ReadableMerchantStorePopulator(com.salesmanager.shop.populator.store.ReadableMerchantStorePopulator) MerchantStoreService(com.salesmanager.core.business.services.merchant.MerchantStoreService) MeasureUnit(com.salesmanager.core.constants.MeasureUnit) CountryService(com.salesmanager.core.business.services.reference.country.CountryService) Logger(org.slf4j.Logger) ReadableMerchantStore(com.salesmanager.shop.model.store.ReadableMerchantStore) ImageFilePath(com.salesmanager.shop.utils.ImageFilePath) Page(org.springframework.data.domain.Page) InputContentFile(com.salesmanager.core.model.content.InputContentFile) Collectors(java.util.stream.Collectors) MerchantConfigurationService(com.salesmanager.core.business.services.system.MerchantConfigurationService) ContentService(com.salesmanager.core.business.services.content.ContentService) List(java.util.List) ReadableImage(com.salesmanager.shop.model.content.ReadableImage) Validate(org.apache.commons.lang3.Validate) MerchantConfiguration(com.salesmanager.core.model.system.MerchantConfiguration) LanguageUtils(com.salesmanager.shop.utils.LanguageUtils) MerchantConfigurationType(com.salesmanager.core.model.system.MerchantConfigurationType) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) PersistableMerchantStore(com.salesmanager.shop.model.store.PersistableMerchantStore) Optional(java.util.Optional) ConversionException(com.salesmanager.core.business.exception.ConversionException) Collections(java.util.Collections) StringUtils(org.drools.core.util.StringUtils) ReadableMerchantStoreList(com.salesmanager.shop.model.store.ReadableMerchantStoreList) ReadableMerchantStore(com.salesmanager.shop.model.store.ReadableMerchantStore) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ReadableMerchantStore(com.salesmanager.shop.model.store.ReadableMerchantStore) PersistableMerchantStore(com.salesmanager.shop.model.store.PersistableMerchantStore) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 2 with ReadableMerchantStore

use of com.salesmanager.shop.model.store.ReadableMerchantStore in project shopizer by shopizer-ecommerce.

the class StoreFacadeImpl method getChildStores.

@Override
public ReadableMerchantStoreList getChildStores(Language language, String code, int page, int count) {
    try {
        // first check if store is retailer
        MerchantStore retailer = this.getByCode(code);
        if (retailer == null) {
            throw new ResourceNotFoundException("Merchant [" + code + "] not found");
        }
        if (retailer.isRetailer() == null || !retailer.isRetailer().booleanValue()) {
            throw new ResourceNotFoundException("Merchant [" + code + "] not a retailer");
        }
        Page<MerchantStore> children = merchantStoreService.listChildren(code, page, count);
        List<ReadableMerchantStore> readableStores = new ArrayList<ReadableMerchantStore>();
        ReadableMerchantStoreList readableList = new ReadableMerchantStoreList();
        if (!CollectionUtils.isEmpty(children.getContent())) {
            for (MerchantStore store : children) readableStores.add(convertMerchantStoreToReadableMerchantStore(language, store));
        }
        readableList.setData(readableStores);
        readableList.setRecordsFiltered(children.getSize());
        readableList.setTotalPages(children.getTotalPages());
        readableList.setRecordsTotal(children.getTotalElements());
        readableList.setNumber(children.getNumber());
        return readableList;
    /*			List<MerchantStore> children = merchantStoreService.listChildren(code);
			List<ReadableMerchantStore> readableStores = new ArrayList<ReadableMerchantStore>();
			if (!CollectionUtils.isEmpty(children)) {
				for (MerchantStore store : children)
					readableStores.add(convertMerchantStoreToReadableMerchantStore(language, store));
			}
			return readableStores;*/
    } catch (ServiceException e) {
        throw new ServiceRuntimeException(e);
    }
}
Also used : ReadableMerchantStore(com.salesmanager.shop.model.store.ReadableMerchantStore) ReadableMerchantStoreList(com.salesmanager.shop.model.store.ReadableMerchantStoreList) ServiceException(com.salesmanager.core.business.exception.ServiceException) ArrayList(java.util.ArrayList) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ReadableMerchantStore(com.salesmanager.shop.model.store.ReadableMerchantStore) PersistableMerchantStore(com.salesmanager.shop.model.store.PersistableMerchantStore) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 3 with ReadableMerchantStore

use of com.salesmanager.shop.model.store.ReadableMerchantStore in project shopizer by shopizer-ecommerce.

the class StoreFacadeImpl method getMerchantStoreNames.

@Override
public List<ReadableMerchantStore> getMerchantStoreNames(MerchantStoreCriteria criteria) {
    Validate.notNull(criteria, "MerchantStoreCriteria must not be null");
    try {
        List<ReadableMerchantStore> stores = null;
        Optional<String> code = Optional.ofNullable(criteria.getStoreCode());
        // TODO Pageable
        if (code.isPresent()) {
            stores = merchantStoreService.findAllStoreNames(code.get()).stream().map(s -> convertStoreName(s)).collect(Collectors.toList());
        } else {
            stores = merchantStoreService.findAllStoreNames().stream().map(s -> convertStoreName(s)).collect(Collectors.toList());
        }
        return stores;
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Exception while getting store name", e);
    }
}
Also used : ReadableMerchantStore(com.salesmanager.shop.model.store.ReadableMerchantStore) ServiceException(com.salesmanager.core.business.exception.ServiceException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 4 with ReadableMerchantStore

use of com.salesmanager.shop.model.store.ReadableMerchantStore in project shopizer by shopizer-ecommerce.

the class StoreFacadeImpl method convertStoreName.

private ReadableMerchantStore convertStoreName(MerchantStore store) {
    ReadableMerchantStore convert = new ReadableMerchantStore();
    convert.setId(store.getId());
    convert.setCode(store.getCode());
    convert.setName(store.getStorename());
    return convert;
}
Also used : ReadableMerchantStore(com.salesmanager.shop.model.store.ReadableMerchantStore)

Example 5 with ReadableMerchantStore

use of com.salesmanager.shop.model.store.ReadableMerchantStore in project shopizer by shopizer-ecommerce.

the class ReadableMerchantStorePopulator method populate.

@Override
public ReadableMerchantStore populate(MerchantStore source, ReadableMerchantStore target, MerchantStore store, Language language) throws ConversionException {
    Validate.notNull(countryService, "Must use setter for countryService");
    Validate.notNull(zoneService, "Must use setter for zoneService");
    if (target == null) {
        target = new ReadableMerchantStore();
    }
    target.setId(source.getId());
    target.setCode(source.getCode());
    if (source.getDefaultLanguage() != null) {
        target.setDefaultLanguage(source.getDefaultLanguage().getCode());
    }
    target.setCurrency(source.getCurrency().getCode());
    target.setPhone(source.getStorephone());
    ReadableAddress address = new ReadableAddress();
    address.setAddress(source.getStoreaddress());
    address.setCity(source.getStorecity());
    if (source.getCountry() != null) {
        try {
            address.setCountry(source.getCountry().getIsoCode());
            Country c = countryService.getCountriesMap(language).get(source.getCountry().getIsoCode());
            if (c != null) {
                address.setCountry(c.getIsoCode());
            }
        } catch (ServiceException e) {
            logger.error("Cannot get Country", e);
        }
    }
    if (source.getParent() != null) {
        ReadableMerchantStore parent = populate(source.getParent(), new ReadableMerchantStore(), source, language);
        target.setParent(parent);
    }
    if (target.getParent() == null) {
        target.setRetailer(true);
    } else {
        target.setRetailer(source.isRetailer() != null ? source.isRetailer().booleanValue() : false);
    }
    target.setDimension(MeasureUnit.valueOf(source.getSeizeunitcode()));
    target.setWeight(WeightUnit.valueOf(source.getWeightunitcode()));
    if (source.getZone() != null) {
        address.setStateProvince(source.getZone().getCode());
        try {
            Zone z = zoneService.getZones(language).get(source.getZone().getCode());
            address.setStateProvince(z.getCode());
        } catch (ServiceException e) {
            logger.error("Cannot get Zone", e);
        }
    }
    if (!StringUtils.isBlank(source.getStorestateprovince())) {
        address.setStateProvince(source.getStorestateprovince());
    }
    if (!StringUtils.isBlank(source.getStoreLogo())) {
        ReadableImage image = new ReadableImage();
        image.setName(source.getStoreLogo());
        if (filePath != null) {
            image.setPath(filePath.buildStoreLogoFilePath(source));
        }
        target.setLogo(image);
    }
    address.setPostalCode(source.getStorepostalcode());
    target.setAddress(address);
    target.setCurrencyFormatNational(source.isCurrencyFormatNational());
    target.setEmail(source.getStoreEmailAddress());
    target.setName(source.getStorename());
    target.setId(source.getId());
    target.setInBusinessSince(DateUtil.formatDate(source.getInBusinessSince()));
    target.setUseCache(source.isUseCache());
    if (!CollectionUtils.isEmpty(source.getLanguages())) {
        List<ReadableLanguage> supported = new ArrayList<ReadableLanguage>();
        for (Language lang : source.getLanguages()) {
            try {
                Language langObject = languageService.getLanguagesMap().get(lang.getCode());
                if (langObject != null) {
                    ReadableLanguage l = new ReadableLanguage();
                    l.setId(langObject.getId());
                    l.setCode(langObject.getCode());
                    supported.add(l);
                }
            } catch (ServiceException e) {
                logger.error("Cannot get Language [" + lang.getId() + "]");
            }
        }
        target.setSupportedLanguages(supported);
    }
    if (source.getAuditSection() != null) {
        ReadableAudit audit = new ReadableAudit();
        if (source.getAuditSection().getDateCreated() != null) {
            audit.setCreated(DateUtil.formatDate(source.getAuditSection().getDateCreated()));
        }
        if (source.getAuditSection().getDateModified() != null) {
            audit.setModified(DateUtil.formatDate(source.getAuditSection().getDateCreated()));
        }
        audit.setUser(source.getAuditSection().getModifiedBy());
        target.setReadableAudit(audit);
    }
    return target;
}
Also used : ReadableImage(com.salesmanager.shop.model.content.ReadableImage) ReadableMerchantStore(com.salesmanager.shop.model.store.ReadableMerchantStore) ServiceException(com.salesmanager.core.business.exception.ServiceException) ReadableLanguage(com.salesmanager.shop.model.references.ReadableLanguage) Language(com.salesmanager.core.model.reference.language.Language) Zone(com.salesmanager.core.model.reference.zone.Zone) ReadableAudit(com.salesmanager.shop.model.entity.ReadableAudit) ArrayList(java.util.ArrayList) ReadableAddress(com.salesmanager.shop.model.references.ReadableAddress) Country(com.salesmanager.core.model.reference.country.Country) ReadableLanguage(com.salesmanager.shop.model.references.ReadableLanguage)

Aggregations

ReadableMerchantStore (com.salesmanager.shop.model.store.ReadableMerchantStore)9 ServiceException (com.salesmanager.core.business.exception.ServiceException)5 ArrayList (java.util.ArrayList)5 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)4 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)3 PersistableMerchantStore (com.salesmanager.shop.model.store.PersistableMerchantStore)3 ReadableMerchantStoreList (com.salesmanager.shop.model.store.ReadableMerchantStoreList)3 Language (com.salesmanager.core.model.reference.language.Language)2 ReadableImage (com.salesmanager.shop.model.content.ReadableImage)2 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)2 ConversionException (com.salesmanager.core.business.exception.ConversionException)1 ContentService (com.salesmanager.core.business.services.content.ContentService)1 MerchantStoreService (com.salesmanager.core.business.services.merchant.MerchantStoreService)1 CountryService (com.salesmanager.core.business.services.reference.country.CountryService)1 LanguageService (com.salesmanager.core.business.services.reference.language.LanguageService)1 ZoneService (com.salesmanager.core.business.services.reference.zone.ZoneService)1 MerchantConfigurationService (com.salesmanager.core.business.services.system.MerchantConfigurationService)1 MeasureUnit (com.salesmanager.core.constants.MeasureUnit)1 GenericEntityList (com.salesmanager.core.model.common.GenericEntityList)1 InputContentFile (com.salesmanager.core.model.content.InputContentFile)1