final Scene scene = sdo.getScene();
final List<Message> messages = sdo.getMessages();
final List<Data.Character> characters = sdo.getCharacters();
final SceneDTO dto = new SceneDTO();
dto.setId(scene.getKey().getId());
dto.setCharacters(mapCharacterHeader(characters, scene, viewCharacterKey));
dto.setMessages(mapMessage(messages));
// use introduction as message
final String introduction = scene.getIntroduction();
if(introduction != null) {
if(dto.getMessages() == null) {
dto.setMessages(new ArrayList<MessageDTO>());
}
final MessageDTO messageDTO = new MessageDTO();
messageDTO.setId(null);
messageDTO.setAction(null);
messageDTO.setAuthor(null);
messageDTO.setContent(introduction);
messageDTO.setIndex(0);
messageDTO.setType(null);
dto.getMessages().add(0, messageDTO);
}
dto.setTimestamp(scene.getTimestamp());
if(viewCharacterKey != null) {
// for a character, only its own informations
final String viewCharacterKeyString = viewCharacterKey.toString();
final Key next = scene.getNext(viewCharacterKeyString);
if (next != null) {
dto.getNext().put(viewCharacterKey, next.getId());
}
final Key previous = scene.getPrevious(viewCharacterKeyString);
if (previous != null) {
dto.getPrevious().put(viewCharacterKey, previous.getId());
}
} else {
// for GM : all informations
for(Map.Entry<String, Key> entry : scene.getNext().entrySet()) {
try {
final Long id = Long.valueOf(entry.getKey());
dto.getNext().put(id, entry.getValue().getId());
} catch (NumberFormatException e) {
// ...
}
}
for(Map.Entry<String, Key> entry : scene.getPrevious().entrySet()) {
try {
final Long id = Long.valueOf(entry.getKey());
dto.getPrevious().put(id, entry.getValue().getId());
} catch (NumberFormatException e) {
// ...
}
}
}