public String findLeastFullRepository(Map<String, PlatformUtil.DF> repoMap) {
   String mostFree = null;
   for (String repo : repoMap.keySet()) {
     PlatformUtil.DF df = repoMap.get(repo);
     if (df != null) {
       if (mostFree == null || (repoMap.get(mostFree)).getAvail() < df.getAvail()) {
         mostFree = repo;
       }
     }
   }
   return mostFree;
 }
  /*
   * When testing no-pdf-check basic XML parsing, you will get partial MD records
   * depending on whether the info comes from dataset.xml or from main.xml
   */
  private void validateDatasetMetadataRecord(ArticleMetadata am) {
    log.debug3("valideDatasetMetadatRecord");
    String doi_val = am.get(MetadataField.FIELD_DOI);
    assertEquals(common_issn, am.get(MetadataField.FIELD_ISSN));

    log.debug3("doi val is: " + doi_val);
    // The dataset doesn't set this value, it'll fail over the main.xml value
    if (doi_val.equals("10.1016/S0140-1111(14)61865-1")) {
      assertEquals(null, am.get(MetadataField.FIELD_DATE));
    } else {
      assertEquals(dateMap.get(doi_val), am.get(MetadataField.FIELD_DATE));
    }
    assertEquals(pubTitleMap.get(doi_val), am.get(MetadataField.FIELD_PUBLICATION_TITLE));
  }
  /** Create LockssKeystores from config subtree below {@link #PARAM_KEYSTORE} */
  void configureKeyStores(Configuration config) {
    Configuration allKs = config.getConfigTree(PARAM_KEYSTORE);
    for (Iterator iter = allKs.nodeIterator(); iter.hasNext(); ) {
      String id = (String) iter.next();
      Configuration oneKs = allKs.getConfigTree(id);
      try {
        LockssKeyStore lk = createLockssKeyStore(oneKs);
        String name = lk.getName();
        if (name == null) {
          log.error("KeyStore definition missing name: " + oneKs);
          continue;
        }
        LockssKeyStore old = keystoreMap.get(name);
        if (old != null && !lk.equals(old)) {
          log.warning(
              "Keystore "
                  + name
                  + " redefined.  "
                  + "New definition may not take effect until daemon restart");
        }

        log.debug("Adding keystore " + name);
        keystoreMap.put(name, lk);

      } catch (Exception e) {
        log.error("Couldn't create keystore: " + oneKs, e);
      }
    }
  }
  /*
   * You will have to tell it the DOI and the schema because those normally come from dataset
   */
  private void validateSingleMainMetadataRecord(ArticleMetadata am, String doi_val, String schema) {
    log.debug3("valideSingleMainMetadatRecord");
    if ("simple-article".equals(schema)) {
      assertEquals(common_simple_article_title, am.get(MetadataField.FIELD_ARTICLE_TITLE));
    } else {
      assertEquals(common_article_title, am.get(MetadataField.FIELD_ARTICLE_TITLE));
    }

    log.debug3("doi val is: " + doi_val);
    assertEquals(authorMap.get(doi_val), am.getList(MetadataField.FIELD_AUTHOR));
    assertEquals(volMap.get(doi_val), am.get(MetadataField.FIELD_VOLUME));
    assertEquals(issueMap.get(doi_val), am.get(MetadataField.FIELD_ISSUE));
    assertEquals("Comment", am.getRaw(ElsevierMainDTD5XmlSchemaHelper.common_dochead));
    assertEquals(doi_val, am.getRaw(ElsevierMainDTD5XmlSchemaHelper.common_doi));
    assertEquals("2014", am.getRaw(ElsevierMainDTD5XmlSchemaHelper.common_copyright));
  }
 // hack only local
 public synchronized LockssRepositoryImpl getRepositoryFromPath(String path) {
   LockssRepositoryImpl repo = (LockssRepositoryImpl) localRepos.get(path);
   if (repo == null) {
     repo = new LockssRepositoryImpl(path);
     repo.initService(getDaemon());
     repo.startService();
     localRepos.put(path, repo);
   }
   return repo;
 }
 static LocalRepository getLocalRepository(String repoRoot) {
   synchronized (localRepositories) {
     LocalRepository localRepo = (LocalRepository) localRepositories.get(repoRoot);
     if (localRepo == null) {
       logger.debug2("Creating LocalRepository(" + repoRoot + ")");
       localRepo = new LocalRepository(repoRoot);
       localRepositories.put(repoRoot, localRepo);
     }
     return localRepo;
   }
 }
  /*
   * When testing a complete extraction out of the tarset, the MD record will be completely filled in
   * and pdf-existence will get established
   */
  private void validateCompleteMetadataRecord(ArticleMetadata am) {
    log.debug3("valideCompleteMetadatRecord");
    String doi_val = am.get(MetadataField.FIELD_DOI);
    /* make sure we can pick up both types of xml article data */
    log.debug3("doi val is: " + doi_val);

    if ("JA 5.2.0 SIMPLE-ARTICLE"
        .equals(am.getRaw(ElsevierDatasetXmlSchemaHelper.dataset_dtd_metadata))) {
      log.debug3("simple-article");
      assertEquals(common_simple_article_title, am.get(MetadataField.FIELD_ARTICLE_TITLE));
    } else {
      assertEquals(common_article_title, am.get(MetadataField.FIELD_ARTICLE_TITLE));
    }
    assertEquals(common_issn, am.get(MetadataField.FIELD_ISSN));
    assertEquals(authorMap.get(doi_val), am.getList(MetadataField.FIELD_AUTHOR));
    assertEquals(dateMap.get(doi_val), am.get(MetadataField.FIELD_DATE));
    assertEquals(accessUrlMap.get(doi_val), am.get(MetadataField.FIELD_ACCESS_URL));
    assertEquals(volMap.get(doi_val), am.get(MetadataField.FIELD_VOLUME));
    assertEquals(issueMap.get(doi_val), am.get(MetadataField.FIELD_ISSUE));
    assertEquals(pubTitleMap.get(doi_val), am.get(MetadataField.FIELD_PUBLICATION_TITLE));
    assertEquals("Elsevier", am.get(MetadataField.FIELD_PROVIDER));
    assertEquals("Elsevier", am.get(MetadataField.FIELD_PUBLISHER));
    log.debug3(am.ppString(2));
  }
 static String canonRoot(String root) {
   synchronized (canonicalRoots) {
     String canon = (String) canonicalRoots.get(root);
     if (canon == null) {
       try {
         canon = new File(root).getCanonicalPath();
         canonicalRoots.put(root, canon);
       } catch (IOException e) {
         logger.warning("Can't canonicalize: " + root, e);
         return root;
       }
     }
     return canon;
   }
 }
 /**
  * Finds the directory for this AU. If none found in the map, designates a new dir for it.
  *
  * @param auid AU id representing the au
  * @param repoRoot path to the root of the repository
  * @return the dir String
  */
 static String getAuDir(String auid, String repoRoot, boolean create) {
   String repoCachePath = extendCacheLocation(repoRoot);
   LocalRepository localRepo = getLocalRepository(repoRoot);
   synchronized (localRepo) {
     Map aumap = localRepo.getAuMap();
     String auPathSlash = (String) aumap.get(auid);
     if (auPathSlash != null) {
       return auPathSlash;
     }
     if (!create) {
       return null;
     }
     logger.debug3("Creating new au directory for '" + auid + "'.");
     String auDir = localRepo.getPrevAuDir();
     for (int cnt = RepositoryManager.getMaxUnusedDirSearch(); cnt > 0; cnt--) {
       // loop through looking for an available dir
       auDir = getNextDirName(auDir);
       File testDir = new File(repoCachePath, auDir);
       if (logger.isDebug3()) logger.debug3("Probe for unused: " + testDir);
       if (!testDir.exists()) {
         if (RepositoryManager.isStatefulUnusedDirSearch()) {
           localRepo.setPrevAuDir(auDir);
         }
         String auPath = testDir.toString();
         logger.debug3("New au directory: " + auPath);
         auPathSlash = auPath + File.separator;
         // write the new au property file to the new dir
         // XXX this data should be backed up elsewhere to avoid single-point
         // corruption
         Properties idProps = new Properties();
         idProps.setProperty(AU_ID_PROP, auid);
         saveAuIdProperties(auPath, idProps);
         aumap.put(auid, auPathSlash);
         return auPathSlash;
       } else {
         if (logger.isDebug3()) {
           logger.debug3("Existing directory found at '" + auDir + "'.  Checking next...");
         }
       }
     }
   }
   throw new RuntimeException(
       "Can't find unused repository dir after "
           + RepositoryManager.getMaxUnusedDirSearch()
           + " tries in "
           + repoCachePath);
 }
    /**
     * Return the auid -> au-subdir-path mapping. Enumerating the directories if necessary to
     * initialize the map
     */
    Map getAuMap() {
      if (auMap == null) {
        logger.debug3("Loading name map for '" + repoCacheFile + "'.");
        auMap = new HashMap();
        if (!repoCacheFile.exists()) {
          logger.debug3("Creating cache dir:" + repoCacheFile + "'.");
          if (!repoCacheFile.mkdirs()) {
            logger.critical("Couldn't create directory, check owner/permissions: " + repoCacheFile);
            // return empty map
            return auMap;
          }
        } else {
          // read each dir's property file and store mapping auid -> dir
          File[] auDirs = repoCacheFile.listFiles();
          for (int ii = 0; ii < auDirs.length; ii++) {
            String dirName = auDirs[ii].getName();
            //       if (dirName.compareTo(lastPluginDir) == 1) {
            //         // adjust the 'lastPluginDir' upwards if necessary
            //         lastPluginDir = dirName;
            //       }

            String path = auDirs[ii].getAbsolutePath();
            Properties idProps = getAuIdProperties(path);
            if (idProps != null) {
              String auid = idProps.getProperty(AU_ID_PROP);
              StringBuilder sb = new StringBuilder(path.length() + File.separator.length());
              sb.append(path);
              sb.append(File.separator);
              auMap.put(auid, sb.toString());
              logger.debug3("Mapping to: " + auMap.get(auid) + ": " + auid);
            } else {
              logger.debug3("Not mapping " + path + ", no auid file.");
            }
          }
        }
      }
      return auMap;
    }
 /**
  * Return the named LockssKeyStore
  *
  * @param name the keystore name
  * @param criticalServiceName if non-null, this is a criticial keystore whose unavailability
  *     should cause the daemon to exit (if org.lockss.keyMgr.exitIfMissingKeystore is true)
  */
 public LockssKeyStore getLockssKeyStore(String name, String criticalServiceName) {
   LockssKeyStore res = keystoreMap.get(name);
   checkFact(res, name, criticalServiceName, null);
   return res;
 }
Example #12
0
 protected boolean hasNoRoleParsm(String roleName) {
   String noRoleParam = noRoleParams.get(roleName);
   return (noRoleParam != null && !StringUtil.isNullString(req.getParameter(noRoleParam)));
 }