26
26
import java .util .ArrayList ;
27
27
import java .util .List ;
28
28
29
+ import org .bson .Document ;
29
30
import org .slf4j .Logger ;
30
31
import org .slf4j .LoggerFactory ;
31
32
import org .springframework .beans .factory .annotation .Autowired ;
@@ -95,7 +96,6 @@ public void addMatchedAggrObjToSubscriptionId(String subscriptionId, int require
95
96
96
97
if (!updateExistingMatchedSubscriptionWithAggrObjId (subscriptionId , requirementId , aggrObjId )) {
97
98
LOGGER .error ("Couldn't update SubscriptionMathced id." );
98
- } else {
99
99
LOGGER .debug (
100
100
"New Subscription AggrId has not matched, inserting new SubscriptionId and AggrObjId to matched list." );
101
101
BasicDBObject document = new BasicDBObject ();
@@ -120,25 +120,33 @@ public void addMatchedAggrObjToSubscriptionId(String subscriptionId, int require
120
120
private boolean updateExistingMatchedSubscriptionWithAggrObjId (String subscriptionId , int requirementId ,
121
121
String aggrObjId ) throws Exception {
122
122
String subscriptionQuery = "{\" subscriptionId\" : \" " + subscriptionId + "\" }" ;
123
-
124
123
JsonNode updateDocJsonNode = mapper .readValue (
125
124
"{\" $push\" : { \" requirements." + requirementId + "\" : \" " + aggrObjId + "\" }}" , JsonNode .class );
126
-
127
- LOGGER .debug ("SubscriptionId \" " , subscriptionId ,
125
+ LOGGER .debug ("SubscriptionId \" " , subscriptionId +
128
126
"\" document will be updated with following requirement update object: "
129
127
+ updateDocJsonNode .toString ());
130
128
131
129
JsonNode queryJsonNode = mapper .readValue (subscriptionQuery , JsonNode .class );
130
+
131
+ Document document = null ;
132
132
try {
133
- mongoDbHandler .findAndModify (dataBaseName , collectionName , queryJsonNode .toString (),
133
+ document = mongoDbHandler .findAndModify (dataBaseName , collectionName , queryJsonNode .toString (),
134
134
updateDocJsonNode .toString ());
135
135
} catch (Exception e ) {
136
136
LOGGER .debug ("Failed to update existing matched SubscriptionId with new AggrId." + "SubscriptionId: "
137
137
+ subscriptionId + "New matched AggrObjId: " + aggrObjId + "RequirementId that have matched: "
138
138
+ requirementId );
139
139
return false ;
140
140
}
141
- return true ;
141
+ if (document != null && !document .isEmpty ()) {
142
+ LOGGER .debug ("Successfully updated Matched Subscription Aggregated Object list:" +
143
+ "\n for subsruptionId: " + subscriptionId +
144
+ "\n with Aggregated Object Id: " + aggrObjId +
145
+ "\n with matched Requirement Id: " + requirementId );
146
+
147
+ return true ;
148
+ }
149
+ return false ;
142
150
}
143
151
144
152
public boolean checkIfAggrObjIdExistInSubscriptionAggrIdsMatchedList (String subscriptionId , int requirementId ,
@@ -153,18 +161,18 @@ public boolean checkIfAggrObjIdExistInSubscriptionAggrIdsMatchedList(String subs
153
161
try {
154
162
JsonNode jNode = mapper .readTree (objArray .get (0 ));
155
163
if (jNode .get ("subscriptionId" ).asText ().trim ().equals (subscriptionId )) {
156
- LOGGER .debug ("SubscriptionId \" " , subscriptionId ,
164
+ LOGGER .debug ("SubscriptionId \" " + subscriptionId +
157
165
"\" , exist in document. Checking if AggrObjId has matched earlier." );
158
166
159
167
LOGGER .debug ("Subscription requirementId: " + requirementId + " and Requirements content:\n "
160
168
+ jNode .get ("requirements" ).get (new Integer (requirementId ).toString ()));
161
169
162
170
boolean triggered = checkRequirementIdTriggered (jNode , requirementId , aggrObjId );
163
171
164
- if (!triggered )
172
+ if (!triggered ) {
165
173
LOGGER .debug ("RequirementId: " + requirementId + " and SubscriptionId: " + subscriptionId
166
174
+ "\n has not matched any AggregatedObject." );
167
-
175
+ }
168
176
return triggered ;
169
177
}
170
178
} catch (Exception e ) {
@@ -189,8 +197,7 @@ private boolean checkRequirementIdTriggered(JsonNode jNode, int requirementId, S
189
197
return false ;
190
198
}
191
199
192
- String idStr = listAggrObjIds .get (requirementId );
193
- if (idStr .equals (aggrObjId )) {
200
+ if (listAggrObjIds .contains (aggrObjId )) {
194
201
LOGGER .debug ("Subscription has matched aggrObjId already: " + aggrObjId );
195
202
return true ;
196
203
}
0 commit comments