Java Code Examples for javax.xml.datatype.XMLGregorianCalendar#compare()

The following examples show how to use javax.xml.datatype.XMLGregorianCalendar#compare() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SamlUtil.java    From keycloak with Apache License 2.0 6 votes vote down vote up
public static SamlSession validateSamlSession(Object potentialSamlSession, SamlDeployment deployment) {
    if (potentialSamlSession == null) {
        log.debug("SamlSession was not found in the session");
        return null;
    }

    if (!(potentialSamlSession instanceof SamlSession)) {
        log.debug("Provided samlSession was not SamlSession type");
        return null;
    }

    SamlSession samlSession = (SamlSession) potentialSamlSession;

    XMLGregorianCalendar sessionNotOnOrAfter = samlSession.getSessionNotOnOrAfter();
    if (sessionNotOnOrAfter != null) {
        XMLGregorianCalendar now = XMLTimeUtil.getIssueInstant();

        XMLTimeUtil.add(sessionNotOnOrAfter, deployment.getIDP().getAllowedClockSkew()); // add clockSkew

        if (now.compare(sessionNotOnOrAfter) != DatatypeConstants.LESSER) {
            return null;
        }
    }

    return samlSession;
}
 
Example 2
Source File: XMLTimeUtil.java    From keycloak with Apache License 2.0 6 votes vote down vote up
/**
 * Validate that the current time falls between the two boundaries
 *
 * @param now
 * @param notbefore
 * @param notOnOrAfter
 *
 * @return
 */
public static boolean isValid(XMLGregorianCalendar now, XMLGregorianCalendar notbefore, XMLGregorianCalendar notOnOrAfter) {
    int val;

    if (notbefore != null) {
        val = notbefore.compare(now);

        if (val == DatatypeConstants.INDETERMINATE || val == DatatypeConstants.GREATER)
            return false;
    }

    if (notOnOrAfter != null) {
        val = notOnOrAfter.compare(now);

        if (val != DatatypeConstants.GREATER)
            return false;
    }

    return true;
}
 
Example 3
Source File: ConditionsValidator.java    From keycloak with Apache License 2.0 6 votes vote down vote up
/**
 * Validate as per Section 2.5.1.2
 * @return
 */
private Result validateExpiration() {
    XMLGregorianCalendar notBefore = conditions.getNotBefore();
    XMLGregorianCalendar notOnOrAfter = conditions.getNotOnOrAfter();

    if (notBefore == null && notOnOrAfter == null) {
        return Result.VALID;
    }

    if (notBefore != null && notOnOrAfter != null && notBefore.compare(notOnOrAfter) != DatatypeConstants.LESSER) {
        return Result.INVALID;
    }

    XMLGregorianCalendar updatedNotBefore = XMLTimeUtil.subtract(notBefore, clockSkewInMillis);
    XMLGregorianCalendar updatedOnOrAfter = XMLTimeUtil.add(notOnOrAfter, clockSkewInMillis);

    LOG.debugf("Evaluating Conditions of Assertion %s. notBefore=%s, notOnOrAfter=%s, updatedNotBefore: %s, updatedOnOrAfter=%s, now: %s", 
            assertionId, notBefore, notOnOrAfter, updatedNotBefore, updatedOnOrAfter, now);
    boolean valid = XMLTimeUtil.isValid(now, updatedNotBefore, updatedOnOrAfter);
    if (! valid) {
        LOG.infof("Assertion %s expired.", assertionId);
    }

    return valid ? Result.VALID : Result.INVALID;
}
 
Example 4
Source File: ConsolidateUtils.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
private static Comparator<MedicationHistoryType> createComparatorMedicationHistoryType() {
   return new Comparator<MedicationHistoryType>() {
      public int compare(MedicationHistoryType o1, MedicationHistoryType o2) {
         XMLGregorianCalendar date1 = this.extractDate(o1);
         XMLGregorianCalendar date2 = this.extractDate(o2);
         return date1.compare(date2);
      }

      private XMLGregorianCalendar extractDate(MedicationHistoryType medicationHistoryType) {
         return medicationHistoryType.getDeliveryDate();
      }
   };
}
 
Example 5
Source File: DefaultXMLCalendarType.java    From jdmn with Apache License 2.0 5 votes vote down vote up
protected Boolean xmlCalendarLessThan(XMLGregorianCalendar first, XMLGregorianCalendar second) {
    if (first == null && second == null) {
        return false;
    } else if (first == null) {
        return null;
    } else if (second == null) {
        return null;
    } else {
        int result = first.compare(second);
        return result == LESSER;
    }
}
 
Example 6
Source File: DefaultXMLCalendarType.java    From jdmn with Apache License 2.0 5 votes vote down vote up
protected Boolean xmlCalendarGreaterThan(XMLGregorianCalendar first, XMLGregorianCalendar second) {
    if (first == null && second == null) {
        return false;
    } else if (first == null) {
        return null;
    } else if (second == null) {
        return null;
    } else {
        int result = first.compare(second);
        return result == GREATER;
    }
}
 
