Search in sources :

Example 56 with DataNode

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

the class PurRepositoryMetaStore method updateElementType.

@Override
public synchronized void updateElementType(String namespace, IMetaStoreElementType elementType) throws MetaStoreException {
    RepositoryFile folder = getElementTypeRepositoryFolder(namespace, elementType);
    RepositoryFile detailsFile = findChildByName(folder.getId(), ELEMENT_TYPE_DETAILS_FILENAME, true);
    DataNode dataNode = getElementTypeDataNode(elementType);
    pur.updateFile(detailsFile, new NodeRepositoryFileData(dataNode), null);
    elementType.setMetaStoreName(getName());
}
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)

Example 57 with DataNode

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

the class PurRepositoryMetaStore method getElement.

@Override
public IMetaStoreElement getElement(String namespace, IMetaStoreElementType elementType, String elementId) throws MetaStoreException {
    NodeRepositoryFileData data = pur.getDataForRead(elementId, NodeRepositoryFileData.class);
    if (data == null) {
        return null;
    }
    IMetaStoreElement element = newElement();
    element.setId(elementId);
    element.setElementType(elementType);
    DataNode dataNode = data.getNode();
    dataNodeToElement(dataNode, element);
    return element;
}
Also used : NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement)

Example 58 with DataNode

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

the class DefaultUnifiedRepositoryAuthorizationIT method testInheritingNodeRemoval.

@Test
public void testInheritingNodeRemoval() throws Exception {
    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);
    final String parentFolderPath = ClientRepositoryPaths.getPublicFolderPath();
    RepositoryFile parentFolder = repo.getFile(parentFolderPath);
    DataNode node = new DataNode("kdjd");
    node.setProperty("ddf", "ljsdfkjsdkf");
    DataNode newChild1 = node.addNode("herfkmdx");
    NodeRepositoryFileData data = new NodeRepositoryFileData(node);
    RepositoryFile repoFile = repo.createFile(parentFolder.getId(), new RepositoryFile.Builder("test").build(), data, null);
    RepositoryFileAcl acl = repo.getAcl(repoFile.getId());
    RepositoryFileSid suzySid = new RepositoryFileSid(userNameUtils.getPrincipleId(tenantAcme, USERNAME_SUZY));
    RepositoryFileAcl.Builder newAclBuilder = new RepositoryFileAcl.Builder(acl).ace(suzySid, EnumSet.of(RepositoryFilePermission.READ, RepositoryFilePermission.WRITE));
    repo.updateAcl(newAclBuilder.build());
    login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
    repoFile = repo.getFile(repoFile.getPath());
    node = new DataNode("kdjd");
    node.setProperty("foo", "bar");
    newChild1 = node.addNode("sdfsdf");
    data = new NodeRepositoryFileData(node);
    repo.updateFile(repoFile, data, "testUpdate");
}
Also used : RepositoryFileSid(org.pentaho.platform.api.repository2.unified.RepositoryFileSid) 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) Matchers.anyString(org.mockito.Matchers.anyString) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) Test(org.junit.Test)

Example 59 with DataNode

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

the class DefaultUnifiedRepositoryContentIT method testCreateACLNodeFile.

@Test
public void testCreateACLNodeFile() throws Exception {
    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);
    login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
    final String expectedName = "aclnode";
    final String parentFolderPath = ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY);
    RepositoryFile parentFolder = repo.getFile(parentFolderPath);
    final String expectedPath = parentFolderPath + RepositoryFile.SEPARATOR + expectedName;
    DataNode node = new DataNode("kdjd");
    DataNode newChild1 = node.addNode("herfkmdx");
    DataNode newChild2 = node.addNode(JcrStringHelper.fileNameEncode("pppq/qqs2"));
    newChild2.setProperty(JcrStringHelper.fileNameEncode("ttt*ss4"), "843skdfj33ksaljdfj");
    NodeRepositoryFileData data = new NodeRepositoryFileData(node);
    RepositoryFile newFile = repo.createFile(parentFolder.getId(), new RepositoryFile.Builder(expectedName).aclNode(true).build(), data, null);
    assertNotNull(newFile.getId());
    RepositoryFile foundFile = repo.getFile(expectedPath);
    assertNotNull(foundFile);
    assertEquals(expectedName, foundFile.getName());
    DataNode foundNode = repo.getDataForRead(foundFile.getId(), NodeRepositoryFileData.class).getNode();
    assertEquals(node.getName(), foundNode.getName());
    assertNotNull(foundNode.getId());
    assertTrue(foundNode.hasNode("herfkmdx"));
    DataNode foundChild1 = foundNode.getNode("herfkmdx");
    assertNotNull(foundChild1.getId());
    assertEquals(newChild1.getName(), foundChild1.getName());
    assertEquals(newChild1.getProperty("shadow"), foundChild1.getProperty("shadow"));
}
Also used : 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) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 60 with DataNode

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

the class NodeRepositoryFileDataTransformer method internalCreateOrUpdate.

protected void internalCreateOrUpdate(final Session session, final PentahoJcrConstants pentahoJcrConstants, final Node jcrParentNode, final DataNode dataNode) throws RepositoryException {
    // $NON-NLS-1$
    final String prefix = session.getNamespacePrefix(PentahoJcrConstants.PHO_NS) + ":";
    // get or create the node represented by dataNode
    Node jcrNode = null;
    String nodeName = dataNode.getName();
    // Not need to check the name if we encoded it
    // JcrRepositoryFileUtils.checkName( dataNode.getName() );
    nodeName = JcrStringHelper.fileNameEncode(nodeName);
    if (NodeHelper.hasNode(jcrParentNode, prefix, nodeName)) {
        jcrNode = NodeHelper.getNode(jcrParentNode, prefix, nodeName);
    } else {
        jcrNode = jcrParentNode.addNode(prefix + nodeName, pentahoJcrConstants.getPHO_NT_INTERNALFOLDER());
    }
    // set any properties represented by dataNode
    for (DataProperty dataProp : dataNode.getProperties()) {
        String propName = dataProp.getName();
        // Not need to check the name if we encoded it
        // JcrRepositoryFileUtils.checkName( propName );
        propName = prefix + JcrStringHelper.fileNameEncode(propName);
        switch(dataProp.getType()) {
            case STRING:
                {
                    jcrNode.setProperty(propName, dataProp.getString());
                    break;
                }
            case BOOLEAN:
                {
                    jcrNode.setProperty(propName, dataProp.getBoolean());
                    break;
                }
            case DOUBLE:
                {
                    jcrNode.setProperty(propName, dataProp.getDouble());
                    break;
                }
            case LONG:
                {
                    jcrNode.setProperty(propName, dataProp.getLong());
                    break;
                }
            case DATE:
                {
                    Calendar cal = Calendar.getInstance();
                    cal.setTime(dataProp.getDate());
                    jcrNode.setProperty(propName, cal);
                    break;
                }
            case REF:
                {
                    jcrNode.setProperty(propName, session.getNodeByIdentifier(dataProp.getRef().getId().toString()));
                    break;
                }
            default:
                {
                    throw new IllegalArgumentException();
                }
        }
    }
    // now process any child nodes of dataNode
    for (DataNode child : dataNode.getNodes()) {
        internalCreateOrUpdate(session, pentahoJcrConstants, jcrNode, child);
    }
}
Also used : DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) Node(javax.jcr.Node) Calendar(java.util.Calendar) DataProperty(org.pentaho.platform.api.repository2.unified.data.node.DataProperty)

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