Example usage for org.apache.commons.lang StringUtils substringAfter

List of usage examples for org.apache.commons.lang StringUtils substringAfter

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils substringAfter.

Prototype

public static String substringAfter(String str, String separator) 

Source Link

Document

Gets the substring after the first occurrence of a separator.

Usage

From source file:edu.ku.brc.specify.Specify.java

public Storage getStorageItem(final DataProviderSessionIFace session, final String path,
        final Storage parentArg) {
    Storage parent = parentArg;/*w w w.  j a  va  2 s  .  c  o m*/
    String nodeStr = StringUtils.substringBefore(path, "/");
    String pathStr = StringUtils.substringAfter(path, "/");
    if (parent == null) {
        parent = session.getData(Storage.class, "name", nodeStr, DataProviderSessionIFace.CompareType.Equals);
        if (StringUtils.isNotEmpty(pathStr)) {
            return getStorageItem(session, pathStr, parent);
        }
        return parent;
    }

    for (Storage node : parent.getChildren()) {
        //log.debug("["+node.getName()+"]["+nodeStr+"]");
        if (node.getName().equals(nodeStr)) {
            if (StringUtils.isNotEmpty(pathStr)) {
                return getStorageItem(session, pathStr, node);
            }
            return node;
        }
    }
    return null;
}

From source file:com.amalto.core.query.StorageQueryTest.java

License:asdf

