Project

General

Profile

« Previous | Next » 

Revision 6019

rollback the accessDAO changes - leaving well enough alone.

View differences:

Eml200SAXHandler.java
52 52
import org.xml.sax.Attributes;
53 53
import org.xml.sax.SAXException;
54 54

  
55
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlForSingleFile;
56 55
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlInterface;
57 56
import edu.ucsb.nceas.metacat.accesscontrol.AccessRule;
58 57
import edu.ucsb.nceas.metacat.accesscontrol.AccessSection;
59
import edu.ucsb.nceas.metacat.accesscontrol.XMLAccessDAO;
60 58
import edu.ucsb.nceas.metacat.database.DBConnection;
61 59
import edu.ucsb.nceas.metacat.database.DBConnectionPool;
62 60
import edu.ucsb.nceas.metacat.properties.PropertyService;
......
2081 2079
    }//writeTopAccessRuletoDB
2082 2080

  
2083 2081
    /* Write a gaven access rule into db */
2084
    private void writeGivenAccessRuleIntoDB(String permOrder, Vector<AccessRule> accessRules,
2082
    private void writeGivenAccessRuleIntoDB(String permOrder, Vector accessRules,
2085 2083
                     String dataId, String subTreeId) throws SAXException
2086 2084
    {
2087 2085
      if (permOrder == null || permOrder.trim().equals("") || dataId == null ||
......
2092 2090
                                  " write to xml_access table");
2093 2091
        throw new SAXException("The access object is null");
2094 2092
      }
2095
       try {
2096
           AccessControlForSingleFile acfsf = new AccessControlForSingleFile(dataId);
2093
       // get rid of rev from dataId
2094
       //dataId = MetacatUtil.getDocIdFromString(dataId);
2095
       //String permOrder = accessSection.getPermissionOrder();
2096
       String sql = null;
2097
       PreparedStatement pstmt = null;
2098
       sql = "INSERT INTO xml_access (docid, principal_name, permission, "
2099
               + "perm_type, perm_order, accessfileid, subtreeid) VALUES "
2100
               + " (?, ?, ?, ?, ?, ?, ?)";
2101

  
2102
       try
2103
       {
2104

  
2105
           pstmt = connection.prepareStatement(sql);
2106
           // Increase DBConnection usage count
2107
           connection.increaseUsageCount(1);
2108
           // Bind the values to the query
2109
           pstmt.setString(1, dataId);
2110
           logMetacat.info("Docid in accesstable: " + docid);
2111
           pstmt.setString(6, docid);
2112
           logMetacat.info("Accessfileid in accesstable: " + docid);
2113
           pstmt.setString(5, permOrder);
2114
           logMetacat.info("PermOder in accesstable: " + permOrder);
2115
           pstmt.setString(7, subTreeId);
2116
           logMetacat.info("subtree id in accesstable: " + subTreeId);
2117
           // if it is not top level, set s id
2118

  
2119
           //Vector accessRules = accessSection.getAccessRules();
2097 2120
           // go through every rule
2098
           for (int i = 0; i < accessRules.size(); i++) {
2099
               AccessRule rule = accessRules.elementAt(i);
2121
           for (int i = 0; i < accessRules.size(); i++)
2122
           {
2123
               AccessRule rule = (AccessRule) accessRules.elementAt(i);
2100 2124
               String permType = rule.getPermissionType();
2101 2125
               int permission = rule.getPermission();
2102
               logMetacat.info("permission in accesstable: " + permission);
2103
               logMetacat.info("Permtype in accesstable: " + permType);
2126
               pstmt.setInt(3, permission);
2127
               logMetacat.info("permission in accesstable: "
2128
                       + permission);
2129
               pstmt.setString(4, permType);
2130
               logMetacat.info(
2131
                       "Permtype in accesstable: " + permType);
2104 2132
               // go through every principle in rule
2105 2133
               Vector nameVector = rule.getPrincipal();
2106
               for (int j = 0; j < nameVector.size(); j++) {
2134
               for (int j = 0; j < nameVector.size(); j++)
2135
               {
2107 2136
                   String prName = (String) nameVector.elementAt(j);
2108
					logMetacat.debug("Principal in accesstable: " + prName);
2109
					XMLAccessDAO dao = new XMLAccessDAO();
2110
					dao.setAccessFileId(docid);
2111
					dao.setDocId(dataId);
2112
					dao.setPermission(new Long(permission));
2113
					dao.setPermOrder(permOrder);
2114
					dao.setPermType(permType);
2115
					dao.setPrincipalName(prName);
2116
					dao.setSubTreeId(subTreeId);
2117
					// insert if it does not exist
2118
					if (!acfsf.accessControlExists(dao)) {
2119
						acfsf.insertPermissions(dao);
2120
					}
2137
                   pstmt.setString(2, prName);
2138
                   logMetacat.info("Principal in accesstable: "
2139
                           + prName);
2140
                   logMetacat.debug("running sql: " + pstmt.toString());
2141
                   pstmt.execute();
2121 2142
               }//for
2122 2143
           }//for
2123
           
2144
           pstmt.close();
2124 2145
       }//try
2125
       catch (Exception e) {
2146
       catch (SQLException e)
2147
       {
2126 2148
           throw new SAXException("EMLSAXHandler.writeAccessRuletoDB(): "
2127 2149
                   + e.getMessage());
2128 2150
       }//catch
2151
       finally
2152
       {
2153
           try
2154
           {
2155
               pstmt.close();
2156
           }
2157
           catch (SQLException ee)
2158
           {
2159
               throw new SAXException("EMLSAXHandler.writeAccessRuletoDB(): "
2160
                       + ee.getMessage());
2161
           }
2162
       }//finally
2129 2163

  
2130 2164
    }//writeGivenAccessRuleIntoDB
2131 2165

  

Also available in: Unified diff