exifIndexer.MetadataQueries.java Source code

Java tutorial

Introduction

Here is the source code for exifIndexer.MetadataQueries.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package exifIndexer;

import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import java.util.ArrayList;
import static java.util.Objects.isNull;

/**
 *
 * @author JOSE
 */
public class MetadataQueries {

    public MetadataQueries() {
    }

    public ResultDataNormal cameraBrand(String s) {
        ArrayList paths = new ArrayList<>();
        ArrayList names = new ArrayList<>();

        //Consulta por marca de camara
        MongoHandler dbmon = new MongoHandler();
        DB dbmongo = dbmon.connect();
        DBCursor cursorDoc;
        DBCollection collection = dbmongo.getCollection("CameraBrands");
        BasicDBObject query = new BasicDBObject("CAMERA_BRAND", s);
        cursorDoc = collection.find(query);
        try {
            while (cursorDoc.hasNext()) {
                paths.add((cursorDoc.next().get("IMG_PATH")));
                names.add((cursorDoc.curr().get("IMG_NAME")) + "." + (cursorDoc.curr().get("EXTENSION")));

            }
        } finally {
            cursorDoc.close();
        }
        return new ResultDataNormal(paths, names);
    }

    public ResultDataNormal cameraModel(String s) {
        ArrayList paths = new ArrayList<>();
        ArrayList names;
        names = new ArrayList<String>();
        //Consulta por modelo de camara
        MongoHandler dbmon = new MongoHandler();
        DB dbmongo = dbmon.connect();
        DBCursor cursorDoc;
        DBCollection collection = dbmongo.getCollection("CameraModels");
        BasicDBObject query = new BasicDBObject("CAMERA_MODEL", s);
        cursorDoc = collection.find(query);

        try {
            while (cursorDoc.hasNext()) {
                paths.add((cursorDoc.next().get("IMG_PATH")));
                names.add((cursorDoc.curr().get("IMG_NAME")) + "." + (cursorDoc.curr().get("EXTENSION")));

            }
        } finally {
            cursorDoc.close();
        }
        return new ResultDataNormal(paths, names);
    }

    public ResultDataNormal searchByISO(String s) {
        ArrayList paths = new ArrayList<>();
        ArrayList names = new ArrayList<>();
        //Consulta por modelo de camara
        MongoHandler dbmon = new MongoHandler();
        DB dbmongo = dbmon.connect();
        DBCursor cursorDoc;
        DBCollection collection = dbmongo.getCollection("SearchByISO");
        BasicDBObject query = new BasicDBObject();
        switch (s) {
        case "LOW":
            query = new BasicDBObject("ISO_VALUE", new BasicDBObject("$lt", 100));
            break;
        case "HIGH":
            query = new BasicDBObject("ISO_VALUE", new BasicDBObject("$gt", 3200));
            break;
        default:
            query = new BasicDBObject("ISO_VALUE", new BasicDBObject("$eq", Integer.parseInt(s)));
            break;

        }

        cursorDoc = collection.find(query);

        try {
            while (cursorDoc.hasNext()) {
                paths.add((cursorDoc.next().get("IMG_PATH")));
                names.add((cursorDoc.curr().get("IMG_NAME")) + "." + (cursorDoc.curr().get("EXTENSION")));

            }
        } finally {
            cursorDoc.close();
        }
        return new ResultDataNormal(paths, names);
    }

    public ResultDataNormal shutterSpeed(String s) {
        //Consulta Shutter Speed
        ArrayList<String> paths = new ArrayList<>();
        ArrayList<String> names = new ArrayList<>();
        MongoHandler dbmon = new MongoHandler();
        DB dbmongo = dbmon.connect();
        DBCursor cursorDoc;

        DBCollection collection = dbmongo.getCollection("Shutter_Speed");
        BasicDBObject query = new BasicDBObject("SHUTTER_VALUE", s);
        cursorDoc = collection.find(query);

        try {
            while (cursorDoc.hasNext()) {
                System.out.println("algo encontrado");
                paths.add((cursorDoc.next().get("IMG_PATH").toString()));
                names.add((cursorDoc.curr().get("IMG_NAME")) + "." + (cursorDoc.curr().get("EXTENSION")));

            }
        } finally {
            cursorDoc.close();
        }
        return new ResultDataNormal(paths, names);
    }

