Skip to content

Commit dbe82f0

Browse files
User can perform CRUD on anonymous subscriptions (#261)
* user can CRUD anonymous subscriptions * added ldapUserName field in CLM * adding ldapUserName property in two test subscriptions
1 parent fb6ef72 commit dbe82f0

File tree

4 files changed

+51
-13
lines changed

4 files changed

+51
-13
lines changed

src/functionaltests/resources/subscriptionRepeatHandlerOneMatch.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@
2121
}
2222
],
2323
"subscriptionName": "Subscription_Test",
24-
"userName": "ABC"
24+
"userName": "ABC",
25+
"ldapUserName":""
2526
}

src/functionaltests/resources/subscriptionRepeatHandlerTwoMatch.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@
2929
}
3030
],
3131
"subscriptionName": "Subscription_Test",
32-
"userName": "ABC"
32+
"userName": "ABC",
33+
"ldapUserName":""
3334
}

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

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,18 @@ public boolean doSubscriptionExist(String subscriptionName) {
113113
public boolean modifySubscription(Subscription subscription, String subscriptionName) {
114114
ObjectMapper mapper = new ObjectMapper();
115115
Document result = null;
116+
String query;
116117
try {
117118
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);
120121
result = subscriptionRepository.modifySubscription(query, stringSubscription);
121122
if (result != null) {
122123
String subscriptionIdQuery = String.format(SUBSCRIPTION_ID, subscriptionName);
123124
if (!cleanSubscriptionRepeatFlagHandlerDb(subscriptionIdQuery)) {
124125
LOG.info("Subscription \"" + subscriptionName
125126
+ "\" 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 "
127128
+ "no matched aggregated objects id has been stored in database for the specific subscription.");
128129
}
129130
}
@@ -137,21 +138,19 @@ public boolean modifySubscription(Subscription subscription, String subscription
137138

138139
@Override
139140
public boolean deleteSubscription(String subscriptionName) throws AccessException {
140-
String ldapUserName = (ldapEnabled) ? HttpSessionConfig.getCurrentUser() : "";
141+
String ldapUserName = getLdapUserName(subscriptionName);
141142
String deleteQuery = generateQuery(subscriptionName, ldapUserName);
142-
143143
boolean deleteResult = subscriptionRepository.deleteSubscription(deleteQuery);
144144
if (deleteResult) {
145145
String subscriptionIdQuery = String.format(SUBSCRIPTION_ID, subscriptionName);
146146
if (!cleanSubscriptionRepeatFlagHandlerDb(subscriptionIdQuery)) {
147147
LOG.info("Subscription \"" + subscriptionName
148148
+ "\" 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 "
150150
+ "no matched aggregated objects id has been stored in database for the specific subscription.");
151151
}
152152
} 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";
155154
throw new AccessException(message);
156155
}
157156

@@ -197,14 +196,50 @@ private boolean cleanSubscriptionRepeatFlagHandlerDb(String subscriptionNameQuer
197196
* name of the current user
198197
* @return a String object
199198
*/
200-
201199
private String generateQuery(String subscriptionName, String ldapUserName) {
202200
String query = String.format(SUBSCRIPTION_NAME, subscriptionName);
203-
if (!ldapUserName.isEmpty()) {
201+
if (ldapUserName != null && !ldapUserName.isEmpty()) {
204202
String queryUser = String.format(USER_NAME, ldapUserName);
205203
String queryTemp = query + "," + queryUser;
206204
query = String.format(AND, queryTemp);
207205
}
208206
return query;
209207
}
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+
}
210245
}

src/test/resources/subscription_CLME.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
}
2626
],
2727
"subscriptionName" : "Single_CLME_Subscription_Test",
28-
"userName" : "ABC"
28+
"userName" : "ABC",
29+
"ldapUserName": ""
2930
}
3031
]

0 commit comments

Comments
 (0)