|
12 | 12 | */
|
13 | 13 | public final class IndexingPolicy extends JsonSerializable {
|
14 | 14 |
|
| 15 | + private static final String DEFAULT_PATH = "/*"; |
| 16 | + |
| 17 | + private Collection<IncludedPath> includedPaths; |
| 18 | + private Collection<ExcludedPath> excludedPaths; |
| 19 | + |
15 | 20 | /**
|
16 | 21 | * Constructor.
|
17 | 22 | */
|
@@ -86,63 +91,70 @@ public IndexingMode getIndexingMode() {
|
86 | 91 | return result;
|
87 | 92 | }
|
88 | 93 |
|
89 |
| - /** |
90 |
| - * Gets or sets the path level configurations for indexing. |
91 |
| - */ |
92 |
| - private Collection<IndexingPath> included; |
93 |
| - private Collection<String> excluded; |
94 |
| - |
95 |
| - |
96 | 94 | /**
|
97 | 95 | * Gets the paths that are chosen to be indexed by the user.
|
98 | 96 | *
|
99 | 97 | * @return the included paths.
|
100 | 98 | */
|
101 |
| - public Collection<IndexingPath> getIncludedPaths() { |
102 |
| - if (this.included == null) { |
103 |
| - this.included = super.getCollection(Constants.Properties.INCLUDED_PATHS, IndexingPath.class); |
| 99 | + public Collection<IncludedPath> getIncludedPaths() { |
| 100 | + if (this.includedPaths == null) { |
| 101 | + this.includedPaths = super.getCollection(Constants.Properties.INCLUDED_PATHS, IncludedPath.class); |
104 | 102 |
|
105 |
| - if (this.included == null) { |
106 |
| - this.included = new ArrayList<IndexingPath>(); |
| 103 | + if (this.includedPaths == null) { |
| 104 | + this.includedPaths = new ArrayList<IncludedPath>(); |
107 | 105 | }
|
108 | 106 | }
|
109 | 107 |
|
110 |
| - return this.included; |
| 108 | + return this.includedPaths; |
| 109 | + } |
| 110 | + |
| 111 | + public void setIncludedPaths(Collection<IncludedPath> includedPaths) { |
| 112 | + this.includedPaths = includedPaths; |
111 | 113 | }
|
112 |
| - |
| 114 | + |
113 | 115 | /**
|
114 | 116 | * Gets the paths that are not indexed.
|
115 | 117 | *
|
116 | 118 | * @return the excluded paths.
|
117 | 119 | */
|
118 |
| - public Collection<String> getExcludedPaths() { |
119 |
| - if (this.excluded == null) { |
120 |
| - this.excluded = super.getCollection(Constants.Properties.EXCLUDED_PATHS, String.class); |
| 120 | + public Collection<ExcludedPath> getExcludedPaths() { |
| 121 | + if (this.excludedPaths == null) { |
| 122 | + this.excludedPaths = super.getCollection(Constants.Properties.EXCLUDED_PATHS, ExcludedPath.class); |
121 | 123 |
|
122 |
| - if (this.excluded == null) { |
123 |
| - this.excluded = new ArrayList<String>(); |
| 124 | + if (this.excludedPaths == null) { |
| 125 | + this.excludedPaths = new ArrayList<ExcludedPath>(); |
124 | 126 | }
|
125 | 127 | }
|
126 | 128 |
|
127 |
| - return this.excluded; |
| 129 | + return this.excludedPaths; |
| 130 | + } |
| 131 | + |
| 132 | + public void setExcludedPaths(Collection<ExcludedPath> excludedPaths) { |
| 133 | + this.excludedPaths = excludedPaths; |
128 | 134 | }
|
129 | 135 |
|
130 | 136 | @Override
|
131 | 137 | void onSave() {
|
132 |
| - boolean bDefaultPaths = (this.included != null && this.included.size() == 0 && |
133 |
| - this.excluded != null && this.excluded.size() == 0); |
134 |
| - |
135 |
| - // If we do not have any user-specified paths, do not serialize. |
136 |
| - // If we don't do this, included and excluded will be sent as empty lists [], [] which have a different meaning |
137 |
| - // on server. |
138 |
| - if (bDefaultPaths) return; |
| 138 | + // If indexing mode is not 'none' and not paths are set, set them to the defaults |
| 139 | + if (this.getIndexingMode() != IndexingMode.None && this.getIncludedPaths().size() == 0 && |
| 140 | + this.getExcludedPaths().size() == 0) { |
| 141 | + IncludedPath includedPath = new IncludedPath(); |
| 142 | + includedPath.setPath(IndexingPolicy.DEFAULT_PATH); |
| 143 | + this.getIncludedPaths().add(includedPath); |
| 144 | + } |
139 | 145 |
|
140 |
| - if (this.included != null) { |
141 |
| - super.set(Constants.Properties.INCLUDED_PATHS, this.included); |
| 146 | + if (this.includedPaths != null) { |
| 147 | + for (IncludedPath includedPath : this.includedPaths) { |
| 148 | + includedPath.onSave(); |
| 149 | + } |
| 150 | + super.set(Constants.Properties.INCLUDED_PATHS, this.includedPaths); |
142 | 151 | }
|
143 | 152 |
|
144 |
| - if (this.excluded != null) { |
145 |
| - super.set(Constants.Properties.EXCLUDED_PATHS, this.excluded); |
| 153 | + if (this.excludedPaths != null) { |
| 154 | + for (ExcludedPath excludedPath : this.excludedPaths) { |
| 155 | + excludedPath.onSave(); |
| 156 | + } |
| 157 | + super.set(Constants.Properties.EXCLUDED_PATHS, this.excludedPaths); |
146 | 158 | }
|
147 | 159 | }
|
148 | 160 | }
|
0 commit comments