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

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

Introduction

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

Prototype

public Object remove(String key);

Source Link

Usage

From source file:com.liferay.content.targeting.rule.facebook.hook.CTFacebookConnectionAction.java

License:Open Source License

protected void updateAnonymousUserFacebookAccessToken(HttpServletRequest request, long userId, String token)
        throws PortalException, SystemException {

    if (_anonymousUsersManager == null) {
        _initAnonymousUserManager();//from  w w w  .ja  v a2  s .  c o  m
    }

    AnonymousUser anonymousUser = _anonymousUsersManager.getAnonymousUser(request, userId);

    if (_anonymousUserLocalService == null) {
        _initAnonymousUserLocalService();
    }

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject(anonymousUser.getTypeSettings());

    String accessToken = jsonObject.getString(WebKeys.FACEBOOK_ACCESS_TOKEN);

    if (Validator.isNull(accessToken)) {
        jsonObject.remove(WebKeys.FACEBOOK_ACCESS_TOKEN);
    }

    jsonObject.put(WebKeys.FACEBOOK_ACCESS_TOKEN, token);

    anonymousUser.setTypeSettings(jsonObject.toString());

    _anonymousUserLocalService.updateAnonymousUser(anonymousUser);
}

From source file:com.liferay.microblogs.hook.upgrade.v1_0_2.UpgradeSocial.java

License:Open Source License

protected void upgradeMicroblogActivities() throws Exception {
    Connection con = null;/*from w  ww.j  a va2 s. c  om*/
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
        con = DataAccess.getUpgradeOptimizedConnection();

        ps = con.prepareStatement(
                "select activityId, extraData from SocialActivity where " + "classNameId = ?");

        ps.setLong(1, PortalUtil.getClassNameId(MicroblogsEntry.class));

        rs = ps.executeQuery();

        while (rs.next()) {
            long activityId = rs.getLong("activityId");
            String extraData = rs.getString("extraData");

            JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject(extraData);

            long parentMicroblogsEntryId = extraDataJSONObject.getLong("receiverMicroblogsEntryId");

            extraDataJSONObject.put("parentMicroblogsEntryId", parentMicroblogsEntryId);

            extraDataJSONObject.remove("receiverMicroblogsEntryId");

            updateSocialActivity(activityId, extraDataJSONObject);
        }
    } finally {
        DataAccess.cleanUp(con, ps, rs);
    }
}

From source file:com.liferay.microblogs.internal.upgrade.v1_0_2.UpgradeSocial.java

License:Open Source License

protected void upgradeMicroblogActivities() throws Exception {
    try (LoggingTimer loggingTimer = new LoggingTimer();
            PreparedStatement ps = connection.prepareStatement(
                    "select activityId, extraData from SocialActivity where " + "classNameId = ?")) {

        ps.setLong(1, PortalUtil.getClassNameId(MicroblogsEntry.class));

        try (ResultSet rs = ps.executeQuery()) {
            while (rs.next()) {
                long activityId = rs.getLong("activityId");
                String extraData = rs.getString("extraData");

                JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject(extraData);

                long parentMicroblogsEntryId = extraDataJSONObject.getLong("receiverMicroblogsEntryId");

                extraDataJSONObject.put("parentMicroblogsEntryId", parentMicroblogsEntryId);

                extraDataJSONObject.remove("receiverMicroblogsEntryId");

                updateSocialActivity(activityId, extraDataJSONObject);
            }//  w w  w.  j a v  a 2 s.c om
        }
    }
}

From source file:com.liferay.notifications.hook.upgrade.v1_0_0.UpgradeUserNotificationEvent.java

License:Open Source License

