Commit 4873419f authored by Aman Verma's avatar Aman Verma
Browse files

Merge branch 'users/amaverma/implementInterfacesForAzure' into users/amaverma/updateOtherCSPs

parents c366974e 7400dad6
Pipeline #62298 failed with stages
in 2 minutes and 42 seconds
......@@ -18,20 +18,6 @@ The following software have components provided under the terms of this license:
- AMQP 1.0 JMS Spring Boot Starter (from https://repo1.maven.org/maven2/org/amqphub/spring/amqp-10-jms-spring-boot-starter)
- ASM based accessors helper used by json-smart (from )
- ASM based accessors helper used by json-smart (from )
- AWS Event Stream (from https://github.com/awslabs/aws-eventstream-java)
- AWS Java SDK :: AWS Core (from https://aws.amazon.com/sdkforjava)
- AWS Java SDK :: Annotations (from https://repo1.maven.org/maven2/software/amazon/awssdk/annotations)
- AWS Java SDK :: Auth (from https://aws.amazon.com/sdkforjava)
- AWS Java SDK :: Core :: Protocols :: AWS Json Protocol (from https://aws.amazon.com/sdkforjava)
- AWS Java SDK :: Core :: Protocols :: Protocol Core (from https://aws.amazon.com/sdkforjava)
- AWS Java SDK :: HTTP Client Interface (from https://repo1.maven.org/maven2/software/amazon/awssdk/http-client-spi)
- AWS Java SDK :: HTTP Clients :: Apache (from https://repo1.maven.org/maven2/software/amazon/awssdk/apache-client)
- AWS Java SDK :: HTTP Clients :: Netty Non-Blocking I/O (from https://repo1.maven.org/maven2/software/amazon/awssdk/netty-nio-client)
- AWS Java SDK :: Profiles (from https://aws.amazon.com/sdkforjava)
- AWS Java SDK :: Regions (from https://repo1.maven.org/maven2/software/amazon/awssdk/regions)
- AWS Java SDK :: SDK Core (from https://aws.amazon.com/sdkforjava)
- AWS Java SDK :: Services :: AWS Simple Systems Management (SSM) (from https://aws.amazon.com/sdkforjava)
- AWS Java SDK :: Utilities (from https://repo1.maven.org/maven2/software/amazon/awssdk/utils)
- AWS Java SDK for AWS Amplify (from https://aws.amazon.com/sdkforjava)
- AWS Java SDK for AWS App Mesh (from https://aws.amazon.com/sdkforjava)
- AWS Java SDK for AWS AppSync (from https://aws.amazon.com/sdkforjava)
......@@ -327,7 +313,7 @@ The following software have components provided under the terms of this license:
- FindBugs-jsr305 (from http://findbugs.sourceforge.net/)
- Google APIs Client Library for Java (from https://repo1.maven.org/maven2/com/google/api-client/google-api-client)
- Google App Engine extensions to the Google HTTP Client Library for Java. (from https://repo1.maven.org/maven2/com/google/http-client/google-http-client-appengine)
- Google Cloud Core (from https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core)
- Google Cloud Core (from https://github.com/googleapis/java-core)
- Google Cloud Core HTTP (from https://github.com/googleapis/java-core)
- Google Cloud Core gRPC (from https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc)
- Google Cloud Datastore (from https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-datastore)
......@@ -364,19 +350,20 @@ The following software have components provided under the terms of this license:
- JSON Web Token support for the JVM (from https://repo1.maven.org/maven2/io/jsonwebtoken/jjwt)
- JSON library from Android SDK (from http://developer.android.com/sdk)
- JSONassert (from https://github.com/skyscreamer/JSONassert)
- JSR107 API and SPI (from https://github.com/jsr107/jsr107spec)
- Jackson 2 extensions to the Google HTTP Client Library for Java. (from https://repo1.maven.org/maven2/com/google/http-client/google-http-client-jackson2)
- Jackson dataformat: CBOR (from http://github.com/FasterXML/jackson-dataformats-binary)
- Jackson dataformat: CBOR (from http://github.com/FasterXML/jackson-dataformats-binary)
- Jackson datatype: JSR310 (from https://repo1.maven.org/maven2/com/fasterxml/jackson/datatype/jackson-datatype-jsr310)
- Jackson datatype: JSR310 (from http://wiki.fasterxml.com/JacksonModuleJSR310)
- Jackson datatype: Joda (from https://github.com/FasterXML/jackson-datatype-joda)
- Jackson datatype: jdk8 (from https://repo1.maven.org/maven2/com/fasterxml/jackson/datatype/jackson-datatype-jdk8)
- Jackson module: JAXB Annotations (from https://github.com/FasterXML/jackson-modules-base)
- Jackson module: Afterburner (from https://github.com/FasterXML/jackson-modules-base)
- Jackson module: Old JAXB Annotations (javax.xml.bind) (from https://github.com/FasterXML/jackson-modules-base)
- Jackson-annotations (from http://github.com/FasterXML/jackson)
- Jackson-core (from https://github.com/FasterXML/jackson-core)
- Jackson-dataformat-Smile (from http://wiki.fasterxml.com/JacksonForSmile)
- Jackson-dataformat-XML (from https://github.com/FasterXML/jackson-dataformat-xml)
- Jackson-dataformat-YAML (from https://github.com/FasterXML/jackson-dataformats-text)
- Jackson-module-Afterburner (from http://wiki.fasterxml.com/JacksonHome)
- Jackson-module-parameter-names (from https://repo1.maven.org/maven2/com/fasterxml/jackson/module/jackson-module-parameter-names)
- Jakarta Bean Validation API (from https://beanvalidation.org)
- Jakarta Expression Language Implementation (from https://projects.eclipse.org/projects/ee4j.el)
......@@ -424,8 +411,6 @@ The following software have components provided under the terms of this license:
- Microsoft Azure Netty HTTP Client Library (from https://github.com/Azure/azure-sdk-for-java)
- Microsoft Azure SDK for SQL API of Azure Cosmos DB Service (from https://github.com/Azure/azure-sdk-for-java)
- Mockito (from http://www.mockito.org)
- Netty Reactive Streams HTTP support (from https://repo1.maven.org/maven2/com/typesafe/netty/netty-reactive-streams-http)
- Netty Reactive Streams Implementation (from https://repo1.maven.org/maven2/com/typesafe/netty/netty-reactive-streams)
- Netty/Buffer (from https://repo1.maven.org/maven2/io/netty/netty-buffer)
- Netty/Codec (from https://repo1.maven.org/maven2/io/netty/netty-codec)
- Netty/Codec/DNS (from https://repo1.maven.org/maven2/io/netty/netty-codec-dns)
......@@ -495,6 +480,8 @@ The following software have components provided under the terms of this license:
- Spring WebFlux (from https://github.com/spring-projects/spring-framework)
- T-Digest (from https://github.com/tdunning/t-digest)
- TypeTools (from http://github.com/jhalterman/typetools/)
- Vavr (from http://vavr.io)
- Vavr Match (from http://vavr.io)
- Woodstox (from https://github.com/FasterXML/woodstox)
- Zipkin Core Library (from https://repo1.maven.org/maven2/io/zipkin/zipkin2/zipkin)
- Zipkin Reporter Brave (from https://repo1.maven.org/maven2/io/zipkin/reporter2/zipkin-reporter-brave)
......@@ -503,17 +490,14 @@ The following software have components provided under the terms of this license:
- aggs-matrix-stats (from https://github.com/elastic/elasticsearch)
- asm (from http://asm.ow2.io/)
- asm (from http://asm.ow2.io/)
- aws-ssm-java-caching-client (from https://github.com/awslabs/aws-ssm-java-caching-client)
- boto3 (from https://github.com/boto/boto3)
- botocore (from https://github.com/boto/botocore)
- cli (from https://github.com/elastic/elasticsearch)
- com.google.api.grpc:proto-google-cloud-datastore-v1 (from https://github.com/googleapis/googleapis)
- compiler (from http://github.com/spullara/mustache.java)
- core (from https://github.com/elastic/elasticsearch)
- datastore-v1-proto-client (from https://repo1.maven.org/maven2/com/google/cloud/datastore/datastore-v1-proto-client)
- elasticsearch-cli (from https://github.com/elastic/elasticsearch)
- elasticsearch-core (from https://github.com/elastic/elasticsearch)
- elasticsearch-geo (from https://github.com/elastic/elasticsearch)
- elasticsearch-secure-sm (from https://github.com/elastic/elasticsearch)
- elasticsearch-x-content (from https://github.com/elastic/elasticsearch)
- error-prone annotations (from https://repo1.maven.org/maven2/com/google/errorprone/error_prone_annotations)
- error-prone annotations (from https://repo1.maven.org/maven2/com/google/errorprone/error_prone_annotations)
- google-auth (from https://github.com/googleapis/google-auth-library-python)
......@@ -550,7 +534,7 @@ The following software have components provided under the terms of this license:
- okhttp-urlconnection (from https://github.com/square/okhttp)
- org.apiguardian:apiguardian-api (from https://github.com/apiguardian-team/apiguardian)
- org.opentest4j:opentest4j (from https://github.com/ota4j-team/opentest4j)
- org.xmlunit:xmlunit-core (from http://www.xmlunit.org/)
- org.xmlunit:xmlunit-core (from https://www.xmlunit.org/)
- parent-join (from https://github.com/elastic/elasticsearch)
- project ':json-path' (from https://github.com/jayway/JsonPath)
- proto-google-cloud-logging-v2 (from https://repo1.maven.org/maven2/com/google/api/grpc/proto-google-cloud-logging-v2)
......@@ -559,10 +543,19 @@ The following software have components provided under the terms of this license:
- proto-google-iam-v1 (from https://github.com/googleapis/java-iam/proto-google-iam-v1)
- rank-eval (from https://github.com/elastic/elasticsearch)
- requests (from https://requests.readthedocs.io)
- resilience4j (from https://resilience4j.readme.io)
- resilience4j (from https://resilience4j.readme.io)
- resilience4j (from https://resilience4j.readme.io)
- resilience4j (from https://github.com/resilience4j/resilience4j)
- resilience4j (from https://resilience4j.readme.io)
- resilience4j (from https://github.com/resilience4j/resilience4j)
- resilience4j (from https://resilience4j.readme.io)
- resilience4j (from https://resilience4j.readme.io)
- rest (from https://github.com/elastic/elasticsearch)
- rest (from https://github.com/elastic/elasticsearch)
- rest-high-level (from https://github.com/elastic/elasticsearch)
- rxjava (from https://github.com/ReactiveX/RxJava)
- secure-sm (from https://github.com/elastic/elasticsearch)
- server (from https://github.com/elastic/elasticsearch)
- spring-boot (from https://spring.io/projects/spring-boot)
- spring-boot (from https://spring.io/projects/spring-boot)
......@@ -578,6 +571,7 @@ The following software have components provided under the terms of this license:
- spring-boot-starter (from https://spring.io/projects/spring-boot)
- spring-boot-starter-actuator (from https://spring.io/projects/spring-boot)
- spring-boot-starter-actuator (from https://spring.io/projects/spring-boot)
- spring-boot-starter-aop (from https://spring.io/projects/spring-boot)
- spring-boot-starter-json (from https://spring.io/projects/spring-boot)
- spring-boot-starter-json (from https://spring.io/projects/spring-boot)
- spring-boot-starter-logging (from https://spring.io/projects/spring-boot)
......@@ -595,15 +589,15 @@ The following software have components provided under the terms of this license:
- spring-boot-test (from https://spring.io/projects/spring-boot)
- spring-boot-test-autoconfigure (from https://spring.io/projects/spring-boot)
- spring-boot-test-autoconfigure (from https://spring.io/projects/spring-boot)
- spring-security-config (from https://spring.io/projects/spring-security)
- spring-security-config (from https://spring.io/projects/spring-security)
- spring-security-core (from https://spring.io/projects/spring-security)
- spring-security-core (from https://spring.io/projects/spring-security)
- spring-security-oauth2-core (from https://spring.io/projects/spring-security)
- spring-security-oauth2-jose (from https://spring.io/projects/spring-security)
- spring-security-oauth2-resource-server (from https://spring.io/projects/spring-security)
- spring-security-web (from https://spring.io/projects/spring-security)
- spring-security-web (from https://spring.io/projects/spring-security)
- spring-security-config (from http://spring.io/spring-security)
- spring-security-config (from http://spring.io/spring-security)
- spring-security-core (from http://spring.io/spring-security)
- spring-security-core (from http://spring.io/spring-security)
- spring-security-oauth2-core (from http://spring.io/spring-security)
- spring-security-oauth2-jose (from http://spring.io/spring-security)
- spring-security-oauth2-resource-server (from http://spring.io/spring-security)
- spring-security-web (from http://spring.io/spring-security)
- spring-security-web (from http://spring.io/spring-security)
- springfox-core (from https://github.com/springfox/springfox)
- springfox-schema (from https://github.com/springfox/springfox)
- springfox-spi (from https://github.com/springfox/springfox)
......@@ -616,6 +610,7 @@ The following software have components provided under the terms of this license:
- swagger-models (from https://repo1.maven.org/maven2/io/swagger/swagger-models)
- tomcat-embed-core (from http://tomcat.apache.org/)
- tomcat-embed-websocket (from https://tomcat.apache.org/)
- x-content (from https://github.com/elastic/elasticsearch)
========================================================================
BSD-2-Clause
......@@ -732,6 +727,7 @@ EPL-1.0
========================================================================
The following software have components provided under the terms of this license:
- AspectJ Weaver (from https://www.eclipse.org/aspectj/)
- JUnit Jupiter (Aggregator) (from https://junit.org/junit5/)
- JUnit Jupiter (Aggregator) (from https://junit.org/junit5/)
- JUnit Jupiter API (from https://junit.org/junit5/)
......@@ -945,8 +941,8 @@ The following software have components provided under the terms of this license:
- msal (from https://github.com/AzureAD/microsoft-authentication-library-for-python)
- msal4j (from https://github.com/AzureAD/microsoft-authentication-library-for-java)
- msal4j-persistence-extension (from https://github.com/AzureAD/microsoft-authentication-extensions-for-java)
- spring-security-core (from https://spring.io/projects/spring-security)
- spring-security-core (from https://spring.io/projects/spring-security)
- spring-security-core (from http://spring.io/spring-security)
- spring-security-core (from http://spring.io/spring-security)
========================================================================
MPL-1.1
......@@ -1019,7 +1015,6 @@ public-domain
The following software have components provided under the terms of this license:
- AOP alliance (from http://aopalliance.sourceforge.net)
- AWS Java SDK :: SDK Core (from https://aws.amazon.com/sdkforjava)
- AWS SDK for Java - Models (from https://aws.amazon.com/sdkforjava)
- Asynchronous Http Client (from https://repo1.maven.org/maven2/org/asynchttpclient/async-http-client)
- Guava: Google Core Libraries for Java (from https://repo1.maven.org/maven2/com/google/guava/guava)
......
......@@ -31,7 +31,7 @@
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-schema</artifactId>
<version>0.10.0-SNAPSHOT</version>
<version>0.12.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>os-schema</name>
<description>os schema service </description>
......
......@@ -18,7 +18,7 @@
<parent>
<artifactId>os-schema</artifactId>
<groupId>org.opengroup.osdu</groupId>
<version>0.10.0-SNAPSHOT</version>
<version>0.12.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
......@@ -35,7 +35,7 @@
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-schema-core</artifactId>
<version>0.10.0-SNAPSHOT</version>
<version>0.12.0-SNAPSHOT</version>
</dependency>
<!-- AWS managed packages -->
<dependency>
......@@ -67,7 +67,7 @@
<dependency>
<groupId>org.opengroup.osdu.core.aws</groupId>
<artifactId>os-core-lib-aws</artifactId>
<version>0.11.0-SNAPSHOT</version>
<version>0.11.0</version>
</dependency>
<dependency>
......
......@@ -18,21 +18,21 @@
<parent>
<artifactId>os-schema</artifactId>
<groupId>org.opengroup.osdu</groupId>
<version>0.10.0-SNAPSHOT</version>
<version>0.12.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>os-schema-azure</artifactId>
<version>0.10.0-SNAPSHOT</version>
<version>0.12.0-SNAPSHOT</version>
<description>Azure related implementation staff.</description>
<packaging>jar</packaging>
<properties>
<azure.version>2.1.7</azure.version>
<osdu.corelibazure.version>0.10.1</osdu.corelibazure.version>
<osdu.oscorecommon.version>0.11.0-rc4</osdu.oscorecommon.version>
<osdu.os-schema-core.version>0.10.0-SNAPSHOT</osdu.os-schema-core.version>
<osdu.corelibazure.version>0.11.0</osdu.corelibazure.version>
<osdu.oscorecommon.version>0.11.0</osdu.oscorecommon.version>
<osdu.os-schema-core.version>0.12.0-SNAPSHOT</osdu.os-schema-core.version>
<mockito.version>1.10.19</mockito.version>
<cucumber.version>5.4.0</cucumber.version>
<nimbus-jose-jwt-azure.version>8.20.2</nimbus-jose-jwt-azure.version>
......
......@@ -20,13 +20,17 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import org.joda.time.DateTime;
import org.opengroup.osdu.azure.eventgrid.EventGridTopicStore;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory;
import org.opengroup.osdu.schema.azure.di.EventGridConfig;
import org.opengroup.osdu.schema.azure.di.SystemResourceConfig;
import org.opengroup.osdu.schema.azure.impl.messagebus.model.SchemaPubSubInfo;
import org.opengroup.osdu.schema.constants.SchemaConstants;
import org.opengroup.osdu.schema.logging.AuditLogger;
......@@ -49,15 +53,26 @@ public class MessageBusImpl implements IMessageBus {
private AuditLogger auditLogger;
@Autowired
DpsHeaders headers;
@Autowired
private ITenantFactory tenantFactory;
@Autowired
SystemResourceConfig systemResourceConfig;
private final static String EVENT_DATA_VERSION = "1.0";
@Override
public void publishMessage(String schemaId, String eventType) {
// This if block will be removed once schema-core starts consuming *System* methods.
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(headers.getPartitionId())) {
this.publishMessageForSystemSchema(schemaId, eventType);
return;
}
if (eventGridConfig.isEventGridEnabled()) {
logger.info("Generating event of type {}",eventType);
try {
publishToEventGrid(schemaId, eventType);
publishToEventGrid(schemaId, eventType, headers.getPartitionId());
auditLogger.schemaNotificationSuccess(Collections.singletonList(schemaId));
}catch (AppException ex) {
......@@ -71,7 +86,38 @@ public class MessageBusImpl implements IMessageBus {
}
}
private void publishToEventGrid(String schemaId, String eventType) {
/**
* Method to publish schema create notification for system schemas.
* @param schemaId
* @param eventType
*/
@Override
public void publishMessageForSystemSchema(String schemaId, String eventType) {
if (eventGridConfig.isEventGridEnabled()) {
logger.info("Generating event of type {}",eventType);
try {
// Publish the event for all the tenants.
List<String> privateTenantList = tenantFactory.listTenantInfo().stream().map(TenantInfo::getName)
.collect(Collectors.toList());
for (String tenant : privateTenantList) {
publishToEventGrid(schemaId, eventType, tenant);
}
auditLogger.schemaNotificationSuccess(Collections.singletonList(schemaId));
}catch (AppException ex) {
//We do not want to fail schema creation if notification delivery has failed, hence just logging the exception
auditLogger.schemaNotificationFailure(Collections.singletonList(schemaId));
logger.warning(SchemaConstants.SCHEMA_NOTIFICATION_FAILED);
}
}else {
logger.info(SchemaConstants.SCHEMA_NOTIFICATION_IS_DISABLED);
}
}
private void publishToEventGrid(String schemaId, String eventType, String dataPartitionId) {
String messageId = UUID.randomUUID().toString();
SchemaPubSubInfo[] schemaPubSubMsgs = new SchemaPubSubInfo [1];
......@@ -79,8 +125,8 @@ public class MessageBusImpl implements IMessageBus {
List<EventGridEvent> eventsList = new ArrayList<>();
HashMap<String, Object> message = new HashMap<>();
message.put("data", schemaPubSubMsgs);
message.put(DpsHeaders.ACCOUNT_ID, headers.getPartitionIdWithFallbackToAccountId());
message.put(DpsHeaders.DATA_PARTITION_ID, headers.getPartitionIdWithFallbackToAccountId());
message.put(DpsHeaders.ACCOUNT_ID, dataPartitionId);
message.put(DpsHeaders.DATA_PARTITION_ID, dataPartitionId);
message.put(DpsHeaders.CORRELATION_ID, headers.getCorrelationId());
//EventGridEvent supports array of messages to be triggered in a batch but at present we do not support
......@@ -95,7 +141,7 @@ public class MessageBusImpl implements IMessageBus {
);
eventsList.add(eventGridEvent);
logger.info("Schema event created: " + messageId);
eventGridTopicStore.publishToEventGridTopic(headers.getPartitionId(), eventGridConfig.getCustomTopicName(), eventsList);
eventGridTopicStore.publishToEventGridTopic(dataPartitionId, eventGridConfig.getCustomTopicName(), eventsList);
logger.info("Schema event generated successfully");
}
......
......@@ -72,17 +72,32 @@ public class AzureAuthorityStore implements IAuthorityStore {
*/
@Override
public Authority get(String authorityId) throws NotFoundException, ApplicationException {
// This if block will be removed once schema-core starts consuming *System* methods.
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(headers.getPartitionId())) {
return this.getSystemAuthority(authorityId);
}
String id = headers.getPartitionId() + ":" + authorityId;
AuthorityDoc authorityDoc;
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(headers.getPartitionId())) {
authorityDoc = cosmosStore.findItem(systemResourceConfig.getCosmosDatabase(), authorityContainer, id, authorityId, AuthorityDoc.class)
.orElseThrow(() -> new NotFoundException("bad input parameter"));
} else {
authorityDoc = cosmosStore.findItem(headers.getPartitionId(), cosmosDBName, authorityContainer, id, authorityId, AuthorityDoc.class)
.orElseThrow(() -> new NotFoundException("bad input parameter"));
}
authorityDoc = cosmosStore.findItem(headers.getPartitionId(), cosmosDBName, authorityContainer, id, authorityId, AuthorityDoc.class)
.orElseThrow(() -> new NotFoundException("bad input parameter"));
return authorityDoc.getAuthority();
}
/**
* Method to get system Authority
* @param authorityId
* @return
* @throws NotFoundException
* @throws ApplicationException
*/
@Override
public Authority getSystemAuthority(String authorityId) throws NotFoundException, ApplicationException {
AuthorityDoc authorityDoc;
authorityDoc = cosmosStore.findItem(systemResourceConfig.getCosmosDatabase(), authorityContainer, authorityId, authorityId, AuthorityDoc.class)
.orElseThrow(() -> new NotFoundException("bad input parameter"));
return authorityDoc.getAuthority();
}
......@@ -96,27 +111,52 @@ public class AzureAuthorityStore implements IAuthorityStore {
*/
@Override
public Authority create(Authority authority) throws ApplicationException, BadRequestException {
// This if block will be removed once schema-core starts consuming *System* methods.
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(headers.getPartitionId())) {
return this.createSystemAuthority(authority);
}
String id = headers.getPartitionId() + ":" + authority.getAuthorityId();
try {
AuthorityDoc authorityDoc = new AuthorityDoc(id, authority);
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(headers.getPartitionId())) {
cosmosStore.createItem(systemResourceConfig.getCosmosDatabase(), authorityContainer, id, authorityDoc);
} else {
cosmosStore.createItem(headers.getPartitionId(), cosmosDBName, authorityContainer, id, authorityDoc);
}
cosmosStore.createItem(headers.getPartitionId(), cosmosDBName, authorityContainer, id, authorityDoc);
} catch (AppException ex) {
if (ex.getError().getCode() == 409) {
log.warning(SchemaConstants.AUTHORITY_EXISTS_ALREADY_REGISTERED);
throw new BadRequestException(MessageFormat.format(SchemaConstants.AUTHORITY_EXISTS_EXCEPTION,
authority.getAuthorityId()));
} else {
log.error(MessageFormat.format(SchemaConstants.OBJECT_INVALID, ex.getMessage()));
throw new ApplicationException(SchemaConstants.INVALID_INPUT);
}
handleAppException(ex, authority);
}
log.info(SchemaConstants.AUTHORITY_CREATED);
return authority;
}
/**
* Method to register a System Authority
* @param authority
* @return
* @throws ApplicationException
* @throws BadRequestException
*/
@Override
public Authority createSystemAuthority(Authority authority) throws ApplicationException, BadRequestException {
try {
AuthorityDoc authorityDoc = new AuthorityDoc(authority.getAuthorityId(), authority);
cosmosStore.createItem(systemResourceConfig.getCosmosDatabase(), authorityContainer, authority.getAuthorityId(), authorityDoc);
} catch (AppException ex) {
handleAppException(ex, authority);
}
log.info(SchemaConstants.AUTHORITY_CREATED);
return authority;
}
private void handleAppException(AppException ex, Authority authority) throws ApplicationException, BadRequestException {
if (ex.getError().getCode() == 409) {
log.warning(SchemaConstants.AUTHORITY_EXISTS_ALREADY_REGISTERED);
throw new BadRequestException(MessageFormat.format(SchemaConstants.AUTHORITY_EXISTS_EXCEPTION,
authority.getAuthorityId()));
} else {
log.error(MessageFormat.format(SchemaConstants.OBJECT_INVALID, ex.getMessage()));
throw new ApplicationException(SchemaConstants.INVALID_INPUT);
}
}
}
......@@ -69,17 +69,31 @@ public class AzureEntityTypeStore implements IEntityTypeStore {
*/
@Override
public EntityType get(String entityTypeId) throws NotFoundException, ApplicationException {
// This if block will be removed once schema-core starts consuming *System* methods.
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(headers.getPartitionId())) {
return this.getSystemEntity(entityTypeId);
}
String id = headers.getPartitionId() + ":" + entityTypeId;
EntityTypeDoc entityTypeDoc;
entityTypeDoc = cosmosStore.findItem(headers.getPartitionId(), cosmosDBName, entityTypeContainer, id, entityTypeId, EntityTypeDoc.class)
.orElseThrow(() -> new NotFoundException("bad input parameter"));
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(headers.getPartitionId())) {
entityTypeDoc = cosmosStore.findItem(systemResourceConfig.getCosmosDatabase(), entityTypeContainer, id, entityTypeId, EntityTypeDoc.class)
.orElseThrow(() -> new NotFoundException("bad input parameter"));
} else {
entityTypeDoc = cosmosStore.findItem(headers.getPartitionId(), cosmosDBName, entityTypeContainer, id, entityTypeId, EntityTypeDoc.class)
.orElseThrow(() -> new NotFoundException("bad input parameter"));
}
return entityTypeDoc.getEntityType();
}
/**
* Method to get system Entity
* @param entityTypeId
* @return
* @throws NotFoundException
* @throws ApplicationException
*/
@Override
public EntityType getSystemEntity(String entityTypeId) throws NotFoundException, ApplicationException {
EntityTypeDoc entityTypeDoc;
entityTypeDoc = cosmosStore.findItem(systemResourceConfig.getCosmosDatabase(), entityTypeContainer, entityTypeId, entityTypeId, EntityTypeDoc.class)
.orElseThrow(() -> new NotFoundException("bad input parameter"));
return entityTypeDoc.getEntityType();
}
......@@ -93,27 +107,51 @@ public class AzureEntityTypeStore implements IEntityTypeStore {
*/
@Override
public EntityType create(EntityType entityType) throws BadRequestException, ApplicationException {
String id = headers.getPartitionId() + ":" + entityType.getEntityTypeId();
// This if block will be removed once schema-core starts consuming *System* methods.
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(headers.getPartitionId())) {
return this.createSystemEntity(entityType);
}
String id = headers.getPartitionId() + ":" + entityType.getEntityTypeId();
try {
EntityTypeDoc entityTypeDoc = new EntityTypeDoc(id, entityType);
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(headers.getPartitionId())) {
cosmosStore.createItem(systemResourceConfig.getCosmosDatabase(), entityTypeContainer, id, entityTypeDoc);
} else {
cosmosStore.createItem(headers.getPartitionId(), cosmosDBName, entityTypeContainer, id, entityTypeDoc);
}
cosmosStore.createItem(headers.getPartitionId(), cosmosDBName, entityTypeContainer, id, entityTypeDoc);
} catch (AppException ex) {
if (ex.getError().getCode() == 409) {
log.warning(SchemaConstants.ENTITY_TYPE_EXISTS);
throw new BadRequestException(MessageFormat.format(SchemaConstants.ENTITY_TYPE_EXISTS_EXCEPTION,
entityType.getEntityTypeId()));
} else {
log.error(MessageFormat.format(SchemaConstants.OBJECT_INVALID, ex.getMessage()));
throw new ApplicationException(SchemaConstants.INVALID_INPUT);
}
handleAppException(ex, entityType);
}
log.info(SchemaConstants.ENTITY_TYPE_CREATED);
return entityType;
}
/**
* Method to create a system Entity
* @param entityType
* @return
* @throws BadRequestException
* @throws ApplicationException
*/
@Override
public EntityType createSystemEntity(EntityType entityType) throws BadRequestException, ApplicationException {
try {
EntityTypeDoc entityTypeDoc = new EntityTypeDoc(entityType.getEntityTypeId(), entityType);
cosmosStore.createItem(systemResourceConfig.getCosmosDatabase(), entityTypeContainer, entityType.getEntityTypeId(), entityTypeDoc);
} catch (AppException ex) {
handleAppException(ex, entityType);
}
log.info(SchemaConstants.ENTITY_TYPE_CREATED);
return entityType;
}
private void handleAppException(AppException ex, EntityType entityType) throws BadRequestException, ApplicationException {
if (ex.getError().getCode() == 409) {
log.warning(SchemaConstants.ENTITY_TYPE_EXISTS);
throw new BadRequestException(MessageFormat.format(SchemaConstants.ENTITY_TYPE_EXISTS_EXCEPTION,
entityType.getEntityTypeId()));
} else {
log.error(MessageFormat.format(SchemaConstants.OBJECT_INVALID, ex.getMessage()));
throw new ApplicationException(SchemaConstants.INVALID_INPUT);
}
}
}
......@@ -67,17 +67,32 @@ public class AzureSourceStore implements ISourceStore {
*/
@Override
public Source get(String sourceId) throws NotFoundException, ApplicationException {
// This if block will be removed once schema-core starts consuming *System* methods.
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(headers.getPartitionId())) {
return this.getSystemSource(sourceId);
}
String id = headers.getPartitionId().toString() + ":" + sourceId;
SourceDoc sourceDoc;