Skip to content

Commit

Permalink
Merge branch 'release/0.2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Brutus5000 committed May 13, 2018
2 parents 8ac82e8 + f825bbd commit 8cf264c
Show file tree
Hide file tree
Showing 106 changed files with 1,164 additions and 1,605 deletions.
35 changes: 24 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.faforever</groupId>
<artifactId>faf-moderator-client</artifactId>
<version>0.2.0</version>
<version>0.2.1</version>
<packaging>jar</packaging>

<name>faf-moderator-client</name>
Expand All @@ -23,7 +23,15 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>

<jitpack.faf-java-commons.version>6a78e08</jitpack.faf-java-commons.version>
<jitpack.nocatch.version>1.1</jitpack.nocatch.version>
<jitpack.q-builders.version>1.6</jitpack.q-builders.version>
<jitpack.jasminb.jsonapi-converter.version>0.8</jitpack.jasminb.jsonapi-converter.version>
<org.mapstruct.version>1.2.0.Final</org.mapstruct.version>
<org.apache.httpcomponents.httpclient.version>4.5.3</org.apache.httpcomponents.httpclient.version>
<com.fasterxml.jackson.datatype.version>2.8.8</com.fasterxml.jackson.datatype.version>
<org.jetbrains.annotations.version>13.0</org.jetbrains.annotations.version>
<javax.inject.version>1</javax.inject.version>
</properties>

