protected void readExpandoTables(PortletDataContext portletDataContext) throws Exception {

    String xml =
        portletDataContext.getZipEntryAsString(
            ExportImportPathUtil.getSourceRootPath(portletDataContext) + "/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 =
            _expandoTableLocalService.getDefaultTable(portletDataContext.getCompanyId(), className);
      } catch (NoSuchTableException nste) {
        expandoTable =
            _expandoTableLocalService.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 =
            _expandoColumnLocalService.getColumn(expandoTable.getTableId(), name);

        if (expandoColumn != null) {
          _expandoColumnLocalService.updateColumn(
              expandoColumn.getColumnId(), name, type, defaultDataObject);
        } else {
          expandoColumn =
              _expandoColumnLocalService.addColumn(
                  expandoTable.getTableId(), name, type, defaultDataObject);
        }

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

        portletDataContext.importPermissions(
            ExpandoColumn.class, columnId, expandoColumn.getColumnId());
      }
    }
  }
예제 #2
0
  protected void updateMPExpandoColumns(long companyId) throws Exception {
    try (LoggingTimer loggingTimer = new LoggingTimer(String.valueOf(companyId))) {

      ExpandoTable expandoTable = null;

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

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

      if (oldExpandoColumn == null) {
        return;
      }

      ExpandoColumn newExpandoColumn =
          _expandoColumnLocalService.getColumn(
              companyId, User.class.getName(), expandoTable.getName(), "clientID");

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

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

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

      _expandoColumnLocalService.deleteColumn(oldExpandoColumn.getColumnId());
    }
  }
  protected void deleteSocialOfficeLayoutSetPrototypes(long companyId) throws Exception {

    LayoutSetPrototype layoutSetPrototype =
        LayoutSetPrototypeUtil.fetchLayoutSetPrototype(
            companyId, SocialOfficeConstants.LAYOUT_SET_PROTOTYPE_KEY_SITE);

    if (layoutSetPrototype != null) {
      try {
        LayoutSetPrototypeLocalServiceUtil.deleteLayoutSetPrototype(layoutSetPrototype);
      } catch (Exception e) {
        _log.error(e, e);
      }
    }

    layoutSetPrototype =
        LayoutSetPrototypeUtil.fetchLayoutSetPrototype(
            companyId, SocialOfficeConstants.LAYOUT_SET_PROTOTYPE_KEY_USER_PRIVATE);

    if (layoutSetPrototype != null) {
      try {
        LayoutSetPrototypeLocalServiceUtil.deleteLayoutSetPrototype(layoutSetPrototype);
      } catch (Exception e) {
        _log.error(e, e);
      }
    }

    layoutSetPrototype =
        LayoutSetPrototypeUtil.fetchLayoutSetPrototype(
            companyId, SocialOfficeConstants.LAYOUT_SET_PROTOTYPE_KEY_USER_PUBLIC);

    if (layoutSetPrototype != null) {
      try {
        LayoutSetPrototypeLocalServiceUtil.deleteLayoutSetPrototype(layoutSetPrototype);
      } catch (Exception e) {
        _log.error(e, e);
      }
    }

    try {
      ExpandoColumn expandoColumn =
          ExpandoColumnLocalServiceUtil.getColumn(
              companyId,
              LayoutSetPrototype.class.getName(),
              ExpandoTableConstants.DEFAULT_TABLE_NAME,
              SocialOfficeConstants.LAYOUT_SET_PROTOTYPE_KEY);

      ExpandoValueLocalServiceUtil.deleteColumnValues(expandoColumn.getColumnId());
    } catch (Exception e) {
      _log.error(e, e);
    }
  }
  protected void exportExpandoTables(PortletDataContext portletDataContext) throws Exception {

    Document document = SAXReaderUtil.createDocument();

    Element rootElement = document.addElement("expando-tables");

    Map<String, List<ExpandoColumn>> expandoColumnsMap = portletDataContext.getExpandoColumns();

    for (Map.Entry<String, List<ExpandoColumn>> entry : expandoColumnsMap.entrySet()) {

      String className = entry.getKey();

      Element expandoTableElement = rootElement.addElement("expando-table");

      expandoTableElement.addAttribute("class-name", className);

      List<ExpandoColumn> expandoColumns = entry.getValue();

      for (ExpandoColumn expandoColumn : expandoColumns) {
        Element expandoColumnElement = expandoTableElement.addElement("expando-column");

        expandoColumnElement.addAttribute("column-id", String.valueOf(expandoColumn.getColumnId()));
        expandoColumnElement.addAttribute("name", expandoColumn.getName());
        expandoColumnElement.addAttribute("type", String.valueOf(expandoColumn.getType()));

        DocUtil.add(expandoColumnElement, "default-data", expandoColumn.getDefaultData());

        Element typeSettingsElement = expandoColumnElement.addElement("type-settings");

        UnicodeProperties typeSettingsProperties = expandoColumn.getTypeSettingsProperties();

        typeSettingsElement.addCDATA(typeSettingsProperties.toString());
      }
    }

    portletDataContext.addZipEntry(
        ExportImportPathUtil.getRootPath(portletDataContext) + "/expando-tables.xml",
        document.formattedString());
  }
  protected void addAttribute(
      Document document, ExpandoColumn expandoColumn, List<ExpandoValue> expandoValues)
      throws PortalException {

    UnicodeProperties unicodeProperties = expandoColumn.getTypeSettingsProperties();

    int indexType =
        GetterUtil.getInteger(unicodeProperties.getProperty(ExpandoColumnConstants.INDEX_TYPE));

    String fieldName = encodeFieldName(expandoColumn.getName(), indexType);

    ExpandoValue expandoValue = new ExpandoValueImpl();

    expandoValue.setColumnId(expandoColumn.getColumnId());
    expandoValue.setData(expandoColumn.getDefaultData());

    boolean defaultValue = true;

    for (ExpandoValue curExpandoValue : expandoValues) {
      if (curExpandoValue.getColumnId() == expandoColumn.getColumnId()) {
        expandoValue = curExpandoValue;

        defaultValue = false;

        break;
      }
    }

    int type = expandoColumn.getType();

    if (type == ExpandoColumnConstants.BOOLEAN) {
      document.addKeyword(fieldName, expandoValue.getBoolean());
    } else if (type == ExpandoColumnConstants.BOOLEAN_ARRAY) {
      if (!defaultValue) {
        document.addKeyword(fieldName, expandoValue.getBooleanArray());
      } else {
        document.addKeyword(fieldName, new boolean[0]);
      }
    } else if (type == ExpandoColumnConstants.DATE) {
      document.addDate(fieldName, expandoValue.getDate());
    } else if (type == ExpandoColumnConstants.DOUBLE) {
      document.addKeyword(fieldName, expandoValue.getDouble());
    } else if (type == ExpandoColumnConstants.DOUBLE_ARRAY) {
      if (!defaultValue) {
        document.addKeyword(fieldName, expandoValue.getDoubleArray());
      } else {
        document.addKeyword(fieldName, new double[0]);
      }
    } else if (type == ExpandoColumnConstants.FLOAT) {
      document.addKeyword(fieldName, expandoValue.getFloat());
    } else if (type == ExpandoColumnConstants.FLOAT_ARRAY) {
      if (!defaultValue) {
        document.addKeyword(fieldName, expandoValue.getFloatArray());
      } else {
        document.addKeyword(fieldName, new float[0]);
      }
    } else if (type == ExpandoColumnConstants.INTEGER) {
      document.addKeyword(fieldName, expandoValue.getInteger());
    } else if (type == ExpandoColumnConstants.INTEGER_ARRAY) {
      if (!defaultValue) {
        document.addKeyword(fieldName, expandoValue.getIntegerArray());
      } else {
        document.addKeyword(fieldName, new int[0]);
      }
    } else if (type == ExpandoColumnConstants.LONG) {
      document.addKeyword(fieldName, expandoValue.getLong());
    } else if (type == ExpandoColumnConstants.LONG_ARRAY) {
      if (!defaultValue) {
        document.addKeyword(fieldName, expandoValue.getLongArray());
      } else {
        document.addKeyword(fieldName, new long[0]);
      }
    } else if (type == ExpandoColumnConstants.NUMBER) {
      document.addKeyword(fieldName, expandoValue.getNumber().toString());
    } else if (type == ExpandoColumnConstants.NUMBER_ARRAY) {
      if (!defaultValue) {
        document.addKeyword(fieldName, ArrayUtil.toStringArray(expandoValue.getNumberArray()));
      } else {
        document.addKeyword(fieldName, new long[0]);
      }
    } else if (type == ExpandoColumnConstants.SHORT) {
      document.addKeyword(fieldName, expandoValue.getShort());
    } else if (type == ExpandoColumnConstants.SHORT_ARRAY) {
      if (!defaultValue) {
        document.addKeyword(fieldName, expandoValue.getShortArray());
      } else {
        document.addKeyword(fieldName, new short[0]);
      }
    } else if (type == ExpandoColumnConstants.STRING) {
      if (indexType == ExpandoColumnConstants.INDEX_TYPE_KEYWORD) {
        document.addKeyword(fieldName, expandoValue.getString());
      } else {
        document.addText(fieldName, expandoValue.getString());
      }
    } else if (type == ExpandoColumnConstants.STRING_ARRAY) {
      if (!defaultValue) {
        if (indexType == ExpandoColumnConstants.INDEX_TYPE_KEYWORD) {
          document.addKeyword(fieldName, expandoValue.getStringArray());
        } else {
          document.addText(
              fieldName, StringUtil.merge(expandoValue.getStringArray(), StringPool.SPACE));
        }
      } else {
        if (indexType == ExpandoColumnConstants.INDEX_TYPE_KEYWORD) {
          document.addKeyword(fieldName, StringPool.BLANK);
        } else {
          document.addText(fieldName, StringPool.BLANK);
        }
      }
    } else if (type == ExpandoColumnConstants.STRING_LOCALIZED) {
      if (!defaultValue) {
        if (indexType == ExpandoColumnConstants.INDEX_TYPE_KEYWORD) {
          document.addLocalizedKeyword(fieldName, expandoValue.getStringMap());
        } else {
          document.addLocalizedText(fieldName, expandoValue.getStringMap());
        }
      }
    }
  }