@Override
  protected AssetRenderer<?> getAssetRenderer(JSONObject jsonObject) {
    MBMessage mbMessage = MBMessageLocalServiceUtil.fetchMBMessage(jsonObject.getLong("classPK"));

    if ((mbMessage != null) && mbMessage.isDiscussion()) {
      return getAssetRenderer(mbMessage.getClassName(), mbMessage.getClassPK());
    } else {
      return getAssetRenderer(jsonObject.getString("className"), jsonObject.getLong("classPK"));
    }
  }
Esempio n. 2
0
  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);
        }
      }
    }
  }
  @Override
  protected String getTitle(
      JSONObject jsonObject, AssetRenderer<?> assetRenderer, ServiceContext serviceContext) {

    MBMessage mbMessage = MBMessageLocalServiceUtil.fetchMBMessage(jsonObject.getLong("classPK"));

    AssetRendererFactory<?> assetRendererFactory =
        AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(
            assetRenderer.getClassName());

    String typeName = assetRendererFactory.getTypeName(serviceContext.getLocale());

    ResourceBundle resourceBundle =
        ResourceBundle.getBundle("content.Language", serviceContext.getLocale());

    if ((mbMessage != null) && mbMessage.isDiscussion()) {
      return LanguageUtil.format(
          resourceBundle,
          "x-mentioned-you-in-a-comment-in-a-x",
          new String[] {
            HtmlUtil.escape(assetRenderer.getUserName()),
            StringUtil.toLowerCase(HtmlUtil.escape(typeName))
          },
          false);
    } else {
      return LanguageUtil.format(
          resourceBundle,
          "x-mentioned-you-in-a-x",
          new String[] {
            HtmlUtil.escape(assetRenderer.getUserName()),
            StringUtil.toLowerCase(HtmlUtil.escape(typeName))
          },
          false);
    }
  }
  protected long[] getLayoutIds(long groupId, boolean privateLayout, String layoutIdsJSON)
      throws Exception {

    if (Validator.isNull(layoutIdsJSON)) {
      return new long[0];
    }

    List<Long> layoutIds = new ArrayList<Long>();

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray(layoutIdsJSON);

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

      long layoutId = jsonObject.getLong("layoutId");

      if (layoutId > 0) {
        layoutIds.add(layoutId);
      }

      if (jsonObject.getBoolean("includeChildren")) {
        addLayoutIds(layoutIds, groupId, privateLayout, layoutId);
      }
    }

    return ArrayUtil.toArray(layoutIds.toArray(new Long[layoutIds.size()]));
  }
  protected void upgradeMicroblogActivities() throws Exception {
    Connection con = null;
    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);
    }
  }
    @Override
    public void transform(DDMFormFieldValue ddmFormFieldValue) throws PortalException {

      Value value = ddmFormFieldValue.getValue();

      for (Locale locale : value.getAvailableLocales()) {
        String valueString = value.getString(locale);

        JSONObject jsonObject = JSONFactoryUtil.createJSONObject(valueString);

        long groupId = GetterUtil.getLong(jsonObject.get("groupId"));
        long layoutId = GetterUtil.getLong(jsonObject.getLong("layoutId"));
        boolean privateLayout = jsonObject.getBoolean("privateLayout");

        Layout layout = _layoutLocalService.getLayout(groupId, privateLayout, layoutId);

        Element entityElement = _portletDataContext.getExportDataElement(_stagedModel);

        _portletDataContext.addReferenceElement(
            _stagedModel,
            entityElement,
            layout,
            PortletDataContext.REFERENCE_TYPE_DEPENDENCY,
            true);
      }
    }
    protected Layout fetchImportedLayout(
        PortletDataContext portletDataContext, JSONObject jsonObject) {

      Map<Long, Layout> layouts =
          (Map<Long, Layout>) portletDataContext.getNewPrimaryKeysMap(Layout.class + ".layout");

      long layoutId = jsonObject.getLong("layoutId");

      Layout layout = layouts.get(layoutId);

      if (layout == null) {
        if (_log.isWarnEnabled()) {
          _log.warn("Unable to find layout with ID " + layoutId);
        }
      }

      return layout;
    }
  @Override
  protected String getLink(
      UserNotificationEvent userNotificationEvent, ServiceContext serviceContext) throws Exception {

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

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

    WorkflowHandler<?> workflowHandler =
        WorkflowHandlerRegistryUtil.getWorkflowHandler(entryClassName);

    if (workflowHandler == null) {
      return null;
    }

    long workflowTaskId = jsonObject.getLong("workflowTaskId");

    return workflowHandler.getURLEditWorkflowTask(workflowTaskId, serviceContext);
  }
  @Override
  protected String getBody(
      UserNotificationEvent userNotificationEvent, ServiceContext serviceContext) throws Exception {

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

    long workflowTaskId = jsonObject.getLong("workflowTaskId");

    WorkflowTask workflowTask =
        WorkflowTaskManagerUtil.fetchWorkflowTask(serviceContext.getCompanyId(), workflowTaskId);

    if (workflowTask == null) {
      _userNotificationEventLocalService.deleteUserNotificationEvent(
          userNotificationEvent.getUserNotificationEventId());

      return null;
    }

    return HtmlUtil.escape(jsonObject.getString("notificationMessage"));
  }
  @Test
  public void testGetSelectedLayoutsJSONSelectChildLayout() throws Exception {
    Layout layout = LayoutTestUtil.addLayout(_stagingGroup);

    Layout childLayout = LayoutTestUtil.addLayout(_stagingGroup, layout.getPlid());

    long[] selectedLayoutIds = new long[] {childLayout.getLayoutId()};

    String selectedLayoutsJSON =
        ExportImportHelperUtil.getSelectedLayoutsJSON(
            _stagingGroup.getGroupId(), false, StringUtil.merge(selectedLayoutIds));

    JSONArray selectedLayoutsJSONArray = JSONFactoryUtil.createJSONArray(selectedLayoutsJSON);

    Assert.assertEquals(1, selectedLayoutsJSONArray.length());

    JSONObject layoutJSONObject = selectedLayoutsJSONArray.getJSONObject(0);

    Assert.assertTrue(layoutJSONObject.getBoolean("includeChildren"));
    Assert.assertEquals(childLayout.getPlid(), layoutJSONObject.getLong("plid"));
  }
  @Override
  protected void doReceive(final Message message) throws Exception {
    if (checkMessagePayload(message)) {
      final MessageStatus messageStatus = (MessageStatus) message.getPayload();

      if (checkMessageStatusPayload(messageStatus)) {
        final JSONObject jsonObject = (JSONObject) messageStatus.getPayload();

        if (checkJSONObject(jsonObject, "nodeId")
            && checkJSONObject(jsonObject, "monitorName")
            && checkJSONObject(jsonObject, "timestamp")
            && checkJSONObject(jsonObject, "result")) {

          final String nodeId = jsonObject.getString("nodeId");
          final String monitorName = jsonObject.getString("monitorName");
          final Long timestamp = jsonObject.getLong("timestamp");
          final JSONObject result = jsonObject.getJSONObject("result");

          monitoryHistoryWriter.addHistoryItem(nodeId, monitorName, timestamp, result);
        }
      }
    }
  }
    protected FileEntry fetchImportedFileEntry(
        PortletDataContext portletDataContext, JSONObject jsonObject) throws PortalException {

      Map<Long, Long> groupIds =
          (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Group.class);

      long groupId = jsonObject.getLong("groupId");
      String uuid = jsonObject.getString("uuid");

      groupId = MapUtil.getLong(groupIds, groupId, groupId);

      if ((groupId > 0) && Validator.isNotNull(uuid)) {
        try {
          return _dlAppService.getFileEntryByUuidAndGroupId(uuid, groupId);
        } catch (NoSuchFileEntryException nsfee) {
          if (_log.isWarnEnabled()) {
            _log.warn(
                "Unable to find file entry with uuid " + uuid + " and groupId " + groupId, nsfee);
          }
        }
      }

      return null;
    }
