Package it.eng.qbe.model.structure

Examples of it.eng.qbe.model.structure.IModelField


 
 
  private static void putWhereClause(StringBuffer toReturn, List<WhereField> whereFields, Query baseQuery, List baseQuerySelectedFields, AbstractStatement stmt) {
    String boundedValue,leftValue,alias;
    String[] rightValues;
    IModelField datamartField;
   
    logger.debug("IN");
    if(whereFields!=null && whereFields.size()>0){
      toReturn.append(" WHERE ");
      for(int i=0; i<whereFields.size(); i++){
        leftValue = whereFields.get(i).getLeftOperand().values[0];
        datamartField = stmt.getDataSource().getModelStructure().getField(leftValue);
       
        rightValues = whereFields.get(i).getRightOperand().values;
       
        alias = getSQLAliasByUniqueName(datamartField.getUniqueName(), baseQuery, baseQuerySelectedFields);
        if(rightValues.length==1){
          boundedValue = stmt.getValueBounded(rightValues[0], datamartField.getType());
          toReturn.append(alias+" = "+boundedValue);
        }else{
          toReturn.append(alias+" IN (");
          for(int j=0; j<rightValues.length; j++){
            boundedValue = stmt.getValueBounded(rightValues[j], datamartField.getType());
            toReturn.append(boundedValue);
            if (j<rightValues.length-1) {
              toReturn.append(", ");
            }
          }
View Full Code Here


  public void service(SourceBean request, SourceBean response) {       
 
    String fieldId;
    IDataSource dataSource;
    IModelStructure structure;
    IModelField field;
    IModelEntity parentEntity;
    IModelEntity dimensionalEntity;
    List fields;
    JSONArray toReturn;
   
    logger.debug("IN");
   
    try {   
      super.service(request, response)
     
      fieldId = getAttributeAsString( FIELD_ID );
      logger.debug("Parameter [" + FIELD_ID + "] is equals to [" + fieldId + "]");
     
      Assert.assertNotNull(getEngineInstance(), "It's not possible to execute " + this.getActionName() + " service before having properly created an instance of EngineInstance class");
     
      dataSource = getDataSource();
      structure = dataSource.getModelStructure();
      field = structure.getField(fieldId);
      parentEntity = field.getParent();
      fields = parentEntity.getAllFields();
     
      toReturn = new JSONArray();
      Iterator it = fields.iterator();
      while (it.hasNext()) {
        IModelField aField = (IModelField) it.next();
        JSONObject aJSONField = new JSONObject();
        aJSONField.put("id", aField.getUniqueName());
        //String name = QbeCacheManager.getInstance().getLabels( getDataSource() , getLocale() ).getLabel(aField);
        String name = getDataSource().getModelI18NProperties(getLocale()).getProperty(aField, "label");
        if (name == null || name.trim().equals(""))
          name = aField.getName();
        aJSONField.put("name", name);
        toReturn.put(aJSONField);
      }
     
     
View Full Code Here

    // add key fields
    List keyFields = entity.getKeyFields();
   
    Iterator keyFieldIterator = keyFields.iterator();
    while (keyFieldIterator.hasNext() ) {
      IModelField field = (IModelField)keyFieldIterator.next();
      JSONObject jsObject = getFieldNode(entity, field);
      if(jsObject != null) {
        children.put( jsObject );
      }
     
    }
   
    // add normal fields
    List normalFields = entity.getNormalFields();
   
    Iterator normalFieldIterator = normalFields.iterator();
    while (normalFieldIterator.hasNext() ) {
      IModelField field = (IModelField)normalFieldIterator.next();
      JSONObject jsObject = getFieldNode(entity, field);
      if(jsObject != null) {
        children.put( jsObject );
      }
    }
View Full Code Here

   
    if (queryRootEntity) {
      logger.debug("Must use query root entity. Looking for select and order fields...");
      IDataSource model = getDataSource();
      IModelStructure structure = model.getModelStructure();
      IModelField selectField = structure.getField(entityId);
      IModelField orderField = null;
      if (orderEntity != null && !orderEntity.equals("")) {
        orderField = structure.getField(orderEntity);
      }
      IModelEntity parentEntity = selectField.getParent();
      logger.debug("Parent entity is " + parentEntity.getUniqueName());
      IModelEntity rootEntity = structure.getRootEntity(parentEntity);
      logger.debug("Relevant root entity is " + rootEntity.getUniqueName());
      List fields = rootEntity.getAllFields();
      Iterator it = fields.iterator();
      while (it.hasNext()) {
        IModelField aField = (IModelField) it.next();
        if (aField.getName().equals(selectField.getName())) {
          entityId = aField.getUniqueName();
          entityPattern = aField.getPropertyAsString("format");
          break;
        }
      }
      logger.debug("Select field in root entity is " + entityId);
      if (orderField != null) {
        it = fields.iterator();
        while (it.hasNext()) {
          IModelField aField = (IModelField) it.next();
          if (aField.getName().equals(orderField.getName())) {
            orderEntity = aField.getUniqueName();
            orderEntityPattern = aField.getPropertyAsString("format");
            break;
          }
        }
        logger.debug("Order field in root entity is " + orderEntity);
      }
View Full Code Here

    JSONArray result;
   
    List fields;
    ISelectField field;
    String fieldUniqueName;
    IModelField datamartField;
    JSONObject fieldJSON;
    Iterator it;
    IModelProperties datamartLabels;
    String label, longDescription;
   
    logger.debug("IN");
   
    try {
      datamartLabels = null;
      if(locale != null) {
        //datamartLabels =  QbeCacheManager.getInstance().getLabels( dataSource , locale );
        datamartLabels = dataSource.getModelI18NProperties(locale);
      }
     
      fields = query.getSelectFields(false);
      Assert.assertNotNull(fields, "Fields cannot be null");
      logger.debug("Query [" + query.getId() + "] have [" + fields.size() + "] field/s to serialize");
     
      result = new JSONArray();
      it = fields.iterator();
      while( it.hasNext() ) {
        field = (ISelectField)it.next();
        logger.debug("Serializing filed [" + field.getAlias() + "]");
        try {
          fieldJSON = new JSONObject();
         
          fieldJSON.put(QuerySerializationConstants.FIELD_ALIAS, field.getAlias());
         
          fieldJSON.put(QuerySerializationConstants.FIELD_VISIBLE, field.isVisible());
          fieldJSON.put(QuerySerializationConstants.FIELD_INCLUDE, field.isIncluded());         
         
          // 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 (
View Full Code Here

   
    List filters;
    WhereField filter;
    WhereField.Operand operand;
    JSONObject filterJSON;
    IModelField datamartFilter;
    String fieldUniqueName;
    Iterator it;
    IModelProperties datamartLabels;
    IModelField datamartField;
   
    filters = query.getWhereFields();
    Assert.assertNotNull(filters, "Filters cannot be null");
   
    datamartLabels = null;
    if(locale != null) {
      //datamartLabels =  QbeCacheManager.getInstance().getLabels( dataSource , locale );
      datamartLabels = dataSource.getModelI18NProperties(locale);
    }
   
    it = filters.iterator();
    while( it.hasNext() ) {
      filter = (WhereField)it.next();
     
      filterJSON = new JSONObject();
      try {
        filterJSON.put(QuerySerializationConstants.FILTER_ID, filter.getName());
        filterJSON.put(QuerySerializationConstants.FILTER_DESCRIPTION, filter.getDescription());
        filterJSON.put(QuerySerializationConstants.FILTER_PROMPTABLE, filter.isPromptable());
       
        operand = filter.getLeftOperand();
        filterJSON.put(QuerySerializationConstants.FILTER_LO_VALUE, operand.values[0]);
        if(operand.type.equalsIgnoreCase("Field Content")) {
          if(operand.values[0].contains("\"expression\":\"")){
            filterJSON.put(QuerySerializationConstants.FILTER_LO_DESCRIPTION, operand.description );
            String description = operand.values[0].substring(operand.values[0].indexOf("\"expression\":\"")+14);
            description.substring(0, description.indexOf("\""));
            filterJSON.put(QuerySerializationConstants.FILTER_LO_LONG_DESCRIPTION, description);           
          }else{
            datamartField = dataSource.getModelStructure().getField( operand.values[0] );
           
            String labelF, labelE;
            labelE = null;
            if(datamartLabels != null) {
              labelE = datamartLabels.getProperty(datamartField.getParent(), "label");
            }
            labelE = StringUtilities.isEmpty(labelE)? datamartField.getParent().getName(): labelE;
           
           
            labelF = null;
            if(datamartLabels != null) {
              labelF = datamartLabels.getProperty(datamartField, "label");
            }
            labelF = StringUtilities.isEmpty(labelF)? datamartField.getName(): labelF;
           
            filterJSON.put(QuerySerializationConstants.FILTER_LO_DESCRIPTION, labelE  + " : " + labelF );
           
            String loLongDescription = getFieldLongDescription(datamartField, datamartLabels);
            filterJSON.put(QuerySerializationConstants.FILTER_LO_LONG_DESCRIPTION, loLongDescription);
          }
        } else if(operand.type.equalsIgnoreCase("Subquery")) {
          String loLongDescription = "Subquery " + operand.description;
          filterJSON.put(QuerySerializationConstants.FILTER_LO_LONG_DESCRIPTION, loLongDescription);
         
          filterJSON.put(QuerySerializationConstants.FILTER_LO_DESCRIPTION, operand.description);
        } else if(operand.type.equalsIgnoreCase("Parent Field Content")) {
          String[] chunks = operand.values[0].split(" ");
          String parentQueryId = chunks[0];
          String fieldName = chunks[1];
          datamartField = dataSource.getModelStructure().getField( fieldName );
          String datamartFieldLongDescription = getFieldLongDescription(datamartField, datamartLabels);
          String loLongDescription = "Query " + parentQueryId + ", " + datamartFieldLongDescription;
          filterJSON.put(QuerySerializationConstants.FILTER_LO_LONG_DESCRIPTION, loLongDescription);
         
          filterJSON.put(QuerySerializationConstants.FILTER_LO_DESCRIPTION, operand.description);
        } else {
          filterJSON.put(QuerySerializationConstants.FILTER_LO_DESCRIPTION, operand.description);
        }
       
       
       
        filterJSON.put(QuerySerializationConstants.FILTER_LO_TYPE, operand.type);
        filterJSON.put(QuerySerializationConstants.FILTER_LO_DEFAULT_VALUE, operand.defaulttValues[0]);
        filterJSON.put(QuerySerializationConstants.FILTER_LO_LAST_VALUE, operand.lastValues[0]);
       
        filterJSON.put(QuerySerializationConstants.FILTER_OPERATOR, filter.getOperator());
       
        operand = filter.getRightOperand();
        filterJSON.put(QuerySerializationConstants.FILTER_RO_VALUE, JSONUtils.asJSONArray(operand.values));
        if(operand.type.equalsIgnoreCase("Field Content")) {
          datamartField = dataSource.getModelStructure().getField( operand.values[0] );
         
          String labelF, labelE;
          labelE = null;
          if(datamartLabels != null) {
            labelE = datamartLabels.getProperty(datamartField.getParent(), "label");
          }
          labelE = StringUtilities.isEmpty(labelE)? datamartField.getParent().getName(): labelE;
         
         
          labelF = null;
          if(datamartLabels != null) {
            labelF = datamartLabels.getProperty(datamartField, "label");
          }
          labelF = StringUtilities.isEmpty(labelF)? datamartField.getName(): labelF;
         
          filterJSON.put(QuerySerializationConstants.FILTER_RO_DESCRIPTION, labelE  + " : " + labelF );
         
          String roLongDescription = getFieldLongDescription(datamartField, datamartLabels);
          filterJSON.put(QuerySerializationConstants.FILTER_RO_LONG_DESCRIPTION, roLongDescription);
View Full Code Here

   
    List havings;
    HavingField filter;
    HavingField.Operand operand;
    JSONObject havingJSON;
    IModelField datamartFilter;
    String fieldUniqueName;
    Iterator it;
    IModelProperties datamartLabels;
    IModelField datamartField;
   
    havings = query.getHavingFields();
    Assert.assertNotNull(havings, "Filters cannot be null");
   
    datamartLabels = null;
    if(locale != null) {
      //datamartLabels =  QbeCacheManager.getInstance().getLabels( dataSource , locale );
      datamartLabels = dataSource.getModelI18NProperties(locale);
    }
   
    it = havings.iterator();
    while( it.hasNext() ) {
      filter = (HavingField)it.next();
     
      havingJSON = new JSONObject();
      try {
        havingJSON.put(QuerySerializationConstants.FILTER_ID, filter.getName());
        havingJSON.put(QuerySerializationConstants.FILTER_DESCRIPTION, filter.getDescription());
        havingJSON.put(QuerySerializationConstants.FILTER_PROMPTABLE, filter.isPromptable());
       
        operand = filter.getLeftOperand();
        havingJSON.put(QuerySerializationConstants.FILTER_LO_VALUE, operand.values[0]);
        if(operand.type.equalsIgnoreCase("Field Content")) {
         
          if(operand.values[0].contains("\"expression\":\"")){
            havingJSON.put(QuerySerializationConstants.FILTER_LO_DESCRIPTION, operand.description );
            String description = operand.values[0].substring(operand.values[0].indexOf("\"expression\":\"")+14);
            description.substring(0, description.indexOf("\""));
            havingJSON.put(QuerySerializationConstants.FILTER_LO_LONG_DESCRIPTION, description);           
          }else{
         
            datamartField = dataSource.getModelStructure().getField( operand.values[0] );
           
            String labelF, labelE;
            labelE = null;
            if(datamartLabels != null) {
              labelE = datamartLabels.getProperty(datamartField.getParent(), "label");
            }
            labelE = StringUtilities.isEmpty(labelE)? datamartField.getParent().getName(): labelE;
           
           
            labelF = null;
            if(datamartLabels != null) {
              labelF = datamartLabels.getProperty(datamartField, "label");
            }
            labelF = StringUtilities.isEmpty(labelF)? datamartField.getName(): labelF;
           
            havingJSON.put(QuerySerializationConstants.FILTER_LO_DESCRIPTION, labelE  + " : " + labelF );
           
            String loLongDescription = getFieldLongDescription(datamartField, datamartLabels);
            havingJSON.put(QuerySerializationConstants.FILTER_LO_LONG_DESCRIPTION, loLongDescription);
 
         
         
        } else if(operand.type.equalsIgnoreCase("Subquery")) {
          String loLongDescription = "Subquery " + operand.description;
          havingJSON.put(QuerySerializationConstants.FILTER_LO_LONG_DESCRIPTION, loLongDescription);
         
          havingJSON.put(QuerySerializationConstants.FILTER_LO_DESCRIPTION, operand.description);
        } else if(operand.type.equalsIgnoreCase("Parent Field Content")) {
          String[] chunks = operand.values[0].split(" ");
          String parentQueryId = chunks[0];
          String fieldName = chunks[1];
          datamartField = dataSource.getModelStructure().getField( fieldName );
          String datamartFieldLongDescription = getFieldLongDescription(datamartField, datamartLabels);
          String loLongDescription = "Query " + parentQueryId + ", " + datamartFieldLongDescription;
          havingJSON.put(QuerySerializationConstants.FILTER_LO_LONG_DESCRIPTION, loLongDescription);
         
          havingJSON.put(QuerySerializationConstants.FILTER_LO_DESCRIPTION, operand.description);
        } else {
          havingJSON.put(QuerySerializationConstants.FILTER_LO_DESCRIPTION, operand.description);
        }
       
       
       
        havingJSON.put(QuerySerializationConstants.FILTER_LO_TYPE, operand.type);
        havingJSON.put(QuerySerializationConstants.FILTER_LO_FUNCTION, operand.function.getName());
        havingJSON.put(QuerySerializationConstants.FILTER_LO_DEFAULT_VALUE, operand.defaulttValues[0]);
        havingJSON.put(QuerySerializationConstants.FILTER_LO_LAST_VALUE, operand.lastValues[0]);
       
        havingJSON.put(QuerySerializationConstants.FILTER_OPERATOR, filter.getOperator());
       
        operand = filter.getRightOperand();
        havingJSON.put(QuerySerializationConstants.FILTER_RO_VALUE, JSONUtils.asJSONArray(operand.values));
        if(operand.type.equalsIgnoreCase("Field Content")) {
          datamartField = dataSource.getModelStructure().getField( operand.values[0] );
         
          String labelF, labelE;
          labelE = null;
          if(datamartLabels != null) {
            labelE = datamartLabels.getProperty(datamartField.getParent(), "label");
          }
          labelE = StringUtilities.isEmpty(labelE)? datamartField.getParent().getName(): labelE;
         
         
          labelF = null;
          if(datamartLabels != null) {
            labelF = datamartLabels.getProperty(datamartField, "label");
          }
          labelF = StringUtilities.isEmpty(labelF)? datamartField.getName(): labelF;
         
          havingJSON.put(QuerySerializationConstants.FILTER_RO_DESCRIPTION, labelE  + " : " + labelF );
         
          String roLongDescription = getFieldLongDescription(datamartField, datamartLabels);
          havingJSON.put(QuerySerializationConstants.FILTER_RO_LONG_DESCRIPTION, roLongDescription);
View Full Code Here

    return query;
  }
 
  private void deserializeFields(JSONArray fieldsJSON, IDataSource dataSource, Query query) throws SerializationException {
    JSONObject fieldJSON;
    IModelField field;
    String alias;
    String fieldType;
   
    String fieldUniqueName;   
    String group;
    String order;
    String funct;
    String pattern;
   
    JSONObject fieldClaculationDescriptor;
    String type;
    String expression;
   
    boolean visible;
    boolean included;
   
    logger.debug("IN");
   
    try {
     
     
      logger.debug("Query [" + query.getId() + "] have [" + fieldsJSON.length() + "] to deserialize");     
      for(int i = 0; i < fieldsJSON.length(); i++) {   
        try {
          fieldJSON = fieldsJSON.getJSONObject(i);
         
          alias = fieldJSON.getString(QuerySerializationConstants.FIELD_ALIAS);         
          fieldType = fieldJSON.getString(QuerySerializationConstants.FIELD_TYPE);
          logger.debug("Deserializing field [" + alias + "] of type [" + fieldType + "]...");
         
          included = fieldJSON.getBoolean(QuerySerializationConstants.FIELD_INCLUDE);
          visible = fieldJSON.getBoolean(QuerySerializationConstants.FIELD_VISIBLE);
         
          if("datamartField".equalsIgnoreCase(fieldType)) {
            fieldUniqueName = fieldJSON.getString(QuerySerializationConstants.FIELD_ID);
            Assert.assertNotNull(fieldUniqueName, "Field name connot be null");
         
            field = dataSource.getModelStructure().getField(fieldUniqueName);
            Assert.assertNotNull(field, "Inpossible to retrive from datamart-structure a fild named " + fieldUniqueName + ". Please check select clause: " + fieldsJSON.toString());
            if(StringUtilities.isEmpty(alias)) alias = "Column_" + (i+1);
           
            group = fieldJSON.optString(QuerySerializationConstants.FIELD_GROUP);
            order = fieldJSON.optString(QuerySerializationConstants.FIELD_ORDER);
            funct = fieldJSON.optString(QuerySerializationConstants.FIELD_AGGREGATION_FUNCTION);
             
            if (AggregationFunctions.get(funct).equals(AggregationFunctions.NONE_FUNCTION)) {
              pattern = field.getPropertyAsString("format");
            } else {
              pattern = null;
            }
            query.addSelectFiled(field.getUniqueName(), funct, alias, included, visible, group.equalsIgnoreCase("true"), order, pattern);   
          } else if ("calculatedField".equalsIgnoreCase(fieldType)) {
           
            fieldClaculationDescriptor = fieldJSON.getJSONObject(QuerySerializationConstants.FIELD_ID);
            type = fieldClaculationDescriptor.getString(QuerySerializationConstants.FIELD_TYPE);
            expression = fieldClaculationDescriptor.getString(QuerySerializationConstants.FIELD_EXPRESSION);
View Full Code Here

 
 
  private void deserializeHavings(JSONArray havingsJOSN, IDataSource dataSource, Query query) throws SerializationException {
   
    JSONObject havingJSON;
    IModelField field;
       
    String filterId;
    String filterDescription;
    boolean promptable;
View Full Code Here

    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);
View Full Code Here

TOP

Related Classes of it.eng.qbe.model.structure.IModelField

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.