protected void doAddAttributes(Document document, ExpandoBridge expandoBridge) { List<ExpandoColumn> expandoColumns = ExpandoColumnLocalServiceUtil.getDefaultTableColumns( expandoBridge.getCompanyId(), expandoBridge.getClassName()); if ((expandoColumns == null) || expandoColumns.isEmpty()) { return; } List<ExpandoColumn> indexedColumns = new ArrayList<>(); for (ExpandoColumn expandoColumn : expandoColumns) { UnicodeProperties properties = expandoColumn.getTypeSettingsProperties(); int indexType = GetterUtil.getInteger(properties.get(ExpandoColumnConstants.INDEX_TYPE)); if (indexType != ExpandoColumnConstants.INDEX_TYPE_NONE) { indexedColumns.add(expandoColumn); } } if (indexedColumns.isEmpty()) { return; } List<ExpandoValue> expandoValues = ExpandoValueLocalServiceUtil.getRowValues( expandoBridge.getCompanyId(), expandoBridge.getClassName(), ExpandoTableConstants.DEFAULT_TABLE_NAME, expandoBridge.getClassPK(), QueryUtil.ALL_POS, QueryUtil.ALL_POS); for (ExpandoColumn expandoColumn : indexedColumns) { try { addAttribute(document, expandoColumn, expandoValues); } catch (Exception e) { _log.error("Indexing " + expandoColumn.getName(), 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()); } } } }