Commit f1b3adb4 authored by Anastasiia Gelmut's avatar Anastasiia Gelmut
Browse files

GONRG-1599 Fixed PartitionServiceImpl.

Fixed readme.
parent 0202f592
......@@ -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();
......
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