diff --git a/provider/register-azure/src/main/java/org/opengroup/osdu/register/provider/azure/action/ActionRepository.java b/provider/register-azure/src/main/java/org/opengroup/osdu/register/provider/azure/action/ActionRepository.java index 577e94fa6d3dec404043f114991b281740b7fc7e..96cfd8740567acc949b883f48241fe8c1c565695 100644 --- a/provider/register-azure/src/main/java/org/opengroup/osdu/register/provider/azure/action/ActionRepository.java +++ b/provider/register-azure/src/main/java/org/opengroup/osdu/register/provider/azure/action/ActionRepository.java @@ -18,6 +18,7 @@ import com.azure.cosmos.FeedOptions; import com.azure.cosmos.SqlParameter; import com.azure.cosmos.SqlParameterList; import com.azure.cosmos.SqlQuerySpec; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.register.action.model.Action; import org.opengroup.osdu.register.provider.interfaces.action.IActionRepo; @@ -47,17 +48,22 @@ public class ActionRepository implements IActionRepo { @Autowired private String cosmosDBName; + @Autowired + private JaxRsDpsLog log; + @Override public Action createAction(Action action) { if(action.getId() == null){ + log.error("Action id cannot be null"); throw new AppException(400, "Bad Request", "Action id cannot be null"); } try { mutex.lock(); if (exists(action.getId())) { - throwConflict(); + log.error(String.format("An action already exists with the id: %s", action.getId())); + throw new AppException(409, "Conflict", String.format("An action already exists with the id: %s", action.getId())); } ActionDoc doc = new ActionDoc(action, headers.getPartitionId()); @@ -118,8 +124,4 @@ public class ActionRepository implements IActionRepo { return action; } - private void throwConflict() { - throw new AppException(409, "Conflict", "An action already exists with the same message and endpoint combination"); - } - } diff --git a/provider/register-azure/src/main/java/org/opengroup/osdu/register/provider/azure/ddms/DdmsRepository.java b/provider/register-azure/src/main/java/org/opengroup/osdu/register/provider/azure/ddms/DdmsRepository.java index e7c4f7d35368eacd385d65d375a334774167de75..11e0c3ca292233b9a590e3fcd591c60cbc58e33a 100644 --- a/provider/register-azure/src/main/java/org/opengroup/osdu/register/provider/azure/ddms/DdmsRepository.java +++ b/provider/register-azure/src/main/java/org/opengroup/osdu/register/provider/azure/ddms/DdmsRepository.java @@ -20,6 +20,7 @@ import com.azure.cosmos.SqlParameterList; import com.azure.cosmos.SqlQuerySpec; import com.google.cloud.Timestamp; import org.opengroup.osdu.azure.CosmosStore; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.register.ddms.model.Ddms; import org.opengroup.osdu.register.ddms.model.RegisteredInterface; @@ -49,6 +50,9 @@ public class DdmsRepository implements IDdmsRepository { @Autowired private String cosmosDBName; + @Autowired + private JaxRsDpsLog log; + @Override public Ddms create(Ddms ddms) { @@ -56,9 +60,9 @@ public class DdmsRepository implements IDdmsRepository { mutex.lock(); if(exists(ddms.getId())){ - throw new AppException(409, "Conflict", "A DDMS already exists with the same id"); + log.error(String.format("A DDMS already exists with the same id: %s", ddms.getId())); + throw new AppException(409, "Conflict", String.format("A DDMS already exists with the same id: %s", ddms.getId())); } - // TODO Size check for Ddms schema [Maximum Size for a CosmosDb item is 2MB] DdmsDoc doc = new DdmsDoc(ddms, headers.getPartitionId()); cosmosStore.upsertItem(headers.getPartitionId(), cosmosDBName, ddmsContainer, doc); diff --git a/provider/register-azure/src/main/java/org/opengroup/osdu/register/provider/azure/Util/GoogleServiceAccountImpl.java b/provider/register-azure/src/main/java/org/opengroup/osdu/register/provider/azure/util/GoogleServiceAccountImpl.java similarity index 95% rename from provider/register-azure/src/main/java/org/opengroup/osdu/register/provider/azure/Util/GoogleServiceAccountImpl.java rename to provider/register-azure/src/main/java/org/opengroup/osdu/register/provider/azure/util/GoogleServiceAccountImpl.java index b4f61f10b40cb4c0fd544dfc0090ea2585afa88d..ab7f947b8ca0590477bd7b2507d804a0c8f77901 100644 --- a/provider/register-azure/src/main/java/org/opengroup/osdu/register/provider/azure/Util/GoogleServiceAccountImpl.java +++ b/provider/register-azure/src/main/java/org/opengroup/osdu/register/provider/azure/util/GoogleServiceAccountImpl.java @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package org.opengroup.osdu.register.provider.azure.Util; +package org.opengroup.osdu.register.provider.azure.util; import lombok.SneakyThrows; import org.opengroup.osdu.register.utils.IGoogleServiceAccount; diff --git a/provider/register-azure/src/test/java/org/opengroup/osdu/register/provider/azure/action/ActionRepositoryTest.java b/provider/register-azure/src/test/java/org/opengroup/osdu/register/provider/azure/action/ActionRepositoryTest.java index 46e570b4fbc30564b8ce6721030e7a119373cefd..ddd52eb661fbe4d9689efcb04d52246bcf563866 100644 --- a/provider/register-azure/src/test/java/org/opengroup/osdu/register/provider/azure/action/ActionRepositoryTest.java +++ b/provider/register-azure/src/test/java/org/opengroup/osdu/register/provider/azure/action/ActionRepositoryTest.java @@ -21,6 +21,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.opengroup.osdu.azure.CosmosStore; +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.register.action.model.Action; @@ -36,7 +37,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.lenient; @@ -55,6 +56,9 @@ public class ActionRepositoryTest { @Mock private CosmosStore cosmosStore; + @Mock + private JaxRsDpsLog log; + @InjectMocks private ActionRepository repo; @@ -81,7 +85,7 @@ public class ActionRepositoryTest { Action action = createAction(); Optional<ActionDoc> cosmosItem = Optional.of(new ActionDoc()); - doReturn(cosmosItem).when(cosmosStore).findItem(anyString(), any(), any(), anyString(), anyString(), any()); + doReturn(cosmosItem).when(cosmosStore).findItem(eq(dataPartitionId), any(), any(), eq(actionId), eq(dataPartitionId), any()); AppException exception = assertThrows(AppException.class, () -> { repo.createAction(action); @@ -89,7 +93,7 @@ public class ActionRepositoryTest { assertEquals(409, exception.getError().getCode()); assertEquals("Conflict", exception.getError().getReason()); - assertEquals("An action already exists with the same message and endpoint combination", exception.getError().getMessage()); + assertEquals(String.format("An action already exists with the id: %s", action.getId()), exception.getError().getMessage()); verify(cosmosStore, times(1)).findItem(dataPartitionId, null, null, actionId, dataPartitionId, ActionDoc.class); } @@ -98,8 +102,8 @@ public class ActionRepositoryTest { Action action = createAction(); Optional<ActionDoc> cosmosItem = Optional.empty(); - doReturn(cosmosItem).when(cosmosStore).findItem(anyString(), any(), any(), anyString(), anyString(), any()); - doNothing().when(cosmosStore).upsertItem(anyString(), any(), any(), any()); + doReturn(cosmosItem).when(cosmosStore).findItem(eq(dataPartitionId), any(), any(), eq(actionId), eq(dataPartitionId), any()); + doNothing().when(cosmosStore).upsertItem(eq(dataPartitionId), any(), any(), any()); Action output = repo.createAction(action); @@ -110,7 +114,7 @@ public class ActionRepositoryTest { @Test public void getAction_throws404_whenIdNotFound() { - doReturn(Optional.empty()).when(cosmosStore).findItem(anyString(), any(), any(), anyString(), anyString(), any()); + doReturn(Optional.empty()).when(cosmosStore).findItem(eq(dataPartitionId), any(), any(), eq(actionId), eq(dataPartitionId), any()); AppException exception = assertThrows(AppException.class, () -> { repo.get(actionId); @@ -128,7 +132,7 @@ public class ActionRepositoryTest { Action action = createAction(); ActionDoc doc = new ActionDoc(action, dataPartitionId); - doReturn(Optional.of(doc)).when(cosmosStore).findItem(anyString(), any(), any(), anyString(), anyString(), any()); + doReturn(Optional.of(doc)).when(cosmosStore).findItem(eq(dataPartitionId), any(), any(), eq(actionId), eq(dataPartitionId), any()); Action output = repo.get(actionId); @@ -139,7 +143,7 @@ public class ActionRepositoryTest { @Test public void deleteAction_returnsFalse_whenIdNotFound() { - doReturn(Optional.empty()).when(cosmosStore).findItem(anyString(), any(), any(), anyString(), anyString(), any()); + doReturn(Optional.empty()).when(cosmosStore).findItem(eq(dataPartitionId), any(), any(), eq(actionId), eq(dataPartitionId), any()); boolean output = repo.delete(actionId); @@ -154,7 +158,7 @@ public class ActionRepositoryTest { ActionDoc doc = new ActionDoc(action, dataPartitionId); Optional<ActionDoc> cosmosItem = Optional.of(doc); - doReturn(cosmosItem).when(cosmosStore).findItem(anyString(), any(), any(), anyString(), anyString(), any()); + doReturn(cosmosItem).when(cosmosStore).findItem(eq(dataPartitionId), any(), any(), eq(actionId), eq(dataPartitionId), any()); boolean output = repo.delete(actionId); @@ -176,7 +180,7 @@ public class ActionRepositoryTest { List<Action> actions = Stream.of(action1, action2).collect(Collectors.toList()); List<ActionDoc> actionDocs = Stream.of(doc1, doc2).collect(Collectors.toList()); - doReturn(actionDocs).when(cosmosStore).queryItems(anyString(), any(), any(), any(), any(), any()); + doReturn(actionDocs).when(cosmosStore).queryItems(eq(dataPartitionId), any(), any(), any(), any(), any()); List<Action> output = repo.getAllActions(); diff --git a/provider/register-azure/src/test/java/org/opengroup/osdu/register/provider/azure/ddms/DdmsRepositoryTest.java b/provider/register-azure/src/test/java/org/opengroup/osdu/register/provider/azure/ddms/DdmsRepositoryTest.java index 1edd43af47e5e7a815aa7d8473066da44a7128c1..36a0835b7a56da6faf75f75719950396ba4b3990 100644 --- a/provider/register-azure/src/test/java/org/opengroup/osdu/register/provider/azure/ddms/DdmsRepositoryTest.java +++ b/provider/register-azure/src/test/java/org/opengroup/osdu/register/provider/azure/ddms/DdmsRepositoryTest.java @@ -21,6 +21,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.opengroup.osdu.azure.CosmosStore; +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.register.ddms.model.Ddms; @@ -37,7 +38,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.lenient; @@ -56,6 +57,9 @@ public class DdmsRepositoryTest { @Mock private CosmosStore cosmosStore; + @Mock + private JaxRsDpsLog log; + @InjectMocks private DdmsRepository repo; @@ -69,7 +73,7 @@ public class DdmsRepositoryTest { Ddms ddms = createDdms(); Optional<DdmsDoc> cosmosItem = Optional.of(new DdmsDoc()); - doReturn(cosmosItem).when(cosmosStore).findItem(anyString(), any(), any(), anyString(), anyString(), any()); + doReturn(cosmosItem).when(cosmosStore).findItem(eq(dataPartitionId), any(), any(), eq(ddmsId), eq(dataPartitionId), any()); AppException exception = assertThrows(AppException.class, () -> { repo.create(ddms); @@ -77,7 +81,7 @@ public class DdmsRepositoryTest { assertEquals(409, exception.getError().getCode()); assertEquals("Conflict", exception.getError().getReason()); - assertEquals("A DDMS already exists with the same id", exception.getError().getMessage()); + assertEquals(String.format("A DDMS already exists with the same id: %s", ddms.getId()), exception.getError().getMessage()); verify(cosmosStore, times(1)).findItem(dataPartitionId, null, null, ddmsId, dataPartitionId, DdmsDoc.class); } @@ -86,8 +90,8 @@ public class DdmsRepositoryTest { Ddms ddms = createDdms(); Optional<DdmsDoc> cosmosItem = Optional.empty(); - doReturn(cosmosItem).when(cosmosStore).findItem(anyString(), any(), any(), anyString(), anyString(), any()); - doNothing().when(cosmosStore).upsertItem(anyString(), any(), any(), any()); + doReturn(cosmosItem).when(cosmosStore).findItem(eq(dataPartitionId), any(), any(), eq(ddmsId), eq(dataPartitionId), any()); + doNothing().when(cosmosStore).upsertItem(eq(dataPartitionId), any(), any(), any()); Ddms output = repo.create(ddms); @@ -98,7 +102,7 @@ public class DdmsRepositoryTest { @Test public void getDdms_throws404_whenIdNotFound() { - doReturn(Optional.empty()).when(cosmosStore).findItem(anyString(), any(), any(), anyString(), anyString(), any()); + doReturn(Optional.empty()).when(cosmosStore).findItem(eq(dataPartitionId), any(), any(), eq(ddmsId), eq(dataPartitionId), any()); AppException exception = assertThrows(AppException.class, () -> { repo.get(ddmsId); @@ -116,7 +120,7 @@ public class DdmsRepositoryTest { Ddms ddms = createDdms(); DdmsDoc doc = new DdmsDoc(ddms, dataPartitionId); - doReturn(Optional.of(doc)).when(cosmosStore).findItem(anyString(), any(), any(), anyString(), anyString(), any()); + doReturn(Optional.of(doc)).when(cosmosStore).findItem(eq(dataPartitionId), any(), any(), eq(ddmsId), eq(dataPartitionId), any()); Ddms output = repo.get(ddmsId); @@ -127,7 +131,7 @@ public class DdmsRepositoryTest { @Test public void deleteDdms_returnsFalse_whenIdNotFound() { - doReturn(Optional.empty()).when(cosmosStore).findItem(anyString(), any(), any(), anyString(), anyString(), any()); + doReturn(Optional.empty()).when(cosmosStore).findItem(eq(dataPartitionId), any(), any(), eq(ddmsId), eq(dataPartitionId), any()); boolean output = repo.delete(ddmsId); @@ -142,7 +146,7 @@ public class DdmsRepositoryTest { DdmsDoc doc = new DdmsDoc(ddms, dataPartitionId); Optional<DdmsDoc> cosmosItem = Optional.of(doc); - doReturn(cosmosItem).when(cosmosStore).findItem(anyString(), any(), any(), anyString(), anyString(), any()); + doReturn(cosmosItem).when(cosmosStore).findItem(eq(dataPartitionId), any(), any(), eq(ddmsId), eq(dataPartitionId), any()); boolean output = repo.delete(ddmsId); @@ -164,7 +168,7 @@ public class DdmsRepositoryTest { List<Ddms> ddmsList = Stream.of(ddms1, ddms2).collect(Collectors.toList()); List<DdmsDoc> ddmsDocList = Stream.of(doc1, doc2).collect(Collectors.toList()); - doReturn(ddmsDocList).when(cosmosStore).queryItems(anyString(), any(), any(), any(), any(), any()); + doReturn(ddmsDocList).when(cosmosStore).queryItems(eq(dataPartitionId), any(), any(), any(), any(), any()); List<Ddms> output = repo.query("type");