Search in sources :

Example 26 with NodeRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData in project pentaho-platform by pentaho.

the class DefaultUnifiedRepositoryContentIT method testMissingRef.

@Test
public void testMissingRef() throws Exception {
    // if a user does not have permission to a reference, it is removed from the node structure and
    // replaced with a missing link. previous releases would throw an exception.
    // create a file that suzy does not have permission to
    // create a file that suzy has permission to but references the one she doesn't
    // load the file as suzy, make sure no exceptions occur and that the node is a missing reference
    loginAsSysTenantAdmin();
    ITenant tenantAcme = tenantManager.createTenant(systemTenant, TENANT_ID_ACME, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
    userRoleDao.createUser(tenantAcme, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
    login(USERNAME_ADMIN, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
    userRoleDao.createUser(tenantAcme, USERNAME_SUZY, PASSWORD, "", null);
    DataNode node = new DataNode("kdjd");
    RepositoryFile sampleFile = createSampleFile(ClientRepositoryPaths.getPublicFolderPath(), "helloworld2.sample", "dfdd", true, 83);
    RepositoryFileAcl acl = repo.getAcl(sampleFile.getId());
    RepositoryFileAcl newAcl = new RepositoryFileAcl.Builder(acl).entriesInheriting(false).clearAces().build();
    repo.updateAcl(newAcl);
    node.setProperty("urei2", new DataNodeRef(sampleFile.getId()));
    final String parentFolderPath = ClientRepositoryPaths.getPublicFolderPath();
    final String expectedName = "helloworld.doesnotmatter";
    RepositoryFile parentFolder = repo.getFile(parentFolderPath);
    assertNotNull(parentFolder);
    final String expectedPath = parentFolderPath + RepositoryFile.SEPARATOR + expectedName;
    NodeRepositoryFileData data = new NodeRepositoryFileData(node);
    RepositoryFile newFile = repo.createFile(parentFolder.getId(), new RepositoryFile.Builder(expectedName).build(), data, null);
    assertNotNull(newFile.getId());
    // now check that the ref is missing
    login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
    RepositoryFile foundFile = repo.getFile(expectedPath);
    assertNotNull(foundFile);
    DataNode foundNode = repo.getDataForRead(newFile.getId(), NodeRepositoryFileData.class).getNode();
    DataProperty d = foundNode.getProperty("urei2");
    assertNotNull(d);
    assertTrue(d.getType() == DataPropertyType.REF);
    assertTrue(d.getRef().getId() == DataNodeRef.REF_MISSING);
    // now change permissions back so she can get access to the node, confirm things are back to normal
    login(USERNAME_ADMIN, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
    newAcl = new RepositoryFileAcl.Builder(acl).entriesInheriting(true).clearAces().build();
    repo.updateAcl(newAcl);
    login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
    foundFile = repo.getFile(expectedPath);
    assertNotNull(foundFile);
    foundNode = repo.getDataForRead(newFile.getId(), NodeRepositoryFileData.class).getNode();
    d = foundNode.getProperty("urei2");
    assertNotNull(d);
    assertTrue(d.getType() == DataPropertyType.REF);
    assertTrue(d.getRef().getId().equals(sampleFile.getId()));
}
Also used : DataNodeRef(org.pentaho.platform.api.repository2.unified.data.node.DataNodeRef) ITenant(org.pentaho.platform.api.mt.ITenant) DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) DataProperty(org.pentaho.platform.api.repository2.unified.data.node.DataProperty) Matchers.anyString(org.mockito.Matchers.anyString) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) Test(org.junit.Test)

Example 27 with NodeRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData in project pentaho-platform by pentaho.

the class DefaultUnifiedRepositoryJaxwsWebServiceIT method makeNodeRepositoryFileData1.

private NodeRepositoryFileData makeNodeRepositoryFileData1() {
    DataNode node = new DataNode("testNode");
    node.setProperty("prop1", "hello world");
    node.setProperty("prop2", false);
    node.setProperty("prop3", 12L);
    return new NodeRepositoryFileData(node);
}
Also used : DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)

Example 28 with NodeRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData in project pentaho-platform by pentaho.

the class JcrBackedDatasourceMgmtService method updateDatasource.

private String updateDatasource(RepositoryFile file, IDatabaseConnection databaseConnection) throws NonExistingDatasourceException, DatasourceMgmtServiceException {
    try {
        if (file != null) {
            file = new RepositoryFile.Builder(file).versionId(file.getVersionId()).id(file.getId()).title(RepositoryFile.DEFAULT_LOCALE, databaseConnection.getName()).build();
            file = repository.updateFile(file, new NodeRepositoryFileData(databaseHelper.databaseConnectionToDataNode(databaseConnection)), null);
            renameIfNecessary(databaseConnection, file);
            return file.getId().toString();
        } else {
            throw new NonExistingDatasourceException(Messages.getInstance().getErrorString("DatasourceMgmtService.ERROR_0006_DATASOURCE_DOES_NOT_EXIST", // $NON-NLS-1$
            databaseConnection.getName()));
        }
    // } catch(PasswordServiceException pse) {
    // throw new DatasourceMgmtServiceException(Messages.getInstance()
    // .getErrorString("DatasourceMgmtService.ERROR_0007_UNABLE_TO_ENCRYPT_PASSWORD"), pse ); //$NON-NLS-1$
    } catch (UnifiedRepositoryException ure) {
        throw new DatasourceMgmtServiceException(Messages.getInstance().getErrorString("DatasourceMgmtService.ERROR_0003_UNABLE_TO_UPDATE_DATASOURCE", databaseConnection.getName(), ure.getLocalizedMessage()), // $NON-NLS-1$
        ure);
    }
}
Also used : NonExistingDatasourceException(org.pentaho.platform.api.repository.datasource.NonExistingDatasourceException) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)

