private void ReplacePathwayComponentRelationships(int componentNbr, Guid parentComponentUid, List <Guid> input, Pathway pathway, int pathwayComponentRelationship, string property, ref SaveStatus status) { var pclist = new List <PathwayComponent>(); foreach (var pcGuid in input) { //look up component var pc = PathwayComponentManager.Get(pcGuid, PathwayComponentManager.componentActionOfNone); if (pc != null && pc.Id > 0) { pclist.Add(pc); } else { //??? status.AddError(string.Format("Component: {0}. Error unable to find PathwayComponent for relationship: {1} using pvGUID: {1}.", componentNbr, pathwayComponentRelationship, pcGuid)); } } //do replace if (!epcmgr.Replace(parentComponentUid, pathwayComponentRelationship, pclist, ref status)) { //nothing more to report? //status.AddError( string.Format( "Component: {0}, Issue encountered replacing {1} component relationships.", componentNbr, property )); } }
private int HandleComponentCondition(PathwayComponentCondition input, Pathway pathway, PathwayComponent component, ref SaveStatus status) { int newId = 0; List <string> messages = new List <string>(); string statusMessage = ""; input.ParentComponentId = component.Id; if (pccm.Save(input, ref messages)) { newId = input.Id; activityMgr.SiteActivityAdd(new SiteActivity() { ActivityType = "PathwayComponent", Activity = "Import", Event = "Add", Comment = string.Format("Added PathwayComponentCondition via Import: '{0}' for Component: '{1}'", input.Name, component.Name), ActivityObjectId = newId, }); } else { status.AddErrorRange(messages); } if (newId == 0 || (!string.IsNullOrWhiteSpace(statusMessage) && statusMessage != "successful")) { status.AddError(string.Format("Row: Issue encountered updating pathway ComponentCondition: {0} for Component: '{1}': {2}", input.Name, component.Name, statusMessage)); return(0); } //================================================== //handle target components - better organization to move this to HandleComponentCondition since all components should now exist List <PathwayComponent> profiles = new List <PathwayComponent>(); messages = new List <string>(); foreach (var tc in input.HasTargetComponentList) { var targetComponent = PathwayComponentManager.Get(tc); if (targetComponent == null || targetComponent.Id == 0) { //shouldn't happen here - although the add attempt could have failed? status.AddError(string.Format("The target pathway component: {0} for ConditionComponent: {1} was not found. This could have been due the an issue adding the component - which should have resulted in an earlier error message.", tc, input.Name)); continue; } profiles.Add(targetComponent); } //now replace relationships if (!epcmgr.Replace(input.RowId, PathwayComponent.PathwayComponentRelationship_TargetComponent, profiles, ref status)) { //status.AddErrorRange( messages ); } return(newId); }
public static TopLevelObject GetEntityAsTopLevelObject(Guid uid) { TopLevelObject tlo = new TopLevelObject(); var entity = EntityManager.GetEntity(uid, false); if (entity == null || entity.Id == 0) { return(null); } // if (entity.EntityTypeId == CodesManager.ENTITY_TYPE_CREDENTIAL) { //actually should return some type info tlo = CredentialManager.GetBasic(entity.EntityBaseId); tlo.EntityTypeId = entity.EntityTypeId; } else if (entity.EntityTypeId == CodesManager.ENTITY_TYPE_ORGANIZATION) { tlo = OrganizationManager.GetBasics(entity.EntityUid); tlo.EntityTypeId = entity.EntityTypeId; } else if (entity.EntityTypeId == CodesManager.ENTITY_TYPE_ASSESSMENT_PROFILE) { tlo = AssessmentManager.GetBasic(entity.EntityBaseId); tlo.EntityTypeId = entity.EntityTypeId; } else if (entity.EntityTypeId == CodesManager.ENTITY_TYPE_LEARNING_OPP_PROFILE) { tlo = LearningOpportunityManager.GetBasic(entity.EntityBaseId); tlo.EntityTypeId = entity.EntityTypeId; } else if (entity.EntityTypeId == CodesManager.ENTITY_TYPE_PATHWAY) { tlo = PathwayManager.GetBasic(entity.EntityBaseId); tlo.EntityTypeId = entity.EntityTypeId; } else if (entity.EntityTypeId == CodesManager.ENTITY_TYPE_PATHWAY_COMPONENT) { tlo = PathwayComponentManager.Get(entity.EntityBaseId); tlo.EntityTypeId = entity.EntityTypeId; } else if (entity.EntityTypeId == CodesManager.ENTITY_TYPE_PATHWAY_SET) { tlo = PathwaySetManager.Get(entity.EntityBaseId); tlo.EntityTypeId = entity.EntityTypeId; } else if (entity.EntityTypeId == CodesManager.ENTITY_TYPE_TRANSFER_VALUE_PROFILE) { tlo = TransferValueProfileManager.Get(entity.EntityBaseId); tlo.EntityTypeId = entity.EntityTypeId; } return(tlo); }
// #endregion #region ComponentRetrievals public static PathwayComponent GetComponentByCtid(string ctid) { PathwayComponent entity = new PathwayComponent(); if (string.IsNullOrWhiteSpace(ctid)) { return(entity); } return(PathwayComponentManager.GetByCtid(ctid)); }
private bool DoesComponentExist(PathwayComponent input, string pathwayCTID, ref PathwayComponent record) { bool isFound = false; var exists = PathwayComponentManager.GetByCtid(input.CTID); if (exists != null && exists.Id > 0) { record = exists; isFound = true; } return(isFound); }
private void ReplacePathwayToPathwayComponentRelationships(List <Guid> input, Pathway pathway, int pathwayComponentRelationship, string property, ref SaveStatus status) { var pclist = new List <PathwayComponent>(); foreach (var pcGuid in input) { //look up component var pc = PathwayComponentManager.Get(pcGuid, PathwayComponentManager.componentActionOfNone); if (pc != null && pc.Id > 0) { pclist.Add(pc); } else { //??? status.AddError(string.Format("ReplacePathwayToPathwayComponentRelationships. Error unable to find record for Pathway.Component using Guid: {0}, for relationship: {1}.", pcGuid, pathwayComponentRelationship)); } } //do replace if (!epcmgr.Replace(pathway.RowId, pathwayComponentRelationship, pclist, ref status)) { //status.AddErrorRange( string.Format( "Row: {0}, Issue encountered replacing {1} component relationships.", currentRowNbr, property ), messages ); } }
public static int ResolveEntityByRegistryAtId(string referencedAtId, int entityTypeId, ref SaveStatus status, ref bool isResolved) { Guid entityUid = Guid.NewGuid(); int newEntityId = 0; string ctid = ""; List <string> messages = new List <string>(); //test direct, and fall back to by ctid?? //should only handle Uri's for now if (referencedAtId.Trim().ToLower().IndexOf("http") == 0) { //should probably ensure a registry url ctid = ExtractCtid(referencedAtId.Trim()); LoggingHelper.DoTrace(7, string.Format("ResolutionServices.ResolveEntityByRegistryAtId: EntityTypeId: {0}, referencedAtId: {1} ", entityTypeId, referencedAtId)); EM.Import_EntityResolution item = ImportManager.Import_EntityResolution_GetById(referencedAtId); if (item != null && item.Id > 0 && (item.EntityBaseId ?? 0) > 0) { isResolved = item.IsResolved != null ? ( bool )item.IsResolved : false; //need to make sure valid //actually should always be valid //if ( BaseFactory.IsGuidValid( item.EntityUid ) ) return((int)item.EntityBaseId); } else { LoggingHelper.DoTrace(6, string.Format("ResolutionServices. **FAILED** ResolveEntityByRegistryAtId: EntityTypeId: {0}, target.CtdlId: {1}. Trying with CTID: {2}", entityTypeId, referencedAtId, ctid)); if (IsCtidValid(ctid, ref messages)) { item = ImportManager.Import_EntityResolution_GetByCtid(ctid); if (item != null && item.Id > 0 && (item.EntityBaseId ?? 0) > 0) { isResolved = item.IsResolved != null ? ( bool )item.IsResolved : false; return(( int )item.EntityBaseId); } } } } else { ctid = ExtractCtid(referencedAtId.Trim()); LoggingHelper.DoTrace(7, string.Format("ResolutionServices.ResolveEntityByRegistryAtId. referencedAtId appears to be a ctid EntityTypeId: {0}, referencedAtId: {1}, ctid: {2} ", entityTypeId, referencedAtId, ctid)); if (IsCtidValid(ctid, ref messages)) { EM.Import_EntityResolution item2 = ImportManager.Import_EntityResolution_GetByCtid(ctid); if (item2 != null && item2.Id > 0 && (item2.EntityBaseId ?? 0) > 0) { isResolved = item2.IsResolved != null ? ( bool )item2.IsResolved : false; return(( int )item2.EntityBaseId); } else { LoggingHelper.DoTrace(5, string.Format("ResolutionServices.ResolveEntityByRegistryAtId. DID NOT RESOLVE VIA CTID referencedAtId appears to be a ctid EntityTypeId: {0}, ctid: {2} ", entityTypeId, referencedAtId, ctid)); } } } //add an import entry - need to do the base first ImportManager importManager = new ImportManager(); string statusMsg = ""; if (entityTypeId == CodesManager.ENTITY_TYPE_CREDENTIAL) { newEntityId = new CredentialManager().AddPendingRecord(entityUid, ctid, referencedAtId, ref statusMsg); if (newEntityId == 0) { //need to log, and reset status.AddError(statusMsg); //need to know what property would need to be fixed - really shouldn't happen entityUid = new Guid(); } } else if (entityTypeId == CodesManager.ENTITY_TYPE_ASSESSMENT_PROFILE) { newEntityId = new AssessmentManager().AddPendingRecord(entityUid, ctid, referencedAtId, ref statusMsg); if (newEntityId == 0) { //need to log, and reset status.AddError(statusMsg); //need to know what property would need to be fixed - really shouldn't happen entityUid = new Guid(); } } else if (entityTypeId == CodesManager.ENTITY_TYPE_LEARNING_OPP_PROFILE) { newEntityId = new LearningOpportunityManager().AddPendingRecord(entityUid, ctid, referencedAtId, ref statusMsg); if (newEntityId == 0) { //need to log, and reset status.AddError(statusMsg); //need to know what property would need to be fixed - really shouldn't happen entityUid = new Guid(); } } else if (entityTypeId == CodesManager.ENTITY_TYPE_COST_MANIFEST) { newEntityId = new CostManifestManager().AddPendingRecord(entityUid, ctid, referencedAtId, ref statusMsg); if (newEntityId == 0) { //need to log, and reset status.AddError(statusMsg); //need to know what property would need to be fixed - really shouldn't happen entityUid = new Guid(); } } else if (entityTypeId == CodesManager.ENTITY_TYPE_CONDITION_MANIFEST) { newEntityId = new ConditionManifestManager().AddPendingRecord(entityUid, ctid, referencedAtId, ref statusMsg); if (newEntityId == 0) { //need to log, and reset status.AddError(statusMsg); //need to know what property would need to be fixed - really shouldn't happen entityUid = new Guid(); } } else if (entityTypeId == CodesManager.ENTITY_TYPE_PATHWAY) { newEntityId = new PathwayManager().AddPendingRecord(entityUid, ctid, referencedAtId, ref statusMsg); if (newEntityId == 0) { //need to log, and reset status.AddError(statusMsg); //need to know what property would need to be fixed - really shouldn't happen entityUid = new Guid(); } } else if (entityTypeId == CodesManager.ENTITY_TYPE_PATHWAY_COMPONENT) { newEntityId = new PathwayComponentManager().AddPendingRecord(entityUid, ctid, referencedAtId, ref statusMsg); if (newEntityId == 0) { //need to log, and reset status.AddError(statusMsg); //need to know what property would need to be fixed - really shouldn't happen entityUid = new Guid(); } } else if (entityTypeId == CodesManager.ENTITY_TYPE_COMPETENCY_FRAMEWORK) { //actually should not happen - confirm the cf must exist or will be rejected by API newEntityId = new CompetencyFrameworkManager().AddPendingRecord(entityUid, ctid, referencedAtId, ref statusMsg); if (newEntityId == 0) { //need to log, and reset status.AddError(statusMsg); //need to know what property would need to be fixed - really shouldn't happen entityUid = new Guid(); } } else if (entityTypeId == CodesManager.ENTITY_TYPE_TRANSFER_VALUE_PROFILE) { //actually should not happen - confirm the tvp must exist or will be rejected by API newEntityId = new TransferValueProfileManager().AddPendingRecord(entityUid, ctid, referencedAtId, ref statusMsg); if (newEntityId == 0) { //need to log, and reset status.AddError(statusMsg); //need to know what property would need to be fixed - really shouldn't happen entityUid = new Guid(); } } // if (newEntityId > 0) { int id = importManager.Import_EntityResolutionAdd(referencedAtId, ctid, entityTypeId, entityUid, newEntityId, false, ref messages, true); //need to create a placeholder if (id == 0) { status.AddError("Error - failed to add Import_EntityResolution for " + referencedAtId); status.AddWarningRange(messages); //this may be wiping out newEntityId //return 0; } } return(newEntityId); }
public static Guid ResolveEntityByRegistryAtIdToGuid(string property, string referencedAtId, int entityTypeId, ref SaveStatus status, ref bool isResolved) { Guid entityUid = new Guid(); string ctid = ""; int newEntityId = 0; if (string.IsNullOrWhiteSpace(referencedAtId)) { return(entityUid); } List <string> messages = new List <string>(); //test direct, and fall back to by ctid?? //should only handle Uri's for now if (referencedAtId.Trim().ToLower().IndexOf("http") == 0) { //should probably ensure a registry url ctid = ExtractCtid(referencedAtId.Trim()); if (ctid == "ce-fa6c139f-0615-401f-9920-6ec8c445baca") { } EM.Import_EntityResolution item = ImportManager.Import_EntityResolution_GetById(referencedAtId); if (item != null && item.Id > 0) { isResolved = item.IsResolved != null ? ( bool )item.IsResolved : false; //need to make sure valid //actually should always be valid //if ( BaseFactory.IsGuidValid( item.EntityUid ) ) //20-07-30 mparsons - why is EntityUid returned here? //check this return(( Guid )item.EntityUid); } else { if (IsCtidValid(ctid, ref messages)) { item = ImportManager.Import_EntityResolution_GetByCtid(ctid); if (item != null && item.Id > 0) { isResolved = item.IsResolved != null ? ( bool )item.IsResolved : false; return(( Guid )item.EntityUid); } } } } else { ctid = ExtractCtid(referencedAtId.Trim()); if (IsCtidValid(ctid, ref messages)) { EM.Import_EntityResolution item2 = ImportManager.Import_EntityResolution_GetByCtid(ctid); if (item2 != null && item2.Id > 0) { isResolved = item2.IsResolved != null ? ( bool )item2.IsResolved : false; return(( Guid )item2.EntityUid); } } } //add an import entry ImportManager importManager = new ImportManager(); entityUid = Guid.NewGuid(); string statusMsg = ""; if (entityTypeId == CodesManager.ENTITY_TYPE_CREDENTIAL) { newEntityId = new CredentialManager().AddPendingRecord(entityUid, ctid, referencedAtId, ref statusMsg); if (newEntityId == 0) { //need to log, and reset status.AddError("Credential Add Pending failed for: " + property + ". " + statusMsg); entityUid = new Guid(); } } else if (entityTypeId == CodesManager.ENTITY_TYPE_ASSESSMENT_PROFILE) { newEntityId = new AssessmentManager().AddPendingRecord(entityUid, ctid, referencedAtId, ref statusMsg); if (newEntityId == 0) { //need to log, and reset status.AddError("Assessment Add Pending failed for: " + property + ". " + statusMsg); entityUid = new Guid(); } } else if (entityTypeId == CodesManager.ENTITY_TYPE_LEARNING_OPP_PROFILE) { newEntityId = new LearningOpportunityManager().AddPendingRecord(entityUid, ctid, referencedAtId, ref statusMsg); if (newEntityId == 0) { //need to log, and reset status.AddError("Learning Opportunity Add Pending failed for: " + property + ". " + statusMsg); entityUid = new Guid(); } } else if (entityTypeId == CodesManager.ENTITY_TYPE_COST_MANIFEST) { //should know the parent org, add to this method newEntityId = new CostManifestManager().AddPendingRecord(entityUid, ctid, referencedAtId, ref statusMsg); if (newEntityId == 0) { //need to log, and reset status.AddError("CostManifest Add Pending failed for: " + property + ". " + statusMsg); entityUid = new Guid(); } } else if (entityTypeId == CodesManager.ENTITY_TYPE_CONDITION_MANIFEST) { newEntityId = new ConditionManifestManager().AddPendingRecord(entityUid, ctid, referencedAtId, ref statusMsg); if (newEntityId == 0) { //need to log, and reset status.AddError("ConditionManifest Add Pending failed for: " + property + ". " + statusMsg); entityUid = new Guid(); } } else if (entityTypeId == CodesManager.ENTITY_TYPE_TRANSFER_VALUE_PROFILE) { //not sure we will ever have a reference to a TVP? newEntityId = new TransferValueProfileManager().AddPendingRecord(entityUid, ctid, referencedAtId, ref statusMsg); if (newEntityId == 0) { //need to log, and reset status.AddError("TransferValue Add Pending failed for: " + property + ". " + statusMsg); entityUid = new Guid(); } } else if (entityTypeId == CodesManager.ENTITY_TYPE_PATHWAY) { newEntityId = new PathwayManager().AddPendingRecord(entityUid, ctid, referencedAtId, ref statusMsg); if (newEntityId == 0) { //need to log, and reset status.AddError("Pathway Add Pending failed for: " + property + ". " + statusMsg); entityUid = new Guid(); } } else if (entityTypeId == CodesManager.ENTITY_TYPE_PATHWAY_COMPONENT) { if (ctid == "ce-fa6c139f-0615-401f-9920-6ec8c445baca") { } //need pathwayCTID for this ce-abcb5fe0-8fde-4f06-9d70-860cd5bdc763 newEntityId = new PathwayComponentManager().AddPendingRecord(entityUid, ctid, referencedAtId, ref statusMsg); if (newEntityId == 0) { //need to log, and reset status.AddError(statusMsg); //need to know what property would need to be fixed - really shouldn't happen entityUid = new Guid(); } } else { //for properties like organization.Offers, we don't know what the entity type is. //SO..... } if (BaseFactory.IsGuidValid(entityUid)) { int id = importManager.Import_EntityResolutionAdd(referencedAtId, ctid, entityTypeId, entityUid, newEntityId, false, ref messages); //need to create a placeholder if (id == 0) { status.AddError("Error - failed to add Import_EntityResolution for " + referencedAtId); status.AddWarningRange(messages); //return 0; } } return(entityUid); }
public void HandleComponents(ThisEntity pathway, ref SaveStatus status) { try { //components //delete all not in current list new Entity_PathwayComponentManager().DeleteNotInList(pathway.CTID, pathway.HasPart, ref status); // //TBD - should we do a fresh get of the pathway with components - or clear all? //handle components foreach (var item in pathway.HasPart) { var component = new PathwayComponent(); //handle each component //add to pathway HasParts on conclusion (with existance checking var recordExists = false; if (HandlePathwayComponent(item, pathway, ref component, ref recordExists, ref status) < 1) { status.RecordsFailed++; continue; } else { if (recordExists) { status.RecordsUpdated++; } else { status.RecordsAdded++; } } //add pathway HasPart for component //?do we need has part in the finder? //will be useful to retrieve data for the detail page epcmgr.Add(pathway.RowId, component.Id, PathwayComponent.PathwayComponentRelationship_HasPart, ref status); } //handle conditions var candidates = pathway.HasPart.Where(s => s.HasCondition != null && s.HasCondition.Count() > 0).ToList(); foreach (var pc in candidates) { foreach (var item in pc.HasCondition) { //get parent component var component = PathwayComponentManager.GetByCtid(pc.CTID); if (component == null || component.Id == 0) { //shouldn't happen here - although the add attempt could have failed? status.AddError(string.Format("The parent pathway component: {0} for ConditionComponent: {1} was not found. This could have been due the an issue adding the component - which should have resulted in an earlier error message.", pc.Name, item.Name)); continue; } var condition = new PathwayComponentCondition(); //add to pathway component Entity.HasPathwayComponent on conclusion if (HandleComponentCondition(item, pathway, component, ref status) < 1) { status.RecordsFailed++; //could continue if have an id (i.e. failed after saved)? continue; } } } //now handle relationships int cntr = 0; foreach (var item in pathway.HasPart) { cntr++; var component = PathwayComponentManager.GetByCtid(item.CTID, PathwayComponentManager.componentActionOfNone); //handle each component //add to pathway HasParts on conclusion (with existance checking ReplacePathwayComponentRelationships(cntr, component.RowId, item.HasChildList, pathway, PathwayComponent.PathwayComponentRelationship_HasChild, "PathwayComponent.HasChild", ref status); ReplacePathwayComponentRelationships(cntr, component.RowId, item.HasPrerequisiteList, pathway, PathwayComponent.PathwayComponentRelationship_Prerequiste, "PathwayComponent.Prerequisite", ref status); // ReplacePathwayComponentRelationships(cntr, component.RowId, item.HasPreceedsList, pathway, PathwayComponent.PathwayComponentRelationship_Preceeds, "PathwayComponent.Preceeds", ref status); } //these may have to been done after processing components //================ destination component ReplacePathwayToPathwayComponentRelationships(pathway.HasDestinationList, pathway, PathwayComponent.PathwayComponentRelationship_HasDestinationComponent, "Pathway.HasDestinationComponent", ref status); // ReplacePathwayToPathwayComponentRelationships(pathway.HasChildList, pathway, PathwayComponent.PathwayComponentRelationship_HasChild, "Pathway.HasChild", ref status); } catch (Exception ex) { LoggingHelper.DoTrace(1, string.Format(thisClassName + ".HandleComponents. Pathway: {0} ({1}) Exception encountered: {2}", pathway.Name, pathway.Id, ex.Message)); //only fail current, and allow to continue status.AddError(string.Format("Exception encountered. Pathway: {0}, Message: {1}", pathway.Name, ex.Message)); LoggingHelper.LogError(ex, string.Format(thisClassName + ".HandleComponents. Pathway: {0} ({1}) Exception encountered", pathway.Name, pathway.Id)); } }
public static PathwayComponent GetComponentBasic(int id) { PathwayComponent entity = PathwayComponentManager.Get(id); return(entity); }