Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
Java Client API
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
2
Issues
2
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Genesys PGR
Java Client API
Commits
df9d1936
Commit
df9d1936
authored
Apr 15, 2015
by
Matija Obreza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
JAutodoc
parent
9aceab50
Changes
19
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
1069 additions
and
103 deletions
+1069
-103
src/main/java/org/genesys2/client/oauth/CLI.java
src/main/java/org/genesys2/client/oauth/CLI.java
+108
-3
src/main/java/org/genesys2/client/oauth/GenesysApiException.java
...n/java/org/genesys2/client/oauth/GenesysApiException.java
+1
-0
src/main/java/org/genesys2/client/oauth/GenesysClient.java
src/main/java/org/genesys2/client/oauth/GenesysClient.java
+63
-22
src/main/java/org/genesys2/client/oauth/GenesysTokens.java
src/main/java/org/genesys2/client/oauth/GenesysTokens.java
+42
-1
src/main/java/org/genesys2/client/oauth/HttpRedirectException.java
...java/org/genesys2/client/oauth/HttpRedirectException.java
+31
-0
src/main/java/org/genesys2/client/oauth/OAuthAuthenticationException.java
...g/genesys2/client/oauth/OAuthAuthenticationException.java
+1
-0
src/main/java/org/genesys2/client/oauth/PleaseRetryException.java
.../java/org/genesys2/client/oauth/PleaseRetryException.java
+2
-0
src/main/java/org/genesys2/client/oauth/api/GenesysApi.java
src/main/java/org/genesys2/client/oauth/api/GenesysApi.java
+7
-4
src/main/java/org/genesys2/client/oauth/api/accession/AccessionJson.java
...rg/genesys2/client/oauth/api/accession/AccessionJson.java
+340
-0
src/main/java/org/genesys2/client/oauth/api/accession/Api1Constants.java
...rg/genesys2/client/oauth/api/accession/Api1Constants.java
+36
-72
src/main/java/org/genesys2/client/oauth/api/accession/CollectingJson.java
...g/genesys2/client/oauth/api/accession/CollectingJson.java
+99
-0
src/main/java/org/genesys2/client/oauth/api/accession/GeoJson.java
...java/org/genesys2/client/oauth/api/accession/GeoJson.java
+75
-0
src/main/java/org/genesys2/client/oauth/api/accession/Remark.java
.../java/org/genesys2/client/oauth/api/accession/Remark.java
+27
-0
src/test/java/org/geneys2/client/oauth/AccessionApiTest.java
src/test/java/org/geneys2/client/oauth/AccessionApiTest.java
+45
-0
src/test/java/org/geneys2/client/oauth/ApiTest.java
src/test/java/org/geneys2/client/oauth/ApiTest.java
+70
-0
src/test/java/org/geneys2/client/oauth/JsonNodeMatchers.java
src/test/java/org/geneys2/client/oauth/JsonNodeMatchers.java
+25
-0
src/test/java/org/geneys2/client/oauth/MockGenesysException.java
...t/java/org/geneys2/client/oauth/MockGenesysException.java
+11
-0
src/test/java/org/geneys2/client/oauth/MockGenesysServer.java
...test/java/org/geneys2/client/oauth/MockGenesysServer.java
+58
-1
src/test/java/org/geneys2/client/oauth/ModelTests.java
src/test/java/org/geneys2/client/oauth/ModelTests.java
+28
-0
No files found.
src/main/java/org/genesys2/client/oauth/CLI.java
View file @
df9d1936
...
...
@@ -47,23 +47,31 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import
com.fasterxml.jackson.databind.node.TextNode
;
/**
* Simple command line interface to Genesys
*
* Simple command line interface to Genesys
.
*
* @author matijaobreza
*
*/
public
class
CLI
{
/** The Constant _log. */
private
static
final
Logger
_log
=
LogManager
.
getLogger
(
CLI
.
class
);
/** The properties file. */
private
File
propertiesFile
;
/** The properties. */
private
Properties
properties
;
/** The in. */
private
Scanner
in
=
new
Scanner
(
System
.
in
);
/** The mapper. */
private
static
ObjectMapper
mapper
=
new
ObjectMapper
();
/** The genesys client. */
private
GenesysClient
genesysClient
=
new
GenesysClient
();
/** The ignored fields. */
private
static
Set
<
String
>
ignoredFields
;
static
{
...
...
@@ -76,6 +84,11 @@ public class CLI {
ignoredFields
.
add
(
"version"
);
}
/**
* The main method.
*
* @param args the arguments
*/
public
static
void
main
(
String
[]
args
)
{
_log
.
info
(
"Hello World!"
);
...
...
@@ -84,6 +97,9 @@ public class CLI {
cli
.
run
();
}
/**
* Run.
*/
private
void
run
()
{
checkPreconditions
();
...
...
@@ -115,6 +131,13 @@ public class CLI {
}
}
/**
* Do work.
*
* @throws GenesysApiException the genesys api exception
* @throws PleaseRetryException the please retry exception
* @throws IOException Signals that an I/O exception has occurred.
*/
private
void
doWork
()
throws
GenesysApiException
,
PleaseRetryException
,
IOException
{
String
line
=
null
;
do
{
...
...
@@ -136,6 +159,12 @@ public class CLI {
}
while
(!
"Q"
.
equalsIgnoreCase
(
line
));
}
/**
* Update json data.
*
* @param label the label
* @param n the n
*/
private
void
updateJsonData
(
String
label
,
JsonNode
n
)
{
if
(
n
.
isArray
())
{
updateJsonArray
(
label
,
(
ArrayNode
)
n
);
...
...
@@ -144,6 +173,12 @@ public class CLI {
}
}
/**
* Update json object.
*
* @param label the label
* @param n the n
*/
private
void
updateJsonObject
(
String
label
,
JsonNode
n
)
{
Iterator
<
Entry
<
String
,
JsonNode
>>
f
=
n
.
fields
();
...
...
@@ -182,6 +217,12 @@ public class CLI {
System
.
out
.
println
(
"Done editing "
+
label
);
}
/**
* Update json array.
*
* @param label the label
* @param n the n
*/
private
void
updateJsonArray
(
String
label
,
ArrayNode
n
)
{
System
.
out
.
println
(
"Array: "
+
n
);
ArrayNode
na
=
n
.
arrayNode
();
...
...
@@ -221,6 +262,11 @@ public class CLI {
System
.
out
.
println
(
"Done editing array "
+
label
);
}
/**
* Do custom.
*
* @throws GenesysApiException the genesys api exception
*/
private
void
doCustom
()
throws
GenesysApiException
{
System
.
out
.
print
(
"URL: "
);
String
url
=
in
.
nextLine
();
...
...
@@ -233,6 +279,11 @@ public class CLI {
System
.
out
.
println
(
genesysClient
.
query
(
Verb
.
valueOf
(
method
),
url
,
null
,
data
));
}
/**
* Do crops.
*
* @throws GenesysApiException the genesys api exception
*/
private
void
doCrops
()
throws
GenesysApiException
{
String
line
=
null
;
do
{
...
...
@@ -255,6 +306,11 @@ public class CLI {
}
while
(!(
"0"
.
equalsIgnoreCase
(
line
)));
}
/**
* Update crop rules.
*
* @throws GenesysApiException the genesys api exception
*/
private
void
updateCropRules
()
throws
GenesysApiException
{
System
.
out
.
println
(
"Crop shortName: "
);
String
shortName
=
in
.
nextLine
().
trim
();
...
...
@@ -283,6 +339,11 @@ public class CLI {
+
genesysClient
.
query
(
Verb
.
POST
,
"/crops/"
+
shortName
+
"/rules"
,
null
,
arr
.
toString
()));
}
/**
* Update crop.
*
* @throws GenesysApiException the genesys api exception
*/
private
void
updateCrop
()
throws
GenesysApiException
{
System
.
out
.
println
(
"Crop shortName: "
);
String
shortName
=
in
.
nextLine
().
trim
();
...
...
@@ -313,6 +374,11 @@ public class CLI {
System
.
out
.
println
(
"Put method: "
+
genesysClient
.
query
(
Verb
.
PUT
,
"/crops"
,
null
,
cropJson
.
toString
()));
}
/**
* Do traits.
*
* @throws GenesysApiException the genesys api exception
*/
private
void
doTraits
()
throws
GenesysApiException
{
String
line
=
null
;
do
{
...
...
@@ -336,6 +402,11 @@ public class CLI {
}
while
(!(
"0"
.
equalsIgnoreCase
(
line
)));
}
/**
* Do datasets.
*
* @throws GenesysApiException the genesys api exception
*/
private
void
doDatasets
()
throws
GenesysApiException
{
String
line
=
null
;
do
{
...
...
@@ -359,6 +430,11 @@ public class CLI {
}
while
(!(
"0"
.
equalsIgnoreCase
(
line
)));
}
/**
* Adds the method.
*
* @throws GenesysApiException the genesys api exception
*/
private
void
addMethod
()
throws
GenesysApiException
{
ObjectNode
datasetJson
=
mapper
.
createObjectNode
();
System
.
out
.
println
(
"Method description: "
);
...
...
@@ -392,6 +468,11 @@ public class CLI {
}
/**
* Adds the dataset.
*
* @throws GenesysApiException the genesys api exception
*/
private
void
addDataset
()
throws
GenesysApiException
{
ObjectNode
datasetJson
=
mapper
.
createObjectNode
();
System
.
out
.
println
(
"WIEWS Code: "
);
...
...
@@ -410,6 +491,11 @@ public class CLI {
}
/**
* Adds the dataset data.
*
* @throws GenesysApiException the genesys api exception
*/
private
void
addDatasetData
()
throws
GenesysApiException
{
ObjectNode
datasetJson
=
mapper
.
createObjectNode
();
...
...
@@ -428,6 +514,11 @@ public class CLI {
+
genesysClient
.
query
(
Verb
.
PUT
,
"/datasets/"
+
datasetId
+
"/data"
,
null
,
datasetJson
.
toString
()));
}
/**
* Adds the dataset raw.
*
* @throws GenesysApiException the genesys api exception
*/
private
void
addDatasetRaw
()
throws
GenesysApiException
{
System
.
out
.
println
(
"Dataset ID: "
);
long
datasetId
=
Long
.
parseLong
(
in
.
nextLine
());
...
...
@@ -442,6 +533,9 @@ public class CLI {
+
genesysClient
.
query
(
Verb
.
PUT
,
"/datasets/"
+
datasetId
+
"/data"
,
null
,
json
));
}
/**
* Check preconditions.
*/
private
void
checkPreconditions
()
{
boolean
restart
=
false
;
if
(
StringUtils
.
isBlank
(
properties
.
getProperty
(
"client.key"
)))
{
...
...
@@ -469,6 +563,9 @@ public class CLI {
}
}
/**
* Authenticate.
*/
private
void
authenticate
()
{
String
authorizationUrl
=
genesysClient
.
getAuthorizationUrl
();
...
...
@@ -487,6 +584,9 @@ public class CLI {
saveProperties
();
}
/**
* Save properties.
*/
private
void
saveProperties
()
{
FileOutputStream
fis
=
null
;
try
{
...
...
@@ -499,6 +599,11 @@ public class CLI {
}
}
/**
* Load properties.
*
* @param propertiesFileName the properties file name
*/
private
void
loadProperties
(
String
propertiesFileName
)
{
// .properties file location
propertiesFile
=
new
File
(
propertiesFileName
);
...
...
src/main/java/org/genesys2/client/oauth/GenesysApiException.java
View file @
df9d1936
...
...
@@ -21,6 +21,7 @@ package org.genesys2.client.oauth;
*/
public
class
GenesysApiException
extends
Exception
{
/** The Constant serialVersionUID. */
private
static
final
long
serialVersionUID
=
-
6008425446284829953L
;
/**
...
...
src/main/java/org/genesys2/client/oauth/GenesysClient.java
View file @
df9d1936
...
...
@@ -49,6 +49,7 @@ import com.fasterxml.jackson.databind.SerializationFeature;
import
com.fasterxml.jackson.databind.node.ArrayNode
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
// TODO: Auto-generated Javadoc
/**
* Genesys API client using Scribe.
*/
...
...
@@ -66,7 +67,7 @@ public class GenesysClient {
/** The service. */
private
OAuthService
service
;
/**
GenesysTokens: access- and refreshToken
*/
/**
GenesysTokens: access- and refreshToken.
*/
private
GenesysTokens
tokens
=
new
GenesysTokens
();
/** The genesys api. */
...
...
@@ -78,10 +79,10 @@ public class GenesysClient {
/** The api secret. */
private
String
apiSecret
;
/**
Socket connect timeout
*/
/**
Socket connect timeout.
*/
private
int
connectTimeout
=
20
;
/**
Socket read timeout
*/
/**
Socket read timeout.
*/
private
int
readTimeout
=
120
;
static
{
...
...
@@ -97,18 +98,38 @@ public class GenesysClient {
public
GenesysClient
()
{
}
/**
* Sets the read timeout.
*
* @param readTimeout the new read timeout
*/
public
void
setReadTimeout
(
int
readTimeout
)
{
this
.
readTimeout
=
readTimeout
;
}
/**
* Gets the read timeout.
*
* @return the read timeout
*/
public
int
getReadTimeout
()
{
return
readTimeout
;
}
/**
* Sets the connect timeout.
*
* @param connectTimeout the new connect timeout
*/
public
void
setConnectTimeout
(
int
connectTimeout
)
{
this
.
connectTimeout
=
connectTimeout
;
}
/**
* Gets the connect timeout.
*
* @return the connect timeout
*/
public
int
getConnectTimeout
()
{
return
connectTimeout
;
}
...
...
@@ -188,10 +209,20 @@ public class GenesysClient {
.
callback
(
callback
).
scope
(
SCOPE
).
build
();
}
/**
* Sets the tokens.
*
* @param tokens the new tokens
*/
public
void
setTokens
(
GenesysTokens
tokens
)
{
this
.
tokens
=
tokens
;
}
/**
* Gets the tokens.
*
* @return the tokens
*/
public
GenesysTokens
getTokens
()
{
return
tokens
;
}
...
...
@@ -219,6 +250,7 @@ public class GenesysClient {
* @return the string
* @throws OAuthAuthenticationException the o auth authentication exception
* @throws PleaseRetryException the please retry exception
* @throws HttpRedirectException the http redirect exception
* @throws GenesysApiException the genesys api exception
*/
public
String
query
(
Verb
method
,
String
url
,
Map
<
String
,
String
>
queryString
,
String
postBody
)
...
...
@@ -311,8 +343,8 @@ public class GenesysClient {
/**
* Refresh accessToken with refreshToken.
*
* @throws GenesysApiException
*
* @throws GenesysApiException
the genesys api exception
*/
public
void
refreshAccessToken
()
throws
GenesysApiException
{
if
(
tokens
.
hasRefreshToken
())
{
...
...
@@ -371,15 +403,14 @@ public class GenesysClient {
}
/**
* Update MLS status of accessions
* Update MLS status of accessions
.
*
* @param instCode the inst code
* @param accns the accns
* @return the string
* @throws GenesysApiException the genesys api exception
* @throws JsonProcessingException
* @throws PleaseRetryException
*
* @throws PleaseRetryException the please retry exception
* @throws JsonProcessingException the json processing exception
* @deprecated Please use {@link #updateAccessions(String, Collection)} with
* only the instCode, acceNumb, (genus, ) and mlsStat provided.
*/
...
...
@@ -422,6 +453,16 @@ public class GenesysClient {
throw
new
RuntimeException
(
"All retries failed"
);
}
/**
* Update accessions.
*
* @param instCode the inst code
* @param accns the accns
* @return the string
* @throws GenesysApiException the genesys api exception
* @throws InterruptedException the interrupted exception
* @throws JsonProcessingException the json processing exception
*/
public
String
updateAccessions
(
String
instCode
,
Collection
<
AccessionJson
>
accns
)
throws
GenesysApiException
,
InterruptedException
,
JsonProcessingException
{
...
...
@@ -496,11 +537,11 @@ public class GenesysClient {
/**
* Delete accessions from Genesys by ID-triplet (INSTCODE, ACCENUMB, GENUS).
*
* @param instCode
* @param jsonAccessionId3List
* @return
* @throws GenesysApiException
*
* @param instCode
the inst code
* @param jsonAccessionId3List
the json accession id3 list
* @return
the string
* @throws GenesysApiException
the genesys api exception
*/
public
String
deleteAccessionsByName
(
String
instCode
,
String
jsonAccessionId3List
)
throws
GenesysApiException
{
return
query
(
Verb
.
POST
,
"/acn/"
+
instCode
+
"/delete-named"
,
null
,
jsonAccessionId3List
);
...
...
@@ -525,14 +566,14 @@ public class GenesysClient {
}
/**
* Delete accessions from Genesys
*
* @param instCode
* @param jsonAccessionIdList
* @return
* @throws OAuthAuthenticationException
* @throws PleaseRetryException
* @throws GenesysApiException
* Delete accessions from Genesys
.
*
* @param instCode
the inst code
* @param jsonAccessionIdList
the json accession id list
* @return
the string
* @throws OAuthAuthenticationException
the o auth authentication exception
* @throws PleaseRetryException
the please retry exception
* @throws GenesysApiException
the genesys api exception
*/
public
String
deleteAccessionsByGenesysId
(
String
instCode
,
String
jsonAccessionIdList
)
throws
OAuthAuthenticationException
,
PleaseRetryException
,
GenesysApiException
{
...
...
src/main/java/org/genesys2/client/oauth/GenesysTokens.java
View file @
df9d1936
/**
* Copyright 201
4
Global Crop Diversity Trust
* Copyright 201
5
Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -25,38 +25,79 @@ import org.scribe.model.Token;
* A place to keep the tokens for the session.
*/
public
class
GenesysTokens
implements
Serializable
{
/** The Constant serialVersionUID. */
private
static
final
long
serialVersionUID
=
3022586353518887500L
;
/** The access token. */
private
String
accessToken
=
null
;
/** The refresh token. */
private
String
refreshToken
=
null
;
/** The _access token. */
private
Token
_accessToken
=
null
;
/**
* Gets the access token.
*
* @return the access token
*/
public
String
getAccessToken
()
{
return
accessToken
;
}
/**
* Sets the access token.
*
* @param accessToken the new access token
*/
public
void
setAccessToken
(
String
accessToken
)
{
this
.
accessToken
=
accessToken
;
this
.
_accessToken
=
new
Token
(
accessToken
,
""
);
}
/**
* Gets the refresh token.
*
* @return the refresh token
*/
public
String
getRefreshToken
()
{
return
refreshToken
;
}
/**
* Sets the refresh token.
*
* @param refreshToken the new refresh token
*/
public
void
setRefreshToken
(
String
refreshToken
)
{
this
.
refreshToken
=
refreshToken
;
}
/**
* Checks for refresh token.
*
* @return true, if successful
*/
public
boolean
hasRefreshToken
()
{
return
StringUtils
.
isNotBlank
(
this
.
refreshToken
);
}
/**
* Checks for access token.
*
* @return true, if successful
*/
public
boolean
hasAccessToken
()
{
return
StringUtils
.
isNotBlank
(
this
.
accessToken
);
}
/**
* Access token.
*
* @return the token
*/
public
Token
accessToken
()
{
return
this
.
_accessToken
;
}
...
...
src/main/java/org/genesys2/client/oauth/HttpRedirectException.java
View file @
df9d1936
/**
* Copyright 2015 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package
org.genesys2.client.oauth
;
/**
* The Class HttpRedirectException.
*/
public
class
HttpRedirectException
extends
GenesysApiException
{
/** The Constant serialVersionUID. */
private
static
final
long
serialVersionUID
=
1L
;
/** The redirect url. */
private
String
redirectUrl
;
/**
* Instantiates a new http redirect exception.
*
* @param redirectUrl the redirect url
*/
public
HttpRedirectException
(
String
redirectUrl
)
{
this
.
redirectUrl
=
redirectUrl
;
}
/**
* Gets the redirect url.
*
* @return the redirect url
*/
public
String
getRedirectUrl
()
{
return
redirectUrl
;
}
...
...
src/main/java/org/genesys2/client/oauth/OAuthAuthenticationException.java
View file @
df9d1936
...
...
@@ -21,6 +21,7 @@ package org.genesys2.client.oauth;
*/
public
class
OAuthAuthenticationException
extends
GenesysApiException
{
/** The Constant serialVersionUID. */
private
static
final
long
serialVersionUID
=
-
6008425446284829953L
;
/**
...
...
src/main/java/org/genesys2/client/oauth/PleaseRetryException.java
View file @
df9d1936
...
...
@@ -16,6 +16,7 @@
package
org.genesys2.client.oauth
;
// TODO: Auto-generated Javadoc
/**
* API exception indicating that the operation failed due to concurrency issues
* and should be retried by the client.
...
...
@@ -32,6 +33,7 @@ public class PleaseRetryException extends GenesysApiException {
super
(
message
);
}
/** The Constant serialVersionUID. */
private
static
final
long
serialVersionUID
=
3763066812749783171L
;
}
src/main/java/org/genesys2/client/oauth/api/GenesysApi.java
View file @
df9d1936
...
...
@@ -33,22 +33,25 @@ import org.scribe.model.Response;
import
org.scribe.model.Token
;
import
org.scribe.utils.OAuthEncoder
;
// TODO: Auto-generated Javadoc
/**
* Genesys API v1.
*/
public
class
GenesysApi
extends
DefaultApi20
{