Example usage for org.apache.commons.lang.time DateUtils parseDate

List of usage examples for org.apache.commons.lang.time DateUtils parseDate

Introduction

In this page you can find the example usage for org.apache.commons.lang.time DateUtils parseDate.

Prototype

public static Date parseDate(String str, String... parsePatterns) throws ParseException 

Source Link

Document

Parses a string representing a date by trying a variety of different parsers.

The parse will try each parse pattern in turn.

Usage

From source file:ru.codeinside.gws3564c.enclosure.grp.EnclosureBuilderTest.java

@Before
public void setUp() throws Exception {
    currentDate = DateUtils.parseDate("01.02.2001", new String[] { "dd.MM.yyyy" });
    context = new DummyContext();
    enclosureGRPBuilder = new SubjectRightsEnclosureBuilder(context);
}

From source file:ru.codeinside.gws3564c.enclosure.grp.TestUtils.java

public static Date getDateValue(String dateStr) {
    try {/*from  ww w.j  a v  a 2 s .co m*/
        return DateUtils.parseDate(dateStr, new String[] { "yyyy-MM-dd" });
    } catch (Exception err) {
        return null;
    }
}

From source file:ru.codeinside.gws3572c.ExportReceiptTest.java

@Test
public void testCreateRequest() throws Exception {
    context.setVariable("operationType", "exportReceipt");
    context.setVariable("postBlockTimeStamp",
            DateUtils.parseDate("2001-12-17 09:30:47", new String[] { "yyyy-MM-dd HH:mm:ss" }));
    context.setVariable("postBlockId", "4548445");
    context.setVariable("postBlockSenderIdentifier", "044525716");
    context.setVariable("startDate",
            DateUtils.parseDate("2001-12-17 09:30:47", new String[] { "yyyy-MM-dd HH:mm:ss" }));
    context.setVariable("endDate",
            DateUtils.parseDate("2001-12-17 09:30:47", new String[] { "yyyy-MM-dd HH:mm:ss" }));
    context.setVariable("exportRequestType", "QUITTANCE");
    context.setVariable("+SupplierBillIDBlock", 1);
    context.setVariable("SupplierBillID_1", "18810X50?586032ZZ0");
    context.setVariable("-SupplierBillIDBlock", "");
    ClientRequest clientRequest = client.createClientRequest(context);
    assertNotNull(clientRequest);/*from   www.j  av a2 s  .  c  o m*/
    assertNotNull(clientRequest.appData);

    String sampleAppData = R.getTextResource("gmp/export_receipt/sample_SupplierBillID.xml");
    //sampleAppData = sampleAppData.replace("[\t|\n]", "");
    assertEquals(sampleAppData, clientRequest.appData);
}

From source file:ru.codeinside.gws3572c.GMPClientSignTest.java

