001package co.codewizards.cloudstore.client; 002 003import static java.util.Objects.*; 004 005import co.codewizards.cloudstore.core.dto.DateTime; 006import co.codewizards.cloudstore.core.oio.File; 007import co.codewizards.cloudstore.core.util.HashUtil; 008import co.codewizards.cloudstore.ls.core.dto.RemoteRepositoryDto; 009import co.codewizards.cloudstore.ls.core.dto.RemoteRepositoryRequestDto; 010import co.codewizards.cloudstore.ls.core.dto.RepoInfoRequestDto; 011import co.codewizards.cloudstore.ls.core.dto.RepoInfoResponseDto; 012import co.codewizards.cloudstore.ls.rest.client.request.RepoInfoRequest; 013 014/** 015 * {@link SubCommand} implementation for showing information about a repository in the local file system. 016 * 017 * @author Marco หงุ่ยตระกูล-Schulze - marco at nightlabs dot de 018 */ 019public class RepoInfoSubCommand extends SubCommandWithExistingLocalRepo 020{ 021 public RepoInfoSubCommand() { } 022 023 protected RepoInfoSubCommand(final File localRoot) { 024 this.localRoot = requireNonNull(localRoot, "localRoot"); 025 this.localFile = this.localRoot; 026 this.local = localRoot.getPath(); 027 } 028 029 @Override 030 public String getSubCommandDescription() { 031 return "Show information about an existing repository."; 032 } 033 034 @Override 035 public void run() throws Exception { 036 final RepoInfoRequestDto repoInfoRequestDto = new RepoInfoRequestDto(); 037 repoInfoRequestDto.setLocalRoot(localRoot.getAbsolutePath()); 038 final RepoInfoResponseDto repoInfoResponseDto = getLocalServerRestClient().execute(new RepoInfoRequest(repoInfoRequestDto)); 039 040 showMainProperties(repoInfoResponseDto); 041 showRemoteRepositories(repoInfoResponseDto); 042 showRemoteRepositoryRequests(repoInfoResponseDto); 043 showRepositoryStats(repoInfoResponseDto); 044 } 045 046 private void showMainProperties(final RepoInfoResponseDto repoInfoResponseDto) { 047 System.out.println("Local repository:"); 048 System.out.println(" repository.repositoryId = " + repoInfoResponseDto.getRepositoryId()); 049 System.out.println(" repository.localRoot = " + repoInfoResponseDto.getLocalRoot()); 050 System.out.println(" repository.aliases = " + repoInfoResponseDto); 051 System.out.println(" repository.publicKeySha1 = " + HashUtil.sha1ForHuman(repoInfoResponseDto.getPublicKey())); 052 System.out.println(); 053 } 054 055 private void showRemoteRepositories(final RepoInfoResponseDto repoInfoResponseDto) { 056 if (repoInfoResponseDto.getRemoteRepositoryDtos().isEmpty()) { 057 System.out.println("Remote repositories connected: {NONE}"); 058 System.out.println(); 059 } 060 else { 061 System.out.println("Remote repositories connected:"); 062 for (final RemoteRepositoryDto remoteRepositoryDto : repoInfoResponseDto.getRemoteRepositoryDtos()) { 063 System.out.println(" * remoteRepository.repositoryId = " + remoteRepositoryDto.getRepositoryId()); 064 if (remoteRepositoryDto.getRemoteRoot() != null) 065 System.out.println(" remoteRepository.remoteRoot = " + remoteRepositoryDto.getRemoteRoot()); 066 067 System.out.println(" remoteRepository.publicKeySha1 = " + HashUtil.sha1ForHuman(remoteRepositoryDto.getPublicKey())); 068 System.out.println(); 069 } 070 } 071 } 072 073 private void showRemoteRepositoryRequests(final RepoInfoResponseDto repoInfoResponseDto) { 074 if (repoInfoResponseDto.getRemoteRepositoryRequestDtos().isEmpty()) { 075 System.out.println("Remote repositories requesting connection: {NONE}"); 076 System.out.println(); 077 } 078 else { 079 System.out.println("Remote repositories requesting connection:"); 080 for (final RemoteRepositoryRequestDto remoteRepositoryRequestDto : repoInfoResponseDto.getRemoteRepositoryRequestDtos()) { 081 System.out.println(" * remoteRepositoryRequest.repositoryId = " + remoteRepositoryRequestDto.getRepositoryId()); 082 System.out.println(" remoteRepositoryRequest.publicKeySha1 = " + HashUtil.sha1ForHuman(remoteRepositoryRequestDto.getPublicKey())); 083 System.out.println(" remoteRepositoryRequest.created = " + new DateTime(remoteRepositoryRequestDto.getCreated())); 084 System.out.println(" remoteRepositoryRequest.changed = " + new DateTime(remoteRepositoryRequestDto.getChanged())); 085 System.out.println(); 086 } 087 } 088 } 089 090 private void showRepositoryStats(final RepoInfoResponseDto repoInfoResponseDto) { 091 System.out.println("Statistics:"); 092 System.out.println(" * Count(NormalFile): " + repoInfoResponseDto.getNormalFileCount()); 093 System.out.println(" * Count(Directory): " + repoInfoResponseDto.getDirectoryCount()); 094 System.out.println(" * Count(CopyModification): " + repoInfoResponseDto.getCopyModificationCount()); 095 System.out.println(" * Count(DeleteModification): " + repoInfoResponseDto.getDeleteModificationCount()); 096 System.out.println(); 097 } 098}