Search in sources :

Example 71 with RepositoryFile

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

the class JcrBackedDatasourceMgmtServiceTest method testGetDatasources.

@Test
public void testGetDatasources() throws Exception {
    final String fileId = "456";
    final String databasesFolderPath = "/etc/pdi/databases";
    final String dotKdb = ".kdb";
    IUnifiedRepository repo = mock(IUnifiedRepository.class);
    // stub out get parent folder
    doReturn(new RepositoryFile.Builder("123", "databases").folder(true).build()).when(repo).getFile(databasesFolderPath);
    doReturn(reservedChars).when(repo).getReservedChars();
    // stub out get file to update
    RepositoryFile f = new RepositoryFile.Builder(fileId, EXP_DBMETA_NAME + dotKdb).path(databasesFolderPath + RepositoryFile.SEPARATOR + EXP_DBMETA_NAME + dotKdb).build();
    doReturn(f).when(repo).getFile(databasesFolderPath + RepositoryFile.SEPARATOR + EXP_DBMETA_NAME + dotKdb);
    final String EXP_HOST_NAME = "hello";
    DataNode rootNode = new DataNode("databaseMeta");
    // required
    rootNode.setProperty("TYPE", "Hypersonic");
    rootNode.setProperty("HOST_NAME", EXP_HOST_NAME);
    // required
    rootNode.addNode("attributes");
    doReturn(new NodeRepositoryFileData(rootNode)).when(repo).getDataForRead(eq(fileId), eq(NodeRepositoryFileData.class));
    IDatasourceMgmtService datasourceMgmtService = new JcrBackedDatasourceMgmtService(repo, new DatabaseDialectService());
    IDatabaseConnection conn = datasourceMgmtService.getDatasourceByName(EXP_DBMETA_NAME);
    assertEquals(EXP_HOST_NAME, conn.getHostname());
}
Also used : DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) DatabaseDialectService(org.pentaho.database.service.DatabaseDialectService) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Matchers.anyString(org.mockito.Matchers.anyString) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) IDatasourceMgmtService(org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService) Test(org.junit.Test)

Example 72 with RepositoryFile

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

the class DefaultUnifiedRepositoryWebServiceTest method testFileMetadata.

public void testFileMetadata() throws Exception {
    final RepositoryFile testfile = repository.createFile(repository.getFile("/etc").getId(), new RepositoryFile.Builder("testfile").build(), new SimpleRepositoryFileData(new ByteArrayInputStream("test".getBytes()), "UTF-8", "text/plain"), null);
    // CHECKSTYLE IGNORE AvoidNestedBlocks FOR NEXT 3 LINES
    {
        // Make sure the repository is setup correctly
        assertNotNull(testfile);
        assertNotNull(testfile.getId());
        final Map<String, Serializable> fileMetadata = repository.getFileMetadata(testfile.getId());
        assertNotNull(fileMetadata);
        assertEquals(0, fileMetadata.size());
    }
    final List<StringKeyStringValueDto> metadata = new ArrayList<StringKeyStringValueDto>();
    metadata.add(new StringKeyStringValueDto("sample key", "sample value"));
    metadata.add(new StringKeyStringValueDto("complex key?", "\"an even more 'complex' value\"! {and them some}"));
    repositoryWS.setFileMetadata(testfile.getId().toString(), metadata);
    // CHECKSTYLE IGNORE AvoidNestedBlocks FOR NEXT 3 LINES
    {
        // Make sure the repository sees the metadata
        assertNotNull(testfile);
        assertNotNull(testfile.getId());
        final Map<String, Serializable> fileMetadata = repository.getFileMetadata(testfile.getId());
        assertNotNull(fileMetadata);
        assertEquals(2, fileMetadata.size());
    }
    // CHECKSTYLE IGNORE AvoidNestedBlocks FOR NEXT 3 LINES
    {
        // Make sure we can get the same metadata back via the web service
        final List<StringKeyStringValueDto> fileMetadata = repositoryWS.getFileMetadata(testfile.getId().toString());
        assertNotNull(fileMetadata);
        assertEquals(2, fileMetadata.size());
        assertTrue(metadata.get(0).equals(fileMetadata.get(0)) || metadata.get(0).equals(fileMetadata.get(1)));
        assertTrue(metadata.get(1).equals(fileMetadata.get(0)) || metadata.get(1).equals(fileMetadata.get(1)));
    }
}
Also used : SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 73 with RepositoryFile

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