private DummyContext createContext() throws ParseException {
    DummyContext ctx = new DummyContext();
    ctx.setVariable("payerType", "1");
    ctx.setVariable("payerPersonDocumentID1", "12345678901");
    ctx.setVariable("postBlockIdRequest", "13454"); //  ?
    ctx.setVariable("postBlockSenderIdentifier", "20091d"); //  ?
    ctx.setVariable("ordinalNumber", "013400000011"); // ?  ?
    ctx.setVariable("postBlockTimeStamp",
            DateUtils.parseDate("25.07.2012 09:40:47", new String[] { "dd.MM.yyyy HH:mm:ss" })); //  ??? ?

    ctx.setVariable("supplierOrgInfoName",
            "   ?  ? ?");
    ctx.setVariable("supplierOrgInfoINN", "1655102196");
    ctx.setVariable("supplierOrgInfoKPP", "165501001");
    ctx.setVariable("accountAccount", "40101810800000010001");
    ctx.setVariable("bankBIK", "049205001");
    ctx.setVariable("bankName", " ?  . ");

    ctx.setVariable("chargeSupplierBillID", "19255500000000000079"); //   ?  
    ctx.setVariable("chargeBillDate", DateUtils.parseDate("10.03.2011", new String[] { "dd.MM.yyyy" })); // ?? ?
    ctx.setVariable("chargeBillFor", "?   ?"); // ?? ?
    ctx.setVariable("chargeTotalAmount", "1000,00");
    ctx.setVariable("chargeChangeStatus",
            "1"); /* ? ? 1 -   2 -   3 -  */
    ctx.setVariable("chargeTreasureBranch", "  ? ?");
    ctx.setVariable("chargeKBK", "19210806000011000110");
    ctx.setVariable("chargeOKATO", "92401000000");
    ctx.setVariable("chargeApplicationID", "455555");
    ctx.setVariable("chargeUnifiedPayerIdentifier", "0100000000006667775555643");

    ctx.setVariable("budgetIndexStatus", "0");
    ctx.setVariable("budgetPaymentType", "0");
    ctx.setVariable("budgetPurpose", "0");
    ctx.setVariable("budgetTaxPeriod", "0");
    ctx.setVariable("budgetTaxDocNumber", "0");
    ctx.setVariable("budgetTaxDocDate", "0");
    ctx.setVariable("operationType", "importCharge");
    return ctx;/*ww w .j  a  v  a 2s.  c  o m*/
}

From source file:ru.codeinside.gws3572c.ImportChargeRequestTest.java

private DummyContext createContext() throws ParseException {
    DummyContext ctx = new DummyContext();
    ctx.setVariable("postBlockSenderIdentifier", "20091d"); //  ?
    ctx.setVariable("ordinalNumber", "013400000011"); //  ?
    ctx.setVariable("postBlockTimeStamp",
            DateUtils.parseDate("25.07.2012 09:40:47", new String[] { "dd.MM.yyyy HH:mm:ss" })); //  ??? ?

    ctx.setVariable("supplierOrgInfoName",
            "   ?  ? ?");
    ctx.setVariable("supplierOrgInfoINN", "1655102196");
    ctx.setVariable("supplierOrgInfoKPP", "165501001");
    ctx.setVariable("accountAccount", "40101810800000010001");
    ctx.setVariable("bankBIK", "049205001");
    ctx.setVariable("bankName", " ?  . ");

    //ctx.setVariable("chargeSupplierBillID", "19255500000000000079"); //   ?  
    ctx.setVariable("chargeBillDate", DateUtils.parseDate("10.03.2011", new String[] { "dd.MM.yyyy" })); // ?? ?
    ctx.setVariable("chargeBillFor", "?   ?"); // ?? ?
    ctx.setVariable("chargeTotalAmount", "1000,00");
    ctx.setVariable("chargeChangeStatus",
            "1"); /* ? ? 1 -   2 -   3 -  */
    ctx.setVariable("chargeTreasureBranch", "  ? ?");
    ctx.setVariable("chargeKBK", "19210806000011000110");
    ctx.setVariable("chargeOKATO", "92401000000");
    ctx.setVariable("chargeApplicationID", "455555");
    ctx.setVariable("chargeUnifiedPayerIdentifier", "0100000000006667775555643");

    ctx.setVariable("budgetIndexStatus", "0");
    ctx.setVariable("budgetPaymentType", "0");
    ctx.setVariable("budgetPurpose", "0");
    ctx.setVariable("budgetTaxPeriod", "0");
    ctx.setVariable("budgetTaxDocNumber", "0");
    ctx.setVariable("budgetTaxDocDate", "0");
    ctx.setVariable("payerType", "01");
    ctx.setVariable("payerPersonDocumentID2", "6667775555");
    ctx.setVariable("payerPersonCitizenshipID", "643");
    ctx.setVariable("operationType", "importCharge");
    return ctx;/*w  w w .  j a  va  2 s  . c o  m*/
}

From source file:tds.dll.mysql.StudentDLL.java

