List of usage examples for java.sql Date valueOf
@SuppressWarnings("deprecation") public static Date valueOf(LocalDate date)
From source file:com.company.eleave.leave.rest.ITAnnualBalanceLeaveController.java
@Test public void testAddLeaveForEmployeeSuccessfully() throws Exception { final long overtimeLeaveTypeId = 8; final int leaveDaysAllowed = 6; final int leaveDaysRemaining = 6; final String leaveTypeName = "Overtime"; final Date validityDate = Date.valueOf("2016-12-12"); final AnnualBalanceLeaveDTO newAnnualBalanceLeaveDTO = new AnnualBalanceLeaveDTO(); newAnnualBalanceLeaveDTO.setLeaveDaysAllowed(leaveDaysAllowed); newAnnualBalanceLeaveDTO.setLeaveDaysRemaining(leaveDaysRemaining); newAnnualBalanceLeaveDTO.setLeaveTypeId(overtimeLeaveTypeId); newAnnualBalanceLeaveDTO.setLeaveTypeName(leaveTypeName); newAnnualBalanceLeaveDTO.setValidityDate(validityDate); mockMvc.perform(post(request(RestURI.ANNUAL_BALANCE_LEAVES_BY_EMPLOYEE, EMPLOYEE_ID)) .contentType(TestObjectConverter.APPLICATION_JSON_UTF8) .content(TestObjectConverter.convertObjectToJsonBytes(newAnnualBalanceLeaveDTO))) .andExpect(status().isCreated()).andExpect(header().string("location", "/annualBalanceLeaves/6")); //check if size of annual balance leaves has increased final String contentAsString = mockMvc .perform(get(request(RestURI.ANNUAL_BALANCE_LEAVES_BY_EMPLOYEE, EMPLOYEE_ID))) .andExpect(status().isOk()).andReturn().getResponse().getContentAsString(); List<LinkedHashMap> result = new ObjectMapper().readValue(contentAsString, List.class); Assert.assertEquals(4, result.size()); final LinkedHashMap firstAnnualBalanceLeave = result.stream().filter(map -> ((int) map.get("id") == 6)) .findAny().get();//from w w w. j a va2 s . c om Assert.assertEquals(leaveDaysAllowed, (int) firstAnnualBalanceLeave.get("leaveDaysAllowed")); Assert.assertEquals(leaveDaysRemaining, (int) firstAnnualBalanceLeave.get("leaveDaysRemaining")); Assert.assertEquals(overtimeLeaveTypeId, (int) firstAnnualBalanceLeave.get("leaveTypeId")); Assert.assertEquals(leaveTypeName, firstAnnualBalanceLeave.get("leaveTypeName")); Assert.assertEquals("2016-12-12", firstAnnualBalanceLeave.get("validityDate")); }
From source file:org.silverpeas.core.web.calendar.AbstractCalendarWebController.java
/** * Handles the time window context./*from www .jav a2s . c o m*/ * @param context the context of the incoming request. */ @POST @Path("calendars/context") @Produces(MediaType.APPLICATION_JSON) public <T extends CalendarTimeWindowViewContext> T view(C context) { CalendarViewType calendarViewType = CalendarViewType.from(context.getRequest().getParameter("view")); if (calendarViewType != null) { getCalendarTimeWindowContext().setViewType(calendarViewType); } String listViewMode = context.getRequest().getParameter("listViewMode"); if (isDefined(listViewMode)) { getCalendarTimeWindowContext().setListViewMode(getBooleanValue(listViewMode)); } String timeWindow = context.getRequest().getParameter("timeWindow"); if (StringUtil.isDefined(timeWindow)) { if ("previous".equals(timeWindow)) { getCalendarTimeWindowContext().previous(); } else if ("next".equals(timeWindow)) { getCalendarTimeWindowContext().next(); } else if ("today".equals(timeWindow)) { getCalendarTimeWindowContext().today(); } else if ("referenceDay".equals(timeWindow)) { LocalDate date = LocalDate.parse(context.getRequest().getParameter("timeWindowDate").split("T")[0]); getCalendarTimeWindowContext().setReferenceDay(Date.valueOf(date)); } } return getCalendarTimeWindowContext(); }
From source file:nu.yona.server.batch.jobs.ActivityAggregationBatchJob.java
@Bean(name = "activityAggregationJobWeekActivityReader", destroyMethod = "") @StepScope//from w w w .j a v a 2 s. co m public ItemReader<Long> weekActivityReader() { return intervalActivityIdReader( Date.valueOf(TimeUtil.getStartOfWeek(DEFAULT_TIME_ZONE, ZonedDateTime.now(DEFAULT_TIME_ZONE)) .minusWeeks(1).toLocalDate()), WeekActivity.class, WEEK_ACTIVITY_CHUNK_SIZE); }
From source file:com.antsdb.saltedfish.util.UberUtil.java
@SuppressWarnings("unchecked") public static <T> T toObject(Class<T> klass, Object val) { if (val == null) { return null; }//w w w .j a va 2 s . c om if (klass.isInstance(val)) { return (T) val; } if (val instanceof byte[]) { if (((byte[]) val).length == 0) { return null; } val = new String((byte[]) val, Charsets.UTF_8); } if (klass == String.class) { return (T) String.valueOf(val); } if (val instanceof String) { String text = (String) val; if (klass == String.class) { return (T) text; } if (text.length() == 0) { return null; } if (klass == Integer.class) { return (T) new Integer(text); } else if (klass == Long.class) { return (T) new Long(text); } else if (klass == BigDecimal.class) { return (T) new BigDecimal(text); } else if (klass == Timestamp.class) { return (T) Timestamp.valueOf(text); } else if (klass == Date.class) { return (T) Date.valueOf(text); } else if (klass == Boolean.class) { return (T) new Boolean(text); } else if (klass == Double.class) { return (T) new Double(text); } } if (val instanceof BigDecimal) { if (klass == Long.class) { Long n = ((BigDecimal) val).longValueExact(); return (T) n; } else if (klass == Integer.class) { Integer n = ((BigDecimal) val).intValueExact(); return (T) n; } else if (klass == Double.class) { Double n = ((BigDecimal) val).doubleValue(); return (T) n; } else if (klass == Boolean.class) { Integer n = ((BigDecimal) val).intValueExact(); return (T) (Boolean) (n != 0); } } if (val instanceof Integer) { if (klass == BigDecimal.class) { return (T) BigDecimal.valueOf((Integer) val); } else if (klass == Long.class) { return (T) Long.valueOf((Integer) val); } else if (klass == Boolean.class) { Integer n = (Integer) val; return (T) (Boolean) (n != 0); } } if (val instanceof Long) { if (klass == BigDecimal.class) { return (T) BigDecimal.valueOf((Long) val); } else if (klass == Boolean.class) { Long n = (Long) val; return (T) (Boolean) (n != 0); } } if (val instanceof Boolean) { if (klass == Long.class) { return (T) Long.valueOf((Boolean) val ? 1 : 0); } } throw new IllegalArgumentException("class: " + val.getClass()); }
From source file:com.mapr.db.utils.ImportCSV.java
public void readAndImportCSV(String path, String delimiter) { String dataLine = ""; String[] dataList;/*from ww w . ja va 2s . c o m*/ String data = ""; ArrayList<Object> values = new ArrayList<>(); int countColumnsInData = 0; try { Scanner scan = new Scanner(new FileReader(path)); while (scan.hasNextLine()) { countColumnsInData = 0; dataLine = scan.nextLine().trim(); //System.out.println(dataLine); if (dataLine.endsWith(delimiter)) { dataLine = dataLine.substring(0, dataLine.length() - 1); } dataList = StringUtils.splitPreserveAllTokens(dataLine, delimiter); for (int i = 0; i < dataList.length; i++) { data = dataList[i]; if (data.isEmpty()) { if (valueTypesInSchema.get(i) == "String") { data = "null"; } else { data = "0"; } } switch (valueTypesInSchema.get(i).toLowerCase()) { case "int": case "integer": case "bigint": case "long": values.add(countColumnsInData, Long.valueOf(data)); break; case "float": case "double": values.add(countColumnsInData, Double.valueOf(data)); break; case "date": values.add(countColumnsInData, Date.valueOf(data)); break; default: values.add(countColumnsInData, String.valueOf(data)); break; } //System.out.println("Inserting " + values.get(countColumnsInData) // + " into column " + columnNamesInSchema.get(countColumnsInData)); countColumnsInData++; } insertDocument(values, countColumnsInData, maprdbTable, maprdbTablePath); } scan.close(); } catch (Exception e) { System.out.println("Error importing text:\n\t" + dataLine + "\ninto\n\t" + maprdbTablePath); e.printStackTrace(); System.exit(-1); } }
From source file:cz.fi.muni.pa165.service.layer.service.AlbumServiceImplementationTest.java
@Test public void testUpdateReleaseDate1() { System.out.println("updateDate1"); Date date = Date.valueOf("1991-10-11"); Album brothersInArmsAlbum2 = brothersInArmsAlbum; brothersInArmsAlbum2.setReleaseDate(date); when(albumDao.update(brothersInArmsAlbum)).thenReturn(brothersInArmsAlbum2); Album updatedResult = albumService.updateAlbumReleaseDate(brothersInArmsAlbum, date); assertEquals(date, updatedResult.getReleaseDate()); }
From source file:net.niyonkuru.koodroid.ui.DataDetailFragment.java
private XYMultipleSeriesDataset getBarDataset(Cursor cursor, int x, int maxX) { XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset(); XYSeries series = new XYSeries(null); Calendar cal = Calendar.getInstance(); CalendarUtils.trimTimestamp(cal);/*w ww . j a v a 2 s . co m*/ if (cursor.isClosed() || !cursor.moveToFirst()) return null; while (x <= maxX) { double count = 0; if (!cursor.isAfterLast()) { /* cursor has data */ Date rowDate = new Date(cal.getTimeInMillis()); Date currDate = Date.valueOf(cursor.getString(UsagesQuery.DATE)); if (rowDate.equals(currDate)) { count = cursor.getDouble(UsagesQuery.COUNT); cursor.moveToNext(); } } cal.add(Calendar.DAY_OF_YEAR, -1); series.add(x++, count); } dataset.addSeries(series); return dataset; }
From source file:org.kuali.kra.committee.bo.CommitteeScheduleTest.java
@Test public void testIsActiveFor() { // create two schedules with two different dates. one in November and the other in December CommitteeSchedule novemberSchedule = new CommitteeSchedule(); novemberSchedule.setScheduledDate(Date.valueOf("2011-11-25")); CommitteeSchedule decemberSchedule = new CommitteeSchedule(); decemberSchedule.setScheduledDate(Date.valueOf("2011-12-25")); // create four committee membership mock objects, // one active only for November date, one active for only December date, // one active for both dates, and the last inactive for both dates. CommitteeMembership novemberMember = new CommitteeMembership() { public boolean isActive(Date date) { if (date.equals(Date.valueOf("2011-11-25"))) { return true; } else { return false; }/*from w w w .j a va 2s . c o m*/ } }; novemberMember.setPersonId("novemberPerson"); CommitteeMembership decemberMember = new CommitteeMembership() { public boolean isActive(Date date) { if (date.equals(Date.valueOf("2011-12-25"))) { return true; } else { return false; } } }; decemberMember.setPersonId("decemberPerson"); CommitteeMembership novemberDecemberMember = new CommitteeMembership() { public boolean isActive(Date date) { if ((date.equals(Date.valueOf("2011-12-25"))) || (date.equals(Date.valueOf("2011-11-25")))) { return true; } else { return false; } } }; novemberDecemberMember.setPersonId("novemberDecemberPerson"); CommitteeMembership neitherNovemberNorDecemberMember = new CommitteeMembership() { public boolean isActive(Date date) { if (!(date.equals(Date.valueOf("2011-12-25"))) && !(date.equals(Date.valueOf("2011-11-25")))) { return true; } else { return false; } } }; neitherNovemberNorDecemberMember.setPersonId("neitherNovemberNorDecemberPerson"); // create the committee instance and add the memberships to it Committee committee = new Committee(); committee.getCommitteeMemberships().add(novemberMember); committee.getCommitteeMemberships().add(decemberMember); committee.getCommitteeMemberships().add(novemberDecemberMember); committee.getCommitteeMemberships().add(neitherNovemberNorDecemberMember); // set the committee instance on the two schedules created earlier decemberSchedule.setCommittee(committee); novemberSchedule.setCommittee(committee); assertTrue(novemberSchedule.isActiveFor("novemberPerson")); assertTrue(decemberSchedule.isActiveFor("decemberPerson")); assertFalse(novemberSchedule.isActiveFor("decemberPerson")); assertFalse(decemberSchedule.isActiveFor("novemberPerson")); assertTrue(decemberSchedule.isActiveFor("novemberDecemberPerson")); assertTrue(novemberSchedule.isActiveFor("novemberDecemberPerson")); assertFalse(novemberSchedule.isActiveFor("neitherNovemberNorDecemberPerson")); assertFalse(decemberSchedule.isActiveFor("neitherNovemberNorDecemberPerson")); assertFalse(novemberSchedule.isActiveFor(null)); decemberSchedule.setCommittee(null); assertFalse(decemberSchedule.isActiveFor("decemberPerson")); // restore committee decemberSchedule.setCommittee(committee); assertTrue(decemberSchedule.isActiveFor("decemberPerson")); }
From source file:se.omegapoint.facepalm.infrastructure.JPAUserRepository.java
@Override public void addFriend(final String user, final String friendToAdd) { notBlank(user);//from w w w . ja v a 2 s .c o m notBlank(friendToAdd); eventService.publish(new GenericEvent(format("User[%s] is now friend of [%s]", user, friendToAdd))); entityManager.persist(new Friendship(user, friendToAdd, Date.valueOf(LocalDate.now()))); }
From source file:org.apache.hadoop.hive.ql.io.sarg.ConvertAstToSearchArg.java
private static Object boxLiteral(ExprNodeConstantDesc constantDesc, PredicateLeaf.Type type) { Object lit = constantDesc.getValue(); if (lit == null) { return null; }/* www . j a va 2 s . com*/ switch (type) { case LONG: if (lit instanceof HiveDecimal) { HiveDecimal dec = (HiveDecimal) lit; if (!dec.isLong()) { throw new ArithmeticException("Overflow"); } return dec.longValue(); } return ((Number) lit).longValue(); case STRING: if (lit instanceof HiveChar) { return ((HiveChar) lit).getPaddedValue(); } else if (lit instanceof String) { return lit; } else { return lit.toString(); } case FLOAT: if (lit instanceof HiveDecimal) { // HiveDecimal -> Float -> Number -> Double return ((Number) ((HiveDecimal) lit).floatValue()).doubleValue(); } else { return ((Number) lit).doubleValue(); } case TIMESTAMP: return Timestamp.valueOf(lit.toString()); case DATE: return Date.valueOf(lit.toString()); case DECIMAL: return new HiveDecimalWritable(lit.toString()); case BOOLEAN: return lit; default: throw new IllegalArgumentException("Unknown literal " + type); } }