/** * Add a TdbAu to a TdbTitle and TdbPubisher, and add links to the TdbTitle specified by the * properties. * * @param props the properties * @param au the TdbAu to add * @throws TdbException if the AU already exists in this Tdb */ private void addTdbAu(Properties props, TdbAu au) throws TdbException { // add au for plugin assuming it is not a duplicate if (!addTdbAuForPlugin(au)) { // au already registered -- report existing au TdbAu existingAu = findExistingTdbAu(au); String titleName = getTdbTitleName(props, au); if (!titleName.equals(existingAu.getTdbTitle().getName())) { throw new TdbException( "Cannot add duplicate au entry: \"" + au.getName() + "\" for title \"" + titleName + "\" with same definition as existing au entry: \"" + existingAu.getName() + "\" for title \"" + existingAu.getTdbTitle().getName() + "\" to title database"); } else if (!existingAu.getName().equals(au.getName())) { // error because it could lead to a missing AU -- one probably has a typo throw new TdbException( "Cannot add duplicate au entry: \"" + au.getName() + "\" with the same definition as \"" + existingAu.getName() + "\" for title \"" + titleName + "\" to title database"); } else { throw new TdbException( "Cannot add duplicate au entry: \"" + au.getName() + "\" for title \"" + titleName + "\" to title database"); } } // get or create the TdbTitle for this TdbTitle title = getTdbTitle(props, au); try { // add AU to title title.addTdbAu(au); } catch (TdbException ex) { // if we can't add au to title, remove for plugin and re-throw exception removeTdbAuForPlugin(au); throw ex; } // process title links Map<String, Map<String, String>> linkMap = new HashMap<String, Map<String, String>>(); for (Map.Entry<Object, Object> entry : props.entrySet()) { String key = "" + entry.getKey(); String value = "" + entry.getValue(); if (key.startsWith("journal.link.")) { // skip to link name String param = key.substring("link.".length()); int i; if (((i = param.indexOf(".type")) < 0) && ((i = param.indexOf(".journalId")) < 0)) { logger.warning( "Ignoring nexpected link key for au \"" + au.getName() + "\" key: \"" + key + "\""); } else { // get link map for linkName String lname = param.substring(0, i); Map<String, String> lmap = linkMap.get(lname); if (lmap == null) { lmap = new HashMap<String, String>(); linkMap.put(lname, lmap); } // add name and value to link map for link String name = param.substring(i + 1); lmap.put(name, value); } } } // add links to title from accumulated "type", "journalId" entries for (Map<String, String> lmap : linkMap.values()) { String name = lmap.get("type"); String value = lmap.get("journalId"); if ((name != null) && (value != null)) { try { TdbTitle.LinkType linkType = TdbTitle.LinkType.valueOf(name); title.addLinkToTdbTitleId(linkType, value); } catch (IllegalArgumentException ex) { logger.warning( "Ignoring unknown link type for au \"" + au.getName() + "\" name: \"" + name + "\""); } } } }