@NotNull Mica.FileDto asFileDto(AttachmentState state, boolean publishedFileSystem, boolean detailed) { Mica.FileDto.Builder builder = asFileDto(state).toBuilder(); if (publishedFileSystem) { builder.clearRevisionStatus(); if (state.isPublished()) { builder.setAttachment(asDto(state.getPublishedAttachment())); } } else { builder.setState(asDto(state, detailed)); builder.setPermissions(permissionsDtos.asDto(state)); } if (builder.getType() == Mica.FileType.FOLDER) { // get the number of files in the folder builder.setSize( fileSystemService.countAttachmentStates(state.getPath(), publishedFileSystem)); } return builder.build(); }
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(); }
@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(); }