ozy.client.PutTenant.java Source code

Java tutorial

Introduction

Here is the source code for ozy.client.PutTenant.java

Source

/*
 * Copyright (c) 2016 Catavolt Inc. All rights reserved.
 *
 * This file is part of Ozy.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package ozy.client;

import io.netty.handler.codec.http.HttpMethod;
import org.json.simple.JSONObject;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 */
public class PutTenant extends ClientRequest {

    private final String _instanceId;
    private final String _tenantId;
    private final JSONObject _bodyObject;

    public static void main(String[] args) throws Exception {
        Logger.getLogger("io.netty").setLevel(Level.FINEST);

        PutTenant request = new PutTenant("http", "127.0.0.1", 8080, testInstanceId(), "solarsource");
        waitForResponse(request.perform());
        Client.shutdown();
    }

    public PutTenant(String scheme, String host, int port, String instanceId, String tenantId) {
        super(HttpMethod.PUT, scheme, host, port);
        if (instanceId == null)
            throw new NullPointerException("instanceId");
        if (tenantId == null)
            throw new NullPointerException("tenantId");
        _instanceId = instanceId;
        _tenantId = tenantId;
        setParams(testParams());
        _bodyObject = new JSONObject();
        JSONObject adminObject = new JSONObject();
        _bodyObject.put("admin", adminObject);
        adminObject.put("userId", "admin");
        adminObject.put("secret", "c68a52015f4640a99f7465072b3ba6cb");
    }

    @Override
    public final String body() {
        return _bodyObject.toJSONString();
    }

    public final String path() {
        return String.format("%s/%s", basePath(_instanceId), _tenantId);
    }

}