示例#1
0
  public static ExpandoTable checkTable(
      long companyId, String tableName, PortletPreferences preferences) throws Exception {

    ExpandoTable expandoTable = null;

    try {
      expandoTable =
          ExpandoTableLocalServiceUtil.getTable(companyId, WebFormUtil.class.getName(), tableName);
    } catch (NoSuchTableException nste) {
      expandoTable = addTable(companyId, tableName);

      int i = 1;

      String fieldLabel = preferences.getValue("fieldLabel" + i, StringPool.BLANK);

      String fieldType = preferences.getValue("fieldType" + i, StringPool.BLANK);

      while ((i == 1) || (Validator.isNotNull(fieldLabel))) {
        if (!fieldType.equalsIgnoreCase("paragraph")) {
          ExpandoColumnLocalServiceUtil.addColumn(
              expandoTable.getTableId(), fieldLabel, ExpandoColumnConstants.STRING);
        }

        i++;

        fieldLabel = preferences.getValue("fieldLabel" + i, StringPool.BLANK);
      }

      ExpandoColumnLocalServiceUtil.addColumn(
          expandoTable.getTableId(), "userId", ExpandoColumnConstants.STRING);
    }

    return expandoTable;
  }
  public static ExpandoColumn addUserExpandoColumn(long companyId, String name, int type)
      throws PortalException, SystemException {

    long tableId = ExpandoUtil.getExpandoTableId(companyId, User.class.getName());

    ExpandoColumn column = ExpandoColumnLocalServiceUtil.getColumn(tableId, name);

    if (column == null) column = ExpandoColumnLocalServiceUtil.addColumn(tableId, name, type);

    return column;
  }
  public void addExpando(Element element, String path, ClassedModel classedModel)
      throws PortalException, SystemException {

    Class<?> clazz = classedModel.getModelClass();

    String className = clazz.getName();

    if (!_expandoColumnsMap.containsKey(className)) {
      List<ExpandoColumn> expandoColumns =
          ExpandoColumnLocalServiceUtil.getDefaultTableColumns(_companyId, className);

      for (ExpandoColumn expandoColumn : expandoColumns) {
        addPermissions(ExpandoColumn.class, expandoColumn.getColumnId());
      }

      _expandoColumnsMap.put(className, expandoColumns);
    }

    ExpandoBridge expandoBridge = classedModel.getExpandoBridge();

    Map<String, Serializable> expandoBridgeAttributes = expandoBridge.getAttributes();

    if (!expandoBridgeAttributes.isEmpty()) {
      String expandoPath = getExpandoPath(path);

      element.addAttribute("expando-path", expandoPath);

      addZipEntry(expandoPath, expandoBridgeAttributes);
    }
  }
  static void ensureUserCustomFieldExists(
      com.liferay.portal.model.User liferayUser, PortletRequest request)
      throws PortalException, SystemException {
    ExpandoBridge exp = liferayUser.getExpandoBridge();
    if (!exp.hasAttribute(CUSTOM_FIELD_PROJECT_GROUP_FILTER)) {
      exp.addAttribute(CUSTOM_FIELD_PROJECT_GROUP_FILTER, ExpandoColumnConstants.STRING, false);
      long companyId = liferayUser.getCompanyId();

      ExpandoColumn column =
          ExpandoColumnLocalServiceUtil.getColumn(
              companyId,
              exp.getClassName(),
              ExpandoTableConstants.DEFAULT_TABLE_NAME,
              CUSTOM_FIELD_PROJECT_GROUP_FILTER);

      String[] roleNames = new String[] {RoleConstants.USER, RoleConstants.POWER_USER};
      for (String roleName : roleNames) {
        Role role = RoleLocalServiceUtil.getRole(companyId, roleName);
        if (role != null && column != null) {
          ResourcePermissionLocalServiceUtil.setResourcePermissions(
              companyId,
              ExpandoColumn.class.getName(),
              ResourceConstants.SCOPE_INDIVIDUAL,
              String.valueOf(column.getColumnId()),
              role.getRoleId(),
              new String[] {ActionKeys.VIEW, ActionKeys.UPDATE});
        }
      }
    }
  }
