Commit 44ad36bf authored by Matija Obreza's avatar Matija Obreza

Updated javadoc and code cleanup

parent 9cab9d3a
/*
* 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.
* 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.
......@@ -106,7 +106,7 @@ public class CLI {
try {
System.out.println("/me: " + genesysClient.query("/me"));
this.properties.put("access.token", genesysClient.getTokens().getAccessToken());
properties.put("access.token", genesysClient.getTokens().getAccessToken());
saveProperties();
} catch (final OAuthAuthenticationException e) {
......@@ -302,9 +302,10 @@ public class CLI {
updateCropRules();
} else if ("9".equals(line)) {
System.out.println("/methods: " + genesysClient.query("/methods"));
} else if ("0".equalsIgnoreCase(line))
} else if ("0".equalsIgnoreCase(line)) {
return;
} while (!("0".equalsIgnoreCase(line)));
}
} while (!"0".equalsIgnoreCase(line));
}
/**
......@@ -397,9 +398,10 @@ public class CLI {
addMethod();
} else if ("9".equals(line)) {
System.out.println("/methods: " + genesysClient.query("/methods"));
} else if ("0".equalsIgnoreCase(line))
} else if ("0".equalsIgnoreCase(line)) {
return;
} while (!("0".equalsIgnoreCase(line)));
}
} while (!"0".equalsIgnoreCase(line));
}
/**
......@@ -425,9 +427,10 @@ public class CLI {
addDatasetData();
} else if ("4".equals(line)) {
addDatasetRaw();
} else if ("0".equalsIgnoreCase(line))
} else if ("0".equalsIgnoreCase(line)) {
return;
} while (!("0".equalsIgnoreCase(line)));
}
} while (!"0".equalsIgnoreCase(line));
}
/**
......@@ -574,10 +577,10 @@ public class CLI {
// Trade the Request Token and Verifier for the Access Token
genesysClient.authenticate(verifierCode);
this.properties.put("access.token", genesysClient.getTokens().getAccessToken());
properties.put("access.token", genesysClient.getTokens().getAccessToken());
// Get refresh token ()
this.properties.put("refresh.token", genesysClient.getTokens().getRefreshToken());
properties.put("refresh.token", genesysClient.getTokens().getRefreshToken());
saveProperties();
}
......@@ -589,7 +592,7 @@ public class CLI {
FileOutputStream fis = null;
try {
fis = new FileOutputStream(propertiesFile);
this.properties.store(fis, "OAuth client properties");
properties.store(fis, "OAuth client properties");
} catch (final IOException e) {
_log.error(e);
} finally {
......
/*
* 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.
* 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.
......
/*
* 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.
* 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.
......@@ -54,7 +54,7 @@ public class GenesysTokens implements Serializable {
*/
public void setAccessToken(final String accessToken) {
this.accessToken = accessToken;
this._accessToken = new Token(accessToken, "");
_accessToken = new Token(accessToken, "");
}
/**
......@@ -81,7 +81,7 @@ public class GenesysTokens implements Serializable {
* @return true, if successful
*/
public boolean hasRefreshToken() {
return StringUtils.isNotBlank(this.refreshToken);
return StringUtils.isNotBlank(refreshToken);
}
/**
......@@ -90,7 +90,7 @@ public class GenesysTokens implements Serializable {
* @return true, if successful
*/
public boolean hasAccessToken() {
return StringUtils.isNotBlank(this.accessToken);
return StringUtils.isNotBlank(accessToken);
}
/**
......@@ -99,6 +99,6 @@ public class GenesysTokens implements Serializable {
* @return the token
*/
public Token accessToken() {
return this._accessToken;
return _accessToken;
}
}
/*
* 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.
* 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.
......
/*
* 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.
* 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.
......
/*
* 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.
* 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.
......@@ -16,9 +16,9 @@
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 {
......
/*
* 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.
* 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.
......@@ -70,10 +70,10 @@ public class GenesysApi extends DefaultApi20 {
*/
public void setBaseUrl(final String baseUrl) {
this.baseUrl = baseUrl;
this.authorizeUrl = this.baseUrl + AUTHORIZE_URL;
this.scopedAuthorizeUrl = this.authorizeUrl + "&scope=%s";
this.refreshTokenEndpoint = this.baseUrl + TOKEN_ENDPOINT;
this.accessTokenEndpoint = this.baseUrl + TOKEN_ENDPOINT + "?grant_type=authorization_code";
authorizeUrl = this.baseUrl + AUTHORIZE_URL;
scopedAuthorizeUrl = authorizeUrl + "&scope=%s";
refreshTokenEndpoint = this.baseUrl + TOKEN_ENDPOINT;
accessTokenEndpoint = this.baseUrl + TOKEN_ENDPOINT + "?grant_type=authorization_code";
}
/*
......@@ -83,7 +83,7 @@ public class GenesysApi extends DefaultApi20 {
*/
@Override
public String getAccessTokenEndpoint() {
return this.accessTokenEndpoint;
return accessTokenEndpoint;
}
/**
......@@ -92,7 +92,7 @@ public class GenesysApi extends DefaultApi20 {
* @return the refresh token endpoint
*/
public String getRefreshTokenEndpoint() {
return this.refreshTokenEndpoint;
return refreshTokenEndpoint;
}
/*
......@@ -104,9 +104,8 @@ public class GenesysApi extends DefaultApi20 {
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()));
? String.format(scopedAuthorizeUrl, config.getApiKey(), config.getApiSecret(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope()))
: String.format(authorizeUrl, config.getApiKey(), config.getApiSecret(), OAuthEncoder.encode(config.getCallback()));
}
/*
......@@ -129,16 +128,19 @@ public class GenesysApi extends DefaultApi20 {
final Pattern refreshTokenPattern = Pattern.compile("\"refresh_token\":\\s*\"(\\S*?)\"");
final Matcher matcher = refreshTokenPattern.matcher(accessToken.getRawResponse());
if (matcher.find())
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
* 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
* /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
......@@ -147,7 +149,7 @@ public class GenesysApi extends DefaultApi20 {
* @throws GenesysApiException the genesys api exception
*/
public Token getAccessToken(final String apiKey, final String apiSecret, final String refreshToken) throws GenesysApiException {
final OAuthRequest request = new OAuthRequest(getAccessTokenVerb(), this.refreshTokenEndpoint);
final OAuthRequest request = new OAuthRequest(getAccessTokenVerb(), refreshTokenEndpoint);
request.addQuerystringParameter(OAuthConstants.CLIENT_ID, apiKey);
request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, apiSecret);
request.addQuerystringParameter("grant_type", "refresh_token");
......@@ -155,12 +157,13 @@ public class GenesysApi extends DefaultApi20 {
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 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.
* 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.
......@@ -16,10 +16,10 @@
package org.genesys2.client.oauth.api.accession;
import org.genesys2.client.oauth.api.accession.Api1Constants.Accession;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.genesys2.client.oauth.api.accession.Api1Constants.Accession;
/**
* The Class AccessionJson.
*/
......@@ -159,11 +159,10 @@ public class AccessionJson {
/**
* Sets the version.
*
* @param l
* the new version
* @param l the new version
*/
public void setVersion(final Long l) {
this.version = l;
version = l;
}
/**
......@@ -178,8 +177,7 @@ public class AccessionJson {
/**
* Sets the genesys id.
*
* @param genesysId
* the new genesys id
* @param genesysId the new genesys id
*/
public void setGenesysId(final Long genesysId) {
this.genesysId = genesysId;
......@@ -197,8 +195,7 @@ public class AccessionJson {
/**
* Sets the inst code.
*
* @param instCode
* the new inst code
* @param instCode the new inst code
*/
public void setInstCode(final String instCode) {
this.instCode = instCode;
......@@ -216,8 +213,7 @@ public class AccessionJson {
/**
* Sets the acce numb.
*
* @param acceNumb
* the new acce numb
* @param acceNumb the new acce numb
*/
public void setAcceNumb(final String acceNumb) {
this.acceNumb = acceNumb;
......@@ -235,8 +231,7 @@ public class AccessionJson {
/**
* Sets the new acce numb.
*
* @param newAcceNumb
* the new new acce numb
* @param newAcceNumb the new new acce numb
*/
public void setNewAcceNumb(final String newAcceNumb) {
this.newAcceNumb = newAcceNumb;
......@@ -254,8 +249,7 @@ public class AccessionJson {
/**
* Sets the genus.
*
* @param genus
* the new genus
* @param genus the new genus
*/
public void setGenus(final String genus) {
this.genus = genus;
......@@ -273,8 +267,7 @@ public class AccessionJson {
/**
* Sets the new genus.
*
* @param newGenus
* the new new genus
* @param newGenus the new new genus
*/
public void setNewGenus(final String newGenus) {
this.newGenus = newGenus;
......@@ -292,8 +285,7 @@ public class AccessionJson {
/**
* Sets the species.
*
* @param species
* the new species
* @param species the new species
*/
public void setSpecies(final String species) {
this.species = species;
......@@ -311,8 +303,7 @@ public class AccessionJson {
/**
* Sets the spauthor.
*
* @param spauthor
* the new spauthor
* @param spauthor the new spauthor
*/
public void setSpauthor(final String spauthor) {
this.spauthor = spauthor;
......@@ -330,8 +321,7 @@ public class AccessionJson {
/**
* Sets the subtaxa.
*
* @param subtaxa
* the new subtaxa
* @param subtaxa the new subtaxa
*/
public void setSubtaxa(final String subtaxa) {
this.subtaxa = subtaxa;
......@@ -349,8 +339,7 @@ public class AccessionJson {
/**
* Sets the subtauthor.
*
* @param subtauthor
* the new subtauthor
* @param subtauthor the new subtauthor
*/
public void setSubtauthor(final String subtauthor) {
this.subtauthor = subtauthor;
......@@ -368,8 +357,7 @@ public class AccessionJson {
/**
* Sets the uuid.
*
* @param uuid
* the new uuid
* @param uuid the new uuid
*/
public void setUuid(final String uuid) {
this.uuid = uuid;
......@@ -387,8 +375,7 @@ public class AccessionJson {
/**
* Sets the org cty.
*
* @param orgCty
* the new org cty
* @param orgCty the new org cty
*/
public void setOrgCty(final String orgCty) {
this.orgCty = orgCty;
......@@ -406,8 +393,7 @@ public class AccessionJson {
/**
* Sets the acq date.
*
* @param acqDate
* the new acq date
* @param acqDate the new acq date
*/
public void setAcqDate(final String acqDate) {
this.acqDate = acqDate;
......@@ -425,8 +411,7 @@ public class AccessionJson {
/**
* Sets the mls stat.
*
* @param mlsStat
* the new mls stat
* @param mlsStat the new mls stat
*/
public void setMlsStat(final Boolean mlsStat) {
this.mlsStat = mlsStat;
......@@ -444,8 +429,7 @@ public class AccessionJson {
/**
* Sets the in trust.
*
* @param inTrust
* the new in trust
* @param inTrust the new in trust
*/
public void setInTrust(final Boolean inTrust) {
this.inTrust = inTrust;
......@@ -463,8 +447,7 @@ public class AccessionJson {
/**
* Sets the available.
*
* @param available
* the new available
* @param available the new available
*/
public void setAvailable(final Boolean available) {
this.available = available;
......@@ -482,8 +465,7 @@ public class AccessionJson {
/**
* Sets the storage.
*
* @param storage
* the new storage
* @param storage the new storage
*/
public void setStorage(final Integer[] storage) {
this.storage = storage;
......@@ -501,8 +483,7 @@ public class AccessionJson {
/**
* Sets the samp stat.
*
* @param sampStat
* the new samp stat
* @param sampStat the new samp stat
*/
public void setSampStat(final Integer sampStat) {
this.sampStat = sampStat;
......@@ -520,8 +501,7 @@ public class AccessionJson {
/**
* Sets the dupl site.
*
* @param duplSite
* the new dupl site
* @param duplSite the new dupl site
*/
public void setDuplSite(final String[] duplSite) {
this.duplSite = duplSite;
......@@ -539,8 +519,7 @@ public class AccessionJson {
/**
* Sets the bred code.
*
* @param bredCode
* the new bred code
* @param bredCode the new bred code
*/
public void setBredCode(final String bredCode) {
this.bredCode = bredCode;
......@@ -558,8 +537,7 @@ public class AccessionJson {
/**
* Sets the ancest.
*
* @param ancest
* the new ancest
* @param ancest the new ancest
*/
public void setAncest(final String ancest) {
this.ancest = ancest;
......@@ -577,8 +555,7 @@ public class AccessionJson {
/**
* Sets the donor code.
*
* @param donorCode
* the new donor code
* @param donorCode the new donor code
*/
public void setDonorCode(final String donorCode) {
this.donorCode = donorCode;
......@@ -596,8 +573,7 @@ public class AccessionJson {
/**
* Sets the donor numb.
*
* @param donorNumb
* the new donor numb
* @param donorNumb the new donor numb
*/
public void setDonorNumb(final String donorNumb) {
this.donorNumb = donorNumb;
......@@ -615,8 +591,7 @@ public class AccessionJson {
/**
* Sets the donor name.
*
* @param donorName
* the new donor name
* @param donorName the new donor name
*/
public void setDonorName(final String donorName) {
this.donorName = donorName;
......@@ -634,8 +609,7 @@ public class AccessionJson {
/**
* Sets the coll.
*
* @param coll
* the new coll
* @param coll the new coll
*/
public void setColl(final CollectingJson coll) {
this.coll = coll;
......@@ -653,8 +627,7 @@ public class AccessionJson {
/**
* Sets the geo.
*
* @param geo
* the new geo
* @param geo the new geo
*/
public void setGeo(final GeoJson geo) {
this.geo = geo;
......@@ -672,8 +645,7 @@ public class AccessionJson {
/**
* Sets the remarks.
*
* @param remarks
* the new remarks
* @param remarks the new remarks
*/
public void setRemarks(final Remark[] remarks) {
this.remarks = remarks;
......@@ -682,8 +654,7 @@ public class AccessionJson {
/**
* Sets the historic.
*
* @param historic
* the new historic
* @param historic the new historic
*/
public void setHistoric(final Boolean historic) {
this.historic = historic;
......@@ -695,7 +666,7 @@ public class AccessionJson {
* @return the historic
*/
public Boolean getHistoric() {
return this.historic;
return historic;
}