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