/** * '$RCSfile$' * Purpose: This class is in order to fix a problem. It doesn't * has functionality for Metacat. * In Currently, some document in xml_document table * doesn't have entries in xml_access table. This is * okay during the old access policy. * But we changed the access policy and if there is no * entry in xml_access table, except owner, other person * can not access it. So we need to associate with access * policy in xml_access table for these doc ids. * The same access policy of these doc' dataset will associate * to them. * Copyright: 2000 Regents of the University of California and the * National Center for Ecological Analysis and Synthesis * Authors: Jing Tao * * '$Author$' * '$Date$' * '$Revision$' * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package edu.ucsb.nceas.metacat; import java.io.*; import java.util.Vector; import java.net.URL; import java.net.MalformedURLException; import java.sql.*; import java.util.Stack; import java.util.Hashtable; import java.util.Enumeration; import java.io.BufferedWriter; import org.apache.log4j.Logger; import edu.ucsb.nceas.metacat.database.DBConnection; import edu.ucsb.nceas.metacat.database.DBConnectionPool; /**This class is in order to fix a problem. It doesn't has functionality for *Metacat. *In Currently, some document in xml_document table doesn't have entries in *xml_access table. This is okay during the old access policy. *But we changed the access policy and if there is no entry in xml_access table, * except owner, other person can not access it. So we need to associate with *access policy in xml_access table for these doc ids. The same access policy *of these docoments' data set will associate to them. */ public class AssociateAccessPolicy { private DBConnection conn = null; private Vector docIdInAccessTable=null; private Vector docIdWithoutAccessEntry=null; private Vector notFoundDataSetId=null; private Vector itsDataSetIdWithouAccessEntry=null; private Hashtable docIdMapDataSetId=null; private Logger logMetacat = Logger.getLogger(AssociateAccessPolicy.class); /** * the main routine used to associate access policy */ static public void main(String[] args) { DBConnection localConn=null; int serialNumber = -1; AssociateAccessPolicy policy=null; try { localConn=DBConnectionPool.getDBConnection("AssociateAccessPolict.main"); serialNumber=localConn.getCheckOutSerialNumber(); policy = new AssociateAccessPolicy(localConn); policy.associateAccess(); //localConn.close(); }//try catch (Exception e) { System.err.println("Error in AssociateAccessPolicy.main"); System.err.println(e.getMessage()); e.printStackTrace(System.err); } finally { DBConnectionPool.returnDBConnection(localConn, serialNumber); }//finally if (!(policy.getNotFoundDataSetId()).isEmpty()) { System.out.println("Following docid which could not find a mapped" +" dataset was associated with defualt policy:"); for (int i=0; i<(policy.getNotFoundDataSetId()).size(); i++) { String str=(String)(policy.getNotFoundDataSetId()).elementAt(i); System.out.println(str); }//for }//if if (!(policy.geItsDataSetIdWithouAccessEntry()).isEmpty()) { System.out.println("Following docid which's mapped dataset doesn't has" +" an access entry was associated with defualt policy:"); for (int i=0; i<(policy.geItsDataSetIdWithouAccessEntry()).size(); i++) { String str=(String) (policy.geItsDataSetIdWithouAccessEntry()).elementAt(i); System.out.println(str); }//for }//if } /** * construct an instance of the DBQuery class * *
Generally, one would call the findDocuments() routine after creating * an instance to specify the search query
* * @param conn the JDBC connection that we use for the query * @param parserName the fully qualified name of a Java class implementing * the org.xml.sax.XMLReader interface */ public AssociateAccessPolicy( DBConnection conn) throws IOException, SQLException, Exception { this.conn = conn; this.docIdInAccessTable=new Vector(); this.docIdWithoutAccessEntry=new Vector(); this.notFoundDataSetId=new Vector(); this.itsDataSetIdWithouAccessEntry=new Vector(); this.docIdMapDataSetId=new Hashtable(); getDocIdInAccessTable(); getDocIdWithoutAccessEntry(); getDocIdMapDataSetId(); } /** * Get the docid which didn't found a dataset id to map it */ public Vector getNotFoundDataSetId() { return notFoundDataSetId; } /** * Get the docid which it's mapped dataset doesn't has access entry */ public Vector geItsDataSetIdWithouAccessEntry() { return itsDataSetIdWithouAccessEntry; } /** * Get all docIds list in xml_access table */ private void getDocIdInAccessTable() throws SQLException, McdbException,Exception { PreparedStatement pStmt; String docId; ResultSet rs=null; //the query stirng String query="SELECT id.docid from xml_access xa, identifier id where xa.guid = id.guid"; try { pStmt=conn.prepareStatement(query); //excute the query pStmt.execute(); //get the result set rs=pStmt.getResultSet(); //process the result while (rs.next()) { docId=rs.getString(1);//the result docId //put the result into docIdInAccessTable vetor if (!docIdInAccessTable.contains(docId))// delete duplicate docid { docIdInAccessTable.add(docId); } }//while //close the pStmt pStmt.close(); }//try catch (SQLException e) { logMetacat.error("Error in getDocidListForDataPackage: " +e.getMessage()); }//catch //System.out.println("docid in access table"); /*for (int i=0; i