use of org.broadleafcommerce.common.web.BroadleafRequestContext in project BroadleafCommerce by BroadleafCommerce.
the class StreamTransactionCapableUtilFailureSimulator method startTransaction.
@Override
protected TransactionStatus startTransaction(int propagationBehavior, int isolationLevel, boolean readOnly, PlatformTransactionManager transactionManager) {
BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
if (context.getAdditionalProperties().containsKey(FAILURE_MODE_KEY)) {
String failureModePU = (String) context.getAdditionalProperties().get(FAILURE_MODE_PU);
String checkClassName = failureModePU.equals("blPU") ? blPUCheckClassName : blEventPUCheckClassName;
if (((HibernateEntityManagerFactory) ((JpaTransactionManager) transactionManager).getEntityManagerFactory()).getSessionFactory().getAllClassMetadata().containsKey(checkClassName)) {
throw (RuntimeException) context.getAdditionalProperties().get(FAILURE_MODE_EXCEPTION);
}
}
return super.startTransaction(propagationBehavior, isolationLevel, readOnly, transactionManager);
}
use of org.broadleafcommerce.common.web.BroadleafRequestContext in project BroadleafCommerce by BroadleafCommerce.
the class StreamTransactionCapableUtilFailureSimulator method startFailureMode.
public void startFailureMode(RuntimeException exceptionToThrow, String persistenceUnit) {
checkPU(persistenceUnit);
BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
context.getAdditionalProperties().put(FAILURE_MODE_KEY, true);
context.getAdditionalProperties().put(FAILURE_MODE_PU, persistenceUnit);
context.getAdditionalProperties().put(FAILURE_MODE_EXCEPTION, exceptionToThrow);
}
use of org.broadleafcommerce.common.web.BroadleafRequestContext in project BroadleafCommerce by BroadleafCommerce.
the class SkuPricingPersistenceProvider method getCurrency.
@Override
protected Currency getCurrency(ExtractValueRequest extractValueRequest, Property property) {
BroadleafCurrency bc = null;
if (extractValueRequest.getEntity() instanceof Product && isDefaultSkuProperty(extractValueRequest, property)) {
Product p = (Product) extractValueRequest.getEntity();
bc = p.getDefaultSku().getCurrency();
} else if (extractValueRequest.getEntity() instanceof Sku) {
Sku s = (Sku) extractValueRequest.getEntity();
bc = s.getCurrency();
}
if (bc == null) {
BroadleafRequestContext brc = BroadleafRequestContext.getBroadleafRequestContext();
return brc.getJavaCurrency();
} else {
return Currency.getInstance(bc.getCurrencyCode());
}
}
use of org.broadleafcommerce.common.web.BroadleafRequestContext in project BroadleafCommerce by BroadleafCommerce.
the class AdminOfferController method getErrorDuplicatingResponse.
protected String getErrorDuplicatingResponse(HttpServletResponse response, String code) {
List<Map<String, Object>> errors = new ArrayList<>();
String message;
BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
if (context != null && context.getMessageSource() != null) {
message = context.getMessageSource().getMessage(code, null, code, context.getJavaLocale());
} else {
LOG.warn("Could not find the MessageSource on the current request, not translating the message key");
message = "Duplication_Failure";
}
Map<String, Object> errorMap = new HashMap<>();
errorMap.put("errorType", "global");
errorMap.put("code", code);
errorMap.put("message", message);
errors.add(errorMap);
return new JsonResponse(response).with("errors", errors).done();
}
use of org.broadleafcommerce.common.web.BroadleafRequestContext in project BroadleafCommerce by BroadleafCommerce.
the class FormBuilderServiceImpl method constructFieldDTOFromFieldData.
protected FieldDTO constructFieldDTOFromFieldData(Field field, BasicFieldMetadata fmd) {
FieldDTO fieldDTO = new FieldDTO();
// translate the label to display
String label = field.getFriendlyName();
BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
MessageSource messages = context.getMessageSource();
if (messages != null) {
label = messages.getMessage(label, null, label, context.getJavaLocale());
}
fieldDTO.setLabel(label);
fieldDTO.setId(field.getName());
if (field.getFieldType().equals("STRING")) {
fieldDTO.setOperators("blcFilterOperators_Text");
} else if (field.getFieldType().equals("DATE")) {
fieldDTO.setOperators("blcFilterOperators_Date");
} else if (field.getFieldType().equals("NUMBER") || field.getFieldType().equals("MONEY") || field.getFieldType().equals("DECIMAL")) {
fieldDTO.setOperators("blcFilterOperators_Numeric");
} else if (field.getFieldType().equals("BOOLEAN")) {
fieldDTO.setOperators("blcFilterOperators_Boolean");
} else if (field.getFieldType().equals("BROADLEAF_ENUMERATION")) {
fieldDTO.setOperators("blcFilterOperators_Enumeration");
fieldDTO.setInput("select");
fieldDTO.setType("string");
String[][] enumerationValues = fmd.getEnumerationValues();
Map<String, String> enumMap = new HashMap<>();
for (int i = 0; i < enumerationValues.length; i++) {
enumMap.put(enumerationValues[i][0], enumerationValues[i][1]);
}
fieldDTO.setValues(new JSONObject(enumMap).toString());
} else if (field.getFieldType().equals("ADDITIONAL_FOREIGN_KEY")) {
fieldDTO.setOperators("blcFilterOperators_Selectize");
fieldDTO.setType("string");
AdminSection section = adminNavigationService.findAdminSectionByClassAndSectionId(fmd.getForeignKeyClass(), null);
if (section != null) {
String sectionKey = section.getUrl().substring(1);
fieldDTO.setSelectizeSectionKey(sectionKey);
} else {
fieldDTO.setSelectizeSectionKey(fmd.getForeignKeyClass());
}
} else {
fieldDTO.setOperators("blcFilterOperators_Text");
}
return fieldDTO;
}
Aggregations