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;
}
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;
}
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();
}
}
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);
}
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);
}
Aggregations