Пример #1
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");
  }
Пример #2
0
  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;
  }