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. |