<repositories>
Expand All @@ -37,7 +45,7 @@
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>13.0</version>
<version>${org.jetbrains.annotations.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -50,37 +58,42 @@
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
<version>${javax.inject.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.8.8</version>
<version>${com.fasterxml.jackson.datatype.version}</version>
</dependency>
<dependency>
<groupId>com.github.jasminb</groupId>
<artifactId>jsonapi-converter</artifactId>
<version>0.8</version>
<version>${jitpack.jasminb.jsonapi-converter.version}</version>
</dependency>
<dependency>
<groupId>com.github.FAForever</groupId>
<artifactId>faf-java-commons</artifactId>
<version>a53e12e</version>
<groupId>com.github.FAForever.faf-java-commons</groupId>
<artifactId>faf-commons-data</artifactId>
<version>${jitpack.faf-java-commons.version}</version>
</dependency>
<dependency>
<groupId>com.github.FAForever.faf-java-commons</groupId>
<artifactId>faf-commons-api</artifactId>
<version>${jitpack.faf-java-commons.version}</version>
</dependency>
<dependency>
<groupId>com.github.micheljung</groupId>
<artifactId>nocatch</artifactId>
<version>1.1</version>
<version>${jitpack.nocatch.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
<version>${org.apache.httpcomponents.httpclient.version}</version>
</dependency>
<dependency>
<groupId>com.github.rutledgepaulv</groupId>
<artifactId>q-builders</artifactId>
<version>1.6</version>
<version>${jitpack.q-builders.version}</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.faforever.moderatorclient.api.rest;
package com.faforever.moderatorclient.api;

import com.github.jasminb.jsonapi.annotations.Type;
import com.github.rutledgepaulv.qbuilders.builders.QBuilder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.faforever.moderatorclient.api.rest;
package com.faforever.moderatorclient.api;

import com.faforever.moderatorclient.api.dto.LegacyAccessLevel;
import com.faforever.moderatorclient.api.dto.Player;
import com.faforever.commons.api.dto.LegacyAccessLevel;
import com.faforever.commons.api.dto.Player;
import com.faforever.moderatorclient.mapstruct.CycleAvoidingMappingContext;
import com.github.jasminb.jsonapi.JSONAPIDocument;
import com.github.jasminb.jsonapi.ResourceConverter;
import lombok.Getter;
Expand Down Expand Up @@ -34,6 +35,7 @@ public class FafApiCommunicationService {
private final ResourceConverter resourceConverter;
@Getter
private Player selfPlayer;
private final CycleAvoidingMappingContext cycleAvoidingMappingContext;
private final RestTemplateBuilder restTemplateBuilder;
private final HttpComponentsClientHttpRequestFactory requestFactory;
private final String apiClientId;
Expand All @@ -44,7 +46,7 @@ public class FafApiCommunicationService {
private RestOperations restOperations;


public FafApiCommunicationService(ResourceConverter resourceConverter, RestTemplateBuilder restTemplateBuilder,
public FafApiCommunicationService(ResourceConverter resourceConverter, CycleAvoidingMappingContext cycleAvoidingMappingContext, RestTemplateBuilder restTemplateBuilder,
JsonApiMessageConverter jsonApiMessageConverter,
JsonApiErrorHandler jsonApiErrorHandler,
@Value("${faforever.api.base-url}")
Expand All @@ -60,6 +62,7 @@ public FafApiCommunicationService(ResourceConverter resourceConverter, RestTempl

) {
this.resourceConverter = resourceConverter;
this.cycleAvoidingMappingContext = cycleAvoidingMappingContext;
this.apiClientId = apiClientId;
this.apiClientSecret = apiClientSecret;
this.apiAccessTokenUrl = apiAccessTokenUrl;
Expand Down Expand Up @@ -105,25 +108,15 @@ public LegacyAccessLevel login(String username, String password) {
}
}

@SneakyThrows
public void post(ElideRouteBuilder<?> routeBuilder, Object request, boolean bufferRequestBody) {
authorizedLatch.await();
requestFactory.setBufferRequestBody(bufferRequestBody);

try {
// Don't use Void.class here, otherwise Spring won't even try to deserialize error messages in the body
restOperations.postForEntity(routeBuilder.build(), request, String.class);
} finally {
requestFactory.setBufferRequestBody(true);
}
}

@SneakyThrows
public <T> T post(ElideRouteBuilder<T> routeBuilder, T object) {
authorizedLatch.await();
JSONAPIDocument<T> data = new JSONAPIDocument<>(object);
String dataString = new String(resourceConverter.writeDocument(data));
ResponseEntity<T> entity = restOperations.postForEntity(routeBuilder.build(), dataString, routeBuilder.getDtoClass());

cycleAvoidingMappingContext.clearCache();

return entity.getBody();
}

Expand All @@ -133,12 +126,16 @@ public Object postRelationship(ElideRouteBuilder<?> routeBuilder, Object object)
JSONAPIDocument<?> data = new JSONAPIDocument<>(object);
String dataString = new String(resourceConverter.writeDocument(data));
ResponseEntity<?> entity = restOperations.postForEntity(routeBuilder.build(), dataString, routeBuilder.getDtoClass());

cycleAvoidingMappingContext.clearCache();

return entity.getBody();
}

@SneakyThrows
public <T> T patch(ElideRouteBuilder<T> routeBuilder, T object) {
authorizedLatch.await();
cycleAvoidingMappingContext.clearCache();
return restOperations.patchForObject(routeBuilder.build(), object, routeBuilder.getDtoClass());
}

Expand All @@ -161,6 +158,7 @@ public <T> T getOne(String endpointPath, Class<T> type) {
@SuppressWarnings("unchecked")
@SneakyThrows
public <T> T getOne(String endpointPath, Class<T> type, java.util.Map<String, Serializable> params) {
cycleAvoidingMappingContext.clearCache();
return restOperations.getForObject(endpointPath, type, params);
}

Expand Down Expand Up @@ -199,6 +197,7 @@ public <T> List<T> getPage(ElideRouteBuilder<T> routeBuilder, int pageSize, int
.pageSize(pageSize)
.pageNumber(page)
.build();
cycleAvoidingMappingContext.clearCache();
log.debug("Sending API request: {}", route);
return (List<T>) restOperations.getForObject(
route,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.faforever.moderatorclient.api.rest;
package com.faforever.moderatorclient.api;


import com.faforever.moderatorclient.api.dto.ApiException;
import com.faforever.commons.api.dto.ApiException;
import com.github.jasminb.jsonapi.exceptions.ResourceParseException;
import com.github.jasminb.jsonapi.models.errors.Errors;
import org.springframework.http.HttpStatus;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.faforever.moderatorclient.api.rest;
package com.faforever.moderatorclient.api;

import com.github.jasminb.jsonapi.JSONAPIDocument;
import com.github.jasminb.jsonapi.ReflectionUtils;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.faforever.moderatorclient.api.rest.domain;
package com.faforever.moderatorclient.api.domain;

import com.faforever.moderatorclient.api.dto.Avatar;
import com.faforever.moderatorclient.api.rest.ElideRouteBuilder;
import com.faforever.moderatorclient.api.rest.FafApiCommunicationService;
import com.faforever.commons.api.dto.Avatar;
import com.faforever.moderatorclient.api.ElideRouteBuilder;
import com.faforever.moderatorclient.api.FafApiCommunicationService;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Service;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.faforever.moderatorclient.api.rest.domain;
package com.faforever.moderatorclient.api.domain;

import com.faforever.moderatorclient.api.dto.DomainBlacklist;
import com.faforever.moderatorclient.api.rest.ElideRouteBuilder;
import com.faforever.moderatorclient.api.rest.FafApiCommunicationService;
import com.faforever.commons.api.dto.DomainBlacklist;
import com.faforever.moderatorclient.api.ElideRouteBuilder;
import com.faforever.moderatorclient.api.FafApiCommunicationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.faforever.moderatorclient.api.rest.domain;
package com.faforever.moderatorclient.api.domain;

import com.faforever.moderatorclient.api.dto.Ladder1v1Map;
import com.faforever.moderatorclient.api.dto.Map;
import com.faforever.moderatorclient.api.dto.MapVersion;
import com.faforever.moderatorclient.api.rest.ElideRouteBuilder;
import com.faforever.moderatorclient.api.rest.FafApiCommunicationService;
import com.faforever.commons.api.dto.Ladder1v1Map;
import com.faforever.commons.api.dto.Map;
import com.faforever.commons.api.dto.MapVersion;
import com.faforever.moderatorclient.api.ElideRouteBuilder;
import com.faforever.moderatorclient.api.FafApiCommunicationService;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Service;
Expand Down
Loading

0 comments on commit 8cf264c

Please sign in to comment.