use of org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileService method doGetFileAcl.
/**
* Retrieves the acls of the selected repository file
*
* @param pathId (colon separated path for the repository file)
* @return <code> RepositoryFileAclDto </code>
*/
public RepositoryFileAclDto doGetFileAcl(String pathId) {
RepositoryFileDto file = getRepoWs().getFile(FileUtils.idToPath(pathId));
RepositoryFileAclDto fileAcl = getRepoWs().getAcl(file.getId());
if (fileAcl.isEntriesInheriting()) {
List<RepositoryFileAclAceDto> aces = getRepoWs().getEffectiveAcesWithForceFlag(file.getId(), fileAcl.isEntriesInheriting());
fileAcl.setAces(aces, fileAcl.isEntriesInheriting());
}
addAdminRole(fileAcl);
return fileAcl;
}
use of org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileService method doCreateDirFor.
private boolean doCreateDirFor(String pathWithSlashes) {
// $NON-NLS-1$//$NON-NLS-2$
String[] folders = pathWithSlashes.split("[" + FileUtils.PATH_SEPARATOR + "]");
RepositoryFileDto parentDir = getRepoWs().getFile(FileUtils.PATH_SEPARATOR);
boolean dirCreated = false;
for (String folder : folders) {
String currentFolderPath = (parentDir.getPath() + FileUtils.PATH_SEPARATOR + folder).substring(1);
if (!currentFolderPath.startsWith(FileUtils.PATH_SEPARATOR)) {
currentFolderPath = FileUtils.PATH_SEPARATOR + currentFolderPath;
}
RepositoryFileDto currentFolder = getRepoWs().getFile(currentFolderPath);
if (currentFolder == null) {
currentFolder = new RepositoryFileDto();
currentFolder.setFolder(true);
currentFolder.setName(decode(folder));
currentFolder.setPath(parentDir.getPath() + FileUtils.PATH_SEPARATOR + folder);
currentFolder = getRepoWs().createFolder(parentDir.getId(), currentFolder, currentFolderPath);
dirCreated = true;
}
parentDir = currentFolder;
}
return dirCreated;
}
use of org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileServiceTest method testSetFileAcls.
@Test
public void testSetFileAcls() throws Exception {
RepositoryFileDto file = mock(RepositoryFileDto.class);
doReturn("file.txt").when(file).getName();
when(fileService.defaultUnifiedRepositoryWebService.getFile(anyString())).thenReturn(file);
String pathId = "/usr/folder/file.txt";
RepositoryFileAclDto acl = mock(RepositoryFileAclDto.class);
fileService.setFileAcls(pathId, acl);
verify(acl, times(1)).setId(anyString());
verify(file, times(1)).getId();
verify(fileService.defaultUnifiedRepositoryWebService, times(1)).updateAcl(acl);
}
use of org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileServiceTest method getMockedRepositoryFileDtoList.
public List<RepositoryFileDto> getMockedRepositoryFileDtoList(String[] fileNames) {
List<RepositoryFileDto> repoFileDtoList = new ArrayList<>();
for (String fileName : fileNames) {
RepositoryFileDto repoFileDto = mock(RepositoryFileDto.class);
when(repoFileDto.getName()).thenReturn(fileName);
when(repoFileDto.getId()).thenReturn(fileName);
repoFileDtoList.add(repoFileDto);
}
return repoFileDtoList;
}
use of org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileServiceTest method testSearchGeneratedContent.
@Test
public void testSearchGeneratedContent() {
String lineageId = "test.prpt", pathId = "test.prpt", userFolder = "public/admin";
RepositoryFileDto fileDetailsMock = mock(RepositoryFileDto.class);
RepositoryFile workspaceFolder = mock(RepositoryFile.class);
doReturn(userFolder).when(workspaceFolder).getId();
SessionResource sessionResource = mock(SessionResource.class);
List<RepositoryFile> children = new ArrayList<RepositoryFile>();
RepositoryFile mockedChild = mock(RepositoryFile.class);
doReturn(false).when(mockedChild).isFolder();
children.add(mockedChild);
Map<String, Serializable> mockedFileMetadata = mock(Map.class);
doReturn(lineageId).when(mockedFileMetadata).get(QuartzScheduler.RESERVEDMAPKEY_LINEAGE_ID);
when(fileService.repository.getFileMetadata(mockedChild.getId())).thenReturn(mockedFileMetadata);
doReturn(pathId).when(fileDetailsMock).getId();
doReturn(userFolder).when(sessionResource).doGetCurrentUserDir();
doReturn(workspaceFolder).when(fileService.repository).getFile(userFolder);
doReturn(sessionResource).when(fileService).getSessionResource();
doReturn(children).when(fileService.repository).getChildren(userFolder);
RepositoryFileDto mockedRepositoryFileDto = mock(RepositoryFileDto.class);
doReturn(mockedRepositoryFileDto).when(fileService).toFileDto(mockedChild, null, false);
try {
doReturn(fileDetailsMock).when(fileService).doGetProperties(pathId);
List<RepositoryFileDto> list = fileService.searchGeneratedContent(userFolder, lineageId, QuartzScheduler.RESERVEDMAPKEY_LINEAGE_ID);
assertEquals(list.size(), 1);
} catch (FileNotFoundException e) {
e.printStackTrace();
fail();
} catch (Throwable t) {
fail();
}
}
Aggregations