From 3fba0e61dede99e597e917d520e3339b18de05c8 Mon Sep 17 00:00:00 2001 From: Mitchell Feinstein Date: Fri, 29 Jun 2018 15:24:16 -0400 Subject: [PATCH 1/4] TIX-807 sharingProhibited: See https://github.com/ryantenney/passkit4j/pull/46 --- .../java/com/ryantenney/passkit4j/Pass.java | 271 +++++++++--------- 1 file changed, 141 insertions(+), 130 deletions(-) diff --git a/src/main/java/com/ryantenney/passkit4j/Pass.java b/src/main/java/com/ryantenney/passkit4j/Pass.java index 8e395ef..51e7fbd 100644 --- a/src/main/java/com/ryantenney/passkit4j/Pass.java +++ b/src/main/java/com/ryantenney/passkit4j/Pass.java @@ -26,174 +26,185 @@ @Data @NoArgsConstructor -@Accessors(chain=true, fluent=true) +@Accessors(chain = true, fluent = true) public class Pass { - // Standard Keys + // Standard Keys - @NonNull private String description; - @NonNull private String organizationName; - @NonNull private String passTypeIdentifier; - @NonNull private String serialNumber; - @NonNull private String teamIdentifier; + @JsonProperty("formatVersion") + private final int $formatVersion = 1; + @NonNull + private String description; + @NonNull + private String organizationName; + @NonNull + private String passTypeIdentifier; + @NonNull + private String serialNumber; + @NonNull + private String teamIdentifier; - @JsonProperty("formatVersion") private final int $formatVersion = 1; + // Visual Appearance Keys + private Barcode barcode; + private List barcodes; - // Visual Appearance Keys + private Color backgroundColor; + private Color foregroundColor; + private String groupingIdentifier; + private Color labelColor; + private String logoText; + @JsonInclude(Include.NON_DEFAULT) + private boolean suppressStripShine = false; - private Barcode barcode; - private List barcodes; - - private Color backgroundColor; - private Color foregroundColor; - private String groupingIdentifier; - private Color labelColor; - private String logoText; - @JsonInclude(Include.NON_DEFAULT) private boolean suppressStripShine = false; + // Web Service Keys - // Web Service Keys + private String webServiceURL; + private String authenticationToken; - private String webServiceURL; - private String authenticationToken; + // Relevance Keys + private boolean ignoresTimeZone = false; + private List locations; + private List beacons; + private Integer maxDistance; + private Date relevantDate; - // Relevance Keys - private boolean ignoresTimeZone = false; - private List locations; - private List beacons; - private Integer maxDistance; - private Date relevantDate; + // Associated App Keys - // Associated App Keys + private List associatedStoreIdentifiers; + private String appLaunchURL; - private List associatedStoreIdentifiers; - private String appLaunchURL; + // Companion App Keys - // Companion App Keys + private JsonNode userInfo; - private JsonNode userInfo; + // Expiration Keys - // Expiration Keys + private Date expirationDate; + @JsonInclude(Include.NON_DEFAULT) + private boolean voided = false; - private Date expirationDate; - @JsonInclude(Include.NON_DEFAULT) private boolean voided = false; + // NFC Keys + private NFC nfc; - // NFC Keys - private NFC nfc; + // Extended properties + @JsonInclude(Include.NON_DEFAULT) + private boolean sharingProhibited = false; + @JsonIgnore + private PassInformation passInformation; + @JsonIgnore + private List files; - @JsonIgnore private PassInformation passInformation; - @JsonIgnore private List files; + public List barcodes() { + return this.barcodes; + } - public List barcodes() { - return this.barcodes; - } - - public Pass barcodes(List values) { - this.barcodes = values; - return this; - } - - public Pass barcodes(Barcode... values) { - this.barcodes = Arrays.asList(values); - return this; - } - - public List files() { - if (this.files == null) { - return Collections.emptyList(); - } - return this.files; - } + public Pass barcodes(List values) { + this.barcodes = values; + return this; + } - public Pass files(List values) { - this.files = values; - return this; - } + public Pass barcodes(Barcode... values) { + this.barcodes = Arrays.asList(values); + return this; + } - public Pass files(NamedInputStreamSupplier... values) { - this.files = Arrays.asList(values); - return this; - } + public List files() { + if (this.files == null) { + return Collections.emptyList(); + } + return this.files; + } - public List locations() { - return this.locations; - } + public Pass files(List values) { + this.files = values; + return this; + } - public Pass locations(List values) { - this.locations = values; - return this; - } + public Pass files(NamedInputStreamSupplier... values) { + this.files = Arrays.asList(values); + return this; + } - public Pass locations(Location... values) { - this.locations = Arrays.asList(values); - return this; - } + public List locations() { + return this.locations; + } - public List beacons() { - return this.beacons; - } + public Pass locations(List values) { + this.locations = values; + return this; + } - public Pass beacons(List values) { - this.beacons = values; - return this; - } + public Pass locations(Location... values) { + this.locations = Arrays.asList(values); + return this; + } - public Pass beacons(Beacon... values) { - this.beacons = Arrays.asList(values); - return this; - } + public List beacons() { + return this.beacons; + } - public List associatedStoreIdentifiers() { - return this.associatedStoreIdentifiers; - } + public Pass beacons(List values) { + this.beacons = values; + return this; + } - public Pass associatedStoreIdentifiers(List values) { - this.associatedStoreIdentifiers = values; - return this; - } - - public Pass associatedStoreIdentifiers(Long... values) { - this.associatedStoreIdentifiers = Arrays.asList(values); - return this; - } + public Pass beacons(Beacon... values) { + this.beacons = Arrays.asList(values); + return this; + } - public Pass relevantDate(Date relevantDate) { - this.relevantDate = relevantDate; - return this; - } - - public Pass relevantDate(long timestamp) { - this.relevantDate = new Date(timestamp); - return this; - } - - public Pass relevantDate(String iso8601dateString) { - this.relevantDate = ISO8601Utils.parse(iso8601dateString); - return this; - } - - public Pass expirationDate(Date expirationDate) { - this.expirationDate = expirationDate; - return this; - } - - public Pass expirationDate(long timestamp) { - this.expirationDate = new Date(timestamp); - return this; - } - - public Pass expirationDate(String iso8601dateString) { - this.expirationDate = ISO8601Utils.parse(iso8601dateString); - return this; - } + public List associatedStoreIdentifiers() { + return this.associatedStoreIdentifiers; + } + + public Pass associatedStoreIdentifiers(List values) { + this.associatedStoreIdentifiers = values; + return this; + } + + public Pass associatedStoreIdentifiers(Long... values) { + this.associatedStoreIdentifiers = Arrays.asList(values); + return this; + } + + public Pass relevantDate(Date relevantDate) { + this.relevantDate = relevantDate; + return this; + } + + public Pass relevantDate(long timestamp) { + this.relevantDate = new Date(timestamp); + return this; + } + + public Pass relevantDate(String iso8601dateString) { + this.relevantDate = ISO8601Utils.parse(iso8601dateString); + return this; + } + + public Pass expirationDate(Date expirationDate) { + this.expirationDate = expirationDate; + return this; + } + + public Pass expirationDate(long timestamp) { + this.expirationDate = new Date(timestamp); + return this; + } + + public Pass expirationDate(String iso8601dateString) { + this.expirationDate = ISO8601Utils.parse(iso8601dateString); + return this; + } } From b8f6e92a553a904ec8db2fb845aba763a443ae46 Mon Sep 17 00:00:00 2001 From: Mitchell Feinstein Date: Fri, 29 Jun 2018 15:24:16 -0400 Subject: [PATCH 2/4] TIX-807 java8-doclint-disabled (needed for java8) --- pom.xml | 635 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 324 insertions(+), 311 deletions(-) diff --git a/pom.xml b/pom.xml index 88a594b..3cc1b6a 100644 --- a/pom.xml +++ b/pom.xml @@ -1,341 +1,354 @@ - - 4.0.0 + + 4.0.0 - com.ryantenney.passkit4j - passkit4j - jar - 2.0.2-SNAPSHOT - https://github.com/ryantenney/passkit4j - Passkit4j - Passbook Library for Java + com.ryantenney.passkit4j + passkit4j + jar + 2.0.2-SNAPSHOT + https://github.com/ryantenney/passkit4j + Passkit4j + Passbook Library for Java - - org.sonatype.oss - oss-parent - 7 - + + org.sonatype.oss + oss-parent + 7 + - - - The Apache Software License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - - + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + + - - scm:git:git://github.com/ryantenney/passkit4j.git - scm:git:git@github.com:ryantenney/passkit4j.git - https://github.com/ryantenney/passkit4j - HEAD - + + scm:git:git://github.com/ryantenney/passkit4j.git + scm:git:git@github.com:ryantenney/passkit4j.git + https://github.com/ryantenney/passkit4j + HEAD + - - github - https://github.com/ryantenney/passkit4j/issues - + + github + https://github.com/ryantenney/passkit4j/issues + - - - ryantenney - Ryan Tenney - ryan@10e.us - -5 - - + + + ryantenney + Ryan Tenney + ryan@10e.us + -5 + + - - UTF-8 - + + UTF-8 + - + - - org.projectlombok - lombok - 0.12.0 - provided - + + org.projectlombok + lombok + 1.18.0 + provided + - - com.fasterxml.jackson.core - jackson-core - 2.1.0 - - - com.fasterxml.jackson.core - jackson-annotations - 2.1.0 - - - com.fasterxml.jackson.core - jackson-databind - 2.1.0 - - - org.bouncycastle - bcmail-jdk15on - 1.47 - + + com.fasterxml.jackson.core + jackson-core + 2.1.0 + + + com.fasterxml.jackson.core + jackson-annotations + 2.1.0 + + + com.fasterxml.jackson.core + jackson-databind + 2.1.0 + + + org.bouncycastle + bcmail-jdk15on + 1.47 + - - junit - junit - 4.10 - test - + + junit + junit + 4.10 + test + - + - + - + - - org.apache.maven.plugins - maven-compiler-plugin - 2.3.2 - - 1.6 - 1.6 - - + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.6 + 1.6 + + - - org.apache.maven.plugins - maven-surefire-plugin - 2.12.3 - - classes - - + + org.apache.maven.plugins + maven-surefire-plugin + 2.12.3 + + classes + + - - org.apache.maven.plugins - maven-source-plugin - 2.1.2 - - - attach-sources - - jar - - - - + + org.apache.maven.plugins + maven-source-plugin + 2.1.2 + + + attach-sources + + jar + + + + - - org.apache.maven.plugins - maven-javadoc-plugin - 2.8.1 - - - attach-javadocs - - jar - - - - aggregate - - aggregate - - site - - - - ${project.version} - target/generated-sources/delombok - - + + org.apache.maven.plugins + maven-javadoc-plugin + 2.8.1 + + + attach-javadocs + + jar + + + ${javadoc.opts} + + + + aggregate + + aggregate + + site + + + + ${project.version} + target/generated-sources/delombok + + - - org.apache.maven.plugins - maven-dependency-plugin - 2.5.1 - - false - false - true - - - - default - verify - - analyze-only - analyze-duplicate - analyze-dep-mgt - - - - + + org.apache.maven.plugins + maven-dependency-plugin + 2.5.1 + + false + false + true + + + + default + verify + + analyze-only + analyze-duplicate + analyze-dep-mgt + + + + - - org.apache.maven.plugins - maven-enforcer-plugin - 1.2 - - - enforce - - - - - - - enforce - - - - + + org.apache.maven.plugins + maven-enforcer-plugin + 1.2 + + + enforce + + + + + + + enforce + + + + - - maven-release-plugin - 2.4 - - true - v@{project.version} - - forked-path - clean test - sonatype-nexus-staging::default::https://oss.sonatype.org/service/local/staging/deploy/maven2 - - + + maven-release-plugin + 2.4 + + true + v@{project.version} + + forked-path + clean test + + sonatype-nexus-staging::default::https://oss.sonatype.org/service/local/staging/deploy/maven2 + + + - - org.projectlombok - lombok-maven-plugin - 0.12.0.0 - - - generate-sources - - delombok - - - - - false - src/main/java - - + + org.projectlombok + lombok-maven-plugin + 1.18.0.0 + + + generate-sources + + delombok + + + + + false + src/main/java + + + + org.apache.maven.plugins + maven-site-plugin + 3.3 + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 2.7 + + false + false + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9 + + + org.codehaus.mojo + findbugs-maven-plugin + 2.5.2 + + Max + Default + true + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 2.10 + + checkstyle.xml + UTF-8 + + + + org.codehaus.mojo + cobertura-maven-plugin + 2.5.2 + + + html + xml + + + + + + + - - org.apache.maven.plugins - maven-site-plugin - 3.3 - - - - org.apache.maven.plugins - maven-project-info-reports-plugin - 2.7 - - false - false - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.9 - - - org.codehaus.mojo - findbugs-maven-plugin - 2.5.2 - - Max - Default - true - - - - org.apache.maven.plugins - maven-checkstyle-plugin - 2.10 - - checkstyle.xml - UTF-8 - - - - - - + - + + + java8-doclint-disabled + + [1.8,) + + + -Xdoclint:none + + - + + release-sign-artifacts + + + performRelease + true + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.4 + + + sign-artifacts + verify + + sign + + + + + + + - + + lombok-needs-tools-jar + + + ${java.home}/../lib/tools.jar + + + + + + org.projectlombok + lombok-maven-plugin + 1.18.0.0 + + + sun.jdk + tools + 1.6 + system + ${java.home}/../lib/tools.jar + + + + + + - - release-sign-artifacts - - - performRelease - true - - - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.4 - - - sign-artifacts - verify - - sign - - - - - - - - - - lombok-needs-tools-jar - - - ${java.home}/../lib/tools.jar - - - - - - org.projectlombok - lombok-maven-plugin - 0.12.0.0 - - - sun.jdk - tools - 1.6 - system - ${java.home}/../lib/tools.jar - - - - - - - - + From 2496443f018127e98c538bba76bc2faf23b2a91f Mon Sep 17 00:00:00 2001 From: Mitchell Feinstein Date: Fri, 29 Jun 2018 15:24:16 -0400 Subject: [PATCH 3/4] TIX-807 Format as per intellij defaults --- checkstyle.xml | 36 +-- .../passkit4j/BufferedPassResource.java | 80 ++--- .../ryantenney/passkit4j/PassResource.java | 96 +++--- .../passkit4j/PassSerializationException.java | 20 +- .../ryantenney/passkit4j/PassSerializer.java | 300 +++++++++--------- .../passkit4j/io/InputStreamSupplier.java | 2 +- .../io/NamedInputStreamSupplier.java | 2 +- .../ryantenney/passkit4j/model/Barcode.java | 12 +- .../passkit4j/sign/PassSignerImpl.java | 275 ++++++++-------- .../passkit4j/sign/PassSigningException.java | 20 +- .../passkit4j/sign/PassSigningUtil.java | 287 +++++++++-------- .../passkit4j/model/BarcodeFormat.java" | 42 +++ .../ryantenney/passkit4j/model/Beacon.java" | 29 ++ .../passkit4j/model/BoardingPass.java" | 25 ++ .../ryantenney/passkit4j/model/Color.java" | 69 ++++ .../ryantenney/passkit4j/model/Coupon.java" | 12 + .../passkit4j/model/DataDetectorType.java" | 42 +++ .../passkit4j/model/DateField.java" | 41 +++ .../passkit4j/model/DateStyle.java" | 43 +++ .../passkit4j/model/EventTicket.java" | 12 + .../ryantenney/passkit4j/model/Field.java" | 4 + .../ryantenney/passkit4j/model/Generic.java" | 12 + .../ryantenney/passkit4j/model/Location.java" | 25 ++ .../com/ryantenney/passkit4j/model/NFC.java" | 21 ++ .../passkit4j/model/NumberField.java" | 35 ++ .../passkit4j/model/NumberStyle.java" | 42 +++ .../passkit4j/model/PassInformation.java" | 80 +++++ .../passkit4j/model/StoreCard.java" | 12 + .../passkit4j/model/TextAlignment.java" | 43 +++ .../passkit4j/model/TextField.java" | 33 ++ .../passkit4j/model/TransitType.java" | 43 +++ .../passkit4j/sign/PassSigner.java" | 7 + .../passkit4j/EventTicketExample.java | 82 ++--- .../passkit4j/StoreCardExample.java | 104 +++--- 34 files changed, 1335 insertions(+), 653 deletions(-) create mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/BarcodeFormat.java" create mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/Beacon.java" create mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/BoardingPass.java" create mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/Color.java" create mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/Coupon.java" create mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/DataDetectorType.java" create mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/DateField.java" create mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/DateStyle.java" create mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/EventTicket.java" create mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/Field.java" create mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/Generic.java" create mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/Location.java" create mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/NFC.java" create mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/NumberField.java" create mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/NumberStyle.java" create mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/PassInformation.java" create mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/StoreCard.java" create mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/TextAlignment.java" create mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/TextField.java" create mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/TransitType.java" create mode 100644 "src/main\240java/com/ryantenney/passkit4j/sign/PassSigner.java" diff --git a/checkstyle.xml b/checkstyle.xml index e44db59..99f4bc9 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -1,7 +1,7 @@ + "-//Puppy Crawl//DTD Check Configuration 1.3//EN" + "http://www.puppycrawl.com/dtds/configuration_1_3.dtd"> - + @@ -59,10 +59,10 @@ - - - - + + + + @@ -101,15 +101,15 @@ - - - - - - - - - + + + + + + + + + @@ -163,8 +163,8 @@ - - + + diff --git a/src/main/java/com/ryantenney/passkit4j/BufferedPassResource.java b/src/main/java/com/ryantenney/passkit4j/BufferedPassResource.java index bb2a4b2..16857a2 100644 --- a/src/main/java/com/ryantenney/passkit4j/BufferedPassResource.java +++ b/src/main/java/com/ryantenney/passkit4j/BufferedPassResource.java @@ -11,45 +11,45 @@ public class BufferedPassResource extends PassResource { - private static final int DEFAULT_BUFFER_SIZE = 32768; - - public BufferedPassResource(final String filename) throws IOException { - this(new File(filename)); - } - - public BufferedPassResource(final File file) throws IOException { - this(file.getName(), file); - } - - public BufferedPassResource(final String name, final File file) throws IOException { - this(name, read(new FileInputStream(file), (int) file.length())); - } - - public BufferedPassResource(final String name, final InputStreamSupplier dataSupplier) throws IOException { - this(name, dataSupplier.getInputStream()); - } - - public BufferedPassResource(final String name, final InputStream data) throws IOException { - this(name, read(data, -1)); - } - - public BufferedPassResource(final String name, final byte[] data) { - super(name, new InputStreamSupplier() { - @Override - public InputStream getInputStream() throws IOException { - return new ByteArrayInputStream(data); - } - }); - } - - private static byte[] read(InputStream input, int length) throws IOException { - ByteArrayOutputStream out = new ByteArrayOutputStream(length == -1 ? DEFAULT_BUFFER_SIZE : length); - int read = 0; - byte[] buf = new byte[4096]; - while ((read = input.read(buf)) != -1) { - out.write(buf, 0, read); - } - return out.toByteArray(); - } + private static final int DEFAULT_BUFFER_SIZE = 32768; + + public BufferedPassResource(final String filename) throws IOException { + this(new File(filename)); + } + + public BufferedPassResource(final File file) throws IOException { + this(file.getName(), file); + } + + public BufferedPassResource(final String name, final File file) throws IOException { + this(name, read(new FileInputStream(file), (int) file.length())); + } + + public BufferedPassResource(final String name, final InputStreamSupplier dataSupplier) throws IOException { + this(name, dataSupplier.getInputStream()); + } + + public BufferedPassResource(final String name, final InputStream data) throws IOException { + this(name, read(data, -1)); + } + + public BufferedPassResource(final String name, final byte[] data) { + super(name, new InputStreamSupplier() { + @Override + public InputStream getInputStream() throws IOException { + return new ByteArrayInputStream(data); + } + }); + } + + private static byte[] read(InputStream input, int length) throws IOException { + ByteArrayOutputStream out = new ByteArrayOutputStream(length == -1 ? DEFAULT_BUFFER_SIZE : length); + int read = 0; + byte[] buf = new byte[4096]; + while ((read = input.read(buf)) != -1) { + out.write(buf, 0, read); + } + return out.toByteArray(); + } } diff --git a/src/main/java/com/ryantenney/passkit4j/PassResource.java b/src/main/java/com/ryantenney/passkit4j/PassResource.java index 641c35d..590df5a 100644 --- a/src/main/java/com/ryantenney/passkit4j/PassResource.java +++ b/src/main/java/com/ryantenney/passkit4j/PassResource.java @@ -13,62 +13,62 @@ public class PassResource implements NamedInputStreamSupplier { - private final String name; - private final InputStreamSupplier dataSupplier; + private final String name; + private final InputStreamSupplier dataSupplier; - public PassResource(final String filename) throws FileNotFoundException { - this(new File(filename)); - } + public PassResource(final String filename) throws FileNotFoundException { + this(new File(filename)); + } - public PassResource(final File file) throws FileNotFoundException { - this(file.getName(), file); - } + public PassResource(final File file) throws FileNotFoundException { + this(file.getName(), file); + } - public PassResource(final String name, final File file) { - this(name, new InputStreamSupplier() { - @Override - public InputStream getInputStream() throws IOException { - return new FileInputStream(file); - } - }); - } + public PassResource(final String name, final File file) { + this(name, new InputStreamSupplier() { + @Override + public InputStream getInputStream() throws IOException { + return new FileInputStream(file); + } + }); + } - public PassResource(final String name, final byte[] data) { - this(name, new InputStreamSupplier() { - @Override - public InputStream getInputStream() throws IOException { - return new ByteArrayInputStream(data); - } - }); - } + public PassResource(final String name, final byte[] data) { + this(name, new InputStreamSupplier() { + @Override + public InputStream getInputStream() throws IOException { + return new ByteArrayInputStream(data); + } + }); + } - public PassResource(final String name, final InputStream data) { - this(name, new InputStreamSupplier() { - private final AtomicBoolean avail = new AtomicBoolean(); + public PassResource(final String name, final InputStream data) { + this(name, new InputStreamSupplier() { + private final AtomicBoolean avail = new AtomicBoolean(); - @Override - public InputStream getInputStream() throws IOException { - if (!avail.compareAndSet(false, true)) { - throw new IOException("PassResource '" + name + "' has been consumed"); - } - return data; - } - }); - } + @Override + public InputStream getInputStream() throws IOException { + if (!avail.compareAndSet(false, true)) { + throw new IOException("PassResource '" + name + "' has been consumed"); + } + return data; + } + }); + } - public PassResource(final String name, final InputStreamSupplier dataSupplier) { - this.name = name; - this.dataSupplier = dataSupplier; - } + public PassResource(final String name, final InputStreamSupplier dataSupplier) { + this.name = name; + this.dataSupplier = dataSupplier; + } - @Override - public String getName() { - return name; - } + @Override + public String getName() { + return name; + } - @Override - public InputStream getInputStream() throws IOException { - return dataSupplier.getInputStream(); - } + @Override + public InputStream getInputStream() throws IOException { + return dataSupplier.getInputStream(); + } } diff --git a/src/main/java/com/ryantenney/passkit4j/PassSerializationException.java b/src/main/java/com/ryantenney/passkit4j/PassSerializationException.java index 031f2a1..018f715 100644 --- a/src/main/java/com/ryantenney/passkit4j/PassSerializationException.java +++ b/src/main/java/com/ryantenney/passkit4j/PassSerializationException.java @@ -4,18 +4,18 @@ public class PassSerializationException extends IOException { - private static final long serialVersionUID = 2782383453975495855L; + private static final long serialVersionUID = 2782383453975495855L; - public PassSerializationException(String message) { - super(message); - } + public PassSerializationException(String message) { + super(message); + } - public PassSerializationException(Throwable cause) { - super(cause); - } + public PassSerializationException(Throwable cause) { + super(cause); + } - public PassSerializationException(String message, Throwable cause) { - super(message, cause); - } + public PassSerializationException(String message, Throwable cause) { + super(message, cause); + } } diff --git a/src/main/java/com/ryantenney/passkit4j/PassSerializer.java b/src/main/java/com/ryantenney/passkit4j/PassSerializer.java index ed407a9..cde4c7a 100644 --- a/src/main/java/com/ryantenney/passkit4j/PassSerializer.java +++ b/src/main/java/com/ryantenney/passkit4j/PassSerializer.java @@ -38,154 +38,156 @@ public class PassSerializer { - public static final String PKPASS_TYPE = "application/vnd.apple.pkpass"; - - private static final ObjectMapper objectMapper; - - static { - objectMapper = new ObjectMapper(); - objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); - objectMapper.setDateFormat(new ISO8601DateFormat()); - objectMapper.setVisibilityChecker(objectMapper.getVisibilityChecker().withFieldVisibility(Visibility.ANY)); - objectMapper.setSerializationInclusion(Include.NON_EMPTY); - } - - public static void writePkPassArchive(Pass pass, PassSigner signer, OutputStream out) throws PassSigningException, PassSerializationException { - ZipOutputStream zip = new ZipOutputStream(out); - - try { - - Map manifest = writeAndHashFiles(pass.files(), zip); - manifest.put("pass.json", write(generatePass(pass), hasher(zipEntry("pass.json", zip))).hash()); - - byte[] manifestData = write(generateManifest(manifest), new ByteArrayOutputStream()).toByteArray(); - write(manifestData, zipEntry("manifest.json", zip)); - - byte[] signatureData = signer.generateSignature(manifestData); - write(signatureData, zipEntry("signature", zip)); - - } catch (NoSuchAlgorithmException e) { - throw new PassSerializationException(e); - } catch (DigestException e) { - throw new PassSerializationException(e); - } catch (NoSuchProviderException e) { - throw new PassSerializationException(e); - } catch (IOException e) { - throw new PassSerializationException(e); - } finally { - try { - if (zip != null) zip.close(); - } catch (IOException e) { - throw new PassSerializationException("Error closing output stream", e); - } - } - } - - protected static ObjectNode generatePass(Pass pass) { - ObjectNode tree = objectMapper.valueToTree(pass); - - PassInformation info = pass.passInformation(); - tree.put(info.typeName(), objectMapper.valueToTree(info)); - - return tree; - } - - protected static ObjectNode generateManifest(Map files) { - ObjectNode node = new ObjectNode(JsonNodeFactory.instance); - for (Map.Entry file : files.entrySet()) { - node.put(file.getKey(), file.getValue()); - } - return node; - } - - protected static Map writeAndHashFiles(List files, ZipOutputStream output) throws IOException, NoSuchAlgorithmException, DigestException, NoSuchProviderException { - Map hashes = new HashMap(); - for (NamedInputStreamSupplier file : files) { - OutputStreamHasher hasher = hasher(zipEntry(file.getName(), output)); - copy(file.getInputStream(), hasher); - hashes.put(file.getName(), hasher.hash()); - } - return hashes; - } - - private static T write(JsonNode node, T output) throws IOException { - objectMapper - .getFactory() - .createGenerator(output) - .useDefaultPrettyPrinter() - .writeTree(node); - output.close(); - return output; - } - - private static T write(byte[] data, T output) throws IOException { - output.write(data); - output.close(); - return output; - } - - private static void copy(InputStream input, OutputStream output) throws IOException, NoSuchAlgorithmException, DigestException { - try { - final int EOF = -1; - int n = 0; - byte[] buffer = new byte[4096]; - while (EOF != (n = input.read(buffer))) { - output.write(buffer, 0, n); - } - } finally { - input.close(); - output.close(); - } - } - - private static OutputStreamHasher hasher(OutputStream output) throws NoSuchAlgorithmException, NoSuchProviderException { - return new OutputStreamHasher(output); - } - - @Accessors(fluent=true) - private static class OutputStreamHasher extends OutputStream { - - @Delegate(types=OutputStream.class, excludes=Closeable.class) - private final DigestOutputStream output; - - private final MessageDigest digest; - - @Getter private final OutputStream inner; - @Getter private String hash; - - public OutputStreamHasher(final OutputStream inner) throws NoSuchAlgorithmException, NoSuchProviderException { - this.inner = inner; - this.digest = MessageDigest.getInstance("SHA1", BouncyCastleProvider.PROVIDER_NAME); - this.output = new DigestOutputStream(this.inner, this.digest); - } - - @Override - public void close() throws IOException { - this.hash = new String(Hex.encode(this.output.getMessageDigest().digest())); - this.output.close(); - } - - } - - private static OutputStream zipEntry(final String name, final ZipOutputStream output) throws IOException { - return new ZipEntryOutputStream(name, output); - } - - private static class ZipEntryOutputStream extends OutputStream { - - @Delegate(types=OutputStream.class, excludes=Closeable.class) - private final ZipOutputStream output; - - public ZipEntryOutputStream(String name, ZipOutputStream output) throws IOException { - this.output = output; - this.output.putNextEntry(new ZipEntry(name)); - } - - @Override - public void close() throws IOException { - output.closeEntry(); - } - - } + public static final String PKPASS_TYPE = "application/vnd.apple.pkpass"; + + private static final ObjectMapper objectMapper; + + static { + objectMapper = new ObjectMapper(); + objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); + objectMapper.setDateFormat(new ISO8601DateFormat()); + objectMapper.setVisibilityChecker(objectMapper.getVisibilityChecker().withFieldVisibility(Visibility.ANY)); + objectMapper.setSerializationInclusion(Include.NON_EMPTY); + } + + public static void writePkPassArchive(Pass pass, PassSigner signer, OutputStream out) throws PassSigningException, PassSerializationException { + ZipOutputStream zip = new ZipOutputStream(out); + + try { + + Map manifest = writeAndHashFiles(pass.files(), zip); + manifest.put("pass.json", write(generatePass(pass), hasher(zipEntry("pass.json", zip))).hash()); + + byte[] manifestData = write(generateManifest(manifest), new ByteArrayOutputStream()).toByteArray(); + write(manifestData, zipEntry("manifest.json", zip)); + + byte[] signatureData = signer.generateSignature(manifestData); + write(signatureData, zipEntry("signature", zip)); + + } catch (NoSuchAlgorithmException e) { + throw new PassSerializationException(e); + } catch (DigestException e) { + throw new PassSerializationException(e); + } catch (NoSuchProviderException e) { + throw new PassSerializationException(e); + } catch (IOException e) { + throw new PassSerializationException(e); + } finally { + try { + if (zip != null) zip.close(); + } catch (IOException e) { + throw new PassSerializationException("Error closing output stream", e); + } + } + } + + protected static ObjectNode generatePass(Pass pass) { + ObjectNode tree = objectMapper.valueToTree(pass); + + PassInformation info = pass.passInformation(); + tree.put(info.typeName(), objectMapper.valueToTree(info)); + + return tree; + } + + protected static ObjectNode generateManifest(Map files) { + ObjectNode node = new ObjectNode(JsonNodeFactory.instance); + for (Map.Entry file : files.entrySet()) { + node.put(file.getKey(), file.getValue()); + } + return node; + } + + protected static Map writeAndHashFiles(List files, ZipOutputStream output) throws IOException, NoSuchAlgorithmException, DigestException, NoSuchProviderException { + Map hashes = new HashMap(); + for (NamedInputStreamSupplier file : files) { + OutputStreamHasher hasher = hasher(zipEntry(file.getName(), output)); + copy(file.getInputStream(), hasher); + hashes.put(file.getName(), hasher.hash()); + } + return hashes; + } + + private static T write(JsonNode node, T output) throws IOException { + objectMapper + .getFactory() + .createGenerator(output) + .useDefaultPrettyPrinter() + .writeTree(node); + output.close(); + return output; + } + + private static T write(byte[] data, T output) throws IOException { + output.write(data); + output.close(); + return output; + } + + private static void copy(InputStream input, OutputStream output) throws IOException, NoSuchAlgorithmException, DigestException { + try { + final int EOF = -1; + int n = 0; + byte[] buffer = new byte[4096]; + while (EOF != (n = input.read(buffer))) { + output.write(buffer, 0, n); + } + } finally { + input.close(); + output.close(); + } + } + + private static OutputStreamHasher hasher(OutputStream output) throws NoSuchAlgorithmException, NoSuchProviderException { + return new OutputStreamHasher(output); + } + + private static OutputStream zipEntry(final String name, final ZipOutputStream output) throws IOException { + return new ZipEntryOutputStream(name, output); + } + + @Accessors(fluent = true) + private static class OutputStreamHasher extends OutputStream { + + @Delegate(types = OutputStream.class, excludes = Closeable.class) + private final DigestOutputStream output; + + private final MessageDigest digest; + + @Getter + private final OutputStream inner; + @Getter + private String hash; + + public OutputStreamHasher(final OutputStream inner) throws NoSuchAlgorithmException, NoSuchProviderException { + this.inner = inner; + this.digest = MessageDigest.getInstance("SHA1", BouncyCastleProvider.PROVIDER_NAME); + this.output = new DigestOutputStream(this.inner, this.digest); + } + + @Override + public void close() throws IOException { + this.hash = new String(Hex.encode(this.output.getMessageDigest().digest())); + this.output.close(); + } + + } + + private static class ZipEntryOutputStream extends OutputStream { + + @Delegate(types = OutputStream.class, excludes = Closeable.class) + private final ZipOutputStream output; + + public ZipEntryOutputStream(String name, ZipOutputStream output) throws IOException { + this.output = output; + this.output.putNextEntry(new ZipEntry(name)); + } + + @Override + public void close() throws IOException { + output.closeEntry(); + } + + } } diff --git a/src/main/java/com/ryantenney/passkit4j/io/InputStreamSupplier.java b/src/main/java/com/ryantenney/passkit4j/io/InputStreamSupplier.java index ce5ddab..9eb4f1d 100644 --- a/src/main/java/com/ryantenney/passkit4j/io/InputStreamSupplier.java +++ b/src/main/java/com/ryantenney/passkit4j/io/InputStreamSupplier.java @@ -5,6 +5,6 @@ public interface InputStreamSupplier { - public InputStream getInputStream() throws IOException; + public InputStream getInputStream() throws IOException; } diff --git a/src/main/java/com/ryantenney/passkit4j/io/NamedInputStreamSupplier.java b/src/main/java/com/ryantenney/passkit4j/io/NamedInputStreamSupplier.java index 38725f9..85a2969 100644 --- a/src/main/java/com/ryantenney/passkit4j/io/NamedInputStreamSupplier.java +++ b/src/main/java/com/ryantenney/passkit4j/io/NamedInputStreamSupplier.java @@ -2,6 +2,6 @@ public interface NamedInputStreamSupplier extends InputStreamSupplier { - public String getName(); + public String getName(); } diff --git a/src/main/java/com/ryantenney/passkit4j/model/Barcode.java b/src/main/java/com/ryantenney/passkit4j/model/Barcode.java index 3828399..c38a165 100644 --- a/src/main/java/com/ryantenney/passkit4j/model/Barcode.java +++ b/src/main/java/com/ryantenney/passkit4j/model/Barcode.java @@ -6,16 +6,18 @@ import lombok.experimental.Accessors; @Data -@Accessors(chain=true, fluent=true) +@Accessors(chain = true, fluent = true) @RequiredArgsConstructor public class Barcode { - @NonNull private BarcodeFormat format; + @NonNull + private BarcodeFormat format; - @NonNull private String message; + @NonNull + private String message; - private String messageEncoding = "iso-8859-1"; + private String messageEncoding = "iso-8859-1"; - private String altText = null; + private String altText = null; } diff --git a/src/main/java/com/ryantenney/passkit4j/sign/PassSignerImpl.java b/src/main/java/com/ryantenney/passkit4j/sign/PassSignerImpl.java index 0999595..0b31f85 100644 --- a/src/main/java/com/ryantenney/passkit4j/sign/PassSignerImpl.java +++ b/src/main/java/com/ryantenney/passkit4j/sign/PassSignerImpl.java @@ -25,139 +25,146 @@ @RequiredArgsConstructor public class PassSignerImpl implements PassSigner { - @NonNull private final CMSSignedDataGenerator generator; - - public static Builder builder() { - return new Builder(); - } - - @Getter - @Setter - @Accessors(chain=true, fluent=true) - @NoArgsConstructor - public static class Builder { - - @NonNull private X509Certificate signingCertificate; - @NonNull private PrivateKey privateKey; - @NonNull private X509Certificate intermediateCertificate; - - private KeyStore keyStore; - private String signingCertificateAlias; - private String privateKeyAlias; - private String password; - - public Builder keystore(InputStream inputStream, String password) throws PassSigningException { - return this.keystore(inputStream, null, password); - } - - /** - * Deprecated in favor of calling {@code keystore(InputStream, String)} - * followed by setting the alias with {@code alias(String)} - * @param keyStore - * @param alias - * @param password - * @return - */ - @Deprecated - public Builder keystore(InputStream inputStream, String alias, String password) throws PassSigningException { - KeyStore keyStore = loadPKCS12File(inputStream, password); - return this.keystore(keyStore, alias, password); - } - - public Builder keystore(KeyStore keyStore, String password) { - return this.keystore(keyStore, null, password); - } - - /** - * Deprecated in favor of calling {@code keystore(KeyStore, String)} - * followed by setting the alias with {@code alias(String)} - * @param keyStore - * @param alias - * @param password - * @return - */ - @Deprecated - public Builder keystore(KeyStore keyStore, String alias, String password) { - this.keyStore = keyStore; - this.signingCertificateAlias = alias; - this.privateKeyAlias = alias; - this.password = password; - return this; - } - - /** - * Sets both the signing certificate and private key aliases - * @param alias - * @return this - */ - public Builder alias(String alias) { - this.signingCertificateAlias = alias; - this.privateKeyAlias = alias; - return this; - } - - public Builder intermediateCertificate(InputStream inputStream) throws PassSigningException { - this.intermediateCertificate = loadDERCertificate(inputStream); - return this; - } - - public Builder intermediateCertificate(X509Certificate intermediateCertificate) { - this.intermediateCertificate = intermediateCertificate; - return this; - } - - public PassSigner build() throws PassSigningException { - if (signingCertificate == null) { - signingCertificate = getCertificate(keyStore, signingCertificateAlias); - } - - if (privateKey == null) { - privateKey = getPrivateKey(keyStore, privateKeyAlias, password); - } - - if (intermediateCertificate == null) { - throw new PassSigningException("Must provide an intermediate certificate"); - } - - return new PassSignerImpl(signingCertificate, privateKey, intermediateCertificate); - } - - } - - public PassSignerImpl(X509Certificate signingCertificate, PrivateKey privateKey, X509Certificate intermediateCertificate) throws PassSigningException { - this.generator = createGenerator(signingCertificate, privateKey, intermediateCertificate); - } - - public CMSSignedDataGenerator createGenerator(X509Certificate signingCertificate, PrivateKey privateKey, X509Certificate intermediateCertificate) throws PassSigningException { - ensureBCProvider(); - - try { - - CMSSignedDataGenerator generator = new CMSSignedDataGenerator(); - generator.addSignerInfoGenerator(new JcaSimpleSignerInfoGeneratorBuilder() - .setProvider(BouncyCastleProvider.PROVIDER_NAME) - .build("SHA1withRSA", privateKey, signingCertificate)); - generator.addCertificates(new JcaCertStore(Arrays.asList(intermediateCertificate, signingCertificate))); - - return generator; - - } catch (Exception ex) { - throw propagateAsPassSigningException("Error creating PassSignerImpl instance", ex); - } - } - - public byte[] generateSignature(byte[] data) throws PassSigningException { - ensureBCProvider(); - - try { - - CMSProcessableByteArray processableData = new CMSProcessableByteArray(data); - CMSSignedData signedData = generator.generate(processableData); - return signedData.getEncoded(); - - } catch (Exception ex) { - throw propagateAsPassSigningException("Error generating signautre", ex); - } - } + @NonNull + private final CMSSignedDataGenerator generator; + + public PassSignerImpl(X509Certificate signingCertificate, PrivateKey privateKey, X509Certificate intermediateCertificate) throws PassSigningException { + this.generator = createGenerator(signingCertificate, privateKey, intermediateCertificate); + } + + public static Builder builder() { + return new Builder(); + } + + public CMSSignedDataGenerator createGenerator(X509Certificate signingCertificate, PrivateKey privateKey, X509Certificate intermediateCertificate) throws PassSigningException { + ensureBCProvider(); + + try { + + CMSSignedDataGenerator generator = new CMSSignedDataGenerator(); + generator.addSignerInfoGenerator(new JcaSimpleSignerInfoGeneratorBuilder() + .setProvider(BouncyCastleProvider.PROVIDER_NAME) + .build("SHA1withRSA", privateKey, signingCertificate)); + generator.addCertificates(new JcaCertStore(Arrays.asList(intermediateCertificate, signingCertificate))); + + return generator; + + } catch (Exception ex) { + throw propagateAsPassSigningException("Error creating PassSignerImpl instance", ex); + } + } + + public byte[] generateSignature(byte[] data) throws PassSigningException { + ensureBCProvider(); + + try { + + CMSProcessableByteArray processableData = new CMSProcessableByteArray(data); + CMSSignedData signedData = generator.generate(processableData); + return signedData.getEncoded(); + + } catch (Exception ex) { + throw propagateAsPassSigningException("Error generating signautre", ex); + } + } + + @Getter + @Setter + @Accessors(chain = true, fluent = true) + @NoArgsConstructor + public static class Builder { + + @NonNull + private X509Certificate signingCertificate; + @NonNull + private PrivateKey privateKey; + @NonNull + private X509Certificate intermediateCertificate; + + private KeyStore keyStore; + private String signingCertificateAlias; + private String privateKeyAlias; + private String password; + + public Builder keystore(InputStream inputStream, String password) throws PassSigningException { + return this.keystore(inputStream, null, password); + } + + /** + * Deprecated in favor of calling {@code keystore(InputStream, String)} + * followed by setting the alias with {@code alias(String)} + * + * @param keyStore + * @param alias + * @param password + * @return + */ + @Deprecated + public Builder keystore(InputStream inputStream, String alias, String password) throws PassSigningException { + KeyStore keyStore = loadPKCS12File(inputStream, password); + return this.keystore(keyStore, alias, password); + } + + public Builder keystore(KeyStore keyStore, String password) { + return this.keystore(keyStore, null, password); + } + + /** + * Deprecated in favor of calling {@code keystore(KeyStore, String)} + * followed by setting the alias with {@code alias(String)} + * + * @param keyStore + * @param alias + * @param password + * @return + */ + @Deprecated + public Builder keystore(KeyStore keyStore, String alias, String password) { + this.keyStore = keyStore; + this.signingCertificateAlias = alias; + this.privateKeyAlias = alias; + this.password = password; + return this; + } + + /** + * Sets both the signing certificate and private key aliases + * + * @param alias + * @return this + */ + public Builder alias(String alias) { + this.signingCertificateAlias = alias; + this.privateKeyAlias = alias; + return this; + } + + public Builder intermediateCertificate(InputStream inputStream) throws PassSigningException { + this.intermediateCertificate = loadDERCertificate(inputStream); + return this; + } + + public Builder intermediateCertificate(X509Certificate intermediateCertificate) { + this.intermediateCertificate = intermediateCertificate; + return this; + } + + public PassSigner build() throws PassSigningException { + if (signingCertificate == null) { + signingCertificate = getCertificate(keyStore, signingCertificateAlias); + } + + if (privateKey == null) { + privateKey = getPrivateKey(keyStore, privateKeyAlias, password); + } + + if (intermediateCertificate == null) { + throw new PassSigningException("Must provide an intermediate certificate"); + } + + return new PassSignerImpl(signingCertificate, privateKey, intermediateCertificate); + } + + } } diff --git a/src/main/java/com/ryantenney/passkit4j/sign/PassSigningException.java b/src/main/java/com/ryantenney/passkit4j/sign/PassSigningException.java index 2ccf97f..b0d1373 100644 --- a/src/main/java/com/ryantenney/passkit4j/sign/PassSigningException.java +++ b/src/main/java/com/ryantenney/passkit4j/sign/PassSigningException.java @@ -2,18 +2,18 @@ public class PassSigningException extends Exception { - private static final long serialVersionUID = 6021707149897120829L; + private static final long serialVersionUID = 6021707149897120829L; - public PassSigningException(String message) { - super(message); - } + public PassSigningException(String message) { + super(message); + } - public PassSigningException(Throwable cause) { - super(cause); - } + public PassSigningException(Throwable cause) { + super(cause); + } - public PassSigningException(String message, Throwable cause) { - super(message, cause); - } + public PassSigningException(String message, Throwable cause) { + super(message, cause); + } } diff --git a/src/main/java/com/ryantenney/passkit4j/sign/PassSigningUtil.java b/src/main/java/com/ryantenney/passkit4j/sign/PassSigningUtil.java index 0e40bc4..a1bf61a 100644 --- a/src/main/java/com/ryantenney/passkit4j/sign/PassSigningUtil.java +++ b/src/main/java/com/ryantenney/passkit4j/sign/PassSigningUtil.java @@ -16,149 +16,148 @@ class PassSigningUtil { - static KeyStore loadPKCS12File(InputStream inputStream, String password) throws PassSigningException { - ensureBCProvider(); - - try { - - KeyStore keystore = KeyStore.getInstance("PKCS12", BouncyCastleProvider.PROVIDER_NAME); - keystore.load(inputStream, chars(password)); - return keystore; - - } catch (Exception e) { - throw propagateAsPassSigningException("Error loading PKCS12 KeyStore", e); - } finally { - try { - if (inputStream != null) inputStream.close(); - } catch (IOException e) {} - } - } - - static X509Certificate loadDERCertificate(InputStream inputStream) throws PassSigningException { - ensureBCProvider(); - - Certificate cert; - try { - - CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509", BouncyCastleProvider.PROVIDER_NAME); - cert = certificateFactory.generateCertificate(inputStream); - - } catch (Exception e) { - throw propagateAsPassSigningException("Error loading certificate", e); - } finally { - try { - if (inputStream != null) inputStream.close(); - } catch (IOException e) {} - } - - if (!(cert instanceof X509Certificate)) { - throw new PassSigningException("Certificate is not of type X509Certificate"); - } - - return (X509Certificate) cert; - } - - /** - * - * @param keyStore - * @param alias - * @param password - * @return a PrivateKey - * @throws PassSigningException if there are problems reading from the KeyStore, - * there is no private key with the provided alias, or the certificate - * is not of type PrivateKey - */ - static PrivateKey getPrivateKey(KeyStore keyStore, String alias, String password) throws PassSigningException { - if (alias == null) alias = firstAlias(keyStore); - - Key key; - try { - key = keyStore.getKey(alias, chars(password)); - } catch (Exception ex) { - throw propagateAsPassSigningException("Error retrieving PrivateKey from KeyStore", ex); - } - - if (key == null) { - throw new PassSigningException("KeyStore does not contain a PrivateKey with alias '" + alias + "'"); - } else if (!(key instanceof PrivateKey)) { - throw new PassSigningException("KeyStore entry with alias '" + alias + "' is not of type PrivateKey"); - } - - return (PrivateKey) key; - } - - /** - * - * @param keyStore - * @param alias - * @return an X509Certificate - * @throws PassSigningException if there are problems reading from the KeyStore, - * there is no certificate with the provided alias, or the certificate - * is not of type X509Certificate - */ - static X509Certificate getCertificate(KeyStore keyStore, String alias) throws PassSigningException { - if (alias == null) alias = firstAlias(keyStore); - - Certificate cert; - try { - cert = keyStore.getCertificate(alias); - } catch (Exception ex) { - throw propagateAsPassSigningException("Error retrieving certificate from KeyStore", ex); - } - - if (cert == null) { - throw new PassSigningException("KeyStore does not contain an X509Certificate with alias '" + alias + "'"); - } else if (!(cert instanceof X509Certificate)) { - throw new PassSigningException("KeyStore entry with alias '" + alias + "' is not of type X509Certificate"); - } - - return (X509Certificate) cert; - } - - /** - * - * @param keyStore - * @return a valid alias from the provided KeyStore - * @throws PassSigningException if there are problems reading from the KeyStore or - * the KeyStore doesn't contain exactly one alias. - */ - static String firstAlias(KeyStore keyStore) throws PassSigningException { - Enumeration aliases; - try { - aliases = keyStore.aliases(); - } catch (KeyStoreException ex) { - throw propagateAsPassSigningException("Error reading aliases from KeyStore", ex); - } - - if (aliases.hasMoreElements()) { - String alias = aliases.nextElement(); - if (aliases.hasMoreElements()) { - throw new PassSigningException("Provided KeyStore contains multiple aliases, please specify an alias"); - } - return alias; - } - throw new PassSigningException("Provided KeyStore is empty"); - } - - static char[] chars(String password) { - if (password == null) return new char[0]; - return password.toCharArray(); - } - - static void ensureBCProvider() { - if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) { - Security.addProvider(new BouncyCastleProvider()); - } - } - - static PassSigningException propagateAsPassSigningException(String message, Exception ex) throws PassSigningException { - if (ex instanceof RuntimeException) { - throw (RuntimeException) ex; - } else if (ex instanceof PassSigningException) { - throw (PassSigningException) ex; - } - - throw new PassSigningException(message, ex); - } + static KeyStore loadPKCS12File(InputStream inputStream, String password) throws PassSigningException { + ensureBCProvider(); + + try { + + KeyStore keystore = KeyStore.getInstance("PKCS12", BouncyCastleProvider.PROVIDER_NAME); + keystore.load(inputStream, chars(password)); + return keystore; + + } catch (Exception e) { + throw propagateAsPassSigningException("Error loading PKCS12 KeyStore", e); + } finally { + try { + if (inputStream != null) inputStream.close(); + } catch (IOException e) { + } + } + } + + static X509Certificate loadDERCertificate(InputStream inputStream) throws PassSigningException { + ensureBCProvider(); + + Certificate cert; + try { + + CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509", BouncyCastleProvider.PROVIDER_NAME); + cert = certificateFactory.generateCertificate(inputStream); + + } catch (Exception e) { + throw propagateAsPassSigningException("Error loading certificate", e); + } finally { + try { + if (inputStream != null) inputStream.close(); + } catch (IOException e) { + } + } + + if (!(cert instanceof X509Certificate)) { + throw new PassSigningException("Certificate is not of type X509Certificate"); + } + + return (X509Certificate) cert; + } + + /** + * @param keyStore + * @param alias + * @param password + * @return a PrivateKey + * @throws PassSigningException if there are problems reading from the KeyStore, + * there is no private key with the provided alias, or the certificate + * is not of type PrivateKey + */ + static PrivateKey getPrivateKey(KeyStore keyStore, String alias, String password) throws PassSigningException { + if (alias == null) alias = firstAlias(keyStore); + + Key key; + try { + key = keyStore.getKey(alias, chars(password)); + } catch (Exception ex) { + throw propagateAsPassSigningException("Error retrieving PrivateKey from KeyStore", ex); + } + + if (key == null) { + throw new PassSigningException("KeyStore does not contain a PrivateKey with alias '" + alias + "'"); + } else if (!(key instanceof PrivateKey)) { + throw new PassSigningException("KeyStore entry with alias '" + alias + "' is not of type PrivateKey"); + } + + return (PrivateKey) key; + } + + /** + * @param keyStore + * @param alias + * @return an X509Certificate + * @throws PassSigningException if there are problems reading from the KeyStore, + * there is no certificate with the provided alias, or the certificate + * is not of type X509Certificate + */ + static X509Certificate getCertificate(KeyStore keyStore, String alias) throws PassSigningException { + if (alias == null) alias = firstAlias(keyStore); + + Certificate cert; + try { + cert = keyStore.getCertificate(alias); + } catch (Exception ex) { + throw propagateAsPassSigningException("Error retrieving certificate from KeyStore", ex); + } + + if (cert == null) { + throw new PassSigningException("KeyStore does not contain an X509Certificate with alias '" + alias + "'"); + } else if (!(cert instanceof X509Certificate)) { + throw new PassSigningException("KeyStore entry with alias '" + alias + "' is not of type X509Certificate"); + } + + return (X509Certificate) cert; + } + + /** + * @param keyStore + * @return a valid alias from the provided KeyStore + * @throws PassSigningException if there are problems reading from the KeyStore or + * the KeyStore doesn't contain exactly one alias. + */ + static String firstAlias(KeyStore keyStore) throws PassSigningException { + Enumeration aliases; + try { + aliases = keyStore.aliases(); + } catch (KeyStoreException ex) { + throw propagateAsPassSigningException("Error reading aliases from KeyStore", ex); + } + + if (aliases.hasMoreElements()) { + String alias = aliases.nextElement(); + if (aliases.hasMoreElements()) { + throw new PassSigningException("Provided KeyStore contains multiple aliases, please specify an alias"); + } + return alias; + } + throw new PassSigningException("Provided KeyStore is empty"); + } + + static char[] chars(String password) { + if (password == null) return new char[0]; + return password.toCharArray(); + } + + static void ensureBCProvider() { + if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) { + Security.addProvider(new BouncyCastleProvider()); + } + } + + static PassSigningException propagateAsPassSigningException(String message, Exception ex) throws PassSigningException { + if (ex instanceof RuntimeException) { + throw (RuntimeException) ex; + } else if (ex instanceof PassSigningException) { + throw (PassSigningException) ex; + } + + throw new PassSigningException(message, ex); + } } diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/BarcodeFormat.java" "b/src/main\240java/com/ryantenney/passkit4j/model/BarcodeFormat.java" new file mode 100644 index 0000000..a232322 --- /dev/null +++ "b/src/main\240java/com/ryantenney/passkit4j/model/BarcodeFormat.java" @@ -0,0 +1,42 @@ +package com.ryantenney.passkit4j.model; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonValue; + +public enum BarcodeFormat { + + PDF417("PKBarcodeFormatPDF417"), + QR("PKBarcodeFormatQR"), + AZTEC("PKBarcodeFormatAztec"), + CODE128("PKBarcodeFormatCode128"); + + private static final Map lookup; + + static { + final Map _lookup = new HashMap(); + for (BarcodeFormat entry : BarcodeFormat.values()) { + _lookup.put(entry.value(), entry); + } + lookup = Collections.unmodifiableMap(_lookup); + } + + private final String value; + + private BarcodeFormat(final String value) { + this.value = value; + } + + @JsonValue + public static BarcodeFormat forValue(String value) { + return lookup.get(value); + } + + @JsonValue + public String value() { + return this.value; + } + +} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/Beacon.java" "b/src/main\240java/com/ryantenney/passkit4j/model/Beacon.java" new file mode 100644 index 0000000..538c8ec --- /dev/null +++ "b/src/main\240java/com/ryantenney/passkit4j/model/Beacon.java" @@ -0,0 +1,29 @@ +package com.ryantenney.passkit4j.model; + +import lombok.AccessLevel; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.experimental.Accessors; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +@Data +@Accessors(chain = true, fluent = true) +@RequiredArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Beacon { + + @NonNull + private String proximityUUID; + + @JsonInclude(Include.NON_DEFAULT) + private long major = -1; + @JsonInclude(Include.NON_DEFAULT) + private long minor = -1; + + private String relevantText; + +} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/BoardingPass.java" "b/src/main\240java/com/ryantenney/passkit4j/model/BoardingPass.java" new file mode 100644 index 0000000..f971384 --- /dev/null +++ "b/src/main\240java/com/ryantenney/passkit4j/model/BoardingPass.java" @@ -0,0 +1,25 @@ +package com.ryantenney.passkit4j.model; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NonNull; +import lombok.experimental.Accessors; + +@Data +@EqualsAndHashCode(callSuper = true) +@Accessors(chain = true, fluent = true) +public class BoardingPass extends PassInformation { + + @NonNull + private TransitType transitType; + + public BoardingPass() { + super("boardingPass"); + } + + public BoardingPass(final TransitType transitType) { + this(); + this.transitType = transitType; + } + +} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/Color.java" "b/src/main\240java/com/ryantenney/passkit4j/model/Color.java" new file mode 100644 index 0000000..cfc893f --- /dev/null +++ "b/src/main\240java/com/ryantenney/passkit4j/model/Color.java" @@ -0,0 +1,69 @@ +package com.ryantenney.passkit4j.model; + +import java.io.IOException; +import java.util.StringTokenizer; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + +import lombok.Data; +import lombok.ToString; +import lombok.experimental.Accessors; + +@Data +@Accessors(fluent = true) +@ToString(includeFieldNames = true) +@JsonSerialize(using = Color.ColorSerializer.class) +@JsonDeserialize(using = Color.ColorDeserializer.class) +public class Color { + + public static final Color WHITE = new Color(255, 255, 255); + public static final Color BLACK = new Color(0, 0, 0); + + private final int red; + private final int green; + private final int blue; + + public Color(int red, int green, int blue) { + this.red = red; + this.green = green; + this.blue = blue; + } + + public Color(java.awt.Color color) { + this.red = color.getRed(); + this.green = color.getGreen(); + this.blue = color.getBlue(); + } + + static final class ColorSerializer extends JsonSerializer { + + @Override + public void serialize(Color color, JsonGenerator json, SerializerProvider serializer) throws IOException, JsonProcessingException { + json.writeString(String.format("rgb(%d, %d, %d)", color.red(), color.green(), color.blue())); + } + + } + + static final class ColorDeserializer extends JsonDeserializer { + + @Override + public Color deserialize(JsonParser json, DeserializationContext context) throws IOException, JsonProcessingException { + String str = json.getText().replace("rgb(", "").replace(")", ""); + StringTokenizer tok = new StringTokenizer(str, ","); + int red = Integer.parseInt(tok.nextToken().trim(), 10); + int green = Integer.parseInt(tok.nextToken().trim(), 10); + int blue = Integer.parseInt(tok.nextToken().trim(), 10); + return new Color(red, green, blue); + } + + } + +} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/Coupon.java" "b/src/main\240java/com/ryantenney/passkit4j/model/Coupon.java" new file mode 100644 index 0000000..8abb236 --- /dev/null +++ "b/src/main\240java/com/ryantenney/passkit4j/model/Coupon.java" @@ -0,0 +1,12 @@ +package com.ryantenney.passkit4j.model; + +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(callSuper = true) +public class Coupon extends PassInformation { + + public Coupon() { + super("coupon"); + } + +} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/DataDetectorType.java" "b/src/main\240java/com/ryantenney/passkit4j/model/DataDetectorType.java" new file mode 100644 index 0000000..ee491d3 --- /dev/null +++ "b/src/main\240java/com/ryantenney/passkit4j/model/DataDetectorType.java" @@ -0,0 +1,42 @@ +package com.ryantenney.passkit4j.model; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonValue; + +public enum DataDetectorType { + + PHONE_NUMBER("PKDataDetectorTypePhoneNumber"), + LINK("PKDataDetectorTypeLink"), + ADDRESS("PKDataDetectorTypeAddress"), + CALENDAR_EVENT("PKDataDetectorTypeCalendarEvent"); + + private static final Map lookup; + + static { + final Map _lookup = new HashMap(); + for (DataDetectorType entry : DataDetectorType.values()) { + _lookup.put(entry.value(), entry); + } + lookup = Collections.unmodifiableMap(_lookup); + } + + private final String value; + + private DataDetectorType(final String value) { + this.value = value; + } + + @JsonValue + public static DataDetectorType forValue(String value) { + return lookup.get(value); + } + + @JsonValue + public String value() { + return this.value; + } + +} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/DateField.java" "b/src/main\240java/com/ryantenney/passkit4j/model/DateField.java" new file mode 100644 index 0000000..c29c0ab --- /dev/null +++ "b/src/main\240java/com/ryantenney/passkit4j/model/DateField.java" @@ -0,0 +1,41 @@ +package com.ryantenney.passkit4j.model; + +import java.util.Date; +import java.util.Set; + +import lombok.Data; +import lombok.NonNull; +import lombok.NoArgsConstructor; +import lombok.RequiredArgsConstructor; +import lombok.experimental.Accessors; + +import com.fasterxml.jackson.annotation.JsonProperty; + +@Data +@Accessors(chain = true, fluent = true) +@NoArgsConstructor +@RequiredArgsConstructor +public class DateField implements Field { + + @NonNull + private String key; + private String label; + private String changeMessage; + private TextAlignment textAlignment; + private Set dataDetectorTypes; + private String attributedValue; + + @NonNull + private Date value; + private DateStyle dateStyle; + private DateStyle timeStyle; + @JsonProperty("isRelative") + private boolean relative = false; + private boolean ignoresTimeZone = false; + + public DateField(String key, String label, Date value) { + this(key, value); + this.label = label; + } + +} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/DateStyle.java" "b/src/main\240java/com/ryantenney/passkit4j/model/DateStyle.java" new file mode 100644 index 0000000..14fc069 --- /dev/null +++ "b/src/main\240java/com/ryantenney/passkit4j/model/DateStyle.java" @@ -0,0 +1,43 @@ +package com.ryantenney.passkit4j.model; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonValue; + +public enum DateStyle { + + NONE("PKDateStyleNone"), + SHORT("PKDateStyleShort"), + MEDIUM("PKDateStyleMedium"), + LONG("PKDateStyleLong"), + FULL("PKDateStyleFull"); + + private static final Map lookup; + + static { + final Map _lookup = new HashMap(); + for (DateStyle entry : DateStyle.values()) { + _lookup.put(entry.value(), entry); + } + lookup = Collections.unmodifiableMap(_lookup); + } + + private final String value; + + private DateStyle(final String value) { + this.value = value; + } + + @JsonValue + public static DateStyle forValue(String value) { + return lookup.get(value); + } + + @JsonValue + public String value() { + return this.value; + } + +} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/EventTicket.java" "b/src/main\240java/com/ryantenney/passkit4j/model/EventTicket.java" new file mode 100644 index 0000000..14af904 --- /dev/null +++ "b/src/main\240java/com/ryantenney/passkit4j/model/EventTicket.java" @@ -0,0 +1,12 @@ +package com.ryantenney.passkit4j.model; + +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(callSuper = true) +public class EventTicket extends PassInformation { + + public EventTicket() { + super("eventTicket"); + } + +} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/Field.java" "b/src/main\240java/com/ryantenney/passkit4j/model/Field.java" new file mode 100644 index 0000000..deaeb1d --- /dev/null +++ "b/src/main\240java/com/ryantenney/passkit4j/model/Field.java" @@ -0,0 +1,4 @@ +package com.ryantenney.passkit4j.model; + +public interface Field { +} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/Generic.java" "b/src/main\240java/com/ryantenney/passkit4j/model/Generic.java" new file mode 100644 index 0000000..4918b87 --- /dev/null +++ "b/src/main\240java/com/ryantenney/passkit4j/model/Generic.java" @@ -0,0 +1,12 @@ +package com.ryantenney.passkit4j.model; + +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(callSuper = true) +public class Generic extends PassInformation { + + public Generic() { + super("generic"); + } + +} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/Location.java" "b/src/main\240java/com/ryantenney/passkit4j/model/Location.java" new file mode 100644 index 0000000..4bf3bac --- /dev/null +++ "b/src/main\240java/com/ryantenney/passkit4j/model/Location.java" @@ -0,0 +1,25 @@ +package com.ryantenney.passkit4j.model; + +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +@Data +@Accessors(chain = true, fluent = true) +@NoArgsConstructor +public class Location { + + private double latitude; + private double longitude; + @JsonInclude(Include.NON_DEFAULT) + private double altitude = Double.NaN; + private String relevantText; + public Location(double latitude, double longitude) { + this.latitude = latitude; + this.longitude = longitude; + } + +} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/NFC.java" "b/src/main\240java/com/ryantenney/passkit4j/model/NFC.java" new file mode 100644 index 0000000..27ddd4a --- /dev/null +++ "b/src/main\240java/com/ryantenney/passkit4j/model/NFC.java" @@ -0,0 +1,21 @@ +package com.ryantenney.passkit4j.model; + +import lombok.AccessLevel; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.experimental.Accessors; + +@Data +@Accessors(chain = true, fluent = true) +@RequiredArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class NFC { + + @NonNull + private String message; + + private String encryptionPublicKey; + +} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/NumberField.java" "b/src/main\240java/com/ryantenney/passkit4j/model/NumberField.java" new file mode 100644 index 0000000..28c6294 --- /dev/null +++ "b/src/main\240java/com/ryantenney/passkit4j/model/NumberField.java" @@ -0,0 +1,35 @@ +package com.ryantenney.passkit4j.model; + +import java.util.Set; + +import lombok.Data; +import lombok.NonNull; +import lombok.NoArgsConstructor; +import lombok.RequiredArgsConstructor; +import lombok.experimental.Accessors; + +@Data +@Accessors(chain = true, fluent = true) +@NoArgsConstructor +@RequiredArgsConstructor +public class NumberField implements Field { + + @NonNull + private String key; + private String label; + private String changeMessage; + private TextAlignment textAlignment; + private Set dataDetectorTypes; + private String attributedValue; + + @NonNull + private Number value; + private NumberStyle numberStyle; + private String currencyCode; + + public NumberField(String key, String label, Number value) { + this(key, value); + this.label = label; + } + +} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/NumberStyle.java" "b/src/main\240java/com/ryantenney/passkit4j/model/NumberStyle.java" new file mode 100644 index 0000000..c81e8d7 --- /dev/null +++ "b/src/main\240java/com/ryantenney/passkit4j/model/NumberStyle.java" @@ -0,0 +1,42 @@ +package com.ryantenney.passkit4j.model; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonValue; + +public enum NumberStyle { + + DECIMAL("PKNumberStyleDecimal"), + PERCENT("PKNumberStylePercent"), + SCIENTIFIC("PKNumberStyleScientific"), + SPELLOUT("PKNumberStyleSpellOut"); + + private static final Map lookup; + + static { + final Map _lookup = new HashMap(); + for (NumberStyle entry : NumberStyle.values()) { + _lookup.put(entry.value(), entry); + } + lookup = Collections.unmodifiableMap(_lookup); + } + + private final String value; + + private NumberStyle(final String value) { + this.value = value; + } + + @JsonValue + public static NumberStyle forValue(String value) { + return lookup.get(value); + } + + @JsonValue + public String value() { + return this.value; + } + +} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/PassInformation.java" "b/src/main\240java/com/ryantenney/passkit4j/model/PassInformation.java" new file mode 100644 index 0000000..f41b2a2 --- /dev/null +++ "b/src/main\240java/com/ryantenney/passkit4j/model/PassInformation.java" @@ -0,0 +1,80 @@ +package com.ryantenney.passkit4j.model; + +import java.util.Arrays; +import java.util.List; + +import lombok.Data; + +import com.fasterxml.jackson.annotation.JsonIgnore; + +@Data +public abstract class PassInformation { + + @JsonIgnore + private final String typeName; + + private List> headerFields; + private List> primaryFields; + private List> secondaryFields; + private List> backFields; + private List> auxiliaryFields; + + protected PassInformation(final String typeName) { + this.typeName = typeName; + } + + public String typeName() { + return this.typeName; + } + + public PassInformation headerFields(Field... fields) { + this.headerFields = Arrays.asList(fields); + return this; + } + + public PassInformation headerFields(List> fields) { + this.headerFields = fields; + return this; + } + + public PassInformation primaryFields(Field... fields) { + this.primaryFields = Arrays.asList(fields); + return this; + } + + public PassInformation primaryFields(List> fields) { + this.primaryFields = fields; + return this; + } + + public PassInformation secondaryFields(Field... fields) { + this.secondaryFields = Arrays.asList(fields); + return this; + } + + public PassInformation secondaryFields(List> fields) { + this.secondaryFields = fields; + return this; + } + + public PassInformation backFields(Field... fields) { + this.backFields = Arrays.asList(fields); + return this; + } + + public PassInformation backFields(List> fields) { + this.backFields = fields; + return this; + } + + public PassInformation auxiliaryFields(Field... fields) { + this.auxiliaryFields = Arrays.asList(fields); + return this; + } + + public PassInformation auxiliaryFields(List> fields) { + this.auxiliaryFields = fields; + return this; + } + +} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/StoreCard.java" "b/src/main\240java/com/ryantenney/passkit4j/model/StoreCard.java" new file mode 100644 index 0000000..9a5d245 --- /dev/null +++ "b/src/main\240java/com/ryantenney/passkit4j/model/StoreCard.java" @@ -0,0 +1,12 @@ +package com.ryantenney.passkit4j.model; + +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(callSuper = true) +public class StoreCard extends PassInformation { + + public StoreCard() { + super("storeCard"); + } + +} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/TextAlignment.java" "b/src/main\240java/com/ryantenney/passkit4j/model/TextAlignment.java" new file mode 100644 index 0000000..3016012 --- /dev/null +++ "b/src/main\240java/com/ryantenney/passkit4j/model/TextAlignment.java" @@ -0,0 +1,43 @@ +package com.ryantenney.passkit4j.model; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonValue; + +public enum TextAlignment { + + LEFT("PKTextAlignmentLeft"), + CENTER("PKTextAlignmentCenter"), + RIGHT("PKTextAlignmentRight"), + JUSTIFIED("PKTextAlignmentJustified"), + NATURAL("PKTextAlignmentNatural"); + + private static final Map lookup; + + static { + final Map _lookup = new HashMap(); + for (TextAlignment entry : TextAlignment.values()) { + _lookup.put(entry.value(), entry); + } + lookup = Collections.unmodifiableMap(_lookup); + } + + private final String value; + + private TextAlignment(final String value) { + this.value = value; + } + + @JsonValue + public static TextAlignment forValue(String value) { + return lookup.get(value); + } + + @JsonValue + public String value() { + return this.value; + } + +} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/TextField.java" "b/src/main\240java/com/ryantenney/passkit4j/model/TextField.java" new file mode 100644 index 0000000..6fe3940 --- /dev/null +++ "b/src/main\240java/com/ryantenney/passkit4j/model/TextField.java" @@ -0,0 +1,33 @@ +package com.ryantenney.passkit4j.model; + +import java.util.Set; + +import lombok.Data; +import lombok.NonNull; +import lombok.NoArgsConstructor; +import lombok.RequiredArgsConstructor; +import lombok.experimental.Accessors; + +@Data +@Accessors(chain = true, fluent = true) +@NoArgsConstructor +@RequiredArgsConstructor +public class TextField implements Field { + + @NonNull + private String key; + private String label; + private String changeMessage; + private TextAlignment textAlignment; + private Set dataDetectorTypes; + private String attributedValue; + + @NonNull + private String value; + + public TextField(String key, String label, String value) { + this(key, value); + this.label = label; + } + +} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/TransitType.java" "b/src/main\240java/com/ryantenney/passkit4j/model/TransitType.java" new file mode 100644 index 0000000..d63bb93 --- /dev/null +++ "b/src/main\240java/com/ryantenney/passkit4j/model/TransitType.java" @@ -0,0 +1,43 @@ +package com.ryantenney.passkit4j.model; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonValue; + +public enum TransitType { + + AIR("PKTransitTypeAir"), + TRAIN("PKTransitTypeTrain"), + BUS("PKTransitTypeBus"), + BOAT("PKTransitTypeBoat"), + GENERIC("PKTransitTypeGeneric"); + + private static final Map lookup; + + static { + final Map _lookup = new HashMap(); + for (TransitType entry : TransitType.values()) { + _lookup.put(entry.value(), entry); + } + lookup = Collections.unmodifiableMap(_lookup); + } + + private final String value; + + private TransitType(final String value) { + this.value = value; + } + + @JsonValue + public static TransitType forValue(String value) { + return lookup.get(value); + } + + @JsonValue + public String value() { + return this.value; + } + +} diff --git "a/src/main\240java/com/ryantenney/passkit4j/sign/PassSigner.java" "b/src/main\240java/com/ryantenney/passkit4j/sign/PassSigner.java" new file mode 100644 index 0000000..a16e1ec --- /dev/null +++ "b/src/main\240java/com/ryantenney/passkit4j/sign/PassSigner.java" @@ -0,0 +1,7 @@ +package com.ryantenney.passkit4j.sign; + +public interface PassSigner { + + public byte[] generateSignature(byte[] data) throws PassSigningException; + +} diff --git a/src/test/java/com/ryantenney/passkit4j/EventTicketExample.java b/src/test/java/com/ryantenney/passkit4j/EventTicketExample.java index 0af8c23..ed9c498 100644 --- a/src/test/java/com/ryantenney/passkit4j/EventTicketExample.java +++ b/src/test/java/com/ryantenney/passkit4j/EventTicketExample.java @@ -12,48 +12,48 @@ public class EventTicketExample { - public static void main(String[] args) throws Throwable { - Pass pass = new Pass() - .teamIdentifier("asdfasdfasdf") - .passTypeIdentifier("pass.com.apple.event") - .organizationName("Apple Inc.") - .description("Apple Event Ticket") - .serialNumber("nmyuxofgnb") - .relevantDate("2011-12-08T13:00:00-08:00") - .locations( - new Location(37.6189722, -122.3748889), - new Location(37.33182, -122.03118) - ) - .barcode(new Barcode(BarcodeFormat.PDF417, "123456789")) - .foregroundColor(Color.WHITE) - .backgroundColor(new Color(60, 65, 76)) - .files( - new PassResource("src/test/resources/eventticket/icon.png"), - new PassResource("src/test/resources/eventticket/icon@2x.png"), - new PassResource("src/test/resources/eventticket/logo.png"), - new PassResource("src/test/resources/eventticket/logo@2x.png"), - new PassResource("src/test/resources/eventticket/background.png"), - new PassResource("src/test/resources/eventticket/background@2x.png") - ) - .passInformation( - new EventTicket() - .primaryFields( - new TextField("event", "EVENT", "The Beat Goes On") - ) - .secondaryFields( - new TextField("loc", "LOCATION", "Moscone West") - ) - .backFields( - new TextField("terms", "TERMS AND CONDITIONS", "Generico offers this pass, including all information, software, products and services available from this pass or offered as part of or in conjunction with this pass (the \"pass\"), to you, the user, conditioned upon your acceptance of all of the terms, conditions, policies and notices stated here. Generico reserves the right to make changes to these Terms and Conditions immediately by posting the changed Terms and Conditions in this location.\n\nUse the pass at your own risk. This pass is provided to you \"as is,\" without warranty of any kind either express or implied. Neither Generico nor its employees, agents, third-party information providers, merchants, licnsors or the like warrant that the pass or its operation will be accurate, reliable, uninterrupted or error-free. No agent or representative has the authority to create any warranty regarding the pass on behalf of Generico. Generico reserves the right to change or discontinue at any time any aspect or feature of the pass.") - ) - ); + public static void main(String[] args) throws Throwable { + Pass pass = new Pass() + .teamIdentifier("asdfasdfasdf") + .passTypeIdentifier("pass.com.apple.event") + .organizationName("Apple Inc.") + .description("Apple Event Ticket") + .serialNumber("nmyuxofgnb") + .relevantDate("2011-12-08T13:00:00-08:00") + .locations( + new Location(37.6189722, -122.3748889), + new Location(37.33182, -122.03118) + ) + .barcode(new Barcode(BarcodeFormat.PDF417, "123456789")) + .foregroundColor(Color.WHITE) + .backgroundColor(new Color(60, 65, 76)) + .files( + new PassResource("src/test/resources/eventticket/icon.png"), + new PassResource("src/test/resources/eventticket/icon@2x.png"), + new PassResource("src/test/resources/eventticket/logo.png"), + new PassResource("src/test/resources/eventticket/logo@2x.png"), + new PassResource("src/test/resources/eventticket/background.png"), + new PassResource("src/test/resources/eventticket/background@2x.png") + ) + .passInformation( + new EventTicket() + .primaryFields( + new TextField("event", "EVENT", "The Beat Goes On") + ) + .secondaryFields( + new TextField("loc", "LOCATION", "Moscone West") + ) + .backFields( + new TextField("terms", "TERMS AND CONDITIONS", "Generico offers this pass, including all information, software, products and services available from this pass or offered as part of or in conjunction with this pass (the \"pass\"), to you, the user, conditioned upon your acceptance of all of the terms, conditions, policies and notices stated here. Generico reserves the right to make changes to these Terms and Conditions immediately by posting the changed Terms and Conditions in this location.\n\nUse the pass at your own risk. This pass is provided to you \"as is,\" without warranty of any kind either express or implied. Neither Generico nor its employees, agents, third-party information providers, merchants, licnsors or the like warrant that the pass or its operation will be accurate, reliable, uninterrupted or error-free. No agent or representative has the authority to create any warranty regarding the pass on behalf of Generico. Generico reserves the right to change or discontinue at any time any aspect or feature of the pass.") + ) + ); - PassSigner signer = PassSignerImpl.builder() - .keystore(new FileInputStream("certificates/Certificates.p12"), null) - .intermediateCertificate(new FileInputStream("certificates/AppleWWDRCA.cer")) - .build(); + PassSigner signer = PassSignerImpl.builder() + .keystore(new FileInputStream("certificates/Certificates.p12"), null) + .intermediateCertificate(new FileInputStream("certificates/AppleWWDRCA.cer")) + .build(); - PassSerializer.writePkPassArchive(pass, signer, new FileOutputStream("EventTicket.pkpass")); - } + PassSerializer.writePkPassArchive(pass, signer, new FileOutputStream("EventTicket.pkpass")); + } } diff --git a/src/test/java/com/ryantenney/passkit4j/StoreCardExample.java b/src/test/java/com/ryantenney/passkit4j/StoreCardExample.java index c0a6458..b541c5d 100644 --- a/src/test/java/com/ryantenney/passkit4j/StoreCardExample.java +++ b/src/test/java/com/ryantenney/passkit4j/StoreCardExample.java @@ -13,59 +13,59 @@ public class StoreCardExample { - public static void main(String[] args) throws Throwable { - Pass pass = new Pass() - .teamIdentifier("asdfasdfasdf") - .passTypeIdentifier("pass.com.bouldercoffeeco.storeCard") - .organizationName("Boulder Coffee Co.") - .description("Boulder Coffee Rewards Card") - .serialNumber("p69f2J") - .locations( - new Location(43.145863, -77.602690).relevantText("South Wedge"), - new Location(43.131063, -77.636425).relevantText("Brooks Landing"), - new Location(43.147528, -77.576051).relevantText("Park Avenue"), - new Location(43.155763, -77.612724).relevantText("State Street"), - new Location(43.165389, -77.589655).relevantText("Public Market") - ) - .barcode(new Barcode(BarcodeFormat.PDF417, "12345678")) - .barcodes( - new Barcode(BarcodeFormat.CODE128, "12345678"), - new Barcode(BarcodeFormat.PDF417, "12345678")) - .logoText("Boulder Coffee") - .foregroundColor(Color.WHITE) - .backgroundColor(new Color(118, 74, 50)) - .files( - new PassResource("en.lproj/pass.strings", new File("src/test/resources/storecard/en.lproj/pass.strings")), - new PassResource("src/test/resources/storecard/icon.png"), - new PassResource("src/test/resources/storecard/icon@2x.png"), - new PassResource("src/test/resources/storecard/logo.png"), - new PassResource("src/test/resources/storecard/logo@2x.png"), - new PassResource("src/test/resources/storecard/strip.png"), - new PassResource("src/test/resources/storecard/strip@2x.png") - ) - .nfc(new NFC("test")) - .passInformation( - new StoreCard() - .headerFields( - new NumberField("balance", "balance_label", 25) - .textAlignment(TextAlignment.RIGHT) - .currencyCode("USD") - ) - .auxiliaryFields( - new TextField("level", "level_label", "level_gold"), - new TextField("usual", "usual_label", "Iced Mocha") - ) - .backFields( - new TextField("terms", "terms_label", "terms_value") - ) - ); + public static void main(String[] args) throws Throwable { + Pass pass = new Pass() + .teamIdentifier("asdfasdfasdf") + .passTypeIdentifier("pass.com.bouldercoffeeco.storeCard") + .organizationName("Boulder Coffee Co.") + .description("Boulder Coffee Rewards Card") + .serialNumber("p69f2J") + .locations( + new Location(43.145863, -77.602690).relevantText("South Wedge"), + new Location(43.131063, -77.636425).relevantText("Brooks Landing"), + new Location(43.147528, -77.576051).relevantText("Park Avenue"), + new Location(43.155763, -77.612724).relevantText("State Street"), + new Location(43.165389, -77.589655).relevantText("Public Market") + ) + .barcode(new Barcode(BarcodeFormat.PDF417, "12345678")) + .barcodes( + new Barcode(BarcodeFormat.CODE128, "12345678"), + new Barcode(BarcodeFormat.PDF417, "12345678")) + .logoText("Boulder Coffee") + .foregroundColor(Color.WHITE) + .backgroundColor(new Color(118, 74, 50)) + .files( + new PassResource("en.lproj/pass.strings", new File("src/test/resources/storecard/en.lproj/pass.strings")), + new PassResource("src/test/resources/storecard/icon.png"), + new PassResource("src/test/resources/storecard/icon@2x.png"), + new PassResource("src/test/resources/storecard/logo.png"), + new PassResource("src/test/resources/storecard/logo@2x.png"), + new PassResource("src/test/resources/storecard/strip.png"), + new PassResource("src/test/resources/storecard/strip@2x.png") + ) + .nfc(new NFC("test")) + .passInformation( + new StoreCard() + .headerFields( + new NumberField("balance", "balance_label", 25) + .textAlignment(TextAlignment.RIGHT) + .currencyCode("USD") + ) + .auxiliaryFields( + new TextField("level", "level_label", "level_gold"), + new TextField("usual", "usual_label", "Iced Mocha") + ) + .backFields( + new TextField("terms", "terms_label", "terms_value") + ) + ); - PassSigner signer = PassSignerImpl.builder() - .keystore(new FileInputStream("certificates/Certificates.p12"), null) - .intermediateCertificate(new FileInputStream("certificates/AppleWWDRCA.cer")) - .build(); + PassSigner signer = PassSignerImpl.builder() + .keystore(new FileInputStream("certificates/Certificates.p12"), null) + .intermediateCertificate(new FileInputStream("certificates/AppleWWDRCA.cer")) + .build(); - PassSerializer.writePkPassArchive(pass, signer, new FileOutputStream("StoreCard.pkpass")); - } + PassSerializer.writePkPassArchive(pass, signer, new FileOutputStream("StoreCard.pkpass")); + } } From 9d15a5a6fc08ff2b07cd7d863b234d0a408b2fe1 Mon Sep 17 00:00:00 2001 From: Mitchell Feinstein Date: Fri, 29 Jun 2018 15:26:31 -0400 Subject: [PATCH 4/4] TIX-807 Format as per intellij defaults --- .../passkit4j/model/BarcodeFormat.java | 60 ++++---- .../ryantenney/passkit4j/model/Beacon.java | 15 +- .../passkit4j/model/BoardingPass.java | 21 +-- .../com/ryantenney/passkit4j/model/Color.java | 72 +++++----- .../ryantenney/passkit4j/model/Coupon.java | 8 +- .../passkit4j/model/DataDetectorType.java | 60 ++++---- .../ryantenney/passkit4j/model/DateField.java | 39 +++--- .../ryantenney/passkit4j/model/DateStyle.java | 62 ++++----- .../passkit4j/model/EventTicket.java | 8 +- .../com/ryantenney/passkit4j/model/Field.java | 3 +- .../ryantenney/passkit4j/model/Generic.java | 8 +- .../ryantenney/passkit4j/model/Location.java | 21 ++- .../com/ryantenney/passkit4j/model/NFC.java | 9 +- .../passkit4j/model/NumberField.java | 30 ++-- .../passkit4j/model/NumberStyle.java | 60 ++++---- .../passkit4j/model/PassInformation.java | 131 +++++++++--------- .../ryantenney/passkit4j/model/StoreCard.java | 8 +- .../passkit4j/model/TextAlignment.java | 62 ++++----- .../ryantenney/passkit4j/model/TextField.java | 26 ++-- .../passkit4j/model/TransitType.java | 62 ++++----- .../ryantenney/passkit4j/sign/PassSigner.java | 2 +- .../passkit4j/model/BarcodeFormat.java" | 42 ------ .../ryantenney/passkit4j/model/Beacon.java" | 29 ---- .../passkit4j/model/BoardingPass.java" | 25 ---- .../ryantenney/passkit4j/model/Color.java" | 69 --------- .../ryantenney/passkit4j/model/Coupon.java" | 12 -- .../passkit4j/model/DataDetectorType.java" | 42 ------ .../passkit4j/model/DateField.java" | 41 ------ .../passkit4j/model/DateStyle.java" | 43 ------ .../passkit4j/model/EventTicket.java" | 12 -- .../ryantenney/passkit4j/model/Field.java" | 4 - .../ryantenney/passkit4j/model/Generic.java" | 12 -- .../ryantenney/passkit4j/model/Location.java" | 25 ---- .../com/ryantenney/passkit4j/model/NFC.java" | 21 --- .../passkit4j/model/NumberField.java" | 35 ----- .../passkit4j/model/NumberStyle.java" | 42 ------ .../passkit4j/model/PassInformation.java" | 80 ----------- .../passkit4j/model/StoreCard.java" | 12 -- .../passkit4j/model/TextAlignment.java" | 43 ------ .../passkit4j/model/TextField.java" | 33 ----- .../passkit4j/model/TransitType.java" | 43 ------ .../passkit4j/sign/PassSigner.java" | 7 - 42 files changed, 390 insertions(+), 1049 deletions(-) delete mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/BarcodeFormat.java" delete mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/Beacon.java" delete mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/BoardingPass.java" delete mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/Color.java" delete mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/Coupon.java" delete mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/DataDetectorType.java" delete mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/DateField.java" delete mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/DateStyle.java" delete mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/EventTicket.java" delete mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/Field.java" delete mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/Generic.java" delete mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/Location.java" delete mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/NFC.java" delete mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/NumberField.java" delete mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/NumberStyle.java" delete mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/PassInformation.java" delete mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/StoreCard.java" delete mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/TextAlignment.java" delete mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/TextField.java" delete mode 100644 "src/main\240java/com/ryantenney/passkit4j/model/TransitType.java" delete mode 100644 "src/main\240java/com/ryantenney/passkit4j/sign/PassSigner.java" diff --git a/src/main/java/com/ryantenney/passkit4j/model/BarcodeFormat.java b/src/main/java/com/ryantenney/passkit4j/model/BarcodeFormat.java index b609d56..a232322 100644 --- a/src/main/java/com/ryantenney/passkit4j/model/BarcodeFormat.java +++ b/src/main/java/com/ryantenney/passkit4j/model/BarcodeFormat.java @@ -8,35 +8,35 @@ public enum BarcodeFormat { - PDF417("PKBarcodeFormatPDF417"), - QR("PKBarcodeFormatQR"), - AZTEC("PKBarcodeFormatAztec"), - CODE128("PKBarcodeFormatCode128"); - - private static final Map lookup; - - static { - final Map _lookup = new HashMap(); - for (BarcodeFormat entry : BarcodeFormat.values()) { - _lookup.put(entry.value(), entry); - } - lookup = Collections.unmodifiableMap(_lookup); - } - - private final String value; - - private BarcodeFormat(final String value) { - this.value = value; - } - - @JsonValue - public String value() { - return this.value; - } - - @JsonValue - public static BarcodeFormat forValue(String value) { - return lookup.get(value); - } + PDF417("PKBarcodeFormatPDF417"), + QR("PKBarcodeFormatQR"), + AZTEC("PKBarcodeFormatAztec"), + CODE128("PKBarcodeFormatCode128"); + + private static final Map lookup; + + static { + final Map _lookup = new HashMap(); + for (BarcodeFormat entry : BarcodeFormat.values()) { + _lookup.put(entry.value(), entry); + } + lookup = Collections.unmodifiableMap(_lookup); + } + + private final String value; + + private BarcodeFormat(final String value) { + this.value = value; + } + + @JsonValue + public static BarcodeFormat forValue(String value) { + return lookup.get(value); + } + + @JsonValue + public String value() { + return this.value; + } } diff --git a/src/main/java/com/ryantenney/passkit4j/model/Beacon.java b/src/main/java/com/ryantenney/passkit4j/model/Beacon.java index 9a7736d..538c8ec 100644 --- a/src/main/java/com/ryantenney/passkit4j/model/Beacon.java +++ b/src/main/java/com/ryantenney/passkit4j/model/Beacon.java @@ -11,16 +11,19 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include; @Data -@Accessors(chain=true, fluent=true) +@Accessors(chain = true, fluent = true) @RequiredArgsConstructor -@NoArgsConstructor(access=AccessLevel.PROTECTED) +@NoArgsConstructor(access = AccessLevel.PROTECTED) public class Beacon { - @NonNull private String proximityUUID; + @NonNull + private String proximityUUID; - @JsonInclude(Include.NON_DEFAULT) private long major = -1; - @JsonInclude(Include.NON_DEFAULT) private long minor = -1; + @JsonInclude(Include.NON_DEFAULT) + private long major = -1; + @JsonInclude(Include.NON_DEFAULT) + private long minor = -1; - private String relevantText; + private String relevantText; } diff --git a/src/main/java/com/ryantenney/passkit4j/model/BoardingPass.java b/src/main/java/com/ryantenney/passkit4j/model/BoardingPass.java index 891a78f..f971384 100644 --- a/src/main/java/com/ryantenney/passkit4j/model/BoardingPass.java +++ b/src/main/java/com/ryantenney/passkit4j/model/BoardingPass.java @@ -6,19 +6,20 @@ import lombok.experimental.Accessors; @Data -@EqualsAndHashCode(callSuper=true) -@Accessors(chain=true, fluent=true) +@EqualsAndHashCode(callSuper = true) +@Accessors(chain = true, fluent = true) public class BoardingPass extends PassInformation { - @NonNull private TransitType transitType; + @NonNull + private TransitType transitType; - public BoardingPass() { - super("boardingPass"); - } + public BoardingPass() { + super("boardingPass"); + } - public BoardingPass(final TransitType transitType) { - this(); - this.transitType = transitType; - } + public BoardingPass(final TransitType transitType) { + this(); + this.transitType = transitType; + } } diff --git a/src/main/java/com/ryantenney/passkit4j/model/Color.java b/src/main/java/com/ryantenney/passkit4j/model/Color.java index dbeb623..cfc893f 100644 --- a/src/main/java/com/ryantenney/passkit4j/model/Color.java +++ b/src/main/java/com/ryantenney/passkit4j/model/Color.java @@ -18,52 +18,52 @@ import lombok.experimental.Accessors; @Data -@Accessors(fluent=true) -@ToString(includeFieldNames=true) -@JsonSerialize(using=Color.ColorSerializer.class) -@JsonDeserialize(using=Color.ColorDeserializer.class) +@Accessors(fluent = true) +@ToString(includeFieldNames = true) +@JsonSerialize(using = Color.ColorSerializer.class) +@JsonDeserialize(using = Color.ColorDeserializer.class) public class Color { - public static final Color WHITE = new Color(255, 255, 255); - public static final Color BLACK = new Color(0, 0, 0); + public static final Color WHITE = new Color(255, 255, 255); + public static final Color BLACK = new Color(0, 0, 0); - private final int red; - private final int green; - private final int blue; + private final int red; + private final int green; + private final int blue; - public Color(int red, int green, int blue) { - this.red = red; - this.green = green; - this.blue = blue; - } + public Color(int red, int green, int blue) { + this.red = red; + this.green = green; + this.blue = blue; + } - public Color(java.awt.Color color) { - this.red = color.getRed(); - this.green = color.getGreen(); - this.blue = color.getBlue(); - } + public Color(java.awt.Color color) { + this.red = color.getRed(); + this.green = color.getGreen(); + this.blue = color.getBlue(); + } - static final class ColorSerializer extends JsonSerializer { + static final class ColorSerializer extends JsonSerializer { - @Override - public void serialize(Color color, JsonGenerator json, SerializerProvider serializer) throws IOException, JsonProcessingException { - json.writeString(String.format("rgb(%d, %d, %d)", color.red(), color.green(), color.blue())); - } + @Override + public void serialize(Color color, JsonGenerator json, SerializerProvider serializer) throws IOException, JsonProcessingException { + json.writeString(String.format("rgb(%d, %d, %d)", color.red(), color.green(), color.blue())); + } - } + } - static final class ColorDeserializer extends JsonDeserializer { + static final class ColorDeserializer extends JsonDeserializer { - @Override - public Color deserialize(JsonParser json, DeserializationContext context) throws IOException, JsonProcessingException { - String str = json.getText().replace("rgb(", "").replace(")", ""); - StringTokenizer tok = new StringTokenizer(str, ","); - int red = Integer.parseInt(tok.nextToken().trim(), 10); - int green = Integer.parseInt(tok.nextToken().trim(), 10); - int blue = Integer.parseInt(tok.nextToken().trim(), 10); - return new Color(red, green, blue); - } + @Override + public Color deserialize(JsonParser json, DeserializationContext context) throws IOException, JsonProcessingException { + String str = json.getText().replace("rgb(", "").replace(")", ""); + StringTokenizer tok = new StringTokenizer(str, ","); + int red = Integer.parseInt(tok.nextToken().trim(), 10); + int green = Integer.parseInt(tok.nextToken().trim(), 10); + int blue = Integer.parseInt(tok.nextToken().trim(), 10); + return new Color(red, green, blue); + } - } + } } diff --git a/src/main/java/com/ryantenney/passkit4j/model/Coupon.java b/src/main/java/com/ryantenney/passkit4j/model/Coupon.java index 497dee3..8abb236 100644 --- a/src/main/java/com/ryantenney/passkit4j/model/Coupon.java +++ b/src/main/java/com/ryantenney/passkit4j/model/Coupon.java @@ -2,11 +2,11 @@ import lombok.EqualsAndHashCode; -@EqualsAndHashCode(callSuper=true) +@EqualsAndHashCode(callSuper = true) public class Coupon extends PassInformation { - public Coupon() { - super("coupon"); - } + public Coupon() { + super("coupon"); + } } diff --git a/src/main/java/com/ryantenney/passkit4j/model/DataDetectorType.java b/src/main/java/com/ryantenney/passkit4j/model/DataDetectorType.java index ef6c466..ee491d3 100644 --- a/src/main/java/com/ryantenney/passkit4j/model/DataDetectorType.java +++ b/src/main/java/com/ryantenney/passkit4j/model/DataDetectorType.java @@ -8,35 +8,35 @@ public enum DataDetectorType { - PHONE_NUMBER("PKDataDetectorTypePhoneNumber"), - LINK("PKDataDetectorTypeLink"), - ADDRESS("PKDataDetectorTypeAddress"), - CALENDAR_EVENT("PKDataDetectorTypeCalendarEvent"); - - private static final Map lookup; - - static { - final Map _lookup = new HashMap(); - for (DataDetectorType entry : DataDetectorType.values()) { - _lookup.put(entry.value(), entry); - } - lookup = Collections.unmodifiableMap(_lookup); - } - - private final String value; - - private DataDetectorType(final String value) { - this.value = value; - } - - @JsonValue - public String value() { - return this.value; - } - - @JsonValue - public static DataDetectorType forValue(String value) { - return lookup.get(value); - } + PHONE_NUMBER("PKDataDetectorTypePhoneNumber"), + LINK("PKDataDetectorTypeLink"), + ADDRESS("PKDataDetectorTypeAddress"), + CALENDAR_EVENT("PKDataDetectorTypeCalendarEvent"); + + private static final Map lookup; + + static { + final Map _lookup = new HashMap(); + for (DataDetectorType entry : DataDetectorType.values()) { + _lookup.put(entry.value(), entry); + } + lookup = Collections.unmodifiableMap(_lookup); + } + + private final String value; + + private DataDetectorType(final String value) { + this.value = value; + } + + @JsonValue + public static DataDetectorType forValue(String value) { + return lookup.get(value); + } + + @JsonValue + public String value() { + return this.value; + } } diff --git a/src/main/java/com/ryantenney/passkit4j/model/DateField.java b/src/main/java/com/ryantenney/passkit4j/model/DateField.java index 4343d04..c29c0ab 100644 --- a/src/main/java/com/ryantenney/passkit4j/model/DateField.java +++ b/src/main/java/com/ryantenney/passkit4j/model/DateField.java @@ -12,27 +12,30 @@ import com.fasterxml.jackson.annotation.JsonProperty; @Data -@Accessors(chain=true, fluent=true) +@Accessors(chain = true, fluent = true) @NoArgsConstructor @RequiredArgsConstructor public class DateField implements Field { - @NonNull private String key; - private String label; - private String changeMessage; - private TextAlignment textAlignment; - private Set dataDetectorTypes; - private String attributedValue; - - @NonNull private Date value; - private DateStyle dateStyle; - private DateStyle timeStyle; - @JsonProperty("isRelative") private boolean relative = false; - private boolean ignoresTimeZone = false; - - public DateField(String key, String label, Date value) { - this(key, value); - this.label = label; - } + @NonNull + private String key; + private String label; + private String changeMessage; + private TextAlignment textAlignment; + private Set dataDetectorTypes; + private String attributedValue; + + @NonNull + private Date value; + private DateStyle dateStyle; + private DateStyle timeStyle; + @JsonProperty("isRelative") + private boolean relative = false; + private boolean ignoresTimeZone = false; + + public DateField(String key, String label, Date value) { + this(key, value); + this.label = label; + } } diff --git a/src/main/java/com/ryantenney/passkit4j/model/DateStyle.java b/src/main/java/com/ryantenney/passkit4j/model/DateStyle.java index 87182ba..14fc069 100644 --- a/src/main/java/com/ryantenney/passkit4j/model/DateStyle.java +++ b/src/main/java/com/ryantenney/passkit4j/model/DateStyle.java @@ -8,36 +8,36 @@ public enum DateStyle { - NONE("PKDateStyleNone"), - SHORT("PKDateStyleShort"), - MEDIUM("PKDateStyleMedium"), - LONG("PKDateStyleLong"), - FULL("PKDateStyleFull"); - - private static final Map lookup; - - static { - final Map _lookup = new HashMap(); - for (DateStyle entry : DateStyle.values()) { - _lookup.put(entry.value(), entry); - } - lookup = Collections.unmodifiableMap(_lookup); - } - - private final String value; - - private DateStyle(final String value) { - this.value = value; - } - - @JsonValue - public String value() { - return this.value; - } - - @JsonValue - public static DateStyle forValue(String value) { - return lookup.get(value); - } + NONE("PKDateStyleNone"), + SHORT("PKDateStyleShort"), + MEDIUM("PKDateStyleMedium"), + LONG("PKDateStyleLong"), + FULL("PKDateStyleFull"); + + private static final Map lookup; + + static { + final Map _lookup = new HashMap(); + for (DateStyle entry : DateStyle.values()) { + _lookup.put(entry.value(), entry); + } + lookup = Collections.unmodifiableMap(_lookup); + } + + private final String value; + + private DateStyle(final String value) { + this.value = value; + } + + @JsonValue + public static DateStyle forValue(String value) { + return lookup.get(value); + } + + @JsonValue + public String value() { + return this.value; + } } diff --git a/src/main/java/com/ryantenney/passkit4j/model/EventTicket.java b/src/main/java/com/ryantenney/passkit4j/model/EventTicket.java index 6685540..14af904 100644 --- a/src/main/java/com/ryantenney/passkit4j/model/EventTicket.java +++ b/src/main/java/com/ryantenney/passkit4j/model/EventTicket.java @@ -2,11 +2,11 @@ import lombok.EqualsAndHashCode; -@EqualsAndHashCode(callSuper=true) +@EqualsAndHashCode(callSuper = true) public class EventTicket extends PassInformation { - public EventTicket() { - super("eventTicket"); - } + public EventTicket() { + super("eventTicket"); + } } diff --git a/src/main/java/com/ryantenney/passkit4j/model/Field.java b/src/main/java/com/ryantenney/passkit4j/model/Field.java index 1a97379..deaeb1d 100644 --- a/src/main/java/com/ryantenney/passkit4j/model/Field.java +++ b/src/main/java/com/ryantenney/passkit4j/model/Field.java @@ -1,3 +1,4 @@ package com.ryantenney.passkit4j.model; -public interface Field {} +public interface Field { +} diff --git a/src/main/java/com/ryantenney/passkit4j/model/Generic.java b/src/main/java/com/ryantenney/passkit4j/model/Generic.java index 4b78d8c..4918b87 100644 --- a/src/main/java/com/ryantenney/passkit4j/model/Generic.java +++ b/src/main/java/com/ryantenney/passkit4j/model/Generic.java @@ -2,11 +2,11 @@ import lombok.EqualsAndHashCode; -@EqualsAndHashCode(callSuper=true) +@EqualsAndHashCode(callSuper = true) public class Generic extends PassInformation { - public Generic() { - super("generic"); - } + public Generic() { + super("generic"); + } } diff --git a/src/main/java/com/ryantenney/passkit4j/model/Location.java b/src/main/java/com/ryantenney/passkit4j/model/Location.java index 2073143..4bf3bac 100644 --- a/src/main/java/com/ryantenney/passkit4j/model/Location.java +++ b/src/main/java/com/ryantenney/passkit4j/model/Location.java @@ -8,19 +8,18 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include; @Data -@Accessors(chain=true, fluent=true) +@Accessors(chain = true, fluent = true) @NoArgsConstructor public class Location { - private double latitude; - private double longitude; - - public Location(double latitude, double longitude) { - this.latitude = latitude; - this.longitude = longitude; - } - - @JsonInclude(Include.NON_DEFAULT) private double altitude = Double.NaN; - private String relevantText; + private double latitude; + private double longitude; + @JsonInclude(Include.NON_DEFAULT) + private double altitude = Double.NaN; + private String relevantText; + public Location(double latitude, double longitude) { + this.latitude = latitude; + this.longitude = longitude; + } } diff --git a/src/main/java/com/ryantenney/passkit4j/model/NFC.java b/src/main/java/com/ryantenney/passkit4j/model/NFC.java index aa1a939..27ddd4a 100644 --- a/src/main/java/com/ryantenney/passkit4j/model/NFC.java +++ b/src/main/java/com/ryantenney/passkit4j/model/NFC.java @@ -8,13 +8,14 @@ import lombok.experimental.Accessors; @Data -@Accessors(chain=true, fluent=true) +@Accessors(chain = true, fluent = true) @RequiredArgsConstructor -@NoArgsConstructor(access=AccessLevel.PROTECTED) +@NoArgsConstructor(access = AccessLevel.PROTECTED) public class NFC { - @NonNull private String message; + @NonNull + private String message; - private String encryptionPublicKey; + private String encryptionPublicKey; } diff --git a/src/main/java/com/ryantenney/passkit4j/model/NumberField.java b/src/main/java/com/ryantenney/passkit4j/model/NumberField.java index bb64af0..28c6294 100644 --- a/src/main/java/com/ryantenney/passkit4j/model/NumberField.java +++ b/src/main/java/com/ryantenney/passkit4j/model/NumberField.java @@ -9,25 +9,27 @@ import lombok.experimental.Accessors; @Data -@Accessors(chain=true, fluent=true) +@Accessors(chain = true, fluent = true) @NoArgsConstructor @RequiredArgsConstructor public class NumberField implements Field { - @NonNull private String key; - private String label; - private String changeMessage; - private TextAlignment textAlignment; - private Set dataDetectorTypes; - private String attributedValue; + @NonNull + private String key; + private String label; + private String changeMessage; + private TextAlignment textAlignment; + private Set dataDetectorTypes; + private String attributedValue; - @NonNull private Number value; - private NumberStyle numberStyle; - private String currencyCode; + @NonNull + private Number value; + private NumberStyle numberStyle; + private String currencyCode; - public NumberField(String key, String label, Number value) { - this(key, value); - this.label = label; - } + public NumberField(String key, String label, Number value) { + this(key, value); + this.label = label; + } } diff --git a/src/main/java/com/ryantenney/passkit4j/model/NumberStyle.java b/src/main/java/com/ryantenney/passkit4j/model/NumberStyle.java index db9378f..c81e8d7 100644 --- a/src/main/java/com/ryantenney/passkit4j/model/NumberStyle.java +++ b/src/main/java/com/ryantenney/passkit4j/model/NumberStyle.java @@ -8,35 +8,35 @@ public enum NumberStyle { - DECIMAL("PKNumberStyleDecimal"), - PERCENT("PKNumberStylePercent"), - SCIENTIFIC("PKNumberStyleScientific"), - SPELLOUT("PKNumberStyleSpellOut"); - - private static final Map lookup; - - static { - final Map _lookup = new HashMap(); - for (NumberStyle entry : NumberStyle.values()) { - _lookup.put(entry.value(), entry); - } - lookup = Collections.unmodifiableMap(_lookup); - } - - private final String value; - - private NumberStyle(final String value) { - this.value = value; - } - - @JsonValue - public String value() { - return this.value; - } - - @JsonValue - public static NumberStyle forValue(String value) { - return lookup.get(value); - } + DECIMAL("PKNumberStyleDecimal"), + PERCENT("PKNumberStylePercent"), + SCIENTIFIC("PKNumberStyleScientific"), + SPELLOUT("PKNumberStyleSpellOut"); + + private static final Map lookup; + + static { + final Map _lookup = new HashMap(); + for (NumberStyle entry : NumberStyle.values()) { + _lookup.put(entry.value(), entry); + } + lookup = Collections.unmodifiableMap(_lookup); + } + + private final String value; + + private NumberStyle(final String value) { + this.value = value; + } + + @JsonValue + public static NumberStyle forValue(String value) { + return lookup.get(value); + } + + @JsonValue + public String value() { + return this.value; + } } diff --git a/src/main/java/com/ryantenney/passkit4j/model/PassInformation.java b/src/main/java/com/ryantenney/passkit4j/model/PassInformation.java index 3a79ac3..f41b2a2 100644 --- a/src/main/java/com/ryantenney/passkit4j/model/PassInformation.java +++ b/src/main/java/com/ryantenney/passkit4j/model/PassInformation.java @@ -10,70 +10,71 @@ @Data public abstract class PassInformation { - @JsonIgnore private final String typeName; - - private List> headerFields; - private List> primaryFields; - private List> secondaryFields; - private List> backFields; - private List> auxiliaryFields; - - protected PassInformation(final String typeName) { - this.typeName = typeName; - } - - public String typeName() { - return this.typeName; - } - - public PassInformation headerFields(Field... fields) { - this.headerFields = Arrays.asList(fields); - return this; - } - - public PassInformation headerFields(List> fields) { - this.headerFields = fields; - return this; - } - - public PassInformation primaryFields(Field... fields) { - this.primaryFields = Arrays.asList(fields); - return this; - } - - public PassInformation primaryFields(List> fields) { - this.primaryFields = fields; - return this; - } - - public PassInformation secondaryFields(Field... fields) { - this.secondaryFields = Arrays.asList(fields); - return this; - } - - public PassInformation secondaryFields(List> fields) { - this.secondaryFields = fields; - return this; - } - - public PassInformation backFields(Field... fields) { - this.backFields = Arrays.asList(fields); - return this; - } - - public PassInformation backFields(List> fields) { - this.backFields = fields; - return this; - } - - public PassInformation auxiliaryFields(Field... fields) { - this.auxiliaryFields = Arrays.asList(fields); - return this; - } - - public PassInformation auxiliaryFields(List> fields) { - this.auxiliaryFields = fields; - return this; - } + @JsonIgnore + private final String typeName; + + private List> headerFields; + private List> primaryFields; + private List> secondaryFields; + private List> backFields; + private List> auxiliaryFields; + + protected PassInformation(final String typeName) { + this.typeName = typeName; + } + + public String typeName() { + return this.typeName; + } + + public PassInformation headerFields(Field... fields) { + this.headerFields = Arrays.asList(fields); + return this; + } + + public PassInformation headerFields(List> fields) { + this.headerFields = fields; + return this; + } + + public PassInformation primaryFields(Field... fields) { + this.primaryFields = Arrays.asList(fields); + return this; + } + + public PassInformation primaryFields(List> fields) { + this.primaryFields = fields; + return this; + } + + public PassInformation secondaryFields(Field... fields) { + this.secondaryFields = Arrays.asList(fields); + return this; + } + + public PassInformation secondaryFields(List> fields) { + this.secondaryFields = fields; + return this; + } + + public PassInformation backFields(Field... fields) { + this.backFields = Arrays.asList(fields); + return this; + } + + public PassInformation backFields(List> fields) { + this.backFields = fields; + return this; + } + + public PassInformation auxiliaryFields(Field... fields) { + this.auxiliaryFields = Arrays.asList(fields); + return this; + } + + public PassInformation auxiliaryFields(List> fields) { + this.auxiliaryFields = fields; + return this; + } } diff --git a/src/main/java/com/ryantenney/passkit4j/model/StoreCard.java b/src/main/java/com/ryantenney/passkit4j/model/StoreCard.java index 8efb1d2..9a5d245 100644 --- a/src/main/java/com/ryantenney/passkit4j/model/StoreCard.java +++ b/src/main/java/com/ryantenney/passkit4j/model/StoreCard.java @@ -2,11 +2,11 @@ import lombok.EqualsAndHashCode; -@EqualsAndHashCode(callSuper=true) +@EqualsAndHashCode(callSuper = true) public class StoreCard extends PassInformation { - public StoreCard() { - super("storeCard"); - } + public StoreCard() { + super("storeCard"); + } } diff --git a/src/main/java/com/ryantenney/passkit4j/model/TextAlignment.java b/src/main/java/com/ryantenney/passkit4j/model/TextAlignment.java index 89bd825..3016012 100644 --- a/src/main/java/com/ryantenney/passkit4j/model/TextAlignment.java +++ b/src/main/java/com/ryantenney/passkit4j/model/TextAlignment.java @@ -8,36 +8,36 @@ public enum TextAlignment { - LEFT("PKTextAlignmentLeft"), - CENTER("PKTextAlignmentCenter"), - RIGHT("PKTextAlignmentRight"), - JUSTIFIED("PKTextAlignmentJustified"), - NATURAL("PKTextAlignmentNatural"); - - private static final Map lookup; - - static { - final Map _lookup = new HashMap(); - for (TextAlignment entry : TextAlignment.values()) { - _lookup.put(entry.value(), entry); - } - lookup = Collections.unmodifiableMap(_lookup); - } - - private final String value; - - private TextAlignment(final String value) { - this.value = value; - } - - @JsonValue - public String value() { - return this.value; - } - - @JsonValue - public static TextAlignment forValue(String value) { - return lookup.get(value); - } + LEFT("PKTextAlignmentLeft"), + CENTER("PKTextAlignmentCenter"), + RIGHT("PKTextAlignmentRight"), + JUSTIFIED("PKTextAlignmentJustified"), + NATURAL("PKTextAlignmentNatural"); + + private static final Map lookup; + + static { + final Map _lookup = new HashMap(); + for (TextAlignment entry : TextAlignment.values()) { + _lookup.put(entry.value(), entry); + } + lookup = Collections.unmodifiableMap(_lookup); + } + + private final String value; + + private TextAlignment(final String value) { + this.value = value; + } + + @JsonValue + public static TextAlignment forValue(String value) { + return lookup.get(value); + } + + @JsonValue + public String value() { + return this.value; + } } diff --git a/src/main/java/com/ryantenney/passkit4j/model/TextField.java b/src/main/java/com/ryantenney/passkit4j/model/TextField.java index 34f8a46..6fe3940 100644 --- a/src/main/java/com/ryantenney/passkit4j/model/TextField.java +++ b/src/main/java/com/ryantenney/passkit4j/model/TextField.java @@ -9,23 +9,25 @@ import lombok.experimental.Accessors; @Data -@Accessors(chain=true, fluent=true) +@Accessors(chain = true, fluent = true) @NoArgsConstructor @RequiredArgsConstructor public class TextField implements Field { - @NonNull private String key; - private String label; - private String changeMessage; - private TextAlignment textAlignment; - private Set dataDetectorTypes; - private String attributedValue; + @NonNull + private String key; + private String label; + private String changeMessage; + private TextAlignment textAlignment; + private Set dataDetectorTypes; + private String attributedValue; - @NonNull private String value; + @NonNull + private String value; - public TextField(String key, String label, String value) { - this(key, value); - this.label = label; - } + public TextField(String key, String label, String value) { + this(key, value); + this.label = label; + } } diff --git a/src/main/java/com/ryantenney/passkit4j/model/TransitType.java b/src/main/java/com/ryantenney/passkit4j/model/TransitType.java index e288a49..d63bb93 100644 --- a/src/main/java/com/ryantenney/passkit4j/model/TransitType.java +++ b/src/main/java/com/ryantenney/passkit4j/model/TransitType.java @@ -8,36 +8,36 @@ public enum TransitType { - AIR("PKTransitTypeAir"), - TRAIN("PKTransitTypeTrain"), - BUS("PKTransitTypeBus"), - BOAT("PKTransitTypeBoat"), - GENERIC("PKTransitTypeGeneric"); - - private static final Map lookup; - - static { - final Map _lookup = new HashMap(); - for (TransitType entry : TransitType.values()) { - _lookup.put(entry.value(), entry); - } - lookup = Collections.unmodifiableMap(_lookup); - } - - private final String value; - - private TransitType(final String value) { - this.value = value; - } - - @JsonValue - public String value() { - return this.value; - } - - @JsonValue - public static TransitType forValue(String value) { - return lookup.get(value); - } + AIR("PKTransitTypeAir"), + TRAIN("PKTransitTypeTrain"), + BUS("PKTransitTypeBus"), + BOAT("PKTransitTypeBoat"), + GENERIC("PKTransitTypeGeneric"); + + private static final Map lookup; + + static { + final Map _lookup = new HashMap(); + for (TransitType entry : TransitType.values()) { + _lookup.put(entry.value(), entry); + } + lookup = Collections.unmodifiableMap(_lookup); + } + + private final String value; + + private TransitType(final String value) { + this.value = value; + } + + @JsonValue + public static TransitType forValue(String value) { + return lookup.get(value); + } + + @JsonValue + public String value() { + return this.value; + } } diff --git a/src/main/java/com/ryantenney/passkit4j/sign/PassSigner.java b/src/main/java/com/ryantenney/passkit4j/sign/PassSigner.java index f5aff11..a16e1ec 100644 --- a/src/main/java/com/ryantenney/passkit4j/sign/PassSigner.java +++ b/src/main/java/com/ryantenney/passkit4j/sign/PassSigner.java @@ -2,6 +2,6 @@ public interface PassSigner { - public byte[] generateSignature(byte[] data) throws PassSigningException; + public byte[] generateSignature(byte[] data) throws PassSigningException; } diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/BarcodeFormat.java" "b/src/main\240java/com/ryantenney/passkit4j/model/BarcodeFormat.java" deleted file mode 100644 index a232322..0000000 --- "a/src/main\240java/com/ryantenney/passkit4j/model/BarcodeFormat.java" +++ /dev/null @@ -1,42 +0,0 @@ -package com.ryantenney.passkit4j.model; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import com.fasterxml.jackson.annotation.JsonValue; - -public enum BarcodeFormat { - - PDF417("PKBarcodeFormatPDF417"), - QR("PKBarcodeFormatQR"), - AZTEC("PKBarcodeFormatAztec"), - CODE128("PKBarcodeFormatCode128"); - - private static final Map lookup; - - static { - final Map _lookup = new HashMap(); - for (BarcodeFormat entry : BarcodeFormat.values()) { - _lookup.put(entry.value(), entry); - } - lookup = Collections.unmodifiableMap(_lookup); - } - - private final String value; - - private BarcodeFormat(final String value) { - this.value = value; - } - - @JsonValue - public static BarcodeFormat forValue(String value) { - return lookup.get(value); - } - - @JsonValue - public String value() { - return this.value; - } - -} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/Beacon.java" "b/src/main\240java/com/ryantenney/passkit4j/model/Beacon.java" deleted file mode 100644 index 538c8ec..0000000 --- "a/src/main\240java/com/ryantenney/passkit4j/model/Beacon.java" +++ /dev/null @@ -1,29 +0,0 @@ -package com.ryantenney.passkit4j.model; - -import lombok.AccessLevel; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import lombok.experimental.Accessors; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonInclude.Include; - -@Data -@Accessors(chain = true, fluent = true) -@RequiredArgsConstructor -@NoArgsConstructor(access = AccessLevel.PROTECTED) -public class Beacon { - - @NonNull - private String proximityUUID; - - @JsonInclude(Include.NON_DEFAULT) - private long major = -1; - @JsonInclude(Include.NON_DEFAULT) - private long minor = -1; - - private String relevantText; - -} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/BoardingPass.java" "b/src/main\240java/com/ryantenney/passkit4j/model/BoardingPass.java" deleted file mode 100644 index f971384..0000000 --- "a/src/main\240java/com/ryantenney/passkit4j/model/BoardingPass.java" +++ /dev/null @@ -1,25 +0,0 @@ -package com.ryantenney.passkit4j.model; - -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NonNull; -import lombok.experimental.Accessors; - -@Data -@EqualsAndHashCode(callSuper = true) -@Accessors(chain = true, fluent = true) -public class BoardingPass extends PassInformation { - - @NonNull - private TransitType transitType; - - public BoardingPass() { - super("boardingPass"); - } - - public BoardingPass(final TransitType transitType) { - this(); - this.transitType = transitType; - } - -} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/Color.java" "b/src/main\240java/com/ryantenney/passkit4j/model/Color.java" deleted file mode 100644 index cfc893f..0000000 --- "a/src/main\240java/com/ryantenney/passkit4j/model/Color.java" +++ /dev/null @@ -1,69 +0,0 @@ -package com.ryantenney.passkit4j.model; - -import java.io.IOException; -import java.util.StringTokenizer; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonSerializer; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; - -import lombok.Data; -import lombok.ToString; -import lombok.experimental.Accessors; - -@Data -@Accessors(fluent = true) -@ToString(includeFieldNames = true) -@JsonSerialize(using = Color.ColorSerializer.class) -@JsonDeserialize(using = Color.ColorDeserializer.class) -public class Color { - - public static final Color WHITE = new Color(255, 255, 255); - public static final Color BLACK = new Color(0, 0, 0); - - private final int red; - private final int green; - private final int blue; - - public Color(int red, int green, int blue) { - this.red = red; - this.green = green; - this.blue = blue; - } - - public Color(java.awt.Color color) { - this.red = color.getRed(); - this.green = color.getGreen(); - this.blue = color.getBlue(); - } - - static final class ColorSerializer extends JsonSerializer { - - @Override - public void serialize(Color color, JsonGenerator json, SerializerProvider serializer) throws IOException, JsonProcessingException { - json.writeString(String.format("rgb(%d, %d, %d)", color.red(), color.green(), color.blue())); - } - - } - - static final class ColorDeserializer extends JsonDeserializer { - - @Override - public Color deserialize(JsonParser json, DeserializationContext context) throws IOException, JsonProcessingException { - String str = json.getText().replace("rgb(", "").replace(")", ""); - StringTokenizer tok = new StringTokenizer(str, ","); - int red = Integer.parseInt(tok.nextToken().trim(), 10); - int green = Integer.parseInt(tok.nextToken().trim(), 10); - int blue = Integer.parseInt(tok.nextToken().trim(), 10); - return new Color(red, green, blue); - } - - } - -} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/Coupon.java" "b/src/main\240java/com/ryantenney/passkit4j/model/Coupon.java" deleted file mode 100644 index 8abb236..0000000 --- "a/src/main\240java/com/ryantenney/passkit4j/model/Coupon.java" +++ /dev/null @@ -1,12 +0,0 @@ -package com.ryantenney.passkit4j.model; - -import lombok.EqualsAndHashCode; - -@EqualsAndHashCode(callSuper = true) -public class Coupon extends PassInformation { - - public Coupon() { - super("coupon"); - } - -} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/DataDetectorType.java" "b/src/main\240java/com/ryantenney/passkit4j/model/DataDetectorType.java" deleted file mode 100644 index ee491d3..0000000 --- "a/src/main\240java/com/ryantenney/passkit4j/model/DataDetectorType.java" +++ /dev/null @@ -1,42 +0,0 @@ -package com.ryantenney.passkit4j.model; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import com.fasterxml.jackson.annotation.JsonValue; - -public enum DataDetectorType { - - PHONE_NUMBER("PKDataDetectorTypePhoneNumber"), - LINK("PKDataDetectorTypeLink"), - ADDRESS("PKDataDetectorTypeAddress"), - CALENDAR_EVENT("PKDataDetectorTypeCalendarEvent"); - - private static final Map lookup; - - static { - final Map _lookup = new HashMap(); - for (DataDetectorType entry : DataDetectorType.values()) { - _lookup.put(entry.value(), entry); - } - lookup = Collections.unmodifiableMap(_lookup); - } - - private final String value; - - private DataDetectorType(final String value) { - this.value = value; - } - - @JsonValue - public static DataDetectorType forValue(String value) { - return lookup.get(value); - } - - @JsonValue - public String value() { - return this.value; - } - -} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/DateField.java" "b/src/main\240java/com/ryantenney/passkit4j/model/DateField.java" deleted file mode 100644 index c29c0ab..0000000 --- "a/src/main\240java/com/ryantenney/passkit4j/model/DateField.java" +++ /dev/null @@ -1,41 +0,0 @@ -package com.ryantenney.passkit4j.model; - -import java.util.Date; -import java.util.Set; - -import lombok.Data; -import lombok.NonNull; -import lombok.NoArgsConstructor; -import lombok.RequiredArgsConstructor; -import lombok.experimental.Accessors; - -import com.fasterxml.jackson.annotation.JsonProperty; - -@Data -@Accessors(chain = true, fluent = true) -@NoArgsConstructor -@RequiredArgsConstructor -public class DateField implements Field { - - @NonNull - private String key; - private String label; - private String changeMessage; - private TextAlignment textAlignment; - private Set dataDetectorTypes; - private String attributedValue; - - @NonNull - private Date value; - private DateStyle dateStyle; - private DateStyle timeStyle; - @JsonProperty("isRelative") - private boolean relative = false; - private boolean ignoresTimeZone = false; - - public DateField(String key, String label, Date value) { - this(key, value); - this.label = label; - } - -} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/DateStyle.java" "b/src/main\240java/com/ryantenney/passkit4j/model/DateStyle.java" deleted file mode 100644 index 14fc069..0000000 --- "a/src/main\240java/com/ryantenney/passkit4j/model/DateStyle.java" +++ /dev/null @@ -1,43 +0,0 @@ -package com.ryantenney.passkit4j.model; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import com.fasterxml.jackson.annotation.JsonValue; - -public enum DateStyle { - - NONE("PKDateStyleNone"), - SHORT("PKDateStyleShort"), - MEDIUM("PKDateStyleMedium"), - LONG("PKDateStyleLong"), - FULL("PKDateStyleFull"); - - private static final Map lookup; - - static { - final Map _lookup = new HashMap(); - for (DateStyle entry : DateStyle.values()) { - _lookup.put(entry.value(), entry); - } - lookup = Collections.unmodifiableMap(_lookup); - } - - private final String value; - - private DateStyle(final String value) { - this.value = value; - } - - @JsonValue - public static DateStyle forValue(String value) { - return lookup.get(value); - } - - @JsonValue - public String value() { - return this.value; - } - -} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/EventTicket.java" "b/src/main\240java/com/ryantenney/passkit4j/model/EventTicket.java" deleted file mode 100644 index 14af904..0000000 --- "a/src/main\240java/com/ryantenney/passkit4j/model/EventTicket.java" +++ /dev/null @@ -1,12 +0,0 @@ -package com.ryantenney.passkit4j.model; - -import lombok.EqualsAndHashCode; - -@EqualsAndHashCode(callSuper = true) -public class EventTicket extends PassInformation { - - public EventTicket() { - super("eventTicket"); - } - -} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/Field.java" "b/src/main\240java/com/ryantenney/passkit4j/model/Field.java" deleted file mode 100644 index deaeb1d..0000000 --- "a/src/main\240java/com/ryantenney/passkit4j/model/Field.java" +++ /dev/null @@ -1,4 +0,0 @@ -package com.ryantenney.passkit4j.model; - -public interface Field { -} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/Generic.java" "b/src/main\240java/com/ryantenney/passkit4j/model/Generic.java" deleted file mode 100644 index 4918b87..0000000 --- "a/src/main\240java/com/ryantenney/passkit4j/model/Generic.java" +++ /dev/null @@ -1,12 +0,0 @@ -package com.ryantenney.passkit4j.model; - -import lombok.EqualsAndHashCode; - -@EqualsAndHashCode(callSuper = true) -public class Generic extends PassInformation { - - public Generic() { - super("generic"); - } - -} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/Location.java" "b/src/main\240java/com/ryantenney/passkit4j/model/Location.java" deleted file mode 100644 index 4bf3bac..0000000 --- "a/src/main\240java/com/ryantenney/passkit4j/model/Location.java" +++ /dev/null @@ -1,25 +0,0 @@ -package com.ryantenney.passkit4j.model; - -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonInclude.Include; - -@Data -@Accessors(chain = true, fluent = true) -@NoArgsConstructor -public class Location { - - private double latitude; - private double longitude; - @JsonInclude(Include.NON_DEFAULT) - private double altitude = Double.NaN; - private String relevantText; - public Location(double latitude, double longitude) { - this.latitude = latitude; - this.longitude = longitude; - } - -} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/NFC.java" "b/src/main\240java/com/ryantenney/passkit4j/model/NFC.java" deleted file mode 100644 index 27ddd4a..0000000 --- "a/src/main\240java/com/ryantenney/passkit4j/model/NFC.java" +++ /dev/null @@ -1,21 +0,0 @@ -package com.ryantenney.passkit4j.model; - -import lombok.AccessLevel; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import lombok.experimental.Accessors; - -@Data -@Accessors(chain = true, fluent = true) -@RequiredArgsConstructor -@NoArgsConstructor(access = AccessLevel.PROTECTED) -public class NFC { - - @NonNull - private String message; - - private String encryptionPublicKey; - -} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/NumberField.java" "b/src/main\240java/com/ryantenney/passkit4j/model/NumberField.java" deleted file mode 100644 index 28c6294..0000000 --- "a/src/main\240java/com/ryantenney/passkit4j/model/NumberField.java" +++ /dev/null @@ -1,35 +0,0 @@ -package com.ryantenney.passkit4j.model; - -import java.util.Set; - -import lombok.Data; -import lombok.NonNull; -import lombok.NoArgsConstructor; -import lombok.RequiredArgsConstructor; -import lombok.experimental.Accessors; - -@Data -@Accessors(chain = true, fluent = true) -@NoArgsConstructor -@RequiredArgsConstructor -public class NumberField implements Field { - - @NonNull - private String key; - private String label; - private String changeMessage; - private TextAlignment textAlignment; - private Set dataDetectorTypes; - private String attributedValue; - - @NonNull - private Number value; - private NumberStyle numberStyle; - private String currencyCode; - - public NumberField(String key, String label, Number value) { - this(key, value); - this.label = label; - } - -} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/NumberStyle.java" "b/src/main\240java/com/ryantenney/passkit4j/model/NumberStyle.java" deleted file mode 100644 index c81e8d7..0000000 --- "a/src/main\240java/com/ryantenney/passkit4j/model/NumberStyle.java" +++ /dev/null @@ -1,42 +0,0 @@ -package com.ryantenney.passkit4j.model; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import com.fasterxml.jackson.annotation.JsonValue; - -public enum NumberStyle { - - DECIMAL("PKNumberStyleDecimal"), - PERCENT("PKNumberStylePercent"), - SCIENTIFIC("PKNumberStyleScientific"), - SPELLOUT("PKNumberStyleSpellOut"); - - private static final Map lookup; - - static { - final Map _lookup = new HashMap(); - for (NumberStyle entry : NumberStyle.values()) { - _lookup.put(entry.value(), entry); - } - lookup = Collections.unmodifiableMap(_lookup); - } - - private final String value; - - private NumberStyle(final String value) { - this.value = value; - } - - @JsonValue - public static NumberStyle forValue(String value) { - return lookup.get(value); - } - - @JsonValue - public String value() { - return this.value; - } - -} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/PassInformation.java" "b/src/main\240java/com/ryantenney/passkit4j/model/PassInformation.java" deleted file mode 100644 index f41b2a2..0000000 --- "a/src/main\240java/com/ryantenney/passkit4j/model/PassInformation.java" +++ /dev/null @@ -1,80 +0,0 @@ -package com.ryantenney.passkit4j.model; - -import java.util.Arrays; -import java.util.List; - -import lombok.Data; - -import com.fasterxml.jackson.annotation.JsonIgnore; - -@Data -public abstract class PassInformation { - - @JsonIgnore - private final String typeName; - - private List> headerFields; - private List> primaryFields; - private List> secondaryFields; - private List> backFields; - private List> auxiliaryFields; - - protected PassInformation(final String typeName) { - this.typeName = typeName; - } - - public String typeName() { - return this.typeName; - } - - public PassInformation headerFields(Field... fields) { - this.headerFields = Arrays.asList(fields); - return this; - } - - public PassInformation headerFields(List> fields) { - this.headerFields = fields; - return this; - } - - public PassInformation primaryFields(Field... fields) { - this.primaryFields = Arrays.asList(fields); - return this; - } - - public PassInformation primaryFields(List> fields) { - this.primaryFields = fields; - return this; - } - - public PassInformation secondaryFields(Field... fields) { - this.secondaryFields = Arrays.asList(fields); - return this; - } - - public PassInformation secondaryFields(List> fields) { - this.secondaryFields = fields; - return this; - } - - public PassInformation backFields(Field... fields) { - this.backFields = Arrays.asList(fields); - return this; - } - - public PassInformation backFields(List> fields) { - this.backFields = fields; - return this; - } - - public PassInformation auxiliaryFields(Field... fields) { - this.auxiliaryFields = Arrays.asList(fields); - return this; - } - - public PassInformation auxiliaryFields(List> fields) { - this.auxiliaryFields = fields; - return this; - } - -} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/StoreCard.java" "b/src/main\240java/com/ryantenney/passkit4j/model/StoreCard.java" deleted file mode 100644 index 9a5d245..0000000 --- "a/src/main\240java/com/ryantenney/passkit4j/model/StoreCard.java" +++ /dev/null @@ -1,12 +0,0 @@ -package com.ryantenney.passkit4j.model; - -import lombok.EqualsAndHashCode; - -@EqualsAndHashCode(callSuper = true) -public class StoreCard extends PassInformation { - - public StoreCard() { - super("storeCard"); - } - -} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/TextAlignment.java" "b/src/main\240java/com/ryantenney/passkit4j/model/TextAlignment.java" deleted file mode 100644 index 3016012..0000000 --- "a/src/main\240java/com/ryantenney/passkit4j/model/TextAlignment.java" +++ /dev/null @@ -1,43 +0,0 @@ -package com.ryantenney.passkit4j.model; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import com.fasterxml.jackson.annotation.JsonValue; - -public enum TextAlignment { - - LEFT("PKTextAlignmentLeft"), - CENTER("PKTextAlignmentCenter"), - RIGHT("PKTextAlignmentRight"), - JUSTIFIED("PKTextAlignmentJustified"), - NATURAL("PKTextAlignmentNatural"); - - private static final Map lookup; - - static { - final Map _lookup = new HashMap(); - for (TextAlignment entry : TextAlignment.values()) { - _lookup.put(entry.value(), entry); - } - lookup = Collections.unmodifiableMap(_lookup); - } - - private final String value; - - private TextAlignment(final String value) { - this.value = value; - } - - @JsonValue - public static TextAlignment forValue(String value) { - return lookup.get(value); - } - - @JsonValue - public String value() { - return this.value; - } - -} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/TextField.java" "b/src/main\240java/com/ryantenney/passkit4j/model/TextField.java" deleted file mode 100644 index 6fe3940..0000000 --- "a/src/main\240java/com/ryantenney/passkit4j/model/TextField.java" +++ /dev/null @@ -1,33 +0,0 @@ -package com.ryantenney.passkit4j.model; - -import java.util.Set; - -import lombok.Data; -import lombok.NonNull; -import lombok.NoArgsConstructor; -import lombok.RequiredArgsConstructor; -import lombok.experimental.Accessors; - -@Data -@Accessors(chain = true, fluent = true) -@NoArgsConstructor -@RequiredArgsConstructor -public class TextField implements Field { - - @NonNull - private String key; - private String label; - private String changeMessage; - private TextAlignment textAlignment; - private Set dataDetectorTypes; - private String attributedValue; - - @NonNull - private String value; - - public TextField(String key, String label, String value) { - this(key, value); - this.label = label; - } - -} diff --git "a/src/main\240java/com/ryantenney/passkit4j/model/TransitType.java" "b/src/main\240java/com/ryantenney/passkit4j/model/TransitType.java" deleted file mode 100644 index d63bb93..0000000 --- "a/src/main\240java/com/ryantenney/passkit4j/model/TransitType.java" +++ /dev/null @@ -1,43 +0,0 @@ -package com.ryantenney.passkit4j.model; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import com.fasterxml.jackson.annotation.JsonValue; - -public enum TransitType { - - AIR("PKTransitTypeAir"), - TRAIN("PKTransitTypeTrain"), - BUS("PKTransitTypeBus"), - BOAT("PKTransitTypeBoat"), - GENERIC("PKTransitTypeGeneric"); - - private static final Map lookup; - - static { - final Map _lookup = new HashMap(); - for (TransitType entry : TransitType.values()) { - _lookup.put(entry.value(), entry); - } - lookup = Collections.unmodifiableMap(_lookup); - } - - private final String value; - - private TransitType(final String value) { - this.value = value; - } - - @JsonValue - public static TransitType forValue(String value) { - return lookup.get(value); - } - - @JsonValue - public String value() { - return this.value; - } - -} diff --git "a/src/main\240java/com/ryantenney/passkit4j/sign/PassSigner.java" "b/src/main\240java/com/ryantenney/passkit4j/sign/PassSigner.java" deleted file mode 100644 index a16e1ec..0000000 --- "a/src/main\240java/com/ryantenney/passkit4j/sign/PassSigner.java" +++ /dev/null @@ -1,7 +0,0 @@ -package com.ryantenney.passkit4j.sign; - -public interface PassSigner { - - public byte[] generateSignature(byte[] data) throws PassSigningException; - -}