List of usage examples for org.joda.time LocalDateTime LocalDateTime
public LocalDateTime()
From source file:fr.mycellar.application.user.impl.ResetPasswordRequestServiceImpl.java
License:Open Source License
@Override public ResetPasswordRequest getByKey(String key) { ResetPasswordRequest request = resetPasswordRequestRepository.findUniqueOrNone( // new SearchBuilder<ResetPasswordRequest>() // .on(ResetPasswordRequest_.key).equalsTo(key).build()); return (request != null) && request.getDateTime().isAfter(new LocalDateTime().minusHours(1)) ? request : null;//from ww w . j av a 2 s .c o m }
From source file:fr.mycellar.infrastructure.user.repository.JpaResetPasswordRequestRepository.java
License:Open Source License
@Override public void deleteOldRequests() { getEntityManager()/*from ww w . j ava 2 s .c om*/ .createQuery( "DELETE " + ResetPasswordRequest.class.getSimpleName() + " WHERE dateTime <= :dateTime") .setParameter("dateTime", new LocalDateTime().minusDays(1)).executeUpdate(); }
From source file:fr.mycellar.interfaces.web.security.SecurityContextTokenRepository.java
License:Open Source License
@Override public SecurityContext loadContext(HttpRequestResponseHolder requestResponseHolder) { try {/*from w w w. ja v a2s .c o m*/ Object key = requestResponseHolder.getRequest() .getHeader(SpringSecurityConfiguration.TOKEN_HEADER_NAME); if ((key != null) && (key instanceof String)) { Token token = keyBasedPersistenceTokenService.verifyToken((String) key); if (token != null) { TimedSecurityContext context = securityContexts.get(token); if (context != null) { context.localDateTime = new LocalDateTime(); return context.securityContext; } } } } catch (Exception e) { // return SecurityContextHolder.createEmptyContext(); } return SecurityContextHolder.createEmptyContext(); }
From source file:fr.mycellar.interfaces.web.security.SecurityContextTokenRepository.java
License:Open Source License
@Override public void saveContext(SecurityContext context, HttpServletRequest request, HttpServletResponse response) { Object key = response.getHeader(SpringSecurityConfiguration.TOKEN_HEADER_NAME); if ((key != null) && (key instanceof String)) { securityContexts.put(keyBasedPersistenceTokenService.verifyToken((String) key), new TimedSecurityContext(context, new LocalDateTime())); }/*www .j a va2s .c o m*/ }
From source file:fr.mycellar.interfaces.web.security.SecurityContextTokenRepository.java
License:Open Source License
@Scheduled(fixedRate = 60000) public void cleanRepository() { LocalDateTime expired = new LocalDateTime().minusMinutes(15); for (Iterator<Entry<Token, TimedSecurityContext>> iterator = securityContexts.entrySet() .iterator(); iterator.hasNext();) { Entry<Token, TimedSecurityContext> entry = iterator.next(); if (entry.getValue().localDateTime.isBefore(expired)) { logger.debug("Remove expired token: {}", entry.getKey().getKey()); iterator.remove();/*from w w w. j a v a 2 s .c o m*/ } } }
From source file:github.priyatam.springrest.MockDataHelper.java
public static DrivingHistory createDrivingHistoryFull(String accident) { return new DrivingHistory.Builder().withAnnualMileage(2000).withIsGarageParked(true) .withIsPrimaryOperator(true).withIsAccident(true).withAccidentTime(new LocalDateTime()) .withIsThirdParyOffence(true).build(); }
From source file:gov.nrel.util.Utility.java
public static void justRegister(String tableJSON, String username) { mapper = new ObjectMapper(); boolean isTimeSeries = true; RegisterMessage msg = null;/*from ww w.ja va2 s . co m*/ try { msg = mapper.readValue(tableJSON, RegisterMessage.class); } catch (JsonParseException e) { if (log.isWarnEnabled()) log.warn("There was a problem parsing the JSON request.", e); } catch (JsonMappingException e) { if (log.isWarnEnabled()) log.warn("Your json request appears to be invalid.", e); } catch (IOException e) { if (log.isWarnEnabled()) log.warn("There was an IO error!", e); } // try if (msg != null) { ensureTableDoesNotAlreadyExist(msg); EntityUser user = NoSql.em().find(EntityUser.class, username); List<SecurityGroup> groupsToAddTableTo = fetchGroupsToAddTableTo(msg, user); String postKey = Utility.getUniqueKey(); // Setup the table meta DboTableMeta tm = new DboTableMeta(); tm.setup(msg.getModelName(), "nreldata", false, null); // create new Table here and add to security group as well SecureTable t = new SecureTable(); t.setTableName(msg.getModelName()); t.setDateCreated(new LocalDateTime()); t.setTableMeta(tm); t.setCreator(user); t.setDescription("Please add a description to this table if you are the owner"); NoSql.em().fillInWithKey(t); tm.setForeignKeyToExtensions(t.getId()); setupEachColumn(msg, t, isTimeSeries); NoSqlEntityManager mgr = NoSql.em(); if (log.isInfoEnabled()) log.info("table id = '" + tm.getColumnFamily() + "'"); for (SecurityGroup g : groupsToAddTableTo) { if (log.isInfoEnabled()) log.info("Adding table = '" + t.getTableName() + "' to group = '" + g.getName() + "'"); g.addTable(t); mgr.put(g); } // for mgr.put(tm); mgr.put(t); mgr.flush(); } else { if (log.isWarnEnabled()) log.warn("Your table JSON is null or invalid."); } }
From source file:graphene.util.time.JodaTimeUtil.java
License:Apache License
public static void test_localDateTime() { System.out.println("Test LocalDateTime"); final LocalDateTime ldt1 = new LocalDateTime(); final java.sql.Timestamp ts = toSQLTimestamp(ldt1); final LocalDateTime ldt2 = toLocalDateTime(ts); System.out.println("LocalDateTime 1 = " + ldt1); System.out.println("Timestamp = " + ts); System.out.println("LocalDateTime 2 = " + ldt2); if (!ldt2.equals(ldt1)) { throw new IllegalStateException(); }// w w w. jav a 2s . c om }
From source file:io.autem.SendMessageService.java
License:Open Source License
public void sendMessage(String apiKey, String chromeToken, String from, String textMessage, String contactName) {// www .j a va 2 s . co m try { URL url; HttpURLConnection urlConn; DataOutputStream printout; DataInputStream input; url = new URL("https://android.googleapis.com/gcm/send"); urlConn = (HttpURLConnection) url.openConnection(); urlConn.setDoInput(true); urlConn.setDoOutput(true); urlConn.setUseCaches(false); urlConn.setRequestProperty("Content-Type", "application/json"); urlConn.setRequestProperty("Authorization", "key=" + apiKey); urlConn.setRequestProperty("Host", "android.googleapis.com"); urlConn.setRequestProperty("charset", "utf-8"); urlConn.connect(); // Send POST output. printout = new DataOutputStream(urlConn.getOutputStream()); JSONObject message = new JSONObject(); AutemConversation autemConversation = new AutemConversation(); AutemContact autemContact = new AutemContact(); autemContact.setName(contactName); autemContact.setPhoneNumber(from); autemConversation.setAutemContact(autemContact); AutemTextMessage autemTextMessage = new AutemTextMessage(); autemTextMessage.setMessage(textMessage); autemTextMessage.setTimestamp(new LocalDateTime()); autemTextMessage.setTo("me"); autemTextMessage.setFrom(from); autemConversation.setAutemTextMessage(autemTextMessage); Gson gson = new Gson(); String json = gson.toJson(autemConversation); message.put("message", json); JSONObject dataJSON = new JSONObject(); dataJSON.put("data", message); dataJSON.put("to", chromeToken); dataJSON.put("priority", "high"); // dataJSON.put("time_to_live", 600); set this later. rather have this off for testing Log.i(TAG, dataJSON.toString()); printout.write(dataJSON.toString().getBytes("UTF-8")); printout.flush(); printout.close(); Log.i(TAG, "Sent Message"); int httpResult = urlConn.getResponseCode(); Log.i(TAG, "http code:" + httpResult); } catch (Exception e) { Log.i(TAG, "Error sending message", e); } }
From source file:net.sourceforge.fenixedu.domain.reports.RaidesPhdReportFile.java
License:Open Source License
private String getReportName(final String prefix, final ExecutionYear executionYear) { final StringBuilder result = new StringBuilder(); result.append(new LocalDateTime().toString("yyyyMMddHHmm")); result.append("_").append(prefix).append("_").append(executionYear.getName().replace('/', '_')); return result.toString(); }