    public String[] possibleShutterSpeeds() {
        //Consulta posibles Shutter Speed

        ArrayList<String> shutterList = new ArrayList<>();

        MongoHandler dbmon = new MongoHandler();
        DB dbmongo = dbmon.connect();
        DBCursor cursorDoc;

        DBCollection collection = dbmongo.getCollection("Possible_shutterSpeeds");

        cursorDoc = collection.find();

        try {
            while (cursorDoc.hasNext()) {
                shutterList.add(cursorDoc.next().get("SHUTTERSPEED").toString());
            }
        } finally {
            cursorDoc.close();
        }
        String[] res = new String[shutterList.size()];
        res = shutterList.toArray(res);

        return res;
    }

    public ResultDataNormal DateCreated(String s) {
        //Consulta DateCreated
        ArrayList paths = new ArrayList<>();
        ArrayList names = new ArrayList<>();
        MongoHandler dbmon = new MongoHandler();
        DB dbmongo = dbmon.connect();
        DBCursor cursorDoc;

        DBCollection collection = dbmongo.getCollection("Date_created");
        BasicDBObject query = new BasicDBObject("DATE_VALUE", s);
        cursorDoc = collection.find(query);

        if (isNull(cursorDoc)) {
            System.out.println("nulo");
        }

        try {
            while (cursorDoc.hasNext()) {
                paths.add((cursorDoc.next().get("IMG_PATH")));
                names.add((cursorDoc.curr().get("IMG_NAME")) + "." + (cursorDoc.curr().get("EXTENSION")));

            }
        } finally {
            cursorDoc.close();
        }
        return new ResultDataNormal(paths, names);
    }

    public ResultDataWithGPS gps() {
        //Consulta gps
        ArrayList paths = new ArrayList<>();
        ArrayList names = new ArrayList<>();
        ArrayList latitudes = new ArrayList<>();
        ArrayList longitudes = new ArrayList<>();
        ArrayList latref = new ArrayList<>();
        ArrayList lonref = new ArrayList<>();
        MongoHandler dbmon = new MongoHandler();
        DB dbmongo = dbmon.connect();
        DBCursor cursorDoc;
        Integer cont = 0;
        Integer pos = 0;
        ResultDataWithGPS res = null;

        DBCollection collection = dbmongo.getCollection("GPSFotos");
        // BasicDBObject query = new BasicDBObject("GPS_VALUE",true);
        cursorDoc = collection.find();

        try {
            while (cursorDoc.hasNext()) {

                pos = cont % 4;

                switch (pos) {
                case 0:
                    //GPS_VALUE                           
                    latitudes.add((cursorDoc.next().get("GPS_VALUE")));

                    break;

                case 1:
                    latref.add((cursorDoc.next().get("GPS_VALUE")));

                    break;

                case 2:
                    longitudes.add((cursorDoc.next().get("GPS_VALUE")));

                    break;

                case 3:
                    lonref.add((cursorDoc.next().get("GPS_VALUE")));

                    break;
                }

                if ((cont != 0) && (pos == 0)) {
                    paths.add((cursorDoc.curr().get("IMG_PATH")));
                    names.add((cursorDoc.curr().get("IMG_NAME")) + "." + (cursorDoc.curr().get("EXTENSION")));
                }
                cont++;
            }
            res = new ResultDataWithGPS(paths, names, latitudes, longitudes, latref, lonref);

        } finally {
            cursorDoc.close();
        }
        return res;
    }

}