List of usage examples for java.sql Date Date
public Date(long date)
From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.action.TraceFileProcessor.java
private void processTraceFile(final File traceFile, final QcContext context) throws IOException { BufferedReader reader = null; try {// w ww . j ava 2 s . c om // find the file id for this file final Long fileInfoId = fileInfoQueries.getFileId(traceFile.getName(), context.getArchive().getId()); if (fileInfoId == null) { context.getArchive().setDeployStatus(Archive.STATUS_IN_REVIEW); context.addError(MessageFormat.format(MessagePropertyType.TRACE_FILE_PROCESSING_ERROR, traceFile.getName(), "File was not found in the database")); return; } // cache barcode ids since they repeat in the files final Map<String, Integer> barcodeIds = new HashMap<String, Integer>(); final Date fileDate = new Date(traceFile.lastModified()); //noinspection IOResourceOpenedButNotSafelyClosed reader = new BufferedReader(new FileReader(traceFile)); String line = reader.readLine(); int lineNum = 1; while (line != null) { processLine(line, lineNum, barcodeIds, traceFile, fileDate, fileInfoId, context); line = reader.readLine(); lineNum++; } //now add biospecimen to file relationship final List<Integer> biospecimenIds = new ArrayList<Integer>(barcodeIds.values()); BiospecimenHelper.insertBiospecimenFileRelationship(biospecimenIds, fileInfoId, bcrDataService, context.getArchive().getTheTumor()); // This is ugly. Created new ticket to update the biosspecimen id to long final List<Long> shippedBiospecimenIds = new ArrayList<Long>(); for (Integer id : biospecimenIds) { shippedBiospecimenIds.add(id.longValue()); } bcrDataService.addShippedBiospecimensFileRelationship(shippedBiospecimenIds, fileInfoId); } finally { IOUtils.closeQuietly(reader); } }
From source file:com.ar.hotwiredautorepairshop.controller.ServiceOrderController.java
@RequestMapping(value = "/serviceOrders/register/newFromComplaint", method = RequestMethod.POST) public ServiceOrder registerServiceOrderFromComplaint( @RequestParam(value = "serviceOrderId") Integer serviceOrderId, @RequestParam(value = "complaintId") Integer complaintId) { ServiceOrder oldServiceOrder = serviceOrderRepository.findOne(serviceOrderId); ServiceOrder newServiceOrder = new ServiceOrder(); java.util.Date utilDate = new java.util.Date(); Date registrationDate = new Date(utilDate.getTime()); newServiceOrder.setRegistrationDate(registrationDate); String customerSSN = oldServiceOrder.getCustomer().getSocialSecurityNumber(); String mechanicSSN = oldServiceOrder.getMechanic().getSocialSecurityNumber(); String licensePlate = oldServiceOrder.getCar().getLicensePlate(); Customer customer = customerRepository.findOne(customerSSN); Mechanic mechanic = mechanicRepository.findOne(mechanicSSN); Car car = carRepository.findOne(licensePlate); if (!mechanic.getCarsInProgress().contains(car)) { mechanic.getCarsInProgress().add(car); }//www. j a v a 2 s. c om Complaint complaint = complaintRepository.findOne(complaintId); complaint.setActive(false); newServiceOrder.setComplaint(complaint); newServiceOrder.setCustomer(customer); newServiceOrder.setCar(car); newServiceOrder.setMechanic(mechanic); Calendar calendar = Calendar.getInstance(); calendar.setTime(registrationDate); calendar.add(Calendar.DATE, 7); Date serviceDate = new Date(calendar.getTimeInMillis()); calendar.setTime(serviceDate); calendar.add(Calendar.DATE, 7); Date pickUpDate = new Date(calendar.getTimeInMillis()); newServiceOrder.setServiceDate(serviceDate); newServiceOrder.setPickupDate(pickUpDate); int totalPrice = 0; for (WorkType workType : complaint.getWorkTypes()) { newServiceOrder.getWorkTypes().add(workType); totalPrice += workType.getPrice(); } newServiceOrder.setTotalPrice(totalPrice); newServiceOrder.setActive(true); serviceOrderRepository.save(newServiceOrder); return newServiceOrder; }
From source file:fr.xebia.demo.ws.employee.EmployeeServiceIntegrationTest.java
@Test(expected = SOAPFaultException.class) public void testPutEmployeeFirstNameTooLong() throws Exception { int id = random.nextInt(); Employee employee = new Employee(); employee.setId(id);/*from www.ja v a 2 s . co m*/ employee.setLastName("Doe-" + id); String firstName = StringUtils.repeat("John ", 100); Assert.assertTrue("firstName must be longer than 256 chars to exceed Schema constraint", firstName.length() > 256); employee.setFirstName(firstName); employee.setGender(Gender.MALE); employee.setBirthdate(new Date(new GregorianCalendar(1976, 01, 05).getTimeInMillis())); try { employeeService.putEmployee(new Holder<Employee>(employee)); } catch (SOAPFaultException e) { e.printStackTrace(); throw e; } /* * throws javax.xml.ws.soap.SOAPFaultException: Marshalling Error: cvc-maxLength-valid: Value '...' with length = '500' is not * facet-valid with respect to maxLength '256' for type '#AnonType_firstNameEmployee'. */ }
From source file:gov.nih.nci.integration.invoker.CaTissueParticipantStrategyTest.java
/** * Tests registerParticipant using the ServiceInvocationStrategy class for the failure scenario * // w ww . jav a2 s. c o m * @throws IntegrationException - IntegrationException * @throws JAXBException - JAXBException */ @SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void registerParticipantFailure() throws IntegrationException, JAXBException { final Date stTime = new Date(new java.util.Date().getTime()); xsltTransformer.transform(null, null, null); EasyMock.expectLastCall().andAnswer(new IAnswer() { public Object answer() { return getSpecimenXMLStr(); } }).anyTimes(); final ServiceInvocationResult clientResult = new ServiceInvocationResult(); clientResult.setDataChanged(false); clientResult.setOriginalData(getSpecimenXMLStr()); final IntegrationException ie = new IntegrationException(IntegrationError._1034, new Throwable( // NOPMD "Participant does not contain the unique identifier SSN"), "Participant does not contain the unique identifier SSN"); clientResult.setInvocationException(ie); EasyMock.expect(caTissueParticipantClient.registerParticipant((String) EasyMock.anyObject())) .andReturn(clientResult); EasyMock.replay(caTissueParticipantClient); final ServiceInvocationMessage serviceInvocationMessage = prepareServiceInvocationMessage(REFMSGID, getSpecimenXMLStr(), stTime, caTissueRegistrationStrategy.getStrategyIdentifier()); final ServiceInvocationResult strategyResult = caTissueRegistrationStrategy .invoke(serviceInvocationMessage); Assert.assertNotNull(strategyResult); }
From source file:com.sap.dirigible.repository.db.dao.DBMapper.java
public static DBFileVersion dbToFileVersion(Connection connection, DBRepository repository, ResultSet resultSet) throws SQLException, DBBaseException, IOException { String path = resultSet.getString("FV_FILE_PATH"); //$NON-NLS-1$ int version = resultSet.getInt("FV_VERSION"); //$NON-NLS-1$ byte[] bytes = dbToDataBinary(connection, resultSet, "FV_CONTENT"); //$NON-NLS-1$ int type = resultSet.getInt("FV_TYPE"); //$NON-NLS-1$ String content = resultSet.getString("FV_CONTENT_TYPE"); //$NON-NLS-1$ String createdBy = resultSet.getString("FV_CREATED_BY"); //$NON-NLS-1$ Date createdAt = new Date(resultSet.getTimestamp("FV_CREATED_AT") //$NON-NLS-1$ .getTime());/*w w w . j a va2s. com*/ DBFileVersion dbFileVersion = new DBFileVersion(repository, (type == OBJECT_TYPE_BINARY), content, version, bytes); dbFileVersion.setPath(path); dbFileVersion.setCreatedBy(createdBy); dbFileVersion.setCreatedAt(createdAt); return dbFileVersion; }
From source file:com.xumpy.thuisadmin.dao.BedragenDaoTest.java
private List<Bedragen> fetchTestBedragen() throws ParseException { List<Bedragen> lstBedragen = new ArrayList<Bedragen>(); GroepenDaoPojo groepNegatief = new GroepenDaoPojo(groepenDao.findOne(2)); GroepenDaoPojo groepPositief = new GroepenDaoPojo(groepenDao.findOne(3)); for (int i = 0; i < 8; i++) { BedragenDaoPojo bedrag = new BedragenDaoPojo(); switch (i) { case 0://from ww w.ja va2 s. co m bedrag.setPk_id(1); bedrag.setBedrag(new BigDecimal(200)); bedrag.setGroep(groepNegatief); bedrag.setDatum(new Date(dt.parse("2015-02-18").getTime())); break; case 1: bedrag.setPk_id(3); bedrag.setBedrag(new BigDecimal(50)); bedrag.setGroep(groepNegatief); bedrag.setDatum(new Date(dt.parse("2015-02-19").getTime())); break; case 2: bedrag.setPk_id(2); bedrag.setBedrag(new BigDecimal(100)); bedrag.setGroep(groepNegatief); bedrag.setDatum(new Date(dt.parse("2015-02-19").getTime())); break; case 3: bedrag.setPk_id(4); bedrag.setBedrag(new BigDecimal(2000)); bedrag.setGroep(groepPositief); bedrag.setDatum(new Date(dt.parse("2015-02-20").getTime())); break; case 4: bedrag.setPk_id(5); bedrag.setBedrag(new BigDecimal(50)); bedrag.setGroep(groepNegatief); bedrag.setDatum(new Date(dt.parse("2015-02-21").getTime())); break; case 5: bedrag.setPk_id(6); bedrag.setBedrag(new BigDecimal(60)); bedrag.setGroep(groepNegatief); bedrag.setDatum(new Date(dt.parse("2015-02-21").getTime())); break; case 6: bedrag.setPk_id(7); bedrag.setBedrag(new BigDecimal(70)); bedrag.setGroep(groepNegatief); bedrag.setDatum(new Date(dt.parse("2015-02-22").getTime())); break; case 7: bedrag.setPk_id(8); bedrag.setBedrag(new BigDecimal(40)); bedrag.setGroep(groepNegatief); bedrag.setDatum(new Date(dt.parse("2015-02-23").getTime())); break; } bedrag.setPersoon(new PersonenDaoPojo(personen)); bedrag.setRekening(new RekeningenDaoPojo(rekening)); bedrag.setOmschrijving("test"); lstBedragen.add(bedrag); } return lstBedragen; }
From source file:org.collectionspace.chain.csp.webui.nuispec.DataGenerator.java
/** * pick a random valid date between the defaults defined * @return//from w w w. ja v a 2s. c om */ private Date randomDate() { BigDecimal retValue = null; BigDecimal length = maxValue.subtract(minValue); BigDecimal factor = new BigDecimal(random.nextDouble()); retValue = length.multiply(factor).add(minValue); return new Date(retValue.toBigInteger().longValue()); }
From source file:org.kawanfw.test.api.client.InsertAndUpdatePrepStatementTest.java
/** * Update the values of a row with an increase factor and a new datetime * //w w w . j ava 2 s .com * @param connection * @param customerId * @param itemId * @throws Exception */ private void updateValues(Connection connection, int customerId, int itemId) throws Exception { String sql = "update orderlog set " + " date_placed = ? " + " , date_shipped = ? " + " , cost_price = ? " + " , is_delivered = ? " + " , quantity = ? " + " where customer_id = ? and item_id = ?"; PreparedStatement prepStatement = connection.prepareStatement(sql); long newTime = (new java.util.Date()).getTime(); Date datePlaced = new Date(newTime); dateShippedUpdated = new Timestamp(newTime); MessageDisplayer.display("dateShippedUpdated : " + dateShippedUpdated); MessageDisplayer .display("dateShippedUpdated.substring.(0, 19): " + dateShippedUpdated.toString().substring(0, 19)); int i = 1; prepStatement.setDate(i++, datePlaced); prepStatement.setTimestamp(i++, dateShippedUpdated); // We use the increase factor prepStatement.setBigDecimal(i++, new BigDecimal(customerId * increaseFactor)); SqlUtil sqlUtil = new SqlUtil(connection); if (sqlUtil.isIngres() || sqlUtil.isPostgreSQL()) { prepStatement.setInt(i++, 1); } else { prepStatement.setBoolean(i++, true); } prepStatement.setInt(i++, customerId * increaseFactor * 2); // Key value prepStatement.setInt(i++, customerId); prepStatement.setInt(i++, itemId); prepStatement.executeUpdate(); prepStatement.close(); }
From source file:com.sciamlab.ckan4j.CKANRating.java
/** * Inserts a rating for the given dataset * /*w w w . j ava 2 s . c o m*/ * @param dataset_id * @param user_id * @param rating * @throws Exception */ public JSONObject postRate(final String dataset_id, final String user_id, final Integer rating) throws Exception { if (rating == null || rating > 5 || rating < 1) throw new Exception("Rating must be in [1,2,3,4,5]"); if (user_id == null || "".equals(user_id)) throw new Exception("User is mandatory"); // //getting dataset info // JSONObject dataset = this.ckan.packageShow(dataset_id); // // Integer rating_count = dataset.opt("rating_count")!=null && !"None".equals(dataset.getString("rating_count")) ? dataset.getInt("rating_count") : new Integer(0); // Double rating_average = dataset.opt("rating_average")!=null && !"None".equals(dataset.getString("rating_average")) ? dataset.getDouble("rating_average") : new Double(0.0); // logger.debug("current count: "+rating_count+" average: "+rating_average); // //converting spatial into string to avoid parsing issue during update // if(dataset.opt("spatial")!=null && !"".equals(dataset.getString("spatial"))){ // JSONObject spatial = new JSONObject(dataset.getString("spatial")); // if(spatial.opt("type")!=null && spatial.opt("coordinates")!=null);{ // dataset.put("spatial", "{ \"type\": \""+spatial.getString("type")+"\", \"coordinates\": "+ spatial.getJSONArray("coordinates") +" }"); // } // } //getting user info // JSONObject user = this.ckan.userShow(user_id); //once checked, then register the rating // final String now_string = SciamlabDateUtils.getCurrentDateAsFormattedString("yyyy-MM-dd hh:mm:ss"); final Date now_string = new Date(new java.util.Date().getTime()); //update rating int sql_result = dao.execUpdate("UPDATE " + this.rating_table + " SET rating = ?, modified = ?" + " WHERE user_id = ? AND package_id = ?;", new ArrayList<Object>() { { add(rating); add(now_string); add(user_id); add(dataset_id); } }); if (sql_result == 0) { logger.debug("No existing rating found for user '" + user_id + "' on dataset '" + dataset_id + "'. Need to create a new one"); //insert new rating sql_result = dao.execUpdate("INSERT INTO " + this.rating_table + " (user_id, package_id, rating, created, modified)" + " VALUES (?, ?, ?, ?, ?);", new ArrayList<Object>() { { add(user_id); add(dataset_id); add(rating); add(now_string); add(now_string); } }); } //calculating the new average Map<String, Properties> map = dao .execQuery("SELECT package_id, count(*) as count, avg(rating) as rating FROM " + this.rating_table + " WHERE package_id = ? GROUP BY package_id", new ArrayList<Object>() { { add(dataset_id); } }, "package_id", new ArrayList<String>() { { add("rating"); add("count"); } }); Properties p = map.get(dataset_id); Double rating_average = Double.parseDouble(p.getProperty("rating")); Integer rating_count = Integer.parseInt(p.getProperty("count")); //getting dataset info JSONObject dataset = this.ckan.packageShow(dataset_id); //converting spatial into string to avoid parsing issue during update if (dataset.opt("spatial") != null && !"".equals(dataset.getString("spatial"))) { JSONObject spatial = new JSONObject(dataset.getString("spatial")); if (spatial.opt("type") != null && spatial.opt("coordinates") != null) ; { dataset.put("spatial", "{ \"type\": \"" + spatial.getString("type") + "\", \"coordinates\": " + spatial.getJSONArray("coordinates") + " }"); } } //updating rating on CKANApiClient dataset.put("rating_average", rating_average); int average_rating_int = this.roundAverageToInteger(rating_average); dataset.put("rating_average_int", average_rating_int); dataset.put("rating_count", rating_count); dataset = this.ckan.packageUpdate(dataset); logger.debug(dataset); logger.info("Rating updated on CKANApiClient: avg " + dataset.get("rating_average") + " count " + dataset.get("rating_count") + " [" + dataset_id + "]"); JSONObject json = new JSONObject(); json.put("dataset", dataset_id); json.put("count", rating_count); json.put("rating", average_rating_int); return json; }
From source file:com.oic.event.RegisterProfile.java
private Date toDate(String date) throws ParseException { Date data;//from w ww . j av a2s . c o m SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); java.util.Date d = format.parse(date); Calendar cal = Calendar.getInstance(); cal.setTime(d); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); data = new Date(cal.getTimeInMillis()); return data; }