Search in sources :

Example 1 with PersistableAddress

use of com.salesmanager.shop.model.references.PersistableAddress 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 2 with PersistableAddress

use of com.salesmanager.shop.model.references.PersistableAddress in project shopizer by shopizer-ecommerce.

the class MerchantStoreApiIntegrationTest method testCreateStore.

/**
 * Create a new store then delete it
 * @throws Exception
 */
@Test
public void testCreateStore() throws Exception {
    PersistableAddress address = new PersistableAddress();
    address.setAddress("121212 simple address");
    address.setPostalCode("12345");
    address.setCountry("US");
    address.setCity("FT LD");
    address.setStateProvince("FL");
    PersistableMerchantStore createdStore = new PersistableMerchantStore();
    createdStore.setCode(TEST_STORE_CODE);
    createdStore.setCurrency(CURRENCY);
    createdStore.setDefaultLanguage(DEFAULT_LANGUAGE);
    createdStore.setEmail("test@test.com");
    createdStore.setName(TEST_STORE_CODE);
    createdStore.setPhone("444-555-6666");
    createdStore.setSupportedLanguages(Arrays.asList(DEFAULT_LANGUAGE));
    createdStore.setAddress(address);
    final HttpEntity<PersistableMerchantStore> httpEntity = new HttpEntity<PersistableMerchantStore>(createdStore, getHeader());
    ResponseEntity<Void> response = testRestTemplate.exchange(String.format("/api/v1/private/store/"), HttpMethod.POST, httpEntity, Void.class);
    assertThat(response.getStatusCode(), is(HttpStatus.OK));
}
Also used : HttpEntity(org.springframework.http.HttpEntity) PersistableAddress(com.salesmanager.shop.model.references.PersistableAddress) PersistableMerchantStore(com.salesmanager.shop.model.store.PersistableMerchantStore) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

PersistableAddress (com.salesmanager.shop.model.references.PersistableAddress)2 PersistableMerchantStore (com.salesmanager.shop.model.store.PersistableMerchantStore)2 ConversionException (com.salesmanager.core.business.exception.ConversionException)1 ServiceException (com.salesmanager.core.business.exception.ServiceException)1 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)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 Date (java.util.Date)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 HttpEntity (org.springframework.http.HttpEntity)1