public void PostSave(QASystem tis, TestResult tr, XmlRepositoryItem xmlRepoItem, ProjectMetaData projectMetaData, ITISExtenderState state) { // do nothing }
/// <summary> /// /// </summary> /// <param name="xml"></param> /// <param name="senderType"></param> /// <param name="fileID"></param> /// <param name="updateRB"></param> /// <param name="updateDoR"></param> /// <param name="sendToHandScoring"></param> /// <param name="ignoreHandscoringDuplicates"></param> /// <param name="emailAlertForWarnings"></param> /// <returns></returns> public QAResult ReceiveTestResult(XmlDocument xml, XmlRepositoryItem xmlRepoItem) { DateTime startDateTime = DateTime.Now; QAResult result = QAResult.Success; ArchiveDB ar = new ArchiveDB(); TestResult tr = null; bool isFatal = false; bool isValid = false; XMLAdapter adapter; SendToModifiers sendToModifiers = null; long? archivedFileID = null; long? dorRecordId = null; // these config settings may be overridden or modified below for this test. ProjectMetaData projectMetaData = new ProjectMetaData(); ITISExtender tisExtender = ServiceLocator.Resolve <ITISExtender>() ?? new NullTISExtender(); ITISExtenderState tisExtenderState = tisExtender.CreateStateContainer(); ITestResultSerializerFactory serializerFactory = ServiceLocator.Resolve <ITestResultSerializerFactory>(); if (serializerFactory == null) { throw new ApplicationException("Must register an ITestResultSerializerFactory with the ServiceLocator."); } try { xmlRepositoryBL = new BL.XmlRepository(QASystemConfigSettings.Instance.LongDbCommandTimeout); adapter = serializerFactory.CreateDeserializer(xml); tr = adapter.CreateTestResult(_tc, out isValid, true); if (tr != null) { // set the project metadata based on the current project (set in the parser) projectMetaData.SetProjectMetaData(tr.ProjectID); // if the opp is null, we can't process the file if (tr.Opportunity == null) { result = QAResult.FailValidation; ar.SaveResultExceptions(tr, adapter.ValidationRecords, xmlRepoItem.FileID); return(result); } //merge item scores from outside vendor if necessary bool qaProjectChanged = false; if (projectMetaData.mergeItemScores && adapter.MergeScores(tr, out qaProjectChanged)) { SetArchiveStrategy(ArchiveStrategy.ArchiveAndInsert); } // if the project changed, refresh the metadata if (qaProjectChanged) { projectMetaData.SetProjectMetaData(tr.ProjectID); } //PRESCORE: tisExtender.PreScore(this, tr, xmlRepoItem, projectMetaData, tisExtenderState); //SCORE: if (tisExtender.ShouldScore(this, adapter, tr, projectMetaData, tisExtenderState)) { if (tr.AddScores(_tc)) { SetArchiveStrategy(ArchiveStrategy.ArchiveAndInsert); } } //COMPLETENESS STATUS: tr.Opportunity.Completeness = !tr.IsComplete() ? "Partial" : "Complete"; // Validation section. This checks the xml file against several business rules. // If validation fails, the file is moved to a failed files directory. List <ValidationRecord> vrs = new List <ValidationRecord>(); tr.ValidationRecords = adapter.ValidationRecords; if (tr.ValidationRecords.Count == 0) { //POSTSCORE: tisExtender.PostScore(this, tr, xmlRepoItem, projectMetaData, tisExtenderState); // if the startdate is null in the file, it will be set to the statusDate. // Make sure we archive it so that we have a record of the unmodified file. if (tr.Opportunity.OriginalStartDate == DateTime.MinValue) { SetArchiveStrategy(ArchiveStrategy.ArchiveAndInsert); } switch (archiveStrategy) { case ArchiveStrategy.ArchiveAndInsert: //Change the status of old XML file to Arcvhive //insert the new XML file with status as Pprocessing //get the new File id archivedFileID = xmlRepoItem.FileID; xmlRepoItem.FileID = xmlRepositoryBL.InsertAndArchiveXML(xmlRepoItem.FileID, BL.XmlRepository.Location.processing, tr.ToXml(serializerFactory)); break; case ArchiveStrategy.UpdateOriginalFile: // just update the contents of the existing file w/o archiving xmlRepositoryBL.UpdateFileContent(xmlRepoItem.FileID, tr.ToXml(serializerFactory)); break; } vrs = tisExtender.Validate(this, tr, xmlRepoItem, projectMetaData, tisExtenderState, out isFatal, out sendToModifiers); tr.Acknowledged = true; if (((tr.Testee.EntityKey < 0 || tr.Opportunity.OpportunityNumber < 0) && !tr.Opportunity.IsDiscrepancy) || tr.Opportunity.StatusDate == null || tr.ValidationRecords.Count > 0 || isFatal) { // Update db with message messages... ar.SaveResultExceptions(tr, tr.ValidationRecords, xmlRepoItem.FileID); // If fatal then save exception and move to failed folder if (isFatal) { result = QAResult.FailValidation; //AM 8/13/2010: changed this; 1 email will be sent at the end with all // warnings (and errors too if there were any) if emailAlertForWarnings = true // and there were warnings to send. ar.SaveResultExceptions(tr, vrs, xmlRepoItem.FileID); //ar.SaveResultExceptions(tr, vrs, destinationFile, fileName, emailAlertForWarnings); return(result); } } //AM 8/13/2010: same comment as above ar.SaveResultExceptions(tr, vrs, xmlRepoItem.FileID); //ar.SaveResultExceptions(tr, vrs, destinationFile, fileName, emailAlertForWarnings); } else // If there are some XML validation errors then save exception and move to exception folder { result = QAResult.FailValidation; ar.SaveResultExceptions(tr, adapter.ValidationRecords, xmlRepoItem.FileID); return(result); } } else // tr == null { result = QAResult.FailValidation; ar.SaveResultExceptions(tr, adapter.ValidationRecords, xmlRepoItem.FileID); return(result); } // Update the test results after validation has been completed. try { if (isValid) { //PREROUTE: tisExtender.PreRoute(this, adapter, tr, xmlRepoItem, projectMetaData, sendToModifiers, tisExtenderState); // Update XML destinations in case some business rule modified it if (sendToModifiers != null) { foreach (KeyValuePair <SendTo, bool> sendInfo in (SendToModifiersTyped)sendToModifiers) { switch (sendInfo.Key) { case SendTo.DoR: projectMetaData.updateDoR = sendInfo.Value; break; case SendTo.Handscoring: projectMetaData.sendToHandScoring = sendInfo.Value; break; case SendTo.RB: projectMetaData.updateRB = sendInfo.Value; break; } } } if (projectMetaData.updateDoR) { try { List <Target> dorTarget = Target.GetOrderedTargets(tr.ProjectID, Target.TargetClass.DoR); if (dorTarget != null && dorTarget.Count == 1) { dorTarget[0].Send(tr, delegate(object o) { dorRecordId = (long)o; }, projectMetaData.doRAdminID); } } catch (Exception ex) { throw new QAException(String.Format("DoR update failed for fileId: {0}, Message: {1}", xmlRepoItem.FileID, ex.Message), QAException.ExceptionType.General, ex); } } //send to configured Handscoring targets ItemScoringManager.Instance.Send(tr, sendToModifiers); // send to configured targets in order (incl RB) foreach (Target t in Target.GetOrderedTargets(tr.ProjectID, Target.TargetClass.General)) { if (!sendToModifiers.ShouldSend(t.Name)) { continue; } ITargetResult targetResult = t.Send(tr); if (targetResult.Sent) { Logger.Log(true, String.Format("Sent data for FileId: {0} to Target: {1} ({2}).", xmlRepoItem.FileID, t.Name, targetResult.ID ?? "<unspecified>"), EventLogEntryType.Information, false, true); } } //POSTROUTE: tisExtender.PostRoute(this, tr, xmlRepoItem, projectMetaData, tisExtenderState); } // Check if this test need to be merged with something else try { TDSQASystemAPI.TestMerge.TestMerge testMerge = TestMergeConfiguration.Instance.GetTestMerge(tr.Name); if (testMerge != null) { testMerge.CreateCombinedTest(_tc, tr, serializerFactory); } } catch (Exception ex) { throw new QAException(String.Format("TestMerge operation failed for fileId: {0}, Message: {1}", xmlRepoItem.FileID, ex.Message), QAException.ExceptionType.General, ex); } } catch (QAException qae) { //TODO: result = QAResult.FailUpdate; string message = qae.GetExceptionMessage(true); if (message.StartsWith("DoR")) { ar.SaveResultExceptions(tr, "DoR update failed: ", message, xmlRepoItem.FileID); Logger.Log(true, message, EventLogEntryType.Error, false, true); } else if (message.StartsWith("Handscoring")) { ar.SaveResultExceptions(tr, "Handscoring update failed: ", message, xmlRepoItem.FileID); Logger.Log(true, message, EventLogEntryType.Error, false, true); } else if (message.StartsWith("TestMerge")) { ar.SaveResultExceptions(tr, "Test merge operation failed: ", message, xmlRepoItem.FileID); Logger.Log(true, message, EventLogEntryType.Error, false, true); } else if (message.StartsWith("AutoAppeal")) { ar.SaveResultExceptions(tr, "AutoAppeal failed: ", message, xmlRepoItem.FileID); Logger.Log(true, message, EventLogEntryType.Error, false, true); } else { ar.SaveResultExceptions(tr, "Response Bank update failed: ", message, xmlRepoItem.FileID); Logger.Log(true, message, EventLogEntryType.Error, false, true); } return(result); } catch (Exception ex) { result = QAResult.FailUpdate; string message = ex.GetExceptionMessage(true); ar.SaveResultExceptions(tr, "Response Bank update failed: ", message, xmlRepoItem.FileID); Logger.Log(true, message, EventLogEntryType.Error, false, true); return(result); } // Log to TestOpportunityStatus, Update the TDS_QC database, and possibly send to TIS if (tr != null) { try { // Log to TestOpportunityStatus, Update the TDS_QC database ar.SaveResultInfo(tr, xmlRepoItem.FileID, tr.Testee.IsDemo, dorRecordId, archivedFileID, projectMetaData.updateRB); } catch (Exception ex) { result = QAResult.FailUpdate; string message = ex.GetExceptionMessage(true); ar.SaveResultExceptions(tr, "Archive ", ex.Message, xmlRepoItem.FileID); Logger.Log(true, message, EventLogEntryType.Error, false, true); return(result); } //POSTSAVE: tisExtender.PostSave(this, tr, xmlRepoItem, projectMetaData, tisExtenderState); } result = QAResult.Success; } catch (Exception ex) { result = QAResult.Unknown; string message = ex.GetExceptionMessage(true); if (tr != null) { ar.SaveResultExceptions(tr, "QA System Exception:", message, xmlRepoItem.FileID); } else { ar.SaveResultExceptions("QA System Exception:", message, xmlRepoItem.FileID); } Logger.Log(true, message, EventLogEntryType.Error, false, true); } finally { if (!(tr == null || tr.Opportunity == null)) { // We don't want to call back to TDS for scanned paper tests, since they did not originate from TDS. // Just skip w/o logging. if (!tr.Mode.Equals("scanned")) { Boolean accepted = true; string message = null; if (result == QAResult.FailUpdate || result == QAResult.FailValidation || result == QAResult.Unknown || !(tr.PassedAllValidations())) { accepted = false; if (result == QAResult.FailUpdate) { message = "failed validation"; } else if (result == QAResult.FailValidation) { message = "failed while either updating the Response Bank, storing data into the DoR, or invoking the Handscoring webservice"; } else if (result == QAResult.Unknown) { message = "An unknown exception occurred"; } else if (!(tr.PassedAllValidations())) { message = "Failed rules validation"; } } IAcknowledgementTargetFactory ackTargetFactory = AIR.Common.ServiceLocator.Resolve <IAcknowledgementTargetFactory>(); if (ackTargetFactory != null) // ok not to acknowledge I suppose { IAcknowledgementTarget ackTarget = ackTargetFactory.SelectTarget(xmlRepoItem); try { if (ackTarget == null || !ackTarget.Send(new Message(tr.Opportunity.Key, accepted, message), xmlRepoItem)) { Logger.Log(true, String.Format("Acknowledgement not sent for fileID: {0}", xmlRepoItem.FileID), EventLogEntryType.Information, false, true); } } catch (Exception ex) { // allow these to be treated as warnings or errors. If TreatAcknowledgementFailureAsError is set to true, // a failure to send an ACK will result in the file being dumped into the reject bin. // Default behavior is to treat these as warnings. We generally don't want to fail a file just because // we can't send the ACK. Note also that a combo may already have been created (if applicable). bool treatAckfailureAsError = false; if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings["TreatAcknowledgementFailureAsError"]) && Convert.ToBoolean(ConfigurationManager.AppSettings["TreatAcknowledgementFailureAsError"])) { treatAckfailureAsError = true; } // if the file would have otherwise succeeded and there was an exception while attempting to send the ACK and // we're not treating these as warnings, fail the file. if (treatAckfailureAsError && result == QAResult.Success) { result = QAResult.Unknown; } Logger.Log(true, String.Format("Could not send acknowledgement for fileID: {0}, Exception: {1}", xmlRepoItem.FileID, ex.GetExceptionMessage(true)), treatAckfailureAsError ? EventLogEntryType.Error : EventLogEntryType.Warning, false, true); } } } } //Move file to appropriate folder based on the QAResult and log the status accordingly. LogAndCleanup(result, xmlRepoItem.FileID, tr, startDateTime); } return(result); }
public List <ValidationRecord> Validate(QASystem tis, TestResult tr, XmlRepositoryItem xmlRepoItem, ProjectMetaData projectMetaData, ITISExtenderState state, out bool isFatal, out SendToModifiers sendToModifiers) { isFatal = false; sendToModifiers = new SendToModifiers(); return(new List <ValidationRecord>()); }
public void PreRoute(QASystem tis, XMLAdapter adapter, TestResult tr, XmlRepositoryItem xmlRepoItem, ProjectMetaData projectMetaData, SendToModifiers sendToModifiers, ITISExtenderState state) { // do nothing }
public bool ShouldScore(QASystem tis, XMLAdapter adapter, TestResult tr, ProjectMetaData projectMetaData, ITISExtenderState state) { return(true); }
public void PreScore(QASystem tis, TDSQASystemAPI.TestResults.TestResult tr, TDSQASystemAPI.Data.XmlRepositoryItem xmlRepoItem, TDSQASystemAPI.Config.ProjectMetaData projectMetaData, ITISExtenderState state) { //add accommodations if we're supposed to ConfigurationHolder configHolder = ServiceLocator.Resolve <ConfigurationHolder>(); if (tr.Testee != null && configHolder.GetFromMetaData(tr.ProjectID, "Accommodations").Exists(x => x.IntVal.Equals(1))) { bool useAlternateStudentId = false; TesteeAttribute ssid = tr.Testee.GetAttribute("StudentIdentifier", TesteeProperty.PropertyContext.INITIAL); if (ssid == null) { ssid = tr.Testee.GetAttribute("AlternateSSID", TesteeProperty.PropertyContext.INITIAL); useAlternateStudentId = true; } if (ssid == null) { throw new NullReferenceException("Neither StudentIdentifier nor AlternateSSID were found as ExamineeAttributes in the XML file with context = INITIAL. At least one is required to get accommodations from ART. OppID = " + tr.Opportunity.OpportunityID); } List <TesteeRelationship> stateAbbrevsList = tr.Testee.GetRelationships("StateAbbreviation", TesteeProperty.PropertyContext.INITIAL); if (stateAbbrevsList.Count != 1) { throw new MissingMemberException(string.Format("StateAbbreviation ExamineeRelationship with context = INITIAL appeared {0} times, but it was exepected to appear only 1 time. OppID = {1}", stateAbbrevsList.Count, tr.Opportunity.OpportunityID)); } WebService webservice = Settings.WebService["ART"]; if (webservice == null) { throw new NullReferenceException("ART web service is not defined in config file. This is required for getting accommodations from ART"); } XmlDocument doc = new ARTDAL(webservice).GetStudentPackageXML(ssid.Value, stateAbbrevsList[0].Value, useAlternateStudentId); if (doc == null) { throw new NullReferenceException("ART Student package could not be retrieved for OppID " + tr.Opportunity.OpportunityID); } ARTStudentPackage package = new ARTStudentPackage(doc); Dictionary <string, ARTAccommodation> artAccs = package.GetAccommodations(tr.Subject); //TODO: should we throw an exception if no accommodations are found? if (artAccs == null) { return; } //now grab the values from TDS configs DB. Key = type, value = list of accoms. Dictionary <string, List <TestAccomodation> > accomsDict = configHolder.GetTestAccommodations(tis.dbHandleConfig, tr.test.TestName); //now convert this to be key = code, value = list of accoms with distinct type / code Dictionary <string, List <TestAccomodation> > myAccomsDict = new Dictionary <string, List <TestAccomodation> >(StringComparer.InvariantCultureIgnoreCase); foreach (List <TestAccomodation> acclist in accomsDict.Values) { foreach (TestAccomodation acc in acclist) { if (!myAccomsDict.ContainsKey(acc.Code)) { myAccomsDict.Add(acc.Code, new List <TestAccomodation>() { acc }); } //get only the list of distinct accom code / types (this is all that is needed for scoring) if (!myAccomsDict[acc.Code].Any(x => x.Code.Equals(acc.Code) && x.Type.Equals(acc.Type))) { myAccomsDict[acc.Code].Add(acc); } } } //now add new accommodations to the Opportunity combining values from each foreach (ARTAccommodation accom in artAccs.Values) { if (!myAccomsDict.ContainsKey(accom.AccomCode)) { continue; // ART accoms are by subject; it seems conceivable that not every test that the student is eligible for with the same subject would have the same accom configuration } //throw new NullReferenceException(string.Format("ART Accommodation code {0} was not found in TDS Configs DB.", accom.AccomCode)); //add all distinct type/code accommodations. Note that we hardcode segment to 0 foreach (TestAccomodation tdsAccom in myAccomsDict[accom.AccomCode]) { tr.Opportunity.AddRTSAccomodation(tdsAccom.Type, tdsAccom.Description, tdsAccom.Code, 0 /*tdsAccom.Segment*/, ""); } } } }
public void PostSave(QASystem tis, TDSQASystemAPI.TestResults.TestResult tr, TDSQASystemAPI.Data.XmlRepositoryItem xmlRepoItem, TDSQASystemAPI.Config.ProjectMetaData projectMetaData, ITISExtenderState state) { // nothing }
public void PreRoute(QASystem tis, TDSQASystemAPI.TestResults.XMLAdapter adapter, TDSQASystemAPI.TestResults.TestResult tr, TDSQASystemAPI.Data.XmlRepositoryItem xmlRepoItem, TDSQASystemAPI.Config.ProjectMetaData projectMetaData, TDSQASystemAPI.Routing.SendToModifiers sendToModifiers, ITISExtenderState state) { // nothing }
public bool ShouldScore(QASystem tis, TDSQASystemAPI.TestResults.XMLAdapter adapter, TDSQASystemAPI.TestResults.TestResult tr, TDSQASystemAPI.Config.ProjectMetaData projectMetaData, ITISExtenderState state) { // score if it's not a reset or an opp with items still requiring scores (operational, selected, not dropped, and not marked as notForScoring) return(!tr.Opportunity.Status.Equals("reset", StringComparison.InvariantCultureIgnoreCase) && !tr.HasItemsRequiringHandscores(TestResult.ItemOperationalStatus.Operational, true, true, true)); }