Project

General

Profile

« Previous | Next » 

Revision 6590

Add support for the various CNReplication calls. Add collectReplicationPolicy() to parse the policy out of the multipart form, and collectReplicaMetadata() to parse out the replica to be updated.

View differences:

src/edu/ucsb/nceas/metacat/restservice/D1ResourceHandler.java
24 24

  
25 25
import java.io.File;
26 26
import java.io.FileInputStream;
27
import java.io.FileNotFoundException;
27 28
import java.io.IOException;
28 29
import java.io.InputStream;
29 30
import java.io.OutputStream;
......
50 51
import org.dataone.service.exceptions.InvalidRequest;
51 52
import org.dataone.service.exceptions.ServiceFailure;
52 53
import org.dataone.service.types.v1.AccessPolicy;
54
import org.dataone.service.types.v1.Replica;
55
import org.dataone.service.types.v1.ReplicationPolicy;
53 56
import org.dataone.service.types.v1.Session;
54 57
import org.dataone.service.types.v1.SystemMetadata;
55 58
import org.dataone.service.util.TypeMarshaller;
......
91 94
    protected static final String RESOURCE_IS_AUTHORIZED = "isAuthorized";
92 95
    protected static final String RESOURCE_ACCESS_RULES = "accessRules";
93 96

  
97
    
94 98
    /*
95 99
     * API Functions used as URL parameters
96 100
     */
......
162 166
        }
163 167
        return extra;
164 168
    }
169

  
170
    /**
171
     * Parse the replication policy document out of the mime-multipart form data
172
     * 
173
     * @return policy  the encoded policy
174
     * @throws ServiceFailure
175
     * @throws InvalidRequest
176
     * @throws IOException
177
     * @throws InstantiationException
178
     * @throws IllegalAccessException
179
     * @throws JiBXException
180
     */
181
    protected ReplicationPolicy collectReplicationPolicy() 
182
        throws ServiceFailure, InvalidRequest, IOException, InstantiationException, 
183
        IllegalAccessException, JiBXException {
184
        
185
        ReplicationPolicy policy = null;
186
        File tmpDir = getTempDirectory();
187
        MultipartRequest mr = null;
188
        Map<String, File> mmFileParts = null;
189
        File replPolicyFile = null;
190
        InputStream replPolicyStream = null;
191
        
192
        // Read the incoming data from its Mime Multipart encoding
193
        logMetacat.debug("Parsing ReplicationPolicy from the mime multipart entity");
194

  
195
        // handle MMP inputs
196
        MultipartRequestResolver mrr = 
197
            new MultipartRequestResolver(tmpDir.getAbsolutePath(),1000000000, 0);
198
        
199
        try {
200
            mr = mrr.resolveMultipart(request);
201
            logMetacat.debug("Resolved the ReplicationPolicy multipart request.");
202
            
203
        } catch (IOException e) {
204
            throw new ServiceFailure("4882", "Couldn't resolve the multipart request: " +
205
                e.getMessage());
206
            
207
        } catch (FileUploadException e) {
208
            throw new ServiceFailure("4882", "Couldn't resolve the multipart request: " +
209
                    e.getMessage());
210
            
211
        } catch (Exception e) {
212
            throw new ServiceFailure("4882", "Couldn't resolve the multipart request: " +
213
                    e.getMessage());
214
            
215
        }
216
        
217
        // get the map of file parts
218
        mmFileParts = mr.getMultipartFiles();
219
        
220
        if ( mmFileParts == null || mmFileParts.keySet() == null) {
221
            throw new InvalidRequest("4883", "The multipart request must include " +
222
                "a file with the name 'policy'.");
223
            
224
        }
225
        
226
        multipartparams = mr.getMultipartParameters();
227
        replPolicyFile = mmFileParts.get("policy");
228
        
229
        if ( replPolicyFile == null ) {
230
            throw new InvalidRequest("4883", "The multipart request must include " +
231
            "a file with the name 'policy'.");
232
            
233
        }
234
        
235
        
236
        // deserialize the ReplicationPolicy
237
        replPolicyStream = new FileInputStream(replPolicyFile);
238
        policy = TypeMarshaller.unmarshalTypeFromStream(ReplicationPolicy.class, replPolicyStream);
239
        
240
        return policy;
241
        
242
    }
243

  
244
    /**
245
     * Parse the replica metadata document out of the mime-multipart form data
246
     * 
247
     * @return replica  the encoded replica
248
     * @throws ServiceFailure
249
     * @throws InvalidRequest
250
     * @throws IOException
251
     * @throws InstantiationException
252
     * @throws IllegalAccessException
253
     * @throws JiBXException
254
     */
255
    protected Replica collectReplicaMetadata() 
