Skip to content

Commit

Permalink
Merge 16a31e1 into e6809bc
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-invoiced committed Nov 15, 2019
2 parents e6809bc + 16a31e1 commit 80bd557
Show file tree
Hide file tree
Showing 104 changed files with 4,307 additions and 46 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ local.properties
# External tool builders
.externalToolBuilders/

# VS Code
.vscode/

# Locally stored "Eclipse launch configurations"
*.launch

Expand Down
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ jdk:
- oraclejdk7
script:
- ./gradlew -i check

before_install:
# needed to use TLSv1.2 on Java 7
- export _JAVA_OPTIONS=-Dhttps.protocols=TLSv1,TLSv1.1,TLSv1.2
after_success:
- ./gradlew cobertura coveralls
notifications:
Expand Down
12 changes: 11 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

plugins {
id 'net.saliman.cobertura' version '2.3.1'
id 'net.saliman.cobertura' version '2.6.1'
id 'com.github.kt3k.coveralls' version '2.6.3'
id 'jacoco'
}

cobertura.coverageFormats = ['html', 'xml']
Expand Down Expand Up @@ -50,3 +51,12 @@ dependencies {
// 'test.useTestNG()' to your build script.
testCompile 'junit:junit:4.12'
}

jacocoTestReport {
group = "Reporting"
reports {
xml.enabled true
csv.enabled false
html.destination file("${buildDir}/reports/coverage/report.html")
}
}
87 changes: 82 additions & 5 deletions src/main/java/com/invoiced/entity/AbstractEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

