Search in sources :

Example 1 with Model

use of org.pentaho.platform.dataaccess.metadata.model.impl.Model in project data-access by pentaho.

the class MetadataService method loadModelJson.

/**
 * Returns a JSON Model object for the requested model. The model will include the basic metadata - categories and
 * columns.
 *
 * @param domainId
 * @param modelId
 * @return JSON string of the model
 */
public String loadModelJson(String domainId, String modelId) {
    Model model = loadModel(domainId, modelId);
    JSONSerializer serializer = new JSONSerializer();
    String json = serializer.deepSerialize(model);
    return json;
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) Model(org.pentaho.platform.dataaccess.metadata.model.impl.Model) JSONSerializer(flexjson.JSONSerializer)

Example 2 with Model

use of org.pentaho.platform.dataaccess.metadata.model.impl.Model 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 3 with Model

use of org.pentaho.platform.dataaccess.metadata.model.impl.Model in project data-access by pentaho.

the class MetadataServiceTest method testLoadModel.

@Test
public void testLoadModel() {
    when(metadataService.loadModel(anyString(), anyString())).thenCallRealMethod();
    Model model = metadataService.loadModel(DOMAIN_ID, LOGICAL_MODEL_ID);
    // Test if the name of the model returned is correct
    Assert.assertTrue(model.getName() == LOGICAL_MODEL_NAME);
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) Model(org.pentaho.platform.dataaccess.metadata.model.impl.Model) Test(org.junit.Test)

Example 4 with Model

use of org.pentaho.platform.dataaccess.metadata.model.impl.Model in project data-access by pentaho.

the class MetadataService method loadModel.

/**
 * Returns a Model object for the requested model. The model will include the basic metadata - categories and
 * columns.
 *
 * @param domainId
 * @param modelId
 * @return
 */
public Model loadModel(String domainId, String modelId) {
    if (domainId == null) {
        // we can't do this without a model
        // $NON-NLS-1$
        error(Messages.getErrorString("MetadataService.ERROR_0003_NULL_DOMAIN"));
        return null;
    }
    if (modelId == null) {
        // we can't do this without a model
        // $NON-NLS-1$
        error(Messages.getErrorString("MetadataService.ERROR_0004_NULL_Model"));
        return null;
    }
    // because it's lighter weight, check the thin model
    Domain domain = getMetadataRepository().getDomain(domainId);
    if (domain == null) {
        // $NON-NLS-1$
        error(Messages.getErrorString("MetadataService.ERROR_0005_DOMAIN_NOT_FOUND", domainId));
        return null;
    }
    LogicalModel model = domain.findLogicalModel(modelId);
    if (model == null) {
        // the model cannot be found or cannot be loaded
        // $NON-NLS-1$
        error(Messages.getErrorString("MetadataService.ERROR_0006_MODEL_NOT_FOUND", modelId));
        return null;
    }
    // create the thin metadata model and return it
    MetadataServiceUtil util = getMetadataServiceUtil();
    util.setDomain(domain);
    Model thinModel = util.createThinModel(model, domainId);
    return thinModel;
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) LogicalModel(org.pentaho.metadata.model.LogicalModel) Model(org.pentaho.platform.dataaccess.metadata.model.impl.Model) Domain(org.pentaho.metadata.model.Domain)

Aggregations

LogicalModel (org.pentaho.metadata.model.LogicalModel)4 Model (org.pentaho.platform.dataaccess.metadata.model.impl.Model)4 JSONSerializer (flexjson.JSONSerializer)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 Domain (org.pentaho.metadata.model.Domain)1 Category (org.pentaho.platform.dataaccess.metadata.model.impl.Category)1