Example usage for java.lang StringBuffer deleteCharAt

List of usage examples for java.lang StringBuffer deleteCharAt

Introduction

In this page you can find the example usage for java.lang StringBuffer deleteCharAt.

Prototype

@Override
public synchronized StringBuffer deleteCharAt(int index) 

Source Link

Usage

From source file:org.apache.geode.internal.cache.wan.WANTestBase.java

public static void createLocator(int dsId, int port, Set<String> localLocatorsList,
        Set<String> remoteLocatorsList) {
    WANTestBase test = new WANTestBase();
    Properties props = test.getDistributedSystemProperties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(DISTRIBUTED_SYSTEM_ID, "" + dsId);
    StringBuffer localLocatorBuffer = new StringBuffer(localLocatorsList.toString());
    localLocatorBuffer.deleteCharAt(0);
    localLocatorBuffer.deleteCharAt(localLocatorBuffer.lastIndexOf("]"));
    String localLocator = localLocatorBuffer.toString();
    localLocator = localLocator.replace(" ", "");

    props.setProperty(LOCATORS, localLocator);
    props.setProperty(START_LOCATOR,/*www  . j  a  v a2 s  . c om*/
            "localhost[" + port + "],server=true,peer=true,hostname-for-clients=localhost");
    StringBuffer remoteLocatorBuffer = new StringBuffer(remoteLocatorsList.toString());
    remoteLocatorBuffer.deleteCharAt(0);
    remoteLocatorBuffer.deleteCharAt(remoteLocatorBuffer.lastIndexOf("]"));
    String remoteLocator = remoteLocatorBuffer.toString();
    remoteLocator = remoteLocator.replace(" ", "");
    props.setProperty(REMOTE_LOCATORS, remoteLocator);
    test.getSystem(props);
}

From source file:com.smart.smartrestfulw.controller.FileDepotController.java

private ExecuteResultParam InvalidDepotFile(FileDepotParamModel paramModel) throws Exception {
    StringBuffer sbSql = new StringBuffer();
    StringBuffer sbSqlDelete = new StringBuffer();
    List<String> lsSql = null;
    try {/*from w ww .j  a v a2s.  c  om*/
        sbSql.append(String.format(
                "insert into FILEDEPOT_LS (FID,FNAME,FPATH,FSUMMARY,OWNID,OWNFILETYPE,UPLOADDATE) select  FID,FNAME,FPATH,FSUMMARY,OWNID,OWNFILETYPE,UPLOADDATE from FILEDEPOT  as t_f where t_f.OWNID='%s' ",
                paramModel.ownid));
        sbSqlDelete.append(String.format("delete FILEDEPOT  where OWNID='%s' ", paramModel.ownid));
        if (paramModel.fileDetaile != null && paramModel.fileDetaile.size() > 0) {
            if (paramModel.selectFlag == 1) {
                sbSql.append(" and t_f.FID in (");
                sbSqlDelete.append(" and FID in (");
            } else if (paramModel.selectFlag == 2) {
                sbSql.append(" and t_f.OWNFILETYPE in ( ");
                sbSqlDelete.append(" and OWNFILETYPE in ( ");
            } else {
                return new ExecuteResultParam(-1,
                        "?json????");
            }
            for (DepotFileDetailModel paramModelTemp : paramModel.fileDetaile) {
                if (paramModel.selectFlag == 1) {
                    sbSql.append("'").append(paramModelTemp.fileId).append("'");
                    sbSqlDelete.append("'").append(paramModelTemp.fileId).append("'");
                } else if (paramModel.selectFlag == 2) {
                    sbSql.append("'").append(paramModelTemp.fileOwnType).append("'");
                    sbSqlDelete.append("'").append(paramModelTemp.fileOwnType).append("'");
                } else {
                    return new ExecuteResultParam(-1,
                            "?json????");
                }
                sbSql.append(',');
                sbSqlDelete.append(",");
            }
            sbSql.deleteCharAt(sbSql.length() - 1);
            sbSql.append(")");

            sbSqlDelete.deleteCharAt(sbSqlDelete.length() - 1);
            sbSqlDelete.append(")");
        }
        lsSql = new ArrayList<String>();

        lsSql.add(sbSql.toString());
        lsSql.add(sbSqlDelete.toString());
        return DBHelper.ExecuteSql(DeployInfo.MasterRSID, lsSql);
    } catch (Exception e) {
        throw new Exception(e.getLocalizedMessage());
    } finally {
        UtileSmart.FreeObjects(paramModel, sbSql, sbSqlDelete);
    }
}

From source file:ParseURL.java

