private IModelEntity getSelectedEntity() { logger.debug("IN"); IModelEntity entity = null; try { IDataSource ds = getDataSource(); // change max recursion level to data source Map<String, Object> properties = ds.getConfiguration().loadDataSourceProperties(); properties.put("maxRecursionLevel", "5"); // ds.setDataMartModelAccessModality(modelAccessModality); IModelStructure structure = ds.getModelStructure(); QbeEngineInstance engineInstance = getEngineInstance(); QbeTemplate template = engineInstance.getTemplate(); if (template.isComposite()) { // composite Qbe is not supported logger.error("Template is composite. This is not supported by the Registry engine"); throw new SpagoBIEngineServiceException( getActionName(), "Template is composite. This is not supported by the Registry engine"); } // takes the only datamart's name configured String modelName = (String) template.getDatamartNames().get(0); RegistryConfiguration registryConfig = (RegistryConfiguration) template.getProperty("registryConfiguration"); String entityName = registryConfig.getEntity(); int index = entityName.lastIndexOf("."); entityName = entityName + "::" + entityName.substring( index + 1); // entity name is something like it.eng.Store::Store logger.debug("Looking for entity [" + entityName + "] in model [" + modelName + "] ..."); entity = structure.getRootEntity(modelName, entityName); logger.debug("Entity [" + entityName + "] was found"); if (entity == null) { logger.error("Entity [" + entityName + "] not found!"); throw new SpagoBIEngineServiceException( getActionName(), "Entity [" + entityName + "] not found!"); } } finally { logger.debug("OUT"); } return entity; }
private Query buildQuery() { logger.debug("IN"); Query query = null; try { QbeEngineInstance qbeEngineInstance = getEngineInstance(); Map env = qbeEngineInstance.getEnv(); query = new Query(); query.setDistinctClauseEnabled(false); IModelEntity entity = getSelectedEntity(); QbeEngineInstance engineInstance = getEngineInstance(); QbeTemplate template = engineInstance.getTemplate(); registryConfig = (RegistryConfiguration) template.getProperty("registryConfiguration"); List<Column> columns = registryConfig.getColumns(); columnMaxSize = registryConfig.getColumnsMaxSize(); Iterator<Column> it = columns.iterator(); Map<String, String> fieldNameIdMap = new HashMap<String, String>(); while (it.hasNext()) { Column column = it.next(); getMandatoryMetadata(column); getColumnsInfos(column); IModelField field = getColumnModelField(column, entity); if (field == null) { logger.error("Field " + column.getField() + " not found!!"); } else { String name = field.getPropertyAsString("label"); if (name == null || name.length() == 0) { name = field.getName(); } String sorter = column.getSorter() != null && (column.getSorter().equalsIgnoreCase("ASC") || column.getSorter().equalsIgnoreCase("DESC")) ? column.getSorter().toUpperCase() : null; query.addSelectFiled( field.getUniqueName(), "NONE", field.getName(), true, true, false, sorter, field.getPropertyAsString("format")); fieldNameIdMap.put(column.getField(), field.getUniqueName()); } } // get Drivers and filters List<RegistryConfiguration.Filter> filters = registryConfig.getFilters(); int i = 0; ArrayList<ExpressionNode> expressionNodes = new ArrayList<ExpressionNode>(); for (Iterator iterator = filters.iterator(); iterator.hasNext(); ) { Filter filter = (Filter) iterator.next(); addFilter(i, query, env, fieldNameIdMap, filter, expressionNodes); i++; } // put together expression nodes if (expressionNodes.size() == 1) { query.setWhereClauseStructure(expressionNodes.get(0)); } else if (expressionNodes.size() > 1) { ExpressionNode exprNodeAnd = new ExpressionNode("NODE_OP", "AND"); exprNodeAnd.setChildNodes(expressionNodes); query.setWhereClauseStructure(exprNodeAnd); } } finally { logger.debug("OUT"); } return query; }