Exemplo n.º 1
0
 /**
  * Return the number of TdbTitles in this Tdb.
  *
  * @return the total TdbTitle count
  */
 public int getTdbTitleCount() {
   int titleCount = 0;
   for (TdbPublisher publisher : tdbPublisherMap.values()) {
     titleCount += publisher.getTdbTitleCount();
   }
   return titleCount;
 }
Exemplo n.º 2
0
 /**
  * Add TdbAus for like (starts with) the specified TdbAu name.
  *
  * @param tdbAuName the name of the AU to select
  * @param tdbAus the collection to add to
  * @return <code>true</code> if TdbAus were added to the collection
  */
 public boolean getTdbAusLikeName(String tdbAuName, Collection<TdbAu> aus) {
   boolean added = false;
   for (TdbPublisher publisher : tdbPublisherMap.values()) {
     added |= publisher.getTdbAusLikeName(tdbAuName, aus);
   }
   return added;
 }
Exemplo n.º 3
0
 /** Print a full description of all elements in the Tdb */
 public void prettyPrint(PrintStream ps) {
   ps.println("Tdb");
   TreeMap<String, TdbPublisher> sorted =
       new TreeMap<String, TdbPublisher>(CatalogueOrderComparator.SINGLETON);
   sorted.putAll(getAllTdbPublishers());
   for (TdbPublisher tdbPublisher : sorted.values()) {
     tdbPublisher.prettyPrint(ps, 2);
   }
 }
Exemplo n.º 4
0
 /**
  * Adds to a collection of TdbTitles like (starts with) the specified title name across all
  * publishers.
  *
  * @param titleName the title name
  * @param titles a collection of matching titles
  * @return a collection of TdbTitles that match the title name
  */
 public boolean getTdbTitlesLikeName(String titleName, Collection<TdbTitle> titles) {
   boolean added = false;
   if (titleName != null) {
     for (TdbPublisher publisher : tdbPublisherMap.values()) {
       added |= publisher.getTdbTitlesLikeName(titleName, titles);
     }
   }
   return added;
 }
Exemplo n.º 5
0
 /** Add to a collection of TdbAus for this TDB that match the ISBN. */
 public boolean getTdbAusByIsbn(String isbn, Collection<TdbAu> matchingTdbAus) {
   boolean added = false;
   if (isbn != null) {
     for (TdbPublisher tdbPublisher : tdbPublisherMap.values()) {
       added |= tdbPublisher.getTdbAusByIsbn(matchingTdbAus, isbn);
     }
   }
   return added;
 }
Exemplo n.º 6
0
 /**
  * Get a title for the specified issn.
  *
  * @param issn the issn
  * @return the title for the titleId or <code>null</code. if not found
  */
 public TdbTitle getTdbTitleByIssn(String issn) {
   if (issn != null) {
     for (TdbPublisher publisher : tdbPublisherMap.values()) {
       TdbTitle title = publisher.getTdbTitleByIssn(issn);
       if (title != null) {
         return title;
       }
     }
   }
   return null;
 }
Exemplo n.º 7
0
 /**
  * Get the title for the specified titleId.
  *
  * @param titleId the titleID
  * @return the title for the titleId or <code>null</code. if not found
  */
 public TdbTitle getTdbTitleById(String titleId) {
   if (titleId != null) {
     for (TdbPublisher publisher : tdbPublisherMap.values()) {
       TdbTitle title = publisher.getTdbTitleById(titleId);
       if (title != null) {
         return title;
       }
     }
   }
   return null;
 }
Exemplo n.º 8
0
  /**
   * Add a new TdbAu to this title database. The TdbAu must have its pluginID, and title set. The
   * TdbAu''s title must also have its titleId and publisher set. The publisher name must be unique
   * to all publishers in this Tdb.
   *
   * @param au the TdbAu to add.
   * @throws TdbException if Tdb is sealed, this is a duplicate au, or the au's publisher is a
   *     duplicate
   */
  public void addTdbAu(TdbAu au) throws TdbException {
    if (au == null) {
      throw new IllegalArgumentException("TdbAu cannot be null");
    }

    // verify not sealed
    if (isSealed()) {
      throw new TdbException("Cannot add TdbAu to sealed Tdb");
    }

    // validate title
    TdbTitle title = au.getTdbTitle();
    if (title == null) {
      throw new IllegalArgumentException("TdbAu's title not set");
    }

    // validate publisher
    TdbPublisher publisher = title.getTdbPublisher();
    if (publisher == null) {
      throw new IllegalArgumentException("TdbAu's publisher not set");
    }

    // make sure publisher is not a duplicate
    String pubName = publisher.getName();
    TdbPublisher oldPublisher = tdbPublisherMap.put(pubName, publisher);
    if ((oldPublisher != null) && (oldPublisher != publisher)) {
      // restore old publisher and report error
      tdbPublisherMap.put(pubName, oldPublisher);
      throw new TdbException("New au publisher with duplicate name: " + pubName);
    }

    // register the au with this instance
    if (!addTdbAuForPlugin(au)) {
      // remove new publisher and report error
      if (oldPublisher == null) {
        tdbPublisherMap.remove(pubName);
      }
      throw new TdbException("Cannot register au " + au.getName());
    }
  }
