コード例 #1
0
  private void addRelationship(
      String subject, String predicate, String object, boolean isLiteral, String datatype)
      throws Exception {
    assertTrue(apim.addRelationship(subject, predicate, object, isLiteral, datatype));
    assertFalse(
        "Adding duplicate relationship should return false",
        apim.addRelationship(subject, predicate, object, isLiteral, datatype));

    // check resource index
    String query = "";
    if (isLiteral) {
      if (datatype != null) {
        query = String.format("* <%s> '%s'^^%s", predicate, object, datatype);
      } else {
        query = String.format("* <%s> '%s'", predicate, object);
      }
    } else {
      query = String.format("* <%s> <%s>", predicate, object);
    }

    TripleIterator triples = queryRI(query);
    try {
      assertTrue("Relationship not found in RI (query = " + query + ")", triples.hasNext());
      while (triples.hasNext()) {
        assertEquals(triples.next().getSubject().stringValue(), subjectAsURI(subject));
      }
    } finally {
      triples.close();
    }
  }
コード例 #2
0
 @After
 public void tearDown() throws Exception {
   apim.purgeObject("demo:777", "", false);
   apim.purgeObject("demo:888", "", false);
   apim.purgeObject("demo:777m", "", false);
   apim.purgeObject("demo:888m", "", false);
   XMLUnit.setXpathNamespaceContext(SimpleNamespaceContext.EMPTY_CONTEXT);
 }
コード例 #3
0
ファイル: DatastreamConduit.java プロジェクト: nrv/fcrepo
 public static void modifyDatastreamByReference(
     FedoraAPIMMTOM skeleton,
     String pid,
     String dsId,
     String[] altIDs,
     String dsLabel,
     String mimeType,
     String formatURI,
     String location,
     String checksumType,
     String checksum,
     String logMessage) {
   skeleton.modifyDatastreamByReference(
       pid,
       dsId,
       TypeUtility.convertStringtoAOS(altIDs),
       dsLabel,
       mimeType,
       formatURI,
       location,
       checksumType,
       checksum,
       logMessage,
       false);
 }
コード例 #4
0
ファイル: DatastreamConduit.java プロジェクト: nrv/fcrepo
 public static void modifyDatastreamByValue(
     FedoraAPIMMTOM skeleton,
     String pid,
     String dsId,
     String[] altIDs,
     String dsLabel,
     String mimeType,
     String formatURI,
     byte[] content,
     String checksumType,
     String checksum,
     String logMessage) {
   skeleton.modifyDatastreamByValue(
       pid,
       dsId,
       TypeUtility.convertStringtoAOS(altIDs),
       dsLabel,
       mimeType,
       formatURI,
       TypeUtility.convertBytesToDataHandler(content),
       checksumType,
       checksum,
       logMessage,
       false);
 }
コード例 #5
0
  @Test
  public void testBadSubjectURI() {
    String s, p, o;

    // subject is a valid info:fedora/ uri for an object, but object does not exist
    s = "info:fedora/does:notexist";
    p = "urn:foo";
    o = "urn:bar";
    try {
      apim.addRelationship(s, p, o, false, null);
      fail(
          "Adding relationship with subject as a Fedora DO that does not exist should have failed");
    } catch (SOAPFaultException se) {
    }

    // subject is a valid info:fedora/ uri for a datastream, but object does not exist
    s = "info:fedora/does:notexist/DS1";
    p = "urn:foo";
    o = "urn:baz";
    try {
      apim.addRelationship(s, p, o, false, null);
      fail(
          "Adding relationship with subject as a Fedora object datastream where DO does not exist should have failed");
    } catch (SOAPFaultException se) {
    }

    // subject is a valid uri, but not in info:fedora/ scheme
    s = "http://www.example.org/test";
    p = "urn:foo";
    o = "urn:quux";
    try {
      apim.addRelationship(s, p, o, false, null);
      fail("Adding relationship with subject uri not in the info:fedora scheme should have failed");
    } catch (SOAPFaultException se) {
    }

    // Valid PID & datastream ID, but invalid subject URI
    // should be: info:fedora/demo:888/DS1
    s = "demo:888/DS1";
    p = "urn:foo";
    o = "urn:quux";
    try {
      apim.addRelationship(s, p, o, false, null);
      fail("Adding relationship with invalid short URI should have failed");
    } catch (SOAPFaultException se) {
    }
  }
コード例 #6
0
ファイル: DatastreamConduit.java プロジェクト: nrv/fcrepo
 public static List<String> purgeDatastream(
     FedoraAPIMMTOM skeleton,
     String pid,
     String dsId,
     String startDT,
     String endDT,
     String logMessage) {
   return skeleton.purgeDatastream(pid, dsId, startDT, endDT, logMessage, false);
 }
