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);
    }
  }
  public void doCreateActivity(
      UserId userId,
      GroupId groupId,
      String appId,
      Set<String> fields,
      Activity activity,
      SecurityToken securityToken)
      throws Exception {

    long userIdLong = GetterUtil.getLong(userId.getUserId(securityToken));

    String activityAppId = activity.getAppId();

    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

    SerializerUtil.copyProperties(activity, extraDataJSONObject, _ACTIVITY_FIELDS);

    SocialActivityLocalServiceUtil.addActivity(
        userIdLong,
        0L,
        Activity.class.getName(),
        activity.getPostedTime(),
        activityAppId.hashCode(),
        extraDataJSONObject.toString(),
        0L);
  }
    @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);
      }
    }
Exemplo n.º 4
0
  protected void addDDMFormFieldLocalizedProperty(
      JSONObject jsonObject,
      String propertyName,
      LocalizedValue localizedValue,
      Locale locale,
      Locale defaultLocale,
      String type) {

    String propertyValue = localizedValue.getString(locale);

    if (Validator.isNull(propertyValue)) {
      propertyValue = localizedValue.getString(defaultLocale);
    }

    if (type.equals(DDMImpl.TYPE_RADIO) || type.equals(DDMImpl.TYPE_SELECT)) {

      if (propertyName.equals("predefinedValue")) {
        try {
          jsonObject.put(propertyName, JSONFactoryUtil.createJSONArray(propertyValue));
        } catch (Exception e) {
        }

        return;
      }
    }

    jsonObject.put(propertyName, propertyValue);
  }
  public JSONObject getJSONGroupTags(long groupId, String name, int start, int end)
      throws PortalException, SystemException {

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    int page = end / (end - start);

    jsonObject.put("page", page);

    List<AssetTag> tags = new ArrayList<AssetTag>();
    int total = 0;

    if (Validator.isNotNull(name)) {
      name = (CustomSQLUtil.keywords(name))[0];

      tags = getTags(groupId, name, new String[0], start, end);
      total = getTagsCount(groupId, name, new String[0]);
    } else {
      tags = getGroupTags(groupId, start, end, null);
      total = getGroupTagsCount(groupId);
    }

    String tagsJSON = JSONFactoryUtil.looseSerialize(tags);

    JSONArray tagsJSONArray = JSONFactoryUtil.createJSONArray(tagsJSON);

    jsonObject.put("tags", tagsJSONArray);

    jsonObject.put("total", total);

    return jsonObject;
  }
  protected void installXuggler(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    ProgressTracker progressTracker =
        new ProgressTracker(actionRequest, WebKeys.XUGGLER_INSTALL_STATUS);

    progressTracker.addProgress(ProgressStatusConstants.DOWNLOADING, 15, "downloading-xuggler");
    progressTracker.addProgress(ProgressStatusConstants.COPYING, 70, "copying-xuggler-files");

    progressTracker.initialize();

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

    try {
      XugglerUtil.installNativeLibraries(jarName, progressTracker);

      JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

      jsonObject.put("success", Boolean.TRUE);

      writeJSON(actionRequest, actionResponse, jsonObject);
    } catch (Exception e) {
      JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

      jsonObject.put("exception", e.getMessage());
      jsonObject.put("success", Boolean.FALSE);

      writeJSON(actionRequest, actionResponse, jsonObject);
    }

    progressTracker.finish();
  }
  /** @deprecated As of 6.2.0, with no direct replacement */
  @Deprecated
  @Override
  public JSONObject getJSONGroupVocabularies(
      long groupId, String name, int start, int end, OrderByComparator<AssetVocabulary> obc)
      throws PortalException {

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    int page = end / (end - start);

    jsonObject.put("page", page);

    List<AssetVocabulary> vocabularies;
    int total = 0;

    if (Validator.isNotNull(name)) {
      name = (CustomSQLUtil.keywords(name))[0];

      vocabularies = getGroupVocabularies(groupId, name, start, end, obc);
      total = getGroupVocabulariesCount(groupId, name);
    } else {
      vocabularies = getGroupVocabularies(groupId, start, end, obc);
      total = getGroupVocabulariesCount(groupId);
    }

    String vocabulariesJSON = JSONFactoryUtil.looseSerialize(vocabularies);

    JSONArray vocabulariesJSONArray = JSONFactoryUtil.createJSONArray(vocabulariesJSON);

    jsonObject.put("vocabularies", vocabulariesJSONArray);

    jsonObject.put("total", total);

    return jsonObject;
  }
  public static JSONObject toJSONObject(AssetTag model) {
    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    jsonObject.put("tagId", model.getTagId());
    jsonObject.put("groupId", model.getGroupId());
    jsonObject.put("companyId", model.getCompanyId());
    jsonObject.put("userId", model.getUserId());
    jsonObject.put("userName", model.getUserName());

    Date createDate = model.getCreateDate();

    String createDateJSON = StringPool.BLANK;

    if (createDate != null) {
      createDateJSON = String.valueOf(createDate.getTime());
    }

    jsonObject.put("createDate", createDateJSON);

    Date modifiedDate = model.getModifiedDate();

    String modifiedDateJSON = StringPool.BLANK;

    if (modifiedDate != null) {
      modifiedDateJSON = String.valueOf(modifiedDate.getTime());
    }

    jsonObject.put("modifiedDate", modifiedDateJSON);
    jsonObject.put("name", model.getName());
    jsonObject.put("assetCount", model.getAssetCount());

    return jsonObject;
  }
  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()]));
  }
