/**
  * Writes output into csv file.
  *
  * @param masterList
  * @param num
  * @throws Exception
  */
 private void write(List<Map<AttributeInterface, Object>> masterList, int num) throws Exception {
   BufferedWriter bos = new BufferedWriter(new FileWriter(new File("c:/test" + num + ".csv")));
   for (AttributeInterface a : allowedAttributes) {
     bos.write(a.getName());
     bos.write(",");
   }
   bos.write("\n");
   for (Map<AttributeInterface, Object> map : masterList) {
     for (AttributeInterface a : allowedAttributes) {
       System.out.println(a.getName());
       Object obj = map.get(a);
       String str = "-";
       if (obj != null) {
         str = obj.toString();
       }
       bos.write(str);
       bos.write(",");
     }
     bos.write("\n");
   }
   bos.flush();
 }
Exemple #2
0
  /**
   * To add the Id columns of MainEntities in the SQL if its not present. It will also populate
   * entityIdIndexMap passes it.
   *
   * @param columnIndex columnIndex
   * @param selectSql selectSql
   * @param entityIdIndexMap entityIdIndexMap
   * @param selectSqlColumnList selectSqlColumnList
   * @param outputTreeDataNode outputTreeDataNode
   * @return The modified SQL string.
   */
  private static Map putIdColumnsInSql(
      int colIndex,
      String selectSql,
      Map<EntityInterface, Integer> entityIdIndexMap,
      List<String> selectSqlColumnList,
      OutputTreeDataNode outputTreeDataNode,
      Map<String, String> specimenMap,
      Map<String, String> columnNameVsAliasMap) {
    int columnIndex = colIndex;
    StringBuffer sql = new StringBuffer(selectSql);
    Map sqlIndexMap = new HashMap();
    if (outputTreeDataNode != null) {
      List<QueryOutputTreeAttributeMetadata> attributes = outputTreeDataNode.getAttributes();
      for (QueryOutputTreeAttributeMetadata attributeMetaData : attributes) {
        AttributeInterface attribute = attributeMetaData.getAttribute();
        String sqlColumnName = attributeMetaData.getColumnName().trim();
        if (attribute.getName().equals(AQConstants.IDENTIFIER)) {
          int index =
              selectSqlColumnList.indexOf(
                  columnNameVsAliasMap.get(sqlColumnName) + " " + sqlColumnName);

          if (index >= 0) {
            entityIdIndexMap.put(attribute.getEntity(), index);
            break;
          } else {
            // appendColNameToSql(selectSql, sql, sqlColumnName);
            entityIdIndexMap.put(attribute.getEntity(), null);
            columnIndex++;
            if (outputTreeDataNode
                .getOutputEntity()
                .getDynamicExtensionsEntity()
                .getName()
                .equals("edu.wustl.catissuecore.domain.Specimen")) {
              if (specimenMap == null) {
                specimenMap = new HashMap<String, String>();
              }
              specimenMap.put("specimenKey", "edu.wustl.catissuecore.domain.Specimen");
              specimenMap.put("columnIndex", String.valueOf(columnIndex - 1));
            }
            break;
          }
        }
      }
    }
    sqlIndexMap.put(AQConstants.SQL, sql.toString());
    sqlIndexMap.put(AQConstants.ID_COLUMN_ID, columnIndex);
    return sqlIndexMap;
  }
Exemple #3
0
 /**
  * @param strToCreateObject strToCreateObject
  * @param oprVsLstOfVals Map
  * @param expression expression
  */
 private static void processRules(
     StringBuffer strToCreateObject,
     Map<RelationalOperator, List<String>> oprVsLstOfVals,
     IExpression expression) {
   ICondition idCondition = null;
   Rule rule = ((Rule) (expression.getOperand(0)));
   for (ICondition condition : rule) {
     AttributeInterface conditionAttr = condition.getAttribute();
     String attrName = conditionAttr.getName();
     if (attrName.equalsIgnoreCase("id")) {
       idCondition = processRuleForId(oprVsLstOfVals, condition);
     } else {
       processRuleForOtherAttributes(strToCreateObject, condition, conditionAttr, attrName);
     }
   }
   // rule.removeCondition(idCondition);
 }
  /**
   * Mock method for creating category records.
   *
   * @param catClass
   * @param howMany
   * @return
   */
  private List<ICategorialClassRecord> createRecord(CategorialClass catClass, int howMany) {
    List<ICategorialClassRecord> records = new ArrayList<ICategorialClassRecord>(howMany);
    Collection<AttributeInterface> collection =
        catClass.getCategorialClassEntity().getAttributeCollection();
    Set<AttributeInterface> set = new HashSet<AttributeInterface>(collection);

    for (int i = 0; i < howMany; i++) {
      ICategorialClassRecord record =
          QueryResultFactory.createCategorialClassRecord(
              catClass, set, new RecordId(recordId++ + "", ""));
      for (AttributeInterface attr : record.getAttributes()) {
        record.putStringValueForAttribute(attr, attr.getName() + "_R_" + counter);
      }
      records.add(record);
      counter++;
    }
    return records;
  }
Exemple #5
0
  /**
   * @see
   *     edu.common.dynamicextensions.validation.ValidatorRuleInterface#validate(edu.common.dynamicextensions.domaininterface.AttributeInterface,
   *     java.lang.Object, java.util.Map)
   * @throws DynamicExtensionsValidationException
   */
  public boolean validate(
      AttributeInterface attribute, Object valueObject, Map<String, String> parameterMap)
      throws DynamicExtensionsValidationException {
    boolean valid = false;
    String attributeName = attribute.getName();
    AttributeTypeInformationInterface attributeTypeInformation =
        attribute.getAttributeTypeInformation();

    if (((valueObject != null) && (!((String) valueObject).trim().equals("")))
        && ((attributeTypeInformation != null)
            && (attributeTypeInformation instanceof DateAttributeTypeInformation))) {
      DateAttributeTypeInformation dateAttributeTypeInformation =
          (DateAttributeTypeInformation) attributeTypeInformation;
      String dateFormat = dateAttributeTypeInformation.getFormat();
      String value = (String) valueObject;

      if (dateFormat.equals(ProcessorConstants.MONTH_YEAR_FORMAT)) {
        value = DynamicExtensionsUtility.formatMonthAndYearDate(value);
        value = value.substring(0, value.length() - 4);
      }
      if (dateFormat.equals(ProcessorConstants.YEAR_ONLY_FORMAT)) {
        value = DynamicExtensionsUtility.formatYearDate(value);
        value = value.substring(0, value.length() - 4);
      }

      try {
        Date date = null;
        date = Utility.parseDate(value, "MM-dd-yyyy");
        if (date != null) {
          valid = true;
        }
      } catch (ParseException parseException) {
        List<String> placeHolders = new ArrayList<String>();
        placeHolders.add(attributeName);
        placeHolders.add(dateFormat);
        throw new DynamicExtensionsValidationException(
            "Validation failed", null, "dynExtn.validation.Date", placeHolders);
      }
    }
    return valid;
  }