public abstract class AbstractEntity<T extends AbstractEntity> {

private Connection conn;
private Class<T> tClass;
protected Connection conn;
protected Class<T> tClass;
private boolean entityCreated;

public AbstractEntity(Connection conn, Class<T> tClass) {
Expand Down Expand Up @@ -138,7 +138,9 @@ public void save() throws EntityException {
return;
}

String url = this.conn.baseUrl() + "/" + this.getEntityName() + "/" + String.valueOf(this.getEntityId());
String url = null;

url = this.conn.baseUrl() + "/" + this.getEntityName() + "/" + this.getEntityIdString();

T v1 = null;

Expand All @@ -155,6 +157,32 @@ public void save() throws EntityException {
}
}

public T retrieve() throws EntityException {

String url = this.conn.baseUrl() + "/" + this.getEntityName();

T v1 = null;

try {

String response = this.conn.get(url, null);

v1 = Util.getMapper().readValue(response, this.tClass);
v1.setConnection(this.conn);
v1.setClass(this.tClass);

if (this.isSubEntity()) {
v1.setParentID(this.getParentID());
}

} catch (Throwable c) {

throw new EntityException(c);
}

return v1;
}

public T retrieve(long id) throws EntityException {

T v1 = null;
Expand Down Expand Up @@ -197,13 +225,58 @@ public T retrieve(long id, HashMap<String, Object> queryParms) throws EntityExce
return v1;
}

public T retrieve(String id) throws EntityException {

T v1 = null;

try {

v1 = this.retrieve(id, null);

} catch (EntityException e) {

throw e;
}

return v1;
}

public T retrieve(String id, HashMap<String, Object> queryParms) throws EntityException {

String url = this.conn.baseUrl() + "/" + this.getEntityName() + "/" + id;

T v1 = null;

try {

String response = this.conn.get(url, queryParms);

v1 = Util.getMapper().readValue(response, this.tClass);
v1.setConnection(this.conn);
v1.setClass(this.tClass);

if (this.isSubEntity()) {
v1.setParentID(this.getParentID());
}

} catch (Throwable c) {

throw new EntityException(c);
}

return v1;
}

public void delete() throws EntityException {

if (!this.hasCRUD()) {
return;
}

String url = this.conn.baseUrl() + "/" + this.getEntityName() + "/" + String.valueOf(this.getEntityId());
String url = null;

url = this.conn.baseUrl() + "/" + this.getEntityName() + "/" + this.getEntityIdString();


try {

Expand Down Expand Up @@ -324,7 +397,9 @@ public EntityList<T> listAll(HashMap<String, Object> queryParms) throws EntityEx
return entities;
}

abstract long getEntityId();
abstract long getEntityId() throws EntityException;

abstract String getEntityIdString() throws EntityException;

abstract String getEntityName();

Expand All @@ -334,6 +409,8 @@ public EntityList<T> listAll(HashMap<String, Object> queryParms) throws EntityEx

abstract boolean isSubEntity();

abstract boolean idIsString();

abstract void setParentID(long parentID);

abstract long getParentID();
Expand Down
127 changes: 127 additions & 0 deletions src/main/java/com/invoiced/entity/CatalogItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package com.invoiced.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.invoiced.exception.EntityException;

public class CatalogItem extends AbstractEntity<CatalogItem> {

public CatalogItem(Connection conn) {
super(conn, CatalogItem.class);
}

CatalogItem() {
super(CatalogItem.class);
}

@Override
@JsonIgnore
protected boolean hasCRUD() {
return true;
}

@Override
@JsonIgnore
protected boolean idIsString() {
return true;
}

@Override
@JsonIgnore
protected String getEntityIdString() {
return this.id;
}

@Override
@JsonIgnore
protected boolean hasList() {
return true;
}

@Override
@JsonIgnore
protected long getEntityId() throws EntityException {
throw new EntityException(new Throwable());
}

@Override
@JsonIgnore
protected String getEntityName() {
return "catalog_items";
}

@Override
@JsonIgnore
protected boolean isSubEntity() {
return false;
}

@Override
@JsonIgnore
protected void setParentID(long parentID) {

}

@Override
@JsonIgnore
protected long getParentID() {
return -1;
}

@JsonInclude(JsonInclude.Include.NON_DEFAULT)
@JsonProperty("id")
public String id;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonProperty("object")
public String object;

@JsonInclude(JsonInclude.Include.NON_DEFAULT)
@JsonProperty("name")
public String name;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonProperty("currency")
public String currency;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonProperty("unit_cost")
public Long unitCost;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonProperty("description")
public String description;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonProperty("type")
public String type;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonProperty("taxable")
public Boolean taxable;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonProperty("taxes")
public Tax[] taxes;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonProperty("avalara_tax_code")
public String avalaraTaxCode;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonProperty("gl_account")
public String glAccount;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonProperty("discountable")
public Boolean discountable;

@JsonProperty(value = "created_at", access = JsonProperty.Access.WRITE_ONLY)
public long createdAt;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonProperty("metadata")
public Object metadata;

}
56 changes: 56 additions & 0 deletions src/main/java/com/invoiced/entity/ChargeRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.invoiced.entity;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

public class ChargeRequest extends AbstractItem {

@JsonInclude(JsonInclude.Include.NON_DEFAULT)
@JsonProperty("customer")
public long customer;

@JsonInclude(JsonInclude.Include.NON_DEFAULT)
@JsonProperty("method")
public long method;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonProperty("currency")
public String currency;

@JsonInclude(JsonInclude.Include.NON_DEFAULT)
@JsonProperty("amount")
public long amount;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonProperty("invoiced_token")
public String invoicedToken;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonProperty("gateway_token")
public String gatewayToken;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonProperty("payment_source_type")
public String paymentSourceType;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonProperty("payment_source_id")
public Long paymentSourceId;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonProperty("vault_method")
public Boolean vaultMethod;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonProperty("make_default")
public Boolean makeDefault;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonProperty("receipt_email")
public String receiptEmail;

@JsonInclude(JsonInclude.Include.NON_DEFAULT)
@JsonProperty("splits")
public ChargeSplit[] splits;

}
20 changes: 20 additions & 0 deletions src/main/java/com/invoiced/entity/ChargeSplit.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.invoiced.entity;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

public class ChargeSplit extends AbstractItem {

@JsonInclude(JsonInclude.Include.NON_DEFAULT)
@JsonProperty("type")
public String type;

@JsonInclude(JsonInclude.Include.NON_DEFAULT)
@JsonProperty("invoice")
public long invoice;

@JsonInclude(JsonInclude.Include.NON_DEFAULT)
@JsonProperty("amount")
public long amount;

}

0 comments on commit 80bd557

Please sign in to comment.