use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.
the class TaxFacadeImpl method taxRates.
@Override
public ReadableEntityList<ReadableTaxRate> taxRates(MerchantStore store, Language language) {
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
try {
List<TaxRate> rates = taxRateService.listByStore(store, language);
List<ReadableTaxRate> readableRates = rates.stream().map(r -> readableTaxRateMapper.convert(r, store, language)).collect(Collectors.toList());
ReadableEntityList<ReadableTaxRate> returnRates = new ReadableEntityList<ReadableTaxRate>();
returnRates.setItems(readableRates);
returnRates.setTotalPages(1);
returnRates.setNumber(readableRates.size());
returnRates.setRecordsTotal(readableRates.size());
return returnRates;
} catch (ServiceException e) {
LOGGER.error("Error while getting taxRates for store [" + store.getCode() + "]", e);
throw new ServiceRuntimeException("Error while getting taxRates for store [" + store.getCode() + "]", e);
}
}
use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.
the class UserFacadeImpl method authorizeStore.
@Override
public boolean authorizeStore(MerchantStore store, String path) {
Validate.notNull(store, "MerchantStore cannot be null");
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (!StringUtils.isBlank(path) && path.contains(PRIVATE_PATH)) {
Validate.notNull(authentication, "Don't call ths method if a user is not authenticated");
try {
String currentPrincipalName = authentication.getName();
LOGGER.info("Principal " + currentPrincipalName);
ReadableUser readableUser = findByUserName(currentPrincipalName, languageService.defaultLanguage());
// ReadableUser readableUser = findByUserName(currentPrincipalName, store.getCode(), store.getDefaultLanguage());
if (readableUser == null) {
return false;
}
// current user match;
String merchant = readableUser.getMerchant();
// user store is store request param
if (store.getCode().equalsIgnoreCase(merchant)) {
return true;
}
// is superadmin
for (ReadableGroup group : readableUser.getGroups()) {
if (Constants.GROUP_SUPERADMIN.equals(group.getName())) {
return true;
}
}
boolean authorized = false;
// user store can be parent and requested store is child
// get parent
// TODO CACHE
MerchantStore parent = null;
if (store.getParent() != null) {
parent = merchantStoreService.getParent(merchant);
}
// user can be in parent
if (parent != null && parent.getCode().equals(store.getCode())) {
authorized = true;
}
// else false
return authorized;
} catch (Exception e) {
throw new UnauthorizedException("Cannot authorize user " + authentication.getPrincipal().toString() + " for store " + store.getCode(), e.getMessage());
}
}
return true;
}
use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.
the class UserFacadeImpl method authorizedStore.
@Override
public boolean authorizedStore(String userName, String merchantStoreCode) {
try {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
Set<String> roles = authentication.getAuthorities().stream().map(r -> r.getAuthority()).collect(Collectors.toSet());
ReadableUser readableUser = findByUserName(userName, languageService.defaultLanguage());
// unless superadmin
for (ReadableGroup group : readableUser.getGroups()) {
if (Constants.GROUP_SUPERADMIN.equals(group.getName())) {
return true;
}
}
boolean authorized = false;
User user = userService.findByStore(readableUser.getId(), merchantStoreCode);
if (user != null) {
authorized = true;
} else {
user = userService.getByUserName(userName);
}
if (user != null && !authorized) {
// get parent
MerchantStore store = merchantStoreService.getParent(merchantStoreCode);
// user can be in parent
MerchantStore st = user.getMerchantStore();
if (store != null && st.getCode().equals(store.getCode())) {
authorized = true;
}
}
return authorized;
} catch (Exception e) {
throw new ServiceRuntimeException("Cannot authorize user " + userName + " for store " + merchantStoreCode, e.getMessage());
}
}
use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.
the class PaymentConfigurationFacadeImpl method configuration.
@Override
public ReadableConfiguration configuration(String module, MerchantStore store) {
try {
ReadableConfiguration config = null;
List<PaymentMethod> methods = paymentService.getAcceptedPaymentMethods(store);
Optional<ReadableConfiguration> configuration = methods.stream().filter(m -> module.equals(m.getModule().getCode())).map(m -> this.configuration(m.getInformations(), store)).findFirst();
if (configuration.isPresent()) {
config = configuration.get();
}
return config;
} catch (ServiceException e) {
throw new ServiceRuntimeException("Error while getting payment configuration [" + module + "]", e);
}
}
use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.
the class PaymentConfigurationFacadeImpl method configurations.
@Override
public List<ReadableConfiguration> configurations(MerchantStore store) {
try {
List<PaymentMethod> methods = paymentService.getAcceptedPaymentMethods(store);
List<ReadableConfiguration> configurations = methods.stream().map(m -> configuration(m.getInformations(), store)).collect(Collectors.toList());
return configurations;
} catch (ServiceException e) {
throw new ServiceRuntimeException("Error while getting payment configurations", e);
}
}
Aggregations