コード例 #7
0
  @Test
  public void testPurgeRelationships() throws Exception {
    String p, o;
    int relNum =
        0; // used to form unique relationships or objects/object literals... addRelationship needs
           // unique predicate x object combinations

    for (String s : subject) {

      p = "urn:p" + relNum++;
      o = "urn:o";
      purgeRelationship(s, p, o, false, null);

      p = "urn:title" + relNum;
      o = "asdf"; // "三国演义"; // test unicode
      purgeRelationship(s, p, o, true, null);

      p = "urn:temperature" + relNum;
      o = "98.6";
      purgeRelationship(s, p, o, true, Constants.RDF_XSD.FLOAT.uri);

      // utf-8 literal with multibyte sequences
      p = "urn:utf8literal" + relNum;
      o = MULTIBYTE_UTF8;
      purgeRelationship(s, p, o, true, null);

      assertFalse(
          "Purging non-existant relation should have failed",
          apim.purgeRelationship(s, "urn:asdf", "867-5309", true, null));

      addRelationship(s, p, o, true, null);
      addRelationship(s, p, "foo", true, null);

      List<RelationshipTuple> tuples = apim.getRelationships(s, p);
      assertNotNull(tuples);
      assertEquals(2, tuples.size());
      assertTrue(
          "Purging relationship with null object should delete all subject/predicate matches",
          apim.purgeRelationship(s, p, null, true, null));
      tuples = apim.getRelationships(s, p);
      assertNotNull(tuples);
      assertEquals(0, tuples.size());
    }
  }
コード例 #8
0
  @Test
  public void testValidation() {
    String p, o;
    int relNum =
        0; // used to form unique relationships or objects/object literals... addRelationship needs
           // unique predicate x object combinations

    for (String s : subject) {

      p = "http://purl.org/dc/elements/1.1/title";
      o = "A Dictionary of Maqiao" + relNum++;

      // DC rels only invalid for RELS-EXT...
      if (!s.endsWith("DS1") && !s.endsWith("DS2")) {
        try {
          apim.addRelationship(s, p, o, true, null);
          fail("Adding Dublin Core relationship should have failed - " + s);
        } catch (SOAPFaultException se) {
          assertTrue(se.getMessage(), se.getMessage().contains("improper relationship assertion"));
        }
      }

      p = "info:fedora/fedora-system:def/model#foo";
      try {
        apim.addRelationship(s, p, o, true, null);
        fail("Adding Fedora Model relationship should have failed - " + s);
      } catch (SOAPFaultException se) {
        assertTrue(se.getMessage(), se.getMessage().contains("Disallowed predicate"));
      }

      p = "urn:bar" + relNum;
      // invalid dateTime literal
      o = "2009-10-05T16:02:26+0100";
      try {
        apim.addRelationship(s, p, o, true, Constants.RDF_XSD.DATE_TIME.uri);
        fail("Adding invalid date/time literal in relationship should have failed - " + s);
      } catch (SOAPFaultException se) {
        assertTrue(se.getMessage(), se.getMessage().contains("is not a valid 'dateTime' value"));
      }
    }
  }
コード例 #9
0
 private void getRelationship(
     String subject, String predicate, String object, boolean isLiteral, String datatype)
     throws Exception {
   addRelationship(subject, predicate, object, isLiteral, datatype);
   List<RelationshipTuple> tuples = apim.getRelationships(subject, predicate);
   assertNotNull(tuples);
   assertEquals(1, tuples.size());
   assertEquals(subjectAsURI(subject), tuples.get(0).getSubject());
   assertEquals(predicate, tuples.get(0).getPredicate());
   assertEquals(object, tuples.get(0).getObject());
   assertEquals(isLiteral, tuples.get(0).isIsLiteral());
   assertEquals(datatype, tuples.get(0).getDatatype());
 }
コード例 #10
0
  @Before
  public void setUp() throws Exception {
    apim = s_client.getAPIMMTOM();
    Map<String, String> nsMap = new HashMap<String, String>();
    nsMap.put("oai_dc", "http://www.openarchives.org/OAI/2.0/oai_dc/");
    nsMap.put("dc", "http://purl.org/dc/elements/1.1/");
    nsMap.put("foxml", "info:fedora/fedora-system:def/foxml#");
    NamespaceContext ctx = new SimpleNamespaceContext(nsMap);
    XMLUnit.setXpathNamespaceContext(ctx);

    apim.ingest(
        TypeUtility.convertBytesToDataHandler(DEMO_888_FOXML),
        FOXML1_1.uri,
        "ingesting new foxml object");
    apim.ingest(
        TypeUtility.convertBytesToDataHandler(DEMO_777_FOXML),
        FOXML1_1.uri,
        "ingesting new foxml object");

    // managed content versions of above (reserved datastreams translated from X to M)
    ManagedContentTranslator.createManagedClone(apim, "demo:888", "demo:888m");
    ManagedContentTranslator.createManagedClone(apim, "demo:777", "demo:777m");
  }