private SingleDataResultSet T_UpdateScoredResponse_common(SQLConnection connection, UUID oppKey, UUID session,
        UUID browserId, String itemId, Integer page, Integer position, String dateCreated,
        Integer responseSequence, Integer score, String response, Boolean isSelected, Boolean isValid,
        Integer scoreLatency, String scoreStatus, String scoreRationale, String scoreDimensions,
        int methodVersion, Float pageDuration) throws ReturnStatusException {

    Date now = _dateUtil.getDateWRetStatus(connection);
    Integer opprestart = null;//www . ja  v  a  2s .c  o m
    String status = null;
    Integer lastSequence = null;
    String itmkey = null;
    Date genDate = null;
    String msg = null;
    Boolean isinactive = null;
    String clientName = null;
    UUID scoremark = null;
    Date scoringDate = null;
    Date scoredDate = null;
    Integer thescore = 0;
    Integer audit = null;
    String environment = null;
    Boolean abortSim = false; // set @abortSim = 0;
    Integer responseCount = null;

    _Ref<String> error = new _Ref<>();
    _ValidateTesteeAccessProc_SP(connection, oppKey, session, browserId, true, error);
    if (error.get() != null) {
        return _commonDll._ReturnError_SP(connection, clientName, "_ValidateTesteeAccessProc", error.get(),
                null, oppKey, "_ValidateTesteeAccess", "denied");
    }

    final String SQL_QUERY1 = "select Restart as opprestart, status, clientname from testopportunity where _Key = ${oppkey};";
    SqlParametersMaps parms1 = new SqlParametersMaps().put("oppkey", oppKey);
    SingleDataResultSet result = executeStatement(connection, SQL_QUERY1, parms1, false).getResultSets().next();
    DbResultRecord record = (result.getCount() > 0 ? result.getRecords().next() : null);
    if (record != null) {
        opprestart = record.<Integer>get("opprestart");
        status = record.<String>get("status");
        clientName = record.<String>get("clientname");
    }

    // Included the segmentEntry and segmentExit statuses here to account for irregular async call timing
    if (DbComparator.notEqual(status, "started") && DbComparator.notEqual(status, "review")
            && DbComparator.notEqual(status, "segmentEntry") && DbComparator.notEqual(status, "segmentExit")) {
        return _commonDll._ReturnError_SP(connection, clientName, "T_UpdateScoredResponse",
                "Your test opportunity has been interrupted. Please check with your Test Administrator to resume your test.",
                null, oppKey, "T_UpdateScoredResponse", "denied");
    }

    final String SQL_QUERY2 = "select environment from _externs where clientname = ${clientname};";
    SqlParametersMaps parms2 = new SqlParametersMaps().put("clientname", clientName);
    result = executeStatement(connection, SQL_QUERY2, parms2, false).getResultSets().next();
    record = (result.getCount() > 0 ? result.getRecords().next() : null);
    if (record != null) {
        environment = record.<String>get("environment");
    }
    if (DbComparator.isEqual(environment, "SIMULATION")) {
        final String SQL_QUERY3 = "select sim_abort as abortSim from session where _Key = ${session};";
        SqlParametersMaps parms3 = new SqlParametersMaps().put("session", session);
        result = executeStatement(connection, SQL_QUERY3, parms3, false).getResultSets().next();
        record = (result.getCount() > 0 ? result.getRecords().next() : null);
        if (record != null) {
            abortSim = record.<Boolean>get("abortSim");
        }
    }
    audit = AuditResponses_FN(connection, clientName);
    final String SQL_QUERY4 = "select responseSequence as lastSequence, _efk_ItemKey as itmkey, dateGenerated as genDate, score as thescore, isInactive as isinactive, "
            + " scoreMark as scoremark, scoringDate, scoredDate from testeeresponse where _fk_TestOpportunity = ${oppkey} and Position = ${position};";
    SqlParametersMaps parms4 = new SqlParametersMaps().put("oppkey", oppKey).put("position", position);
    result = executeStatement(connection, SQL_QUERY4, parms4, false).getResultSets().next();
    record = (result.getCount() > 0 ? result.getRecords().next() : null);
    if (record != null) {
        lastSequence = record.<Integer>get("lastSequence");
        itmkey = record.<String>get("itmkey");
        genDate = record.<Date>get("genDate");
        thescore = record.<Integer>get("thescore");
        isinactive = record.<Boolean>get("isinactive");
        scoremark = record.<UUID>get("scoremark");
        scoringDate = record.<Date>get("scoringDate");
        scoredDate = record.<Date>get("scoredDate");
    }

    Date dt = null;
    try {
        if (dateCreated != null) {
            String[] tokens = dateCreated.split("\\.");
            if (tokens.length == 2 && tokens[1].length() > 3) {
                dateCreated = String.format("%s.%s", tokens[0], tokens[1].substring(0, 3));
            }
            dt = DateUtils.parseDate(dateCreated,
                    new String[] { "yyyy-MM-dd HH:mm:ss.SSS", "yyyy-MM-dd HH:mm:ss" });
        }
    } catch (Exception e) {
        _logger.error(String.format(
                "Unexpected dateCreated format: %s, please update StudentDLL.T_UpdateScoredResponse to parse this format!",
                dateCreated));
    }

    // if (itmkey == null || DbComparator.notEqual (itmkey, itemId)) {
    if (itmkey == null || checkItem(connection, itmkey, itemId) == false) {

        msg = String.format(
                "The item does not exist at this position in this test opportunity: Position = %d; Item = %s; testeeresponse._efk_ItemKey found is %s",
                position, itemId, (itmkey == null ? "null" : itmkey));

        // } else if (DbComparator.notEqual (genDate, dt)) {
    } else if (genDate != null && dt != null && genDate.getTime() != dt.getTime()) {

        msg = String.format("Item security codes do not match:  Position = %d; Item = %s; Date = %s ", position,
                itemId, dateCreated);
        // ("Item security codes do not match:  Position = %d; Item = %s; Date = %s ",
        // position, itemId, dateCreated);

    } else if (DbComparator.greaterThan(lastSequence, responseSequence)) {

        msg = String.format(
                "Responses out of sequence: Position = %d;  Stored sequence = %d;  New sequence = %d", position,
                lastSequence, responseSequence);
    }

    if (msg != null) {
        _commonDll._LogDBError_SP(connection, "T_UpdateScoredResponse", msg, null, null, null, oppKey,
                clientName, session);
        return _commonDll._ReturnError_SP(connection, clientName, "T_UpdateScoredResponse",
                "Response update failed", null, oppKey, null);
    }

    if (response != null && (score == null || DbComparator.lessThan(score, 0))) {
        // new response, score to be determined
        thescore = -1; // not scored
        scoremark = UUID.randomUUID(); // app will need this token to update the
                                       // record with the score for THIS response
                                       // once it is determined asynchronously
        scoringDate = now; // start the scoring clock running
        scoredDate = null; // no score, so the date scored is undetermined
    } else {
        if (response != null && DbComparator.greaterOrEqual(scoreLatency, 0)) {
            scoremark = null; // any previous scoremark is now obsolete
            thescore = score; // use the provided score
            scoringDate = now; // 'instantaneous' time lag
            scoredDate = now;
        }
    }
    if (response == null) {
        final String SQL_UPDATE = "Update testeeresponse  set IsSelected = ${isSelected}, IsValid = ${isValid}, _fk_Browser = ${browserID}, responseSequence = ${responseSequence} "
                + " where _fk_TestOpportunity = ${oppkey} and position = ${position};";
        SqlParametersMaps parms5 = new SqlParametersMaps();
        parms5.put("oppkey", oppKey);
        parms5.put("position", position);
        parms5.put("isSelected", isSelected);
        parms5.put("isValid", isValid);
        parms5.put("browserID", browserId);
        parms5.put("responseSequence", responseSequence);
        executeStatement(connection, SQL_UPDATE, parms5, false).getUpdateCount();
    } else {

        response = StringUtils.replace(response, "\\", "\\\\");

        String tmp = null;
        //      if (methodVersion == 1)
        //        tmp = "Update testeeresponse set IsSelected = ${isSelected}, IsValid = ${isValid}, _fk_ResponseSession = ${session}, _fk_Browser = ${browserID}, " +
        //            " scoreMark = ${scoremark}, NumUpdates =  NumUpdates + 1, DateSubmitted = ${now}, Response = ${response}, responseSequence = ${responseSequence}, responseLength = length(${response})," +
        //            " Score = ${thescore}, DateFirstResponse = COALESCE(DateFirstResponse, ${now}), ScoreLatency = ScoreLatency + ${scoreLatency}, scorestatus = ${scorestatus}, scoringDate = ${scoringDate},"
        //            +
        //            " scoreRationale = ${scoreRationale}, scoredDate = ${scoredDate} "
        //            + " where _fk_TestOpportunity = ${oppkey} and position = ${position} and responseSequence <= ${responseSequence};";
        //      else
        tmp = "Update testeeresponse set IsSelected = ${isSelected}, IsValid = ${isValid}, _fk_ResponseSession = ${session}, _fk_Browser = ${browserID}, "
                + " scoreMark = ${scoremark}, NumUpdates =  NumUpdates + 1, DateSubmitted = ${now}, Response = ${response}, responseSequence = ${responseSequence}, responseLength = length(${response}),"
                + " Score = ${thescore}, DateFirstResponse = COALESCE(DateFirstResponse, ${now}), ScoreLatency = ScoreLatency + ${scoreLatency}, scorestatus = ${scorestatus}, scoringDate = ${scoringDate},"
                + " scoreRationale = ${scoreRationale}, scoredDate = ${scoredDate}, scoreDimensions = ${scoreDimensions}, responseDurationInSecs = COALESCE(responseDurationInSecs, 0) + "
                + " (SELECT (${pageDuration} / (SELECT COUNT(*) FROM (SELECT * FROM testeeresponse WHERE _fk_testopportunity = ${oppkey} AND page = ${page}) as tr))) "
                + " where _fk_TestOpportunity = ${oppkey} and position = ${position} and responseSequence <= ${responseSequence};";

        final String SQL_UPDATE1 = tmp;
        SqlParametersMaps parms6 = new SqlParametersMaps();
        parms6.put("isSelected", isSelected);
        parms6.put("isValid", isValid);
        parms6.put("session", session);
        parms6.put("browserID", browserId);
        parms6.put("scoremark", scoremark);
        parms6.put("now", now);
        parms6.put("response", response);
        parms6.put("responseSequence", responseSequence);
        parms6.put("thescore", thescore);
        parms6.put("scoreLatency", scoreLatency);
        parms6.put("scorestatus", scoreStatus);
        parms6.put("scoringDate", scoringDate);
        parms6.put("scoreRationale", scoreRationale);
        parms6.put("scoredDate", scoredDate);
        parms6.put("oppkey", oppKey);
        parms6.put("pageDuration", pageDuration);
        parms6.put("page", page);
        parms6.put("position", position).put("scoreDimensions", scoreDimensions);
        executeStatement(connection, SQL_UPDATE1, parms6, false).getUpdateCount();

        if (DbComparator.notEqual(audit, 0)) {
            final String SQL_INSERT = "INSERT INTO  testeeresponseaudit(_fk_TestOpportunity, position, scoremark, sequence, response, sessionKey, browserKey, isSelected, isValid, "
                    + " score, scorelatency, scoringDate, scoredDate, _efk_Item, _date) "
                    + " select ${oppkey}, ${position},${scoremark}, ${responseSequence}, ${response}, ${session}, ${browserID}, ${isSelected},"
                    + " ${isValid}, ${thescore}, ${scoreLatency}, ${scoringDate}, ${scoredDate}, ${itemID}, now(3)";
            SqlParametersMaps parms7 = new SqlParametersMaps();
            parms7.put("oppkey", oppKey);
            parms7.put("position", position);
            parms7.put("scoremark", scoremark);
            parms7.put("responseSequence", responseSequence);
            parms7.put("response", response);
            parms7.put("session", session);
            parms7.put("browserID", browserId);
            parms7.put("isSelected", isSelected);
            parms7.put("isValid", isValid);
            parms7.put("thescore", thescore);
            parms7.put("scoreLatency", scoreLatency);
            parms7.put("scoringDate", scoringDate);
            parms7.put("scoredDate", scoredDate);
            parms7.put("itemID", itemId);
            executeStatement(connection, SQL_INSERT, parms7, false).getUpdateCount();
        }
    }
    final String SQL_QUERY5 = "select count(*) as responseCount from testeeresponse where _fk_TestOpportunity = ${oppkey} and dateFirstResponse is not null;";
    SqlParametersMaps parms8 = parms1;
    result = executeStatement(connection, SQL_QUERY5, parms8, false).getResultSets().next();
    record = (result.getCount() > 0 ? result.getRecords().next() : null);
    if (record != null) {
        responseCount = record.<Long>get("responseCount").intValue();
    }
    final String SQL_UPDATE2 = "update testopportunity set numResponses = ${responseCount} where _Key = ${oppkey};";
    SqlParametersMaps parms9 = new SqlParametersMaps().put("oppkey", oppKey).put("responseCount",
            responseCount);
    executeStatement(connection, SQL_UPDATE2, parms9, false).getUpdateCount();

    List<CaseInsensitiveMap<Object>> resultList = new ArrayList<CaseInsensitiveMap<Object>>();
    CaseInsensitiveMap<Object> rcd = new CaseInsensitiveMap<Object>();
    rcd.put("status", "updated");
    rcd.put("number", 1);
    rcd.put("reason", null);
    rcd.put("scoremark", scoremark);
    rcd.put("responseCount", responseCount);
    rcd.put("abortSim", abortSim);
    resultList.add(rcd);

    result = new SingleDataResultSet();
    result.addColumn("status", SQL_TYPE_To_JAVA_TYPE.VARCHAR);
    result.addColumn("number", SQL_TYPE_To_JAVA_TYPE.INT);
    result.addColumn("reason", SQL_TYPE_To_JAVA_TYPE.VARCHAR);
    result.addColumn("scoremark", SQL_TYPE_To_JAVA_TYPE.UNIQUEIDENTIFIER);
    result.addColumn("responseCount", SQL_TYPE_To_JAVA_TYPE.INT);
    result.addColumn("abortSim", SQL_TYPE_To_JAVA_TYPE.BIT);

    result.addRecords(resultList);

    _commonDll._LogDBLatency_SP(connection, "T_UpdateScoredResponse", now, null, true, position, oppKey,
            session, clientName, null);

    return result;
}

