Example usage for com.liferay.portal.kernel.util MapUtil getString

List of usage examples for com.liferay.portal.kernel.util MapUtil getString

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util MapUtil getString.

Prototype

public static String getString(Map<String, ?> map, String key) 

Source Link

Usage

From source file:com.liferay.asset.lar.test.AssetLinkExportImportTest.java

License:Open Source License

protected PortletDataContext getPortletDataContext() throws Exception {
    Map<String, String[]> parameterMap = ExportImportConfigurationParameterMapFactory.buildParameterMap();

    String userIdStrategyString = MapUtil.getString(parameterMap, PortletDataHandlerKeys.USER_ID_STRATEGY);

    UserIdStrategy userIdStrategy = ExportImportHelperUtil.getUserIdStrategy(TestPropsValues.getUserId(),
            userIdStrategyString);//ww  w  . j  a  va2s .  c o  m

    return PortletDataContextFactoryUtil.createImportPortletDataContext(group.getCompanyId(),
            importedGroup.getGroupId(), parameterMap, userIdStrategy,
            ZipReaderFactoryUtil.getZipReader(larFile));
}

From source file:com.liferay.calendar.internal.exportimport.data.handler.CalendarPortletDataHandler.java

License:Open Source License

@Override
protected PortletPreferences doImportData(PortletDataContext portletDataContext, String portletId,
        PortletPreferences portletPreferences, String data) throws Exception {

    Group scopeGroup = _groupLocalService.fetchGroup(portletDataContext.getScopeGroupId());

    String layoutsImportMode = MapUtil.getString(portletDataContext.getParameterMap(),
            PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE);

    if (layoutsImportMode.equals(PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_CREATED_FROM_PROTOTYPE)
            && (scopeGroup != null) && scopeGroup.isUser()) {

        return portletPreferences;
    }/*from   w  w w  .  j av a2s. co  m*/

    if (portletDataContext.getBooleanParameter(NAMESPACE, "calendars")) {
        Element calendarsElement = portletDataContext.getImportDataGroupElement(Calendar.class);

        List<Element> calendarElements = calendarsElement.elements();

        for (Element calendarElement : calendarElements) {
            StagedModelDataHandlerUtil.importStagedModel(portletDataContext, calendarElement);
        }

        Element calendarResourcesElement = portletDataContext.getImportDataGroupElement(CalendarResource.class);

        List<Element> calendarResourceElements = calendarResourcesElement.elements();

        for (Element calendarResourceElement : calendarResourceElements) {
            StagedModelDataHandlerUtil.importStagedModel(portletDataContext, calendarResourceElement);
        }
    }

    if (portletDataContext.getBooleanParameter(NAMESPACE, "calendar-bookings")) {

        Element calendarBookingsElement = portletDataContext.getImportDataGroupElement(CalendarBooking.class);

        List<Element> calendarBookingElements = calendarBookingsElement.elements();

        for (Element calendarBookingElement : calendarBookingElements) {
            StagedModelDataHandlerUtil.importStagedModel(portletDataContext, calendarBookingElement);
        }
    }

    if (portletDataContext.getBooleanParameter(NAMESPACE, "calendar-notification-templates")) {

        Element calendarNotificationTemplatesElement = portletDataContext
                .getImportDataGroupElement(CalendarNotificationTemplate.class);

        List<Element> calendarNotificationTemplateElements = calendarNotificationTemplatesElement.elements();

        for (Element calendarNotificationTemplateElement : calendarNotificationTemplateElements) {

            StagedModelDataHandlerUtil.importStagedModel(portletDataContext,
                    calendarNotificationTemplateElement);
        }
    }

    return portletPreferences;
}

From source file:com.liferay.dynamic.data.lists.form.web.internal.portlet.action.GetFunctionsMVCResourceCommand.java

License:Open Source License

@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC, policyOption = ReferencePolicyOption.GREEDY, unbind = "removeDDMExpressionFunction")
protected void addDDMExpressionFunction(DDMExpressionFunction ddmExpressionFunction,
        Map<String, Object> properties) {

    if (properties.containsKey("ddm.form.evaluator.function.available.on.calculation.rule")
            && properties.containsKey("ddm.form.evaluator.function.name")) {

        boolean available = MapUtil.getBoolean(properties,
                "ddm.form.evaluator.function.available.on.calculation.rule");

        if (!available) {
            return;
        }/* w w w .j  a va2  s .  c om*/

        String functionName = MapUtil.getString(properties, "ddm.form.evaluator.function.name");

        _ddmExpressionFunctions.putIfAbsent(functionName, ddmExpressionFunction);
    }
}

