@@ -113,17 +113,18 @@ public boolean doSubscriptionExist(String subscriptionName) {
113
113
public boolean modifySubscription (Subscription subscription , String subscriptionName ) {
114
114
ObjectMapper mapper = new ObjectMapper ();
115
115
Document result = null ;
116
+ String query ;
116
117
try {
117
118
String stringSubscription = mapper .writeValueAsString (subscription );
118
- String ldapUserName = ( ldapEnabled ) ? HttpSessionConfig . getCurrentUser () : "" ;
119
- String query = generateQuery (subscriptionName , ldapUserName );
119
+ String ldapUserName = getLdapUserName ( subscriptionName ) ;
120
+ query = generateQuery (subscriptionName , ldapUserName );
120
121
result = subscriptionRepository .modifySubscription (query , stringSubscription );
121
122
if (result != null ) {
122
123
String subscriptionIdQuery = String .format (SUBSCRIPTION_ID , subscriptionName );
123
124
if (!cleanSubscriptionRepeatFlagHandlerDb (subscriptionIdQuery )) {
124
125
LOG .info ("Subscription \" " + subscriptionName
125
126
+ "\" matched aggregated objects id from repeat flag handler database could not be cleaned during the update of the subscription,\n "
126
- + "probably due to subscription has never matched any aggregated objects and "
127
+ + "probably due to subscription has never matched any aggregated objects and "
127
128
+ "no matched aggregated objects id has been stored in database for the specific subscription." );
128
129
}
129
130
}
@@ -137,21 +138,19 @@ public boolean modifySubscription(Subscription subscription, String subscription
137
138
138
139
@ Override
139
140
public boolean deleteSubscription (String subscriptionName ) throws AccessException {
140
- String ldapUserName = ( ldapEnabled ) ? HttpSessionConfig . getCurrentUser () : "" ;
141
+ String ldapUserName = getLdapUserName ( subscriptionName ) ;
141
142
String deleteQuery = generateQuery (subscriptionName , ldapUserName );
142
-
143
143
boolean deleteResult = subscriptionRepository .deleteSubscription (deleteQuery );
144
144
if (deleteResult ) {
145
145
String subscriptionIdQuery = String .format (SUBSCRIPTION_ID , subscriptionName );
146
146
if (!cleanSubscriptionRepeatFlagHandlerDb (subscriptionIdQuery )) {
147
147
LOG .info ("Subscription \" " + subscriptionName
148
148
+ "\" matched aggregated objects id from repeat flag handler database could not be cleaned during the removal of subscription,\n "
149
- + "probably due to subscription has never matched any aggregated objects and "
149
+ + "probably due to subscription has never matched any aggregated objects and "
150
150
+ "no matched aggregated objects id has been stored in database for the specific subscription." );
151
151
}
152
152
} else if (doSubscriptionExist (subscriptionName )) {
153
- String message = "Failed to delete subscription \" " + subscriptionName
154
- + "\" invalid ldapUserName" ;
153
+ String message = "Failed to delete subscription \" " + subscriptionName + "\" invalid ldapUserName" ;
155
154
throw new AccessException (message );
156
155
}
157
156
@@ -197,14 +196,50 @@ private boolean cleanSubscriptionRepeatFlagHandlerDb(String subscriptionNameQuer
197
196
* name of the current user
198
197
* @return a String object
199
198
*/
200
-
201
199
private String generateQuery (String subscriptionName , String ldapUserName ) {
202
200
String query = String .format (SUBSCRIPTION_NAME , subscriptionName );
203
- if (!ldapUserName .isEmpty ()) {
201
+ if (ldapUserName != null && !ldapUserName .isEmpty ()) {
204
202
String queryUser = String .format (USER_NAME , ldapUserName );
205
203
String queryTemp = query + "," + queryUser ;
206
204
query = String .format (AND , queryTemp );
207
205
}
208
206
return query ;
209
207
}
208
+
209
+ /**
210
+ * This method finds whether a given subscription has an owner
211
+ *
212
+ * @param subscriptionName-
213
+ * subscription name
214
+ * @return a boolean
215
+ * @throws SubscriptionNotFoundException
216
+ */
217
+ private boolean doSubscriptionOwnerExist (String subscriptionName ) {
218
+ boolean ownerExist = false ;
219
+ try {
220
+ if (!getSubscription (subscriptionName ).getLdapUserName ().isEmpty ()) {
221
+ ownerExist = true ;
222
+ }
223
+ } catch (SubscriptionNotFoundException e ) {
224
+ LOG .error (e .getMessage ());
225
+ }
226
+ return ownerExist ;
227
+ }
228
+
229
+ /**
230
+ * This method ldapUserName, if exists, otherwise return empty string
231
+ *
232
+ * @param subscriptionName-
233
+ * subscription name
234
+ * @return a string
235
+ */
236
+ private String getLdapUserName (String subscriptionName ) {
237
+ String ldapUserName = (ldapEnabled ) ? HttpSessionConfig .getCurrentUser () : "" ;
238
+ boolean ownerExist = doSubscriptionOwnerExist (subscriptionName );
239
+ if (!ownerExist ) {
240
+ ldapUserName = "" ;
241
+ }
242
+
243
+ return ldapUserName ;
244
+ }
210
245
}
0 commit comments