From source file:ubic.gemma.loader.entrez.pubmed.PubMedXMLParser.java

/**
 * @param bibRef//  w w  w. j  a  v  a 2s  .com
 * @param item
 * @throws IOException
 */
public void extractBookPublicationYear(BibliographicReference bibRef, Node item) throws IOException {
    NodeList c = item.getChildNodes();
    for (int i = 0; i < c.getLength(); i++) {
        Node a = c.item(i);
        if (!(a instanceof Element)) {
            continue;
        }
        if (a.getNodeName().equals("Year")) {
            try {
                bibRef.setPublicationDate(DateUtils.parseDate(XMLUtils.getTextValue((Element) a), formats));
            } catch (ParseException e) {
                log.warn("Could not extract date of publication from : " + XMLUtils.getTextValue((Element) a));
            }
        }
    }
}

From source file:ubic.gemma.loader.entrez.pubmed.PubMedXMLParser.java

/**
 * @param dateNode/*from w  w w .  j  av a 2  s  . c  o  m*/
 * @return
 * @throws TransformerException
 * @throws IOException
 */
private Date extractJournalIssueDate(Node dateNode) throws IOException {

    String yearText = null;// = XMLUtils.getTextValue( ( Element ) y );
    String medLineText = null;// = XMLUtils.getTextValue( ( Element ) medLineDate );
    String monthText = null;// = XMLUtils.getTextValue( ( Element ) m );
    String dayText = null;// = XMLUtils.getTextValue( ( Element ) dn );

    NodeList childNodes = dateNode.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node c = childNodes.item(i);
        if (!(c instanceof Element)) {
            continue;
        }
        String t = XMLUtils.getTextValue((Element) c);
        if (c.getNodeName().equals("Year")) {
            yearText = t;
        } else if (c.getNodeName().equals("Month")) {
            monthText = t;
        } else if (c.getNodeName().equals("Day")) {
            dayText = t;
        } else if (c.getNodeName().equals("MedlineDate")) {
            medLineText = t;
        }
    }

    df.setLenient(true);

    if (yearText == null && medLineText != null) {
        String[] yearmo = medLineText.split("\\s");
        if (yearmo.length == 2) {
            // 1983 Aug
            yearText = yearmo[0];
            monthText = yearmo[1];
            monthText = monthText.replaceAll("-\\w+", "");
        } else if (yearmo.length == 4) {
            // 1983 Aug 31-Sep 6
            yearText = yearmo[0];
            monthText = yearmo[1];
            dayText = yearmo[2].replaceAll("-\\w+", "");
        } else if (yearmo.length == 3) {
            // 1983 Jul 9-16
            yearText = yearmo[0];
            monthText = yearmo[1];
            dayText = yearmo[2].replaceAll("-\\w+", "");
        } else if (yearmo.length == 1) {
            // 1983-84
            yearText = yearmo[0];
            yearText = yearText.replaceAll("-\\w+", "");
        } else {
            log.warn("No data information from medline text: " + medLineText);
        }
    }

    if (monthText == null) {
        monthText = "Jan"; // arbitrary...
    }

    String dateString = monthText + " " + (dayText == null ? "1" : dayText) + ", " + yearText;

    try {
        return DateUtils.parseDate(dateString, formats);
    } catch (ParseException e) {
        log.warn("Could not parse date " + dateString + " from medlinetext=" + medLineText);
        return null;
    }
}

