Search in sources :

Example 76 with RepositoryFile

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)));
}
Also used : IAclNodeHelper(org.pentaho.platform.api.repository2.unified.IAclNodeHelper) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Example 77 with RepositoryFile

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");
}
Also used : Answer(org.mockito.stubbing.Answer) IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) Serializable(java.io.Serializable) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Iterator(java.util.Iterator) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 78 with RepositoryFile

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);
}
Also used : Serializable(java.io.Serializable) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Callable(java.util.concurrent.Callable) ISecurityHelper(org.pentaho.platform.api.engine.ISecurityHelper) InvocationOnMock(org.mockito.invocation.InvocationOnMock) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Before(org.junit.Before)

Example 79 with RepositoryFile

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;
}
Also used : IFileFilter(org.pentaho.platform.api.repository2.unified.IFileFilter) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IOException(java.io.IOException)

Example 80 with RepositoryFile

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;
}
Also used : SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) IOException(java.io.IOException)

Aggregations

RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)455 Test (org.junit.Test)183 ITenant (org.pentaho.platform.api.mt.ITenant)87 Matchers.anyString (org.mockito.Matchers.anyString)86 ArrayList (java.util.ArrayList)85 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)83 Serializable (java.io.Serializable)56 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)53 SimpleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData)49 KettleException (org.pentaho.di.core.exception.KettleException)40 NodeRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)40 ByteArrayInputStream (java.io.ByteArrayInputStream)39 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)39 IOException (java.io.IOException)37 File (java.io.File)34 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)34 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)33 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)33 IdNotFoundException (org.pentaho.di.core.exception.IdNotFoundException)32 KettleFileException (org.pentaho.di.core.exception.KettleFileException)32