Project

General

Profile

1
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2000 Regents of the University of California and the
4
 *              National Center for Ecological Analysis and Synthesis
5
 *
6
 *   '$Author: $'
7
 *     '$Date: 2009-06-13 15:28:13 +0300  $'
8
 *
9
 * This program is free software; you can redistribute it and/or modify
10
 * it under the terms of the GNU General Public License as published by
11
 * the Free Software Foundation; either version 2 of the License, or
12
 * (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22
 */
23
package edu.ucsb.nceas.metacat.dataone;
24

    
25
import java.io.ByteArrayOutputStream;
26
import java.io.File;
27
import java.io.FileNotFoundException;
28
import java.io.FileOutputStream;
29
import java.io.IOException;
30
import java.io.InputStream;
31
import java.io.OutputStream;
32
import java.io.PrintWriter;
33
import java.sql.SQLException;
34
import java.util.Date;
35
import java.util.Enumeration;
36
import java.util.Hashtable;
37
import java.util.Timer;
38

    
39
import javax.servlet.ServletContext;
40
import javax.servlet.http.HttpServletRequest;
41
import javax.servlet.http.HttpServletResponse;
42

    
43
import org.apache.commons.io.IOUtils;
44
import org.apache.log4j.Logger;
45
import org.dataone.service.exceptions.IdentifierNotUnique;
46
import org.dataone.service.exceptions.InsufficientResources;
47
import org.dataone.service.exceptions.InvalidRequest;
48
import org.dataone.service.exceptions.InvalidSystemMetadata;
49
import org.dataone.service.exceptions.InvalidToken;
50
import org.dataone.service.exceptions.NotAuthorized;
51
import org.dataone.service.exceptions.NotFound;
52
import org.dataone.service.exceptions.NotImplemented;
53
import org.dataone.service.exceptions.ServiceFailure;
54
import org.dataone.service.exceptions.UnsupportedType;
55
import org.dataone.service.mn.MemberNodeCrud;
56
import org.dataone.service.types.AuthToken;
57
import org.dataone.service.types.Checksum;
58
import org.dataone.service.types.DescribeResponse;
59
import org.dataone.service.types.Identifier;
60
import org.dataone.service.types.LogRecordSet;
61
import org.dataone.service.types.SystemMetadata;
62
import org.jibx.runtime.BindingDirectory;
63
import org.jibx.runtime.IBindingFactory;
64
import org.jibx.runtime.IMarshallingContext;
65
import org.jibx.runtime.IUnmarshallingContext;
66
import org.jibx.runtime.JiBXException;
67

    
68
import com.gc.iotools.stream.is.InputStreamFromOutputStream;
69

    
70
import edu.ucsb.nceas.metacat.AccessionNumberException;
71
import edu.ucsb.nceas.metacat.DocumentImpl;
72
import edu.ucsb.nceas.metacat.EventLog;
73
import edu.ucsb.nceas.metacat.IdentifierManager;
74
import edu.ucsb.nceas.metacat.McdbDocNotFoundException;
75
import edu.ucsb.nceas.metacat.McdbException;
76
import edu.ucsb.nceas.metacat.MetacatHandler;
77
import edu.ucsb.nceas.metacat.client.InsufficientKarmaException;
78
import edu.ucsb.nceas.metacat.properties.PropertyService;
79
import edu.ucsb.nceas.metacat.replication.ForceReplicationHandler;
80
import edu.ucsb.nceas.metacat.service.SessionService;
81
import edu.ucsb.nceas.metacat.util.DocumentUtil;
82
import edu.ucsb.nceas.metacat.util.SessionData;
83
import edu.ucsb.nceas.utilities.ParseLSIDException;
84
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
85

    
86
/**
87
 * 
88
 * Implements DataONE MemberNode CRUD API for Metacat. 
89
 * 
90
 * @author Matthew Jones
91
 */
92
public class CrudService implements MemberNodeCrud {
93

    
94
    private ServletContext servletContext;
95
    private HttpServletRequest request;
96
    private HttpServletResponse response;
97

    
98
    private MetacatHandler handler;
99
    private Hashtable<String, String[]> params;
100
    Logger logMetacat = null;
101

    
102
    /**
103
     * Initializes new instance by setting servlet context,request and response.
104
     * TODO: remove dependency on Servlet infrastructure
105
     * TODO: Make this a real service, and make it a Singleton
106
     */
107
    public CrudService(ServletContext servletContext,
108
            HttpServletRequest request, HttpServletResponse response) {
109
    //change crud service into a singleton.  dont pass servlet data structures here
110
    
111
        this.servletContext = servletContext;
112
        this.request = request;
113
        this.response = response;
114
        logMetacat = Logger.getLogger(CrudService.class);
115

    
116
        handler = new MetacatHandler(this.servletContext, new Timer());
117
        initParams();
118
//        loadSessionData();
119
    }
120

    
121
    /**
122
     *  copies request parameters to a Hashtable which is given as argument to 
123
     *  native MetacatHandler functions  
124
     */
125
    private void initParams() {
126

    
127
        String name = null;
128
        String[] value = null;
129
        params = new Hashtable<String, String[]>();
130
        Enumeration paramlist = request.getParameterNames();
131
        while (paramlist.hasMoreElements()) {
132
            name = (String) paramlist.nextElement();
133
            value = request.getParameterValues(name);
134
            params.put(name, value);
135
        }
136
    }
137
    
138
    public Identifier create(AuthToken token, Identifier guid, 
139
            InputStream object, SystemMetadata sysmeta) throws InvalidToken, 
140
            ServiceFailure, NotAuthorized, IdentifierNotUnique, UnsupportedType, 
141
            InsufficientResources, InvalidSystemMetadata, NotImplemented {
142

    
143
        logMetacat.debug("Starting CrudService.create()...");
144
        
145
        // authenticate & get user info
146
        SessionData sessionData = getSessionData(token);
147
        String username = sessionData.getUserName();
148
        String[] groups = sessionData.getGroupNames();
149

    
150
        // verify that guid == SystemMetadata.getIdentifier()
151
        logMetacat.debug("Comparing guid|sysmeta_guid: " + guid.getValue() + "|" + sysmeta.getIdentifier().getValue());
152
        if (!guid.getValue().equals(sysmeta.getIdentifier().getValue())) {
153
            throw new InvalidSystemMetadata(1180, 
154
                "GUID in method call does not match GUID in system metadata.");
155
        }
156

    
157
        logMetacat.debug("Checking if identifier exists...");
158
        // Check that the identifier does not already exist
159
        IdentifierManager im = IdentifierManager.getInstance();
160
        if (im.identifierExists(guid.getValue())) {
161
            throw new IdentifierNotUnique(1120, 
162
                "GUID is already in use by an existing object.");
163
        }
164

    
165
        // Check if we are handling metadata or data
166
        boolean isScienceMetadata = isScienceMetadata(sysmeta);
167
        
168
        if (isScienceMetadata) {
169
            // CASE METADATA:
170
            try {
171
                String xml = IOUtils.toString(object);
172
                this.insertDocument(xml, guid, sessionData);
173
            } catch (IOException e) {
174
                String msg = "Could not create string from XML stream: " +
175
                    " " + e.getMessage();
176
                logMetacat.debug(msg);
177
                throw new ServiceFailure(1190, msg);
178
            }
179

    
180
        } else {
181
            // DEFAULT CASE: DATA (needs to be checked and completed)
182
            insertDataObject(object, guid, sessionData);
183
            
184
        }
185

    
186
        // For Metadata and Data, insert the system metadata into the object store too
187
        insertSystemMetadata(sysmeta, sessionData);
188

    
189
        logMetacat.debug("Returning from CrudService.create()");
190
        return guid;
191
    }
192

    
193
    public Identifier delete(AuthToken token, Identifier guid)
194
            throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, 
195
            NotImplemented {
196
        throw new NotImplemented(1000, "This method not yet implemented.");
197
    }
198

    
199
    public DescribeResponse describe(AuthToken token, Identifier guid)
200
            throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, 
201
            NotImplemented {
202
        throw new NotImplemented(1000, "This method not yet implemented.");
203
    }
204
    
205
    public InputStream get(AuthToken token, Identifier guid)
206
            throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, 
207
            NotImplemented {
208
        
209
        // Retrieve the session information from the AuthToken
210
        // If the session is expired, then the user is 'public'
211
        final SessionData sessionData = getSessionData(token);
212
        
213
        // Look up the localId for this global identifier
214
        IdentifierManager im = IdentifierManager.getInstance();
215
        try {
216
            final String localId = im.getLocalId(guid.getValue());
217

    
218
            final InputStreamFromOutputStream<String> objectStream = 
219
                new InputStreamFromOutputStream<String>() {
220
                
221
                @Override
222
                public String produce(final OutputStream dataSink) throws Exception {
223

    
224
                    try {
225
                        handler.readFromMetacat(request.getRemoteAddr(), null, 
226
                                dataSink, localId, "xml",
227
                                sessionData.getUserName(), 
228
                                sessionData.getGroupNames(), true, params);
229
                    } catch (PropertyNotFoundException e) {
230
                        throw new ServiceFailure(1030, e.getMessage());
231
                    } catch (ClassNotFoundException e) {
232
                        throw new ServiceFailure(1030, e.getMessage());
233
                    } catch (IOException e) {
234
                        throw new ServiceFailure(1030, e.getMessage());
235
                    } catch (SQLException e) {
236
                        throw new ServiceFailure(1030, e.getMessage());
237
                    } catch (McdbException e) {
238
                        throw new ServiceFailure(1030, e.getMessage());
239
                    } catch (ParseLSIDException e) {
240
                        throw new NotFound(1020, e.getMessage());
241
                    } catch (InsufficientKarmaException e) {
242
                        throw new NotAuthorized(1000, "Not authorized for get().");
243
                    }
244

    
245
                    return "Completed";
246
                }
247
            };
248
            return objectStream;
249

    
250
        } catch (McdbDocNotFoundException e) {
251
            throw new NotFound(1020, e.getMessage());
252
        }
253
    }
254

    
255
    public Checksum getChecksum(AuthToken token, Identifier guid)
256
            throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, 
257
            InvalidRequest, NotImplemented {
258
        throw new NotImplemented(1000, "This method not yet implemented.");
259
    }
260

    
261
    public Checksum getChecksum(AuthToken token, Identifier guid, 
262
            String checksumAlgorithm) throws InvalidToken, ServiceFailure, 
263
            NotAuthorized, NotFound, InvalidRequest, NotImplemented {
264
        throw new NotImplemented(1000, "This method not yet implemented.");
265
    }
266

    
267
    public LogRecordSet getLogRecords(AuthToken token, Date fromDate, Date toDate)
268
            throws InvalidToken, ServiceFailure, NotAuthorized, InvalidRequest, 
269
            NotImplemented {
270
        throw new NotImplemented(1000, "This method not yet implemented.");
271
    }
272

    
273
    public SystemMetadata getSystemMetadata(AuthToken token, Identifier guid)
274
            throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, 
275
            InvalidRequest, NotImplemented {
276
        
277
        logMetacat.debug("CrudService.getSystemMetadata - for guid: " + guid.getValue());
278
        
279
        // Retrieve the session information from the AuthToken
280
        // If the session is expired, then the user is 'public'
281
        final SessionData sessionData = getSessionData(token);
282

    
283
        // TODO: Check access control rules
284
                
285
        try {
286
            IdentifierManager im = IdentifierManager.getInstance();
287
            // This is a test id of an existing sysmeta document -- for temporary testing
288
            String testGuid = "autogen.20101192441566.1";
289
            // TODO: Look up ID of system metadata based on guid
290
            // TODO: Initially from document, later from entry in table?
291
//            String localId = im.getLocalId(guid.getValue());
292
            final String localId = im.getLocalId(testGuid);
293
            
294
            // Read system metadata from metacat's db
295
            final InputStreamFromOutputStream<String> objectStream = 
296
                new InputStreamFromOutputStream<String>() {
297
                
298
                @Override
299
                public String produce(final OutputStream dataSink) throws Exception {
300
                    try {
301
                        handler.readFromMetacat(request.getRemoteAddr(), null, 
302
                                dataSink, localId, "xml",
303
                                sessionData.getUserName(), 
304
                                sessionData.getGroupNames(), true, params);
305
                    } catch (PropertyNotFoundException e) {
306
                        throw new ServiceFailure(1030, e.getMessage());
307
                    } catch (ClassNotFoundException e) {
308
                        throw new ServiceFailure(1030, e.getMessage());
309
                    } catch (IOException e) {
310
                        throw new ServiceFailure(1030, e.getMessage());
311
                    } catch (SQLException e) {
312
                        throw new ServiceFailure(1030, e.getMessage());
313
                    } catch (McdbException e) {
314
                        throw new ServiceFailure(1030, e.getMessage());
315
                    } catch (ParseLSIDException e) {
316
                        throw new NotFound(1020, e.getMessage());
317
                    } catch (InsufficientKarmaException e) {
318
                        throw new NotAuthorized(1000, "Not authorized for get().");
319
                    }
320

    
321
                    return "Completed";
322
                }
323
            };
324
            
325
            // Deserialize the xml to create a SystemMetadata object
326
            SystemMetadata sysmeta = deserializeSystemMetadata(objectStream);
327
            return sysmeta;
328
            
329
        } catch (McdbDocNotFoundException e) {
330
            throw new NotFound(1000, e.getMessage());
331
        }                
332
    }
333

    
334
    public Identifier update(AuthToken token, Identifier guid, 
335
            InputStream object, Identifier obsoletedGuid, SystemMetadata sysmeta) 
336
            throws InvalidToken, ServiceFailure, NotAuthorized, IdentifierNotUnique, 
337
            UnsupportedType, InsufficientResources, NotFound, InvalidSystemMetadata, 
338
            NotImplemented {
339
        throw new NotImplemented(1000, "This method not yet implemented.");
340
    }
341

    
342
    /*
343
     * Look up the information on the session using the token provided in
344
     * the AuthToken.  The Session should have all relevant user information.
345
     * If the session has expired or is invalid, the 'public' session will
346
     * be returned, giving the user anonymous access.
347
     */
348
    private static SessionData getSessionData(AuthToken token) {
349
        SessionData sessionData = null;
350
        String sessionId = "PUBLIC";
351
        if (token != null) {
352
            sessionId = token.getToken();
353
        }
354
        
355
        // if the session id is registered in SessionService, get the
356
        // SessionData for it. Otherwise, use the public session.
357
        if (SessionService.isSessionRegistered(sessionId)) {
358
            sessionData = SessionService.getRegisteredSession(sessionId);
359
        } else {
360
            sessionData = SessionService.getPublicSession();
361
        }
362
        
363
        return sessionData;
364
    }
365

    
366
    /** 
367
     * Determine if a given object should be treated as an XML science metadata
368
     * object. 
369
     * 
370
     * TODO: This test should be externalized in a configuration dictionary rather than being hardcoded.
371
     * 
372
     * @param sysmeta the SystemMetadata describig the object
373
     * @return true if the object should be treated as science metadata
374
     */
375
    private boolean isScienceMetadata(SystemMetadata sysmeta) {
376
        boolean scimeta = false;
377
        switch (sysmeta.getObjectFormat()) {
378
            case EML_2_1_0: scimeta = true; break;
379
            case EML_2_0_1: scimeta = true; break;
380
            case EML_2_0_0: scimeta = true; break;
381
            case FGDC_STD_001_1_1999: scimeta = true; break;
382
            case FGDC_STD_001_1998: scimeta = true; break;
383
            case NCML_2_2: scimeta = true; break;
384
        }
385
        
386
        return scimeta;
387
    }
388

    
389
    private void insertDataObject(InputStream object, Identifier guid, 
390
            SessionData sessionData) throws ServiceFailure {
391
        
392
        String username = sessionData.getUserName();
393
        String[] groups = sessionData.getGroupNames();
394

    
395
        // generate guid/localId pair for object
396
        logMetacat.debug("Generating a guid/localId mapping");
397
        IdentifierManager im = IdentifierManager.getInstance();
398
        String localId = im.generateLocalId(guid.getValue(), 1);
399

    
400
        try {
401
            logMetacat.debug("Case DATA: starting to write to disk.");
402
            if (DocumentImpl.getDataFileLockGrant(localId)) {
403
    
404
                // Save the data file to disk using "localId" as the name
405
                try {
406
                    String datafilepath = PropertyService.getProperty("application.datafilepath");
407
    
408
                    File dataDirectory = new File(datafilepath);
409
                    dataDirectory.mkdirs();
410
    
411
                    File newFile = writeStreamToFile(dataDirectory, localId, object);
412
    
413
                    // TODO: Check that the file size matches SystemMetadata
414
                    //                        long size = newFile.length();
415
                    //                        if (size == 0) {
416
                    //                            throw new IOException("Uploaded file is 0 bytes!");
417
                    //                        }
418
    
419
                    // Register the file in the database (which generates an exception
420
                    // if the localId is not acceptable or other untoward things happen
421
                    try {
422
                        logMetacat.debug("Registering document...");
423
                        DocumentImpl.registerDocument(localId, "BIN", localId,
424
                                username, groups);
425
                        logMetacat.debug("Registration step completed.");
426
                    } catch (SQLException e) {
427
                        //newFile.delete();
428
                        logMetacat.debug("SQLE: " + e.getMessage());
429
                        e.printStackTrace(System.out);
430
                        throw new ServiceFailure(1190, "Registration failed: " + e.getMessage());
431
                    } catch (AccessionNumberException e) {
432
                        //newFile.delete();
433
                        logMetacat.debug("ANE: " + e.getMessage());
434
                        e.printStackTrace(System.out);
435
                        throw new ServiceFailure(1190, "Registration failed: " + e.getMessage());
436
                    } catch (Exception e) {
437
                        //newFile.delete();
438
                        logMetacat.debug("Exception: " + e.getMessage());
439
                        e.printStackTrace(System.out);
440
                        throw new ServiceFailure(1190, "Registration failed: " + e.getMessage());
441
                    }
442
    
443
                    logMetacat.debug("Logging the creation event.");
444
                    EventLog.getInstance().log(request.getRemoteAddr(),
445
                            username, localId, "create");
446
    
447
                    // Schedule replication for this data file
448
                    logMetacat.debug("Scheduling replication.");
449
                    ForceReplicationHandler frh = new ForceReplicationHandler(
450
                            localId, "insert", false, null);
451
    
452
                } catch (PropertyNotFoundException e) {
453
                    throw new ServiceFailure(1190, "Could not lock file for writing:" + e.getMessage());
454
                }
455
    
456
            }
457
        } catch (Exception e) {
458
            // Could not get a lock on the document, so we can not update the file now
459
            throw new ServiceFailure(1190, "Failed to lock file: " + e.getMessage());
460
        }
461
    }
462

    
463
    private File writeStreamToFile(File dir, String fileName, InputStream data) 
464
        throws ServiceFailure {
465
        
466
        File newFile = new File(dir, fileName);
467
        logMetacat.debug("Filename for write is: " + newFile.getAbsolutePath());
468

    
469
        try {
470
            if (newFile.createNewFile()) {
471
                // write data stream to desired file
472
                OutputStream os = new FileOutputStream(newFile);
473
                long length = IOUtils.copyLarge(data, os);
474
                os.flush();
475
                os.close();
476
            } else {
477
                logMetacat.debug("File creation failed, or file already exists.");
478
                throw new ServiceFailure(1190, "File already exists: " + fileName);
479
            }
480
        } catch (FileNotFoundException e) {
481
            logMetacat.debug("FNF: " + e.getMessage());
482
            throw new ServiceFailure(1190, "File not found: " + fileName + " " 
483
                    + e.getMessage());
484
        } catch (IOException e) {
485
            logMetacat.debug("IOE: " + e.getMessage());
486
            throw new ServiceFailure(1190, "File was not written: " + fileName 
487
                    + " " + e.getMessage());
488
        }
489

    
490
        return newFile;
491
    }
492

    
493
    private void insertSystemMetadata(SystemMetadata sysmeta, SessionData sessionData) 
494
        throws ServiceFailure {
495
        logMetacat.debug("Starting to insert SystemMetadata...");
496
    
497
        // generate guid/localId pair for sysmeta
498
        Identifier sysMetaGuid = new Identifier();
499
        sysMetaGuid.setValue(DocumentUtil.generateDocumentId(1));
500
        sysmeta.setDateSysMetadataModified(new Date());
501

    
502
        String xml = new String(serializeSystemMetadata(sysmeta).toByteArray());
503
        String localId = insertDocument(xml, sysMetaGuid, sessionData);
504
        //insert the system metadata doc id into the identifiers table to 
505
        //link it to the data or metadata document
506
        IdentifierManager.getInstance().createSystemMetadataMapping(sysMetaGuid.getValue(), localId);
507
    }
508
    
509
    /**
510
     * insert a document, return the id of the document that was inserted
511
     */
512
    private String insertDocument(String xml, Identifier guid, SessionData sessionData) 
513
        throws ServiceFailure {
514
        logMetacat.debug("Starting to insert xml document...");
515
        IdentifierManager im = IdentifierManager.getInstance();
516

    
517
        // generate guid/localId pair for sysmeta
518
        String localId = im.generateLocalId(guid.getValue(), 1);
519
        logMetacat.debug("Metadata guid|localId: " + guid.getValue() + "|" +
520
                localId);
521

    
522
        String[] action = new String[1];
523
        action[0] = "insert";
524
        params.put("action", action);
525
        String[] docid = new String[1];
526
        docid[0] = localId;
527
        params.put("docid", docid);
528
        String[] doctext = new String[1];
529
        doctext[0] = xml;
530
        logMetacat.debug(doctext[0]);
531
        params.put("doctext", doctext);
532
        
533
        // TODO: refactor handleInsertOrUpdateAction() to not output XML directly
534
        // onto output stream, or alternatively, capture that and parse it to 
535
        // generate the right exceptions
536
        ByteArrayOutputStream output = new ByteArrayOutputStream();
537
        PrintWriter pw = new PrintWriter(output);
538
        handler.handleInsertOrUpdateAction(request.getRemoteAddr(), response, 
539
                pw, params, sessionData.getUserName(),
540
                sessionData.getGroupNames());
541
        String outputS = new String(output.toByteArray());
542
        logMetacat.debug("CrudService.insertDocument - Metacat returned: " + outputS);
543
//        if (!(outputS.indexOf("<success>") > 0 && outputS.indexOf(localId) > 0)) {
544
//            throw new ServiceFailure(1190, outputS);
545
//        }
546
        logMetacat.debug("Finsished inserting xml document with id " + localId);
547
        return localId;
548
    }
549
    
550
    public static ByteArrayOutputStream serializeSystemMetadata(SystemMetadata sysmeta) 
551
        throws ServiceFailure {
552
        IBindingFactory bfact;
553
        ByteArrayOutputStream sysmetaOut = null;
554
        try {
555
            bfact = BindingDirectory.getFactory(SystemMetadata.class);
556
            IMarshallingContext mctx = bfact.createMarshallingContext();
557
            sysmetaOut = new ByteArrayOutputStream();
558
            mctx.marshalDocument(sysmeta, "UTF-8", null, sysmetaOut);
559
        } catch (JiBXException e) {
560
            throw new ServiceFailure(1190, "Failed to serialize and insert SystemMetadata: " + e.getMessage());
561
        }
562
        
563
        return sysmetaOut;
564
    }
565
    
566
    public static SystemMetadata deserializeSystemMetadata(InputStream xml) 
567
        throws ServiceFailure {
568
        try {
569
            IBindingFactory bfact = BindingDirectory.getFactory(SystemMetadata.class);
570
            IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
571
            SystemMetadata sysmeta = (SystemMetadata) uctx.unmarshalDocument(xml, null);
572
            return sysmeta;
573
        } catch (JiBXException e) {
574
            throw new ServiceFailure(1190, "Failed to serialize and insert SystemMetadata: " + e.getMessage());
575
        }    
576
    }
577
}
    (1-1/1)