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()]));
  }
    @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);
      }
    }
  @Override
  public void deleteStagedModel(String uuid, long groupId, String className, String extraData)
      throws PortalException {

    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject(extraData);

    boolean privateLayout = extraDataJSONObject.getBoolean("privateLayout");

    Layout layout = _layoutLocalService.fetchLayoutByUuidAndGroupId(uuid, groupId, privateLayout);

    if (layout != null) {
      deleteStagedModel(layout);
    }
  }
  protected void addLayout(long parentLayoutId, JSONObject layoutJSONObject) throws Exception {

    String name = layoutJSONObject.getString("name");
    String title = layoutJSONObject.getString("title");
    boolean hidden = layoutJSONObject.getBoolean("hidden");

    String friendlyURL = layoutJSONObject.getString("friendlyURL");

    if (Validator.isNotNull(friendlyURL) && !friendlyURL.startsWith(StringPool.SLASH)) {

      friendlyURL = StringPool.SLASH + friendlyURL;
    }

    Layout layout =
        LayoutLocalServiceUtil.addLayout(
            userId,
            groupId,
            privateLayout,
            parentLayoutId,
            name,
            title,
            StringPool.BLANK,
            LayoutConstants.TYPE_PORTLET,
            hidden,
            friendlyURL,
            serviceContext);

    LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();

    String layoutTemplateId =
        layoutJSONObject.getString("layoutTemplateId", _defaultLayoutTemplateId);

    if (Validator.isNotNull(layoutTemplateId)) {
      layoutTypePortlet.setLayoutTemplateId(userId, layoutTemplateId, false);
    }

    JSONArray columnsJSONArray = layoutJSONObject.getJSONArray("columns");

    addLayoutColumns(layout, columnsJSONArray);

    LayoutLocalServiceUtil.updateLayout(
        groupId, layout.isPrivateLayout(), layout.getLayoutId(), layout.getTypeSettings());

    JSONArray layoutsJSONArray = layoutJSONObject.getJSONArray("layouts");

    addLayouts(layout.getLayoutId(), layoutsJSONArray);
  }
  @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"));
  }
Пример #6
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;
  }
Пример #7
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;
  }