Search in sources :

Example 11 with DataProperty

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

the class DefaultUnifiedRepositoryContentIT method testMissingRef.

@Test
public void testMissingRef() throws Exception {
    // if a user does not have permission to a reference, it is removed from the node structure and
    // replaced with a missing link. previous releases would throw an exception.
    // create a file that suzy does not have permission to
    // create a file that suzy has permission to but references the one she doesn't
    // load the file as suzy, make sure no exceptions occur and that the node is a missing reference
    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);
    DataNode node = new DataNode("kdjd");
    RepositoryFile sampleFile = createSampleFile(ClientRepositoryPaths.getPublicFolderPath(), "helloworld2.sample", "dfdd", true, 83);
    RepositoryFileAcl acl = repo.getAcl(sampleFile.getId());
    RepositoryFileAcl newAcl = new RepositoryFileAcl.Builder(acl).entriesInheriting(false).clearAces().build();
    repo.updateAcl(newAcl);
    node.setProperty("urei2", new DataNodeRef(sampleFile.getId()));
    final String parentFolderPath = ClientRepositoryPaths.getPublicFolderPath();
    final String expectedName = "helloworld.doesnotmatter";
    RepositoryFile parentFolder = repo.getFile(parentFolderPath);
    assertNotNull(parentFolder);
    final String expectedPath = parentFolderPath + RepositoryFile.SEPARATOR + expectedName;
    NodeRepositoryFileData data = new NodeRepositoryFileData(node);
    RepositoryFile newFile = repo.createFile(parentFolder.getId(), new RepositoryFile.Builder(expectedName).build(), data, null);
    assertNotNull(newFile.getId());
    // now check that the ref is missing
    login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
    RepositoryFile foundFile = repo.getFile(expectedPath);
    assertNotNull(foundFile);
    DataNode foundNode = repo.getDataForRead(newFile.getId(), NodeRepositoryFileData.class).getNode();
    DataProperty d = foundNode.getProperty("urei2");
    assertNotNull(d);
    assertTrue(d.getType() == DataPropertyType.REF);
    assertTrue(d.getRef().getId() == DataNodeRef.REF_MISSING);
    // now change permissions back so she can get access to the node, confirm things are back to normal
    login(USERNAME_ADMIN, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
    newAcl = new RepositoryFileAcl.Builder(acl).entriesInheriting(true).clearAces().build();
    repo.updateAcl(newAcl);
    login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
    foundFile = repo.getFile(expectedPath);
    assertNotNull(foundFile);
    foundNode = repo.getDataForRead(newFile.getId(), NodeRepositoryFileData.class).getNode();
    d = foundNode.getProperty("urei2");
    assertNotNull(d);
    assertTrue(d.getType() == DataPropertyType.REF);
    assertTrue(d.getRef().getId().equals(sampleFile.getId()));
}
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) DataProperty(org.pentaho.platform.api.repository2.unified.data.node.DataProperty) Matchers.anyString(org.mockito.Matchers.anyString) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) Test(org.junit.Test)

Example 12 with DataProperty

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

the class DatabaseHelper method dataNodeToDatabaseConnection.

public IDatabaseConnection dataNodeToDatabaseConnection(final Serializable id, final String name, final DataNode rootNode) {
    IDatabaseConnection databaseConnection = new DatabaseConnection();
    String databaseType = getString(rootNode, PROP_TYPE);
    databaseConnection.setDatabaseType(databaseType != null ? databaseTypeHelper.getDatabaseTypeByShortName(databaseType) : null);
    databaseConnection.setName(name);
    if (id != null) {
        databaseConnection.setId(id.toString());
    }
    String accessType = getString(rootNode, PROP_CONTYPE);
    // This is a special case with some PDI connections
    if (accessType != null && accessType.contains("Native")) {
        accessType = DatabaseAccessType.NATIVE.getName();
    } else if (accessType != null && accessType.equals(", ")) {
        accessType = DatabaseAccessType.JNDI.getName();
    }
    databaseConnection.setAccessType(accessType != null ? DatabaseAccessType.getAccessTypeByName(accessType) : null);
    databaseConnection.setHostname(getString(rootNode, PROP_HOST_NAME));
    databaseConnection.setDatabaseName(getString(rootNode, PROP_DATABASE_NAME));
    databaseConnection.setDatabasePort(getString(rootNode, PROP_PORT));
    databaseConnection.setUsername(getString(rootNode, PROP_USERNAME));
    databaseConnection.setPassword(decryptPassword(getString(rootNode, PROP_PASSWORD)));
    databaseConnection.setInformixServername(getString(rootNode, PROP_SERVERNAME));
    databaseConnection.setDataTablespace(getString(rootNode, PROP_DATA_TBS));
    databaseConnection.setIndexTablespace(getString(rootNode, PROP_INDEX_TBS));
    databaseConnection.setConnectSql(getString(rootNode, PROP_CONNECT_SQL));
    databaseConnection.setInitialPoolSize(getInt(rootNode, PROP_INITIAL_POOL_SIZE));
    databaseConnection.setMaximumPoolSize(getInt(rootNode, PROP_MAX_POOL_SIZE));
    databaseConnection.setUsingConnectionPool(getBoolean(rootNode, PROP_IS_POOLING));
    databaseConnection.setForcingIdentifiersToLowerCase(getBoolean(rootNode, PROP_IS_FORCING_TO_LOWER));
    databaseConnection.setForcingIdentifiersToUpperCase(getBoolean(rootNode, PROP_IS_FORCING_TO_UPPER));
    databaseConnection.setQuoteAllFields(getBoolean(rootNode, PROP_IS_QUOTE_FIELDS));
    databaseConnection.setUsingDoubleDecimalAsSchemaTableSeparator(getBoolean(rootNode, PROP_IS_DECIMAL_SEPERATOR));
    // Also, load all the properties we can find...
    DataNode attrNode = rootNode.getNode(NODE_ATTRIBUTES);
    if (attrNode != null) {
        for (DataProperty property : attrNode.getProperties()) {
            String code = property.getName();
            String attribute = property.getString();
            databaseConnection.getAttributes().put(code, // $NON-NLS-1$
            (attribute == null || attribute.length() == 0) ? "" : attribute);
        }
    }
    // Also, load any pooling params
    attrNode = rootNode.getNode(NODE_POOLING_PROPS);
    if (attrNode != null) {
        for (DataProperty property : attrNode.getProperties()) {
            String code = property.getName();
            String attribute = property.getString();
            databaseConnection.getConnectionPoolingProperties().put(code, // $NON-NLS-1$
            (attribute == null || attribute.length() == 0) ? "" : attribute);
        }
    }
    // Load extra options
    attrNode = rootNode.getNode(NODE_EXTRA_OPTIONS);
    if (attrNode != null) {
        for (DataProperty property : attrNode.getProperties()) {
            String code = property.getName();
            String attribute = property.getString();
            databaseConnection.getExtraOptions().put(code, // $NON-NLS-1$
            (attribute == null || attribute.length() == 0) ? "" : attribute);
        }
    }
    attrNode = rootNode.getNode(NODE_EXTRA_OPTIONS_ORDER);
    if (attrNode != null) {
        for (DataProperty property : attrNode.getProperties()) {
            String code = property.getName();
            String attribute = property.getString();
            databaseConnection.getExtraOptionsOrder().put(code, // $NON
            (attribute == null || attribute.length() == 0) ? "" : attribute);
        }
    }
    return databaseConnection;
}
Also used : DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DataProperty(org.pentaho.platform.api.repository2.unified.data.node.DataProperty) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection)

Example 13 with DataProperty

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

the class JobDelegateTest method testDataNodeToElementCopiesAttributesToJobEntryCopyAndJobEntry.

