Revision 6250
Added by Chris Jones over 13 years ago
src/edu/ucsb/nceas/metacat/dataone/MNodeService.java | ||
---|---|---|
26 | 26 |
import java.io.IOException; |
27 | 27 |
import java.io.InputStream; |
28 | 28 |
import java.security.NoSuchAlgorithmException; |
29 |
import java.sql.SQLException; |
|
29 | 30 |
import java.util.Date; |
31 |
import java.util.List; |
|
30 | 32 |
|
31 | 33 |
import org.apache.log4j.Logger; |
32 | 34 |
import org.dataone.service.exceptions.IdentifierNotUnique; |
... | ... | |
50 | 52 |
import org.dataone.service.types.ChecksumAlgorithm; |
51 | 53 |
import org.dataone.service.types.DescribeResponse; |
52 | 54 |
import org.dataone.service.types.Event; |
55 |
import org.dataone.service.types.Group; |
|
53 | 56 |
import org.dataone.service.types.Identifier; |
54 | 57 |
import org.dataone.service.types.Log; |
55 | 58 |
import org.dataone.service.types.MonitorList; |
... | ... | |
63 | 66 |
import org.dataone.service.types.SystemMetadata; |
64 | 67 |
import org.dataone.service.types.util.ServiceTypeUtil; |
65 | 68 |
|
69 |
import edu.ucsb.nceas.metacat.DocumentImpl; |
|
66 | 70 |
import edu.ucsb.nceas.metacat.EventLog; |
67 | 71 |
import edu.ucsb.nceas.metacat.IdentifierManager; |
68 | 72 |
import edu.ucsb.nceas.metacat.McdbDocNotFoundException; |
73 |
import edu.ucsb.nceas.metacat.client.InsufficientKarmaException; |
|
69 | 74 |
import edu.ucsb.nceas.metacat.properties.PropertyService; |
70 | 75 |
import edu.ucsb.nceas.utilities.PropertyNotFoundException; |
71 | 76 |
|
... | ... | |
150 | 155 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, |
151 | 156 |
NotImplemented, InvalidRequest { |
152 | 157 |
|
153 |
return null; |
|
158 |
String localId = null; |
|
159 |
boolean allowed = false; |
|
160 |
Subject subject = session.getSubject(); |
|
161 |
List<Group> groupList = session.getSubjectList().getGroupList(); |
|
162 |
String[] groups = new String[groupList.size()]; |
|
163 |
IdentifierManager im = IdentifierManager.getInstance(); |
|
164 |
|
|
165 |
// put the group names into a string array |
|
166 |
if( session != null ) { |
|
167 |
for ( int i = 0; i > groupList.size(); i++ ) { |
|
168 |
groups[i] = groupList.get(i).getGroupName(); |
|
169 |
|
|
170 |
} |
|
171 |
} |
|
172 |
|
|
173 |
// be sure the user is authenticated for delete() |
|
174 |
if (subject.getValue() == null || |
|
175 |
subject.getValue().toLowerCase().equals("public") ) { |
|
176 |
throw new NotAuthorized("1320", "The provided identity does not have " + |
|
177 |
"permission to DELETE objects on the Member Node."); |
|
178 |
|
|
179 |
} |
|
180 |
|
|
181 |
// do we have a valid pid? |
|
182 |
if ( pid == null || pid.getValue().trim().equals("") ) { |
|
183 |
throw new InvalidRequest("1322", "The provided identifier was invalid."); |
|
184 |
|
|
185 |
} |
|
186 |
|
|
187 |
// check for the existing identifier |
|
188 |
try { |
|
189 |
localId = im.getLocalId(pid.getValue()); |
|
190 |
|
|
191 |
} catch (McdbDocNotFoundException e) { |
|
192 |
throw new InvalidRequest("1322", "The object with the provided " + |
|
193 |
"identifier was not found."); |
|
194 |
|
|
195 |
} |
|
196 |
|
|
197 |
// does the subject have DELETE (a D1 CHANGE_PERMISSION level) priveleges on the pid? |
|
198 |
allowed = isAuthorized(session, pid, Permission.CHANGE_PERMISSION); |
|
199 |
|
|
200 |
if ( allowed ) { |
|
201 |
try { |
|
202 |
// delete the document |
|
203 |
DocumentImpl.delete(localId, subject.getValue(), groups, null); |
|
204 |
|
|
205 |
} catch (McdbDocNotFoundException e) { |
|
206 |
throw new InvalidRequest("1322", "The provided identifier was invalid."); |
|
207 |
|
|
208 |
} catch (SQLException e) { |
|
209 |
throw new ServiceFailure("1350", "There was a problem deleting the object." + |
|
210 |
"The error message was: " + e.getMessage()); |
|
211 |
|
|
212 |
} catch (InsufficientKarmaException e) { |
|
213 |
throw new NotAuthorized("1320", "The provided identity does not have " + |
|
214 |
"permission to DELETE objects on the Member Node."); |
|
215 |
|
|
216 |
} catch (Exception e) { // for some reason DocumentImpl throws a general Exception |
|
217 |
throw new ServiceFailure("1350", "There was a problem deleting the object." + |
|
218 |
"The error message was: " + e.getMessage()); |
|
219 |
|
|
220 |
} |
|
221 |
|
|
222 |
} else { |
|
223 |
|
|
224 |
} |
|
225 |
|
|
226 |
return pid; |
|
154 | 227 |
} |
155 | 228 |
|
156 | 229 |
/** |
Also available in: Unified diff
Implement the MNStorage.delete() MNodeService. There is debate about what permissions are needed to 'delete' an object (archive it in metacat terms): D1 'WRITE' (metacat 'write') or D1 CHANGE_PERMISSION (metacat 'all'). For now we are using CHANGE_PERMISSION until it is ironed out.