All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.minlessika.membership.integration.RestSequence Maven / Gradle / Ivy

Go to download

It's a library to help developers to integration membership services to another project.

There is a newer version: 0.3.1
Show newest version
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");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy