Search in sources :

Example 1 with PropertiesWrapper

use of org.pentaho.platform.repository2.unified.webservices.PropertiesWrapper 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.repository2.unified.webservices.RepositoryFileDto) StringKeyStringValueDto(org.pentaho.platform.repository2.unified.webservices.StringKeyStringValueDto) ArrayList(java.util.ArrayList) PropertiesWrapper(org.pentaho.platform.repository2.unified.webservices.PropertiesWrapper) Properties(java.util.Properties)

Example 2 with PropertiesWrapper

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

the class FileServiceTest method testDoGetLocalProperties.

@Test
public void testDoGetLocalProperties() throws Exception {
    String pathId = "path:to:file:file1.ext";
    String fileId = "file1";
    String locale = "";
    doReturn("/path/to/file/file1.ext").when(fileService).idToPath(pathId);
    Set<String> propertiesList = new HashSet<String>();
    propertiesList.add("prop1");
    propertiesList.add("prop2");
    RepositoryFileDto repositoryFileDto = mock(RepositoryFileDto.class);
    doReturn(fileId).when(repositoryFileDto).getId();
    doReturn(repositoryFileDto).when(fileService.defaultUnifiedRepositoryWebService).getFile(anyString());
    Properties properties = mock(Properties.class);
    doReturn("value1").when(properties).getProperty("prop1");
    doReturn("value2").when(properties).getProperty("prop2");
    doReturn(false).when(properties).isEmpty();
    doReturn(propertiesList).when(properties).stringPropertyNames();
    PropertiesWrapper propertiesWrapper = mock(PropertiesWrapper.class);
    when(propertiesWrapper.getProperties()).thenReturn(properties);
    doReturn(propertiesWrapper).when(fileService.defaultUnifiedRepositoryWebService).getLocalePropertiesForFileById(anyString(), anyString());
    List<StringKeyStringValueDto> keyValueList = fileService.doGetLocaleProperties(pathId, locale);
    verify(fileService.defaultUnifiedRepositoryWebService).getFile("/path/to/file/file1.ext");
    verify(properties).getProperty("prop1");
    verify(properties).getProperty("prop2");
    verify(properties).isEmpty();
    verify(properties).stringPropertyNames();
    verify(fileService.defaultUnifiedRepositoryWebService).getLocalePropertiesForFileById(anyString(), anyString());
    assertEquals(2, keyValueList.size());
    assertEquals("prop1", keyValueList.get(1).getKey());
    assertEquals("prop2", keyValueList.get(0).getKey());
    assertEquals("value1", keyValueList.get(1).getValue());
    assertEquals("value2", keyValueList.get(0).getValue());
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) StringKeyStringValueDto(org.pentaho.platform.repository2.unified.webservices.StringKeyStringValueDto) Matchers.anyString(org.mockito.Matchers.anyString) Properties(java.util.Properties) PropertiesWrapper(org.pentaho.platform.repository2.unified.webservices.PropertiesWrapper) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Properties (java.util.Properties)2 PropertiesWrapper (org.pentaho.platform.repository2.unified.webservices.PropertiesWrapper)2 RepositoryFileDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto)2 StringKeyStringValueDto (org.pentaho.platform.repository2.unified.webservices.StringKeyStringValueDto)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1