Program: 136670
Project: 136670
Buggy source:
/** 
 * Added: (20120808 yyin, TDQ-4189) The system indicators are not read-only because the user may want to write his own SQL template. so this task deals with the modified SI from imported one, and merge them with the current studio. 1)only when the user select the"Overwrite existing items" on the import wizard(and the modifydate is newer than the current studio's SI), the conflict modification in imported SI will overwrite the ones in current studio, otherwise, the SI in current studio will keep. 2)If a language does not exist in the system indicator but exists in the user modified indicator, then we add it 3)if a language exists in the system indicator but has been removed in the user modified indicator, then we keep the system indicator definition. [for Indicator matadata(Purpose, Description, Author, Status): 1) will replace old value with new value if new value is not blank; 2) will keep old value if new value is blank][for IndicatorDefinitionParameter: 1) will replace the same name old parameter with new parameter; 2) will keep the old parameter if new one don't include the same name parameter ]
 * @param record imported modified system indicator
 * @param siDef the system indicator in the current studio
 */
protected void mergeSystemIndicator(ItemRecord record,TDQIndicatorDefinitionItem siDefItem){
  boolean isModified=false;
  IndicatorDefinition siDef=siDefItem.getIndicatorDefinition();
  Property siProp=siDefItem.getProperty();
  IndicatorDefinition indDef=(IndicatorDefinition)record.getElement();
  Property indDefProp=record.getProperty();
  EList<TdExpression> importedExs=indDef.getSqlGenericExpression();
  for (  TdExpression importedEx : importedExs) {
    if (importedEx.getModificationDate() == null) {
      continue;
    }
    TdExpression systemExpression=null;
    for (    TdExpression ex : siDef.getSqlGenericExpression()) {
      if (ex.getLanguage().equals(importedEx.getLanguage())) {
        systemExpression=ex;
        break;
      }
    }
    if (systemExpression == null) {
      IndicatorDefinitionFileHelper.addSqlExpression(siDef,importedEx.getLanguage(),importedEx.getBody(),importedEx.getModificationDate());
      isModified=true;
    }
 else {
      if (replaceExpression(systemExpression,importedEx)) {
        IndicatorDefinitionFileHelper.removeSqlExpression(siDef,importedEx.getLanguage());
        IndicatorDefinitionFileHelper.addSqlExpression(siDef,importedEx.getLanguage(),importedEx.getBody(),importedEx.getModificationDate());
        isModified=true;
      }
    }
  }
  IndicatorCategory siDefCategory=IndicatorCategoryHelper.getCategory(siDef);
  IndicatorCategory indDefCategory=IndicatorCategoryHelper.getCategory(indDef);
  if (siDefCategory != null && indDefCategory != null && !indDefCategory.eIsProxy()) {
    if (!siDefCategory.equals(indDefCategory)) {
      IndicatorCategoryHelper.setCategory(siDef,indDefCategory);
      isModified=true;
    }
  }
  if (siProp != null && indDefProp != null) {
    if (!StringUtils.isBlank(indDefProp.getPurpose())) {
      siProp.setPurpose(indDefProp.getPurpose());
    }
    if (!StringUtils.isBlank(indDefProp.getDescription())) {
      siProp.setDescription(indDefProp.getDescription());
    }
    siProp.setAuthor(indDefProp.getAuthor());
    siProp.setStatusCode(indDefProp.getStatusCode());
    isModified=true;
  }
  String jarFilePath=TaggedValueHelper.getJarFilePath(indDef);
  if (!StringUtils.isBlank(jarFilePath)) {
    TaggedValueHelper.setJarFilePath(jarFilePath,siDef);
    isModified=true;
  }
  String classNameText=TaggedValueHelper.getClassNameText(indDef);
  if (!StringUtils.isBlank(classNameText)) {
    TaggedValueHelper.setClassNameText(classNameText,siDef);
    isModified=true;
  }
  EList<IndicatorDefinitionParameter> siParameter=siDef.getIndicatorDefinitionParameter();
  EList<IndicatorDefinitionParameter> indDefParameter=indDef.getIndicatorDefinitionParameter();
  List<IndicatorDefinitionParameter> tempParameter=new ArrayList<IndicatorDefinitionParameter>();
  for (  IndicatorDefinitionParameter indDefPara : indDefParameter) {
    boolean include=false;
    String key=indDefPara.getKey();
    for (    IndicatorDefinitionParameter siPara : siParameter) {
      if (key.equals(siPara.getKey())) {
        include=true;
        siPara.setValue(indDefPara.getValue());
        isModified=true;
      }
    }
    if (!include) {
      tempParameter.add(indDefPara);
      isModified=true;
    }
  }
  if (isModified && !tempParameter.isEmpty()) {
    siParameter.addAll(tempParameter);
  }
  if (isModified) {
    try {
      ElementWriterFactory.getInstance().createIndicatorDefinitionWriter().save(siDefItem,false);
    }
 catch (    Exception e) {
      log.error(e);
    }
  }
}

