Search in sources :

Example 41 with DataNode

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

the class JobDelegateTest method addDataProperty.

public static DataProperty addDataProperty(DataNode node, String name) {
    DataProperty dataProperty = mock(DataProperty.class);
    when(node.hasProperty(name)).thenReturn(true);
    when(node.getProperty(name)).thenReturn(dataProperty);
    return dataProperty;
}
Also used : DataProperty(org.pentaho.platform.api.repository2.unified.data.node.DataProperty)

Example 42 with DataNode

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

the class PurRepositoryMetaStoreTest method testDataNodeConversion.

@Test
public void testDataNodeConversion() throws Exception {
    IMetaStoreElement expected = new MemoryMetaStoreElement();
    expected.setName("parent");
    expected.addChild(new MemoryMetaStoreAttribute("date", new Date()));
    expected.addChild(new MemoryMetaStoreAttribute("long", 32L));
    expected.addChild(new MemoryMetaStoreAttribute("double", 3.2));
    expected.addChild(new MemoryMetaStoreAttribute("string", "value"));
    MemoryMetaStoreAttribute collection = new MemoryMetaStoreAttribute("collection", "collection-value");
    for (int i = 0; i < 10; i++) {
        collection.addChild(new MemoryMetaStoreAttribute("key-" + i, "value-" + i));
    }
    expected.addChild(collection);
    DataNode dataNode = new DataNode("test");
    metaStore.elementToDataNode(expected, dataNode);
    IMetaStoreElement verify = new MemoryMetaStoreElement();
    metaStore.dataNodeToElement(dataNode, verify);
    assertEquals(expected.getName(), verify.getName());
    validate(expected, verify);
}
Also used : MemoryMetaStoreAttribute(org.pentaho.metastore.stores.memory.MemoryMetaStoreAttribute) DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) Date(java.util.Date) MemoryMetaStoreElement(org.pentaho.metastore.stores.memory.MemoryMetaStoreElement) Test(org.junit.Test)

Example 43 with DataNode

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

the class AttributesMapUtil method saveAttributesMap.

public static final void saveAttributesMap(DataNode dataNode, AttributesInterface attributesInterface) throws KettleException {
    Map<String, Map<String, String>> attributesMap = attributesInterface.getAttributesMap();
    DataNode attributeNodes = dataNode.getNode(NODE_ATTRIBUTE_GROUPS);
    if (attributeNodes == null) {
        attributeNodes = dataNode.addNode(NODE_ATTRIBUTE_GROUPS);
    }
    for (String groupName : attributesMap.keySet()) {
        DataNode attributeNode = attributeNodes.getNode(groupName);
        if (attributeNode == null) {
            attributeNode = attributeNodes.addNode(groupName);
        }
        Map<String, String> attributes = attributesMap.get(groupName);
        for (String key : attributes.keySet()) {
            String value = attributes.get(key);
            if (key != null && value != null) {
                attributeNode.setProperty(key, attributes.get(key));
            }
        }
    }
}
Also used : DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) Map(java.util.Map) HashMap(java.util.HashMap)

Example 44 with DataNode

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

the class DatabaseDelegate method dataNodeToElement.

public void dataNodeToElement(final DataNode rootNode, final RepositoryElementInterface element) throws KettleException {
    DatabaseMeta databaseMeta = (DatabaseMeta) element;
    databaseMeta.setDatabaseType(getString(rootNode, PROP_TYPE));
    databaseMeta.setAccessType(DatabaseMeta.getAccessType(getString(rootNode, PROP_CONTYPE)));
    databaseMeta.setHostname(getString(rootNode, PROP_HOST_NAME));
    databaseMeta.setDBName(getString(rootNode, PROP_DATABASE_NAME));
    databaseMeta.setDBPort(getString(rootNode, PROP_PORT));
    databaseMeta.setUsername(getString(rootNode, PROP_USERNAME));
    databaseMeta.setPassword(Encr.decryptPasswordOptionallyEncrypted(getString(rootNode, PROP_PASSWORD)));
    databaseMeta.setServername(getString(rootNode, PROP_SERVERNAME));
    databaseMeta.setDataTablespace(getString(rootNode, PROP_DATA_TBS));
    databaseMeta.setIndexTablespace(getString(rootNode, PROP_INDEX_TBS));
    // Also, load all the properties we can find...
    DataNode attrNode = rootNode.getNode(NODE_ATTRIBUTES);
    for (DataProperty property : attrNode.getProperties()) {
        String code = property.getName();
        String attribute = property.getString();
        // We need to unescape the code as it was escaped to handle characters that JCR does not handle
        String unescapeCode = RepositoryFilenameUtils.unescape(code);
        // $NON-NLS-1$
        databaseMeta.getAttributes().put(unescapeCode, Const.NVL(attribute, ""));
    }
}
Also used : DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) DataProperty(org.pentaho.platform.api.repository2.unified.data.node.DataProperty) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta)

Example 45 with DataNode

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

the class DatabaseDelegate method elementToDataNode.

// ~ Methods =========================================================================================================
public DataNode elementToDataNode(final RepositoryElementInterface element) throws KettleException {
    DatabaseMeta databaseMeta = (DatabaseMeta) element;
    DataNode rootNode = new DataNode(NODE_ROOT);
    // Then the basic db information
    // 
    rootNode.setProperty(PROP_TYPE, databaseMeta.getPluginId());
    rootNode.setProperty(PROP_CONTYPE, DatabaseMeta.getAccessTypeDesc(databaseMeta.getAccessType()));
    rootNode.setProperty(PROP_HOST_NAME, databaseMeta.getHostname());
    rootNode.setProperty(PROP_DATABASE_NAME, databaseMeta.getDatabaseName());
    rootNode.setProperty(PROP_PORT, new Long(Const.toInt(databaseMeta.getDatabasePortNumberString(), -1)));
    rootNode.setProperty(PROP_USERNAME, databaseMeta.getUsername());
    rootNode.setProperty(PROP_PASSWORD, Encr.encryptPasswordIfNotUsingVariables(databaseMeta.getPassword()));
    rootNode.setProperty(PROP_SERVERNAME, databaseMeta.getServername());
    rootNode.setProperty(PROP_DATA_TBS, databaseMeta.getDataTablespace());
    rootNode.setProperty(PROP_INDEX_TBS, databaseMeta.getIndexTablespace());
    DataNode attrNode = rootNode.addNode(NODE_ATTRIBUTES);
    // Now store all the attributes set on the database connection...
    // 
    Properties attributes = databaseMeta.getAttributes();
    Enumeration<Object> keys = databaseMeta.getAttributes().keys();
    while (keys.hasMoreElements()) {
        String code = (String) keys.nextElement();
        String attribute = (String) attributes.get(code);
        // Save this attribute
        // 
        // Escape the code as it might contain invalid JCR characters like '/' as in AS/400
        String escapedCode = RepositoryFilenameUtils.escape(code, repo.getUnderlyingRepository().getReservedChars());
        attrNode.setProperty(escapedCode, attribute);
    }
    return rootNode;
}
Also used : DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) Properties(java.util.Properties) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta)

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