Commit 49a86b3c authored by Anastasiia Gelmut's avatar Anastasiia Gelmut
Browse files

GONRG-1191 Implement Partition Service

-PartitionService implementation is fixed.
parent e0725552
......@@ -19,16 +19,9 @@ package org.opengroup.osdu.partition.provider.gcp.security;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
import org.opengroup.osdu.core.common.entitlements.IEntitlementsFactory;
import org.opengroup.osdu.core.common.entitlements.IEntitlementsService;
import org.opengroup.osdu.core.common.http.HttpResponse;
import org.opengroup.osdu.core.common.model.entitlements.EntitlementsException;
import org.opengroup.osdu.core.common.model.entitlements.Groups;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.partition.provider.interfaces.IAuthorizationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;
......@@ -39,25 +32,22 @@ import org.springframework.web.context.annotation.RequestScope;
@RequiredArgsConstructor
public class AuthorizationService implements IAuthorizationService {
private static final String ERROR_REASON = "Access denied";
private static final String ERROR_MSG = "The user is not authorized to perform this action";
private static final String PARTITION_ADMIN_ROLE = "service.partition.admin";
private static final String PARTITION_ADMIN_ROLE = "service.partition.admin";
private final DpsHeaders headers;
private final DpsHeaders headers;
private final org.opengroup.osdu.core.common.provider.interfaces.IAuthorizationService authorizationService;
private final org.opengroup.osdu.core.common.provider.interfaces.IAuthorizationService authorizationService;
@Override
public boolean isDomainAdminServiceAccount() {
try {
authorizationService.authorizeAny(headers,PARTITION_ADMIN_ROLE);
} catch (AppException e) {
throw e;
} catch (Exception e) {
throw new AppException(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Authentication Failure",
e.getMessage(), e);
}
return true;
}
@Override
public boolean isDomainAdminServiceAccount() {
try {
authorizationService.authorizeAny(headers, PARTITION_ADMIN_ROLE);
} catch (AppException e) {
throw e;
} catch (Exception e) {
throw new AppException(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Authentication Failure",
e.getMessage(), e);
}
return true;
}
}
......@@ -18,6 +18,7 @@
package org.opengroup.osdu.partition.provider.gcp.service;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -48,16 +49,18 @@ public class PartitionServiceImpl implements IPartitionService {
@Override
public PartitionInfo createPartition(String partitionId, PartitionInfo partitionInfo) {
if (this.partitionPropertyEntityRepository.findByPartitionId(partitionId).isPresent()) {
throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, UNKNOWN_ERROR_REASON,
throw new AppException(HttpStatus.SC_CONFLICT, UNKNOWN_ERROR_REASON,
"Partition already exists.");
}
List<PartitionPropertyEntity> partitionProperties = new ArrayList<>();
for (Map.Entry<String, Property> entry : partitionInfo.getProperties().entrySet()) {
PartitionPropertyEntity entity = new PartitionPropertyEntity(partitionId,
entry.getKey(), entry.getValue());
encryptPartitionPropertyEntityIfNeeded(entity);
partitionProperties.add(entity);
}
this.partitionPropertyEntityRepository.performTransaction(repository -> {
for (Map.Entry<String, Property> entry : partitionInfo.getProperties().entrySet()) {
PartitionPropertyEntity entity = new PartitionPropertyEntity(partitionId,
entry.getKey(), entry.getValue());
encryptPartitionPropertyEntityIfNeeded(entity);
repository.save(entity);
}
repository.saveAll(partitionProperties);
return true;
});
return getEncryptedPartition(partitionId);
......@@ -99,6 +102,7 @@ public class PartitionServiceImpl implements IPartitionService {
.orElseThrow(
() -> new AppException(HttpStatus.SC_NOT_FOUND, UNKNOWN_ERROR_REASON,
"An attempt to update not existing partition."));
List<PartitionPropertyEntity> partitionProperties = new ArrayList<>();
for (Map.Entry<String, Property> entry : partitionInfo.getProperties().entrySet()) {
PartitionPropertyEntity entity = this.partitionPropertyEntityRepository
.findByPartitionIdAndName(partitionId, entry.getKey());
......@@ -109,8 +113,9 @@ public class PartitionServiceImpl implements IPartitionService {
entity = new PartitionPropertyEntity(partitionId, entry.getKey(), entry.getValue());
}
encryptPartitionPropertyEntityIfNeeded(entity);
this.partitionPropertyEntityRepository.save(entity);
partitionProperties.add(entity);
}
this.partitionPropertyEntityRepository.saveAll(partitionProperties);
return getEncryptedPartition(partitionId);
}
......
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