Search in sources :

Example 6 with IMetadataDomainRepository

use of org.pentaho.metadata.repository.IMetadataDomainRepository 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 7 with IMetadataDomainRepository

use of org.pentaho.metadata.repository.IMetadataDomainRepository in project pentaho-platform by pentaho.

the class PentahoPlatformExporterTest method testExportMetadata.

@Test
public void testExportMetadata() throws Exception {
    IMetadataDomainRepository mdr = mock(IMetadataDomainRepository.class);
    Set<String> domainIds = new HashSet<>();
    domainIds.add("test1");
    when(mdr.getDomainIds()).thenReturn(domainIds);
    exporterSpy.setMetadataDomainRepository(mdr);
    exporterSpy.zos = mock(ZipOutputStream.class);
    Map<String, InputStream> inputMap = new HashMap<>();
    InputStream is = mock(InputStream.class);
    when(is.read(any((new byte[] {}).getClass()))).thenReturn(-1);
    inputMap.put("test1", is);
    doReturn(inputMap).when(exporterSpy).getDomainFilesData("test1");
    exporterSpy.exportMetadataModels();
    assertEquals(1, exporterSpy.getExportManifest().getMetadataList().size());
    assertEquals("test1", exporterSpy.getExportManifest().getMetadataList().get(0).getDomainId());
    assertEquals(PentahoPlatformExporter.METADATA_PATH_IN_ZIP + "test1.xmi", exporterSpy.getExportManifest().getMetadataList().get(0).getFile());
}
Also used : HashMap(java.util.HashMap) ZipOutputStream(java.util.zip.ZipOutputStream) InputStream(java.io.InputStream) IMetadataDomainRepository(org.pentaho.metadata.repository.IMetadataDomainRepository) Mockito.anyString(org.mockito.Mockito.anyString) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with IMetadataDomainRepository

use of org.pentaho.metadata.repository.IMetadataDomainRepository in project pentaho-platform by pentaho.

the class PentahoPlatformExporterTest method testExportMetadata_noModels.

@Test
public void testExportMetadata_noModels() throws Exception {
    IMetadataDomainRepository mdr = mock(IMetadataDomainRepository.class);
    exporter.setMetadataDomainRepository(mdr);
    exporter.exportMetadataModels();
    assertEquals(0, exporter.getExportManifest().getMetadataList().size());
}
Also used : IMetadataDomainRepository(org.pentaho.metadata.repository.IMetadataDomainRepository) Test(org.junit.Test)

Example 9 with IMetadataDomainRepository

use of org.pentaho.metadata.repository.IMetadataDomainRepository in project pentaho-platform by pentaho.

the class MetadataQueryComponentIT method setUp.

