Fixing code

This commit is contained in:
Luca Frosini 2024-04-24 16:37:41 +02:00
parent 7ecf6a2f77
commit 0c547f14e3
4 changed files with 16 additions and 16 deletions

View File

@ -2,15 +2,12 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
# Changelog for Accounting Library
## [v5.0.0]
## [v5.0.0-SNAPSHOT]
- removed old Providers
- Added compatibility between smartgears 3 and smartgears 4 component
## [v4.2.0-SNAPSHOT]
-
## [v4.1.0]
- Deprecated not needed properties to reduce data and improve aggregation

10
pom.xml
View File

@ -5,11 +5,11 @@
<parent>
<groupId>org.gcube.tools</groupId>
<artifactId>maven-parent</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
</parent>
<groupId>org.gcube.accounting</groupId>
<artifactId>accounting-lib</artifactId>
<version>5.0.0</version>
<version>5.0.0-SNAPSHOT</version>
<name>Accounting Library</name>
<description>Accounting Library</description>
<properties>
@ -53,12 +53,16 @@
<groupId>org.gcube.common</groupId>
<artifactId>gcube-jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>common-utility-sg4</artifactId>
</dependency>
<!-- Test Dependencies -->
<dependency>
<groupId>org.gcube.common.security</groupId>
<artifactId>gcube-secrets</artifactId>
<scope>test</scope>
</dependency>
<!-- Test Dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>

View File

@ -10,8 +10,7 @@ import java.util.SortedSet;
import org.gcube.accounting.datamodel.validations.annotations.ValidOperationResult;
import org.gcube.accounting.datamodel.validations.validators.ValidOperationResultValidator;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.common.security.secrets.Secret;
import org.gcube.common.context.ContextUtility;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.implementation.AbstractRecord;
import org.gcube.documentstore.records.implementation.RequiredField;
@ -51,9 +50,9 @@ public abstract class BasicUsageRecord extends AbstractRecord implements UsageRe
super.init();
// Backward compatibility
try {
Secret secret = SecretManagerProvider.instance.get();
this.setScope(secret.getContext());
} catch (Exception e) {
String context = ContextUtility.getCurrentContextFullName();
this.setScope(context);
} catch (Throwable t) {
logger.warn(
"Unable to automaticcally set the scope using scope provider. The record will not be valid if the scope will not be explicitly set.");
}

View File

@ -6,12 +6,12 @@ package org.gcube.accounting.persistence;
import java.util.List;
import java.util.Map;
import org.gcube.common.context.ContextUtility;
import org.gcube.common.encryption.encrypter.StringEncrypter;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
import org.gcube.common.resources.gcore.utils.Group;
import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.documentstore.persistence.PersistenceBackendConfiguration;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
@ -41,7 +41,7 @@ public class AccountingPersistenceConfiguration extends PersistenceBackendConfig
public AccountingPersistenceConfiguration(Class<?> clz) throws Exception {
super();
String context = SecretManagerProvider.instance.get().getContext();
String context = ContextUtility.getCurrentContextFullName();
try {
ServiceEndpoint serviceEndpoint = getServiceEndpoint(SERVICE_ENDPOINT_CATEGORY, SERVICE_ENDPOINT_NAME, clz);
setValues(serviceEndpoint, clz);
@ -66,7 +66,7 @@ public class AccountingPersistenceConfiguration extends PersistenceBackendConfig
DiscoveryClient<ServiceEndpoint> client = ICFactory.clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> serviceEndpoints = client.submit(query);
if(serviceEndpoints.size()>1){
String scope = SecretManagerProvider.instance.get().getContext();
String scope = ContextUtility.getCurrentContextFullName();
query.addCondition(String.format("$resource/Profile/AccessPoint/Properties/Property/Name/text() eq '%s'", TARGET_SCOPE));
query.addCondition(String.format("$resource/Profile/AccessPoint/Properties/Property/Value/text() eq '%s'", scope));
serviceEndpoints = client.submit(query);