Package com.nabalive.data.core.model

Examples of com.nabalive.data.core.model.Nabaztag


public class SleepTest {
    @Test
    public void sleepTest(){
        ConnectionWelcome welcome = new ConnectionWelcome();

        Nabaztag nabaztag = new Nabaztag();
        nabaztag.getSleep().add("14:06-7");
        nabaztag.getSleep().add("08:50-5");
        nabaztag.getSleep().add("10:17-3");


        nabaztag.getWakeup().add("14:03-6");
        nabaztag.getWakeup().add("11:45-6");
        nabaztag.getWakeup().add("10:32-2");
        boolean b = welcome.checkSleep(nabaztag);

        System.out.println("b:" + b);

View Full Code Here


        assertNotNull(userDAO);
    }

    @Test
    public void testInserNabaztag() {
        Nabaztag n1 = new Nabaztag();
        Nabaztag n2 = new Nabaztag();

        n1.setName("n1");
        n2.setName("n2");

        n1.setMacAddress(UUID.randomUUID().toString());
        n2.setMacAddress(UUID.randomUUID().toString());
       
        nabaztagDAO.save(n1);
        nabaztagDAO.save(n2);
    }
View Full Code Here

                        String action = request.getParam("action");
                        String chor = request.getParam("chor");

                        String host = request.request.getHeader("Host");

                        Nabaztag nabaztag;
                        try{
                            nabaztag = checkNotNull(nabaztagDAO.findOne("macAddress", mac));
                        }catch(NullPointerException e){
                            throw new HttpException(HttpResponseStatus.UNAUTHORIZED, "mac address doesn't exists");
                        }
                       
                        if (!token.equalsIgnoreCase(nabaztag.getApikey())) {
                            throw new HttpException(HttpResponseStatus.UNAUTHORIZED, "token is not valid");
                        }

