/*******************************************************************************
 * Copyright 2016 Research Triangle Institute
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/
package org.search.nibrs.validation;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

import org.search.nibrs.common.NIBRSError;
import org.search.nibrs.model.AbstractReport;
import org.search.nibrs.model.GroupAIncidentReport;
import org.search.nibrs.model.GroupBArrestReport;
import org.search.nibrs.model.NIBRSSubmission;
import org.search.nibrs.model.ZeroReport;
import org.search.nibrs.validation.groupa.GroupAIncidentReportValidator;
import org.search.nibrs.validation.groupb.GroupBArrestReportValidator;
import org.search.nibrs.validation.zeroreport.ZeroReportValidator;

/**
 * Class that applies edits to validate the segments contained within a NIBRS Submission
 */
public class SubmissionValidator {

	private static final Logger LOG = Logger.getLogger(SubmissionValidator.class.getName());

	/**
	 * Apply edits to validate all Reports within the specified submission.
	 * 
	 * @param nibrsSubmission submission containing all the reports to be validated
	 * @return A List of all errors encountered in validating the submission
	 */
	public List<NIBRSError> validate(NIBRSSubmission nibrsSubmission) {

		List<NIBRSError> errorList = new ArrayList<NIBRSError>();
		List<AbstractReport> reportList = nibrsSubmission.getReports();

		for (AbstractReport report : reportList) {
			List<NIBRSError> singleReportErrorsList = validateReport(report);
			errorList.addAll(singleReportErrorsList);
		}

		return errorList;
		
	}

	/**
	 * Validate an individual Report within the specified submission
	 * @param report the report to be validated
	 * @return A List of all errors encountered in validating the report
	 */
	public List<NIBRSError> validateReport(AbstractReport report) {

		List<NIBRSError> nibrsErrorList = new ArrayList<>();

		if (report instanceof ZeroReport) {
			ZeroReport zeroReport = (ZeroReport) report;
			ZeroReportValidator zeroReportValidator = new ZeroReportValidator();
			nibrsErrorList = zeroReportValidator.validate(zeroReport);
		} else if (report instanceof GroupAIncidentReport) {
			GroupAIncidentReport groupAIncidentReport = (GroupAIncidentReport) report;
			GroupAIncidentReportValidator groupAValidator = new GroupAIncidentReportValidator();
			nibrsErrorList = groupAValidator.validate(groupAIncidentReport);
		} else if (report instanceof GroupBArrestReport) {
			GroupBArrestReport groupBIncidentReport = (GroupBArrestReport) report;
			GroupBArrestReportValidator groupBValidator = new GroupBArrestReportValidator();
			nibrsErrorList = groupBValidator.validate(groupBIncidentReport);
		}

		return nibrsErrorList;
		
	}

}

@@ -849,32 +849,78 @@
 l.List;%0A
+%0A
 import 
-java.util
+org.apache.logging.log4j.LogManager;%0Aimport org.apache
 .logging
@@ -924,16 +924,22 @@
 ing.
+log4j.
 Logger;%0A
 %0Aimp
@@ -934,17 +934,16 @@
 Logger;%0A
-%0A
 import o
@@ -1597,16 +1597,20 @@
 OG = Log
+Mana
 ger.getL
@@ -1644,18 +1644,8 @@
 lass
-.getName()
 );%0A%0A
@@ -2527,24 +2527,109 @@
 t report) %7B%0A
+%09%09%0A%09%09LOG.info(%22Validating report: %22 + report.getGloballyUniqueReportIdentifier());%0A%09%09
 %0A%09%09List%3CNIBR
@@ -3458,32 +3458,91 @@
 ntReport);%0A%09%09%7D%0A%0A
+%09%09LOG.info(%22Found %22 + nibrsErrorList.size() + %22 errors%22);%0A%0A
 %09%09return nibrsEr

Improve trace