Subversion Repositories SmartDukaan

Rev

Rev 21850 | Rev 21974 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 21850 Rev 21920
Line 1... Line 1...
1
package in.shop2020.dtrapi.Storage;
1
package in.shop2020.dtrapi.Storage;
2
 
2
 
3
 
3
 
4
import in.shop2020.dtrapi.models.FofoForm;
-
 
5
import in.shop2020.dtrapi.models.MasterData;
-
 
6
 
-
 
7
import java.awt.List;
4
import java.lang.reflect.Type;
8
import java.net.UnknownHostException;
5
import java.net.UnknownHostException;
-
 
6
import java.util.List;
9
import java.util.ArrayList;
7
import java.util.ArrayList;
10
 
8
 
11
import com.google.gson.Gson;
9
import com.google.gson.Gson;
-
 
10
import com.google.gson.reflect.TypeToken;
12
import com.mongodb.BasicDBObject;
11
import com.mongodb.BasicDBObject;
13
import com.mongodb.DB;
12
import com.mongodb.DB;
14
import com.mongodb.DBCollection;
13
import com.mongodb.DBCollection;
15
import com.mongodb.DBCursor;
14
import com.mongodb.DBCursor;
16
import com.mongodb.DBObject;
15
import com.mongodb.DBObject;
17
import com.mongodb.MongoClient;
16
import com.mongodb.MongoClient;
18
import com.mongodb.util.JSON;
17
import com.mongodb.util.JSON;
19
 
18
 
-
 
19
import in.shop2020.dtrapi.models.FofoForm;
-
 
20
import in.shop2020.dtrapi.models.MasterData;
-
 
21
 
20
 
22
 
21
public class Mongo {
23
public class Mongo {
22
 
24
 
23
	private static MongoClient mongo;
25
	private static MongoClient mongo;
24
	private static final String CATALOG_DB = "Catalog";
26
	private static final String CATALOG_DB = "Catalog";
Line 81... Line 83...
81
		}
83
		}
82
		ff.set_id(id);
84
		ff.set_id(id);
83
		Gson gs = new Gson();
85
		Gson gs = new Gson();
84
		DBObject dbObject = (DBObject) JSON.parse(gs.toJson(ff));
86
		DBObject dbObject = (DBObject) JSON.parse(gs.toJson(ff));
85
		collection.insert(dbObject);
87
		collection.insert(dbObject);
-
 
88
	}
-
 
89
	
-
 
90
	public static List<FofoForm> getFofoForms(int offset, int limit) {
-
 
91
		List<FofoForm> ffList = new ArrayList<FofoForm>(); 
-
 
92
		DB db = mongo.getDB(FOFO_DB);
-
 
93
		DBCollection collection = db.getCollection(FOFO_FORM_COLLECTION);
-
 
94
		BasicDBObject orderBy = new BasicDBObject();
-
 
95
		orderBy.put("_id", -1);
-
 
96
		DBCursor dbc = collection.find().sort(orderBy).limit(limit).skip(offset);
-
 
97
		while (dbc.hasNext()) {
-
 
98
			ffList.add(convertJSONToPojo(dbc.next().toString()));
-
 
99
		}
86
		//collection.find();
100
		return ffList;
-
 
101
	}
-
 
102
	
-
 
103
	public static FofoForm getFofoForm(int fofoId) {
-
 
104
		DB db = mongo.getDB(FOFO_DB);
-
 
105
		BasicDBObject filter = new BasicDBObject();
-
 
106
		filter.append("_id", fofoId);
-
 
107
		DBCollection collection = db.getCollection(FOFO_FORM_COLLECTION);
-
 
108
		DBObject fofoDbOject = collection.find(filter).one();
-
 
109
		System.out.println(fofoDbOject.toString());
-
 
110
		return new Gson().fromJson(fofoDbOject.toString(), FofoForm.class);
-
 
111
		//return convertJSONToPojo(fofoDbOject.toString());
-
 
112
	}
-
 
113
	
-
 
114
	private static FofoForm convertJSONToPojo(String json){
-
 
115
 
-
 
116
	    Type type = new TypeToken< FofoForm >(){}.getType();
-
 
117
 
-
 
118
	    return new Gson().fromJson(json, type);
-
 
119
 
87
	}
120
	}
88
 
121
 
89
	public static void main(String[] args) throws Exception{
122
	public static void main(String[] args) throws Exception{
90
		System.out.println(getItemsByBundleId(100000));
123
		System.out.println(getFofoForms(0, 10));
-
 
124
 
91
	}
125
	}
92
}
126
}
93
127