Search in sources :

Example 26 with IRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.IRepositoryFileData in project pentaho-platform by pentaho.

the class DefaultUnifiedRepository method getDataForReadInBatch.

/**
 * {@inheritDoc}
 */
public <T extends IRepositoryFileData> List<T> getDataForReadInBatch(final List<RepositoryFile> files, final Class<T> dataClass) {
    Assert.notNull(files);
    List<T> data = new ArrayList<T>(files.size());
    for (RepositoryFile f : files) {
        Assert.notNull(f);
        data.add(getDataAtVersionForRead(f.getId(), f.getVersionId(), dataClass));
    }
    return data;
}
Also used : ArrayList(java.util.ArrayList) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 27 with IRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.IRepositoryFileData in project pentaho-platform by pentaho.

the class RepositoryUtils method getFile.

/**
 * Returns the specified file from the current repository. If it can not be found, it will optionally be created.
 * The missing parent folders can also be created if needed.
 *
 * @param path
 *          the full path to the requested file in the repository
 * @param data
 *          the data to put in the file if it does not exist ... use {@code null} at your discretion
 * @param createIfNotExist
 *          {@code true} indicates the file will be created if it doesn't exist
 * @param createParents
 *          {@code true} indicates that any missing parent folders will be created if they do not exist
 * @param versionMessage
 *          the message used if the file or any folders are created
 * @return the {@link RepositoryFile} of the request file, or {@code null} if it does not exist and the
 *         parameters do not allow for it to be created
 */
public RepositoryFile getFile(final String path, final IRepositoryFileData data, final boolean createIfNotExist, final boolean createParents, final String versionMessage) {
    // Get the requested folder
    RepositoryFile file = repository.getFile(path);
    if (null == file && createIfNotExist) {
        final String parentFolderName = RepositoryFilenameUtils.getFullPathNoEndSeparator(path);
        final RepositoryFile parentFolder = getFolder(parentFolderName, createParents, createParents, versionMessage);
        if (null != parentFolder) {
            final String fileName = RepositoryFilenameUtils.getName(path);
            file = new RepositoryFile.Builder(fileName).folder(false).build();
            file = repository.createFile(parentFolder.getId(), file, data, versionMessage);
        }
    }
    return file;
}
Also used : RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 28 with IRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.IRepositoryFileData in project pentaho-platform by pentaho.

the class UnifiedRepositoryToWebServiceAdapter method getDataForReadInBatch.

@Override
@SuppressWarnings("unchecked")
public <T extends IRepositoryFileData> java.util.List<T> getDataForReadInBatch(final List<RepositoryFile> files, final Class<T> dataClass) {
    List<RepositoryFileDto> fileDtos = new ArrayList<RepositoryFileDto>(files.size());
    for (RepositoryFile file : files) {
        fileDtos.add(repositoryFileAdapter.marshal(file));
    }
    if (dataClass.equals(NodeRepositoryFileData.class)) {
        List<NodeRepositoryFileDataDto> nodeData = repoWebService.getDataAsNodeForReadInBatch(fileDtos);
        List<T> data = new ArrayList<T>(nodeData.size());
        for (NodeRepositoryFileDataDto node : nodeData) {
            data.add((T) nodeRepositoryFileDataAdapter.unmarshal(node));
        }
        return data;
    } else if (dataClass.equals(SimpleRepositoryFileData.class)) {
        List<SimpleRepositoryFileDataDto> nodeData = repoWebService.getDataAsBinaryForReadInBatch(fileDtos);
        List<T> data = new ArrayList<T>(nodeData.size());
        for (SimpleRepositoryFileDataDto node : nodeData) {
            data.add((T) SimpleRepositoryFileDataDto.convert(node));
        }
        return data;
    } else {
        throw new IllegalArgumentException();
    }
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) NodeRepositoryFileDataDto(org.pentaho.platform.repository2.unified.webservices.NodeRepositoryFileDataDto) ArrayList(java.util.ArrayList) SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) ArrayList(java.util.ArrayList) List(java.util.List)

Example 29 with IRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.IRepositoryFileData in project pentaho-platform by pentaho.

the class RepositoryFileOutputStreamTest method convertTest.

