Package org.jaibo.api.dataserver

Examples of org.jaibo.api.dataserver.DataServerInfoObject


    }

    @Override
    protected String action() {
        DataServerInfoPackage infoPackage = new DataServerInfoPackage();
        DataServerInfoObject infoObject = new DataServerInfoObject();

        Advertisement[] advertisements = this.object.getAdvertisements();
        ArrayList<DataServerInfoObject> advertisementList = new ArrayList<DataServerInfoObject>();

        for (Advertisement advertisement : advertisements) {
            String text = advertisement.getAdvertisementText();
            short id = advertisement.getAdvertisementId();
            String timePeriod = String.format("%d minutes", advertisement.getTimePeriod());

            DataServerInfoObject adObject = new DataServerInfoObject();
            adObject.putData("id", id);
            adObject.putData("text", text);
            adObject.putData("period", timePeriod);
            advertisementList.add(adObject);
        }

        infoObject.putArrayWithoutEscaping("advertisements", advertisementList);
View Full Code Here


        assertEquals(infoObject.toString(), "{\"collection\":[\"value1\",\"value2\"]}");
    }

    public void testComplexArrayNode() {
        ArrayList<DataServerInfoObject> objectArray = new ArrayList<DataServerInfoObject>();
        DataServerInfoObject obj1 = new DataServerInfoObject();
        obj1.putData("key1", "value1");
        DataServerInfoObject obj2 = new DataServerInfoObject();
        obj2.putData("key2", "value2");
        objectArray.add(obj1);
        objectArray.add(obj2);

        infoObject.putArrayWithoutEscaping("collection", objectArray);
View Full Code Here

        assertEquals(infoObject.toString(), "{\"subObject\":{\"key\":\"value\"},\"key\":\"value\"}");
    }

    public void testNewSubPackage() {
        DataServerInfoObject newObject = new DataServerInfoObject();
        newObject.putData("newKey", "newValue");
        infoObject.putData("key", "value");
        infoObject.putSubObject("subObject", newObject);

        assertEquals(infoObject.toString(), "{\"subObject\":{\"newKey\":\"newValue\"},\"key\":\"value\"}");
    }
View Full Code Here

        infoPackage.clear();
    }

    public void testSimpleDataWithSuccessStatus() {
        DataServerInfoObject infoObject = new DataServerInfoObject();
        infoObject.putData("key", "value");

        this.infoPackage.setInfoObject(infoObject);

        assertEquals(this.infoPackage.toString(), "{\"status\":\"Success\",\"data\":{\"key\":\"value\"}}");
    }
