There is a security vulnerability in SSH key-generation using GitKraken < v8.0.1. If you used this tool to create SSH keys, please update GitKraken and regenerate. If you need help with this, contact forum-support@opengroup.org

Commit 61f8cf8e authored by Paromita Mitra's avatar Paromita Mitra
Browse files

get subscriptions by topic

parent 1379fb3e
Pipeline #67618 failed with stages
in 1 minute and 42 seconds
......@@ -31,7 +31,7 @@
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-core-lib-ibm</artifactId>
<version>0.9.0</version>
<version>0.12.0-SNAPSHOT</version>
</dependency>
<dependency>
......
......@@ -25,6 +25,7 @@ import org.springframework.stereotype.Repository;
import com.cloudant.client.api.Database;
import com.cloudant.client.api.query.QueryBuilder;
import com.cloudant.client.api.query.QueryResult;
import com.cloudant.client.api.query.Sort;
import com.cloudant.client.org.lightcouch.DocumentConflictException;
import com.cloudant.client.org.lightcouch.NoDocumentException;
......@@ -196,4 +197,20 @@ public class DatastoreAccess implements IDatastoreAccess {
doc.getNotificationId(), secret);
}
@Override
public List<Subscription> getByTopic(String topic) {
Database db = dataStoreTenants.get(getDbNameWithTenant());
List<Subscription> subscriptions = new ArrayList<Subscription>();
QueryResult<SubscriptionDoc> results = db.query(new QueryBuilder(
eq("topic", topic)).
build(), SubscriptionDoc.class);
if (results == null || results.getDocs().isEmpty()) {
throw new AppException(404, "Not Found",
format("Sunscription not found for topic %s ", topic));
}
subscriptions = results.getDocs().stream().map(i -> convertToSubscription(i)).collect(Collectors.toList());
return subscriptions;
}
}
......@@ -13,6 +13,8 @@ public interface IDatastoreAccess {
Subscription create(Subscription s);
Subscription get(String id);
List<Subscription> getByTopic(String topic);
List<Subscription> query(String notificationId);
......
......@@ -45,6 +45,11 @@ public class SubscriptionRepository implements ISubscriptionRepository {
public boolean delete(String id) {
return datastoreAccess.delete(id);
}
@Override
public List<Subscription> getByTopic(String topic) {
return datastoreAccess.getByTopic(topic);
}
@Override
public boolean patch(Subscription subscription, Secret secret) {
......
......@@ -16,6 +16,7 @@
package org.opengroup.osdu.register.api;
import java.util.ArrayList;
import java.util.Collections;
import org.opengroup.osdu.core.common.model.notification.Topic;
import org.opengroup.osdu.register.api.dto.SubscriptionInfo;
......@@ -115,4 +116,16 @@ public class SubscriberApi {
public ResponseEntity<List<Topic>> listMessages() {
return new ResponseEntity<>(topics.list(), HttpStatus.OK);
}
@GetMapping("subscription/topic/{topic}")
@PreAuthorize("@authorizationFilter.hasAnyPermission('" + ServiceRole.OPS + "', '" + ServiceRole.ADMIN + "', '" + ServiceRole.EDITOR + "')")
public ResponseEntity<List<SubscriptionInfo>> getSubscriptionsByTopic(@PathVariable("topic") @NotBlank String topic) {
List<Subscription> subscriptions = subscriptionRepository.get().getByTopic(topic);
List<SubscriptionInfo> subsInfoList = new ArrayList<SubscriptionInfo>();
for(Subscription subs: subscriptions) {
subsInfoList.add(new SubscriptionInfo(subs));
}
return new ResponseEntity<>(subsInfoList, HttpStatus.OK);
}
}
......@@ -25,6 +25,8 @@ public interface ISubscriptionRepository {
Subscription create(Subscription s) throws Exception;
Subscription get(String id);
List<Subscription> getByTopic(String topic);
List<Subscription> query(String notificationId);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment