check whether the subscriber exist before creating

4.x.x
ayyoob 9 years ago
parent afe965e787
commit 9d4defaa01

@ -77,7 +77,18 @@
<artifactId>commons-httpclient</artifactId> <artifactId>commons-httpclient</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.base</artifactId>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple.wso2</groupId>
<artifactId>json-simple</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.user.api</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.wso2.carbon</groupId> <groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.utils</artifactId> <artifactId>org.wso2.carbon.utils</artifactId>

@ -286,14 +286,18 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe
try { try {
APIConsumer consumer = APIManagerFactory.getInstance().getAPIConsumer(subscriberName); APIConsumer consumer = APIManagerFactory.getInstance().getAPIConsumer(subscriberName);
if (consumer != null) { if (consumer != null) {
Subscriber subscriber = new Subscriber(subscriberName); synchronized (consumer) {
subscriber.setSubscribedDate(new Date()); if (consumer.getSubscriber(subscriberName) == null) {
subscriber.setEmail(subscriberEmail); Subscriber subscriber = new Subscriber(subscriberName);
subscriber.setTenantId(tenantId); subscriber.setSubscribedDate(new Date());
consumer.addSubscriber(subscriber, groupId); subscriber.setEmail(subscriberEmail);
if (log.isDebugEnabled()) { subscriber.setTenantId(tenantId);
log.debug("Successfully created subscriber with name : " + subscriberName + " with groupID : " + consumer.addSubscriber(subscriber, groupId);
groupId); if (log.isDebugEnabled()) {
log.debug("Successfully created subscriber with name : " + subscriberName +
" with groupID : " + groupId);
}
}
} }
} else { } else {
throw new APIManagerException("API provider configured for the given API configuration is null. " + throw new APIManagerException("API provider configured for the given API configuration is null. " +

Loading…
Cancel
Save