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;
}
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);
}
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));
}
}
}
}
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, ""));
}
}
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;
}
Aggregations