protected void upgradeNotifications() throws Exception {
    Connection con = null;//  ww w  . jav  a 2 s  .c  o m
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
        con = DataAccess.getUpgradeOptimizedConnection();

        ps = con.prepareStatement(
                "select userNotificationEventId, payload from " + "UserNotificationEvent where type_ = ?");

        ps.setString(1, "6_WAR_soportlet");

        rs = ps.executeQuery();

        while (rs.next()) {
            long userNotificationEventId = rs.getLong("userNotificationEventId");
            String payload = rs.getString("payload");

            JSONObject payloadJSONObject = JSONFactoryUtil.createJSONObject(payload);

            String type = payloadJSONObject.getString("portletId");

            if (Validator.isNull(type)) {
                return;
            }

            if (type.equals(PortletKeys.ANNOUNCEMENTS)) {
                type = PortletKeys.SO_ANNOUNCEMENTS;
            }

            payloadJSONObject.remove("portletId");

            long entryId = payloadJSONObject.getLong("entryId");

            if (entryId > 0) {
                payloadJSONObject.put("classPK", entryId);

                payloadJSONObject.remove("entryId");
            } else if (type.equals(PortletKeys.CONTACTS_CENTER)) {
                long socialRequestId = payloadJSONObject.getLong("requestId");

                if (socialRequestId > 0) {
                    payloadJSONObject.put("classPK", socialRequestId);

                    payloadJSONObject.remove("socialRequestId");
                }
            } else if (type.equals(PortletKeys.SO_INVITE_MEMBERS)) {
                long memberRequestId = payloadJSONObject.getLong("memberRequestId");

                if (memberRequestId > 0) {
                    payloadJSONObject.put("classPK", memberRequestId);

                    payloadJSONObject.remove("memberRequestId");
                }
            }

            updateNotification(userNotificationEventId, type, payloadJSONObject);
        }
    } finally {
        DataAccess.cleanUp(con, ps, rs);
    }
}

From source file:com.liferay.notifications.web.internal.upgrade.v1_0_0.UpgradeUserNotificationEvent.java

License:Open Source License

protected void updateUserNotificationEvents() throws Exception {
    try (LoggingTimer loggingTimer = new LoggingTimer()) {
        List<UserNotificationEvent> userNotificationEvents = _userNotificationEventLocalService
                .getTypeNotificationEvents("6_WAR_soportlet");

        for (UserNotificationEvent userNotificationEvent : userNotificationEvents) {

            JSONObject payloadJSONObject = JSONFactoryUtil.createJSONObject(userNotificationEvent.getPayload());

            String type = payloadJSONObject.getString("portletId");

            if (Validator.isNull(type)) {
                return;
            }/*from  w  ww .j a va 2  s.co m*/

            payloadJSONObject.remove("portletId");

            long entryId = payloadJSONObject.getLong("entryId");

            if (entryId > 0) {
                payloadJSONObject.put("classPK", entryId);

                payloadJSONObject.remove("entryId");
            } else if (type.equals("1_WAR_contactsportlet")) {
                long socialRequestId = payloadJSONObject.getLong("requestId");

                if (socialRequestId > 0) {
                    payloadJSONObject.put("classPK", socialRequestId);

                    payloadJSONObject.remove("socialRequestId");
                }
            } else if (type.equals("2_WAR_soportlet")) {
                long memberRequestId = payloadJSONObject.getLong("memberRequestId");

                if (memberRequestId > 0) {
                    payloadJSONObject.put("classPK", memberRequestId);

                    payloadJSONObject.remove("memberRequestId");
                }
            }

            userNotificationEvent.setType(type);
            userNotificationEvent.setPayload(payloadJSONObject.toString());

            _userNotificationEventLocalService.updateUserNotificationEvent(userNotificationEvent);
        }
    }
}

From source file:com.liferay.notifications.web.internal.upgrade.v2_1_0.UpgradeUserNotificationEvent.java

License:Open Source License

protected void updateUserNotificationEvents() throws Exception {
    try (LoggingTimer loggingTimer = new LoggingTimer();
            PreparedStatement ps = connection.prepareStatement(
                    "select userNotificationEventId, payload from " + "UserNotificationEvent");
            ResultSet rs = ps.executeQuery()) {

        while (rs.next()) {
            long userNotificationEventId = rs.getLong("userNotificationEventId");
            String payload = rs.getString("payload");

            UserNotificationEvent userNotificationEvent = _userNotificationEventLocalService
                    .getUserNotificationEvent(userNotificationEventId);

            userNotificationEvent.setDelivered(true);

            int deliveryType = userNotificationEvent.getDeliveryType();

            if (deliveryType == 0) {
                userNotificationEvent.setDeliveryType(UserNotificationDeliveryConstants.TYPE_WEBSITE);
            }//  ww  w .j  a  v  a2s  .  com

            JSONObject jsonObject = JSONFactoryUtil.createJSONObject(payload);

            boolean actionRequired = jsonObject.getBoolean("actionRequired");

            jsonObject.remove("actionRequired");

            userNotificationEvent.setPayload(jsonObject.toString());

            if (!userNotificationEvent.isActionRequired()) {
                userNotificationEvent.setActionRequired(actionRequired);
            }

            _userNotificationEventLocalService.updateUserNotificationEvent(userNotificationEvent);
        }
    }
}

