Project

General

Profile

« Previous | Next » 

Revision 7077

View differences:

src/edu/ucsb/nceas/metacat/restservice/CNResourceHandler.java
249 249
                    } else if (httpVerb == HEAD) {
250 250
                        describeObject(extra);
251 251
                        status = true;
252
                    }
252
                    } else if (httpVerb == DELETE) {
253
                        deleteObject(extra);
254
                        status = true;
255
                    } 
253 256

  
254 257
                } else if (resource.startsWith(RESOURCE_FORMATS)) {
255 258
                    logMetacat.debug("Using resource: " + RESOURCE_FORMATS);
......
747 750
        response.addHeader("DataONE-SerialVersion", dr.getSerialVersion().toString());
748 751

  
749 752
    }
753
    
754
    /**
755
     * Handle delete 
756
     * @param pid ID of data object to be deleted
757
     * @throws IOException
758
     * @throws InvalidRequest 
759
     * @throws NotImplemented 
760
     * @throws NotFound 
761
     * @throws NotAuthorized 
762
     * @throws ServiceFailure 
763
     * @throws InvalidToken 
764
     * @throws JiBXException 
765
     */
766
    private void deleteObject(String pid) throws IOException, InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented, InvalidRequest, JiBXException 
767
    {
750 768

  
769
        OutputStream out = response.getOutputStream();
770
        response.setStatus(200);
771
        response.setContentType("text/xml");
772

  
773
        Identifier id = new Identifier();
774
        id.setValue(pid);
775

  
776
        logMetacat.debug("Calling delete");
777
        CNodeService.getInstance(request).delete(session, id);
778
        TypeMarshaller.marshalTypeToOutputStream(id, out);
779
        
780
    }
781

  
751 782
    /**
752 783
     * Return the requested object format
753 784
     * 
src/edu/ucsb/nceas/metacat/dataone/MNodeService.java
178 178
    public Identifier delete(Session session, Identifier pid) 
179 179
        throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented {
180 180

  
181
        String localId = null;
182
        boolean allowed = false;
183
        String username = Constants.SUBJECT_PUBLIC;
184
        String[] groupnames = null;
185
        if (session == null) {
186
        	throw new InvalidToken("1330", "No session has been provided");
187
        } else {
188
            username = session.getSubject().getValue();
189
            if (session.getSubjectInfo() != null) {
190
                List<Group> groupList = session.getSubjectInfo().getGroupList();
191
                if (groupList != null) {
192
                    groupnames = new String[groupList.size()];
193
                    for (int i = 0; i > groupList.size(); i++) {
194
                        groupnames[i] = groupList.get(i).getGroupName();
195
                    }
196
                }
197
            }
198
        }
199

  
200
        // do we have a valid pid?
201
        if (pid == null || pid.getValue().trim().equals("")) {
202
            throw new ServiceFailure("1350", "The provided identifier was invalid.");
203
        }
204

  
205
        // check for the existing identifier
206
        try {
207
            localId = IdentifierManager.getInstance().getLocalId(pid.getValue());
208
        } catch (McdbDocNotFoundException e) {
209
            throw new NotFound("1340", "The object with the provided " + "identifier was not found.");
210
        }
211

  
212
        // does the subject have DELETE (a D1 CHANGE_PERMISSION level) priveleges on the pid?
213
        try {
214
			allowed = isAuthorized(session, pid, Permission.CHANGE_PERMISSION);
215
		} catch (InvalidRequest e) {
216
            throw new ServiceFailure("1350", e.getDescription());
217
		}
218
            
219

  
220
        if (allowed) {
221
            try {
222
                // delete the document
223
                DocumentImpl.delete(localId, username, groupnames, null);
224
                EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"), username, localId, Event.DELETE.xmlValue());
225

  
226
                // archive it
227
                SystemMetadata sysMeta = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
228
                sysMeta.setArchived(true);
229
                HazelcastService.getInstance().getSystemMetadataMap().put(pid, sysMeta);
230
                
231
                // remove the system metadata for it
232
                //HazelcastService.getInstance().getSystemMetadataMap().remove(pid);
233
                
234
            } catch (McdbDocNotFoundException e) {
235
                throw new NotFound("1340", "The provided identifier was invalid.");
236

  
237
            } catch (SQLException e) {
238
                throw new ServiceFailure("1350", "There was a problem deleting the object." + "The error message was: " + e.getMessage());
239

  
240
            } catch (InsufficientKarmaException e) {
241
                throw new NotAuthorized("1320", "The provided identity does not have " + "permission to DELETE objects on the Member Node.");
242

  
243
            } catch (Exception e) { // for some reason DocumentImpl throws a general Exception
244
                throw new ServiceFailure("1350", "There was a problem deleting the object." + "The error message was: " + e.getMessage());
245
            }
246

  
247
        } else {
248
            throw new NotAuthorized("1320", "The provided identity does not have " + "permission to DELETE objects on the Member Node.");
249
        }
250

  
251
        return pid;
181
    	// defer to superclass implementation
182
        return super.delete(session, pid);
252 183
    }
253 184

  
254 185
    /**
src/edu/ucsb/nceas/metacat/dataone/CNodeService.java
317 317
  }
318 318
  
319 319
  /**
320
   * Deletes an object from the Coordinating Node, where the object is a 
321
   * a science metadata object.
322
   * 
323
   * @param session - the Session object containing the credentials for the Subject
324
   * @param pid - The object identifier to be deleted
325
   * 
326
   * @return pid - the identifier of the object used for the deletion
327
   * 
328
   * @throws InvalidToken
329
   * @throws ServiceFailure
330
   * @throws NotAuthorized
331
   * @throws NotFound
332
   * @throws NotImplemented
333
   * @throws InvalidRequest
334
   */
