-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from blackdoor/feature/#5_uri-templates
The href in a HalLink can now be an RFC6570 URI template
- Loading branch information
Showing
5 changed files
with
140 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,6 @@ addons: | |
apt: | ||
packages: | ||
- oracle-java8-installer | ||
cache: | ||
directories: | ||
- $HOME/.m2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,136 @@ | ||
package black.door.hate; | ||
|
||
import com.damnhandy.uri.template.UriTemplate; | ||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import lombok.Builder; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import lombok.Getter; | ||
import lombok.NonNull; | ||
import lombok.SneakyThrows; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Created by nfischer on 12/8/2015. | ||
*/ | ||
@Builder | ||
@Getter | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public class HalLink implements LinkOrResource{ | ||
@NonNull | ||
private URI href; | ||
|
||
private Boolean templated; | ||
private String type; | ||
private URL deprecation; | ||
private String name; | ||
private URI profile; | ||
private String title; | ||
private String hreflang; | ||
private @NonNull final String href; | ||
private final Boolean templated; | ||
private final String type; | ||
private final URL deprecation; | ||
private final String name; | ||
private final URI profile; | ||
private final String title; | ||
private final String hreflang; | ||
|
||
@java.beans.ConstructorProperties({"href", "templated", "type", "deprecation", "name", "profile", "title", "hreflang"}) | ||
HalLink(String href, Boolean templated, String type, URL deprecation, String name, URI profile, String title, String hreflang) { | ||
this.href = href; | ||
this.templated = templated; | ||
this.type = type; | ||
this.deprecation = deprecation; | ||
this.name = name; | ||
this.profile = profile; | ||
this.title = title; | ||
this.hreflang = hreflang; | ||
} | ||
|
||
|
||
public static HalLinkBuilder builder() { | ||
return new HalLinkBuilder(); | ||
} | ||
|
||
@JsonIgnore | ||
@SneakyThrows(URISyntaxException.class) | ||
public URI getHrefAsUri(){ | ||
return new URI(href); | ||
} | ||
|
||
@JsonIgnore | ||
public UriTemplate getHrefAsTemplate(){ | ||
return UriTemplate.fromTemplate(href); | ||
} | ||
|
||
@Override | ||
public HalLink asLink() { | ||
return this; | ||
} | ||
|
||
@Override | ||
@SneakyThrows(JsonProcessingException.class) | ||
public String toString(){ | ||
return new ObjectMapper().writeValueAsString(this); | ||
} | ||
|
||
public static class HalLinkBuilder { | ||
private String href; | ||
private Boolean templated; | ||
private String type; | ||
private URL deprecation; | ||
private String name; | ||
private URI profile; | ||
private String title; | ||
private String hreflang; | ||
|
||
HalLinkBuilder() { | ||
} | ||
|
||
public HalLink.HalLinkBuilder href(UriTemplate href) { | ||
this.href = href.expandPartial(); | ||
templated = true; | ||
return this; | ||
} | ||
|
||
public HalLink.HalLinkBuilder href(URI href) { | ||
this.href = href.toASCIIString(); | ||
if(Objects.equals(templated, true)) | ||
templated = null; | ||
return this; | ||
} | ||
|
||
public HalLink.HalLinkBuilder type(String type) { | ||
this.type = type; | ||
return this; | ||
} | ||
|
||
public HalLink.HalLinkBuilder deprecation(URL deprecation) { | ||
this.deprecation = deprecation; | ||
return this; | ||
} | ||
|
||
public HalLink.HalLinkBuilder name(String name) { | ||
this.name = name; | ||
return this; | ||
} | ||
|
||
public HalLink.HalLinkBuilder profile(URI profile) { | ||
this.profile = profile; | ||
return this; | ||
} | ||
|
||
public HalLink.HalLinkBuilder title(String title) { | ||
this.title = title; | ||
return this; | ||
} | ||
|
||
public HalLink.HalLinkBuilder hreflang(String hreflang) { | ||
this.hreflang = hreflang; | ||
return this; | ||
} | ||
|
||
public HalLink build() { | ||
return new HalLink(href, templated, type, deprecation, name, profile, title, hreflang); | ||
} | ||
|
||
public String toString() { | ||
return "black.door.hate.HalLink.HalLinkBuilder(href=" + this.href + ", templated=" + this.templated + ", type=" + this.type + ", deprecation=" + this.deprecation + ", name=" + this.name + ", profile=" + this.profile + ", title=" + this.title + ", hreflang=" + this.hreflang + ")"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters