Skip to content

Commit

Permalink
3.0.21 - Remove constructors in Expand
Browse files Browse the repository at this point in the history
  • Loading branch information
saw303 committed Sep 1, 2023
1 parent 1181e73 commit 5fdd47c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 22 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {

subprojects { subproject ->

version = "3.0.20"
version = "3.0.21"

apply plugin: 'com.github.ben-manes.versions'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class RestApiPlugin implements Plugin<Project> {

project.configurations.maybeCreate(CONFIGURATION_REST_API)

final String pluginVersion = "3.0.20"
final String pluginVersion = "3.0.21"
final String libPhoneNumberVersion = "8.11.5"

final List<String> deps = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,18 @@ private void attachExpandedGetsBody(
HttpRequest<?> request,
EntityModel initialBody,
boolean mustAddEntityId) {
for (String expand : expands.trim().split(",")) {
for (String expandName : expands.trim().split(",")) {

Optional<SubResource> potSubResource =
contract.getSubresources().stream()
.filter(subResource -> expand.equals(subResource.getName()))
.filter(subResource -> Objects.equals(expandName, subResource.getName()))
.findAny();

if (!potSubResource.isPresent()) {
if (potSubResource.isEmpty()) {
log.warn(
"Expand '{}' is not a sub resource of '{}'", expand, contract.getGeneral().getName());
"Expand '{}' is not a sub resource of '{}'",
expandName,
contract.getGeneral().getName());
continue;
}

Expand All @@ -213,7 +215,7 @@ private void attachExpandedGetsBody(
Map<String, Object> variables = new HashMap<>(routeMatchCurrentResource.getVariableValues());

if (mustAddEntityId) {
variables.put("id", ((Identifiable) initialBody.getData()).getId());
variables.put("id", ((Identifiable<?>) initialBody.getData()).getId());
}

String targetUri =
Expand All @@ -224,7 +226,7 @@ private void attachExpandedGetsBody(
if (routeMatch.isPresent()) {
UriRouteMatch<Object, Object> routeMatchSubResource = routeMatch.get();
ExecutableMethod<Object, Object> executableMethod =
(ExecutableMethod<Object, Object>) routeMatchSubResource.getExecutableMethod();
routeMatchSubResource.getExecutableMethod();

Optional<Verb> getCollectionVerb =
contract.getVerbs().stream()
Expand All @@ -251,7 +253,7 @@ private void attachExpandedGetsBody(
}
}

Class declaringType = executableMethod.getDeclaringType();
Class<Object> declaringType = executableMethod.getDeclaringType();

Object bean = applicationContext.getBean(declaringType);

Expand Down Expand Up @@ -291,7 +293,8 @@ private void attachExpandedGetsBody(

Object result = executableMethod.invoke(bean, argumentList);

Expand expandedData = new Expand(expand);
Expand expandedData = new Expand();
expandedData.setName(expandName);

if (result instanceof Collection) {
expandedData.setData((List<ResourceModel>) result);
Expand All @@ -302,13 +305,13 @@ private void attachExpandedGetsBody(
} else if (result != null) {
log.error(
"Expand {} is neither a collection nor a resource model (class: {})",
expand,
expandName,
result.getClass().getCanonicalName());
} else {
log.error("Expand {} is null", expand);
log.error("Expand {} is null", expandName);
}
} catch (Exception e) {
log.error("Exception caught while expanding sub resource " + expand, e);
log.error("Exception caught while expanding sub resource " + expandName, e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,6 @@ public class Expand {

public Expand() {}

public Expand(String name) {
this.name = name;
}

public Expand(String name, List<ResourceModel> data) {
this.name = name;
this.data = data;
}

public String getName() {
return name;
}
Expand Down

0 comments on commit 5fdd47c

Please sign in to comment.