Search in sources :

Example 1 with ModelInfo

use of org.pentaho.platform.dataaccess.metadata.model.impl.ModelInfo 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)

Example 2 with ModelInfo

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

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

the class MetadataService method listBusinessModelsJson.

/**
 * Returns a JSON list of the available business models
 *
 * @param domainName optional domain to limit the results
 * @return JSON string of list of ModelInfo objects representing the available models
 * @throws IOException
 */
public String listBusinessModelsJson(String domainName) throws IOException {
    ModelInfo[] models = listBusinessModels(domainName);
    JSONSerializer serializer = new JSONSerializer();
    String json = serializer.deepSerialize(models);
    return json;
}
Also used : ModelInfo(org.pentaho.platform.dataaccess.metadata.model.impl.ModelInfo) JSONSerializer(flexjson.JSONSerializer)

Aggregations

ModelInfo (org.pentaho.platform.dataaccess.metadata.model.impl.ModelInfo)3 IMetadataDomainRepository (org.pentaho.metadata.repository.IMetadataDomainRepository)2 JSONSerializer (flexjson.JSONSerializer)1 ArrayList (java.util.ArrayList)1 Domain (org.pentaho.metadata.model.Domain)1 LogicalModel (org.pentaho.metadata.model.LogicalModel)1 ModelInfoComparator (org.pentaho.platform.dataaccess.metadata.model.impl.ModelInfoComparator)1