예제 #1
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();
 }
예제 #2
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();
  }