Search in sources :

Example 21 with LogicalModel

use of org.pentaho.metadata.model.LogicalModel in project data-access by pentaho.

the class InlineSqlModelerSource method serializeIntoDomain.

public void serializeIntoDomain(Domain d) {
    LogicalModel lm = d.getLogicalModels().get(0);
    // $NON-NLS-1$
    lm.setProperty("source_type", SOURCE_TYPE);
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel)

Example 22 with LogicalModel

use of org.pentaho.metadata.model.LogicalModel in project data-access by pentaho.

the class MetadataServiceUtil method convertQuery.

/**
 * Converts a thin query model into a full query
 *
 * @param src
 * @return
 */
public org.pentaho.metadata.query.model.Query convertQuery(Query src) {
    IMetadataDomainRepository domainRepository = getMetadataRepository();
    Domain fullDomain = domainRepository.getDomain(src.getDomainName());
    LogicalModel logicalModel = fullDomain.findLogicalModel(src.getModelId());
    // create a new full query object
    org.pentaho.metadata.query.model.Query dest = new org.pentaho.metadata.query.model.Query(fullDomain, logicalModel);
    // now add the selections
    List<Selection> selections = dest.getSelections();
    for (Column column : src.getColumns()) {
        // get the objects needed for the selection
        LogicalColumn logicalColumn = logicalModel.findLogicalColumn(column.getId());
        org.pentaho.metadata.model.Category category = getCategory(column.getId(), logicalModel);
        AggregationType aggregationType = AggregationType.valueOf(column.getSelectedAggType());
        // create a selection and add it to the list
        Selection selection = new Selection(category, logicalColumn, aggregationType);
        selections.add(selection);
    }
    // now add the filters
    List<Constraint> constraints = dest.getConstraints();
    for (Condition condition : src.getConditions()) {
        org.pentaho.metadata.query.model.CombinationType combinationType = CombinationType.valueOf(condition.getCombinationType());
        LogicalColumn logicalColumn = logicalModel.findLogicalColumn(condition.getColumn());
        String paramName = null;
        for (Parameter parameter : src.getParameters()) {
            if (parameter.getColumn().equals(condition.getColumn())) {
                paramName = parameter.getName() == null ? parameter.getColumn() : parameter.getName();
            }
        }
        // condition.setParameterized(parameterized);
        String formula = condition.getCondition(logicalColumn.getDataType().name(), paramName);
        Constraint constraint = new Constraint(combinationType, formula);
        constraints.add(constraint);
    }
    // now set the disable distinct option
    if (src.getDisableDistinct() != null) {
        dest.setDisableDistinct(src.getDisableDistinct());
    }
    // now add the sorting information
    List<org.pentaho.metadata.query.model.Order> orders = dest.getOrders();
    for (Order order : src.getOrders()) {
        // find the selection
        for (Selection selection : selections) {
            if (selection.getLogicalColumn().getId().equals(order.getColumn())) {
                Type type = Type.valueOf(order.getOrderType());
                org.pentaho.metadata.query.model.Order fullOrder = new org.pentaho.metadata.query.model.Order(selection, type);
                orders.add(fullOrder);
            }
        }
    }
    // now add the parameter information
    List<org.pentaho.metadata.query.model.Parameter> parameters = dest.getParameters();
    for (Parameter parameter : src.getParameters()) {
        // find the column for this parameter
        LogicalColumn logicalColumn = logicalModel.findLogicalColumn(parameter.getColumn());
        DataType type = logicalColumn.getDataType();
        String[] value = parameter.getValue();
        org.pentaho.metadata.query.model.Parameter fullParam = new org.pentaho.metadata.query.model.Parameter(parameter.getColumn(), type, value[0]);
        parameters.add(fullParam);
    }
    return dest;
}
Also used : LogicalColumn(org.pentaho.metadata.model.LogicalColumn) Query(org.pentaho.platform.dataaccess.metadata.model.impl.Query) Constraint(org.pentaho.metadata.query.model.Constraint) Selection(org.pentaho.metadata.query.model.Selection) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) AggregationType(org.pentaho.metadata.model.concept.types.AggregationType) LogicalModel(org.pentaho.metadata.model.LogicalModel) LogicalColumn(org.pentaho.metadata.model.LogicalColumn) IPhysicalColumn(org.pentaho.metadata.model.IPhysicalColumn) Column(org.pentaho.platform.dataaccess.metadata.model.impl.Column) DataType(org.pentaho.metadata.model.concept.types.DataType) Condition(org.pentaho.platform.dataaccess.metadata.model.impl.Condition) Order(org.pentaho.platform.dataaccess.metadata.model.impl.Order) IMetadataDomainRepository(org.pentaho.metadata.repository.IMetadataDomainRepository) DataType(org.pentaho.metadata.model.concept.types.DataType) AggregationType(org.pentaho.metadata.model.concept.types.AggregationType) FieldType(org.pentaho.metadata.model.concept.types.FieldType) Type(org.pentaho.metadata.query.model.Order.Type) CombinationType(org.pentaho.metadata.query.model.CombinationType) Parameter(org.pentaho.platform.dataaccess.metadata.model.impl.Parameter) Domain(org.pentaho.metadata.model.Domain) CombinationType(org.pentaho.metadata.query.model.CombinationType)

Example 23 with LogicalModel

use of org.pentaho.metadata.model.LogicalModel in project data-access by pentaho.

the class MetadataServiceUtil method createThinModel.

