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);
  }
  protected void updateBasicConfiguration(
      PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    boolean displayScopeFacet =
        GetterUtil.getBoolean(getParameter(actionRequest, "displayScopeFacet"));
    boolean displayAssetCategoriesFacet =
        GetterUtil.getBoolean(getParameter(actionRequest, "displayAssetCategoriesFacet"));
    boolean displayAssetTagsFacet =
        GetterUtil.getBoolean(getParameter(actionRequest, "displayAssetTagsFacet"));
    boolean displayAssetTypeFacet =
        GetterUtil.getBoolean(getParameter(actionRequest, "displayAssetTypeFacet"));
    boolean displayFolderFacet =
        GetterUtil.getBoolean(getParameter(actionRequest, "displayFolderFacet"));
    boolean displayUserFacet =
        GetterUtil.getBoolean(getParameter(actionRequest, "displayUserFacet"));
    boolean displayModifiedRangeFacet =
        GetterUtil.getBoolean(getParameter(actionRequest, "displayModifiedRangeFacet"));

    String searchConfiguration = ContentUtil.get(SearchWebConfigurationValues.FACET_CONFIGURATION);

    JSONObject configurationJSONObject = JSONFactoryUtil.createJSONObject(searchConfiguration);

    JSONArray oldFacetsJSONArray = configurationJSONObject.getJSONArray("facets");

    if (oldFacetsJSONArray == null) {
      if (_log.isWarnEnabled()) {
        _log.warn(
            "The resource "
                + SearchWebConfigurationValues.FACET_CONFIGURATION
                + " is missing a valid facets JSON array");
      }
    }

    JSONArray newFacetsJSONArray = JSONFactoryUtil.createJSONArray();

    for (int i = 0; i < oldFacetsJSONArray.length(); i++) {
      JSONObject oldFacetJSONObject = oldFacetsJSONArray.getJSONObject(i);

      String fieldName = oldFacetJSONObject.getString("fieldName");

      if ((displayScopeFacet && fieldName.equals("groupId"))
          || (displayAssetCategoriesFacet && fieldName.equals("assetCategoryIds"))
          || (displayAssetTagsFacet && fieldName.equals("assetTagNames"))
          || (displayAssetTypeFacet && fieldName.equals("entryClassName"))
          || (displayFolderFacet && fieldName.equals("folderId"))
          || (displayUserFacet && fieldName.equals("userId"))
          || (displayModifiedRangeFacet && fieldName.equals("modified"))) {

        newFacetsJSONArray.put(oldFacetJSONObject);
      }
    }

    configurationJSONObject.put("facets", newFacetsJSONArray);

    searchConfiguration = configurationJSONObject.toString();

    setPreference(actionRequest, "searchConfiguration", searchConfiguration);
  }
  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 testDocumentLibraryDDMFormFieldValueValues(DDMFormFieldValue ddmFormFieldValue)
      throws Exception {

    Assert.assertEquals("autx", ddmFormFieldValue.getInstanceId());

    JSONObject expectedJSONObject = JSONFactoryUtil.createJSONObject();

    expectedJSONObject.put("groupId", 10192);
    expectedJSONObject.put("uuid", "c8acdf70-e101-46a6-83e5-c5f5e087b0dc");
    expectedJSONObject.put("version", 1.0);

    Value value = ddmFormFieldValue.getValue();

    JSONAssert.assertEquals(expectedJSONObject.toString(), value.getString(LocaleUtil.US), false);
    JSONAssert.assertEquals(
        expectedJSONObject.toString(), value.getString(LocaleUtil.BRAZIL), false);
  }
  @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 String toJSON(Layout layout) {
      JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

      jsonObject.put("groupId", layout.getGroupId());
      jsonObject.put("layoutId", layout.getLayoutId());
      jsonObject.put("privateLayout", layout.isPrivateLayout());

      return jsonObject.toString();
    }
  @Override
  public MBThread moveThreadToTrash(long userId, MBThread thread) throws PortalException {

    // Thread

    if (thread.getCategoryId() == MBCategoryConstants.DISCUSSION_CATEGORY_ID) {

      return thread;
    }

    int oldStatus = thread.getStatus();

    if (oldStatus == WorkflowConstants.STATUS_PENDING) {
      thread.setStatus(WorkflowConstants.STATUS_DRAFT);

      mbThreadPersistence.update(thread);
    }

    thread = updateStatus(userId, thread.getThreadId(), WorkflowConstants.STATUS_IN_TRASH);

    // Trash

    TrashEntry trashEntry =
        trashEntryLocalService.addTrashEntry(
            userId,
            thread.getGroupId(),
            MBThread.class.getName(),
            thread.getThreadId(),
            thread.getUuid(),
            null,
            oldStatus,
            null,
            null);

    // Messages

    moveDependentsToTrash(thread.getGroupId(), thread.getThreadId(), trashEntry.getEntryId());

    // Social

    MBMessage message = mbMessageLocalService.getMBMessage(thread.getRootMessageId());

    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

    extraDataJSONObject.put("rootMessageId", thread.getRootMessageId());
    extraDataJSONObject.put("title", message.getSubject());

    SocialActivityManagerUtil.addActivity(
        userId,
        thread,
        SocialActivityConstants.TYPE_MOVE_TO_TRASH,
        extraDataJSONObject.toString(),
        0);

    return thread;
  }
    protected String toJSON(FileEntry fileEntry, String type) {
      JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

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

      return jsonObject.toString();
    }
  @Test
  public void testDeserializationWithUnlocalizableField() throws Exception {
    String serializedDDMFormValues =
        read("ddm-form-values-json-deserializer-unlocalizable-fields.json");

    DDMFormValues ddmFormValues =
        _ddmFormValuesJSONDeserializer.deserialize(null, serializedDDMFormValues);

    List<DDMFormFieldValue> ddmFormFieldValues = ddmFormValues.getDDMFormFieldValues();

    Assert.assertEquals(2, ddmFormFieldValues.size());

    DDMFormFieldValue booleanDDMFormFieldValue = ddmFormFieldValues.get(0);

    Assert.assertEquals("usht", booleanDDMFormFieldValue.getInstanceId());

    Value booleanValue = booleanDDMFormFieldValue.getValue();

    Assert.assertFalse(booleanValue.isLocalized());
    Assert.assertEquals("false", booleanValue.getString(LocaleUtil.US));
    Assert.assertEquals("false", booleanValue.getString(LocaleUtil.BRAZIL));

    DDMFormFieldValue documentLibraryDDMFormFieldValue = ddmFormFieldValues.get(1);

    Assert.assertEquals("xdwp", documentLibraryDDMFormFieldValue.getInstanceId());

    Value documentLibraryValue = documentLibraryDDMFormFieldValue.getValue();

    Assert.assertFalse(documentLibraryValue.isLocalized());

    JSONObject expectedJSONObject = JSONFactoryUtil.createJSONObject();

    expectedJSONObject.put("groupId", 10192);
    expectedJSONObject.put("uuid", "c8acdf70-e101-46a6-83e5-c5f5e087b0dc");
    expectedJSONObject.put("version", 1.0);

    JSONAssert.assertEquals(
        expectedJSONObject.toString(), documentLibraryValue.getString(LocaleUtil.US), false);
    JSONAssert.assertEquals(
        expectedJSONObject.toString(), documentLibraryValue.getString(LocaleUtil.BRAZIL), false);
  }