                        StringBuilder commands = new StringBuilder();
                        if(chor != null){
View Full Code Here

                    public void handle(Request request, Response response, Map<String, String> map) throws Exception {
                        String mac = checkNotNull(request.getParam("sn")).toLowerCase();
                        if (!connectionManager.containsKey(mac))
                            throw new HttpException(HttpResponseStatus.NOT_FOUND, "sn is not connected");

                        Nabaztag nabaztag = checkNotNull(nabaztagDAO.findOne("macAddress", mac));

                        ChannelBuffer content = request.request.getContent();
                        logger.debug("record orig size: {}", content.readableBytes());
                        ChannelBufferInputStream inputStream = new ChannelBufferInputStream(content);

                        TmpData sound = new TmpData();
                        sound.setData(ByteStreams.toByteArray(inputStream));
                        tmpDataDAO.save(sound, WriteConcern.SAFE);


                        String host = request.request.getHeader("Host");
                        String url = "http://" + host + "/record/" + sound.getId().toString();
                        logger.debug("sound url: {}", url);

                        final String command = "ST " + url + "\nMW\n";

                        Query<Nabaztag> query = nabaztagDAO.createQuery();
                        query.filter("subscribe.objectId", nabaztag.getId().toString());
                        List<Nabaztag> nabaztags = nabaztagDAO.find(query).asList();


                        logger.debug("sending to {} subscribers", nabaztags.size());
                        for (Nabaztag nab : nabaztags) {
                            if (connectionManager.containsKey(nab.getMacAddress())) {
                                final Nabaztag nabTmp = nab;
                                Runnable runnable = new Runnable() {
                                    @Override
                                    public void run() {
                                        logger.debug("sending to {}", nabTmp.getMacAddress());
                                        logger.debug("command {}", command);
                                        messageService.sendMessage(nabTmp.getMacAddress(), command);
                                    }
                                };
                                ses.schedule(runnable, 500, TimeUnit.MILLISECONDS);
                            }
                        }
View Full Code Here

        Application application = checkNotNull(applicationManager.getApplication(CLOCK_APIKEY)); // clock

        Query<Nabaztag> query = nabaztagDAO.createQuery().filter("applicationConfigList.applicationStoreApikey", CLOCK_APIKEY);
        Iterator<Nabaztag> iterator = nabaztagDAO.find(query).iterator();
        while (iterator.hasNext()) {
            Nabaztag nabaztag = iterator.next();
            Status status = connectionManager.get(nabaztag.getMacAddress());
            if (status != null && !status.isAsleep()) {
                try {
                    application.onStartup(nabaztag, findConfig(CLOCK_APIKEY, nabaztag.getApplicationConfigList()));
                } catch (Exception e) {
                    logger.debug("cannot send message", e);
                }
            }
        }
View Full Code Here

        Application application = checkNotNull(applicationManager.getApplication(MOOD_APIKEY)); // mood

        Query<Nabaztag> query = nabaztagDAO.createQuery().filter("applicationConfigList.applicationStoreApikey", MOOD_APIKEY);
        Iterator<Nabaztag> iterator = nabaztagDAO.find(query).iterator();
        while (iterator.hasNext()) {
            Nabaztag nabaztag = iterator.next();
            Status status = connectionManager.get(nabaztag.getMacAddress());
            if (status != null && status.isIdle()) {
                if (rand.nextInt(4) == 0){
                    try {
                        application.onStartup(nabaztag, findConfig(MOOD_APIKEY, nabaztag.getApplicationConfigList()));
                    } catch (Exception e) {
                        logger.debug("cannot send message", e);
                    }
                }
            }
View Full Code Here

        Application application = checkNotNull(applicationManager.getApplication(TAICHI_APIKEY)); // taichi

        Query<Nabaztag> query = nabaztagDAO.createQuery().filter("applicationConfigList.applicationStoreApikey", TAICHI_APIKEY);
        Iterator<Nabaztag> iterator = nabaztagDAO.find(query).iterator();
        while (iterator.hasNext()) {
            Nabaztag nabaztag = iterator.next();
            Status status = connectionManager.get(nabaztag.getMacAddress());
            if (status != null && status.isIdle()) {
                if (rand.nextInt(4) == 0){
                    try {
                        application.onStartup(nabaztag, findConfig(TAICHI_APIKEY, nabaztag.getApplicationConfigList()));
                    } catch (Exception e) {
                        logger.debug("cannot send message", e);
                    }
                }
            }
View Full Code Here

    }
   
    private void sendToAll(Query<Nabaztag> query, Packet p){
        Iterator<Nabaztag> iterator = nabaztagDAO.find(query).iterator();
        while (iterator.hasNext()) {
            Nabaztag nabaztag = iterator.next();
            if (connectionManager.containsKey(nabaztag.getMacAddress())) {
                messageService.sendMessage(nabaztag.getMacAddress(), p);
            }
        }
    }
View Full Code Here

    @Override
    public void onEvent(String sender, Event event) throws Exception {
        logger.debug("event type {}", event.type);
        logger.debug("event type {}", event.content);
        if (event.type == Event.Type.UNBIND_RESOURCE && event.content.contains("<resource>boot</resource></unbind>")) {
            Nabaztag nabaztag = nabaztagDAO.findOne("macAddress", sender);
            logger.debug("WELCOME: unbind {}", nabaztag);

            messageService.sendMessage(sender, new PingPacket(60));

            if (nabaztag == null) {
                logger.debug("WELCOME: SENDING SOUND");
                String command = "CH http://www.nabalive.com/api/chor/rand/5\nMW\n" +
                        "ST " + WELCOME_URL + "\nMW\n";
                messageService.sendMessage(sender, command);
            } else {
                boolean isSleep = checkSleep(nabaztag);
                logger.debug("WELCOME: ISSLEEP :" + isSleep);
                if (isSleep) {
                    logger.debug("WELCOME: SENDING SLEEP");
                    messageService.sendMessage(nabaztag.getMacAddress(), new SleepPacket(SleepPacket.Action.Sleep));
                }
            }
        }
    }
View Full Code Here

                    public void handle(Request request, Response response, Map<String, String> map) throws Exception {
                        String mac = checkNotNull(request.getParam("sn")).toLowerCase();
                        String tagValue = checkNotNull(request.getParam("t")).toLowerCase();
                        String host = request.request.getHeader("Host");

                        Nabaztag nabaztag = nabaztagDAO.findOne("macAddress", mac);
                        if(nabaztag == null){
                            messageService.sendMessage(mac, "ST " + ConnectionWelcome.WELCOME_URL + "\nMW\n");
                            response.write("ok");
                            return;
                        }

                        if (!nabaztag.hasTag(tagValue)) {
                            Tag tag = new Tag();
                            tag.setValue(tagValue);
                            tag.setName(tagValue);
                            nabaztag.getTags().add(tag);
                            nabaztagDAO.save(nabaztag);
                            nabaztagController.tts(nabaztag.getMacAddress(), host, "fr", "Nouveau tag ajouté");
                        } else {
                            for (ApplicationConfig applicationConfig : nabaztag.getApplicationConfigList()) {
                                if (applicationConfig.getTags().contains(tagValue)) {
                                    String apikey = applicationConfig.getApplicationStoreApikey();
                                    Application application = applicationManager.getApplication(apikey);

                                    applicationConfig.getParameters().put("__RFID__", (new ImmutableList.Builder<String>()).add(tagValue).build());
                                    application.onStartup(nabaztag, applicationConfig);
                                    response.write("ok");
                                    return;
                                }
                            }
                            nabaztagController.tts(nabaztag.getMacAddress(), host, "fr", "Aucune application associée au tag");
                        }
                        response.write("ok");
                    }
                });
    }
View Full Code Here

TOP

Related Classes of com.nabalive.data.core.model.Nabaztag

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.