Пример #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;
  }
  protected void validate(long companyId, long tableId, long classNameId, String name)
      throws PortalException, SystemException {

    if (Validator.isNull(name)) {
      throw new TableNameException();
    }

    ExpandoTable table = expandoTablePersistence.fetchByC_C_N(companyId, classNameId, name);

    if ((table != null) && (table.getTableId() != tableId)) {
      throw new DuplicateTableNameException();
    }
  }
  @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);
  }
  public void deleteTable(ExpandoTable table) throws SystemException {

    // Table

    expandoTablePersistence.remove(table);

    // Columns

    runSQL("delete from ExpandoColumn where tableId = " + table.getTableId());

    expandoColumnPersistence.clearCache();

    // Rows

    runSQL("delete from ExpandoRow where tableId = " + table.getTableId());

    expandoRowPersistence.clearCache();

    // Values

    runSQL("delete from ExpandoValue where tableId = " + table.getTableId());

    expandoValuePersistence.clearCache();
  }
Пример #5
0
  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) {
    }
  }
  public static long getExpandoTableId(long companyId, String className)
      throws PortalException, SystemException {
    ExpandoTable exandoTable = null;
    long tableId = 0l;

    try {
      exandoTable =
          ExpandoTableLocalServiceUtil.getTable(
              companyId, className, ExpandoTableConstants.DEFAULT_TABLE_NAME);
    } catch (Exception ex) {
    }

    if (exandoTable == null) {
      exandoTable =
          ExpandoTableLocalServiceUtil.addTable(
              companyId, className, ExpandoTableConstants.DEFAULT_TABLE_NAME);
    }

    tableId = exandoTable.getTableId();
    return tableId;
  }
Пример #7
0
  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());
      }
    }
  }