Search in sources :

Example 6 with PentahoMetadataDomainRepository

use of org.pentaho.platform.plugin.services.metadata.PentahoMetadataDomainRepository in project data-access by pentaho.

the class MetadataDatasourceService method storeDomain.

/**
 * @param metadataFile
 *          Input stream for the metadata.xmi
 * @param domainId
 *          Unique identifier for the metadata datasource
 *
 * @return Response containing the success of the method
 *
 * @throws PentahoAccessControlException
 *           Thrown when validation of access fails
 */
@PUT
@Path("/storeDomain")
@Consumes({ MediaType.APPLICATION_OCTET_STREAM, TEXT_PLAIN })
@Produces("text/plain")
@Facet(name = "Unsupported")
public Response storeDomain(InputStream metadataFile, @QueryParam("domainId") String domainId) throws PentahoAccessControlException {
    try {
        DatasourceService.validateAccess();
        PentahoMetadataDomainRepository metadataImporter = new PentahoMetadataDomainRepository(PentahoSystem.get(IUnifiedRepository.class));
        metadataImporter.storeDomain(metadataFile, domainId, true);
        return Response.ok("SUCCESS").type(MediaType.TEXT_PLAIN).build();
    } catch (PentahoAccessControlException e) {
        return Response.serverError().entity(e.toString()).build();
    } catch (Exception e) {
        return Response.serverError().entity(Messages.getString("MetadataDatasourceService.ERROR_001_METADATA_DATASOURCE_ERROR")).build();
    }
}
Also used : PentahoMetadataDomainRepository(org.pentaho.platform.plugin.services.metadata.PentahoMetadataDomainRepository) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Facet(org.codehaus.enunciate.Facet)

Example 7 with PentahoMetadataDomainRepository

use of org.pentaho.platform.plugin.services.metadata.PentahoMetadataDomainRepository in project data-access by pentaho.

the class MetadataDatasourceService method uploadServletImportMetadataDatasource.

/**
 * @param localizeBundleEntries
 * @param domainId
 *          Unique identifier for the metadata datasource
 * @param metadataFile
 *          Input stream for the metadata.xmi
 *
 * @return Response containing the success of the method
 *
 * @throws PentahoAccessControlException
 *           Thrown when validation of access fails
 */
