List of usage examples for java.sql Date Date
public Date(long date)
From source file:gov.nih.nci.integration.invoker.CaTissueParticipantStrategyTest.java
/** * Tests rollbackRegisterParticipant using the ServiceInvocationStrategy class * //from w w w . ja va2s. c o m * @throws IntegrationException - IntegrationException * @throws JAXBException - JAXBException */ @SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void rollbackRegisterParticipant() 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(); EasyMock.expect(caTissueParticipantClient.deleteParticipant((String) EasyMock.anyObject())) .andReturn(clientResult); EasyMock.replay(caTissueParticipantClient); final ServiceInvocationMessage serviceInvocationMessage = prepareServiceInvocationMessage(REFMSGID, getSpecimenXMLStr(), stTime, caTissueRegistrationStrategy.getStrategyIdentifier()); final ServiceInvocationResult strategyResult = caTissueRegistrationStrategy .rollback(serviceInvocationMessage); Assert.assertNotNull(strategyResult); }
From source file:lp.reminiscens.crawler.FlickrToURL.java
public void parseJSON(String json) { if (!photos.isEmpty()) { photos.clear();//w w w . j a v a 2s . c o m } String id = null; String owner = null; String secret = null; String server = null; String farm = null; String title = null; String taken_date = null; String upload_date = null; String lat = "0"; String lon = "0"; // Double lat = null; // Double lon = null; String tags = ""; try { JSONObject JsonObject = new JSONObject(json); JSONObject Json_photos = JsonObject.getJSONObject("photos"); JSONArray JsonArray_photo = Json_photos.getJSONArray("photo"); JSONObject FlickrPhoto = null; String url = null; Media photo = null; for (int i = 0; i < JsonArray_photo.length(); i++) { FlickrPhoto = JsonArray_photo.getJSONObject(i); id = FlickrPhoto.getString("id"); owner = FlickrPhoto.getString("owner"); secret = FlickrPhoto.getString("secret"); server = FlickrPhoto.getString("server"); farm = FlickrPhoto.getString("farm"); title = FlickrPhoto.getString("title"); lat = FlickrPhoto.getString("latitude"); lon = FlickrPhoto.getString("longitude"); tags = FlickrPhoto.getString("tags"); taken_date = FlickrPhoto.getString("datetaken"); upload_date = FlickrPhoto.getString("dateupload"); Long uploadtime = (Long.parseLong(upload_date) * 1000L); upload_date = (new Date(uploadtime)).toString(); photo = new Media(id, owner, title, secret); photo.setMedia_url(farm, server, id, secret); photo.setLocale("ita"); photo.setTags(tags); Fuzzy_Date startdate = new Fuzzy_Date(); startdate.setSeasonLimits(); startdate.splitDate(taken_date); if (upload_date.equals(taken_date.substring(0, 10))) { startdate.setTimeTrust(false); } startdate.setPhoto(photo); if (startdate.getHour().equalsIgnoreCase(startdate.getMinute()) && startdate.getMinute().equalsIgnoreCase(startdate.getSecond()) && startdate.getSecond().equalsIgnoreCase("00")) { startdate.setHour(null); startdate.setMinute(null); startdate.setSecond(null); startdate.setAccuracy(9); } photo.setTakenDate(startdate); Location location = new Location(); location.setLocale("ita"); location.setLat(lat.toString()); location.setLon(lon.toString()); if (lat.equals("0") && lon.equals("0")) { location.setTextual(FlickrTag); } photo.setLocation(location); location.setPhoto(photo); photos.add(photo); } } catch (JSONException e) { e.printStackTrace(); } }
From source file:org.apache.phoenix.end2end.QueryMoreIT.java
private Map<String, List<String>> createHistoryTableRows(String dataTableName, String[] tenantIds, int numRowsPerTenant) throws Exception { String upsertDML = "UPSERT INTO " + dataTableName + " VALUES (?, ?, ?, ?, ?, ?, ?)"; Connection conn = DriverManager.getConnection(getUrl()); Map<String, List<String>> historyIdsForTenant = new HashMap<String, List<String>>(); try {//from w w w . jav a 2s . c o m PreparedStatement stmt = conn.prepareStatement(upsertDML); for (int j = 0; j < tenantIds.length; j++) { List<String> parentIds = new ArrayList<String>(); for (int i = 0; i < numRowsPerTenant; i++) { stmt.setString(1, tenantIds[j]); stmt.setString(2, rightPad("parentId", 15, 'p')); stmt.setDate(3, new Date(100)); String historyId = rightPad("history" + i, 15, 'h'); stmt.setString(4, historyId); stmt.setString(5, "datatype"); stmt.setString(6, "oldval"); stmt.setString(7, "newval"); stmt.executeUpdate(); parentIds.add(historyId); } historyIdsForTenant.put(tenantIds[j], parentIds); } conn.commit(); return historyIdsForTenant; } finally { conn.close(); } }
From source file:app.order.OrderMetier.java
@Override public void createBill() { makePersistent(order);//from w w w. ja v a 2s . c o m //customer.addOrder(order); if (this.order.getBill() != null) return; this.bill = (Bill) ApplicationContextProvider.getContext().getBean("bill"); this.bill.setOrder(order); this.bill.setCreationDate(new Date(Calendar.getInstance().getTimeInMillis())); this.order.setBill(this.bill); // // billMetier.makePersistent(this.bill); //super.makePersistent(this.order); }
From source file:com.tingtingapps.securesms.MessageDetailsActivity.java
private void updateTime(MessageRecord messageRecord) { if (messageRecord.isPending() || messageRecord.isFailed()) { sentDate.setText("-"); receivedContainer.setVisibility(View.GONE); } else {/*w ww . j a v a 2 s .co m*/ Locale dateLocale = dynamicLanguage.getCurrentLocale(); SimpleDateFormat dateFormatter = DateUtils.getDetailedDateFormatter(this, dateLocale); sentDate.setText(dateFormatter.format(new Date(messageRecord.getDateSent()))); if (messageRecord.getDateReceived() != messageRecord.getDateSent() && !messageRecord.isOutgoing()) { receivedDate.setText(dateFormatter.format(new Date(messageRecord.getDateReceived()))); receivedContainer.setVisibility(View.VISIBLE); } else { receivedContainer.setVisibility(View.GONE); } } }
From source file:gov.nih.nci.integration.caaers.CaAERSParticipantStrategyTest.java
/** * Tests registerParticipant using the ServiceInvocationStrategy class for failure case * // ww w . ja v a2 s. c o m * @throws IntegrationException - IntegrationException * @throws JAXBException - JAXBException * @throws MalformedURLException - MalformedURLException * @throws SOAPFaultException - SOAPFaultException * * */ @SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void registerParticipantFailure() throws IntegrationException, SOAPFaultException, MalformedURLException, 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 getParticipantXMLString(); } }).anyTimes(); final CaaersServiceResponse caaersServiceResponse = getRegisterParticipantResponse(FAILURE); EasyMock.expect(wsClient.createParticipant((String) EasyMock.anyObject())).andReturn(caaersServiceResponse); EasyMock.replay(wsClient); final ServiceInvocationMessage serviceInvocationMessage = prepareServiceInvocationMessage(REFMSGID, getParticipantInterimMessage(), stTime, caAERSRegistrationServiceInvocationStrategy.getStrategyIdentifier()); final ServiceInvocationResult result = caAERSRegistrationServiceInvocationStrategy .invoke(serviceInvocationMessage); Assert.assertNotNull(result); }
From source file:com.facebook.presto.accumulo.model.Row.java
/** * Converts the given String into a Java object based on the given Presto type * * @param str String to convert//from w w w .j a v a 2s . c om * @param type Presto Type * @return Java object * @throws PrestoException If the type is not supported by this function */ public static Object valueFromString(String str, Type type) { if (str == null || str.isEmpty()) { return null; } else if (Types.isArrayType(type)) { Type elementType = Types.getElementType(type); ImmutableList.Builder<Object> listBuilder = ImmutableList.builder(); for (String element : Splitter.on(',').split(str)) { listBuilder.add(valueFromString(element, elementType)); } return AccumuloRowSerializer.getBlockFromArray(elementType, listBuilder.build()); } else if (Types.isMapType(type)) { Type keyType = Types.getKeyType(type); Type valueType = Types.getValueType(type); ImmutableMap.Builder<Object, Object> mapBuilder = ImmutableMap.builder(); for (String element : Splitter.on(',').split(str)) { ImmutableList.Builder<String> builder = ImmutableList.builder(); List<String> keyValue = builder.addAll(Splitter.on("->").split(element)).build(); checkArgument(keyValue.size() == 2, format("Map element %s has %d entries, not 2", element, keyValue.size())); mapBuilder.put(valueFromString(keyValue.get(0), keyType), valueFromString(keyValue.get(1), valueType)); } return AccumuloRowSerializer.getBlockFromMap(type, mapBuilder.build()); } else if (type.equals(BIGINT)) { return Long.parseLong(str); } else if (type.equals(BOOLEAN)) { return Boolean.parseBoolean(str); } else if (type.equals(DATE)) { return new Date(DATE_PARSER.parseDateTime(str).getMillis()); } else if (type.equals(DOUBLE)) { return Double.parseDouble(str); } else if (type.equals(INTEGER)) { return Integer.parseInt(str); } else if (type.equals(REAL)) { return Float.parseFloat(str); } else if (type.equals(SMALLINT)) { return Short.parseShort(str); } else if (type.equals(TIME)) { return new Time(TIME_PARSER.parseDateTime(str).getMillis()); } else if (type.equals(TIMESTAMP)) { return new Timestamp(TIMESTAMP_PARSER.parseDateTime(str).getMillis()); } else if (type.equals(TINYINT)) { return Byte.valueOf(str); } else if (type.equals(VARBINARY)) { return str.getBytes(UTF_8); } else if (type instanceof VarcharType) { return str; } else { throw new PrestoException(NOT_SUPPORTED, "Unsupported type " + type); } }
From source file:eionet.meta.imp.VocabularyImportBaseHandler.java
/** * Utility method to searches concepts (both touched and untouched, and returns found if any, null otherwise). * * @param conceptIdentifier/*from w w w .j a va2 s . c o m*/ * identifier of concept to search for * @return found concept with a flag if it is found in seen concepts */ protected Pair<VocabularyConcept, Boolean> findOrCreateConcept(String conceptIdentifier) { int j = getPositionIn(this.concepts, conceptIdentifier); // concept found if (j < this.concepts.size()) { return new Pair<VocabularyConcept, Boolean>(this.concepts.remove(j), false); } // concept may already created, check it first j = getPositionIn(this.notSeenConceptsYet, conceptIdentifier); if (j < this.notSeenConceptsYet.size()) { return new Pair<VocabularyConcept, Boolean>(this.notSeenConceptsYet.remove(j), false); } j = getPositionIn(this.toBeUpdatedConcepts, conceptIdentifier); // concept found in to be updated concepts if (j < this.toBeUpdatedConcepts.size()) { return new Pair<VocabularyConcept, Boolean>(this.toBeUpdatedConcepts.get(j), true); } if (j == this.toBeUpdatedConcepts.size()) { // if there is already such a concept, ignore that line. if not, add a new concept with params. VocabularyConcept lastFoundConcept = new VocabularyConcept(); lastFoundConcept.setId(--this.numberOfCreatedConcepts); lastFoundConcept.setIdentifier(conceptIdentifier); lastFoundConcept.setStatus(StandardGenericStatus.VALID); lastFoundConcept.setStatusModified(new Date(System.currentTimeMillis())); lastFoundConcept.setAcceptedDate(new Date(System.currentTimeMillis())); List<List<DataElement>> newConceptElementAttributes = new ArrayList<List<DataElement>>(); lastFoundConcept.setElementAttributes(newConceptElementAttributes); return new Pair<VocabularyConcept, Boolean>(lastFoundConcept, false); } return null; }
From source file:com.ar.hotwiredautorepairshop.controller.CustomerController.java
private Integer calculateAge(String socialSecurityNumber) { socialSecurityNumber = socialSecurityNumber.substring(0, 8); java.util.Date dateParsed = new java.util.Date(); try {/* ww w.j a va2 s . com*/ 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:org.kuali.mobility.sakai.service.SakaiForumServiceImpl.java
public ForumTopic findTopic(String topicId, String userId, String topicTitle) { ForumTopic topic = new ForumTopic(); topic.setTitle(topicTitle);//from w w w . j ava 2 s.c om topic.setId(topicId); try { String url = configParamService.findValueByName("Sakai.Url.Base") + "forum_message/topic/" + topicId + ".json"; ResponseEntity<InputStream> is = oncourseOAuthService.oAuthGetRequest(userId, url, "text/html"); String json = IOUtils.toString(is.getBody(), "UTF-8"); JSONObject jsonObj = (JSONObject) JSONSerializer.toJSON(json); JSONArray itemArray = jsonObj.getJSONArray("forum_message_collection"); List<ForumThread> threads = topic.getThreads(); Set<String> unreadMessages = new HashSet<String>(); Map<String, List<String>> messageReplies = new HashMap<String, List<String>>(); for (int i = 0; i < itemArray.size(); i++) { JSONObject message = itemArray.getJSONObject(i); if (message.getInt("indentIndex") == 0) { ForumThread thread = new ForumThread(); thread.setId(message.getString("messageId")); thread.setTopicId(message.getString("topicId")); thread.setCreatedBy(message.getString("authoredBy")); thread.setTitle(message.getString("title")); Date cDate = new Date(message.getLong("createdOn")); DateFormat df = new SimpleDateFormat("MM/dd/yyyy h:mm a"); thread.setCreatedDate(df.format(cDate)); if (!message.getBoolean("read")) { unreadMessages.add(thread.getId()); } threads.add(thread); if (messageReplies.get(thread.getId()) == null) { messageReplies.put(thread.getId(), new ArrayList<String>()); } } else { String replyToId = message.getString("replyTo"); String messageId = message.getString("messageId"); List<String> replyList = messageReplies.get(replyToId); if (replyList == null) { replyList = new ArrayList<String>(); messageReplies.put(replyToId, replyList); } replyList.add(messageId); if (!message.getBoolean("read")) { unreadMessages.add(messageId); } } } computeUnreadCounts(threads, messageReplies, unreadMessages); } catch (Exception e) { LOG.error(e.getMessage(), e); } return topic; }