//public bool Import( InputEntity input, string envelopeIdentifier, SaveStatus status ) //{ // List<string> messages = new List<string>(); // bool importSuccessfull = false; // EntityServices mgr = new EntityServices(); // //try // //{ // //input = JsonConvert.DeserializeObject<InputEntity>( item.DecodedResource.ToString() ); // string ctid = input.Ctid; // string referencedAtId = input.CtdlId; // LoggingHelper.DoTrace( 5, " name: " + input.Name ); // LoggingHelper.DoTrace( 6, " url: " + input.SubjectWebpage ); // LoggingHelper.DoTrace( 5, " ctid: " + input.Ctid ); // LoggingHelper.DoTrace( 5, " @Id: " + input.CtdlId ); // status.Ctid = ctid; // if ( status.DoingDownloadOnly ) // return true; // if ( !DoesEntityExist( input.Ctid, ref output ) ) // { // output.RowId = Guid.NewGuid(); // } // //re:messages - currently passed to mapping but no errors are trapped?? // // - should use SaveStatus and skip import if errors encountered (vs warnings) // output.Name = input.Name; // output.Description = input.Description; // output.CTID = input.Ctid; // output.CredentialRegistryId = envelopeIdentifier; // output.SubjectWebpage = input.SubjectWebpage; // output.OwningAgentUid = MappingHelper.MapOrganizationReferencesGuid( input.ConditionManifestOf, ref status ); // output.Requires = MappingHelper.FormatConditionProfile( input.Requires, ref status ); // output.Recommends = MappingHelper.FormatConditionProfile( input.Recommends, ref status ); // output.EntryCondition = MappingHelper.FormatConditionProfile( input.EntryConditions, ref status ); // output.Corequisite = MappingHelper.FormatConditionProfile( input.Corequisite, ref status ); // output.Renewal = MappingHelper.FormatConditionProfile( input.Renewal, ref status ); // status.DocumentId = output.Id; // status.DocumentRowId = output.RowId; // //=== if any messages were encountered treat as warnings for now // if ( messages.Count > 0 ) // status.SetMessages( messages, true ); // importSuccessfull = mgr.Import( output, ref status ); // //just in case // if ( status.HasErrors ) // importSuccessfull = false; // //if record was added to db, add to/or set EntityResolution as resolved // int ierId = new ImportManager().Import_EntityResolutionAdd( referencedAtId, // ctid, // CodesManager.ENTITY_TYPE_CONDITION_MANIFEST, // output.RowId, // output.Id, // false, // ref messages, // output.Id > 0 ); // return importSuccessfull; //} public bool ImportV3(string payload, string envelopeIdentifier, SaveStatus status) { InputEntityV3 input = new InputEntityV3(); var bnodes = new List <BNodeV3>(); var mainEntity = new Dictionary <string, object>(); //status.AddWarning( "The resource uses @graph and is not handled yet" ); Dictionary <string, object> dictionary = RegistryServices.JsonToDictionary(payload); object graph = dictionary["@graph"]; //serialize the graph object var glist = JsonConvert.SerializeObject(graph); //parse graph in to list of objects JArray graphList = JArray.Parse(glist); int cntr = 0; foreach (var item in graphList) { cntr++; if (cntr == 1) { var main = item.ToString(); //may not use this. Could add a trace method mainEntity = RegistryServices.JsonToDictionary(main); input = JsonConvert.DeserializeObject <InputEntityV3>(main); } else { var bn = item.ToString(); bnodes.Add(JsonConvert.DeserializeObject <BNodeV3>(bn)); } } List <string> messages = new List <string>(); bool importSuccessfull = false; EntityServices mgr = new EntityServices(); MappingHelperV3 helper = new MappingHelperV3(19); helper.entityBlankNodes = bnodes; helper.CurrentEntityCTID = input.CTID; helper.CurrentEntityName = input.Name.ToString(); //try //{ //input = JsonConvert.DeserializeObject<InputEntity>( item.DecodedResource.ToString() ); string ctid = input.CTID; string referencedAtId = input.CtdlId; LoggingHelper.DoTrace(5, " name: "+ input.Name.ToString()); LoggingHelper.DoTrace(6, " url: "+ input.SubjectWebpage); LoggingHelper.DoTrace(5, " ctid: "+ input.CTID); LoggingHelper.DoTrace(5, " @Id: "+ input.CtdlId); status.Ctid = ctid; if (status.DoingDownloadOnly) { return(true); } try { if (!DoesEntityExist(input.CTID, ref output)) { output.RowId = Guid.NewGuid(); LoggingHelper.DoTrace(1, string.Format(thisClassName + ".ImportV3(). Record was NOT found using CTID: '{0}'", input.CTID)); } else { LoggingHelper.DoTrace(1, string.Format(thisClassName + ".ImportV3(). Found record: '{0}' using CTID: '{1}'", input.Name, input.CTID)); } helper.currentBaseObject = output; //re:messages - currently passed to mapping but no errors are trapped?? // - should use SaveStatus and skip import if errors encountered (vs warnings) output.Name = helper.HandleLanguageMap(input.Name, output, "Name"); output.Description = helper.HandleLanguageMap(input.Description, output, "Description"); output.CTID = input.CTID; output.CredentialRegistryId = envelopeIdentifier; output.SubjectWebpage = input.SubjectWebpage; output.OwningAgentUid = helper.MapOrganizationReferencesGuid("ConditionManifest.OwningAgentUid", input.ConditionManifestOf, ref status); helper.CurrentOwningAgentUid = output.OwningAgentUid; output.Requires = helper.FormatConditionProfile(input.Requires, ref status); output.Recommends = helper.FormatConditionProfile(input.Recommends, ref status); output.EntryCondition = helper.FormatConditionProfile(input.EntryConditions, ref status); output.Corequisite = helper.FormatConditionProfile(input.Corequisite, ref status); output.Renewal = helper.FormatConditionProfile(input.Renewal, ref status); status.DocumentId = output.Id; status.DocumentRowId = output.RowId; //=== if any messages were encountered treat as warnings for now if (messages.Count > 0) { status.SetMessages(messages, true); } importSuccessfull = mgr.Import(output, ref status); //just in case if (status.HasErrors) { importSuccessfull = false; } //if record was added to db, add to/or set EntityResolution as resolved int ierId = new ImportManager().Import_EntityResolutionAdd(referencedAtId, ctid, CodesManager.ENTITY_TYPE_CONDITION_MANIFEST, output.RowId, output.Id, false, ref messages, output.Id > 0); } catch (Exception ex) { LoggingHelper.LogError(ex, string.Format("CostManifest ImportV3. Exception encountered for CTID: {0}", ctid), false, "CostManifest Import exception"); } finally { } return(importSuccessfull); }
public bool ImportV3(string payload, string envelopeIdentifier, SaveStatus status) { //instantiate the input document (credential) InputEntityV3 input = new InputEntityV3(); var bnodes = new List <BNode>(); var mainEntity = new Dictionary <string, object>(); //map payload to a dictionary Dictionary <string, object> dictionary = RegistryServices.JsonToDictionary(payload); //get the @graph property object graph = dictionary["@graph"]; //serialize the graph object var glist = JsonConvert.SerializeObject(graph); //parse graph in to list of objects JArray graphList = JArray.Parse(glist); int cntr = 0; foreach (var item in graphList) { cntr++; if (cntr == 1) { var main = item.ToString(); //may not use this. Could add a trace method //mainEntity = RegistryServices.JsonToDictionary( main ); input = JsonConvert.DeserializeObject <InputEntityV3>(main); } else { //save blank nodes - typically reference organizations var bn = item.ToString(); bnodes.Add(JsonConvert.DeserializeObject <BNode>(bn)); } } List <string> messages = new List <string>(); bool importSuccessfull = false; EntityServices mgr = new EntityServices(); MappingHelperV3 helper = new MappingHelperV3(); helper.entityBlankNodes = bnodes; status.EnvelopeId = envelopeIdentifier; try { //input = JsonConvert.DeserializeObject<InputEntity>( item.DecodedResource.ToString() ); string ctid = input.Ctid; string referencedAtId = input.CtdlId; LoggingHelper.DoTrace(5, " name: "+ input.Name.ToString()); LoggingHelper.DoTrace(6, " url: "+ input.SubjectWebpage); LoggingHelper.DoTrace(5, " ctid: "+ input.Ctid); LoggingHelper.DoTrace(6, " @Id: "+ input.CtdlId); status.Ctid = ctid; if (status.DoingDownloadOnly) { return(true); } if (!DoesEntityExist(input.Ctid, ref output)) { //set the rowid now, so that can be referenced as needed output.RowId = Guid.NewGuid(); } helper.currentBaseObject = output; //start with language and may use with language maps foreach (var l in input.InLanguage) { if (!string.IsNullOrWhiteSpace(l)) { var language = CodesManager.GetLanguage(l); output.InLanguageCodeList.Add(new TextValueProfile() { CodeId = language.CodeId, TextTitle = language.Name, TextValue = language.Value }); } } if (input.InLanguage.Count > 0) { //could use to alter helper.DefaultLanguage } output.Name = helper.HandleLanguageMap(input.Name, output, "Name"); output.Description = helper.HandleLanguageMap(input.Description, output, "Description"); output.SubjectWebpage = input.SubjectWebpage; output.CTID = input.Ctid; //warning this gets set to blank if doing a manual import by ctid output.CredentialRegistryId = envelopeIdentifier; output.CredentialStatusType = helper.MapCAOToEnumermation(input.CredentialStatusType); output.DateEffective = input.DateEffective; output.AlternateNames = helper.MapToTextValueProfile(input.AlternateName, output, "AlternateName"); output.ImageUrl = input.Image; output.CredentialTypeSchema = input.CredentialType; output.AvailabilityListing = helper.MapListToString(input.AvailabilityListing); output.AvailableOnlineAt = helper.MapListToString(input.AvailableOnlineAt); output.CredentialId = input.CredentialId; //TODO - develope entity for IdentitifierValue output.VersionIdentifier = helper.MapIdentifierValueListToString(input.VersionIdentifier); output.VersionIdentifierList = helper.MapIdentifierValueList(input.VersionIdentifier); output.CodedNotation = input.CodedNotation; output.ISICV4 = input.IsicV4; output.ProcessStandards = input.ProcessStandards; output.ProcessStandardsDescription = helper.HandleLanguageMap(input.ProcessStandardsDescription, output, "ProcessStandardsDescription"); output.LatestVersion = input.LatestVersion; output.PreviousVersion = input.PreviousVersion; output.NextVersion = input.NextVersion; output.SupersededBy = input.SupersededBy; output.Supersedes = input.Supersedes; output.Subject = helper.MapCAOListToTextValueProfile(input.Subject, CodesManager.PROPERTY_CATEGORY_SUBJECT); //occupations //output.Occupation = helper.MapCAOListToEnumermation( input.OccupationType ); //actually used by import output.Occupations = helper.MapCAOListToCAOProfileList(input.OccupationType); //just append alternative items. Ensure empty lists are ignored output.Occupations.AddRange(helper.AppendLanguageMapListToCAOProfileList(input.AlternativeOccupationType)); //skip if no occupations if (output.Occupations.Count() == 0 && UtilityManager.GetAppKeyValue("skipCredImportIfNoOccupations", false)) { //LoggingHelper.DoTrace( 2, string.Format( " ***Skipping Credential# {0}, {1} as it has no occupations and this is a special run.", output.Id, output.Name ) ); //return true; } //Industries output.Industries = helper.MapCAOListToCAOProfileList(input.IndustryType); output.Industries.AddRange(helper.AppendLanguageMapListToCAOProfileList(input.AlternativeIndustryType)); //naics output.Naics = input.Naics; output.InstructionalProgramTypes = helper.MapCAOListToCAOProfileList(input.InstructionalProgramType); output.InstructionalProgramTypes.AddRange(helper.AppendLanguageMapListToCAOProfileList(input.AlternativeInstructionalProgramType)); // //will want a custom method to lookup the rating NavyServices nsrvs = new NavyServices(); output.NavyRating = NavyServices.MapRatingsListToEnumermation(input.HasRating); output.NavyRatingType.AddRange(nsrvs.MapCAOListToCAOProfileList(input.HasRating, ref messages)); // output.Keyword = helper.MapToTextValueProfile(input.Keyword, output, "Keyword"); output.Jurisdiction = helper.MapToJurisdiction(input.Jurisdiction, ref status); //CopyrightHolder - expecting single; will need to expand output.CopyrightHolder = helper.MapOrganizationReferencesGuid("Credential.CopyrightHolder", input.CopyrightHolder, ref status); //CAO output.AudienceLevelType = helper.MapCAOListToEnumermation(input.AudienceLevelType); // output.AudienceType = helper.MapCAOListToEnumermation(input.AudienceType); output.DegreeConcentration = helper.MapCAOListToTextValueProfile(input.DegreeConcentration, CodesManager.PROPERTY_CATEGORY_DEGREE_CONCENTRATION); output.DegreeMajor = helper.MapCAOListToTextValueProfile(input.DegreeMajor, CodesManager.PROPERTY_CATEGORY_DEGREE_MAJOR); output.DegreeMinor = helper.MapCAOListToTextValueProfile(input.DegreeMinor, CodesManager.PROPERTY_CATEGORY_DEGREE_MINOR); output.AssessmentDeliveryType = helper.MapCAOListToEnumermation(input.AssessmentDeliveryType); output.LearningDeliveryType = helper.MapCAOListToEnumermation(input.LearningDeliveryType); //EstimatedCost //will need to format, all populate Entity.RelatedCosts (for bubble up) - actually this would be for asmts, and lopps output.EstimatedCost = helper.FormatCosts(input.EstimatedCost, ref status); //EstimatedDuration output.EstimatedDuration = helper.FormatDuration(input.EstimatedDuration, ref status); output.RenewalFrequency = helper.FormatDurationItem(input.RenewalFrequency); //conditions output.Requires = helper.FormatConditionProfile(input.Requires, ref status); output.Recommends = helper.FormatConditionProfile(input.Recommends, ref status); output.Renewal = helper.FormatConditionProfile(input.Renewal, ref status); output.Corequisite = helper.FormatConditionProfile(input.Corequisite, ref status); output.Revocation = helper.FormatRevocationProfile(input.Revocation, ref status); //connections output.AdvancedStandingFrom = helper.FormatConditionProfile(input.AdvancedStandingFrom, ref status); output.AdvancedStandingFor = helper.FormatConditionProfile(input.IsAdvancedStandingFor, ref status); output.PreparationFrom = helper.FormatConditionProfile(input.PreparationFrom, ref status); output.IsPreparationFor = helper.FormatConditionProfile(input.IsPreparationFor, ref status); output.IsRequiredFor = helper.FormatConditionProfile(input.IsRequiredFor, ref status); output.IsRecommendedFor = helper.FormatConditionProfile(input.IsRecommendedFor, ref status); //common conditions output.ConditionManifestIds = helper.MapEntityReferences(input.CommonConditions, CodesManager.ENTITY_TYPE_CONDITION_MANIFEST, CodesManager.ENTITY_TYPE_CREDENTIAL, ref status); //common costs output.CostManifestIds = helper.MapEntityReferences(input.CommonCosts, CodesManager.ENTITY_TYPE_COST_MANIFEST, CodesManager.ENTITY_TYPE_CREDENTIAL, ref status); //HasPart/IsPart //WARNING - these methods assume all parts are the same type - the provided thisEntityTypeId. AT THIS TIME, THE PARTS SHOULD ALL BE CREDENTIALS output.HasPartIds = helper.MapEntityReferences(input.HasPart, thisEntityTypeId, ref status); output.IsPartOfIds = helper.MapEntityReferences(input.IsPartOf, thisEntityTypeId, ref status); //Process profiles output.AdministrationProcess = helper.FormatProcessProfile(input.AdministrationProcess, ref status); output.DevelopmentProcess = helper.FormatProcessProfile(input.DevelopmentProcess, ref status); output.MaintenanceProcess = helper.FormatProcessProfile(input.MaintenanceProcess, ref status); output.AppealProcess = helper.FormatProcessProfile(input.AppealProcess, ref status); output.ComplaintProcess = helper.FormatProcessProfile(input.ComplaintProcess, ref status); output.ReviewProcess = helper.FormatProcessProfile(input.ReviewProcess, ref status); output.RevocationProcess = helper.FormatProcessProfile(input.RevocationProcess, ref status); //FinancialAssistance output.FinancialAssistance = helper.FormatFinancialAssistance(input.FinancialAssistance, ref status); output.Addresses = helper.FormatAvailableAtAddresses(input.AvailableAt, ref status); //BYs output.AccreditedBy = helper.MapOrganizationReferenceGuids("Credential.AccreditedBy", input.AccreditedBy, ref status); output.ApprovedBy = helper.MapOrganizationReferenceGuids("Credential.ApprovedBy", input.ApprovedBy, ref status); output.OfferedBy = helper.MapOrganizationReferenceGuids("Credential.OfferedBy", input.OfferedBy, ref status); //note need to set output.OwningAgentUid to the first entry output.OwnedBy = helper.MapOrganizationReferenceGuids("Credential.OwnedBy", input.OwnedBy, ref status); if (output.OwnedBy != null && output.OwnedBy.Count > 0) { output.OwningAgentUid = output.OwnedBy[0]; } else { //add warning? if (output.OfferedBy == null && output.OfferedBy.Count == 0) { status.AddWarning("document doesn't have an owning or offering organization."); } } output.RecognizedBy = helper.MapOrganizationReferenceGuids("Credential.RecognizedBy", input.RecognizedBy, ref status); output.RegulatedBy = helper.MapOrganizationReferenceGuids("Credential.RegulatedBy", input.RegulatedBy, ref status); output.RevokedBy = helper.MapOrganizationReferenceGuids("Credential.RevokedBy", input.RevokedBy, ref status); output.RenewedBy = helper.MapOrganizationReferenceGuids("Credential.RenewedBy", input.RenewedBy, ref status); //INs output.AccreditedIn = helper.MapToJurisdiction(input.AccreditedIn, ref status); output.ApprovedIn = helper.MapToJurisdiction(input.ApprovedIn, ref status); output.ApprovedIn = helper.MapToJurisdiction(input.ApprovedIn, ref status); output.RecognizedIn = helper.MapToJurisdiction(input.RecognizedIn, ref status); output.RegulatedIn = helper.MapToJurisdiction(input.RegulatedIn, ref status); output.RevokedIn = helper.MapToJurisdiction(input.RevokedIn, ref status); output.RenewedIn = helper.MapToJurisdiction(input.RenewedIn, ref status); //=== if any messages were encountered treat as warnings for now if (messages.Count > 0) { status.SetMessages(messages, true); } //just in case check if entity added since start if (output.Id == 0) { ThisEntity entity = EntityServices.GetByCtid(ctid); if (entity != null && entity.Id > 0) { output.Id = entity.Id; output.RowId = entity.RowId; } } //save the data importSuccessfull = mgr.Import(output, ref status); status.DocumentId = output.Id; status.DetailPageUrl = string.Format("~/credential/{0}", output.Id); status.DocumentRowId = output.RowId; //if record was added to db, add to/or set EntityResolution as resolved int ierId = new ImportManager().Import_EntityResolutionAdd(referencedAtId, ctid, CodesManager.ENTITY_TYPE_CREDENTIAL, output.RowId, output.Id, (output.Id > 0), ref messages, output.Id > 0); //just in case if (status.HasErrors) { importSuccessfull = false; } } catch (Exception ex) { LoggingHelper.LogError(ex, string.Format("Exception encountered in envelopeId: {0}", envelopeIdentifier), false, "workIT Import exception"); } return(importSuccessfull); }
public bool ImportV3(string payload, string envelopeIdentifier, SaveStatus status) { InputEntityV3 input = new InputEntityV3(); var bnodes = new List <BNodeV3>(); var mainEntity = new Dictionary <string, object>(); //status.AddWarning( "The resource uses @graph and is not handled yet" ); Dictionary <string, object> dictionary = RegistryServices.JsonToDictionary(payload); object graph = dictionary["@graph"]; //serialize the graph object var glist = JsonConvert.SerializeObject(graph); //parse graph in to list of objects JArray graphList = JArray.Parse(glist); int cntr = 0; foreach (var item in graphList) { cntr++; if (cntr == 1) { var main = item.ToString(); //may not use this. Could add a trace method mainEntity = RegistryServices.JsonToDictionary(main); input = JsonConvert.DeserializeObject <InputEntityV3>(main); } else { var bn = item.ToString(); bnodes.Add(JsonConvert.DeserializeObject <BNodeV3>(bn)); } } List <string> messages = new List <string>(); bool importSuccessfull = false; EntityServices mgr = new EntityServices(); MappingHelperV3 helper = new MappingHelperV3(); helper.entityBlankNodes = bnodes; string ctid = input.Ctid; string referencedAtId = input.CtdlId; LoggingHelper.DoTrace(5, " name: "+ input.Name.ToString()); LoggingHelper.DoTrace(6, " url: "+ input.CostDetails); LoggingHelper.DoTrace(5, " ctid: "+ input.Ctid); LoggingHelper.DoTrace(5, " @Id: "+ input.CtdlId); status.Ctid = ctid; if (status.DoingDownloadOnly) { return(true); } if (!DoesEntityExist(input.Ctid, ref output)) { output.RowId = Guid.NewGuid(); } helper.currentBaseObject = output; output.Name = helper.HandleLanguageMap(input.Name, output, "Name"); output.Description = helper.HandleLanguageMap(input.Description, output, "Description"); output.CTID = input.Ctid; output.CredentialRegistryId = envelopeIdentifier; output.CostDetails = input.CostDetails; output.OwningAgentUid = helper.MapOrganizationReferencesGuid("CostManifest.OwningAgentUid", input.CostManifestOf, ref status); output.StartDate = helper.MapDate(input.StartDate, "StartDate", ref status); output.EndDate = helper.MapDate(input.EndDate, "StartDate", ref status); output.EstimatedCosts = helper.FormatCosts(input.EstimatedCost, ref status); status.DocumentId = output.Id; status.DocumentRowId = output.RowId; //=== if any messages were encountered treat as warnings for now if (messages.Count > 0) { status.SetMessages(messages, true); } importSuccessfull = mgr.Import(output, ref status); //just in case if (status.HasErrors) { importSuccessfull = false; } //if record was added to db, add to/or set EntityResolution as resolved int ierId = new ImportManager().Import_EntityResolutionAdd(referencedAtId, ctid, CodesManager.ENTITY_TYPE_COST_MANIFEST, output.RowId, output.Id, false, ref messages, output.Id > 0); return(importSuccessfull); }