From source file:com.liferay.osb.scv.user.profile.util.UserProfileUtil.java

License:Open Source License

public static void updateDataSourceEntries(long mappingDataSourceId,
        Map<String, List<String>> searchTermFieldNameMap, JSONObject jsonObject) throws Exception {

    List<String> tableNames = new ArrayList<>();
    List<String> pkFields = new ArrayList<>();

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

    while (iterator.hasNext()) {
        String tableName = iterator.next();

        tableNames.add(tableName);//from w  ww  .  j ava 2s  . co m

        if (!StringUtil.equalsIgnoreCase(tableName, "user")) {
            pkFields.add(StringUtil.lowerCase(tableName) + "Ids");
        }
    }

    for (String tableName : tableNames) {
        List<String> searchTermFieldNames = searchTermFieldNameMap.get(tableName);

        JSONArray jsonArray = jsonObject.getJSONArray(tableName);

        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject entityJSONObject = jsonArray.getJSONObject(i);

            String id = entityJSONObject.getString(StringUtil.lowerCase(tableName) + "Id");

            List<String> searchTerms = new ArrayList<>();

            if (!ListUtil.isEmpty(searchTermFieldNames)) {
                for (String searchTermFieldName : searchTermFieldNames) {
                    searchTerms.add(entityJSONObject.getString(searchTermFieldName));
                }

                for (String pkField : pkFields) {
                    Object value = entityJSONObject.get(pkField);

                    if (value == null) {
                        continue;
                    }

                    entityJSONObject.put(UserProfileConstants.FIELD_ASSOCIATED + pkField, value);
                    entityJSONObject.remove(pkField);
                }
            }

            updateDataSourceEntry(mappingDataSourceId, tableName, id, searchTerms, entityJSONObject);
        }
    }
}

From source file:com.liferay.portlet.configuration.css.web.internal.portlet.PortletConfigurationCSSPortlet.java

License:Open Source License

public void updateLookAndFeel(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    Layout layout = themeDisplay.getLayout();

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    String portletId = ParamUtil.getString(actionRequest, "portletId");

    if (!PortletPermissionUtil.contains(permissionChecker, layout, portletId, ActionKeys.CONFIGURATION)) {

        return;//w w  w . j a  va  2  s  .co m
    }

    PortletPreferences portletSetup = PortletPreferencesFactoryUtil.getStrictLayoutPortletSetup(layout,
            portletId);

    String css = ParamUtil.getString(actionRequest, "css");

    if (_log.isDebugEnabled()) {
        _log.debug("Updating css " + css);
    }

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject(css);

    JSONObject portletDataJSONObject = jsonObject.getJSONObject("portletData");

    jsonObject.remove("portletData");

    css = jsonObject.toString();

    String linkToLayoutUuid = GetterUtil.getString(portletDataJSONObject.getString("portletLinksTarget"));
    String portletDecoratorId = portletDataJSONObject.getString("portletDecoratorId");
    JSONObject titlesJSONObject = portletDataJSONObject.getJSONObject("titles");
    boolean useCustomTitle = portletDataJSONObject.getBoolean("useCustomTitle");

    Set<Locale> locales = LanguageUtil.getAvailableLocales(themeDisplay.getSiteGroupId());

    for (Locale locale : locales) {
        String languageId = LocaleUtil.toLanguageId(locale);

        String title = null;

        if (titlesJSONObject.has(languageId)) {
            title = GetterUtil.getString(titlesJSONObject.getString(languageId));
        }

        String rootPortletId = PortletConstants.getRootPortletId(portletId);

        String defaultPortletTitle = _portal.getPortletTitle(rootPortletId, languageId);

        if ((title != null) && !Objects.equals(defaultPortletTitle, title)) {

            portletSetup.setValue("portletSetupTitle_" + languageId, title);
        } else {
            portletSetup.reset("portletSetupTitle_" + languageId);
        }
    }

    portletSetup.setValue("portletSetupUseCustomTitle", String.valueOf(useCustomTitle));

    if (Validator.isNotNull(linkToLayoutUuid)) {
        portletSetup.setValue("portletSetupLinkToLayoutUuid", linkToLayoutUuid);
    } else {
        portletSetup.reset("portletSetupLinkToLayoutUuid");
    }

    if (Validator.isNotNull(portletDecoratorId)) {
        portletSetup.setValue("portletSetupPortletDecoratorId", portletDecoratorId);
    } else {
        portletSetup.reset("portletSetupPortletDecoratorId");
    }

    portletSetup.setValue("portletSetupCss", css);

    portletSetup.store();
}

