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 # Changelog for Accounting Library
## [v5.0.0] ## [v5.0.0-SNAPSHOT]
- removed old Providers - removed old Providers
- Added compatibility between smartgears 3 and smartgears 4 component
## [v4.2.0-SNAPSHOT]
-
## [v4.1.0] ## [v4.1.0]
- Deprecated not needed properties to reduce data and improve aggregation - Deprecated not needed properties to reduce data and improve aggregation

10
pom.xml
View File

@ -5,11 +5,11 @@
<parent> <parent>
<groupId>org.gcube.tools</groupId> <groupId>org.gcube.tools</groupId>
<artifactId>maven-parent</artifactId> <artifactId>maven-parent</artifactId>
<version>1.1.0</version> <version>1.2.0</version>
</parent> </parent>
<groupId>org.gcube.accounting</groupId> <groupId>org.gcube.accounting</groupId>
<artifactId>accounting-lib</artifactId> <artifactId>accounting-lib</artifactId>
<version>5.0.0</version> <version>5.0.0-SNAPSHOT</version>
<name>Accounting Library</name> <name>Accounting Library</name>
<description>Accounting Library</description> <description>Accounting Library</description>
<properties> <properties>
@ -53,12 +53,16 @@
<groupId>org.gcube.common</groupId> <groupId>org.gcube.common</groupId>
<artifactId>gcube-jackson-databind</artifactId> <artifactId>gcube-jackson-databind</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>common-utility-sg4</artifactId>
</dependency>
<!-- Test Dependencies -->
<dependency> <dependency>
<groupId>org.gcube.common.security</groupId> <groupId>org.gcube.common.security</groupId>
<artifactId>gcube-secrets</artifactId> <artifactId>gcube-secrets</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<!-- Test Dependencies -->
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <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.annotations.ValidOperationResult;
import org.gcube.accounting.datamodel.validations.validators.ValidOperationResultValidator; import org.gcube.accounting.datamodel.validations.validators.ValidOperationResultValidator;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore; import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
import org.gcube.common.security.providers.SecretManagerProvider; import org.gcube.common.context.ContextUtility;
import org.gcube.common.security.secrets.Secret;
import org.gcube.documentstore.exception.InvalidValueException; import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.implementation.AbstractRecord; import org.gcube.documentstore.records.implementation.AbstractRecord;
import org.gcube.documentstore.records.implementation.RequiredField; import org.gcube.documentstore.records.implementation.RequiredField;
@ -51,9 +50,9 @@ public abstract class BasicUsageRecord extends AbstractRecord implements UsageRe
super.init(); super.init();
// Backward compatibility // Backward compatibility
try { try {
Secret secret = SecretManagerProvider.instance.get(); String context = ContextUtility.getCurrentContextFullName();
this.setScope(secret.getContext()); this.setScope(context);
} catch (Exception e) { } catch (Throwable t) {
logger.warn( 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."); "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.List;
import java.util.Map; import java.util.Map;
import org.gcube.common.context.ContextUtility;
import org.gcube.common.encryption.encrypter.StringEncrypter; import org.gcube.common.encryption.encrypter.StringEncrypter;
import org.gcube.common.resources.gcore.ServiceEndpoint; import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint; import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.Property; import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
import org.gcube.common.resources.gcore.utils.Group; import org.gcube.common.resources.gcore.utils.Group;
import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.documentstore.persistence.PersistenceBackendConfiguration; import org.gcube.documentstore.persistence.PersistenceBackendConfiguration;
import org.gcube.resources.discovery.client.api.DiscoveryClient; import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery; import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
@ -41,7 +41,7 @@ public class AccountingPersistenceConfiguration extends PersistenceBackendConfig
public AccountingPersistenceConfiguration(Class<?> clz) throws Exception { public AccountingPersistenceConfiguration(Class<?> clz) throws Exception {
super(); super();
String context = SecretManagerProvider.instance.get().getContext(); String context = ContextUtility.getCurrentContextFullName();
try { try {
ServiceEndpoint serviceEndpoint = getServiceEndpoint(SERVICE_ENDPOINT_CATEGORY, SERVICE_ENDPOINT_NAME, clz); ServiceEndpoint serviceEndpoint = getServiceEndpoint(SERVICE_ENDPOINT_CATEGORY, SERVICE_ENDPOINT_NAME, clz);
setValues(serviceEndpoint, clz); setValues(serviceEndpoint, clz);
@ -66,7 +66,7 @@ public class AccountingPersistenceConfiguration extends PersistenceBackendConfig
DiscoveryClient<ServiceEndpoint> client = ICFactory.clientFor(ServiceEndpoint.class); DiscoveryClient<ServiceEndpoint> client = ICFactory.clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> serviceEndpoints = client.submit(query); List<ServiceEndpoint> serviceEndpoints = client.submit(query);
if(serviceEndpoints.size()>1){ 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/Name/text() eq '%s'", TARGET_SCOPE));
query.addCondition(String.format("$resource/Profile/AccessPoint/Properties/Property/Value/text() eq '%s'", scope)); query.addCondition(String.format("$resource/Profile/AccessPoint/Properties/Property/Value/text() eq '%s'", scope));
serviceEndpoints = client.submit(query); serviceEndpoints = client.submit(query);