Revision 6151
Added by ben leinfelder over 13 years ago
src/edu/ucsb/nceas/metacat/util/MetacatPopulator.java | ||
---|---|---|
44 | 44 |
import org.dataone.client.D1Client; |
45 | 45 |
import org.dataone.client.MNode; |
46 | 46 |
import org.dataone.client.ObjectFormatCache; |
47 |
import org.dataone.service.types.AuthToken; |
|
47 |
import org.dataone.service.types.AccessPolicy; |
|
48 |
import org.dataone.service.types.AccessRule; |
|
48 | 49 |
import org.dataone.service.types.Checksum; |
49 | 50 |
import org.dataone.service.types.ChecksumAlgorithm; |
50 | 51 |
import org.dataone.service.types.Identifier; |
51 | 52 |
import org.dataone.service.types.NodeReference; |
52 | 53 |
import org.dataone.service.types.ObjectFormat; |
54 |
import org.dataone.service.types.Permission; |
|
55 |
import org.dataone.service.types.Session; |
|
53 | 56 |
import org.dataone.service.types.Subject; |
54 | 57 |
import org.dataone.service.types.SystemMetadata; |
55 | 58 |
import org.ecoinformatics.datamanager.DataManager; |
... | ... | |
125 | 128 |
|
126 | 129 |
printHeader("Processing " + docs.size() + " results."); |
127 | 130 |
printHeader("logging in to the destination " + destinationUrl); |
128 |
AuthToken authtoken = mn.login(username, password); |
|
129 |
System.out.println("authtoken: " + authtoken.getToken()); |
|
131 |
//AuthToken authtoken = mn.login(username, password); |
|
132 |
// TODO: get session |
|
133 |
Session session = null; |
|
134 |
System.out.println("session: " + session.getSubject()); |
|
130 | 135 |
for(int i=0; i<docs.size(); i++) |
131 | 136 |
{ |
132 | 137 |
//for each document in the query |
... | ... | |
197 | 202 |
dataDocSysMeta.setSize(dataDocText.getBytes(MetaCatServlet.DEFAULT_ENCODING).length); |
198 | 203 |
dataDocSysMeta.addDescribedBy(sysmeta.getIdentifier()); |
199 | 204 |
boolean error = false; |
205 |
|
|
206 |
// create access policy |
|
207 |
//"public", "read", "allow", "allowFirst" |
|
208 |
AccessPolicy accessPolicy = new AccessPolicy(); |
|
209 |
AccessRule accessRule = new AccessRule(); |
|
210 |
accessRule.addPermission(Permission.READ); |
|
211 |
Subject subject = new Subject(); |
|
212 |
subject.setValue("public"); |
|
213 |
accessRule.addSubject(subject ); |
|
214 |
accessPolicy.addAllow(accessRule ); |
|
200 | 215 |
//create the data doc on d1 |
201 | 216 |
try |
202 | 217 |
{ |
203 |
mn.create(authtoken, dataDocSysMeta.getIdentifier(), IOUtils.toInputStream(dataDocText), dataDocSysMeta);
|
|
204 |
mn.setAccess(authtoken, dataDocSysMeta.getIdentifier(), "public", "read", "allow", "allowFirst");
|
|
218 |
mn.create(session, dataDocSysMeta.getIdentifier(), IOUtils.toInputStream(dataDocText), dataDocSysMeta);
|
|
219 |
mn.setAccessPolicy(session, dataDocSysMeta.getIdentifier(), accessPolicy);
|
|
205 | 220 |
} |
206 | 221 |
catch(Exception e) |
207 | 222 |
{ |
... | ... | |
233 | 248 |
|
234 | 249 |
try |
235 | 250 |
{ |
236 |
Identifier id = mn.create(authtoken, sysmeta.getIdentifier(),
|
|
251 |
Identifier id = mn.create(session, sysmeta.getIdentifier(),
|
|
237 | 252 |
IOUtils.toInputStream(doc.doctext), sysmeta); |
238 | 253 |
System.out.println("Success inserting document " + id.getValue()); |
239 | 254 |
|
Also available in: Unified diff
remove AuthToken (use session). Remove login() call. Use AccessPolicu object to set public read permission