Example #1
0
    private void write(OaiDcType dc, long timestamp, String message) throws DigitalObjectException {
      EditorResult result = editor.createResult();

      // DO NOT include schemaLocation. Fedora validator does not accept it.
      DcUtils.marshal(result, dc, false);
      editor.write(result, timestamp, message);

      // Label: spec requires identifier + title
      StringBuilder label = new StringBuilder();
      if (!dc.getIdentifiers().isEmpty()) {
        label.append(dc.getIdentifiers().get(0).getValue());
      }
      if (!dc.getTitles().isEmpty()) {
        if (label.length() > 0) {
          label.append(' ');
        }
        label.append(dc.getTitles().get(0).getValue());
      }
      String objLabel = label.toString().trim();
      object.setLabel(objLabel.isEmpty() ? "?" : objLabel);

      // DC
      DcStreamEditor dcEditor = handler.objectMetadata();
      DublinCoreRecord dcr = dcEditor.read();
      dcr.setDc(dc);
      dcEditor.write(handler, dcr, message);
    }
Example #2
0
    @Override
    public void setDissemination(DisseminationInput input, String message)
        throws DigitalObjectException {
      defaultHandler.setDissemination(input, message);
      MetadataHandler<OaiDcType> metadata = handler.metadata();
      DescriptionMetadata<OaiDcType> dm = metadata.getMetadata();
      OaiDcType data = dm.getData();
      List<ElementType> titles = data.getTitles();
      titles.clear();
      String filename = input.getFilename();
      titles.add(new ElementType(filename, null));
      List<ElementType> formats = data.getFormats();
      formats.clear();
      formats.add(new ElementType(input.getMime().toString(), null));

      metadata.setMetadata(dm, message);
    }
  @Test
  public void testCreateDc() {
    String xml =
        "<mods version='3.5' xmlns='http://www.loc.gov/mods/v3'>"
            + "<titleInfo>"
            + "<nonSort>NS1</nonSort><title>T1</title><subTitle>S1</subTitle><partName>PNam1</partName><partNumber>PNum1</partNumber>"
            + "</titleInfo>"
            + "<titleInfo>"
            + "<title>T2</title><subTitle>S2</subTitle>"
            + "</titleInfo>"
            + "</mods>";
    ModsDefinition mods = ModsUtils.unmarshalModsType(new StreamSource(new StringReader(xml)));
    NdkPeriodicalMapper mapper = new NdkPeriodicalMapper();
    Context ctx = new Context("uuid:testId");

    OaiDcType result = mapper.createDc(mods, ctx);
    assertEquals("NS1 T1: S1", result.getTitles().get(0).getValue());
    assertEquals("T2: S2", result.getTitles().get(1).getValue());
    assertEquals("PNum1", result.getDescriptions().get(0).getValue());
    assertEquals("PNam1", result.getDescriptions().get(1).getValue());
  }
Example #4
0
    private OaiDcType createDefautDc() throws DigitalObjectException {
      OaiDcType dc = new OaiDcType();
      DigitalObjectHandler parent = handler.getParameterParent();
      String modelId = handler.relations().getModel();

      if (MODEL_FOLDER.equals(modelId)) {
        String identifier = getProducerCode() + "_";
        dc.getIdentifiers().add(new ElementType(identifier, null));
        dc.getTitles().add(new ElementType(identifier + '-', null));
      } else if (MODEL_DOCUMENT.equals(modelId)) {
        OaiDcType parentDc = getParentDcMetadata(parent);
        if (parentDc != null) {
          if (!parentDc.getIdentifiers().isEmpty()) {
            String identifier = parentDc.getIdentifiers().get(0).getValue();
            dc.getIdentifiers().add(new ElementType(identifier + '-', null));
            dc.getSubjects().add(new ElementType(identifier, null));
          }
          if (!parentDc.getTitles().isEmpty()) {
            String title = parentDc.getTitles().get(0).getValue() + '-';
            dc.getTitles().add(new ElementType(title, null));
          }
          if (!parentDc.getTypes().isEmpty()) {
            String type = parentDc.getTypes().get(0).getValue();
            dc.getTypes().add(new ElementType(type, null));
          }
        }
      }
      return dc;
    }