Revision 7602
Added by Jing Tao over 11 years ago
metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/SystemMetadataEventListener.java | ||
---|---|---|
29 | 29 |
import java.io.FileInputStream; |
30 | 30 |
import java.io.FileNotFoundException; |
31 | 31 |
import java.io.InputStream; |
32 |
import java.util.ArrayList; |
|
33 |
import java.util.List; |
|
32 | 34 |
|
33 | 35 |
import org.apache.commons.logging.Log; |
34 | 36 |
import org.apache.commons.logging.LogFactory; |
... | ... | |
148 | 150 |
log.info("stopping index entry listener..."); |
149 | 151 |
this.systemMetadataMap.removeEntryListener(this); |
150 | 152 |
} |
153 |
|
|
154 |
/** |
|
155 |
* Get the SystemMetadata for the specified id from the distributed Map. |
|
156 |
* The null maybe is returned if there is no system metadata found. |
|
157 |
* @param id the specified id. |
|
158 |
* @return the SystemMetadata associated with the id. |
|
159 |
*/ |
|
160 |
public SystemMetadata getSystemMetadata(String id) { |
|
161 |
SystemMetadata metadata = null; |
|
162 |
if(systemMetadataMap != null && id != null) { |
|
163 |
metadata = systemMetadataMap.get(id); |
|
164 |
} |
|
165 |
return metadata; |
|
166 |
} |
|
167 |
|
|
168 |
/** |
|
169 |
* Get the obsoletes chain of the specified id. The returned list doesn't include |
|
170 |
* the specified id itself. The newer version has the lower index number in the list. |
|
171 |
* Empty list will be returned if there is no document to be obsoleted by this id. |
|
172 |
* @param id |
|
173 |
* @return |
|
174 |
*/ |
|
175 |
public List<String> getObsoletes(String id) { |
|
176 |
List<String> obsoletes = new ArrayList<String>(); |
|
177 |
while (id != null) { |
|
178 |
SystemMetadata metadata = getSystemMetadata(id); |
|
179 |
id = null;//set it to be null in order to stop the while loop if the id can't be assinged to a new value in the following code. |
|
180 |
if(metadata != null) { |
|
181 |
Identifier identifier = metadata.getObsoletes(); |
|
182 |
if(identifier != null && identifier.getValue() != null && !identifier.getValue().trim().equals("")) { |
|
183 |
obsoletes.add(identifier.getValue()); |
|
184 |
id = identifier.getValue(); |
|
185 |
} |
|
186 |
} |
|
187 |
} |
|
188 |
return obsoletes; |
|
189 |
} |
|
151 | 190 |
|
152 | 191 |
public void entryAdded(EntryEvent<Identifier, SystemMetadata> entryEvent) { |
153 | 192 |
// use the same implementation for insert/update for now |
Also available in: Unified diff
Add the getSystemMetadata and getObsoletes methods.