@PUT
@Path("/uploadServletImport")
@Consumes({ TEXT_PLAIN })
@Produces("text/plain")
@Deprecated
@Facet(name = "Unsupported")
public Response uploadServletImportMetadataDatasource(String localizeBundleEntries, @QueryParam("domainId") String domainId, @QueryParam("metadataFile") String metadataFile) throws PentahoAccessControlException {
    try {
        DatasourceService.validateAccess();
    } catch (PentahoAccessControlException e) {
        return Response.serverError().entity(e.toString()).build();
    }
    IMetadataDomainRepository metadataDomainRepository = PentahoSystem.get(IMetadataDomainRepository.class, PentahoSessionHolder.getSession());
    PentahoMetadataDomainRepository metadataImporter = new PentahoMetadataDomainRepository(PentahoSystem.get(IUnifiedRepository.class));
    CsvUtils csvUtils = new CsvUtils();
    boolean validPropertyFiles = true;
    StringBuffer invalidFiles = new StringBuffer();
    try {
        String TMP_FILE_PATH = File.separatorChar + "system" + File.separatorChar + "tmp" + File.separatorChar;
        String sysTmpDir = PentahoSystem.getApplicationContext().getSolutionPath(TMP_FILE_PATH);
        FileInputStream metadataInputStream = new FileInputStream(sysTmpDir + File.separatorChar + metadataFile);
        metadataImporter.storeDomain(metadataInputStream, domainId, true);
        metadataDomainRepository.getDomain(domainId);
        StringTokenizer bundleEntriesParam = new StringTokenizer(localizeBundleEntries, ";");
        while (bundleEntriesParam.hasMoreTokens()) {
            String localizationBundleElement = bundleEntriesParam.nextToken();
            StringTokenizer localizationBundle = new StringTokenizer(localizationBundleElement, "=");
            String localizationFileName = localizationBundle.nextToken();
            String localizationFile = localizationBundle.nextToken();
            if (localizationFileName.endsWith(".properties")) {
                String encoding = csvUtils.getEncoding(localizationFile);
                if (ENCODINGS.contains(encoding)) {
                    for (final Pattern propertyBundlePattern : patterns) {
                        final Matcher propertyBundleMatcher = propertyBundlePattern.matcher(localizationFileName);
                        if (propertyBundleMatcher.matches()) {
                            FileInputStream bundleFileInputStream = new FileInputStream(sysTmpDir + File.separatorChar + localizationFile);
                            metadataImporter.addLocalizationFile(domainId, propertyBundleMatcher.group(2), bundleFileInputStream, true);
                            break;
                        }
                    }
                } else {
                    validPropertyFiles = false;
                    invalidFiles.append(localizationFileName);
                }
            } else {
                validPropertyFiles = false;
                invalidFiles.append(localizationFileName);
            }
        }
        if (!validPropertyFiles) {
            return Response.serverError().entity(Messages.getString("MetadataDatasourceService.ERROR_002_PROPERTY_FILES_ERROR") + invalidFiles.toString()).build();
        }
        return Response.ok("SUCCESS").type(MediaType.TEXT_PLAIN).build();
    } catch (Exception e) {
        metadataImporter.removeDomain(domainId);
        return Response.serverError().entity(Messages.getString("MetadataDatasourceService.ERROR_001_METADATA_DATASOURCE_ERROR")).build();
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) PentahoMetadataDomainRepository(org.pentaho.platform.plugin.services.metadata.PentahoMetadataDomainRepository) IMetadataDomainRepository(org.pentaho.metadata.repository.IMetadataDomainRepository) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) FileInputStream(java.io.FileInputStream) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) CsvUtils(org.pentaho.platform.dataaccess.datasource.wizard.csv.CsvUtils) StringTokenizer(java.util.StringTokenizer) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Facet(org.codehaus.enunciate.Facet)

Example 8 with PentahoMetadataDomainRepository

use of org.pentaho.platform.plugin.services.metadata.PentahoMetadataDomainRepository in project data-access by pentaho.

the class MetadataDatasourceService method addLocalizationFile.

/**
 * @param domainId
 *          Unique identifier for the metadata datasource
 * @param locale
 *          String value of the locale
 * @param propertiesFile
 *          Input stream of the properties file
 *
 * @return Response containing the success of the method
 *
 * @throws PentahoAccessControlException
 *           Thrown when validation of access fails
 */
@PUT
@Path("/addLocalizationFile")
@Consumes({ MediaType.APPLICATION_OCTET_STREAM, TEXT_PLAIN })
@Produces("text/plain")
@Facet(name = "Unsupported")
public Response addLocalizationFile(@QueryParam("domainId") String domainId, @QueryParam("locale") String locale, InputStream propertiesFile) throws PentahoAccessControlException {
    try {
        DatasourceService.validateAccess();
        PentahoMetadataDomainRepository metadataImporter = new PentahoMetadataDomainRepository(PentahoSystem.get(IUnifiedRepository.class));
        metadataImporter.addLocalizationFile(domainId, locale, propertiesFile, true);
        return Response.ok("SUCCESS").type(MediaType.TEXT_PLAIN).build();
    } catch (PentahoAccessControlException e) {
        return Response.serverError().entity(e.toString()).build();
    } catch (Exception e) {
        return Response.serverError().entity(Messages.getString("MetadataDatasourceService.ERROR_001_METADATA_DATASOURCE_ERROR")).build();
    }
}
Also used : PentahoMetadataDomainRepository(org.pentaho.platform.plugin.services.metadata.PentahoMetadataDomainRepository) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Facet(org.codehaus.enunciate.Facet)