335
  @Override
336
  public Identifier delete(Session session, Identifier pid) 
337
      throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented {
338

  
339
	  // TODO: any CN-specific checks to perform?
340
	  
341
	  // defer to superclass implementation
342
      return super.delete(session, pid);
343
  }
344
  
345
  /**
320 346
   * Set the obsoletedBy attribute in System Metadata
321 347
   * @param session
322 348
   * @param pid
src/edu/ucsb/nceas/metacat/dataone/D1NodeService.java
85 85
import edu.ucsb.nceas.metacat.IdentifierManager;
86 86
import edu.ucsb.nceas.metacat.McdbDocNotFoundException;
87 87
import edu.ucsb.nceas.metacat.MetacatHandler;
88
import edu.ucsb.nceas.metacat.client.InsufficientKarmaException;
88 89
import edu.ucsb.nceas.metacat.database.DBConnection;
89 90
import edu.ucsb.nceas.metacat.database.DBConnectionPool;
90 91
import edu.ucsb.nceas.metacat.dataone.hazelcast.HazelcastService;
......
149 150
  }
150 151
  
151 152
  /**
153
   * Deletes an object from the Member Node, where the object is either a 
154
   * data object or a science metadata object.
155
   * 
156
   * @param session - the Session object containing the credentials for the Subject
157
   * @param pid - The object identifier to be deleted
158
   * 
159
   * @return pid - the identifier of the object used for the deletion
160
   * 
161
   * @throws InvalidToken
162
   * @throws ServiceFailure
163
   * @throws NotAuthorized
164
   * @throws NotFound
165
   * @throws NotImplemented
166
   * @throws InvalidRequest
167
   */
168
  public Identifier delete(Session session, Identifier pid) 
169
      throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented {
170

  
171
      String localId = null;
172
      boolean allowed = false;
173
      String username = Constants.SUBJECT_PUBLIC;
174
      String[] groupnames = null;
175
      if (session == null) {
176
      	throw new InvalidToken("1330", "No session has been provided");
177
      } else {
178
          username = session.getSubject().getValue();
179
          if (session.getSubjectInfo() != null) {
180
              List<Group> groupList = session.getSubjectInfo().getGroupList();
181
              if (groupList != null) {
182
                  groupnames = new String[groupList.size()];
183
                  for (int i = 0; i > groupList.size(); i++) {
184
                      groupnames[i] = groupList.get(i).getGroupName();
185
                  }
186
              }
187
          }
188
      }
189

  
190
      // do we have a valid pid?
191
      if (pid == null || pid.getValue().trim().equals("")) {
192
          throw new ServiceFailure("1350", "The provided identifier was invalid.");
193
      }
194

  
195
      // check for the existing identifier
196
      try {
197
          localId = IdentifierManager.getInstance().getLocalId(pid.getValue());
198
      } catch (McdbDocNotFoundException e) {
199
          throw new NotFound("1340", "The object with the provided " + "identifier was not found.");
200
      }
201

  
202
      // does the subject have DELETE (a D1 CHANGE_PERMISSION level) priveleges on the pid?
203
      try {
204
			allowed = isAuthorized(session, pid, Permission.CHANGE_PERMISSION);
205
		} catch (InvalidRequest e) {
206
          throw new ServiceFailure("1350", e.getDescription());
207
		}
208
          
209

  
210
      if (allowed) {
211
          try {
212
              // delete the document
213
              DocumentImpl.delete(localId, username, groupnames, null);
214
              EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"), username, localId, Event.DELETE.xmlValue());
215

  
216
              // archive it
217
              SystemMetadata sysMeta = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
218
              sysMeta.setArchived(true);
219
              HazelcastService.getInstance().getSystemMetadataMap().put(pid, sysMeta);
220
              
221
              // remove the system metadata for it
222
              //HazelcastService.getInstance().getSystemMetadataMap().remove(pid);
223
              
224
          } catch (McdbDocNotFoundException e) {
225
              throw new NotFound("1340", "The provided identifier was invalid.");
226

  
227
          } catch (SQLException e) {
228
              throw new ServiceFailure("1350", "There was a problem deleting the object." + "The error message was: " + e.getMessage());
229

  
230
          } catch (InsufficientKarmaException e) {
231
              throw new NotAuthorized("1320", "The provided identity does not have " + "permission to DELETE objects on the Member Node.");
232

  
233
          } catch (Exception e) { // for some reason DocumentImpl throws a general Exception
234
              throw new ServiceFailure("1350", "There was a problem deleting the object." + "The error message was: " + e.getMessage());
235
          }
236

  
237
      } else {
238
          throw new NotAuthorized("1320", "The provided identity does not have " + "permission to DELETE objects on the Member Node.");
239
      }
240

  
241
      return pid;
242
  }
243
  
244
  /**
152 245
   * Low level, "are you alive" operation. A valid ping response is 
153 246
   * indicated by a HTTP status of 200.
154 247
   * 

Also available in: Unified diff