Example 29 with NodeRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData in project pentaho-platform by pentaho.

the class JcrBackedDatasourceMgmtService method getDatasource.

private IDatabaseConnection getDatasource(RepositoryFile file) throws DatasourceMgmtServiceException {
    try {
        if (file != null) {
            NodeRepositoryFileData data = repository.getDataForRead(file.getId(), NodeRepositoryFileData.class);
            IDatabaseConnection databaseConnection = databaseHelper.dataNodeToDatabaseConnection(file.getId(), file.getTitle(), data.getNode());
            // databaseMeta.setPassword(passwordService.decrypt(databaseMeta.getPassword()));
            return databaseConnection;
        } else {
            throw new DatasourceMgmtServiceException(Messages.getInstance().getErrorString("DatasourceMgmtService.ERROR_0004_UNABLE_TO_RETRIEVE_DATASOURCE", "", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            ""));
        }
    // } catch(PasswordServiceException pse) {
    // throw new DatasourceMgmtServiceException(Messages.getInstance()
    // .getErrorString("DatasourceMgmtService.ERROR_0008_UNABLE_TO_DECRYPT_PASSWORD"), pse ); //$NON-NLS-1$
    } catch (UnifiedRepositoryException ure) {
        throw new DatasourceMgmtServiceException(Messages.getInstance().getErrorString("DatasourceMgmtService.ERROR_0004_UNABLE_TO_RETRIEVE_DATASOURCE", file.getName(), ure.getLocalizedMessage()), // $NON-NLS-1$
        ure);
    }
}
Also used : NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)

Example 30 with NodeRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData in project pentaho-kettle by pentaho.

the class PurRepository_DatabaseNames_IT method getDatabaseId_ReturnsExactMatch_PriorToCaseInsensitiveMatch.

@Test
public void getDatabaseId_ReturnsExactMatch_PriorToCaseInsensitiveMatch() throws Exception {
    final String exact = "databaseExactMatch";
    final String similar = exact.toLowerCase();
    assertNotSame(similar, exact);
    DatabaseMeta db = saveDatabase(exact);
    // simulate legacy repository - store a DB with a name different only in case
    // it became illegal to store such DB via API, thus create the file accessing UnifiedRepository directly
    DatabaseMeta another = new DatabaseMeta();
    another.setName(similar);
    final String filename = PurRepository.checkAndSanitize(RepositoryFilenameUtils.escape(similar, unifiedRepository.getReservedChars()) + RepositoryObjectType.DATABASE.getExtension());
    RepositoryFile file = new RepositoryFile.Builder(filename).title(similar).build();
    file = unifiedRepository.createFile(purRepository.getDatabaseMetaParentFolderId(), file, new NodeRepositoryFileData(new DatabaseDelegate(purRepository).elementToDataNode(another)), null);
    assertNotNull(file.getId());
    assertNotSame(file.getId().toString(), db.getObjectId().toString());
    ObjectId id = purRepository.getDatabaseID(exact);
    assertEquals(db.getObjectId(), id);
}
Also used : ObjectId(org.pentaho.di.repository.ObjectId) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Test(org.junit.Test)

Aggregations

NodeRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)46 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)36 DataNode (org.pentaho.platform.api.repository2.unified.data.node.DataNode)22 KettleException (org.pentaho.di.core.exception.KettleException)14 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)11 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)11 IdNotFoundException (org.pentaho.di.core.exception.IdNotFoundException)10 KettleFileException (org.pentaho.di.core.exception.KettleFileException)10 KettleSecurityException (org.pentaho.di.core.exception.KettleSecurityException)10 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)10 UnifiedRepositoryCreateFileException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryCreateFileException)10 UnifiedRepositoryUpdateFileException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryUpdateFileException)10 Test (org.junit.Test)9 Matchers.anyString (org.mockito.Matchers.anyString)7 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)7 ITenant (org.pentaho.platform.api.mt.ITenant)6 StringObjectId (org.pentaho.di.repository.StringObjectId)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4