/**
 * Creates a lightweight, serializable model object from a logical model
 *
 * @param m
 * @param domainId
 * @return
 */
public Model createThinModel(LogicalModel m, String domainId) {
    // create the model object
    Model model = new Model();
    model.setName(m.getName(getLocale()));
    model.setId(m.getId());
    model.setDomainId(domainId);
    model.setDescription(m.getDescription(getLocale()));
    // add the categories to the model
    List<Category> categories = new ArrayList<Category>();
    for (org.pentaho.metadata.model.Category cat : m.getCategories()) {
        categories.add(createCategory(m, cat));
    }
    model.setCategories(categories.toArray(new Category[categories.size()]));
    return model;
}
Also used : Category(org.pentaho.platform.dataaccess.metadata.model.impl.Category) LogicalModel(org.pentaho.metadata.model.LogicalModel) Model(org.pentaho.platform.dataaccess.metadata.model.impl.Model) ArrayList(java.util.ArrayList)

Example 24 with LogicalModel

use of org.pentaho.metadata.model.LogicalModel in project data-access by pentaho.

the class DataSourceWizardService method doGetDSWFilesAsDownload.

public Map<String, InputStream> doGetDSWFilesAsDownload(String dswId) throws PentahoAccessControlException {
    if (!canManageACL()) {
        throw new PentahoAccessControlException();
    }
    // First get the metadata files;
    Map<String, InputStream> fileData = getMetadataFiles(dswId);
    // Then get the corresponding mondrian files
    Domain domain = metadataDomainRepository.getDomain(dswId);
    ModelerWorkspace model = createModelerWorkspace();
    model.setDomain(domain);
    LogicalModel logicalModel = model.getLogicalModel(ModelerPerspective.ANALYSIS);
    if (logicalModel == null) {
        logicalModel = model.getLogicalModel(ModelerPerspective.REPORTING);
    }
    if (logicalModel.getProperty(MONDRIAN_CATALOG_REF) != null) {
        MondrianCatalogRepositoryHelper helper = createMondrianCatalogRepositoryHelper();
        String catalogRef = (String) logicalModel.getProperty(MONDRIAN_CATALOG_REF);
        fileData.putAll(helper.getModrianSchemaFiles(catalogRef));
        parseMondrianSchemaNameWrapper(dswId, fileData);
    }
    return fileData;
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) MondrianCatalogRepositoryHelper(org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper) Domain(org.pentaho.metadata.model.Domain) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) ModelerWorkspace(org.pentaho.agilebi.modeler.ModelerWorkspace)

Example 25 with LogicalModel

use of org.pentaho.metadata.model.LogicalModel in project data-access by pentaho.

the class DataSourceWizardService method removeDSW.

public void removeDSW(String dswId) throws PentahoAccessControlException {
    try {
        ensureDataAccessPermissionCheck();
    } catch (ConnectionServiceException e) {
        throw new PentahoAccessControlException();
    }
    Domain domain = metadataDomainRepository.getDomain(dswId);
    ModelerWorkspace model = createModelerWorkspace();
    model.setDomain(domain);
    LogicalModel logicalModel = model.getLogicalModel(ModelerPerspective.ANALYSIS);
    if (logicalModel == null) {
        logicalModel = model.getLogicalModel(ModelerPerspective.REPORTING);
    }
    if (logicalModel.getProperty(MONDRIAN_CATALOG_REF) != null) {
        String catalogRef = (String) logicalModel.getProperty(MONDRIAN_CATALOG_REF);
        try {
            mondrianCatalogService.removeCatalog(catalogRef, getSession());
        } catch (MondrianCatalogServiceException e) {
            logger.warn("Failed to remove mondrian catalog", e);
        }
    }
    try {
        dswService.deleteLogicalModel(domain.getId(), logicalModel.getId());
    } catch (DatasourceServiceException ex) {
        logger.warn("Failed to remove logical model", ex);
    }
    metadataDomainRepository.removeDomain(dswId);
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) MondrianCatalogServiceException(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogServiceException) Domain(org.pentaho.metadata.model.Domain) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) ModelerWorkspace(org.pentaho.agilebi.modeler.ModelerWorkspace) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)

Aggregations

LogicalModel (org.pentaho.metadata.model.LogicalModel)53 Domain (org.pentaho.metadata.model.Domain)29 LocalizedString (org.pentaho.metadata.model.concept.types.LocalizedString)14 Test (org.junit.Test)13 ModelerWorkspace (org.pentaho.agilebi.modeler.ModelerWorkspace)11 LogicalTable (org.pentaho.metadata.model.LogicalTable)11 ArrayList (java.util.ArrayList)10 LogicalColumn (org.pentaho.metadata.model.LogicalColumn)9 Category (org.pentaho.metadata.model.Category)8 Matchers.anyString (org.mockito.Matchers.anyString)7 SqlPhysicalModel (org.pentaho.metadata.model.SqlPhysicalModel)7 SqlPhysicalTable (org.pentaho.metadata.model.SqlPhysicalTable)6 IMetadataDomainRepository (org.pentaho.metadata.repository.IMetadataDomainRepository)6 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)6 DomainIdNullException (org.pentaho.metadata.repository.DomainIdNullException)5 DomainStorageException (org.pentaho.metadata.repository.DomainStorageException)5 ConnectionServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException)5 DatasourceServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)5 IOException (java.io.IOException)4 SqlDataSource (org.pentaho.metadata.model.SqlDataSource)4