Example usage for com.liferay.portal.kernel.json JSONObject getString

List of usage examples for com.liferay.portal.kernel.json JSONObject getString

Introduction

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

Prototype

public String getString(String key);

Source Link

Usage

From source file:at.graz.meduni.bibbox.liferay.portlet.model.impl.ApplicationInstanceImpl.java

License:Open Source License

public String getApplicationname() {
    if (applicationname_ == null) {
        JSONObject application = getApplicationfile();
        String applicationname_ = application.getString("short_name");
        if (applicationname_.equals("")) {
            applicationname_ = this.getApplication();
        }/*from  w w  w.  ja v  a 2 s .c  om*/
    }
    return applicationname_;
}

From source file:at.graz.meduni.bibbox.liferay.portlet.service.impl.ApplicationInstanceServiceImpl.java

License:Open Source License

private String addMessageActivity(String name, String type, String state, String result) {
    JSONObject activity = JSONFactoryUtil.createJSONObject();
    Date curDate = new Date();
    activity.put("name", name);
    activity.put("type", type);
    activity.put("state", state);
    activity.put("result", result);
    activity.put("start_time", format_date.format(curDate) + "T" + format_time.format(curDate) + "Z");
    if (state.equals("FINISHED")) {
        activity.put("finished_time", format_date.format(curDate) + "T" + format_time.format(curDate) + "Z");
    }/*w  w w. j  av a  2 s.c o  m*/
    JSONObject activityresult = ActivitiesProtocol.createActivity(activity.toJSONString());
    return activityresult.getString("activitId");
}

From source file:bean.CustomNotificationHandler.java

@Override
protected String getBody(UserNotificationEvent userNotificationEvent, ServiceContext serviceContext)
        throws Exception {
    JSONObject jsonObject = JSONFactoryUtil.createJSONObject(userNotificationEvent.getPayload());
    fullName = jsonObject.getString("fullName");
    bodyText = jsonObject.getString("message");
    body = StringUtil.replace(getBodyTemplate(), new String[] { "[$FULL_NAME$]", "[$BODY_TEXT$]" },
            new String[] { fullName, bodyText });
    return body;//from  w w w  .ja v  a 2 s .c om
}

From source file:ch.inofix.data.model.impl.MeasurementImpl.java

License:Open Source License

public Map<String, String> getDataMap() {

    JSONObject jsonObject = null;
    Map<String, String> map = new HashMap<String, String>();

    try {//from w ww .  ja v  a2  s  .c  o m
        jsonObject = JSONFactoryUtil.createJSONObject(GetterUtil.getString(getData()));

        Iterator<String> keys = jsonObject.keys();

        while (keys.hasNext()) {

            String key = keys.next();

            map.put(key, jsonObject.getString(key));

        }

    } catch (JSONException e) {
        _log.error(e);
    }

    return map;

}

From source file:com.acs.DDMXSD.java

License:Open Source License

