Search in sources :

Example 11 with IMetadataDomainRepository

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

the class MetadataService method listBusinessModels.

/**
 * Returns a list of the available business models
 *
 * @param domainName optional domain to limit the results
 * @return list of ModelInfo objects representing the available models
 * @throws IOException
 */
public ModelInfo[] listBusinessModels(String domainName) throws IOException {
    List<ModelInfo> models = new ArrayList<ModelInfo>();
    // get hold of the metadata repository
    IMetadataDomainRepository repo = getMetadataRepository();
    if (repo == null) {
        // $NON-NLS-1$
        error(Messages.getErrorString("MetadataService.ERROR_0001_BAD_REPO"));
        return null;
    }
    try {
        if (domainName == null) {
            // if no domain has been specified, loop over all of them
            for (String domain : getMetadataRepository().getDomainIds()) {
                getModelInfos(domain, models);
            }
        } else {
            // get the models for the specified domain
            getModelInfos(domainName, models);
        }
    } catch (Throwable t) {
        // $NON-NLS-1$
        error(Messages.getErrorString("MetadataService.ERROR_0002_BAD_MODEL_LIST"), t);
    }
    Collections.sort(models, new ModelInfoComparator());
    return models.toArray(new ModelInfo[models.size()]);
}
Also used : ModelInfo(org.pentaho.platform.dataaccess.metadata.model.impl.ModelInfo) ModelInfoComparator(org.pentaho.platform.dataaccess.metadata.model.impl.ModelInfoComparator) ArrayList(java.util.ArrayList) IMetadataDomainRepository(org.pentaho.metadata.repository.IMetadataDomainRepository)

Example 12 with IMetadataDomainRepository

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

the class MetadataServiceTest method initialize.

@Before
public void initialize() {
    List<Category> categoryList = new ArrayList();
    Category category = mock(Category.class);
    when(category.getId()).thenReturn(CATEGORY_ID);
    categoryList.add(category);
    LogicalColumn logicalColumn = mock(LogicalColumn.class);
    when(logicalColumn.getId()).thenReturn(COLUMN_ID);
    when(logicalColumn.getDataType()).thenReturn(DataType.STRING);
    when(category.findLogicalColumn(anyString())).thenReturn(logicalColumn);
    logicalModel = mock(LogicalModel.class);
    when(logicalModel.getId()).thenReturn(LOGICAL_MODEL_ID);
    when(logicalModel.getName(anyString())).thenReturn(LOGICAL_MODEL_NAME);
    when(logicalModel.getCategories()).thenReturn(categoryList);
    when(logicalModel.findLogicalColumn(anyString())).thenReturn(logicalColumn);
    when(logicalModel.getProperty(anyString())).thenReturn(null);
    logicalModel2 = mock(LogicalModel.class);
    when(logicalModel2.getId()).thenReturn(LOGICAL_MODEL_2_ID);
    when(logicalModel2.getName(anyString())).thenReturn(LOGICAL_MODEL_2_NAME);
    when(logicalModel2.getProperty(anyString())).thenReturn(null);
    Domain domainOnlyReportingModel = new Domain();
    domainOnlyReportingModel.setId(DOMAIN_ID);
    domainOnlyReportingModel.setLogicalModels(new ArrayList<LogicalModel>() {

        {
            add(logicalModel2);
        }

        {
            add(logicalModel);
        }
    });
    iMetadataDomainRepository = mock(IMetadataDomainRepository.class);
    when(iMetadataDomainRepository.getDomain(DOMAIN_ID)).thenReturn(domainOnlyReportingModel);
    Set<String> domains = new HashSet<String>();
    domains.add(DOMAIN_ID);
    when(iMetadataDomainRepository.getDomainIds()).thenReturn(domains);
    metadataService = mock(MetadataService.class);
    when(metadataService.getMetadataRepository()).thenReturn(iMetadataDomainRepository);
    metadataServiceUtil = mock(MetadataServiceUtil.class);
    when(metadataServiceUtil.getMetadataRepository()).thenReturn(iMetadataDomainRepository);
    when(metadataServiceUtil.createThinModel(any(LogicalModel.class), anyString())).thenCallRealMethod();
    when(metadataService.getMetadataServiceUtil()).thenReturn(metadataServiceUtil);
}
Also used : LogicalColumn(org.pentaho.metadata.model.LogicalColumn) Category(org.pentaho.metadata.model.Category) ArrayList(java.util.ArrayList) IMetadataDomainRepository(org.pentaho.metadata.repository.IMetadataDomainRepository) Matchers.anyString(org.mockito.Matchers.anyString) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) LogicalModel(org.pentaho.metadata.model.LogicalModel) Domain(org.pentaho.metadata.model.Domain) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 13 with IMetadataDomainRepository

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

