Avatar findAttachmentMetadataById(String avatarId) {
if (avatarId == null) {
return null;
}
Avatar avatar = new Avatar();
avatar.setAvatarId(avatarId);
ColumnQuery<String, String, String> queryFilename = HFactory.createColumnQuery(keyspaceOperator,
StringSerializer.get(), StringSerializer.get(), StringSerializer.get());
HColumn<String, String> columnFilename =
queryFilename.setColumnFamily(AVATAR_CF)
.setKey(avatarId)
.setName(FILENAME)
.execute()
.get();
if (columnFilename != null && columnFilename.getValue() != null) {
avatar.setFilename(columnFilename.getValue());
} else {
return null;
}
ColumnQuery<String, String, Long> querySize = HFactory.createColumnQuery(keyspaceOperator,
StringSerializer.get(), StringSerializer.get(), LongSerializer.get());
HColumn<String, Long> columnSize =
querySize.setColumnFamily(AVATAR_CF)
.setKey(avatarId)
.setName(SIZE)
.execute()
.get();
if (columnSize != null && columnSize.getValue() != null) {
avatar.setSize(columnSize.getValue());
} else {
return null;
}
ColumnQuery<String, String, Date> queryCreationDate = HFactory.createColumnQuery(keyspaceOperator,
StringSerializer.get(), StringSerializer.get(), DateSerializer.get());
HColumn<String, Date> columnCreationDate =
queryCreationDate.setColumnFamily(AVATAR_CF)
.setKey(avatarId)
.setName(CREATION_DATE)
.execute()
.get();
if (columnCreationDate != null && columnCreationDate.getValue() != null) {
avatar.setCreationDate(columnCreationDate.getValue());
} else {
avatar.setCreationDate(new Date());
}
return avatar;
}