17
17
import java .util .Iterator ;
18
18
import java .util .List ;
19
19
20
- import javax .annotation .PostConstruct ;
21
-
22
20
import org .json .JSONArray ;
23
21
import org .json .JSONObject ;
24
22
import org .slf4j .Logger ;
32
30
import com .fasterxml .jackson .databind .ObjectMapper ;
33
31
34
32
/**
35
- * This class represents the mechanism to extract the aggregated data on the
36
- * basis of the ID from the aggregatedObject .
33
+ * This class represents the mechanism to extract the aggregated object, which
34
+ * matches the given search criteria, from the database .
37
35
*/
38
36
@ Component
39
37
public class ProcessAggregatedObject {
@@ -47,71 +45,72 @@ public class ProcessAggregatedObject {
47
45
private String aggregationDataBaseName ;
48
46
49
47
@ Autowired
50
- private MongoDBHandler handler ;
48
+ private MongoDBHandler mongoDBHandler ;
51
49
52
50
/**
53
- * The method is responsible to extract the aggregated data on the basis of the
54
- * ID from the aggregatedObject .
51
+ * The method is responsible to extract the aggregated data given the
52
+ * ID from the aggregated object .
55
53
*
56
54
* @param id
57
55
* @return ArrayList
58
56
*/
59
57
public ArrayList <String > processQueryAggregatedObject (String id ) {
60
58
ObjectMapper mapper = new ObjectMapper ();
61
59
String query = "{\" _id\" : \" " + id + "\" }" ;
62
-
63
- LOGGER .debug ("The condition is : " + query );
64
60
JsonNode jsonCondition = null ;
61
+
65
62
try {
66
63
jsonCondition = mapper .readTree (query );
67
64
} catch (Exception e ) {
68
65
LOGGER .error (e .getMessage (), e );
69
66
}
70
- LOGGER .debug ("The Json condition is : " + jsonCondition );
71
- ArrayList <String > response = handler .find (aggregationDataBaseName , aggregationCollectionName ,
67
+ LOGGER .debug ("The JSON condition is: {}" , jsonCondition );
68
+ ArrayList <String > response = mongoDBHandler .find (aggregationDataBaseName , aggregationCollectionName ,
72
69
jsonCondition .toString ());
73
70
return response ;
74
71
}
75
72
76
73
/**
77
- * The method is responsible to extract the aggregated data on the basis of the
78
- * ID from the aggregatedObject .
74
+ * The method is responsible to extract the aggregated data given the
75
+ * templateName from the aggregated object .
79
76
*
80
77
* @param templateName
81
78
* @return ArrayList
82
79
*/
83
80
public ArrayList <String > getAggregatedObjectByTemplateName (String templateName ) {
84
81
String condition = "{\" aggregatedObject.id\" : /.*" + templateName + "/}" ;
85
- LOGGER .debug ("The Json condition is : " + condition );
86
- return handler .find (aggregationDataBaseName , aggregationCollectionName , condition );
82
+ LOGGER .debug ("The JSON condition is: {}" , condition );
83
+ return mongoDBHandler .find (aggregationDataBaseName , aggregationCollectionName , condition );
87
84
}
88
85
89
86
/**
90
- * The method is responsible for the delete the aggregated object using template
91
- * name suffix
87
+ * This method is responsible for deleting the aggregated object with given
88
+ * template name suffix
92
89
*
93
90
* @param templateName
94
91
* @return boolean
95
92
*/
96
93
public boolean deleteAggregatedObject (String templateName ) {
97
94
String condition = "{\" aggregatedObject.id\" : /.*" + templateName + "/}" ;
98
- LOGGER .debug ("The Json condition for delete aggregated object is : " + condition );
99
- return handler .dropDocument (aggregationDataBaseName , aggregationCollectionName , condition );
95
+ LOGGER .debug ("The JSON condition for deleting aggregated object is: {}" , condition );
96
+ return mongoDBHandler .dropDocument (aggregationDataBaseName , aggregationCollectionName , condition );
100
97
}
101
98
102
99
/**
103
- * This method is responsible for fetching all the aggregatedObjects from the
104
- * Aggregation database and return it as JSONArray.
100
+ * This method is responsible for fetching all the aggregated objects from the
101
+ * aggregation database based on the given query and returns the result as a
102
+ * JSONArray.
105
103
*
106
- * @param request
104
+ * @param query
105
+ * A String containing search criteria to use
107
106
* @param AggregationDataBaseName
108
107
* @param AggregationCollectionName
109
108
* @return JSONArray
110
109
*/
111
- public JSONArray processQueryAggregatedObject (String request , String AggregationDataBaseName ,
110
+ public JSONArray processQueryAggregatedObject (String query , String AggregationDataBaseName ,
112
111
String AggregationCollectionName ) {
113
- List <String > allDocuments = handler .find (AggregationDataBaseName , AggregationCollectionName , request );
114
- LOGGER .debug ("Number of document returned from AggregatedObject collection is : " + allDocuments .size ());
112
+ List <String > allDocuments = mongoDBHandler .find (AggregationDataBaseName , AggregationCollectionName , query );
113
+ LOGGER .debug ("Number of documents returned from {} collection is : {}" , AggregationCollectionName , allDocuments .size ());
115
114
Iterator <String > allDocumentsItr = allDocuments .iterator ();
116
115
JSONArray jsonArray = new JSONArray ();
117
116
JSONObject doc = null ;
@@ -127,9 +126,4 @@ public JSONArray processQueryAggregatedObject(String request, String Aggregation
127
126
return jsonArray ;
128
127
}
129
128
130
- @ PostConstruct
131
- public void init () {
132
- LOGGER .debug ("The Aggregated Database is : " + aggregationDataBaseName + "\n The Aggregated Collection is : "
133
- + aggregationCollectionName );
134
- }
135
129
}
0 commit comments