Package net.cloudcodex.server.data.Data

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


    return user;
  }
 
  private Data.CharacterNote createNote(DAO dao, Data.Character on, Data.Character by, String text) {
 
    final CharacterNote note = new CharacterNote(on);
    note.setAuthor(by);
    note.setContent(text);
    dao.save(null, note);
    return note;
  }
View Full Code Here


            // author's key is null for GM
            final Key authorKey = entry.getKey() == null ? null
                : Data.Character.createKey(campaignKey, entry.getKey());

            // read the current note from this author
            CharacterNote noteDB = dao.getCharacterNoteByAuthor(context, characterKey, authorKey);
            if(noteDB == null) {
              noteDB = new CharacterNote(character);
              noteDB.setAuthor(authorKey);
            }
           
            // Notes are never deleted, just set to null (usefull when checking deltas)
            noteDB.setContent(entry.getValue());
            dao.save(context, noteDB);
          }
        }
       
        if(dead != null) {
          character.setDead(dead);
        }

        // Only PCs can be locked
        if(locked != null && !npc) {
          character.setLocked(locked);
        }
       
        dao.save(context, character);

      } else {
       
        if(notes != null) {
          if(byCharacterId == null) {
            logger.severe("user " + context.getUser().getKey()
                + " has tried to update GM note on " + characterKey);
            context.addError(USER_USURPATION_GM);
            return null;
          }
         
          // players can only update their own.
          final Key authorKey = Data.Character.createKey(campaignKey, byCharacterId);

          // check the writer exists
          final Data.Character author = dao.readCharacter(context, authorKey);
          if(author == null) {
            logger.severe("character not found " + characterKey);
            context.addError(NOT_FOUND_CHARACTER, characterId);
            return null;
          }
         
          // check the user is the writer's owner
          if(!isOwner(context, author)) {
            logger.severe("user " + context.getUser().getKey() + " has tried to update "
                + author.getOwner() + "'s note on " + characterKey);
            context.addError(Errors.USER_USURPATION);
            return null;
          }

          // update or create the note if not an NPC
          CharacterNote noteDB = dao.getCharacterNoteByAuthor(context, characterKey, authorKey);
          if(noteDB == null) {
            noteDB = new CharacterNote(character);
            noteDB.setAuthor(authorKey);
          }
          noteDB.setContent(notes.get(byCharacterId));
          dao.save(context, noteDB);
        }
      }

      tx.commit();
View Full Code Here

TOP

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

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.