Package org.jaibo.api.dataserver

Examples of org.jaibo.api.dataserver.DataServerInfoPackage


        this.setInfoPath("/advertisement/list");
    }

    @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);

        infoPackage.setInfoObject(infoObject);

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


        this.setInfoPath("/core/unload");
    }

    @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));
            }
        }

        infoPackage.setInfoObject(infoObject);

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

        this.setInfoPath("/core/motd");
    }

    @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));
            }
        }

        infoPackage.setInfoObject(infoObject);

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

        this.setInfoPath("/core/update/configuration");
    }

    @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));
            }
        }

        infoPackage.setInfoObject(infoObject);

        return infoPackage.toString();
    }
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

        this.setInfoPath("/core/restart");
    }

    @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));
            }
        }

        infoPackage.setInfoObject(infoObject);

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

        this.setInfoPath("/core/extensions");
    }

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

        String[] extensionNames = this.extensionObject.getExtensionManager().getAllExtensionList();
        ArrayList<DataServerInfoObject> extensions = new ArrayList<DataServerInfoObject>();

        for (int i = 0; i < extensionNames.length; i++) {
            DataServerInfoObject extensionObject = new DataServerInfoObject();
            String extensionName = extensionNames[i];
            boolean isRunning = this.extensionObject.getExtensionManager().isExtensionAlreadyAdded(extensionName);

            extensionObject.putData("running", isRunning);
            extensionObject.putData("extension", extensionName);

            extensions.add(extensionObject);
        }

        infoObject.putArrayWithoutEscaping("extensions", extensions);

        infoPackage.setInfoObject(infoObject);

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

        this.setInfoPath("/core/uptime");
    }

    @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)) {
                String upTime = GregorianCalendarHelper.GetDifferenceAsHumanReadableString(
                        new GregorianCalendar(),
                        AIBO.getStartDateTime());

                long usedMB = AIBO.getRAMUsage();

                infoObject.putData("uptime", String.format("Uptime: %s | Memory usage: %d MB", upTime, usedMB));
            } else {
                infoPackage.setStatus(DataServerInfoStatusCode.ARGUMENT_ERROR);
                infoPackage.setStatusMessage(String.format("'%s' unknown token", adminHost));
            }
        }

        infoPackage.setInfoObject(infoObject);

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

        this.setInfoPath("/core/load");
    }

    @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().addExtensionByName(extensionName);

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

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

        infoPackage.setInfoObject(infoObject);

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

        this.setInfoPath("/core/shutdown");
    }

    @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 will shut down in 5 seconds");

                AIBO.Shutdown();
            } else {
                infoPackage.setStatus(DataServerInfoStatusCode.ARGUMENT_ERROR);
                infoPackage.setStatusMessage(String.format("'%s' unknown token", adminHost));
            }
        }

        infoPackage.setInfoObject(infoObject);

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

TOP

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

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.