public JSONArray getJSONArray(Element element) throws JSONException {
    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    Document document = element.getDocument();

    String defaultLocale = LocalizationUtil.getDefaultLocale(document.asXML());

    List<Element> dynamicElementElements = element.elements("dynamic-element");

    for (Element dynamicElementElement : dynamicElementElements) {
        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
        JSONObject localizationMapJSONObject = JSONFactoryUtil.createJSONObject();

        List<Element> metadataElements = dynamicElementElement.elements("meta-data");

        for (Element metadataElement : metadataElements) {
            if (metadataElement == null) {
                continue;
            }/*  w w w .  ja  va  2s  . c  o  m*/

            String locale = metadataElement.attributeValue("locale");

            JSONObject localeMap = JSONFactoryUtil.createJSONObject();

            localizationMapJSONObject.put(locale, localeMap);

            for (Element metadataEntryElement : metadataElement.elements()) {

                String attributeName = metadataEntryElement.attributeValue("name");
                String attributeValue = metadataEntryElement.getText();

                localeMap.put(attributeName, attributeValue);

                if (defaultLocale.equals(locale)) {
                    jsonObject.put(attributeName, attributeValue);
                }
            }
        }

        jsonObject.put("localizationMap", localizationMapJSONObject);

        for (Attribute attribute : dynamicElementElement.attributes()) {
            jsonObject.put(attribute.getName(), attribute.getValue());
        }

        jsonObject.put("id", dynamicElementElement.attributeValue("name"));

        JSONArray hiddenAttributesJSONArray = JSONFactoryUtil.createJSONArray();

        String type = jsonObject.getString("type");

        if (type.equals(_TYPE_CHECKBOX)) {
            hiddenAttributesJSONArray.put("required");
        }

        if (type.equals(_TYPE_DDM_FILEUPLOAD)) {
            hiddenAttributesJSONArray.put("predefinedValue");
        }

        hiddenAttributesJSONArray.put("readOnly");

        jsonObject.put("hiddenAttributes", hiddenAttributesJSONArray);

        String key = "fields";

        if (type.equals(_TYPE_RADIO) || type.equals(_TYPE_SELECT)) {
            key = "options";

            String predefinedValue = jsonObject.getString("predefinedValue");

            jsonObject.put("predefinedValue", JSONFactoryUtil.createJSONArray(predefinedValue));
        }

        jsonObject.put(key, getJSONArray(dynamicElementElement));

        jsonArray.put(jsonObject);
    }

    return jsonArray;
}

From source file:com.beorn.paymentapi.model.ApiPaymentMethod.java

License:Open Source License

public static ApiPaymentMethod fromJSON(JSONObject jsonObject) {
    return new ApiPaymentMethod(jsonObject.getLong("paymentMethodId"), jsonObject.getString("key"),
            jsonObject.getString("name"));
}

From source file:com.beorn.paymentapi.model.ApiTransaction.java

License:Open Source License

public static ApiTransaction fromJSON(JSONObject jsonObject) {
    return new ApiTransaction(jsonObject.getLong("transactionId"), jsonObject.getLong("sellerId"),
            jsonObject.getDouble("amount"), jsonObject.getString("currencyCode"), jsonObject.getLong("status"));
}

From source file:com.beorn.paypalpaymentplugin.method.PaypalMethodHandlerTest.java

License:Open Source License

