You can subscribe to this list here.
| 2008 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(11) |
Dec
(6) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2009 |
Jan
(2) |
Feb
(64) |
Mar
(4) |
Apr
(2) |
May
(10) |
Jun
(26) |
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
(1) |
Dec
|
| 2010 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2011 |
Jan
(14) |
Feb
(7) |
Mar
(7) |
Apr
(37) |
May
(59) |
Jun
(4) |
Jul
(16) |
Aug
(3) |
Sep
(9) |
Oct
(1) |
Nov
|
Dec
(25) |
| 2012 |
Jan
(68) |
Feb
(5) |
Mar
(28) |
Apr
(12) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-03-24 13:05:57
|
Revision: 485
http://sword-app.svn.sourceforge.net/sword-app/?rev=485&view=rev
Author: richard-jones
Date: 2012-03-24 13:05:46 +0000 (Sat, 24 Mar 2012)
Log Message:
-----------
add complete deposit tests, and fix bug with client's complete method
Modified Paths:
--------------
JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java
JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java
Modified: JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java 2012-03-24 12:50:34 UTC (rev 484)
+++ JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java 2012-03-24 13:05:46 UTC (rev 485)
@@ -949,10 +949,10 @@
throws SWORDClientException, ProtocolViolationException, SWORDError
{
String url = null;
- SwordIdentifier eml = receipt.getEditMediaLink();
- if (eml != null)
+ SwordIdentifier el = receipt.getEditLink();
+ if (el != null)
{
- url = eml.getHref();
+ url = el.getHref();
return this.complete(url, auth);
}
return null;
Modified: JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java
===================================================================
--- JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java 2012-03-24 12:50:34 UTC (rev 484)
+++ JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java 2012-03-24 13:05:46 UTC (rev 485)
@@ -993,32 +993,32 @@
assertTrue(statement instanceof OreStatement);
}
- /* Python tests to mimic
+ @Test
+ public void completeDeposit()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass, this.obo));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
- def test_34_complete_deposit(self):
- conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
- conn.get_service_document()
- col = conn.sd.workspaces[0][1][0]
- e = Entry(title="Foo", id="asidjasidj", dcterms_abstract="abstract", dcterms_title="my title")
- with open(PACKAGE) as pkg:
- receipt = conn.create(col_iri = col.href,
- metadata_entry = e,
- payload=pkg,
- mimetype=PACKAGE_MIME,
- filename="example.zip",
- packaging = 'http://purl.org/net/sword/package/SimpleZip',
- in_progress = True,
- suggested_identifier = "zyxwvutsrq")
+ Deposit deposit = new Deposit();
+ deposit.setFile(new FileInputStream(this.file));
+ deposit.setMimeType("application/zip");
+ deposit.setFilename("example.zip");
+ deposit.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ deposit.setMd5(this.fileMd5);
+ deposit.setInProgress(true);
- # ensure that we have a receipt (the server may not give us one
- # by default)
- edit_iri = receipt.location
- receipt = conn.get_deposit_receipt(edit_iri)
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass, this.obo));
+ receipt = client.getDepositReceipt(receipt.getLocation(), new AuthCredentials(this.user, this.pass, this.obo));
- response = conn.complete_deposit(dr=receipt)
+ DepositReceipt newReceipt = client.complete(receipt, new AuthCredentials(this.user, this.pass, this.obo));
- assert response.code == 200
+ assertEquals(newReceipt.getStatusCode(), 200);
+ }
+ /* Python tests to mimic
+
def test_35_error_checksum_mismatch(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW,
error_response_raises_exceptions=False)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-03-24 12:50:40
|
Revision: 484
http://sword-app.svn.sourceforge.net/sword-app/?rev=484&view=rev
Author: richard-jones
Date: 2012-03-24 12:50:34 +0000 (Sat, 24 Mar 2012)
Log Message:
-----------
add enhanced authentication and mediated deposit testing
Modified Paths:
--------------
JavaClient2.0/src/test/java/org/swordapp/client/test/SSSSemiUnits.java
Modified: JavaClient2.0/src/test/java/org/swordapp/client/test/SSSSemiUnits.java
===================================================================
--- JavaClient2.0/src/test/java/org/swordapp/client/test/SSSSemiUnits.java 2012-03-24 11:56:14 UTC (rev 483)
+++ JavaClient2.0/src/test/java/org/swordapp/client/test/SSSSemiUnits.java 2012-03-24 12:50:34 UTC (rev 484)
@@ -12,6 +12,7 @@
import org.swordapp.client.SWORDClient;
import org.swordapp.client.SWORDCollection;
import org.swordapp.client.SWORDWorkspace;
+import org.swordapp.client.ServerResource;
import org.swordapp.client.ServiceDocument;
import org.swordapp.client.Statement;
import org.swordapp.client.UriRegistry;
@@ -179,6 +180,16 @@
assertEquals(statement.getOriginalDeposits().size(), 1);
assertEquals(statement.getParts().size(), 5);
assertEquals(statement.getState().size(), 1);
+
+ List<ServerResource> ods = statement.getOriginalDeposits();
+ boolean checked = false;
+ for (ServerResource od : ods)
+ {
+ assertEquals(od.getDepositedBy(), this.user);
+ assertEquals(od.getDepositedOnBehalfOf(), this.obo);
+ checked = true;
+ }
+ assertTrue(checked);
}
@Test
@@ -209,5 +220,15 @@
assertEquals(statement.getOriginalDeposits().size(), 1);
assertEquals(statement.getParts().size(), 5);
assertEquals(statement.getState().size(), 1);
+
+ List<ServerResource> ods = statement.getOriginalDeposits();
+ boolean checked = false;
+ for (ServerResource od : ods)
+ {
+ assertEquals(od.getDepositedBy(), this.user);
+ assertEquals(od.getDepositedOnBehalfOf(), this.obo);
+ checked = true;
+ }
+ assertTrue(checked);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-03-24 11:56:25
|
Revision: 483
http://sword-app.svn.sourceforge.net/sword-app/?rev=483&view=rev
Author: richard-jones
Date: 2012-03-24 11:56:14 +0000 (Sat, 24 Mar 2012)
Log Message:
-----------
validation and warnings for inadvisable deposits, plus test enhancements around packaging
Modified Paths:
--------------
JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java
JavaClient2.0/src/test/java/org/swordapp/client/test/SSSSemiUnits.java
JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java
Modified: JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java 2012-03-24 11:02:34 UTC (rev 482)
+++ JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java 2012-03-24 11:56:14 UTC (rev 483)
@@ -192,7 +192,7 @@
public DepositReceipt deposit(SWORDCollection collection, Deposit deposit)
throws SWORDClientException, SWORDError, ProtocolViolationException
{
- return this.deposit(collection.getHref().toString(), deposit, null);
+ return this.deposit(collection, deposit, null);
}
public DepositReceipt deposit(String targetURL, Deposit deposit)
@@ -210,6 +210,15 @@
" mediation; an error in response is likely. Provide an AuthCredentials object with " +
"valid contents on next run");
}
+ if (deposit.getPackaging() != null)
+ {
+ if (!collection.getAcceptPackaging().contains(deposit.getPackaging()))
+ {
+ log.warn("About to attempt a deposit of a package format that the collection does not " +
+ "support; an error response is likely. Check the collection object for acceptable " +
+ "package formats before next run");
+ }
+ }
return this.deposit(collection.getHref().toString(), deposit, auth);
}
@@ -1252,7 +1261,7 @@
throw new ProtocolViolationException("Unexpected response code " + status);
}
}
-
+
public Content getContent(SwordIdentifier contentId)
throws SWORDClientException, ProtocolViolationException, SWORDError
{
Modified: JavaClient2.0/src/test/java/org/swordapp/client/test/SSSSemiUnits.java
===================================================================
--- JavaClient2.0/src/test/java/org/swordapp/client/test/SSSSemiUnits.java 2012-03-24 11:02:34 UTC (rev 482)
+++ JavaClient2.0/src/test/java/org/swordapp/client/test/SSSSemiUnits.java 2012-03-24 11:56:14 UTC (rev 483)
@@ -17,6 +17,7 @@
import org.swordapp.client.UriRegistry;
import java.io.FileInputStream;
+import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.*;
@@ -92,13 +93,22 @@
assertEquals(ma.size(), 1);
assertEquals(sa.size(), 1);
assertEquals(ma.get(0), sa.get(0));
+ assertTrue("*/*".equals(ma.get(0)));
assertTrue(collection.getCollectionPolicy() != null);
assertTrue(collection.allowsMediation());
- assertTrue(collection.getTreatment() != null);
+ assertTrue("Treatment description".equals(collection.getTreatment()));
List<String> ap = collection.getAcceptPackaging();
- assertTrue(ap.size() > 0);
+ assertTrue(ap.size() == 3);
+ List<String> expectedPackaging = new ArrayList<String>();
+ expectedPackaging.add("http://purl.org/net/sword/package/SimpleZip");
+ expectedPackaging.add("http://purl.org/net/sword/package/Binary");
+ expectedPackaging.add("http://purl.org/net/sword/package/METSDSpaceSIP");
+ for (String packaging : ap)
+ {
+ assertTrue(expectedPackaging.contains(packaging));
+ }
List<String> ss = collection.getSubServices();
assertTrue(ss.size() == 1);
@@ -132,6 +142,7 @@
assertTrue(receipt.getOREStatementLink() != null);
assertTrue(receipt.getOriginalDepositLink() != null);
assertEquals(receipt.getPackaging().size(), 1);
+ assertTrue(receipt.getPackaging().contains(UriRegistry.PACKAGE_SIMPLE_ZIP));
assertTrue(receipt.getSplashPageLink() != null);
assertTrue(receipt.getStatementLink("application/rdf+xml") != null);
assertTrue(receipt.getStatementLink("application/atom+xml;type=feed") != null);
Modified: JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java
===================================================================
--- JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java 2012-03-24 11:02:34 UTC (rev 482)
+++ JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java 2012-03-24 11:56:14 UTC (rev 483)
@@ -995,31 +995,6 @@
/* Python tests to mimic
- def test_33_get_ore_statement(self):
- conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
- conn.get_service_document()
- col = conn.sd.workspaces[0][1][0]
- e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
- with open(PACKAGE) as pkg:
- receipt = conn.create(col_iri = col.href,
- metadata_entry = e,
- payload=pkg,
- mimetype=PACKAGE_MIME,
- filename="example.zip",
- packaging = 'http://purl.org/net/sword/package/SimpleZip')
-
- # ensure that we have a receipt (the server may not give us one
- # by default)
- edit_iri = receipt.location
- receipt = conn.get_deposit_receipt(edit_iri)
-
- assert receipt.ore_statement_iri is not None
-
- # get the statement
- statement = conn.get_ore_sword_statement(receipt.ore_statement_iri)
-
- assert isinstance(statement, Ore_Sword_Statement)
-
def test_34_complete_deposit(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
conn.get_service_document()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-03-24 11:02:40
|
Revision: 482
http://sword-app.svn.sourceforge.net/sword-app/?rev=482&view=rev
Author: richard-jones
Date: 2012-03-24 11:02:34 +0000 (Sat, 24 Mar 2012)
Log Message:
-----------
add syntactic sugar for get, put, delete on arbitrary uris with support for sword headers, as per 6.10 and 6.11)
Modified Paths:
--------------
JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java
Modified: JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java 2012-03-23 15:58:14 UTC (rev 481)
+++ JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java 2012-03-24 11:02:34 UTC (rev 482)
@@ -911,6 +911,31 @@
}
}
+ // These methods are syntactic sugar for speaking to individual files if such an operation
+ // is supported by the server. They re-use existing calls (e.g. to getContent or replaceMedia)
+ // but with the URLs of the file resource rather than those of the standard sword urls
+ // (see sections 6.10 and 6.11 of the spec)
+
+ Content getFile(String url, String mimeType, AuthCredentials auth)
+ throws SWORDClientException, ProtocolViolationException, SWORDError
+ {
+ return this.getContent(url, mimeType, null, auth);
+ }
+
+ SwordResponse replaceFile(String url, Deposit deposit, AuthCredentials auth)
+ throws SWORDClientException, ProtocolViolationException, SWORDError
+ {
+ return this.replaceMedia(url, deposit, auth);
+ }
+
+ SwordResponse deleteFile(String url, AuthCredentials auth)
+ throws SWORDClientException, ProtocolViolationException, SWORDError
+ {
+ return this.delete(url, auth);
+ }
+
+ /////////////////////////////////////////////////////////////////////////////////////////
+
public DepositReceipt complete(DepositReceipt receipt, AuthCredentials auth)
throws SWORDClientException, ProtocolViolationException, SWORDError
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-03-23 15:58:25
|
Revision: 481
http://sword-app.svn.sourceforge.net/sword-app/?rev=481&view=rev
Author: richard-jones
Date: 2012-03-23 15:58:14 +0000 (Fri, 23 Mar 2012)
Log Message:
-----------
fix ORE Statement support, plus associated tests
Modified Paths:
--------------
JavaClient2.0/src/main/java/org/swordapp/client/AtomStatement.java
JavaClient2.0/src/main/java/org/swordapp/client/OreStatement.java
JavaClient2.0/src/main/java/org/swordapp/client/UriRegistry.java
JavaClient2.0/src/test/java/org/swordapp/client/test/SSSSemiUnits.java
JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java
Added Paths:
-----------
JavaClient2.0/src/main/java/org/swordapp/client/SQName.java
Modified: JavaClient2.0/src/main/java/org/swordapp/client/AtomStatement.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/AtomStatement.java 2012-03-17 18:41:19 UTC (rev 480)
+++ JavaClient2.0/src/main/java/org/swordapp/client/AtomStatement.java 2012-03-23 15:58:14 UTC (rev 481)
@@ -251,23 +251,32 @@
* @return
* @throws SWORDClientException
*/
- public List<ResourceState> getState() throws SWORDClientException
+ public List<ResourceState> getState()
+ throws SWORDClientException
+
{
- List<ResourceState> states = new ArrayList<ResourceState>();
- List<Category> cats = this.feed.getCategories();
- String comparator = UriRegistry.SWORD_STATE.getNamespaceURI() + UriRegistry.SWORD_STATE.getLocalPart();
- for (Category cat : cats)
- {
- if (comparator.equals(cat.getScheme().toString()))
- {
- ResourceState state = new ResourceState();
- state.setIri(new IRI(cat.getTerm()));
- state.setDescription(cat.getText());
- states.add(state);
- }
- }
- return states;
- }
+ try
+ {
+ List<ResourceState> states = new ArrayList<ResourceState>();
+ List<Category> cats = this.feed.getCategories();
+ String comparator = UriRegistry.SWORD_STATE.toURI().toString();
+ for (Category cat : cats)
+ {
+ if (comparator.equals(cat.getScheme().toString()))
+ {
+ ResourceState state = new ResourceState();
+ state.setIri(new IRI(cat.getTerm()));
+ state.setDescription(cat.getText());
+ states.add(state);
+ }
+ }
+ return states;
+ }
+ catch (URISyntaxException e)
+ {
+ throw new SWORDClientException(e);
+ }
+ }
public String getContentMD5()
throws SWORDClientException
Modified: JavaClient2.0/src/main/java/org/swordapp/client/OreStatement.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/OreStatement.java 2012-03-17 18:41:19 UTC (rev 480)
+++ JavaClient2.0/src/main/java/org/swordapp/client/OreStatement.java 2012-03-23 15:58:14 UTC (rev 481)
@@ -83,107 +83,118 @@
{
List<ServerResource> parts = new ArrayList<ServerResource>();
List<AggregatedResource> ars = this.rem.getAggregatedResources();
- for (AggregatedResource ar : ars)
- {
- ServerResource resource = new ServerResource();
+ for (AggregatedResource ar : ars)
+ {
+ ServerResource resource = new ServerResource();
resource.setUri(ar.getURI());
+ this.populateResource(ar, resource);
+ parts.add(resource);
+ }
+ return parts;
+ }
+ catch (OREException e)
+ {
+ throw new SWORDClientException(e);
+ }
+ }
- TripleSelector packaging = new TripleSelector(ar.getURI(), new URI(UriRegistry.SWORD_PACKAGING.toString()), null);
- TripleSelector depositedOn = new TripleSelector(ar.getURI(), new URI(UriRegistry.SWORD_DEPOSITED_ON.toString()), null);
- TripleSelector depositedBy = new TripleSelector(ar.getURI(), new URI(UriRegistry.SWORD_DEPOSITED_BY.toString()), null);
- TripleSelector depositedObo = new TripleSelector(ar.getURI(), new URI(UriRegistry.SWORD_DEPOSITED_ON_BEHALF_OF.toString()), null);
+ private void populateResource(AggregatedResource ar, ServerResource resource)
+ throws SWORDClientException
+ {
+ try
+ {
+ TripleSelector packaging = new TripleSelector(ar.getURI(), UriRegistry.SWORD_PACKAGING.toURI(), null);
+ TripleSelector depositedOn = new TripleSelector(ar.getURI(), UriRegistry.SWORD_DEPOSITED_ON.toURI(), null);
+ TripleSelector depositedBy = new TripleSelector(ar.getURI(), UriRegistry.SWORD_DEPOSITED_BY.toURI(), null);
+ TripleSelector depositedObo = new TripleSelector(ar.getURI(), UriRegistry.SWORD_DEPOSITED_ON_BEHALF_OF.toURI(), null);
- List<Triple> pt = ar.listTriples(packaging);
- List<Triple> dot = ar.listAllTriples(depositedOn);
- List<Triple> dbt = ar.listTriples(depositedBy);
- List<Triple> dobot = ar.listTriples(depositedObo);
+ List<Triple> pt = ar.listTriples(packaging);
+ List<Triple> dot = ar.listAllTriples(depositedOn);
+ List<Triple> dbt = ar.listTriples(depositedBy);
+ List<Triple> dobot = ar.listTriples(depositedObo);
- List<String> packs = new ArrayList<String>();
- if (pt != null && pt.size() > 0)
- {
- for (Triple triple : pt)
- {
- if (triple.isLiteral())
- {
- packs.add(triple.getObjectLiteral());
- }
- else
- {
- packs.add(triple.getObject().getURI().toString());
- }
- }
- }
- else
- {
- packs.add(UriRegistry.PACKAGE_SIMPLE_ZIP);
- }
- resource.setPackaging(packs);
+ List<String> packs = new ArrayList<String>();
+ if (pt != null && pt.size() > 0)
+ {
+ for (Triple triple : pt)
+ {
+ if (triple.isLiteral())
+ {
+ packs.add(triple.getObjectLiteral());
+ }
+ else
+ {
+ packs.add(triple.getObjectURI().toString());
+ }
+ }
+ }
+ else
+ {
+ packs.add(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ }
+ resource.setPackaging(packs);
- Date depositedDate = null;
- if (dot != null && dot.size() > 0)
- {
- for (Triple triple : dot)
- {
- if (triple.isLiteral())
- {
- try
- {
- depositedDate = DateParser.parse(triple.getObjectLiteral());
- }
- catch (OREParserException e)
- {
- // no reason that this should kill the parser
- continue;
- }
- }
- // we only want one
- break;
- }
- }
- resource.setDepositedOn(depositedDate);
+ Date depositedDate = null;
+ if (dot != null && dot.size() > 0)
+ {
+ for (Triple triple : dot)
+ {
+ if (triple.isLiteral())
+ {
+ try
+ {
+ depositedDate = DateParser.parse(triple.getObjectLiteral());
+ }
+ catch (OREParserException e)
+ {
+ // no reason that this should kill the parser
+ continue;
+ }
+ }
+ // we only want one
+ break;
+ }
+ }
+ resource.setDepositedOn(depositedDate);
- String depositor = null;
- if (dbt != null && dbt.size() > 0)
- {
- for (Triple triple : dbt)
- {
- if (triple.isLiteral())
- {
- depositor = triple.getObjectLiteral();
- }
- else
- {
- depositor = triple.getObject().getURI().toString();
- }
- // we only want one
- break;
- }
- }
- resource.setDepositedBy(depositor);
+ String depositor = null;
+ if (dbt != null && dbt.size() > 0)
+ {
+ for (Triple triple : dbt)
+ {
+ if (triple.isLiteral())
+ {
+ depositor = triple.getObjectLiteral();
+ }
+ else
+ {
+ depositor = triple.getObjectURI().toString();
+ }
+ // we only want one
+ break;
+ }
+ }
+ resource.setDepositedBy(depositor);
- String obo = null;
- if (dobot != null && dobot.size() > 0)
- {
- for (Triple triple : dobot)
- {
- if (triple.isLiteral())
- {
- obo = triple.getObjectLiteral();
- }
- else
- {
- obo = triple.getObject().getURI().toString();
- }
- // we only want one
- break;
- }
- }
- resource.setDepositedOnBehalfOf(obo);
-
- parts.add(resource);
- }
- return parts;
- }
+ String obo = null;
+ if (dobot != null && dobot.size() > 0)
+ {
+ for (Triple triple : dobot)
+ {
+ if (triple.isLiteral())
+ {
+ obo = triple.getObjectLiteral();
+ }
+ else
+ {
+ obo = triple.getObjectURI().toString();
+ }
+ // we only want one
+ break;
+ }
+ }
+ resource.setDepositedOnBehalfOf(obo);
+ }
catch (OREException e)
{
throw new SWORDClientException(e);
@@ -192,126 +203,39 @@
{
throw new SWORDClientException(e);
}
- }
+ }
- @Override
public List<ServerResource> getOriginalDeposits()
throws SWORDClientException
{
try
{
List<ServerResource> ods = new ArrayList<ServerResource>();
- List<AggregatedResource> ars = this.rem.getAggregatedResources();
- TripleSelector selector = new TripleSelector(null, new URI(UriRegistry.REL_ORIGINAL_DEPOSIT), null);
- for (AggregatedResource ar : ars)
- {
- List<Triple> odt = ar.listTriples(selector);
- if (odt == null || odt.size() == 0)
- {
- // this is not an aggregated resource which was an original depoisit
- continue;
- }
- // if we arrive here, then we know that this Aggregated Resource represents
- // an original deposit
+ Aggregation agg = this.rem.getAggregation();
+ TripleSelector selector = new TripleSelector(agg.getURI(), new URI(UriRegistry.REL_ORIGINAL_DEPOSIT), null);
+ List<Triple> odt = agg.listTriples(selector);
+ if (odt == null || odt.size() == 0)
+ {
+ // no original deposits in this object
+ return null;
+ }
- ServerResource resource = new ServerResource();
- resource.setUri(ar.getURI());
-
- TripleSelector packaging = new TripleSelector(ar.getURI(), new URI(UriRegistry.SWORD_PACKAGING.toString()), null);
- TripleSelector depositedOn = new TripleSelector(ar.getURI(), new URI(UriRegistry.SWORD_DEPOSITED_ON.toString()), null);
- TripleSelector depositedBy = new TripleSelector(ar.getURI(), new URI(UriRegistry.SWORD_DEPOSITED_BY.toString()), null);
- TripleSelector depositedObo = new TripleSelector(ar.getURI(), new URI(UriRegistry.SWORD_DEPOSITED_ON_BEHALF_OF.toString()), null);
-
- List<Triple> pt = ar.listTriples(packaging);
- List<Triple> dot = ar.listAllTriples(depositedOn);
- List<Triple> dbt = ar.listTriples(depositedBy);
- List<Triple> dobot = ar.listTriples(depositedObo);
-
- List<String> packs = new ArrayList<String>();
- if (pt != null && pt.size() > 0)
- {
- for (Triple triple : pt)
- {
- if (triple.isLiteral())
- {
- packs.add(triple.getObjectLiteral());
- }
- else
- {
- packs.add(triple.getObject().getURI().toString());
- }
- }
- }
- else
- {
- packs.add(UriRegistry.PACKAGE_SIMPLE_ZIP);
- }
- resource.setPackaging(packs);
-
- Date depositedDate = null;
- if (dot != null && dot.size() > 0)
- {
- for (Triple triple : dot)
- {
- if (triple.isLiteral())
- {
- try
- {
- depositedDate = DateParser.parse(triple.getObjectLiteral());
- }
- catch (OREParserException e)
- {
- // no reason that this should kill the parser
- continue;
- }
- }
- // we only want one
- break;
- }
- }
- resource.setDepositedOn(depositedDate);
-
- String depositor = null;
- if (dbt != null && dbt.size() > 0)
- {
- for (Triple triple : dbt)
- {
- if (triple.isLiteral())
- {
- depositor = triple.getObjectLiteral();
- }
- else
- {
- depositor = triple.getObject().getURI().toString();
- }
- // we only want one
- break;
- }
- }
- resource.setDepositedBy(depositor);
-
- String obo = null;
- if (dobot != null && dobot.size() > 0)
- {
- for (Triple triple : dobot)
- {
- if (triple.isLiteral())
- {
- obo = triple.getObjectLiteral();
- }
- else
- {
- obo = triple.getObject().getURI().toString();
- }
- // we only want one
- break;
- }
- }
- resource.setDepositedOnBehalfOf(obo);
-
- ods.add(resource);
- }
- return ods;
+ List<AggregatedResource> ars = this.rem.getAggregatedResources();
+ for (Triple od : odt)
+ {
+ ServerResource resource = new ServerResource();
+ resource.setUri(od.getObjectURI());
+ for (AggregatedResource ar : ars)
+ {
+ if (ar.getURI().toString().equals(od.getObjectURI().toString()))
+ {
+ this.populateResource(ar, resource);
+ break;
+ }
+ }
+ ods.add(resource);
+ }
+ return ods;
}
catch (OREException e)
{
@@ -323,14 +247,13 @@
}
}
- @Override
public List<ResourceState> getState()
throws SWORDClientException
{
try
{
Aggregation agg = this.rem.getAggregation();
- TripleSelector state = new TripleSelector(agg.getURI(), new URI(UriRegistry.SWORD_STATE.toString()), null);
+ TripleSelector state = new TripleSelector(agg.getURI(), UriRegistry.SWORD_STATE.toURI(), null);
List<Triple> states = agg.listTriples(state);
if (states == null || states.size() == 0)
{
@@ -344,7 +267,7 @@
rs.setIri(new IRI(triple.getObjectURI().toString()));
// find the state description
- TripleSelector desc = new TripleSelector(triple.getObjectURI(), new URI(UriRegistry.SWORD_STATE_DESCRIPTION.toString()), null);
+ TripleSelector desc = new TripleSelector(triple.getObjectURI(), UriRegistry.SWORD_STATE_DESCRIPTION.toURI(), null);
List<Triple> dts = this.rem.listAllTriples(desc);
if (dts != null)
{
@@ -375,14 +298,12 @@
}
}
- @Override
public String getContentMD5()
throws SWORDClientException
{
return this.contentMD5;
}
- @Override
public Date getLastModified() throws SWORDClientException
{
return this.lastModified;
Added: JavaClient2.0/src/main/java/org/swordapp/client/SQName.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/SQName.java (rev 0)
+++ JavaClient2.0/src/main/java/org/swordapp/client/SQName.java 2012-03-23 15:58:14 UTC (rev 481)
@@ -0,0 +1,24 @@
+package org.swordapp.client;
+
+import javax.xml.namespace.QName;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+public class SQName extends QName
+ {
+ public SQName(java.lang.String namespaceURI, java.lang.String localPart)
+ {
+ super(namespaceURI, localPart);
+ }
+
+ public SQName(java.lang.String namespaceURI, java.lang.String localPart, java.lang.String prefix)
+ {
+ super(namespaceURI, localPart, prefix);
+ }
+
+ public URI toURI()
+ throws URISyntaxException
+ {
+ return new URI(this.getNamespaceURI() + this.getLocalPart());
+ }
+ }
Modified: JavaClient2.0/src/main/java/org/swordapp/client/UriRegistry.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/UriRegistry.java 2012-03-17 18:41:19 UTC (rev 480)
+++ JavaClient2.0/src/main/java/org/swordapp/client/UriRegistry.java 2012-03-23 15:58:14 UTC (rev 481)
@@ -1,7 +1,5 @@
package org.swordapp.client;
-import javax.xml.namespace.QName;
-
public class UriRegistry
{
// Namespaces
@@ -12,22 +10,22 @@
public static String ATOM_NAMESPACE = "http://www.w3.org/2005/Atom";
// QNames for Extension Elements
- public static QName SWORD_VERSION = new QName(SWORD_TERMS_NAMESPACE, "version");
- public static QName SWORD_MAX_UPLOAD_SIZE = new QName(SWORD_TERMS_NAMESPACE, "maxUploadSize");
- public static QName SWORD_COLLECTION_POLICY = new QName(SWORD_TERMS_NAMESPACE, "collectionPolicy");
- public static QName SWORD_MEDIATION = new QName(SWORD_TERMS_NAMESPACE, "mediation");
- public static QName SWORD_TREATMENT = new QName(SWORD_TERMS_NAMESPACE, "treatment");
- public static QName SWORD_ACCEPT_PACKAGING = new QName(SWORD_TERMS_NAMESPACE, "acceptPackaging");
- public static QName SWORD_SERVICE = new QName(SWORD_TERMS_NAMESPACE, "service");
- public static QName SWORD_PACKAGING = new QName(SWORD_TERMS_NAMESPACE, "packaging");
- public static QName SWORD_VERBOSE_DESCRIPTION = new QName(SWORD_TERMS_NAMESPACE, "verboseDescription");
- public static QName DC_ABSTRACT = new QName(DC_NAMESPACE, "abstract");
+ public static SQName SWORD_VERSION = new SQName(SWORD_TERMS_NAMESPACE, "version");
+ public static SQName SWORD_MAX_UPLOAD_SIZE = new SQName(SWORD_TERMS_NAMESPACE, "maxUploadSize");
+ public static SQName SWORD_COLLECTION_POLICY = new SQName(SWORD_TERMS_NAMESPACE, "collectionPolicy");
+ public static SQName SWORD_MEDIATION = new SQName(SWORD_TERMS_NAMESPACE, "mediation");
+ public static SQName SWORD_TREATMENT = new SQName(SWORD_TERMS_NAMESPACE, "treatment");
+ public static SQName SWORD_ACCEPT_PACKAGING = new SQName(SWORD_TERMS_NAMESPACE, "acceptPackaging");
+ public static SQName SWORD_SERVICE = new SQName(SWORD_TERMS_NAMESPACE, "service");
+ public static SQName SWORD_PACKAGING = new SQName(SWORD_TERMS_NAMESPACE, "packaging");
+ public static SQName SWORD_VERBOSE_DESCRIPTION = new SQName(SWORD_TERMS_NAMESPACE, "verboseDescription");
+ public static SQName DC_ABSTRACT = new SQName(DC_NAMESPACE, "abstract");
- public static QName SWORD_DEPOSITED_BY = new QName(SWORD_TERMS_NAMESPACE, "depositedBy");
- public static QName SWORD_DEPOSITED_ON = new QName(SWORD_TERMS_NAMESPACE, "depositedOn");
- public static QName SWORD_DEPOSITED_ON_BEHALF_OF = new QName(SWORD_TERMS_NAMESPACE, "depositedOnBehalfOf");
- public static QName SWORD_STATE = new QName(SWORD_TERMS_NAMESPACE, "state");
- public static QName SWORD_STATE_DESCRIPTION = new QName(SWORD_TERMS_NAMESPACE, "stateDescription");
+ public static SQName SWORD_DEPOSITED_BY = new SQName(SWORD_TERMS_NAMESPACE, "depositedBy");
+ public static SQName SWORD_DEPOSITED_ON = new SQName(SWORD_TERMS_NAMESPACE, "depositedOn");
+ public static SQName SWORD_DEPOSITED_ON_BEHALF_OF = new SQName(SWORD_TERMS_NAMESPACE, "depositedOnBehalfOf");
+ public static SQName SWORD_STATE = new SQName(SWORD_TERMS_NAMESPACE, "state");
+ public static SQName SWORD_STATE_DESCRIPTION = new SQName(SWORD_TERMS_NAMESPACE, "stateDescription");
// rel values
public static String REL_STATEMENT = SWORD_TERMS_NAMESPACE + "statement";
Modified: JavaClient2.0/src/test/java/org/swordapp/client/test/SSSSemiUnits.java
===================================================================
--- JavaClient2.0/src/test/java/org/swordapp/client/test/SSSSemiUnits.java 2012-03-17 18:41:19 UTC (rev 480)
+++ JavaClient2.0/src/test/java/org/swordapp/client/test/SSSSemiUnits.java 2012-03-23 15:58:14 UTC (rev 481)
@@ -8,6 +8,7 @@
import org.swordapp.client.ClientConfiguration;
import org.swordapp.client.Deposit;
import org.swordapp.client.DepositReceipt;
+import org.swordapp.client.OreStatement;
import org.swordapp.client.SWORDClient;
import org.swordapp.client.SWORDCollection;
import org.swordapp.client.SWORDWorkspace;
@@ -168,4 +169,34 @@
assertEquals(statement.getParts().size(), 5);
assertEquals(statement.getState().size(), 1);
}
+
+ @Test
+ public void oreStatement()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass, this.obo));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
+
+ Deposit deposit = new Deposit();
+ deposit.setFile(new FileInputStream(this.file));
+ deposit.setMimeType("application/zip");
+ deposit.setFilename("example.zip");
+ deposit.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ deposit.setMd5(this.fileMd5);
+
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass, this.obo));
+ receipt = client.getDepositReceipt(receipt.getLocation(), new AuthCredentials(this.user, this.pass, this.obo));
+
+ assertTrue(receipt.getOREStatementLink() != null);
+
+ Statement statement = client.getStatement(receipt, "application/rdf+xml", new AuthCredentials(this.user, this.pass, this.obo));
+
+ assertTrue(statement instanceof OreStatement);
+ assertNotNull(((OreStatement) statement).getResourceMap());
+ assertEquals(statement.getMimeType(), "application/rdf+xml");
+ assertEquals(statement.getOriginalDeposits().size(), 1);
+ assertEquals(statement.getParts().size(), 5);
+ assertEquals(statement.getState().size(), 1);
+ }
}
Modified: JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java
===================================================================
--- JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java 2012-03-17 18:41:19 UTC (rev 480)
+++ JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java 2012-03-23 15:58:14 UTC (rev 481)
@@ -13,6 +13,7 @@
import org.swordapp.client.Deposit;
import org.swordapp.client.DepositReceipt;
import org.swordapp.client.EntryPart;
+import org.swordapp.client.OreStatement;
import org.swordapp.client.SWORDClient;
import org.swordapp.client.SWORDClientException;
import org.swordapp.client.SWORDCollection;
@@ -967,6 +968,31 @@
assertTrue(statement instanceof AtomStatement);
}
+ @Test
+ public void getOreStatement()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass, this.obo));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
+
+ Deposit deposit = new Deposit();
+ deposit.setFile(new FileInputStream(this.file));
+ deposit.setMimeType("application/zip");
+ deposit.setFilename("example.zip");
+ deposit.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ deposit.setMd5(this.fileMd5);
+
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass, this.obo));
+ receipt = client.getDepositReceipt(receipt.getLocation(), new AuthCredentials(this.user, this.pass, this.obo));
+
+ assertTrue(receipt.getOREStatementLink() != null);
+
+ Statement statement = client.getStatement(receipt, "application/rdf+xml", new AuthCredentials(this.user, this.pass, this.obo));
+
+ assertTrue(statement instanceof OreStatement);
+ }
+
/* Python tests to mimic
def test_33_get_ore_statement(self):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-03-17 18:41:26
|
Revision: 480
http://sword-app.svn.sourceforge.net/sword-app/?rev=480&view=rev
Author: richard-jones
Date: 2012-03-17 18:41:19 +0000 (Sat, 17 Mar 2012)
Log Message:
-----------
add a lot more (unit) tests, plus associated api enhancements for usability and bug fixes
Modified Paths:
--------------
JavaClient2.0/src/main/java/org/swordapp/client/AtomStatement.java
JavaClient2.0/src/main/java/org/swordapp/client/ErrorHandler.java
JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java
JavaClient2.0/src/test/java/org/swordapp/client/test/ClientTests.java
JavaClient2.0/src/test/java/org/swordapp/client/test/SSSSemiUnits.java
JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java
Added Paths:
-----------
JavaClient2.0/src/main/java/org/swordapp/client/StatementFactory.java
Modified: JavaClient2.0/src/main/java/org/swordapp/client/AtomStatement.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/AtomStatement.java 2012-03-17 18:40:31 UTC (rev 479)
+++ JavaClient2.0/src/main/java/org/swordapp/client/AtomStatement.java 2012-03-17 18:41:19 UTC (rev 480)
@@ -64,7 +64,6 @@
* @throws SWORDClientException
* @throws StatementParseException
*/
- @Override
public void parse(ClientResponse resp)
throws SWORDClientException, StatementParseException
{
@@ -94,7 +93,6 @@
*
* @return
*/
- @Override
public String getMimeType()
{
return "application/atom+xml;type=feed";
@@ -106,7 +104,6 @@
* @return
* @throws SWORDClientException
*/
- @Override
public List<ServerResource> getParts()
throws SWORDClientException
{
@@ -134,8 +131,11 @@
try
{
Element depositedOn = entry.getExtension(UriRegistry.SWORD_DEPOSITED_ON);
- Date date = DateParser.parse(depositedOn.getText());
- resource.setDepositedOn(date);
+ if (depositedOn != null)
+ {
+ Date date = DateParser.parse(depositedOn.getText());
+ resource.setDepositedOn(date);
+ }
}
catch (OREParserException e)
{
@@ -143,10 +143,16 @@
}
Element depositedBy = entry.getExtension(UriRegistry.SWORD_DEPOSITED_BY);
- resource.setDepositedBy(depositedBy.getText());
+ if (depositedBy != null)
+ {
+ resource.setDepositedBy(depositedBy.getText());
+ }
Element depositedObo = entry.getExtension(UriRegistry.SWORD_DEPOSITED_ON_BEHALF_OF);
- resource.setDepositedOnBehalfOf(depositedObo.getText());
+ if (depositedObo != null)
+ {
+ resource.setDepositedOnBehalfOf(depositedObo.getText());
+ }
parts.add(resource);
}
@@ -165,7 +171,6 @@
* @return
* @throws SWORDClientException
*/
- @Override
public List<ServerResource> getOriginalDeposits() throws SWORDClientException
{
try
@@ -207,8 +212,11 @@
try
{
Element depositedOn = entry.getExtension(UriRegistry.SWORD_DEPOSITED_ON);
- Date date = DateParser.parse(depositedOn.getText());
- resource.setDepositedOn(date);
+ if (depositedOn != null)
+ {
+ Date date = DateParser.parse(depositedOn.getText());
+ resource.setDepositedOn(date);
+ }
}
catch (OREParserException e)
{
@@ -216,10 +224,16 @@
}
Element depositedBy = entry.getExtension(UriRegistry.SWORD_DEPOSITED_BY);
- resource.setDepositedBy(depositedBy.getText());
+ if (depositedBy != null)
+ {
+ resource.setDepositedBy(depositedBy.getText());
+ }
Element depositedObo = entry.getExtension(UriRegistry.SWORD_DEPOSITED_ON_BEHALF_OF);
- resource.setDepositedOnBehalfOf(depositedObo.getText());
+ if (depositedObo != null)
+ {
+ resource.setDepositedOnBehalfOf(depositedObo.getText());
+ }
parts.add(resource);
}
@@ -237,14 +251,14 @@
* @return
* @throws SWORDClientException
*/
- @Override
public List<ResourceState> getState() throws SWORDClientException
{
List<ResourceState> states = new ArrayList<ResourceState>();
List<Category> cats = this.feed.getCategories();
+ String comparator = UriRegistry.SWORD_STATE.getNamespaceURI() + UriRegistry.SWORD_STATE.getLocalPart();
for (Category cat : cats)
{
- if (UriRegistry.SWORD_STATE.toString().equals(cat.getScheme()))
+ if (comparator.equals(cat.getScheme().toString()))
{
ResourceState state = new ResourceState();
state.setIri(new IRI(cat.getTerm()));
@@ -255,14 +269,12 @@
return states;
}
- @Override
public String getContentMD5()
throws SWORDClientException
{
return this.contentMD5;
}
- @Override
public Date getLastModified() throws SWORDClientException
{
return this.lastModified;
Modified: JavaClient2.0/src/main/java/org/swordapp/client/ErrorHandler.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/ErrorHandler.java 2012-03-17 18:40:31 UTC (rev 479)
+++ JavaClient2.0/src/main/java/org/swordapp/client/ErrorHandler.java 2012-03-17 18:41:19 UTC (rev 480)
@@ -15,22 +15,25 @@
{
try
{
+ int status = resp.getStatus();
+
// get hold of the XML content of the response if available
InputStream inputStream = resp.getInputStream();
Builder parser = new Builder();
- Document doc = parser.build(inputStream);
-
- int status = resp.getStatus();
-
- return new SWORDError(status, doc);
+ try
+ {
+ Document doc = parser.build(inputStream);
+ return new SWORDError(status, doc);
+ }
+ catch (ParsingException e)
+ {
+ // just ignore the body, probably content is erroneous
+ return new SWORDError(status, null);
+ }
}
catch (IOException e)
{
throw new SWORDClientException(e);
}
- catch (ParsingException e)
- {
- throw new SWORDClientException(e);
- }
}
}
Modified: JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java 2012-03-17 18:40:31 UTC (rev 479)
+++ JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java 2012-03-17 18:41:19 UTC (rev 480)
@@ -452,6 +452,12 @@
}
}
+ public SwordResponse replace(DepositReceipt receipt, Deposit deposit, AuthCredentials auth)
+ throws SWORDClientException, SWORDError, ProtocolViolationException
+ {
+ return this.replace(receipt.getEditLink().getHref(), deposit, auth);
+ }
+
public SwordResponse replace(String editURL, Deposit deposit, AuthCredentials auth)
throws SWORDClientException, SWORDError, ProtocolViolationException
{
@@ -558,6 +564,18 @@
}
}
+ public SwordResponse deleteContent(DepositReceipt receipt, AuthCredentials auth)
+ throws SWORDClientException, SWORDError, ProtocolViolationException
+ {
+ return this.delete(receipt.getEditMediaLink().getHref(), auth);
+ }
+
+ public SwordResponse deleteContainer(DepositReceipt receipt, AuthCredentials auth)
+ throws SWORDClientException, SWORDError, ProtocolViolationException
+ {
+ return this.delete(receipt.getEditLink().getHref(), auth);
+ }
+
public SwordResponse delete(String deleteUrl, AuthCredentials auth)
throws SWORDClientException, SWORDError, ProtocolViolationException
{
@@ -626,6 +644,12 @@
}
}
+ public SwordResponse addToMediaResource(DepositReceipt receipt, Deposit deposit, AuthCredentials auth)
+ throws SWORDClientException, SWORDError, ProtocolViolationException
+ {
+ return this.addToMediaResource(receipt.getEditMediaLink().getHref(), deposit, auth);
+ }
+
public SwordResponse addToMediaResource(String editMediaURL, Deposit deposit, AuthCredentials auth)
throws SWORDClientException, SWORDError, ProtocolViolationException
{
@@ -666,6 +690,7 @@
http.addContentDisposition(options, deposit.getFilename());
http.addContentMd5(options, deposit.getMd5());
http.addMetadataRelevant(options, deposit.isMetadataRelevant());
+ http.addPackaging(options, deposit.getPackaging());
// prepare the content to be delivered
InputStreamRequestEntity media = new InputStreamRequestEntity(deposit.getFile(), deposit.getMimeType());
@@ -737,6 +762,12 @@
}
}
+ public DepositReceipt addToContainer(DepositReceipt receipt, Deposit deposit, AuthCredentials auth)
+ throws SWORDClientException, SWORDError, ProtocolViolationException
+ {
+ return this.addToContainer(receipt.getEditLink().getHref(), deposit, auth);
+ }
+
public DepositReceipt addToContainer(String editURL, Deposit deposit, AuthCredentials auth)
throws SWORDClientException, SWORDError, ProtocolViolationException
{
@@ -1119,6 +1150,18 @@
}
}
+ public Statement getStatement(DepositReceipt receipt, String type, AuthCredentials auth)
+ throws SWORDClientException, StatementParseException, ProtocolViolationException, SWORDError
+ {
+ SwordIdentifier si = receipt.getStatementLink(type);
+ if (si == null)
+ {
+ return null;
+ }
+ Statement shell = StatementFactory.getStatementShell(type);
+ return this.getStatement(si.getHref(), shell, auth);
+ }
+
public Statement getStatement(String statementUrl, Statement statementShell, AuthCredentials auth)
throws SWORDClientException, StatementParseException, ProtocolViolationException, SWORDError
{
Added: JavaClient2.0/src/main/java/org/swordapp/client/StatementFactory.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/StatementFactory.java (rev 0)
+++ JavaClient2.0/src/main/java/org/swordapp/client/StatementFactory.java 2012-03-17 18:41:19 UTC (rev 480)
@@ -0,0 +1,17 @@
+package org.swordapp.client;
+
+public class StatementFactory
+{
+ public static Statement getStatementShell(String type)
+ {
+ if ("application/rdf+xml".equals(type))
+ {
+ return new OreStatement();
+ }
+ else if ("application/atom+xml".equals(type) || "application/atom+xml;type=feed".equals(type))
+ {
+ return new AtomStatement();
+ }
+ return null;
+ }
+}
Modified: JavaClient2.0/src/test/java/org/swordapp/client/test/ClientTests.java
===================================================================
--- JavaClient2.0/src/test/java/org/swordapp/client/test/ClientTests.java 2012-03-17 18:40:31 UTC (rev 479)
+++ JavaClient2.0/src/test/java/org/swordapp/client/test/ClientTests.java 2012-03-17 18:41:19 UTC (rev 480)
@@ -3,16 +3,23 @@
import org.apache.abdera.i18n.iri.IRI;
import org.junit.*;
import static org.junit.Assert.*;
+
+import org.swordapp.client.AtomStatement;
import org.swordapp.client.ClientConfiguration;
import org.swordapp.client.Content;
import org.swordapp.client.Deposit;
import org.swordapp.client.EntryPart;
+import org.swordapp.client.OreStatement;
import org.swordapp.client.SWORDClient;
+import org.swordapp.client.Statement;
+import org.swordapp.client.StatementFactory;
import org.swordapp.client.SwordIdentifier;
+import org.swordapp.client.SwordResponse;
import javax.activation.MimeType;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
+import java.util.Date;
public class ClientTests
{
@@ -120,4 +127,39 @@
assertNull(si3.getLink());
assertEquals(si3.getMimeType(), mime);
}
+
+ @Test
+ public void swordResponseObject()
+ {
+ SwordResponse sr = new SwordResponse(204);
+
+ assertEquals(sr.getStatusCode(), 204);
+ assertNull(sr.getContentMD5());
+ assertNull(sr.getLastModified());
+ assertNull(sr.getLocation());
+
+ SwordResponse sr1 = new SwordResponse(204, "http://location");
+
+ assertEquals(sr1.getStatusCode(), 204);
+ assertEquals(sr1.getLocation(), "http://location");
+ assertNull(sr.getContentMD5());
+ assertNull(sr.getLastModified());
+
+ sr1.setContentMD5("abcdef");
+ assertEquals(sr1.getContentMD5(), "abcdef");
+
+ Date date = new Date();
+ sr1.setLastModified(date);
+ assertEquals(sr1.getLastModified(), date);
+ }
+
+ @Test
+ public void statementFactory()
+ {
+ Statement s = StatementFactory.getStatementShell("application/rdf+xml");
+ assertTrue(s instanceof OreStatement);
+
+ Statement s1 = StatementFactory.getStatementShell("application/atom+xml;type=feed");
+ assertTrue(s1 instanceof AtomStatement);
+ }
}
Modified: JavaClient2.0/src/test/java/org/swordapp/client/test/SSSSemiUnits.java
===================================================================
--- JavaClient2.0/src/test/java/org/swordapp/client/test/SSSSemiUnits.java 2012-03-17 18:40:31 UTC (rev 479)
+++ JavaClient2.0/src/test/java/org/swordapp/client/test/SSSSemiUnits.java 2012-03-17 18:41:19 UTC (rev 480)
@@ -3,6 +3,7 @@
import org.apache.commons.codec.digest.DigestUtils;
import org.junit.Before;
import org.junit.Test;
+import org.swordapp.client.AtomStatement;
import org.swordapp.client.AuthCredentials;
import org.swordapp.client.ClientConfiguration;
import org.swordapp.client.Deposit;
@@ -11,6 +12,7 @@
import org.swordapp.client.SWORDCollection;
import org.swordapp.client.SWORDWorkspace;
import org.swordapp.client.ServiceDocument;
+import org.swordapp.client.Statement;
import org.swordapp.client.UriRegistry;
import java.io.FileInputStream;
@@ -136,4 +138,34 @@
assertTrue(receipt.getTreatment() != null);
assertTrue(receipt.getVerboseDescription() != null);
}
+
+ @Test
+ public void atomStatement()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass, this.obo));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
+
+ Deposit deposit = new Deposit();
+ deposit.setFile(new FileInputStream(this.file));
+ deposit.setMimeType("application/zip");
+ deposit.setFilename("example.zip");
+ deposit.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ deposit.setMd5(this.fileMd5);
+
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass, this.obo));
+ receipt = client.getDepositReceipt(receipt.getLocation(), new AuthCredentials(this.user, this.pass, this.obo));
+
+ assertTrue(receipt.getAtomStatementLink() != null);
+
+ Statement statement = client.getStatement(receipt, "application/atom+xml;type=feed", new AuthCredentials(this.user, this.pass, this.obo));
+
+ assertTrue(statement instanceof AtomStatement);
+ assertNotNull(((AtomStatement) statement).getFeed());
+ assertEquals(statement.getMimeType(), "application/atom+xml;type=feed");
+ assertEquals(statement.getOriginalDeposits().size(), 1);
+ assertEquals(statement.getParts().size(), 5);
+ assertEquals(statement.getState().size(), 1);
+ }
}
Modified: JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java
===================================================================
--- JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java 2012-03-17 18:40:31 UTC (rev 479)
+++ JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java 2012-03-17 18:41:19 UTC (rev 480)
@@ -5,6 +5,8 @@
import org.junit.Test;
import org.junit.Before;
import static org.junit.Assert.*;
+
+import org.swordapp.client.AtomStatement;
import org.swordapp.client.AuthCredentials;
import org.swordapp.client.ClientConfiguration;
import org.swordapp.client.Content;
@@ -12,9 +14,12 @@
import org.swordapp.client.DepositReceipt;
import org.swordapp.client.EntryPart;
import org.swordapp.client.SWORDClient;
+import org.swordapp.client.SWORDClientException;
import org.swordapp.client.SWORDCollection;
import org.swordapp.client.SWORDError;
import org.swordapp.client.ServiceDocument;
+import org.swordapp.client.Statement;
+import org.swordapp.client.SwordResponse;
import org.swordapp.client.UriRegistry;
import java.io.FileInputStream;
@@ -338,6 +343,7 @@
Content content = client.getContent(receipt.getEditMediaLink(), packaging, new AuthCredentials(this.user, this.pass, this.obo));
assertTrue(content.getInputStream() != null);
+ assertTrue(content.getFeed() == null);
}
@Test
@@ -373,473 +379,596 @@
assertTrue(wasError);
}
- /* Python tests to mimic
+ @Test
+ public void retrieveContentEmIRIAsFeed()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
- def test_15_retrieve_content_em_iri_as_feed(self):
- conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
- conn.get_service_document()
- col = conn.sd.workspaces[0][1][0]
- with open(PACKAGE) as pkg:
- receipt = conn.create(col_iri = col.href,
- payload=pkg,
- mimetype=PACKAGE_MIME,
- filename="example.zip",
- packaging='http://purl.org/net/sword/package/SimpleZip')
- # ensure that we have a receipt (the server may not give us one
- # by default)
- receipt = conn.get_deposit_receipt(receipt.location)
+ Deposit deposit = new Deposit();
+ deposit.setFile(new FileInputStream(this.file));
+ deposit.setMimeType("application/zip");
+ deposit.setFilename("example.zip");
+ deposit.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ deposit.setMd5(this.fileMd5);
- # we're going to work with the edit_media_feed iri
- assert receipt.edit_media_feed is not None
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass));
+ receipt = client.getDepositReceipt(receipt.getLocation(), new AuthCredentials(this.user, this.pass));
- response = conn.get_resource(content_iri=receipt.edit_media_feed)
+ assertTrue(receipt.getEditMediaLink("application/atom+xml;type=feed") != null);
- assert response.code == 200
- assert response.content is not None
+ Content content = client.getContent(receipt.getEditMediaLink("application/atom+xml;type=feed"), new AuthCredentials(this.user, this.pass));
- # the response should be an xml document, so let's see if we can parse
- # it. This should give us an exception which will fail the test if not
- dom = etree.fromstring(response.content)
+ assertTrue(content.getFeed() != null);
+ assertTrue(content.getInputStream() == null);
+ }
- def test_16_basic_replace_file_content(self):
- conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
- conn.get_service_document()
- col = conn.sd.workspaces[0][1][0]
- with open(PACKAGE) as pkg:
- receipt = conn.create(col_iri = col.href,
- payload=pkg,
- mimetype=PACKAGE_MIME,
- filename="example.zip",
- packaging='http://purl.org/net/sword/package/SimpleZip')
- # ensure that we have a receipt (the server may not give us one
- # by default)
- receipt = conn.get_deposit_receipt(receipt.location)
+ @Test
+ public void basicReplaceFileContent()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
- # now do the replace
- with open(PACKAGE) as pkg:
- new_receipt = conn.update(dr = receipt,
- payload=pkg,
- mimetype=PACKAGE_MIME,
- filename="update.zip",
- packaging='http://purl.org/net/sword/package/SimpleZip')
+ Deposit deposit = new Deposit();
+ deposit.setFile(new FileInputStream(this.file));
+ deposit.setMimeType("application/zip");
+ deposit.setFilename("example.zip");
+ deposit.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ deposit.setMd5(this.fileMd5);
- assert new_receipt.code == 204
- assert new_receipt.dom is None
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass));
+ receipt = client.getDepositReceipt(receipt.getLocation(), new AuthCredentials(this.user, this.pass));
- def test_17_advanced_replace_file_content(self):
- conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
- conn.get_service_document()
- col = conn.sd.workspaces[0][1][0]
- with open(PACKAGE) as pkg:
- receipt = conn.create(col_iri = col.href,
- payload=pkg,
- mimetype=PACKAGE_MIME,
- filename="example.zip",
- packaging='http://purl.org/net/sword/package/SimpleZip')
- # ensure that we have a receipt (the server may not give us one
- # by default)
- receipt = conn.get_deposit_receipt(receipt.location)
+ Deposit replacement = new Deposit();
+ replacement.setFile(new FileInputStream(this.file));
+ replacement.setMimeType("application/zip");
+ replacement.setFilename("updated.zip");
+ replacement.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ replacement.setMd5(this.fileMd5);
- # now do the replace
- with open(PACKAGE) as pkg:
- new_receipt = conn.update(dr = receipt,
- payload=pkg,
- mimetype=PACKAGE_MIME,
- filename="update.zip",
- packaging='http://purl.org/net/sword/package/SimpleZip',
- metadata_relevant=True)
+ SwordResponse resp = client.replaceMedia(receipt, replacement, new AuthCredentials(this.user, this.pass));
- assert new_receipt.code == 204
- assert new_receipt.dom is None
+ assertEquals(resp.getStatusCode(), 204);
+ }
- def test_18_basic_replace_metadata(self):
- conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
- conn.get_service_document()
- col = conn.sd.workspaces[0][1][0]
- e = Entry(title="An entry only deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
- receipt = conn.create(col_iri = col.href, metadata_entry = e)
+ @Test
+ public void advancedReplaceFileContent()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass, this.obo));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
- # ensure that we have a receipt (the server may not give us one
- # by default)
- receipt = conn.get_deposit_receipt(receipt.location)
+ Deposit deposit = new Deposit();
+ deposit.setFile(new FileInputStream(this.file));
+ deposit.setMimeType("application/zip");
+ deposit.setFilename("example.zip");
+ deposit.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ deposit.setMd5(this.fileMd5);
- # now do the replace
- ne = Entry(title="A metadata update", id="asidjasidj", dcterms_abstract="new abstract", dcterms_identifier="http://elsewhere/")
- new_receipt = conn.update(dr=receipt, metadata_entry=ne)
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass, this.obo));
+ receipt = client.getDepositReceipt(receipt.getLocation(), new AuthCredentials(this.user, this.pass, this.obo));
- assert new_receipt.code == 204 or new_receipt.code == 200
- if new_receipt.code == 204:
- assert new_receipt.dom is None
- if new_receipt.code == 200:
- assert new_receipt.parsed == True
- assert new_receipt.valid == True
+ Deposit replacement = new Deposit();
+ replacement.setFile(new FileInputStream(this.file));
+ replacement.setMimeType("application/zip");
+ replacement.setFilename("updated.zip");
+ replacement.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ replacement.setMd5(this.fileMd5);
+ replacement.setMetadataRelevant(true);
- def test_19_advanced_replace_metadata(self):
- conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
- conn.get_service_document()
- col = conn.sd.workspaces[0][1][0]
- e = Entry(title="An entry only deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
- receipt = conn.create(col_iri = col.href, metadata_entry = e)
+ SwordResponse resp = client.replaceMedia(receipt, replacement, new AuthCredentials(this.user, this.pass, this.obo));
- # ensure that we have a receipt (the server may not give us one
- # by default)
- receipt = conn.get_deposit_receipt(receipt.location)
+ assertEquals(resp.getStatusCode(), 204);
+ }
- # now do the replace
- ne = Entry(title="A metadata update", id="asidjasidj", dcterms_abstract="new abstract", dcterms_identifier="http://elsewhere/")
- new_receipt = conn.update(dr=receipt, metadata_entry=ne, in_progress=True)
+ @Test
+ public void basicReplaceMetadata()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
- assert new_receipt.code == 204 or new_receipt.code == 200
- if new_receipt.code == 204:
- assert new_receipt.dom is None
- if new_receipt.code == 200:
- assert new_receipt.parsed == True
- assert new_receipt.valid == True
+ EntryPart ep = new EntryPart();
+ ep.addDublinCore("title", "An entry only deposit");
+ ep.addDublinCore("abstract", "abstract");
+ ep.addDublinCore("identifier", "http://whatever/");
- def test_20_basic_replace_with_multipart(self):
- conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
- conn.get_service_document()
- col = conn.sd.workspaces[0][1][0]
- e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
- with open(PACKAGE) as pkg:
- receipt = conn.create(col_iri = col.href,
- metadata_entry = e,
- payload=pkg,
- mimetype=PACKAGE_MIME,
- filename="example.zip",
- packaging = 'http://purl.org/net/sword/package/SimpleZip')
+ Deposit deposit = new Deposit();
+ deposit.setEntryPart(ep);
- # ensure that we have a receipt (the server may not give us one
- # by default)
- receipt = conn.get_deposit_receipt(receipt.location)
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass));
+ receipt = client.getDepositReceipt(receipt.getLocation(), new AuthCredentials(this.user, this.pass));
- # now do the replace
- ne = Entry(title="A multipart update", id="asidjasidj", dcterms_abstract="new abstract", dcterms_identifier="http://elsewhere/")
- with open(PACKAGE) as pkg:
- new_receipt = conn.update(dr = receipt,
- metadata_entry = ne,
- payload=pkg,
- mimetype=PACKAGE_MIME,
- filename="update.zip",
- packaging='http://purl.org/net/sword/package/SimpleZip')
+ EntryPart nep = new EntryPart();
+ nep.addDublinCore("title", "A metadata update");
+ nep.addDublinCore("abstract", "new abstract");
+ nep.addDublinCore("identifier", "http://elsewhere/");
- assert new_receipt.code == 204 or new_receipt.code == 200
- if new_receipt.code == 204:
- assert new_receipt.dom is None
- if new_receipt.code == 200:
- assert new_receipt.parsed == True
- assert new_receipt.valid == True
+ Deposit replacement = new Deposit();
+ replacement.setEntryPart(nep);
- def test_21_advanced_replace_with_multipart(self):
- conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
- conn.get_service_document()
- col = conn.sd.workspaces[0][1][0]
- e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
- with open(PACKAGE) as pkg:
- receipt = conn.create(col_iri = col.href,
- metadata_entry = e,
- payload=pkg,
- mimetype=PACKAGE_MIME,
- filename="example.zip",
- packaging = 'http://purl.org/net/sword/package/SimpleZip')
+ SwordResponse resp = client.replace(receipt, replacement, new AuthCredentials(this.user, this.pass));
- # ensure that we have a receipt (the server may not give us one
- # by default)
- receipt = conn.get_deposit_receipt(receipt.location)
+ assertTrue(resp.getStatusCode() == 200 || resp.getStatusCode() == 204);
+ }
- # now do the replace
- ne = Entry(title="A multipart update", id="asidjasidj", dcterms_abstract="new abstract", dcterms_identifier="http://elsewhere/")
- with open(PACKAGE) as pkg:
- new_receipt = conn.update(dr = receipt,
- metadata_entry = ne,
- payload=pkg,
- mimetype=PACKAGE_MIME,
- filename="update.zip",
- packaging='http://purl.org/net/sword/package/SimpleZip',
- in_progress=True)
+ @Test
+ public void advancedReplaceMetadata()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass, this.obo));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
- assert new_receipt.code == 204 or new_receipt.code == 200
- if new_receipt.code == 204:
- assert new_receipt.dom is None
- if new_receipt.code == 200:
- assert new_receipt.parsed == True
- assert new_receipt.valid == True
+ EntryPart ep = new EntryPart();
+ ep.addDublinCore("title", "An entry only deposit");
+ ep.addDublinCore("abstract", "abstract");
+ ep.addDublinCore("identifier", "http://whatever/");
- def test_22_delete_content(self):
- conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
- conn.get_service_document()
- col = conn.sd.workspaces[0][1][0]
- e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
- with open(PACKAGE) as pkg:
- receipt = conn.create(col_iri = col.href,
- metadata_entry = e,
- payload=pkg,
- mimetype=PACKAGE_MIME,
- filename="example.zip",
- packaging = 'http://purl.org/net/sword/package/SimpleZip')
+ Deposit deposit = new Deposit();
+ deposit.setEntryPart(ep);
- # ensure that we have a receipt (the server may not give us one
- # by default)
- receipt = conn.get_deposit_receipt(receipt.location)
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass, this.obo));
+ receipt = client.getDepositReceipt(receipt.getLocation(), new AuthCredentials(this.user, this.pass, this.obo));
- # now delete the content but not the container
- new_receipt = conn.delete_content_of_resource(dr=receipt)
+ EntryPart nep = new EntryPart();
+ nep.addDublinCore("title", "A metadata update");
+ nep.addDublinCore("abstract", "new abstract");
+ nep.addDublinCore("identifier", "http://elsewhere/");
- assert new_receipt.code == 204
- assert new_receipt.dom is None
+ Deposit replacement = new Deposit();
+ replacement.setEntryPart(nep);
+ replacement.setInProgress(true);
- def test_23_basic_add_content_to_resource_single_file(self):
- conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
- conn.get_service_document()
- col = conn.sd.workspaces[0][1][0]
- with open(PACKAGE) as pkg:
- receipt = conn.create(col_iri = col.href,
- payload=pkg,
- mimetype=PACKAGE_MIME,
- filename="example.zip",
- packaging = 'http://purl.org/net/sword/package/SimpleZip')
- receipt = conn.get_deposit_receipt(receipt.location)
+ SwordResponse resp = client.replace(receipt, replacement, new AuthCredentials(this.user, this.pass, this.obo));
- with open(PACKAGE) as pkg:
- new_receipt = conn.add_file_to_resource(receipt.edit_media, pkg, "addition.zip", mimetype=PACKAGE_MIME)
+ assertTrue(resp.getStatusCode() == 200 || resp.getStatusCode() == 204);
+ }
- assert new_receipt.code >= 200 and new_receipt.code < 400
- assert new_receipt.location is not None
- assert new_receipt.location != receipt.edit_media
+ /* FIXME: multipart is not currently functional ...
+ @Test
+ public void basicReplaceWithMutlipart()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
- def test_24_advanced_add_content_to_resource_single_file(self):
- conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
- conn.get_service_document()
- col = conn.sd.workspaces[0][1][0]
- with open(PACKAGE) as pkg:
- receipt = conn.create(col_iri = col.href,
- payload=pkg,
- mimetype=PACKAGE_MIME,
- filename="example.zip",
- packaging = 'http://purl.org/net/sword/package/SimpleZip')
- receipt = conn.get_deposit_receipt(receipt.location)
+ EntryPart ep = new EntryPart();
+ ep.addDublinCore("title", "My Title");
- with open(PACKAGE) as pkg:
- new_receipt = conn.add_file_to_resource(receipt.edit_media, pkg, "addition.zip",
- mimetype=PACKAGE_MIME,
- metadata_relevant=True)
+ Deposit deposit = new Deposit();
+ deposit.setEntryPart(ep);
+ deposit.setFile(new FileInputStream(this.file));
+ deposit.setMimeType("application/zip");
+ deposit.setFilename("example.zip");
+ deposit.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ deposit.setMd5(this.fileMd5);
- assert new_receipt.code >= 200 and new_receipt.code < 400
- assert new_receipt.location is not None
- assert new_receipt.location != receipt.edit_media
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass));
+ receipt = client.getDepositReceipt(receipt.getLocation(), new AuthCredentials(this.user, this.pass));
- def test_25_basic_add_content_to_resource_package(self):
- conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
- conn.get_service_document()
- col = conn.sd.workspaces[0][1][0]
- with open(PACKAGE) as pkg:
- receipt = conn.create(col_iri = col.href,
- payload=pkg,
- mimetype=PACKAGE_MIME,
- filename="example.zip",
- packaging = 'http://purl.org/net/sword/package/SimpleZip')
- receipt = conn.get_deposit_receipt(receipt.location)
+ EntryPart nep = new EntryPart();
+ nep.addDublinCore("title", "A metadata update");
+ nep.addDublinCore("abstract", "new abstract");
+ nep.addDublinCore("identifier", "http://elsewhere/");
- with open(PACKAGE) as pkg:
- new_receipt = conn.add_file_to_resource(receipt.edit_media, pkg, "addition.zip",
- mimetype=PACKAGE_MIME,
- packaging="http://purl.org/net/sword/package/SimpleZip")
+ Deposit replacement = new Deposit();
+ replacement.setEntryPart(nep);
+ replacement.setFile(new FileInputStream(this.file));
+ replacement.setMimeType("application/zip");
+ replacement.setFilename("updated.zip");
+ replacement.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ replacement.setMd5(this.fileMd5);
- assert new_receipt.code >= 200 and new_receipt.code < 400
- assert new_receipt.location is not None
- assert new_receipt.location == receipt.edit_media
+ SwordResponse resp = client.replace(receipt, replacement, new AuthCredentials(this.user, this.pass));
- def test_26_advanced_add_content_to_resource_package(self):
- conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
- conn.get_service_document()
- col = conn.sd.workspaces[0][1][0]
- with open(PACKAGE) as pkg:
- receipt = conn.create(col_iri = col.href,
- payload=pkg,
- mimetype=PACKAGE_MIME,
- filename="example.zip",
- packaging = 'http://purl.org/net/sword/package/SimpleZip')
- receipt = conn.get_deposit_receipt(receipt.location)
+ assertTrue(resp.getStatusCode() == 200 || resp.getStatusCode() == 204);
+ }
- with open(PACKAGE) as pkg:
- new_receipt = conn.add_file_to_resource(receipt.edit_media, pkg, "addition.zip",
- mimetype=PACKAGE_MIME,
- packaging="http://purl.org/net/sword/package/SimpleZip",
- metadata_relevant=True)
+ @Test
+ public void advancedReplaceWithMutlipart()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass, this.obo));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
- assert new_receipt.code >= 200 and new_receipt.code < 400
- assert new_receipt.location is not None
- assert new_receipt.location == receipt.edit_media
+ EntryPart ep = new EntryPart();
+ ep.addDublinCore("title", "My Title");
- def test_27_basic_add_metadata(self):
- conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
- conn.get_service_document()
- col = conn.sd.workspaces[0][1][0]
- e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
- with open(PACKAGE) as pkg:
- receipt = conn.create(col_iri = col.href,
- metadata_entry = e,
- payload=pkg,
- mimetype=PACKAGE_MIME,
- filename="example.zip",
- packaging = 'http://purl.org/net/sword/package/SimpleZip')
+ Deposit deposit = new Deposit();
+ deposit.setEntryPart(ep);
+ deposit.setFile(new FileInputStream(this.file));
+ deposit.setMimeType("application/zip");
+ deposit.setFilename("example.zip");
+ deposit.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ deposit.setMd5(this.fileMd5);
- # ensure that we have a receipt (the server may not give us one
- # by default)
- receipt = conn.get_deposit_receipt(receipt.location)
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass, this.obo));
+ receipt = client.getDepositReceipt(receipt.getLocation(), new AuthCredentials(this.user, this.pass, this.obo));
- ne = Entry(title="Multipart deposit", id="asidjasidj", dcterms_identifier="http://another/",
- dcterms_creator="Me!", dcterms_rights="CC0")
- new_receipt = conn.append(dr=receipt, metadata_entry=ne)
+ EntryPart nep = new EntryPart();
+ nep.addDublinCore("title", "A metadata update");
+ nep.addDublinCore("abstract", "new abstract");
+ nep.addDublinCore("identifier", "http://elsewhere/");
- assert new_receipt.code == 200
+ Deposit replacement = new Deposit();
+ replacement.setEntryPart(nep);
+ replacement.setFile(new FileInputStream(this.file));
+ replacement.setMimeType("application/zip");
+ replacement.setFilename("updated.zip");
+ replacement.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ replacement.setMd5(this.fileMd5);
+ replacement.setInProgress(true);
- def test_28_advanced_add_metadata(self):
- conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
- conn.get_service_document()
- col = conn.sd.workspaces[0][1][0]
- e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
- with open(PACKAGE) as pkg:
- receipt = conn.create(col_iri = col.href,
- metadata_entry = e,
- payload=pkg,
- mimetype=PACKAGE_MIME,
- filename="example.zip",
- packaging = 'http://purl.org/net/sword/package/SimpleZip')
+ SwordResponse resp = client.replace(receipt, replacement, new AuthCredentials(this.user, this.pass, this.obo));
- # ensure that we have a receipt (the server may not give us one
- # by default)
- receipt = conn.get_deposit_receipt(receipt.location)
+ assertTrue(resp.getStatusCode() == 200 || resp.getStatusCode() == 204);
+ }
+ */
- ne = Entry(title="Multipart deposit", id="asidjasidj", dcterms_identifier="http://another/",
- dcterms_creator="Me!", dcterms_rights="CC0")
- new_receipt = conn.append(dr=receipt, metadata_entry=ne, in_progress=True)
+ @Test
+ public void deleteContent()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass, this.obo));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
- assert new_receipt.code == 200
+ Deposit deposit = new Deposit();
+ deposit.setFile(new FileInputStream(this.file));
+ deposit.setMimeType("application/zip");
+ deposit.setFilename("example.zip");
+ deposit.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ deposit.setMd5(this.fileMd5);
- def test_29_basic_add_multipart(self):
- conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
- conn.get_service_document()
- col = conn.sd.workspaces[0][1][0]
- e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
- with open(PACKAGE) as pkg:
- receipt = conn.create(col_iri = col.href,
- metadata_entry = e,
- payload=pkg,
- mimetype=PACKAGE_MIME,
- filename="example.zip",
- packaging = 'http://purl.org/net/sword/package/SimpleZip')
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass, this.obo));
+ receipt = client.getDepositReceipt(receipt.getLocation(), new AuthCredentials(this.user, this.pass, this.obo));
- # ensure that we have a receipt (the server may not give us one
- # by default)
- receipt = conn.get_deposit_receipt(receipt.location)
+ SwordResponse resp = client.deleteContent(receipt, new AuthCredentials(this.user, this.pass, this.obo));
+ assertEquals(resp.getStatusCode(), 204);
+ }
- ne = Entry(title="Multipart deposit", id="asidjasidj", dcterms_identifier="http://another/",
- dcterms_creator="Me!", dcterms_rights="CC0")
- with open(PACKAGE) as pkg:
- new_receipt = conn.append(dr=receipt,
- metadata_entry=ne,
- payload=pkg,
- filename="addition.zip",
- mimetype=PACKAGE_MIME,
- packaging="http://purl.org/net/sword/package/SimpleZip")
+ @Test
+ public void basicAddContentSingleFile()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
- assert new_receipt.code >= 200 and new_receipt.code < 400
+ Deposit deposit = new Deposit();
+ deposit.setFile(new FileInputStream(this.file));
+ deposit.setMimeType("application/zip");
+ deposit.setFilename("example.zip");
+ deposit.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ deposit.setMd5(this.fileMd5);
- def test_30_advanced_add_multipart(self):
- conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
- conn.get_service_document()
- col = conn.sd.workspaces[0][1][0]
- e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
- with open(PACKAGE) as pkg:
- receipt = conn.create(col_iri = col.href,
- metadata_entry = e,
- payload=pkg,
- mimetype=PACKAGE_MIME,
- filename="example.zip",
- packaging = 'http://purl.org/net/sword/package/SimpleZip')
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass));
+ receipt = client.getDepositReceipt(receipt.getLocation(), new AuthCredentials(this.user, this.pass));
- # ensure that we have a receipt (the server may not give us one
- # by default)
- receipt = conn.get_deposit_receipt(receipt.location)
+ Deposit addition = new Deposit();
+ addition.setFile(new FileInputStream(this.file));
+ addition.setMimeType("application/zip");
+ addition.setFilename("additional.zip");
+ addition.setMd5(this.fileMd5);
- ne = Entry(title="Multipart deposit", id="asidjasidj", dcterms_identifier="http://another/",
- dcterms_creator="Me!", dcterms_rights="CC0")
- with open(PACKAGE) as pkg:
- new_receipt = conn.append(dr=receipt,
- metadata_entry=ne,
- payload=pkg,
- filename="addition.zip",
- mimetype=PACKAGE_MIME,
- packaging="http://purl.org/net/sword/package/SimpleZip",
- in_progress=True,
- metadata_relevant=True)
+ SwordResponse resp = client.addToMediaResource(receipt, addition, new AuthCredentials(this.user, this.pass));
- assert new_receipt.code >= 200 and new_receipt.code < 400
+ assertTrue(resp.getStatusCode() >= 200 && resp.getStatusCode() < 400);
+ assertTrue(resp.getLocation() != null);
+ }
- # FIXME: this test just does not work, for no discernable reason. The
- # final assert of a 404 fails, and the debug output of the client says
- # that the server responded with a 200. Nonetheless, the server logs show
- # that it responded with a 404, which would suggest a caching issue in the
- # client. I have so far been unable to figure out where, though, despite
- # having tried turning off httplib2 caching and passing cache-control
- # headers in as per the httplib2 documentation. help?
- def test_31_delete_container(self):
- conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO,
- error_response_raises_exceptions=False)
- conn.get_service_document()
- col = conn.sd.workspaces[0][1][0]
- e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
- with open(PACKAGE) as pkg:
- receipt = conn.create(col_iri = col.href,
- metadata_entry = e,
- payload=pkg,
- mimetype=PACKAGE_MIME,
- filename="example.zip",
- packaging = 'http://purl.org/net/sword/package/SimpleZip')
+ @Test
+ public void advancedAddContentSingleFile()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass, this.obo));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
- # ensure that we have a receipt (the server may not give us one
- # by default)
- edit_iri = receipt.location
- receipt = conn.get_deposit_receipt(edit_iri)
+ Deposit deposit = new Deposit();
+ deposit.setFile(new FileInputStream(this.file));
+ deposit.setMimeType("application/zip");
+ deposit.setFilename("example.zip");
+ deposit.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ deposit.setMd5(this.fileMd5);
- # delete the container
- new_receipt = conn.delete_container(dr=receipt)
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass, this.obo));
+ receipt = client.getDepositReceipt(receipt.getLocation(), new AuthCredentials(this.user, this.pass, this.obo));
- assert new_receipt.code == 204
- assert new_receipt.dom is None
+ Deposit addition = new Deposit();
+ addition.setFile(new FileInputStream(this.file));
+ addition.setMimeType("application/zip");
+ addition.setFilename("additional.zip");
+ addition.setMd5(this.fileMd5);
+ addition.setMetadataRelevant(true);
- # the next check is that this 404s appropriately now
- another_receipt = conn.get_deposit_receipt(edit_iri)
+ SwordResponse resp = client.addToMediaResource(receipt, addition, new AuthCredentials(this.user, this.pass, this.obo));
- # FIXME: this is the broken assert
- #assert another_receipt.code == 404
+ assertTrue(resp.getStatusCode() >= 200 && resp.getStatusCode() < 400);
+ assertTrue(resp.getLocation() != null);
+ }
- def test_32_get_atom_statement(self):
- conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
- conn.get_service_document()
- col = conn.sd.workspaces[0][1][0]
- e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
- with open(PACKAGE) as pkg:
- receipt = conn.create(col_iri = col.href,
- metadata_entry = e,
- payload=pkg,
- mimetype=PACKAGE_MIME,
- filename="example.zip",
- packaging = 'http://purl.org/net/sword/package/SimpleZip')
+ @Test
+ public void basicAddContentPackage()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
- # ensure that we have a receipt (the server may not give us one
- # by default)
- edit_iri = receipt.location
- receipt = conn.get_deposit_receipt(edit_iri)
+ Deposit deposit = new Deposit();
+ deposit.setFile(new FileInputStream(this.file));
+ deposit.setMimeType("application/zip");
+ deposit.setFilename("example.zip");
+ deposit.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ deposit.setMd5(this.fileMd5);
- assert receipt.atom_statement_iri is not None
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass));
+ receipt = client.getDepositReceipt(receipt.getLocation(), new AuthCredentials(this.user, this.pass));
- # get the statement
- statement = conn.get_atom_sword_statement(receipt.atom_statement_iri)
+ Deposit addition = new Deposit();
+ addition.setFile(new FileInputStream(this.file));
+ addition.setMimeType("application/zip");
+ addition.setFilename("additional.zip");
+ addition.setMd5(this.fileMd5);
+ addition.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
- assert isinstance(statement, Atom_Sword_Statement)
+ SwordResponse resp = client.addToMediaResource(receipt, addition, new AuthCredentials(this.user, this.pass));
+ assertTrue(resp.getStatusCode() >= 200 && resp.getStatusCode() < 400);
+ assertTrue(resp.getLocation() != null);
+ }
+
+ @Test
+ public void advancedAddContentPackage()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass, this.obo));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
+
+ Deposit deposit = new Deposit();
+ deposit.setFile(new FileInputStream(this.file));
+ deposit.setMimeType("application/zip");
+ deposit.setFilename("example.zip");
+ deposit.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ deposit.setMd5(this.fileMd5);
+
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass, this.obo));
+ receipt = client.getDepositReceipt(receipt.getLocation(), new AuthCredentials(this.user, this.pass, this.obo));
+
+ Deposit addition = new Deposit();
+ addition.setFile(new FileInputStream(this.file));
+ addition.setMimeType("application/zip");
+ addition.setFilename("additional.zip");
+ addition.setMd5(this.fileMd5);
+ addition.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ addition.setMetadataRelevant(true);
+
+ SwordResponse resp = client.addToMediaResource(receipt, addition, new AuthCredentials(this.user, this.pass, this.obo));
+
+ assertTrue(resp.getStatusCode() >= 200 && resp.getStatusCode() < 400);
+ assertTrue(resp.getLocation() != null);
+ }
+
+ @Test
+ public void basicAddMetadata()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
+
+ EntryPart ep = new EntryPart();
+ ep.addDublinCore("title", "An entry only deposit");
+ ep.addDublinCore("abstract", "abstract");
+ ep.addDublinCore("identifier", "http://whatever/");
+
+ Deposit deposit = new Deposit();
+ deposit.setEntryPart(ep);
+
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass));
+ receipt = client.getDepositReceipt(receipt.getLocation(), new AuthCredentials(this.user, this.pass));
+
+ EntryPart nep = new EntryPart();
+ nep.addDublinCore("title", "A metadata update");
+ nep.addDublinCore("abstract", "new abstract");
+ nep.addDublinCore("identifier", "http://elsewhere/");
+
+ Deposit additional = new Deposit();
+ additional.setEntryPart(nep);
+
+ DepositReceipt newReceipt = client.addToContainer(receipt, additional, new AuthCredentials(this.user, this.pass));
+ assertTrue(newReceipt.getStatusCode() == 200);
+ }
+
+ @Test
+ public void advancedAddMetadata()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass, this.obo));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
+
+ EntryPart ep = new EntryPart();
+ ep.addDublinCore("title", "An entry only deposit");
+ ep.addDublinCore("abstract", "abstract");
+ ep.addDublinCore("identifier", "http://whatever/");
+
+ Deposit deposit = new Deposit();
+ deposit.setEntryPart(ep);
+
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass, this.obo));
+ receipt = client.getDepositReceipt(receipt.getLocation(), new AuthCredentials(this.user, this.pass, this.obo));
+
+ EntryPart nep = new EntryPart();
+ nep.addDublinCore("title", "A metadata update");
+ nep.addDublinCore("abstract", "new abstract");
+ nep.addDublinCore("identifier", "http://elsewhere/");
+
+ Deposit additional = new Deposit();
+ additional.setEntryPart(nep);
+ additional.setInProgress(true);
+
+ DepositReceipt newReceipt = client.addToContainer(receipt, additional, new AuthCredentials(this.user, this.pass, this.obo));
+ assertTrue(newReceipt.getStatusCode() == 200);
+ }
+
+ /*
+ @Test
+ public void basicAddMultipart()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
+
+ EntryPart ep = new EntryPart();
+ ep.addDublinCore("title", "My Title");
+
+ Deposit deposit = new Deposit();
+ deposit.setEntryPart(ep);
+ deposit.setFile(new FileInputStream(this.file));
+ deposit.setMimeType("application/zip");
+ deposit.setFilename("example.zip");
+ deposit.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ deposit.setMd5(this.fileMd5);
+
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass));
+ receipt = client.getDepositReceipt(receipt.getLocation(), new AuthCredentials(this.user, this.pass));
+
+ EntryPart nep = new EntryPart();
+ nep.addDublinCore("title", "A metadata update");
+ nep.addDublinCore("abstract", "new abstract");
+ nep.addDublinCore("identifier", "http://elsewhere/");
+
+ Deposit replacement = new Deposit();
+ replacement.setEntryPart(nep);
+ replacement.setFile(new FileInputStream(this.file));
+ replacement.setMimeType("application/zip");
+ replacement.setFilename("updated.zip");
+ replacement.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ replacement.setMd5(this.fileMd5);
+
+ SwordResponse resp = client.addToContainer(receipt, replacement, new AuthCredentials(this.user, this.pass));
+
+ assertTrue(resp.getStatusCode() >= 200 && resp.getStatusCode() < 400);
+ }
+
+ @Test
+ public void advancedAddMultipart()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass, this.obo));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
+
+ EntryPart ep = new EntryPart();
+ ep.addDublinCore("title", "My Title");
+
+ Deposit deposit = new Deposit();
+ deposit.setEntryPart(ep);
+ deposit.setFile(new FileInputStream(this.file));
+ deposit.setMimeType("application/zip");
+ deposit.setFilename("example.zip");
+ deposit.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ deposit.setMd5(this.fileMd5);
+
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass, this.obo));
+ receipt = client.getDepositReceipt(receipt.getLocation(), new AuthCredentials(this.user, this.pass, this.obo));
+
+ EntryPart nep = new EntryPart();
+ nep.addDublinCor...
[truncated message content] |
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-03-17 18:40:37
|
Revision: 479
http://sword-app.svn.sourceforge.net/sword-app/?rev=479&view=rev
Author: richard-jones
Date: 2012-03-17 18:40:31 +0000 (Sat, 17 Mar 2012)
Log Message:
-----------
fix bug with aggregated resource uris being erroneously kept in memory between statements, and correct serialisation of state in atom formatted sword statement
Modified Paths:
--------------
sss/branches/sss-2/sss/core.py
sss/branches/sss-2/sss/spec.py
sss/branches/sss-2/sss/webpy.py
Modified: sss/branches/sss-2/sss/core.py
===================================================================
--- sss/branches/sss-2/sss/core.py 2012-03-17 10:23:41 UTC (rev 478)
+++ sss/branches/sss-2/sss/core.py 2012-03-17 18:40:31 UTC (rev 479)
@@ -729,7 +729,7 @@
"""
Class representing the Statement; a description of the object as it appears on the server
"""
- def __init__(self, rdf_file=None, aggregation_uri=None, rem_uri=None, original_deposits=[], aggregates=[], states=[]):
+ def __init__(self, rdf_file=None, aggregation_uri=None, rem_uri=None, original_deposits=None, aggregates=None, states=None):
"""
The statement has 4 important properties:
- aggregation_uri - The URI of the aggregation in ORE terms
@@ -740,9 +740,9 @@
"""
self.aggregation_uri = aggregation_uri
self.rem_uri = rem_uri
- self.original_deposits = original_deposits
- self.aggregates = aggregates
- self.states = states
+ self.original_deposits = original_deposits if original_deposits is not None else []
+ self.aggregates = aggregates if aggregates is not None else []
+ self.states = states if states is not None else []
# Namespace map for XML serialisation
self.ns = Namespaces()
@@ -855,13 +855,25 @@
# create the root atom feed element
feed = etree.Element(self.ns.ATOM + "feed", nsmap=self.fmap)
+ # NOTE: this bit is incorrect, just in for reference, see replacement
+ # implementation
# create the sword:state term in the root of the feed
+ """
for state_uri, state_description in self.states:
state = etree.SubElement(feed, self.ns.SWORD + "state")
state.set("href", state_uri)
meaning = etree.SubElement(state, self.ns.SWORD + "stateDescription")
meaning.text = state_description
-
+ """
+
+ # create the state categories
+ for state_uri, state_description in self.states:
+ state = etree.SubElement(feed, self.ns.ATOM + "category")
+ state.set("scheme", self.ns.SWORD_STATE)
+ state.set("term", state_uri)
+ state.set("label", "State")
+ state.text = state_description
+
# now do an entry for each original deposit
for (uri, datestamp, format_uri, by, obo) in self.original_deposits:
# FIXME: this is not an official atom entry yet
Modified: sss/branches/sss-2/sss/spec.py
===================================================================
--- sss/branches/sss-2/sss/spec.py 2012-03-17 10:23:41 UTC (rev 478)
+++ sss/branches/sss-2/sss/spec.py 2012-03-17 18:40:31 UTC (rev 479)
@@ -24,6 +24,9 @@
self.SWORD_NS = "http://purl.org/net/sword/terms/"
self.SWORD = "{%s}" % self.SWORD_NS
self.SWORD_PREFIX = "sword"
+
+ # SWORD State Scheme
+ self.SWORD_STATE = self.SWORD_NS + "state"
# Dublin Core namespace and lxml format
self.DC_NS = "http://purl.org/dc/terms/"
Modified: sss/branches/sss-2/sss/webpy.py
===================================================================
--- sss/branches/sss-2/sss/webpy.py 2012-03-17 10:23:41 UTC (rev 478)
+++ sss/branches/sss-2/sss/webpy.py 2012-03-17 18:40:31 UTC (rev 479)
@@ -136,11 +136,11 @@
def manage_error(self, sword_error):
status = STATUS_MAP.get(sword_error.status, "400 Bad Request")
ssslog.info("Returning error (" + str(sword_error.status) + ") - " + str(sword_error.error_uri))
- web.ctx.status = status
+ web.ctx.status = str(sword_error.status)
if not sword_error.empty:
web.header("Content-Type", "text/xml")
return sword_error.error_document
- return
+ return ""
def _map_webpy_headers(self, headers):
return dict([(c[0][5:].replace("_", "-") if c[0].startswith("HTTP_") else c[0].replace("_", "-"), c[1]) for c in headers.items()])
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-03-17 10:23:47
|
Revision: 478
http://sword-app.svn.sourceforge.net/sword-app/?rev=478&view=rev
Author: richard-jones
Date: 2012-03-17 10:23:41 +0000 (Sat, 17 Mar 2012)
Log Message:
-----------
add Content-Type header which was missing from get_container request (requests for the deposit receipt)
Modified Paths:
--------------
sss/branches/sss-2/sss/pylons_sword_controller.py
sss/branches/sss-2/sss/webpy.py
Modified: sss/branches/sss-2/sss/pylons_sword_controller.py
===================================================================
--- sss/branches/sss-2/sss/pylons_sword_controller.py 2012-03-17 10:22:59 UTC (rev 477)
+++ sss/branches/sss-2/sss/pylons_sword_controller.py 2012-03-17 10:23:41 UTC (rev 478)
@@ -682,6 +682,8 @@
# now actually get hold of the representation of the container and send it to the client
cont = ss.get_container(path, accept_parameters)
ssslog.info("Returning " + response.status + " from request on " + inspect.stack()[0][3])
+ if cont is not None:
+ response.headers["Content-Type"] = accept_parameters.content_type.mimetype()
return cont
except SwordError as e:
Modified: sss/branches/sss-2/sss/webpy.py
===================================================================
--- sss/branches/sss-2/sss/webpy.py 2012-03-17 10:22:59 UTC (rev 477)
+++ sss/branches/sss-2/sss/webpy.py 2012-03-17 10:23:41 UTC (rev 478)
@@ -788,6 +788,8 @@
# now actually get hold of the representation of the container and send it to the client
cont = ss.get_container(path, accept_parameters)
+ if cont is not None:
+ web.header("Content-Type", accept_parameters.content_type.mimetype())
return cont
except SwordError as e:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-03-17 10:23:06
|
Revision: 477
http://sword-app.svn.sourceforge.net/sword-app/?rev=477&view=rev
Author: richard-jones
Date: 2012-03-17 10:22:59 +0000 (Sat, 17 Mar 2012)
Log Message:
-----------
add swordidentifier class which normalises the interface to the various Link and IRI objects which Abdera provides, and use this class throughout the relevant interfaces; associated tests included
Modified Paths:
--------------
JavaClient2.0/src/main/java/org/swordapp/client/DepositReceipt.java
JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java
JavaClient2.0/src/main/java/org/swordapp/client/SwordCli.java
JavaClient2.0/src/test/java/org/swordapp/client/test/ClientTests.java
JavaClient2.0/src/test/java/org/swordapp/client/test/SSSSemiUnits.java
JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java
Added Paths:
-----------
JavaClient2.0/src/main/java/org/swordapp/client/SwordIdentifier.java
Modified: JavaClient2.0/src/main/java/org/swordapp/client/DepositReceipt.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/DepositReceipt.java 2012-03-16 16:23:32 UTC (rev 476)
+++ JavaClient2.0/src/main/java/org/swordapp/client/DepositReceipt.java 2012-03-17 10:22:59 UTC (rev 477)
@@ -43,27 +43,22 @@
return entry;
}
- public Link getEditLink()
+ public SwordIdentifier getEditLink()
{
- return this.entry.getEditLink();
+ return new SwordIdentifier(this.entry.getEditLink());
}
- public IRI getContentSrc()
+ public SwordIdentifier getContentLink()
{
- return this.entry.getContentSrc();
+ return new SwordIdentifier(this.entry.getContentSrc(), this.entry.getContentMimeType());
}
- public MimeType getContentMimeType()
+ public SwordIdentifier getEditMediaLink()
{
- return this.entry.getContentMimeType();
+ return new SwordIdentifier(this.entry.getEditMediaLink());
}
- public Link getEditMediaLink()
- {
- return this.entry.getEditMediaLink();
- }
-
- public Link getEditMediaLink(String type)
+ public SwordIdentifier getEditMediaLink(String type)
throws SWORDClientException
{
try
@@ -76,7 +71,7 @@
if ("edit-media".equals(link.getRel()) &&
link.getMimeType().toString().equals(mt.toString()))
{
- return link;
+ return new SwordIdentifier(link);
}
}
}
@@ -88,14 +83,14 @@
}
}
- public Link getEditMediaLink(String type, String hreflang)
+ public SwordIdentifier getEditMediaLink(String type, String hreflang)
{
- return this.entry.getEditMediaLink(type, hreflang);
+ return new SwordIdentifier(this.entry.getEditMediaLink(type, hreflang));
}
- public Link getSwordEditLink()
+ public SwordIdentifier getSwordEditLink()
{
- return this.entry.getLink(UriRegistry.REL_SWORD_EDIT);
+ return new SwordIdentifier(this.entry.getLink(UriRegistry.REL_SWORD_EDIT));
}
public String getTreatment()
@@ -129,7 +124,7 @@
return packages;
}
- public Link getStatementLink(String type)
+ public SwordIdentifier getStatementLink(String type)
throws SWORDClientException
{
try
@@ -141,7 +136,7 @@
if (statementRel.equals(link.getRel()) &&
link.getMimeType().toString().equals(mt.toString()))
{
- return link;
+ return new SwordIdentifier(link);
}
}
return null;
@@ -152,16 +147,16 @@
}
}
- public Link getOREStatementLink()
+ public SwordIdentifier getOREStatementLink()
throws SWORDClientException
{
return this.getStatementLink("application/rdf+xml");
}
- public Link getAtomStatementLink()
+ public SwordIdentifier getAtomStatementLink()
throws SWORDClientException
{
- Link stmt = this.getStatementLink("application/atom+xml;type=feed");
+ SwordIdentifier stmt = this.getStatementLink("application/atom+xml;type=feed");
if (stmt == null)
{
// try an alternative mimetype
@@ -184,23 +179,29 @@
return dc;
}
- public IRI getSplashPageIRI()
+ public SwordIdentifier getSplashPageLink()
{
Link alt = this.entry.getAlternateLink();
if (alt != null)
{
- return alt.getHref();
+ return new SwordIdentifier(alt);
}
return null;
}
- public Link getOriginalDepositLink()
+ public SwordIdentifier getOriginalDepositLink()
{
- return this.entry.getLink(UriRegistry.REL_ORIGINAL_DEPOSIT);
+ return new SwordIdentifier(this.entry.getLink(UriRegistry.REL_ORIGINAL_DEPOSIT));
}
- public List<Link> getDerivedResourceLinks()
+ public List<SwordIdentifier> getDerivedResourceLinks()
{
- return this.entry.getLinks(UriRegistry.REL_DERIVED_RESOURCE);
+ List<SwordIdentifier> sis = new ArrayList<SwordIdentifier>();
+ List<Link> links = this.entry.getLinks(UriRegistry.REL_DERIVED_RESOURCE);
+ for (Link link : links)
+ {
+ sis.add(new SwordIdentifier(link));
+ }
+ return sis;
}
}
Modified: JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java 2012-03-16 16:23:32 UTC (rev 476)
+++ JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java 2012-03-17 10:22:59 UTC (rev 477)
@@ -1,6 +1,7 @@
package org.swordapp.client;
import org.apache.abdera.Abdera;
+import org.apache.abdera.i18n.iri.IRI;
import org.apache.abdera.model.Document;
import org.apache.abdera.model.Element;
import org.apache.abdera.model.Entry;
@@ -343,12 +344,13 @@
throws SWORDClientException, SWORDError, ProtocolViolationException
{
String url = null;
- Link eml = receipt.getEditMediaLink();
+ SwordIdentifier eml = receipt.getEditMediaLink();
if (eml != null)
{
- url = eml.getHref().toString();
+ url = eml.getHref();
+ return this.replaceMedia(url, deposit, auth);
}
- return this.replaceMedia(url, deposit, auth);
+ return null;
}
public SwordResponse replaceMedia(String editMediaURL, Deposit deposit, AuthCredentials auth)
@@ -882,12 +884,13 @@
throws SWORDClientException, ProtocolViolationException, SWORDError
{
String url = null;
- Link eml = receipt.getEditMediaLink();
+ SwordIdentifier eml = receipt.getEditMediaLink();
if (eml != null)
{
- url = eml.getHref().toString();
+ url = eml.getHref();
+ return this.complete(url, auth);
}
- return this.complete(url, auth);
+ return null;
}
public DepositReceipt complete(String editURL, AuthCredentials auth)
@@ -1182,7 +1185,25 @@
}
}
- public Content getContent(String contentURL, String mimeType)
+ public Content getContent(SwordIdentifier contentId)
+ throws SWORDClientException, ProtocolViolationException, SWORDError
+ {
+ return this.getContent(contentId.getHref(), contentId.getType(), UriRegistry.PACKAGE_SIMPLE_ZIP, null);
+ }
+
+ public Content getContent(SwordIdentifier contentId, AuthCredentials auth)
+ throws SWORDClientException, ProtocolViolationException, SWORDError
+ {
+ return this.getContent(contentId.getHref(), contentId.getType(), UriRegistry.PACKAGE_SIMPLE_ZIP, auth);
+ }
+
+ public Content getContent(SwordIdentifier contentId, String packaging, AuthCredentials auth)
+ throws SWORDClientException, ProtocolViolationException, SWORDError
+ {
+ return this.getContent(contentId.getHref(), contentId.getType(), packaging, auth);
+ }
+
+ public Content getContent(String contentURL, String mimeType)
throws SWORDClientException, ProtocolViolationException, SWORDError
{
return this.getContent(contentURL, mimeType, UriRegistry.PACKAGE_SIMPLE_ZIP, null);
@@ -1260,7 +1281,7 @@
{
throw new SWORDClientException(e);
}
- if (feedType.toString().equals(responseType.toString())) // urgh, but such is life
+ if (responseType != null && feedType.toString().equals(responseType.toString())) // urgh, but such is life
{
log.info("Content retrieved from " + url.toString() + " is an Atom Feed");
Document<Feed> doc = resp.getDocument();
Modified: JavaClient2.0/src/main/java/org/swordapp/client/SwordCli.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/SwordCli.java 2012-03-16 16:23:32 UTC (rev 476)
+++ JavaClient2.0/src/main/java/org/swordapp/client/SwordCli.java 2012-03-17 10:22:59 UTC (rev 477)
@@ -139,9 +139,9 @@
}
}
- Link oreStatementLink = receipt.getStatementLink("application/rdf+xml");
+ SwordIdentifier oreStatementLink = receipt.getStatementLink("application/rdf+xml");
String oreUri = oreStatementLink.getHref().toString();
- Link feedStatementLink = receipt.getStatementLink("application/atom+xml;type=feed");
+ SwordIdentifier feedStatementLink = receipt.getStatementLink("application/atom+xml;type=feed");
String feedUri = feedStatementLink.getHref().toString();
Statement oreStmt = client.getStatement(oreUri, new OreStatement(), auth);
@@ -339,7 +339,7 @@
}
}
- Link eml = receipt.getEditMediaLink();
+ SwordIdentifier eml = receipt.getEditMediaLink();
String emiri = eml.getHref().toString();
InputStream is2 = new FileInputStream(new File(exampleZip));
@@ -417,7 +417,7 @@
}
}
- Link eml = receipt.getEditMediaLink();
+ SwordIdentifier eml = receipt.getEditMediaLink();
String emiri = eml.getHref().toString();
SwordResponse resp = client.delete(emiri, auth);
@@ -522,7 +522,7 @@
}
}
- Link eml = receipt.getEditMediaLink("application/zip");
+ SwordIdentifier eml = receipt.getEditMediaLink("application/zip");
String emiri = eml.getHref().toString();
InputStream is2 = new FileInputStream(new File(exampleZip));
@@ -554,12 +554,11 @@
}
}
- String contentSrc = receipt.getContentSrc().toString();
- MimeType contentMime = receipt.getContentMimeType();
- Link eml = receipt.getEditMediaLink("application/atom+xml;type=feed");
+ SwordIdentifier contentSrc = receipt.getContentLink();
+ SwordIdentifier eml = receipt.getEditMediaLink("application/atom+xml;type=feed");
String emiri = eml.getHref().toString();
- System.out.println("Content: " + contentSrc + " - " + contentMime.toString());
+ System.out.println("Content: " + contentSrc.getHref() + " - " + contentSrc.getType());
System.out.println("EM: " + emiri);
// now we need to get the content out as an atom feed
@@ -593,16 +592,15 @@
}
}
- String contentSrc = receipt.getContentSrc().toString();
- MimeType contentMime = receipt.getContentMimeType();
- Link eml = receipt.getEditMediaLink("application/zip");
+ SwordIdentifier contentSrc = receipt.getContentLink();
+ SwordIdentifier eml = receipt.getEditMediaLink("application/zip");
String emiri = eml.getHref().toString();
- System.out.println("Content: " + contentSrc + " - " + contentMime.toString());
+ System.out.println("Content: " + contentSrc.getHref() + " - " + contentSrc.getType());
System.out.println("EM: " + emiri);
// now we need to get the content out
- Content content = client.getContent(emiri, contentMime.toString(), UriRegistry.PACKAGE_SIMPLE_ZIP, auth);
+ Content content = client.getContent(emiri, contentSrc.getType(), UriRegistry.PACKAGE_SIMPLE_ZIP, auth);
System.out.println(content.getPackaging() + " - " + content.getMimeType());
}
@@ -765,7 +763,7 @@
}
}
- Link odl = receipt.getOriginalDepositLink();
+ SwordIdentifier odl = receipt.getOriginalDepositLink();
InputStream is2 = new FileInputStream(new File(docx));
Deposit d2 = factory.replaceBinary(is2, "hy.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", UriRegistry.PACKAGE_BINARY, null, true, false);
System.out.println(odl.getHref().toString());
Added: JavaClient2.0/src/main/java/org/swordapp/client/SwordIdentifier.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/SwordIdentifier.java (rev 0)
+++ JavaClient2.0/src/main/java/org/swordapp/client/SwordIdentifier.java 2012-03-17 10:22:59 UTC (rev 477)
@@ -0,0 +1,63 @@
+package org.swordapp.client;
+
+import org.apache.abdera.i18n.iri.IRI;
+import org.apache.abdera.model.Link;
+
+import javax.activation.MimeType;
+
+public class SwordIdentifier
+{
+ private Link link = null;
+ private IRI iri = null;
+ private MimeType mimeType = null;
+
+ private String href = null;
+ private String type = null;
+ private String rel = null;
+
+ public SwordIdentifier(String href, String type, String rel)
+ {
+ this.href = href;
+ this.type = type;
+ this.rel = rel;
+ }
+
+ public SwordIdentifier(String href, String type)
+ {
+ this(href, type, null);
+ }
+
+ public SwordIdentifier(IRI iri, MimeType mimeType, String rel)
+ {
+ this(iri.toString(), mimeType != null ? mimeType.toString().replace(" ", "") : null, rel);
+
+ this.iri = iri;
+ this.mimeType = mimeType;
+ }
+
+ public SwordIdentifier(IRI iri, MimeType mimeType)
+ {
+ this(iri.toString(), mimeType != null ? mimeType.toString().replace(" ", "") : null);
+
+ this.iri = iri;
+ this.mimeType = mimeType;
+ }
+
+ public SwordIdentifier(Link link)
+ {
+ this(link.getHref(), link.getMimeType(), link.getRel());
+ this.link = link;
+ }
+
+ public String getHref() { return this.href; }
+
+ public String getType() { return this.type; }
+
+ public String getRel() { return this.rel; }
+
+ public Link getLink() { return this.link; }
+
+ public IRI getIRI() { return this.iri; }
+
+ public MimeType getMimeType() { return this.mimeType; }
+}
Modified: JavaClient2.0/src/test/java/org/swordapp/client/test/ClientTests.java
===================================================================
--- JavaClient2.0/src/test/java/org/swordapp/client/test/ClientTests.java 2012-03-16 16:23:32 UTC (rev 476)
+++ JavaClient2.0/src/test/java/org/swordapp/client/test/ClientTests.java 2012-03-17 10:22:59 UTC (rev 477)
@@ -1,12 +1,16 @@
package org.swordapp.client.test;
+import org.apache.abdera.i18n.iri.IRI;
import org.junit.*;
import static org.junit.Assert.*;
import org.swordapp.client.ClientConfiguration;
+import org.swordapp.client.Content;
import org.swordapp.client.Deposit;
import org.swordapp.client.EntryPart;
import org.swordapp.client.SWORDClient;
+import org.swordapp.client.SwordIdentifier;
+import javax.activation.MimeType;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
@@ -52,4 +56,68 @@
String s = new String(bytes);
assertEquals(s, "test");
}
+
+ @Test
+ public void contentObject()
+ throws Exception
+ {
+ Content content = new Content();
+
+ content.setInputStream(new ByteArrayInputStream("test".getBytes()));
+ content.setMimeType(new MimeType("application/atom+xml;type=feed"));
+ content.setPackaging("http://packaging/");
+
+ assertEquals(content.getMimeType().toString(), "application/atom+xml; type=feed");
+ assertEquals(content.getPackaging(), "http://packaging/");
+
+ byte[] bytes = new byte["test".getBytes().length];
+ content.getInputStream().read(bytes);
+ String s = new String(bytes);
+ assertEquals(s, "test");
+ }
+
+ @Test
+ public void identifierObject()
+ throws Exception
+ {
+ String href = "http://testing/";
+ String type = "application/atom+xml;type=feed";
+ String rel = "edit-media";
+
+ IRI iri = new IRI(href);
+ MimeType mime = new MimeType(type);
+
+ // test the different constructors
+ SwordIdentifier si = new SwordIdentifier(href, type, rel);
+ assertEquals(si.getHref(), href);
+ assertEquals(si.getType(), type);
+ assertEquals(si.getRel(), rel);
+ assertNull(si.getIRI());
+ assertNull(si.getLink());
+ assertNull(si.getMimeType());
+
+ SwordIdentifier si1 = new SwordIdentifier(href, type);
+ assertEquals(si1.getHref(), href);
+ assertEquals(si1.getType(), type);
+ assertNull(si1.getRel());
+ assertNull(si1.getIRI());
+ assertNull(si1.getLink());
+ assertNull(si1.getMimeType());
+
+ SwordIdentifier si2 = new SwordIdentifier(iri, mime, rel);
+ assertEquals(si2.getHref(), href);
+ assertEquals(si2.getType(), type);
+ assertEquals(si2.getRel(), rel);
+ assertEquals(si2.getIRI(), iri);
+ assertNull(si2.getLink());
+ assertEquals(si2.getMimeType(), mime);
+
+ SwordIdentifier si3 = new SwordIdentifier(iri, mime);
+ assertEquals(si3.getHref(), href);
+ assertEquals(si3.getType(), type);
+ assertNull(si3.getRel());
+ assertEquals(si3.getIRI(), iri);
+ assertNull(si3.getLink());
+ assertEquals(si3.getMimeType(), mime);
+ }
}
Modified: JavaClient2.0/src/test/java/org/swordapp/client/test/SSSSemiUnits.java
===================================================================
--- JavaClient2.0/src/test/java/org/swordapp/client/test/SSSSemiUnits.java 2012-03-16 16:23:32 UTC (rev 476)
+++ JavaClient2.0/src/test/java/org/swordapp/client/test/SSSSemiUnits.java 2012-03-17 10:22:59 UTC (rev 477)
@@ -123,13 +123,13 @@
assertTrue(receipt.getLocation() != null);
assertEquals(receipt.getStatusCode(), 201);
assertTrue(receipt.getAtomStatementLink() != null);
- assertEquals(receipt.getContentMimeType().toString(), "application/zip");
+ assertEquals(receipt.getContentLink().getType(), "application/zip");
assertEquals(receipt.getDerivedResourceLinks().size(), 4);
assertTrue(receipt.getEditLink() != null);
assertTrue(receipt.getOREStatementLink() != null);
assertTrue(receipt.getOriginalDepositLink() != null);
assertEquals(receipt.getPackaging().size(), 1);
- assertTrue(receipt.getSplashPageIRI() != null);
+ assertTrue(receipt.getSplashPageLink() != null);
assertTrue(receipt.getStatementLink("application/rdf+xml") != null);
assertTrue(receipt.getStatementLink("application/atom+xml;type=feed") != null);
assertTrue(receipt.getSwordEditLink() != null);
Modified: JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java
===================================================================
--- JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java 2012-03-16 16:23:32 UTC (rev 476)
+++ JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java 2012-03-17 10:22:59 UTC (rev 477)
@@ -1,20 +1,24 @@
package org.swordapp.client.test;
+import nu.xom.jaxen.function.FalseFunction;
import org.apache.commons.codec.digest.DigestUtils;
import org.junit.Test;
import org.junit.Before;
import static org.junit.Assert.*;
import org.swordapp.client.AuthCredentials;
import org.swordapp.client.ClientConfiguration;
+import org.swordapp.client.Content;
import org.swordapp.client.Deposit;
import org.swordapp.client.DepositReceipt;
import org.swordapp.client.EntryPart;
import org.swordapp.client.SWORDClient;
import org.swordapp.client.SWORDCollection;
+import org.swordapp.client.SWORDError;
import org.swordapp.client.ServiceDocument;
import org.swordapp.client.UriRegistry;
import java.io.FileInputStream;
+import java.util.List;
public class SpecTests
{
@@ -163,173 +167,214 @@
}
*/
- /* Python tests to mimic
+ @Test
+ public void basicCreateResourceWithEntry()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
- def test_07_basic_create_resource_with_entry(self):
- conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
- conn.get_service_document()
- col = conn.sd.workspaces[0][1][0]
- e = Entry(title="An entry only deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
- receipt = conn.create(col_iri = col.href,
- metadata_entry = e)
+ EntryPart ep = new EntryPart();
+ ep.addDublinCore("title", "An entry only deposit");
+ ep.addDublinCore("abstract", "abstract");
+ ep.addDublinCore("identifier", "http://whatever/");
- assert receipt.code == 201
- assert receipt.location != None
+ Deposit deposit = new Deposit();
+ deposit.setEntryPart(ep);
- # these last two assertions are contingent on if we actually get a
- # receipt back from the server (which we might not legitimately get)
- assert receipt.dom is None or receipt.parsed == True
- assert receipt.dom is None or receipt.valid == True
+ assertTrue(deposit.isEntryOnly());
- def test_08_advanced_create_resource_with_entry(self):
- conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
- conn.get_service_document()
- col = conn.sd.workspaces[0][1][0]
- e = Entry(title="An entry only deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
- receipt = conn.create(col_iri = col.href,
- metadata_entry = e,
- in_progress = True,
- suggested_identifier = "1234567890")
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass));
+ assertEquals(receipt.getStatusCode(), 201);
+ assertTrue(receipt.getLocation() != null);
+ }
- assert receipt.code == 201
- assert receipt.location != None
+ @Test
+ public void advancedCreateResourceWithEntry()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass, this.obo));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
- # these last two assertions are contingent on if we actually get a
- # receipt back from the server (which we might not legitimately get)
- assert receipt.dom is None or receipt.parsed == True
- assert receipt.dom is None or receipt.valid == True
+ EntryPart ep = new EntryPart();
+ ep.addDublinCore("title", "An entry only deposit");
+ ep.addDublinCore("abstract", "abstract");
+ ep.addDublinCore("identifier", "http://whatever/");
- def test_09_basic_retrieve_deposit_receipt(self):
- conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
- conn.get_service_document()
- col = conn.sd.workspaces[0][1][0]
- with open(PACKAGE) as pkg:
- receipt = conn.create(col_iri = col.href,
- payload=pkg,
- mimetype=PACKAGE_MIME,
- filename="example.zip",
- packaging = 'http://purl.org/net/sword/package/SimpleZip')
+ Deposit deposit = new Deposit();
+ deposit.setEntryPart(ep);
+ deposit.setInProgress(true);
+ deposit.setSuggestedIdentifier("1234567890");
- # we're going to work with the location
- assert receipt.location != None
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass, this.obo));
+ assertEquals(receipt.getStatusCode(), 201);
+ assertTrue(receipt.getLocation() != null);
+ }
- new_receipt = conn.get_deposit_receipt(receipt.location)
+ @Test
+ public void basicRetrieveDepositReceipt()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
- assert new_receipt.code == 200
- assert new_receipt.parsed == True
- assert new_receipt.valid == True
+ Deposit deposit = new Deposit();
+ deposit.setFile(new FileInputStream(this.file));
+ deposit.setMimeType("application/zip");
+ deposit.setFilename("example.zip");
+ deposit.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ deposit.setMd5(this.fileMd5);
- def test_10_advanced_retrieve_deposit_receipt(self):
- conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
- conn.get_service_document()
- col = conn.sd.workspaces[0][1][0]
- with open(PACKAGE) as pkg:
- receipt = conn.create(col_iri = col.href,
- payload=pkg,
- mimetype=PACKAGE_MIME,
- filename="example.zip",
- packaging = 'http://purl.org/net/sword/package/SimpleZip',
- in_progress = True,
- suggested_identifier = "0987654321")
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass));
+ assertTrue(receipt.getLocation() != null);
- # we're going to work with the location
- assert receipt.location != None
+ DepositReceipt newReceipt = client.getDepositReceipt(receipt.getLocation(), new AuthCredentials(this.user, this.pass));
+ assertEquals(newReceipt.getStatusCode(), 200);
+ assertTrue(newReceipt.getEntry() != null);
+ }
- new_receipt = conn.get_deposit_receipt(receipt.location)
+ @Test
+ public void advancedRetrieveDepositReceipt()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass, this.obo));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
- assert new_receipt.code == 200
- assert new_receipt.parsed == True
- assert new_receipt.valid == True
+ Deposit deposit = new Deposit();
+ deposit.setFile(new FileInputStream(this.file));
+ deposit.setMimeType("application/zip");
+ deposit.setFilename("example.zip");
+ deposit.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ deposit.setMd5(this.fileMd5);
+ deposit.setInProgress(true);
+ deposit.setSuggestedIdentifier("0987654321");
- def test_11_basic_retrieve_content_cont_iri(self):
- conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
- conn.get_service_document()
- col = conn.sd.workspaces[0][1][0]
- with open(PACKAGE) as pkg:
- receipt = conn.create(col_iri = col.href,
- payload=pkg,
- mimetype=PACKAGE_MIME,
- filename="example.zip",
- packaging='http://purl.org/net/sword/package/SimpleZip')
- # ensure that we have a receipt (the server may not give us one
- # by default)
- receipt = conn.get_deposit_receipt(receipt.location)
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass, this.obo));
+ assertTrue(receipt.getLocation() != null);
- # we're going to work with the cont_iri
- assert receipt.cont_iri is not None
+ DepositReceipt newReceipt = client.getDepositReceipt(receipt.getLocation(), new AuthCredentials(this.user, this.pass, this.obo));
+ assertEquals(newReceipt.getStatusCode(), 200);
+ assertTrue(newReceipt.getEntry() != null);
+ }
- resource = conn.get_resource(content_iri=receipt.cont_iri)
+ @Test
+ public void basicRetrieveContentContIRI()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
- assert resource.code == 200
- assert resource.content is not None
+ Deposit deposit = new Deposit();
+ deposit.setFile(new FileInputStream(this.file));
+ deposit.setMimeType("application/zip");
+ deposit.setFilename("example.zip");
+ deposit.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ deposit.setMd5(this.fileMd5);
- def test_12_basic_retrieve_content_em_iri(self):
- conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
- conn.get_service_document()
- col = conn.sd.workspaces[0][1][0]
- with open(PACKAGE) as pkg:
- receipt = conn.create(col_iri = col.href,
- payload=pkg,
- mimetype=PACKAGE_MIME,
- filename="example.zip",
- packaging='http://purl.org/net/sword/package/SimpleZip')
- # ensure that we have a receipt (the server may not give us one
- # by default)
- receipt = conn.get_deposit_receipt(receipt.location)
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass));
+ receipt = client.getDepositReceipt(receipt.getLocation(), new AuthCredentials(this.user, this.pass, this.obo));
- # we're going to work with the edit_media iri
- assert receipt.edit_media is not None
+ assertTrue(receipt.getContentLink() != null);
+ Content content = client.getContent(receipt.getContentLink());
- resource = conn.get_resource(content_iri=receipt.edit_media)
+ assertTrue(content.getInputStream() != null);
+ }
- assert resource.code == 200
- assert resource.content is not None
+ @Test
+ public void basicRetrieveContentEmIRI()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
- def test_13_advanced_retrieve_content_em_iri(self):
- conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
- conn.get_service_document()
- col = conn.sd.workspaces[0][1][0]
- with open(PACKAGE) as pkg:
- receipt = conn.create(col_iri = col.href,
- payload=pkg,
- mimetype=PACKAGE_MIME,
- filename="example.zip",
- packaging='http://purl.org/net/sword/package/SimpleZip')
- # ensure that we have a receipt (the server may not give us one
- # by default)
- receipt = conn.get_deposit_receipt(receipt.location)
+ Deposit deposit = new Deposit();
+ deposit.setFile(new FileInputStream(this.file));
+ deposit.setMimeType("application/zip");
+ deposit.setFilename("example.zip");
+ deposit.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ deposit.setMd5(this.fileMd5);
- packaging = 'http://purl.org/net/sword/package/SimpleZip'
- if receipt.packaging is not None and len(receipt.packaging) > 0:
- packaging = receipt.packaging[0]
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass));
+ receipt = client.getDepositReceipt(receipt.getLocation(), new AuthCredentials(this.user, this.pass));
- resource = conn.get_resource(content_iri=receipt.edit_media, packaging=packaging, on_behalf_of=SSS_OBO)
+ assertTrue(receipt.getEditMediaLink() != null);
+ Content content = client.getContent(receipt.getEditMediaLink(), new AuthCredentials(this.user, this.pass));
- assert resource.code == 200
- assert resource.content is not None
+ assertTrue(content.getInputStream() != null);
+ }
- def test_14_error_retrieve_content_em_iri(self):
- conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW,
- error_response_raises_exceptions=False)
- conn.get_service_document()
- col = conn.sd.workspaces[0][1][0]
- with open(PACKAGE) as pkg:
- receipt = conn.create(col_iri = col.href,
- payload=pkg,
- mimetype=PACKAGE_MIME,
- filename="example.zip",
- packaging='http://purl.org/net/sword/package/SimpleZip')
- # ensure that we have a receipt (the server may not give us one
- # by default)
- receipt = conn.get_deposit_receipt(receipt.location)
+ @Test
+ public void advancedRetrieveContentEmIRI()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass, this.obo));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
- error = 'http://purl.org/net/sword/package/IJustMadeThisUp'
- response = conn.get_resource(content_iri=receipt.edit_media, packaging=error)
+ Deposit deposit = new Deposit();
+ deposit.setFile(new FileInputStream(this.file));
+ deposit.setMimeType("application/zip");
+ deposit.setFilename("example.zip");
+ deposit.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ deposit.setMd5(this.fileMd5);
- assert response.code == 406
- assert isinstance(response, Error_Document)
- assert response.error_href == "http://purl.org/net/sword/error/ErrorContent"
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass, this.obo));
+ receipt = client.getDepositReceipt(receipt.getLocation(), new AuthCredentials(this.user, this.pass, this.obo));
+ assertTrue(receipt.getEditMediaLink() != null);
+
+ List<String> packagings = receipt.getPackaging();
+ String packaging = UriRegistry.PACKAGE_SIMPLE_ZIP;
+ if (packagings.size() > 0)
+ {
+ packaging = packagings.get(0);
+ }
+ Content content = client.getContent(receipt.getEditMediaLink(), packaging, new AuthCredentials(this.user, this.pass, this.obo));
+
+ assertTrue(content.getInputStream() != null);
+ }
+
+ @Test
+ public void errorRetrieveContentEmIRI()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
+
+ Deposit deposit = new Deposit();
+ deposit.setFile(new FileInputStream(this.file));
+ deposit.setMimeType("application/zip");
+ deposit.setFilename("example.zip");
+ deposit.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ deposit.setMd5(this.fileMd5);
+
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass));
+ receipt = client.getDepositReceipt(receipt.getLocation(), new AuthCredentials(this.user, this.pass));
+
+ String error = "http://purl.org/net/sword/package/IJustMadeThisUp";
+ boolean wasError = false;
+ try
+ {
+ Content content = client.getContent(receipt.getEditMediaLink(), error, new AuthCredentials(this.user, this.pass));
+ }
+ catch (SWORDError e)
+ {
+ assertEquals(e.getStatus(), 406);
+ assertEquals(e.getErrorURI(), "http://purl.org/net/sword/error/ErrorContent");
+ wasError = true;
+ }
+ assertTrue(wasError);
+ }
+
+ /* Python tests to mimic
+
def test_15_retrieve_content_em_iri_as_feed(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
conn.get_service_document()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-03-16 16:23:41
|
Revision: 476
http://sword-app.svn.sourceforge.net/sword-app/?rev=476&view=rev
Author: richard-jones
Date: 2012-03-16 16:23:32 +0000 (Fri, 16 Mar 2012)
Log Message:
-----------
add unused tests for multipart deposit, and add notes on why multipart doesn't work and a todo file to remind us
Modified Paths:
--------------
JavaClient2.0/src/main/java/org/swordapp/client/SWORDMultipartRequestEntity.java
JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java
Added Paths:
-----------
JavaClient2.0/TODO
Added: JavaClient2.0/TODO
===================================================================
--- JavaClient2.0/TODO (rev 0)
+++ JavaClient2.0/TODO 2012-03-16 16:23:32 UTC (rev 476)
@@ -0,0 +1,24 @@
+TODO List
+=========
+
+This is a register of some things that still need to be adequately handled in this code library
+
+1/ Multipart does not work.
+
+This occurs when a 401 Unauthorised challenge is received. In making the initial request, the library
+reads all of the data from the input stream to be delivered, and therefore cannot re-deliver it once
+authentication has taken place.
+
+
+Notes
+-----
+
+- Create mechanism for handling arbitrary response codes (might act on response codes that we understand, like
+302, etc); possible value in a response code handler with default behaviour that can be customised per-request
+
+- documentation
+
+- logging
+
+- modify foresite to allow namespace prefixes to be passed in
+
Modified: JavaClient2.0/src/main/java/org/swordapp/client/SWORDMultipartRequestEntity.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/SWORDMultipartRequestEntity.java 2012-03-16 15:57:39 UTC (rev 475)
+++ JavaClient2.0/src/main/java/org/swordapp/client/SWORDMultipartRequestEntity.java 2012-03-16 16:23:32 UTC (rev 476)
@@ -55,6 +55,8 @@
out.writeBytes("\r\n--" + this.boundary + "\r\n");
}
+ // FIXME: this fails if we receive an authentication request, because it has
+ // already burned through the input stream on the first attempt
private void writeInput(DataOutputStream out) throws IOException
{
if (this.contentType == null)
Modified: JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java
===================================================================
--- JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java 2012-03-16 15:57:39 UTC (rev 475)
+++ JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java 2012-03-16 16:23:32 UTC (rev 476)
@@ -8,6 +8,7 @@
import org.swordapp.client.ClientConfiguration;
import org.swordapp.client.Deposit;
import org.swordapp.client.DepositReceipt;
+import org.swordapp.client.EntryPart;
import org.swordapp.client.SWORDClient;
import org.swordapp.client.SWORDCollection;
import org.swordapp.client.ServiceDocument;
@@ -77,6 +78,8 @@
deposit.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
deposit.setMd5(this.fileMd5);
+ assertTrue(deposit.isBinaryOnly());
+
DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass));
assertEquals(receipt.getStatusCode(), 201);
assertTrue(receipt.getLocation() != null);
@@ -104,52 +107,64 @@
assertTrue(receipt.getLocation() != null);
}
- /* Python tests to mimic
+ /* FIXME: multipart is not currently functional ...
+ @Test
+ public void basicCreateResourceWithMutlipart()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
- def test_05_basic_create_resource_with_multipart(self):
- conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
- conn.get_service_document()
- col = conn.sd.workspaces[0][1][0]
- e = Entry(title="Foo", id="asidjasidj", dcterms_abstract="abstract", dcterms_title="my title")
- with open(PACKAGE) as pkg:
- receipt = conn.create(col_iri = col.href,
- metadata_entry = e,
- payload=pkg,
- mimetype=PACKAGE_MIME,
- filename="example.zip",
- packaging = 'http://purl.org/net/sword/package/SimpleZip')
+ EntryPart ep = new EntryPart();
+ ep.addDublinCore("title", "My Title");
- assert receipt.code == 201
- assert receipt.location != None
+ Deposit deposit = new Deposit();
+ deposit.setEntryPart(ep);
+ deposit.setFile(new FileInputStream(this.file));
+ deposit.setMimeType("application/zip");
+ deposit.setFilename("example.zip");
+ deposit.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ deposit.setMd5(this.fileMd5);
- # these last two assertions are contingent on if we actually get a
- # receipt back from the server (which we might not legitimately get)
- assert receipt.dom is None or receipt.parsed == True
- assert receipt.dom is None or receipt.valid == True
+ assertTrue(deposit.isMultipart());
- def test_06_advanced_create_resource_with_multipart(self):
- conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
- conn.get_service_document()
- col = conn.sd.workspaces[0][1][0]
- e = Entry(title="Foo", id="asidjasidj", dcterms_abstract="abstract", dcterms_title="my title")
- with open(PACKAGE) as pkg:
- receipt = conn.create(col_iri = col.href,
- metadata_entry = e,
- payload=pkg,
- mimetype=PACKAGE_MIME,
- filename="example.zip",
- packaging = 'http://purl.org/net/sword/package/SimpleZip',
- in_progress = True,
- suggested_identifier = "zyxwvutsrq")
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass));
+ assertEquals(receipt.getStatusCode(), 201);
+ assertTrue(receipt.getLocation() != null);
+ }
- assert receipt.code == 201
- assert receipt.location != None
+ @Test
+ public void advancedCreateResourceWithMutlipart()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass, this.obo));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
- # these last two assertions are contingent on if we actually get a
- # receipt back from the server (which we might not legitimately get)
- assert receipt.dom is None or receipt.parsed == True
- assert receipt.dom is None or receipt.valid == True
+ EntryPart ep = new EntryPart();
+ ep.addDublinCore("title", "My Title");
+ Deposit deposit = new Deposit();
+ deposit.setEntryPart(ep);
+ deposit.setFile(new FileInputStream(this.file));
+ deposit.setMimeType("application/zip");
+ deposit.setFilename("example.zip");
+ deposit.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ deposit.setMd5(this.fileMd5);
+ deposit.setInProgress(true);
+ deposit.setSuggestedIdentifier("abcdefg");
+
+ assertTrue(deposit.isMultipart());
+
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass, this.obo));
+ assertEquals(receipt.getStatusCode(), 201);
+ assertTrue(receipt.getLocation() != null);
+ }
+ */
+
+ /* Python tests to mimic
+
def test_07_basic_create_resource_with_entry(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
conn.get_service_document()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-03-16 15:57:49
|
Revision: 475
http://sword-app.svn.sourceforge.net/sword-app/?rev=475&view=rev
Author: richard-jones
Date: 2012-03-16 15:57:39 +0000 (Fri, 16 Mar 2012)
Log Message:
-----------
more tests around deposit, deposit receipt and binary deposit operations
Modified Paths:
--------------
JavaClient2.0/src/test/java/org/swordapp/client/test/ClientTests.java
JavaClient2.0/src/test/java/org/swordapp/client/test/SSSSemiUnits.java
JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java
Modified: JavaClient2.0/src/test/java/org/swordapp/client/test/ClientTests.java
===================================================================
--- JavaClient2.0/src/test/java/org/swordapp/client/test/ClientTests.java 2012-03-16 15:02:07 UTC (rev 474)
+++ JavaClient2.0/src/test/java/org/swordapp/client/test/ClientTests.java 2012-03-16 15:57:39 UTC (rev 475)
@@ -1,9 +1,15 @@
package org.swordapp.client.test;
import org.junit.*;
+import static org.junit.Assert.*;
import org.swordapp.client.ClientConfiguration;
+import org.swordapp.client.Deposit;
+import org.swordapp.client.EntryPart;
import org.swordapp.client.SWORDClient;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
public class ClientTests
{
@Test
@@ -15,4 +21,35 @@
// construct with a default ClientConfiguration
SWORDClient client2 = new SWORDClient(new ClientConfiguration());
}
+
+ @Test
+ public void depositObject()
+ throws Exception
+ {
+ Deposit deposit = new Deposit();
+
+ deposit.setSlug("abcdef");
+ deposit.setInProgress(true);
+ deposit.setFilename("example.zip");
+ deposit.setMd5("3df4ed");
+ deposit.setMetadataRelevant(true);
+ deposit.setMimeType("application/zip");
+ deposit.setPackaging("http://package/");
+ deposit.setEntryPart(new EntryPart());
+ deposit.setFile(new ByteArrayInputStream("test".getBytes()));
+
+ assertEquals(deposit.getSlug(), "abcdef");
+ assertEquals(deposit.getSuggestedIdentifier(), "abcdef");
+ assertTrue(deposit.isInProgress());
+ assertEquals(deposit.getFilename(), "example.zip");
+ assertEquals(deposit.getMd5(), "3df4ed");
+ assertTrue(deposit.isMetadataRelevant());
+ assertEquals(deposit.getPackaging(), "http://package/");
+ assertTrue(deposit.getEntryPart() != null);
+
+ byte[] bytes = new byte["test".getBytes().length];
+ deposit.getFile().read(bytes);
+ String s = new String(bytes);
+ assertEquals(s, "test");
+ }
}
Modified: JavaClient2.0/src/test/java/org/swordapp/client/test/SSSSemiUnits.java
===================================================================
--- JavaClient2.0/src/test/java/org/swordapp/client/test/SSSSemiUnits.java 2012-03-16 15:02:07 UTC (rev 474)
+++ JavaClient2.0/src/test/java/org/swordapp/client/test/SSSSemiUnits.java 2012-03-16 15:57:39 UTC (rev 475)
@@ -1,14 +1,19 @@
package org.swordapp.client.test;
+import org.apache.commons.codec.digest.DigestUtils;
import org.junit.Before;
import org.junit.Test;
import org.swordapp.client.AuthCredentials;
import org.swordapp.client.ClientConfiguration;
+import org.swordapp.client.Deposit;
+import org.swordapp.client.DepositReceipt;
import org.swordapp.client.SWORDClient;
import org.swordapp.client.SWORDCollection;
import org.swordapp.client.SWORDWorkspace;
import org.swordapp.client.ServiceDocument;
+import org.swordapp.client.UriRegistry;
+import java.io.FileInputStream;
import java.util.List;
import static org.junit.Assert.*;
@@ -27,14 +32,19 @@
private String user = null;
private String pass = null;
private String obo = null;
+ private String file = null;
+ private String fileMd5 = null;
@Before
public void setUp()
+ throws Exception
{
this.sdIRI = "http://localhost:8080/sd-uri";
this.user = "sword";
this.pass = "sword";
this.obo = "obo";
+ this.file = "/home/richard/Code/External/JavaClient2.0/src/test/resources/example.zip";
+ this.fileMd5 = DigestUtils.md5Hex(new FileInputStream(this.file));
}
@Test
@@ -90,4 +100,40 @@
List<String> ss = collection.getSubServices();
assertTrue(ss.size() == 1);
}
+
+ @Test
+ public void depositReceipt()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
+
+ Deposit deposit = new Deposit();
+ deposit.setFile(new FileInputStream(this.file));
+ deposit.setMimeType("application/zip");
+ deposit.setFilename("example.zip");
+ deposit.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ deposit.setMd5(this.fileMd5);
+
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass));
+
+ // check all of the methods on the receipt
+ assertTrue(receipt.getEditMediaLink() != null);
+ assertTrue(receipt.getLocation() != null);
+ assertEquals(receipt.getStatusCode(), 201);
+ assertTrue(receipt.getAtomStatementLink() != null);
+ assertEquals(receipt.getContentMimeType().toString(), "application/zip");
+ assertEquals(receipt.getDerivedResourceLinks().size(), 4);
+ assertTrue(receipt.getEditLink() != null);
+ assertTrue(receipt.getOREStatementLink() != null);
+ assertTrue(receipt.getOriginalDepositLink() != null);
+ assertEquals(receipt.getPackaging().size(), 1);
+ assertTrue(receipt.getSplashPageIRI() != null);
+ assertTrue(receipt.getStatementLink("application/rdf+xml") != null);
+ assertTrue(receipt.getStatementLink("application/atom+xml;type=feed") != null);
+ assertTrue(receipt.getSwordEditLink() != null);
+ assertTrue(receipt.getTreatment() != null);
+ assertTrue(receipt.getVerboseDescription() != null);
+ }
}
Modified: JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java
===================================================================
--- JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java 2012-03-16 15:02:07 UTC (rev 474)
+++ JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java 2012-03-16 15:57:39 UTC (rev 475)
@@ -35,7 +35,6 @@
this.pass = "sword";
this.obo = "obo";
this.file = "/home/richard/Code/External/JavaClient2.0/src/test/resources/example.zip";
-
this.fileMd5 = DigestUtils.md5Hex(new FileInputStream(this.file));
}
@@ -107,27 +106,6 @@
/* Python tests to mimic
- def test_04_advanced_create_resource_with_package(self):
- conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
- conn.get_service_document()
- col = conn.sd.workspaces[0][1][0]
- with open(PACKAGE) as pkg:
- receipt = conn.create(col_iri = col.href,
- payload=pkg,
- mimetype=PACKAGE_MIME,
- filename="example.zip",
- packaging = 'http://purl.org/net/sword/package/SimpleZip',
- in_progress = True,
- suggested_identifier = "abcdefghijklmnop")
-
- assert receipt.code == 201
- assert receipt.location != None
-
- # these last two assertions are contingent on if we actually get a
- # receipt back from the server (which we might not legitimately get)
- assert receipt.dom is None or receipt.parsed == True
- assert receipt.dom is None or receipt.valid == True
-
def test_05_basic_create_resource_with_multipart(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
conn.get_service_document()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-03-16 15:02:18
|
Revision: 474
http://sword-app.svn.sourceforge.net/sword-app/?rev=474&view=rev
Author: richard-jones
Date: 2012-03-16 15:02:07 +0000 (Fri, 16 Mar 2012)
Log Message:
-----------
add binary deposit test cases and add extra method to the deposit object to be in-line with the python client
Modified Paths:
--------------
JavaClient2.0/pom.xml
JavaClient2.0/src/main/java/org/swordapp/client/Deposit.java
JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java
JavaClient2.0/sword-client.iml
Added Paths:
-----------
JavaClient2.0/src/test/resources/
JavaClient2.0/src/test/resources/example.zip
Modified: JavaClient2.0/pom.xml
===================================================================
--- JavaClient2.0/pom.xml 2012-03-16 13:26:52 UTC (rev 473)
+++ JavaClient2.0/pom.xml 2012-03-16 15:02:07 UTC (rev 474)
@@ -75,5 +75,10 @@
<artifactId>junit</artifactId>
<version>4.4</version>
</dependency>
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>1.4</version>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
Modified: JavaClient2.0/src/main/java/org/swordapp/client/Deposit.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/Deposit.java 2012-03-16 13:26:52 UTC (rev 473)
+++ JavaClient2.0/src/main/java/org/swordapp/client/Deposit.java 2012-03-16 15:02:07 UTC (rev 474)
@@ -101,6 +101,16 @@
this.mimeType = mimeType;
}
+ public void setSuggestedIdentifier(String slug)
+ {
+ this.setSlug(slug);
+ }
+
+ public String getSuggestedIdentifier()
+ {
+ return this.getSlug();
+ }
+
public String getSlug()
{
return slug;
Modified: JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java
===================================================================
--- JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java 2012-03-16 13:26:52 UTC (rev 473)
+++ JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java 2012-03-16 15:02:07 UTC (rev 474)
@@ -1,27 +1,42 @@
package org.swordapp.client.test;
+import org.apache.commons.codec.digest.DigestUtils;
import org.junit.Test;
import org.junit.Before;
import static org.junit.Assert.*;
import org.swordapp.client.AuthCredentials;
import org.swordapp.client.ClientConfiguration;
+import org.swordapp.client.Deposit;
+import org.swordapp.client.DepositReceipt;
import org.swordapp.client.SWORDClient;
+import org.swordapp.client.SWORDCollection;
import org.swordapp.client.ServiceDocument;
+import org.swordapp.client.UriRegistry;
+import java.io.FileInputStream;
+
public class SpecTests
{
private String sdIRI = null;
private String user = null;
private String pass = null;
private String obo = null;
+ private String file = null;
+ private String fileMd5 = null;
@Before
public void setUp()
+ throws Exception
{
+ // FIXME: should read this all from some test config, or try to auto-locate
+ // resources (particularly the file)
this.sdIRI = "http://localhost:8080/sd-uri";
this.user = "sword";
this.pass = "sword";
this.obo = "obo";
+ this.file = "/home/richard/Code/External/JavaClient2.0/src/test/resources/example.zip";
+
+ this.fileMd5 = DigestUtils.md5Hex(new FileInputStream(this.file));
}
@Test
@@ -48,27 +63,50 @@
assertEquals(sd.getVersion(), "2.0");
}
- /* Python tests to mimic
+ @Test
+ public void basicCreateResourceWithPackage()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
- def test_03_basic_create_resource_with_package(self):
- conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
- conn.get_service_document()
- col = conn.sd.workspaces[0][1][0]
- with open(PACKAGE) as pkg:
- receipt = conn.create(col_iri = col.href,
- payload=pkg,
- mimetype=PACKAGE_MIME,
- filename="example.zip",
- packaging = 'http://purl.org/net/sword/package/SimpleZip')
+ Deposit deposit = new Deposit();
+ deposit.setFile(new FileInputStream(this.file));
+ deposit.setMimeType("application/zip");
+ deposit.setFilename("example.zip");
+ deposit.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ deposit.setMd5(this.fileMd5);
- assert receipt.code == 201
- assert receipt.location != None
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass));
+ assertEquals(receipt.getStatusCode(), 201);
+ assertTrue(receipt.getLocation() != null);
+ }
- # these last two assertions are contingent on if we actually get a
- # receipt back from the server (which we might not legitimately get)
- assert receipt.dom is None or receipt.parsed == True
- assert receipt.dom is None or receipt.valid == True
+ @Test
+ public void advancedCreateResourceWithPackage()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass, this.obo));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
+ Deposit deposit = new Deposit();
+ deposit.setFile(new FileInputStream(this.file));
+ deposit.setMimeType("application/zip");
+ deposit.setFilename("example.zip");
+ deposit.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ deposit.setMd5(this.fileMd5);
+ deposit.setInProgress(true);
+ deposit.setSuggestedIdentifier("abcdefg");
+
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass, this.obo));
+ assertEquals(receipt.getStatusCode(), 201);
+ assertTrue(receipt.getLocation() != null);
+ }
+
+ /* Python tests to mimic
+
def test_04_advanced_create_resource_with_package(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
conn.get_service_document()
Added: JavaClient2.0/src/test/resources/example.zip
===================================================================
(Binary files differ)
Property changes on: JavaClient2.0/src/test/resources/example.zip
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Modified: JavaClient2.0/sword-client.iml
===================================================================
--- JavaClient2.0/sword-client.iml 2012-03-16 13:26:52 UTC (rev 473)
+++ JavaClient2.0/sword-client.iml 2012-03-16 15:02:07 UTC (rev 474)
@@ -8,15 +8,15 @@
<sourceFolder url="file://$MODULE_DIR$/target/generated-sources/annotations" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
+ <sourceFolder url="file://$MODULE_DIR$/src/test/resources" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target/classes" />
<excludeFolder url="file://$MODULE_DIR$/target/test-classes" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
- <orderEntry type="library" name="Maven: junit:junit:4.4" level="project" />
<orderEntry type="library" name="Maven: commons-httpclient:commons-httpclient:3.1" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.0.4" level="project" />
- <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.2" level="project" />
+ <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.4" level="project" />
<orderEntry type="library" name="Maven: log4j:log4j:1.2.15" level="project" />
<orderEntry type="library" name="Maven: org.apache.abdera:abdera-client:1.1.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.abdera:abdera-core:1.1.1" level="project" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-03-16 13:26:58
|
Revision: 473
http://sword-app.svn.sourceforge.net/sword-app/?rev=473&view=rev
Author: richard-jones
Date: 2012-03-16 13:26:52 +0000 (Fri, 16 Mar 2012)
Log Message:
-----------
add some SSS specific tests which do their best to provide 'unit' tests for the client (which are not straightforward due to dependence on Abdera and lack of mocks for that library)
Added Paths:
-----------
JavaClient2.0/src/test/java/org/swordapp/client/test/SSSSemiUnits.java
Added: JavaClient2.0/src/test/java/org/swordapp/client/test/SSSSemiUnits.java
===================================================================
--- JavaClient2.0/src/test/java/org/swordapp/client/test/SSSSemiUnits.java (rev 0)
+++ JavaClient2.0/src/test/java/org/swordapp/client/test/SSSSemiUnits.java 2012-03-16 13:26:52 UTC (rev 473)
@@ -0,0 +1,93 @@
+package org.swordapp.client.test;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.swordapp.client.AuthCredentials;
+import org.swordapp.client.ClientConfiguration;
+import org.swordapp.client.SWORDClient;
+import org.swordapp.client.SWORDCollection;
+import org.swordapp.client.SWORDWorkspace;
+import org.swordapp.client.ServiceDocument;
+
+import java.util.List;
+
+import static org.junit.Assert.*;
+
+/**
+ * This class uses explicit knowledge of the SSS test server configuration
+ * in order to test units of functionality in the client library. This is
+ * because the Abdera library around which this is based does not support
+ * mocking (at least not trivially), and it is therefore impossible to
+ * truly isolate application units for testing. Instead we do the best
+ * we can here
+ */
+public class SSSSemiUnits
+{
+ private String sdIRI = null;
+ private String user = null;
+ private String pass = null;
+ private String obo = null;
+
+ @Before
+ public void setUp()
+ {
+ this.sdIRI = "http://localhost:8080/sd-uri";
+ this.user = "sword";
+ this.pass = "sword";
+ this.obo = "obo";
+ }
+
+ @Test
+ public void serviceDocumentBasics()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass));
+
+ // verify that the service document contains the sorts of things we are expecting
+ assertTrue(sd.getService() != null);
+ assertEquals(sd.getVersion(), "2.0");
+ assertTrue(sd.getMaxUploadSize() > 0);
+ }
+
+ @Test
+ public void serviceDocumentWorkspaces()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass));
+
+ assertEquals(sd.getWorkspaces().size(), 1);
+ }
+
+ @Test
+ public void serviceDocumentCollections()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass));
+
+ List<SWORDWorkspace> workspaces = sd.getWorkspaces();
+
+ assertEquals(workspaces.get(0).getCollections().size(), 10);
+
+ SWORDCollection collection = workspaces.get(0).getCollections().get(0);
+
+ List<String> ma = collection.getMultipartAccept();
+ List<String> sa = collection.getSinglepartAccept();
+
+ assertEquals(ma.size(), 1);
+ assertEquals(sa.size(), 1);
+ assertEquals(ma.get(0), sa.get(0));
+
+ assertTrue(collection.getCollectionPolicy() != null);
+ assertTrue(collection.allowsMediation());
+ assertTrue(collection.getTreatment() != null);
+
+ List<String> ap = collection.getAcceptPackaging();
+ assertTrue(ap.size() > 0);
+
+ List<String> ss = collection.getSubServices();
+ assertTrue(ss.size() == 1);
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-03-16 11:55:03
|
Revision: 472
http://sword-app.svn.sourceforge.net/sword-app/?rev=472&view=rev
Author: richard-jones
Date: 2012-03-16 11:54:51 +0000 (Fri, 16 Mar 2012)
Log Message:
-----------
add new class with spec tests; this is being set up to mimic the python client for consistency
Modified Paths:
--------------
JavaClient2.0/sword-client.iml
Added Paths:
-----------
JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java
Added: JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java
===================================================================
--- JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java (rev 0)
+++ JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java 2012-03-16 11:54:51 UTC (rev 472)
@@ -0,0 +1,889 @@
+package org.swordapp.client.test;
+
+import org.junit.Test;
+import org.junit.Before;
+import static org.junit.Assert.*;
+import org.swordapp.client.AuthCredentials;
+import org.swordapp.client.ClientConfiguration;
+import org.swordapp.client.SWORDClient;
+import org.swordapp.client.ServiceDocument;
+
+public class SpecTests
+{
+ private String sdIRI = null;
+ private String user = null;
+ private String pass = null;
+ private String obo = null;
+
+ @Before
+ public void setUp()
+ {
+ this.sdIRI = "http://localhost:8080/sd-uri";
+ this.user = "sword";
+ this.pass = "sword";
+ this.obo = "obo";
+ }
+
+ @Test
+ public void getServiceDocument()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass));
+
+ // verify that the service document contains the sorts of things we are expecting
+ assertTrue(sd.getService() != null);
+ assertEquals(sd.getVersion(), "2.0");
+ }
+
+ @Test
+ public void getServiceDocumentOBO()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass, this.obo));
+
+ // verify that the service document contains the sorts of things we are expecting
+ assertTrue(sd.getService() != null);
+ assertEquals(sd.getVersion(), "2.0");
+ }
+
+ /* Python tests to mimic
+
+ def test_03_basic_create_resource_with_package(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip')
+
+ assert receipt.code == 201
+ assert receipt.location != None
+
+ # these last two assertions are contingent on if we actually get a
+ # receipt back from the server (which we might not legitimately get)
+ assert receipt.dom is None or receipt.parsed == True
+ assert receipt.dom is None or receipt.valid == True
+
+ def test_04_advanced_create_resource_with_package(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip',
+ in_progress = True,
+ suggested_identifier = "abcdefghijklmnop")
+
+ assert receipt.code == 201
+ assert receipt.location != None
+
+ # these last two assertions are contingent on if we actually get a
+ # receipt back from the server (which we might not legitimately get)
+ assert receipt.dom is None or receipt.parsed == True
+ assert receipt.dom is None or receipt.valid == True
+
+ def test_05_basic_create_resource_with_multipart(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ e = Entry(title="Foo", id="asidjasidj", dcterms_abstract="abstract", dcterms_title="my title")
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ metadata_entry = e,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip')
+
+ assert receipt.code == 201
+ assert receipt.location != None
+
+ # these last two assertions are contingent on if we actually get a
+ # receipt back from the server (which we might not legitimately get)
+ assert receipt.dom is None or receipt.parsed == True
+ assert receipt.dom is None or receipt.valid == True
+
+ def test_06_advanced_create_resource_with_multipart(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ e = Entry(title="Foo", id="asidjasidj", dcterms_abstract="abstract", dcterms_title="my title")
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ metadata_entry = e,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip',
+ in_progress = True,
+ suggested_identifier = "zyxwvutsrq")
+
+ assert receipt.code == 201
+ assert receipt.location != None
+
+ # these last two assertions are contingent on if we actually get a
+ # receipt back from the server (which we might not legitimately get)
+ assert receipt.dom is None or receipt.parsed == True
+ assert receipt.dom is None or receipt.valid == True
+
+ def test_07_basic_create_resource_with_entry(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ e = Entry(title="An entry only deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
+ receipt = conn.create(col_iri = col.href,
+ metadata_entry = e)
+
+ assert receipt.code == 201
+ assert receipt.location != None
+
+ # these last two assertions are contingent on if we actually get a
+ # receipt back from the server (which we might not legitimately get)
+ assert receipt.dom is None or receipt.parsed == True
+ assert receipt.dom is None or receipt.valid == True
+
+ def test_08_advanced_create_resource_with_entry(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ e = Entry(title="An entry only deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
+ receipt = conn.create(col_iri = col.href,
+ metadata_entry = e,
+ in_progress = True,
+ suggested_identifier = "1234567890")
+
+ assert receipt.code == 201
+ assert receipt.location != None
+
+ # these last two assertions are contingent on if we actually get a
+ # receipt back from the server (which we might not legitimately get)
+ assert receipt.dom is None or receipt.parsed == True
+ assert receipt.dom is None or receipt.valid == True
+
+ def test_09_basic_retrieve_deposit_receipt(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip')
+
+ # we're going to work with the location
+ assert receipt.location != None
+
+ new_receipt = conn.get_deposit_receipt(receipt.location)
+
+ assert new_receipt.code == 200
+ assert new_receipt.parsed == True
+ assert new_receipt.valid == True
+
+ def test_10_advanced_retrieve_deposit_receipt(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip',
+ in_progress = True,
+ suggested_identifier = "0987654321")
+
+ # we're going to work with the location
+ assert receipt.location != None
+
+ new_receipt = conn.get_deposit_receipt(receipt.location)
+
+ assert new_receipt.code == 200
+ assert new_receipt.parsed == True
+ assert new_receipt.valid == True
+
+ def test_11_basic_retrieve_content_cont_iri(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging='http://purl.org/net/sword/package/SimpleZip')
+ # ensure that we have a receipt (the server may not give us one
+ # by default)
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ # we're going to work with the cont_iri
+ assert receipt.cont_iri is not None
+
+ resource = conn.get_resource(content_iri=receipt.cont_iri)
+
+ assert resource.code == 200
+ assert resource.content is not None
+
+ def test_12_basic_retrieve_content_em_iri(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging='http://purl.org/net/sword/package/SimpleZip')
+ # ensure that we have a receipt (the server may not give us one
+ # by default)
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ # we're going to work with the edit_media iri
+ assert receipt.edit_media is not None
+
+ resource = conn.get_resource(content_iri=receipt.edit_media)
+
+ assert resource.code == 200
+ assert resource.content is not None
+
+ def test_13_advanced_retrieve_content_em_iri(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging='http://purl.org/net/sword/package/SimpleZip')
+ # ensure that we have a receipt (the server may not give us one
+ # by default)
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ packaging = 'http://purl.org/net/sword/package/SimpleZip'
+ if receipt.packaging is not None and len(receipt.packaging) > 0:
+ packaging = receipt.packaging[0]
+
+ resource = conn.get_resource(content_iri=receipt.edit_media, packaging=packaging, on_behalf_of=SSS_OBO)
+
+ assert resource.code == 200
+ assert resource.content is not None
+
+ def test_14_error_retrieve_content_em_iri(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW,
+ error_response_raises_exceptions=False)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging='http://purl.org/net/sword/package/SimpleZip')
+ # ensure that we have a receipt (the server may not give us one
+ # by default)
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ error = 'http://purl.org/net/sword/package/IJustMadeThisUp'
+ response = conn.get_resource(content_iri=receipt.edit_media, packaging=error)
+
+ assert response.code == 406
+ assert isinstance(response, Error_Document)
+ assert response.error_href == "http://purl.org/net/sword/error/ErrorContent"
+
+ def test_15_retrieve_content_em_iri_as_feed(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging='http://purl.org/net/sword/package/SimpleZip')
+ # ensure that we have a receipt (the server may not give us one
+ # by default)
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ # we're going to work with the edit_media_feed iri
+ assert receipt.edit_media_feed is not None
+
+ response = conn.get_resource(content_iri=receipt.edit_media_feed)
+
+ assert response.code == 200
+ assert response.content is not None
+
+ # the response should be an xml document, so let's see if we can parse
+ # it. This should give us an exception which will fail the test if not
+ dom = etree.fromstring(response.content)
+
+ def test_16_basic_replace_file_content(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging='http://purl.org/net/sword/package/SimpleZip')
+ # ensure that we have a receipt (the server may not give us one
+ # by default)
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ # now do the replace
+ with open(PACKAGE) as pkg:
+ new_receipt = conn.update(dr = receipt,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="update.zip",
+ packaging='http://purl.org/net/sword/package/SimpleZip')
+
+ assert new_receipt.code == 204
+ assert new_receipt.dom is None
+
+ def test_17_advanced_replace_file_content(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging='http://purl.org/net/sword/package/SimpleZip')
+ # ensure that we have a receipt (the server may not give us one
+ # by default)
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ # now do the replace
+ with open(PACKAGE) as pkg:
+ new_receipt = conn.update(dr = receipt,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="update.zip",
+ packaging='http://purl.org/net/sword/package/SimpleZip',
+ metadata_relevant=True)
+
+ assert new_receipt.code == 204
+ assert new_receipt.dom is None
+
+ def test_18_basic_replace_metadata(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ e = Entry(title="An entry only deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
+ receipt = conn.create(col_iri = col.href, metadata_entry = e)
+
+ # ensure that we have a receipt (the server may not give us one
+ # by default)
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ # now do the replace
+ ne = Entry(title="A metadata update", id="asidjasidj", dcterms_abstract="new abstract", dcterms_identifier="http://elsewhere/")
+ new_receipt = conn.update(dr=receipt, metadata_entry=ne)
+
+ assert new_receipt.code == 204 or new_receipt.code == 200
+ if new_receipt.code == 204:
+ assert new_receipt.dom is None
+ if new_receipt.code == 200:
+ assert new_receipt.parsed == True
+ assert new_receipt.valid == True
+
+ def test_19_advanced_replace_metadata(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ e = Entry(title="An entry only deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
+ receipt = conn.create(col_iri = col.href, metadata_entry = e)
+
+ # ensure that we have a receipt (the server may not give us one
+ # by default)
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ # now do the replace
+ ne = Entry(title="A metadata update", id="asidjasidj", dcterms_abstract="new abstract", dcterms_identifier="http://elsewhere/")
+ new_receipt = conn.update(dr=receipt, metadata_entry=ne, in_progress=True)
+
+ assert new_receipt.code == 204 or new_receipt.code == 200
+ if new_receipt.code == 204:
+ assert new_receipt.dom is None
+ if new_receipt.code == 200:
+ assert new_receipt.parsed == True
+ assert new_receipt.valid == True
+
+ def test_20_basic_replace_with_multipart(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ metadata_entry = e,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip')
+
+ # ensure that we have a receipt (the server may not give us one
+ # by default)
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ # now do the replace
+ ne = Entry(title="A multipart update", id="asidjasidj", dcterms_abstract="new abstract", dcterms_identifier="http://elsewhere/")
+ with open(PACKAGE) as pkg:
+ new_receipt = conn.update(dr = receipt,
+ metadata_entry = ne,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="update.zip",
+ packaging='http://purl.org/net/sword/package/SimpleZip')
+
+ assert new_receipt.code == 204 or new_receipt.code == 200
+ if new_receipt.code == 204:
+ assert new_receipt.dom is None
+ if new_receipt.code == 200:
+ assert new_receipt.parsed == True
+ assert new_receipt.valid == True
+
+ def test_21_advanced_replace_with_multipart(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ metadata_entry = e,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip')
+
+ # ensure that we have a receipt (the server may not give us one
+ # by default)
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ # now do the replace
+ ne = Entry(title="A multipart update", id="asidjasidj", dcterms_abstract="new abstract", dcterms_identifier="http://elsewhere/")
+ with open(PACKAGE) as pkg:
+ new_receipt = conn.update(dr = receipt,
+ metadata_entry = ne,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="update.zip",
+ packaging='http://purl.org/net/sword/package/SimpleZip',
+ in_progress=True)
+
+ assert new_receipt.code == 204 or new_receipt.code == 200
+ if new_receipt.code == 204:
+ assert new_receipt.dom is None
+ if new_receipt.code == 200:
+ assert new_receipt.parsed == True
+ assert new_receipt.valid == True
+
+ def test_22_delete_content(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ metadata_entry = e,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip')
+
+ # ensure that we have a receipt (the server may not give us one
+ # by default)
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ # now delete the content but not the container
+ new_receipt = conn.delete_content_of_resource(dr=receipt)
+
+ assert new_receipt.code == 204
+ assert new_receipt.dom is None
+
+ def test_23_basic_add_content_to_resource_single_file(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip')
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ with open(PACKAGE) as pkg:
+ new_receipt = conn.add_file_to_resource(receipt.edit_media, pkg, "addition.zip", mimetype=PACKAGE_MIME)
+
+ assert new_receipt.code >= 200 and new_receipt.code < 400
+ assert new_receipt.location is not None
+ assert new_receipt.location != receipt.edit_media
+
+ def test_24_advanced_add_content_to_resource_single_file(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip')
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ with open(PACKAGE) as pkg:
+ new_receipt = conn.add_file_to_resource(receipt.edit_media, pkg, "addition.zip",
+ mimetype=PACKAGE_MIME,
+ metadata_relevant=True)
+
+ assert new_receipt.code >= 200 and new_receipt.code < 400
+ assert new_receipt.location is not None
+ assert new_receipt.location != receipt.edit_media
+
+ def test_25_basic_add_content_to_resource_package(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip')
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ with open(PACKAGE) as pkg:
+ new_receipt = conn.add_file_to_resource(receipt.edit_media, pkg, "addition.zip",
+ mimetype=PACKAGE_MIME,
+ packaging="http://purl.org/net/sword/package/SimpleZip")
+
+ assert new_receipt.code >= 200 and new_receipt.code < 400
+ assert new_receipt.location is not None
+ assert new_receipt.location == receipt.edit_media
+
+ def test_26_advanced_add_content_to_resource_package(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip')
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ with open(PACKAGE) as pkg:
+ new_receipt = conn.add_file_to_resource(receipt.edit_media, pkg, "addition.zip",
+ mimetype=PACKAGE_MIME,
+ packaging="http://purl.org/net/sword/package/SimpleZip",
+ metadata_relevant=True)
+
+ assert new_receipt.code >= 200 and new_receipt.code < 400
+ assert new_receipt.location is not None
+ assert new_receipt.location == receipt.edit_media
+
+ def test_27_basic_add_metadata(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ metadata_entry = e,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip')
+
+ # ensure that we have a receipt (the server may not give us one
+ # by default)
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ ne = Entry(title="Multipart deposit", id="asidjasidj", dcterms_identifier="http://another/",
+ dcterms_creator="Me!", dcterms_rights="CC0")
+ new_receipt = conn.append(dr=receipt, metadata_entry=ne)
+
+ assert new_receipt.code == 200
+
+ def test_28_advanced_add_metadata(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ metadata_entry = e,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip')
+
+ # ensure that we have a receipt (the server may not give us one
+ # by default)
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ ne = Entry(title="Multipart deposit", id="asidjasidj", dcterms_identifier="http://another/",
+ dcterms_creator="Me!", dcterms_rights="CC0")
+ new_receipt = conn.append(dr=receipt, metadata_entry=ne, in_progress=True)
+
+ assert new_receipt.code == 200
+
+ def test_29_basic_add_multipart(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ metadata_entry = e,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip')
+
+ # ensure that we have a receipt (the server may not give us one
+ # by default)
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ ne = Entry(title="Multipart deposit", id="asidjasidj", dcterms_identifier="http://another/",
+ dcterms_creator="Me!", dcterms_rights="CC0")
+ with open(PACKAGE) as pkg:
+ new_receipt = conn.append(dr=receipt,
+ metadata_entry=ne,
+ payload=pkg,
+ filename="addition.zip",
+ mimetype=PACKAGE_MIME,
+ packaging="http://purl.org/net/sword/package/SimpleZip")
+
+ assert new_receipt.code >= 200 and new_receipt.code < 400
+
+ def test_30_advanced_add_multipart(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ metadata_entry = e,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip')
+
+ # ensure that we have a receipt (the server may not give us one
+ # by default)
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ ne = Entry(title="Multipart deposit", id="asidjasidj", dcterms_identifier="http://another/",
+ dcterms_creator="Me!", dcterms_rights="CC0")
+ with open(PACKAGE) as pkg:
+ new_receipt = conn.append(dr=receipt,
+ metadata_entry=ne,
+ payload=pkg,
+ filename="addition.zip",
+ mimetype=PACKAGE_MIME,
+ packaging="http://purl.org/net/sword/package/SimpleZip",
+ in_progress=True,
+ metadata_relevant=True)
+
+ assert new_receipt.code >= 200 and new_receipt.code < 400
+
+ # FIXME: this test just does not work, for no discernable reason. The
+ # final assert of a 404 fails, and the debug output of the client says
+ # that the server responded with a 200. Nonetheless, the server logs show
+ # that it responded with a 404, which would suggest a caching issue in the
+ # client. I have so far been unable to figure out where, though, despite
+ # having tried turning off httplib2 caching and passing cache-control
+ # headers in as per the httplib2 documentation. help?
+ def test_31_delete_container(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO,
+ error_response_raises_exceptions=False)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ metadata_entry = e,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip')
+
+ # ensure that we have a receipt (the server may not give us one
+ # by default)
+ edit_iri = receipt.location
+ receipt = conn.get_deposit_receipt(edit_iri)
+
+ # delete the container
+ new_receipt = conn.delete_container(dr=receipt)
+
+ assert new_receipt.code == 204
+ assert new_receipt.dom is None
+
+ # the next check is that this 404s appropriately now
+ another_receipt = conn.get_deposit_receipt(edit_iri)
+
+ # FIXME: this is the broken assert
+ #assert another_receipt.code == 404
+
+ def test_32_get_atom_statement(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ metadata_entry = e,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip')
+
+ # ensure that we have a receipt (the server may not give us one
+ # by default)
+ edit_iri = receipt.location
+ receipt = conn.get_deposit_receipt(edit_iri)
+
+ assert receipt.atom_statement_iri is not None
+
+ # get the statement
+ statement = conn.get_atom_sword_statement(receipt.atom_statement_iri)
+
+ assert isinstance(statement, Atom_Sword_Statement)
+
+ def test_33_get_ore_statement(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ metadata_entry = e,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip')
+
+ # ensure that we have a receipt (the server may not give us one
+ # by default)
+ edit_iri = receipt.location
+ receipt = conn.get_deposit_receipt(edit_iri)
+
+ assert receipt.ore_statement_iri is not None
+
+ # get the statement
+ statement = conn.get_ore_sword_statement(receipt.ore_statement_iri)
+
+ assert isinstance(statement, Ore_Sword_Statement)
+
+ def test_34_complete_deposit(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ e = Entry(title="Foo", id="asidjasidj", dcterms_abstract="abstract", dcterms_title="my title")
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ metadata_entry = e,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip',
+ in_progress = True,
+ suggested_identifier = "zyxwvutsrq")
+
+ # ensure that we have a receipt (the server may not give us one
+ # by default)
+ edit_iri = receipt.location
+ receipt = conn.get_deposit_receipt(edit_iri)
+
+ response = conn.complete_deposit(dr=receipt)
+
+ assert response.code == 200
+
+ def test_35_error_checksum_mismatch(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW,
+ error_response_raises_exceptions=False)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip',
+ in_progress = True,
+ suggested_identifier = "zyxwvutsrq",
+ md5sum="123456789")
+
+ assert receipt.code == 412
+ assert isinstance(receipt, Error_Document)
+ assert receipt.error_href == "http://purl.org/net/sword/error/ErrorChecksumMismatch"
+
+ def test_36_error_bad_request(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW,
+ error_response_raises_exceptions=False)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip',
+ in_progress = "Invalid", # the API seems to allow this!
+ suggested_identifier = "zyxwvutsrq")
+
+ assert receipt.code == 400
+ assert isinstance(receipt, Error_Document)
+ assert receipt.error_href == "http://purl.org/net/sword/error/ErrorBadRequest"
+
+ def test_37_error_target_owner_unknown(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW,
+ error_response_raises_exceptions=False)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip',
+ in_progress = True,
+ suggested_identifier = "zyxwvutsrq",
+ on_behalf_of="richard") # we expressly set the wrong obo on the request rather than the connection
+
+ assert receipt.code == 403
+ assert isinstance(receipt, Error_Document)
+ assert receipt.error_href == "http://purl.org/net/sword/error/TargetOwnerUnknown"
+
+ def test_38_error_mediation_not_allowed(self):
+ # this is a placeholder; it's not possible to reliably test for this
+ pass
+
+ def test_39_error_method_not_allowed(self):
+ # this is a placeholder; it's not possible to reliably test for this
+ pass
+
+ def test_40_error_max_upload_size_exceeded(self):
+ # this is a placeholder; it's not possible to reliably test for this
+ pass
+
+ def test_41_get_service_document_unauthorised(self):
+ conn = Connection(SSS_URL, user_name="alsdkfjsdz", user_pass="ZAKJKLASJDF")
+ conn.get_service_document()
+ assert conn.sd is None
+ */
+}
Modified: JavaClient2.0/sword-client.iml
===================================================================
--- JavaClient2.0/sword-client.iml 2012-03-15 12:09:49 UTC (rev 471)
+++ JavaClient2.0/sword-client.iml 2012-03-16 11:54:51 UTC (rev 472)
@@ -6,12 +6,14 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/target/generated-sources/test-annotations" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/target/generated-sources/annotations" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target/classes" />
- <excludeFolder url="file://$MODULE_DIR$/target/maven-archiver" />
<excludeFolder url="file://$MODULE_DIR$/target/test-classes" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="library" name="Maven: junit:junit:4.4" level="project" />
<orderEntry type="library" name="Maven: commons-httpclient:commons-httpclient:3.1" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.0.4" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.2" level="project" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-03-15 12:10:00
|
Revision: 471
http://sword-app.svn.sourceforge.net/sword-app/?rev=471&view=rev
Author: richard-jones
Date: 2012-03-15 12:09:49 +0000 (Thu, 15 Mar 2012)
Log Message:
-----------
adds the following: failed scalability enhancement for webpy.py (code retained but unused), fix list_collections on default repository to provide valid atom feed, fix content type returned with service document
Modified Paths:
--------------
sss/branches/sss-2/sss/config.py
sss/branches/sss-2/sss/pylons_sword_controller.py
sss/branches/sss-2/sss/repository.py
sss/branches/sss-2/sss/webpy.py
Modified: sss/branches/sss-2/sss/config.py
===================================================================
--- sss/branches/sss-2/sss/config.py 2012-03-12 15:16:42 UTC (rev 470)
+++ sss/branches/sss-2/sss/config.py 2012-03-15 12:09:49 UTC (rev 471)
@@ -51,6 +51,12 @@
"store_dir" : "./store/",
# If you are using Apache you should set the store directory in full
+ # The directory where incoming content will be temporarily stored
+ "tmp_dir" : "./tmp/",
+
+ # The chunk size used to copy file streams into and out of the temp directory
+ "copy_chunk_size" : 8096,
+
# explicitly set the sword version, so if you're testing validation of
# service documents you can "break" it.
"sword_version" : "2.0",
Modified: sss/branches/sss-2/sss/pylons_sword_controller.py
===================================================================
--- sss/branches/sss-2/sss/pylons_sword_controller.py 2012-03-12 15:16:42 UTC (rev 470)
+++ sss/branches/sss-2/sss/pylons_sword_controller.py 2012-03-15 12:09:49 UTC (rev 471)
@@ -401,7 +401,8 @@
# if we get here authentication was successful and we carry on (we don't care who authenticated)
ss = SwordServer(config, auth)
sd = ss.service_document(path)
- response.content_type = "text/xml"
+ response.content_type = "application/atomsvc+xml"
+ #response.content_type = "text/xml"
ssslog.info("Returning " + response.status + " from request on " + inspect.stack()[0][3])
return sd
Modified: sss/branches/sss-2/sss/repository.py
===================================================================
--- sss/branches/sss-2/sss/repository.py 2012-03-12 15:16:42 UTC (rev 470)
+++ sss/branches/sss-2/sss/repository.py 2012-03-15 12:09:49 UTC (rev 471)
@@ -254,6 +254,19 @@
# create an empty feed element for the collection
feed = etree.Element(self.ns.ATOM + "feed", nsmap=self.cmap)
+
+ title = etree.SubElement(feed, self.ns.ATOM + "title")
+ title.text = "Title: " + id
+ myid = etree.SubElement(feed, self.ns.ATOM + "id")
+ myid.text = self.um.col_uri(id)
+ atomlink = etree.SubElement(feed, self.ns.ATOM + "link")
+ atomlink.set('rel', 'self')
+ atomlink.set('href', self.um.col_uri(id))
+ updated = etree.SubElement(feed, self.ns.ATOM + "updated")
+ updated.text = datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ")
+ author = etree.SubElement(feed, self.ns.ATOM + "author")
+ authorname = etree.SubElement(author, self.ns.ATOM + "name")
+ authorname.text = "Simple Sword Server"
# if the collection path does not exist, then return the empty feed
cpath = os.path.join(self.configuration.store_dir, str(id))
@@ -264,9 +277,21 @@
parts = os.listdir(cpath)
for part in parts:
entry = etree.SubElement(feed, self.ns.ATOM + "entry")
+ entrytitle = etree.SubElement(entry, self.ns.ATOM + "title")
+ entrytitle.text = "Title: " + part
+ entryid = etree.SubElement(entry, self.ns.ATOM + "id")
+ entryid.text = self.um.edit_uri(id, part)
+ entryupdated = etree.SubElement(entry, self.ns.ATOM + "updated")
+ entryupdated.text = datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ")
+ summary = etree.SubElement(entry, self.ns.ATOM + "summary")
+ summary.text = "Summary for " + part
link = etree.SubElement(entry, self.ns.ATOM + "link")
link.set("rel", "edit")
link.set("href", self.um.edit_uri(id, part))
+ link2 = etree.SubElement(entry, self.ns.ATOM + "link")
+ link2.set("rel", "alternate")
+ link2.set("type", "text/html")
+ link2.set("href", self.um.edit_uri(id, part))
# pretty print and return
return etree.tostring(feed, pretty_print=True)
Modified: sss/branches/sss-2/sss/webpy.py
===================================================================
--- sss/branches/sss-2/sss/webpy.py 2012-03-12 15:16:42 UTC (rev 470)
+++ sss/branches/sss-2/sss/webpy.py 2012-03-15 12:09:49 UTC (rev 471)
@@ -1,4 +1,4 @@
-import web, re, base64, urllib, uuid
+import web, re, base64, urllib, uuid, os
from web.wsgiserver import CherryPyWSGIServer
from core import Auth, SwordError, AuthException, DepositRequest, DeleteRequest
from negotiator import ContentNegotiator, AcceptParameters, ContentType
@@ -73,6 +73,32 @@
# Define a set of handlers for the various URLs defined above to be used by web.py
class SwordHttpHandler(object):
+
+ def read_to_tmp(self, web):
+ # the incoming body content is in wsgi.input, which is a file-like object
+ # but which only supports "read", not useful extras like "seek", so we
+ # stream this into a temp file, and return a handle to that instead
+ size = web.utils.intget(web.ctx.env.get('CONTENT_LENGTH'), 0)
+ wsgi_input = web.ctx.env['wsgi.input']
+ if not os.path.exists(config.tmp_dir):
+ os.mkdir(config.tmp_dir)
+ fn = os.path.join(config.tmp_dir, str(uuid.uuid4()))
+ ssslog.info("Reading incoming content of size " + str(size) + "to temp file " + fn)
+ if wsgi_input is not None:
+ with open(fn, "wb") as outfile:
+ while size > 0:
+ chunk_size = config.copy_chunk_size if size > config.copy_chunk_size else size
+ chunk = wsgi_input.rfile.read(chunk_size)
+ if chunk is None or chunk == "":
+ break
+ outfile.write(chunk)
+ outfile.flush()
+ os.fsync(outfile.fileno())
+ size -= chunk_size
+ with open(fn, "r") as tmpfile:
+ return tmpfile
+ return None
+
def http_basic_authenticate(self, web):
# extract the appropriate HTTP headers
auth_header = web.ctx.env.get('HTTP_AUTHORIZATION')
@@ -180,7 +206,118 @@
except ValidationException as e:
raise SwordError(error_uri=Errors.bad_request, msg=e.message)
+
+ ''' FIXME: this was an experimental version which was supposed to scale
+ def validate_deposit_request(self, web, file_handle, entry_section=None, binary_section=None, multipart_section=None, empty_section=None, allow_multipart=True, allow_empty=False):
+ h = HttpHeaders()
+
+ # map the headers to standard http
+ mapped_headers = self._map_webpy_headers(web.ctx.environ)
+ ssslog.debug("Validating on header dictionary: " + str(mapped_headers))
+
+ # run the validation
+ try:
+ # there must be both an "atom" and "payload" input or data in web.data()
+ webin = web.input()
+ if len(webin) != 2 and len(webin) > 0:
+ raise ValidationException("Multipart request does not contain exactly 2 parts")
+ if len(webin) >= 2 and not webin.has_key("atom") and not webin.has_key("payload"):
+ raise ValidationException("Multipart request must contain Content-Dispositions with names 'atom' and 'payload'")
+ if len(webin) > 0 and not allow_multipart:
+ raise ValidationException("Multipart request not permitted in this context")
+
+ # if we get to here then we have a valid multipart or no multipart
+ is_multipart = False
+ is_empty = False
+ if len(webin) != 2:
+ if file_handle is not None:
+ file_handle.seek(0, 0)
+ byte = file_handle.read(1)
+ if byte == "" and allow_empty:
+ # the body is empty
+ ssslog.debug("first byte of deposit request is the empty string")
+ is_empty = True
+ else:
+ ssslog.debug("first byte of deposit request is \"" + byte + "\" ... not an empty request")
+ file_handle.seek(0, 0)
+ else:
+ is_empty = True
+ """
+ # NOTE: the wsgi_input is a SizeCheckWrapper object which imperfectly
+ # wraps a file object. We therefore have to access the "rfile"
+ # property to interact with the file itself (although that is dangerous,
+ # as the file will be WSGI implementation specific)
+ wsgi_input = web.ctx.env['wsgi.input']
+ # if there is a wsgi input object with seek enabled, it may have already
+ # been read by webpy, so we seek back to the start
+ #if hasattr(wsgi_input, "seek"):
+ if wsgi_input is not None:
+ # in empty requests, the wsgi input object doesn't have a seek() method
+ # so we have to check for it
+ # wsgi_input.rfile.seek(0, 0)
+
+ # read just one byte out of the file, to see if there's any content
+ # if there is not, byte will be the empty string
+ byte = wsgi_input.rfile.read(1)
+ if byte == "" and allow_empty:
+ # the body is empty
+ ssslog.debug("first byte of deposit request is the empty string")
+ is_empty = True
+ else:
+ ssslog.debug("first byte of deposit request is \"" + byte + "\" ... not an empty request")
+ # wsgi_input.rfile.seek(0, 0)
+
+ elif wsgi_input is None:
+ is_empty = True
+ """
+
+ # validate whether we allow an empty deposit
+ if is_empty and not allow_empty:
+ raise ValidationException("No content sent to the server")
+ elif is_empty and allow_empty:
+ ssslog.info("Validating an empty deposit (could be a control operation)")
+ else:
+ ssslog.info("Validating a multipart deposit")
+ is_multipart = True
+
+ """
+ if wsgi_input is None or wsgi_input.read().strip() == "": # FIXME: this IS NOT safe to scale
+ if allow_empty:
+ ssslog.info("Validating an empty deposit (could be a control operation)")
+ is_empty = True
+ else:
+ raise ValidationException("No content sent to the server")
+ """
+ """
+ if len(webin) != 2: # if it is not multipart
+ if web.data() is None or web.data().strip() == "": # FIXME: this does not look safe to scale
+ if allow_empty:
+ ssslog.info("Validating an empty deposit (could be a control operation)")
+ is_empty = True
+ else:
+ raise ValidationException("No content sent to the server")
+ """
+
+
+ is_entry = False
+ content_type = mapped_headers.get("CONTENT-TYPE")
+ if content_type is not None and content_type.startswith("application/atom+xml"):
+ ssslog.info("Validating an atom-only deposit")
+ is_entry = True
+
+ if not is_entry and not is_multipart and not is_empty:
+ ssslog.info("Validating a binary deposit")
+
+ section = entry_section if is_entry else multipart_section if is_multipart else empty_section if is_empty else binary_section
+
+ # now validate the http headers
+ h.validate(mapped_headers, section)
+
+ except ValidationException as e:
+ raise SwordError(error_uri=Errors.bad_request, msg=e.message)
+ '''
+
def get_deposit(self, web, auth=None, atom_only=False):
# FIXME: this reads files into memory, and therefore does not scale
# FIXME: this does not deal with the Media Part headers on a multipart deposit
@@ -245,7 +382,80 @@
# now just attach the authentication data and return
d.auth = auth
return d
+
+ ''' FIXME: this was an experimental version which was supposed to scale
+ def get_deposit(self, web, file_handle, auth=None, atom_only=False):
+ # FIXME: this reads files into memory, and therefore does not scale
+ # FIXME: this does not deal with the Media Part headers on a multipart deposit
+ """
+ Take a web.py web object and extract from it the parameters and content required for a SWORD deposit. This
+ includes determining whether this is an Atom Multipart request or not, and extracting the atom/payload where
+ appropriate. It also includes extracting the HTTP headers which are relevant to deposit, and for those not
+ supplied providing their defaults in the returned DepositRequest object
+ """
+ d = DepositRequest()
+ # map the webpy headers to something more standard
+ mapped_headers = self._map_webpy_headers(web.ctx.environ)
+
+ # get the headers that have been provided. Any headers which have not been provided will
+ # will have default values applied
+ h = HttpHeaders()
+ d.set_from_headers(h.get_sword_headers(mapped_headers))
+
+ if d.content_type.startswith("application/atom+xml"):
+ atom_only=True
+
+ empty_request = False
+ if d.content_length == 0:
+ ssslog.info("Received empty deposit request")
+ empty_request = True
+ if d.content_length > config.max_upload_size:
+ raise SwordError(error_uri=Errors.max_upload_size_exceeded,
+ msg="Max upload size is " + str(config.max_upload_size) +
+ "; incoming content length was " + str(d.content_length))
+
+ # find out if this is a multipart or not
+ is_multipart = False
+
+ # FIXME: these headers aren't populated yet, because the webpy api doesn't
+ # appear to have a mechanism to retrieve them. urgh.
+ entry_part_headers = {}
+ media_part_headers = {}
+ webin = web.input()
+ if len(webin) == 2:
+ ssslog.info("Received multipart deposit request")
+ d.atom = webin['atom']
+ # FIXME: this reads the payload into memory, we need to sort that out
+ # read the zip file from the base64 encoded string
+ d.content = base64.decodestring(webin['payload'])
+ is_multipart = True
+ elif not empty_request:
+ # if this wasn't a multipart, and isn't an empty request, then the data is in web.data(). This could be a binary deposit or
+ # an atom entry deposit - reply on the passed/determined argument to determine which
+ if atom_only:
+ ssslog.info("Received Entry deposit request")
+ d.atom = file_handle.read() # read from the tmp file
+ else:
+ ssslog.info("Received Binary deposit request")
+ d.content = file_handle.read() # read from the tmp file
+ """
+ wsgi_input = web.ctx.env['wsgi.input']
+ if wsgi_input is not None:
+ wsgi_input.rfile.seek(0, 0)
+ d.content = wsgi_input.rfile.read()
+ """
+
+ if is_multipart:
+ d.filename = h.extract_filename(media_part_headers)
+ else:
+ d.filename = h.extract_filename(mapped_headers)
+
+ # now just attach the authentication data and return
+ d.auth = auth
+ return d
+ '''
+
def get_delete(self, web, auth=None):
"""
Take a web.py web object and extract from it the parameters and content required for a SWORD delete request.
@@ -284,7 +494,8 @@
# if we get here authentication was successful and we carry on (we don't care who authenticated)
ss = SwordServer(config, auth)
sd = ss.service_document(sub_path)
- web.header("Content-Type", "text/xml")
+ web.header("Content-Type", "application/atomsvc+xml")
+ # web.header("Content-Type", "text/xml")
return sd
class Collection(SwordHttpHandler):
@@ -311,7 +522,7 @@
cl = ss.list_collection(collection)
web.header("Content-Type", "text/xml")
return cl
-
+
def POST(self, collection):
"""
POST either an Atom Multipart request, or a simple package into the specified collection
@@ -325,6 +536,14 @@
# authenticate
auth = self.http_basic_authenticate(web)
+ # FIXME: this was supposed to help us with our scalability, but
+ # unfortunately the way that web.py works, it is not possible to
+ # read the incoming file to disk and still use the other functions
+ # on the web object (e.g. input())
+
+ # store any body content in a temp file
+ #fh = self.read_to_tmp(web)
+
# check the validity of the request
self.validate_deposit_request(web, "6.3.3", "6.3.1", "6.3.2")
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-03-12 15:16:53
|
Revision: 470
http://sword-app.svn.sourceforge.net/sword-app/?rev=470&view=rev
Author: richard-jones
Date: 2012-03-12 15:16:42 +0000 (Mon, 12 Mar 2012)
Log Message:
-----------
add basic junit test
Modified Paths:
--------------
JavaClient2.0/pom.xml
JavaClient2.0/src/test/java/org/swordapp/client/test/ClientTests.java
JavaClient2.0/sword-client.iml
Modified: JavaClient2.0/pom.xml
===================================================================
--- JavaClient2.0/pom.xml 2012-03-12 14:20:19 UTC (rev 469)
+++ JavaClient2.0/pom.xml 2012-03-12 15:16:42 UTC (rev 470)
@@ -70,5 +70,10 @@
<artifactId>servlet-api</artifactId>
<version>2.4</version>
</dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.4</version>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
Modified: JavaClient2.0/src/test/java/org/swordapp/client/test/ClientTests.java
===================================================================
--- JavaClient2.0/src/test/java/org/swordapp/client/test/ClientTests.java 2012-03-12 14:20:19 UTC (rev 469)
+++ JavaClient2.0/src/test/java/org/swordapp/client/test/ClientTests.java 2012-03-12 15:16:42 UTC (rev 470)
@@ -1,6 +1,18 @@
package org.swordapp.client.test;
+import org.junit.*;
+import org.swordapp.client.ClientConfiguration;
+import org.swordapp.client.SWORDClient;
+
public class ClientTests
{
-
+ @Test
+ public void simpleClientInit()
+ {
+ // construct without arguments
+ SWORDClient client1 = new SWORDClient();
+
+ // construct with a default ClientConfiguration
+ SWORDClient client2 = new SWORDClient(new ClientConfiguration());
+ }
}
Modified: JavaClient2.0/sword-client.iml
===================================================================
--- JavaClient2.0/sword-client.iml 2012-03-12 14:20:19 UTC (rev 469)
+++ JavaClient2.0/sword-client.iml 2012-03-12 15:16:42 UTC (rev 470)
@@ -4,8 +4,6 @@
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
- <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/target/generated-sources/test-annotations" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/target/generated-sources/annotations" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target/classes" />
@@ -14,10 +12,6 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
- <orderEntry type="library" name="Maven: xml-apis:xml-apis:1.3.03" level="project" />
- <orderEntry type="library" name="Maven: xerces:xercesImpl:2.8.0" level="project" />
- <orderEntry type="library" name="Maven: xom:xom:1.2.5" level="project" />
- <orderEntry type="library" name="Maven: javax.servlet:servlet-api:2.4" level="project" />
<orderEntry type="library" name="Maven: commons-httpclient:commons-httpclient:3.1" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.0.4" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.2" level="project" />
@@ -54,7 +48,7 @@
<orderEntry type="library" name="Maven: xalan:xalan:2.7.0" level="project" />
<orderEntry type="library" name="Maven: commons-cli:commons-cli:1.0" level="project" />
<orderEntry type="library" name="Maven: commons-lang:commons-lang:1.0" level="project" />
- <orderEntry type="library" name="Maven: junit:junit:3.7" level="project" />
+ <orderEntry type="library" name="Maven: junit:junit:4.4" level="project" />
<orderEntry type="library" name="Maven: joda-time:joda-time:1.6" level="project" />
<orderEntry type="library" name="Maven: xom:xom:1.2.5" level="project" />
<orderEntry type="library" name="Maven: javax.servlet:servlet-api:2.4" level="project" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-03-12 14:20:30
|
Revision: 469
http://sword-app.svn.sourceforge.net/sword-app/?rev=469&view=rev
Author: richard-jones
Date: 2012-03-12 14:20:19 +0000 (Mon, 12 Mar 2012)
Log Message:
-----------
various minor additions to testing code
Modified Paths:
--------------
JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java
JavaClient2.0/src/main/java/org/swordapp/client/SwordCli.java
JavaClient2.0/sword-client.iml
Modified: JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java 2012-02-28 12:17:46 UTC (rev 468)
+++ JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java 2012-03-12 14:20:19 UTC (rev 469)
@@ -686,7 +686,7 @@
ResponseStatus rs = rcm.addToMediaResource(status);
if (rs.isCorrect() || rs.isIncorrectButAllowed())
{
- log.info("Delete request on " + url.toString() + " returned HTTP status " + status + "; SUCCESS");
+ log.info("Add request on " + url.toString() + " returned HTTP status " + status + "; SUCCESS");
if (rs.isIncorrectButAllowed())
{
Modified: JavaClient2.0/src/main/java/org/swordapp/client/SwordCli.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/SwordCli.java 2012-02-28 12:17:46 UTC (rev 468)
+++ JavaClient2.0/src/main/java/org/swordapp/client/SwordCli.java 2012-03-12 14:20:19 UTC (rev 469)
@@ -19,11 +19,13 @@
private String exampleZip = "/Users/richard/Code/External/SSS/example.zip";
private String image = "/Users/richard/Code/Internal/DepositMO/Dome_sm.jpg";
private String docx = "/Users/richard/Code/Internal/DepositMO/hy.docx";
+ private String bagit = "/Users/richard/Dropbox/Documents/DUO/BagIt.zip";
//private String sdIRI = "http://localhost:8080/sd-uri";
- private String sdIRI = "http://localhost:8080/sword2/servicedocument";
+ private String sdIRI = "http://localhost:8080/swordv2/servicedocument";
private String user = "richard";
private String pass = "dspace";
private String obo = null;
+ private String mediaUri = "http://localhost:8080/swordv2/edit-media/34";
public static void main(String[] args)
throws Exception
@@ -32,7 +34,7 @@
// cli.trySwordServiceDocument();
// cli.tryCollectionEntries();
// cli.tryBinaryDeposit();
-// cli.tryEntryDeposit();
+// cli.tryEntryDeposit();
// cli.tryMultipartDeposit();
// cli.tryContentRetrieve();
// cli.tryFeedRetrieve();
@@ -49,9 +51,37 @@
// cli.tryContinuedDeposit();
// cli.tryImage();
// cli.tryDocument();
- cli.tryFileReplace();
+// cli.tryFileReplace();
+// cli.tryAddToMediaResource();
+ cli.tryFSDeposit();
}
+ private void tryFSDeposit()
+ throws Exception
+ {
+ System.out.println("tryFSDeposit");
+ SWORDClient client = new SWORDClient();
+ InputStream is = new FileInputStream(new File(bagit));
+ DepositFactory factory = new DepositFactory();
+ Deposit deposit = factory.newBinaryOnly(is, "bagit.zip", "application/zip", "http://duo.uio.no/terms/package/FSBagIt", null, null, true);
+ AuthCredentials auth = new AuthCredentials(this.user, this.pass, this.obo);
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, auth);
+ DepositReceipt receipt = null;
+ List<SWORDWorkspace> ws = sd.getWorkspaces();
+ for (SWORDWorkspace w : ws)
+ {
+ List<SWORDCollection> collections = w.getCollections();
+ for (SWORDCollection c : collections)
+ {
+ // do the deposit to the first collection we find
+ receipt = client.deposit(c, deposit, auth);
+ break;
+ }
+ }
+ System.out.println(receipt.getEditLink().getHref().toString());
+ receipt.getEntry().writeTo(System.out);
+ }
+
private void tryContinuedDeposit()
throws Exception
{
@@ -333,6 +363,36 @@
content.getFeed().writeTo(System.out);
}
+ private void tryAddToMediaResource()
+ throws Exception
+ {
+ System.out.println("tryAddToContainer");
+ // first we need to put some content in
+ SWORDClient client = new SWORDClient();
+ DepositFactory factory = new DepositFactory();
+ AuthCredentials auth = new AuthCredentials(this.user, this.pass, this.obo);
+
+ InputStream is2 = new FileInputStream(new File(exampleZip));
+ Deposit updateDeposit = factory.addMediaResource(is2, "example2.zip", "application/zip");
+ SwordResponse resp = client.addToMediaResource(mediaUri, updateDeposit, auth);
+ System.out.println(resp.getStatusCode());
+
+ if (resp instanceof DepositReceipt)
+ {
+ ((DepositReceipt) resp).getEntry().writeTo(System.out);
+ }
+ else
+ {
+ System.out.println("Response was NOT a deposit receipt");
+ }
+
+ // now we need to get the content out as an atom feed to see the multiple files
+ Content content = client.getContent(mediaUri, "application/atom+xml;type=feed", null, auth);
+
+ // prove that we got a feed
+ content.getFeed().writeTo(System.out);
+ }
+
private void tryDeleteContent()
throws Exception
{
@@ -555,7 +615,7 @@
ep.addDublinCore("title", "Richard Woz Ere");
ep.addDublinCore("bibliographicCitation", "this is my citation");
DepositFactory factory = new DepositFactory();
- Deposit deposit = factory.newMetadataOnly(ep);
+ Deposit deposit = factory.newMetadataOnly(ep, null, true);
AuthCredentials auth = new AuthCredentials(this.user, this.pass, this.obo);
ServiceDocument sd = client.getServiceDocument(this.sdIRI, auth);
DepositReceipt receipt = null;
Modified: JavaClient2.0/sword-client.iml
===================================================================
--- JavaClient2.0/sword-client.iml 2012-02-28 12:17:46 UTC (rev 468)
+++ JavaClient2.0/sword-client.iml 2012-03-12 14:20:19 UTC (rev 469)
@@ -4,11 +4,12 @@
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/target/generated-sources/test-annotations" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/target/generated-sources/annotations" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target/classes" />
+ <excludeFolder url="file://$MODULE_DIR$/target/maven-archiver" />
<excludeFolder url="file://$MODULE_DIR$/target/test-classes" />
</content>
<orderEntry type="inheritedJdk" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-02-28 12:17:57
|
Revision: 468
http://sword-app.svn.sourceforge.net/sword-app/?rev=468&view=rev
Author: richard-jones
Date: 2012-02-28 12:17:46 +0000 (Tue, 28 Feb 2012)
Log Message:
-----------
fix typo in list_collections handling
Modified Paths:
--------------
sss/branches/sss-2/sss/webpy.py
Modified: sss/branches/sss-2/sss/webpy.py
===================================================================
--- sss/branches/sss-2/sss/webpy.py 2012-02-21 16:50:14 UTC (rev 467)
+++ sss/branches/sss-2/sss/webpy.py 2012-02-28 12:17:46 UTC (rev 468)
@@ -308,7 +308,7 @@
# if we get here authentication was successful and we carry on (we don't care who authenticated)
ss = SwordServer(config, auth)
- cl = sss.list_collection(collection)
+ cl = ss.list_collection(collection)
web.header("Content-Type", "text/xml")
return cl
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-02-21 16:50:25
|
Revision: 467
http://sword-app.svn.sourceforge.net/sword-app/?rev=467&view=rev
Author: richard-jones
Date: 2012-02-21 16:50:14 +0000 (Tue, 21 Feb 2012)
Log Message:
-----------
add minor logging improvements
Modified Paths:
--------------
sss/branches/sss-2/sss/pylons_sword_controller.py
Modified: sss/branches/sss-2/sss/pylons_sword_controller.py
===================================================================
--- sss/branches/sss-2/sss/pylons_sword_controller.py 2012-02-09 16:56:15 UTC (rev 466)
+++ sss/branches/sss-2/sss/pylons_sword_controller.py 2012-02-21 16:50:14 UTC (rev 467)
@@ -112,8 +112,10 @@
response.status_int = sword_error.status
ssslog.info("Returning error (" + str(sword_error.status) + ") - " + str(sword_error.error_uri))
if not sword_error.empty:
+ ssslog.debug("Returning error document: " + sword_error.error_document)
response.content_type = "text/xml"
return sword_error.error_document
+ ssslog.debug("Returning empty body in error response")
return
def _map_webpy_headers(self, headers):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-02-09 16:56:26
|
Revision: 466
http://sword-app.svn.sourceforge.net/sword-app/?rev=466&view=rev
Author: richard-jones
Date: 2012-02-09 16:56:15 +0000 (Thu, 09 Feb 2012)
Log Message:
-----------
add enhanced handling for non-DC metadata in entry documents
Modified Paths:
--------------
sss/branches/sss-2/sss/core.py
Modified: sss/branches/sss-2/sss/core.py
===================================================================
--- sss/branches/sss-2/sss/core.py 2012-02-08 11:44:33 UTC (rev 465)
+++ sss/branches/sss-2/sss/core.py 2012-02-09 16:56:15 UTC (rev 466)
@@ -149,13 +149,13 @@
packaging=[], state_uris=[], updated=None, dc_metadata={},
generator=("http://www.swordapp.org/sss", __version__),
verbose_description=None, treatment=None, original_deposit_uri=None, derived_resource_uris=[], nsmap=None,
- xml_source=None):
+ xml_source=None, other_metadata=None):
self.ns = Namespaces()
self.drmap = {None: self.ns.ATOM_NS, "sword" : self.ns.SWORD_NS, "dcterms" : self.ns.DC_NS}
if nsmap is not None:
self.drmap = nsmap
- self.other_metadata = {}
+ self.other_metadata = other_metadata if other_metadata is not None else []
self.dc_metadata = dc_metadata
self.atom_id = atom_id if atom_id is not None else "urn:uuid:" + str(uuid.uuid4())
self.updated = updated if updated is not None else datetime.now()
@@ -222,12 +222,8 @@
else:
self.dc_metadata[field] = [element.text.strip()]
else:
- if element.text is not None: # handle empty elements
- if self.other_metadata.has_key(field):
- self.other_metadata[field].append(element.text.strip())
- else:
- self.other_metadata[field] = [element.text.strip()]
-
+ # add any unhandled elements to the other_metadata
+ self.other_metadata.append(element)
def _canonical_tag(self, tag):
ns, field = tag.rsplit("}", 1)
@@ -395,6 +391,10 @@
dr.set("rel", "http://purl.org/net/sword/terms/derivedResource")
dr.set("href", uri)
+ # finally, add any foreign markup to the dom
+ for fm in self.other_metadata:
+ entry.append(fm)
+
return etree.tostring(entry, pretty_print=True)
class SDCollection(object):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-02-08 11:44:44
|
Revision: 465
http://sword-app.svn.sourceforge.net/sword-app/?rev=465&view=rev
Author: richard-jones
Date: 2012-02-08 11:44:33 +0000 (Wed, 08 Feb 2012)
Log Message:
-----------
add documentation to new standard config values, and also add CLI validation routine
Modified Paths:
--------------
sss/branches/sss-2/sss/config.py
Modified: sss/branches/sss-2/sss/config.py
===================================================================
--- sss/branches/sss-2/sss/config.py 2012-02-07 10:53:52 UTC (rev 464)
+++ sss/branches/sss-2/sss/config.py 2012-02-08 11:44:33 UTC (rev 465)
@@ -10,6 +10,35 @@
DEFAULT_CONFIG = """
{
+ ############################################################################
+ # SWORD SERVER CONFIGURATION
+ ############################################################################
+ # This configuration file specifies the parameters for SSS
+ #
+ # Each configuration option can be accessed as an attribute of the
+ # Configuration python object. e.g.
+ #
+ # Configuration().base_url
+ #
+ # You may add any other configuration options directly to this JSON file
+ # and they will be picked up in the same way by the Configuration object.
+ #
+ # Some core configuration options have special methods for access built into
+ # the Configuration object (check the docs for details)
+ #
+ # This file is JSON formatted with one extension: comments are allowed.
+ # Comments are must be on a line of their own, and prefixed with #. The #
+ # must be the first non-whitespace character on the line. The configuration
+ # interpreter will strip all such lines before parsing the JSON, but will
+ # leave blank lines in the resulting JSON so that errors may be detected
+ # accurately by line number.
+ #
+ # To validate an this file, run:
+ #
+ # python config.py /path/to/sss.conf.json
+ #
+ ############################################################################
+
# The base url of the webservice where SSS is deployed
"base_url" : "http://localhost:8080/",
# if you are using Apache, you should probably use this base_url instead
@@ -101,25 +130,40 @@
# we can turn off deposit receipts, which is allowed by the specification
"return_deposit_receipt" : true,
+ # The acceptable formats that the server can return the media resource in
+ # on request.
+ # This is used in Content Negotiation during GET on the EM-URI
"media_resource_formats" : [
{"content_type" : "application/zip", "packaging": "http://purl.org/net/sword/package/SimpleZip"},
{"content_type" : "application/zip"},
{"content_type" : "application/atom+xml;type=feed"},
{"content_type" : "text/html"}
],
+
+ # If no Accept parameters are given to the server on GET to the EM-URI the
+ # following defaults will be used to determine the response type
"media_resource_default" : {
"content_type" : "application/zip"
},
+ # The acceptable formats that the server can return the entry document in
+ # on request
+ # This is used in Content Negotiation during GET on the Edit-URI
"container_formats" : [
{"content_type" : "application/atom+xml;type=entry" },
{"content_type" : "application/atom+xml;type=feed" },
{"content_type" : "application/rdf+xml" }
],
+
+ # If no Accept parameters are given to the server on GET to the Edit-URI the
+ # following defaults will be used to determine the response type
"container_format_default" : {
"content_type" : "application/atom+xml;type=entry"
},
+ # Dynamically load the implementation classes for the 3 main interfaces
+ # In this default configuration we use the built-in SSS repository's
+ # implementations for everything
"sword_server" : "sss.repository.SSS",
"authenticator" : "sss.repository.SSSAuthenticator",
"webui" : "sss.repository.WebInterface"
@@ -252,3 +296,13 @@
def __getattr__(self, attr):
return self.cfg.get(attr, None)
+
+if __name__ == "__main__":
+ # if we are run from the command line, run validation over the
+ # specified file
+ if len(sys.argv) != 2:
+ print "Please supply a path to a file to validate"
+ exit()
+ print "Validating Configuration File: " + sys.argv[1]
+ c = Configuration(config_file=sys.argv[1])
+ print "File is valid"
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-02-07 10:54:02
|
Revision: 464
http://sword-app.svn.sourceforge.net/sword-app/?rev=464&view=rev
Author: richard-jones
Date: 2012-02-07 10:53:52 +0000 (Tue, 07 Feb 2012)
Log Message:
-----------
fix bug with basic item web page and add type attribute to auto-discovery statement links
Modified Paths:
--------------
sss/branches/sss-2/sss/repository.py
Modified: sss/branches/sss-2/sss/repository.py
===================================================================
--- sss/branches/sss-2/sss/repository.py 2012-01-26 14:18:36 UTC (rev 463)
+++ sss/branches/sss-2/sss/repository.py 2012-02-07 10:53:52 UTC (rev 464)
@@ -1222,12 +1222,12 @@
file_frag = self._layout_files(statement)
frag = "<h1>Item: " + id + "</h1>"
- frag += "<strong>State</strong>: " + state_frag
+ frag += "<strong>State(s)</strong>: " + state_frag
frag += self._layout_sections(md_frag, file_frag)
head_frag = "<link rel=\"http://purl.org/net/sword/terms/edit\" href=\"" + self.um.edit_uri(collection, id) + "\"/>"
- head_frag += "<link rel=\"http://purl.org/net/sword/terms/statement\" href=\"" + self.um.state_uri(collection, id, "atom") + "\"/>"
- head_frag += "<link rel=\"http://purl.org/net/sword/terms/statement\" href=\"" + self.um.state_uri(collection, id, "ore") + "\"/>"
+ head_frag += "<link rel=\"http://purl.org/net/sword/terms/statement\" type=\"application/atom+xml\" href=\"" + self.um.state_uri(collection, id, "atom") + "\"/>"
+ head_frag += "<link rel=\"http://purl.org/net/sword/terms/statement\" type=\"application/rdf+xml\" href=\"" + self.um.state_uri(collection, id, "ore") + "\"/>"
return self._wrap_html("Item: " + id, frag, head_frag)
@@ -1249,10 +1249,10 @@
return frag
def _get_state_frag(self, statement):
- if statement.in_progress:
- return statement.in_progress_uri
- else:
- return statement.archived_uri
+ frag = ""
+ for state, desc in statement.states:
+ frag += state + " (" + desc + ") "
+ return frag
def _layout_sections(self, metadata, files):
return "<table border=\"0\"><tr><td valign=\"top\">" + metadata + "</td><td valign=\"top\">" + files + "</td></tr></table>"
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-01-26 14:18:43
|
Revision: 463
http://sword-app.svn.sourceforge.net/sword-app/?rev=463&view=rev
Author: richard-jones
Date: 2012-01-26 14:18:36 +0000 (Thu, 26 Jan 2012)
Log Message:
-----------
fix bugs with calls to updated auth object in demo repository
Modified Paths:
--------------
sss/branches/sss-2/sss/core.py
sss/branches/sss-2/sss/repository.py
Modified: sss/branches/sss-2/sss/core.py
===================================================================
--- sss/branches/sss-2/sss/core.py 2012-01-24 16:07:01 UTC (rev 462)
+++ sss/branches/sss-2/sss/core.py 2012-01-26 14:18:36 UTC (rev 463)
@@ -954,9 +954,9 @@
"""
Get an lxml Element object back representing this statement
"""
+ if existing_rdf_as_string is not None:
+ ssslog.debug("Merging with supplied RDF string: " + existing_rdf_as_string)
- ssslog.debug("Merging with supplied RDF string: " + existing_rdf_as_string)
-
# first parse in the existing rdf if necessary
rdf = None
aggregation = None
Modified: sss/branches/sss-2/sss/repository.py
===================================================================
--- sss/branches/sss-2/sss/repository.py 2012-01-24 16:07:01 UTC (rev 462)
+++ sss/branches/sss-2/sss/repository.py 2012-01-26 14:18:36 UTC (rev 463)
@@ -333,8 +333,8 @@
s = Statement()
s.aggregation_uri = agg_uri
s.rem_uri = edit_uri
- by = deposit.auth.by if deposit.auth is not None else None
- obo = deposit.auth.obo if deposit.auth is not None else None
+ by = deposit.auth.username if deposit.auth is not None else None
+ obo = deposit.auth.on_behalf_of if deposit.auth is not None else None
if deposit_uri is not None:
s.original_deposit(deposit_uri, datetime.now(), deposit.packaging, by, obo)
s.aggregates = derived_resource_uris
@@ -488,8 +488,8 @@
s.aggregation_uri = agg_uri
s.rem_uri = edit_uri
if deposit_uri is not None:
- by = deposit.auth.by if deposit.auth is not None else None
- obo = deposit.auth.obo if deposit.auth is not None else None
+ by = deposit.auth.username if deposit.auth is not None else None
+ obo = deposit.auth.on_behalf_of if deposit.auth is not None else None
s.original_deposit(deposit_uri, datetime.now(), deposit.packaging, by, obo)
s.add_state(state_uri, state_description)
s.aggregates = derived_resource_uris
@@ -616,8 +616,8 @@
# An identifier which will resolve to the package just deposited
deposit_uri = self.um.part_uri(collection, id, fn)
- by = deposit.auth.by if deposit.auth is not None else None
- obo = deposit.auth.obo if deposit.auth is not None else None
+ by = deposit.auth.username if deposit.auth is not None else None
+ obo = deposit.auth.on_behalf_of if deposit.auth is not None else None
s.original_deposit(deposit_uri, datetime.now(), deposit.packaging, by, obo)
# a list of identifiers which will resolve to the derived resources
@@ -756,8 +756,8 @@
deposit_uri = self.um.part_uri(collection, id, fn)
# add the new deposit
- by = deposit.auth.by if deposit.auth is not None else None
- obo = deposit.auth.obo if deposit.auth is not None else None
+ by = deposit.auth.username if deposit.auth is not None else None
+ obo = deposit.auth.on_behalf_of if deposit.auth is not None else None
s.original_deposit(deposit_uri, datetime.now(), deposit.packaging, by, obo)
# add the new list of aggregations to the existing list, allowing the
@@ -896,7 +896,7 @@
def check_delete_errors(self, delete):
# have we been asked to do a mediated delete, when this is not allowed?
if delete.auth is not None:
- if delete.auth.obo is not None and not self.configuration.mediation:
+ if delete.auth.on_behalf_of is not None and not self.configuration.mediation:
raise SwordError(Errors.mediation_not_allowed)
def check_deposit_errors(self, deposit):
@@ -914,7 +914,7 @@
# have we been asked to do a mediated deposit, when this is not allowed?
if deposit.auth is not None:
- if deposit.auth.obo is not None and not self.configuration.mediation:
+ if deposit.auth.on_behalf_of is not None and not self.configuration.mediation:
raise SwordError(error_uri=Errors.mediation_not_allowed)
return None
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-01-24 16:07:11
|
Revision: 462
http://sword-app.svn.sourceforge.net/sword-app/?rev=462&view=rev
Author: richard-jones
Date: 2012-01-24 16:07:01 +0000 (Tue, 24 Jan 2012)
Log Message:
-----------
enable pylons controller to use repoze.who for authentication
Modified Paths:
--------------
sss/branches/sss-2/sss/core.py
sss/branches/sss-2/sss/pylons_sword_controller.py
Modified: sss/branches/sss-2/sss/core.py
===================================================================
--- sss/branches/sss-2/sss/core.py 2012-01-23 12:15:56 UTC (rev 461)
+++ sss/branches/sss-2/sss/core.py 2012-01-24 16:07:01 UTC (rev 462)
@@ -139,6 +139,9 @@
def basic_authenticate(self, username, password, obo):
raise NotImplementedError()
+
+ def repoze_who_authenticate(self, identity, obo):
+ raise NotImplementedError()
class EntryDocument(object):
@@ -557,18 +560,16 @@
return etree.tostring(entry, pretty_print=True)
class AuthException(Exception):
- def __init__(self, authentication_failed=False, target_owner_unknown=False):
+ def __init__(self, authentication_failed=False, target_owner_unknown=False, msg=None):
self.authentication_failed = authentication_failed
self.target_owner_unknown = target_owner_unknown
+ self.msg = msg
class Auth(object):
- def __init__(self, by=None, obo=None):
- self.by = by
- self.obo = obo
+ def __init__(self, username=None, on_behalf_of=None):
+ self.username = username
+ self.on_behalf_of = on_behalf_of
- def success(self):
- return self.by is not None and not self.target_owner_unknown
-
class SWORDRequest(object):
"""
General class to represent any sword request (such as deposit or delete)
Modified: sss/branches/sss-2/sss/pylons_sword_controller.py
===================================================================
--- sss/branches/sss-2/sss/pylons_sword_controller.py 2012-01-23 12:15:56 UTC (rev 461)
+++ sss/branches/sss-2/sss/pylons_sword_controller.py 2012-01-24 16:07:01 UTC (rev 462)
@@ -42,7 +42,39 @@
# Generically useful methods
############################
+ def authenticate(self):
+ # first check to see if there's a repoze.who auth
+ identity = request.environ.get("repoze.who.identity")
+ if identity is not None:
+ # we have authenticated with repoze.who already
+ return self.repoze_who_authenticate()
+ else:
+ # try and do HTTP basic
+ return self.http_basic_authenticate()
+
+ def repoze_who_authenticate(self):
+ ssslog.debug("Authentication handled by repoze.who")
+
+ # get the auth details
+ identity = request.environ.get("repoze.who.identity")
+ obo = request.environ.get(HEADER_MAP[HttpHeaders.on_behalf_of])
+
+ ssslog.info("Authentication details: " + str(identity["repoze.who.userid"]) + "; On Behalf Of: " + str(obo))
+
+ authenticator = Authenticator(config)
+ try:
+ auth = authenticator.repoze_who_authenticate(identity, obo)
+ except AuthException as e:
+ if e.authentication_failed:
+ raise SwordError(status=401, empty=True)
+ elif e.target_owner_unknown:
+ raise SwordError(error_uri=Errors.target_owner_unknown, msg="unknown user " + str(obo) + " as on behalf of user")
+
+ return auth
+
def http_basic_authenticate(self):
+ ssslog.debug("Attempting HTTP Basic Authentication")
+
# extract the appropriate HTTP headers
auth_header = request.environ.get('HTTP_AUTHORIZATION')
obo = request.environ.get(HEADER_MAP[HttpHeaders.on_behalf_of])
@@ -360,7 +392,7 @@
# authenticate
try:
- auth = self.http_basic_authenticate()
+ auth = self.authenticate()
except SwordError as e:
return self.manage_error(e)
@@ -382,7 +414,7 @@
# authenticate
try:
- auth = self.http_basic_authenticate()
+ auth = self.authenticate()
except SwordError as e:
return self.manage_error(e)
@@ -404,7 +436,7 @@
try:
# authenticate
- auth = self.http_basic_authenticate()
+ auth = self.authenticate()
# check the validity of the request
self.validate_deposit_request("6.3.3", "6.3.1", "6.3.2")
@@ -502,7 +534,7 @@
# authenticate
try:
- auth = self.http_basic_authenticate()
+ auth = self.authenticate()
# check the validity of the request (note that multipart requests
# and atom-only are not permitted in this method)
@@ -542,7 +574,7 @@
# authenticate
try:
- auth = self.http_basic_authenticate()
+ auth = self.authenticate()
# check the validity of the request
self.validate_deposit_request(None, "6.7.1", None, allow_multipart=False)
@@ -586,7 +618,7 @@
# authenticate
try:
- auth = self.http_basic_authenticate()
+ auth = self.authenticate()
# check the validity of the request
self.validate_delete_request("6.6")
@@ -620,7 +652,7 @@
# authenticate
try:
- auth = self.http_basic_authenticate()
+ auth = self.authenticate()
ss = SwordServer(config, auth)
@@ -666,7 +698,7 @@
try:
# authenticate
- auth = self.http_basic_authenticate()
+ auth = self.authenticate()
# check the validity of the request
self.validate_deposit_request("6.5.2", None, "6.5.3")
@@ -712,7 +744,7 @@
try:
# authenticate
- auth = self.http_basic_authenticate()
+ auth = self.authenticate()
# check the validity of the request
self.validate_deposit_request("6.7.2", None, "6.7.3", "9.3", allow_empty=True)
@@ -758,7 +790,7 @@
raise SwordError(error_uri=Errors.method_not_allowed, msg="Delete operations not currently permitted")
# authenticate
- auth = self.http_basic_authenticate()
+ auth = self.authenticate()
# check the validity of the request
self.validate_delete_request("6.8")
@@ -784,7 +816,7 @@
try:
# authenticate
- auth = self.http_basic_authenticate()
+ auth = self.authenticate()
ss = SwordServer(config, auth)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-01-23 12:16:02
|
Revision: 461
http://sword-app.svn.sourceforge.net/sword-app/?rev=461&view=rev
Author: richard-jones
Date: 2012-01-23 12:15:56 +0000 (Mon, 23 Jan 2012)
Log Message:
-----------
add more logging to statement code
Modified Paths:
--------------
sss/branches/sss-2/sss/core.py
Modified: sss/branches/sss-2/sss/core.py
===================================================================
--- sss/branches/sss-2/sss/core.py 2012-01-22 21:22:35 UTC (rev 460)
+++ sss/branches/sss-2/sss/core.py 2012-01-23 12:15:56 UTC (rev 461)
@@ -770,6 +770,7 @@
- deposit_time: When the deposit was originally made
- packaging_format: The package format of the deposit, as supplied in the Packaging header
"""
+ ssslog.debug("Adding original deposit to Statement: " + uri)
self.original_deposits.append((uri, deposit_time, packaging_format, by, obo))
def add_normalised_aggregations(self, aggs):
@@ -995,12 +996,14 @@
# we want to create an ORE resource map, and also add on the sword specific bits for the original deposits and the state
- # Create ore:aggreages for all ordinary aggregated files
+ # Create ore:aggregates for all ordinary aggregated files
# First build a list of all the urls which are already referred to in the existing rem
existing_a = []
existing_aggregates = aggregation.findall(self.ns.ORE + "aggregates")
for ea in existing_aggregates:
existing_a.append(ea.get(self.ns.RDF + "resource"))
+ ssslog.debug("Existing aggregated resources: " + str(existing_a))
+ ssslog.debug("Adding aggregated resources: " + str(self.aggregates))
for uri in self.aggregates:
if uri in existing_a:
continue
@@ -1013,14 +1016,17 @@
existing_ods = aggregation.findall(self.ns.SWORD + "originalDeposit")
for eo in existing_ods:
existing_od.append(eo.get(self.ns.RDF + "resource"))
+ ssslog.debug("Existing original deposits: " + str(existing_od))
for (uri, datestamp, format, by, obo) in self.original_deposits:
# standard ORE aggregates statement
if uri not in existing_a:
+ ssslog.debug("Adding aggregated resource: " + uri)
aggregates = etree.SubElement(aggregation, self.ns.ORE + "aggregates", nsmap=self.smap)
aggregates.set(self.ns.RDF + "resource", uri)
# assert that this is an original package
if uri not in existing_od:
+ ssslog.debug("Adding original deposit: " + uri)
original = etree.SubElement(aggregation, self.ns.SWORD + "originalDeposit", nsmap=self.smap)
original.set(self.ns.RDF + "resource", uri)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|