Exemplo n.º 9
0
  /**
   * Adds a collection of pluginIds for TdbAus that are different from those in this Tdb.
   *
   * @param pluginIds the set of pluginIds
   * @param otherTdb a Tdb
   */
  private void addPluginIdsForDifferences(Set<String> pluginIds, Tdb otherTdb) {
    Map<String, TdbPublisher> tdbPublishers = otherTdb.getAllTdbPublishers();

    for (TdbPublisher tdbPublisher : tdbPublishers.values()) {
      if (!this.tdbPublisherMap.containsKey(tdbPublisher.getName())) {
        // add pluginIds for publishers in tdb that are not in this Tdb
        tdbPublisher.addAllPluginIds(pluginIds);
      }
    }

    for (TdbPublisher thisPublisher : tdbPublisherMap.values()) {
      TdbPublisher tdbPublisher = tdbPublishers.get(thisPublisher.getName());
      if (tdbPublisher == null) {
        // add pluginIds for publisher in this Tdb that is not in tdb
        thisPublisher.addAllPluginIds(pluginIds);
      } else {
        // add pluginIds for publishers in both Tdbs that are different
        thisPublisher.addPluginIdsForDifferences(pluginIds, tdbPublisher);
      }
    }
  }
Exemplo n.º 10
0
  /**
   * Get or create TdbTitle for the specified properties and TdbAu.
   *
   * @param props the properties
   * @param au the TdbAu
   * @return the corresponding TdbTitle
   */
  private TdbTitle getTdbTitle(Properties props, TdbAu au) {
    TdbTitle title = null;

    // get publisher name
    String publisherNameFromProps = getTdbPublisherName(props, au);

    // get the title name
    String titleNameFromProps = getTdbTitleName(props, au);

    // get the title ID
    String titleIdFromProps = getTdbTitleId(props, au);

    String titleId = titleIdFromProps;
    if (titleId == null) {
      // generate a titleId if one not specified, using the
      // hash code of the combined title name and publisher names
      int hash = (titleNameFromProps + publisherNameFromProps).hashCode();
      titleId = (hash < 0) ? ("id:1" + (-hash)) : ("id:0" + hash);
    }

    // get publisher specified by property name
    TdbPublisher publisher = tdbPublisherMap.get(publisherNameFromProps);
    if (publisher != null) {
      // find title from publisher
      title = publisher.getTdbTitleById(titleId);
      if (title != null) {
        // warn that title name is different
        if (!title.getName().equals(titleNameFromProps)) {
          logger.warning(
              "Title for au \""
                  + au.getName()
                  + "\": \""
                  + titleNameFromProps
                  + "\" is different than existing title \""
                  + title.getName()
                  + "\" for id "
                  + titleId
                  + " -- using existing title.");
        }
        return title;
      }
    }

    if (publisher == null) {
      // warn of missing publisher name
      if (publisherNameFromProps.startsWith(UNKNOWN_PUBLISHER_PREFIX)) {
        logger.warning(
            "Publisher missing for au \""
                + au.getName()
                + "\" -- using \""
                + publisherNameFromProps
                + "\"");
      }

      // create new publisher for specified publisher name
      publisher = new TdbPublisher(publisherNameFromProps);
      tdbPublisherMap.put(publisherNameFromProps, publisher);
    }

    // warn of missing title name and/or id
    if (titleNameFromProps.startsWith(UNKNOWN_TITLE_PREFIX)) {
      logger.warning(
          "Title missing for au \"" + au.getName() + "\" -- using \"" + titleNameFromProps + "\"");
    }
    if (titleIdFromProps == null) {
      logger.debug2("Title ID missing for au \"" + au.getName() + "\" -- using " + titleId);
    }

    // create title and add to publisher
    title = new TdbTitle(titleNameFromProps, titleId);
    try {
      publisher.addTdbTitle(title);
    } catch (TdbException ex) {
      // shouldn't happen: title already exists in publisher
      logger.error(ex.getMessage(), ex);
    }

    return title;
  }
Exemplo n.º 11
0
  /**
   * Merge other Tdb into this one. Makes copies of otherTdb's non-duplicate TdbPublisher, TdbTitle,
   * and TdbAu objects and their non-duplicate children. The object themselves are not merged.
   *
   * @param otherTdb the other Tdb
   * @throws TdbException if Tdb is sealed
   */
  public void copyFrom(Tdb otherTdb) throws TdbException {
    // ignore inappropriate Tdb values
    if ((otherTdb == null) || (otherTdb == this)) {
      return;
    }

    if (isSealed()) {
      throw new TdbException("Cannot add otherTdb AUs to sealed Tdb");
    }

    // merge non-duplicate publishers of otherTdb
    boolean tdbIsNew = tdbPublisherMap.isEmpty();
    for (TdbPublisher otherPublisher : otherTdb.getAllTdbPublishers().values()) {
      String pubName = otherPublisher.getName();
      TdbPublisher thisPublisher;
      boolean publisherIsNew = true;
      if (tdbIsNew) {
        // no need to check for existing publisher if TDB is new
        thisPublisher = new TdbPublisher(pubName);
        tdbPublisherMap.put(pubName, thisPublisher);
      } else {
        thisPublisher = tdbPublisherMap.get(pubName);
        publisherIsNew = (thisPublisher == null);
        if (publisherIsNew) {
          // copy publisher if not present in this Tdb
          thisPublisher = new TdbPublisher(pubName);
          tdbPublisherMap.put(pubName, thisPublisher);
        }
      }

      // merge non-duplicate titles of otherPublisher into thisPublisher
      for (TdbTitle otherTitle : otherPublisher.getTdbTitles()) {
        String otherId = otherTitle.getId();
        TdbTitle thisTitle;
        boolean titleIsNew = true;
        if (publisherIsNew) {
          // no need to check for existing title if publisher is new
          thisTitle = otherTitle.copyForTdbPublisher(thisPublisher);
          thisPublisher.addTdbTitle(thisTitle);
        } else {
          thisTitle = thisPublisher.getTdbTitleById(otherId);
          titleIsNew = (thisTitle == null);
          if (titleIsNew) {
            // copy title if not present in this publisher
            thisTitle = otherTitle.copyForTdbPublisher(thisPublisher);
            thisPublisher.addTdbTitle(thisTitle);
          } else if (!thisTitle.getName().equals(otherTitle.getName())) {
            // error because it could lead to a missing title -- one probably has a typo
            // (what about checking other title elements too?)
            logger.error(
                "Ignorning duplicate title entry: \""
                    + otherTitle.getName()
                    + "\" with the same ID as \""
                    + thisTitle.getName()
                    + "\"");
          }
        }

        // merge non-duplicate TdbAus of otherTitle into thisTitle
        for (TdbAu otherAu : otherTitle.getTdbAus()) {
          // no need to check for existing au if title is new
          String pluginId = otherAu.getPluginId();
          if (titleIsNew || !getTdbAuIds(pluginId).contains(otherAu.getId())) {
            // always succeeds we've already checked for duplicate
            TdbAu thisAu = otherAu.copyForTdbTitle(thisTitle);
            addTdbAuForPlugin(thisAu);
          } else {
            TdbAu thisAu = findExistingTdbAu(otherAu);
            if (!thisAu.getTdbTitle().getName().equals(otherAu.getTdbTitle().getName())) {
              if (!thisAu.getName().equals(otherAu.getName())) {
                logger.error(
                    "Ignorning duplicate au entry: \""
                        + otherAu.getName()
                        + "\" for title \""
                        + otherAu.getTdbTitle().getName()
                        + "\" with same definion as existing au entry: \""
                        + thisAu.getName()
                        + "\" for title \""
                        + thisAu.getTdbTitle().getName()
                        + "\"");
              } else {
                logger.error(
                    "Ignorning duplicate au entry: \""
                        + otherAu.getName()
                        + "\" for title \""
                        + otherAu.getTdbTitle().getName()
                        + "\" with same definion as existing one for title \""
                        + thisAu.getTdbTitle().getName()
                        + "\"");
              }
            } else if (!thisAu.getName().equals(otherAu.getName())) {
              // error because it could lead to a missing AU -- one probably has a typo
              logger.error(
                  "Ignorning duplicate au entry: \""
                      + otherAu.getName()
                      + "\" with the same definition as \""
                      + thisAu.getName()
                      + "\" for title \""
                      + otherAu.getTdbTitle().getName());
            } else {
              logger.warning(
                  "Ignoring duplicate au entry: \""
                      + otherAu.getName()
                      + "\" for title \""
                      + otherAu.getTdbTitle().getName());
            }
          }
        }
      }
    }
  }