Package it.eng.qbe.query

Examples of it.eng.qbe.query.DataMartSelectField


    selectedFieldsJSON = new JSONArray();
   
    for(int i = 0; i < selectedFields.size(); i++) {
      ISelectField f = (ISelectField)selectedFields.get(i);
      if(f.isDataMartField()) {
        DataMartSelectField dataMartSelectField = (DataMartSelectField)f;
        JSONObject selectFieldJSON = new JSONObject();
        try {
          selectFieldJSON.put("name", dataMartSelectField.getUniqueName());
          selectFieldJSON.put("alias", dataMartSelectField.getAlias());
        } catch (JSONException e) {
          throw new SpagoBIEngineServiceException(getActionName(), "An error occurred while serializing field [" + dataMartSelectField.getUniqueName() + " - " + dataMartSelectField.getAlias() +"]", e);
        }
        selectedFieldsJSON.put(selectFieldJSON);
      }
    }
   
View Full Code Here


     
      // aggregate measures
      List dataMartSelectFields = query.getDataMartSelectFields(true);
      Iterator it = dataMartSelectFields.iterator();
      while (it.hasNext()) {
        DataMartSelectField field = (DataMartSelectField) it.next();
        int fieldIndex = query.getSelectFieldIndex(field.getUniqueName());       
        String[] f = (String[])selectFields.get(fieldIndex);
        IAggregationFunction aggregationFunction = field.getFunction();
        if (aggregationFunction != null && aggregationFunction != AggregationFunctions.NONE_FUNCTION) {
          transformer.addAggregateColumn(f[1]!=null? f[1]:f[0], aggregationFunction.getName(), field.getAlias());
        }
      }
     
      sqlQuery = (String)transformer.transformQuery(sqlQuery);
     
View Full Code Here

    String toReturn = null;
   
    List qbeQueryFields = baseQuery.getSelectFields(true);
    int index = -1;
    for (int i = 0; i < qbeQueryFields.size(); i++) {
      DataMartSelectField field = (DataMartSelectField) qbeQueryFields.get(i);
      if (field.getUniqueName().equals(elementUniqueName)) {
        index = i;
        break;
      }
    }
   
