package eu.europa.esig.dss.validation.process.bbb.xcv.checks;

import java.util.Date;

import eu.europa.esig.dss.jaxb.detailedreport.XmlXCV;
import eu.europa.esig.dss.validation.MessageTag;
import eu.europa.esig.dss.validation.policy.rules.Indication;
import eu.europa.esig.dss.validation.policy.rules.SubIndication;
import eu.europa.esig.dss.validation.process.ChainItem;
import eu.europa.esig.dss.validation.reports.wrapper.CertificateWrapper;
import eu.europa.esig.jaxb.policy.LevelConstraint;

public class CertificateExpirationCheck extends ChainItem<XmlXCV> {

	private final Date currentTime;
	private final CertificateWrapper certificate;

	public CertificateExpirationCheck(XmlXCV result, CertificateWrapper certificate, Date currentTime, LevelConstraint constraint) {
		super(result, constraint);
		this.currentTime = currentTime;
		this.certificate = certificate;
	}

	@Override
	protected boolean process() {
		Date notBefore = certificate.getNotBefore();
		Date notAfter = certificate.getNotAfter();
		Date expiredCertsRevocationInfo = certificate.getCertificateTSPServiceExpiredCertsRevocationInfo();
		boolean certificateValidity = (notBefore != null && (currentTime.compareTo(notBefore) >= 0))
				&& (notAfter != null && (currentTime.compareTo(notAfter) <= 0));
		return ((expiredCertsRevocationInfo != null) || certificateValidity); // TODO Check the value of
																				// expiredCertsRevocationInfo -> it may
																				// be always null
	}

	@Override
	protected MessageTag getMessageTag() {
		return MessageTag.BBB_XCV_ICTIVRSC;
	}

	@Override
	protected MessageTag getErrorMessageTag() {
		return MessageTag.BBB_XCV_ICTIVRSC_ANS;
	}

	@Override
	protected Indication getFailedIndicationForConclusion() {
		return Indication.INDETERMINATE;
	}

	@Override
	protected SubIndication getFailedSubIndicationForConclusion() {
		return SubIndication.OUT_OF_BOUNDS_NO_POE;
	}
}

@@ -1010,110 +1010,8 @@
 ();%0A
-%09%09Date expiredCertsRevocationInfo = certificate.getCertificateTSPServiceExpiredCertsRevocationInfo();%0A
 %09%09bo
@@ -1183,195 +1183,28 @@
 urn 
-((expiredCertsRevocationInfo != null) %7C%7C certificateValidity); // TODO Check the value of%0A%09%09%09%09%09%09%09%09%09%09%09%09%09%09%09%09%09%09%09%09// expiredCertsRevocationInfo -%3E it may%0A%09%09%09%09%09%09%09%09%09%09%09%09%09%09%09%09%09%09%09%09// be always null
+certificateValidity;
 %0A%09%7D%0A

Clean (expiredCertsRevocationInfo is never set and not mentioned in validation standard)