Search in sources :

Example 41 with RepositoryFileDto

use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.

the class FileServiceTest method testGetDefaultLocation_Scenario_ProvidedFolderIsVisible.

@Test
public void testGetDefaultLocation_Scenario_ProvidedFolderIsVisible() throws Exception {
    RepositoryFileDto visibleDto = new RepositoryFileDto();
    visibleDto.setFolder(true);
    visibleDto.setHidden(false);
    visibleDto.setId(RandomStringUtils.randomNumeric(20));
    visibleDto.setName("joe");
    visibleDto.setPath("/home/joe");
    RepositoryFileDto homeFolderDto = new RepositoryFileDto();
    homeFolderDto.setFolder(true);
    homeFolderDto.setHidden(false);
    homeFolderDto.setId(RandomStringUtils.randomNumeric(20));
    homeFolderDto.setName("home");
    homeFolderDto.setPath("/home");
    DefaultUnifiedRepositoryWebService repoWs = mock(DefaultUnifiedRepositoryWebService.class);
    doReturn(repoWs).when(fileService).getRepoWs();
    doReturn(visibleDto).when(repoWs).getFile("/home/joe");
    doReturn(homeFolderDto).when(repoWs).getFile("/home");
    assertEquals("/home/joe", fileService.doGetDefaultLocation(":home:joe"));
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) DefaultUnifiedRepositoryWebService(org.pentaho.platform.repository2.unified.webservices.DefaultUnifiedRepositoryWebService) Test(org.junit.Test)

Example 42 with RepositoryFileDto

use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.

the class FileServiceTest method testGetDefaultLocation_Scenario_DefaultFolderIsVisible.

@Test
public void testGetDefaultLocation_Scenario_DefaultFolderIsVisible() throws Exception {
    RepositoryFileDto hiddenDto = new RepositoryFileDto();
    hiddenDto.setFolder(true);
    hiddenDto.setHidden(true);
    hiddenDto.setId(RandomStringUtils.randomNumeric(20));
    hiddenDto.setName("suzy");
    hiddenDto.setPath("/home/suzy");
    RepositoryFileDto defaultDto = new RepositoryFileDto();
    defaultDto.setFolder(true);
    defaultDto.setHidden(false);
    defaultDto.setId(RandomStringUtils.randomNumeric(20));
    defaultDto.setName("default");
    defaultDto.setPath("/default-folder");
    DefaultUnifiedRepositoryWebService repoWs = mock(DefaultUnifiedRepositoryWebService.class);
    doReturn(repoWs).when(fileService).getRepoWs();
    doReturn(hiddenDto).when(repoWs).getFile("/home/suzy");
    when(PentahoSystem.get(ISystemConfig.class).getProperty(eq(PentahoSystem.DEFAULT_FOLDER_WHEN_HOME_FOLDER_IS_HIDDEN_PROPERTY))).thenReturn("/default-folder");
    doReturn(defaultDto).when(repoWs).getFile("/default-folder");
    assertEquals("/default-folder", fileService.doGetDefaultLocation(":home:suzy"));
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) DefaultUnifiedRepositoryWebService(org.pentaho.platform.repository2.unified.webservices.DefaultUnifiedRepositoryWebService) ISystemConfig(org.pentaho.platform.api.engine.ISystemConfig) Test(org.junit.Test)

Example 43 with RepositoryFileDto

use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.

the class FileService method doCreateDirFor.

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;
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto)

Example 44 with RepositoryFileDto

use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.

the class FileService method doGetLocaleProperties.

/**
 * Retrieve the list of locale properties for a given locale
 *
 * @param pathId (colon separated path for the repository file)
 * @param locale
 * @return
 */
public List<StringKeyStringValueDto> doGetLocaleProperties(String pathId, String locale) {
    RepositoryFileDto file = getRepoWs().getFile(idToPath(pathId));
    List<StringKeyStringValueDto> keyValueList = new ArrayList<StringKeyStringValueDto>();
    if (file != null) {
        PropertiesWrapper propertiesWrapper = getRepoWs().getLocalePropertiesForFileById(file.getId(), locale);
        if (propertiesWrapper != null) {
            Properties properties = propertiesWrapper.getProperties();
            if (properties != null && !properties.isEmpty()) {
                for (String key : properties.stringPropertyNames()) {
                    keyValueList.add(getStringKeyStringValueDto(key, properties.getProperty(key)));
                }
            }
        }
    }
    return keyValueList;
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) StringKeyStringValueDto(org.pentaho.platform.api.repository2.unified.webservices.StringKeyStringValueDto) ArrayList(java.util.ArrayList) PropertiesWrapper(org.pentaho.platform.repository2.unified.webservices.PropertiesWrapper) Properties(java.util.Properties)

Example 45 with RepositoryFileDto

use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.

the class FileService method getRepositoryRequest.

protected RepositoryRequest getRepositoryRequest(RepositoryFileDto repositoryFileDto, Boolean showHidden, String filter, Boolean includeAcls) {
    RepositoryRequest repositoryRequest = new RepositoryRequest(repositoryFileDto.getId(), showHidden, 0, filter);
    repositoryRequest.setIncludeAcls(includeAcls);
    return repositoryRequest;
}
Also used : RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest)

Aggregations

Test (org.junit.Test)77 RepositoryFileDto (org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto)77 FileNotFoundException (java.io.FileNotFoundException)35 ArrayList (java.util.ArrayList)34 RepositoryFileDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto)29 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)27 Serializable (java.io.Serializable)26 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)26 Matchers.anyString (org.mockito.Matchers.anyString)25 GeneralSecurityException (java.security.GeneralSecurityException)14 StringKeyStringValueDto (org.pentaho.platform.api.repository2.unified.webservices.StringKeyStringValueDto)11 IllegalSelectorException (java.nio.channels.IllegalSelectorException)9 InvalidParameterException (java.security.InvalidParameterException)9 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)9 Properties (java.util.Properties)8 UnifiedRepositoryAccessDeniedException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException)8 DefaultUnifiedRepositoryWebService (org.pentaho.platform.repository2.unified.webservices.DefaultUnifiedRepositoryWebService)8 IOException (java.io.IOException)7 IRepositoryFileData (org.pentaho.platform.api.repository2.unified.IRepositoryFileData)7 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)7