Esempio n. 1
0
  protected void updateActivitySettings(ActionRequest actionRequest) throws Exception {

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

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

    JSONObject settingsJSONObject = JSONFactoryUtil.createJSONObject(settingsJSON);

    JSONArray actionsJSONArray = settingsJSONObject.getJSONArray("actions");

    String modelName = settingsJSONObject.getString("modelName");

    for (int i = 0; i < actionsJSONArray.length(); i++) {
      JSONObject actionJSONObject = actionsJSONArray.getJSONObject(i);

      int activityType = actionJSONObject.getInt("activityType");

      SocialActivityDefinition activityDefinition =
          SocialActivitySettingServiceUtil.getActivityDefinition(
              themeDisplay.getSiteGroupIdOrLiveGroupId(), modelName, activityType);

      if (activityDefinition == null) {
        continue;
      }

      List<SocialActivityCounterDefinition> activityCounterDefinitions = new ArrayList<>();

      activityCounterDefinitions.add(
          updateActivityCounterDefinition(
              actionJSONObject,
              activityDefinition,
              SocialActivityCounterConstants.NAME_CONTRIBUTION));

      activityCounterDefinitions.add(
          updateActivityCounterDefinition(
              actionJSONObject,
              activityDefinition,
              SocialActivityCounterConstants.NAME_PARTICIPATION));

      activityCounterDefinitions.add(
          updateActivityCounterDefinition(
              actionJSONObject,
              activityDefinition,
              SocialActivityCounterConstants.NAME_POPULARITY));

      SocialActivitySettingServiceUtil.updateActivitySettings(
          themeDisplay.getSiteGroupIdOrLiveGroupId(),
          modelName,
          activityType,
          activityCounterDefinitions);
    }
  }
Esempio n. 2
0
  protected SocialActivityCounterDefinition updateActivityCounterDefinition(
      JSONObject actionJSONObject,
      SocialActivityDefinition activityDefinition,
      String activityCounterName) {

    SocialActivityCounterDefinition activityCounterDefinition =
        activityDefinition.getActivityCounterDefinition(activityCounterName);

    if (activityCounterDefinition == null) {
      activityCounterDefinition = new SocialActivityCounterDefinition();

      activityCounterDefinition.setName(activityCounterName);
    }

    if (activityCounterName.equals(SocialActivityCounterConstants.NAME_CONTRIBUTION)) {

      activityCounterDefinition.setOwnerType(SocialActivityCounterConstants.TYPE_CREATOR);
    } else if (activityCounterName.equals(SocialActivityCounterConstants.NAME_PARTICIPATION)) {

      activityCounterDefinition.setOwnerType(SocialActivityCounterConstants.TYPE_ACTOR);
    } else if (activityCounterName.equals(SocialActivityCounterConstants.NAME_POPULARITY)) {

      activityCounterDefinition.setOwnerType(SocialActivityCounterConstants.TYPE_ASSET);

      activityCounterName = SocialActivityCounterConstants.NAME_CONTRIBUTION;
    } else {
      throw new IllegalArgumentException();
    }

    activityCounterDefinition.setEnabled(actionJSONObject.getBoolean("active"));
    activityCounterDefinition.setIncrement(
        actionJSONObject.getInt(activityCounterName + "Increment"));
    activityCounterDefinition.setLimitPeriod(
        actionJSONObject.getInt(activityCounterName + "LimitPeriod"));
    activityCounterDefinition.setLimitValue(
        actionJSONObject.getInt(activityCounterName + "LimitValue"));

    return activityCounterDefinition;
  }
  @Override
  protected String getTitle(
      JSONObject jsonObject, AssetRenderer<?> assetRenderer, ServiceContext serviceContext) {

    MicroblogsEntry microblogsEntry =
        _microblogsEntryLocalService.fetchMicroblogsEntry(assetRenderer.getClassPK());

    String title = StringPool.BLANK;

    String userFullName =
        HtmlUtil.escape(PortalUtil.getUserName(microblogsEntry.getUserId(), StringPool.BLANK));

    int notificationType = jsonObject.getInt("notificationType");

    if (notificationType == MicroblogsEntryConstants.NOTIFICATION_TYPE_REPLY) {

      title = serviceContext.translate("x-commented-on-your-post", userFullName);
    } else if (notificationType == MicroblogsEntryConstants.NOTIFICATION_TYPE_REPLY_TO_REPLIED) {

      long parentMicroblogsEntryUserId = microblogsEntry.fetchParentMicroblogsEntryUserId();

      User user = _userLocalService.fetchUser(parentMicroblogsEntryUserId);

      if (user != null) {
        title =
            serviceContext.translate(
                "x-also-commented-on-x's-post", userFullName, user.getFullName());
      }
    } else if (notificationType == MicroblogsEntryConstants.NOTIFICATION_TYPE_REPLY_TO_TAGGED) {

      title = serviceContext.translate("x-commented-on-a-post-you-are-tagged-in", userFullName);
    } else if (notificationType == MicroblogsEntryConstants.NOTIFICATION_TYPE_TAG) {

      title = serviceContext.translate("x-tagged-you-in-a-post", userFullName);
    }

    return title;
  }
  protected FileEntry saveTempImageFileEntry(ActionRequest actionRequest) throws Exception {

    FileEntry tempFileEntry = null;

    InputStream tempImageStream = null;

    try {
      tempFileEntry = getTempImageFileEntry(actionRequest);

      tempImageStream = tempFileEntry.getContentStream();

      ImageBag imageBag = ImageToolUtil.read(tempImageStream);

      RenderedImage renderedImage = imageBag.getRenderedImage();

      String cropRegionJSON = ParamUtil.getString(actionRequest, "cropRegion");

      if (Validator.isNotNull(cropRegionJSON)) {
        JSONObject jsonObject = JSONFactoryUtil.createJSONObject(cropRegionJSON);

        int height = jsonObject.getInt("height");
        int width = jsonObject.getInt("width");
        int x = jsonObject.getInt("x");
        int y = jsonObject.getInt("y");

        if ((x == 0)
            && (y == 0)
            && (renderedImage.getHeight() == height)
            && (renderedImage.getWidth() == width)) {

          return tempFileEntry;
        }

        if ((height + y) > renderedImage.getHeight()) {
          height = renderedImage.getHeight() - y;
        }

        if ((width + x) > renderedImage.getWidth()) {
          width = renderedImage.getWidth() - x;
        }

        renderedImage = ImageToolUtil.crop(renderedImage, height, width, x, y);
      }

      byte[] bytes = ImageToolUtil.getBytes(renderedImage, imageBag.getType());

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

      File file = FileUtil.createTempFile(bytes);

      try {
        TempFileEntryUtil.deleteTempFileEntry(
            themeDisplay.getScopeGroupId(),
            themeDisplay.getUserId(),
            getTempImageFolderName(),
            getTempImageFileName(actionRequest));
      } catch (Exception e) {
      }

      return TempFileEntryUtil.addTempFileEntry(
          themeDisplay.getScopeGroupId(),
          themeDisplay.getUserId(),
          getTempImageFolderName(),
          getTempImageFileName(actionRequest),
          file,
          tempFileEntry.getMimeType());
    } catch (NoSuchFileEntryException nsfee) {
      throw new UploadException(nsfee);
    } catch (NoSuchRepositoryException nsre) {
      throw new UploadException(nsre);
    } finally {
      StreamUtil.cleanUp(tempImageStream);
    }
  }