Exemplo n.º 11
0
  protected void updateSocialActivity(long activityId, JSONObject jsonObject) throws Exception {

    try (PreparedStatement ps =
        connection.prepareStatement(
            "update SocialActivity set extraData = ? where activityId = " + "?")) {

      ps.setString(1, jsonObject.toString());
      ps.setLong(2, activityId);

      ps.executeUpdate();
    }
  }
  private String _getServerInfo(String clusterNodeId) throws Exception {
    Map<String, String> serverInfo = LicenseUtil.getClusterServerInfo(clusterNodeId);

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    if (serverInfo != null) {
      for (Map.Entry<String, String> entry : serverInfo.entrySet()) {
        jsonObject.put(entry.getKey(), entry.getValue());
      }
    }

    return jsonObject.toString();
  }
  protected void testGeolocationDDMFormFieldValueValues(DDMFormFieldValue ddmFormFieldValue)
      throws Exception {

    Assert.assertEquals("powq", ddmFormFieldValue.getInstanceId());

    Value value = ddmFormFieldValue.getValue();

    JSONObject expectedJSONObject = JSONFactoryUtil.createJSONObject();

    expectedJSONObject.put("latitude", 34.0286226);
    expectedJSONObject.put("longitude", -117.8103367);

    JSONAssert.assertEquals(expectedJSONObject.toString(), value.getString(LocaleUtil.US), false);

    expectedJSONObject = JSONFactoryUtil.createJSONObject();

    expectedJSONObject.put("latitude", -8.0349219);
    expectedJSONObject.put("longitude", -34.91922120);

    JSONAssert.assertEquals(
        expectedJSONObject.toString(), value.getString(LocaleUtil.BRAZIL), false);
  }
  protected void testImageDDMFormFieldValueValues(DDMFormFieldValue ddmFormFieldValue)
      throws Exception {

    Assert.assertEquals("labt", ddmFormFieldValue.getInstanceId());

    Value value = ddmFormFieldValue.getValue();

    JSONObject expectedJSONObject = JSONFactoryUtil.createJSONObject();

    expectedJSONObject.put("alt", "This is a image description.");
    expectedJSONObject.put("data", "base64Value");

    JSONAssert.assertEquals(expectedJSONObject.toString(), value.getString(LocaleUtil.US), false);

    expectedJSONObject = JSONFactoryUtil.createJSONObject();

    expectedJSONObject.put("alt", "Isto e uma descricao de imagem.");
    expectedJSONObject.put("data", "valorEmBase64");

    JSONAssert.assertEquals(
        expectedJSONObject.toString(), value.getString(LocaleUtil.BRAZIL), false);
  }
  protected String getLinkToLayoutFieldValue(Layout layout, boolean includeGroupId) {

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    if (includeGroupId) {
      jsonObject.put("groupId", String.valueOf(layout.getGroupId()));
    }

    jsonObject.put("layoutId", String.valueOf(layout.getLayoutId()));
    jsonObject.put("privateLayout", layout.isPrivateLayout());

    return jsonObject.toString();
  }
  @Override
  public KBTemplate addKBTemplate(
      long userId, String title, String content, ServiceContext serviceContext)
      throws PortalException {

    // KB template

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

    validate(title, content);

    long kbTemplateId = counterLocalService.increment();

    KBTemplate kbTemplate = kbTemplatePersistence.create(kbTemplateId);

    kbTemplate.setUuid(serviceContext.getUuid());
    kbTemplate.setGroupId(groupId);
    kbTemplate.setCompanyId(user.getCompanyId());
    kbTemplate.setUserId(user.getUserId());
    kbTemplate.setUserName(user.getFullName());
    kbTemplate.setCreateDate(serviceContext.getCreateDate(now));
    kbTemplate.setModifiedDate(serviceContext.getModifiedDate(now));
    kbTemplate.setTitle(title);
    kbTemplate.setContent(content);

    kbTemplatePersistence.update(kbTemplate);

    // Resources

    resourceLocalService.addModelResources(kbTemplate, serviceContext);

    // Social

    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

    extraDataJSONObject.put("title", kbTemplate.getTitle());

    socialActivityLocalService.addActivity(
        userId,
        groupId,
        KBTemplate.class.getName(),
        kbTemplateId,
        AdminActivityKeys.ADD_KB_TEMPLATE,
        extraDataJSONObject.toString(),
        0);

    return kbTemplate;
  }
  private void _processJoinEvent(ClusterNode clusterNode) {
    Message message = new Message();

    message.put(ClusterLink.CLUSTER_FORWARD_MESSAGE, true);

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    jsonObject.put("clusterNodeId", clusterNode.getClusterNodeId());
    jsonObject.put("command", "addClusterNode");

    message.setPayload(jsonObject.toString());

    MessageBusUtil.sendMessage(DestinationNames.LIVE_USERS, message);
  }
  @Override
  @Transactional(enabled = false)
  public Map<String, Object> updateFileEntries(File zipFile) throws PortalException {

    Map<String, Object> responseMap = new HashMap<>();

    ZipReader zipReader = null;

    try {
      zipReader = ZipReaderFactoryUtil.getZipReader(zipFile);

      String manifest = zipReader.getEntryAsString("/manifest.json");

      JSONArray jsonArray = JSONFactoryUtil.createJSONArray(manifest);

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

        JSONWebServiceActionParametersMap jsonWebServiceActionParametersMap =
            JSONFactoryUtil.looseDeserialize(
                jsonObject.toString(), JSONWebServiceActionParametersMap.class);

        String zipFileId = MapUtil.getString(jsonWebServiceActionParametersMap, "zipFileId");

        try {
          responseMap.put(
              zipFileId,
              updateFileEntries(zipReader, zipFileId, jsonWebServiceActionParametersMap));
        } catch (Exception e) {
          String message = e.getMessage();

          if (!message.startsWith(StringPool.QUOTE) && !message.endsWith(StringPool.QUOTE)) {

            message = StringUtil.quote(message, StringPool.QUOTE);
          }

          String json = "{\"exception\": " + message + "}";

          responseMap.put(zipFileId, json);
        }
      }
    } finally {
      if (zipReader != null) {
        zipReader.close();
      }
    }

    return responseMap;
  }
  protected void testLinkToPageDDMFormFieldValueValues(DDMFormFieldValue ddmFormFieldValue)
      throws Exception {

    Assert.assertEquals("nast", ddmFormFieldValue.getInstanceId());

    Value value = ddmFormFieldValue.getValue();

    JSONObject expectedJSONObject = JSONFactoryUtil.createJSONObject();

    expectedJSONObject.put("groupId", 10192);
    expectedJSONObject.put("layoutId", 1);
    expectedJSONObject.put("privateLayout", false);

    JSONAssert.assertEquals(expectedJSONObject.toString(), value.getString(LocaleUtil.US), false);

    expectedJSONObject = JSONFactoryUtil.createJSONObject();

    expectedJSONObject.put("groupId", 10192);
    expectedJSONObject.put("layoutId", 2);
    expectedJSONObject.put("privateLayout", false);

    JSONAssert.assertEquals(
        expectedJSONObject.toString(), value.getString(LocaleUtil.BRAZIL), false);
  }
