com.minlessika.membership.integration.RestTaxes Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of membership-integration Show documentation
Show all versions of membership-integration Show documentation
It's a library to help developers to integration membership services to another project.
package com.minlessika.membership.integration;
import com.google.common.collect.ImmutableMap;
import com.minlessika.http.client.RestClient;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import javax.json.Json;
public class RestTaxes implements Taxes {
private final Organization organization;
private final RestClient client;
public RestTaxes(final RestClient client, final Organization organization) {
this.organization = organization;
this.client = client;
}
@Override
public Tax getTvaTax() {
return new JsTax(
this.client.get(
"/api/organization/tax-by-shortname",
ImmutableMap.of("org", this.organization.uid(), "shortname", "TVA")
).asJsonObject()
);
}
@Override
public Tax add(String name, String shortName, double value, NumberValueType valueType, TaxType type) {
return this.add(UUID.randomUUID(), name, shortName, value, valueType, type);
}
@Override
public Tax add(final UUID uid, final String name, final String shortName, final double value, final NumberValueType valueType, final TaxType type) {
this.client.post(
"/api/organization/tax",
ImmutableMap.of("org", this.organization.uid()),
Json.createObjectBuilder()
.add("id", uid.toString())
.add("shortName", shortName)
.add("name", name)
.add("typeId", type.id())
.add("value", value)
.add("valueTypeId", valueType.id())
.build()
);
return this.get(uid);
}
@Override
public Tax get(final UUID uid) {
return new JsTax(
this.client.get(
"/api/organization/tax",
ImmutableMap.of("id", uid, "org", this.organization.uid())
).asJsonObject()
);
}
@Override
public boolean contains(final String filter) {
return this.client.get(
"/api/organization/tax/contains",
ImmutableMap.of("filter", filter, "org", this.organization.uid())
).asJsonObject().getBoolean("value");
}
@Override
public Iterable iterate() {
final List items = new LinkedList<>();
this.client.get(
"/api/organization/taxes",
ImmutableMap.of("org", this.organization.uid())
).asJsonArray()
.forEach(
json -> {
items.add(
new JsTax(json.asJsonObject())
);
}
);
return items;
}
}