@Before
public void setUp() throws Exception {
    microPlatform = new MicroPlatform(TestResourceLocation.TEST_RESOURCES + "/solution");
    microPlatform.define(ISolutionEngine.class, SolutionEngine.class);
    microPlatform.define(IMetadataDomainRepository.class, InMemoryMetadataDomainRepository.class, Scope.GLOBAL);
    microPlatform.define("connection-SQL", SQLConnection.class);
    microPlatform.define(IUnifiedRepository.class, FileSystemBackedUnifiedRepository.class, Scope.GLOBAL);
    FileSystemBackedUnifiedRepository repos = (FileSystemBackedUnifiedRepository) PentahoSystem.get(IUnifiedRepository.class);
    repos.setRootDir(new File(TestResourceLocation.TEST_RESOURCES + "/solution"));
    microPlatform.define(IDBDatasourceService.class, JndiDatasourceService.class, Scope.GLOBAL);
    KettleEnvironment.init(false);
    IMetadataDomainRepository repo = PentahoSystem.get(IMetadataDomainRepository.class, null);
    Domain domain = getBasicDomain();
    Domain domain2 = getJdbcDomain();
    Domain domain3 = getJdbcDomain();
    domain3.setId("JDBCDOMAIN2");
    domain3.getLogicalModels().get(0).setProperty("max_rows", new BigDecimal(10));
    Domain domain4 = getBasicDomain();
    ((SqlPhysicalModel) domain4.getPhysicalModels().get(0)).getDatasource().setDialectType("MYSQL");
    Map<String, String> attributes = new HashMap<String, String>();
    attributes.put("QUOTE_ALL_FIELDS", "Y");
    ((SqlPhysicalModel) domain4.getPhysicalModels().get(0)).getDatasource().setAttributes(attributes);
    domain4.setId("MYSQL_DOMAIN");
    repo.storeDomain(domain, true);
    repo.storeDomain(domain2, true);
    repo.storeDomain(domain3, true);
    repo.storeDomain(domain4, true);
    // JNDI
    // $NON-NLS-1$ //$NON-NLS-2$
    System.setProperty("java.naming.factory.initial", "org.osjava.sj.SimpleContextFactory");
    // $NON-NLS-1$ //$NON-NLS-2$
    System.setProperty("org.osjava.sj.root", TestResourceLocation.TEST_RESOURCES + "/solution/system/simple-jndi");
    // $NON-NLS-1$ //$NON-NLS-2$
    System.setProperty("org.osjava.sj.delimiter", "/");
}
Also used : HashMap(java.util.HashMap) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) IMetadataDomainRepository(org.pentaho.metadata.repository.IMetadataDomainRepository) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) Domain(org.pentaho.metadata.model.Domain) File(java.io.File) BigDecimal(java.math.BigDecimal) FileSystemBackedUnifiedRepository(org.pentaho.platform.repository2.unified.fs.FileSystemBackedUnifiedRepository) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Before(org.junit.Before)

Example 10 with IMetadataDomainRepository

use of org.pentaho.metadata.repository.IMetadataDomainRepository in project data-access by pentaho.

the class MetadataService method getModelInfos.

/**
 * Returns a list of ModelInfo objects for the specified domain. These objects are small and this list is intended to
 * allow a client to provide a list of models to a user so the user can pick which one they want to work with.
 *
 * @param domain
 * @param models
 */
private void getModelInfos(final String domain, List<ModelInfo> models) {
    IMetadataDomainRepository repo = getMetadataRepository();
    Domain domainObject = repo.getDomain(domain);
    // find the best locale
    String locale = LocaleHelper.getClosestLocale(LocaleHelper.getLocale().toString(), domainObject.getLocaleCodes());
    // iterate over all of the models in this domain
    for (LogicalModel model : domainObject.getLogicalModels()) {
        // create a new ModelInfo object and give it the envelope information about the model
        ModelInfo modelInfo = new ModelInfo();
        modelInfo.setDomainId(domain);
        modelInfo.setModelId(model.getId());
        modelInfo.setModelName(model.getName(locale));
        if (model.getDescription() != null) {
            String modelDescription = model.getDescription(locale);
            modelInfo.setModelDescription(modelDescription);
        }
        models.add(modelInfo);
    }
    return;
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) ModelInfo(org.pentaho.platform.dataaccess.metadata.model.impl.ModelInfo) IMetadataDomainRepository(org.pentaho.metadata.repository.IMetadataDomainRepository) Domain(org.pentaho.metadata.model.Domain)

Aggregations

IMetadataDomainRepository (org.pentaho.metadata.repository.IMetadataDomainRepository)13 Domain (org.pentaho.metadata.model.Domain)5 LogicalModel (org.pentaho.metadata.model.LogicalModel)5 LocalizedString (org.pentaho.metadata.model.concept.types.LocalizedString)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Before (org.junit.Before)2 Test (org.junit.Test)2 LogicalColumn (org.pentaho.metadata.model.LogicalColumn)2 QueryXmlHelper (org.pentaho.metadata.query.model.util.QueryXmlHelper)2 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)2 ModelInfo (org.pentaho.platform.dataaccess.metadata.model.impl.ModelInfo)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 BigDecimal (java.math.BigDecimal)1 Properties (java.util.Properties)1 StringTokenizer (java.util.StringTokenizer)1 Matcher (java.util.regex.Matcher)1