1
22
23 package com.liferay.portlet.expando.util;
24
25 import com.liferay.portal.SystemException;
26 import com.liferay.portal.kernel.dao.orm.QueryUtil;
27 import com.liferay.portal.kernel.log.Log;
28 import com.liferay.portal.kernel.log.LogFactoryUtil;
29 import com.liferay.portal.kernel.search.Document;
30 import com.liferay.portal.kernel.util.GetterUtil;
31 import com.liferay.portal.kernel.util.UnicodeProperties;
32 import com.liferay.portlet.expando.model.ExpandoBridge;
33 import com.liferay.portlet.expando.model.ExpandoColumn;
34 import com.liferay.portlet.expando.model.ExpandoTableConstants;
35 import com.liferay.portlet.expando.model.ExpandoValue;
36 import com.liferay.portlet.expando.service.ExpandoColumnLocalServiceUtil;
37 import com.liferay.portlet.expando.service.ExpandoValueLocalServiceUtil;
38
39 import java.util.ArrayList;
40 import java.util.List;
41
42
47 public class ExpandoBridgeIndexerImpl implements ExpandoBridgeIndexer {
48
49 public void addAttributes(Document doc, ExpandoBridge expandoBridge) {
50 if (expandoBridge == null) {
51 return;
52 }
53
54 try {
55 doAddAttributes(doc, expandoBridge);
56 }
57 catch (SystemException se) {
58 _log.error(se, se);
59 }
60 }
61
62 protected void doAddAttributes(Document doc, ExpandoBridge expandoBridge)
63 throws SystemException {
64
65 List<ExpandoColumn> expandoColumns =
66 ExpandoColumnLocalServiceUtil.getDefaultTableColumns(
67 expandoBridge.getClassName());
68
69 if ((expandoColumns == null) || expandoColumns.isEmpty()) {
70 return;
71 }
72
73 List<ExpandoColumn> indexedColumns = new ArrayList<ExpandoColumn>();
74
75 for (ExpandoColumn expandoColumn : expandoColumns) {
76 UnicodeProperties properties =
77 expandoColumn.getTypeSettingsProperties();
78
79 boolean indexable = GetterUtil.getBoolean(
80 properties.get(ExpandoBridgeIndexer.INDEXABLE));
81
82 if (indexable) {
83 indexedColumns.add(expandoColumn);
84 }
85 }
86
87 if (indexedColumns.isEmpty()) {
88 return;
89 }
90
91 List<ExpandoValue> expandoValues =
92 ExpandoValueLocalServiceUtil.getRowValues(
93 expandoBridge.getClassName(),
94 ExpandoTableConstants.DEFAULT_TABLE_NAME,
95 expandoBridge.getClassPK(), QueryUtil.ALL_POS,
96 QueryUtil.ALL_POS);
97
98 for (ExpandoColumn expandoColumn : indexedColumns) {
99 try {
100 String value = expandoColumn.getDefaultData();
101
102 for (ExpandoValue expandoValue : expandoValues) {
103 if (expandoValue.getColumnId() ==
104 expandoColumn.getColumnId()) {
105
106 value = expandoValue.getData();
107
108 break;
109 }
110 }
111
112 doc.addText(expandoColumn.getName(), value);
113 }
114 catch (Exception e) {
115 _log.error("Indexing " + expandoColumn.getName(), e);
116 }
117 }
118 }
119
120 private static Log _log =
121 LogFactoryUtil.getLog(ExpandoBridgeIndexerImpl.class);
122
123 }