Exemplo n.º 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 ExpandoTable updateTable(long tableId, String name)
      throws PortalException, SystemException {

    ExpandoTable table = expandoTablePersistence.findByPrimaryKey(tableId);

    if (table.getName().equals(ExpandoTableConstants.DEFAULT_TABLE_NAME)) {
      throw new TableNameException("Cannot rename " + ExpandoTableConstants.DEFAULT_TABLE_NAME);
    }

    validate(table.getCompanyId(), tableId, table.getClassNameId(), name);

    table.setName(name);

    return expandoTablePersistence.update(table);
  }
Exemplo n.º 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 ExpandoTable addTable(long companyId, long classNameId, String name)
      throws PortalException, SystemException {

    validate(companyId, 0, classNameId, name);

    long tableId = counterLocalService.increment();

    ExpandoTable table = expandoTablePersistence.create(tableId);

    table.setCompanyId(companyId);
    table.setClassNameId(classNameId);
    table.setName(name);

    expandoTablePersistence.update(table);

    return table;
  }
  @Override
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }

    if (!(obj instanceof ExpandoTable)) {
      return false;
    }

    ExpandoTable expandoTable = (ExpandoTable) obj;

    long primaryKey = expandoTable.getPrimaryKey();

    if (getPrimaryKey() == primaryKey) {
      return true;
    } else {
      return false;
    }
  }
  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;
  }
  @Override
  public int compareTo(ExpandoTable expandoTable) {
    long primaryKey = expandoTable.getPrimaryKey();

    if (getPrimaryKey() < primaryKey) {
      return -1;
    } else if (getPrimaryKey() > primaryKey) {
      return 1;
    } else {
      return 0;
    }
  }
Exemplo n.º 10
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());
  }
  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();
  }
Exemplo n.º 12
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());
      }
    }
  }