the class ModelerService method serializeModels.

public String serializeModels(final Domain domain, final String name, final boolean doOlap) throws Exception {
    String domainId = null;
    initKettle();
    if (dataAccessPermHandler.hasDataAccessPermission(PentahoSessionHolder.getSession())) {
        SecurityHelper.getInstance().runAsSystem(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                try {
                    if (datasourceService == null) {
                        datasourceService = new DSWDatasourceServiceImpl();
                    }
                    ModelerWorkspace model = new ModelerWorkspace(new GwtModelerWorkspaceHelper(), datasourceService.getGeoContext());
                    model.setModelName(name);
                    model.setDomain(domain);
                    if (name.endsWith(".xmi")) {
                        domain.setId(name);
                    } else {
                        domain.setId(name + ".xmi");
                    }
                    LogicalModel lModel = model.getLogicalModel(ModelerPerspective.ANALYSIS);
                    if (lModel == null) {
                        lModel = model.getLogicalModel(ModelerPerspective.REPORTING);
                    }
                    lModel.setProperty("AGILE_BI_GENERATED_SCHEMA", "TRUE");
                    lModel.setProperty("WIZARD_GENERATED_SCHEMA", "TRUE");
                    String catName = lModel.getName(Locale.getDefault().toString());
                    // strip off the _olap suffix for the catalog ref
                    catName = catName.replace(BaseModelerWorkspaceHelper.OLAP_SUFFIX, "");
                    if (doOlap) {
                        // $NON-NLS-1$
                        lModel.setProperty("MondrianCatalogRef", catName);
                    }
                    // Stores metadata into JCR.
                    IMetadataDomainRepository metadataDomainRep = PentahoSystem.get(IMetadataDomainRepository.class);
                    if (metadataDomainRep != null) {
                        metadataDomainRep.storeDomain(model.getDomain(), true);
                    }
                    // Serialize domain to olap schema.
                    if (doOlap) {
                        MondrianModelExporter exporter = new MondrianModelExporter(lModel, Locale.getDefault().toString());
                        String mondrianSchema = exporter.createMondrianModelXML();
                        IPentahoSession session = PentahoSessionHolder.getSession();
                        if (session != null) {
                            // first remove the existing schema, including any
                            // model annotations which may have been previously applied
                            IMondrianCatalogService mondrianCatalogService = // $NON-NLS-1$
                            PentahoSystem.get(IMondrianCatalogService.class, "IMondrianCatalogService", session);
                            // try to get the current catalog
                            MondrianCatalog currentCatalog = mondrianCatalogService.getCatalog(catName, session);
                            // if current catalog exists, remove it
                            if (currentCatalog != null) {
                                mondrianCatalogService.removeCatalog(catName, session);
                            }
                            session.setAttribute("MONDRIAN_SCHEMA_XML_CONTENT", mondrianSchema);
                            // $NON-NLS-1$
                            String catConnectStr = "Provider=mondrian;DataSource=\"" + getMondrianDatasource(domain) + "\"";
                            addCatalog(catName, catConnectStr, session);
                        }
                    }
                } catch (Exception e) {
                    logger.error(e);
                    throw e;
                }
                return null;
            }
        });
    }
    return domainId;
}
Also used : MondrianCatalog(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) IMetadataDomainRepository(org.pentaho.metadata.repository.IMetadataDomainRepository) IMondrianCatalogService(org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService) KettleException(org.pentaho.di.core.exception.KettleException) GwtModelerWorkspaceHelper(org.pentaho.agilebi.modeler.gwt.GwtModelerWorkspaceHelper) LogicalModel(org.pentaho.metadata.model.LogicalModel) MondrianModelExporter(org.pentaho.metadata.util.MondrianModelExporter) ModelerWorkspace(org.pentaho.agilebi.modeler.ModelerWorkspace)

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