*/
public static CharacterHeaderDTO mapCharacterToHeader(
Data.Character character, Scene scene,
Long viewCharacterKey) {
final CharacterHeaderDTO dto = new CharacterHeaderDTO();
dto.setId(character.getKey().getId());
dto.setIcon(character.getIcon());
dto.setDescription(character.getDescription());
dto.setProfile(Boolean.TRUE.equals(character.getProfile()));
final Key ownerKey = character.getOwner();
// character can see that a character header is itself an kwow the owner
if(viewCharacterKey == null || viewCharacterKey.equals(dto.getId())) {
dto.setOwner(ownerKey == null ? null : ownerKey.getId());
dto.setOwnerNickname(character.getOwnerNickname());
dto.setDead(character.getDead());
dto.setLocked(character.getLocked());
}
if(viewCharacterKey == null) {
dto.setName(character.getName());
if(scene != null) {
// transform aliases, but only the character aliases.
final Map<String, String> allAliases = scene.getAlias();
if(allAliases != null) {
final Map<Long, String> aliases = dto.getAliases();
final String stringId = String.valueOf(dto.getId());
final String prefix = stringId + "-";
for(Map.Entry<String, String> entry : allAliases.entrySet()) {
final String key = entry.getKey();
if(key != null) {
if(stringId.equals(key)) {
aliases.put(null, entry.getValue());
} else if(key.startsWith(prefix)) {
try {
final Long id = Long.valueOf(key.substring(prefix.length()));
aliases.put(id, entry.getValue());
} catch (NumberFormatException e) {
// nothing ...
}
}
}
}
}
}
} else {
// try to get an alias
final String alias = getCharacterAlias(dto.getId(), scene, viewCharacterKey);
if(alias != null) {
dto.setName(alias);
} else {
dto.setName(character.getName());
}
}
return dto;
}