private DataField ensureFieldExists(Record marc, String tag) { DataField df = (DataField) MarcUtils.getVaribleField(marc, tag, 0); if (df == null) { df = new DataField(tag, ' ', ' '); marc.add(df); } return df; }
private void makeMaregdRecord( int databaseType, Record record, String controlNumber, CustomStorageRecord storageRecord) { // making latin record String entryTag = StorageUtils.findEntryTagForAuthority((AuthorityRecord) storageRecord); String entryRelatedTag = "7" + entryTag.substring(1); record = storageRecord.getRecord(); Record engRecord = MarcUtils.parseContent(storageRecord.getContent()); engRecord.getControlField(Tags.ID).setData("0"); // exchanging fields DataField df200 = engRecord.getDataField(entryTag); DataField df700 = engRecord.getDataField(entryRelatedTag); if (df700 != null) { df700.setTag(entryTag); if (df200 != null) { df200.setTag(entryRelatedTag); df200.add(new Subfield('3', String.valueOf(storageRecord.getId()))); } CustomStorageRecord engStorageRecord = StorageUtils.createNewStorageRecord( StorageUtils.getStorageClassByClassType(databaseType)); engStorageRecord.setId(0); engStorageRecord.setContent(MarcUtils.marshalContent(engRecord)); engStorageRecord.setLanguageOfCataloging(MarcConsts.LANG_ENGLISH); engStorageRecord.setCharacterSets("50"); engStorageRecord.setSubfieldRangeData(Tags.GENERAL_PROCESSING_DATA, 'a', "ba", 21, 22); engStorageRecord.setSubfieldRangeData(Tags.GENERAL_PROCESSING_DATA, 'a', "0", 23, 23); engStorageRecord.setSubfieldData(Tags.LANGUAGE_OF_THE_ITEM, 'a', MarcConsts.LANG_PERSIAN); try { engStorageRecord = save(engStorageRecord); logger.info(" ^^ english record added.", null); df700 = record.getDataField(entryRelatedTag); if (df700 != null) { df700.add(new Subfield('3', String.valueOf(engStorageRecord.getId()))); storageRecord.setContent(MarcUtils.marshalContent(record)); storageRecord = save(storageRecord); logger.info(" ^^ farsi record changed.", null); } } catch (Exception ex) { logger.error("error: RecordNo = " + controlNumber + " english making error!! **", ex); } } }
public boolean importRecord( AbstractWorkGroup workGroup, Class<CustomStorageRecord> persistentClass, TempDatabankDefinition storageDatabak, Record record, boolean isFromDos, boolean addToNews, int NewsDuration) { String controlNumber = ""; ControlField cf = record.getControlField(Tags.ID); if (cf == null) { cf = new ControlField(Tags.ID, "0"); record.getControlFieldList().add(0, cf); } controlNumber = String.copyValueOf(cf.getData()); if (controlNumber == null || controlNumber.length() == 0) { controlNumber = "0"; } // CustomStorageRecord storageRecord = StorageUtils // .createNewStorageRecord(StorageUtils // .getStorageClassByClassType(databaseType)); // storageRecord.setContent(MarcUtils.marshalContent(record)); // if (isFromDos) { UniBibUtils.setCharacterSets(record, "50"); // storageRecord.setCharacterSets("50"); // String docType = UniBibUtils.getLocalDocType(record); // if ("AF".equals(docType)) { // String file = MarcUtils.getSubfieldData(record, Tags.BIB_ELECTRONICAL_LOCATION, 0, // 'd', 0); // if (file != null && file.length() != 0) // MarcUtils.setSubfieldData(record, Tags.CUSTOM_CATEGORY, 'a', "G"); // } // } /** @todo move to server */ // storageRecord.setDateEnterdOnFile(insertDate); // storageRecord.setId(0); try { List holdings = generateHoldings(record); CustomStorageRecord storageRecord = (CustomStorageRecord) StorageUtils.createNewStorageRecord(persistentClass); if (storageRecord instanceof TempDatabankRecord) { ((TempDatabankRecord) storageRecord).setDatabank(storageDatabak); } if (storageRecord instanceof BaseBibliographicRecord) { storageRecord.setWorkGroup(workGroup); } storageRecord.setContent(MarcUtils.marshalContent(record)); long id = saveFast(storageRecord, holdings); logger.info("Saved: New record no. = " + id, null); if (holdings.size() > 0) logger.info(holdings.size() + " holding(s) has been attached to record no. " + id, null); } catch (Exception ex) { logger.error("Not saved!: Old recordNo = " + controlNumber, ex); } return true; }
private List generateHoldings(Record storageRecord) { List result = new ArrayList(); EntityObject wd = dataEntryService.findDefaultHoldingWorksheetFast(storageRecord); List holdDataFields = MarcUtils.getVaribleFieldList(storageRecord, "999"); for (int i = 0; i < holdDataFields.size(); i++) { DataField hold = (DataField) holdDataFields.get(i); String locCode = MarcUtils.getSubfieldData(hold, 's', 0); locCode = StringUtils.extendedArabicToLatinDigit(locCode); ConstantTableItem location = findOrCreateLocationByCode(locCode); if (location == null) { continue; } String regNo = MarcUtils.getSubfieldData(hold, 'r', 0); if (regNo == null || regNo.length() == 0) { continue; } String vol = MarcUtils.getSubfieldData(hold, 'v', 0); String copy = MarcUtils.getSubfieldData(hold, 'c', 0); String part = MarcUtils.getSubfieldData(hold, 'p', 0); Record marc = dataEntryService.createPreparedRegisterRecordFast( Register.class, storageRecord, location, AppSession.getInstance().getCurrentUser()); DataField df = ensureFieldExists(marc, Tags.HOL_LOC_CALL_NO); MarcUtils.setSubfieldData(df, 'b', locCode); MarcUtils.setSubfieldData(df, 'm', regNo); df = (DataField) ensureFieldExists(marc, Tags.HOL_COPY_VOL_INFO); MarcUtils.setSubfieldData(df, 'a', vol); MarcUtils.setSubfieldData(df, 'b', copy); MarcUtils.setSubfieldData(df, 'c', part); Register reg = new Register(); reg.setRegNo(regNo); reg.setVolume(vol); reg.setCopy(copy); reg.setLocation(location); if (wd != null) reg.setWorksheetDefinitionId(wd.getId()); reg.setContent(MarcUtils.marshalContent(marc)); // reg.setBibliographicRecord(storageRecord); // storageRecord.getRegisters().add(reg); result.add(reg); storageRecord.getDataFieldList().remove(hold); } return result; // remove 999 fields // for (Iterator iter = storageRecord.getDataFieldList().iterator(); iter.hasNext();) { // DataField element = (DataField) iter.next(); // if ("999".equals(element.getTag())) // iter.remove(); // } }