Ejemplo n.º 1
0
 private Map<String, Map> generateResultMapForBibTreeWithItemUuidAndResultType(BibTrees bibTrees) {
   Map<String, Map> resultTypeMap = new HashMap<>();
   if (null != bibTrees) {
     List<BibTree> bibTreeList = bibTrees.getBibTrees();
     if (CollectionUtils.isNotEmpty(bibTreeList)) {
       for (Iterator<BibTree> bibTreeIterator = bibTreeList.iterator();
           bibTreeIterator.hasNext(); ) {
         BibTree bibTree = bibTreeIterator.next();
         List<HoldingsTree> holdingsTrees = bibTree.getHoldingsTrees();
         if (CollectionUtils.isNotEmpty(holdingsTrees)) {
           for (Iterator<HoldingsTree> holdingsTreeIterator = holdingsTrees.iterator();
               holdingsTreeIterator.hasNext(); ) {
             HoldingsTree holdingsTree = holdingsTreeIterator.next();
             List<Item> items = holdingsTree.getItems();
             if (CollectionUtils.isNotEmpty(items)) {
               for (Iterator<Item> itemIterator = items.iterator(); itemIterator.hasNext(); ) {
                 Item item = itemIterator.next();
                 Map statusMap = new HashMap();
                 statusMap.put("result", item.getResult());
                 statusMap.put("message", item.getMessage());
                 statusMap.put("barcode", item.getBarcode());
                 resultTypeMap.put(item.getId(), statusMap);
               }
             }
           }
         }
       }
     }
   }
   return resultTypeMap;
 }
  private BibTrees fetchResultSet(int batchSize, BatchStatistics batchStatistics, Boolean isBibOnly)
      throws Exception {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    BibTrees bibTrees = new BibTrees();
    int count = 0;
    if (batchSize <= 0) {
      return bibTrees;
    }
    while (bibResultSet.next()) {
      count++;
      BibTree bibTree = new BibTree();
      Bib bib = fetchBibRecord();
      bibTree.setBib(bib);
      if (!isBibOnly) {
        List<HoldingsTree> holdingsList =
            fetchHoldingsTreeForBib(Integer.parseInt(bib.getLocalId()));
        bibTree.getHoldingsTrees().addAll(holdingsList);
        batchStatistics.addHoldingsCount(holdingsList.size());

        for (HoldingsTree holdingsTree : holdingsList) {
          batchStatistics.addItemCount(holdingsTree.getItems().size());
        }
      }

      bibTrees.getBibTrees().add(bibTree);
      if (count == batchSize) {
        break;
      }
    }
    stopWatch.stop();
    batchStatistics.addTimeTaken(stopWatch.getTotalTimeMillis());
    batchStatistics.addBibCount(bibTrees.getBibTrees().size());
    return bibTrees;
  }
