use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.
the class ZipExportProcessorTest method testGetFixedZipEntryName.
@Test
public void testGetFixedZipEntryName() {
IUnifiedRepository repo = mock(IUnifiedRepository.class);
final String fileName = "eval (+)%.prpt";
final String filePath = "/home/test user/two words/eval (+)%.prpt";
String processorBasePath = "/home/test user";
ZipExportProcessor zipMF = new ZipExportProcessor(processorBasePath, repo, true);
ZipExportProcessor zipNoMF = new ZipExportProcessor(processorBasePath, repo, false);
String basePath = "/home/test user";
String simpleZipEntryName = "two words/eval (+)%.prpt";
String encodedZipEntryName = "two+words/eval+%28%2B%29%25.prpt";
RepositoryFile file = null;
file = new RepositoryFile.Builder(fileName).path(filePath).folder(false).build();
assertEquals(simpleZipEntryName, zipNoMF.getFixedZipEntryName(file, basePath));
assertEquals(encodedZipEntryName, zipMF.getFixedZipEntryName(file, basePath));
file = new RepositoryFile.Builder(fileName).path(filePath).folder(true).build();
assertEquals(simpleZipEntryName + "/", zipNoMF.getFixedZipEntryName(file, basePath));
assertEquals(encodedZipEntryName + "/", zipMF.getFixedZipEntryName(file, basePath));
basePath = "/";
simpleZipEntryName = "home/test user/two words/eval (+)%.prpt";
encodedZipEntryName = "home/test+user/two+words/eval+%28%2B%29%25.prpt";
file = new RepositoryFile.Builder(fileName).path(filePath).folder(false).build();
assertEquals(simpleZipEntryName, zipNoMF.getFixedZipEntryName(file, basePath));
assertEquals(encodedZipEntryName, zipMF.getFixedZipEntryName(file, basePath));
file = new RepositoryFile.Builder(fileName).path(filePath).folder(true).build();
assertEquals(simpleZipEntryName + "/", zipNoMF.getFixedZipEntryName(file, basePath));
assertEquals(encodedZipEntryName + "/", zipMF.getFixedZipEntryName(file, basePath));
basePath = "";
simpleZipEntryName = "home/test user/two words/eval (+)%.prpt";
encodedZipEntryName = "home/test+user/two+words/eval+%28%2B%29%25.prpt";
file = new RepositoryFile.Builder(fileName).path(filePath).folder(false).build();
assertEquals(simpleZipEntryName, zipNoMF.getFixedZipEntryName(file, basePath));
assertEquals(encodedZipEntryName, zipMF.getFixedZipEntryName(file, basePath));
file = new RepositoryFile.Builder(fileName).path(filePath).folder(true).build();
assertEquals(simpleZipEntryName + "/", zipNoMF.getFixedZipEntryName(file, basePath));
assertEquals(encodedZipEntryName + "/", zipMF.getFixedZipEntryName(file, basePath));
}
use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.
the class RepositoryFileReader method getEncoding.
protected static String getEncoding(RepositoryFile file) throws FileNotFoundException {
IUnifiedRepository repository = PentahoSystem.get(IUnifiedRepository.class);
SimpleRepositoryFileData fileData = repository.getDataForRead(file.getId(), SimpleRepositoryFileData.class);
return fileData.getEncoding();
}
use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.
the class RepositoryFileReader method getEncoding.
protected static String getEncoding(Serializable id) throws FileNotFoundException {
IUnifiedRepository repository = PentahoSystem.get(IUnifiedRepository.class);
RepositoryFile file = (new RepositoryFileInputStream(id)).getFile();
SimpleRepositoryFileData fileData = repository.getDataForRead(file.getId(), SimpleRepositoryFileData.class);
return fileData.getEncoding();
}
use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.
the class SolutionFolderIT method testNoLocaleFileDiscovery.
/**
* Tests MetadataDomainRepository.getLocalePropertyFilenames() where one xmi resource and no property file exists in
* the metadata folder.
*/
@Test
public void testNoLocaleFileDiscovery() {
PentahoMetadataDomainRepository domainRepository;
IUnifiedRepository repository = new FileSystemBackedUnifiedRepository();
repository = new FileSystemBackedUnifiedRepository(BI_DEVELOPERS_FULL_PATH);
domainRepository = new PentahoMetadataDomainRepository(repository);
File metadataXmiFile = null;
try {
metadataXmiFile = localeTestUtil.createFile(BI_DEVELOPERS_FULL_PATH, XMI_FILENAME_EXTENSION);
Map<String, InputStream> localizationFiles = domainRepository.getDomainFilesData("metadata");
assertEquals(0, localizationFiles.size());
} catch (IOException ioe) {
fail(ioe.getMessage());
} catch (Exception e) {
e.printStackTrace();
} finally {
if (metadataXmiFile != null) {
metadataXmiFile.delete();
}
}
}
use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.
the class QuartzScheduler method validateJobParams.
/**
* Checks if the text configuration for the input/output files is present.
* If not - silently returns. If present checks if the input file is allowed to be scheduled.
* @param jobParams scheduling job parameters
* @throws SchedulerException the configuration is recognized but the file can't be scheduled, is a folder or doesn't exist.
*/
@Override
public void validateJobParams(Map<String, Serializable> jobParams) throws SchedulerException {
final Object streamProviderObj = jobParams.get(RESERVEDMAPKEY_STREAMPROVIDER);
if (streamProviderObj instanceof String) {
String inputFilePath = null;
final String inputOutputString = (String) streamProviderObj;
final String[] tokens = inputOutputString.split(":");
if (!ArrayUtils.isEmpty(tokens) && tokens.length == 2) {
inputFilePath = tokens[0].split("=")[1].trim();
if (StringUtils.isNotBlank(inputFilePath)) {
final IUnifiedRepository repository = PentahoSystem.get(IUnifiedRepository.class);
final RepositoryFile repositoryFile = repository.getFile(inputFilePath);
if ((repositoryFile == null) || repositoryFile.isFolder() || !repositoryFile.isSchedulable()) {
throw new SchedulerException(Messages.getInstance().getString("QuartzScheduler.ERROR_0008_SCHEDULING_IS_NOT_ALLOWED"));
}
}
}
}
}
Aggregations