Search in sources :

Example 61 with DataNode

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

the class NodeRepositoryFileDataTransformer method internalRead.

protected DataNode internalRead(final Session session, final PentahoJcrConstants pentahoJcrConstants, final Node jcrNode, final DataNode parentDataNode) throws RepositoryException {
    // $NON-NLS-1$
    final String prefix = session.getNamespacePrefix(PentahoJcrConstants.PHO_NS) + ":";
    // $NON-NLS-1$
    final String pattern = prefix + "*";
    String nodeName = JcrStringHelper.fileNameDecode(jcrNode.getName().substring(prefix.length()));
    DataNode dataNode = parentDataNode != null ? parentDataNode.addNode(nodeName) : new DataNode(nodeName);
    dataNode.setId(jcrNode.getIdentifier());
    PropertyIterator props = jcrNode.getProperties(pattern);
    while (props.hasNext()) {
        Property prop = props.nextProperty();
        String propName = JcrStringHelper.fileNameDecode(prop.getName().substring(prefix.length()));
        switch(prop.getType()) {
            case PropertyType.STRING:
                {
                    dataNode.setProperty(propName, prop.getString());
                    break;
                }
            case PropertyType.BOOLEAN:
                {
                    dataNode.setProperty(propName, prop.getBoolean());
                    break;
                }
            case PropertyType.DOUBLE:
                {
                    dataNode.setProperty(propName, prop.getDouble());
                    break;
                }
            case PropertyType.LONG:
                {
                    dataNode.setProperty(propName, prop.getLong());
                    break;
                }
            case PropertyType.DATE:
                {
                    dataNode.setProperty(propName, prop.getDate().getTime());
                    break;
                }
            case PropertyType.REFERENCE:
                {
                    try {
                        dataNode.setProperty(propName, new DataNodeRef(prop.getNode().getIdentifier()));
                    } catch (ItemNotFoundException e) {
                        // reference is missing, replace with missing data ref
                        // this situation can occur if the user does not have permission to access the reference.
                        dataNode.setProperty(propName, new DataNodeRef(DataNodeRef.REF_MISSING));
                    }
                    break;
                }
            default:
                {
                    throw new IllegalArgumentException();
                }
        }
    }
    // iterate over children
    NodeIterator nodes = jcrNode.getNodes(pattern);
    while (nodes.hasNext()) {
        Node child = nodes.nextNode();
        internalRead(session, pentahoJcrConstants, child, dataNode);
    }
    return dataNode;
}
Also used : DataNodeRef(org.pentaho.platform.api.repository2.unified.data.node.DataNodeRef) NodeIterator(javax.jcr.NodeIterator) DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) DataProperty(org.pentaho.platform.api.repository2.unified.data.node.DataProperty) Property(javax.jcr.Property) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 62 with DataNode

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

the class DatabaseHelperTest method createDataNode.

private DataNode createDataNode() {
    DataNode rootNode = new DataNode(NODE_ROOT);
    rootNode.setProperty(PROP_TYPE, "portType");
    rootNode.setProperty(PROP_CONTYPE, "contype");
    rootNode.setProperty(PROP_HOST_NAME, "portType");
    rootNode.setProperty(PROP_DATABASE_NAME, "databaseName");
    rootNode.setProperty(PROP_PORT, 8080);
    rootNode.setProperty(PROP_USERNAME, "username");
    rootNode.setProperty(PROP_PASSWORD, "password");
    rootNode.setProperty(PROP_SERVERNAME, "servername");
    rootNode.setProperty(PROP_DATA_TBS, "dataTbs");
    rootNode.setProperty(PROP_INDEX_TBS, "1");
    rootNode.setProperty(PROP_CONNECT_SQL, "connectSql");
    rootNode.setProperty(PROP_INITIAL_POOL_SIZE, "1");
    rootNode.setProperty(PROP_MAX_POOL_SIZE, "1");
    rootNode.setProperty(PROP_IS_POOLING, "true");
    rootNode.setProperty(PROP_IS_FORCING_TO_LOWER, "true");
    rootNode.setProperty(PROP_IS_FORCING_TO_UPPER, "true");
    rootNode.setProperty(PROP_IS_QUOTE_FIELDS, "true");
    rootNode.setProperty(PROP_IS_DECIMAL_SEPERATOR, "true");
    DataNode attrNode = rootNode.addNode(NODE_ATTRIBUTES);
    attrNode.setProperty("key", "value");
    attrNode = rootNode.addNode(NODE_POOLING_PROPS);
    attrNode.setProperty("key", "value");
    attrNode = rootNode.addNode(NODE_EXTRA_OPTIONS);
    attrNode.setProperty("key", "value");
    attrNode = rootNode.addNode(NODE_EXTRA_OPTIONS_ORDER);
    attrNode.setProperty("key", "value");
    return rootNode;
}
Also used : DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode)