/**************************************************************************
 * Create a new munge string containing the desired RBNB munge components.
 * <p>/*from w w  w . jav  a2s  .c om*/
 * The user can selectively remove munge components as specified by the
 * boolean arguments.  If the user has not chosen to remove any munge
 * component, then the original, complete munge string is returned.
 *
 * @author John P. Wilson
 *
 * @param bRemoveTimeI      Remove time from returned munge?
 * @param bRemoveDurationI      Remove duration from returned munge?
 * @param bRemoveReferenceI      Remove reference from returned munge?
 * @param bRemoveFetchI      Remove fetch from returned munge?
 * @param bRemoveByteorderI      Remove byteorder from returned munge?
 * @param bRemoveDatatypeI      Remove datatype from returned munge?
 * @param bRemoveMuxI      Remove mux from returned munge?
 * @param bRemoveBlocksizeI      Remove blocksize from returned munge?
 * @param bRemoveMimeI      Remove mime from returned munge?
 * @param bRemoveNonRBNBMungeI   Remove non RBNB munges from returned munge?
 *
 * @version 09/28/2006
 */

/*
 *
 *   Date      By     Description
 * MM/DD/YYYY
 * ----------  --     -----------
 * 09/28/2006  JPW    Change "bRemoveMessageI" to "bRemoveNonRBNBMungeI"
 * 06/02/2006  JPW    Created
 *
 */

public String createNewRBNBMunge(boolean bRemoveTimeI, boolean bRemoveDurationI, boolean bRemoveReferenceI,
        boolean bRemoveFetchI, boolean bRemoveByteorderI, boolean bRemoveDatatypeI, boolean bRemoveMuxI,
        boolean bRemoveBlocksizeI, boolean bRemoveMimeI, boolean bRemoveNonRBNBMungeI) {

    // JPW 09/28/2006: If user has not chosen to remove anything, then
    //                 simply return the original, complete munge string.
    if ((!bRemoveTimeI) && (!bRemoveDurationI) && (!bRemoveReferenceI) && (!bRemoveFetchI)
            && (!bRemoveByteorderI) && (!bRemoveDatatypeI) && (!bRemoveMuxI) && (!bRemoveBlocksizeI)
            && (!bRemoveMimeI) && (!bRemoveNonRBNBMungeI)) {
        return munge;
    }

    StringBuffer newMunge = new StringBuffer();

    if ((getTime() != null) && (!bRemoveTimeI)) {
        newMunge.append("&t=" + getTime().toString());
    }
    if ((getDuration() != null) && (!bRemoveDurationI)) {
        newMunge.append("&d=" + getDuration().toString());
    }
    if ((getReference() != null) && (!bRemoveReferenceI)) {
        newMunge.append("&r=" + getReference());
    }
    if ((getFetch() != null) && (!bRemoveFetchI)) {
        newMunge.append("&f=" + getFetch());
    }
    if ((getByteorder() != null) && (!bRemoveByteorderI)) {
        newMunge.append("&bo=" + getByteorder());
    }
    if ((getDatatype() != null) && (!bRemoveDatatypeI)) {
        newMunge.append("&dt=" + getDatatype());
    }
    if ((getMux() != null) && (!bRemoveMuxI)) {
        newMunge.append("&x=" + getMux().toString());
    }
    if ((getBlocksize() != null) && (!bRemoveBlocksizeI)) {
        newMunge.append("&bs=" + getBlocksize().toString());
    }
    if ((getMime() != null) && (!bRemoveMimeI)) {
        newMunge.append("&m=" + getMime());
    }
    // JPW 09/28/2006: Return the non RBNB munges as a series of key/value
    //                 pairs; don't return them encoded in the "msg"
    //                 munge (RBNB servlet doesn't do anything special
    //                 with the "msg" munge now).
    if ((getNonRBNBMungeStr() != null) && (!bRemoveNonRBNBMungeI)) {
        newMunge.append("&" + getNonRBNBMungeStr());
    }

    if (newMunge.length() == 0) {
        return null;
    }

    // If there is a leading '&', remove it
    if (newMunge.charAt(0) == '&') {
        newMunge = newMunge.deleteCharAt(0);
    }

    return newMunge.toString();

}

From source file:org.LexGrid.util.sql.lgTables.SQLTableUtilities.java

/**
 * Runs SQL Statement "SELECT" with supplied attributes and where clause
 * //from   w w  w.  ja  v a 2s.co m
 * @param tableName
 * @param attributeNames
 * @param whereClause
 * @return
 * @throws SQLException
 */
public ResultSet extractDataFromDB(String tableName, Map attributeNames, String whereClause, String dbType)
        throws SQLException {

    StringBuffer stmt = new StringBuffer();
    PreparedStatement prepStmt = null;
    ResultSet resultSet = null;

    stmt.append("SELECT ");

    for (int i = 0; i < attributeNames.size(); i++) {
        stmt.append(attributeNames.get("" + (i + 1)) + ",");
    }

    stmt = stmt.deleteCharAt(stmt.length() - 1);

    stmt.append(" FROM ");
    stmt.append(tablePrefix_ + tableName);

    if (whereClause != null && !whereClause.equals("")) {
        stmt.append(" WHERE ");
        stmt.append(whereClause);
    }

    log.debug("************ SELECT QUERY ************");
    log.debug(stmt.toString());
    log.debug("**************************************");

    try {
        String statement = new GenericSQLModifier(dbType, false).modifySQL(stmt.toString());

        prepStmt = sqlConnection_.prepareStatement(statement, ResultSet.TYPE_SCROLL_INSENSITIVE,
                ResultSet.CONCUR_READ_ONLY);
        resultSet = prepStmt.executeQuery();
    } catch (Exception e) {
        log.error("Exception @ extractDataFromDB: " + e.getMessage());
    } finally {
        // prepStmt.close();
    }

    return resultSet;
}

From source file:org.soas.solr.update.processor.WhereDifferentUPF.java

@Override
public final UpdateRequestProcessor getInstance(SolrQueryRequest req, SolrQueryResponse rsp,
        UpdateRequestProcessor next) {/*from  w ww .ja  va2 s. c om*/
    return new UpdateRequestProcessor(next) {
        @Override
        public void processAdd(AddUpdateCommand cmd) throws IOException {

            final SolrInputDocument doc = cmd.getSolrInputDocument();

            Collection c = doc.getFieldValues(tagFieldName);

            if (c != null) {
                Iterator it = c.iterator();

                while (it.hasNext()) {
                    String next = (String) it.next();

                    if (doc.containsKey(posFieldName + "_" + next)
                            && doc.containsKey(compareFieldName + "_" + next)) {
                        String posFieldValue = (String) doc.getFieldValue(posFieldName + "_" + next);
                        String[] pos = posFieldValue.split("\\s+");
                        String compareFieldValue = (String) doc.getFieldValue(compareFieldName + "_" + next);
                        String[] compare = compareFieldValue.split("\\s+");

                        //log.info("posFieldValue = " + posFieldValue);
                        //log.info("compareFieldValue = " + compareFieldValue);

                        if (compare.length == pos.length
                                && !(compare.length == 1 && compare[0].equals(compareFieldValue))) {
                            //Pattern oneTag = Pattern.compile("\\[?([^\\]]+)\\]?");
                            Pattern splitter = Pattern.compile("\\]\\[");
                            StringBuffer sbDiff = new StringBuffer();
                            StringBuffer sbChange = new StringBuffer();
                            for (int i = 0; i < compare.length; i++) {
                                sbDiff.append(pos[i]);
                                String tags = compare[i].substring(compare[i].indexOf('|') + 1);
                                if (tags.charAt(0) == '[') {
                                    tags = tags.substring(1, tags.length() - 1); //strip [ and ]
                                }

                                //Matcher m = oneTag.matcher(tags);
                                //if (m.matches()) {

                                String[] tagList = splitter.split(tags);
                                String posRef = pos[i].substring(pos[i].indexOf('|') + 1);
                                boolean match = false;
                                for (int k = 0; k < tagList.length; k++) {
                                    //String tag = m.group(1); //tags.substring(1, tags.length()-1);
                                    //if (!tag.equals(pos[i].substring(pos[i].indexOf('|')+1))) {
                                    if (tagList[k].equals(posRef)) {
                                        match = true;
                                        break;
                                    }
                                }

                                if (!match) {
                                    sbDiff.append(diffDelim);
                                    sbDiff.append(StringUtils.join(tagList, "~"));
                                }
                                /*
                                    sbDiff.append(diffDelim);
                                    sbDiff.append(tag);
                                    sbChange.append(pos[i].substring(0, pos[i].indexOf('|')));
                                    sbChange.append(diffDelim);
                                    sbChange.append(tag);
                                }
                                else {
                                    sbChange.append(pos[i]);
                                }
                                }
                                else {
                                sbChange.append(pos[i]);
                                }
                                */
                                sbDiff.append(' ');
                                sbChange.append(' ');
                            }
                            sbDiff.deleteCharAt(sbDiff.length() - 1); //remove final space  
                            sbChange.deleteCharAt(sbChange.length() - 1); //remove final space

                            if (differentFieldName != null) {
                                SolrInputField differentField = new SolrInputField(
                                        differentFieldName + "_" + next);
                                differentField.setValue(sbDiff.toString(), 1.0f);
                                doc.put(differentFieldName + "_" + next, differentField);
                            }

                            if (changeFieldName != null) {
                                SolrInputField changeField = new SolrInputField(changeFieldName + "_" + next);
                                changeField.setValue(sbChange.toString(), 1.0f);
                                doc.put(changeFieldName + "_" + next, changeField);
                            }
                        }
                    }
                }
            }

            super.processAdd(cmd);
        }
    };
}

From source file:org.ecoinformatics.datamanager.database.DelimitedReader.java

private String[] processQuoteCharacterOneRowData(String oneRowData) throws Exception {
    String[] elements = null;/*from  w w  w  . ja  va 2  s.co  m*/
    Vector elementsVector = new Vector();
    if (oneRowData == null) {
        return elements;
    }
    quoteCharacter = transferQuoteCharacter(quoteCharacter);
    char quote = '#';
    boolean quoted = false;
    if (quoteCharacter != null) {
        quoted = true;
        quote = quoteCharacter.charAt(0);
    }
    char literal = '/';
    boolean literaled = false;
    if (literalCharacter != null) {
        literaled = true;
        literal = literalCharacter.charAt(0);
    }
    if (literaled && literalCharacter.length() != 1) {
        throw new Exception("Literal Character length should be 1 character in EML");
    }
    char currentChar = '2';
    StringBuffer fieldData = new StringBuffer();
    int length = oneRowData.length();
    int priviousDelimiterIndex = -2;
    int currentDelimiterIndex = -2;
    int delimiterLength = delimiter.length();
    boolean startQuote = false;
    boolean delimiterAtEnd = false;
    //this string buffer is only for deleting if hit a delimiter
    StringBuffer delimiterStorage = new StringBuffer(delimiter.length());
    for (int i = 0; i < length; i++) {
        currentChar = oneRowData.charAt(i);
        //System.out.println("current char is "+currentChar);
        fieldData.append(currentChar);
        if (i < delimiterLength) {
            delimiterStorage.append(currentChar);
        } else {
            //delimiterStorage.deleteCharAt(position);
            delimiterStorage = shiftBuffer(delimiterStorage, currentChar);
        }
        //System.out.println("current delimiter storage content is "+delimiterStorage.toString());
        //System.out.println("currnet value in the string buffer is "+fieldData.toString());
        // we should check if there is quoteCharacter in the string.
        if (quoted && currentChar == quote) {
            char previousChar = '1';
            boolean escapingQuote = false;
            // check if this quote is escaped
            if (literaled) {
                if ((i - 1) >= 0) {
                    previousChar = oneRowData.charAt(i - 1);
                    if (previousChar == literal) {
                        escapingQuote = true;
                        // delette the literal character
                        if (!includeLiteralCharacter) {
                            //if we don't want literal character in the data,
                            //we should delete literal character.
                            int fieldLength = fieldData.length();
                            if ((fieldLength - 1 - 1) >= 0) {
                                fieldData.deleteCharAt(fieldLength - 1 - 1);
                            }
                        }
                    }
                }
            }
            if (!escapingQuote) {
                if (!startQuote) {
                    //System.out.println("start quote");
                    startQuote = true;
                } else {
                    //System.out.println("end quote");
                    // at end of quote
                    //put string buffers value into vector and reset string buffer
                    startQuote = false;

                }
            }

        }

        //found a delimiter
        if (delimiterStorage.indexOf(delimiter) != -1 && !startQuote) {

            //check if there is literal character before the delimiter,
            //if does, this we should skip this delmiter
            int indexOfCharBeforeDelimiter = i - delimiterLength;
            boolean escapeDelimiter = false;
            if (literaled && indexOfCharBeforeDelimiter >= 0) {
                char charBeforeDelimiter = oneRowData.charAt(indexOfCharBeforeDelimiter);
                ////there is a literal character before delimiter we should skip this demlimiter
                if (charBeforeDelimiter == literal) {
                    if (!includeLiteralCharacter) {
                        //if we don't want literal character in the data,
                        //we should delete literal character.
                        int fieldLength = fieldData.length();
                        if ((fieldLength - delimiterLength - 1) >= 0) {
                            fieldData.deleteCharAt(fieldLength - delimiterLength - 1);
                        }
                    }
                    escapeDelimiter = true;
                    continue;
                }
            }

            // check if the delimiter is in the end of the string
            if (i == (length - 1) && !startQuote && !escapeDelimiter) {
                delimiterAtEnd = true;
            }

            ////here we should treat sequential delimiter as single delimiter
            if (collapseDelimiters) {
                priviousDelimiterIndex = currentDelimiterIndex;
                currentDelimiterIndex = i;
                //there is nothing between two delimiter, should skip it.
                if ((currentDelimiterIndex - priviousDelimiterIndex) == delimiterLength) {
                    //delete sequnced delimiter
                    fieldData = new StringBuffer();
                    continue;
                }
            }

            String value = "";
            int delimiterIndex = fieldData.lastIndexOf(delimiter);
            if (delimiterIndex == 0) {
                //this path means field data on has delimiter, no real data
                value = "";
            } else {
                value = fieldData.substring(0, delimiterIndex);

            }
            elementsVector.add(value);
            //reset string buffer fieldData
            fieldData = new StringBuffer();

        }
    }
    // if startQuote is true at the end, which means there is no close quote character in this row,
    // code should throw an exception
    if (startQuote) {
        throw new Exception("There is a un-closed quote in data file");
    }
    // add last field. If this string end of delimiter, we need add a ""
    // else, we need to add the value in string buffer.
    String lastFieldValue = null;
    if (delimiterAtEnd == true) {
        //this path means field data on has delimiter, no real data
        lastFieldValue = "";
    } else {
        lastFieldValue = fieldData.toString();

    }
    elementsVector.add(lastFieldValue);
    //transform vector to string array
    int size = elementsVector.size();
    elements = new String[size];
    for (int i = 0; i < size; i++) {
        elements[i] = (String) elementsVector.elementAt(i);
    }
    return elements;
}

From source file:com.wabacus.system.component.application.report.ListReportType.java

private String getSubDataString(Object dataObj) {
    StringBuffer resultBuf = new StringBuffer();
    Object coldataTmp;//from   ww  w .jav  a  2 s. co  m
    for (Entry<String, Method> entryTmp : this.alrbean.getSubdisplaybean().getMPropertiesAndGetMethods()
            .entrySet()) {
        resultBuf.append("\"" + entryTmp.getKey() + "\":\"");
        try {
            coldataTmp = entryTmp.getValue().invoke(dataObj, new Object[] {});
        } catch (Exception e) {
            throw new WabacusRuntimeException("??" + entryTmp.getValue().getName() + "?"
                    + rbean.getPath() + "?", e);
        }
        if (coldataTmp == null) {
            resultBuf.append("");
        } else {
            resultBuf.append(Tools.jsParamEncode(String.valueOf(coldataTmp)));
        }
        resultBuf.append("\",");
    }
    if (resultBuf.charAt(resultBuf.length() - 1) == ',')
        resultBuf.deleteCharAt(resultBuf.length() - 1);
    return resultBuf.toString();
}

From source file:com.globalsight.everest.webapp.pagehandler.edit.inctxrv.EditorPageHandler.java

/**
 * Get the target language based on job id and source page id
 * //  ww  w. j av a2  s.  com
 * @throws EnvoyServletException
 */
private String getTargetIDS(String p_jobId, String p_srcPageId) throws EnvoyServletException {
    StringBuffer result = new StringBuffer();
    try {
        Job job = ServerProxy.getJobHandler().getJobById(Long.parseLong(p_jobId));
        Collection<Workflow> wfs = job.getWorkflows();
        for (Iterator<Workflow> it = wfs.iterator(); it.hasNext();) {
            Workflow wf = (Workflow) it.next();
            if (Workflow.CANCELLED.equals(wf.getState()) || Workflow.EXPORT_FAILED.equals(wf.getState())
                    || Workflow.IMPORT_FAILED.equals(wf.getState())) {
                continue;
            }

            /*
             * Canceled for GBS-2419 Collection targetPages =
             * wf.getTargetPages(); for (Iterator itr =
             * targetPages.iterator(); itr.hasNext();) { TargetPage tp =
             * (TargetPage) itr.next(); if
             * (p_srcPageId.equals(Long.toString(tp.getSourcePage()
             * .getId()))) { return wf.getTargetLocale().getDisplayName(); }
             * }
             */

            result.append(wf.getTargetLocale().getId()).append(",");
        }
    } catch (Exception e) {
        CATEGORY.error("Problem getting job from database ", e);
        throw new EnvoyServletException(e);
    }

    if (result.length() > 0 && result.toString().endsWith(",")) {
        result.deleteCharAt(result.length() - 1);
    }

    return result.toString();
}

From source file:com.cardpay.pccredit.ipad.service.IpadCommonService.java

public CompositeData ipadQueryDhjcist(CompositeData BODY, String limit, String page) throws Exception {
    String QUERY_TYPE = BODY.getField("TRAN_TYPE").strValue();
    String userId = BODY.getField("USER_NO").strValue();
    String chineseName = BODY.getField("CLIENT_NAME").strValue();
    String cardId = BODY.getField("GLOBAL_ID").strValue();
    String clientNo = BODY.getField("CLIENT_NO").strValue();
    String checkType = BODY.getField("CHECK_TYPE").strValue();
    String APPROVE_STATUS = BODY.getField("APPROVE_STATUS").strValue();

    //?/*from  w  w  w  .  j a  v a 2s  .  co m*/
    if (StringUtils.isEmpty(userId)) {
        throw new IpadException("?!");
    }

    StringBuffer belongChildIds = new StringBuffer();
    belongChildIds.append("(");
    if ("1".equals(APPROVE_STATUS.substring(0, 1))) {
        belongChildIds.append("'").append("0").append("'").append(",");
    }

    if ("1".equals(APPROVE_STATUS.substring(1, 2))) {
        belongChildIds.append("'").append("1").append("'").append(",");
    }

    if ("1".equals(APPROVE_STATUS.substring(2, 3))) {
        belongChildIds.append("'").append("2").append("'").append(",");
    }
    belongChildIds = belongChildIds.deleteCharAt(belongChildIds.length() - 1);
    belongChildIds.append(")");

    List<CustomerDhJcInfoIpad> CustomerDhJcInfoIpad_ls = new ArrayList<CustomerDhJcInfoIpad>();

    //?
    CustomerDhJcInfoIpad_ls = customerInforDao.ipadDhJcByUserId(QUERY_TYPE, APPROVE_STATUS, userId, chineseName,
            cardId, clientNo, checkType, belongChildIds.toString(), limit, page);

    //
    CompositeData respBody = new CompositeData();
    Array array = new Array();
    for (CustomerDhJcInfoIpad obj : CustomerDhJcInfoIpad_ls) {
        CompositeData struct = new CompositeData();

        Field TASK_ID = new Field(new FieldAttr(FieldType.FIELD_STRING, 20));
        TASK_ID.setValue(obj.getTaskId());
        struct.addField("TASK_ID", TASK_ID);

        Field CLIENT_NAME = new Field(new FieldAttr(FieldType.FIELD_STRING, 150));
        CLIENT_NAME.setValue(obj.getClientName());
        struct.addField("CLIENT_NAME", CLIENT_NAME);

        Field GLOBAL_ID = new Field(new FieldAttr(FieldType.FIELD_STRING, 30));
        GLOBAL_ID.setValue(obj.getGlobalId());
        struct.addField("GLOBAL_ID", GLOBAL_ID);

        Field CLIENT_CODE = new Field(new FieldAttr(FieldType.FIELD_STRING, 16));
        CLIENT_CODE.setValue(obj.getClientCode());
        struct.addField("CLIENT_CODE", CLIENT_CODE);

        Field TASK_TYPE = new Field(new FieldAttr(FieldType.FIELD_STRING, 100));
        if (StringUtils.isNotEmpty(obj.getCheckDescribe())) {
            TASK_TYPE.setValue(obj.getCheckDescribe());
        } else {
            if (obj.getTaskType().equals("1")) {
                TASK_TYPE.setValue("");
            } else if (obj.getTaskType().equals("2")) {
                TASK_TYPE.setValue("?");
            } else if (obj.getTaskType().equals("3")) {
                TASK_TYPE.setValue("??");
            } else if (obj.getTaskType().equals("4")) {
                TASK_TYPE.setValue("");
            }
        }
        struct.addField("TASK_TYPE", TASK_TYPE);

        Field TASK_DATE = new Field(new FieldAttr(FieldType.FIELD_STRING, 8));
        TASK_DATE.setValue(obj.getTaskDate());
        struct.addField("TASK_DATE", TASK_DATE);

        Field LOAN_AMT = new Field(new FieldAttr(FieldType.FIELD_DOUBLE, 20));
        LOAN_AMT.setValue(obj.getLoanAmt());
        struct.addField("LOAN_AMT", LOAN_AMT);

        Field LOAN_BALANCE = new Field(new FieldAttr(FieldType.FIELD_DOUBLE, 20));
        LOAN_BALANCE.setValue(obj.getLoanBalance());
        struct.addField("LOAN_BALANCE", LOAN_BALANCE);

        Field CNT = new Field(new FieldAttr(FieldType.FIELD_STRING, 10));
        CNT.setValue(obj.getCnt());
        struct.addField("CNT", CNT);

        //?(0: 1: 2:)
        Field approve_status = new Field(new FieldAttr(FieldType.FIELD_STRING, 5));
        if (obj.getApproveStatus().equals("0")) {
            approve_status.setValue("");
        } else if (obj.getApproveStatus().equals("1")) {
            approve_status.setValue("");
        } else if (obj.getApproveStatus().equals("2")) {
            approve_status.setValue("");
        }
        struct.addField("APPROVE_STATUS", approve_status);

        Field BACK_REASON = new Field(new FieldAttr(FieldType.FIELD_STRING, 300));
        BACK_REASON.setValue(obj.getBackReason());
        struct.addField("BACK_REASON", BACK_REASON);

        array.addStruct(struct);

    }
    respBody.addArray("AFTER_LOAN_INFO_ARRAY", array);
    return respBody;
}

From source file:org.egov.works.web.actions.reports.WorksGISReportAction.java

