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;
}
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());
}
Aggregations