the class MockUnifiedRepository method createFolder.

@Override
public RepositoryFile createFolder(final Serializable parentFolderId, final RepositoryFile file, final RepositoryFileAcl acl, final String versionMessage) {
    Validate.isTrue(file.isFolder());
    Validate.isTrue(!file.isVersioned());
    if (!hasAccess(parentFolderId, EnumSet.of(WRITE))) {
        throw new AccessDeniedException("access denied");
    }
    FileRecord parentFolder = idManager.getFileById(parentFolderId);
    RepositoryFile fileFromRepo = new RepositoryFile.Builder(file).path(parentFolder.getPath() + (parentFolder.getPath().endsWith(RepositoryFile.SEPARATOR) ? "" : RepositoryFile.SEPARATOR) + file.getName()).title(findTitle(file)).description(findDesc(file)).build();
    RepositoryFileAcl aclFromRepo = new RepositoryFileAcl.Builder(acl).build();
    FileRecord fileRecord = new FileRecord(fileFromRepo, null, aclFromRepo, new HashMap<String, Serializable>());
    idManager.register(fileRecord);
    parentFolder.addChild(fileRecord);
    return fileRecord.getFile();
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) Serializable(java.io.Serializable) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)

Example 74 with RepositoryFile

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

the class MockUnifiedRepository method getTree.

@Override
public RepositoryFileTree getTree(final String path, final int depth, final String filter, final boolean showHidden) {
    FileRecord r = root.getFileRecord(path);
    RepositoryFile rootFile = r.getFile();
    if ((!showHidden && rootFile.isHidden()) || rootFile.isAclNode()) {
        return null;
    }
    List<RepositoryFileTree> children;
    if (depth != 0) {
        children = new ArrayList<RepositoryFileTree>();
        if (rootFile.isFolder()) {
            List<RepositoryFile> childrenTmp = getChildren(rootFile.getId(), filter);
            for (RepositoryFile child : childrenTmp) {
                RepositoryFileTree repositoryFileTree = getTree(child.getPath(), depth - 1, filter, showHidden);
                if (repositoryFileTree != null) {
                    children.add(repositoryFileTree);
                }
            }
        }
        Collections.sort(children);
    } else {
        children = null;
    }
    return new RepositoryFileTree(rootFile, children);
}
Also used : RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree)

Example 75 with RepositoryFile

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

the class MockUnifiedRepository method init.

protected void init() {
    RepositoryFile rootFolder = new RepositoryFile.Builder("").path(RepositoryFile.SEPARATOR).folder(true).build();
    RepositoryFileAcl rootFolderAcl = new RepositoryFileAcl.Builder(root()).entriesInheriting(false).ace(everyone(), READ).build();
    root = new FileRecord(rootFolder, rootFolderAcl);
    idManager.register(root);
    RepositoryFile publicFolder = new RepositoryFile.Builder("public").path(RepositoryFile.SEPARATOR + "public").folder(true).build();
    RepositoryFileAcl publicFolderAcl = new RepositoryFileAcl.Builder(root()).entriesInheriting(false).ace(everyone(), READ, WRITE).build();
    FileRecord pub = new FileRecord(publicFolder, publicFolderAcl);
    root.addChild(pub);
    idManager.register(pub);
    RepositoryFile etcFolder = new RepositoryFile.Builder("etc").path(RepositoryFile.SEPARATOR + "etc").folder(true).build();
    RepositoryFileAcl etcFolderAcl = new RepositoryFileAcl.Builder(root()).entriesInheriting(true).build();
    FileRecord etc = new FileRecord(etcFolder, etcFolderAcl);
    root.addChild(etc);
    idManager.register(etc);
}
Also used : RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)

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