List of usage examples for java.util Calendar after
public boolean after(Object when)
Calendar
represents a time after the time represented by the specified Object
. From source file:org.ms123.common.team.TeamServiceImpl.java
private boolean checkTeamDate(Map teamInternalMap, Map teamMap) { Calendar today = Calendar.getInstance(); today.set(Calendar.HOUR_OF_DAY, 0); today.set(Calendar.MINUTE, 0); today.set(Calendar.SECOND, 0); today.set(Calendar.MILLISECOND, 0); Calendar validFrom = null;/*from ww w . j a v a 2 s.c om*/ if (teamMap != null && teamMap.get("validFrom") != null) { validFrom = getCalendar(teamMap, "validFrom", 0); } else { if (teamInternalMap != null) { validFrom = getCalendar(teamInternalMap, "validFrom", 0); } } Calendar validTo = null; if (teamMap != null && teamMap.get("validTo") != null) { validTo = getCalendar(teamMap, "validTo", Long.MAX_VALUE); } else { if (teamInternalMap != null) { validTo = getCalendar(teamInternalMap, "validTo", Long.MAX_VALUE); } } boolean startOk = true; boolean endOk = true; if (validFrom != null) { debug("checkTeamDate.validFrom:" + validFrom.getTime()); debug("checkTeamDate.validFrom.before:" + today.before(validFrom)); if (today.before(validFrom)) { startOk = false; } } if (validTo != null) { debug("checkTeamDate.validTo:" + validTo.getTime()); debug("checkTeamDate.validTo.after:" + today.after(validTo)); if (today.after(validTo)) { endOk = false; } } debug("checkTeamDate:" + startOk + "/" + endOk); if (!startOk || !endOk) { return false; } return true; }
From source file:com.ecofactor.qa.automation.newapp.service.MockDataServiceImpl.java
/** * Checks if is sPO block active./* ww w .j a v a 2 s . c om*/ * * @param thermostatId * the thermostat id * @param algoId * the algo id * @return true, if is sPO block active * @see com.ecofactor.qa.automation.algorithm.service.DataService#isSPOBlockActive(java.lang.Integer, * int) */ @Override public boolean isSPOBlockActive(Integer thermostatId, int algoId) { log("Check if SPO is active for thermostat :" + thermostatId, true); boolean spoActive = false; Thermostat thermostat = findBythermostatId(thermostatId); Calendar currentTime = (Calendar) Calendar.getInstance(TimeZone.getTimeZone(thermostat.getTimezone())) .clone(); JSONArray jsonArray = getJobData(thermostatId); for (int i = 0; i < jsonArray.length(); i++) { try { JSONObject jsonObj = jsonArray.getJSONObject(i); Calendar startCal = DateUtil.getTimeZoneCalendar((String) jsonObj.get("start"), thermostat.getTimezone()); Calendar endcal = DateUtil.getTimeZoneCalendar((String) jsonObj.get("end"), thermostat.getTimezone()); if (currentTime.after(startCal) && currentTime.before(endcal)) { spoActive = true; break; } } catch (JSONException e) { e.printStackTrace(); } } return spoActive; }
From source file:edu.stanford.muse.util.Util.java
public static List<Pair<Calendar, Calendar>> getSlidingMonthlyIntervalsForward(Calendar start, Calendar end, int windowSizeInMonths, int stepSizeInMonths) { List<Pair<Calendar, Calendar>> intervals = new ArrayList<Pair<Calendar, Calendar>>(); if (start == null || end == null) return intervals; if (start.after(end)) // error {//from w w w .j a v a 2 s . c o m softAssert(false); return intervals; } Calendar windowStart = start; int windowStartMonth = start.get(Calendar.MONTH); int windowStartYear = start.get(Calendar.YEAR); while (true) { int windowEndMonth = windowStartMonth + windowSizeInMonths; int windowEndYear = windowStartYear; if (windowEndMonth >= 12) { windowEndYear += windowEndMonth / 12; windowEndMonth = windowEndMonth % 12; } Calendar windowEnd = new GregorianCalendar(windowEndYear, windowEndMonth, 1, 0, 0, 0); intervals.add(new Pair<Calendar, Calendar>(windowStart, windowEnd)); if (windowEnd.after(end)) break; // step window start windowStartMonth += stepSizeInMonths; if (windowStartMonth >= 12) { windowStartYear += windowStartMonth / 12; windowStartMonth = windowStartMonth % 12; } windowStart = new GregorianCalendar(windowStartYear, windowStartMonth, 1, 0, 0, 0); } return intervals; }
From source file:com.ecofactor.qa.automation.newapp.service.DataServiceImpl.java
/** * Checks if is sPO block active.//from w w w . j a v a2 s. c o m * * @param thermostatId * the thermostat id * @param algoId * the algo id * @return true, if is sPO block active * @see com.ecofactor.qa.automation.algorithm.service.SPODataService#isSPOBlockActive(java.lang.Integer, * int) */ @Override public boolean isSPOBlockActive(Integer thermostatId, int algoId) { DriverConfig.setLogString("Check SPO is Active Now for Thermostat Id :" + thermostatId, true); boolean isSPOActive = false; Calendar currentTime = DateUtil.getUTCCalendar(); JSONArray jsonArray = getJobData(thermostatId); boolean isDataChanged = false; for (int i = 0; i < jsonArray.length(); i++) { try { JSONObject jsonObj = jsonArray.getJSONObject(i); Calendar startCal = DateUtil.getUTCTimeZoneCalendar((String) jsonObj.get("start")); Calendar endcal = DateUtil.getUTCTimeZoneCalendar((String) jsonObj.get("end")); int endHour = endcal.get(Calendar.HOUR_OF_DAY); int startHour = startCal.get(Calendar.HOUR_OF_DAY); if (isDataChanged) { startCal.set(Calendar.DATE, startCal.get(Calendar.DATE) + 1); endcal.set(Calendar.DATE, endcal.get(Calendar.DATE) + 1); } if (startHour > endHour) { endcal.set(Calendar.DATE, endcal.get(Calendar.DATE) + 1); isDataChanged = true; } DriverConfig.setLogString("startCal :" + DateUtil.format(startCal, DateUtil.DATE_FMT_FULL_TZ), true); DriverConfig.setLogString("endcal :" + DateUtil.format(endcal, DateUtil.DATE_FMT_FULL_TZ), true); if (currentTime.after(startCal) && currentTime.before(endcal)) { isSPOActive = true; break; } } catch (JSONException e) { e.printStackTrace(); } } return isSPOActive; }
From source file:nl.strohalm.cyclos.services.accounts.guarantees.GuaranteeServiceImpl.java
@Override public Guarantee requestGuarantee(final PaymentObligationPackDTO pack) { final Long[] poIds = pack.getPaymentObligations(); // verifies the pack validity if (pack.getIssuer() == null) { throw new IllegalArgumentException("Invalid guarantee request: Issuer is null"); } else if (poIds == null || poIds.length == 0) { throw new IllegalArgumentException("Invalid guarantee request: payment obligations pack is empty"); }/*w w w .j av a 2 s.c o m*/ // take the first payment obligation to get the currency and buyer (all belong to the same buyer and have the same currency) final PaymentObligation firstPaymentObligation = paymentObligationService.load(poIds[0]); final Member buyer = firstPaymentObligation.getBuyer(); final Member seller = firstPaymentObligation.getSeller(); final Member issuer = pack.getIssuer(); final AccountOwner accOwner = LoggedUser.accountOwner(); if (!accOwner.equals(seller)) { throw new PermissionDeniedException(); } final Certification certification = certificationService .getActiveCertification(firstPaymentObligation.getCurrency(), buyer, issuer); // verifies if there is an active certification if (certification == null) { throw new ActiveCertificationNotFoundException(buyer, issuer, firstPaymentObligation.getCurrency()); } // calculates the guarantee's amount and expirationDate BigDecimal amount = firstPaymentObligation.getAmount(); final ArrayList<PaymentObligation> paymentObligations = new ArrayList<PaymentObligation>(); paymentObligations.add(firstPaymentObligation); Calendar lastExpirationdate = firstPaymentObligation.getExpirationDate(); for (int i = 1; i < poIds.length; i++) { final PaymentObligation po = paymentObligationService.load(poIds[i]); if (!accOwner.equals(po.getSeller())) { throw new PermissionDeniedException(); } amount = amount.add(po.getAmount()); if (po.getExpirationDate().after(lastExpirationdate)) { lastExpirationdate = po.getExpirationDate(); } paymentObligations.add(po); } // verify that the certificatin's amount is not exceeded final BigDecimal usedCertificationAmount = certificationService.getUsedAmount(certification, true); final BigDecimal remainingAmount = certification.getAmount().subtract(usedCertificationAmount); if (amount.compareTo(remainingAmount) > 0) { throw new CertificationAmountExceededException(certification, remainingAmount, amount); } // verify that the certificatin's validity is not exceeded if (lastExpirationdate.after(certification.getValidity().getEnd())) { throw new CertificationValidityExceededException(certification); } final GuaranteeType guaranteeType = certification.getGuaranteeType(); Guarantee guarantee = new Guarantee(); guarantee.setBuyer(buyer); guarantee.setSeller(seller); guarantee.setIssuer(pack.getIssuer()); guarantee.setCertification(certification); guarantee.setGuaranteeType(guaranteeType); guarantee.setAmount(amount); guarantee.setValidity(new Period(null, lastExpirationdate)); guarantee.setPaymentObligations(paymentObligations); guarantee.setCreditFeeSpec((GuaranteeFeeVO) guaranteeType.getCreditFee().clone()); guarantee.setIssueFeeSpec((GuaranteeFeeVO) guaranteeType.getIssueFee().clone()); guarantee = save(guarantee, false); for (int i = 0; i < poIds.length; i++) { final PaymentObligation po = paymentObligations.get(i); po.setGuarantee(guarantee); paymentObligationService.changeStatus(po.getId(), PaymentObligation.Status.ACCEPTED); } memberNotificationHandler.guaranteePendingIssuerNotification(guarantee); return guarantee; }
From source file:com.centeractive.ws.builder.soap.SampleXmlUtil.java
private String formatDate(SchemaType sType) { GDateBuilder gdateb = new GDateBuilder( new Date(1000L * pick(365 * 24 * 60 * 60) + (30L + pick(20)) * 365 * 24 * 60 * 60 * 1000)); GDate min = null, max = null;/*from w w w .j av a 2 s .c o m*/ // Find the min and the max according to the type switch (sType.getPrimitiveType().getBuiltinTypeCode()) { case SchemaType.BTC_DATE_TIME: { XmlDateTime x = (XmlDateTime) sType.getFacet(SchemaType.FACET_MIN_INCLUSIVE); if (x != null) min = x.getGDateValue(); x = (XmlDateTime) sType.getFacet(SchemaType.FACET_MIN_EXCLUSIVE); if (x != null) if (min == null || min.compareToGDate(x.getGDateValue()) <= 0) min = x.getGDateValue(); x = (XmlDateTime) sType.getFacet(SchemaType.FACET_MAX_INCLUSIVE); if (x != null) max = x.getGDateValue(); x = (XmlDateTime) sType.getFacet(SchemaType.FACET_MAX_EXCLUSIVE); if (x != null) if (max == null || max.compareToGDate(x.getGDateValue()) >= 0) max = x.getGDateValue(); break; } case SchemaType.BTC_TIME: { XmlTime x = (XmlTime) sType.getFacet(SchemaType.FACET_MIN_INCLUSIVE); if (x != null) min = x.getGDateValue(); x = (XmlTime) sType.getFacet(SchemaType.FACET_MIN_EXCLUSIVE); if (x != null) if (min == null || min.compareToGDate(x.getGDateValue()) <= 0) min = x.getGDateValue(); x = (XmlTime) sType.getFacet(SchemaType.FACET_MAX_INCLUSIVE); if (x != null) max = x.getGDateValue(); x = (XmlTime) sType.getFacet(SchemaType.FACET_MAX_EXCLUSIVE); if (x != null) if (max == null || max.compareToGDate(x.getGDateValue()) >= 0) max = x.getGDateValue(); break; } case SchemaType.BTC_DATE: { XmlDate x = (XmlDate) sType.getFacet(SchemaType.FACET_MIN_INCLUSIVE); if (x != null) min = x.getGDateValue(); x = (XmlDate) sType.getFacet(SchemaType.FACET_MIN_EXCLUSIVE); if (x != null) if (min == null || min.compareToGDate(x.getGDateValue()) <= 0) min = x.getGDateValue(); x = (XmlDate) sType.getFacet(SchemaType.FACET_MAX_INCLUSIVE); if (x != null) max = x.getGDateValue(); x = (XmlDate) sType.getFacet(SchemaType.FACET_MAX_EXCLUSIVE); if (x != null) if (max == null || max.compareToGDate(x.getGDateValue()) >= 0) max = x.getGDateValue(); break; } case SchemaType.BTC_G_YEAR_MONTH: { XmlGYearMonth x = (XmlGYearMonth) sType.getFacet(SchemaType.FACET_MIN_INCLUSIVE); if (x != null) min = x.getGDateValue(); x = (XmlGYearMonth) sType.getFacet(SchemaType.FACET_MIN_EXCLUSIVE); if (x != null) if (min == null || min.compareToGDate(x.getGDateValue()) <= 0) min = x.getGDateValue(); x = (XmlGYearMonth) sType.getFacet(SchemaType.FACET_MAX_INCLUSIVE); if (x != null) max = x.getGDateValue(); x = (XmlGYearMonth) sType.getFacet(SchemaType.FACET_MAX_EXCLUSIVE); if (x != null) if (max == null || max.compareToGDate(x.getGDateValue()) >= 0) max = x.getGDateValue(); break; } case SchemaType.BTC_G_YEAR: { XmlGYear x = (XmlGYear) sType.getFacet(SchemaType.FACET_MIN_INCLUSIVE); if (x != null) min = x.getGDateValue(); x = (XmlGYear) sType.getFacet(SchemaType.FACET_MIN_EXCLUSIVE); if (x != null) if (min == null || min.compareToGDate(x.getGDateValue()) <= 0) min = x.getGDateValue(); x = (XmlGYear) sType.getFacet(SchemaType.FACET_MAX_INCLUSIVE); if (x != null) max = x.getGDateValue(); x = (XmlGYear) sType.getFacet(SchemaType.FACET_MAX_EXCLUSIVE); if (x != null) if (max == null || max.compareToGDate(x.getGDateValue()) >= 0) max = x.getGDateValue(); break; } case SchemaType.BTC_G_MONTH_DAY: { XmlGMonthDay x = (XmlGMonthDay) sType.getFacet(SchemaType.FACET_MIN_INCLUSIVE); if (x != null) min = x.getGDateValue(); x = (XmlGMonthDay) sType.getFacet(SchemaType.FACET_MIN_EXCLUSIVE); if (x != null) if (min == null || min.compareToGDate(x.getGDateValue()) <= 0) min = x.getGDateValue(); x = (XmlGMonthDay) sType.getFacet(SchemaType.FACET_MAX_INCLUSIVE); if (x != null) max = x.getGDateValue(); x = (XmlGMonthDay) sType.getFacet(SchemaType.FACET_MAX_EXCLUSIVE); if (x != null) if (max == null || max.compareToGDate(x.getGDateValue()) >= 0) max = x.getGDateValue(); break; } case SchemaType.BTC_G_DAY: { XmlGDay x = (XmlGDay) sType.getFacet(SchemaType.FACET_MIN_INCLUSIVE); if (x != null) min = x.getGDateValue(); x = (XmlGDay) sType.getFacet(SchemaType.FACET_MIN_EXCLUSIVE); if (x != null) if (min == null || min.compareToGDate(x.getGDateValue()) <= 0) min = x.getGDateValue(); x = (XmlGDay) sType.getFacet(SchemaType.FACET_MAX_INCLUSIVE); if (x != null) max = x.getGDateValue(); x = (XmlGDay) sType.getFacet(SchemaType.FACET_MAX_EXCLUSIVE); if (x != null) if (max == null || max.compareToGDate(x.getGDateValue()) >= 0) max = x.getGDateValue(); break; } case SchemaType.BTC_G_MONTH: { XmlGMonth x = (XmlGMonth) sType.getFacet(SchemaType.FACET_MIN_INCLUSIVE); if (x != null) min = x.getGDateValue(); x = (XmlGMonth) sType.getFacet(SchemaType.FACET_MIN_EXCLUSIVE); if (x != null) if (min == null || min.compareToGDate(x.getGDateValue()) <= 0) min = x.getGDateValue(); x = (XmlGMonth) sType.getFacet(SchemaType.FACET_MAX_INCLUSIVE); if (x != null) max = x.getGDateValue(); x = (XmlGMonth) sType.getFacet(SchemaType.FACET_MAX_EXCLUSIVE); if (x != null) if (max == null || max.compareToGDate(x.getGDateValue()) >= 0) max = x.getGDateValue(); break; } } if (min != null && max == null) { if (min.compareToGDate(gdateb) >= 0) { // Reset the date to min + (1-8) hours Calendar c = gdateb.getCalendar(); c.add(Calendar.HOUR_OF_DAY, pick(8)); gdateb = new GDateBuilder(c); } } else if (min == null && max != null) { if (max.compareToGDate(gdateb) <= 0) { // Reset the date to max - (1-8) hours Calendar c = gdateb.getCalendar(); c.add(Calendar.HOUR_OF_DAY, 0 - pick(8)); gdateb = new GDateBuilder(c); } } else if (min != null && max != null) { if (min.compareToGDate(gdateb) >= 0 || max.compareToGDate(gdateb) <= 0) { // Find a date between the two Calendar c = min.getCalendar(); Calendar cmax = max.getCalendar(); c.add(Calendar.HOUR_OF_DAY, 1); if (c.after(cmax)) { c.add(Calendar.HOUR_OF_DAY, -1); c.add(Calendar.MINUTE, 1); if (c.after(cmax)) { c.add(Calendar.MINUTE, -1); c.add(Calendar.SECOND, 1); if (c.after(cmax)) { c.add(Calendar.SECOND, -1); c.add(Calendar.MILLISECOND, 1); if (c.after(cmax)) c.add(Calendar.MILLISECOND, -1); } } } gdateb = new GDateBuilder(c); } } gdateb.setBuiltinTypeCode(sType.getPrimitiveType().getBuiltinTypeCode()); if (pick(2) == 0) gdateb.clearTimeZone(); return gdateb.toString(); }
From source file:org.moqui.impl.service.ServiceDefinition.java
private boolean validateParameterSingle(MNode valNode, String parameterName, Object pv, ExecutionContextImpl eci) {//from w ww. ja va 2 s . c om // should never be null (caller checks) but check just in case if (pv == null) return true; String validateName = valNode.getName(); if ("val-or".equals(validateName)) { boolean anyPass = false; for (MNode child : valNode.getChildren()) if (validateParameterSingle(child, parameterName, pv, eci)) anyPass = true; return anyPass; } else if ("val-and".equals(validateName)) { boolean allPass = true; for (MNode child : valNode.getChildren()) if (!validateParameterSingle(child, parameterName, pv, eci)) allPass = false; return allPass; } else if ("val-not".equals(validateName)) { boolean allPass = true; for (MNode child : valNode.getChildren()) if (!validateParameterSingle(child, parameterName, pv, eci)) allPass = false; return !allPass; } else if ("matches".equals(validateName)) { if (!(pv instanceof CharSequence)) { Map<String, Object> map = new HashMap<>(1); map.put("pv", pv); eci.getMessage().addValidationError(null, parameterName, serviceName, eci.getResource().expand( "Value entered (${pv}) is not a string, cannot do matches validation.", "", map), null); return false; } String pvString = pv.toString(); String regexp = valNode.attribute("regexp"); if (regexp != null && !regexp.isEmpty() && !pvString.matches(regexp)) { // a message attribute should always be there, but just in case we'll have a default final String message = valNode.attribute("message"); Map<String, Object> map = new HashMap<>(2); map.put("pv", pv); map.put("regexp", regexp); eci.getMessage().addValidationError(null, parameterName, serviceName, eci.getResource() .expand(message != null && !message.isEmpty() ? message : "Value entered (${pv}) did not match expression: ${regexp}", "", map), null); return false; } return true; } else if ("number-range".equals(validateName)) { BigDecimal bdVal = new BigDecimal(pv.toString()); String minStr = valNode.attribute("min"); if (minStr != null && !minStr.isEmpty()) { BigDecimal min = new BigDecimal(minStr); if ("false".equals(valNode.attribute("min-include-equals"))) { if (bdVal.compareTo(min) <= 0) { Map<String, Object> map = new HashMap<>(2); map.put("pv", pv); map.put("min", min); eci.getMessage().addValidationError(null, parameterName, serviceName, eci.getResource().expand( "Value entered (${pv}) is less than or equal to ${min} must be greater than.", "", map), null); return false; } } else { if (bdVal.compareTo(min) < 0) { Map<String, Object> map = new HashMap<>(2); map.put("pv", pv); map.put("min", min); eci.getMessage().addValidationError(null, parameterName, serviceName, eci.getResource().expand( "Value entered (${pv}) is less than ${min} and must be greater than or equal to.", "", map), null); return false; } } } String maxStr = valNode.attribute("max"); if (maxStr != null && !maxStr.isEmpty()) { BigDecimal max = new BigDecimal(maxStr); if ("true".equals(valNode.attribute("max-include-equals"))) { if (bdVal.compareTo(max) > 0) { Map<String, Object> map = new HashMap<>(2); map.put("pv", pv); map.put("max", max); eci.getMessage().addValidationError(null, parameterName, serviceName, eci.getResource().expand( "Value entered (${pv}) is greater than ${max} and must be less than or equal to.", "", map), null); return false; } } else { if (bdVal.compareTo(max) >= 0) { Map<String, Object> map = new HashMap<>(2); map.put("pv", pv); map.put("max", max); eci.getMessage().addValidationError(null, parameterName, serviceName, eci.getResource().expand( "Value entered (${pv}) is greater than or equal to ${max} and must be less than.", "", map), null); return false; } } } return true; } else if ("number-integer".equals(validateName)) { try { new BigInteger(pv.toString()); } catch (NumberFormatException e) { if (logger.isTraceEnabled()) logger.trace( "Adding error message for NumberFormatException for BigInteger parse: " + e.toString()); Map<String, Object> map = new HashMap<>(1); map.put("pv", pv); eci.getMessage().addValidationError(null, parameterName, serviceName, eci.getResource().expand("Value [${pv}] is not a whole (integer) number.", "", map), null); return false; } return true; } else if ("number-decimal".equals(validateName)) { try { new BigDecimal(pv.toString()); } catch (NumberFormatException e) { if (logger.isTraceEnabled()) logger.trace( "Adding error message for NumberFormatException for BigDecimal parse: " + e.toString()); Map<String, Object> map = new HashMap<>(1); map.put("pv", pv); eci.getMessage().addValidationError(null, parameterName, serviceName, eci.getResource().expand("Value [${pv}] is not a decimal number.", "", map), null); return false; } return true; } else if ("text-length".equals(validateName)) { String str = pv.toString(); String minStr = valNode.attribute("min"); if (minStr != null && !minStr.isEmpty()) { int min = Integer.parseInt(minStr); if (str.length() < min) { Map<String, Object> map = new HashMap<>(3); map.put("pv", pv); map.put("str", str); map.put("minStr", minStr); eci.getMessage().addValidationError(null, parameterName, serviceName, eci.getResource().expand( "Value entered (${pv}), length ${str.length()}, is shorter than ${minStr} characters.", "", map), null); return false; } } String maxStr = valNode.attribute("max"); if (maxStr != null && !maxStr.isEmpty()) { int max = Integer.parseInt(maxStr); if (str.length() > max) { Map<String, Object> map = new HashMap<>(3); map.put("pv", pv); map.put("str", str); map.put("maxStr", maxStr); eci.getMessage().addValidationError(null, parameterName, serviceName, eci.getResource().expand( "Value entered (${pv}), length ${str.length()}, is longer than ${maxStr} characters.", "", map), null); return false; } } return true; } else if ("text-email".equals(validateName)) { String str = pv.toString(); if (!emailValidator.isValid(str)) { Map<String, String> map = new HashMap<>(1); map.put("str", str); eci.getMessage().addValidationError(null, parameterName, serviceName, eci.getResource().expand("Value entered (${str}) is not a valid email address.", "", map), null); return false; } return true; } else if ("text-url".equals(validateName)) { String str = pv.toString(); if (!urlValidator.isValid(str)) { Map<String, String> map = new HashMap<>(1); map.put("str", str); eci.getMessage().addValidationError(null, parameterName, serviceName, eci.getResource().expand("Value entered (${str}) is not a valid URL.", "", map), null); return false; } return true; } else if ("text-letters".equals(validateName)) { String str = pv.toString(); for (char c : str.toCharArray()) { if (!Character.isLetter(c)) { Map<String, String> map = new HashMap<>(1); map.put("str", str); eci.getMessage().addValidationError(null, parameterName, serviceName, eci.getResource().expand("Value entered (${str}) must have only letters.", "", map), null); return false; } } return true; } else if ("text-digits".equals(validateName)) { String str = pv.toString(); for (char c : str.toCharArray()) { if (!Character.isDigit(c)) { Map<String, String> map = new HashMap<>(1); map.put("str", str); eci.getMessage().addValidationError(null, parameterName, serviceName, eci.getResource().expand("Value [${str}] must have only digits.", "", map), null); return false; } } return true; } else if ("time-range".equals(validateName)) { Calendar cal; String format = valNode.attribute("format"); if (pv instanceof CharSequence) { cal = eci.getL10n().parseDateTime(pv.toString(), format); } else { // try letting groovy convert it cal = Calendar.getInstance(); // TODO: not sure if this will work: ((pv as java.util.Date).getTime()) cal.setTimeInMillis((DefaultGroovyMethods.asType(pv, Date.class)).getTime()); } String after = valNode.attribute("after"); if (after != null && !after.isEmpty()) { // handle after date/time/date-time depending on type of parameter, support "now" too Calendar compareCal; if ("now".equals(after)) { compareCal = Calendar.getInstance(); compareCal.setTimeInMillis(eci.getUser().getNowTimestamp().getTime()); } else { compareCal = eci.getL10n().parseDateTime(after, format); } if (cal != null && !cal.after(compareCal)) { Map<String, Object> map = new HashMap<>(2); map.put("pv", pv); map.put("after", after); eci.getMessage().addValidationError(null, parameterName, serviceName, eci.getResource().expand("Value entered (${pv}) is before ${after}.", "", map), null); return false; } } String before = valNode.attribute("before"); if (before != null && !before.isEmpty()) { // handle after date/time/date-time depending on type of parameter, support "now" too Calendar compareCal; if ("now".equals(before)) { compareCal = Calendar.getInstance(); compareCal.setTimeInMillis(eci.getUser().getNowTimestamp().getTime()); } else { compareCal = eci.getL10n().parseDateTime(before, format); } if (cal != null && !cal.before(compareCal)) { Map<String, Object> map = new HashMap<>(1); map.put("pv", pv); eci.getMessage().addValidationError(null, parameterName, serviceName, eci.getResource().expand("Value entered (${pv}) is after ${before}.", "", map), null); return false; } } return true; } else if ("credit-card".equals(validateName)) { long creditCardTypes = 0; String types = valNode.attribute("types"); if (types != null && !types.isEmpty()) { for (String cts : types.split(",")) creditCardTypes += creditCardTypeMap.get(cts.trim()); } else { creditCardTypes = allCreditCards; } CreditCardValidator ccv = new CreditCardValidator(creditCardTypes); String str = pv.toString(); if (!ccv.isValid(str)) { Map<String, String> map = new HashMap<>(1); map.put("str", str); eci.getMessage().addValidationError(null, parameterName, serviceName, eci.getResource() .expand("Value entered (${str}) is not a valid credit card number.", "", map), null); return false; } return true; } // shouldn't get here, but just in case return true; }
From source file:org.kuali.ole.module.purap.document.service.impl.InvoiceServiceImpl.java
/** * Returns whichever date is later, the invoicedDateCalendar or the processedDateCalendar. * * @param invoicedDateCalendar One of the dates to be used in determining which date is later. * @param processedDateCalendar The other date to be used in determining which date is later. * @return The date which is the later of the two given dates in the input parameters. *//* w w w. j av a2 s . co m*/ protected Date returnLaterDate(Calendar invoicedDateCalendar, Calendar processedDateCalendar) { if (invoicedDateCalendar.after(processedDateCalendar)) { return new Date(invoicedDateCalendar.getTimeInMillis()); } else { return new Date(processedDateCalendar.getTimeInMillis()); } }
From source file:org.kuali.kfs.module.purap.document.service.impl.PaymentRequestServiceImpl.java
/** * Returns whichever date is later, the invoicedDateCalendar or the processedDateCalendar. * * @param invoicedDateCalendar One of the dates to be used in determining which date is later. * @param processedDateCalendar The other date to be used in determining which date is later. * @return The date which is the later of the two given dates in the input parameters. *///from w ww . ja v a2 s.c o m protected java.sql.Date returnLaterDate(Calendar invoicedDateCalendar, Calendar processedDateCalendar) { if (invoicedDateCalendar.after(processedDateCalendar)) { return new java.sql.Date(invoicedDateCalendar.getTimeInMillis()); } else { return new java.sql.Date(processedDateCalendar.getTimeInMillis()); } }
From source file:org.kuali.kra.proposaldevelopment.printing.xmlstream.NIHResearchAndRelatedXmlStream.java
/** * //from w w w . j a v a 2 s . c o m * This method computes the number of months between any 2 given * {@link Date} objects * * @param dateStart * starting date. * @param dateEnd * end date. * * @return number of months between the start date and end date. */ private BudgetDecimal getNumberOfMonths(Date dateStart, Date dateEnd) { BudgetDecimal monthCount = BudgetDecimal.ZERO; int fullMonthCount = 0; Calendar startDate = Calendar.getInstance(); Calendar endDate = Calendar.getInstance(); startDate.setTime(dateStart); endDate.setTime(dateEnd); startDate.clear(Calendar.HOUR); startDate.clear(Calendar.MINUTE); startDate.clear(Calendar.SECOND); startDate.clear(Calendar.MILLISECOND); endDate.clear(Calendar.HOUR); endDate.clear(Calendar.MINUTE); endDate.clear(Calendar.SECOND); endDate.clear(Calendar.MILLISECOND); if (startDate.after(endDate)) { return BudgetDecimal.ZERO; } int startMonthDays = startDate.getActualMaximum(Calendar.DATE) - startDate.get(Calendar.DATE); startMonthDays++; int startMonthMaxDays = startDate.getActualMaximum(Calendar.DATE); BudgetDecimal startMonthFraction = new BudgetDecimal(startMonthDays) .divide(new BudgetDecimal(startMonthMaxDays)); int endMonthDays = endDate.get(Calendar.DATE); int endMonthMaxDays = endDate.getActualMaximum(Calendar.DATE); BudgetDecimal endMonthFraction = new BudgetDecimal(endMonthDays).divide(new BudgetDecimal(endMonthMaxDays)); startDate.set(Calendar.DATE, 1); endDate.set(Calendar.DATE, 1); while (startDate.getTimeInMillis() < endDate.getTimeInMillis()) { startDate.set(Calendar.MONTH, startDate.get(Calendar.MONTH) + 1); fullMonthCount++; } fullMonthCount = fullMonthCount - 1; monthCount = monthCount.add(new BudgetDecimal(fullMonthCount)).add(startMonthFraction) .add(endMonthFraction); return monthCount; }