コード例 #11
0
  private void checkExistsViaGetRelationships(String subject, String predicate, String object)
      throws Exception {
    boolean found = false;

    for (RelationshipTuple tuple : apim.getRelationships(subject, predicate)) {
      if (tuple.getSubject().equals(subjectAsURI(subject))
          && tuple.getPredicate().equals(predicate)
          && tuple.getObject().equals(object)) {
        found = true;
      }
    }
    assertTrue(
        "Relationship not found via getRelationships (subject="
            + subject
            + ", predicate="
            + predicate
            + ", object="
            + object,
        found);
  }
コード例 #12
0
 @Test
 public void testGetAllRelationships() throws Exception {
   // subject uri and pid
   List<RelationshipTuple> tuples = apim.getRelationships("demo:777", null);
   assertEquals(1, tuples.size());
 }
コード例 #13
0
ファイル: PolicyUtils.java プロジェクト: unikent/fcrepo
  public String addPolicy(File policyFile) throws Exception {
    byte[] policy = DataUtils.loadFile(policyFile.getAbsolutePath());

    String policyId = getPolicyId(policy);

    String policyFileName = "file:///" + policyFile.getAbsolutePath();

    // escape any pid namespace character
    if (policyId.contains(":")) {
      policyId = policyId.replace(":", "%3A");
    }

    String pid = "demo:" + policyId;

    StringBuilder foxml = new StringBuilder();

    // basic empty object

    foxml.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    foxml.append(
        "<foxml:digitalObject VERSION=\"1.1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n");
    foxml.append("    xmlns:foxml=\"info:fedora/fedora-system:def/foxml#\"\n");
    foxml.append(
        "           xsi:schemaLocation=\""
            + Constants.FOXML.uri
            + " "
            + Constants.FOXML1_1.xsdLocation
            + "\"");
    foxml.append("\n           PID=\"" + StreamUtility.enc(pid) + "\">\n");
    foxml.append("  <foxml:objectProperties>\n");
    foxml.append(
        "    <foxml:property NAME=\"info:fedora/fedora-system:def/model#state\" VALUE=\"A\"/>\n");
    foxml.append(
        "    <foxml:property NAME=\"info:fedora/fedora-system:def/model#label\" VALUE=\""
            + StreamUtility.enc("test policy object")
            + "\"/>\n");
    foxml.append("  </foxml:objectProperties>\n");

    foxml.append(
        "<foxml:datastream ID=\""
            + FedoraPolicyStore.FESL_POLICY_DATASTREAM
            + "\" CONTROL_GROUP=\"M\">");
    foxml.append(
        "<foxml:datastreamVersion ID=\"POLICY.0\" MIMETYPE=\"text/xml\" LABEL=\"XACML policy datastream\">");

    foxml.append("  <foxml:contentLocation REF=\"" + policyFileName + "\" TYPE=\"URL\"/>");

    // foxml.append("  <foxml:xmlContent>");
    // foxml.append(policy);
    // foxml.append("    </foxml:xmlContent>");

    foxml.append("  </foxml:datastreamVersion>");
    foxml.append("</foxml:datastream>");

    foxml.append("</foxml:digitalObject>");

    apim.ingest(
        TypeUtility.convertBytesToDataHandler(foxml.toString().getBytes("UTF-8")),
        FOXML1_1.uri,
        "ingesting new foxml object");

    return policyId;
  }
コード例 #14
0
ファイル: DatastreamConduit.java プロジェクト: nrv/fcrepo
 public static List<Datastream> getDatastreams(
     FedoraAPIMMTOM skeleton, String pid, String asOfDateTime, String state) {
   return skeleton.getDatastreams(pid, asOfDateTime, state);
 }
コード例 #15
0
ファイル: DatastreamConduit.java プロジェクト: nrv/fcrepo
 public static Datastream getDatastream(
     FedoraAPIMMTOM skeleton, String pid, String dsId, String asOfDateTime) {
   return skeleton.getDatastream(pid, dsId, asOfDateTime);
 }
コード例 #16
0
ファイル: DatastreamConduit.java プロジェクト: nrv/fcrepo
 public static List<Datastream> getDatastreamHistory(
     FedoraAPIMMTOM skeleton, String pid, String dsId) {
   return skeleton.getDatastreamHistory(pid, dsId);
 }
コード例 #17
0
 private void purgeRelationship(
     String subject, String predicate, String object, boolean isLiteral, String datatype)
     throws Exception {
   addRelationship(subject, predicate, object, isLiteral, datatype);
   assertTrue(apim.purgeRelationship(subject, predicate, object, isLiteral, datatype));
 }
コード例 #18
0
ファイル: PolicyUtils.java プロジェクト: unikent/fcrepo
 public void delPolicy(String policyId) throws Exception {
   String pid = "demo:" + policyId;
   apim.purgeObject(pid, "removing test policy object", false);
 }