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

com.global.api.entities.tableservice.ServerAssignmentResponse Maven / Gradle / Ivy

There is a newer version: 14.2.3
Show newest version
package com.global.api.entities.tableservice;

import com.global.api.entities.exceptions.ApiException;
import com.global.api.utils.JsonDoc;
import com.global.api.utils.StringUtils;

import java.util.HashSet;
import java.util.Set;

public class ServerAssignmentResponse extends TableServiceResponse {
    private ShiftAssignments assignments;

    public ShiftAssignments getAssignments() {
        return assignments;
    }

    public ServerAssignmentResponse(String json) throws ApiException {
        this(json, "default");
    }
    public ServerAssignmentResponse(String json, String configName) throws ApiException {
        super(json, configName);
        expectedAction = "getServerAssignment";
    }

    protected void mapResponse(JsonDoc response) throws ApiException {
        super.mapResponse(response);

        assignments = new ShiftAssignments();

        // if we have a row then it's an array
        if(response.has("row")) {
            for(JsonDoc row: response.getEnumerator("row"))
                addAssignment(row);
        }
        else addAssignment(response);
    }

    private void addAssignment(JsonDoc assignment) {
        String server = assignment.getString("server");
        String tables = assignment.getString("tables");

        if(!StringUtils.isNullOrEmpty(tables)) {
            Set ids = new HashSet();
            for(String table: tables.split(","))
                ids.add(Integer.parseInt(table));

            assignments.put(server, ids.toArray(new Integer[ids.size()]));
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy