Search in sources :

Example 1 with PersistableMerchantStore

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

the class StoreFacadeImpl method create.

@Override
public void create(PersistableMerchantStore store) {
    Validate.notNull(store, "PersistableMerchantStore must not be null");
    Validate.notNull(store.getCode(), "PersistableMerchantStore.code must not be null");
    // check if store code exists
    MerchantStore storeForCheck = get(store.getCode());
    if (storeForCheck != null) {
        throw new ServiceRuntimeException("MerhantStore " + store.getCode() + " already exists");
    }
    MerchantStore mStore = convertPersistableMerchantStoreToMerchantStore(store, languageService.defaultLanguage());
    createMerchantStore(mStore);
}
Also used : 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 PersistableMerchantStore

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

the class PersistableMerchantStorePopulator method populate.

@Override
public MerchantStore populate(PersistableMerchantStore source, MerchantStore target, MerchantStore store, Language language) throws ConversionException {
    Validate.notNull(source, "PersistableMerchantStore mst not be null");
    if (target == null) {
        target = new MerchantStore();
    }
    target.setCode(source.getCode());
    if (source.getId() != 0) {
        target.setId(source.getId());
    }
    if (store.getStoreLogo() != null) {
        target.setStoreLogo(store.getStoreLogo());
    }
    if (!StringUtils.isEmpty(source.getInBusinessSince())) {
        try {
            Date dt = DateUtil.getDate(source.getInBusinessSince());
            target.setInBusinessSince(dt);
        } catch (Exception e) {
            throw new ConversionException("Cannot parse date [" + source.getInBusinessSince() + "]", e);
        }
    }
    if (source.getDimension() != null) {
        target.setSeizeunitcode(source.getDimension().name());
    }
    if (source.getWeight() != null) {
        target.setWeightunitcode(source.getWeight().name());
    }
    target.setCurrencyFormatNational(source.isCurrencyFormatNational());
    target.setStorename(source.getName());
    target.setStorephone(source.getPhone());
    target.setStoreEmailAddress(source.getEmail());
    target.setUseCache(source.isUseCache());
    target.setRetailer(source.isRetailer());
    // get parent store
    if (!StringUtils.isBlank(source.getRetailerStore())) {
        if (source.getRetailerStore().equals(source.getCode())) {
            throw new ConversionException("Parent store [" + source.getRetailerStore() + "] cannot be parent of current store");
        }
        try {
            MerchantStore parent = merchantStoreService.getByCode(source.getRetailerStore());
            if (parent == null) {
                throw new ConversionException("Parent store [" + source.getRetailerStore() + "] does not exist");
            }
            target.setParent(parent);
        } catch (ServiceException e) {
            throw new ConversionException(e);
        }
    }
    try {
        if (!StringUtils.isEmpty(source.getDefaultLanguage())) {
            Language l = languageService.getByCode(source.getDefaultLanguage());
            target.setDefaultLanguage(l);
        }
        if (!StringUtils.isEmpty(source.getCurrency())) {
            Currency c = currencyService.getByCode(source.getCurrency());
            target.setCurrency(c);
        } else {
            target.setCurrency(currencyService.getByCode(Constants.DEFAULT_CURRENCY.getCurrencyCode()));
        }
        List<String> languages = source.getSupportedLanguages();
        if (!CollectionUtils.isEmpty(languages)) {
            for (String lang : languages) {
                Language ll = languageService.getByCode(lang);
                target.getLanguages().add(ll);
            }
        }
    } catch (Exception e) {
        throw new ConversionException(e);
    }
    // address population
    PersistableAddress address = source.getAddress();
    if (address != null) {
        Country country;
        try {
            country = countryService.getByCode(address.getCountry());
            Zone zone = zoneService.getByCode(address.getStateProvince());
            if (zone != null) {
                target.setZone(zone);
            } else {
                target.setStorestateprovince(address.getStateProvince());
            }
            target.setStoreaddress(address.getAddress());
            target.setStorecity(address.getCity());
            target.setCountry(country);
            target.setStorepostalcode(address.getPostalCode());
        } catch (ServiceException e) {
            throw new ConversionException(e);
        }
    }
    if (StringUtils.isNotEmpty(source.getTemplate()))
        target.setStoreTemplate(source.getTemplate());
    return target;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) ServiceException(com.salesmanager.core.business.exception.ServiceException) Language(com.salesmanager.core.model.reference.language.Language) Zone(com.salesmanager.core.model.reference.zone.Zone) Currency(com.salesmanager.core.model.reference.currency.Currency) PersistableAddress(com.salesmanager.shop.model.references.PersistableAddress) Country(com.salesmanager.core.model.reference.country.Country) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) PersistableMerchantStore(com.salesmanager.shop.model.store.PersistableMerchantStore) Date(java.util.Date) ServiceException(com.salesmanager.core.business.exception.ServiceException) ConversionException(com.salesmanager.core.business.exception.ConversionException)

Example 3 with PersistableMerchantStore

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

the class StoreFacadeImpl method update.

@Override
public void update(PersistableMerchantStore store) {
    Validate.notNull(store);
    MerchantStore mStore = mergePersistableMerchantStoreToMerchantStore(store, store.getCode(), languageService.defaultLanguage());
    updateMerchantStore(mStore);
}
Also used : MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ReadableMerchantStore(com.salesmanager.shop.model.store.ReadableMerchantStore) PersistableMerchantStore(com.salesmanager.shop.model.store.PersistableMerchantStore)

Example 4 with PersistableMerchantStore

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

the class StoreFacadeImpl method convertPersistableMerchantStoreToMerchantStore.

private MerchantStore convertPersistableMerchantStoreToMerchantStore(PersistableMerchantStore store, Language language) {
    MerchantStore mStore = new MerchantStore();
    // set default values
    mStore.setWeightunitcode(MeasureUnit.KG.name());
    mStore.setSeizeunitcode(MeasureUnit.IN.name());
    try {
        mStore = persistableMerchantStorePopulator.populate(store, mStore, language);
    } catch (ConversionException e) {
        throw new ConversionRuntimeException(e);
    }
    return mStore;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ReadableMerchantStore(com.salesmanager.shop.model.store.ReadableMerchantStore) PersistableMerchantStore(com.salesmanager.shop.model.store.PersistableMerchantStore) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException)

Example 5 with PersistableMerchantStore

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

the class StoreFacadeImpl method mergePersistableMerchantStoreToMerchantStore.

private MerchantStore mergePersistableMerchantStoreToMerchantStore(PersistableMerchantStore store, String code, Language language) {
    MerchantStore mStore = getMerchantStoreByCode(code);
    store.setId(mStore.getId());
    try {
        mStore = persistableMerchantStorePopulator.populate(store, mStore, language);
    } catch (ConversionException e) {
        throw new ConversionRuntimeException(e);
    }
    return mStore;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ReadableMerchantStore(com.salesmanager.shop.model.store.ReadableMerchantStore) PersistableMerchantStore(com.salesmanager.shop.model.store.PersistableMerchantStore) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException)

Aggregations

PersistableMerchantStore (com.salesmanager.shop.model.store.PersistableMerchantStore)6 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)5 ReadableMerchantStore (com.salesmanager.shop.model.store.ReadableMerchantStore)4 ConversionException (com.salesmanager.core.business.exception.ConversionException)3 PersistableAddress (com.salesmanager.shop.model.references.PersistableAddress)2 ConversionRuntimeException (com.salesmanager.shop.store.api.exception.ConversionRuntimeException)2 ServiceException (com.salesmanager.core.business.exception.ServiceException)1 Country (com.salesmanager.core.model.reference.country.Country)1 Currency (com.salesmanager.core.model.reference.currency.Currency)1 Language (com.salesmanager.core.model.reference.language.Language)1 Zone (com.salesmanager.core.model.reference.zone.Zone)1 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)1 Date (java.util.Date)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 HttpEntity (org.springframework.http.HttpEntity)1