Example 9 with PentahoMetadataDomainRepository

use of org.pentaho.platform.plugin.services.metadata.PentahoMetadataDomainRepository in project data-access by pentaho.

the class DatasourceResourceIT method createMetadataDomainRepository.

private static PentahoMetadataDomainRepository createMetadataDomainRepository() throws Exception {
    IUnifiedRepository repository = new FileSystemBackedUnifiedRepository("target/test-classes/dsw");
    mp.defineInstance(IUnifiedRepository.class, repository);
    Assert.assertNotNull(new RepositoryUtils(repository).getFolder("/etc/metadata", true, true, null));
    Assert.assertNotNull(new RepositoryUtils(repository).getFolder("/etc/mondrian", true, true, null));
    PentahoMetadataDomainRepository pentahoMetadataDomainRepository = new PentahoMetadataDomainRepository(repository);
    return pentahoMetadataDomainRepository;
}
Also used : RepositoryUtils(org.pentaho.platform.repository2.unified.RepositoryUtils) PentahoMetadataDomainRepository(org.pentaho.platform.plugin.services.metadata.PentahoMetadataDomainRepository) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) FileSystemBackedUnifiedRepository(org.pentaho.platform.repository2.unified.fs.FileSystemBackedUnifiedRepository)

Example 10 with PentahoMetadataDomainRepository

use of org.pentaho.platform.plugin.services.metadata.PentahoMetadataDomainRepository in project data-access by pentaho.

the class MetadataServiceTest method testGetMetadataDatasourceAcl.

@Test
public void testGetMetadataDatasourceAcl() throws Exception {
    String domainId = DOMAIN_ID;
    final RepositoryFileAcl acl = new RepositoryFileAcl.Builder("owner").build();
    doReturn(true).when(metadataService).canManageACL();
    when(metadataService.aclAwarePentahoMetadataDomainRepositoryImporter.getAclFor(domainId)).thenReturn(acl);
    final Map<String, InputStream> domainFilesData = mock(Map.class);
    when(domainFilesData.isEmpty()).thenReturn(false);
    when(((PentahoMetadataDomainRepository) metadataService.metadataDomainRepository).getDomainFilesData(domainId)).thenReturn(domainFilesData);
    final RepositoryFileAclDto aclDto = metadataService.getMetadataAcl(domainId);
    verify(metadataService.aclAwarePentahoMetadataDomainRepositoryImporter).getAclFor(eq(domainId));
    assertEquals(acl, new RepositoryFileAclAdapter().unmarshal(aclDto));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) StringInputStream(org.apache.tools.ant.filters.StringInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) PentahoMetadataDomainRepository(org.pentaho.platform.plugin.services.metadata.PentahoMetadataDomainRepository) Matchers.anyString(org.mockito.Matchers.anyString) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) RepositoryFileAclAdapter(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclAdapter) Test(org.junit.Test)

Aggregations

PentahoMetadataDomainRepository (org.pentaho.platform.plugin.services.metadata.PentahoMetadataDomainRepository)11 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)7 FileInputStream (java.io.FileInputStream)5 InputStream (java.io.InputStream)5 Test (org.junit.Test)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 StringInputStream (org.apache.tools.ant.filters.StringInputStream)4 Matchers.anyString (org.mockito.Matchers.anyString)4 FileSystemBackedUnifiedRepository (org.pentaho.platform.repository2.unified.fs.FileSystemBackedUnifiedRepository)4 Facet (org.codehaus.enunciate.Facet)3 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)3 RepositoryUtils (org.pentaho.platform.repository2.unified.RepositoryUtils)3 RepositoryFileAclDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto)3 RepositoryFileAclAdapter (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclAdapter)2 File (java.io.File)1 IOException (java.io.IOException)1 StringTokenizer (java.util.StringTokenizer)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 DomainStorageException (org.pentaho.metadata.repository.DomainStorageException)1