Fixed version (ground truth):
/** 
 * Added: (20120808 yyin, TDQ-4189) The system indicators are not read-only because the user may want to write his own SQL template. so this task deals with the modified SI from imported one, and merge them with the current studio. 1)only when the user select the"Overwrite existing items" on the import wizard(and the modifydate is newer than the current studio's SI), the conflict modification in imported SI will overwrite the ones in current studio, otherwise, the SI in current studio will keep. 2)If a language does not exist in the system indicator but exists in the user modified indicator, then we add it 3)if a language exists in the system indicator but has been removed in the user modified indicator, then we keep the system indicator definition. [for Indicator matadata(Purpose, Description, Author, Status): 1) will replace old value with new value if new value is not blank; 2) will keep old value if new value is blank][for IndicatorDefinitionParameter: 1) will replace the same name old parameter with new parameter; 2) will keep the old parameter if new one don't include the same name parameter ]
 * @param record imported modified system indicator
 * @param siDef the system indicator in the current studio
 */
protected void mergeSystemIndicator(ItemRecord record,TDQIndicatorDefinitionItem siDefItem){
  boolean isModified=false;
  IndicatorDefinition siDef=siDefItem.getIndicatorDefinition();
  Property siProp=siDefItem.getProperty();
  IndicatorDefinition indDef=(IndicatorDefinition)record.getElement();
  Property indDefProp=record.getProperty();
  EList<TdExpression> importedExs=indDef.getSqlGenericExpression();
  for (  TdExpression importedEx : importedExs) {
    if (importedEx.getModificationDate() == null) {
      continue;
    }
    TdExpression systemExpression=null;
    for (    TdExpression ex : siDef.getSqlGenericExpression()) {
      if (ex.getLanguage().equals(importedEx.getLanguage())) {
        systemExpression=ex;
        break;
      }
    }
    if (systemExpression == null) {
      IndicatorDefinitionFileHelper.addSqlExpression(siDef,importedEx.getLanguage(),importedEx.getBody(),importedEx.getModificationDate());
      isModified=true;
    }
 else {
      if (replaceExpression(systemExpression,importedEx)) {
        IndicatorDefinitionFileHelper.removeSqlExpression(siDef,importedEx.getLanguage());
        IndicatorDefinitionFileHelper.addSqlExpression(siDef,importedEx.getLanguage(),importedEx.getBody(),importedEx.getModificationDate());
        isModified=true;
      }
    }
  }
  IndicatorCategory siDefCategory=IndicatorCategoryHelper.getCategory(siDef);
  IndicatorCategory indDefCategory=IndicatorCategoryHelper.getCategory(indDef);
  siDefCategory=(IndicatorCategory)EObjectHelper.resolveObject(siDefCategory);
  indDefCategory=(IndicatorCategory)EObjectHelper.resolveObject(indDefCategory);
  if (!ModelElementHelper.compareUUID(siDefCategory,indDefCategory)) {
    IndicatorCategoryHelper.setCategory(siDef,indDefCategory);
    isModified=true;
  }
 else {
    if (siDefCategory != null && indDefCategory != null && !siDefCategory.eIsProxy()) {
      if (!indDefCategory.equals(siDefCategory)) {
        if (!indDefCategory.getLabel().equals("String_Node_Str")) {
          IndicatorCategoryHelper.setCategory(siDef,indDefCategory);
          isModified=true;
        }
      }
    }
  }
  if (siProp != null && indDefProp != null) {
    if (!StringUtils.isBlank(indDefProp.getPurpose())) {
      siProp.setPurpose(indDefProp.getPurpose());
    }
    if (!StringUtils.isBlank(indDefProp.getDescription())) {
      siProp.setDescription(indDefProp.getDescription());
    }
    siProp.setAuthor(indDefProp.getAuthor());
    siProp.setStatusCode(indDefProp.getStatusCode());
    isModified=true;
  }
  String jarFilePath=TaggedValueHelper.getJarFilePath(indDef);
  if (!StringUtils.isBlank(jarFilePath)) {
    TaggedValueHelper.setJarFilePath(jarFilePath,siDef);
    isModified=true;
  }
  String classNameText=TaggedValueHelper.getClassNameText(indDef);
  if (!StringUtils.isBlank(classNameText)) {
    TaggedValueHelper.setClassNameText(classNameText,siDef);
    isModified=true;
  }
  EList<IndicatorDefinitionParameter> siParameter=siDef.getIndicatorDefinitionParameter();
  EList<IndicatorDefinitionParameter> indDefParameter=indDef.getIndicatorDefinitionParameter();
  List<IndicatorDefinitionParameter> tempParameter=new ArrayList<IndicatorDefinitionParameter>();
  for (  IndicatorDefinitionParameter indDefPara : indDefParameter) {
    boolean include=false;
    String key=indDefPara.getKey();
    for (    IndicatorDefinitionParameter siPara : siParameter) {
      if (key.equals(siPara.getKey())) {
        include=true;
        siPara.setValue(indDefPara.getValue());
        isModified=true;
      }
    }
    if (!include) {
      tempParameter.add(indDefPara);
      isModified=true;
    }
  }
  if (isModified && !tempParameter.isEmpty()) {
    siParameter.addAll(tempParameter);
  }
  if (isModified) {
    try {
      ElementWriterFactory.getInstance().createIndicatorDefinitionWriter().save(siDefItem,false);
    }
 catch (    Exception e) {
      log.error(e);
    }
  }
}