public String getPublishDateDisplay(MarcFunctionContext ctx) {
   for (String tag : new String[] {"260", "264"}) {
     for (DataField df : ctx.record().getDataFields(tag)) {
       if (tag.equals("264") && df.getIndicator2() != '1') {
         continue;
       }
       if (df.getSubfield('c') != null) {
         String subC = df.getSubfield('c').getData();
         if (SINGLE_YEAR_PATTERN.matcher(subC).matches()) {
           return subC;
         }
       }
     }
   }
   return null;
 }
예제 #2
0
  /**
   * Tests {@link Record#find(String)} and {@link Record#find(String, String)} and {@link
   * Record#find(String[], String)}.
   *
   * @throws Exception
   */
  @Test
  public void testFind() throws Exception {
    VariableField field = record.getVariableField("245");
    assertEquals(true, field.find("Summerland"));
    assertEquals(true, field.find("Sum*erland"));
    assertEquals(true, field.find("[Cc]habo[a-z]"));

    field = record.getVariableField("008");
    assertEquals(true, field.find("eng"));

    List<? extends VariableField> result = record.find("Summerland");
    assertEquals(1, result.size());
    field = (VariableField) result.get(0);
    assertEquals("245", field.getTag());

    result = record.find("Chabon");
    assertEquals(2, result.size());

    result = record.find("100", "Chabon");
    assertEquals(1, result.size());

    String[] tags = {"100", "260", "300"};
    result = record.find(tags, "Chabon");
    assertEquals(1, result.size());

    result = record.find("040", "DLC");
    assertTrue(result.size() > 0);

    DataField df = (DataField) result.get(0);
    String agency = df.getSubfield('a').getData();
    assertTrue(agency.matches("DLC"));
  }
  public Set<Integer> getPublishDate(MarcFunctionContext ctx) {
    MarcRecord record = ctx.record();
    Set<Integer> years = new TreeSet<Integer>();

    for (DataField datafield : record.getDataFields("264")) {
      if (datafield.getIndicator2() == '1') {
        if (datafield.getSubfield('c') != null) {
          years.addAll(getPublishDateFromItem(datafield.getSubfield('c').getData()));
        }
      }
    }
    years.addAll(getPublishDateFromItems(ctx, "260", 'c'));
    years.addAll(getPublishDateFromItems(ctx, "773", '9'));
    years.addAll(getPublishDateFromItems(ctx, "996", 'y'));

    String field008 = record.getControlField("008");
    years.addAll(parsePublishDateFrom008(field008));

    return years;
  }
예제 #4
0
 @Override
 public String[] getValues(VariableField vf) {
   DataField df = (DataField) vf;
   String value = df.getSubfield('a').getData();
   String tag = df.getTag();
   if (tag.equals("100")) {
     Subfield csf = df.getSubfield('c');
     if (csf != null) {
       String data = csf.getData();
       int dlen = data.length();
       StringBuffer sb = new StringBuffer(value.length() + data.length() + 1);
       sb.append(value);
       sb.append(' ');
       char c = data.charAt(dlen - 1);
       if (c == ',' || c == '.') {
         sb.append(data, 0, dlen - 1);
       } else sb.append(data);
       value = sb.toString();
     }
   } else { // 110 & 710
     List<Subfield> sfs = df.getSubfields('b');
     if (sfs.size() > 0) {
       StringBuffer buf = new StringBuffer(value.length() + sfs.size() * 5);
       buf.append(value);
       Iterator<Subfield> sfi = sfs.iterator();
       while (sfi.hasNext()) {
         buf.append(' ');
         buf.append(sfi.next().getData());
       }
       int last = buf.length() - 1;
       char c = buf.charAt(last);
       if (c == ',' || c == '.') {
         buf.setLength(last);
       }
       value = buf.toString();
     }
   }
   return new String[] {trim(value).toString()};
 }
  @Override
  public Set<SkatKey> process(Long item) throws Exception {
    Set<SkatKey> result = new HashSet<>();
    HarvestedRecord hr = harvestedRecordDao.get(item);
    if (hr.getRawRecord() == null) {
      return result;
    }

    MarcRecord marc = null;
    InputStream is = new ByteArrayInputStream(hr.getRawRecord());
    try {
      marc = marcXmlParser.parseRecord(is);
    } catch (Exception e) {
      return result;
    }

    for (DataField df : marc.getDataFields("996")) {
      if (df.getSubfield('e') == null) {
        continue;
      }
      if (df.getSubfield('w') == null) {
        continue;
      }
      String sigla = df.getSubfield('e').getData();
      String recordId = df.getSubfield('w').getData();

      if (recordId.length() > 100 || sigla.length() > 20) {
        // ignore garbage
        continue;
      }

      SkatKey key = new SkatKey(new SkatKeyCompositeId(hr.getId(), sigla, recordId));
      result.add(key);
    }

    // ignore records having not enough information
    return result.size() < 2 ? Collections.emptySet() : result;
  }
  public static void main(String args[]) throws Exception {

    InputStream input = ReadMarcExample.class.getResourceAsStream("resources/summerland.mrc");

    MarcReader reader = new MarcStreamReader(input);
    while (reader.hasNext()) {
      Record record = reader.next();

      // check if the cataloging agency is DLC
      List result = record.find("040", "DLC");
      if (result.size() > 0) System.out.println("Agency for this record is DLC");

      // there is no specific find for a specific subfield
      // so to check if it is the orignal cataloging agency
      DataField field = (DataField) result.get(0);
      String agency = field.getSubfield('a').getData();
      if (agency.matches("DLC")) System.out.println("DLC is the original agency");
    }
  }
  // file import rules
  public ActionResult importFile(File selectedFile) throws IOException {
    Timer timer = new Timer();
    TreeMap<String, Stats> types = new TreeMap<String, Stats>();

    InputStream in = new FileInputStream(selectedFile);
    MarcReader reader = new MarcPermissiveStreamReader(in, true, true);

    while (reader.hasNext()) {
      Record record = reader.next();

      String bib_id = "";
      DataField df907 = (DataField) record.getVariableField("907");

      if (df907 != null) {
        Subfield df907a = df907.getSubfield('a');
        if (df907a != null) {
          bib_id = df907a.getData();
        }
      }
      if (bib_id.startsWith(".b")) {
        bib_id = bib_id.substring(2, 9);
      }

      String key = bib_id;
      Stats stat = Generator.INSTANCE.create(key);
      types.put(stat.key, stat);

      String checksum = getChecksum(record.toString());
      stat.setVal(InventoryStatsItem.Hash_Code, checksum);
    } // end while loop

    return new ActionResult(
        selectedFile,
        selectedFile.getName(),
        this.toString(),
        details,
        types,
        true,
        timer.getDuration());
  }