io.personium.client.BoxManager.java Source code

Java tutorial

Introduction

Here is the source code for io.personium.client.BoxManager.java

Source

/**
 * Personium
 * Copyright 2014 - 2017 FUJITSU LIMITED
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.personium.client;

import java.util.HashMap;

import org.json.simple.JSONObject;

import io.personium.client.utils.UrlUtils;

///**
// * Box?CRUD????.
// */
/**
 * It creates a new object of BoxManager. This class performs CRUD operations for Box.
 */
public class BoxManager extends ODataManager {
    // /**
    // * .
    // * @param as Accessor
    // */
    /**
     * This is the parameterized constructor with one parameter calling its parent constructor.
     * @param as Accessor
     */
    public BoxManager(Accessor as) {
        super(as);
    }

    /**
     * This method is used to generate the URL for performing Box related operations.
     * @return URL value
     */
    @Override
    public String getUrl() {
        StringBuilder sb = new StringBuilder(accessor.getCurrentCell().getUrl());
        sb.append("__ctl/Box");
        return sb.toString();
    }

    // /**
    // * Box?.
    // * @param obj Box
    // * @return Box
    // * @throws DaoException DAO
    // */
    /**
     * This method is used to create a Box from Box object.
     * @param obj Box object
     * @return Box object that is created
     * @throws DaoException Exception thrown
     */
    @SuppressWarnings("unchecked")
    public Box create(Box obj) throws DaoException {
        JSONObject body = new JSONObject();
        body.put("Name", obj.getName());
        body.put("Schema", obj.getSchema());
        JSONObject json = internalCreate(body);
        String path = UrlUtils.append(accessor.getCurrentCell().getUrl(), (String) body.get("Name"));
        obj.initialize(this.accessor, json, path);
        return obj;
    }

    // /**
    // * Box?.
    // * @param body 
    // * @return ???Box
    // * @throws DaoException DAO
    // */
    /**
     * This method is used to create a Box from request body.
     * @param body Request Body
     * @return Box object
     * @throws DaoException Exception thrown
     */
    public Box create(HashMap<String, Object> body) throws DaoException {
        JSONObject json = internalCreate(body);
        return new Box(accessor, json,
                UrlUtils.append(accessor.getCurrentCell().getUrl(), (String) body.get("Name")));
    }

    // /**
    // * Box?.
    // * @param name ??box??
    // * @return ?????Box
    // * @throws DaoException DAO
    // */
    /**
     * This method is used to retrieve box details for the specified box.
     * @param name Box Name
     * @return Box object
     * @throws DaoException Exception thrown
     */
    public Box retrieve(String name) throws DaoException {
        JSONObject json = internalRetrieve(name);
        return new Box(accessor, json, UrlUtils.append(accessor.getCurrentCell().getUrl(), name));
    }

}