lundi 30 janvier 2017

Need to remove Reflection

I need to remove reflection code from my code cause its very time consuming.What are the possible alternatives?

This is my method

TransformFileType method

  public static String transformFileType( Field pField, String psValue)throws Exception{

    String sMethodName  = pField.getTransformMethod();
    if(pField.getTransformExportMethod() != null) {
        sMethodName = pField.getTransformExportMethod();
    }

    if(StringUtil.isValid(psValue))
    {
    psValue=psValue.replaceAll( "<br/>", "\n");
    }
    //FS_CUSTOM_COL_ISSUE ends
    if(sMethodName == null && pField.isBuildField()){
        return psValue;
    } else {
        if(!pField.isBuildField()) {
            String dsFldType = pField.getDisplayTypeField(); 
            if(!dsFldType.equals("Radio") && !dsFldType.equals("Combo") && !dsFldType.equals("Checkbox")) {

                String validationType=pField.getValidationType();
                if("Numeric".equals(dsFldType) && "-1".equals(psValue))
                    return "";
                else 
                    if("Double".equals(validationType)  || "Percentage".equals(validationType))
                        return  NumberFormatUtils.formatNumberField(psValue);
                    else if(!StringUtil.isValid(sMethodName))//BUG_ID-28505 added ends 
                return psValue;
            } else {
                if(!StringUtil.isValid(sMethodName)) 
                    sMethodName = "transformOptionValueForId";
            }
        }
    }
    if(!pField.isTransformRequiredInExport()) {
        return psValue;
    }
    if(StringUtil.isValid(sMethodName) && pField.getSrcTable() != null) {
        return psValue;
    }
    Class clsArr[] = new Class[]{String.class};
    Object valArr[] = new Object[]{psValue};

    if (sMethodName.equals("transformAddress") || sMethodName.equals("transformDocumentsData") || sMethodName.equals("transformAreaDocumentsData") || sMethodName.equals("transformMuDocumentsData")  )
    {
        clsArr = new Class[]{String.class, String.class};
        valArr = new Object[]{psValue, pField.getFieldName()};
    } else if(sMethodName.equals("transformOptionValueForId")) {
        clsArr = new Class[]{String.class, String.class, String.class};
        //valArr = new Object[]{pField.getFieldName(), pField.getTableName(), psValue};


        String syncWith = pField.getSyncWithField();
        String tableName = pField.getTableName();
        String fieldNameSync = pField.getFieldName();
        if(StringUtil.isValidNew(syncWith)) {
            String[] name = syncWith.split("##");
            tableName = name[0];
            fieldNameSync = name[1];
        }
        valArr = new Object[]{fieldNameSync, tableName, psValue};

    }
    ExportDataManipulator manipulator = ExportDataManipulator.getInstance();
    Method method =null;
    String sNewVal   ="";
    RefMap.put(sMethodName,clsArr);

    try{

    method = manipulator.getClass().getDeclaredMethod(sMethodName+"fileType",clsArr);
    sNewVal = (String)method.invoke(null,valArr);
    }catch(NoSuchMethodException e){

        try{
            method = manipulator.getClass().getDeclaredMethod(sMethodName,clsArr);
            sNewVal = (String)method.invoke(null,valArr);
        }catch(NoSuchMethodException e1){
            return psValue; //P_B_REST_73044
        }
    }


    if("xls".equals(exportType)&& StringUtil.isValid(sNewVal)){
        sNewVal=PortalUtils.replaceAll(sNewVal, "<br>", " ");
    }


    return sNewVal;
}

ExportDataManipulator.getLeadownerId

  public static String getLeadOwnerId(String id) throws Exception {
    try {
        //return CommonMgr.newInstance().getCommonFsDAO().getAllLeadOwners().get(id);
        return CommonMgr.newInstance().getCommonFsDAO().getLeadOwnerById(id);
    } catch(Exception e) {
        Debug.print(e);
    }
    return "";
}

CollectData->transform file type

                if(isMuFran) {
                    selectedAlias = this.dependentMuFranFieldsMap.get(tableName);
                } else {
                    selectedAlias = this.dependentFieldsMap.get(tableName);
                }
                dTable =  dependenTables[i];
                if(selectedAlias!=null && selectedAlias.contains(dTable.getTableAliasName())){
                    if (!smData.containsKey(headerName+dTable.getTableAnchor()))
                    {
                        smData.put(headerName+dTable.getTableAnchor(), new SequenceMap());
                    }
                    if("collectData".equals(fromWhere)){
                        collectData(dTable.getTableAnchor(), exportResult, smData, false, headerName);
                    }else if("collectSearchData".equals(fromWhere)){
                        if("fim".equals(menuName) && "fimEntityDetail".equals(tableName) && selectedAlias!=null && selectedAlias.contains("address_0")){//Bug 62581
                            collectSearchData(dTable.getTableAnchor(), result, smData, false, dashBoard,hFld,mappings,headerName);
                        }
                        //collectSearchData(dTable.getTableAnchor(), result, smData, false, dashBoard,hFld,mappings,headerName);
                    }
                }
            }     





Aucun commentaire:

Enregistrer un commentaire