#784 - Polishing.

* Formatting.
* Copyright headers.
* Unused/unneeded methods.
This commit is contained in:
Greg Turnquist
2019-01-15 11:33:24 -06:00
parent b7a1c06f79
commit e9074c5d52
15 changed files with 96 additions and 82 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2018 the original author or authors.
* Copyright 2017-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -433,16 +433,16 @@ public class Jackson2UberModule extends SimpleModule {
List<Link> links = doc.getUber().getLinks();
return doc.getUber().getData().stream().filter(uberData -> !StringUtils.isEmpty(uberData.getName())).findFirst()
.map(uberData -> convertUberDataToResource(uberData, links)).orElseThrow(
.map(uberData -> convertToResource(uberData, links)).orElseThrow(
() -> new IllegalStateException("No data entry containing a 'value' was found in this document!"));
}
@NotNull
private Resource<Object> convertUberDataToResource(UberData uberData, List<Link> links) {
private Resource<Object> convertToResource(UberData uberData, List<Link> links) {
// Primitive type
List<UberData> data = uberData.getData();
if (data != null && data.size() == 1 && data.get(0).getName() == null) {
if (isPrimitiveType(data)) {
Object scalarValue = data.get(0).getValue();
return new Resource<>(scalarValue, links);
}
@@ -641,7 +641,7 @@ public class Jackson2UberModule extends SimpleModule {
// Primitive type
List<UberData> itemData = item.getData();
if (itemData != null && itemData.size() == 1 && itemData.get(0).getName() == null) {
if (isPrimitiveType(itemData)) {
Object scalarValue = itemData.get(0).getValue();
resource = new Resource<>(scalarValue, uberData.getLinks());
@@ -681,18 +681,26 @@ public class Jackson2UberModule extends SimpleModule {
* ...or return a Resources<T>
*/
List<Object> resourceLessContent = content.stream().map(item -> (Resource<?>) item).map(Resource::getContent)
List<Object> resourceLessContent = content.stream()
.map(item -> (Resource<?>) item)
.map(Resource::getContent)
.collect(Collectors.toList());
return new Resources<>(resourceLessContent, doc.getUber().getLinks());
}
}
private static boolean isPrimitiveType(List<UberData> data) {
return data != null && data.size() == 1 && data.get(0).getName() == null;
}
private static PageMetadata extractPagingMetadata(UberDocument doc) {
return doc.getUber().getData().stream()
.filter(uberData -> uberData.getName() != null && uberData.getName().equals("page")).findFirst()
.map(Jackson2UberModule::convertUberDataToPageMetaData).orElse(null);
.filter(uberData -> uberData.getName() != null && uberData.getName().equals("page"))
.findFirst()
.map(Jackson2UberModule::convertUberDataToPageMetaData)
.orElse(null);
}
@NotNull
@@ -724,6 +732,7 @@ public class Jackson2UberModule extends SimpleModule {
case "totalPages":
totalPages = (int) data.getValue();
break;
default:
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2018 the original author or authors.
* Copyright 2018-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@ import org.springframework.hateoas.uber.Jackson2UberModule.UberPagedResourcesDes
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
/**
* Jackson 2 mixin to handle {@link PagedResources}.
* Jackson 2 mixin to handle {@link PagedResources} for {@literal UBER+JSON}.
*
* @author Greg Turnquist
* @since 1.0

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2018 the original author or authors.
* Copyright 2018-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@ import org.springframework.hateoas.uber.Jackson2UberModule.UberResourceDeseriali
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
/**
* Jackson 2 mixin to handle {@link Resource}.
* Jackson 2 mixin to handle {@link Resource} for {@literal UBER+JSON}.
*
* @author Greg Turnquist
* @since 1.0

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2018 the original author or authors.
* Copyright 2018-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@ import org.springframework.hateoas.uber.Jackson2UberModule.UberResourceSupportDe
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
/**
* Jackson 2 mixin to handle {@link ResourceSupport}.
* Jackson 2 mixin to handle {@link ResourceSupport} for {@literal UBER+JSON}.
*
* @author Greg Turnquist
* @since 1.0

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2018 the original author or authors.
* Copyright 2018-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@ import org.springframework.hateoas.uber.Jackson2UberModule.UberResourcesDeserial
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
/**
* Jackson 2 mixin to handle {@link Resources}.
* Jackson 2 mixin to handle {@link Resources} for {@literal UBER+JSON}.
*
* @author Greg Turnquist
* @since 1.0

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2018 the original author or authors.
* Copyright 2018-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,7 +31,7 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* Enclosing collection in an UBER representation.
* Enclosing collection in an {@literal UBER+JSON} representation.
*
* @author Greg Turnquist
* @since 1.0

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 the original author or authors.
* Copyright 2014-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,7 +26,7 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
/**
* Embodies possible actions for an UBER representation, mapped onto {@link HttpMethod}s.
* Embodies possible actions for an {@literal UBER+JSON} representation, mapped onto {@link HttpMethod}s.
*
* @author Dietrich Schulten
* @author Greg Turnquist

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2018 the original author or authors.
* Copyright 2018-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2018 the original author or authors.
* Copyright 2018-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2018 the original author or authors.
* Copyright 2018-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -45,6 +45,7 @@ import org.springframework.util.StringUtils;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
@@ -57,6 +58,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
@Value
@Wither(AccessLevel.PACKAGE)
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
class UberData {
private String id;
@@ -109,28 +111,6 @@ class UberData {
return this.action;
}
/*
* Don't render if {@literal null}.
*/
public List<String> getRel() {
if (this.rel == null || this.rel.isEmpty()) {
return null;
}
return this.rel;
}
/*
* Don't render if {@literal null}.
*/
public List<UberData> getData() {
if (this.data == null || this.data.isEmpty()) {
return null;
}
return this.data;
}
/*
* Use a {@link Boolean} to support returning {@literal null}, and if it is {@literal null}, don't render.
*/
@@ -141,10 +121,6 @@ class UberData {
.orElse(null);
}
public void setTemplated(boolean __) {
// Ignore since "templated" is a virtual property
}
/*
* Use a {@link Boolean} to support returning {@literal null}, and if it is {@literal null}, don't render.
*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2018 the original author or authors.
* Copyright 2018-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,13 +21,12 @@ import lombok.Value;
import lombok.experimental.Wither;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* Top-level element in an UBER representation.
* Top-level element in an {@literal UBER+JSON} representation.
*
* @author Greg Turnquist
* @since 1.0
@@ -48,23 +47,4 @@ class UberDocument {
UberDocument() {
this("1.0", null, null);
}
/**
* Transform an object into a {@link UberDocument}.
*
* @param object
* @return
*/
static UberDocument toUberDocument(final Object object) {
if (object == null) {
return null;
}
if (object instanceof UberDocument) {
return (UberDocument) object;
}
throw new IllegalArgumentException("Don't know how to handle type : " + object.getClass());
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2018 the original author or authors.
* Copyright 2018-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,7 +25,7 @@ import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* UBER representation of an error.
* {@literal UBER+JSON} representation of an error.
*
* @author Greg Turnquist
* @since 1.0

View File

@@ -29,7 +29,7 @@ import org.springframework.http.MediaType;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* Find links by rel in an UBER representation.
* Find links by rel in an {@literal UBER+JSON} representation.
*
* TODO: Pending https://github.com/json-path/JsonPath/issues/429, replace deserializing solution with JsonPath-based expression "$.uber.data[?(@.rel.indexOf('%s') != -1)].url"
*