@@ -121,6 +121,15 @@ public boolean doSubscriptionExist(String subscriptionName) {
121
121
return !list .isEmpty ();
122
122
}
123
123
124
+ /**
125
+ * Finds an existing subscription and replaces with a new updated subscription. If the update
126
+ * was successful, any previous matches on aggregations for the old subscription is cleaned from
127
+ * the database.
128
+ *
129
+ * @param subscription the updated subscription to save in the database
130
+ * @param subscriptionName the name of the existing subscription which will be updated
131
+ * @return boolean result of the update operation
132
+ * */
124
133
@ Override
125
134
public boolean modifySubscription (Subscription subscription , String subscriptionName ) {
126
135
ObjectMapper mapper = new ObjectMapper ();
@@ -132,14 +141,7 @@ public boolean modifySubscription(Subscription subscription, String subscription
132
141
query = generateQuery (subscriptionName , ldapUserName );
133
142
result = subscriptionRepository .modifySubscription (query , stringSubscription );
134
143
if (result != null ) {
135
- String subscriptionIdQuery = String .format (SUBSCRIPTION_ID , subscriptionName );
136
- if (!cleanSubscriptionRepeatFlagHandlerDb (subscriptionIdQuery )) {
137
- LOGGER .info ("Subscription \" {}"
138
- + "\" matched aggregated objects id from repeat flag handler database could not be cleaned during the update of the subscription,\n "
139
- + "probably due to subscription has never matched any aggregated objects and "
140
- + "no matched aggregated objects id has been stored in database for the specific subscription." ,
141
- subscriptionName );
142
- }
144
+ cleanSubscriptionRepeatFlagHandlerDb (subscriptionName );
143
145
}
144
146
145
147
} catch (JSONException | JsonProcessingException e ) {
@@ -149,20 +151,20 @@ public boolean modifySubscription(Subscription subscription, String subscription
149
151
return true ;
150
152
}
151
153
154
+ /**
155
+ * Removes a given subscription from the database. If the operation was successful, any previous
156
+ * matches on aggregations for the removed subscription is also cleaned from the database.
157
+ *
158
+ * @param subscriptionName the name of the subscription to delete
159
+ * @return boolean result of the delete operation
160
+ * */
152
161
@ Override
153
162
public boolean deleteSubscription (String subscriptionName ) throws AccessException {
154
163
String ldapUserName = getLdapUserName (subscriptionName );
155
164
String deleteQuery = generateQuery (subscriptionName , ldapUserName );
156
165
boolean deleteResult = subscriptionRepository .deleteSubscription (deleteQuery );
157
166
if (deleteResult ) {
158
- String subscriptionIdQuery = String .format (SUBSCRIPTION_ID , subscriptionName );
159
- if (!cleanSubscriptionRepeatFlagHandlerDb (subscriptionIdQuery )) {
160
- LOGGER .info ("Subscription \" {}"
161
- + "\" matched aggregated objects id from repeat flag handler database could not be cleaned during the removal of subscription,\n "
162
- + "probably due to subscription has never matched any aggregated objects and "
163
- + "no matched aggregated objects id has been stored in database for the specific subscription." ,
164
- subscriptionName );
165
- }
167
+ cleanSubscriptionRepeatFlagHandlerDb (subscriptionName );
166
168
} else if (doSubscriptionExist (subscriptionName )) {
167
169
String message = "Failed to delete subscription \" " + subscriptionName
168
170
+ "\" invalid ldapUserName" ;
@@ -172,6 +174,11 @@ public boolean deleteSubscription(String subscriptionName) throws AccessExceptio
172
174
return deleteResult ;
173
175
}
174
176
177
+ /**
178
+ * Retrieves all existing subscriptions from the database in a list.
179
+ *
180
+ * @throws SubscriptionNotFoundException if no subscriptions exists in the database
181
+ * */
175
182
@ Override
176
183
public List <Subscription > getSubscriptions () throws SubscriptionNotFoundException {
177
184
String query = "{}" ;
@@ -215,13 +222,12 @@ private Subscription doEncryption(Subscription subscription) {
215
222
return subscription ;
216
223
}
217
224
218
- private boolean cleanSubscriptionRepeatFlagHandlerDb (String subscriptionNameQuery ) {
219
- LOGGER .debug (
220
- "Cleaning and removing matched subscriptions AggrObjIds in ReapeatHandlerFlag database with query: {}" ,
221
- subscriptionNameQuery );
225
+ private void cleanSubscriptionRepeatFlagHandlerDb (String subscriptionName ) {
226
+ LOGGER .debug ("Cleaning up previously matched aggregations for subscription: {}." ,
227
+ subscriptionName );
228
+ String subscriptionIdQuery = String . format ( SUBSCRIPTION_ID , subscriptionName );
222
229
MongoDBHandler mongoDbHandler = subscriptionRepository .getMongoDbHandler ();
223
- return mongoDbHandler .dropDocument (dataBaseName , repeatFlagHandlerCollection ,
224
- subscriptionNameQuery );
230
+ mongoDbHandler .dropDocument (dataBaseName , repeatFlagHandlerCollection , subscriptionIdQuery );
225
231
}
226
232
227
233
/**
0 commit comments