Example 7
Source File: DefaultXMLCalendarType.java    From jdmn with Apache License 2.0 5 votes vote down vote up
protected Boolean xmlCalendarLessEqualThan(XMLGregorianCalendar first, XMLGregorianCalendar second) {
    if (first == null && second == null) {
        return true;
    } else if (first == null) {
        return null;
    } else if (second == null) {
        return null;
    } else {
        int result = first.compare(second);
        return result == LESSER || result == EQUAL;
    }
}
 
Example 8
Source File: DefaultXMLCalendarType.java    From jdmn with Apache License 2.0 5 votes vote down vote up
protected Boolean xmlCalendarGreaterEqualThan(XMLGregorianCalendar first, XMLGregorianCalendar second) {
    if (first == null && second == null) {
        return true;
    } else if (first == null) {
        return null;
    } else if (second == null) {
        return null;
    } else {
        int result = first.compare(second);
        return result == GREATER || result == EQUAL;
    }
}
 
Example 9
Source File: DefaultSignavioXMLCalendarType.java    From jdmn with Apache License 2.0 5 votes vote down vote up
protected Boolean xmlCalendarEqual(XMLGregorianCalendar first, XMLGregorianCalendar second) {
    if (first == null && second == null) {
        return true;
    } else if (first == null) {
        return false;
    } else if (second == null) {
        return false;
    } else {
        int result = first.compare(second);
        return result == EQUAL;
    }
}
 
Example 10
Source File: DefaultSignavioXMLCalendarType.java    From jdmn with Apache License 2.0 5 votes vote down vote up
protected Boolean xmlCalendarLessThan(XMLGregorianCalendar first, XMLGregorianCalendar second) {
    if (first == null && second == null) {
        return null;
    } else if (first == null) {
        return null;
    } else if (second == null) {
        return null;
    } else {
        int result = first.compare(second);
        return result == LESSER;
    }
}
 
Example 11
Source File: DefaultSignavioXMLCalendarType.java    From jdmn with Apache License 2.0 5 votes vote down vote up
protected Boolean xmlCalendarGreaterThan(XMLGregorianCalendar first, XMLGregorianCalendar second) {
    if (first == null && second == null) {
        return null;
    } else if (first == null) {
        return null;
    } else if (second == null) {
        return null;
    } else {
        int result = first.compare(second);
        return result == GREATER;
    }
}
 
Example 12
Source File: DefaultSignavioXMLCalendarType.java    From jdmn with Apache License 2.0 5 votes vote down vote up
protected Boolean xmlCalendarLessEqualThan(XMLGregorianCalendar first, XMLGregorianCalendar second) {
    if (first == null && second == null) {
        return null;
    } else if (first == null) {
        return null;
    } else if (second == null) {
        return null;
    } else {
        int result = first.compare(second);
        return result == LESSER || result == EQUAL;
    }
}
 
Example 13
Source File: DefaultSignavioXMLCalendarType.java    From jdmn with Apache License 2.0 5 votes vote down vote up
protected Boolean xmlCalendarGreaterEqualThan(XMLGregorianCalendar first, XMLGregorianCalendar second) {
    if (first == null && second == null) {
        return null;
    } else if (first == null) {
        return null;
    } else if (second == null) {
        return null;
    } else {
        int result = first.compare(second);
        return result == GREATER || result == EQUAL;
    }
}
 
