Search in sources :

Example 26 with IUnifiedRepository

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));
}
Also used : RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Matchers.anyString(org.mockito.Matchers.anyString) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Example 27 with IUnifiedRepository

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();
}
Also used : SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository)

Example 28 with IUnifiedRepository

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();
}
Also used : SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository)

Example 29 with IUnifiedRepository

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();
        }
    }
}
Also used : InputStream(java.io.InputStream) PentahoMetadataDomainRepository(org.pentaho.platform.plugin.services.metadata.PentahoMetadataDomainRepository) IOException(java.io.IOException) File(java.io.File) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) PlatformInitializationException(org.pentaho.platform.engine.core.system.boot.PlatformInitializationException) IOException(java.io.IOException) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) FileSystemBackedUnifiedRepository(org.pentaho.platform.repository2.unified.fs.FileSystemBackedUnifiedRepository) Test(org.junit.Test)

Example 30 with IUnifiedRepository

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"));
                }
            }
        }
    }
}
Also used : SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository)

Aggregations

IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)88 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)61 Test (org.junit.Test)51 Matchers.anyString (org.mockito.Matchers.anyString)37 ArrayList (java.util.ArrayList)18 List (java.util.List)10 StringObjectId (org.pentaho.di.repository.StringObjectId)10 Serializable (java.io.Serializable)9 DatabaseDialectService (org.pentaho.database.service.DatabaseDialectService)7 RepositoryFileTree (org.pentaho.platform.api.repository2.unified.RepositoryFileTree)7 DataNode (org.pentaho.platform.api.repository2.unified.data.node.DataNode)7 InputStream (java.io.InputStream)6 JobMeta (org.pentaho.di.job.JobMeta)6 SimpleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData)6 FileSystemBackedUnifiedRepository (org.pentaho.platform.repository2.unified.fs.FileSystemBackedUnifiedRepository)6 HashMap (java.util.HashMap)5 ObjectId (org.pentaho.di.repository.ObjectId)5 IDatasourceMgmtService (org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService)5 Properties (java.util.Properties)4 Log (org.apache.commons.logging.Log)4