Search in sources :

Example 51 with ResourceNotFoundException

use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.

the class ShippingConfigurationApi method shippingModule.

/**
 * Get merchant shipping module details
 *
 * @param code
 * @param merchantStore
 * @param language
 * @return
 */
@GetMapping("/private/modules/shipping/{code}")
@ApiOperation(httpMethod = "GET", value = "Shipping module by code", produces = "application/json", response = List.class)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT") })
public IntegrationConfiguration shippingModule(@PathVariable String code, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) {
    try {
        // configured modules
        List<IntegrationModule> modules = shippingService.getShippingMethods(merchantStore);
        // check if exist
        Optional<IntegrationModule> checkIfExist = modules.stream().filter(m -> m.getCode().equals(code)).findAny();
        if (!checkIfExist.isPresent()) {
            throw new ResourceNotFoundException("Shipping module [" + code + "] not found");
        }
        IntegrationConfiguration config = shippingService.getShippingConfiguration(code, merchantStore);
        if (config == null) {
            config = new IntegrationConfiguration();
        }
        /**
         * Build return object for now this is a read copy
         */
        config.setActive(config.isActive());
        config.setDefaultSelected(config.isDefaultSelected());
        config.setIntegrationKeys(config.getIntegrationKeys());
        config.setIntegrationOptions(config.getIntegrationOptions());
        return config;
    } catch (ServiceException e) {
        LOGGER.error("Error getting shipping module [" + code + "]", e);
        throw new ServiceRuntimeException("Error getting shipping module [" + code + "]", e);
    }
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) IntegrationModuleConfiguration(com.salesmanager.shop.model.system.IntegrationModuleConfiguration) ShippingFacade(com.salesmanager.shop.store.controller.shipping.facade.ShippingFacade) Constants(com.salesmanager.shop.constants.Constants) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ServiceException(com.salesmanager.core.business.exception.ServiceException) RequestBody(org.springframework.web.bind.annotation.RequestBody) Language(com.salesmanager.core.model.reference.language.Language) ApiOperation(io.swagger.annotations.ApiOperation) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) AuthorizationUtils(com.salesmanager.shop.utils.AuthorizationUtils) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Map(java.util.Map) GetMapping(org.springframework.web.bind.annotation.GetMapping) IntegrationModule(com.salesmanager.core.model.system.IntegrationModule) Api(io.swagger.annotations.Api) Tag(io.swagger.annotations.Tag) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ShippingService(com.salesmanager.core.business.services.shipping.ShippingService) PostMapping(org.springframework.web.bind.annotation.PostMapping) Logger(org.slf4j.Logger) ApiImplicitParam(io.swagger.annotations.ApiImplicitParam) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) IntegrationModuleSummaryEntity(com.salesmanager.shop.model.system.IntegrationModuleSummaryEntity) ApiIgnore(springfox.documentation.annotations.ApiIgnore) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) Stream(java.util.stream.Stream) PackageDetails(com.salesmanager.core.model.shipping.PackageDetails) IntegrationConfiguration(com.salesmanager.core.model.system.IntegrationConfiguration) SwaggerDefinition(io.swagger.annotations.SwaggerDefinition) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) Optional(java.util.Optional) PersistableAddress(com.salesmanager.shop.model.references.PersistableAddress) ReadableAddress(com.salesmanager.shop.model.references.ReadableAddress) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ServiceException(com.salesmanager.core.business.exception.ServiceException) IntegrationConfiguration(com.salesmanager.core.model.system.IntegrationConfiguration) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) IntegrationModule(com.salesmanager.core.model.system.IntegrationModule) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) GetMapping(org.springframework.web.bind.annotation.GetMapping) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ApiOperation(io.swagger.annotations.ApiOperation)

Example 52 with ResourceNotFoundException

use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.

the class CatalogApi method addCatalogEntry.

@PostMapping(value = "/private/catalog/{id}")
@ResponseStatus(HttpStatus.OK)
@ApiOperation(httpMethod = "POST", value = "Add catalog entry to catalog", notes = "", response = ReadableCatalogCategoryEntry.class)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public ReadableCatalogCategoryEntry addCatalogEntry(@PathVariable Long id, @RequestBody @Valid PersistableCatalogCategoryEntry catalogEntry, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) {
    ReadableCatalog c = catalogFacade.getCatalog(id, merchantStore, language);
    if (c == null) {
        throw new ResourceNotFoundException("Catalog id [" + id + "] not found");
    }
    catalogEntry.setCatalog(c.getCode());
    return catalogFacade.addCatalogEntry(catalogEntry, merchantStore, language);
}
Also used : ReadableCatalog(com.salesmanager.shop.model.catalog.catalog.ReadableCatalog) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException)

Example 53 with ResourceNotFoundException

use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.

the class OrderFacadeImpl method updateOrderCustomre.