From source file:com.liferay.dynamic.data.lists.form.web.internal.portlet.action.GetFunctionsMVCResourceCommand.java

License:Open Source License

protected void removeDDMExpressionFunction(DDMExpressionFunction ddmExpressionFunction,
        Map<String, Object> properties) {

    if (properties.containsKey("ddm.form.evaluator.function.name")) {
        String functionName = MapUtil.getString(properties, "ddm.form.evaluator.function.name");

        _ddmExpressionFunctions.remove(functionName);
    }//from   w  ww  . j  a v a2 s. co m
}

From source file:com.liferay.dynamic.data.mapping.expression.internal.DDMExpressionFactoryImpl.java

License:Open Source License

@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC, policyOption = ReferencePolicyOption.GREEDY, unbind = "removeDDMExpressionFunction")
protected void addDDMExpressionFunction(DDMExpressionFunction ddmExpressionFunction,
        Map<String, Object> properties) {

    if (properties.containsKey("ddm.form.evaluator.function.name")) {
        String functionName = MapUtil.getString(properties, "ddm.form.evaluator.function.name");

        _ddmExpressionFunctionMap.putIfAbsent(functionName, ddmExpressionFunction);
    }/* w  ww.ja v a2s  .c  o m*/
}

From source file:com.liferay.dynamic.data.mapping.expression.internal.DDMExpressionFactoryImpl.java

License:Open Source License

protected void removeDDMExpressionFunction(DDMExpressionFunction ddmExpressionFunction,
        Map<String, Object> properties) {

    if (properties.containsKey("ddm.form.evaluator.function.name")) {
        String functionName = MapUtil.getString(properties, "ddm.form.evaluator.function.name");

        _ddmExpressionFunctionMap.remove(functionName);
    }// w  ww .j a  v a2  s  .  c o m
}

From source file:com.liferay.dynamic.data.mapping.form.builder.internal.context.DDMFormBuilderContextFactoryHelper.java

License:Open Source License

protected void populateDDMFormFieldSettingsContext(Map<String, Object> ddmFormTemplateContext,
        Map<String, DDMFormField> ddmFormFieldsMap) {

    DDMFormBuilderContextFieldVisitor ddmFormBuilderContextFieldVisitor = new DDMFormBuilderContextFieldVisitor(
            ddmFormTemplateContext, new Consumer<Map<String, Object>>() {

                @Override/* ww  w .  ja  v a  2  s  .  c  om*/
                public void accept(Map<String, Object> fieldContext) {
                    String fieldName = MapUtil.getString(fieldContext, "fieldName");

                    try {
                        fieldContext.put("settingsContext",
                                doCreateDDMFormFieldSettingContext(ddmFormFieldsMap.get(fieldName)));
                    } catch (PortalException pe) {
                        _log.error("Unable to create field settings context", pe);
                    }
                }

            });

    ddmFormBuilderContextFieldVisitor.visit();
}

From source file:com.liferay.dynamic.data.mapping.form.evaluator.DDMFormFieldEvaluationResult.java

License:Open Source License

public String getErrorMessage() {
    return MapUtil.getString(_properties, "errorMessage");
}

From source file:com.liferay.dynamic.data.mapping.form.field.type.internal.DDMFormFieldTypeServicesTrackerImpl.java

License:Open Source License

@Override
public List<DDMFormFieldType> getDDMFormFieldTypesByDataDomain(String dataDomain) {

    List<DDMFormFieldType> ddmFormFieldTypes = new ArrayList<>();

    List<ServiceWrapper<DDMFormFieldType>> ddmFormFieldTypeServiceWrappers = ListUtil
            .fromCollection(_ddmFormFieldTypeServiceTrackerMap.values());

    for (ServiceWrapper<DDMFormFieldType> ddmFormFieldTypeServiceWrapper : ddmFormFieldTypeServiceWrappers) {

        String fieldDataDomain = MapUtil.getString(ddmFormFieldTypeServiceWrapper.getProperties(),
                "ddm.form.field.type.data.domain");

        if (Objects.equals(fieldDataDomain, dataDomain)) {
            ddmFormFieldTypes.add(ddmFormFieldTypeServiceWrapper.getService());
        }//from w  w  w.ja  v  a2  s . c o  m
    }

    return Collections.unmodifiableList(ddmFormFieldTypes);
}

