コード例 #1
0
 @Override
 public void execute() {
   CommandDAO dao = new CommandDAO();
   try {
     dao.setStatus(getCommandId(), "STARTED");
     if (region == null || url == null) {
       log.info("Invalid Process Inventory Command, " + this);
     } else {
       ProductDAO pdao = new ProductDAO();
       pdao.whitelist(region);
       String filePath = downloads + File.separator + System.currentTimeMillis();
       String downloadedFile = downloadFile(url, filePath);
       processContents(downloadedFile, pdao);
     }
     dao.setStatus(getCommandId(), "COMPLETED");
   } catch (Exception e) {
     log.error("Error blacklisting", e);
     try {
       dao.setStatus(getCommandId(), "ERROR");
     } catch (DBException e1) {
     }
   }
 }
コード例 #2
0
 private void processContents(String filePath, ProductDAO pdao) throws Exception {
   BufferedReader reader =
       new BufferedReader(new InputStreamReader(new FileInputStream(filePath)));
   try {
     String line = null;
     do {
       line = reader.readLine();
       if (line != null) {
         String productId = line.trim();
         pdao.addToBlacklist(region, productId);
       }
     } while (line != null);
   } finally {
     if (reader != null) {
       reader.close();
     }
   }
 }