Exemplo n.º 10
0
  protected JSONArray getPortletURLsJSONArray(Map<String, PortletURL> portletURLs) {

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    if (MapUtil.isEmpty(portletURLs)) {
      return jsonArray;
    }

    for (Map.Entry<String, PortletURL> entry : portletURLs.entrySet()) {
      JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

      jsonObject.put("name", entry.getKey());

      PortletURL portletURL = entry.getValue();

      portletURL.setParameter("selPlid", "{selPlid}");

      jsonObject.put(
          "value",
          StringUtil.replace(portletURL.toString(), HttpUtil.encodePath("{selPlid}"), "{selPlid}"));

      jsonArray.put(jsonObject);
    }

    return jsonArray;
  }
  protected void sendNotificationEvent(MBMessage mbMessage) throws PortalException {

    JSONObject notificationEventJSONObject = JSONFactoryUtil.createJSONObject();

    notificationEventJSONObject.put("classPK", mbMessage.getMessageId());
    notificationEventJSONObject.put("userId", mbMessage.getUserId());

    List<UserThread> userThreads =
        UserThreadLocalServiceUtil.getMBThreadUserThreads(mbMessage.getThreadId());

    for (UserThread userThread : userThreads) {
      if ((userThread.getUserId() == mbMessage.getUserId())
          || ((userThread.getUserId() != mbMessage.getUserId())
              && !UserNotificationManagerUtil.isDeliver(
                  userThread.getUserId(),
                  PortletKeys.PRIVATE_MESSAGING,
                  0,
                  PrivateMessagingConstants.NEW_MESSAGE,
                  UserNotificationDeliveryConstants.TYPE_WEBSITE))) {

        continue;
      }

      UserNotificationEventLocalServiceUtil.sendUserNotificationEvents(
          userThread.getUserId(),
          PortletKeys.PRIVATE_MESSAGING,
          UserNotificationDeliveryConstants.TYPE_WEBSITE,
          notificationEventJSONObject);
    }
  }
  public JSONObject getJSONVocabularyCategories(
      long groupId, String name, long vocabularyId, int start, int end, OrderByComparator obc)
      throws PortalException, SystemException {

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    int page = 0;

    if (end > 0 && start > 0) {
      page = end / (end - start);
    }

    jsonObject.put("page", page);

    List<AssetCategory> categories;
    int total = 0;

    if (Validator.isNotNull(name)) {
      name = (CustomSQLUtil.keywords(name))[0];

      categories = getVocabularyCategories(groupId, name, vocabularyId, start, end, obc);
      total = getVocabularyCategoriesCount(groupId, name, vocabularyId);
    } else {
      categories = getVocabularyCategories(vocabularyId, start, end, obc);
      total = getVocabularyCategoriesCount(groupId, vocabularyId);
    }

    jsonObject.put("categories", toJSONArray(categories));
    jsonObject.put("total", total);

    return jsonObject;
  }
