List of usage examples for org.apache.commons.vfs2 FileNotFoundException FileNotFoundException
public FileNotFoundException(final Object info0)
From source file:com.hygenics.parser.QualityAssurer.java
public void run() { this.checkTable(); // CHECK THAT VARIABLES WHERE specified Correctly if (this.photoFolder != null || this.photoTable != null) { if (this.photoFolder != null ^ this.photoTable != null) { log.error("When specifiying a Photo Table or Photo Folder both variables must be present"); throw new NullPointerException("Photo Table or Photo Folder is missing"); } else {// ww w .j a v a 2 s.c o m int exists = 0; int nonexistant = 0; // check that the photos folder matches the photo database for (String f : new File(this.photoFolder).list()) { if (this.template.getJsonData("SELECT * FROM " + this.photoTable + " WHERE " + this.imageColumn + " ILIKE '%" + f.replaceAll(this.imageReplace, "") + "%'").size() > 0) { exists++; } else { nonexistant++; } } if (exists == 0 || (imageCutoff > -1 && nonexistant > 0 && exists / nonexistant < imageCutoff)) { try { throw new DataCountException( "Photo Counts too Low!\nRation: " + Double.toString(exists / nonexistant)); } catch (DataCountException e) { e.printStackTrace(); System.exit(-1); } } } } java.sql.Timestamp date = new java.sql.Timestamp(Calendar.getInstance().getTimeInMillis()); File[] files = new File(this.dropFolder).listFiles(); //check that a file that at least one of the following is present if (oneMustMatch != null) { for (String r : oneMustMatch) { Pattern p = Pattern.compile(r); boolean found = false; for (File f : files) { Matcher m = p.matcher(f.getName()); if (m.find()) { found = true; } } if (!found) { try { throw new FileNotFoundException("The file " + r + " Must Be Present!"); } catch (FileNotFoundException e) { e.printStackTrace(); System.exit(-1); } } } } // check file naming convention if (this.filenameRegex != null || this.dropFolder != null) { if (this.filenameRegex != null ^ this.dropFolder != null) { log.error( "If Drop Folder is Specified or File Name Regex is specified, the other must also be specified."); throw new NullPointerException("Drop Folder or File Name Regex Not Specified"); } if (files != null) { for (File f : files) { if (f.isFile() && !f.getName().contains(".zip") && f.getName().replaceAll(filenameRegex, "").length() != 0) { log.error("File Name Was Not Appropriately Specified"); try { throw new InvalidPath("File Name Not Specified Properly. " + f + " must conform to " + this.filenameRegex); } catch (InvalidPath e) { e.printStackTrace(); System.exit(-1); } } } } else { try { throw new FileNotFoundException("No Directory %s found!".format(this.dropFolder)); } catch (FileNotFoundException e) { e.printStackTrace(); System.exit(255); } } } // Insert Column Counts into QA Table int recCount = 0; ArrayList<String> jsons = this.template.getJsonData( "SELECT table_schema as schema,table_name as table,column_name as column FROM information_schema.columns WHERE table_schema LIKE '" + this.schema + "'"); ArrayList<String> tables = new ArrayList<String>(); if (jsons.size() > 0) { // get column count for (String json : jsons) { Map<String, Json> jmap = Json.read(json).asJsonMap(); if (!tables.contains(jmap.get("table").asString())) { // get table counts and add to appropriate jsons String tquery = "SELECT count(*) FROM " + jmap.get("schema").asString() + "." + jmap.get("table").asString(); int tcount = Json.read(this.template.getJsonData(tquery).get(0)).asJsonMap().get("count") .asInteger(); recCount += tcount; this.template.execute("INSERT INTO " + this.countTable + "(schemaname,tablename,count) VALUES('" + jmap.get("schema").asString() + "','" + jmap.get("table").asString() + "','" + tcount + "')"); tables.add(jmap.get("table").asString()); } String query = "SELECT count(\"" + jmap.get("column").asString() + "\") FROM " + jmap.get("schema").asString() + "." + jmap.get("table").asString() + " WHERE \"" + jmap.get("column").asString() + "\" IS NOT NULL AND length(trim(cast(\"" + jmap.get("column").asString() + "\" as text))) > 0"; int count = Json.read(this.template.getJsonData(query).get(0)).asJsonMap().get("count").asInteger(); this.template.execute( "INSERT INTO " + this.columnCheckTable + "(schemaname,tablename,columnname,count) VALUES('" + jmap.get("schema").asString() + "','" + jmap.get("table").asString() + "','" + jmap.get("column").asString() + "','" + count + "')"); } this.template.execute( "INSERT INTO " + this.sourceTable + " VALUES('" + this.schema.replaceAll("[0-9]+", "") + "')"); } // if no records are discovered, error if (recCount == 0) { log.error("No Data Found in Tables. Terminating!"); try { throw new MissingData("No Data Found In Tables"); } catch (MissingData e) { e.printStackTrace(); System.exit(-1); } } // If all checks succeed, insert into the source table this.template.execute("INSERT INTO " + this.sourceTable + " VALUES('" + this.schema + "')"); }