use of org.pentaho.platform.api.repository2.unified.IRepositoryFileData in project pentaho-platform by pentaho.
the class RepositoryUtils method createFile.
/**
* Creates a new file that is known to not exist
*
* @param filePath
* the full path to the file
* @param data
* the data to be stored in the file
* @param createParentDirs
* indicates of the directory structure should be created if it doesn't exist
* @param versionMessage
* the version message
* @return the newly create {@code IRepositoryFile} or {@code null} if it couldn't be created
*/
protected RepositoryFile createFile(final String filePath, final IRepositoryFileData data, final boolean createParentDirs, final boolean versioned, final String versionMessage) {
final String path = RepositoryFilenameUtils.getFullPath(filePath);
final String filename = RepositoryFilenameUtils.getName(filePath);
final RepositoryFile parentDir = getFolder(path, createParentDirs, createParentDirs, versionMessage);
if (null == parentDir) {
return null;
}
return repository.createFile(parentDir.getId(), new RepositoryFile.Builder(filename).versioned(versioned).build(), data, versionMessage);
}
use of org.pentaho.platform.api.repository2.unified.IRepositoryFileData in project pentaho-platform by pentaho.
the class RepositoryFileHelper method getFileData.
public static IRepositoryFileData getFileData(RepositoryFile repositoryFile) {
IRepositoryContentConverterHandler converterHandler;
Map<String, Converter> converters;
IPlatformMimeResolver mimeResolver;
IRepositoryFileData repositoryFileData = null;
if (!repositoryFile.isFolder()) {
// Get the extension
final String ext = RepositoryFilenameUtils.getExtension(repositoryFile.getName());
if ((ext == null) || (ext.isEmpty())) {
return null;
}
// Find the converter
// If we have not been given a handler, try PentahoSystem
converterHandler = PentahoSystem.get(IRepositoryContentConverterHandler.class);
// fail if we have no converter handler
if (converterHandler == null) {
return null;
}
converters = converterHandler.getConverters();
final Converter converter = converters.get(ext);
if (converter == null) {
return null;
}
// Check the mime type
mimeResolver = PentahoSystem.get(IPlatformMimeResolver.class);
// fail if we have no mime resolver
if (mimeResolver == null) {
return null;
}
final String mimeType = mimeResolver.resolveMimeTypeForFileName(repositoryFile.getName()).getName();
if ((mimeType == null) || (mimeType.isEmpty())) {
return null;
}
// Get the input stream
InputStream inputStream = converter.convert(repositoryFile.getId());
if (inputStream == null) {
return null;
}
// Get the file data
repositoryFileData = converter.convert(inputStream, "UTF-8", mimeType);
if (repositoryFileData == null) {
return null;
}
}
return repositoryFileData;
}
use of org.pentaho.platform.api.repository2.unified.IRepositoryFileData in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryContentIT method testTransactionRollback.
/**
* Create a versioned file then update it with invalid data and the checkout that we did before setting the data
* should be rolled back.
*/
@Test
public void testTransactionRollback() 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.sample";
final String sampleString = "Ciao World!";
final boolean sampleBoolean = true;
final int sampleInteger = 99;
final String parentFolderPath = ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY);
final String expectedAbsolutePath = ServerRepositoryPaths.getTenantRootFolderPath() + parentFolderPath + RepositoryFile.SEPARATOR + expectedName;
RepositoryFile newFile = createSampleFile(parentFolderPath, expectedName, sampleString, sampleBoolean, sampleInteger, true);
assertNotNull(SimpleJcrTestUtils.getItem(testJcrTemplate, expectedAbsolutePath));
try {
repo.updateFile(newFile, new IRepositoryFileData() {
@Override
public long getDataSize() {
return 0;
}
}, null);
fail("expected UnifiedRepositoryException");
} catch (UnifiedRepositoryException e) {
// ignore
}
assertFalse(SimpleJcrTestUtils.isCheckedOut(testJcrTemplate, expectedAbsolutePath));
}
use of org.pentaho.platform.api.repository2.unified.IRepositoryFileData in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryContentIT method testCreateFileUnrecognizedContentType.
@Test(expected = UnifiedRepositoryException.class)
public void testCreateFileUnrecognizedContentType() 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 });
RepositoryFile parentFolder = repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY));
IRepositoryFileData content = new IRepositoryFileData() {
@Override
public long getDataSize() {
// TODO Auto-generated method stub
return 0;
}
};
repo.createFile(parentFolder.getId(), new RepositoryFile.Builder("helloworld.xaction").build(), content, null);
}
use of org.pentaho.platform.api.repository2.unified.IRepositoryFileData in project pentaho-platform by pentaho.
the class JcrRepositoryFileDaoIT method testUpdateFile1.
@Test
public // Running within defined date
void testUpdateFile1() throws Exception {
RepositoryFile newFile = createFile("JcrRepositoryFileDaoTest1.test");
IRepositoryFileData dataMock = new SampleRepositoryFileData("", true, 0);
Date startDate = new Date();
newFile = new RepositoryFile.Builder(newFile).createdDate(startDate).build();
repo.updateFile(newFile, dataMock, "edition #2");
List<VersionSummary> summaries = repo.getVersionSummaries(newFile.getId());
Date lastVersionDate = summaries.get(summaries.size() - 1).getDate();
assertEquals("incorrect version date", lastVersionDate, startDate);
}
Aggregations