@Override
public void updateOrderCustomre(Long orderId, PersistableCustomer customer, MerchantStore store) {
    try {
        // get order by order id
        Order modelOrder = orderService.getOrder(orderId, store);
        if (modelOrder == null) {
            throw new ResourceNotFoundException("Order id [" + orderId + "] not found for store [" + store.getCode() + "]");
        }
        // set customer information
        modelOrder.setCustomerEmailAddress(customer.getEmailAddress());
        modelOrder.setBilling(this.convertBilling(customer.getBilling()));
        modelOrder.setDelivery(this.convertDelivery(customer.getDelivery()));
        orderService.saveOrUpdate(modelOrder);
    } catch (Exception e) {
        throw new ServiceRuntimeException("An error occured while updating order customer", e);
    }
}
Also used : ShopOrder(com.salesmanager.shop.model.order.ShopOrder) Order(com.salesmanager.core.model.order.Order) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ConversionException(com.salesmanager.core.business.exception.ConversionException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 54 with ResourceNotFoundException

use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.

the class OrderFacadeImpl method listTransactions.

@Override
public List<ReadableTransaction> listTransactions(Long orderId, MerchantStore store) {
    Validate.notNull(orderId, "orderId must not be null");
    Validate.notNull(store, "MerchantStore must not be null");
    List<ReadableTransaction> trx = new ArrayList<ReadableTransaction>();
    try {
        Order modelOrder = orderService.getOrder(orderId, store);
        if (modelOrder == null) {
            throw new ResourceNotFoundException("Order id [" + orderId + "] not found for store [" + store.getCode() + "]");
        }
        List<Transaction> transactions = transactionService.listTransactions(modelOrder);
        ReadableTransaction transaction = null;
        ReadableTransactionPopulator trxPopulator = null;
        for (Transaction tr : transactions) {
            transaction = new ReadableTransaction();
            trxPopulator = new ReadableTransactionPopulator();
            trxPopulator.setOrderService(orderService);
            trxPopulator.setPricingService(pricingService);
            trxPopulator.populate(tr, transaction, store, store.getDefaultLanguage());
            trx.add(transaction);
        }
        return trx;
    } catch (Exception e) {
        LOGGER.error("Error while getting transactions for order [" + orderId + "] and store code [" + store.getCode() + "]");
        throw new ServiceRuntimeException("Error while getting transactions for order [" + orderId + "] and store code [" + store.getCode() + "]");
    }
}
Also used : ShopOrder(com.salesmanager.shop.model.order.ShopOrder) Order(com.salesmanager.core.model.order.Order) ReadableTransaction(com.salesmanager.shop.model.order.transaction.ReadableTransaction) Transaction(com.salesmanager.core.model.payments.Transaction) ReadableTransactionPopulator(com.salesmanager.shop.populator.order.transaction.ReadableTransactionPopulator) ReadableTransaction(com.salesmanager.shop.model.order.transaction.ReadableTransaction) ArrayList(java.util.ArrayList) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ConversionException(com.salesmanager.core.business.exception.ConversionException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 55 with ResourceNotFoundException

use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.

the class OrderFacadeImpl method nextTransaction.

@Override
public TransactionType nextTransaction(Long orderId, MerchantStore store) {
    try {
        Order modelOrder = orderService.getOrder(orderId, store);
        if (modelOrder == null) {
            throw new ResourceNotFoundException("Order id [" + orderId + "] not found for store [" + store.getCode() + "]");
        }
        Transaction last = transactionService.lastTransaction(modelOrder, store);
        if (last.getTransactionType().name().equals(TransactionType.AUTHORIZE.name())) {
            return TransactionType.CAPTURE;
        } else if (last.getTransactionType().name().equals(TransactionType.AUTHORIZECAPTURE.name())) {
            return TransactionType.REFUND;
        } else if (last.getTransactionType().name().equals(TransactionType.CAPTURE.name())) {
            return TransactionType.REFUND;
        } else if (last.getTransactionType().name().equals(TransactionType.REFUND.name())) {
            return TransactionType.OK;
        } else {
            return TransactionType.OK;
        }
    } catch (Exception e) {
        throw new ServiceRuntimeException("Error while getting last transaction for order [" + orderId + "]", e);
    }
}
Also used : ShopOrder(com.salesmanager.shop.model.order.ShopOrder) Order(com.salesmanager.core.model.order.Order) ReadableTransaction(com.salesmanager.shop.model.order.transaction.ReadableTransaction) Transaction(com.salesmanager.core.model.payments.Transaction) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ConversionException(com.salesmanager.core.business.exception.ConversionException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Aggregations

ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)108 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)77 ServiceException (com.salesmanager.core.business.exception.ServiceException)62 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)22 UnauthorizedException (com.salesmanager.shop.store.api.exception.UnauthorizedException)22 Product (com.salesmanager.core.model.catalog.product.Product)21 Language (com.salesmanager.core.model.reference.language.Language)19 List (java.util.List)19 Collectors (java.util.stream.Collectors)19 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)17 ArrayList (java.util.ArrayList)17 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)16 OperationNotAllowedException (com.salesmanager.shop.store.api.exception.OperationNotAllowedException)15 Autowired (org.springframework.beans.factory.annotation.Autowired)15 ConversionException (com.salesmanager.core.business.exception.ConversionException)13 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)13 Inject (javax.inject.Inject)12 Optional (java.util.Optional)11 Service (org.springframework.stereotype.Service)11 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)11