256
        throws ServiceFailure, InvalidRequest {
257
        
258
        Replica replica = null;
259
        File tmpDir = getTempDirectory();
260
        MultipartRequest mr = null;
261
        Map<String, File> mmFileParts = null;
262
        File replicaFile = null;
263
        InputStream replicaStream = null;
264
        
265
        // Read the incoming data from its Mime Multipart encoding
266
        logMetacat.debug("Parsing Replica from the mime multipart entity");
267

  
268
        // handle MMP inputs
269
        MultipartRequestResolver mrr = 
270
            new MultipartRequestResolver(tmpDir.getAbsolutePath(),1000000000, 0);
271
        
272
        try {
273
            mr = mrr.resolveMultipart(request);
274
            logMetacat.debug("Resolved the Replica multipart request.");
275
            
276
        } catch (IOException e) {
277
            throw new ServiceFailure("4852", "Couldn't resolve the multipart request: " +
278
                e.getMessage());
279
            
280
        } catch (FileUploadException e) {
281
            throw new ServiceFailure("4852", "Couldn't resolve the multipart request: " +
282
                    e.getMessage());
283
            
284
        } catch (Exception e) {
285
            throw new ServiceFailure("4852", "Couldn't resolve the multipart request: " +
286
                    e.getMessage());
287
            
288
        }
289
        
290
        // get the map of file parts
291
        mmFileParts = mr.getMultipartFiles();
292
        
293
        if ( mmFileParts == null || mmFileParts.keySet() == null) {
294
            throw new InvalidRequest("4853", "The multipart request must include " +
295
                "a file with the name 'replicaMetadata'.");
296
            
297
        }
298
        
299
        multipartparams = mr.getMultipartParameters();
300
        replicaFile = mmFileParts.get("replicaMetadata");
301
        
302
        if ( replicaFile == null ) {
303
            throw new InvalidRequest("4853", "The multipart request must include " +
304
            "a file with the name 'replicaMetadata'.");
305
            
306
        }
307
        
308
        
309
        // deserialize the ReplicationPolicy
310
        try {
311
            replicaStream = new FileInputStream(replicaFile);
312
        } catch (FileNotFoundException e) {
313
            throw new ServiceFailure("4852", "Couldn't find the multipart file: " +
314
                    e.getMessage());
315
            
316
        }
317
        
318
        try {
319
            replica = TypeMarshaller.unmarshalTypeFromStream(Replica.class, replicaStream);
320
        } catch (IOException e) {
321
            throw new ServiceFailure("4852", "Couldn't deserialize the replica document: " +
322
                    e.getMessage());
323
            
324
        } catch (InstantiationException e) {
325
            throw new ServiceFailure("4852", "Couldn't deserialize the replica document: " +
326
                    e.getMessage());
327
            
328
        } catch (IllegalAccessException e) {
329
            throw new ServiceFailure("4852", "Couldn't deserialize the replica document: " +
330
                    e.getMessage());
331
            
332
        } catch (JiBXException e) {
333
            throw new ServiceFailure("4852", "Couldn't deserialize the replica document: " +
334
                    e.getMessage());
335
            
336
        }
337
        
338
        return replica;
339
        
340
    }
165 341
    
166
    protected AccessPolicy collectAccessPolicy() throws IOException, ServiceFailure, InvalidRequest, JiBXException, InstantiationException, IllegalAccessException, ParserConfigurationException, SAXException  {
342
    protected AccessPolicy collectAccessPolicy() 
343
        throws IOException, ServiceFailure, InvalidRequest, JiBXException, 
344
        InstantiationException, IllegalAccessException, ParserConfigurationException, 
345
        SAXException  {
167 346
		
168 347
		// Read the incoming data from its Mime Multipart encoding
169 348
		logMetacat.debug("Disassembling MIME multipart form");
......
203 382
		return accessPolicy;
204 383
	}
205 384
    
206
    protected SystemMetadata collectSystemMetadata() throws IOException, FileUploadException, ServiceFailure, InvalidRequest, JiBXException, InstantiationException, IllegalAccessException  {
385
    protected SystemMetadata collectSystemMetadata() 
386
        throws IOException, FileUploadException, ServiceFailure, InvalidRequest, 
387
        JiBXException, InstantiationException, IllegalAccessException  {
207 388
		
208 389
		// Read the incoming data from its Mime Multipart encoding
209 390
		logMetacat.debug("Disassembling MIME multipart form");
......
278 459
		return systemMetadata;
279 460
	}
280 461
    
281
    protected Map<String, File> collectMultipartFiles() throws ServiceFailure, InvalidRequest {
462
    protected Map<String, File> collectMultipartFiles() 
463
        throws ServiceFailure, InvalidRequest {
282 464
    	
283 465
        // Read the incoming data from its Mime Multipart encoding
284 466
        logMetacat.debug("Disassembling MIME multipart form");
......
354 536
    }
355 537
    
356 538
		/**
357
     *  copies request parameters to a hashtable which is given as argument to native metacathandler functions  
539
     *  copies request parameters to a hashtable which is given as argument to 
540
     *  native metacathandler functions  
358 541
     */
359 542
    protected void initParams() {
360 543

  

Also available in: Unified diff