Search in sources :

Example 1 with Jsr283Encoder

use of org.modeshape.common.text.Jsr283Encoder in project kylo by Teradata.

the class JcrDatasourceProvider method ensureDerivedDatasource.

/**
 * gets or creates the Derived datasource
 */
public DerivedDatasource ensureDerivedDatasource(String datasourceType, String identityString, String title, String desc, Map<String, Object> properties) {
    // ensure the identity String is not null
    if (identityString == null) {
        identityString = "";
    }
    if (datasourceType == null) {
        datasourceType = "Datasource";
    }
    DerivedDatasource derivedDatasource = findDerivedDatasource(datasourceType, identityString);
    if (derivedDatasource == null) {
        try {
            if (!getSession().getRootNode().hasNode("metadata/datasources/derived")) {
                if (!getSession().getRootNode().hasNode("metadata/datasources")) {
                    getSession().getRootNode().addNode("metadata", "datasources");
                }
                getSession().getRootNode().getNode("metadata/datasources").addNode("derived");
            }
            Node parentNode = getSession().getNode(EntityUtil.pathForDerivedDatasource());
            String nodeName = datasourceType + "-" + identityString;
            if (Jsr283Encoder.containsEncodeableCharacters(identityString)) {
                nodeName = new Jsr283Encoder().encode(nodeName);
            }
            JcrDerivedDatasource jcrDerivedDatasource = null;
            try {
                jcrDerivedDatasource = findDerivedDatasourceByNodeName(nodeName);
            } catch (RepositoryException e) {
                log.warn("An exception occurred trying to find the DerivedDatasource by node name {}.  {} ", nodeName, e.getMessage());
            }
            derivedDatasource = jcrDerivedDatasource;
            if (jcrDerivedDatasource == null) {
                Node derivedDatasourceNode = JcrUtil.createNode(parentNode, nodeName, JcrDerivedDatasource.NODE_TYPE);
                jcrDerivedDatasource = new JcrDerivedDatasource(derivedDatasourceNode);
                jcrDerivedDatasource.setSystemName(identityString);
                jcrDerivedDatasource.setDatasourceType(datasourceType);
                jcrDerivedDatasource.setTitle(title);
                jcrDerivedDatasource.setDescription(desc);
                derivedDatasource = jcrDerivedDatasource;
            }
        } catch (RepositoryException e) {
            log.error("Failed to create Derived Datasource for DatasourceType: {}, IdentityString: {}, Error: {}", datasourceType, identityString, e.getMessage(), e);
        }
    }
    if (derivedDatasource != null) {
        // ((JcrDerivedDatasource)derivedDatasource).mergeProperties()
        if (properties != null) {
            derivedDatasource.setProperties(properties);
        }
        derivedDatasource.setTitle(title);
    }
    return derivedDatasource;
}
Also used : Jsr283Encoder(org.modeshape.common.text.Jsr283Encoder) Node(javax.jcr.Node) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) DerivedDatasource(com.thinkbiganalytics.metadata.api.datasource.DerivedDatasource)

Aggregations

DerivedDatasource (com.thinkbiganalytics.metadata.api.datasource.DerivedDatasource)1 MetadataRepositoryException (com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException)1 Node (javax.jcr.Node)1 RepositoryException (javax.jcr.RepositoryException)1 Jsr283Encoder (org.modeshape.common.text.Jsr283Encoder)1