@Override protected BasicFileAttributeViewDto toDto(BasicFileAttributeView src) { return new BasicFileAttributeViewDto(src); } };
public BasicFileAttributeViewDto(BasicFileAttributeView bfad) { this.setName(bfad.getName()); this.setDirectory(bfad.isDirectory()); if (null != bfad.getLastModifiedTime()) { this.setLastModifiedTime(DateConverter.getFormattedDate(bfad.getLastModifiedTime(), SystemConstants.API_DATE_FORMAT)); } this.setSize(bfad.getSize()); if (bfad instanceof RootFolderAttributeView) { this.setProtectedFolder(((RootFolderAttributeView) bfad).isProtectedFolder()); } }
@Test public void testValidRequest() throws Exception { List<BasicFileAttributeViewDto> dtos = new ArrayList<>(); BasicFileAttributeViewDto dto = new BasicFileAttributeViewDto(); dto.setName("folder"); dto.setDirectory(true); dtos.add(dto); when(fileBrowserService.browseFolder(ArgumentMatchers.anyString(), ArgumentMatchers.any())).thenReturn(dtos); UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build(); String accessToken = mockOAuthInterceptor(user); ResultActions result = mockMvc .perform(get("/fileBrowser") .contentType(MediaType.APPLICATION_JSON_VALUE) .header("Authorization", "Bearer " + accessToken)); Mockito.verify(fileBrowserService, Mockito.times(1)).browseFolder(ArgumentMatchers.anyString(), ArgumentMatchers.any()); result.andExpect(status().isOk()); result.andExpect(jsonPath("$.payload", Matchers.hasSize(1))); result.andExpect(jsonPath("$.errors", Matchers.hasSize(0))); result.andExpect(jsonPath("$.metaData.size()", is(2))); }
@Override public List<BasicFileAttributeViewDto> browseFolder(String currentPath, Boolean protectedFolder) { this.checkResource(currentPath, "Folder", protectedFolder); List<BasicFileAttributeViewDto> dtos = null; try { BasicFileAttributeView[] views = null; if (null == protectedFolder) { views = new BasicFileAttributeView[]{this.getRootFolder(false), this.getRootFolder(true)}; } else { views = this.getStorageManager().listAttributes(currentPath, protectedFolder); } dtos = this.getFileAttributeViewDtoDtoBuilder().convert(Arrays.asList(views)); dtos.stream().forEach(i -> i.buildPath(currentPath)); if (null != protectedFolder) { dtos.stream().forEach(i -> i.setProtectedFolder(protectedFolder)); } } catch (Throwable t) { logger.error("error browsing folder {} - type {}", currentPath, protectedFolder); throw new RestServerError("error browsing folder", t); } return dtos; }