From source file:ubic.gemma.loader.expression.geo.service.GeoBrowser.java

/**
 * Retrieves and parses tab delimited file from GEO. File contains pageSize
 * GEO records starting from startPage./*from   ww w. ja va2  s  .c  om*/
 * 
 * @param startPage
 * @param pageSize
 * @return list of GeoRecords
 * @throws IOException
 * @throws ParseException
 */
public List<GeoRecord> getRecentGeoRecords(int startPage, int pageSize) throws IOException, ParseException {

    if (startPage < 0 || pageSize < 0)
        throw new IllegalArgumentException("Values must be greater than zero ");

    List<GeoRecord> records = new ArrayList<GeoRecord>();
    URL url = null;
    try {
        url = new URL(GEO_BROWSE_URL + startPage + GEO_BROWSE_SUFFIX + pageSize);
    } catch (MalformedURLException e) {
        throw new RuntimeException("Invalid URL " + url, e);
    }

    InputStream is = null;

    try {
        URLConnection conn = url.openConnection();
        conn.connect();
        is = conn.getInputStream();
    } catch (IOException e) {
        log.error(e, e);
        throw e;
    }

    // We are getting a tab delimited file.
    BufferedReader br = new BufferedReader(new InputStreamReader(is));

    // Read columns headers.
    String headerLine = br.readLine();
    String[] headers = StringUtil.csvSplit(headerLine);

    // Map column names to their indices (handy later).
    Map<String, Integer> columnNameToIndex = new HashMap<String, Integer>();
    for (int i = 0; i < headers.length; i++) {
        columnNameToIndex.put(headers[i], i);
    }

    // Read the rest of the file.
    String line = null;
    while ((line = br.readLine()) != null) {
        String[] fields = StringUtil.csvSplit(line);

        GeoRecord geoRecord = new GeoRecord();
        geoRecord.setGeoAccession(fields[columnNameToIndex.get("Accession")]);
        geoRecord.setTitle(StringUtils
                .strip(fields[columnNameToIndex.get("Title")].replaceAll(FLANKING_QUOTES_REGEX, "")));

        String sampleCountS = fields[columnNameToIndex.get("Sample Count")];
        if (StringUtils.isNotBlank(sampleCountS)) {
            try {
                geoRecord.setNumSamples(Integer.parseInt(sampleCountS));
            } catch (NumberFormatException e) {
                throw new RuntimeException("Could not parse sample count: " + sampleCountS);
            }
        } else {
            log.warn("No sample count for " + geoRecord.getGeoAccession());
        }
        geoRecord
                .setContactName(fields[columnNameToIndex.get("Contact")].replaceAll(FLANKING_QUOTES_REGEX, ""));

        String[] taxons = fields[columnNameToIndex.get("Taxonomy")].replaceAll(FLANKING_QUOTES_REGEX, "")
                .split(";");
        geoRecord.getOrganisms().addAll(Arrays.asList(taxons));

        Date date = DateUtils.parseDate(
                fields[columnNameToIndex.get("Release Date")].replaceAll(FLANKING_QUOTES_REGEX, ""),
                DATE_FORMATS);
        geoRecord.setReleaseDate(date);

        geoRecord.setSeriesType(fields[columnNameToIndex.get("Series Type")]);

        records.add(geoRecord);
    }

    is.close();

    if (records.isEmpty()) {
        log.warn("No records obtained");
    }
    return records;

}

From source file:xmltype.XMLTypeTest.java

private ChargeType createCharge() throws ParseException {
    final ChargeType charge = new ChargeType();

    charge.setSupplierBillID("19255500000000000079"); //   ?   TODO ,  ?      (Bill.xsd)
    Date billDate = DateUtils.parseDate("2011-03-10", new String[] { "yyyy-MM-dd" });
    charge.setBillDate(XmlTypes.date(DateFormatUtils.format(billDate, "dd.MM.yyyy"))); // ?? ?

    final Organization supplierOrgInfo = new Organization();
    supplierOrgInfo.setName(//from w ww  .ja  va 2 s  . c om
            "   ?  ? ?");
    supplierOrgInfo.setINN("1655102196");
    supplierOrgInfo.setKPP("165501001");
    final Account account = new Account();
    account.setAccount("40101810800000010001");
    final Bank bank = new Bank();
    bank.setBIK("049205001");
    bank.setName(" ?  . ");
    account.setBank(bank);
    supplierOrgInfo.setAccount(account);
    charge.setSupplierOrgInfo(supplierOrgInfo);
    charge.setBillFor("?   ?");
    charge.setTotalAmount(100000L);
    charge.setChangeStatus(
            "1"); /* ? ? 1 -   2 -   3 -  */
    charge.setTreasureBranch("  ? ?"); //  ,  ?   ? ?? 
    charge.setKBK("19210806000011000110");
    charge.setOKATO("92401000000");

    final BudgetIndex budgetIndex = new BudgetIndex();
    budgetIndex.setStatus("0"); //?  //TODO   ? budgetIndex ? ?       ??  ??? ? ? ??
    budgetIndex.setPaymentType("0"); //  
    budgetIndex.setPurpose("0"); // ?  2 ? ?
    budgetIndex.setTaxPeriod("0"); //    10 ?
    budgetIndex.setTaxDocNumber("0"); //   
    budgetIndex.setTaxDocDate("0"); //   
    charge.setBudgetIndex(budgetIndex);

    charge.setApplicationID("455555"); //TODO ,  ?  ??           ?  20 ?
    charge.setUnifiedPayerIdentifier("0100000000006667775555643"); //    
    return charge;
}