diff --git a/partition-core/src/main/java/org/opengroup/osdu/partition/service/CachedPartitionServiceImpl.java b/partition-core/src/main/java/org/opengroup/osdu/partition/service/CachedPartitionServiceImpl.java index 2e889e647a3e4f4346a0f8e99a28e431a45d5161..a060902382b29112fed96fd9356377ef054aca61 100644 --- a/partition-core/src/main/java/org/opengroup/osdu/partition/service/CachedPartitionServiceImpl.java +++ b/partition-core/src/main/java/org/opengroup/osdu/partition/service/CachedPartitionServiceImpl.java @@ -49,7 +49,7 @@ public class CachedPartitionServiceImpl implements IPartitionService { PartitionInfo pi = partitionService.createPartition(partitionId, partitionInfo); if (pi != null) { - partitionServiceCache.put(partitionId, partitionInfo); + partitionServiceCache.put(partitionId, pi); partitionListCache.clearAll(); } diff --git a/provider/partition-gcp/README.md b/provider/partition-gcp/README.md index c8bae54083462d72b6ea65a077b7eabd0d9b03c0..d4dde2dda176f4e42ecc2aedade901f7cb353f80 100644 --- a/provider/partition-gcp/README.md +++ b/provider/partition-gcp/README.md @@ -161,16 +161,6 @@ Add **Cloud KMS CryptoKey Encrypter/Decrypter** role to the **App Engine default Add "Cloud KMS Encrypt/Decrypt" role to the "App Engine default service account" of ***master project*** -#### Memory Store (Redis Instance) Setup - -Create a new Standard tier Redis instance on the ***service project*** - -The Redis instance must be created under the same region with the App Engine application which needs to access it. - -```bash - gcloud beta redis instances create redis-cache-search --size=10 --region=<service-deployment-region> --zone=<service-deployment-zone> --tier=STANDARD -``` - ## Licence Copyright © Google LLC Copyright © EPAM Systems diff --git a/provider/partition-gcp/src/main/java/org/opengroup/osdu/partition/provider/gcp/service/PartitionServiceImpl.java b/provider/partition-gcp/src/main/java/org/opengroup/osdu/partition/provider/gcp/service/PartitionServiceImpl.java index c828ce8fc169e0778f0c1eecb271c8306b0fbc48..608b170ffe4ffe28569b8beee0e556a152cb167d 100644 --- a/provider/partition-gcp/src/main/java/org/opengroup/osdu/partition/provider/gcp/service/PartitionServiceImpl.java +++ b/provider/partition-gcp/src/main/java/org/opengroup/osdu/partition/provider/gcp/service/PartitionServiceImpl.java @@ -63,7 +63,7 @@ public class PartitionServiceImpl implements IPartitionService { repository.saveAll(partitionProperties); return true; }); - return getEncryptedPartition(partitionId); + return getPartition(partitionId); } private void encryptPartitionPropertyEntityIfNeeded(PartitionPropertyEntity entity) { @@ -78,28 +78,11 @@ public class PartitionServiceImpl implements IPartitionService { } } - private PartitionInfo getEncryptedPartition(String partitionId) { - List<PartitionPropertyEntity> partitionPropertiesList = this.partitionPropertyEntityRepository - .findByPartitionId(partitionId) - .orElseThrow( - () -> new AppException(HttpStatus.SC_NOT_FOUND, UNKNOWN_ERROR_REASON, - "Partition does not exist.")); - PartitionInfo partitionInfo = new PartitionInfo(); - Map<String, Property> partitionInfoProperties = new HashMap<>(); - for (PartitionPropertyEntity entity : partitionPropertiesList) { - partitionInfoProperties - .put(entity.getName(), new Property(entity.getSensitive(), entity.getValue())); - } - partitionInfo.setProperties(partitionInfoProperties); - - return partitionInfo; - } - - @Transactional @Override public PartitionInfo updatePartition(String partitionId, PartitionInfo partitionInfo) { - if(partitionInfo.getProperties().containsKey("id")) { - throw new AppException(HttpStatus.SC_BAD_REQUEST, "can not update id", "the field id can not be updated"); + if (partitionInfo.getProperties().containsKey("id")) { + throw new AppException(HttpStatus.SC_BAD_REQUEST, "can not update id", + "the field id can not be updated"); } if (!this.partitionPropertyEntityRepository.findByPartitionId(partitionId).isPresent()) { @@ -120,11 +103,13 @@ public class PartitionServiceImpl implements IPartitionService { encryptPartitionPropertyEntityIfNeeded(entity); partitionProperties.add(entity); } - this.partitionPropertyEntityRepository.saveAll(partitionProperties); - return getEncryptedPartition(partitionId); + this.partitionPropertyEntityRepository.performTransaction(repository -> { + repository.saveAll(partitionProperties); + return true; + }); + return getPartition(partitionId); } - @Transactional @Override public PartitionInfo getPartition(String partitionId) { PartitionInfo partitionInfo = getEncryptedPartition(partitionId); @@ -134,6 +119,23 @@ public class PartitionServiceImpl implements IPartitionService { return partitionInfo; } + private PartitionInfo getEncryptedPartition(String partitionId) { + List<PartitionPropertyEntity> partitionPropertiesList = this.partitionPropertyEntityRepository + .findByPartitionId(partitionId) + .orElseThrow( + () -> new AppException(HttpStatus.SC_NOT_FOUND, UNKNOWN_ERROR_REASON, + "Partition does not exist.")); + PartitionInfo partitionInfo = new PartitionInfo(); + Map<String, Property> partitionInfoProperties = new HashMap<>(); + for (PartitionPropertyEntity entity : partitionPropertiesList) { + partitionInfoProperties + .put(entity.getName(), new Property(entity.getSensitive(), entity.getValue())); + } + partitionInfo.setProperties(partitionInfoProperties); + + return partitionInfo; + } + private void decryptPartitionPropertyIfNeeded(Property property) { if (property.isSensitive()) { String propertyValue = property.getValue().toString(); diff --git a/testing/partition-test-gcp/src/test/java/org/opengroup/osdu/partition/api/TestCreatePartition.java b/testing/partition-test-gcp/src/test/java/org/opengroup/osdu/partition/api/TestCreatePartition.java index 07090d93b9e29977968fd56269a73a7df527a57c..31b9eb1f65216e0a8be37e7cffee36c056f72f8b 100644 --- a/testing/partition-test-gcp/src/test/java/org/opengroup/osdu/partition/api/TestCreatePartition.java +++ b/testing/partition-test-gcp/src/test/java/org/opengroup/osdu/partition/api/TestCreatePartition.java @@ -17,8 +17,12 @@ package org.opengroup.osdu.partition.api; +import static org.junit.Assert.assertEquals; + +import com.sun.jersey.api.client.ClientResponse; import org.junit.After; import org.junit.Before; +import org.junit.Test; import org.opengroup.osdu.partition.util.GCPTestUtils; public class TestCreatePartition extends CreatePartitionTest { @@ -34,4 +38,12 @@ public class TestCreatePartition extends CreatePartitionTest { public void tearDown() throws Exception { this.testUtils = null; } + + @Override + @Test + public void should_return40XResponseCode_when_makingRequest_withInvalidPayload() throws Exception { + String invalidPayload = "invalidPayload"; + ClientResponse response = descriptor.runWithCustomPayload(getId(), invalidPayload, testUtils.getAccessToken()); + assertEquals(400, response.getStatus()); + } }