Search in sources :

Example 1 with IModelAnnotationsAwareMetadataDomainRepositoryImporter

use of org.pentaho.platform.plugin.services.metadata.IModelAnnotationsAwareMetadataDomainRepositoryImporter in project pentaho-platform by pentaho.

the class MetadataImportHandler method processMetadataFile.

/**
 * Processes the file as a metadata file and returns the domain name. It will import the file into the Pentaho
 * Metadata Domain Repository.
 *
 * @param bundle
 * @return
 */
protected String processMetadataFile(final IPlatformImportBundle bundle) throws PlatformImportException {
    final String domainId = (String) bundle.getProperty("domain-id");
    if (domainId == null) {
        throw new PlatformImportException("Bundle missing required domain-id property");
    }
    try {
        log.debug("Importing as metadata - [domain=" + domainId + "]");
        final InputStream inputStream;
        if (bundle.isPreserveDsw()) {
            // storeDomain needs to be able to close the stream
            inputStream = cloneStream(bundle.getInputStream());
        } else {
            inputStream = StripDswFromStream(bundle.getInputStream());
        }
        if (metadataRepositoryImporter instanceof IAclAwarePentahoMetadataDomainRepositoryImporter) {
            IAclAwarePentahoMetadataDomainRepositoryImporter importer = (IAclAwarePentahoMetadataDomainRepositoryImporter) metadataRepositoryImporter;
            importer.storeDomain(inputStream, domainId, bundle.overwriteInRepository(), bundle.isApplyAclSettings() ? bundle.getAcl() : null);
        } else {
            metadataRepositoryImporter.storeDomain(inputStream, domainId, bundle.overwriteInRepository());
        }
        if (metadataRepositoryImporter instanceof IModelAnnotationsAwareMetadataDomainRepositoryImporter) {
            // Store annotations xml with the domain if it exists
            final String annotationsXml = (String) bundle.getProperty(IModelAnnotationsAwareMetadataDomainRepositoryImporter.PROPERTY_NAME_ANNOTATIONS);
            if (StringUtils.isNotBlank(annotationsXml)) {
                // Save annotations
                IModelAnnotationsAwareMetadataDomainRepositoryImporter importer = (IModelAnnotationsAwareMetadataDomainRepositoryImporter) metadataRepositoryImporter;
                importer.storeAnnotationsXml(domainId, annotationsXml);
            }
        }
        return domainId;
    } catch (DomainIdNullException dine) {
        throw new PlatformImportException(dine.getMessage(), PlatformImportException.PUBLISH_TO_SERVER_FAILED, dine);
    } catch (DomainStorageException dse) {
        throw new PlatformImportException(dse.getMessage(), PlatformImportException.PUBLISH_TO_SERVER_FAILED, dse);
    } catch (DomainAlreadyExistsException daee) {
        throw new PlatformImportException(messages.getString("PentahoPlatformImporter.ERROR_0007_PUBLISH_SCHEMA_EXISTS_ERROR"), PlatformImportException.PUBLISH_SCHEMA_EXISTS_ERROR, daee);
    } catch (Exception e) {
        final String errorMessage = messages.getErrorString("MetadataImportHandler.ERROR_0001_IMPORTING_METADATA", domainId, e.getLocalizedMessage());
        log.error(errorMessage, e);
        throw new PlatformImportException(errorMessage, e);
    }
}
Also used : DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) IModelAnnotationsAwareMetadataDomainRepositoryImporter(org.pentaho.platform.plugin.services.metadata.IModelAnnotationsAwareMetadataDomainRepositoryImporter) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) IAclAwarePentahoMetadataDomainRepositoryImporter(org.pentaho.platform.plugin.services.metadata.IAclAwarePentahoMetadataDomainRepositoryImporter) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 DomainAlreadyExistsException (org.pentaho.metadata.repository.DomainAlreadyExistsException)1 DomainIdNullException (org.pentaho.metadata.repository.DomainIdNullException)1 DomainStorageException (org.pentaho.metadata.repository.DomainStorageException)1 IAclAwarePentahoMetadataDomainRepositoryImporter (org.pentaho.platform.plugin.services.metadata.IAclAwarePentahoMetadataDomainRepositoryImporter)1 IModelAnnotationsAwareMetadataDomainRepositoryImporter (org.pentaho.platform.plugin.services.metadata.IModelAnnotationsAwareMetadataDomainRepositoryImporter)1