Created
November 19, 2013 18:33
-
-
Save pseudorandoom/7550129 to your computer and use it in GitHub Desktop.
From http://www.liferay.com/community/wiki/-/wiki/Main/Developing+with+Expando
liferay crear y settear expandos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void setExpandoAttributesAndValues( | |
Set<ExpandoItem> incomingExpandoSet, long companyId, | |
long classPKId, Class klass, ExpandoBridge expandoBridge, boolean indexable) | |
throws PortalException, SystemException { | |
ExpandoTable tbl = null; | |
CompanyThreadLocal.setCompanyId(companyId); | |
try { | |
tbl = ExpandoTableLocalServiceUtil.getDefaultTable(klass.getName()); | |
} catch (NoSuchTableException e) { | |
tbl = ExpandoTableLocalServiceUtil.addDefaultTable(klass.getName()); | |
} finally { | |
if (tbl == null) { | |
throw new SystemException("Could not get/create expando table"); | |
} | |
} | |
for (ExpandoItem item : incomingExpandoSet) { | |
String itemName = item.getName(); | |
int itemType = item.getType(); | |
ExpandoColumn col = ExpandoColumnLocalServiceUtil.getColumn(tbl | |
.getTableId(), itemName); | |
if (null == col) { | |
col = ExpandoColumnLocalServiceUtil.addColumn(tbl.getTableId(), | |
itemName, itemType); | |
} | |
UnicodeProperties properties = expandoBridge | |
.getAttributeProperties(col.getName()); | |
properties.setProperty(ExpandoBridgeIndexer.INDEXABLE, Boolean.valueOf(indexable) | |
.toString()); | |
col.setTypeSettingsProperties(properties); | |
ExpandoValue val = null; | |
if (item.isArray()) { | |
Serializable[] itemValue = (Serializable[]) item | |
.getArrayValue(); | |
val = ExpandoValueLocalServiceUtil.addValue(klass.getName(), | |
tbl.getName(), col.getName(), classPKId, itemValue); | |
} else { | |
Serializable itemValue = (Serializable) item.getValue(); | |
val = ExpandoValueLocalServiceUtil.addValue(klass.getName(), | |
tbl.getName(), col.getName(), classPKId, itemValue); | |
} | |
if (val == null) { | |
throw new SystemException( | |
"Could not add expando value: class: " | |
+ klass.getName() + ", table: " + tbl.getName() | |
+ ", column: " + col.getName() + " classPKId: " | |
+ classPKId); | |
} | |
} | |
reIndex(indexable, klass.getName(), classPKId); | |
} | |
/** | |
* Reindex the journal article | |
* @param isIndexEnabled (for the journal article) | |
* @param className | |
* @param classPK | |
*/ | |
void reIndex(boolean isIndexEnabled, String className, long classPK) { | |
if (!isIndexEnabled) { | |
return; | |
} | |
Indexer indexer = IndexerRegistryUtil.getIndexer(className); | |
if (indexer != null) { | |
try { | |
indexer.reIndex(className, classPK); | |
} catch (Exception e) { | |
logger.error("reindex journal article error", e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment