Search in sources :

Example 26 with DataNode

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

the class NodeRepositoryFileDataAdapter method unmarshal.

@Override
public NodeRepositoryFileData unmarshal(final NodeRepositoryFileDataDto v) {
    DataNode node = toDataNode(v.node);
    NodeRepositoryFileData data = new NodeRepositoryFileData(node);
    return data;
}
Also used : DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)

Example 27 with DataNode

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

the class NodeRepositoryFileDataAdapter method toDataNodeDto.

protected void toDataNodeDto(final DataNodeDto nodeDto, final DataNode node) {
    nodeDto.name = node.getName();
    if (node.getId() != null) {
        nodeDto.id = node.getId().toString();
    }
    List<DataPropertyDto> dtoProps = new ArrayList<DataPropertyDto>();
    for (DataProperty prop : node.getProperties()) {
        DataPropertyDto dtoProp = new DataPropertyDto();
        dtoProp.name = prop.getName();
        if ((prop.getType() == DataPropertyType.BOOLEAN) || (prop.getType() == DataPropertyType.DOUBLE) || (prop.getType() == DataPropertyType.LONG) || (prop.getType() == DataPropertyType.STRING) || (prop.getType() == DataPropertyType.REF)) {
            dtoProp.value = prop.getString();
        } else if (prop.getType() == DataPropertyType.DATE) {
            Date dateProp = prop.getDate();
            dtoProp.value = dateProp != null ? String.valueOf(dateProp.getTime()) : null;
        } else {
            throw new IllegalArgumentException();
        }
        dtoProp.type = prop.getType() != null ? prop.getType().ordinal() : -1;
        dtoProps.add(dtoProp);
    }
    nodeDto.childProperties = dtoProps;
    List<DataNodeDto> nodeDtos = new ArrayList<DataNodeDto>();
    for (DataNode childNode : node.getNodes()) {
        DataNodeDto child = new DataNodeDto();
        nodeDtos.add(child);
        toDataNodeDto(child, childNode);
    }
    nodeDto.childNodes = nodeDtos;
}
Also used : DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) ArrayList(java.util.ArrayList) DataProperty(org.pentaho.platform.api.repository2.unified.data.node.DataProperty) Date(java.util.Date)

Example 28 with DataNode

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

the class DefaultUnifiedRepositoryContentIT method testCreateNodeFile.

@Test
public void testCreateNodeFile() 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 = "helloworld.doesnotmatter";
    final String parentFolderPath = ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY);
    RepositoryFile parentFolder = repo.getFile(parentFolderPath);
    final String expectedPath = parentFolderPath + RepositoryFile.SEPARATOR + expectedName;
    final String serverPath = ServerRepositoryPaths.getTenantRootFolderPath() + parentFolderPath + RepositoryFile.SEPARATOR + "helloworld2.sample";
    RepositoryFile sampleFile = createSampleFile(parentFolderPath, "helloworld2.sample", "dfdd", true, 83);
    final Date EXP_DATE = new Date();
    DataNode node = new DataNode("kdjd");
    node.setProperty("ddf", "ljsdfkjsdkf");
    DataNode newChild1 = node.addNode("herfkmdx");
    newChild1.setProperty("sdfs", true);
    newChild1.setProperty("ks3", EXP_DATE);
    newChild1.setProperty("ids32", 7.32D);
    newChild1.setProperty("erere3", 9856684583L);
    newChild1.setProperty("tttss4", "843skdfj33ksaljdfj");
    newChild1.setProperty("urei2", new DataNodeRef(sampleFile.getId()));
    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).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());
    assertEquals(node.getProperty("ddf"), foundNode.getProperty("ddf"));
    int actualPropCount = 0;
    for (DataProperty prop : foundNode.getProperties()) {
        actualPropCount++;
    }
    assertEquals(1, actualPropCount);
    assertTrue(foundNode.hasNode("herfkmdx"));
    DataNode foundChild1 = foundNode.getNode("herfkmdx");
    assertNotNull(foundChild1.getId());
    assertEquals(newChild1.getName(), foundChild1.getName());
    assertEquals(newChild1.getProperty("sdfs"), foundChild1.getProperty("sdfs"));
    assertEquals(newChild1.getProperty("ks3"), foundChild1.getProperty("ks3"));
    assertEquals(newChild1.getProperty("ids32"), foundChild1.getProperty("ids32"));
    assertEquals(newChild1.getProperty("erere3"), foundChild1.getProperty("erere3"));
    assertEquals(newChild1.getProperty("tttss4"), foundChild1.getProperty("tttss4"));
    assertEquals(newChild1.getProperty("urei2"), foundChild1.getProperty("urei2"));
    try {
        repo.deleteFile(sampleFile.getId(), true, null);
        fail();
    } catch (UnifiedRepositoryException e) {
    // should fail due to referential integrity (newFile payload has reference to sampleFile)
    }
    actualPropCount = 0;
    for (DataProperty prop : newChild1.getProperties()) {
        actualPropCount++;
    }
    assertEquals(6, actualPropCount);
    assertTrue(foundNode.hasNode(JcrStringHelper.fileNameEncode("pppq/qqs2")));
    DataNode foundChild2 = foundNode.getNode(JcrStringHelper.fileNameEncode("pppq/qqs2"));
    assertNotNull(foundChild2.getId());
    assertEquals(newChild2.getName(), foundChild2.getName());
    assertEquals(newChild2.getProperty(JcrStringHelper.fileNameEncode("ttt:ss4")), foundChild2.getProperty(JcrStringHelper.fileNameEncode("ttt:ss4")));
    actualPropCount = 0;
    for (DataProperty prop : foundChild2.getProperties()) {
        actualPropCount++;
    }
    assertEquals(1, actualPropCount);
    // ordering
    int i = 0;
    for (DataNode currentNode : foundNode.getNodes()) {
        if (i++ == 0) {
            assertEquals(newChild1.getName(), currentNode.getName());
        } else {
            assertEquals(newChild2.getName(), currentNode.getName());
        }
    }
}
Also used : DataNodeRef(org.pentaho.platform.api.repository2.unified.data.node.DataNodeRef) 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) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) DataProperty(org.pentaho.platform.api.repository2.unified.data.node.DataProperty) Matchers.anyString(org.mockito.Matchers.anyString) Date(java.util.Date) Test(org.junit.Test)

Example 29 with DataNode

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

the class DefaultUnifiedRepositoryContentIT method testGetReferrers.

@Test
public void testGetReferrers() 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 refereeFileName = "referee.sample";
    final String referrerFileName = "referrer.sample";
    final String parentFolderPath = ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY);
    RepositoryFile parentFolder = repo.getFile(parentFolderPath);
    RepositoryFile refereeFile = createSampleFile(parentFolderPath, refereeFileName, "dfdd", true, 83);
    DataNode node = new DataNode("kdjd");
    node.setProperty("ddf", "ljsdfkjsdkf");
    DataNode newChild1 = node.addNode("herfkmdx");
    newChild1.setProperty("urei2", new DataNodeRef(refereeFile.getId()));
    NodeRepositoryFileData data = new NodeRepositoryFileData(node);
    repo.createFile(parentFolder.getId(), new RepositoryFile.Builder(referrerFileName).build(), data, null);
    List<RepositoryFile> referrers = repo.getReferrers(refereeFile.getId());
    assertNotNull(referrers);
    assertEquals(1, referrers.size());
    assertEquals(referrers.get(0).getName(), referrerFileName);
}
Also used : DataNodeRef(org.pentaho.platform.api.repository2.unified.data.node.DataNodeRef) 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 30 with DataNode

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

the class DefaultUnifiedRepositoryContentIT method testSymbol.

private void testSymbol(char symbol, boolean isGood) {
    DataNode goodNode = new DataNode("node");
    goodNode.setProperty("property", "whatever");
    NodeRepositoryFileData goodNodeData = new NodeRepositoryFileData(goodNode);
    DataNode badNode = new DataNode("node" + symbol);
    badNode.setProperty("property", "whatever");
    NodeRepositoryFileData badNodeData = new NodeRepositoryFileData(badNode);
    DataNode goodNodeBadProp = new DataNode("node");
    goodNodeBadProp.setProperty("property" + symbol, "whatever");
    NodeRepositoryFileData goodNodeBadPropData = new NodeRepositoryFileData(goodNodeBadProp);
    final String parentFolderPath = ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName());
    RepositoryFile parentFolder = repo.getFile(parentFolderPath);
    try {
        final String name = "folder" + symbol;
        final RepositoryFile folder = repo.createFolder(parentFolder.getId(), new RepositoryFile.Builder(name).folder(true).build(), null);
        failIfTrue(!isGood, symbol);
        assertEquals(name, folder.getName());
    } catch (UnifiedRepositoryMalformedNameException e) {
        failIfTrue(isGood, symbol);
    }
    try {
        final String name = "file" + symbol;
        final RepositoryFile file = repo.createFile(parentFolder.getId(), new RepositoryFile.Builder(name).build(), goodNodeData, null);
        failIfTrue(!isGood, symbol);
        assertEquals(name, file.getName());
    } catch (UnifiedRepositoryMalformedNameException e) {
        failIfTrue(isGood, symbol);
    }
    try {
        final RepositoryFile file = repo.getFile(parentFolder.getPath() + RepositoryFile.SEPARATOR + "file");
        if (file != null) {
            repo.deleteFile(file.getId(), null);
        }
        final RepositoryFile file1 = repo.createFile(parentFolder.getId(), new RepositoryFile.Builder("file").build(), badNodeData, null);
        failIfTrue(!isGood, symbol);
        assertEquals(badNodeData.getNode().getName(), repo.getDataForRead(file1.getId(), NodeRepositoryFileData.class).getNode().getName());
    } catch (UnifiedRepositoryMalformedNameException e) {
        failIfTrue(isGood, symbol);
    }
    try {
        final RepositoryFile file = repo.getFile(parentFolder.getPath() + RepositoryFile.SEPARATOR + "file");
        if (file != null) {
            repo.deleteFile(file.getId(), null);
        }
        final RepositoryFile file1 = repo.createFile(parentFolder.getId(), new RepositoryFile.Builder("file").build(), goodNodeBadPropData, null);
        failIfTrue(!isGood, symbol);
        assertEquals(goodNodeBadPropData.getNode().getProperties().iterator().next().getName(), repo.getDataForRead(file1.getId(), NodeRepositoryFileData.class).getNode().getProperties().iterator().next().getName());
    } catch (UnifiedRepositoryMalformedNameException e) {
        failIfTrue(isGood, symbol);
    }
}
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) Matchers.anyString(org.mockito.Matchers.anyString) UnifiedRepositoryMalformedNameException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryMalformedNameException)

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