Search in sources :

Example 1 with SimpleRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData in project pentaho-platform by pentaho.

the class StreamConverter method convert.

public InputStream convert(final Serializable fileId) {
    InputStream stream = null;
    if (repository != null) {
        SimpleRepositoryFileData fileData = repository.getDataForRead(fileId, SimpleRepositoryFileData.class);
        stream = fileData.getStream();
    }
    return stream;
}
Also used : SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) InputStream(java.io.InputStream)

Example 2 with SimpleRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData in project pentaho-platform by pentaho.

the class DefaultUnifiedRepositoryWebServiceTest method testFileMetadata.

public void testFileMetadata() throws Exception {
    final RepositoryFile testfile = repository.createFile(repository.getFile("/etc").getId(), new RepositoryFile.Builder("testfile").build(), new SimpleRepositoryFileData(new ByteArrayInputStream("test".getBytes()), "UTF-8", "text/plain"), null);
    // CHECKSTYLE IGNORE AvoidNestedBlocks FOR NEXT 3 LINES
    {
        // Make sure the repository is setup correctly
        assertNotNull(testfile);
        assertNotNull(testfile.getId());
        final Map<String, Serializable> fileMetadata = repository.getFileMetadata(testfile.getId());
        assertNotNull(fileMetadata);
        assertEquals(0, fileMetadata.size());
    }
    final List<StringKeyStringValueDto> metadata = new ArrayList<StringKeyStringValueDto>();
    metadata.add(new StringKeyStringValueDto("sample key", "sample value"));
    metadata.add(new StringKeyStringValueDto("complex key?", "\"an even more 'complex' value\"! {and them some}"));
    repositoryWS.setFileMetadata(testfile.getId().toString(), metadata);
    // CHECKSTYLE IGNORE AvoidNestedBlocks FOR NEXT 3 LINES
    {
        // Make sure the repository sees the metadata
        assertNotNull(testfile);
        assertNotNull(testfile.getId());
        final Map<String, Serializable> fileMetadata = repository.getFileMetadata(testfile.getId());
        assertNotNull(fileMetadata);
        assertEquals(2, fileMetadata.size());
    }
    // CHECKSTYLE IGNORE AvoidNestedBlocks FOR NEXT 3 LINES
    {
        // Make sure we can get the same metadata back via the web service
        final List<StringKeyStringValueDto> fileMetadata = repositoryWS.getFileMetadata(testfile.getId().toString());
        assertNotNull(fileMetadata);
        assertEquals(2, fileMetadata.size());
        assertTrue(metadata.get(0).equals(fileMetadata.get(0)) || metadata.get(0).equals(fileMetadata.get(1)));
        assertTrue(metadata.get(1).equals(fileMetadata.get(0)) || metadata.get(1).equals(fileMetadata.get(1)));
    }
}
Also used : SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 3 with SimpleRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData in project pentaho-platform by pentaho.

the class PentahoMetadataDomainRepository method loadAnnotationsXml.

@Override
public String loadAnnotationsXml(final String domainId) {
    if (StringUtils.isBlank(domainId)) {
        // exit early
        return null;
    }
    try {
        final RepositoryFile domainFile = getMetadataRepositoryFile(domainId);
        final RepositoryFile annotationFile = getRepository().getFile(resolveAnnotationsFilePath(domainFile));
        // Load referenced annotations xml repo file
        SimpleRepositoryFileData data = getRepository().getDataForRead(annotationFile.getId(), SimpleRepositoryFileData.class);
        // return as String
        return IOUtils.toString(data.getInputStream());
    } catch (Exception e) {
        getLogger().warn("Unable to load annotations xml file for domain: " + domainId);
    }
    return null;
}
Also used : SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) IOException(java.io.IOException)

Example 4 with SimpleRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData in project pentaho-platform by pentaho.

the class PentahoMetadataDomainRepository method loadProperties.

