Revision 7077
Added by ben leinfelder about 12 years ago
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
include CN.delete()
https://redmine.dataone.org/issues/2506