Commit 5823e184 authored by Artem Dobrynin (EPAM)'s avatar Artem Dobrynin (EPAM)
Browse files

GONRG-1779: Implement logic for Register [publish]

https://jiraeu.epam.com/browse/GONRG-1779
https://jiraeu.epam.com/browse/GONRG-1735

* Added logback.xml
* Updated pom
* Updated DatastoreMultiTenantAccess with the latest changes of os-core-lib-gcp
parent 9bc83bf4
......@@ -31,11 +31,10 @@
</parent>
<dependencies>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>core-lib-gcp</artifactId>
<version>0.1.21</version>
<version>0.6.0-SNAPSHOT</version>
</dependency>
<dependency>
......@@ -54,6 +53,12 @@
<artifactId>spring-security-config</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback.contrib</groupId>
<artifactId>logback-json-classic</artifactId>
<version>0.1.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
......
......@@ -83,7 +83,7 @@ public class DatastoreActionRepo implements IActionRepo {
@Override
public Action get(String id) {
Datastore ds = dataStoreTenants.get(tenantInfo.getName());
Datastore ds = dataStoreTenants.get(tenantInfo);
Key key = createkey(ds, id);
Entity entity = ds.get(key);
if (entity == null)
......@@ -101,7 +101,7 @@ public class DatastoreActionRepo implements IActionRepo {
}
private Action createActionInDatastore(Action action) {
Datastore ds = dataStoreTenants.get(tenantInfo.getName());
Datastore ds = dataStoreTenants.get(tenantInfo);
Key key = createkey(ds, action.getId());
FullEntity<Key> entity = convertActionToEntity(action, key);
......@@ -134,7 +134,7 @@ public class DatastoreActionRepo implements IActionRepo {
}
private boolean deleteFromDatastore(String id) {
Datastore ds = dataStoreTenants.get(tenantInfo.getName());
Datastore ds = dataStoreTenants.get(tenantInfo);
boolean output = false;
Key key = createkey(ds, id);
......@@ -166,7 +166,7 @@ public class DatastoreActionRepo implements IActionRepo {
@Override
public List<Action> getAllActions() {
Datastore ds = dataStoreTenants.get(tenantInfo.getName());
Datastore ds = dataStoreTenants.get(tenantInfo);
Query<Entity> q = Query
.newGqlQueryBuilder(Query.ResultType.ENTITY, "Select * from ACTION")
......
......@@ -65,7 +65,7 @@ public class DatastoreDdmsRepository implements IDdmsRepository {
@Override
public Ddms create(Ddms ddms) {
Datastore ds = dataStoreTenants.get(tenantInfo.getName());
Datastore ds = dataStoreTenants.get(tenantInfo);
Key key = createkey(ds, ddms.getId());
FullEntity<Key> entity = convertDmsToEntity(ddms, key);
......@@ -95,7 +95,7 @@ public class DatastoreDdmsRepository implements IDdmsRepository {
@Override
public Ddms get(String id) {
Datastore ds = dataStoreTenants.get(tenantInfo.getName());
Datastore ds = dataStoreTenants.get(tenantInfo);
Key key = createkey(ds, id);
Entity entity = ds.get(key);
if (entity == null)
......@@ -106,7 +106,7 @@ public class DatastoreDdmsRepository implements IDdmsRepository {
@Override
public List<Ddms> query(String type) {
List<Ddms> output = new ArrayList<>();
Datastore ds = dataStoreTenants.get(tenantInfo.getName());
Datastore ds = dataStoreTenants.get(tenantInfo);
Query<Entity> q = Query
.newGqlQueryBuilder(Query.ResultType.ENTITY, "SELECT * FROM DDMS WHERE interfaces.type=@t")
.setBinding("t", type)
......@@ -122,7 +122,7 @@ public class DatastoreDdmsRepository implements IDdmsRepository {
@Override
public boolean delete(String id) {
Datastore ds = dataStoreTenants.get(tenantInfo.getName());
Datastore ds = dataStoreTenants.get(tenantInfo);
boolean output = false;
Key key = createkey(ds, id);
......
......@@ -16,9 +16,12 @@
package org.opengroup.osdu.register.provider.gcp.ddms.datastore;
import static java.util.Objects.isNull;
import com.google.cloud.datastore.Datastore;
import org.apache.commons.lang3.StringUtils;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.gcp.multitenancy.DatastoreFactory;
import org.opengroup.osdu.core.gcp.multitenancy.IDatastoreFactory;
import org.opengroup.osdu.core.gcp.multitenancy.TenantFactory;
......@@ -36,27 +39,28 @@ public class DatastoreMultiTenantAccess {
private final Map<String, Datastore> tenantRepositories = new HashMap<>();
public DatastoreMultiTenantAccess() {
this(new DatastoreFactory(new TenantFactory()));
this(new DatastoreFactory(new TenantInfo()));
}
DatastoreMultiTenantAccess(IDatastoreFactory factory) {
this.factory = factory;
}
public Datastore get(String tenantName) {
if (StringUtils.isBlank(tenantName))
throw invalidTenantGivenException(tenantName);
if (!tenantRepositories.containsKey(tenantName)) {
addRepository(tenantName);
public Datastore get(TenantInfo tenantInfo) {
if (isNull(tenantInfo)){
throw invalidTenantGivenException("null");
}
if (!tenantRepositories.containsKey(tenantInfo.getName())) {
addRepository(tenantInfo);
}
return tenantRepositories.get(tenantName);
return tenantRepositories.get(tenantInfo.getName());
}
private void addRepository(String tenantName) {
Datastore ds = factory.getDatastore(tenantName, tenantName);
private void addRepository(TenantInfo tenantInfo) {
Datastore ds = factory.getDatastore(tenantInfo);
if (ds == null)
throw invalidTenantGivenException(tenantName);
tenantRepositories.put(tenantName, ds);
throw invalidTenantGivenException(tenantInfo.getName());
tenantRepositories.put(tenantInfo.getName(), ds);
}
private AppException invalidTenantGivenException(String tenantName) {
......
......@@ -66,7 +66,7 @@ public class DatastoreAccess implements IDatastoreAccess {
@Override
public Subscription get(String id) {
Datastore ds = dataStoreTenants.get(tenantInfo.getName());
Datastore ds = dataStoreTenants.get(tenantInfo);
Key key = createKey(ds, id);
Entity entity = ds.get(key);
if (entity == null)
......@@ -83,7 +83,7 @@ public class DatastoreAccess implements IDatastoreAccess {
@Override
public List<Subscription> query(String notificationId) {
List<Subscription> output = new ArrayList<>();
Datastore ds = dataStoreTenants.get(tenantInfo.getName());
Datastore ds = dataStoreTenants.get(tenantInfo);
Query<Entity> q = Query
.newGqlQueryBuilder(Query.ResultType.ENTITY, "SELECT * FROM SUBSCRIPTION WHERE notificationId=@t")
.setBinding("t", notificationId)
......@@ -114,7 +114,7 @@ public class DatastoreAccess implements IDatastoreAccess {
@Override
public List<Subscription> getAll() throws Exception {
Datastore ds = dataStoreTenants.get(tenantInfo.getName());
Datastore ds = dataStoreTenants.get(tenantInfo);
Query<Entity> q = Query
.newGqlQueryBuilder(Query.ResultType.ENTITY, "Select * from SUBSCRIPTION")
.setNamespace(NAMESPACE).build();
......@@ -131,7 +131,7 @@ public class DatastoreAccess implements IDatastoreAccess {
}
private Subscription createSubscriberInDatastore(Subscription s) {
Datastore ds = dataStoreTenants.get(tenantInfo.getName());
Datastore ds = dataStoreTenants.get(tenantInfo);
Key key = createKey(ds, s.getId());
Transaction txn = ds.newTransaction();
......@@ -162,7 +162,7 @@ public class DatastoreAccess implements IDatastoreAccess {
}
private boolean deleteFromDatastore(String id, boolean deleteSubscription) {
Datastore ds = dataStoreTenants.get(tenantInfo.getName());
Datastore ds = dataStoreTenants.get(tenantInfo);
boolean output = false;
Key key = createKey(ds, id);
......@@ -198,7 +198,7 @@ public class DatastoreAccess implements IDatastoreAccess {
}
private boolean updateInDataStore(String id, Secret secret) {
Datastore ds = dataStoreTenants.get(tenantInfo.getName());
Datastore ds = dataStoreTenants.get(tenantInfo);
boolean output = false;
Key key = createKey(ds, id);
......
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<springProfile name="local">
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%yellow([%thread]) %highlight(| %-5level |) %green(%d) %cyan(| %logger{15} |) %highlight(%msg) %n</pattern>
<charset>utf8</charset>
</encoder>
</appender>
<root level="DEBUG">
<appender-ref ref="CONSOLE"/>
</root>
</springProfile>
<springProfile name="!local">
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="ch.qos.logback.contrib.json.classic.JsonLayout">
<timestampFormat>yyyy-MM-dd HH:mm:ss.SSS</timestampFormat>
<timestampFormatTimezoneId>Etc/UTC</timestampFormatTimezoneId>
<appendLineSeparator>true</appendLineSeparator>
<jsonFormatter class="org.opengroup.osdu.core.gcp.logging.formatter.GoogleJsonFormatter">
<prettyPrint>false</prettyPrint>
</jsonFormatter>
</layout>
</encoder>
</appender>
<root level="debug">
<appender-ref ref="stdout"/>
</root>
</springProfile>
</configuration>
\ No newline at end of file
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