@Test
public void testDataNodeToElementCopiesAttributesToJobEntryCopyAndJobEntry() throws KettleException {
    IUnifiedRepository mockUnifiedRepository = mock(IUnifiedRepository.class);
    JobDelegate jobDelegate = new JobDelegate(mockPurRepository, mockUnifiedRepository);
    DataNode mockDataNode = mock(DataNode.class);
    DataNode entriesNode = addSubnode(mockDataNode, JobDelegate.NODE_ENTRIES);
    DataNode copyNode = mock(DataNode.class);
    setNodes(entriesNode, JobDelegate.PROP_NR_JOB_ENTRY_COPIES, Arrays.asList(copyNode));
    DataNode nodeCustom = addSubnode(copyNode, JobDelegate.NODE_CUSTOM);
    DataNode notesNode = addSubnode(mockDataNode, JobDelegate.NODE_NOTES);
    DataNode hopsNode = addSubnode(mockDataNode, JobDelegate.NODE_HOPS);
    DataNode paramsNode = addSubnode(mockDataNode, JobDelegate.NODE_PARAMETERS);
    DataNode groupsNode = addSubnode(copyNode, AttributesMapUtil.NODE_ATTRIBUTE_GROUPS);
    DataNode groupNode = mock(DataNode.class);
    setNodes(groupsNode, null, Arrays.asList(groupNode));
    JobMeta mockJobMeta = mock(JobMeta.class);
    JobLogTable mockJobLogTable = mock(JobLogTable.class);
    List<JobEntryCopy> jobCopies = new ArrayList<JobEntryCopy>();
    DataProperty mockDataProperty = mock(DataProperty.class);
    List<DataProperty> dataProperties = Arrays.asList(mockDataProperty);
    setProperty(mockDataNode, JobDelegate.PROP_JOB_STATUS, 0L);
    setProperty(mockDataNode, JobDelegate.PROP_USE_BATCH_ID, false);
    setProperty(mockDataNode, JobDelegate.PROP_PASS_BATCH_ID, false);
    setProperty(mockDataNode, JobDelegate.PROP_USE_LOGFIELD, false);
    setProperty(copyNode, JobDelegate.PROP_JOBENTRY_TYPE, "WRITE_TO_LOG");
    when(copyNode.getId()).thenReturn("COPYNODE_ID");
    setProperty(copyNode, JobDelegate.PROP_NR, 0L);
    setProperty(copyNode, JobDelegate.PROP_GUI_LOCATION_X, 0L);
    setProperty(copyNode, JobDelegate.PROP_GUI_LOCATION_Y, 0L);
    setProperty(copyNode, JobDelegate.PROP_GUI_DRAW, false);
    setProperty(copyNode, JobDelegate.PROP_PARALLEL, false);
    setProperty(nodeCustom, "logmessage_#_0", (String) null);
    setNodes(notesNode, JobDelegate.PROP_NR_NOTES, Arrays.<DataNode>asList());
    setNodes(hopsNode, JobDelegate.PROP_NR_HOPS, Arrays.<DataNode>asList());
    setProperty(paramsNode, JobDelegate.PROP_NR_PARAMETERS, 0L);
    when(mockJobMeta.getJobCopies()).thenReturn(jobCopies);
    when(mockJobMeta.getJobLogTable()).thenReturn(mockJobLogTable);
    when(groupNode.getName()).thenReturn("GROUP_NODE_NAME");
    when(groupNode.getProperties()).thenReturn(dataProperties);
    when(mockDataProperty.getName()).thenReturn("MOCK_PROPERTY");
    when(mockDataProperty.getString()).thenReturn("MOCK_VALUE");
    jobDelegate.dataNodeToElement(mockDataNode, mockJobMeta);
    assertEquals(jobCopies.get(0).getAttributesMap(), ((JobEntryBase) jobCopies.get(0).getEntry()).getAttributesMap());
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) JobLogTable(org.pentaho.di.core.logging.JobLogTable) DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) ArrayList(java.util.ArrayList) DataProperty(org.pentaho.platform.api.repository2.unified.data.node.DataProperty) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Example 14 with DataProperty

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

the class JobDelegateTest method addDataProperty.

public static DataProperty addDataProperty(DataNode node, String name) {
    DataProperty dataProperty = mock(DataProperty.class);
    when(node.hasProperty(name)).thenReturn(true);
    when(node.getProperty(name)).thenReturn(dataProperty);
    return dataProperty;
}
Also used : DataProperty(org.pentaho.platform.api.repository2.unified.data.node.DataProperty)

Example 15 with DataProperty

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

the class DatabaseDelegate method dataNodeToElement.

public void dataNodeToElement(final DataNode rootNode, final RepositoryElementInterface element) throws KettleException {
    DatabaseMeta databaseMeta = (DatabaseMeta) element;
    databaseMeta.setDatabaseType(getString(rootNode, PROP_TYPE));
    databaseMeta.setAccessType(DatabaseMeta.getAccessType(getString(rootNode, PROP_CONTYPE)));
    databaseMeta.setHostname(getString(rootNode, PROP_HOST_NAME));
    databaseMeta.setDBName(getString(rootNode, PROP_DATABASE_NAME));
    databaseMeta.setDBPort(getString(rootNode, PROP_PORT));
    databaseMeta.setUsername(getString(rootNode, PROP_USERNAME));
    databaseMeta.setPassword(Encr.decryptPasswordOptionallyEncrypted(getString(rootNode, PROP_PASSWORD)));
    databaseMeta.setServername(getString(rootNode, PROP_SERVERNAME));
    databaseMeta.setDataTablespace(getString(rootNode, PROP_DATA_TBS));
    databaseMeta.setIndexTablespace(getString(rootNode, PROP_INDEX_TBS));
    // Also, load all the properties we can find...
    DataNode attrNode = rootNode.getNode(NODE_ATTRIBUTES);
    for (DataProperty property : attrNode.getProperties()) {
        String code = property.getName();
        String attribute = property.getString();
        // We need to unescape the code as it was escaped to handle characters that JCR does not handle
        String unescapeCode = RepositoryFilenameUtils.unescape(code);
        // $NON-NLS-1$
        databaseMeta.getAttributes().put(unescapeCode, Const.NVL(attribute, ""));
    }
}
Also used : DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) DataProperty(org.pentaho.platform.api.repository2.unified.data.node.DataProperty) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta)

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