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();
}
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);
}
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);
}
}
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);
}
}
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);
}
}
Aggregations