public void testDuplicateFieldNames() {
    UserQueryBuilder qb = from(product);

    List<String> viewables = new ArrayList<String>();
    viewables.add("Product/Id");
    viewables.add("Product/Name");
    viewables.add("Product/Family");
    viewables.add("ProductFamily/Id");
    viewables.add("ProductFamily/Name");

    List<IWhereItem> conditions = new ArrayList<IWhereItem>();
    conditions.add(new WhereCondition("Product/Family", "JOINS", "ProductFamily/Id", "&"));

    IWhereItem fullWhere = new WhereAnd(conditions);
    qb.where(UserQueryHelper.buildCondition(qb, fullWhere, repository));

    // add order by Id to make the test stable
    qb.orderBy(product.getField("Id"), Direction.ASC);

    for (String viewableBusinessElement : viewables) {
        String viewableTypeName = StringUtils.substringBefore(viewableBusinessElement, "/"); //$NON-NLS-1$
        String viewablePath = StringUtils.substringAfter(viewableBusinessElement, "/"); //$NON-NLS-1$
        qb.select(UserQueryHelper.getFields(repository.getComplexType(viewableTypeName), viewablePath).get(0));
    }/*from  w  w w.j  a va 2 s  .  c  om*/

    StorageResults results = storage.fetch(qb.getSelect());
    assertEquals(2, results.getCount());

    DataRecordWriter writer = new ViewSearchResultsWriter();
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    List<String> strings = new ArrayList<String>();
    for (DataRecord result : results) {
        try {
            writer.write(result, output);
            String document = new String(output.toByteArray(), Charset.forName("UTF-8"));
            strings.add(document);
            output.reset();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    assertEquals(2, strings.size());
    assertEquals(
            "<result xmlns:metadata=\"http://www.talend.com/mdm/metadata\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n\t<Id>1</Id>\n\t<Name>Product name</Name>\n\t<Family>[2]</Family>\n\t<Id>2</Id>\n\t<Name>Product family #2</Name>\n</result>",
            strings.get(0));
    assertEquals(
            "<result xmlns:metadata=\"http://www.talend.com/mdm/metadata\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n\t<Id>2</Id>\n\t<Name>Renault car</Name>\n\t<Family/>\n\t<Id/>\n\t<Name/>\n</result>",
            strings.get(1));
}

From source file:com.amalto.core.query.StorageQueryTest.java

License:asdf

public void testTMDM8828() {
    UserQueryBuilder qb = from(organisation);

    List<String> viewables = new ArrayList<String>();
    viewables.add("Organisation/OrganisationId");
    viewables.add("Location/LocationId");
    viewables.add("Location/translation/locationTranslation");

    // add order by Id to make the test stable
    qb.orderBy(organisation.getField("OrganisationId"), Direction.ASC);

    List<IWhereItem> conditions = new ArrayList<IWhereItem>();
    conditions.add(new WhereCondition("Organisation/locations/location", "JOINS", "Location/LocationId", "&"));
    conditions.add(new WhereCondition("Organisation/OrganisationId", "=", "2", "&"));

    IWhereItem fullWhere = new WhereAnd(conditions);
    qb.where(UserQueryHelper.buildCondition(qb, fullWhere, repository));

    for (String viewableBusinessElement : viewables) {
        String viewableTypeName = StringUtils.substringBefore(viewableBusinessElement, "/"); //$NON-NLS-1$
        String viewablePath = StringUtils.substringAfter(viewableBusinessElement, "/"); //$NON-NLS-1$
        TypedExpression expression = UserQueryHelper
                .getFields(repository.getComplexType(viewableTypeName), viewablePath).get(0);
        qb.select(expression);/*from  w w w. ja v a  2  s.c om*/
    }

    StorageResults results = storage.fetch(qb.getSelect());
    assertEquals(2, results.getCount());

    DataRecordWriter writer = new ViewSearchResultsWriter();
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    List<String> strings = new ArrayList<String>();
    for (DataRecord result : results) {
        try {
            writer.write(result, output);
            String document = new String(output.toByteArray(), Charset.forName("UTF-8"));
            strings.add(document);
            output.reset();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    assertEquals(2, strings.size());
    assertEquals(
            "<result xmlns:metadata=\"http://www.talend.com/mdm/metadata\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n\t<OrganisationId>2</OrganisationId>\n\t<LocationId>t2</LocationId>\n\t<locationTranslation>Trans1</locationTranslation>\n</result>",
            strings.get(0));
    assertEquals(
            "<result xmlns:metadata=\"http://www.talend.com/mdm/metadata\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n\t<OrganisationId>2</OrganisationId>\n\t<LocationId>t2</LocationId>\n\t<locationTranslation>Trans2</locationTranslation>\n</result>",
            strings.get(1));
}

From source file:com.primovision.lutransport.service.ImportMainSheetServiceImpl.java

@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public List<String> importeztollMainSheet(InputStream is, Boolean override) throws Exception {
    // initializing the InputStream from a file using
    // POIFSFileSystem, before converting the result
    // into an HSSFWorkbook instance //XSSFWorkbook
    HSSFWorkbook wb = null;/*from  w  w  w  .  j  a v a  2s.c  om*/
    StringBuffer buffer = null;
    List<String> list = new ArrayList<String>();
    List<EzToll> eztolls = new ArrayList<EzToll>();
    // List<String> emptydatalist=new ArrayList<String>();
    int count = 1;
    int errorcount = 0;
    try {
        POIFSFileSystem fs = new POIFSFileSystem(is);
        ErrorData edata = new ErrorData();
        // FileWriter writer = new FileWriter("e:/errordata.txt");
        wb = new HSSFWorkbook(fs);
        int numOfSheets = wb.getNumberOfSheets();
        Map criterias = new HashMap();
        HSSFSheet sheet = wb.getSheetAt(0);
        HSSFRow row = null;
        HSSFCell cell = null;
        EzToll eztoll = null;

        Iterator rows = sheet.rowIterator();
        StringBuffer lineError;
        while (rows.hasNext()) {
            boolean error = false;
            buffer = new StringBuffer();
            int cellCount = 0;
            row = (HSSFRow) rows.next();
            if (count == 1) {
                count++;
                continue;
            }
            lineError = new StringBuffer("");
            try {
                eztoll = new EzToll();
                // FOR Toll COMPANY
                String tollcompany = ((String) getCellValue(row.getCell(0)));
                try {
                    criterias.clear();
                    criterias.put("name", tollcompany);
                    TollCompany tollcompanyName = genericDAO.getByCriteria(TollCompany.class, criterias);
                    if (tollcompanyName == null)
                        throw new Exception("Invalid Toll Company Name");
                    eztoll.setToolcompany(tollcompanyName);
                } catch (Exception ex) {
                    // System.out.println("\n\n Error in Driver first
                    // name========>"+ex);
                    error = true;
                    lineError.append("Toll Company Name,");
                    log.warn(ex.getMessage());
                }
                // FOR COMPANY
                String company = ((String) getCellValue(row.getCell(1)));
                try {
                    criterias.clear();
                    criterias.put("type", 3);
                    criterias.put("name", company);
                    Location companyName = genericDAO.getByCriteria(Location.class, criterias);
                    // System.out.println("\ncompanyName====>"+companyName+"\n");

                    if (companyName == null)
                        throw new Exception("Invalid Company Name");
                    eztoll.setCompany(companyName);
                } catch (Exception ex) {
                    // System.out.println("\n\n Error in Driver first
                    // name========>"+ex);
                    error = true;
                    lineError.append("Invalid Company Name,");
                    log.warn(ex.getMessage());
                }
                // FOR TERMINAL
                /*
                 * try { criterias.clear(); String name = (String)
                 * getCellValue(row.getCell(2));
                 * //System.out.println("\nTerminal====>"+name+"\n"); if
                 * (StringUtils.isEmpty(name)) throw new
                 * Exception("Invalid terminal"); else {
                 * criterias.put("name", name); criterias.put("type", 4); }
                 * Location location =
                 * genericDAO.getByCriteria(Location.class, criterias); if
                 * (location == null) throw new
                 * Exception("no such Terminal"); else
                 * eztoll.setTerminal(location); } catch (Exception ex) {
                 * error = true; lineError.append("Terminal,");
                 * log.warn(ex.getMessage()); }
                 */

                if (override == false) {
                    Date date2 = row.getCell(10).getDateCellValue();

                    try {
                        if (validDate(date2)) {
                            eztoll.setInvoiceDate(dateFormat1.parse(dateFormat1.format(date2)));
                        } else {
                            error = true;
                            lineError.append("Invoice Date,");
                        }
                    } catch (Exception ex) {
                        error = true;
                        lineError.append("Invoice Date,");
                        log.warn(ex.getMessage());

                    }
                } else {
                    if (validDate(getCellValue(row.getCell(10))))
                        eztoll.setInvoiceDate((Date) getCellValue(row.getCell(10)));
                    else {
                        eztoll.setInvoiceDate(null);
                    }
                }

                validateAndResetTollTagAndPlateNumber(row, eztoll);

                String plateNum = null;

                if (getCellValue(row.getCell(4)) == null) {
                    // do nothing
                } else if (getCellValue(row.getCell(4)).equals("")) {
                    // do nothing
                } else {
                    plateNum = getCellValue(row.getCell(4)).toString();
                }

                String tollNum = null;

                if (getCellValue(row.getCell(3)) == null) {
                    // do nothing
                } else if (getCellValue(row.getCell(3)).equals("")) {
                    // do nothing
                } else {
                    tollNum = getCellValue(row.getCell(3)).toString();
                }

                // if both toll number and plate number is empty
                if (tollNum == null && plateNum == null) {
                    error = true;
                    lineError.append("Either tolltag number or plate number is required,");
                    log.warn("Either Toll tag number or Plate number is required ");
                } else {
                    // for toll number
                    if (tollNum != null) {
                        try {
                            String transactiondate = null;
                            if (validDate(getCellValue(row.getCell(6)))) {
                                transactiondate = dateFormat
                                        .format(((Date) getCellValue(row.getCell(6))).getTime());
                            }
                            StringBuffer query = new StringBuffer(
                                    "select obj from VehicleTollTag obj where obj.tollTagNumber='"
                                            + (String) getCellValue(row.getCell(3)) + "'");

                            if (eztoll.getToolcompany() != null) {
                                query.append(" and obj.tollCompany='" + eztoll.getToolcompany().getId() + "'");
                            }

                            query.append(" and obj.validFrom <='" + transactiondate + "' and obj.validTo >= '"
                                    + transactiondate + "'");

                            List<VehicleTollTag> vehicletolltags = genericDAO
                                    .executeSimpleQuery(query.toString());

                            if (vehicletolltags.isEmpty() && vehicletolltags.size() == 0)
                                throw new Exception("no such Toll tag Number");
                            else {
                                /***Correction for unit no. mapping to multiple vehicle ids***/
                                /*String vehquery = "Select obj from Vehicle obj where obj.unit="
                                      + vehicletolltags.get(0).getVehicle().getUnit() + " and obj.validFrom <='"
                                      + transactiondate + "' and obj.validTo >= '" + transactiondate + "'";
                                String vehquery = "Select obj from Vehicle obj where obj.id="
                                      + vehicletolltags.get(0).getVehicle().getId() + " and obj.validFrom <='"
                                      + transactiondate + "' and obj.validTo >= '" + transactiondate + "'";
                                System.out.println("******************** the vehicle query is " + vehquery);
                                List<Vehicle> vehicle = genericDAO.executeSimpleQuery(vehquery.toString());*/

                                List<Vehicle> vehicle = retrieveVehicle(vehicletolltags.get(0),
                                        transactiondate);
                                if (vehicle.isEmpty() && vehicle.size() == 0) {
                                    throw new Exception(
                                            "TOLL_ERROR_MSG: Invalid Toll Tag Number - No matching vehicle found for given id and txn date");
                                } else {
                                    eztoll.setUnit(vehicle.get(0));
                                    eztoll.setTollTagNumber(vehicletolltags.get(0));
                                    String drv_name = (String) getCellValue(row.getCell(5));
                                    if (!(StringUtils.isEmpty(drv_name))) {
                                        /*criterias.clear();
                                        criterias.put("fullName", getCellValue(row.getCell(5)));
                                                
                                        Driver driver = genericDAO.getByCriteria(Driver.class, criterias);*/

                                        Driver driver = getDriverObjectFromName(drv_name, row);
                                        if (driver == null) {
                                            error = true;
                                            lineError.append("Invalid Driver Name, ");
                                        } else {
                                            eztoll.setDriver(driver);
                                            eztoll.setTerminal(driver.getTerminal());
                                        }
                                    } else {
                                        /*String drivequery = "select obj from Ticket obj where obj.loadDate<='"
                                              + transactiondate + "' and obj.unloadDate>='" + transactiondate
                                              + "' and obj.vehicle=" + vehicle.get(0).getId();
                                                
                                        System.out.println(" my query is " + drivequery);
                                        List<Ticket> tickets = genericDAO.executeSimpleQuery(drivequery);*/

                                        List<Vehicle> vehicleList = retrieveVehicleForUnit(
                                                vehicletolltags.get(0).getVehicle().getUnit(), transactiondate);
                                        List<Ticket> tickets = getTicketsForVehicle(vehicleList,
                                                transactiondate);

                                        // More than one driver fix - 13th May 2016
                                        String txnTime = getCellValue(row.getCell(7)).toString();
                                        Date txnDate = (Date) getCellValue(row.getCell(6));
                                        tickets = determineCorrectTicket(tickets, txnDate, txnTime);

                                        if (!tickets.isEmpty()) {
                                            boolean tic = true;
                                            boolean first = true;
                                            List<String> driverid = new ArrayList<String>();
                                            for (Ticket ticket : tickets) {
                                                boolean d = driverid.contains(ticket.getDriver().getId() + "");
                                                driverid.add(ticket.getDriver().getId() + "");
                                                if (first) {
                                                    first = false;
                                                    continue;
                                                }
                                                if (!d) {
                                                    if (override == false) {
                                                        error = true;
                                                        lineError.append("More than one Driver, ");
                                                        tic = false;
                                                    } else {
                                                        tic = false;

                                                        try {
                                                            criterias.clear();
                                                            String name = (String) getCellValue(row.getCell(2));
                                                            // System.out.println("\nTerminal====>"+name+"\n");
                                                            if (StringUtils.isEmpty(name))
                                                                throw new Exception("Invalid terminal");
                                                            else {
                                                                criterias.put("name", name);
                                                                criterias.put("type", 4);
                                                            }
                                                            Location location = genericDAO
                                                                    .getByCriteria(Location.class, criterias);
                                                            if (location == null)
                                                                throw new Exception("no such Terminal");
                                                            else
                                                                eztoll.setTerminal(location);
                                                        } catch (Exception ex) {
                                                            error = true;
                                                            lineError.append("Terminal,");
                                                            log.warn(ex.getMessage());
                                                        }

                                                    }
                                                }
                                            }
                                            if (tic) {
                                                eztoll.setDriver(tickets.get(0).getDriver());
                                                Driver driver = genericDAO.getById(Driver.class,
                                                        tickets.get(0).getDriver().getId());
                                                eztoll.setTerminal(driver.getTerminal());
                                            }
                                        } else {
                                            String driverFuelLogQuery = "select obj from DriverFuelLog obj where obj.transactionDate='"
                                                    + transactiondate + "' and obj.truck="
                                                    + vehicle.get(0).getId();

                                            System.out.println(" my query is " + driverFuelLogQuery);
                                            List<DriverFuelLog> driverFuelLog = genericDAO
                                                    .executeSimpleQuery(driverFuelLogQuery);

                                            if (!driverFuelLog.isEmpty()) {
                                                boolean tic = true;
                                                boolean first = true;
                                                List<String> driverid = new ArrayList<String>();
                                                for (DriverFuelLog drvFuelLog : driverFuelLog) {

                                                    boolean d = driverid
                                                            .contains(drvFuelLog.getDriver().getId() + "");
                                                    driverid.add(drvFuelLog.getDriver().getId() + "");
                                                    if (first) {
                                                        first = false;
                                                        continue;
                                                    }
                                                    if (!d) {
                                                        if (override == false) {
                                                            error = true;
                                                            lineError.append("More than one Driver, ");
                                                            tic = false;
                                                        } else {
                                                            tic = false;

                                                            try {
                                                                criterias.clear();
                                                                String name = (String) getCellValue(
                                                                        row.getCell(2));
                                                                // System.out.println("\nTerminal====>"+name+"\n");
                                                                if (StringUtils.isEmpty(name))
                                                                    throw new Exception("Invalid terminal");
                                                                else {
                                                                    criterias.put("name", name);
                                                                    criterias.put("type", 4);
                                                                }
                                                                Location location = genericDAO.getByCriteria(
                                                                        Location.class, criterias);
                                                                if (location == null)
                                                                    throw new Exception("no such Terminal");
                                                                else
                                                                    eztoll.setTerminal(location);
                                                            } catch (Exception ex) {
                                                                error = true;
                                                                lineError.append("Terminal,");
                                                                log.warn(ex.getMessage());
                                                            }

                                                        }
                                                    }

                                                }
                                                if (tic) {
                                                    eztoll.setDriver(driverFuelLog.get(0).getDriver());
                                                    Driver driver = genericDAO.getById(Driver.class,
                                                            driverFuelLog.get(0).getDriver().getId());
                                                    eztoll.setTerminal(driver.getTerminal());
                                                }
                                            } else {

                                                String driverOdometerQuery = "select obj from Odometer obj where obj.recordDate='"
                                                        + transactiondate + "' and obj.truck="
                                                        + vehicle.get(0).getId();

                                                System.out.println(" odometer query is " + driverOdometerQuery);
                                                List<Odometer> odometer = genericDAO
                                                        .executeSimpleQuery(driverOdometerQuery);

                                                if (!odometer.isEmpty()) {

                                                    boolean tic = true;
                                                    boolean first = true;
                                                    List<String> driverid = new ArrayList<String>();
                                                    for (Odometer odometerObj : odometer) {

                                                        boolean d = driverid
                                                                .contains(odometerObj.getDriver().getId() + "");
                                                        driverid.add(odometerObj.getDriver().getId() + "");
                                                        if (first) {
                                                            first = false;
                                                            continue;
                                                        }
                                                        if (!d) {
                                                            if (override == false) {
                                                                error = true;
                                                                lineError.append("More than one Driver, ");
                                                                tic = false;
                                                            } else {
                                                                tic = false;

                                                                try {
                                                                    criterias.clear();
                                                                    String name = (String) getCellValue(
                                                                            row.getCell(2));
                                                                    // System.out.println("\nTerminal====>"+name+"\n");
                                                                    if (StringUtils.isEmpty(name))
                                                                        throw new Exception("Invalid terminal");
                                                                    else {
                                                                        criterias.put("name", name);
                                                                        criterias.put("type", 4);
                                                                    }
                                                                    Location location = genericDAO
                                                                            .getByCriteria(Location.class,
                                                                                    criterias);
                                                                    if (location == null)
                                                                        throw new Exception("no such Terminal");
                                                                    else
                                                                        eztoll.setTerminal(location);
                                                                } catch (Exception ex) {
                                                                    error = true;
                                                                    lineError.append("Terminal,");
                                                                    log.warn(ex.getMessage());
                                                                }

                                                            }
                                                        }

                                                    }
                                                    if (tic) {
                                                        eztoll.setDriver(odometer.get(0).getDriver());
                                                        Driver driver = genericDAO.getById(Driver.class,
                                                                odometer.get(0).getDriver().getId());
                                                        eztoll.setTerminal(driver.getTerminal());
                                                    }

                                                } else {
                                                    if (override == false) {
                                                        error = true;
                                                        lineError.append(
                                                                "No matching  Ticket, Fuel Log,  Odometer entry, ");
                                                    } else {
                                                        try {
                                                            criterias.clear();
                                                            String name = (String) getCellValue(row.getCell(2));
                                                            // System.out.println("\nTerminal====>"+name+"\n");
                                                            if (StringUtils.isEmpty(name))
                                                                throw new Exception("Invalid terminal");
                                                            else {
                                                                criterias.put("name", name);
                                                                criterias.put("type", 4);
                                                            }
                                                            Location location = genericDAO
                                                                    .getByCriteria(Location.class, criterias);
                                                            if (location == null)
                                                                throw new Exception("no such Terminal");
                                                            else
                                                                eztoll.setTerminal(location);
                                                        } catch (Exception ex) {
                                                            error = true;
                                                            lineError.append("Terminal,");
                                                            log.warn(ex.getMessage());
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }

                                }
                            }

                        } catch (Exception ex) {
                            error = true;
                            //lineError.append("Invalid Toll Tag Number, ");
                            String errMsg = "Invalid Toll Tag Number";
                            String exceptionMsg = StringUtils.substringAfter(ex.getMessage(),
                                    "TOLL_ERROR_MSG: ");
                            if (!StringUtils.isEmpty(exceptionMsg)) {
                                errMsg = exceptionMsg;
                            }
                            lineError.append(errMsg + ", ");
                            log.warn(ex.getMessage());
                        }
                    }

                    // FOR PLATE#
                    if (plateNum != null) {
                        try {
                            /**Correction for plate no. verification - adding txn date***/
                            /*criterias.clear();
                            criterias.put("plate", (String) getCellValue(row.getCell(4)));
                            Vehicle vehicle = genericDAO.getByCriteria(Vehicle.class, criterias);*/

                            Vehicle vehicle = retrieveVehicleForPlate((String) getCellValue(row.getCell(4)),
                                    row);

                            if (vehicle == null)
                                throw new Exception("no such Plate or Toll tag Number");
                            else {
                                if (tollNum != null) {
                                    String transactiondate = null;

                                    if (validDate(getCellValue(row.getCell(6)))) {
                                        transactiondate = dateFormat
                                                .format(((Date) getCellValue(row.getCell(6))).getTime());
                                        System.out.println("\n****--****\n");
                                    }

                                    StringBuffer query = new StringBuffer(
                                            "select obj from VehicleTollTag obj where obj.tollTagNumber='"
                                                    + (String) getCellValue(row.getCell(3)) + "'");
                                    if (eztoll.getToolcompany() != null) {
                                        query.append(" and obj.tollCompany='" + eztoll.getToolcompany().getId()
                                                + "'");
                                    }
                                    query.append(" and obj.vehicle='" + vehicle.getId()
                                            + "' and obj.validFrom <='" + transactiondate
                                            + "' and obj.validTo >= '" + transactiondate + "'");

                                    System.out.println("******* query  ======>" + query);
                                    try {
                                        List<VehicleTollTag> vehicletolltags = genericDAO
                                                .executeSimpleQuery(query.toString());
                                        if (vehicletolltags.isEmpty() && vehicletolltags.size() == 0)
                                            throw new Exception("Invalid Plate Number");
                                        else {
                                            /*
                                             * Code to get the active plate
                                             * numbers
                                             */
                                            /*List<Vehicle> vehicleList = genericDAO
                                                  .executeSimpleQuery(
                                                        // Correction for unit no. mapping to multiple vehicle ids
                                                        //"select o from Vehicle o where o.unit="
                                                        //+ vehicletolltags.get(0).getUnit()
                                                        //+ " and o.validFrom<=SYSDATE() and o.validTo>=SYSDATE() ");
                                                        "select o from Vehicle o where o.id="
                                                        + vehicletolltags.get(0).getVehicle().getId()
                                                        + " and o.validFrom <='"+ transactiondate + "' and o.validTo >= '" 
                                                        + transactiondate + "'");*/
                                            List<Vehicle> vehicleList = retrieveVehicle(vehicletolltags.get(0),
                                                    transactiondate);
                                            if (vehicleList.isEmpty() && vehicleList.size() == 0)
                                                throw new Exception("Invalid Plate Number");
                                            else
                                                eztoll.setPlateNumber(vehicleList.get(0));
                                        }
                                    } catch (Exception ex) {
                                        System.out.println("\n*******\n");
                                    }
                                } else {

                                    String transactiondate1 = null;
                                    if (validDate(getCellValue(row.getCell(6)))) {
                                        transactiondate1 = dateFormat
                                                .format(((Date) getCellValue(row.getCell(6))).getTime());
                                        System.out.println("\n****--****\n");
                                    }

                                    StringBuffer query = new StringBuffer(
                                            "select obj from VehicleTollTag obj where ");
                                    query.append("obj.vehicle='" + vehicle.getId() + "' and obj.validFrom <='"
                                            + transactiondate1 + "' and obj.validTo >= '" + transactiondate1
                                            + "'");
                                    if (eztoll.getToolcompany() != null) {
                                        query.append(" and obj.tollCompany='" + eztoll.getToolcompany().getId()
                                                + "'");
                                    }

                                    System.out.println("******* query  ======>" + query);
                                    try {
                                        List<VehicleTollTag> vehicletolltags = genericDAO
                                                .executeSimpleQuery(query.toString());
                                        if (vehicletolltags.isEmpty() && vehicletolltags.size() == 0) {
                                            // throw new Exception("Invalid Plate Number");
                                        } else {
                                            eztoll.setTollTagNumber(vehicletolltags.get(0));
                                        }
                                    } catch (Exception ex) {
                                        System.out.println("\n*******\n");
                                    }

                                    String drv_name = (String) getCellValue(row.getCell(5));
                                    if (!(StringUtils.isEmpty(drv_name))) {
                                        /*criterias.clear();
                                        criterias.put("fullName", getCellValue(row.getCell(5)));
                                                
                                        Driver driver = genericDAO.getByCriteria(Driver.class, criterias);*/

                                        Driver driver = getDriverObjectFromName(drv_name, row);
                                        if (driver == null) {
                                            error = true;
                                            lineError.append("Invalid Driver Name, ");
                                        } else {
                                            eztoll.setDriver(driver);
                                            eztoll.setTerminal(driver.getTerminal());
                                        }
                                    } else {

                                        String transactiondate = null;
                                        if (validDate(getCellValue(row.getCell(6)))) {
                                            transactiondate = dateFormat
                                                    .format(((Date) getCellValue(row.getCell(6))).getTime());
                                        }

                                        /*String drivequery = "select obj from Ticket obj where obj.loadDate<='"
                                              + transactiondate + "' and obj.unloadDate>='" + transactiondate
                                              + "' and obj.vehicle=" + vehicle.getId();
                                        System.out.println(" my query is " + drivequery);
                                        List<Ticket> tickets = genericDAO.executeSimpleQuery(drivequery);*/

                                        List<Vehicle> vehicleListForDriver = new ArrayList<Vehicle>();
                                        vehicleListForDriver.add(vehicle);
                                        List<Ticket> tickets = getTicketsForVehicle(vehicleListForDriver,
                                                transactiondate);

                                        // More than one driver fix - 13th May 2016
                                        String txnTime = getCellValue(row.getCell(7)).toString();
                                        Date txnDate = (Date) getCellValue(row.getCell(6));
                                        tickets = determineCorrectTicket(tickets, txnDate, txnTime);

                                        if (!tickets.isEmpty()) {
                                            boolean tic = true;
                                            boolean first = true;
                                            List<String> driverid = new ArrayList<String>();
                                            for (Ticket ticket : tickets) {
                                                boolean d = driverid.contains(ticket.getDriver().getId() + "");
                                                driverid.add(ticket.getDriver().getId() + "");
                                                if (first) {
                                                    first = false;
                                                    continue;
                                                }
                                                if (!d) {
                                                    if (override == false) {
                                                        error = true;
                                                        lineError.append("More than one Driver, ");
                                                        tic = false;
                                                    } else {
                                                        tic = false;

                                                        try {
                                                            criterias.clear();
                                                            String name = (String) getCellValue(row.getCell(2));
                                                            // System.out.println("\nTerminal====>"+name+"\n");
                                                            if (StringUtils.isEmpty(name))
                                                                throw new Exception("Invalid terminal");
                                                            else {
                                                                criterias.put("name", name);
                                                                criterias.put("type", 4);
                                                            }
                                                            Location location = genericDAO
                                                                    .getByCriteria(Location.class, criterias);
                                                            if (location == null)
                                                                throw new Exception("no such Terminal");
                                                            else
                                                                eztoll.setTerminal(location);
                                                        } catch (Exception ex) {
                                                            error = true;
                                                            lineError.append("Terminal,");
                                                            log.warn(ex.getMessage());
                                                        }

                                                    }
                                                }
                                            }
                                            if (tic) {
                                                eztoll.setDriver(tickets.get(0).getDriver());
                                                Driver driver = genericDAO.getById(Driver.class,
                                                        tickets.get(0).getDriver().getId());
                                                eztoll.setTerminal(driver.getTerminal());
                                            }
                                        } else {
                                            String driverFuelLogQuery = "select obj from DriverFuelLog obj where obj.transactionDate='"
                                                    + transactiondate + "' and obj.truck=" + vehicle.getId();

                                            System.out.println(" my query is " + driverFuelLogQuery);
                                            List<DriverFuelLog> driverFuelLog = genericDAO
                                                    .executeSimpleQuery(driverFuelLogQuery);

                                            if (!driverFuelLog.isEmpty()) {
                                                boolean tic = true;
                                                boolean first = true;
                                                List<String> driverid = new ArrayList<String>();
                                                for (DriverFuelLog drvFuelLog : driverFuelLog) {

                                                    boolean d = driverid
                                                            .contains(drvFuelLog.getDriver().getId() + "");
                                                    driverid.add(drvFuelLog.getDriver().getId() + "");
                                                    if (first) {
                                                        first = false;
                                                        continue;
                                                    }
                                                    if (!d) {
                                                        if (override == false) {
                                                            error = true;
                                                            lineError.append("More than one Driver, ");
                                                            tic = false;
                                                        } else {
                                                            tic = false;

                                                            try {
                                                                criterias.clear();
                                                                String name = (String) getCellValue(
                                                                        row.getCell(2));
                                                                // System.out.println("\nTerminal====>"+name+"\n");
                                                                if (StringUtils.isEmpty(name))
                                                                    throw new Exception("Invalid terminal");
                                                                else {
                                                                    criterias.put("name", name);
                                                                    criterias.put("type", 4);
                                                                }
                                                                Location location = genericDAO.getByCriteria(
                                                                        Location.class, criterias);
                                                                if (location == null)
                                                                    throw new Exception("no such Terminal");
                                                                else
                                                                    eztoll.setTerminal(location);
                                                            } catch (Exception ex) {
                                                                error = true;
                                                                lineError.append("Terminal,");
                                                                log.warn(ex.getMessage());
                                                            }

                                                        }
                                                    }

                                                }
                                                if (tic) {
                                                    eztoll.setDriver(driverFuelLog.get(0).getDriver());
                                                    Driver driver = genericDAO.getById(Driver.class,
                                                            driverFuelLog.get(0).getDriver().getId());
                                                    eztoll.setTerminal(driver.getTerminal());
                                                }
                                            } else {

                                                String driverOdometerQuery = "select obj from Odometer obj where obj.recordDate='"
                                                        + transactiondate + "' and obj.truck="
                                                        + vehicle.getId();

                                                System.out.println(" odometer query is " + driverOdometerQuery);
                                                List<Odometer> odometer = genericDAO
                                                        .executeSimpleQuery(driverOdometerQuery);

                                                if (!odometer.isEmpty()) {

                                                    boolean tic = true;
                                                    boolean first = true;
                                                    List<String> driverid = new ArrayList<String>();
                                                    for (Odometer odometerObj : odometer) {

                                                        boolean d = driverid
                                                                .contains(odometerObj.getDriver().getId() + "");
                                                        driverid.add(odometerObj.getDriver().getId() + "");
                                                        if (first) {
                                                            first = false;
                                                            continue;
                                                        }
                                                        if (!d) {
                                                            if (override == false) {
                                                                error = true;
                                                                lineError.append("More than one Driver, ");
                                                                tic = false;
                                                            } else {
                                                                tic = false;

                                                                try {
                                                                    criterias.clear();
                                                                    String name = (String) getCellValue(
                                                                            row.getCell(2));
                                                                    // System.out.println("\nTerminal====>"+name+"\n");
                                                                    if (StringUtils.isEmpty(name))
                                                                        throw new Exception("Invalid terminal");
                                                                    else {
                                                                        criterias.put("name", name);
                                                                        criterias.put("type", 4);
                                                                    }
                                                                    Location location = genericDAO
                                                                            .getByCriteria(Location.class,
                                                                                    criterias);
                                                                    if (location == null)
                                                                        throw new Exception("no such Terminal");
                                                                    else
                                                                        eztoll.setTerminal(location);
                                                                } catch (Exception ex) {
                                                                    error = true;
                                                                    lineError.append("Terminal,");
                                                                    log.warn(ex.getMessage());
                                                                }

                                                            }
                                                        }

                                                    }
                                                    if (tic) {
                                                        eztoll.setDriver(odometer.get(0).getDriver());
                                                        Driver driver = genericDAO.getById(Driver.class,
                                                                odometer.get(0).getDriver().getId());
                                                        eztoll.setTerminal(driver.getTerminal());
                                                    }

                                                } else {
                                                    if (override == false) {
                                                        error = true;
                                                        lineError.append(
                                                                "No matching  Ticket, Fuel Log,  Odometer entry, ");
                                                    } else {
                                                        try {
                                                            criterias.clear();
                                                            String name = (String) getCellValue(row.getCell(2));
                                                            // System.out.println("\nTerminal====>"+name+"\n");
                                                            if (StringUtils.isEmpty(name))
                                                                throw new Exception("Invalid terminal");
                                                            else {
                                                                criterias.put("name", name);
                                                                criterias.put("type", 4);
                                                            }
                                                            Location location = genericDAO
                                                                    .getByCriteria(Location.class, criterias);
                                                            if (location == null)
                                                                throw new Exception("no such Terminal");
                                                            else
                                                                eztoll.setTerminal(location);
                                                        } catch (Exception ex) {
                                                            error = true;
                                                            lineError.append("Terminal,");
                                                            log.warn(ex.getMessage());
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    eztoll.setPlateNumber(vehicle);
                                    eztoll.setUnit(vehicle);
                                }

                            }
                        } catch (Exception ex) {
                            error = true;
                            lineError.append("Invalid Plate or Toll tag Number, ");
                            log.warn(ex.getMessage());
                        }

                    } else {
                        if (eztoll.getTollTagNumber() != null) {
                            String transactiondate = null;
                            if (validDate(getCellValue(row.getCell(6)))) {
                                transactiondate = dateFormat
                                        .format(((Date) getCellValue(row.getCell(6))).getTime());
                            }

                            VehicleTollTag vehicletoll = genericDAO.getById(VehicleTollTag.class,
                                    eztoll.getTollTagNumber().getId());

                            /* Code to get the active plate numbers */
                            /*List<Vehicle> vehicleList = genericDAO.executeSimpleQuery(
                                  // Correction for unit no. mapping to multiple vehicle ids
                                  //"select o from Vehicle o where o.unit=" + vehicletoll.getUnit()
                                  //+ " and o.validFrom<=SYSDATE() and o.validTo>=SYSDATE() ");
                                  "select o from Vehicle o where o.id=" + vehicletoll.getVehicle().getId()
                                  + " and o.validFrom <='"+ transactiondate + "' and o.validTo >= '" 
                                  + transactiondate + "'");*/
                            List<Vehicle> vehicleList = retrieveVehicle(vehicletoll, transactiondate);
                            if (vehicleList.isEmpty() && vehicleList.size() == 0)
                                //throw new Exception("Invalid Plate Number");
                                throw new Exception(
                                        "Invalid Toll Tag Number - no matching vehicle found for given id and txn date");
                            else
                                eztoll.setPlateNumber(vehicleList.get(0));

                            // eztoll.setPlateNumber(vehicletoll.getVehicle());
                        }
                    }
                }

                // FOR TRANSACTION DATE
                try {
                    if (validDate(getCellValue(row.getCell(6))))
                        eztoll.setTransactiondate((Date) getCellValue(row.getCell(6)));
                    else {
                        error = true;
                        lineError.append("Transaction Date,");
                    }
                } catch (Exception ex) {
                    System.out.println("\nERROR IN TRANSACTION DATE\n");
                    log.warn(ex.getMessage());

                }
                // FOR TRANSACTION TIME
                try {
                    if (validDate(getCellValue(row.getCell(7)))) {
                        eztoll.setTransactiontime(dateFormat2.format((Date) getCellValue(row.getCell(7))));
                    } else {
                        String trxTime1 = (String) getCellValue(row.getCell(7));

                        if (!(StringUtils.isEmpty(trxTime1))) {
                            if (trxTime1.length() == 5 || trxTime1.length() == 8 || trxTime1.length() == 7) {
                                StringBuilder time = new StringBuilder(
                                        StringUtils.leftPad((String) getCellValue(row.getCell(7)), 4, '0'));
                                // time.insert(2, ':');
                                if (trxTime1.length() == 8) {
                                    eztoll.setTransactiontime(time.toString().substring(0, 5));
                                } else if (trxTime1.length() == 7) {
                                    eztoll.setTransactiontime(time.toString().substring(0, 4));
                                } else {
                                    eztoll.setTransactiontime(time.toString());
                                }

                            } else {
                                // System.out.println("\ntrx time is not
                                // valid\n");
                                error = true;
                                lineError.append("Transaction Time,");
                            }
                        } else {
                            lineError.append("Transaction Time,");
                        }

                    }
                } catch (Exception e) {

                }
                /*
                 * if (validTime((String) getCellValue(row.getCell(6)))) {
                 * StringBuilder time = new
                 * StringBuilder(StringUtils.leftPad((String)getCellValue(
                 * row.getCell(6)),4,'0')); int
                 * hh=Integer.parseInt(time.substring(0,2)); int
                 * mm=Integer.parseInt(time.substring(2));
                 * 
                 * if(hh==24) { if(mm==0) { time.insert(2, ':');
                 * eztoll.setTransactiontime(time.toString()); //
                 * System.out.println("\nTRANSACTION TIME ====>"+time+"\n");
                 * } else { error = true;
                 * lineError.append("transaction time,"); } } else {
                 * if(hh<24) { if(mm<=59) { time.insert(2, ':');
                 * eztoll.setTransactiontime(time.toString()); //
                 * System.out.println("\nTRANSACTION TIME ====>"+time+"\n");
                 * } else { error = true;
                 * lineError.append("transaction time minut is > 59,"); } }
                 * else { error = true;
                 * lineError.append("transaction time hours is > 24,"); } }
                 * } else { error = true;
                 * lineError.append("transaction time more than 5 degits,");
                 * 
                 * }
                 */

                // FOR AGENCY
                try {
                    eztoll.setAgency((String) getCellValue(row.getCell(8)));
                } catch (Exception ex) {
                    error = true;
                    lineError.append("Agency,");
                    log.warn(ex.getMessage());
                }
                // FOR AMOUNTS
                String amount1 = row.getCell(9).toString();
                Double amount2 = getValidGallon(amount1);
                if (amount2 != null) {
                    //eztoll.setAmount(Math.abs(amount2));
                    eztoll.setAmount(amount2);
                } else {
                    lineError.append("Amount,");
                    error = true;
                }

                /**Added dup check**/
                // END OF CELL
                if (override == false) {
                    System.out.println("***** eneter here ok 0");
                    if (!error) {
                        System.out.println("***** eneter here ok 1");
                        Map prop = new HashMap();
                        prop.put("toolcompany", eztoll.getToolcompany().getId());
                        prop.put("company", eztoll.getCompany().getId());
                        prop.put("driver", eztoll.getDriver().getId());
                        prop.put("terminal", eztoll.getTerminal().getId());
                        prop.put("unit", eztoll.getUnit().getId());
                        prop.put("agency", eztoll.getAgency());
                        prop.put("invoiceDate", dateFormat1.format(eztoll.getInvoiceDate()));
                        prop.put("transactiondate", dateFormat1.format(eztoll.getTransactiondate()));
                        prop.put("transactiontime", eztoll.getTransactiontime());
                        if (eztoll.getTollTagNumber() != null) {
                            prop.put("tollTagNumber", eztoll.getTollTagNumber().getId());
                        }
                        if (eztoll.getPlateNumber() != null) {
                            prop.put("plateNumber", eztoll.getPlateNumber().getId());
                        }
                        prop.put("amount", eztoll.getAmount());
                        boolean rst = genericDAO.isUnique(EzToll.class, eztoll, prop);
                        System.out.println("***** eneter here ok 2" + rst);
                        if (!rst) {
                            System.out.println("***** eneter here ok 3");
                            lineError.append("Toll tag entry already exists(Duplicate),");
                            error = true;
                            errorcount++;
                        }

                        if (eztolls.contains(eztoll)) {
                            lineError.append("Duplicate eztoll in excel,");
                            error = true;
                        }
                        // Toll upload improvement - 23rd Jul 2016
                        /*else { 
                           eztolls.add(eztoll);
                        }*/
                    } else {
                        errorcount++;
                    }
                } else {
                    if (!error) {
                        eztolls.add(eztoll);
                    } else {
                        errorcount++;
                    }
                }
                /**End of adding dup check**/

                /*// END OF CELL
                if (!error) {
                    if (eztolls.contains(eztoll)) {
                       lineError.append("Duplicate eztoll,"); 
                       error = true;
                    } else { 
                       eztolls.add(eztoll);
                    }
                            
                   //eztolls.add(eztoll);
                } else {
                   errorcount++;
                }*/

            } // TRY INSIDE SHILE(LOOP)
            catch (Exception ex) {
                error = true;
                lineError.append("Exception while processing toll upload records,");
                log.warn(ex);
            }
            if (lineError.length() > 0) {
                System.out.println("Error :" + lineError.toString());
                list.add("Line " + count + ":" + lineError.toString() + "<br/>");
            }
            // Toll upload improvement - 23rd Jul 2016
            else {
                eztolls.add(eztoll);
            }

            System.out.println("Record No :" + count);
            count++;
        } // CLOSE while (rows.hasNext())
    } // FIRST TRY
    catch (Exception e) {
        log.warn("Error in import eztoll :" + e);
        // Toll upload improvement - 23rd Jul 2016
        throw e;
    }

    // Toll upload improvement - 23rd Jul 2016
    //if (errorcount == 0) {
    for (EzToll etoll : eztolls) {
        Map criti = new HashMap();
        criti.clear();
        criti.put("id", etoll.getDriver().getId());
        Driver drvOBj = genericDAO.getByCriteria(Driver.class, criti);
        if (drvOBj != null)
            etoll.setDriverFullName(drvOBj.getFullName());

        criti.clear();
        criti.put("id", etoll.getUnit().getId());
        Vehicle vehObj = genericDAO.getByCriteria(Vehicle.class, criti);
        if (vehObj != null)
            etoll.setUnitNum(vehObj.getUnitNum());
        genericDAO.saveOrUpdate(etoll);
    }
    // Toll upload improvement - 23rd Jul 2016
    //}
    return list;
}

From source file:net.umpay.mailbill.hql.orm.hibernate.HibernateDao.java

/**
 * countHql.//from  w ww .ja  v  a2 s  .com
 * 
 * ???hql?,??hql?count?.
 */
protected long countHqlResult(final String hql, final Object... values) {
    String fromHql = hql;
    //select??order by???count,?.
    fromHql = "from " + StringUtils.substringAfter(fromHql, "from");
    fromHql = StringUtils.substringBefore(fromHql, "order by");

    String countHql = "select count(*) " + fromHql.replaceAll("fetch", "");

    try {
        Long count = findUnique(countHql, values);
        return count;
    } catch (Exception e) {
        throw new RuntimeException("hql can't be auto count, hql is:" + countHql, e);
    }
}

From source file:net.umpay.mailbill.hql.orm.hibernate.HibernateDao.java

/**
 * countHql./*ww  w  . ja  v a  2 s  . co m*/
 * 
 * ???hql?,??hql?count?.
 */
protected long countHqlResult(final String hql, final Map<String, ?> values) {
    String fromHql = hql;
    //select??order by???count,?.
    fromHql = "from " + StringUtils.substringAfter(fromHql, "from");
    fromHql = StringUtils.substringBefore(fromHql, "order by");

    String countHql = "select count(*) " + fromHql.replaceAll("fetch", "");

    try {
        Long count = findUnique(countHql, values);
        return count;
    } catch (Exception e) {
        throw new RuntimeException("hql can't be auto count, hql is:" + countHql, e);
    }
}

From source file:net.ymate.framework.addons.plugin.view.FreemarkerPluginView.java

protected void __doProcessPath() {
    if (StringUtils.isNotBlank(__contentType)) {
        WebContext.getResponse().setContentType(__contentType);
    }/*w  w  w  .j av  a 2  s.  co  m*/
    for (Map.Entry<String, Object> _entry : __attributes.entrySet()) {
        WebContext.getRequest().setAttribute(_entry.getKey(), _entry.getValue());
    }
    if (StringUtils.isBlank(__path)) {
        String _mapping = WebContext.getRequestContext().getRequestMapping();
        if (_mapping.charAt(0) == '/') {
            _mapping = _mapping.substring(1);
        }
        if (_mapping.endsWith("/")) {
            _mapping = _mapping.substring(0, _mapping.length() - 1);
        }
        __path = __alias.concat("/templates/").concat(_mapping).concat(".ftl");
    } else {
        if (!__path.startsWith("/")) {
            __path = __alias.concat("/templates/").concat(__path);
        } else if (__path.startsWith(ViewPathUtils.pluginViewPath())) {
            __path = StringUtils.substringAfter(__path, ViewPathUtils.pluginViewPath());
        }
        if (!__path.endsWith(".ftl")) {
            __path += ".ftl";
        }
    }
}

From source file:net.ymate.framework.addons.plugin.view.FreemarkerPluginView.java

/**
 * ?Freemarker???()// ww w. j a  v a  2s .com
 *
 * @param owner WebMVC?
 */
@Override
protected synchronized void __doViewInit(IWebMvc owner) {
    super.__doViewInit(owner);
    if (__freemarkerConfig == null) {
        try {
            FreemarkerConfigBuilder _builder = FreemarkerConfigBuilder.create();
            if (__baseViewPath.startsWith("/WEB-INF")) {
                _builder.addTemplateFileDir(new File(RuntimeUtils.getRootPath(),
                        StringUtils.substringAfter(__baseViewPath, "/WEB-INF/"))).build();
            } else {
                _builder.addTemplateFileDir(new File(__baseViewPath)).build();
            }
        } catch (IOException e) {
            throw new Error(RuntimeUtils.unwrapThrow(e));
        }
    }
}

From source file:net.ymate.framework.commons.HttpClientHelper.java

private void __doExecHttpDownload(RequestBuilder requestBuilder, final IFileHandler handler) throws Exception {
    CloseableHttpClient _httpClient = __doBuildHttpClient();
    try {/*from   w w w  . j av a  2  s .  c  om*/
        _httpClient.execute(requestBuilder.build(), new ResponseHandler<Void>() {

            public Void handleResponse(HttpResponse response) throws IOException {
                String _fileName = null;
                if (response.getStatusLine().getStatusCode() == 200) {
                    if (response.containsHeader("Content-disposition")) {
                        _fileName = StringUtils.substringAfter(
                                response.getFirstHeader("Content-disposition").getValue(), "filename=");
                    }
                }
                handler.handle(response,
                        new IFileWrapper.NEW(_fileName, response.getEntity().getContentType().getValue(),
                                response.getEntity().getContentLength(),
                                new BufferedInputStream(response.getEntity().getContent())));
                return null;
            }
        });
    } finally {
        _httpClient.close();
    }
}

From source file:net.ymate.framework.core.util.WebUtils.java

/**
 * @param request      HttpServletRequest
 * @param requestPath  //from  w w w.  j  a  va 2s . co  m
 * @param withBasePath ???
 * @return URL
 */
public static String buildURL(HttpServletRequest request, String requestPath, boolean withBasePath) {
    requestPath = StringUtils.trimToEmpty(requestPath);
    if (withBasePath && !requestPath.equals("") && requestPath.charAt(0) == '/') {
        requestPath = StringUtils.substringAfter(requestPath, "/");
    }
    return (withBasePath ? WebUtils.baseURL(request) + requestPath : requestPath)
            + StringUtils.defaultIfEmpty(YMP.get().getConfig().getParam(Optional.REQUEST_SUFFIX), "");
}