コード例 #1
0
  private static DcsFile getFile(SolrDocument doc) {
    SeadFile file = new SeadFile();

    file.setId(get(doc, EntityField.ID));
    file.setFixity(getFixitySet(doc));
    file.setFormats(getFormatSet(doc));
    file.setExtant((Boolean) doc.getFieldValue(FileField.EXTANT.solrName()));

    if (has(doc, FileField.VALID)) {
      file.setValid((Boolean) doc.getFieldValue(FileField.VALID.solrName()));
    }

    if (has(doc, FileField.NAME)) {
      file.setName(getFirst(doc, FileField.NAME));
    }

    if (has(doc, FileField.SOURCE)) {
      file.setSource(getFirst(doc, FileField.SOURCE));
    }

    if (has(doc, SeadSolrField.EntityField.IMMEDIATEANCESTRY)) {
      file.setParent(getFirst(doc, SeadSolrField.EntityField.IMMEDIATEANCESTRY));
    }

    if (has(doc, SeadSolrField.EntityField.MDUPDATE_DATE)) {
      Object object = doc.getFirstValue(SeadSolrField.EntityField.MDUPDATE_DATE.solrName());
      if (object instanceof Date) {
        Date date = (Date) object;

        if (date != null) {
          file.setMetadataUpdateDate(DateUtil.getThreadLocalDateFormat().format(date));
        }
      } else {

        if (object != null) {
          file.setMetadataUpdateDate(object.toString());
        }
      }
    } else {
      file.setMetadataUpdateDate("2012-10-27T22:05:20.809Z");
    }

    if (has(doc, SeadSolrField.FileField.DEPOSITDATE)) {

      Object object = doc.getFirstValue(SeadSolrField.FileField.DEPOSITDATE.solrName());
      if (object instanceof Date) {
        Date date = (Date) object; // doc.getFirstValue(FileField.DEPOSITDATE.solrName());

        if (date != null) {
          file.setDepositDate(DateUtil.getThreadLocalDateFormat().format(date));
        }
      } else {

        if (object != null) {
          file.setDepositDate(object.toString());
        }
      }
    } else {
      file.setDepositDate("2012-10-27T22:05:20.809Z");
    }

    long size = (Long) doc.getFirstValue(FileField.SIZE.solrName());
    if (size > 0) {
      file.setSizeBytes(size);
    }

    file.setMetadata(getMetadataSet(doc));
    file.setMetadataRef(getMetadataRefSet(doc, EntityField.METADATA_REF));
    file.setAlternateIds(getResourceIdentifierSet(doc));
    SeadDataLocation primaryDataLocation = getPrimaryDataLocation(doc);
    file.setPrimaryLocation(primaryDataLocation);

    file.setSecondaryDataLocations(getSecondaryDataLocationSet(doc));

    return file;
  }
コード例 #2
0
  private static SolrInputDocument toSolr(SeadFile file, ArchiveStore store) throws IOException {
    SolrInputDocument doc = new SolrInputDocument();
    add(doc, EntityField.ID, file.getId());
    add(doc, EntityField.TYPE, EntityTypeValue.FILE.solrValue());

    add(doc, FileField.NAME, file.getName());
    add(doc, FileField.SOURCE, file.getSource());
    add(doc, FileField.SIZE, file.getSizeBytes());

    if (file.getMetadataUpdateDate() == null || file.getMetadataUpdateDate().length() == 0)
      add(
          doc,
          SeadSolrField.EntityField.MDUPDATE_DATE,
          toIso8601(now())); // file.getMetadataUpdateDate());
    else add(doc, SeadSolrField.EntityField.MDUPDATE_DATE, file.getMetadataUpdateDate());

    if (file.getValid() != null) {
      doc.addField(FileField.VALID.solrName(), file.getValid());
    }

    doc.addField(FileField.EXTANT.solrName(), file.isExtant());

    addFixitySet(doc, file.getFixity());
    addFormatSet(doc, file.getFormats());
    addResourceIdentifierSet(doc, file.getAlternateIds());

    SeadDataLocation primaryDataLocation = new SeadDataLocation();
    primaryDataLocation.setLocation(file.getPrimaryLocation().getLocation());
    primaryDataLocation.setName(file.getPrimaryLocation().getName());
    primaryDataLocation.setType(file.getPrimaryLocation().getType());
    addPrimaryDataLocation(doc, primaryDataLocation);
    addSecondaryDataLocationSet(doc, file.getSecondaryDataLocations());

    addMetadataSet(doc, file.getMetadata());
    addMetadataRefSet(doc, file.getMetadataRef(), EntityField.METADATA_REF, store);

    return doc;
  }