Project

General

Profile

« Previous | Next » 

Revision 7785

Added by Jing Tao over 11 years ago

Add two static methods to get the SystemMetadata and data object InputStream for the specified id.

View differences:

metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/DistributedMapsFactory.java
26 26
 */
27 27
package edu.ucsb.nceas.metacat.index;
28 28

  
29
import java.io.FileInputStream;
29 30
import java.io.FileNotFoundException;
31
import java.io.InputStream;
30 32

  
31 33
import org.apache.commons.logging.Log;
32 34
import org.apache.commons.logging.LogFactory;
......
56 58
    private static String hzObjectPath = null;
57 59
    private static int waitingTime = IndexGenerator.WAITTIME;
58 60
    private static int maxAttempts = IndexGenerator.MAXWAITNUMBER;
61
    private static IMap<Identifier, SystemMetadata> systemMetadataMap = null;
62
    private static IMap<Identifier, String> objectPathMap = null;
59 63
    
60 64
    /*
61 65
     * Start the hazel cast client
......
140 144
        if(hzClient == null) {
141 145
            startHazelCastClient();
142 146
        }
143
        return hzClient.getMap(hzSystemMetadata);
147
        systemMetadataMap = hzClient.getMap(hzSystemMetadata);
148
        return systemMetadataMap;
144 149
    }
145 150
    
146 151
    /**
......
153 158
        if(hzClient == null) {
154 159
            startHazelCastClient();
155 160
        }
156
        return hzClient.getMap(hzObjectPath);
161
        objectPathMap = hzClient.getMap(hzObjectPath);
162
        return objectPathMap;
157 163
    }
158 164
    
165
    /**
166
     * Get the SystemMetadata for the specified id. The null will be returned if there is no SystemMetadata found for this id
167
     * @param id the specified id.
168
     * @return the SystemMetadata for the id
169
     * @throws FileNotFoundException
170
     * @throws ServiceFailure
171
     */
172
    public static SystemMetadata getSystemMetadata(String id) throws FileNotFoundException, ServiceFailure {
173
        if(systemMetadataMap == null) {
174
            getSystemMetadataMap();
175
        }
176
        SystemMetadata metadata = null;
177
        if(systemMetadataMap != null && id != null) {
178
            Identifier identifier = new Identifier();
179
            identifier.setValue(id);
180
            metadata = systemMetadataMap.get(identifier);
181
        }
182
        return metadata;
183
    }
184
    
185
    /**
186
     * Get the DataObject for the specified id. The null will be returned if not data object is found.
187
     * @param id the specified id
188
     * @return the InputStream of the data object for the specified id.
189
     * @throws FileNotFoundException
190
     * @throws ServiceFailure
191
     */
192
    public static InputStream getDataObject(String id) throws FileNotFoundException, ServiceFailure {
193
        if(objectPathMap == null) {
194
            getObjectPathMap();
195
        }
196
        InputStream data = null;
197
        if(objectPathMap != null && id != null) {
198
            Identifier identifier = new Identifier();
199
            identifier.setValue(id);
200
            String objectPath = objectPathMap.get(identifier);
201
            if(objectPath != null) {
202
                data = new FileInputStream(objectPath);
203
            }
204
        }
205
        return data;
206
    }
207
    
159 208
}

Also available in: Unified diff