Search in sources :

Example 11 with UnauthorizedException

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

the class MerchantStoreApi method list.

/**
 * List of store names
 * @param merchantStore
 * @param request
 * @return
 */
@ResponseStatus(HttpStatus.OK)
@GetMapping(value = { "/private/stores/names" }, produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(httpMethod = "GET", value = "Get list of store names. Returns all retailers and stores", notes = "", response = ReadableMerchantStore.class)
public List<ReadableMerchantStore> list(@ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, @RequestParam(value = "page", required = false, defaultValue = "0") Integer page, @RequestParam(value = "count", required = false, defaultValue = "10") Integer count, HttpServletRequest request) {
    String authenticatedUser = userFacade.authenticatedUser();
    if (authenticatedUser == null) {
        throw new UnauthorizedException();
    }
    // requires superadmin, admin and admin retail to see all
    userFacade.authorizedGroup(authenticatedUser, Stream.of(Constants.GROUP_SUPERADMIN, Constants.GROUP_ADMIN, Constants.GROUP_ADMIN_RETAIL).collect(Collectors.toList()));
    MerchantStoreCriteria criteria = createMerchantStoreCriteria(request);
    if (userFacade.userInRoles(authenticatedUser, Arrays.asList(Constants.GROUP_SUPERADMIN))) {
        criteria.setStoreCode(null);
    } else {
        criteria.setStoreCode(merchantStore.getCode());
    }
    ReadableMerchantStoreList list = storeFacade.findAll(criteria, language, page, count);
    return list.getData();
}
Also used : ReadableMerchantStoreList(com.salesmanager.shop.model.store.ReadableMerchantStoreList) MerchantStoreCriteria(com.salesmanager.core.model.merchant.MerchantStoreCriteria) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(io.swagger.annotations.ApiOperation)

Example 12 with UnauthorizedException

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

the class SearchToolsApi method contact.

@PostMapping("/private/system/search/index")
@ApiOperation(httpMethod = "POST", value = "Indexes all products", notes = "", produces = "application/json")
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public ResponseEntity<Void> contact(@ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request) {
    // superadmin, admin and admin_catalogue
    String authenticatedUser = userFacade.authenticatedUser();
    if (authenticatedUser == null) {
        throw new UnauthorizedException();
    }
    Principal principal = request.getUserPrincipal();
    String userName = principal.getName();
    ReadableUser user = userFacade.findByUserName(userName, null, language);
    if (user == null) {
        throw new UnauthorizedException();
    }
    userFacade.authorizedGroup(authenticatedUser, Stream.of(Constants.GROUP_SUPERADMIN, Constants.GROUP_ADMIN, Constants.GROUP_ADMIN_CATALOGUE, Constants.GROUP_ADMIN_RETAIL).collect(Collectors.toList()));
    if (!user.getMerchant().equals(merchantStore.getCode())) {
        throw new UnauthorizedException();
    }
    try {
        searchFacade.indexAllData(merchantStore);
    } catch (Exception e) {
        throw new RestApiException("Exception while indexing store data", e);
    }
    return new ResponseEntity<Void>(HttpStatus.CREATED);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ReadableUser(com.salesmanager.shop.model.user.ReadableUser) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) RestApiException(com.salesmanager.shop.store.api.exception.RestApiException) Principal(java.security.Principal) RestApiException(com.salesmanager.shop.store.api.exception.RestApiException) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) PostMapping(org.springframework.web.bind.annotation.PostMapping) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ApiOperation(io.swagger.annotations.ApiOperation)

Example 13 with UnauthorizedException

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

the class TaxFacadeImpl method deleteTaxClass.