Exemplo n.º 13
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);
        }
      }
    }
  }
  public void downloadApp(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    long appPackageId = ParamUtil.getLong(actionRequest, "appPackageId");
    boolean unlicensed = ParamUtil.getBoolean(actionRequest, "unlicensed");

    File file = null;

    try {
      file = FileUtil.createTempFile();

      downloadApp(actionRequest, actionResponse, appPackageId, unlicensed, file);

      App app = _appService.updateApp(file);

      JSONObject jsonObject = getAppJSONObject(app.getRemoteAppId());

      jsonObject.put("cmd", "downloadApp");
      jsonObject.put("message", "success");

      writeJSON(actionRequest, actionResponse, jsonObject);
    } finally {
      if (file != null) {
        file.delete();
      }
    }
  }
  public static JSONObject toJSONObject(AssetCategoryProperty model) {
    JSONObject jsonObj = JSONFactoryUtil.createJSONObject();

    jsonObj.put("categoryPropertyId", model.getCategoryPropertyId());
    jsonObj.put("companyId", model.getCompanyId());
    jsonObj.put("userId", model.getUserId());
    jsonObj.put("userName", model.getUserName());

    Date createDate = model.getCreateDate();

    String createDateJSON = StringPool.BLANK;

    if (createDate != null) {
      createDateJSON = String.valueOf(createDate.getTime());
    }

    jsonObj.put("createDate", createDateJSON);

    Date modifiedDate = model.getModifiedDate();

    String modifiedDateJSON = StringPool.BLANK;

    if (modifiedDate != null) {
      modifiedDateJSON = String.valueOf(modifiedDate.getTime());
    }

    jsonObj.put("modifiedDate", modifiedDateJSON);
    jsonObj.put("categoryId", model.getCategoryId());
    jsonObj.put("key", model.getKey());
    jsonObj.put("value", model.getValue());

    return jsonObj;
  }
Exemplo n.º 16
0
  protected void addTempAttachment(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);

    long nodeId = ParamUtil.getLong(actionRequest, "nodeId");
    String sourceFileName = uploadPortletRequest.getFileName("file");

    InputStream inputStream = null;

    try {
      inputStream = uploadPortletRequest.getFileAsStream("file");

      String mimeType = uploadPortletRequest.getContentType("file");

      String tempFileName = TempFileEntryUtil.getTempFileName(sourceFileName);

      FileEntry fileEntry =
          _wikiPageService.addTempFileEntry(
              nodeId, _TEMP_FOLDER_NAME, tempFileName, inputStream, mimeType);

      JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

      jsonObject.put("groupId", fileEntry.getGroupId());
      jsonObject.put("name", fileEntry.getTitle());
      jsonObject.put("title", sourceFileName);
      jsonObject.put("uuid", fileEntry.getUuid());

      JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
    } finally {
      StreamUtil.cleanUp(inputStream);
    }
  }
  public JSONArray getJSONActivityDefinitions(long groupId, String className)
      throws PortalException, SystemException {

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    List<SocialActivityDefinition> activityDefinitions =
        socialActivitySettingLocalService.getActivityDefinitions(groupId, className);

    for (SocialActivityDefinition activityDefinition : activityDefinitions) {

      JSONObject activityDefinitionJSONObject =
          JSONFactoryUtil.createJSONObject(JSONFactoryUtil.looseSerialize(activityDefinition));

      JSONArray activityCounterDefinitionsJSONArray = JSONFactoryUtil.createJSONArray();

      for (SocialActivityCounterDefinition activityCounterDefinition :
          activityDefinition.getActivityCounterDefinitions()) {

        JSONObject activityCounterDefinitionJSONObject =
            JSONFactoryUtil.createJSONObject(
                JSONFactoryUtil.looseSerialize(activityCounterDefinition));

        activityCounterDefinitionsJSONArray.put(activityCounterDefinitionJSONObject);
      }

      activityDefinitionJSONObject.put("counters", activityCounterDefinitionsJSONArray);

      jsonArray.put(activityDefinitionJSONObject);
    }

    return jsonArray;
  }