View Full Code Here

        JSONObject filter = (JSONObject) dynamicFilters.get(i);
        String id = filter.getString(QbeJSONTemplateParser.ID);
        String field = formViewerState.getDynamicFilterField(id);
        if (field != null && !field.trim().equals("")) {
          List fields = query.getDataMartSelectFields(false);
          DataMartSelectField selectField = null;
          Iterator it = fields.iterator();
          while (it.hasNext()) {
            selectField = (DataMartSelectField) it.next();
            if (selectField.getUniqueName().equals(field)) {
              break;
            }
          }
          if (selectField != null) {
            if (selectField.getFunction() != null && selectField.getFunction() != AggregationFunctions.NONE_FUNCTION) {
              logger.debug("Applying having filter to field " + selectField.getUniqueName());
              addHavingFilter(query, selectField, filter);
            } else {
              logger.debug("Applying where filter to field " + selectField.getUniqueName());
              addWhereFilter(query, field, filter);
            }
          } else {
            logger.error("Field " + field + " not found on query selected fields");
          }
View Full Code Here

         
          // field nature can me "measure" or "attribute"
          String nature = null;
         
          if (field.isDataMartField()) {
            DataMartSelectField dataMartSelectField = (DataMartSelectField)field;
           
            fieldJSON.put(QuerySerializationConstants.FIELD_TYPE, field.DATAMART_FIELD);
           
            fieldUniqueName = dataMartSelectField.getUniqueName();
            datamartField = dataSource.getModelStructure().getField( fieldUniqueName );
            Assert.assertNotNull(datamartField, "A filed named [" + fieldUniqueName + "] does not exist in the datamart model");
           
            fieldJSON.put(QuerySerializationConstants.FIELD_ID, datamartField.getUniqueName());
                       
            // localize entity name
            label = null;
            if(datamartLabels != null) {
              label = datamartLabels.getProperty(datamartField.getParent(), "label");
            }
            label = StringUtilities.isEmpty(label)? datamartField.getParent().getName(): label;
            fieldJSON.put(QuerySerializationConstants.FIELD_ENTITY, label);
           
            // localize field name
            label = null;
            if(datamartLabels != null) {
              label = datamartLabels.getProperty(datamartField, "label");
            }
            label = StringUtilities.isEmpty(label)? datamartField.getName(): label;
            fieldJSON.put(QuerySerializationConstants.FIELD_NAME, label);
            longDescription = getFieldLongDescription(datamartField, datamartLabels);
            fieldJSON.put(QuerySerializationConstants.FIELD_LONG_DESCRIPTION, longDescription);
           
            if( dataMartSelectField.isGroupByField() ) {
              fieldJSON.put(QuerySerializationConstants.FIELD_GROUP, "true");
            } else {
              fieldJSON.put(QuerySerializationConstants.FIELD_GROUP, "");
            }
            fieldJSON.put(QuerySerializationConstants.FIELD_ORDER, dataMartSelectField.getOrderType());
            fieldJSON.put(QuerySerializationConstants.FIELD_AGGREGATION_FUNCTION, dataMartSelectField.getFunction().getName());
           
            //DatamartProperties datamartProperties = dataSource.getDataMartProperties();
            String iconCls = datamartField.getPropertyAsString("type")
            fieldJSON.put(QuerySerializationConstants.FIELD_ICON_CLS, iconCls);
           
            // if an aggregation function is defined or if the field is declared as "measure" into property file,
            // then it is a measure, elsewhere it is an attribute
            if (
                (dataMartSelectField.getFunction() != null
                && !dataMartSelectField.getFunction().equals(AggregationFunctions.NONE_FUNCTION))
                || iconCls.equals("measure")) {
              nature = QuerySerializationConstants.FIELD_NATURE_MEASURE;
            } else {
              nature = QuerySerializationConstants.FIELD_NATURE_ATTRIBUTE;
            }
View Full Code Here

    StringBuffer buffer;
    List selectFields;
    List allSelectFields;
    List<InLineCalculatedSelectField> selectInLineCalculatedFields = new ArrayList<InLineCalculatedSelectField>();
    AbstractSelectField selectAbstractField;
    DataMartSelectField selectField;
    InLineCalculatedSelectField selectInLineField;
    IModelEntity rootEntity;
    IModelField datamartField;
    String queryName;
    String rootEntityAlias;
    String selectClauseElement; // rootEntityAlias.queryName
    Map entityAliases;
    List<String> aliasEntityMapping;
   
    logger.debug("IN");
    buffer = new StringBuffer();
    try {
      selectFields = query.getSelectFields(true);
     
      if(selectFields == null ||selectFields.size() == 0) {
        return "";
      }
     
      entityAliases = (Map)entityAliasesMaps.get(query.getId());
           
      buffer.append(SELECT);   
      if (query.isDistinctClauseEnabled()) {
        buffer.append(" " + DISTINCT);
      }
     
      Iterator it = selectFields.iterator();
      if(it.hasNext()){
        selectAbstractField = (AbstractSelectField)it.next();
        String[] idsForQuery = new String[selectFields.size()-query.getCalculatedSelectFields(true).size()];
        int index=0;
        do{       
          if(selectAbstractField.isDataMartField()){
         
            selectField = (DataMartSelectField)selectAbstractField;
           
            logger.debug("select field unique name [" + selectField.getUniqueName() + "]");
           
            datamartField = getDataSource().getModelStructure().getField(selectField.getUniqueName());
            queryName = (String)datamartField.getQueryName().getFirst();
            logger.debug("select field query name [" + queryName + "]");
           
            rootEntity = datamartField.getParent().getRoot();    
            logger.debug("select field root entity unique name [" + rootEntity.getUniqueName() + "]");
           
            rootEntityAlias = (String)entityAliases.get(rootEntity.getUniqueName());
            if(rootEntityAlias == null) {
              rootEntityAlias = getNextAlias(entityAliasesMaps);
              entityAliases.put(rootEntity.getUniqueName(), rootEntityAlias);
            }
            logger.debug("select field root entity alias [" + rootEntityAlias + "]");
           
           
            selectClauseElement = rootEntityAlias + "." + queryName;
            logger.debug("select clause element before aggregation [" + selectClauseElement + "]");
           
            selectClauseElement = selectField.getFunction().apply(selectClauseElement);
            logger.debug("select clause element after aggregation [" + selectClauseElement + "]");
           
           
            idsForQuery[index] = " " + selectClauseElement;
            index++;
View Full Code Here

      if(abstractSelectedField.isInLineCalculatedField()){
        InLineCalculatedSelectField icf = (InLineCalculatedSelectField)abstractSelectedField;
        fieldName = parseInLinecalculatedField(icf.getExpression(), query, entityAliasesMaps);
      }else{
     
        DataMartSelectField groupByField = (DataMartSelectField)abstractSelectedField;
        IModelField datamartField = getDataSource().getModelStructure().getField(groupByField.getUniqueName());
        IModelEntity entity = datamartField.getParent().getRoot();
        String queryName = (String)datamartField.getQueryName().getFirst();
        if(!entityAliases.containsKey(entity.getUniqueName())) {
          entityAliases.put(entity.getUniqueName(), getNextAlias(entityAliasesMaps));
        }
View Full Code Here

 
  private List getOrderByFields(Query query) {
    List orderByFields = new ArrayList();
    Iterator it = query.getDataMartSelectFields(false).iterator();
    while( it.hasNext() ) {
      DataMartSelectField selectField = (DataMartSelectField)it.next();
      if(selectField.isOrderByField()) {
        orderByFields.add(selectField);
      }
    }
    return orderByFields;
  }
View Full Code Here

  }
 
  private String buildOrderByClause(Query query, Map entityAliasesMaps) {
    StringBuffer buffer;
    Iterator it;
    DataMartSelectField selectField;
   
    it = getOrderByFields(query).iterator();   
    if(!it.hasNext()) {
      return "";
    }
   
    buffer = new StringBuffer()
    buffer.append("ORDER BY");
   
    Map entityAliases = (Map)entityAliasesMaps.get(query.getId());
         
    while( it.hasNext() ) {
      selectField = (DataMartSelectField)it.next();
     
      Assert.assertTrue(selectField.isOrderByField(), "Field [" + selectField.getUniqueName() +"] is not an orderBy filed");
     
      IModelField datamartField = getDataSource().getModelStructure().getField(selectField.getUniqueName());
      IModelEntity entity = datamartField.getParent().getRoot();
      String queryName = (String)datamartField.getQueryName().getFirst();
      if(!entityAliases.containsKey(entity.getUniqueName())) {
        entityAliases.put(entity.getUniqueName(), getNextAlias(entityAliasesMaps));
      }
      String entityAlias = (String)entityAliases.get( entity.getUniqueName() );
      String fieldName = entityAlias + "." + queryName;
      buffer.append(" " + selectField.getFunction().apply(fieldName));
      buffer.append(" " + (selectField.isAscendingOrder()?"ASC": "DESC") );
           
      if( it.hasNext() ) {
        buffer.append(",");
      }
    }
View Full Code Here

      queryFiled = (ISelectField)fieldsIterator.next();
     
      dataStoreFieldMeta = new FieldMetadata();
      dataStoreFieldMeta.setAlias( queryFiled.getAlias() );
      if(queryFiled.isDataMartField()) {
        DataMartSelectField dataMartSelectField = (DataMartSelectField) queryFiled;
        dataStoreFieldMeta.setName( ((DataMartSelectField)queryFiled).getUniqueName() );
        dataStoreFieldMeta.setProperty("calculated", new Boolean(false));
        dataStoreFieldMeta.setProperty("uniqueName", dataMartSelectField.getUniqueName());
        dataStoreFieldMeta.setType(Object.class);
        String format = dataMartSelectField.getPattern();
        if (format != null && !format.trim().equals("")) {
          dataStoreFieldMeta.setProperty("format", format);
        }
      } else if(queryFiled.isCalculatedField()){
        CalculatedSelectField claculatedQueryField = (CalculatedSelectField)queryFiled;
View Full Code Here

TOP

Related Classes of it.eng.qbe.query.DataMartSelectField

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.