View Full Code Here

        assertEquals(this.infoPackage.toString(), "{\"status\":\"Success\",\"data\":{\"key\":\"value\"}}");
    }

    public void testSimpleDataWithCustomStatusesStatus() {
        DataServerInfoObject infoObject = new DataServerInfoObject();
        infoObject.putData("key", "value");

        this.infoPackage.setInfoObject(infoObject);

        assertEquals(this.infoPackage.toString(), "{\"status\":\"Success\",\"data\":{\"key\":\"value\"}}");
View Full Code Here

    }

    @Override
    protected String action() {
        DataServerInfoPackage infoPackage = new DataServerInfoPackage();
        DataServerInfoObject infoObject = new DataServerInfoObject();

        if (this.getInfoObject() == null || this.getInfoObject().get("token") == null
                || this.getInfoObject().get("token").isEmpty()) {

            infoPackage.setStatus(DataServerInfoStatusCode.ARGUMENT_ERROR);
            infoPackage.setStatusMessage("You must have a token");

        } else {
            String adminHost = this.getInfoObject().get("token");
            String extensionName = this.getInfoObject().get("extension");

            if (this.extensionObject.isApiAuthTokenCorrect(adminHost)) {
                if (extensionName != null && !extensionName.isEmpty()) {
                    try {
                        if (ExtensionManager.IsExtensionObjectExists(extensionName)) {
                            this.extensionObject.getExtensionManager().removeExtensionByName(extensionName);

                            infoObject.putData("answer", "Extension will be unloaded: " + extensionName);
                        } else {
                            infoObject.putData("answer", "Extension is not exists " + extensionName);
                        }
                    } catch (ExtensionManagerError e) {
                        infoObject.putData("answer", e.getMessage());
                    }
                } else {
                    infoObject.putData("answer", "Can't remove extension: empty string provided");
                }

            } else {
                infoPackage.setStatus(DataServerInfoStatusCode.ARGUMENT_ERROR);
                infoPackage.setStatusMessage(String.format("'%s' unknown token", adminHost));
View Full Code Here

    }

    @Override
    protected String action() {
        DataServerInfoPackage infoPackage = new DataServerInfoPackage();
        DataServerInfoObject infoObject = new DataServerInfoObject();

        if (this.getInfoObject() == null || this.getInfoObject().get("token") == null
                || this.getInfoObject().get("token").isEmpty()) {

            infoPackage.setStatus(DataServerInfoStatusCode.ARGUMENT_ERROR);
            infoPackage.setStatusMessage("You must have a token");

        } else {
            String adminHost = this.getInfoObject().get("token");
            String messageOfTheDay = this.getInfoObject().get("message");

            if (this.extensionObject.isApiAuthTokenCorrect(adminHost)) {
                if (messageOfTheDay != null && !messageOfTheDay.isEmpty()) {
                    this.extensionObject.getExtensionMessenger().setMessageOfTheDay(this.extensionObject.getChannels(),
                            messageOfTheDay);

                    infoObject.putData("answer", "Message of the day been updated: " + messageOfTheDay);
                } else {
                    infoObject.putData("answer", "Message of the day was not set: empty string provided");
                }

            } else {
                infoPackage.setStatus(DataServerInfoStatusCode.ARGUMENT_ERROR);
                infoPackage.setStatusMessage(String.format("'%s' unknown token", adminHost));
View Full Code Here

    }

    @Override
    protected String action() {
        DataServerInfoPackage infoPackage = new DataServerInfoPackage();
        DataServerInfoObject infoObject = new DataServerInfoObject();

        if (this.getInfoObject() == null || this.getInfoObject().get("token") == null
                || this.getInfoObject().get("token").isEmpty()) {

            infoPackage.setStatus(DataServerInfoStatusCode.ARGUMENT_ERROR);
            infoPackage.setStatusMessage("You must have a token");

        } else {
            String adminHost = this.getInfoObject().get("token");

            if (this.extensionObject.isApiAuthTokenCorrect(adminHost)) {
                AIBO.Configuration.update();

                infoObject.putData("answer", "Configuration updated");
            } else {
                infoPackage.setStatus(DataServerInfoStatusCode.ARGUMENT_ERROR);
                infoPackage.setStatusMessage(String.format("'%s' unknown token", adminHost));
            }
        }
View Full Code Here

    @Override
    protected String action() {
        String aboutString = AIBO.Configuration.get("aibo.about");

        DataServerInfoPackage infoPackage = new DataServerInfoPackage();
        DataServerInfoObject infoObject = new DataServerInfoObject();
        infoObject.putData("about", aboutString);
        infoPackage.setInfoObject(infoObject);

        return infoPackage.toString();
    }
View Full Code Here

    }

    @Override
    protected String action() {
        DataServerInfoPackage infoPackage = new DataServerInfoPackage();
        DataServerInfoObject infoObject = new DataServerInfoObject();

        if (this.getInfoObject() == null || this.getInfoObject().get("token") == null
                || this.getInfoObject().get("token").isEmpty()) {

            infoPackage.setStatus(DataServerInfoStatusCode.ARGUMENT_ERROR);
            infoPackage.setStatusMessage("You must have a token");

        } else {
            String adminHost = this.getInfoObject().get("token");

            if (this.extensionObject.isApiAuthTokenCorrect(adminHost)) {
                infoObject.putData("answer", "Bot is going to restart now");

                AIBO.restart();
            } else {
                infoPackage.setStatus(DataServerInfoStatusCode.ARGUMENT_ERROR);
                infoPackage.setStatusMessage(String.format("'%s' unknown token", adminHost));
View Full Code Here

TOP

Related Classes of org.jaibo.api.dataserver.DataServerInfoObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.