Example 63 with DataNode

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

the class NodeRepositoryFileDataAdapter method toDataNode.

protected DataNode toDataNode(final DataNodeDto nodeDto) {
    DataNode node = new DataNode(nodeDto.name);
    node.setId(nodeDto.id);
    for (DataPropertyDto dtoProp : nodeDto.childProperties) {
        if (dtoProp.type == DataPropertyType.BOOLEAN.ordinal()) {
            node.setProperty(dtoProp.name, Boolean.parseBoolean(dtoProp.value));
        } else if (dtoProp.type == DataPropertyType.DATE.ordinal()) {
            node.setProperty(dtoProp.name, new Date(Long.parseLong(dtoProp.value)));
        } else if (dtoProp.type == DataPropertyType.DOUBLE.ordinal()) {
            node.setProperty(dtoProp.name, Double.parseDouble(dtoProp.value));
        } else if (dtoProp.type == DataPropertyType.LONG.ordinal()) {
            node.setProperty(dtoProp.name, Long.parseLong(dtoProp.value));
        } else if (dtoProp.type == DataPropertyType.STRING.ordinal()) {
            node.setProperty(dtoProp.name, dtoProp.value);
        } else if (dtoProp.type == DataPropertyType.REF.ordinal()) {
            node.setProperty(dtoProp.name, new DataNodeRef(dtoProp.value));
        } else {
            throw new IllegalArgumentException();
        }
    }
    for (DataNodeDto childNodeDto : nodeDto.childNodes) {
        node.addNode(toDataNode(childNodeDto));
    }
    return node;
}
Also used : DataNodeRef(org.pentaho.platform.api.repository2.unified.data.node.DataNodeRef) DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) Date(java.util.Date)

Example 64 with DataNode

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

the class UnifiedRepositoryTestUtils method stubGetData.

/**
 * Stubs a {@code getDataForRead} call. The pairs specified will be used to construct a
 * {@code NodeRepositoryFileData} .
 */
public static void stubGetData(final IUnifiedRepository repo, final String path, final String rootNodeName, final PathPropertyPair... pairs) {
    final String prefix = RepositoryFile.SEPARATOR + rootNodeName;
    DataNode rootNode = new DataNode(rootNodeName);
    for (PathPropertyPair pair : pairs) {
        if (!pair.getPath().startsWith(prefix)) {
            throw new IllegalArgumentException("all paths must have a common prefix");
        }
        String[] pathSegments = pair.getPath().substring(prefix.length() + 1).split("/");
        addChild(rootNode, pair.getProperty(), pathSegments, 0);
    }
    doReturn(new NodeRepositoryFileData(rootNode)).when(repo).getDataForRead(makeIdObject(path), NodeRepositoryFileData.class);
}
Also used : DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)

Example 65 with DataNode

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

the class MondrianCatalogRepositoryHelper method addOlap4jServer.

public void addOlap4jServer(String name, String className, String URL, String user, String password, Properties props) {
    final RepositoryFile etcOlapServers = repository.getFile(ETC_OLAP_SERVERS_JCR_FOLDER);
    RepositoryFile entry = repository.getFile(ETC_OLAP_SERVERS_JCR_FOLDER + RepositoryFile.SEPARATOR + name);
    if (entry == null) {
        entry = repository.createFolder(etcOlapServers.getId(), new RepositoryFile.Builder(name).folder(true).build(), "Creating entry for olap server: " + name + " into folder " + ETC_OLAP_SERVERS_JCR_FOLDER);
    }
    final String path = ETC_OLAP_SERVERS_JCR_FOLDER + RepositoryFile.SEPARATOR + name + RepositoryFile.SEPARATOR + "metadata";
    // Convert the properties to a serializable XML format.
    final String xmlProperties;
    final ByteArrayOutputStream os = new ByteArrayOutputStream();
    try {
        props.storeToXML(os, "Connection properties for server: " + name, "UTF-8");
        xmlProperties = os.toString("UTF-8");
    } catch (IOException e) {
        // Very bad. Just throw.
        throw new RuntimeException(e);
    } finally {
        try {
            os.close();
        } catch (IOException e) {
        // Don't care. Just cleaning up.
        }
    }
    final DataNode node = new DataNode("server");
    node.setProperty("name", name);
    node.setProperty("className", className);
    node.setProperty("URL", URL);
    node.setProperty("user", user);
    node.setProperty("password", password);
    node.setProperty("properties", xmlProperties);
    NodeRepositoryFileData data = new NodeRepositoryFileData(node);
    final RepositoryFile metadata = repository.getFile(path);
    if (metadata == null) {
        repository.createFile(entry.getId(), new RepositoryFile.Builder("metadata").build(), data, "Creating olap-server metadata for server " + name);
    } else {
        repository.updateFile(metadata, data, "Updating olap-server metadata for server " + name);
    }
}
Also used : 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) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

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