Package net.cloudcodex.server.data.Data

Examples of net.cloudcodex.server.data.Data.Campaign


          seqChars.add(character);
        }
      }
    }
   
    final Campaign campaign = dao.readCampaign(context, campaignKey);
   
    if(campaign == null) {
      logger.severe("startScene() : campaign not found :" + campaignKey);
      context.addError(Errors.NOT_FOUND_CAMPAIGN, campaignKey);
      return null;
View Full Code Here


      context.addError(Errors.REQUIRED, "scenes");
      return false;
    }
   
    final Key campaignKey = Campaign.createKey(campaignId);
    final Campaign campaign = dao.readCampaign(context, campaignKey);
    if(campaign == null) {
      logger.severe("Campaign not found " + campaignKey);
      context.addError(Errors.NOT_FOUND_CAMPAIGN, campaignKey);
      return false;
    }
View Full Code Here

   * @return
   */
  public boolean deleteMessage(Context context, long campaignId, long sceneId, long messageId) {

    final Key campaignKey = Data.Campaign.createKey(campaignId);
    final Campaign campaign = dao.readCampaign(context, campaignKey);
    if(campaign == null) {
      logger.severe("Campaign not found " + campaignKey);
      context.addError(Errors.NOT_FOUND_CAMPAIGN, campaignKey);
      return false;
    }
View Full Code Here

    // choose randomly a message to delete
    final long messageId = messages.get(random.nextInt(messages.size())).getKey().getId();
   
    // check the campaign
    final Campaign campaign = dao.readCampaign(context, campaignKey);
    if(campaign == null) {
      logger.severe("Campaign not found " + campaignKey);
      context.addError(Errors.NOT_FOUND_CAMPAIGN, campaignKey);
      return false;
    }
   
    // may be 100% of test cases
    if(!isGameMaster(context, campaign)) {
      // then we cheat ...
      final Key masterKey = campaign.getMaster();
      final User master = dao.readUser(context, masterKey);
      if(master == null){
        logger.severe("Master not found " + masterKey);
        context.addError(Errors.NOT_FOUND_USER, masterKey);
        return false;
View Full Code Here

    // choose randomly after which insert a new message
    final long messageId = messages.get(random.nextInt(messages.size())).getKey().getId();
   
   
    // check the campaign
    final Campaign campaign = dao.readCampaign(context, campaignKey);
    if(campaign == null) {
      logger.severe("Campaign not found " + campaignKey);
      context.addError(Errors.NOT_FOUND_CAMPAIGN, campaignKey);
      return false;
    }

    // may be 100% of test cases
    if(!isGameMaster(context, campaign)) {
      // then we cheat ...
      final Key masterKey = campaign.getMaster();
      final User master = dao.readUser(context, masterKey);
      if(master == null){
        logger.severe("Master not found " + masterKey);
        context.addError(Errors.NOT_FOUND_USER, masterKey);
        return false;
View Full Code Here

      return false;
    }
   
    // check the campaign
    final Key campaignKey = Campaign.createKey(campaignId);
    final Campaign campaign = dao.readCampaign(context, campaignKey);
    if(campaign == null) {
      logger.severe("Campaign not found " + campaignKey);
      context.addError(Errors.NOT_FOUND_CAMPAIGN, campaignKey);
      return false;
    }
View Full Code Here

      final Data.User romain = createUser(dao, "krazlafas@gmail.com", "Romain");
     
      {
        final Transaction tx = datastore.beginTransaction();
        try {
          final Campaign campaign = campaignService.createCampaign(null, "Thomas's Campaign", "Some game", "Some desc", null, thomas);
         
          // Create a generic notification for all characters of the notification.
          createNotification(dao, "Please make OFF session to define your character", campaign.getKey());
         
         
          final Data.Character ulrich = createCharacter(dao, campaign, "Ulrich", xavier);
          final Data.Character olukun = createCharacter(dao, campaign, "Olukun", arnaud);
          final Data.Character hektor = createCharacter(dao, campaign, "Hektor", daniel);
          final Data.Character inigo = createCharacter(dao, campaign, "Inigo", romain);
          createNote(dao, ulrich, inigo, "I think he wants to kill me !!!");
         
          final Data.Character deBloni = createCharacter(dao, campaign, "Victor de Bloni", null);
          createNote(dao, deBloni, ulrich, "Met at Shallya's orphanage");
          createNote(dao, deBloni, hektor, "He hides something ...");
         
          final Data.Character guardChief = createCharacter(dao, campaign, "Otto Meuler", null);
          guardChief.setDescription("Faussenburg's Guard Chief");
          dao.save(null, guardChief);

          final Data.Character mayor = createCharacter(dao, campaign, "Herman Storn", null);
          mayor.setDescription("Faussenburg's Mayor");
          dao.save(null, mayor);
         
          // commit here because cannot read items ...
          tx.commit();

          /*
           * Init some scenes and messages.
           */
          Scene scene = messageService.startScene(context, "You're talking to the Guard chief", ulrich, inigo, guardChief);
          scene.setAlias(guardChief.getKey().getId() + "", "Global Alias for Guard Chief");
          scene.setAlias(ulrich.getKey().getId() + "", "Global Alias for Ulrich");
          scene.setAlias(ulrich.getKey().getId() + "-" + inigo.getKey().getId(), "My friend");
          dao.save(context, scene);
          messageService.postSpeech(context, null, ulrich, "Have you seen the mayor ?");
          messageService.postSpeech(context, null, ulrich, "Guy, I'm talking to you !");
          messageService.postSpeech(context, scene.getKey(), guardChief, "No, Not the last days. I'm worried.");
          messageService.postSpeech(context, null, inigo, "I'm sure he's gone with the town gold !");
          messageService.postSpeech(context, scene.getKey(), guardChief, "I'm going right now to check the bank !");
          scene = messageService.startScene(context, "Guard chief is gone, you're alone in the street", ulrich, inigo);
          messageService.postSpeech(context, null, inigo, "OK, wat a stupid guy ...");
          messageService.postSpeech(context, null, ulrich, "Yes, we can now deliver our friend from the jail.");
          messageService.postSpeech(context, null, inigo, "Let's go ! I'm going to search Hektor");
          scene = messageService.startScene(context, "Hektor, Inigo is coming to you at the inn", hektor, inigo);
          messageService.postSpeech(context, null, inigo, "You ! Come with me !");
          messageService.postSpeech(context, null, hektor, "Huh ?!? OK ...");
         
          // now ulrich scene
          messageService.postOFF(context, null, ulrich.getKey(), null, "Is it to late to go to the market ?");
          messageService.postOFF(context, null, null, ulrich.getKey(), "No, you can.");
          messageService.postOFF(context, null, ulrich.getKey(), null, "So I go to the market");
          messageService.postOFF(context, null, null, ulrich.getKey(), "When arriving to market, you see Olukun.");
          messageService.postOFF(context, null, ulrich.getKey(), null, "I go talk to him");
          scene = messageService.startScene(context, "Olukun, Ulrich is here.", ulrich, olukun);
          messageService.postSpeech(context, null, olukun, "Hey ! How do you do ?");
         
          // ...
          scene = messageService.startScene(context, "Everybody is here ...", ulrich, olukun, hektor, inigo);
          messageService.postSpeech(context, null, inigo, "OK Let's go to the jail !");
          messageService.postSpeech(context, null, olukun, "Huh ... wait a minute ...");
         
          {
            List<Scene> scenes = dao.asListOfScenes(null, dao.queryScene(campaign.getKey()), null);
            if(scenes != null) {
              for(Scene seq : scenes) {
                System.err.println(seq.getEntity());
                final List<Message> messages =
                  dao.asListOfMessages(null,
                    dao.queryMessage(seq.getKey()), null,
                    Message.Properties.TIMESTAMP);
                if(messages != null) {
                  for(Message msg : messages) {
                    System.err.println(msg.getEntity());
                  }
                }
              }
            }
          }
         
          {
            System.err.println("----------- Inigo messages");
            final Context context2 = new Context(romain);
            final List<SceneSDO> scenes = messageService.getMessages(context2,
                campaign.getKey().getId(),
                inigo.getKey().getId(), null, null);
           
            if(scenes != null) {
              for(SceneSDO sdo : scenes) {
                final Scene seq = sdo.getScene();
                System.err.println(seq.getEntity());
                final List<Message> messages = sdo.getMessages();
                if(messages != null) {
                  for(Message msg : messages) {
                    System.err.println(msg.getEntity());
                  }
                }
              }
            }
          }

          {
            System.err.println("----------- Ulrich messages");
            final Context context2 = new Context(xavier);
            final List<SceneSDO> scenes = messageService.getMessages(context2,
                campaign.getKey().getId(),
                ulrich.getKey().getId(), null, null);
           
            if(scenes != null) {
              for(SceneSDO sdo : scenes) {
                final Scene seq = sdo.getScene();
                System.err.println(seq.getEntity());
                final List<Message> messages = sdo.getMessages();
                if(messages != null) {
                  for(Message msg : messages) {
                    System.err.println(msg.getEntity());
                  }
                }
              }
            }
          }
         
          {
            System.err.println("----------- Olukun messages");
            final Context context2 = new Context(arnaud);
            final List<SceneSDO> scenes = messageService.getMessages(context2,
                campaign.getKey().getId(),
                olukun.getKey().getId(), null, null);
           
            if(scenes != null) {
              for(SceneSDO sdo : scenes) {
                final Scene seq = sdo.getScene();
                System.err.println(seq.getEntity());
                final List<Message> messages = sdo.getMessages();
                if(messages != null) {
                  for(Message msg : messages) {
                    System.err.println(msg.getEntity());
                  }
                }
              }
            }
          }

          {
            System.err.println("----------- Hektor messages");
            final Context context2 = new Context(daniel);
            final List<SceneSDO> scenes = messageService.getMessages(context2,
                campaign.getKey().getId(),
                hektor.getKey().getId(), null, null);
           
            if(scenes != null) {
              for(SceneSDO sdo : scenes) {
                final Scene seq = sdo.getScene();
                System.err.println(seq.getEntity());
                final List<Message> messages = sdo.getMessages();
                if(messages != null) {
                  for(Message msg : messages) {
                    System.err.println(msg.getEntity());
                  }
                }
              }
            }
          }

        } finally {
          if(tx.isActive()) {
            tx.rollback();
          }
        }
      }
      {
        final Transaction tx = datastore.beginTransaction();
        try {
          final Campaign campaign = campaignService.createCampaign(null, "another thomas' campaign", "Some game", "Some desc", null, thomas);
          campaign.setIcon("http://4.bp.blogspot.com/_SniTwfm5BwE/StS30qA7boI/AAAAAAAABpc/1kDwWjGglHI/s320/D%26D4E.jpg");
          createNotification(dao,  "this is another Notification", campaign.getKey());
          dao.save(null, campaign);
          tx.commit();
        } finally {
          if(tx.isActive()) {
            tx.rollback();
          }
        }
      }
     
      {
        final Transaction tx = datastore.beginTransaction();
        try {
          final Campaign campaign = campaignService.createCampaign(null, "Campaign 3", "Some game", "Some desc", null, daniel);
          campaign.setIcon("http://www.wizards.com/dnd/images/rhod_gallery/95863.jpg");
          createNotification(dao, "Please," + daniel.getNickname()+ " make OFF session to define your character", campaign.getKey());
         
          dao.save(null, campaign);
          tx.commit();
        } finally {
          if(tx.isActive()) {
            tx.rollback();
          }
        }
      }

     
      {
        final Transaction tx = datastore.beginTransaction();
        try {
          final Campaign campaign = campaignService.createCampaign(null, "Campaign 2", "Some game", "Some desc", null, daniel);
          campaign.setIcon("http://4.bp.blogspot.com/_SniTwfm5BwE/StS30qA7boI/AAAAAAAABpc/1kDwWjGglHI/s320/D%26D4E.jpg");
          createNotification(dao,  "this is another Notification", campaign.getKey());
         
          dao.save(null, campaign);
          tx.commit();
        } finally {
          if(tx.isActive()) {
            tx.rollback();
          }
        }
      }

     
      {
        final Transaction tx = datastore.beginTransaction();
        try {
          final Campaign campaign = campaignService.createCampaign(null, "Daniel's Campaign", "Some game", "Some desc", null, daniel);
          createNotification(dao,  "this is a Notification", campaign.getKey());
          final Data.Character joe = createCharacter(dao, campaign, "Joe", thomas);
          final Data.Character jack = createCharacter(dao, campaign, "Jack", arnaud);
          createNote(dao, jack, joe, "Why this guy is always following me ?!?");
          final Data.Character eric = createCharacter(dao, campaign, "Eric", null);
          tx.commit();
        } finally {
          if(tx.isActive()) {
            tx.rollback();
          }
        }
      }
    }

   
    /*
     * Tests for Home
     */
    {
      final Data.User user1 = createUser(dao, "user1@home.com", "User1");
      final Data.User user2 = createUser(dao, "user2@home.com", "User2");
      final Data.User user3 = createUser(dao, "user3@home.com", "User3");
     
      final Campaign campaign = campaignService.createCampaign(null, "My Home !", "Some game", "Some desc", null, user3);

      final Data.Character char1 = campaignService.createCharacter(null, campaign, "Char1", user1, null, null);
      final Data.Character char2 = campaignService.createCharacter(null, campaign, "Char2", user2, null, null);
      final Data.Character char3 = campaignService.createCharacter(null, campaign, "Char3", user3, null, null);
     
View Full Code Here

      context.addError(REQUIRED);
      return null;
    }
   
    // check the campaign doesn't already exist
    Campaign campaign = dao.getCampaignByName(context, name);
    if(campaign != null) {
      logger.severe("campaign '" + name + "' alreayd exists");
      context.addError(IMPOSSIBLE_EXISTS, name);
      return null;
    }
   
    campaign = new Campaign();
    campaign.setName(name);
    campaign.setGame(game);
    campaign.setMaster(master);
    campaign.setDate(new Date());
    campaign.setDescription(description);
    campaign.setIcon(icon);
    campaign.setDate(new Date());
    dao.save(context, campaign);

    return campaign;
  }
View Full Code Here

      context.addError(USER_USURPATION_GM);
      return null;
    }
   
    // check the campaign doesn't already exist
    Campaign otherCampaign = dao.getCampaignByName(context, name);
    if(otherCampaign != null) {
      logger.severe("campaign '" + name + "' alreayd exists");
      context.addError(IMPOSSIBLE_EXISTS, name);
      return null;
    }
View Full Code Here

   * @param campaignId campaign id.
   * @return the campaign's characters.
   */
  public List<CharacterSDO> getCampaignCharacters(Context context, long campaignId) {
   
    final Campaign campaign = dao.readCampaign(context, campaignId);
    if(campaign == null) {
      logger.severe("Campaign not found " + campaignId);
      context.addError(NOT_FOUND_CAMPAIGN, campaignId);
      return null;
    }

    final Key campaignKey = campaign.getKey();
   
    // Check current user is campaign GM
    final Data.User user = context.getUser();
    if(!campaign.getMaster().equals(user.getKey())) {
      logger.severe("Unauthorized access by "
          + user.getKey() + " on " + campaignKey);
      context.addError(USER_USURPATION_GM);
      return null;
    }
View Full Code Here

TOP

Related Classes of net.cloudcodex.server.data.Data.Campaign

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.