use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.
the class SolutionRepositoryVfsFileObjectTest method initFileTest.
@Test
public void initFileTest() throws Exception {
String fileRef = "/etc/mondrian/SteelWheels/schema.xml";
String dsRef = "/etc/mondrian/SteelWheels";
SolutionRepositoryVfsFileObject fileObject = new SolutionRepositoryVfsFileObject(fileRef);
SolutionRepositoryVfsFileObject fileObjectSpy = spy(fileObject);
IAclNodeHelper aclNodeHelper = mock(IAclNodeHelper.class);
doReturn(aclNodeHelper).when(fileObjectSpy).getAclHelper();
RepositoryFile file = mock(RepositoryFile.class);
doReturn(true).when(aclNodeHelper).canAccess(file, EnumSet.of(RepositoryFilePermission.READ));
IUnifiedRepository repository = mock(IUnifiedRepository.class);
doReturn(file).when(repository).getFile(fileRef);
doReturn(repository).when(fileObjectSpy).getRepository();
fileObjectSpy.getName();
verify(repository, times(1)).getFile(eq(dsRef));
verify(repository, times(1)).getFile(eq(fileRef));
verify(aclNodeHelper, times(1)).canAccess(any(RepositoryFile.class), eq(EnumSet.of(RepositoryFilePermission.READ)));
fileRef = "/etca/mondriana/SteelWheels/schema.xml";
fileObject = new SolutionRepositoryVfsFileObject(fileRef);
fileObjectSpy = spy(fileObject);
doReturn(aclNodeHelper).when(fileObjectSpy).getAclHelper();
doReturn(false).when(aclNodeHelper).canAccess(file, EnumSet.of(RepositoryFilePermission.READ));
doReturn(repository).when(fileObjectSpy).getRepository();
fileObjectSpy.getName();
verify(repository, times(2)).getFile(eq(fileRef));
verify(aclNodeHelper, times(2)).canAccess(any(RepositoryFile.class), eq(EnumSet.of(RepositoryFilePermission.READ)));
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.
the class UserSettingServiceTest method testDeleteUserSettingsByName.
@Test
public void testDeleteUserSettingsByName() throws Exception {
IAuthorizationPolicy policy = mock(IAuthorizationPolicy.class);
when(policy.isAllowed(anyString())).thenReturn(true);
PentahoSystem.registerObject(policy);
final RepositoryFile repositoryFile = mock(RepositoryFile.class);
when(repositoryFile.getId()).thenReturn(USER_FOLDER_ID);
when(repository.getFile(anyString())).thenReturn(repositoryFile);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
final Map<String, Serializable> settings = (Map<String, Serializable>) invocation.getArguments()[1];
assertNotNull(settings);
assertEquals(2, settings.size());
final Iterator<String> iterator = settings.keySet().iterator();
assertFalse(iterator.next().startsWith(UserSettingService.SETTING_PREFIX));
assertFalse(iterator.next().startsWith(UserSettingService.SETTING_PREFIX));
return null;
}
}).when(repository).setFileMetadata(eq(USER_FOLDER_ID), anyMap());
userSettingService.deleteUserSettings("test");
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.
the class UserSettingServiceTest method setUp.
@Before
public void setUp() throws Exception {
repository = mock(IUnifiedRepository.class);
session = mock(IPentahoSession.class);
when(session.getName()).thenReturn("test");
PentahoSessionHolder.setSession(session);
userSettings = new HashMap<String, Serializable>() {
{
put(USER_SETTING_NAME_1, USER_SETTING_VALUE_1);
put(UserSettingService.SETTING_PREFIX + COMMON_SETTING_NAME, COMMON_USER_SETTING_VALUE);
put(USER_SETTING_NAME_2, USER_SETTING_VALUE_2);
put(UserSettingService.SETTING_PREFIX + USER_SETTING_NAME_3, USER_SETTING_VALUE_3);
}
};
globalSettings = new HashMap<String, Serializable>() {
{
put(GLOBAL_SETTING_NAME_1, GLOBAL_SETTING_VALUE_1);
put(UserSettingService.SETTING_PREFIX + COMMON_SETTING_NAME, COMMON_GLOBAL_SETTING_VALUE);
put(GLOBAL_SETTING_NAME_2, GLOBAL_SETTING_VALUE_2);
put(UserSettingService.SETTING_PREFIX + GLOBAL_SETTING_NAME_3, GLOBAL_SETTING_VALUE_3);
}
};
when(repository.getFileMetadata(eq(USER_FOLDER_ID))).thenReturn(userSettings);
when(repository.getFileMetadata(eq(TENANT_FOLDER_ID))).thenReturn(globalSettings);
final RepositoryFile tenantRepositoryFile = mock(RepositoryFile.class);
when(tenantRepositoryFile.getId()).thenReturn(TENANT_FOLDER_ID);
when(repository.getFile(eq(ClientRepositoryPaths.getEtcFolderPath()))).thenReturn(tenantRepositoryFile);
final RepositoryFile userRepositoryFile = mock(RepositoryFile.class);
when(userRepositoryFile.getId()).thenReturn(USER_FOLDER_ID);
when(repository.getFile(eq(ClientRepositoryPaths.getUserHomeFolderPath(session.getName())))).thenReturn(userRepositoryFile);
securityHelper = mock(ISecurityHelper.class);
when(securityHelper.runAsSystem(any(Callable.class))).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
final Callable callable = (Callable) invocation.getArguments()[0];
if (callable != null) {
return callable.call();
}
return null;
}
});
SecurityHelper.setMockInstance(securityHelper);
userSettingService = new UserSettingServiceForTesting(repository);
userSettingService.init(session);
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.
the class ActionSequenceJCRHelper method getLocaleString.
protected String getLocaleString(final String key, String baseName, final RepositoryFile baseFile, boolean marchUpParents) {
String parentPath = FilenameUtils.getFullPathNoEndSeparator(baseFile.getPath());
RepositoryFile searchDir = repository.getFile(parentPath);
if (baseFile.isFolder()) {
searchDir = baseFile;
}
try {
boolean searching = true;
while (searching) {
RepositoryFile[] propertyFiles = listFiles(searchDir, new IFileFilter() {
public boolean accept(RepositoryFile file) {
return file.getName().toLowerCase().endsWith(PROPERTIES_SUFFIX);
}
});
RepositoryFile blcv = null;
RepositoryFile blc = null;
RepositoryFile bl = null;
RepositoryFile b = null;
for (RepositoryFile element : propertyFiles) {
if (element.getName().equalsIgnoreCase(baseName + '_' + getLocale().getLanguage() + '_' + getLocale().getCountry() + '_' + getLocale().getVariant() + PROPERTIES_SUFFIX)) {
blcv = element;
}
if (element.getName().equalsIgnoreCase(baseName + '_' + getLocale().getLanguage() + '_' + getLocale().getCountry() + PROPERTIES_SUFFIX)) {
blc = element;
}
if (element.getName().equalsIgnoreCase(baseName + '_' + getLocale().getLanguage() + PROPERTIES_SUFFIX)) {
bl = element;
}
if (element.getName().equalsIgnoreCase(baseName + PROPERTIES_SUFFIX)) {
b = element;
}
}
String localeText = getLocaleText(key, blcv);
if (localeText == null) {
localeText = getLocaleText(key, blc);
if (localeText == null) {
localeText = getLocaleText(key, bl);
if (localeText == null) {
localeText = getLocaleText(key, b);
}
}
}
if (localeText != null) {
return localeText;
}
if (searching && marchUpParents) {
if (!baseName.equals("messages")) {
// $NON-NLS-1$
// $NON-NLS-1$
baseName = "messages";
} else {
parentPath = FilenameUtils.getFullPathNoEndSeparator(searchDir.getPath());
// If the parent path is empty or the same as the parent's parent path (meaning root)
if (parentPath == null || parentPath.length() < 1 || parentPath.equals(searchDir.getPath())) {
searching = false;
} else {
searchDir = repository.getFile(parentPath);
}
}
} else if (!marchUpParents) {
searching = false;
}
}
return null;
} catch (Exception e) {
logger.error(Messages.getInstance().getErrorString("ActionSequenceJCRHelper.ERROR_0007_COULD_NOT_READ_PROPERTIES", baseFile.getPath()), // $NON-NLS-1$
e);
}
return null;
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.
the class PentahoMetadataDomainRepository method loadAnnotationsXml.
@Override
public String loadAnnotationsXml(final String domainId) {
if (StringUtils.isBlank(domainId)) {
// exit early
return null;
}
try {
final RepositoryFile domainFile = getMetadataRepositoryFile(domainId);
final RepositoryFile annotationFile = getRepository().getFile(resolveAnnotationsFilePath(domainFile));
// Load referenced annotations xml repo file
SimpleRepositoryFileData data = getRepository().getDataForRead(annotationFile.getId(), SimpleRepositoryFileData.class);
// return as String
return IOUtils.toString(data.getInputStream());
} catch (Exception e) {
getLogger().warn("Unable to load annotations xml file for domain: " + domainId);
}
return null;
}
Aggregations