Esempio n. 13
0
  @Override
  public Serializable getDisplayFieldValue(
      ThemeDisplay themeDisplay, Serializable fieldValue, String type) throws Exception {

    if (fieldValue instanceof Date) {
      Date valueDate = (Date) fieldValue;

      DateFormat dateFormat = DateFormatFactoryUtil.getDate(themeDisplay.getLocale());

      fieldValue = dateFormat.format(valueDate);
    } else if (type.equals(DDMImpl.TYPE_CHECKBOX)) {
      Boolean valueBoolean = (Boolean) fieldValue;

      if (valueBoolean) {
        fieldValue = LanguageUtil.get(themeDisplay.getLocale(), "yes");
      } else {
        fieldValue = LanguageUtil.get(themeDisplay.getLocale(), "no");
      }
    } else if (type.equals(DDMImpl.TYPE_DDM_DOCUMENTLIBRARY)) {
      if (Validator.isNull(fieldValue)) {
        return StringPool.BLANK;
      }

      String valueString = String.valueOf(fieldValue);

      JSONObject jsonObject = JSONFactoryUtil.createJSONObject(valueString);

      String uuid = jsonObject.getString("uuid");
      long groupId = jsonObject.getLong("groupId");

      FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntryByUuidAndGroupId(uuid, groupId);

      fieldValue =
          DLUtil.getPreviewURL(
              fileEntry, fileEntry.getFileVersion(), null, StringPool.BLANK, false, true);
    } else if (type.equals(DDMImpl.TYPE_DDM_LINK_TO_PAGE)) {
      if (Validator.isNull(fieldValue)) {
        return StringPool.BLANK;
      }

      String valueString = String.valueOf(fieldValue);

      JSONObject jsonObject = JSONFactoryUtil.createJSONObject(valueString);

      long groupId = jsonObject.getLong("groupId");
      boolean privateLayout = jsonObject.getBoolean("privateLayout");
      long layoutId = jsonObject.getLong("layoutId");

      Layout layout = LayoutLocalServiceUtil.getLayout(groupId, privateLayout, layoutId);

      fieldValue = PortalUtil.getLayoutFriendlyURL(layout, themeDisplay);
    } else if (type.equals(DDMImpl.TYPE_RADIO) || type.equals(DDMImpl.TYPE_SELECT)) {

      String valueString = String.valueOf(fieldValue);

      JSONArray jsonArray = JSONFactoryUtil.createJSONArray(valueString);

      String[] stringArray = ArrayUtil.toStringArray(jsonArray);

      fieldValue = stringArray[0];
    }

    return fieldValue;
  }