Subversion Repositories SmartDukaan

Rev

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

Rev 22105 Rev 22125
Line 2... Line 2...
2
 
2
 
3
import java.lang.reflect.Type;
3
import java.lang.reflect.Type;
4
import java.net.UnknownHostException;
4
import java.net.UnknownHostException;
5
import java.util.ArrayList;
5
import java.util.ArrayList;
6
import java.util.List;
6
import java.util.List;
-
 
7
import java.util.Map;
7
 
8
 
8
import org.json.JSONObject;
9
import org.json.JSONObject;
9
 
10
 
10
import com.google.gson.Gson;
11
import com.google.gson.Gson;
11
import com.google.gson.reflect.TypeToken;
12
import com.google.gson.reflect.TypeToken;
Line 121... Line 122...
121
		DBCollection collection = db.getCollection(FOFO_FORM_COLLECTION);
122
		DBCollection collection = db.getCollection(FOFO_FORM_COLLECTION);
122
		DBObject fofoDbOject = collection.findOne(filter);
123
		DBObject fofoDbOject = collection.findOne(filter);
123
		return fofoDbOject.toString();
124
		return fofoDbOject.toString();
124
	}
125
	}
125
	
126
	
-
 
127
	public static String getFofoFormsJsonString(){
-
 
128
		DB db = mongo_dtr.getDB(FOFO_DB);
-
 
129
		DBCollection collection = db.getCollection(FOFO_FORM_COLLECTION);
-
 
130
		DBCursor cursor = collection.find();
-
 
131
		StringBuilder fofoFormsJsonString = new StringBuilder();
-
 
132
		fofoFormsJsonString.append("[");
-
 
133
		while(cursor.hasNext()){
-
 
134
			fofoFormsJsonString.append(cursor.next().toString());
-
 
135
			if(cursor.hasNext()){
-
 
136
				fofoFormsJsonString.append(",");
-
 
137
			}
-
 
138
		}
-
 
139
		fofoFormsJsonString.append("]");
-
 
140
		return fofoFormsJsonString.toString();
-
 
141
	}
-
 
142
	
126
	public static FofoForm getFofoForm(int fofoId) {
143
	public static FofoForm getFofoForm(int fofoId) {
127
		String fofoFormJsonString = getFofoFormJsonStringByFofoId(fofoId);
144
		String fofoFormJsonString = getFofoFormJsonStringByFofoId(fofoId);
128
		System.out.println(fofoFormJsonString);
145
		System.out.println(fofoFormJsonString);
129
		return new Gson().fromJson(fofoFormJsonString, FofoForm.class);
146
		return new Gson().fromJson(fofoFormJsonString, FofoForm.class);
130
		//return convertJSONToPojo(fofoDbOject.toString());
147
		//return convertJSONToPojo(fofoDbOject.toString());
Line 135... Line 152...
135
	    Type type = new TypeToken< FofoForm >(){}.getType();
152
	    Type type = new TypeToken< FofoForm >(){}.getType();
136
 
153
 
137
	    return new Gson().fromJson(json, type);
154
	    return new Gson().fromJson(json, type);
138
 
155
 
139
	}
156
	}
-
 
157
	
-
 
158
	public static void updateColumnsById(Map<String, Integer> map, int fofoId){
-
 
159
		DB db = mongo_dtr.getDB(FOFO_DB);
-
 
160
		BasicDBObject filter = new BasicDBObject();
-
 
161
		filter.append("_id", fofoId);
-
 
162
		DBCollection collection = db.getCollection(FOFO_FORM_COLLECTION);
-
 
163
		BasicDBObject updateFields = new BasicDBObject();
-
 
164
		for(Map.Entry<String, Integer> entry : map.entrySet()){
-
 
165
			updateFields.append(entry.getKey(), entry.getValue());
-
 
166
		}
-
 
167
		BasicDBObject newDocument = new BasicDBObject();
-
 
168
		newDocument.append("$set", updateFields);
-
 
169
		collection.update(filter, newDocument);
-
 
170
	}
140
 
171
 
141
}
172
}