Search in sources :

Example 66 with Language

use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.

the class CatalogFacadeImpl method listCatalogEntry.

@Override
public ReadableEntityList<ReadableCatalogCategoryEntry> listCatalogEntry(Optional<String> product, Long id, MerchantStore store, Language language, int page, int count) {
    Validate.notNull(store, "MerchantStore cannot be null");
    String productCode = product.orElse(null);
    Catalog catalog = catalogService.getById(id, store).orElseThrow(() -> new ResourceNotFoundException("Catalog with id [" + id + "] not found for store [" + store.getCode() + "]"));
    Page<CatalogCategoryEntry> entries = catalogEntryService.list(catalog, store, language, productCode, page, count);
    if (entries.isEmpty()) {
        return new ReadableEntityList<>();
    }
    List<ReadableCatalogCategoryEntry> readableList = entries.getContent().stream().map(cat -> readableCatalogEntryMapper.convert(cat, store, language)).collect(Collectors.toList());
    return createReadableList(entries, readableList);
}
Also used : PersistableCatalogCategoryEntry(com.salesmanager.shop.model.catalog.catalog.PersistableCatalogCategoryEntry) ReadableCatalogCategoryEntry(com.salesmanager.shop.model.catalog.catalog.ReadableCatalogCategoryEntry) CatalogCategoryEntry(com.salesmanager.core.model.catalog.catalog.CatalogCategoryEntry) ReadableEntityUtil.createReadableList(com.salesmanager.shop.util.ReadableEntityUtil.createReadableList) ReadableCatalogCategoryEntryMapper(com.salesmanager.shop.mapper.catalog.ReadableCatalogCategoryEntryMapper) CatalogService(com.salesmanager.core.business.services.catalog.catalog.CatalogService) ReadableCatalog(com.salesmanager.shop.model.catalog.catalog.ReadableCatalog) Autowired(org.springframework.beans.factory.annotation.Autowired) ReadableCatalogMapper(com.salesmanager.shop.mapper.catalog.ReadableCatalogMapper) ServiceException(com.salesmanager.core.business.exception.ServiceException) CatalogFacade(com.salesmanager.shop.store.controller.catalog.facade.CatalogFacade) Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) CatalogEntryService(com.salesmanager.core.business.services.catalog.catalog.CatalogEntryService) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Service(org.springframework.stereotype.Service) Catalog(com.salesmanager.core.model.catalog.catalog.Catalog) PersistableCatalog(com.salesmanager.shop.model.catalog.catalog.PersistableCatalog) PersistableCatalogCategoryEntry(com.salesmanager.shop.model.catalog.catalog.PersistableCatalogCategoryEntry) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) Mapper(com.salesmanager.shop.mapper.Mapper) Validate(org.jsoup.helper.Validate) ReadableCatalogCategoryEntry(com.salesmanager.shop.model.catalog.catalog.ReadableCatalogCategoryEntry) CatalogCategoryEntry(com.salesmanager.core.model.catalog.catalog.CatalogCategoryEntry) PersistableCatalogMapper(com.salesmanager.shop.mapper.catalog.PersistableCatalogMapper) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) Optional(java.util.Optional) ReadableEntityList(com.salesmanager.shop.model.entity.ReadableEntityList) ReadableEntityList(com.salesmanager.shop.model.entity.ReadableEntityList) ReadableCatalogCategoryEntry(com.salesmanager.shop.model.catalog.catalog.ReadableCatalogCategoryEntry) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableCatalog(com.salesmanager.shop.model.catalog.catalog.ReadableCatalog) Catalog(com.salesmanager.core.model.catalog.catalog.Catalog) PersistableCatalog(com.salesmanager.shop.model.catalog.catalog.PersistableCatalog)

Example 67 with Language

use of com.salesmanager.core.model.reference.language.Language 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 68 with Language

use of com.salesmanager.core.model.reference.language.Language 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)

Example 69 with Language

use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.

the class OrderRESTController method listOrders.

