Subversion Repositories SmartDukaan

Rev

Rev 21974 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 21974 Rev 22003
Line 2... Line 2...
2
 
2
 
3
 
3
 
4
import java.lang.reflect.Type;
4
import java.lang.reflect.Type;
5
import java.net.UnknownHostException;
5
import java.net.UnknownHostException;
6
import java.util.List;
6
import java.util.List;
-
 
7
 
-
 
8
import org.apache.log4j.Logger;
-
 
9
 
7
import java.util.ArrayList;
10
import java.util.ArrayList;
8
 
11
 
9
import com.google.gson.Gson;
12
import com.google.gson.Gson;
10
import com.google.gson.reflect.TypeToken;
13
import com.google.gson.reflect.TypeToken;
11
import com.mongodb.BasicDBObject;
14
import com.mongodb.BasicDBObject;
Line 25... Line 28...
25
	private static MongoClient mongo;
28
	private static MongoClient mongo;
26
	private static final String CATALOG_DB = "Catalog";
29
	private static final String CATALOG_DB = "Catalog";
27
	private static final String MASTER_DATA = "MasterData";
30
	private static final String MASTER_DATA = "MasterData";
28
	private static final String FOFO_DB = "Fofo";
31
	private static final String FOFO_DB = "Fofo";
29
	private static final String FOFO_FORM_COLLECTION = "RegistrationForm";
32
	private static final String FOFO_FORM_COLLECTION = "RegistrationForm";
-
 
33
	private static Logger log = Logger.getLogger(Mongo.class);
30
 
34
 
31
	static {
35
	static {
32
		try {
36
		try {
33
			mongo = new MongoClient( "localhost" , 27017 );
37
			mongo = new MongoClient( "localhost" , 27017 );
34
		} catch (UnknownHostException e) {
38
		} catch (UnknownHostException e) {
Line 68... Line 72...
68
		}
72
		}
69
		return items;
73
		return items;
70
	}
74
	}
71
	
75
	
72
	public static void persistFofoRegInfo(FofoForm ff){
76
	public static void persistFofoRegInfo(FofoForm ff){
73
		DB db = mongo.getDB(FOFO_DB);
77
	    DB db = mongo.getDB(FOFO_DB);
74
		DBCollection collection = db.getCollection(FOFO_FORM_COLLECTION);
78
		DBCollection collection = db.getCollection(FOFO_FORM_COLLECTION);
-
 
79
		if(ff.get_id()==0) {
75
		BasicDBObject orderBy = new BasicDBObject();
80
			BasicDBObject orderBy = new BasicDBObject();
76
		orderBy.put("_id", -1);
81
			orderBy.put("_id", -1);
77
		DBCursor cursor = collection.find().sort(orderBy).limit(1);
82
			DBCursor cursor = collection.find().sort(orderBy).limit(1);
78
		long id = 1l;
83
			long id = 1l;
79
		while (cursor.hasNext()) {
84
			while (cursor.hasNext()) {
80
			Gson gson = new Gson();
85
				Gson gson = new Gson();
81
			FofoForm existingFofo = gson.fromJson(cursor.next().toString(), FofoForm.class);
86
				FofoForm existingFofo = gson.fromJson(cursor.next().toString(), FofoForm.class);
82
			id = existingFofo.get_id() + 1;
87
				id = existingFofo.get_id() + 1;
-
 
88
			}
-
 
89
			ff.set_id(id);
83
		}
90
		}
84
		ff.set_id(id);
-
 
85
		Gson gs = new Gson();
91
		Gson gs = new Gson();
86
		DBObject dbObject = (DBObject) JSON.parse(gs.toJson(ff));
92
		DBObject dbObject = (DBObject) JSON.parse(gs.toJson(ff));
87
		collection.insert(dbObject);
93
		collection.save(dbObject);
88
	}
94
	}
89
	
95
	
90
	public static List<FofoForm> getFofoForms(int offset, int limit) {
96
	public static List<FofoForm> getFofoForms(int offset, int limit) {
91
		List<FofoForm> ffList = new ArrayList<FofoForm>(); 
97
		List<FofoForm> ffList = new ArrayList<FofoForm>(); 
92
		DB db = mongo.getDB(FOFO_DB);
98
		DB db = mongo.getDB(FOFO_DB);