Skip to content
Snippets Groups Projects
Commit 56f560b1 authored by Riabokon Stanislav(EPAM)[GCP]'s avatar Riabokon Stanislav(EPAM)[GCP]
Browse files

Merge branch 'feature/GONRG-1599_Fixed_PartitionServiceImpl' into 'integration-master'

GONRG-1599 Fixed PartitionServiceImpl.

See merge request go3-nrg/platform/System/partition!19
parents 0202f592 1af924e8
No related branches found
No related tags found
4 merge requests!47Authentication for PartitionService to work under SA(GONRG-1843),!45(GONRG-2074) GCP incorrect response,!36Partition: Audit Logs Implementation (GONRG-1607),!35Partition Service for GCP (GONRG-1706)
Pipeline #23951 failed
......@@ -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();
}
......
......@@ -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
......
......@@ -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();
......
......@@ -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());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment