Search in sources :

Example 6 with DataProperty

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

the class UnifiedRepositoryTestUtils method pathPropertyPair.

/**
 * Factory for {@link PathPropertyPair} instances.
 */
public static PathPropertyPair pathPropertyPair(final String path, final double value) {
    checkPath(path);
    String[] pathSegments = path.split("/");
    return new PathPropertyPair(path, new DataProperty(pathSegments[pathSegments.length - 1], value, DataPropertyType.DOUBLE));
}
Also used : DataProperty(org.pentaho.platform.api.repository2.unified.data.node.DataProperty)

Example 7 with DataProperty

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

the class UnifiedRepositoryTestUtils method pathPropertyPair.

/**
 * Factory for {@link PathPropertyPair} instances.
 */
public static PathPropertyPair pathPropertyPair(final String path, final Date value) {
    checkPath(path);
    String[] pathSegments = path.split("/");
    return new PathPropertyPair(path, new DataProperty(pathSegments[pathSegments.length - 1], value, DataPropertyType.DATE));
}
Also used : DataProperty(org.pentaho.platform.api.repository2.unified.data.node.DataProperty)

Example 8 with DataProperty

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

the class NodeRepositoryFileDataAdapterTest method testMarshalUnmarshalDate.

private void testMarshalUnmarshalDate(Locale locale, TimeZone timeZone) throws Exception {
    final Locale defaultLocale = Locale.getDefault();
    final TimeZone defaultTimeZone = TimeZone.getDefault();
    // $NON-NLS-1$
    final String DATE_PROPERTY = "date";
    NodeRepositoryFileDataAdapter adapter = new NodeRepositoryFileDataAdapter();
    Date date = new Date();
    // $NON-NLS-1$
    DataNode node = new DataNode("");
    node.setProperty(DATE_PROPERTY, date);
    NodeRepositoryFileData data = new NodeRepositoryFileData(node);
    NodeRepositoryFileData result;
    // Convert using the provided locale
    try {
        Locale.setDefault(locale);
        TimeZone.setDefault(timeZone);
        NodeRepositoryFileDataDto dto = adapter.marshal(data);
        result = adapter.unmarshal(dto);
    } finally {
        Locale.setDefault(defaultLocale);
        TimeZone.setDefault(defaultTimeZone);
    }
    DataProperty property = result.getNode().getProperty(DATE_PROPERTY);
    assertNotNull(property);
    assertEquals(date, property.getDate());
}
Also used : Locale(java.util.Locale) TimeZone(java.util.TimeZone) DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) DataProperty(org.pentaho.platform.api.repository2.unified.data.node.DataProperty) Date(java.util.Date)

Example 9 with DataProperty

use of org.pentaho.platform.api.repository2.unified.data.node.DataProperty 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 10 with DataProperty

use of org.pentaho.platform.api.repository2.unified.data.node.DataProperty 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)

Aggregations

DataProperty (org.pentaho.platform.api.repository2.unified.data.node.DataProperty)22 DataNode (org.pentaho.platform.api.repository2.unified.data.node.DataNode)13 NodeRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)4 Date (java.util.Date)3 Test (org.junit.Test)3 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)3 ArrayList (java.util.ArrayList)2 Matchers.anyString (org.mockito.Matchers.anyString)2 ObjectId (org.pentaho.di.repository.ObjectId)2 StringObjectId (org.pentaho.di.repository.StringObjectId)2 ITenant (org.pentaho.platform.api.mt.ITenant)2 DataNodeRef (org.pentaho.platform.api.repository2.unified.data.node.DataNodeRef)2 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 Map (java.util.Map)1 TimeZone (java.util.TimeZone)1 Node (javax.jcr.Node)1 DatabaseConnection (org.pentaho.database.model.DatabaseConnection)1 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)1