Skip to content

Commit

Permalink
more sonar style fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximKulikov committed Jan 2, 2018
1 parent f389e7a commit 1d3fab2
Show file tree
Hide file tree
Showing 17 changed files with 159 additions and 55 deletions.
13 changes: 5 additions & 8 deletions src/main/java/ru/maximkulikov/goodgame/api/GoodChat.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import java.io.IOException;
import java.net.URI;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.eclipse.jetty.websocket.api.Session;
Expand Down Expand Up @@ -60,7 +62,6 @@ public void run() {

} catch (Exception e) {
logger.error("Connecting exeption: {}", e.getLocalizedMessage());
e.printStackTrace();
} finally {
try {
GoodChat.this.client.stop();
Expand Down Expand Up @@ -116,7 +117,6 @@ public final void sendMessage(final ReqChatObject chatObject) {
Thread.sleep(700);

} catch (InterruptedException e) {
e.printStackTrace();
logger.error("Send message Exeption. Closing thread: {}", e.getLocalizedMessage());
Thread.currentThread().interrupt();
}
Expand Down Expand Up @@ -153,7 +153,6 @@ public final void stop() {
GoodChat.this.client.stop();
} catch (Exception e) {
logger.error("GoddChat dit not stop in proper way! {}", e.getLocalizedMessage());
e.printStackTrace();
}
}
}
Expand Down Expand Up @@ -361,15 +360,14 @@ public final void onMessage(final String msg) {
break;
default:
answer = new Response(ChatResponses.UNKNOWN, null);
System.out.println(msg);
logger.info(msg);
break;
}

this.chat.onMessage(answer);

} catch (IOException e) {
logger.error("On message receive exception: {}", e.getLocalizedMessage());
e.printStackTrace();
}
}

