Ejemplo n.º 1
0
  @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();
  }
Ejemplo n.º 2
0
  @NotNull
  Attachment fromDto(@NotNull Mica.AttachmentDtoOrBuilder dto) {
    Attachment attachment = new Attachment();
    attachment.setId(dto.getId());
    attachment.setName(dto.getFileName());
    if (dto.hasType()) attachment.setType(dto.getType());
    if (dto.getDescriptionCount() > 0)
      attachment.setDescription(localizedStringDtos.fromDto(dto.getDescriptionList()));
    if (dto.hasLang()) attachment.setLang(new Locale(dto.getLang()));
    attachment.setSize(dto.getSize());
    if (dto.hasMd5()) attachment.setMd5(dto.getMd5());
    attachment.setJustUploaded(dto.getJustUploaded());

    if (dto.hasTimestamps()) TimestampsDtos.fromDto(dto.getTimestamps(), attachment);

    if (dto.getAttributesCount() > 0) {
      dto.getAttributesList()
          .forEach(attributeDto -> attachment.addAttribute(attributeDtos.fromDto(attributeDto)));
    }

    if (dto.hasPath()) attachment.setPath(dto.getPath());

    return attachment;
  }