Commit 7c77564e authored by Matija Obreza's avatar Matija Obreza

Source code formatted

parent d278bd04
/**
* Copyright 2014 Global Crop Diversity Trust
/*
* Copyright 2016 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.
......@@ -12,7 +12,7 @@
* 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;
......@@ -20,7 +20,7 @@ package org.genesys2.client.oauth;
* General GenesysApiException.
*/
public class GenesysApiException extends Exception {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = -6008425446284829953L;
......@@ -35,7 +35,7 @@ public class GenesysApiException extends Exception {
*
* @param string the string
*/
public GenesysApiException(String string) {
public GenesysApiException(final String string) {
super(string);
}
......
/**
* Copyright 2015 Global Crop Diversity Trust
/*
* Copyright 2016 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.
......@@ -12,7 +12,7 @@
* 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;
......@@ -25,13 +25,13 @@ 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;
......@@ -52,7 +52,7 @@ public class GenesysTokens implements Serializable {
*
* @param accessToken the new access token
*/
public void setAccessToken(String accessToken) {
public void setAccessToken(final String accessToken) {
this.accessToken = accessToken;
this._accessToken = new Token(accessToken, "");
}
......@@ -71,7 +71,7 @@ public class GenesysTokens implements Serializable {
*
* @param refreshToken the new refresh token
*/
public void setRefreshToken(String refreshToken) {
public void setRefreshToken(final String refreshToken) {
this.refreshToken = refreshToken;
}
......
/**
* Copyright 2015 Global Crop Diversity Trust
/*
* Copyright 2016 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.
......@@ -12,26 +12,26 @@
* 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;
private final String redirectUrl;
/**
* Instantiates a new http redirect exception.
*
* @param redirectUrl the redirect url
*/
public HttpRedirectException(String redirectUrl) {
public HttpRedirectException(final String redirectUrl) {
this.redirectUrl = redirectUrl;
}
......
/**
* Copyright 2014 Global Crop Diversity Trust
/*
* Copyright 2016 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.
......@@ -12,15 +12,15 @@
* 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;
/**
* Exception for authentication exceptions.
* Exception for authentication exceptions.
*/
public class OAuthAuthenticationException extends GenesysApiException {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = -6008425446284829953L;
......@@ -35,7 +35,7 @@ public class OAuthAuthenticationException extends GenesysApiException {
*
* @param string the string
*/
public OAuthAuthenticationException(String string) {
public OAuthAuthenticationException(final String string) {
super(string);
}
......
/**
* Copyright 2014 Global Crop Diversity Trust
/*
* Copyright 2016 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.
......@@ -12,24 +12,22 @@
* 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;
// TODO: Auto-generated Javadoc
/**
* API exception indicating that the operation failed due to concurrency issues
* and should be retried by the client.
* API exception indicating that the operation failed due to concurrency issues and should be retried by the client.
*/
public class PleaseRetryException extends GenesysApiException {
/**
* Instantiates a new please retry exception.
*
* @param message
* the message
* @param message the message
*/
public PleaseRetryException(String message) {
public PleaseRetryException(final String message) {
super(message);
}
......
/**
* Copyright 2014 Global Crop Diversity Trust
/*
* Copyright 2016 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.
......@@ -12,7 +12,7 @@
* 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.api;
......@@ -68,7 +68,7 @@ public class GenesysApi extends DefaultApi20 {
*
* @param baseUrl the new base url
*/
public void setBaseUrl(String baseUrl) {
public void setBaseUrl(final String baseUrl) {
this.baseUrl = baseUrl;
this.authorizeUrl = this.baseUrl + AUTHORIZE_URL;
this.scopedAuthorizeUrl = this.authorizeUrl + "&scope=%s";
......@@ -78,7 +78,7 @@ public class GenesysApi extends DefaultApi20 {
/*
* (non-Javadoc)
*
*
* @see org.scribe.builder.api.DefaultApi20#getAccessTokenEndpoint()
*/
@Override
......@@ -97,23 +97,21 @@ public class GenesysApi extends DefaultApi20 {
/*
* (non-Javadoc)
*
* @see
* org.scribe.builder.api.DefaultApi20#getAuthorizationUrl(org.scribe.model
* .OAuthConfig)
*
* @see org.scribe.builder.api.DefaultApi20#getAuthorizationUrl(org.scribe.model .OAuthConfig)
*/
@Override
public String getAuthorizationUrl(OAuthConfig config) {
public String getAuthorizationUrl(final OAuthConfig config) {
return config.hasScope() ? String.format(this.scopedAuthorizeUrl, config.getApiKey(), config.getApiSecret(),
OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope())) : String
.format(this.authorizeUrl, config.getApiKey(), config.getApiSecret(),
OAuthEncoder.encode(config.getCallback()));
return config.hasScope()
? String.format(this.scopedAuthorizeUrl, config.getApiKey(), config.getApiSecret(), OAuthEncoder.encode(config.getCallback()),
OAuthEncoder.encode(config.getScope()))
: String.format(this.authorizeUrl, config.getApiKey(), config.getApiSecret(), OAuthEncoder.encode(config.getCallback()));
}
/*
* (non-Javadoc)
*
*
* @see org.scribe.builder.api.DefaultApi20#getAccessTokenExtractor()
*/
@Override
......@@ -127,24 +125,20 @@ public class GenesysApi extends DefaultApi20 {
* @param accessToken the access token
* @return the refresh token
*/
public Token getRefreshToken(Token accessToken) {
Pattern refreshTokenPattern = Pattern.compile("\"refresh_token\":\\s*\"(\\S*?)\"");
public Token getRefreshToken(final Token accessToken) {
final Pattern refreshTokenPattern = Pattern.compile("\"refresh_token\":\\s*\"(\\S*?)\"");
Matcher matcher = refreshTokenPattern.matcher(accessToken.getRawResponse());
if (matcher.find()) {
final Matcher matcher = refreshTokenPattern.matcher(accessToken.getRawResponse());
if (matcher.find())
return new Token(matcher.group(1), "", accessToken.getRawResponse());
}
return null;
}
/**
* http://stackoverflow.com/questions/20044222/spring-security-oauth-2-
* implicit-grant-no-support-for-refresh-token
*
* /oauth/token?client_id=MyClient&grant_type=refresh_token&
* client_secret=
* mysecret&refresh_token=19698a4a-960a-4d24-a8cc-44d4b71df47b
* http://stackoverflow.com/questions/20044222/spring-security-oauth-2- implicit-grant-no-support-for-refresh-token
*
* /oauth/token?client_id=MyClient&grant_type=refresh_token& client_secret= mysecret&refresh_token=19698a4a-960a-4d24-a8cc-44d4b71df47b
*
* @param apiKey the api key
* @param apiSecret the api secret
......@@ -152,22 +146,21 @@ public class GenesysApi extends DefaultApi20 {
* @return the access token
* @throws GenesysApiException the genesys api exception
*/
public Token getAccessToken(String apiKey, String apiSecret, String refreshToken) throws GenesysApiException {
OAuthRequest request = new OAuthRequest(getAccessTokenVerb(), this.refreshTokenEndpoint);
public Token getAccessToken(final String apiKey, final String apiSecret, final String refreshToken) throws GenesysApiException {
final OAuthRequest request = new OAuthRequest(getAccessTokenVerb(), this.refreshTokenEndpoint);
request.addQuerystringParameter(OAuthConstants.CLIENT_ID, apiKey);
request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, apiSecret);
request.addQuerystringParameter("grant_type", "refresh_token");
request.addQuerystringParameter("refresh_token", refreshToken);
Response response = request.send();
final Response response = request.send();
_log.debug("HTTP status code " + response.getCode());
_log.debug("Redirect: " + response.getHeader(HttpHeaders.LOCATION));
if (response.getCode() >= 200 && response.getCode() < 300) {
if (response.getCode() >= 200 && response.getCode() < 300)
return getAccessTokenExtractor().extract(response.getBody());
} else if (response.getCode() == 400) {
else if (response.getCode() == 400)
throw new OAuthException("Refresh token no longer valid.");
} else {
else
throw new GenesysApiException("Server responded with unexpected HTTP response code " + response.getCode());
}
}
/**
......
/**
* Copyright 2015 Global Crop Diversity Trust
/*
* Copyright 2016 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.
......@@ -12,7 +12,7 @@
* 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.api.accession;
......@@ -22,7 +22,7 @@ package org.genesys2.client.oauth.api.accession;
* @author mobreza
*/
public interface Api1Constants {
/**
* The Interface Accession.
*/
......@@ -51,8 +51,7 @@ public interface Api1Constants {
public static final String GENUS_NEW = "newGenus";
/**
* Specific epithet portion of the scientific name, in latin, in
* lowercase letters. Following abbreviation is allowed: ‘sp.’
* Specific epithet portion of the scientific name, in latin, in lowercase letters. Following abbreviation is allowed: ‘sp.’
*/
public static final String SPECIES = "species";
......@@ -66,9 +65,7 @@ public interface Api1Constants {
public static final String SUBTAUTHOR = "subtauthor";
/**
* Universally Unique IDentifier for the accession, assigned by the
* first holding institute and immutable when accession is duplicated in
* another institute.
* Universally Unique IDentifier for the accession, assigned by the first holding institute and immutable when accession is duplicated in another institute.
*/
public static final String UUID = "uuid";
......@@ -78,16 +75,12 @@ public interface Api1Constants {
public static final String ORIGCTY = "orgCty";
/**
* Date on which the accession entered the collection as YYYYMMDD.
* Missing data (MM or DD) should be indicated with hyphens. Leading
* zeros are required.
* Date on which the accession entered the collection as YYYYMMDD. Missing data (MM or DD) should be indicated with hyphens. Leading zeros are required.
*/
public static final String ACQDATE = "acqDate";
/**
* The status of an accession with regards to the Multilateral System
* (MLS) of the International Treaty on PlantGenetic Resources for Food
* and Agriculture.
* The status of an accession with regards to the Multilateral System (MLS) of the International Treaty on PlantGenetic Resources for Food and Agriculture.
*/
public static final String MLSSTAT = "mlsStat";
......@@ -95,8 +88,7 @@ public interface Api1Constants {
public static final String INTRUST = "inTrust";
/**
* The general availability of the accession for distribution, but
* subject to current stock.
* The general availability of the accession for distribution, but subject to current stock.
*/
public static final String AVAILABLE = "available";
......@@ -109,8 +101,7 @@ public interface Api1Constants {
public static final String SAMPSTAT = "sampStat";
/**
* FAO Institute Code (WIEWS code) of the institute where a safety
* duplicate of the accession is maintained.
* FAO Institute Code (WIEWS code) of the institute where a safety duplicate of the accession is maintained.
*/
public static final String DUPLSITE = "duplSite";
......@@ -133,8 +124,7 @@ public interface Api1Constants {
public static final String DONORNUMB = "donorNumb";
/**
* Name of the donor institute (or person). Provide only when donorCode
* is not available.
* Name of the donor institute (or person). Provide only when donorCode is not available.
*/
public static final String DONORNAME = "donorName";
......@@ -148,8 +138,7 @@ public interface Api1Constants {
public static final String REMARKS = "remarks";
/**
* Marks if accession record is about a historic holding and the
* accession no longer exists.
* Marks if accession record is about a historic holding and the accession no longer exists.
*/
public static final String HISTORIC = "historic";
......
/**
* Copyright 2014 Global Crop Diversity Trust
/*
* Copyright 2016 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.
......@@ -12,47 +12,47 @@
* 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.api.accession;
import org.genesys2.client.oauth.api.accession.Api1Constants.Collecting;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.genesys2.client.oauth.api.accession.Api1Constants.Collecting;
/**
* The Class CollectingJson.
*/
public class CollectingJson {
/** The coll date. */
@JsonProperty(value = Collecting.COLLDATE)
private String collDate;
/** The coll site. */
@JsonProperty(value = Collecting.COLLSITE)
private String collSite;
/** The coll numb. */
@JsonProperty(value = Collecting.COLLNUMB)
private String collNumb;
/** The coll src. */
@JsonProperty(value = Collecting.COLLSRC)
private Integer collSrc;
/** The coll code. */
@JsonProperty(value = Collecting.COLLCODE)
private String collCode;
/** The coll name. */
@JsonProperty(value = Collecting.COLLNAME)
private String collName;
/** The coll inst address. */
@JsonProperty(value = Collecting.COLLINSTADDRESS)
private String collInstAddress;
/** The coll miss id. */
@JsonProperty(value = Collecting.COLLMISSID)
private String collMissId;
......@@ -71,7 +71,7 @@ public class CollectingJson {
*
* @param collDate the new coll date
*/
public void setCollDate(String collDate) {
public void setCollDate(final String collDate) {
this.collDate = collDate;
}
......@@ -89,7 +89,7 @@ public class CollectingJson {
*
* @param collSite the new coll site
*/
public void setCollSite(String collSite) {
public void setCollSite(final String collSite) {
this.collSite = collSite;
}
......@@ -107,7 +107,7 @@ public class CollectingJson {
*
* @param collNumb the new coll numb
*/
public void setCollNumb(String collNumb) {
public void setCollNumb(final String collNumb) {
this.collNumb = collNumb;
}
......@@ -125,7 +125,7 @@ public class CollectingJson {
*
* @param integer the new coll src
*/
public void setCollSrc(Integer integer) {
public void setCollSrc(final Integer integer) {
this.collSrc = integer;
}
......@@ -143,7 +143,7 @@ public class CollectingJson {
*
* @param collCode the new coll code
*/
public void setCollCode(String collCode) {
public void setCollCode(final String collCode) {
this.collCode = collCode;
}
......@@ -161,7 +161,7 @@ public class CollectingJson {
*
* @param collName the new coll name
*/
public void setCollName(String collName) {
public void setCollName(final String collName) {
this.collName = collName;
}
......@@ -179,7 +179,7 @@ public class CollectingJson {
*
* @param collInstAddress the new coll inst address
*/
public void setCollInstAddress(String collInstAddress) {
public void setCollInstAddress(final String collInstAddress) {
this.collInstAddress = collInstAddress;
}
......@@ -197,7 +197,7 @@ public class CollectingJson {
*
* @param collMissId the new coll miss id
*/
public void setCollMissId(String collMissId) {
public void setCollMissId(final String collMissId) {
this.collMissId = collMissId;
}
......
/**
* Copyright 2014 Global Crop Diversity Trust
/*
* Copyright 2016 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.
......@@ -12,39 +12,39 @@
* 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.api.accession;
import org.genesys2.client.oauth.api.accession.Api1Constants.Geo;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.genesys2.client.oauth.api.accession.Api1Constants.Geo;
/**
* The Class GeoJson.
*/
public class GeoJson {
/** The latitude. */
@JsonProperty(value = Geo.LATITUDE)
private Double latitude;
/** The longitude. */
@JsonProperty(value = Geo.LONGITUDE)
private Double longitude;
/** The elevation. */
@JsonProperty(value = Geo.ELEVATION)
private Double elevation;
/** The coord uncert. */
@JsonProperty(value = Geo.COORDUNCERT)
private Double coordUncert;
/** The coord datum. */
@JsonProperty(value = Geo.COORDDATUM)
private String coordDatum;
/** The georef meth. */
@JsonProperty(value = Geo.GEOREFMETH)
private String georefMeth;
......@@ -63,7 +63,7 @@ public class GeoJson {
*
* @param latitude the new latitude
*/
public void setLatitude(Double latitude) {
public void setLatitude(final Double latitude) {
this.latitude = latitude;
}
......@@ -81,7 +81,7 @@ public class GeoJson {
*
* @param longitude the new longitude
*/