@Override
public void deleteTaxClass(Long id, MerchantStore store, Language language) {
    Validate.notNull(id, "TaxClass id cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
    try {
        TaxClass model = taxClassService.getById(id);
        if (model == null) {
            throw new ResourceNotFoundException("TaxClass not found [" + id + "] for store [" + store.getCode() + "]");
        } else {
            if (!model.getMerchantStore().getCode().equals(store.getCode())) {
                throw new UnauthorizedException("MerchantStore [" + store.getCode() + "] cannot delete tax class [" + id + "]");
            }
        }
        taxClassService.delete(model);
    } catch (ServiceException e) {
        LOGGER.error("Error while getting taxClasse [" + id + "] for store [" + store.getCode() + "]", e);
        throw new ServiceRuntimeException("Error while getting taxClasse [" + id + "] for store [" + store.getCode() + "]", e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) TaxClass(com.salesmanager.core.model.tax.taxclass.TaxClass) ReadableTaxClass(com.salesmanager.shop.model.tax.ReadableTaxClass) PersistableTaxClass(com.salesmanager.shop.model.tax.PersistableTaxClass) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 14 with UnauthorizedException

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

the class TaxFacadeImpl method taxClass.

@Override
public ReadableTaxClass taxClass(String code, MerchantStore store, Language language) {
    Validate.notNull(code, "TaxClass code cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
    try {
        TaxClass model = taxClassService.getByCode(code, store);
        if (model == null) {
            throw new ResourceNotFoundException("TaxClass not found [" + code + "] for store [" + store.getCode() + "]");
        }
        if (model != null) {
            if (!model.getMerchantStore().getCode().equals(store.getCode())) {
                throw new UnauthorizedException("MerchantStore [" + store.getCode() + "] cannot get tax class [" + code + "]");
            }
        }
        return readableTaxClassMapper.convert(model, store, language);
    } catch (ServiceException e) {
        LOGGER.error("Error while getting taxClass [" + code + "] for store [" + store.getCode() + "]", e);
        throw new ServiceRuntimeException("Error while getting taxClass [" + code + "] for store [" + store.getCode() + "]", e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) TaxClass(com.salesmanager.core.model.tax.taxclass.TaxClass) ReadableTaxClass(com.salesmanager.shop.model.tax.ReadableTaxClass) PersistableTaxClass(com.salesmanager.shop.model.tax.PersistableTaxClass) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 15 with UnauthorizedException

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

the class TaxFacadeImpl method taxRateByCode.

// get by code
private TaxRate taxRateByCode(String code, MerchantStore store, Language language) {
    Validate.notNull(code, "TaxRate code cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
    try {
        TaxRate model = taxRateService.getByCode(code, store);
        if (model == null) {
            throw new ResourceNotFoundException("TaxRate not found [" + code + "] for store [" + store.getCode() + "]");
        }
        if (model != null) {
            if (!model.getMerchantStore().getCode().equals(store.getCode())) {
                throw new UnauthorizedException("MerchantStore [" + store.getCode() + "] cannot get tax rate [" + code + "]");
            }
        }
        return model;
    } catch (ServiceException e) {
        LOGGER.error("Error while getting taxRate [" + code + "] for store [" + store.getCode() + "]", e);
        throw new ServiceRuntimeException("Error while getting taxRate [" + code + "] for store [" + store.getCode() + "]", e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) TaxRate(com.salesmanager.core.model.tax.taxrate.TaxRate) ReadableTaxRate(com.salesmanager.shop.model.tax.ReadableTaxRate) PersistableTaxRate(com.salesmanager.shop.model.tax.PersistableTaxRate) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Aggregations

UnauthorizedException (com.salesmanager.shop.store.api.exception.UnauthorizedException)19 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)10 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)10 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)8 ServiceException (com.salesmanager.core.business.exception.ServiceException)7 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)7 ApiOperation (io.swagger.annotations.ApiOperation)6 GetMapping (org.springframework.web.bind.annotation.GetMapping)5 Category (com.salesmanager.core.model.catalog.category.Category)4 ReadableUser (com.salesmanager.shop.model.user.ReadableUser)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 Product (com.salesmanager.core.model.catalog.product.Product)3 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)3 TaxClass (com.salesmanager.core.model.tax.taxclass.TaxClass)3 PersistableTaxClass (com.salesmanager.shop.model.tax.PersistableTaxClass)3 ReadableTaxClass (com.salesmanager.shop.model.tax.ReadableTaxClass)3 IOException (java.io.IOException)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 MerchantStoreCriteria (com.salesmanager.core.model.merchant.MerchantStoreCriteria)2 LightPersistableProduct (com.salesmanager.shop.model.catalog.product.LightPersistableProduct)2