Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
Legal
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OSDU
OSDU Data Platform
Security and Compliance
Legal
Commits
fb4311c7
Commit
fb4311c7
authored
3 months ago
by
Isha Kumari
Browse files
Options
Downloads
Plain Diff
Merge branch 'cherry-pick-
635ad07f
' into 'Ibm_legal_coo_m24'
'coo_legal_service' changes into M24 branch See merge request
!623
parents
67a4f07e
bf7530c8
No related branches found
Branches containing commit
No related tags found
1 merge request
!623
'coo_legal_service' changes into M24 branch
Pipeline
#294122
canceled
3 months ago
Stage: build
Stage: coverage
Stage: scan
Stage: publish
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
provider/legal-ibm/src/main/java/org/opengroup/osdu/legal/ibm/countries/StorageReaderImpl.java
+20
-18
20 additions, 18 deletions
...opengroup/osdu/legal/ibm/countries/StorageReaderImpl.java
with
20 additions
and
18 deletions
provider/legal-ibm/src/main/java/org/opengroup/osdu/legal/ibm/countries/StorageReaderImpl.java
+
20
−
18
View file @
fb4311c7
...
...
@@ -7,10 +7,14 @@ import static com.cloudant.client.api.query.Expression.eq;
import
static
com
.
cloudant
.
client
.
api
.
query
.
Operation
.
and
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.lang.ref.WeakReference
;
import
java.net.MalformedURLException
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
java.util.concurrent.atomic.AtomicLong
;
import
com.google.gson.JsonParser
;
import
jakarta.inject.Inject
;
import
org.opengroup.osdu.core.common.logging.JaxRsDpsLog
;
...
...
@@ -42,7 +46,7 @@ public class StorageReaderImpl implements IStorageReader {
private
static
final
long
CACHE_EXPIRATION_MS
=
60000
;
private
AtomicLong
lastUpdate
=
new
AtomicLong
(
0
);
private
WeakReference
<
byte
[]>
cache
=
new
WeakReference
<
byte
[]>(
null
);
private
static
final
String
LEGAL_CONFIG_FILE_NAME
=
"legal.coo.json"
;
public
StorageReaderImpl
(
TenantInfo
tenantInfo
,
String
projectRegion
,
IBMCloudantClientFactory
cloudantFactory
,
String
dbNamePrefix
,
String
dbName
)
throws
MalformedURLException
,
FileNotFoundException
{
this
.
tenantInfo
=
tenantInfo
;
...
...
@@ -71,28 +75,26 @@ public class StorageReaderImpl implements IStorageReader {
}
try
{
Database
db
=
cloudantFactory
.
getDatabase
(
cloudant
,
dbNamePrefix
,
dbName
);
QueryResult
<
JsonObject
>
result
=
db
.
query
(
new
QueryBuilder
(
and
(
eq
(
"tenant"
,
tenantInfo
.
getName
()),
eq
(
"region"
,
cloudRegion
)))
.
fields
(
"name"
,
"alpha2"
,
"numeric"
,
"residencyRisk"
,
"typesNotApplyDataResidency"
).
build
(),
JsonObject
.
class
);
// The encapsulation of the Database class sucks in this case. If we could grab its internal
// import com.cloudant.client.org.lightcouch.CouchDbClient we could avoid de-serializing the
// response just to serialize it again.
JsonArray
array
=
new
JsonArray
();
for
(
JsonObject
s:
result
.
getDocs
())
{
array
.
add
(
s
);
}
byte
[]
blob
=
cloudant
.
getGson
().
toJson
(
array
).
getBytes
();
QueryResult
<
JsonObject
>
result
=
db
.
query
(
new
QueryBuilder
(
and
(
eq
(
"tenant"
,
tenantInfo
.
getName
()),
eq
(
"region"
,
cloudRegion
)))
.
fields
(
"name"
,
"alpha2"
,
"numeric"
,
"residencyRisk"
,
"typesNotApplyDataResidency"
).
build
(),
JsonObject
.
class
);
JsonArray
array
=
new
JsonArray
();
for
(
JsonObject
s:
result
.
getDocs
())
{
array
.
add
(
s
);
}
String
content
=
new
String
(
Files
.
readAllBytes
(
Paths
.
get
(
"/config/"
+
LEGAL_CONFIG_FILE_NAME
)));
JsonArray
data
=
JsonParser
.
parseString
(
content
).
getAsJsonArray
();
array
.
forEach
(
data:
:
add
);
byte
[]
blob
=
cloudant
.
getGson
().
toJson
(
data
).
getBytes
();
cache
=
new
WeakReference
<
byte
[]>(
blob
);
lastUpdate
.
set
(
System
.
currentTimeMillis
());
return
blob
;
}
catch
(
MalformedURL
Exception
e
)
{
logger
.
error
(
" 500,
Malformed URL Invalid cloudant URL
"
,
e
);
throw
new
AppException
(
500
,
"
Malformed URL
"
,
"Invalid cloudant URL"
,
e
);
}
catch
(
IO
Exception
e
)
{
logger
.
error
(
" 500,
IOException
"
,
e
);
throw
new
AppException
(
500
,
"
IOException
"
,
"Invalid cloudant URL"
,
e
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment