Search in sources :

Example 31 with DataNode

use of org.pentaho.platform.api.repository2.unified.data.node.DataNode 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 32 with DataNode

use of org.pentaho.platform.api.repository2.unified.data.node.DataNode 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 33 with DataNode

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

the class DatabaseHelper method databaseConnectionToDataNode.

public DataNode databaseConnectionToDataNode(final IDatabaseConnection databaseConnection) {
    DataNode rootNode = new DataNode(NODE_ROOT);
    // Then the basic db information
    if (databaseConnection.getDatabaseType() != null) {
        rootNode.setProperty(PROP_TYPE, databaseConnection.getDatabaseType().getShortName());
    }
    String port = ("".equals(setNull(databaseConnection.getDatabasePort()))) ? "0" : databaseConnection.getDatabasePort();
    rootNode.setProperty(PROP_CONTYPE, setNull(databaseConnection.getAccessType().getName()));
    rootNode.setProperty(PROP_HOST_NAME, setNull(databaseConnection.getHostname()));
    rootNode.setProperty(PROP_DATABASE_NAME, setNull(databaseConnection.getDatabaseName()));
    rootNode.setProperty(PROP_PORT, new Long(port));
    rootNode.setProperty(PROP_USERNAME, setNull(databaseConnection.getUsername()));
    rootNode.setProperty(PROP_PASSWORD, encryptPassword(databaseConnection.getPassword()));
    rootNode.setProperty(PROP_SERVERNAME, setNull(databaseConnection.getInformixServername()));
    rootNode.setProperty(PROP_DATA_TBS, setNull(databaseConnection.getDataTablespace()));
    rootNode.setProperty(PROP_INDEX_TBS, setNull(databaseConnection.getIndexTablespace()));
    rootNode.setProperty(PROP_CONNECT_SQL, setNull(databaseConnection.getConnectSql()));
    rootNode.setProperty(PROP_INITIAL_POOL_SIZE, databaseConnection.getInitialPoolSize());
    rootNode.setProperty(PROP_MAX_POOL_SIZE, databaseConnection.getMaximumPoolSize());
    rootNode.setProperty(PROP_IS_POOLING, databaseConnection.isUsingConnectionPool());
    rootNode.setProperty(PROP_IS_FORCING_TO_LOWER, databaseConnection.isForcingIdentifiersToLowerCase());
    rootNode.setProperty(PROP_IS_FORCING_TO_UPPER, databaseConnection.isForcingIdentifiersToUpperCase());
    rootNode.setProperty(PROP_IS_QUOTE_FIELDS, databaseConnection.isQuoteAllFields());
    rootNode.setProperty(PROP_IS_DECIMAL_SEPERATOR, databaseConnection.isUsingDoubleDecimalAsSchemaTableSeparator());
    // Now store all the attributes set on the database connection...
    DataNode attrNode = rootNode.addNode(NODE_ATTRIBUTES);
    Map<String, String> attributes = databaseConnection.getAttributes();
    Set<String> keys = attributes.keySet();
    for (String key : keys) {
        String value = attributes.get(key);
        attrNode.setProperty(key, value);
    }
    attrNode.setProperty(ATTRIBUTE_PORT_NUMBER, new Long(port).longValue());
    // Now store the pooling parameters
    attrNode = rootNode.addNode(NODE_POOLING_PROPS);
    attributes = databaseConnection.getConnectionPoolingProperties();
    keys = attributes.keySet();
    for (String key : keys) {
        String value = attributes.get(key);
        attrNode.setProperty(key, value);
    }
    // Store the extra options
    attrNode = rootNode.addNode(NODE_EXTRA_OPTIONS);
    attributes = databaseConnection.getExtraOptions();
    for (String key : attributes.keySet()) {
        String value = attributes.get(key);
        attrNode.setProperty(key, value);
    }
    // Store the extra options order
    attrNode = rootNode.addNode(NODE_EXTRA_OPTIONS_ORDER);
    Map<String, String> extraOptionsOrder = databaseConnection.getExtraOptionsOrder();
    for (String key : extraOptionsOrder.keySet()) {
        String value = extraOptionsOrder.get(key);
        attrNode.setProperty(key, value);
    }
    return rootNode;
}
Also used : DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode)

Example 34 with DataNode

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

the class DatabaseHelper method dataNodeToDatabaseConnection.

public IDatabaseConnection dataNodeToDatabaseConnection(final Serializable id, final String name, final DataNode rootNode) {
    IDatabaseConnection databaseConnection = new DatabaseConnection();
    String databaseType = getString(rootNode, PROP_TYPE);
    databaseConnection.setDatabaseType(databaseType != null ? databaseTypeHelper.getDatabaseTypeByShortName(databaseType) : null);
    databaseConnection.setName(name);
    if (id != null) {
        databaseConnection.setId(id.toString());
    }
    String accessType = getString(rootNode, PROP_CONTYPE);
    // This is a special case with some PDI connections
    if (accessType != null && accessType.contains("Native")) {
        accessType = DatabaseAccessType.NATIVE.getName();
    } else if (accessType != null && accessType.equals(", ")) {
        accessType = DatabaseAccessType.JNDI.getName();
    }
    databaseConnection.setAccessType(accessType != null ? DatabaseAccessType.getAccessTypeByName(accessType) : null);
    databaseConnection.setHostname(getString(rootNode, PROP_HOST_NAME));
    databaseConnection.setDatabaseName(getString(rootNode, PROP_DATABASE_NAME));
    databaseConnection.setDatabasePort(getString(rootNode, PROP_PORT));
    databaseConnection.setUsername(getString(rootNode, PROP_USERNAME));
    databaseConnection.setPassword(decryptPassword(getString(rootNode, PROP_PASSWORD)));
    databaseConnection.setInformixServername(getString(rootNode, PROP_SERVERNAME));
    databaseConnection.setDataTablespace(getString(rootNode, PROP_DATA_TBS));
    databaseConnection.setIndexTablespace(getString(rootNode, PROP_INDEX_TBS));
    databaseConnection.setConnectSql(getString(rootNode, PROP_CONNECT_SQL));
    databaseConnection.setInitialPoolSize(getInt(rootNode, PROP_INITIAL_POOL_SIZE));
    databaseConnection.setMaximumPoolSize(getInt(rootNode, PROP_MAX_POOL_SIZE));
    databaseConnection.setUsingConnectionPool(getBoolean(rootNode, PROP_IS_POOLING));
    databaseConnection.setForcingIdentifiersToLowerCase(getBoolean(rootNode, PROP_IS_FORCING_TO_LOWER));
    databaseConnection.setForcingIdentifiersToUpperCase(getBoolean(rootNode, PROP_IS_FORCING_TO_UPPER));
    databaseConnection.setQuoteAllFields(getBoolean(rootNode, PROP_IS_QUOTE_FIELDS));
    databaseConnection.setUsingDoubleDecimalAsSchemaTableSeparator(getBoolean(rootNode, PROP_IS_DECIMAL_SEPERATOR));
    // Also, load all the properties we can find...
    DataNode attrNode = rootNode.getNode(NODE_ATTRIBUTES);
    if (attrNode != null) {
        for (DataProperty property : attrNode.getProperties()) {
            String code = property.getName();
            String attribute = property.getString();
            databaseConnection.getAttributes().put(code, // $NON-NLS-1$
            (attribute == null || attribute.length() == 0) ? "" : attribute);
        }
    }
    // Also, load any pooling params
    attrNode = rootNode.getNode(NODE_POOLING_PROPS);
    if (attrNode != null) {
        for (DataProperty property : attrNode.getProperties()) {
            String code = property.getName();
            String attribute = property.getString();
            databaseConnection.getConnectionPoolingProperties().put(code, // $NON-NLS-1$
            (attribute == null || attribute.length() == 0) ? "" : attribute);
        }
    }
    // Load extra options
    attrNode = rootNode.getNode(NODE_EXTRA_OPTIONS);
    if (attrNode != null) {
        for (DataProperty property : attrNode.getProperties()) {
            String code = property.getName();
            String attribute = property.getString();
            databaseConnection.getExtraOptions().put(code, // $NON-NLS-1$
            (attribute == null || attribute.length() == 0) ? "" : attribute);
        }
    }
    attrNode = rootNode.getNode(NODE_EXTRA_OPTIONS_ORDER);
    if (attrNode != null) {
        for (DataProperty property : attrNode.getProperties()) {
            String code = property.getName();
            String attribute = property.getString();
            databaseConnection.getExtraOptionsOrder().put(code, // $NON
            (attribute == null || attribute.length() == 0) ? "" : attribute);
        }
    }
    return databaseConnection;
}
Also used : DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DataProperty(org.pentaho.platform.api.repository2.unified.data.node.DataProperty) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection)

Example 35 with DataNode

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

the class DatabaseDelegateTest method testExtraOptionUnescapeWithInvalidCharInDatabaseType.

@Test
public void testExtraOptionUnescapeWithInvalidCharInDatabaseType() throws KettleException {
    DataNode mockDataNode = mock(DataNode.class);
    DataNode unescapedExtraOptions = new DataNode("options");
    unescapedExtraOptions.setProperty("EXTRA_OPTION_AS%2F400.optionExtraOption", true);
    when(mockDataNode.getNode("attributes")).thenReturn(unescapedExtraOptions);
    DatabaseMeta unescapedDbMeta = mock(DatabaseMeta.class);
    when(unescapedDbMeta.getAttributes()).thenReturn(new Properties());
    dbDelegate.dataNodeToElement(mockDataNode, unescapedDbMeta);
    assertEquals("true", unescapedDbMeta.getAttributes().getProperty("EXTRA_OPTION_AS/400.optionExtraOption"));
}
Also used : DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) Properties(java.util.Properties) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Test(org.junit.Test)

Aggregations

DataNode (org.pentaho.platform.api.repository2.unified.data.node.DataNode)63 NodeRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)22 Test (org.junit.Test)17 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)17 DataProperty (org.pentaho.platform.api.repository2.unified.data.node.DataProperty)15 DataNodeRef (org.pentaho.platform.api.repository2.unified.data.node.DataNodeRef)11 Matchers.anyString (org.mockito.Matchers.anyString)7 Date (java.util.Date)6 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)6 ArrayList (java.util.ArrayList)5 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)5 ITenant (org.pentaho.platform.api.mt.ITenant)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 NotePadMeta (org.pentaho.di.core.NotePadMeta)4 KettleException (org.pentaho.di.core.exception.KettleException)4 JobMeta (org.pentaho.di.job.JobMeta)4 JobEntryCopy (org.pentaho.di.job.entry.JobEntryCopy)4 StringObjectId (org.pentaho.di.repository.StringObjectId)4 Properties (java.util.Properties)3