Skip to content

Commit 6d1d5dd

Browse files
Remove duplicate logging (#466)
Add javadoc on some public methods Simplified complex methods
1 parent 1ca3cbf commit 6d1d5dd

File tree

2 files changed

+28
-23
lines changed

2 files changed

+28
-23
lines changed

src/main/java/com/ericsson/ei/services/ISubscriptionService.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public interface ISubscriptionService {
3131
*
3232
* @param subscription
3333
* @throws JsonProcessingException
34-
* @throws EncryptorException
3534
* @throws MongoWriteException
3635
*/
3736
void addSubscription(Subscription subscription) throws JsonProcessingException, MongoWriteException;

src/main/java/com/ericsson/ei/services/SubscriptionService.java

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,15 @@ public boolean doSubscriptionExist(String subscriptionName) {
121121
return !list.isEmpty();
122122
}
123123

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+
* */
124133
@Override
125134
public boolean modifySubscription(Subscription subscription, String subscriptionName) {
126135
ObjectMapper mapper = new ObjectMapper();
@@ -132,14 +141,7 @@ public boolean modifySubscription(Subscription subscription, String subscription
132141
query = generateQuery(subscriptionName, ldapUserName);
133142
result = subscriptionRepository.modifySubscription(query, stringSubscription);
134143
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);
143145
}
144146

145147
} catch (JSONException | JsonProcessingException e) {
@@ -149,20 +151,20 @@ public boolean modifySubscription(Subscription subscription, String subscription
149151
return true;
150152
}
151153

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+
* */
152161
@Override
153162
public boolean deleteSubscription(String subscriptionName) throws AccessException {
154163
String ldapUserName = getLdapUserName(subscriptionName);
155164
String deleteQuery = generateQuery(subscriptionName, ldapUserName);
156165
boolean deleteResult = subscriptionRepository.deleteSubscription(deleteQuery);
157166
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);
166168
} else if (doSubscriptionExist(subscriptionName)) {
167169
String message = "Failed to delete subscription \"" + subscriptionName
168170
+ "\" invalid ldapUserName";
@@ -172,6 +174,11 @@ public boolean deleteSubscription(String subscriptionName) throws AccessExceptio
172174
return deleteResult;
173175
}
174176

177+
/**
178+
* Retrieves all existing subscriptions from the database in a list.
179+
*
180+
* @throws SubscriptionNotFoundException if no subscriptions exists in the database
181+
* */
175182
@Override
176183
public List<Subscription> getSubscriptions() throws SubscriptionNotFoundException {
177184
String query = "{}";
@@ -215,13 +222,12 @@ private Subscription doEncryption(Subscription subscription) {
215222
return subscription;
216223
}
217224

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);
222229
MongoDBHandler mongoDbHandler = subscriptionRepository.getMongoDbHandler();
223-
return mongoDbHandler.dropDocument(dataBaseName, repeatFlagHandlerCollection,
224-
subscriptionNameQuery);
230+
mongoDbHandler.dropDocument(dataBaseName, repeatFlagHandlerCollection, subscriptionIdQuery);
225231
}
226232

227233
/**

0 commit comments

Comments
 (0)