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();
}
}
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());
}
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());
}
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", "/");
}
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;
}
Aggregations