@Test
public void testGetPaymentUrl() throws Exception {

    // Data//from ww  w  .j  a v  a 2 s.  c  om

    String domain = "http://testdomain";
    String token = "t1";
    Map<String, String> serviceConfigMap = new HashMap<String, String>();
    serviceConfigMap.put("acct1.UserName", "testUserName");
    serviceConfigMap.put("acct1.Password", "testPassword");
    serviceConfigMap.put("acct1.Signature", "testSignature");
    serviceConfigMap.put("acct1.AppId", "testAppId");
    serviceConfigMap.put("mode", "sandbox");

    long transactionId = 123;
    long sellerId = 456;
    double amount = 789;
    String currencyCode = "EUR";
    long status = 1;
    ApiTransaction transaction = new ApiTransaction(transactionId, sellerId, amount, currencyCode, status);
    String languageId = "B";
    String backUrl = "C";
    String successUrl = "D";
    String errorUrl = "E";

    // Mocks

    mockStatic(PaymentPluginUtil.class);
    mockStatic(PayPalConfigUtil.class);
    mockStatic(TokenLocalServiceUtil.class);

    ServletContext servletContext = mock(ServletContext.class);
    JSONObject miscSellerConfig = mock(JSONObject.class);
    JSONObject sellerConfig = mock(JSONObject.class);
    JSONObject serviceSandboxConfig = mock(JSONObject.class);
    JSONObject pluginConfig = mock(JSONObject.class);
    JSONObject config = mock(JSONObject.class);
    PaymentPluginSender paymentPluginSender = mock(PaymentPluginSender.class);
    SetExpressCheckoutResponseType setExpressCheckoutResponseType = mock(SetExpressCheckoutResponseType.class);
    PayPalAPIInterfaceServiceService payPalAPIInterfaceServiceService = mock(
            PayPalAPIInterfaceServiceService.class);

    when(PaymentPluginUtil.getPaymentPluginSender()).thenReturn(paymentPluginSender);
    when(paymentPluginSender.getPaymentPluginConfig(sellerId)).thenReturn(config);
    when(PayPalConfigUtil.toPaypalServiceConfig(config)).thenReturn(serviceConfigMap);
    whenNew(PayPalAPIInterfaceServiceService.class).withArguments(serviceConfigMap)
            .thenReturn(payPalAPIInterfaceServiceService);
    when(payPalAPIInterfaceServiceService.setExpressCheckout(Mockito.any(SetExpressCheckoutReq.class)))
            .thenReturn(setExpressCheckoutResponseType);
    when(setExpressCheckoutResponseType.getAck()).thenReturn(AckCodeType.SUCCESS);
    when(setExpressCheckoutResponseType.getToken()).thenReturn(token);
    when(config.getJSONObject("sellerConfig")).thenReturn(sellerConfig);
    when(config.getJSONObject("pluginConfig")).thenReturn(pluginConfig);
    when(sellerConfig.getJSONObject("misc")).thenReturn(miscSellerConfig);
    when(miscSellerConfig.getBoolean("useSandbox")).thenReturn(true);
    when(pluginConfig.getJSONObject("serviceSandbox")).thenReturn(serviceSandboxConfig);
    when(serviceSandboxConfig.getString("paymentDomain")).thenReturn(domain);

    // Test

    PaypalMethodHandler methodHandler = new PaypalMethodHandler();
    methodHandler.initialize(servletContext);

    String paymentUrl = methodHandler.getPaymentUrl(transaction, languageId, backUrl, successUrl, errorUrl);

    verifyStatic();
    TokenLocalServiceUtil.addToken(token, transactionId, TokenStatus.AWAITING_PAYMENT);

    Assert.assertEquals(domain + "/cgi-bin/webscr?cmd=_express-checkout&useraction=commit&token=" + token,
            paymentUrl);
}

From source file:com.beorn.paypalpaymentplugin.util.PayPalConfigUtil.java

License:Open Source License

private static void putProperty(Map<String, String> configurationMap, JSONObject config, String name)
        throws InvalidConfigException {

    if (!config.has(name))
        throw new InvalidConfigException("Missing parameter \"" + name + "\"");

    String value = config.getString(name);

    if (Validator.isNotNull(value))
        configurationMap.put(name, value);
}

From source file:com.custom.portal.verify.CustomVerifyDynamicDataMapping.java

License:Open Source License

protected void updateFileUploadReferences(long companyId, long storageId, long userId, long groupId,
        BaseModel<?> baseModel, int status) throws Exception {

    Map<String, String> fieldValues = new HashMap<String, String>();

    Fields fields = StorageEngineUtil.getFields(storageId);

    for (Field field : fields) {
        String dataType = field.getDataType();

        if (!dataType.equals("file-upload") || Validator.isNull(field.getValue())) {

            continue;
        }/*  w w w.  j  av a2s.co m*/

        long primaryKey = GetterUtil.getLong(baseModel.getPrimaryKeyObj());

        Folder folder = addFolder(userId, groupId, primaryKey, field.getName());

        String valueString = String.valueOf(field.getValue());

        JSONObject jsonObject = JSONFactoryUtil.createJSONObject(valueString);

        String filePath = getFileUploadPath(baseModel) + StringPool.SLASH + field.getName();

        FileEntry fileEntry = addFileEntry(companyId, userId, groupId, folder.getFolderId(),
                jsonObject.getString("name"), filePath, status);

        if (fileEntry != null) {
            fieldValues.put(field.getName(), getJSON(fileEntry));
        }
    }

    updateFieldValues(storageId, fieldValues);
}