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