Exemplo n.º 18
0
  public void getActionMethodNames(
      ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws IOException {

    PrintWriter printWriter = resourceResponse.getWriter();

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    String contextName = ParamUtil.getString(resourceRequest, "contextName");

    Map<String, Set<JSONWebServiceActionMapping>> jsonWebServiceActionMappingsMap =
        getServiceJSONWebServiceActionMappingsMap(contextName);

    String serviceClassName = ParamUtil.getString(resourceRequest, "serviceClassName");

    Set<JSONWebServiceActionMapping> jsonWebServiceActionMappingsSet =
        jsonWebServiceActionMappingsMap.get(serviceClassName);

    for (JSONWebServiceActionMapping jsonWebServiceActionMapping :
        jsonWebServiceActionMappingsSet) {

      JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

      Method method = jsonWebServiceActionMapping.getActionMethod();

      String actionMethodName = method.getName();

      jsonObject.put("actionMethodName", actionMethodName);

      jsonArray.put(jsonObject);
    }

    printWriter.write(jsonArray.toString());
  }
Exemplo n.º 19
0
  protected JSONArray getServiceClassNamesToContextNamesJSONArray() {
    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    Set<String> contextNames = _jsonWebServiceActionsManager.getContextNames();

    for (String contextName : contextNames) {
      Map<String, Set<JSONWebServiceActionMapping>> jsonWebServiceActionMappingsMap =
          getServiceJSONWebServiceActionMappingsMap(contextName);

      for (Map.Entry<String, Set<JSONWebServiceActionMapping>> entry :
          jsonWebServiceActionMappingsMap.entrySet()) {

        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

        jsonObject.put("serviceClassName", entry.getKey());

        Set<JSONWebServiceActionMapping> jsonWebServiceActionMappingsSet = entry.getValue();

        Iterator<JSONWebServiceActionMapping> iterator = jsonWebServiceActionMappingsSet.iterator();

        JSONWebServiceActionMapping firstJSONWebServiceActionMapping = iterator.next();

        jsonObject.put("contextName", firstJSONWebServiceActionMapping.getContextName());

        jsonArray.put(jsonObject);
      }
    }

    return jsonArray;
  }
  @Override
  protected String getBody(SocialActivity activity, ServiceContext serviceContext)
      throws Exception {

    String link = getLink(activity, serviceContext);

    String text = StringPool.BLANK;

    int activityType = activity.getType();

    if (activityType == JIRAActivityKeys.ADD_CHANGE) {
      JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject(activity.getExtraData());

      text =
          interpretJIRAChangeItems(
              extraDataJSONObject.getJSONArray("jiraChangeItems"), serviceContext);
    } else if (activityType == JIRAActivityKeys.ADD_COMMENT) {
      long jiraActionId = GetterUtil.getLong(getJSONValue(activity.getExtraData(), "jiraActionId"));

      JIRAAction jiraAction = JIRAActionLocalServiceUtil.getJIRAAction(jiraActionId);

      text = HtmlUtil.escape(jiraAction.getBody());
    } else if (activityType == JIRAActivityKeys.ADD_ISSUE) {
      JIRAIssue jiraIssue = JIRAIssueLocalServiceUtil.getJIRAIssue(activity.getClassPK());

      text = HtmlUtil.escape(jiraIssue.getSummary());
    }

    return wrapLink(link, text);
  }
 @Override
 public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
     throws IOException, PortletException {
   String id = resourceRequest.getResourceID();
   if (id.equalsIgnoreCase("getBrokerTopics")) {
     JSONArray topics = JSONFactoryUtil.createJSONArray();
     long brokerId = ParamUtil.getLong(resourceRequest, "brokerId");
     long brokerMessageListenerId = ParamUtil.getLong(resourceRequest, "brokerMessageListenerId");
     try {
       Broker b = BrokerLocalServiceUtil.fetchBroker(brokerId);
       BrokerMessageListener bml =
           (brokerMessageListenerId > 0)
               ? BrokerMessageListenerLocalServiceUtil.fetchBrokerMessageListener(
                   brokerMessageListenerId)
               : null;
       String[] topicsArr = b.getTopics().split(";");
       for (int i = 0; i < topicsArr.length; i++) {
         JSONObject obj = JSONFactoryUtil.createJSONObject();
         obj.put("topic", topicsArr[i]);
         boolean checked = false;
         if (bml != null) {
           String[] messageListenerTopcs = bml.getTopics().split(";");
           for (int j = 0; j < messageListenerTopcs.length && !checked; j++) {
             if (messageListenerTopcs[j].equalsIgnoreCase(topicsArr[i])) checked = true;
           }
         }
         obj.put("checked", checked);
         topics.put(obj);
       }
     } catch (Exception e) {
       logger.error(e);
     }
     resourceResponse.getWriter().println(topics.toString());
   }
 }
  protected void deleteTempFileEntry(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

    long folderId = ParamUtil.getLong(actionRequest, "folderId");
    String fileName = ParamUtil.getString(actionRequest, "fileName");

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    try {
      _dlAppService.deleteTempFileEntry(
          themeDisplay.getScopeGroupId(), folderId, TEMP_FOLDER_NAME, fileName);

      jsonObject.put("deleted", Boolean.TRUE);
    } catch (Exception e) {
      String errorMessage =
          themeDisplay.translate("an-unexpected-error-occurred-while-deleting-the-file");

      jsonObject.put("deleted", Boolean.FALSE);
      jsonObject.put("errorMessage", errorMessage);
    }

    JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
  }
  public static void process(
      ActionRequest actionRequest,
      ActionResponse actionResponse,
      Map<String, BaseAlloyControllerImpl> alloyControllers)
      throws Exception {

    String jsonString = null;

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

    BaseAlloyControllerImpl baseAlloyControllerImpl = alloyControllers.get(controller);

    if (baseAlloyControllerImpl == null) {
      throw new Exception("Unable to find controller " + controller);
    }

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

    try {
      if (action.equals("custom")) {
        Class<?> clazz = BaseAlloyControllerImpl.class;

        Method method =
            clazz.getDeclaredMethod("processDataRequest", new Class<?>[] {ActionRequest.class});

        jsonString =
            (String)
                ServiceBeanMethodInvocationFactoryUtil.proceed(
                    baseAlloyControllerImpl,
                    clazz,
                    method,
                    new Object[] {actionRequest},
                    new String[] {"transactionAdvice"});
      } else if (action.equals("dynamicQuery")) {
        jsonString = executeDynamicQuery(baseAlloyControllerImpl, actionRequest);
      } else if (action.equals("search")) {
        jsonString = executeSearch(baseAlloyControllerImpl, actionRequest);
      }
    } catch (Exception e) {
      JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

      String message = e.getMessage();

      if (Validator.isNull(message)) {
        message = baseAlloyControllerImpl.translate("an-unexpected-error-occurred");
      }

      jsonObject.put("message", message);

      jsonObject.put("stacktrace", StackTraceUtil.getStackTrace(e));
      jsonObject.put("success", false);

      jsonString = jsonObject.toString();
    }

    if (jsonString != null) {
      writeJSON(actionRequest, actionResponse, jsonString);
    }
  }
    protected void sendUserNotifications(
        List<Long> receiverUserIds,
        MicroblogsEntry microblogsEntry,
        JSONObject notificationEventJSONObject)
        throws PortalException {

      int count = receiverUserIds.size();

      int pages = count / Indexer.DEFAULT_INTERVAL;

      for (int i = 0; i <= pages; i++) {
        int start = (i * Indexer.DEFAULT_INTERVAL);
        int end = start + Indexer.DEFAULT_INTERVAL;

        if (count < end) {
          end = count;
        }

        for (int j = start; j < end; j++) {
          long subscriptionId = getSubscriptionId(receiverUserIds.get(j), microblogsEntry);

          notificationEventJSONObject.put("subscriptionId", subscriptionId);

          int notificationType =
              MicroblogsUtil.getNotificationType(
                  microblogsEntry,
                  receiverUserIds.get(j),
                  UserNotificationDeliveryConstants.TYPE_PUSH);

          if (notificationType != MicroblogsEntryConstants.NOTIFICATION_TYPE_UNKNOWN) {

            notificationEventJSONObject.put("notificationType", notificationType);

            userNotificationEventLocalService.sendUserNotificationEvents(
                receiverUserIds.get(j),
                MicroblogsPortletKeys.MICROBLOGS,
                UserNotificationDeliveryConstants.TYPE_PUSH,
                notificationEventJSONObject);
          }

          notificationType =
              MicroblogsUtil.getNotificationType(
                  microblogsEntry,
                  receiverUserIds.get(j),
                  UserNotificationDeliveryConstants.TYPE_WEBSITE);

          if (notificationType != MicroblogsEntryConstants.NOTIFICATION_TYPE_UNKNOWN) {

            notificationEventJSONObject.put("notificationType", notificationType);

            userNotificationEventLocalService.sendUserNotificationEvents(
                receiverUserIds.get(j),
                MicroblogsPortletKeys.MICROBLOGS,
                UserNotificationDeliveryConstants.TYPE_WEBSITE,
                notificationEventJSONObject);
          }
        }
      }
    }
  public static JSONObject toJSONObject(SoLoaiVanBanNoiBo model) {
    JSONObject jsonObj = JSONFactoryUtil.createJSONObject();

    jsonObj.put("soVanBanNoiBoId", model.getSoVanBanNoiBoId());
    jsonObj.put("loaiVanBanNoiBoId", model.getLoaiVanBanNoiBoId());

    return jsonObj;
  }
  @Override
  public KBComment addKBComment(
      long userId,
      long classNameId,
      long classPK,
      String content,
      boolean helpful,
      ServiceContext serviceContext)
      throws PortalException {

    // KB comment

    User user = userPersistence.findByPrimaryKey(userId);
    long groupId = serviceContext.getScopeGroupId();
    Date now = new Date();

    validate(content);

    long kbCommentId = counterLocalService.increment();

    KBComment kbComment = kbCommentPersistence.create(kbCommentId);

    kbComment.setUuid(serviceContext.getUuid());
    kbComment.setGroupId(groupId);
    kbComment.setCompanyId(user.getCompanyId());
    kbComment.setUserId(user.getUserId());
    kbComment.setUserName(user.getFullName());
    kbComment.setCreateDate(serviceContext.getCreateDate(now));
    kbComment.setModifiedDate(serviceContext.getModifiedDate(now));
    kbComment.setClassNameId(classNameId);
    kbComment.setClassPK(classPK);
    kbComment.setContent(content);
    kbComment.setHelpful(helpful);
    kbComment.setStatus(KBCommentConstants.STATUS_NEW);

    kbCommentPersistence.update(kbComment);

    // Social

    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

    putTitle(extraDataJSONObject, kbComment);

    socialActivityLocalService.addActivity(
        userId,
        kbComment.getGroupId(),
        KBComment.class.getName(),
        kbCommentId,
        AdminActivityKeys.ADD_KB_COMMENT,
        extraDataJSONObject.toString(),
        0);

    // Subscriptions

    notifySubscribers(kbComment, serviceContext);

    return kbComment;
  }
  public void joinOrganization(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

    Group group = _groupLocalService.getGroup(themeDisplay.getScopeGroupId());

    Organization organization = _organizationLocalService.getOrganization(group.getClassPK());

    Role role =
        _roleLocalService.getRole(themeDisplay.getCompanyId(), "Organization Administrator");

    LinkedHashMap<String, Object> userParams = new LinkedHashMap<>();

    userParams.put("userGroupRole", new Long[] {group.getGroupId(), role.getRoleId()});

    List<User> users =
        _userLocalService.search(
            themeDisplay.getCompanyId(),
            null,
            WorkflowConstants.STATUS_APPROVED,
            userParams,
            QueryUtil.ALL_POS,
            QueryUtil.ALL_POS,
            (OrderByComparator<User>) null);

    if (users.isEmpty()) {
      Role adminRole =
          _roleLocalService.getRole(themeDisplay.getCompanyId(), RoleConstants.ADMINISTRATOR);

      userParams.clear();

      userParams.put("usersRoles", adminRole.getRoleId());

      users =
          _userLocalService.search(
              themeDisplay.getCompanyId(),
              null,
              WorkflowConstants.STATUS_APPROVED,
              userParams,
              QueryUtil.ALL_POS,
              QueryUtil.ALL_POS,
              (OrderByComparator<User>) null);
    }

    JSONObject extraDataJSONObject = getExtraDataJSONObject(actionRequest);

    for (User user : users) {
      _socialRequestLocalService.addRequest(
          themeDisplay.getUserId(),
          0,
          Organization.class.getName(),
          organization.getOrganizationId(),
          MembersRequestKeys.ADD_MEMBER,
          extraDataJSONObject.toString(),
          user.getUserId());
    }
  }
  protected JSONObject getExtraDataJSONObject(ActionRequest actionRequest) {
    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

    String portletId = PortalUtil.getPortletId(actionRequest);

    extraDataJSONObject.put("portletId", PortletConstants.getRootPortletId(portletId));

    return extraDataJSONObject;
  }
Exemplo n.º 29
0
  @Override
  protected BooleanClause doGetFacetClause() {
    SearchContext searchContext = getSearchContext();

    FacetConfiguration facetConfiguration = getFacetConfiguration();

    JSONObject dataJSONObject = facetConfiguration.getData();

    String[] values = null;

    if (isStatic() && dataJSONObject.has("values")) {
      JSONArray valuesJSONArray = dataJSONObject.getJSONArray("values");

      values = new String[valuesJSONArray.length()];

      for (int i = 0; i < valuesJSONArray.length(); i++) {
        values[i] = valuesJSONArray.getString(i);
      }
    }

    String[] valuesParam =
        StringUtil.split(GetterUtil.getString(searchContext.getAttribute(getFieldName())));

    if (!isStatic() && (valuesParam != null) && (valuesParam.length > 0)) {
      values = valuesParam;
    }

    if ((values == null) || (values.length == 0)) {
      return null;
    }

    BooleanQuery facetQuery = BooleanQueryFactoryUtil.create(searchContext);

    for (String value : values) {
      FacetValueValidator facetValueValidator = getFacetValueValidator();

      if ((searchContext.getUserId() > 0) && !facetValueValidator.check(searchContext, value)) {

        continue;
      }

      TermQuery termQuery = TermQueryFactoryUtil.create(searchContext, getFieldName(), value);

      try {
        facetQuery.add(termQuery, BooleanClauseOccur.SHOULD);
      } catch (ParseException pe) {
        _log.error(pe, pe);
      }
    }

    if (!facetQuery.hasClauses()) {
      return null;
    }

    return BooleanClauseFactoryUtil.create(
        searchContext, facetQuery, BooleanClauseOccur.MUST.getName());
  }
  public static JSONObject toJSONObject(QAChuDeCauHoi model) {
    JSONObject jsonObj = JSONFactoryUtil.createJSONObject();

    jsonObj.put("maChuDeCauHoi", model.getMaChuDeCauHoi());
    jsonObj.put("tenChuDeCauHoi", model.getTenChuDeCauHoi());
    jsonObj.put("active", model.getActive());

    return jsonObj;
  }