com.minlessika.membership.integration.RestSequence 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.UUID;
import javax.json.JsonObject;
import org.apache.commons.lang3.StringUtils;
public final class RestSequence implements Sequence {
private final JsonObject json;
private final RestClient client;
private final Organization organization;
public RestSequence(final RestClient client, final JsonObject json, final Organization organization) {
this.client = client;
this.json = json;
this.organization = organization;
}
@Override
public UUID uid() {
return UUID.fromString(this.json.getString("guid"));
}
@Override
public String code() {
return this.json.getString("code");
}
@Override
public String name() {
return this.json.getString("name");
}
@Override
public String prefix() {
return this.json.getString("prefix");
}
@Override
public String suffix() {
return this.json.getString("suffix");
}
@Override
public int size() {
return this.json.getInt("size");
}
@Override
public int step() {
return this.json.getInt("step");
}
@Override
public long nextNumber() {
return this.json.getJsonNumber("nextNumber").longValue();
}
@Override
public String generate() {
return this.client.post(
"/api/organization/sequence/generate",
ImmutableMap.of(
"id", this.uid(),
"org", this.organization.uid()
)
).get().asJsonObject().getString("code");
}
}