Example 14
Source File: QueryResults.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static boolean bindingSetsMatch(BindingSet bs1, BindingSet bs2, Map<BNode, BNode> bNodeMapping) {

		if (bs1.size() != bs2.size()) {
			return false;
		}

		for (Binding binding1 : bs1) {
			Value value1 = binding1.getValue();
			Value value2 = bs2.getValue(binding1.getName());

			if (value1 instanceof BNode && value2 instanceof BNode) {
				BNode mappedBNode = bNodeMapping.get(value1);

				if (mappedBNode != null) {
					// bNode 'value1' was already mapped to some other bNode
					if (!value2.equals(mappedBNode)) {
						// 'value1' and 'value2' do not match
						return false;
					}
				} else {
					// 'value1' was not yet mapped, we need to check if 'value2' is a
					// possible mapping candidate
					if (bNodeMapping.containsValue(value2)) {
						// 'value2' is already mapped to some other value.
						return false;
					}
				}
			} else {
				// values are not (both) bNodes
				if (value1 instanceof Literal && value2 instanceof Literal) {
					// do literal value-based comparison for supported datatypes
					Literal leftLit = (Literal) value1;
					Literal rightLit = (Literal) value2;

					IRI dt1 = leftLit.getDatatype();
					IRI dt2 = rightLit.getDatatype();

					if (dt1 != null && dt2 != null && dt1.equals(dt2)
							&& XMLDatatypeUtil.isValidValue(leftLit.getLabel(), dt1)
							&& XMLDatatypeUtil.isValidValue(rightLit.getLabel(), dt2)) {
						Integer compareResult = null;
						if (dt1.equals(XMLSchema.DOUBLE)) {
							compareResult = Double.compare(leftLit.doubleValue(), rightLit.doubleValue());
						} else if (dt1.equals(XMLSchema.FLOAT)) {
							compareResult = Float.compare(leftLit.floatValue(), rightLit.floatValue());
						} else if (dt1.equals(XMLSchema.DECIMAL)) {
							compareResult = leftLit.decimalValue().compareTo(rightLit.decimalValue());
						} else if (XMLDatatypeUtil.isIntegerDatatype(dt1)) {
							compareResult = leftLit.integerValue().compareTo(rightLit.integerValue());
						} else if (dt1.equals(XMLSchema.BOOLEAN)) {
							Boolean leftBool = leftLit.booleanValue();
							Boolean rightBool = rightLit.booleanValue();
							compareResult = leftBool.compareTo(rightBool);
						} else if (XMLDatatypeUtil.isCalendarDatatype(dt1)) {
							XMLGregorianCalendar left = leftLit.calendarValue();
							XMLGregorianCalendar right = rightLit.calendarValue();

							compareResult = left.compare(right);
						}

						if (compareResult != null) {
							if (compareResult.intValue() != 0) {
								return false;
							}
						} else if (!value1.equals(value2)) {
							return false;
						}
					} else if (!value1.equals(value2)) {
						return false;
					}
				} else if (!value1.equals(value2)) {
					return false;
				}
			}
		}

		return true;
	}
 
Example 15
Source File: WebTestUtils.java    From cumulusrdf with Apache License 2.0 4 votes vote down vote up
/**
 * Copied from org.openrdf.query.QueryResultUtil
 */
private static boolean bindingSetsMatch(final BindingSet bs1, final BindingSet bs2) {

	if (bs1.size() != bs2.size()) {
		return false;
	}

	for (Binding binding1 : bs1) {
		Value value1 = binding1.getValue();
		Value value2 = bs2.getValue(binding1.getName());

		if ((value1 instanceof BNode) && (value2 instanceof BNode)) {
			// BNode mappedBNode = bNodeMapping.get(value1);
			//
			// if (mappedBNode != null) {
			// // bNode 'value1' was already mapped to some other bNode
			// if (!value2.equals(mappedBNode)) {
			// // 'value1' and 'value2' do not match
			// return false;
			// }
			// } else {
			// // 'value1' was not yet mapped, we need to check if 'value2'
			// // is a
			// // possible mapping candidate
			// if (bNodeMapping.containsValue(value2)) {
			// // 'value2' is already mapped to some other value.
			// return false;
			// }
			// }

			return value1.equals(value2);
		} else {
			// values are not (both) bNodes
			if ((value1 instanceof Literal) && (value2 instanceof Literal)) {
				// do literal value-based comparison for supported datatypes
				Literal leftLit = (Literal) value1;
				Literal rightLit = (Literal) value2;

				URI dt1 = leftLit.getDatatype();
				URI dt2 = rightLit.getDatatype();

				if ((dt1 != null) && (dt2 != null) && dt1.equals(dt2) && XMLDatatypeUtil.isValidValue(leftLit.getLabel(), dt1)
						&& XMLDatatypeUtil.isValidValue(rightLit.getLabel(), dt2)) {
					Integer compareResult = null;
					if (dt1.equals(XMLSchema.DOUBLE)) {
						compareResult = Double.compare(leftLit.doubleValue(), rightLit.doubleValue());
					} else if (dt1.equals(XMLSchema.FLOAT)) {
						compareResult = Float.compare(leftLit.floatValue(), rightLit.floatValue());
					} else if (dt1.equals(XMLSchema.DECIMAL)) {
						compareResult = leftLit.decimalValue().compareTo(rightLit.decimalValue());
					} else if (XMLDatatypeUtil.isIntegerDatatype(dt1)) {
						compareResult = leftLit.integerValue().compareTo(rightLit.integerValue());
					} else if (dt1.equals(XMLSchema.BOOLEAN)) {
						Boolean leftBool = Boolean.valueOf(leftLit.booleanValue());
						Boolean rightBool = Boolean.valueOf(rightLit.booleanValue());
						compareResult = leftBool.compareTo(rightBool);
					} else if (XMLDatatypeUtil.isCalendarDatatype(dt1)) {
						XMLGregorianCalendar left = leftLit.calendarValue();
						XMLGregorianCalendar right = rightLit.calendarValue();

						compareResult = left.compare(right);
					}

					if (compareResult != null) {
						if (compareResult.intValue() != 0) {
							return false;
						}
					} else if (!value1.equals(value2)) {
						return false;
					}
				} else if (!value1.equals(value2)) {
					return false;
				}
			} else if (!value1.equals(value2)) {
				return false;
			}
		}
	}

	return true;
}