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()); }
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()); } } }