Commit a8650fc8 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 5a283dde
......@@ -24,8 +24,8 @@ import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.common.util.Crc32c;
import org.opengroup.osdu.core.gcp.multitenancy.IDatastoreFactory;
import org.opengroup.osdu.register.action.model.Action;
import org.opengroup.osdu.register.provider.gcp.ddms.datastore.DatastoreMultiTenantAccess;
import org.opengroup.osdu.register.provider.interfaces.action.IActionRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
......@@ -72,7 +72,7 @@ public class DatastoreActionRepo implements IActionRepo {
@Autowired
private JaxRsDpsLog log;
@Autowired
private IDatastoreFactory datastoreFactory;
private DatastoreMultiTenantAccess dataStoreTenants;
@Autowired
private TenantInfo tenantInfo;
......@@ -83,7 +83,7 @@ public class DatastoreActionRepo implements IActionRepo {
@Override
public Action get(String id) {
Datastore ds = datastoreFactory.getDatastore(tenantInfo);
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 = datastoreFactory.getDatastore(tenantInfo);
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 = datastoreFactory.getDatastore(tenantInfo);
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 = datastoreFactory.getDatastore(tenantInfo);
Datastore ds = dataStoreTenants.get(tenantInfo);
Query<Entity> q = Query
.newGqlQueryBuilder(Query.ResultType.ENTITY, "Select * from ACTION")
......
......@@ -22,7 +22,6 @@ import java.util.Map;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.gcp.multitenancy.IDatastoreFactory;
import org.opengroup.osdu.register.ddms.model.Ddms;
import org.opengroup.osdu.register.ddms.model.RegisteredInterface;
import org.opengroup.osdu.register.provider.interfaces.ddms.IDdmsRepository;
......@@ -60,13 +59,13 @@ public class DatastoreDdmsRepository implements IDdmsRepository {
private static final String CONFLICT_REASON = "Conflict";
@Autowired
private IDatastoreFactory datastoreFactory;
private DatastoreMultiTenantAccess dataStoreTenants;
@Autowired
private TenantInfo tenantInfo;
@Override
public Ddms create(Ddms ddms) {
Datastore ds = datastoreFactory.getDatastore(tenantInfo);
Datastore ds = dataStoreTenants.get(tenantInfo);
Key key = createkey(ds, ddms.getId());
FullEntity<Key> entity = convertDmsToEntity(ddms, key);
......@@ -96,7 +95,7 @@ public class DatastoreDdmsRepository implements IDdmsRepository {
@Override
public Ddms get(String id) {
Datastore ds = datastoreFactory.getDatastore(tenantInfo);
Datastore ds = dataStoreTenants.get(tenantInfo);
Key key = createkey(ds, id);
Entity entity = ds.get(key);
if (entity == null)
......@@ -107,7 +106,7 @@ public class DatastoreDdmsRepository implements IDdmsRepository {
@Override
public List<Ddms> query(String type) {
List<Ddms> output = new ArrayList<>();
Datastore ds = datastoreFactory.getDatastore(tenantInfo);
Datastore ds = dataStoreTenants.get(tenantInfo);
Query<Entity> q = Query
.newGqlQueryBuilder(Query.ResultType.ENTITY, "SELECT * FROM DDMS WHERE interfaces.type=@t")
.setBinding("t", type)
......@@ -123,7 +122,7 @@ public class DatastoreDdmsRepository implements IDdmsRepository {
@Override
public boolean delete(String id) {
Datastore ds = datastoreFactory.getDatastore(tenantInfo);
Datastore ds = dataStoreTenants.get(tenantInfo);
boolean output = false;
Key key = createkey(ds, id);
......
......@@ -21,28 +21,21 @@ import static java.util.Objects.isNull;
import com.google.cloud.datastore.Datastore;
import java.util.HashMap;
import java.util.Map;
import lombok.RequiredArgsConstructor;
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.gcp.multitenancy.DatastoreFactory;
import org.opengroup.osdu.core.gcp.multitenancy.IDatastoreFactory;
import org.springframework.stereotype.Component;
@Component
@RequiredArgsConstructor
public class DatastoreMultiTenantAccess {
private final IDatastoreFactory factory;
private final Map<String, Datastore> tenantRepositories = new HashMap<>();
public DatastoreMultiTenantAccess() {
this(new DatastoreFactory(new TenantInfo()));
}
DatastoreMultiTenantAccess(IDatastoreFactory factory) {
this.factory = factory;
}
public Datastore get(TenantInfo tenantInfo) {
if (isNull(tenantInfo)){
throw invalidTenantGivenException("null");
......@@ -55,8 +48,9 @@ public class DatastoreMultiTenantAccess {
private void addRepository(TenantInfo tenantInfo) {
Datastore ds = factory.getDatastore(tenantInfo);
if (ds == null)
if (ds == null) {
throw invalidTenantGivenException(tenantInfo.getName());
}
tenantRepositories.put(tenantInfo.getName(), ds);
}
......
......@@ -19,7 +19,7 @@ package org.opengroup.osdu.register.provider.gcp.subscriber;
import com.google.cloud.datastore.*;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.gcp.multitenancy.IDatastoreFactory;
import org.opengroup.osdu.register.provider.gcp.ddms.datastore.DatastoreMultiTenantAccess;
import org.opengroup.osdu.register.provider.gcp.util.GcpAppServiceConfig;
import org.opengroup.osdu.register.subscriber.model.Secret;
import org.opengroup.osdu.register.subscriber.model.Subscription;
......@@ -41,7 +41,7 @@ public class DatastoreAccess implements IDatastoreAccess {
@Autowired
private PushSubscription pushSubscription;
@Autowired
private IDatastoreFactory datastoreFactory;
private DatastoreMultiTenantAccess dataStoreTenants;
@Autowired
private TenantInfo tenantInfo;
@Autowired
......@@ -66,7 +66,7 @@ public class DatastoreAccess implements IDatastoreAccess {
@Override
public Subscription get(String id) {
Datastore ds = datastoreFactory.getDatastore(tenantInfo);
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 = datastoreFactory.getDatastore(tenantInfo);
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 = datastoreFactory.getDatastore(tenantInfo);
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 = datastoreFactory.getDatastore(tenantInfo);
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 = datastoreFactory.getDatastore(tenantInfo);
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 = datastoreFactory.getDatastore(tenantInfo);
Datastore ds = dataStoreTenants.get(tenantInfo);
boolean output = false;
Key key = createKey(ds, id);
......
......@@ -28,6 +28,8 @@ import static org.mockito.Mockito.when;
import java.sql.Timestamp;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
......@@ -41,9 +43,9 @@ import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.gcp.multitenancy.IDatastoreFactory;
import org.opengroup.osdu.register.action.model.Action;
import org.opengroup.osdu.register.action.model.Filter;
import org.opengroup.osdu.register.provider.gcp.ddms.datastore.DatastoreMultiTenantAccess;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
......@@ -61,7 +63,7 @@ public class DatastoreActionRepoTest {
private static final String CHECKSUM = "checksum";
@Mock
private IDatastoreFactory datastoreFactory;
private DatastoreMultiTenantAccess dataStoreTenants;
@Mock
TenantInfo tenantInfo;
......@@ -77,7 +79,7 @@ public class DatastoreActionRepoTest {
public void setup() {
MockitoAnnotations.initMocks(this);
when(datastore.newKeyFactory()).thenReturn(keyFactory);
when(datastoreFactory.getDatastore(any())).thenReturn(datastore);
when(dataStoreTenants.get(any())).thenReturn(datastore);
}
@Test
......
......@@ -25,7 +25,6 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.gcp.multitenancy.IDatastoreFactory;
import org.opengroup.osdu.register.ddms.model.Ddms;
import org.opengroup.osdu.register.ddms.model.RegisteredInterface;
import org.powermock.core.classloader.annotations.PrepareForTest;
......@@ -46,7 +45,7 @@ import static org.mockito.MockitoAnnotations.initMocks;
@PrepareForTest({Datastore.class, KeyFactory.class, Key.class})
public class DatastoreDdmsRepositoryTest {
@Mock
private IDatastoreFactory datastoreFactory;
private DatastoreMultiTenantAccess dataStoreTenants;
@Mock
private TenantInfo tenantInfo;
@Mock
......@@ -63,7 +62,7 @@ public class DatastoreDdmsRepositoryTest {
public void setup() {
initMocks(this);
when(datastore.newKeyFactory()).thenReturn(keyFactory);
when(datastoreFactory.getDatastore(any())).thenReturn(datastore);
when(dataStoreTenants.get(any())).thenReturn(datastore);
}
@Test
......
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