Ejemplo n.º 3
0
  public Map<String, Map> updateItemsToDocstore(List<Item> itemList) {
    org.kuali.ole.docstore.common.document.BibTrees bibTrees =
        new org.kuali.ole.docstore.common.document.BibTrees();

    org.kuali.ole.docstore.common.document.BibTree bibTree =
        new org.kuali.ole.docstore.common.document.BibTree();
    org.kuali.ole.docstore.common.document.Bib bib =
        new org.kuali.ole.docstore.common.document.Bib();
    bibTree.setBib(bib);
    bib.setId("");

    org.kuali.ole.docstore.common.document.HoldingsTree holdingsTree =
        new org.kuali.ole.docstore.common.document.HoldingsTree();
    org.kuali.ole.docstore.common.document.Holdings holdings =
        new org.kuali.ole.docstore.common.document.Holdings();
    holdings.setId("");
    holdingsTree.setHoldings(holdings);

    List<String> locationLevel = BatchBibImportUtil.getLocationLevel();

    for (Iterator<Item> iterator = itemList.iterator(); iterator.hasNext(); ) {
      Item item = iterator.next();
      if (CollectionUtils.isNotEmpty(locationLevel)) {
        populateLocationLevels(item, locationLevel);
      }
      item.buildLocationLevels(
          (org.kuali.ole.docstore.common.document.content.instance.Item) item.getContentObject());
      item.setOperation(
          org.kuali.ole.docstore.common.document.DocstoreDocument.OperationType.UPDATE);
      item.serializeContent();
      holdingsTree.getItems().add(item);
    }

    bibTree.getHoldingsTrees().add(holdingsTree);

    bibTrees.getBibTrees().add(bibTree);
    BibTrees responseBibTree = null;
    try {
      responseBibTree = getDocstoreClientLocator().getDocstoreClient().processBibTrees(bibTrees);
    } catch (Exception e) {
      e.printStackTrace();
    }
    Map<String, Map> statusMap =
        generateResultMapForBibTreeWithItemUuidAndResultType(responseBibTree);
    return statusMap;
  }
  public List<HoldingsTree> fetchHoldingsTreeForBib(int bibId) throws Exception {
    List<HoldingsTree> holdingsTrees = new ArrayList<HoldingsTree>();

    holdingsPreparedStatement.setInt(1, bibId);
    ResultSet resultSet = holdingsPreparedStatement.executeQuery();
    Map<String, HoldingsTree> map = new HashMap<>();
    Map<String, ExtentOfOwnership> extentOfOwnershipMap = new HashMap<>();
    Set<String> uriSet = null;
    Set<String> noteSet = null;
    Set<String> donorSet = null;
    Set<String> coverageSet = null;
    Set<String> perpetualSet = null;
    Set<String> extentOfOwnershipNoteSet = null;
    Set<String> linkSet = null;

    while (resultSet.next()) {
      String holdingsType = resultSet.getString("HOLDINGS_TYPE");
      String id = resultSet.getString("HOLDINGS_ID");
      OleHoldings oleHoldings = null;
      if (map.containsKey(id)) {
        oleHoldings = map.get(id).getHoldings().getContentObject();
      } else {
        oleHoldings = new OleHoldings();
        Location location =
            getLocationDetails(
                resultSet.getString("LOCATION"), resultSet.getString("LOCATION_LEVEL"));
        oleHoldings.setLocation(location);
        oleHoldings.setHoldingsType(holdingsType);
        CallNumber callNumber = new CallNumber();
        callNumber.setNumber(resultSet.getString("CALL_NUMBER"));
        callNumber.setPrefix(resultSet.getString("CALL_NUMBER_PREFIX"));
        ShelvingOrder shelvingOrder = new ShelvingOrder();
        if (resultSet.getString("SHELVING_ORDER") != null
            && !"null".equals(resultSet.getString("SHELVING_ORDER"))) {
          shelvingOrder.setCodeValue(resultSet.getString("SHELVING_ORDER"));
          shelvingOrder.setFullValue(resultSet.getString("SHELVING_ORDER"));
        }
        callNumber.setShelvingOrder(shelvingOrder);
        ShelvingScheme shelvingScheme = new ShelvingScheme();
        if (resultSet.getString("CALL_NUMBER_TYPE_ID") != null) {
          String[] strings =
              callNumberType.get(resultSet.getString("CALL_NUMBER_TYPE_ID")).split("[|]");
          shelvingScheme.setCodeValue(strings[0]);
          shelvingScheme.setFullValue(strings[1]);
        }
        callNumber.setShelvingScheme(shelvingScheme);
        oleHoldings.setCallNumber(callNumber);
        oleHoldings.setCopyNumber(resultSet.getString("COPY_NUMBER"));
        HoldingsTree holdingsTree = new HoldingsTree();

        Holdings holdings = null;

        if (holdingsType.equalsIgnoreCase(PHoldings.PRINT)) {
          holdings = new PHoldings();

          if (resultSet.getString("RECEIPT_STATUS_ID") != null) {
            oleHoldings.setReceiptStatus(resultSet.getString("RECEIPT_STATUS_ID"));
          }
          extentOfOwnershipNoteSet = new HashSet<>();
          donorSet = coverageSet = perpetualSet = null;
        } else {
          holdings = new EHoldings();
          oleHoldings.setAccessStatus(resultSet.getString("ACCESS_STATUS"));
          oleHoldings.setImprint(resultSet.getString("IMPRINT"));
          Platform platform = new Platform();
          platform.setPlatformName(resultSet.getString("PLATFORM"));
          platform.setAdminUrl(resultSet.getString("ADMIN_URL"));
          platform.setAdminUserName(resultSet.getString("ADMIN_USERNAME"));
          platform.setAdminPassword(resultSet.getString("ADMIN_PASSWORD"));
          oleHoldings.setPlatform(platform);

          oleHoldings.setPublisher(resultSet.getString("PUBLISHER"));
          HoldingsAccessInformation holdingsAccessInformation = new HoldingsAccessInformation();

          holdingsAccessInformation.setProxiedResource(resultSet.getString("PROXIED_RESOURCE"));
          holdingsAccessInformation.setAccessUsername(resultSet.getString("ACCESS_USERNAME"));
          holdingsAccessInformation.setAccessPassword(resultSet.getString("ACCESS_PASSWORD"));
          holdingsAccessInformation.setNumberOfSimultaneousUser(
              resultSet.getString("NUMBER_SIMULT_USERS"));
          holdingsAccessInformation.setAccessLocation(resultSet.getString("CODE"));
          holdingsAccessInformation.setAuthenticationType(
              resultSet.getString("AUTHENTICATION_TYPE_ID"));
          oleHoldings.setHoldingsAccessInformation(holdingsAccessInformation);
          String statisticalSearchId = resultSet.getString("STAT_SEARCH_CODE_ID");
          if (StringUtils.isNotEmpty(statisticalSearchId)) {
            String[] strings = statisticalSearchCodeMap.get(statisticalSearchId).split("[|]");
            StatisticalSearchingCode statisticalSearchingCode = new StatisticalSearchingCode();
            statisticalSearchingCode.setCodeValue(strings[0]);
            statisticalSearchingCode.setFullValue(strings[1]);
            oleHoldings.setStatisticalSearchingCode(statisticalSearchingCode);
          }
          oleHoldings.setLocalPersistentLink(resultSet.getString("LOCAL_PERSISTENT_URI"));
          oleHoldings.setSubscriptionStatus(resultSet.getString("SUBSCRIPTION_STATUS"));
          oleHoldings.setInterLibraryLoanAllowed(Boolean.valueOf(resultSet.getString("ALLOW_ILL")));
          coverageSet = new HashSet<>();
          perpetualSet = new HashSet<>();
          donorSet = new HashSet<>();
          ExtentOfOwnership extentOfOwnership = new ExtentOfOwnership();
          Coverages coverages = new Coverages();
          PerpetualAccesses perpetualAccesses = new PerpetualAccesses();
          extentOfOwnership.setCoverages(coverages);
          extentOfOwnership.setPerpetualAccesses(perpetualAccesses);
          oleHoldings.getExtentOfOwnership().add(extentOfOwnership);
        }
        holdings.setHoldingsType(holdingsType);
        holdings.setId("who-" + id);
        holdings.setContentObject(oleHoldings);
        holdings.setCreatedBy(resultSet.getString("CREATED_BY"));
        holdings.setCreatedOn(resultSet.getString("DATE_CREATED"));
        if (resultSet.getString("STAFF_ONLY") != null) {
          holdings.setStaffOnly(
              (resultSet.getString("STAFF_ONLY").equalsIgnoreCase("Y")
                  ? Boolean.TRUE
                  : Boolean.FALSE));
        }
        holdings.setUpdatedBy(resultSet.getString("UPDATED_BY"));
        holdings.setUpdatedOn(resultSet.getString("DATE_UPDATED"));
        holdings.setLastUpdated(resultSet.getString("DATE_UPDATED"));

        uriSet = new HashSet<>();
        noteSet = new HashSet<>();
        linkSet = new HashSet<>();
        List<Item> itemList = fetchItemForHoldings(Integer.parseInt(id));
        holdingsTree.setHoldings(holdings);
        holdingsTree.getItems().addAll(itemList);

        map.put(id, holdingsTree);

        holdingsTrees.add(holdingsTree);
      }

      if (StringUtils.isNotEmpty(holdingsType) && holdingsType.equalsIgnoreCase(PHoldings.PRINT)) {
        if (uriSet.add(resultSet.getString("HOLDINGS_URI_ID"))) {
          Uri uri = new Uri();
          uri.setValue(resultSet.getString("TEXT"));
          oleHoldings.getUri().add(uri);
        }
        ExtentOfOwnership extentOfOwnership = null;
        if (extentOfOwnershipMap.containsKey(resultSet.getString("EXT_OWNERSHIP_ID"))) {
          extentOfOwnership = extentOfOwnershipMap.get(resultSet.getString("EXT_OWNERSHIP_ID"));
        } else {
          extentOfOwnership = new ExtentOfOwnership();
          if (StringUtils.isNotEmpty(resultSet.getString("EXT_OWNERSHIP_TYPE_ID"))) {
            String[] strings =
                extentOfOwnershipTypeMap
                    .get(resultSet.getString("EXT_OWNERSHIP_TYPE_ID"))
                    .split("[|]");
            extentOfOwnership.setType(strings[1]);
          }
          extentOfOwnershipMap.put(resultSet.getString("EXT_OWNERSHIP_ID"), extentOfOwnership);
          oleHoldings.getExtentOfOwnership().add(extentOfOwnership);
        }
        String extOwnershipNoteId = resultSet.getString("EXT_OWNERSHIP_NOTE_ID");
        if (extentOfOwnershipNoteSet != null
            && StringUtils.isNotEmpty(extOwnershipNoteId)
            && extentOfOwnershipNoteSet.add(resultSet.getString("EXT_OWNERSHIP_NOTE_ID"))) {
          Note note = new Note();
          note.setValue(resultSet.getString(83));
          note.setType(resultSet.getString(82));

          extentOfOwnership.getNote().add(note);
        }
      } else {
        if (linkSet.add(resultSet.getString("HOLDINGS_URI_ID"))) {
          Link link = new Link();
          link.setUrl(resultSet.getString("URI"));
          link.setText(resultSet.getString("TEXT"));
          oleHoldings.getLink().add(link);
        }
        if (oleHoldings.getExtentOfOwnership() != null
            && oleHoldings.getExtentOfOwnership().size() > 0) {
          if (coverageSet != null && coverageSet.add(resultSet.getString("HOLDINGS_COVERAGE_ID"))) {
            Coverage coverage = new Coverage();
            coverage.setCoverageStartIssue(resultSet.getString("COVERAGE_START_ISSUE"));
            coverage.setCoverageStartDate(resultSet.getString("COVERAGE_START_DATE"));
            coverage.setCoverageStartVolume(resultSet.getString("COVERAGE_START_VOLUME"));
            coverage.setCoverageEndIssue(resultSet.getString("HOLDINGS_COVERAGE_ID"));
            coverage.setCoverageEndDate(resultSet.getString("COVERAGE_END_DATE"));
            coverage.setCoverageEndVolume(resultSet.getString("COVERAGE_END_VOLUME"));
            oleHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().add(coverage);
          }

          if (perpetualSet != null
              && perpetualSet.add(resultSet.getString("HOLDINGS_PERPETUAL_ACCESS_ID"))) {
            PerpetualAccess perpetualAccess = new PerpetualAccess();
            perpetualAccess.setPerpetualAccessStartDate(
                resultSet.getString("PERPETUAL_ACCESS_START_DATE"));
            perpetualAccess.setPerpetualAccessStartIssue(
                resultSet.getString("PERPETUAL_ACCESS_START_ISSUE"));
            perpetualAccess.setPerpetualAccessStartVolume(
                resultSet.getString("PERPETUAL_ACCESS_START_VOLUME"));
            perpetualAccess.setPerpetualAccessEndDate(
                resultSet.getString("PERPETUAL_ACCESS_END_DATE"));
            perpetualAccess.setPerpetualAccessEndVolume(
                resultSet.getString("PERPETUAL_ACCESS_END_VOLUME"));
            perpetualAccess.setPerpetualAccessEndIssue(
                resultSet.getString("PERPETUAL_ACCESS_END_ISSUE"));
            oleHoldings
                .getExtentOfOwnership()
                .get(0)
                .getPerpetualAccesses()
                .getPerpetualAccess()
                .add(perpetualAccess);
          }
        }
        if (donorSet != null && donorSet.add(resultSet.getString("HOLDINGS_DONOR_ID"))) {
          DonorInfo donorInfo = new DonorInfo();
          donorInfo.setDonorCode(resultSet.getString("DONOR_CODE"));
          donorInfo.setDonorNote(resultSet.getString("DONOR_NOTE"));
          donorInfo.setDonorPublicDisplay(resultSet.getString("DONOR_DISPLAY_NOTE"));
          oleHoldings.getDonorInfo().add(donorInfo);
        }
      }

      if (noteSet.add(resultSet.getString("HOLDINGS_NOTE_ID"))) {
        Note note = new Note();
        note.setValue(resultSet.getString("NOTE"));
        note.setType(resultSet.getString("TYPE"));
        oleHoldings.getNote().add(note);
      }
    }
    resultSet.close();
    return holdingsTrees;
  }