Пример #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();
  }
Пример #2
0
 @NotNull
 Mica.FileDto asFileDto(AttachmentState state) {
   boolean isFolder = FileUtils.isDirectory(state);
   String name = state.getName();
   String path = String.format("%s/%s", state.getPath(), state.getName());
   if (isFolder) {
     int idx = state.getPath().lastIndexOf('/');
     name = state.getPath().substring(idx + 1);
     path = state.getPath();
   }
   Mica.FileDto.Builder builder = Mica.FileDto.newBuilder();
   return builder
       .setPath(path) //
       .setName(name) //
       .setTimestamps(TimestampsDtos.asDto(state)) //
       .setType(isFolder ? Mica.FileType.FOLDER : Mica.FileType.FILE) //
       .setSize(state.getAttachment().getSize()) //
       .setRevisionStatus(state.getRevisionStatus().name()) //
       .build();
 }
Пример #3
0
  Mica.AttachmentStateDto asDto(AttachmentState state, boolean detailed) {
    Mica.AttachmentStateDto.Builder builder = Mica.AttachmentStateDto.newBuilder();
    builder
        .setId(state.getId()) //
        .setName(state.getName()) //
        .setPath(state.getPath()) //
        .setTimestamps(TimestampsDtos.asDto(state)) //
        .setAttachment(asDto(state.getAttachment()));
    if (state.isPublished()) {
      builder
          .setPublishedId(state.getPublishedAttachment().getId()) //
          .setPublicationDate(state.getPublicationDate().toString());

      if (state.getPublishedBy() != null) builder.setPublishedBy(state.getPublishedBy());
    }
    if (detailed && !FileUtils.isDirectory(state))
      builder.addAllRevisions(
          fileSystemService
              .getAttachmentRevisions(state)
              .stream()
              .map(this::asDto)
              .collect(Collectors.toList()));
    return builder.build();
  }