From source file:com.liferay.dynamic.data.mapping.form.renderer.internal.DDMFormFieldTemplateContextFactoryTest.java

License:Open Source License

@Test
public void testTextField() {

    // Dynamic data mapping form

    DDMForm ddmForm = DDMFormTestUtil.createDDMForm();

    boolean required = true;

    DDMFormField ddmFormField = DDMFormTestUtil.createTextDDMFormField("Field1", false, false, required);

    ddmFormField.setLabel(DDMFormValuesTestUtil.createLocalizedValue("Field 1", _LOCALE));
    ddmFormField.setReadOnly(false);/*from w w w .  java2  s .  c o m*/
    ddmFormField.setTip(DDMFormValuesTestUtil.createLocalizedValue("This is a tip.", _LOCALE));

    ddmFormField.setProperty("displayStyle", "singleline");

    ddmForm.addDDMFormField(ddmFormField);

    // Dynamic data mapping form field evaluation

    String instanceId = StringUtil.randomString();

    DDMFormFieldEvaluationResult ddmFormFieldEvaluationResult = new DDMFormFieldEvaluationResult("Field1",
            instanceId);

    ddmFormFieldEvaluationResult.setRequired(required);
    ddmFormFieldEvaluationResult.setValid(true);
    ddmFormFieldEvaluationResult.setVisible(true);

    DDMFormEvaluationResult ddmFormEvaluationResult = getDDMFormEvaluationResult(ddmFormFieldEvaluationResult);

    // Dynamic data mapping form values

    List<DDMFormFieldValue> ddmFormFieldValues = new ArrayList<>();

    DDMFormFieldValue ddmFormFieldValue = DDMFormValuesTestUtil.createUnlocalizedDDMFormFieldValue("Field1",
            "Value 1");

    ddmFormFieldValue.setInstanceId(instanceId);

    ddmFormFieldValues.add(ddmFormFieldValue);

    DDMFormFieldTemplateContextFactory ddmFormFieldTemplateContextFactory = createDDMFormFieldTemplateContextFactory(
            ddmForm, ddmFormEvaluationResult, ddmFormFieldValues, false, getTextDDMFormFieldRenderer(),
            getTextDDMFormFieldTemplateContextContributor());

    List<Object> fields = ddmFormFieldTemplateContextFactory.create();

    Assert.assertEquals(fields.toString(), 1, fields.size());

    Map<String, Object> fieldTemplateContext = (Map<String, Object>) fields.get(0);

    Assert.assertEquals("singleline", MapUtil.getString(fieldTemplateContext, "displayStyle"));
    Assert.assertEquals("Field 1", MapUtil.getString(fieldTemplateContext, "label"));
    Assert.assertEquals(false, MapUtil.getBoolean(fieldTemplateContext, "readOnly"));
    Assert.assertEquals(false, MapUtil.getBoolean(fieldTemplateContext, "repeatable"));
    Assert.assertEquals(true, MapUtil.getBoolean(fieldTemplateContext, "required"));
    Assert.assertEquals("This is a tip.", MapUtil.getString(fieldTemplateContext, "tip"));
    Assert.assertEquals(true, MapUtil.getBoolean(fieldTemplateContext, "valid"));
    Assert.assertEquals(StringPool.BLANK, MapUtil.getString(fieldTemplateContext, "validationErrorMessage"));
    Assert.assertEquals("Value 1", MapUtil.getString(fieldTemplateContext, "value"));
    Assert.assertEquals(true, MapUtil.getBoolean(fieldTemplateContext, "visible"));

    String expectedName = String.format(_FIELD_NAME_FORMAT, "Field1", instanceId, 0, _LOCALE.toString());

    Assert.assertEquals(expectedName, MapUtil.getString(fieldTemplateContext, "name"));
}