Project

General

Profile

« Previous | Next » 

Revision 945

Added by Jing Tao over 22 years ago

A new method named hasPermissionToExportPackage was added. So when MetaCat handle export action, it will check if user has permission to read the data package. If it has, MetaCat will export a zip output stream to it. Otherwise, MetaCat will be through a exception.

View differences:

src/edu/ucsb/nceas/metacat/DBQuery.java
931 931
  }//isDataPackageId()
932 932
  
933 933
  /**
934
   * Check if the user has the permission to export data package
935
   * @param conn, the connection
936
   * @param docId, the id need to be checked
937
   * @param user, the name of user
938
   * @param groups, the user's group
939
   */ 
940
   private boolean hasPermissionToExportPackage(Connection conn, String docId, 
941
                                        String user, String[] groups)
942
                   throws Exception
943
   {
944
     DocumentImpl doc=new DocumentImpl(conn,docId);
945
     return doc.hasReadPermission(conn, user, groups,docId);
946
   }
947
   
948
  /**
934 949
   *Get the current Rev for a docid in xml_documents table
935 950
   * @param docId, the id need to get version numb
936 951
   * If the return value is -5, means no value in rev field for this docid
......
1201 1216
        
1202 1217
  }//addHtmlSummaryToZipOutputStream
1203 1218
  
1219
  
1220
  
1204 1221
  /**
1205 1222
   * put a data packadge into a zip output stream
1206 1223
   * @param docId, which the user want to put into zip output stream
......
1218 1235
    DocumentImpl docImpls=null;
1219 1236
    Connection dbConn = null;
1220 1237
    Vector docIdList=new Vector();
1221
    Vector documentImplList= new Vector(); 
1238
    Vector documentImplList=new Vector();
1239
    Vector htmlDocumentImplList=new Vector();
1222 1240
    String packageId=null;
1223 1241
    String rootName="package";//the package zip entry name
1224 1242
    
......
1240 1258
    //check if the reqused docId is a data package id
1241 1259
    if (!isDataPackageId(docId))//if it is not, throw a exception
1242 1260
    {
1243
      Exception e = new Exception("The request the doc id " +docId+
1261
      Exception e = new Exception("The request the doc id " +docIdString+
1244 1262
                                    " is not a data package id");
1245 1263
      dbConn.close();
1246 1264
      throw e;
1247 1265
    }
1266
    else if(!hasPermissionToExportPackage(dbConn, docId, user, groups))
1267
    {
1268
      Exception e = new Exception("User " + user + " does not have permission"
1269
                       +" to export the data package " + docIdString);
1270
      dbConn.close();
1271
      throw e;
1272
    }
1248 1273
    else //it is a packadge id
1249 1274
    { 
1250 1275
      //store the package id
......
1284 1309
        //create a docmentImpls object (represent xml doc) base on the docId
1285 1310
        docImpls=(DocumentImpl)documentImplList.elementAt(i);
1286 1311

  
1287
         
1288
        if ((docImpls.getDoctype()).compareTo("BIN")!=0)
1312
         //if the docImpls is metadata 
1313
        if ((docImpls.getDoctype()).compareTo("BIN")!=0)  
1289 1314
        {
1290
          //if the docImpls is metadata
1291
          //add metadata into zip output stream
1292
          addDocToZipOutputStream(docImpls, zOut, rootName);
1315
          //eml-access file wouldn't put into the zip output stream
1316
          //if the docImpls is not a eml-access file 
1317
          if ((util.getOption("accessdoctype")).
1318
            lastIndexOf(docImpls.getDoctype())==-1)
1319
          { 
1320
            
1321
            //add metadata into zip output stream
1322
            addDocToZipOutputStream(docImpls, zOut, rootName);
1323
            //add the documentImpl into the vetor which will be used in html
1324
            htmlDocumentImplList.add(docImpls);
1325
          }
1293 1326
        }
1294
        else //if the docImpls is a data file
1295
        {
1296
           //add data file into zip output stream too
1327
        //eml-access file wouldn't put into the zip output stream
1328
        else 
1329
       {
1330
           
1331
           //it is data file 
1297 1332
           addDataFileToZipOutputStream(docImpls, zOut, rootName);
1333
           htmlDocumentImplList.add(docImpls);
1298 1334
        }
1299 1335

  
1300 1336
      }//for
1301 1337

  
1302 1338
      //add html summary file
1303
      addHtmlSummaryToZipOutputStream(documentImplList, zOut, rootName);
1339
      addHtmlSummaryToZipOutputStream(htmlDocumentImplList, zOut, rootName);
1304 1340
      zOut.finish(); //terminate the zip file
1305 1341
      dbConn.close();
1306 1342
      return zOut;

Also available in: Unified diff