Displaying differences for changeset
 
display as  

nbproject/project.properties

@@ -1,6 +1,6 @@
 file.reference.commons-lang3-3.7.jar=lib/commons-lang3-3.7.jar
 file.reference.opencsv-4.2.jar=lib/opencsv-4.2.jar
-j2ee.platform.classpath=${j2ee.server.home}/lib/annotations-api.jar:${j2ee.server.home}/lib/catalina-ant.jar:${j2ee.server.home}/lib/catalina-ha.jar:${j2ee.server.home}/lib/catalina-storeconfig.jar:${j2ee.server.home}/lib/catalina-tribes.jar:${j2ee.server.home}/lib/catalina.jar:${j2ee.server.home}/lib/ecj-4.4.2.jar:${j2ee.server.home}/lib/el-api.jar:${j2ee.server.home}/lib/jasper-el.jar:${j2ee.server.home}/lib/jasper.jar:${j2ee.server.home}/lib/jsp-api.jar:${j2ee.server.home}/lib/servlet-api.jar:${j2ee.server.home}/lib/tomcat-api.jar:${j2ee.server.home}/lib/tomcat-coyote.jar:${j2ee.server.home}/lib/tomcat-dbcp.jar:${j2ee.server.home}/lib/tomcat-i18n-es.jar:${j2ee.server.home}/lib/tomcat-i18n-fr.jar:${j2ee.server.home}/lib/tomcat-i18n-ja.jar:${j2ee.server.home}/lib/tomcat-jdbc.jar:${j2ee.server.home}/lib/tomcat-jni.jar:${j2ee.server.home}/lib/tomcat-util-scan.jar:${j2ee.server.home}/lib/tomcat-util.jar:${j2ee.server.home}/lib/tomcat-websocket.jar:${j2ee.server.home}/lib/websocket-api.jar
+j2ee.platform.classpath=${j2ee.server.home}/lib/annotations-api.jar:${j2ee.server.home}/lib/catalina-ant.jar:${j2ee.server.home}/lib/catalina-ha.jar:${j2ee.server.home}/lib/catalina-storeconfig.jar:${j2ee.server.home}/lib/catalina-tribes.jar:${j2ee.server.home}/lib/catalina.jar:${j2ee.server.home}/lib/ecj-4.4.1.jar:${j2ee.server.home}/lib/el-api.jar:${j2ee.server.home}/lib/jasper-el.jar:${j2ee.server.home}/lib/jasper.jar:${j2ee.server.home}/lib/jsp-api.jar:${j2ee.server.home}/lib/servlet-api.jar:${j2ee.server.home}/lib/tomcat-api.jar:${j2ee.server.home}/lib/tomcat-coyote.jar:${j2ee.server.home}/lib/tomcat-dbcp.jar:${j2ee.server.home}/lib/tomcat-i18n-es.jar:${j2ee.server.home}/lib/tomcat-i18n-fr.jar:${j2ee.server.home}/lib/tomcat-i18n-ja.jar:${j2ee.server.home}/lib/tomcat-jdbc.jar:${j2ee.server.home}/lib/tomcat-jni.jar:${j2ee.server.home}/lib/tomcat-spdy.jar:${j2ee.server.home}/lib/tomcat-util-scan.jar:${j2ee.server.home}/lib/tomcat-util.jar:${j2ee.server.home}/lib/tomcat-websocket.jar:${j2ee.server.home}/lib/websocket-api.jar
 #Sun Nov 08 20:17:36 MST 2015
 javadoc.splitindex=true
 lib.dir=${web.docbase.dir}/WEB-INF/lib

src/java/m/timeseries/delete/V1_0.java

@@ -28,7 +28,7 @@
  */
 @Name("Timeseries delete")
 @Description("Delete a timeseries collection or document in mongo.")