public String search() {
    List<Object[]> findAll = null;
    locationList = new ArrayList<GeoLocation>();
    GeoLatLong latlong = new GeoLatLong();
    Map<String, Object> markerdata = null;
    final String query = generateQuery();
    try {//w  w w. jav  a2  s  .  c  o  m
        LOGGER.info("HQl query=" + query.toString());
        findAll = persistenceService.findAllBy(query.toString());
        LOGGER.info("HQl query RESULT " + findAll.size());
        Long estId, projcodeId, contractPeriod;
        BigDecimal estLat, estLon;
        String estNumber, estWorkName, wpno, tenderDocReleasedDt, typeOfWork, subTypeOfWork, workOrderDate,
                contractorName, workCommencedDt;
        Money workValue;
        Double ovrheads;
        // Start format and push the data
        GeoLocation geoLocation = null;
        for (final Object[] columnOutput : findAll) {
            // Reset the values
            estId = projcodeId = contractPeriod = null;
            estLat = estLon = null;
            estNumber = estWorkName = wpno = tenderDocReleasedDt = typeOfWork = subTypeOfWork = workOrderDate = contractorName = workCommencedDt = null;
            workValue = null;
            ovrheads = null;

            // Set the values
            estId = (Long) columnOutput[0];
            estLat = (BigDecimal) columnOutput[1];
            estLon = (BigDecimal) columnOutput[2];
            estNumber = (String) columnOutput[3];
            estWorkName = (String) columnOutput[4];
            workValue = (Money) columnOutput[5];
            ovrheads = (Double) columnOutput[6];
            wpno = (String) columnOutput[7];
            tenderDocReleasedDt = (String) columnOutput[8];
            typeOfWork = (String) columnOutput[9];
            subTypeOfWork = (String) columnOutput[10];
            projcodeId = (Long) columnOutput[11];

            geoLocation = new GeoLocation();
            if (null != estLat && null != estLon) {
                latlong = new GeoLatLong();
                latlong.setLatitude(estLat);
                latlong.setLongitude(estLat);
            }
            geoLocation.setGeoLatLong(latlong);
            // **geoLocation.setUseNiceInfoWindow(true);
            geoLocation.setUrlRedirect(
                    "../estimate/abstractEstimate!edit.action?id=" + estId + "&sourcepage=search~" + estNumber);
            String max50CharName = "";
            if (null != estWorkName && estWorkName.length() >= 50)
                max50CharName = estWorkName.substring(0, 50) + "...";
            else
                max50CharName = estWorkName;
            geoLocation.setInfo2("Work Name=" + max50CharName);
            if (workValue != null || ovrheads != null) {
                BigDecimal amt = workValue != null ? new BigDecimal(workValue.getValue()) : BigDecimal.ZERO;
                amt = amt.add(ovrheads != null ? new BigDecimal(ovrheads) : BigDecimal.ZERO);
                geoLocation.setInfo3("Estimate Value(Rs)="
                        + NumberUtil.formatNumber(amt, NumberUtil.NumberFormatStyle.CRORES));
            } else
                geoLocation.setInfo3("Estimate Value(Rs)=0.00");
            if (wpno != null)
                geoLocation.setInfo4("Works Package Number=" + wpno);
            markerdata = new HashMap<String, Object>();
            if (typeOfWork != null) {
                geoLocation.appendToInfo5("Type of Work=" + typeOfWork);
                if (typeOfWork.equalsIgnoreCase(WorksConstants.TYPE_OF_WORK_BRIDGES))
                    markerdata.put("icon", GeoLocationConstants.MARKEROPTION_ICON_PURPLE);
                else if (typeOfWork.equalsIgnoreCase(WorksConstants.TYPE_OF_WORK_BUILDINGS))
                    markerdata.put("icon", GeoLocationConstants.MARKEROPTION_ICON_YELLOW);
                else if (typeOfWork.equalsIgnoreCase(WorksConstants.TYPE_OF_WORK_ELECTRICAL))
                    markerdata.put("icon", GeoLocationConstants.MARKEROPTION_ICON_GREEN);
                else if (typeOfWork.equalsIgnoreCase(WorksConstants.TYPE_OF_WORK_ROADS))
                    markerdata.put("icon", GeoLocationConstants.MARKEROPTION_ICON_ORANGE);
                else if (typeOfWork.equalsIgnoreCase(WorksConstants.TYPE_OF_WORK_STORMWATER_DRAIN))
                    markerdata.put("icon", GeoLocationConstants.MARKEROPTION_ICON_BLUE);
            }
            if (subTypeOfWork != null)
                geoLocation.appendToInfo5("Subtype of Work=" + subTypeOfWork);
            if (tenderDocReleasedDt != null)
                geoLocation.appendToInfo5("Tender Document Released Date=" + tenderDocReleasedDt);
            final String tenderAmount = getTenderAmount(estId);
            if (StringUtils.isNotBlank(tenderAmount))
                geoLocation.appendToInfo5("Tender Finalized Value(Rs)=" + tenderAmount);
            if (contractorId != null && contractorId != -1) {
                workOrderDate = (String) columnOutput[12];
                if (columnOutput[13] != null)
                    contractPeriod = Long.parseLong(columnOutput[13].toString());
                contractorName = (String) columnOutput[14];
                workCommencedDt = (String) columnOutput[15];
                if (workOrderDate != null)
                    geoLocation.appendToInfo5("Work Order Date=" + workOrderDate);
                if (workCommencedDt != null)
                    geoLocation.appendToInfo5("Work Commenced Date=" + workCommencedDt);
                if (contractPeriod != null)
                    geoLocation.appendToInfo5("Contract Period In Days=" + contractPeriod);
                if (workCommencedDt != null && contractPeriod != null) {
                    final Date woDate = new Date(workCommencedDt);
                    final Calendar cal = Calendar.getInstance();
                    cal.setTime(woDate);
                    cal.add(Calendar.DATE, new Long(contractPeriod).intValue());
                    geoLocation.appendToInfo5("Expected Date Of Completion =" + sdf.format(cal.getTime()));
                }
                if (projcodeId != null) {
                    final String paymentAmt = getPaymentAmount(projcodeId);
                    if (paymentAmt != null)
                        geoLocation.appendToInfo5("Payment Released(Rs)=" + paymentAmt);
                }
                if (contractorName != null)
                    geoLocation.appendToInfo5("Contractor Name=" + contractorName);
            } else {
                final List<WorkOrder> woList = persistenceService.findAllBy(
                        "  select woe.workOrder from WorkOrderEstimate woe where woe.estimate.id=? and upper(woe.workOrder.egwStatus.code) not in ('"
                                + WorksConstants.NEW + "','" + WorksConstants.CANCELLED_STATUS + "') ",
                        estId);
                if (woList != null && woList.size() > 0) {
                    final StringBuffer workOrderDatesBuf = new StringBuffer("");
                    final StringBuffer workCommencedDateBuf = new StringBuffer("");
                    final StringBuffer contractorNameBuf = new StringBuffer("");
                    final StringBuffer workExpectedCompletionDateBuf = new StringBuffer("");
                    final StringBuffer workOrderContractPeriodBuf = new StringBuffer("");
                    for (final WorkOrder wo : woList) {
                        Long workOrderContractPeriod = null;
                        workOrderDatesBuf.append(sdf.format(wo.getWorkOrderDate()) + ",");
                        contractorNameBuf.append(wo.getContractor().getName() + ",");
                        if (wo.getContractPeriod() != null) {
                            workOrderContractPeriod = Long.valueOf(wo.getContractPeriod());
                            workOrderContractPeriodBuf.append(wo.getContractPeriod() + ",");
                        } else
                            workOrderContractPeriodBuf.append("NA,");
                        boolean workCommencedPresent = false;
                        boolean workExpectedCompletedPresent = false;
                        for (final OfflineStatus ss : wo.getOfflineStatuses())
                            if (ss.getEgwStatus().getCode()
                                    .equalsIgnoreCase(WorksConstants.WO_STATUS_WOCOMMENCED)) {
                                workCommencedDateBuf.append(sdf.format(ss.getStatusDate()) + ",");
                                workCommencedPresent = true;
                                if (workOrderContractPeriod != null) {
                                    final Calendar cal = Calendar.getInstance();
                                    cal.setTime(wo.getWorkOrderDate());
                                    cal.add(Calendar.DATE, workOrderContractPeriod.intValue());
                                    workExpectedCompletionDateBuf.append(sdf.format(cal.getTime()) + ",");
                                    workExpectedCompletedPresent = true;
                                }
                            }
                        if (!workCommencedPresent)
                            workCommencedDateBuf.append("NA,");
                        if (!workExpectedCompletedPresent)
                            workExpectedCompletionDateBuf.append("NA,");
                    }
                    geoLocation.appendToInfo5("Work Order Date="
                            + workOrderDatesBuf.deleteCharAt(workOrderDatesBuf.lastIndexOf(",")).toString());
                    if (StringUtils.isNotBlank(workCommencedDateBuf.toString()))
                        geoLocation.appendToInfo5("Work Commenced Date=" + workCommencedDateBuf
                                .deleteCharAt(workCommencedDateBuf.lastIndexOf(",")).toString());
                    if (StringUtils.isNotBlank(workOrderContractPeriodBuf.toString()))
                        geoLocation.appendToInfo5("Contract Period In Days=" + workOrderContractPeriodBuf
                                .deleteCharAt(workOrderContractPeriodBuf.lastIndexOf(",")).toString());
                    if (StringUtils.isNotBlank(workExpectedCompletionDateBuf.toString()))
                        geoLocation.appendToInfo5("Expected Date Of Completion=" + workExpectedCompletionDateBuf
                                .deleteCharAt(workExpectedCompletionDateBuf.lastIndexOf(",")).toString());
                    if (projcodeId != null) {
                        final String paymentAmt = getPaymentAmount(projcodeId);
                        if (paymentAmt != null)
                            geoLocation.appendToInfo5("Payment Released(Rs)=" + paymentAmt);
                    }
                    geoLocation.appendToInfo5("Contractor Name="
                            + contractorNameBuf.deleteCharAt(contractorNameBuf.lastIndexOf(",")).toString());
                }
            }
            geoLocation.setMarkerOptionData(markerdata);
            locationList.add(geoLocation);
        }
        ServletActionContext.getRequest().setAttribute("kmlfilename", "coczone");
        ServletActionContext.getRequest().setAttribute(GeoLocationConstants.GEOLOCATIONLIST_ATTRIBUTE,
                locationList);
        resultStatus = AFTER_SEARCH;
        if (locationList != null && locationList.size() >= 1)
            return GMAP;
    } catch (final Exception e) {
        LOGGER.error(e, e);
    }
    return GMAP;
}