Expand All @@ -385,9 +383,8 @@ protected final void sendMessage(final String s) {
fut = this.session.getRemote().sendStringByFuture(s);
fut.get(2, TimeUnit.SECONDS);

} catch (Throwable t) {
logger.error("send Message exception: {}", t.getLocalizedMessage());
t.printStackTrace();
} catch (InterruptedException | ExecutionException | TimeoutException e) {
logger.error("send Message exception: {}", e.getLocalizedMessage());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ public final void setRefreshToken(final String refreshToken) {
* @return
*/
public String setHost(final String host) {
return this.host = host;
this.host = host;
return this.host;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ private void processRequest() {
) {

String requestLine = br.readLine();
String rawRequest = "\n" + requestLine;

String headerLine = null;
while ((headerLine = br.readLine()).length() != 0) {
rawRequest += headerLine + "\n";
}
// String rawRequest = "\n" + requestLine;
//
// String headerLine = null;
// while ((headerLine = br.readLine()).length() != 0) {
// rawRequest += headerLine + "\n";
// }

StringTokenizer tokens = new StringTokenizer(requestLine);

Expand Down Expand Up @@ -165,9 +165,6 @@ private void processRequest() {
os.writeBytes(entityBody);
}

os.close();
br.close();

this.socket.close();

if (this.authenticationListener != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class AuthenticationCallbackServer implements AuthenticationListener {
private final URL failurePage;
private final URL successPage;
private int port;
private String host = "127.0.0.1";
private String host;
private ServerSocket serverSocket;
private String accessToken;
private AuthenticationError authenticationError;
Expand All @@ -44,6 +44,7 @@ public class AuthenticationCallbackServer implements AuthenticationListener {

public AuthenticationCallbackServer(final int port) {
this.port = port;
host = "127.0.0.1";
// Load default pages
this.authPage = getClass().getResource(DEFAULT_AUTH_PAGE);
this.failurePage = getClass().getResource(DEFAULT_FAILURE_PAGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@ public final Empty getData() {
return this.data;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;

if (o == null || getClass() != o.getClass()) return false;
public final void setData(final Empty data) {
this.data = data;
}

ReqIgnoreListContainer that = (ReqIgnoreListContainer) o;
public final String getType() {
return this.type;
}

return new EqualsBuilder()
.append(type, that.type)
.append(data, that.data)
.isEquals();
public final void setType(final String type) {
this.type = type;
}

@Override
Expand All @@ -41,23 +39,18 @@ public int hashCode() {
.toHashCode();
}

/**
*
*/

public ReqIgnoreListContainer() {
}
@Override
public boolean equals(Object o) {
if (this == o) return true;

public final void setData(final Empty data) {
this.data = data;
}
if (o == null || getClass() != o.getClass()) return false;

public final String getType() {
return this.type;
}
ReqIgnoreListContainer that = (ReqIgnoreListContainer) o;

public final void setType(final String type) {
this.type = type;
return new EqualsBuilder()
.append(type, that.type)
.append(data, that.data)
.isEquals();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ protected AbstractResource(final String baseUrl) {

}

;

protected void configureHeaders() {

http.removeHeader(ACCEPT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class AjaxResource extends AbstractResource {
private static final String CONTENT_TYPE = "Content-Type";
private static final String FORM_URL_ENCODED = "application/x-www-form-urlencoded; charset=UTF-8";
private static final String COOKIE = "Cookie";
private static final String PARAMETERS_NULL = "{} parameters are null";
private GoodGame gg;

/**
Expand All @@ -46,6 +47,10 @@ public AjaxResource(final String ajaxBaseUrl, final GoodGame gg) {
* @param handler
*/
public final boolean games(final String searchGame, final AjaxGamesHandler handler) {
if (searchGame == null) {
logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName());
return false;
}
String url = String.format("%s/games/all/", getBaseUrl());

RequestParams params = new RequestParams();
Expand Down Expand Up @@ -83,8 +88,12 @@ public void onSuccess(int statusCode, Map<String, List<String>> headers, String
* @param handler
*/
public final boolean games(final String searchGame, final RequestParams params, final AjaxGamesHandler handler) {
String url = String.format("%s/games/all/", getBaseUrl());
if (searchGame == null || params == null) {
logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName());
return false;
}

String url = String.format("%s/games/all/", getBaseUrl());
params.put("q", searchGame);

http.get(url, params, new GoodGameHttpResponseHandler(handler) {
Expand Down Expand Up @@ -119,6 +128,10 @@ public void onSuccess(int statusCode, Map<String, List<String>> headers, String
* @see GoodGame#setPhpSessId(String)
*/
public final boolean login(final String login, final String password, final AjaxLoginResponseHandler handler) {
if (login == null || password == null) {
logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName());
return false;
}
String url = String.format("%s/login/", getBaseUrl());

RequestParams params = new RequestParams();
Expand Down Expand Up @@ -152,6 +165,7 @@ public void onSuccess(int statusCode, Map<String, List<String>> headers, String
}
handler.onSuccess(value);
} catch (IOException e) {
logger.error("IOException {}", e.getLocalizedMessage());
handler.onFailure(e);
}
}
Expand All @@ -169,6 +183,11 @@ public void onSuccess(int statusCode, Map<String, List<String>> headers, String
* @see #games(String, AjaxGamesHandler)
*/
public final boolean updateTitle(final String channelId, final String title, final String gameId, final UpdateTitleResponseHandler handler) {
if (channelId == null || title == null || gameId == null) {
logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName());
return false;
}

String url = String.format("%s/channel/update-title/", getBaseUrl());

RequestParams params = new RequestParams();
Expand All @@ -177,7 +196,6 @@ public final boolean updateTitle(final String channelId, final String title, fin
params.put("title", title);
params.put("gameId", gameId);


http.removeHeader(CONTENT_TYPE);
http.removeHeader(COOKIE);
http.setHeader(CONTENT_TYPE, FORM_URL_ENCODED);
Expand All @@ -190,6 +208,7 @@ public void onSuccess(int statusCode, Map<String, List<String>> headers, String
UpdateTitle value = objectMapper.readValue(content, UpdateTitle.class);
handler.onSuccess(value);
} catch (IOException e) {
logger.error("IOException {}", e.getLocalizedMessage());
handler.onFailure(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
public class ChannelsResource extends AbstractResource {
private static final Logger logger = LoggerFactory.getLogger(ChannelsResource.class);
private static final String PARAMETERS_NULL = "{} parameters are null";

/**
* @param baseUrl Базовая ссылка для доступа к ресурсу
Expand All @@ -39,6 +40,10 @@ public ChannelsResource(final String baseUrl, final int apiVersion) {
* @param handler
*/
public final boolean getDonations(final String channel, final DonationsResponseHandler handler) {
if (channel == null) {
logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName());
return false;
}
String url = String.format("%s/channel/%s/donations", getBaseUrl(), channel);
this.configureHeaders();
http.get(url, new GoodGameHttpResponseHandler(handler) {
Expand All @@ -48,6 +53,7 @@ public void onSuccess(final int statusCode, final Map<String, List<String>> head
DonationsContainer value = objectMapper.readValue(content, DonationsContainer.class);
handler.onSuccess(value);
} catch (IOException e) {
logger.error("IOException {}", e.getLocalizedMessage());
handler.onFailure(e);
}
}
Expand All @@ -67,6 +73,10 @@ public void onSuccess(final int statusCode, final Map<String, List<String>> head
*/
public final boolean getDonations(final String channel, final RequestParams params,
final DonationsResponseHandler handler) {
if (channel == null || params == null) {
logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName());
return false;
}
String url = String.format("%s/channel/%s/donations", getBaseUrl(), channel);
this.configureHeaders();
http.get(url, params, new GoodGameHttpResponseHandler(handler) {
Expand All @@ -76,6 +86,7 @@ public void onSuccess(final int statusCode, final Map<String, List<String>> head
DonationsContainer value = objectMapper.readValue(content, DonationsContainer.class);
handler.onSuccess(value);
} catch (IOException e) {
logger.error("IOException {}", e.getLocalizedMessage());
handler.onFailure(e);
}
}
Expand All @@ -92,6 +103,10 @@ public void onSuccess(final int statusCode, final Map<String, List<String>> head
* @param handler
*/
public final boolean getPremiums(final String channel, final PremiumsResponseHandler handler) {
if (channel == null) {
logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName());
return false;
}
String url = String.format("%s/channel/%s/premiums", getBaseUrl(), channel);

this.configureHeaders();
Expand Down Expand Up @@ -121,6 +136,10 @@ public void onSuccess(final int statusCode, final Map<String, List<String>> head
*/
public final boolean getPremiums(final String channel, final RequestParams params,
final PremiumsResponseHandler handler) {
if (channel == null || params == null) {
logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName());
return false;
}
String url = String.format("%s/channel/%s/premiums", getBaseUrl(), channel);

this.configureHeaders();
Expand All @@ -147,6 +166,10 @@ public void onSuccess(final int statusCode, final Map<String, List<String>> head
* @param handler
*/
public final boolean getSubscribers(final String channel, final SubscriberResponseHandler handler) {
if (channel == null) {
logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName());
return false;
}
String url = String.format("%s/channel/%s/subscribers", getBaseUrl(), channel);

this.configureHeaders();
Expand Down Expand Up @@ -176,6 +199,10 @@ public void onSuccess(final int statusCode, final Map<String, List<String>> head
*/
public final boolean getSubscribers(final String channel, final RequestParams params,
final SubscriberResponseHandler handler) {
if (channel == null || params == null) {
logger.error(PARAMETERS_NULL, getClass().getEnclosingMethod().getName());
return false;
}
String url = String.format("%s/channel/%s/subscribers", getBaseUrl(), channel);

this.configureHeaders();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public void onSuccess(final int statusCode, final Map<String, List<String>> head
ChatToken value = objectMapper.readValue(content, ChatToken.class);
handler.onSuccess(value);
} catch (IOException e) {
logger.error("IOException {}", e.getLocalizedMessage());
handler.onFailure(e);
}
}
Expand Down
Loading

0 comments on commit 1d3fab2

Please sign in to comment.