@Test
public void convertTest() throws Exception {
    RepositoryFileOutputStream spy = Mockito.spy(new RepositoryFileOutputStream("1.ktr", "UTF-8"));
    Converter converter = Mockito.mock(Converter.class);
    ByteArrayInputStream bis = Mockito.mock(ByteArrayInputStream.class);
    Mockito.doReturn(Mockito.mock(NodeRepositoryFileData.class)).when(converter).convert(bis, "UTF-8", "");
    IRepositoryFileData data = spy.convert(null, bis, "");
    Assert.assertTrue(data instanceof SimpleRepositoryFileData);
    data = spy.convert(converter, bis, "");
    Assert.assertTrue(data instanceof NodeRepositoryFileData);
}
Also used : IRepositoryFileData(org.pentaho.platform.api.repository2.unified.IRepositoryFileData) ByteArrayInputStream(java.io.ByteArrayInputStream) SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) Converter(org.pentaho.platform.api.repository2.unified.Converter) Test(org.junit.Test)

Example 30 with IRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.IRepositoryFileData in project pentaho-platform by pentaho.

the class JcrRepositoryFileDaoTest method setUp.

@Before
public void setUp() throws RepositoryException {
    Node node = mock(Node.class);
    Node nodeParent = mock(Node.class);
    when(node.getIdentifier()).thenReturn("");
    when(nodeParent.getIdentifier()).thenReturn("");
    when(node.getParent()).thenReturn(nodeParent);
    when(node.isNodeType("null:pentahoFile")).thenReturn(true);
    when(node.isNodeType("null:pentahoVersionable")).thenReturn(true);
    VersionManagerImpl versionManager = mock(VersionManagerImpl.class);
    Workspace workspace = mock(Workspace.class);
    when(workspace.getVersionManager()).thenReturn(versionManager);
    Session session = mock(Session.class);
    when(session.getWorkspace()).thenReturn(workspace);
    when(session.getNodeByIdentifier(anyString())).thenReturn(node);
    when(session.getItem(anyString())).thenReturn(node);
    pentahoSession = mock(IPentahoSession.class);
    PentahoSessionHolder.setSession(pentahoSession);
    IRepositoryVersionManager repositoryVersionManager = mock(IRepositoryVersionManager.class);
    when(repositoryVersionManager.isVersioningEnabled(anyString())).thenReturn(true);
    PentahoSystem.registerObject(repositoryVersionManager);
    JcrTemplate jcrTemplate = new JcrTemplate() {

        @Override
        public Object execute(JcrCallback callback) throws DataAccessException {
            try {
                return callback.doInJcr(session);
            } catch (Exception e) {
                // wrapping exception to comply overriding rules
                throw new RuntimeException(e);
            }
        }
    };
    List<ITransformer<IRepositoryFileData>> transformerList = Collections.emptyList();
    IPathConversionHelper pathConversionHelper = new DefaultPathConversionHelper();
    IRepositoryFileAclDao aclDao = mock(IRepositoryFileAclDao.class);
    accessVoterManager = mock(IRepositoryAccessVoterManager.class);
    JcrRepositoryFileDao jcrDao = new JcrRepositoryFileDao(jcrTemplate, transformerList, null, null, pathConversionHelper, aclDao, null, accessVoterManager);
    dao = spy(jcrDao);
}
Also used : JcrTemplate(org.springframework.extensions.jcr.JcrTemplate) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Node(javax.jcr.Node) JcrCallback(org.springframework.extensions.jcr.JcrCallback) IRepositoryFileAclDao(org.pentaho.platform.repository2.unified.IRepositoryFileAclDao) IRepositoryVersionManager(org.pentaho.platform.api.repository2.unified.IRepositoryVersionManager) DataAccessException(org.springframework.dao.DataAccessException) AccessDeniedException(javax.jcr.AccessDeniedException) RepositoryException(javax.jcr.RepositoryException) VersionManagerImpl(org.apache.jackrabbit.core.VersionManagerImpl) IRepositoryAccessVoterManager(org.pentaho.platform.api.repository2.unified.IRepositoryAccessVoterManager) Workspace(javax.jcr.Workspace) Session(javax.jcr.Session) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Before(org.junit.Before)

Aggregations

RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)23 IRepositoryFileData (org.pentaho.platform.api.repository2.unified.IRepositoryFileData)16 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)9 Test (org.junit.Test)6 NodeRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 File (java.io.File)5 SimpleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData)5 FileNotFoundException (java.io.FileNotFoundException)4 Serializable (java.io.Serializable)4 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 Converter (org.pentaho.platform.api.repository2.unified.Converter)4 FileOutputStream (java.io.FileOutputStream)3 IOException (java.io.IOException)3 List (java.util.List)3 Node (javax.jcr.Node)3 Session (javax.jcr.Session)3 Matchers.anyString (org.mockito.Matchers.anyString)3 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)3