Search in sources :

Example 41 with BroadleafRequestContext

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);
}
Also used : BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) HibernateEntityManagerFactory(org.hibernate.ejb.HibernateEntityManagerFactory)

Example 42 with BroadleafRequestContext

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);
}
Also used : BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext)

Example 43 with BroadleafRequestContext

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());
    }
}
Also used : BroadleafCurrency(org.broadleafcommerce.common.currency.domain.BroadleafCurrency) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) Product(org.broadleafcommerce.core.catalog.domain.Product) Sku(org.broadleafcommerce.core.catalog.domain.Sku)

Example 44 with BroadleafRequestContext

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();
}
Also used : HashMap(java.util.HashMap) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) MultiValueMap(org.springframework.util.MultiValueMap) JsonResponse(org.broadleafcommerce.common.web.JsonResponse)

Example 45 with BroadleafRequestContext

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;
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) HashMap(java.util.HashMap) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) AdminSection(org.broadleafcommerce.openadmin.server.security.domain.AdminSection) MessageSource(org.springframework.context.MessageSource) EntityFormModifierDataPoint(org.broadleafcommerce.openadmin.server.security.service.EntityFormModifierDataPoint) FieldDTO(org.broadleafcommerce.openadmin.web.rulebuilder.dto.FieldDTO)

Aggregations

BroadleafRequestContext (org.broadleafcommerce.common.web.BroadleafRequestContext)78 Site (org.broadleafcommerce.common.site.domain.Site)16 HashMap (java.util.HashMap)12 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 ArrayList (java.util.ArrayList)9 Map (java.util.Map)9 Locale (org.broadleafcommerce.common.locale.domain.Locale)8 SandBox (org.broadleafcommerce.common.sandbox.domain.SandBox)5 StructuredContentDTO (org.broadleafcommerce.common.structure.dto.StructuredContentDTO)5 MessageSource (org.springframework.context.MessageSource)5 List (java.util.List)4 StructuredContent (org.broadleafcommerce.cms.structure.domain.StructuredContent)4 Field (java.lang.reflect.Field)3 HashSet (java.util.HashSet)3 Locale (java.util.Locale)3 Catalog (org.broadleafcommerce.common.site.domain.Catalog)3 BroadleafAttributeModifier (org.broadleafcommerce.presentation.model.BroadleafAttributeModifier)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 File (java.io.File)2 PrintWriter (java.io.PrintWriter)2