Search in sources :

Example 1 with NodeRepositoryFileData

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

the class JcrBackedDatasourceMgmtServiceTest method testGetDatasources.

@Test
public void testGetDatasources() throws Exception {
    final String fileId = "456";
    final String databasesFolderPath = "/etc/pdi/databases";
    final String dotKdb = ".kdb";
    IUnifiedRepository repo = mock(IUnifiedRepository.class);
    // stub out get parent folder
    doReturn(new RepositoryFile.Builder("123", "databases").folder(true).build()).when(repo).getFile(databasesFolderPath);
    doReturn(reservedChars).when(repo).getReservedChars();
    // stub out get file to update
    RepositoryFile f = new RepositoryFile.Builder(fileId, EXP_DBMETA_NAME + dotKdb).path(databasesFolderPath + RepositoryFile.SEPARATOR + EXP_DBMETA_NAME + dotKdb).build();
    doReturn(f).when(repo).getFile(databasesFolderPath + RepositoryFile.SEPARATOR + EXP_DBMETA_NAME + dotKdb);
    final String EXP_HOST_NAME = "hello";
    DataNode rootNode = new DataNode("databaseMeta");
    // required
    rootNode.setProperty("TYPE", "Hypersonic");
    rootNode.setProperty("HOST_NAME", EXP_HOST_NAME);
    // required
    rootNode.addNode("attributes");
    doReturn(new NodeRepositoryFileData(rootNode)).when(repo).getDataForRead(eq(fileId), eq(NodeRepositoryFileData.class));
    IDatasourceMgmtService datasourceMgmtService = new JcrBackedDatasourceMgmtService(repo, new DatabaseDialectService());
    IDatabaseConnection conn = datasourceMgmtService.getDatasourceByName(EXP_DBMETA_NAME);
    assertEquals(EXP_HOST_NAME, conn.getHostname());
}
Also used : DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) DatabaseDialectService(org.pentaho.database.service.DatabaseDialectService) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Matchers.anyString(org.mockito.Matchers.anyString) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) IDatasourceMgmtService(org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService) Test(org.junit.Test)

Example 2 with NodeRepositoryFileData

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

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

the class MondrianCatalogRepositoryHelper method createDatasourceMetadata.

/*
   * Creates "/etc/mondrian/<catalog>/metadata" and the connection nodes
   */
private void createDatasourceMetadata(RepositoryFile catalog, String datasourceInfo) {
    final String path = ETC_MONDRIAN_JCR_FOLDER + RepositoryFile.SEPARATOR + catalog.getName() + RepositoryFile.SEPARATOR + "metadata";
    RepositoryFile metadata = repository.getFile(path);
    String definition = "mondrian:/" + catalog.getName();
    DataNode node = new DataNode("catalog");
    node.setProperty("definition", encodeUrl(definition));
    node.setProperty("datasourceInfo", datasourceInfo);
    NodeRepositoryFileData data = new NodeRepositoryFileData(node);
    if (metadata == null) {
        repository.createFile(catalog.getId(), new RepositoryFile.Builder("metadata").build(), data, null);
    } else {
        repository.updateFile(metadata, data, null);
    }
}
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 4 with NodeRepositoryFileData

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

the class JcrAclNodeHelper method createAclNode.

private RepositoryFile createAclNode(RepositoryFile fileToAddAclFor) {
    DataNode dataNode = new DataNode("acl node");
    DataNodeRef dataNodeRef = new DataNodeRef(fileToAddAclFor.getId());
    dataNode.setProperty(TARGET, dataNodeRef);
    dataNode.setProperty(IS_ACL_NODE, true);
    NodeRepositoryFileData nodeRepositoryFileData = new NodeRepositoryFileData(dataNode);
    return unifiedRepository.createFile(unifiedRepository.getFile("/").getId(), new RepositoryFile.Builder(UUID.randomUUID().toString()).aclNode(true).build(), nodeRepositoryFileData, "");
}
Also used : DataNodeRef(org.pentaho.platform.api.repository2.unified.data.node.DataNodeRef) 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 5 with NodeRepositoryFileData

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

the class JcrRepositoryFileDao method internalCreateFile.

private RepositoryFile internalCreateFile(final Serializable parentFolderId, final RepositoryFile file, final IRepositoryFileData content, final RepositoryFileAcl acl, final String versionMessage) {
    if (isKioskEnabled()) {
        // $NON-NLS-1$
        throw new RuntimeException(Messages.getInstance().getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED"));
    }
    /*
     * PPP-3049: Changed the Assert.notNull(content) to code that creates a file with a single blank when the assert
     * WOULD have been triggered.
     */
    Assert.notNull(file);
    Assert.isTrue(!file.isFolder());
    // Get repository file info and acl info of parent
    if (parentFolderId != null) {
        RepositoryFile parentRepositoryFile = getFileById(parentFolderId);
        if (parentRepositoryFile != null) {
            RepositoryFileAcl parentAcl = aclDao.getAcl(parentRepositoryFile.getId());
            // Invoke accessVoterManager to see if we have access to perform this operation
            if (!accessVoterManager.hasAccess(parentRepositoryFile, RepositoryFilePermission.WRITE, parentAcl, PentahoSessionHolder.getSession())) {
                return null;
            }
        }
    }
    // Assert.notNull(content);
    DataNode emptyDataNode = new DataNode(file.getName());
    // $NON-NLS-1$ //$NON-NLS-2$
    emptyDataNode.setProperty(" ", "content");
    final IRepositoryFileData emptyContent = new NodeRepositoryFileData(emptyDataNode);
    return (RepositoryFile) jcrTemplate.execute(new JcrCallback() {

        @Override
        public Object doInJcr(final Session session) throws RepositoryException, IOException {
            PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
            JcrRepositoryFileUtils.checkoutNearestVersionableFileIfNecessary(session, pentahoJcrConstants, parentFolderId);
            Node fileNode = JcrRepositoryFileUtils.createFileNode(session, pentahoJcrConstants, parentFolderId, file, content == null ? emptyContent : content, findTransformerForWrite(content == null ? emptyContent.getClass() : content.getClass()));
            // create a tmp file with correct path for default acl creation purposes.
            String path = JcrRepositoryFileUtils.getAbsolutePath(session, pentahoJcrConstants, fileNode);
            RepositoryFile tmpFile = new RepositoryFile.Builder(file).path(path).build();
            // we must create the acl during checkout
            aclDao.createAcl(fileNode.getIdentifier(), acl == null ? defaultAclHandler.createDefaultAcl(tmpFile) : acl);
            session.save();
            if (file.isVersioned()) {
                JcrRepositoryFileUtils.checkinNearestVersionableNodeIfNecessary(session, pentahoJcrConstants, fileNode, versionMessage, file.getCreatedDate(), false);
            }
            JcrRepositoryFileUtils.checkinNearestVersionableFileIfNecessary(session, pentahoJcrConstants, parentFolderId, Messages.getInstance().getString("JcrRepositoryFileDao.USER_0002_VER_COMMENT_ADD_FILE", file.getName(), // $NON-NLS-1$ //$NON-NLS-2$
            (parentFolderId == null ? "root" : parentFolderId.toString())));
            return JcrRepositoryFileUtils.nodeToFile(session, pentahoJcrConstants, pathConversionHelper, lockHelper, fileNode);
        }
    });
}
Also used : IRepositoryFileData(org.pentaho.platform.api.repository2.unified.IRepositoryFileData) DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) Node(javax.jcr.Node) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) JcrCallback(org.springframework.extensions.jcr.JcrCallback) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) Session(javax.jcr.Session)

Aggregations

NodeRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)47 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)37 DataNode (org.pentaho.platform.api.repository2.unified.data.node.DataNode)23 KettleException (org.pentaho.di.core.exception.KettleException)14 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)11 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)11 URISyntaxException (java.net.URISyntaxException)10 IdNotFoundException (org.pentaho.di.core.exception.IdNotFoundException)10 KettleFileException (org.pentaho.di.core.exception.KettleFileException)10 KettleSecurityException (org.pentaho.di.core.exception.KettleSecurityException)10 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)10 UnifiedRepositoryCreateFileException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryCreateFileException)10 UnifiedRepositoryUpdateFileException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryUpdateFileException)10 Test (org.junit.Test)9 Matchers.anyString (org.mockito.Matchers.anyString)8 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)7 ITenant (org.pentaho.platform.api.mt.ITenant)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5