List of usage examples for org.joda.time DateTime DateTime
public DateTime(Object instant, Chronology chronology)
From source file:AgeCalculator.java
License:Apache License
private void updateResults() { try {// w w w .j a va2 s . com DateTime dt = new DateTime(iBirthdateStr.trim(), iChronology); long minuend = System.currentTimeMillis(); long subtrahend = dt.getMillis(); for (int i = 0; i < iFieldSets.length; i++) { iFieldSets[i].updateResults(minuend, subtrahend); } } catch (IllegalArgumentException e) { for (int i = 0; i < iFieldSets.length; i++) { iFieldSets[i].setResultsText(""); } } }
From source file:aaf.vhr.idp.http.VhrRemoteUserAuthServlet.java
License:Open Source License
/** {@inheritDoc} */ @Override/*from w w w .j av a2s. c o m*/ protected void service(final HttpServletRequest httpRequest, final HttpServletResponse httpResponse) throws ServletException, IOException { try { // key to ExternalAuthentication session String key = null; boolean isVhrReturn = false; boolean isForceAuthn = false; DateTime authnStart = null; // when this authentication started at the IdP // array to use as return parameter when calling VhrSessionValidator DateTime authnInstantArr[] = new DateTime[1]; if (httpRequest.getParameter(REDIRECT_REQ_PARAM_NAME) != null) { // we have come back from the VHR isVhrReturn = true; key = httpRequest.getParameter(REDIRECT_REQ_PARAM_NAME); HttpSession hs = httpRequest.getSession(); if (hs != null && hs.getAttribute(AUTHN_INIT_INSTANT_ATTR_NAME + key) != null) { authnStart = (DateTime) hs.getAttribute(AUTHN_INIT_INSTANT_ATTR_NAME + key); // remove the attribute from the session so that we do not attempt to reuse it... hs.removeAttribute(AUTHN_INIT_INSTANT_ATTR_NAME); } ; if (hs != null && hs.getAttribute(IS_FORCE_AUTHN_ATTR_NAME + key) != null) { isForceAuthn = ((Boolean) hs.getAttribute(IS_FORCE_AUTHN_ATTR_NAME + key)).booleanValue(); // remove the attribute from the session so that we do not attempt to reuse it... hs.removeAttribute(AUTHN_INIT_INSTANT_ATTR_NAME); } ; } else { // starting a new SSO request key = ExternalAuthentication.startExternalAuthentication(httpRequest); // check if forceAuthn is set Object forceAuthnAttr = httpRequest.getAttribute(ExternalAuthentication.FORCE_AUTHN_PARAM); if (forceAuthnAttr != null && forceAuthnAttr instanceof java.lang.Boolean) { log.debug("Loading foceAuthn value"); isForceAuthn = ((Boolean) forceAuthnAttr).booleanValue(); } // check if we can see when authentication was initiated final AuthenticationContext authCtx = ExternalAuthentication .getProfileRequestContext(key, httpRequest) .getSubcontext(AuthenticationContext.class, false); if (authCtx != null) { log.debug("Authentication initiation is {}", authCtx.getInitiationInstant()); authnStart = new DateTime(authCtx.getInitiationInstant(), DateTimeZone.UTC); log.debug("AuthnStart is {}", authnStart); } ; } ; log.debug("forceAuthn is {}, authnStart is {}", isForceAuthn, authnStart); if (key == null) { log.error("No ExternalAuthentication sesssion key found"); throw new ServletException("No ExternalAuthentication sesssion key found"); } ; // we now have a key - either: // * we started new authentication // * or we have returned from VHR and loaded the key from the HttpSession String username = null; // We may have a cookie - either as part of return or from previous session // Attempt to locate VHR SessionID String vhrSessionID = null; Cookie[] cookies = httpRequest.getCookies(); for (Cookie cookie : cookies) { if (cookie.getName().equals(SSO_COOKIE_NAME)) { vhrSessionID = cookie.getValue(); break; } } if (vhrSessionID != null) { log.info("Found vhrSessionID from {}. Establishing validity.", httpRequest.getRemoteHost()); username = vhrSessionValidator.validateSession(vhrSessionID, (isForceAuthn ? authnStart : null), authnInstantArr); } ; // If we do not have a username yet (no Vhr session cookie or did not validate), // we redirect to VHR - but only if we are not returning from the VHR // Reason: (i) we do not want to loop and (ii) we do not have the full context otherwise initialized by // ExternalAuthentication.startExternalAuthentication() if (username == null && !isVhrReturn) { URLCodec codec = new URLCodec(); String relyingParty = (String) httpRequest.getAttribute("relyingParty"); String serviceName = ""; log.info("No vhrSessionID found from {}. Directing to VHR authentication process.", httpRequest.getRemoteHost()); log.debug("Relying party which initiated the SSO request was: {}", relyingParty); // try getting a RelyingPartyUIContext // we should pass on the request for consent revocation final ProfileRequestContext prc = ExternalAuthentication.getProfileRequestContext(key, httpRequest); final RelyingPartyUIContext rpuiCtx = prc.getSubcontext(AuthenticationContext.class, true) .getSubcontext(RelyingPartyUIContext.class, false); if (rpuiCtx != null) { serviceName = rpuiCtx.getServiceName(); log.debug("RelyingPartyUIContext received, ServiceName is {}", serviceName); } ; // save session *key* HttpSession hs = httpRequest.getSession(true); hs.setAttribute(IS_FORCE_AUTHN_ATTR_NAME + key, new Boolean(isForceAuthn)); hs.setAttribute(AUTHN_INIT_INSTANT_ATTR_NAME + key, authnStart); try { httpResponse.sendRedirect(String.format(vhrLoginEndpoint, codec.encode(httpRequest.getRequestURL().toString() + "?" + REDIRECT_REQ_PARAM_NAME + "=" + codec.encode(key)), codec.encode(relyingParty), codec.encode(serviceName))); } catch (EncoderException e) { log.error("Could not encode VHR redirect params"); throw new IOException(e); } return; // we issued a redirect - return now } ; if (username == null) { log.warn("VirtualHome authentication failed: no username received"); httpRequest.setAttribute(ExternalAuthentication.AUTHENTICATION_ERROR_KEY, "VirtualHome authentication failed: no username received"); ExternalAuthentication.finishExternalAuthentication(key, httpRequest, httpResponse); return; } // check if consent revocation was requested String consentRevocationParam = httpRequest.getParameter(consentRevocationParamName); if (consentRevocationParam != null) { // we should pass on the request for consent revocation final ProfileRequestContext prc = ExternalAuthentication.getProfileRequestContext(key, httpRequest); final ConsentManagementContext consentCtx = prc.getSubcontext(ConsentManagementContext.class, true); log.debug("Consent revocation request received, setting revokeConsent in consentCtx"); consentCtx.setRevokeConsent(consentRevocationParam.equalsIgnoreCase("true")); } ; // Set authnInstant to timestamp returned by VHR if (authnInstantArr[0] != null) { log.debug("Response from VHR includes authenticationInstant time {}, passing this back to IdP", authnInstantArr[0]); httpRequest.setAttribute(ExternalAuthentication.AUTHENTICATION_INSTANT_KEY, authnInstantArr[0]); } ; httpRequest.setAttribute(ExternalAuthentication.PRINCIPAL_NAME_KEY, username); ExternalAuthentication.finishExternalAuthentication(key, httpRequest, httpResponse); } catch (final ExternalAuthenticationException e) { throw new ServletException("Error processing external authentication request", e); } }
From source file:be.fedict.eid.applet.service.signer.ooxml.OOXMLSignatureFacet.java
License:Open Source License
private void addSignatureTime(XMLSignatureFactory signatureFactory, Document document, String signatureId, List<XMLStructure> objectContent) { /*//www . j a v a 2 s. c o m * SignatureTime */ Element signatureTimeElement = document.createElementNS(OOXML_DIGSIG_NS, "mdssi:SignatureTime"); signatureTimeElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:mdssi", OOXML_DIGSIG_NS); Element formatElement = document.createElementNS(OOXML_DIGSIG_NS, "mdssi:Format"); formatElement.setTextContent("YYYY-MM-DDThh:mm:ssTZD"); signatureTimeElement.appendChild(formatElement); Element valueElement = document.createElementNS(OOXML_DIGSIG_NS, "mdssi:Value"); Date now = this.clock.getTime(); DateTime dateTime = new DateTime(now.getTime(), DateTimeZone.UTC); DateTimeFormatter fmt = ISODateTimeFormat.dateTimeNoMillis(); String nowStr = fmt.print(dateTime); LOG.debug("now: " + nowStr); valueElement.setTextContent(nowStr); signatureTimeElement.appendChild(valueElement); List<XMLStructure> signatureTimeContent = new LinkedList<XMLStructure>(); signatureTimeContent.add(new DOMStructure(signatureTimeElement)); SignatureProperty signatureTimeSignatureProperty = signatureFactory .newSignatureProperty(signatureTimeContent, "#" + signatureId, "idSignatureTime"); List<SignatureProperty> signaturePropertyContent = new LinkedList<SignatureProperty>(); signaturePropertyContent.add(signatureTimeSignatureProperty); SignatureProperties signatureProperties = signatureFactory.newSignatureProperties(signaturePropertyContent, "id-signature-time-" + UUID.randomUUID().toString()); objectContent.add(signatureProperties); }
From source file:be.fedict.eid.dss.model.bean.DocumentServiceBean.java
License:Open Source License
private boolean isExpired(DocumentEntity document) { return new DateTime(document.getExpiration(), ISOChronology.getInstanceUTC()).isBeforeNow(); }
From source file:br.edu.utfpr.cm.JGitMinerWeb.services.metric.auxiliary.AuxCoChangeMetrics.java
public AuxCoChangeMetrics(AuxPairOfFiles auxCoChanged, GenericDao dao) { this.pullRequest = AuxPullRequest.getPullRequestByID(dao, auxCoChanged.getIdPullRequest()); this.auxPairOfFiles = auxCoChanged; this.repositoryCommitFile1 = AuxRepositoryCommit.getRepositoryCommitBySha(dao, this.auxPairOfFiles.getshaCommitFile1()); this.repositoryCommitFile2 = AuxRepositoryCommit.getRepositoryCommitBySha(dao, this.auxPairOfFiles.getshaCommitFile2()); //List<EntityRepositoryCommit> list = Lists.newArrayList(pullRequest.getRepositoryCommits()); this.dateFile1 = new DateTime(repositoryCommitFile1.getCommit().getAuthor().getDateCommitUser(), DateTimeZone.UTC);/*from w w w. j a v a 2 s . co m*/ this.dateFile2 = new DateTime(repositoryCommitFile2.getCommit().getAuthor().getDateCommitUser(), DateTimeZone.UTC); }
From source file:br.edu.utfpr.cm.JGitMinerWeb.services.metric.auxiliary.AuxTime.java
public AuxTime(AuxPairOfFiles auxCoChanged, GenericDao dao) { this.pullRequest = AuxPullRequest.getPullRequestByID(dao, auxCoChanged.getIdPullRequest()); this.auxPairOfFiles = auxCoChanged; this.repositoryCommitFile1 = AuxRepositoryCommit.getRepositoryCommitBySha(dao, this.auxPairOfFiles.getshaCommitFile1()); this.repositoryCommitFile2 = AuxRepositoryCommit.getRepositoryCommitBySha(dao, this.auxPairOfFiles.getshaCommitFile2()); this.dateFile1 = new DateTime(repositoryCommitFile1.getCommit().getCommitter().getDateCommitUser(), DateTimeZone.UTC);//from ww w.jav a2 s. c om this.dateFile2 = new DateTime(repositoryCommitFile2.getCommit().getCommitter().getDateCommitUser(), DateTimeZone.UTC); }
From source file:br.edu.utfpr.cm.JGitMinerWeb.services.metric.social.TimeMetric.java
public void calculateMetric(AuxAllMetrics pairOfFile, DateTime being, DateTime end) { List<AuxCountTimeMetrics> timeMetricsList = new ArrayList<>(); // if (result.containsKey(pairOfFiles.getAuxPairOfFiles())) { // timeMetricsList = result.get(pairOfFiles.getAuxPairOfFiles()); // } else { // timeMetricsList = new ArrayList<>(); // }//from w w w . j a va 2s .c om PeriodOfDayCount periodOfDayCount = new PeriodOfDayCount(); DayOfWeekCount dayOfWeekCount = new DayOfWeekCount(); DayOfMonthCount dayOfMonthCount = new DayOfMonthCount(); MonthCount monthCount = new MonthCount(); // if (isBetweenDate(pairOfFiles.getDateFile1(), being, end)) { if (!pairOfFile.getRepoCommits_idList().isEmpty()) { for (EntityRepositoryCommit repoCommit : pairOfFile.getRepoCommits()) { DateTime repoCommitDate = new DateTime(repoCommit.getCommit().getAuthor().getDateCommitUser(), DateTimeZone.UTC); if (isBetweenDate(repoCommitDate, being, end)) { periodOfDayCount.countPeriodOfDay(getPeriodOfDay(repoCommitDate)); dayOfWeekCount.countDayOfWeek(repoCommitDate.getDayOfWeek()); dayOfMonthCount.countDayOfMonth(repoCommitDate.getDayOfMonth()); monthCount.countMonth(repoCommitDate.getMonthOfYear()); } } } // periodOfDayCount.countPeriodOfDay(pairOfFiles.getPedriodOfDayFile1()); // dayOfWeekCount.countDayOfWeek(pairOfFiles.getDayOfWeekFile1()); // dayOfMonthCount.countDayOfMonth(pairOfFiles.getDayOfMonthFile1()); // monthCount.countMonth(pairOfFiles.getMonthOfModFile1()); AuxCountTimeMetrics timeMetrics = new AuxCountTimeMetrics(periodOfDayCount, dayOfWeekCount, dayOfMonthCount, monthCount); timeMetricsList.add(timeMetrics); // } result.put(pairOfFile.getId(), timeMetricsList); }
From source file:ch.emad.business.schuetu.BusinessImpl.java
License:Apache License
public void initZeilen(final boolean sonntag) { DateTime start;/* w w w .ja va 2s .c o m*/ List<SpielZeile> zeilen; BusinessImpl.LOG.info("date: starttag -->" + this.getSpielEinstellungen().getStarttag()); final DateTime start2 = new DateTime(this.getSpielEinstellungen().getStart(), DateTimeZone.forID("Europe/Zurich")); BusinessImpl.LOG.info("date: starttag Europe/Zurich -->" + start2); if (!sonntag) { start = new DateTime(start2); zeilen = createZeilen(start, false); } else { start = new DateTime(start2); start = start.plusDays(1); zeilen = createZeilen(start, true); } BusinessImpl.LOG.info("-->" + zeilen); this.spielzeilenRepo.save(zeilen); }
From source file:ch.icclab.cyclops.support.database.influxdb.client.InfluxDBClient.java
License:Open Source License
/** * Will look into database and return the date of last pull, or epoch if there was none * @return DateTime object//from w ww . j ava 2 s. c om */ public DateTime getLastPull() { InfluxDB db = getConnection(); // this is epoch DateTime date = new DateTime(0, DateTimeZone.UTC); // prepare select query String select = "SELECT * FROM \"" + cloudStackEvents + "\" WHERE event = 'pull' ORDER BY time DESC LIMIT 1"; try { // fire up the query QueryResult response = db.query(createQuery(select, logsDb)); // parse all results JSONArray resultArray = new JSONArray(response.getResults()); // get first result JSONObject result = (JSONObject) resultArray.get(0); // get series JSONArray series = (JSONArray) result.get("series"); // get first series JSONObject firstSeries = (JSONObject) series.get(0); // get values JSONArray values = (JSONArray) firstSeries.get("values"); // use first value JSONArray firstValue = (JSONArray) values.get(0); // and finally our time String time = firstValue.get(0).toString(); date = Time.getDateForTime(time); } catch (Exception e) { logger.debug("This is the first pull, therefore we will pull data since Epoch"); } return date; }
From source file:com.ace.erp.handler.mybatis.JodaDateTimeTypeHandler.java
@Override public Object getResult(ResultSet rs, String columnName) throws SQLException { Timestamp ts = rs.getTimestamp(columnName); if (ts != null) { return new DateTime(ts.getTime(), DateTimeZone.UTC); } else {// ww w . j a v a 2s .c o m return null; } }