示例#5
0
  protected void updateMPExpandoColumns(long companyId) throws Exception {
    ExpandoTable expandoTable = null;

    try {
      expandoTable = ExpandoTableLocalServiceUtil.getTable(companyId, User.class.getName(), "MP");
    } catch (NoSuchTableException nste) {
      return;
    }

    ExpandoColumn oldExpandoColumn =
        ExpandoColumnLocalServiceUtil.getColumn(
            companyId, User.class.getName(), expandoTable.getName(), "client-id");

    if (oldExpandoColumn == null) {
      return;
    }

    ExpandoColumn newExpandoColumn =
        ExpandoColumnLocalServiceUtil.getColumn(
            companyId, User.class.getName(), expandoTable.getName(), "clientId");

    if (newExpandoColumn == null) {
      newExpandoColumn =
          ExpandoColumnLocalServiceUtil.updateColumn(
              oldExpandoColumn.getColumnId(), "clientId", ExpandoColumnConstants.STRING);
    }

    List<ExpandoValue> expandoValues =
        ExpandoValueLocalServiceUtil.getColumnValues(
            oldExpandoColumn.getColumnId(), QueryUtil.ALL_POS, QueryUtil.ALL_POS);

    for (ExpandoValue expandoValue : expandoValues) {
      ExpandoValueLocalServiceUtil.addValue(
          expandoValue.getCompanyId(), User.class.getName(),
          expandoTable.getName(), newExpandoColumn.getName(),
          expandoValue.getClassPK(), expandoValue.getString());
    }

    ExpandoColumnLocalServiceUtil.deleteColumn(oldExpandoColumn.getColumnId());
  }
  @Before
  @Override
  public void setUp() throws Exception {
    super.setUp();

    SimpleAction simpleAction = new AddDefaultDocumentLibraryStructuresAction();

    String companyIdString = String.valueOf(TestPropsValues.getCompanyId());

    simpleAction.run(new String[] {companyIdString});

    List<DLFileEntryType> dlFileEntryTypes =
        DLFileEntryTypeLocalServiceUtil.getFileEntryTypes(
            PortalUtil.getCurrentAndAncestorSiteGroupIds(group.getGroupId()));

    for (DLFileEntryType dlFileEntryType : dlFileEntryTypes) {
      String name = dlFileEntryType.getName(LocaleUtil.getSiteDefault());

      if (name.equals(DLFileEntryTypeConstants.NAME_CONTRACT)) {
        _contractDLFileEntryTypeId = dlFileEntryType.getFileEntryTypeId();
      }
    }

    ExpandoTable expandoTable =
        ExpandoTableLocalServiceUtil.addDefaultTable(
            PortalUtil.getDefaultCompanyId(), DLFileEntry.class.getName());

    ExpandoColumnLocalServiceUtil.addColumn(
        expandoTable.getTableId(),
        _EXPANDO_ATTRIBUTE_NAME,
        ExpandoColumnConstants.STRING,
        StringPool.BLANK);

    _serviceContext = getServiceContext();

    FileEntry fileEntry =
        DLAppServiceUtil.addFileEntry(
            group.getGroupId(),
            parentFolder.getFolderId(),
            _SOURCE_FILE_NAME,
            ContentTypes.APPLICATION_OCTET_STREAM,
            _TITLE,
            StringPool.BLANK,
            StringPool.BLANK,
            _DATA_VERSION_1,
            _serviceContext);

    _fileVersion =
        DLFileVersionLocalServiceUtil.getFileVersion(
            fileEntry.getFileEntryId(), DLFileEntryConstants.VERSION_DEFAULT);
  }
  protected void doRun(long companyId) throws Exception {
    ExpandoTable table = null;

    try {
      table = ExpandoTableLocalServiceUtil.addTable(companyId, User.class.getName(), "MP");
    } catch (DuplicateTableNameException dtne) {
      table = ExpandoTableLocalServiceUtil.getTable(companyId, User.class.getName(), "MP");
    }

    try {
      ExpandoColumnLocalServiceUtil.addColumn(
          table.getTableId(), "client-id", ExpandoColumnConstants.STRING);
    } catch (DuplicateColumnNameException dcne) {
    }
  }
  @Test
  public void testActionableDynamicQuery() throws Exception {
    final IntegerWrapper count = new IntegerWrapper();

    ActionableDynamicQuery actionableDynamicQuery =
        ExpandoColumnLocalServiceUtil.getActionableDynamicQuery();

    actionableDynamicQuery.setPerformActionMethod(
        new ActionableDynamicQuery.PerformActionMethod() {
          @Override
          public void performAction(Object object) {
            ExpandoColumn expandoColumn = (ExpandoColumn) object;

            Assert.assertNotNull(expandoColumn);

            count.increment();
          }
        });

    actionableDynamicQuery.performActions();

    Assert.assertEquals(count.getValue(), _persistence.countAll());
  }
  protected void readExpandoTables(PortletDataContext portletDataContext) throws Exception {

    String xml =
        portletDataContext.getZipEntryAsString(
            portletDataContext.getSourceRootPath() + "/expando-tables.xml");

    if (xml == null) {
      return;
    }

    Document document = SAXReaderUtil.read(xml);

    Element rootElement = document.getRootElement();

    List<Element> expandoTableElements = rootElement.elements("expando-table");

    for (Element expandoTableElement : expandoTableElements) {
      String className = expandoTableElement.attributeValue("class-name");

      ExpandoTable expandoTable = null;

      try {
        expandoTable =
            ExpandoTableLocalServiceUtil.getDefaultTable(
                portletDataContext.getCompanyId(), className);
      } catch (NoSuchTableException nste) {
        expandoTable =
            ExpandoTableLocalServiceUtil.addDefaultTable(
                portletDataContext.getCompanyId(), className);
      }

      List<Element> expandoColumnElements = expandoTableElement.elements("expando-column");

      for (Element expandoColumnElement : expandoColumnElements) {
        long columnId = GetterUtil.getLong(expandoColumnElement.attributeValue("column-id"));
        String name = expandoColumnElement.attributeValue("name");
        int type = GetterUtil.getInteger(expandoColumnElement.attributeValue("type"));
        String defaultData = expandoColumnElement.elementText("default-data");
        String typeSettings = expandoColumnElement.elementText("type-settings");

        Serializable defaultDataObject =
            ExpandoConverterUtil.getAttributeFromString(type, defaultData);

        ExpandoColumn expandoColumn = null;

        try {
          expandoColumn = ExpandoColumnLocalServiceUtil.getColumn(expandoTable.getTableId(), name);

          ExpandoColumnLocalServiceUtil.updateColumn(
              expandoColumn.getColumnId(), name, type, defaultDataObject);
        } catch (NoSuchColumnException nsce) {
          expandoColumn =
              ExpandoColumnLocalServiceUtil.addColumn(
                  expandoTable.getTableId(), name, type, defaultDataObject);
        }

        ExpandoColumnLocalServiceUtil.updateTypeSettings(expandoColumn.getColumnId(), typeSettings);

        portletDataContext.importPermissions(
            ExpandoColumn.class, columnId, expandoColumn.getColumnId());
      }
    }
  }