-@Author(org="CSU")
+@Author(org = "CSU")
 @License(License.MIT)
 @Path("m/delete/1.0")
 public class V1_0 extends ModelDataService {
@@ -37,6 +37,7 @@
     MongoDatabase db;
     JSONObject results = new JSONObject();
 
+
     protected void open(String mongoclienturi) {
         MongoClientURI u = new MongoClientURI(mongoclienturi);
         mongo = new MongoClient(u);
@@ -60,25 +61,29 @@
         String mongo_uri = getStringParam("mongo_uri");
         String mongo_collection = getStringParam("mongo_collection");
         JSONArray ids = getJSONArrayParam("ids", null);
+        
         if (ids != null) {
-            deleteIds(mongo_uri, mongo_collection, ids, LOG);
+            deleteIds(mongo_uri, mongo_collection, ids);
         } else {
             // If no ids specified, then delete the collection.
-            deleteCollection(mongo_uri, mongo_collection, LOG);
+            deleteCollection(mongo_uri, mongo_collection);
         }
     }
-    
-    public void deleteCollection(String mongo_uri, String mongo_collection, SessionLogger LOG) throws JSONException {
+
+
+    public void deleteCollection(String mongo_uri, String mongo_collection) throws JSONException {
         open(mongo_uri);
         MongoCollection<Document> collection = db.getCollection(mongo_collection);
         collection.drop();
         results.put("deleted_collection", mongo_collection);
+        close();
     }
 
-    public void deleteIds(String mongo_uri, String mongo_collection, JSONArray ids, SessionLogger LOG) throws JSONException {
+
+    public void deleteIds(String mongo_uri, String mongo_collection, JSONArray ids) throws JSONException {
         open(mongo_uri);
         MongoCollection<Document> collection = db.getCollection(mongo_collection);
-        
+
         List<String> ids_list = new ArrayList();
         for (int i = 0; i < ids.length(); i++) {
             ids_list.add(ids.getString(i));
@@ -86,16 +91,16 @@
 
         List<String> deleted_ids = new ArrayList();
         FindIterable<Document> c = collection.find();
-        for (Document finddoc: c) {
-            String find_id = (String)finddoc.get("_id");
+        for (Document finddoc : c) {
+            String find_id = (String) finddoc.get("_id");
             if (ids_list.contains(find_id)) {
                 LOG.info("Deleting existing doc");
                 collection.deleteOne(finddoc);
                 deleted_ids.add(find_id);
             }
         }
-
         results.put("deleted_document_ids", new JSONArray(deleted_ids));
+        close();
     }
 
 
@@ -103,16 +108,17 @@
     protected void postProcess() throws Exception {
         putResult("result", results);
     }
-    
-    public static void main(String [] args) throws JSONException {
+
+
+    public static void main(String[] args) throws JSONException {
         V1_0 timeseries = new V1_0();
-        SessionLogger LOG = new SessionLogger();
         JSONArray delete_ids = new JSONArray();
         delete_ids.put("test_ref");
-        timeseries.deleteIds("mongodb://eds0.engr.colostate.edu:27017/csip_timeseries", "test_coll", delete_ids, LOG);
-        timeseries.deleteCollection("mongodb://eds0.engr.colostate.edu:27017/csip_timeseries", "test_coll", LOG);   
+        timeseries.deleteIds("mongodb://eds0.engr.colostate.edu:27017/csip_timeseries", "test_coll", delete_ids);
+        timeseries.deleteCollection("mongodb://eds0.engr.colostate.edu:27017/csip_timeseries", "test_coll");
     }
-    
+
+
     public static String[] toStringArray(List<String> data) {
         return (String[]) data.stream().map(String::toString).toArray();
     }

src/java/m/timeseries/insert/V1_0.java

@@ -56,7 +56,6 @@
         if (!u.getDatabase().equals("csip_timeseries")) {
             throw new RuntimeException("Can only modify csip_timeseries collection");
         }
-
         db = mongo.getDatabase(u.getDatabase());
     }
 
@@ -78,11 +77,13 @@
         String date_fmt = getStringParam("date_format");
         JSONArray locationArray = getJSONArrayParam("location");
         List<Double> location = Arrays.asList(Double.parseDouble(locationArray.get(0).toString()), Double.parseDouble(locationArray.get(1).toString()));
+        
         run(mongo_uri, mongo_collection, doc_id, data_file, data_col, metadata, date_fmt, location, LOG);
     }
     
-    public void run(String mongo_uri, String mongo_collection, String doc_id, File data_file, String data_col, JSONObject metadata,
+    void run(String mongo_uri, String mongo_collection, String doc_id, File data_file, String data_col, JSONObject metadata,
             String date_fmt, List<Double> location, SessionLogger LOG) throws FileNotFoundException, IOException, JSONException, ParseException {
+
         open(mongo_uri);
         MongoCollection<Document> collection = db.getCollection(mongo_collection);
 
@@ -130,6 +131,7 @@
         }
         results = new JSONObject();
         results.put("updated_document_id", doc.get("_id").toString());
+        close();
     }
 
 

src/java/m/timeseries/query/V1_0.java

@@ -35,6 +35,7 @@
 import org.codehaus.jettison.json.JSONObject;
 import java.util.logging.Level;
 import java.util.logging.Logger;
+import org.apache.catalina.ant.ServerinfoTask;
 
 /**
  * Mongodb timeseries data insertion
@@ -77,18 +78,21 @@
         String end_date = getStringParam("end_date", null);
         boolean metadata_only = getBooleanParam("metadata_only", true);
         String search_id = getStringParam("search_id", null);
-        JSONObject search_feature;
-        try {
-            search_feature = getJSONParam("search_feature", null);
-        } catch (ServiceException ex) {
-            throw new RuntimeException(ex);
-        }
-        run(mongo_uri, mongo_collection, search_feature, search_id, start_date, end_date, metadata_only, LOG);
+        JSONObject search_feature = getJSONParam("search_feature", null);
+        
+        run(mongo_uri, mongo_collection, search_feature, search_id, start_date, end_date, metadata_only);
     }
 
 
-    public void run(String mongo_uri, String mongo_collection, JSONObject search_feature, String search_id,
-            String start_date_str, String end_date_str, boolean metadata_only, SessionLogger LOG) throws JSONException {
+    @Override
+    protected void postProcess() throws Exception {
+        putResult("result", results);
+    }
+
+
+    void run(String mongo_uri, String mongo_collection, JSONObject search_feature, String search_id,
+            String start_date_str, String end_date_str, boolean metadata_only) throws JSONException, ServiceException {
+
         open(mongo_uri);
         MongoCollection<Document> collection = db.getCollection(mongo_collection);
 
@@ -119,14 +123,13 @@
             }
         } else {
             JSONArray features = search_feature.getJSONArray("features");
-
             for (int i = 0; i < features.length(); i++) {
                 JSONObject feat = features.getJSONObject(i);
                 List<Bson> agg_match = null;
                 try {
                     agg_match = getMatch(feat, search_id);
                 } catch (IOException ex) {
-                    Logger.getLogger(V1_0.class.getName()).log(Level.SEVERE, null, ex);
+                    throw new ServiceException(ex);
                 }
                 AggregateIterable<Document> c = collection.aggregate(agg_match);
                 for (Document doc : c) {
@@ -135,6 +138,7 @@
                 }
             }
         }
+        close();
     }
 
 
@@ -179,12 +183,6 @@
     }
 
 
-    @Override
-    protected void postProcess() throws Exception {
-        putResult("result", results);
-    }
-
-
     public List<Bson> getMatch(JSONObject feat, String search_id) throws JSONException, IOException {
         String geom = feat.getJSONObject("geometry").toString();
         Document match_arg = new Document("location",
@@ -209,7 +207,7 @@
     }
 
 
-    public static void main(String[] args) throws FileNotFoundException, IOException, JSONException, ParseException {
+    public static void main(String[] args) throws FileNotFoundException, IOException, JSONException, ParseException, ServiceException {
         V1_0 timeseries = new V1_0();
         JSONObject searchFeature = new JSONObject("{\n"
                 + "                \"type\": \"FeatureCollection\",\n"
@@ -252,8 +250,7 @@
                 + "                  }\n"
                 + "                ]\n"
                 + "            }");
-        SessionLogger LOG = new SessionLogger();
         String search_id = null;
-        timeseries.run("mongodb://eds0.engr.colostate.edu:27017/csip_timeseries", "test_coll", searchFeature, search_id, "2014-04-04", "2014-05-08", false, LOG);
+        timeseries.run("mongodb://eds0.engr.colostate.edu:27017/csip_timeseries", "test_coll", searchFeature, search_id, "2014-04-04", "2014-05-08", false);
     }
 }