/**
 * Get a list of orders for a given customer
 * accept request parameter 'lang' [en,fr...] otherwise store dafault language
 * accept request parameter 'start' start index for count
 * accept request parameter 'max' maximum number count, otherwise returns all
 * @param store
 * @param order
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping(value = "/{store}/orders/customer/{id}", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.ACCEPTED)
@ResponseBody
public ReadableOrderList listOrders(@PathVariable final String store, @PathVariable final Long id, HttpServletRequest request, HttpServletResponse response) throws Exception {
    MerchantStore merchantStore = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
    if (merchantStore != null) {
        if (!merchantStore.getCode().equals(store)) {
            merchantStore = null;
        }
    }
    if (merchantStore == null) {
        merchantStore = merchantStoreService.getByCode(store);
    }
    if (merchantStore == null) {
        LOGGER.error("Merchant store is null for code " + store);
        response.sendError(503, "Merchant store is null for code " + store);
        return null;
    }
    // get additional request parameters for orders
    String lang = request.getParameter(Constants.LANG);
    String start = request.getParameter(Constants.START);
    String max = request.getParameter(Constants.MAX);
    int startCount = 0;
    int maxCount = 0;
    if (StringUtils.isBlank(lang)) {
        lang = merchantStore.getDefaultLanguage().getCode();
    }
    Language language = languageService.getByCode(lang);
    if (language == null) {
        LOGGER.error("Language is null for code " + lang);
        response.sendError(503, "Language is null for code " + lang);
        return null;
    }
    try {
        startCount = Integer.parseInt(start);
    } catch (Exception e) {
        LOGGER.info("Invalid value for start " + start);
    }
    try {
        maxCount = Integer.parseInt(max);
    } catch (Exception e) {
        LOGGER.info("Invalid value for max " + max);
    }
    Customer customer = customerService.getById(id);
    if (customer == null) {
        LOGGER.error("Customer is null for id " + id);
        response.sendError(503, "Customer is null for id " + id);
        return null;
    }
    if (customer.getMerchantStore().getId().intValue() != merchantStore.getId().intValue()) {
        LOGGER.error("Customer is null for id " + id + " and store id " + store);
        response.sendError(503, "Customer is null for id " + id + " and store id " + store);
        return null;
    }
    ReadableOrderList returnList = orderFacade.getReadableOrderList(merchantStore, startCount, maxCount, language);
    return returnList;
}
Also used : ReadableOrderList(com.salesmanager.shop.model.order.v0.ReadableOrderList) Language(com.salesmanager.core.model.reference.language.Language) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore)

Example 70 with Language

use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.

the class ProductItemsRESTController method getProductItemsByGroup.

/**
 * Query for a product group
 * public/products/{store code}/products/group/{id}?lang=fr|en
 * no lang it will take session lang or default store lang
 * @param store
 * @param language
 * @param groupCode
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping("/public/{store}/products/group/{code}")
@ResponseBody
public ReadableProductList getProductItemsByGroup(@PathVariable String store, @PathVariable final String code, HttpServletRequest request, HttpServletResponse response) throws Exception {
    try {
        MerchantStore merchantStore = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
        if (merchantStore != null) {
            if (!merchantStore.getCode().equals(store)) {
                // reset for the current request
                merchantStore = null;
            }
        }
        if (merchantStore == null) {
            merchantStore = merchantStoreService.getByCode(store);
        }
        if (merchantStore == null) {
            LOGGER.error("Merchant store is null for code " + store);
            // TODO localized message
            response.sendError(503, "Merchant store is null for code " + store);
            return null;
        }
        Language lang = languageUtils.getRequestLanguage(request, response);
        // get product group
        List<ProductRelationship> group = productRelationshipService.getByGroup(merchantStore, code, lang);
        if (group != null) {
            Date today = new Date();
            List<Long> ids = new ArrayList<Long>();
            for (ProductRelationship relationship : group) {
                Product product = relationship.getRelatedProduct();
                if (product.isAvailable() && DateUtil.dateBeforeEqualsDate(product.getDateAvailable(), today)) {
                    ids.add(product.getId());
                }
            }
            ReadableProductList list = productItemsFacade.listItemsByIds(merchantStore, lang, ids, 0, 0);
            return list;
        }
    } catch (Exception e) {
        LOGGER.error("Error while getting products", e);
        response.sendError(503, "An error occured while retrieving products " + e.getMessage());
    }
    return null;
}
Also used : ReadableProductList(com.salesmanager.shop.model.catalog.product.ReadableProductList) Language(com.salesmanager.core.model.reference.language.Language) ProductRelationship(com.salesmanager.core.model.catalog.product.relationship.ProductRelationship) ArrayList(java.util.ArrayList) Product(com.salesmanager.core.model.catalog.product.Product) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) Date(java.util.Date) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

Language (com.salesmanager.core.model.reference.language.Language)148 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)115 ArrayList (java.util.ArrayList)58 List (java.util.List)56 ServiceException (com.salesmanager.core.business.exception.ServiceException)55 Collectors (java.util.stream.Collectors)50 Product (com.salesmanager.core.model.catalog.product.Product)45 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)44 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)42 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)38 Autowired (org.springframework.beans.factory.annotation.Autowired)35 ConversionException (com.salesmanager.core.business.exception.ConversionException)30 Category (com.salesmanager.core.model.catalog.category.Category)30 Validate (org.apache.commons.lang3.Validate)29 Customer (com.salesmanager.core.model.customer.Customer)28 Optional (java.util.Optional)28 Inject (javax.inject.Inject)28 Service (org.springframework.stereotype.Service)28 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)27 ImageFilePath (com.salesmanager.shop.utils.ImageFilePath)25