Project

General

Profile

« Previous | Next » 

Revision 4682

Added by daigle over 15 years ago

On update, check if the accession number exists in the db. If not, change the action to insert.

View differences:

src/edu/ucsb/nceas/metacat/MetaCatServlet.java
2154 2154
                String[] docid = params.get("docid");
2155 2155
                String newdocid = null;
2156 2156
                
2157
                String accNumber = docid[0];
2158

  
2159
                if (accNumber.equals("")) {
2160
                    accNumber = null;
2161
                }
2162
                
2157 2163
                String doAction = null;
2164
                boolean accessionNumberExists = AccessionNumber.accNumberIsCurrent(accNumber);
2158 2165
                if (action[0].equals("insert") || action[0].equals("insertmultipart")) {
2159 2166
                    doAction = "INSERT";
2167
                } else if (action[0].equals("update") && !accessionNumberExists) {
2168
                	doAction = "INSERT";
2160 2169
                } else if (action[0].equals("update")) {
2161 2170
                    doAction = "UPDATE";
2162 2171
                }
2163 2172
                
2173
                logMetacat.debug("" + doAction + " " + accNumber + "...");
2174
                
2164 2175
                try {
2165 2176
                    // get a connection from the pool
2166 2177
                    dbConn = DBConnectionPool
......
2169 2180
                    
2170 2181
                    // write the document to the database and disk
2171 2182
                    try {
2172
                        String accNumber = docid[0];
2173
                        logMetacat.debug("" + doAction + " "
2174
                                + accNumber + "...");
2175
                        if (accNumber.equals("")) {
2176
                            accNumber = null;
2177
                        }
2178 2183

  
2179 2184
                        newdocid = documentWrapper.write(dbConn, xml, pub, dtd,
2180 2185
                                doAction, accNumber, user, groups);
src/edu/ucsb/nceas/metacat/AccessionNumber.java
203 203
    return hasAccNumber;
204 204
  }
205 205

  
206
  // check for existence of Accesssion Number in xml_documents table
207
  private boolean accNumberIsCurrent(String accNumber) throws SQLException {
206
  // check for existence of Accession Number in xml_documents table
207
  public static boolean accNumberIsCurrent(String accNumber) throws SQLException {
208 208

  
209 209
    boolean hasCurrentAccNumber = false;
210 210
    DBConnection conn = null;

Also available in: Unified diff