@NotNull AttachmentDto asDto(@NotNull Attachment attachment) { AttachmentDto.Builder builder = AttachmentDto.newBuilder() .setId(attachment.getId()) .setFileName(attachment.getName()) .setTimestamps(TimestampsDtos.asDto(attachment)); if (attachment.getType() != null) builder.setType(attachment.getType()); if (attachment.getDescription() != null) { builder.addAllDescription(localizedStringDtos.asDto(attachment.getDescription())); } if (attachment.getMd5() != null) { builder.setMd5(attachment.getMd5()).setSize(attachment.getSize()); if (attachment.getLang() != null) builder.setLang(attachment.getLang().toString()); } if (attachment.getAttributes() != null) { attachment .getAttributes() .asAttributeList() .forEach(attribute -> builder.addAttributes(attributeDtos.asDto(attribute))); } if (!Strings.isNullOrEmpty(attachment.getPath())) builder.setPath(attachment.getPath()); if (attachment.hasLastModifiedBy()) builder.setLastModifiedBy(attachment.getLastModifiedBy()); return builder.build(); }