From source file:com.liferay.portlet.portletconfiguration.action.UpdateLookAndFeelAction.java

License:Open Source License

@Override
public String getJSON(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    HttpSession session = request.getSession();

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    Layout layout = themeDisplay.getLayout();

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    String portletId = ParamUtil.getString(request, "portletId");

    if (!PortletPermissionUtil.contains(permissionChecker, themeDisplay.getPlid(), portletId,
            ActionKeys.CONFIGURATION)) {

        return null;
    }/* ww w.j a v  a 2  s.  c o m*/

    PortletPreferences portletSetup = PortletPreferencesFactoryUtil.getLayoutPortletSetup(layout, portletId);

    String css = ParamUtil.getString(request, "css");

    if (_log.isDebugEnabled()) {
        _log.debug("Updating css " + css);
    }

    JSONObject jsonObj = JSONFactoryUtil.createJSONObject(css);

    JSONObject portletData = jsonObj.getJSONObject("portletData");

    jsonObj.remove("portletData");

    css = jsonObj.toString();

    boolean useCustomTitle = portletData.getBoolean("useCustomTitle");
    boolean showBorders = portletData.getBoolean("showBorders");
    String linkToLayoutUuid = GetterUtil.getString(portletData.getString("portletLinksTarget"));

    JSONObject titles = portletData.getJSONObject("titles");

    Locale[] locales = LanguageUtil.getAvailableLocales();

    for (int i = 0; i < locales.length; i++) {
        String languageId = LocaleUtil.toLanguageId(locales[i]);

        String title = null;

        if (titles.has(languageId)) {
            title = GetterUtil.getString(titles.getString(languageId));
        }

        if (Validator.isNotNull(title)) {
            portletSetup.setValue("portletSetupTitle_" + languageId, title);
        } else {
            portletSetup.reset("portletSetupTitle_" + languageId);
        }
    }

    portletSetup.setValue("portletSetupUseCustomTitle", String.valueOf(useCustomTitle));
    portletSetup.setValue("portletSetupShowBorders", String.valueOf(showBorders));

    if (Validator.isNotNull(linkToLayoutUuid)) {
        portletSetup.setValue("portletSetupLinkToLayoutUuid", linkToLayoutUuid);
    } else {
        portletSetup.reset("portletSetupLinkToLayoutUuid");
    }

    portletSetup.setValue("portletSetupCss", css);

    JSONObject wapData = jsonObj.getJSONObject("wapData");

    String wapTitle = wapData.getString("title");
    String wapInitialWindowState = wapData.getString("initialWindowState");

    portletSetup.setValue("lfrWapTitle", wapTitle);
    portletSetup.setValue("lfrWapInitialWindowState", wapInitialWindowState);

    portletSetup.store();

    InvokerPortletImpl.clearResponse(session, layout.getPrimaryKey(), portletId,
            LanguageUtil.getLanguageId(request));

    return null;
}

From source file:com.liferay.pushnotifications.sender.apple.ApplePushNotificationsSender.java

License:Open Source License

protected String buildPayload(JSONObject jsonObject) {
    PayloadBuilder builder = PayloadBuilder.newPayload();

    JSONObject payloadJSONObject = jsonObject.getJSONObject(PushNotificationsConstants.KEY_PAYLOAD);

    String message = payloadJSONObject.getString(PushNotificationsConstants.KEY_MESSAGE);

    if (message != null) {
        builder.alertBody(message);/*from  w w w. j a  v a2s  .  com*/
    }

    jsonObject.remove(PushNotificationsConstants.KEY_PAYLOAD);

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

    while (keys.hasNext()) {
        String key = keys.next();

        builder.customField(key, jsonObject.getString(key));
    }

    return builder.build();
}