Exemplo n.º 20
0
  private static byte[] _encryptRequest(String serverURL, String request) throws Exception {

    byte[] bytes = request.getBytes(StringPool.UTF8);

    if (serverURL.startsWith(Http.HTTPS)) {
      return bytes;
    } else {
      JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

      bytes = Encryptor.encryptUnencoded(_symmetricKey, bytes);

      jsonObject.put("content", Base64.objectToString(bytes));
      jsonObject.put("key", _encryptedSymmetricKey);

      return jsonObject.toString().getBytes(StringPool.UTF8);
    }
  }
  protected static String getFileEntryValue(FileEntry fileEntry, ThemeDisplay themeDisplay)
      throws Exception {

    JSONObject fileEntryJSONObject = JSONFactoryUtil.createJSONObject();

    fileEntryJSONObject.put("fileEntryId", fileEntry.getFileEntryId());
    fileEntryJSONObject.put("groupId", fileEntry.getGroupId());
    fileEntryJSONObject.put("title", fileEntry.getTitle());
    fileEntryJSONObject.put("type", "document");
    fileEntryJSONObject.put(
        "url",
        DLUtil.getPreviewURL(
            fileEntry, fileEntry.getFileVersion(), themeDisplay, StringPool.BLANK, false, false));
    fileEntryJSONObject.put("uuid", fileEntry.getUuid());

    return fileEntryJSONObject.toString();
  }
  protected Field getDocumentLibraryField(FileEntry fileEntry, long ddmStructureId) {

    Field docLibraryField = new Field();

    docLibraryField.setDDMStructureId(ddmStructureId);
    docLibraryField.setName("document_library");

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    jsonObject.put("groupId", fileEntry.getGroupId());
    jsonObject.put("title", fileEntry.getTitle());
    jsonObject.put("uuid", fileEntry.getUuid());
    jsonObject.put("version", fileEntry.getVersion());

    docLibraryField.addValue(_enLocale, jsonObject.toString());

    return docLibraryField;
  }
  protected void updateSocialActivity(long activityId, JSONObject jsonObject) throws Exception {

    Connection con = null;
    PreparedStatement ps = null;

    try {
      con = DataAccess.getUpgradeOptimizedConnection();

      ps = con.prepareStatement("update SocialActivity set extraData = ? where activityId = ?");

      ps.setString(1, jsonObject.toString());
      ps.setLong(2, activityId);

      ps.executeUpdate();
    } finally {
      DataAccess.cleanUp(con, ps);
    }
  }
  @Test
  public void testGetSettingsLayout() throws Exception {
    JSONFactory jsonFactory = new JSONFactoryImpl();

    DDMFormFieldTypeSettingsSerializerHelper ddmFormFieldTypeSettingsSerializerHelper =
        new DDMFormFieldTypeSettingsSerializerHelper(
            SampleDDMFormFieldTypeSettings.class,
            new DDMFormJSONSerializerImpl(),
            new DDMFormLayoutJSONSerializerImpl(),
            jsonFactory);

    String expectedJSON = read("ddm-form-field-type-settings-layout-serializer-test-data.json");

    JSONObject actualJSONObject =
        ddmFormFieldTypeSettingsSerializerHelper.getSettingsLayoutJSONObject();

    JSONAssert.assertEquals(expectedJSON, actualJSONObject.toString(), false);
  }
  public static java.lang.String getJSONGroupVocabularies(
      long groupId,
      java.lang.String name,
      int start,
      int end,
      com.liferay.portal.kernel.util.OrderByComparator obc)
      throws RemoteException {
    try {
      com.liferay.portal.kernel.json.JSONObject returnValue =
          AssetVocabularyServiceUtil.getJSONGroupVocabularies(groupId, name, start, end, obc);

      return returnValue.toString();
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }
Exemplo n.º 26
0
  protected String getImageFieldValue(UploadRequest uploadRequest, String fieldNameValue) {

    try {
      byte[] bytes = getImageBytes(uploadRequest, fieldNameValue);

      if (ArrayUtil.isNotEmpty(bytes)) {
        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

        jsonObject.put("alt", uploadRequest.getParameter(fieldNameValue + "Alt"));
        jsonObject.put("data", UnicodeFormatter.bytesToHex(bytes));

        return jsonObject.toString();
      }
    } catch (Exception e) {
    }

    return StringPool.BLANK;
  }
  @Override
  public KBTemplate updateKBTemplate(
      long kbTemplateId, String title, String content, ServiceContext serviceContext)
      throws PortalException {

    // KB template

    validate(title, content);

    KBTemplate kbTemplate = kbTemplatePersistence.findByPrimaryKey(kbTemplateId);

    kbTemplate.setModifiedDate(serviceContext.getModifiedDate(null));
    kbTemplate.setTitle(title);
    kbTemplate.setContent(content);

    kbTemplatePersistence.update(kbTemplate);

    // Resources

    if ((serviceContext.getGroupPermissions() != null)
        || (serviceContext.getGuestPermissions() != null)) {

      updateKBTemplateResources(
          kbTemplate, serviceContext.getGroupPermissions(), serviceContext.getGuestPermissions());
    }

    // Social

    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

    extraDataJSONObject.put("title", kbTemplate.getTitle());

    socialActivityLocalService.addActivity(
        kbTemplate.getUserId(),
        kbTemplate.getGroupId(),
        KBTemplate.class.getName(),
        kbTemplateId,
        AdminActivityKeys.UPDATE_KB_TEMPLATE,
        extraDataJSONObject.toString(),
        0);

    return kbTemplate;
  }
Exemplo n.º 28
0
  public static Map<String, Object> registerOrder(
      String orderUuid, String productEntryName, int maxServers) {

    Map<String, Object> attributes = new HashMap<String, Object>();

    if (Validator.isNull(orderUuid)) {
      return attributes;
    }

    try {
      JSONObject jsonObject = _createRequest(orderUuid, productEntryName, maxServers);

      String response = sendRequest(jsonObject.toString());

      JSONObject responseJSONObject = JSONFactoryUtil.createJSONObject(response);

      attributes.put("ORDER_PRODUCT_ID", responseJSONObject.getString("productId"));
      attributes.put("ORDER_PRODUCTS", _getOrderProducts(responseJSONObject));

      String errorMessage = responseJSONObject.getString("errorMessage");

      if (Validator.isNotNull(errorMessage)) {
        attributes.put("ERROR_MESSAGE", errorMessage);

        return attributes;
      }

      String licenseXML = responseJSONObject.getString("licenseXML");

      if (Validator.isNotNull(licenseXML)) {
        LicenseManagerUtil.registerLicense(responseJSONObject);

        attributes.clear();
        attributes.put("SUCCESS_MESSAGE", "Your license has been successfully registered.");
      }
    } catch (Exception e) {
      _log.error(e, e);

      attributes.put("ERROR_MESSAGE", "There was an error contacting " + LICENSE_SERVER_URL);
    }

    return attributes;
  }
  @Override
  public KBComment updateKBComment(
      long kbCommentId,
      long classNameId,
      long classPK,
      String content,
      boolean helpful,
      int status,
      ServiceContext serviceContext)
      throws PortalException {

    // KB comment

    validate(content);

    KBComment kbComment = kbCommentPersistence.findByPrimaryKey(kbCommentId);

    kbComment.setModifiedDate(serviceContext.getModifiedDate(null));
    kbComment.setClassNameId(classNameId);
    kbComment.setClassPK(classPK);
    kbComment.setContent(content);
    kbComment.setHelpful(helpful);
    kbComment.setStatus(status);

    kbCommentPersistence.update(kbComment);

    // Social

    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

    putTitle(extraDataJSONObject, kbComment);

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

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

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

    OAuthRequest oAuthRequest = new OAuthRequest(Verb.POST, getServerPortletURL());

    setBaseRequestParameters(actionRequest, actionResponse, oAuthRequest);

    addOAuthParameter(oAuthRequest, "p_p_lifecycle", "1");
    addOAuthParameter(oAuthRequest, "p_p_state", WindowState.NORMAL.toString());

    String serverNamespace = getServerNamespace();

    addOAuthParameter(
        oAuthRequest,
        serverNamespace.concat("compatibility"),
        String.valueOf(ReleaseInfo.getBuildNumber()));
    addOAuthParameter(
        oAuthRequest, serverNamespace.concat("javax.portlet.action"), "getPrepackagedApps");

    Map<String, String> prepackagedApps = _appLocalService.getPrepackagedApps();

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    Set<String> keys = prepackagedApps.keySet();

    for (String key : keys) {
      jsonObject.put(key, prepackagedApps.get(key));
    }

    addOAuthParameter(
        oAuthRequest, serverNamespace.concat("prepackagedApps"), jsonObject.toString());

    Response response = getResponse(themeDisplay.getUser(), oAuthRequest);

    JSONObject responseJSONObject = JSONFactoryUtil.createJSONObject(response.getBody());

    writeJSON(actionRequest, actionResponse, responseJSONObject);
  }