protected Properties loadProperties(final RepositoryFile bundle) {
    try {
        Properties properties = null;
        final SimpleRepositoryFileData bundleData = repository.getDataForRead(bundle.getId(), SimpleRepositoryFileData.class);
        if (bundleData != null) {
            properties = new Properties();
            properties.load(bundleData.getStream());
        } else {
            if (logger.isWarnEnabled()) {
                logger.warn("Could not load properties from repository file: " + bundle.getName());
            }
        }
        return properties;
    } catch (IOException e) {
        throw new UnifiedRepositoryException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0008_ERROR_IN_REPOSITORY", e.getLocalizedMessage()), e);
    }
}
Also used : SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) IOException(java.io.IOException) Properties(java.util.Properties)

Example 5 with SimpleRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData in project pentaho-platform by pentaho.

the class PentahoMetadataDomainRepository method getDomain.

/**
 * retrieve a domain from the repo. This does lazy loading of the repo, so it calls reloadDomains() if not already
 * loaded.
 *
 * @param domainId domain to get from the repository
 * @return domain object
 */
@Override
public Domain getDomain(final String domainId) {
    if (logger.isDebugEnabled()) {
        logger.debug("getDomain(" + domainId + ")");
    }
    if (StringUtils.isEmpty(domainId)) {
        throw new IllegalArgumentException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0004_DOMAIN_ID_INVALID", domainId));
    }
    Domain domain = null;
    try {
        // Load the domain file
        final RepositoryFile file = getMetadataRepositoryFile(domainId);
        if (file != null) {
            if (hasAccessFor(file)) {
                SimpleRepositoryFileData data = repository.getDataForRead(file.getId(), SimpleRepositoryFileData.class);
                if (data != null) {
                    InputStream is = data.getStream();
                    try {
                        domain = xmiParser.parseXmi(is);
                    } finally {
                        IOUtils.closeQuietly(is);
                    }
                    domain.setId(domainId);
                    logger.debug("loaded domain");
                    // Load any I18N bundles
                    loadLocaleStrings(domainId, domain);
                    logger.debug("loaded I18N bundles");
                } else {
                    throw new UnifiedRepositoryException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0005_ERROR_RETRIEVING_DOMAIN", domainId, "data not found"));
                }
            } else {
                throw new PentahoAccessControlException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0005_ERROR_RETRIEVING_DOMAIN", domainId, "access denied"));
            }
        }
    } catch (Exception e) {
        if (!(e instanceof UnifiedRepositoryException || e instanceof PentahoAccessControlException)) {
            throw new UnifiedRepositoryException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0005_ERROR_RETRIEVING_DOMAIN", domainId, e.getLocalizedMessage()), e);
        }
    }
    // Return
    return domain;
}
Also used : SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) ByteArrayInputStream(java.io.ByteArrayInputStream) RepositoryFileInputStream(org.pentaho.platform.repository2.unified.fileio.RepositoryFileInputStream) InputStream(java.io.InputStream) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Domain(org.pentaho.metadata.model.Domain) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) IOException(java.io.IOException)

Aggregations

SimpleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData)58 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)43 ByteArrayInputStream (java.io.ByteArrayInputStream)31 Test (org.junit.Test)25 Matchers.anyString (org.mockito.Matchers.anyString)18 ITenant (org.pentaho.platform.api.mt.ITenant)17 InputStream (java.io.InputStream)16 IOException (java.io.IOException)14 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)12 Serializable (java.io.Serializable)10 File (java.io.File)9 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)9 FileNotFoundException (java.io.FileNotFoundException)5 DomainStorageException (org.pentaho.metadata.repository.DomainStorageException)5 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)5 VersionSummary (org.pentaho.platform.api.repository2.unified.VersionSummary)5 FileOutputStream (java.io.FileOutputStream)4 DomainAlreadyExistsException (org.pentaho.metadata.repository.DomainAlreadyExistsException)4 DomainIdNullException (org.pentaho.metadata.repository.DomainIdNullException)4 RepositoryRequest (org.pentaho.platform.api.repository2.unified.RepositoryRequest)4