Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openbis
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sispub
openbis
Commits
8c7f85ae
Commit
8c7f85ae
authored
1 year ago
by
juanf
Browse files
Options
Downloads
Patches
Plain Diff
SSDM-13251: Changes from code review
parent
e193048c
No related branches found
No related tags found
1 merge request
!40
SSDM-13578 : 2PT : Database and V3 Implementation - include the new AFS "free"...
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
api-data-store-server-java/src/main/java/ch/ethz/sis/afsclient/client/AfsClientV2.java
+15
-13
15 additions, 13 deletions
...c/main/java/ch/ethz/sis/afsclient/client/AfsClientV2.java
with
15 additions
and
13 deletions
api-data-store-server-java/src/main/java/ch/ethz/sis/afsclient/client/AfsClientV2.java
+
15
−
13
View file @
8c7f85ae
...
...
@@ -17,10 +17,7 @@ import java.net.http.HttpRequest;
import
java.net.http.HttpResponse
;
import
java.nio.charset.StandardCharsets
;
import
java.time.Duration
;
import
java.util.AbstractMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.UUID
;
import
java.util.*
;
import
java.util.stream.Stream
;
public
final
class
AfsClientV2
implements
PublicAPI
...
...
@@ -155,7 +152,7 @@ public final class AfsClientV2 implements PublicAPI
{
validateSessionToken
();
return
request
(
"POST"
,
"write"
,
Boolean
.
class
,
Map
.
of
(
"owner"
,
owner
,
"source"
,
source
,
"offset"
,
offset
.
toString
(),
"md5Hash"
,
getMd5HexString
(
md5Hash
))
,
data
);
"offset"
,
offset
.
toString
(),
"data"
,
Base64
.
getEncoder
().
encodeToString
(
data
),
"md5Hash"
,
getMd5HexString
(
md5Hash
)));
}
@Override
...
...
@@ -223,15 +220,10 @@ public final class AfsClientV2 implements PublicAPI
return
request
(
"POST"
,
"recover"
,
List
.
class
,
Map
.
of
());
}
private
<
T
>
T
request
(
@NonNull
final
String
httpMethod
,
@NonNull
final
String
apiMethod
,
Class
<
T
>
responseType
,
@NonNull
final
Map
<
String
,
String
>
parameters
)
throws
Exception
{
return
request
(
httpMethod
,
apiMethod
,
responseType
,
parameters
,
new
byte
[
0
]);
}
@SuppressWarnings
({
"OptionalGetWithoutIsPresent"
,
"unchecked"
})
private
<
T
>
T
request
(
@NonNull
final
String
httpMethod
,
@NonNull
final
String
apiMethod
,
Class
<
T
>
responseType
,
@NonNull
final
Map
<
String
,
String
>
params
,
final
byte
@NonNull
[]
body
)
@NonNull
final
Map
<
String
,
String
>
params
)
throws
Exception
{
HttpClient
.
Builder
clientBuilder
=
HttpClient
.
newBuilder
()
...
...
@@ -256,17 +248,27 @@ public final class AfsClientV2 implements PublicAPI
params
.
put
(
"transactionManagerKey"
,
transactionManagerKey
);
}
final
String
qu
er
y
=
Stream
.
concat
(
String
paramet
er
s
=
Stream
.
concat
(
Stream
.
of
(
new
AbstractMap
.
SimpleImmutableEntry
<>(
"method"
,
apiMethod
)),
params
.
entrySet
().
stream
())
.
map
(
entry
->
{
return
urlEncode
(
entry
.
getKey
())
+
"="
+
urlEncode
(
entry
.
getValue
());
})
.
reduce
((
s1
,
s2
)
->
s1
+
"&"
+
s2
).
get
();
// GET Request - Parameters on the query string
String
queryParameters
=
null
;
if
(
httpMethod
.
equals
(
"GET"
))
{
queryParameters
=
parameters
;
}
// POST Request - Parameters on body
byte
[]
body
=
null
;
if
(
httpMethod
.
equals
(
"POST"
))
{
body
=
parameters
.
getBytes
(
StandardCharsets
.
UTF_8
);
}
final
URI
uri
=
new
URI
(
serverUri
.
getScheme
(),
null
,
serverUri
.
getHost
(),
serverUri
.
getPort
(),
serverUri
.
getPath
(),
query
,
null
);
serverUri
.
getPath
(),
query
Parameters
,
null
);
HttpRequest
.
Builder
builder
=
HttpRequest
.
newBuilder
()
.
uri
(
uri
)
...
...
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