Commit fa961b53 authored by Komal Makkar's avatar Komal Makkar
Browse files

intermediate changes

parent 7d934f7a
Pipeline #30606 failed with stages
in 2 minutes and 5 seconds
......@@ -30,7 +30,7 @@
<version>0.6.0-SNAPSHOT</version>
<properties>
<osdu.register-core.version>0.6.0-SNAPSHOT</osdu.register-core.version>
<osdu.corelibazure.version>0.0.60</osdu.corelibazure.version>
<osdu.corelibazure.version>0.6.1</osdu.corelibazure.version>
<junit-jupiter.version>5.6.0</junit-jupiter.version>
<mockito-junit-jupiter.version>2.23.0</mockito-junit-jupiter.version>
</properties>
......
......@@ -25,6 +25,7 @@ import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.register.provider.azure.di.AzureBootstrapConfig;
import org.opengroup.osdu.register.provider.azure.di.CosmosContainerConfig;
import org.opengroup.osdu.register.provider.azure.util.CryptographyUtil;
import org.opengroup.osdu.register.provider.azure.util.PartitionHelper;
import org.opengroup.osdu.register.provider.azure.util.TopicsHelper;
import org.opengroup.osdu.register.provider.interfaces.subscriber.ISubscriptionRepository;
import org.opengroup.osdu.register.subscriber.model.GsaSecret;
......@@ -61,8 +62,11 @@ public class SubscriptionRepository implements ISubscriptionRepository {
@Autowired
private CryptographyUtil cryptographyUtil;
/*@Autowired
private TopicsHelper topicsHelper;*/
@Autowired
private TopicsHelper topicsHelper;
private PartitionHelper partitionHelper;
@Autowired
private PushSubscription pushSubscription;
......@@ -97,7 +101,7 @@ public class SubscriptionRepository implements ISubscriptionRepository {
@Override
public Subscription create(Subscription input) {
SubscriptionDoc doc = new SubscriptionDoc(input, dpsHeaders.getPartitionId());
doc.setTopic(topicsHelper.nameResolver(input.getTopic()));
doc.setTopic(partitionHelper.getFullyQualifiedTopicName(input.getTopic()));
doc.setSecretValue(cryptographyUtil.encryptData(input.getSecret().toString()));
doc.setKeyName(cryptographyUtil.getKeyName());
doc.setKeyVersion(cryptographyUtil.getKeyVersion());
......@@ -309,7 +313,9 @@ public class SubscriptionRepository implements ISubscriptionRepository {
hmacSecret.setValue(secretValue);
secret = hmacSecret;
}
return new Subscription(doc.getId(), doc.getName(),doc.getDescription(), topicsHelper.extractDisplayName(doc.getTopic()), doc.getPushEndpoint(),
/*return new Subscription(doc.getId(), doc.getName(),doc.getDescription(), topicsHelper.extractDisplayName(doc.getTopic()), doc.getPushEndpoint(),
doc.getCreatedBy(), doc.getCreatedOnEpoch(), doc.getNotificationId(), secret);*/
return new Subscription(doc.getId(), doc.getName(),doc.getDescription(), partitionHelper.getFullyQualifiedTopicName(doc.getTopic()), doc.getPushEndpoint(),
doc.getCreatedBy(), doc.getCreatedOnEpoch(), doc.getNotificationId(), secret);
}
}
......@@ -29,7 +29,8 @@ public class TopicsRepositoryImpl implements ITopicsRepository {
private final JaxRsDpsLog log;
private final DpsHeaders headers;
private final PartitionHelper partitionHelper;
private final TopicsHelper topicsHelper;
//private final TopicsHelper topicsHelper;
private Map<String, String> fullyQualifiedNameToAliasMap = new HashMap<>();
private Map<String, List<Topic>> topicsMap = new HashMap<>();
......@@ -39,28 +40,29 @@ public class TopicsRepositoryImpl implements ITopicsRepository {
return topicsMap.get(partitionId);
}
final Topic template = getTopicTemplate();
List<Topic> collect = partitionHelper.retrieveTopicNames().stream()
final List<Topic> template = getTopicTemplate();
/*List<Topic> collect = partitionHelper.retrieveTopicNames().stream()
.map(topicsHelper::extractDisplayName)
.map(s -> createTopic(template, s))
.collect(Collectors.toList());
.map(s -> createTopic(template.stream(), s))
.collect(Collectors.toList());*/
topicsMap.put(partitionId, collect);
return collect;
topicsMap.put(partitionId, template);
return template;
}
private Topic getTopicTemplate() {
Type type = new TypeToken<ArrayList<Topic>>() {}.getType();
List<Topic> templates = new Gson().fromJson(FileUtil.readFile("topics.json", log), type);
return templates.get(0);
public String getTopicAliasFromFullyQualifiedTopicName(String fullyQualifiedTopicName) {
List<Topic> topicList = listMessages();
for (Topic topicIterator: topicList) {
fullyQualifiedNameToAliasMap.put(partitionHelper.getFullyQualifiedTopicName(topicIterator.getName()), topicIterator.getName());
}
return fullyQualifiedNameToAliasMap.get(fullyQualifiedTopicName);
}
private Topic createTopic(Topic template, String topicName) {
Topic topic = new Topic();
topic.setName(topicName);
topic.setDescription(template.getDescription());
topic.setExample(template.getExample());
topic.setState(template.getState());
return topic;
private List<Topic> getTopicTemplate() {
Type type = new TypeToken<ArrayList<Topic>>() {}.getType();
return new Gson().fromJson(FileUtil.readFile("topics.json", log), type);
}
}
......@@ -14,9 +14,12 @@
package org.opengroup.osdu.register.provider.azure.util;
import org.opengroup.osdu.azure.partition.EventGridTopicPartitionInfoAzure;
import org.opengroup.osdu.azure.partition.PartitionInfoAzure;
import org.opengroup.osdu.azure.partition.PartitionServiceClient;
import org.opengroup.osdu.azure.partition.PartitionServiceEventGridClient;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.partition.PartitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
......@@ -29,6 +32,8 @@ public class PartitionHelper {
@Autowired
private PartitionServiceClient partitionService;
@Autowired
private PartitionServiceEventGridClient partitionServiceEventGridClient;
@Autowired
private DpsHeaders headers;
public String retrieveResourceGroup() {
......@@ -42,6 +47,17 @@ public class PartitionHelper {
return Arrays.asList(topicName);
}
public String getFullyQualifiedTopicName(String topicNameAlias) {
EventGridTopicPartitionInfoAzure eventGridTopicPartitionInfoAzure = null;
try {
eventGridTopicPartitionInfoAzure = partitionServiceEventGridClient.getEventGridTopicInPartition(headers.getPartitionId(), topicNameAlias);
} catch (PartitionException e) {
}
return eventGridTopicPartitionInfoAzure.getTopicName().split("\\.")[0].replace("https://", "");
}
public String retrieveKeyIdentifier() {
PartitionInfoAzure partition = partitionService.getPartition(headers.getPartitionId());
return partition.getCryptographyEncryptionKeyIdentifier();
......
[
{
"name": "topic-name",
"name": "recordstopic",
"description": "This notification is sent whenever a new record or record version is created, updated or deleted, and when a new schema is created in storage.",
"state": "ACTIVE",
"example": [
......
/*
package org.opengroup.osdu.register.provider.azure.subscriber;
import org.junit.jupiter.api.BeforeEach;
......@@ -51,3 +52,4 @@ public class TopicsRepositoryImplTest {
}
}
*/
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