List of usage examples for java.sql Date Date
public Date(long date)
From source file:com.wavemaker.json.JSONMarshallerTest.java
public void testMapWithAListOfDate() throws Exception { JSONState state = new JSONState(); state.getTypeState().addType(new DateTypeDefinition(Date.class)); Map<String, Object> map = new HashMap<String, Object>(); List<Object> dates = new ArrayList<Object>(); dates.add(new Date(1)); dates.add(new Date(2)); map.put("result", dates); String s = JSONMarshaller.marshal(map, state); assertEquals("{\"result\":[1,2]}", s); }
From source file:org.apache.phoenix.end2end.DateTimeIT.java
@Test public void testDateInList() throws Exception { String query = "SELECT entity_id FROM " + this.tableName + " WHERE a_date IN (?,?) AND a_integer < 4"; PreparedStatement statement = conn.prepareStatement(query); statement.setDate(1, new Date(0)); statement.setDate(2, date);/* www . j av a 2 s.c o m*/ ResultSet rs = statement.executeQuery(); assertTrue(rs.next()); assertEquals(ROW1, rs.getString(1)); assertFalse(rs.next()); }
From source file:it.evilsocket.dsploit.net.http.RequestParser.java
public static ArrayList<BasicClientCookie> parseRawCookie(String rawCookie) { String[] rawCookieParams = rawCookie.split(";"); ArrayList<BasicClientCookie> cookies = new ArrayList<BasicClientCookie>(); for (String rawCookieParam : rawCookieParams) { String[] rawCookieNameAndValue = rawCookieParam.split("="); if (rawCookieNameAndValue.length != 2) continue; String cookieName = rawCookieNameAndValue[0].trim(); String cookieValue = rawCookieNameAndValue[1].trim(); BasicClientCookie cookie = new BasicClientCookie(cookieName, cookieValue); for (int i = 1; i < rawCookieParams.length; i++) { String rawCookieParamNameAndValue[] = rawCookieParams[i].trim().split("="); String paramName = rawCookieParamNameAndValue[0].trim(); if (paramName.equalsIgnoreCase("secure")) cookie.setSecure(true);/*from w ww. j av a2 s .co m*/ else { // attribute not a flag or missing value. if (rawCookieParamNameAndValue.length == 2) { String paramValue = rawCookieParamNameAndValue[1].trim(); if (paramName.equalsIgnoreCase("max-age")) { long maxAge = Long.parseLong(paramValue); Date expiryDate = new Date(java.lang.System.currentTimeMillis() + maxAge); cookie.setExpiryDate(expiryDate); } else if (paramName.equalsIgnoreCase("domain")) cookie.setDomain(paramValue); else if (paramName.equalsIgnoreCase("path")) cookie.setPath(paramValue); else if (paramName.equalsIgnoreCase("comment")) cookie.setComment(paramValue); } } } cookies.add(cookie); } return cookies; }
From source file:eionet.meta.dao.mysql.VocabularyConceptDAOImpl.java
/** * {@inheritDoc}//from w w w . java 2 s . co m */ @Override public void insertEmptyConcepts(int vocabularyFolderId, int amount, int identifier, String label, String definition) { StringBuilder sql = new StringBuilder(); sql.append( "insert into VOCABULARY_CONCEPT (VOCABULARY_ID, IDENTIFIER, LABEL, DEFINITION, NOTATION, STATUS, "); sql.append("NOT_ACCEPTED_DATE, STATUS_MODIFIED) "); sql.append("values (:vocabularyFolderId, :identifier, :label, :definition, :notation, :status, "); sql.append(":notAcceptedDate, :statusModified)"); @SuppressWarnings("unchecked") Map<String, Object>[] batchValues = new HashMap[amount]; for (int i = 0; i < batchValues.length; i++) { Map<String, Object> params = new HashMap<String, Object>(); params.put("vocabularyFolderId", vocabularyFolderId); params.put("identifier", Integer.toString(identifier)); params.put("label", label); params.put("definition", definition); params.put("notation", Integer.toString(identifier)); params.put("status", StandardGenericStatus.INVALID.getValue()); Date now = new Date(System.currentTimeMillis()); params.put("notAcceptedDate", now); params.put("statusModified", now); identifier++; batchValues[i] = params; } getNamedParameterJdbcTemplate().batchUpdate(sql.toString(), batchValues); }
From source file:com.ar.hotwiredautorepairshop.beans.MainBean.java
public Integer calculateAge(String socialSecurityNumber) { socialSecurityNumber = socialSecurityNumber.substring(0, 8); java.util.Date dateParsed = new java.util.Date(); try {//from www .ja v a2 s. c o m dateParsed = new SimpleDateFormat("yyyyMMdd").parse(socialSecurityNumber); } catch (ParseException e) { } Date customerDate = new Date(dateParsed.getTime()); Calendar dateOfBirth = Calendar.getInstance(); dateOfBirth.setTime(customerDate); Calendar today = Calendar.getInstance(); int age = today.get(Calendar.YEAR) - dateOfBirth.get(Calendar.YEAR); if (today.get(Calendar.MONTH) < dateOfBirth.get(Calendar.MONTH)) { age--; } else if (today.get(Calendar.MONTH) == dateOfBirth.get(Calendar.MONTH) && today.get(Calendar.DAY_OF_MONTH) < dateOfBirth.get(Calendar.DAY_OF_MONTH)) { age--; } return age; }
From source file:eionet.meta.service.RDFVocabularyImportServiceTest.java
/** * In this test, two concepts RDF is imported. Concepts have updated values. * * @throws Exception/* w w w.j a v a 2 s .c om*/ */ @Test @Rollback public void testIfConceptsAndElementsUpdatedAfterPurge() throws Exception { // get vocabulary folder VocabularyFolder vocabularyFolder = vocabularyService.getVocabularyFolder(TEST_VALID_VOCABULARY_ID); // get initial values of concepts with attributes List<VocabularyConcept> concepts = getVocabularyConceptsWithAttributes(vocabularyFolder); // get reader for RDF file Reader reader = getReaderFromResource("rdf_import/rdf_import_test_2.rdf"); // import RDF into database vocabularyImportService.importRdfIntoVocabulary(reader, vocabularyFolder, true, false); Assert.assertFalse("Transaction rolled back (unexpected)", transactionManager.getTransaction(null).isRollbackOnly()); // manually update initial values of concepts for comparison VocabularyConcept vc8 = findVocabularyConceptById(concepts, 8); vc8.setStatus(StandardGenericStatus.VALID); vc8.setAcceptedDate(new Date(System.currentTimeMillis())); vc8.setStatusModified(new Date(System.currentTimeMillis())); vc8.setDefinition("rdf_test_concept_def_1_updated"); List<List<DataElement>> dataElements = vc8.getElementAttributes(); List<DataElement> elems = null; elems = VocabularyImportBaseHandler.getDataElementValuesByNameAndLang("skos:prefLabel", "bg", dataElements); DataElement element = findDataElemByAttrValue(elems, "bg2_rdf_test_concept_1"); element.setAttributeValue("bg2_rdf_test_concept_1_updated"); elems = VocabularyImportBaseHandler.getDataElementValuesByNameAndLang("skos:prefLabel", "en", dataElements); element = findDataElemByAttrValue(elems, "en_rdf_test_concept_1"); element.setAttributeValue("en_rdf_test_concept_1_updated"); elems = VocabularyImportBaseHandler.getDataElementValuesByName("skos:broader", dataElements); element = elems.get(0); element.setRelatedConceptLabel(null); element.setRelatedConceptId(null); element.setRelatedConceptIdentifier(null); element.setRelatedConceptVocSet(null); element.setRelatedConceptBaseURI(null); element.setRelatedConceptVocabulary(null); element.setAttributeValue(VocabularyFolder.getBaseUri(vocabularyFolder) + "rdf_test_concept_2"); // the rdf contains a triple [concept1 skos:related concetp3] but no vice versa. // Both relations will be created if RDF has such error? elems = new ArrayList<DataElement>(); dataElements.add(elems); Map<String, List<String>> elemAttrValues = new HashMap<String, List<String>>(); List<String> aValues = new ArrayList<String>(); aValues.add("localref"); elemAttrValues.put("Datatype", aValues); element = new DataElement(); element.setIdentifier("skos:related"); element.setId(7); element.setRelatedConceptLabel("rdf_test_concept_label_3_updated"); element.setRelatedConceptId(null); element.setRelatedConceptIdentifier("rdf_test_concept_3"); element.setRelatedConceptVocSet("rdf_header_vs"); element.setRelatedConceptBaseURI( "http://127.0.0.1:8080/datadict/vocabulary/rdf_header_vs/rdf_header_vocab/"); element.setRelatedConceptVocabulary("rdf_header_vocab"); element.setAttributeValue(null); element.setElemAttributeValues(elemAttrValues); elems.add(element); VocabularyConcept vc10 = findVocabularyConceptById(concepts, 10); vc10.setLabel("rdf_test_concept_label_3_updated"); vc10.setDefinition("rdf_test_concept_def_3_updated"); vc10.setStatus(StandardGenericStatus.VALID); vc10.setAcceptedDate(new Date(System.currentTimeMillis())); vc10.setStatusModified(new Date(System.currentTimeMillis())); dataElements = vc10.getElementAttributes(); elems = VocabularyImportBaseHandler.getDataElementValuesByNameAndLang("skos:prefLabel", "bg", dataElements); element = findDataElemByAttrValue(elems, "bg_rdf_test_concept_3"); element.setAttributeValue("bg_rdf_test_concept_3_updated"); elems = VocabularyImportBaseHandler.getDataElementValuesByNameAndLang("skos:definition", "pl", dataElements); element = findDataElemByAttrValue(elems, "pl_rdf_test_concept_3"); element.setAttributeValue("pl_rdf_test_concept_3_updated"); elems = VocabularyImportBaseHandler.getDataElementValuesByName("skos:related", dataElements); element = elems.get(0); element.setRelatedConceptLabel(null); element.setRelatedConceptId(null); element.setRelatedConceptIdentifier(null); element.setRelatedConceptVocSet(null); element.setRelatedConceptBaseURI(null); element.setRelatedConceptVocabulary(null); element.setAttributeValue(VocabularyFolder.getBaseUri(vocabularyFolder) + "rdf_test_concept_2"); element = new DataElement(); element.setIdentifier("skos:related"); element.setId(7); element.setElemAttributeValues(elemAttrValues); element.setElemAttributeValues(elemAttrValues); element.setRelatedConceptLabel("rdf_test_concept_label_1_lets_get_sure"); element.setRelatedConceptId(null); element.setRelatedConceptIdentifier("rdf_test_concept_1"); element.setRelatedConceptVocSet("rdf_header_vs"); element.setRelatedConceptBaseURI( "http://127.0.0.1:8080/datadict/vocabulary/rdf_header_vs/rdf_header_vocab/"); element.setRelatedConceptVocabulary("rdf_header_vocab"); element.setAttributeValue(null); elems.add(element); // get updated values of concepts with attributes List<VocabularyConcept> updatedConcepts = getVocabularyConceptsWithAttributes(vocabularyFolder); Assert.assertEquals("Updated Concepts does not include 2 vocabulary concepts", updatedConcepts.size(), 2); VocabularyConcept vc8Updated = findVocabularyConceptByIdentifier(updatedConcepts, vc8.getIdentifier()); VocabularyConcept vc10Updated = findVocabularyConceptByIdentifier(updatedConcepts, vc10.getIdentifier()); vc8.setId(vc8Updated.getId()); dataElements = vc8.getElementAttributes(); elems = VocabularyImportBaseHandler.getDataElementValuesByName("skos:related", dataElements); elems.get(0).setRelatedConceptId(vc10Updated.getId()); dataElements = vc10.getElementAttributes(); elems = VocabularyImportBaseHandler.getDataElementValuesByName("skos:related", dataElements); elems.get(1).setRelatedConceptId(vc8Updated.getId()); vc10.setId(vc10Updated.getId()); concepts = new ArrayList<VocabularyConcept>(); concepts.add(vc8); concepts.add(vc10); // compare manually updated objects with queried ones (after import operation) ReflectionAssert.assertReflectionEquals(concepts, updatedConcepts, ReflectionComparatorMode.LENIENT_DATES, ReflectionComparatorMode.LENIENT_ORDER); }
From source file:adalid.commons.util.TimeUtils.java
public static java.util.Date parse(String pdq) { if (StringUtils.isBlank(pdq)) { return null; }/*from w ww . j a va 2 s . co m*/ String string = pdq.trim(); ParsePosition position = new ParsePosition(0); java.util.Date util = timestampFormatter().parse(string, position); int i = position.getIndex(); int l = string.length(); if (util != null && i == l) { return new Timestamp(util.getTime()); } position.setIndex(0); util = dateFormatter().parse(string, position); i = position.getIndex(); if (util != null) { if (i == l) { return new Date(util.getTime()); } java.util.Date time = timeFormatter().parse(string, position); i = position.getIndex(); if (time != null && i == l) { return merge(util, time); } } position.setIndex(0); util = timeFormatter().parse(string, position); i = position.getIndex(); if (util != null && i == l) { return new Time(util.getTime()); } return null; }
From source file:org.kuali.coeus.common.budget.impl.period.BudgetPeriodRule.java
private String compareDate(Budget budget, Date periodStartDate, Date periodEndDate, Date previousPeriodEndDate) { String returnErrorValue = null; LOG.info("prd st dt " + periodStartDate.getTime() + periodEndDate.getTime() + budget.getStartDate().getTime() + budget.getEndDate().getTime()); Date budgetEndDate = new Date(budget.getBudgetEndDate().getTime()); Date budgetStartDate = new Date(budget.getBudgetStartDate().getTime()); if (periodStartDate.after(budgetEndDate)) { LOG.info("ERROR_PERIOD_START_AFTER_PROJECT_END" + periodStartDate + budget.getEndDate()); returnErrorValue = "ERROR_PERIOD_START_AFTER_PROJECT_END"; } else if (periodStartDate.before(budgetStartDate)) { LOG.info("ERROR_PERIOD_START_BEFORE_PROJECT_START" + periodStartDate + budget.getStartDate()); returnErrorValue = "ERROR_PERIOD_START_BEFORE_PROJECT_START"; } else if (periodEndDate.before(budget.getStartDate())) { LOG.info("ERROR_PERIOD_END_BEFORE_PROJECT_START" + periodEndDate + budget.getStartDate()); returnErrorValue = "ERROR_PERIOD_END_BEFORE_PROJECT_START"; } else if (periodEndDate.after(budgetEndDate)) { LOG.info("ERROR_PERIOD_END_AFTER_PROJECT_END" + periodEndDate + budget.getEndDate()); returnErrorValue = "ERROR_PERIOD_END_AFTER_PROJECT_END"; } else if (periodStartDate.after(periodEndDate)) { LOG.info("ERROR_PERIOD_START_AFTER_PERIOD_END" + periodStartDate + periodEndDate); returnErrorValue = "ERROR_PERIOD_START_AFTER_PERIOD_END"; } else if (previousPeriodEndDate != null && !periodStartDate.after(previousPeriodEndDate)) { LOG.info("ERROR_PERIOD_START_BEFORE_PREVIOUS_END" + previousPeriodEndDate + periodStartDate); returnErrorValue = "ERROR_PERIOD_START_BEFORE_PREVIOUS_END"; } else if (previousPeriodEndDate != null && !periodEndDate.after(previousPeriodEndDate)) { LOG.info("ERROR_PERIOD_END_BEFORE_PREVIOUS_END" + previousPeriodEndDate + periodEndDate); returnErrorValue = "ERROR_PERIOD_END_BEFORE_PREVIOUS_END"; }//from ww w . ja v a 2 s .c o m return returnErrorValue; }
From source file:com.zimbra.qa.unittest.TestImap.java
@Test public void testOverflowNotAppend() throws Exception { int oldReadTimeout = connection.getConfig().getReadTimeout(); try {//from w ww . ja v a 2 s . com connection.setReadTimeout(10); Flags flags = Flags.fromSpec("afs"); Date date = new Date(System.currentTimeMillis()); ImapRequest req = connection.newRequest(CAtom.FETCH, "1:*"); req.addParam("{" + ((long) (Integer.MAX_VALUE) + 1) + "+}"); ImapResponse resp = req.send(); assertTrue(resp.isNO() || resp.isBAD()); } finally { connection.setReadTimeout(oldReadTimeout); } }
From source file:edu.arizona.kra.institutionalproposal.negotiationlog.service.NegotiationLogMigrationServiceImpl.java
/** * Creates the first and only activity that will encompass all that happened in the negotiation log * @param negotiation//from w w w . j a v a 2 s . c o m * @param negotiationLog * @return */ private NegotiationActivity createNegotiationActivity(Negotiation negotiation, NegotiationLog negotiationLog) { LOG.debug("Start createNegotiationActivity"); NegotiationActivity activity = new NegotiationActivity(); NegotiationActivityType activityType = findNegotiationTypeByCode(NegotiationActivityType.class, DEFAULT_ACTIVITY_CODE, DEFAULT_ACTIVITY_CODE); activity.setActivityType(activityType); activity.setActivityTypeId(activity.getActivityType().getId()); activity.setLocation(findActivityLocation(negotiationLog)); activity.setLocationId(activity.getLocation().getId()); activity.setDescription(buildActivityDescription(negotiationLog)); //activity cannot start before the negotiation started, make sure they are in sync. activity.setStartDate(negotiationLog.getNegotiationStart()); if (negotiationLog.getNegotiationStart() == null) { activity.setStartDate(negotiation.getNegotiationStartDate()); } else if (negotiation.getNegotiationStartDate().after(negotiationLog.getNegotiationStart())) { activity.setStartDate(negotiation.getNegotiationStartDate()); } activity.setCreateDate(activity.getStartDate()); if (negotiationLog.getClosed()) { //activity cannot end after the negotiation ended, make sure they are in sync. activity.setEndDate(negotiation.getNegotiationEndDate()); } activity.setLastModifiedUsername(GlobalVariables.getUserSession().getPrincipalName()); activity.setLastModifiedDate( activity.getEndDate() != null ? activity.getEndDate() : new Date(System.currentTimeMillis())); activity.setRestricted(false); negotiation.getActivities().add(activity); LOG.debug("Finished createNegotiationActivity log=" + negotiationLog.getNegotiationLogId() + " SD=" + activity.getStartDate() + " ED=" + activity.getEndDate() + " User=" + activity.getLastModifiedUsername()); return null; }