public static void MapFromDB(DBEntity input, ThisEntity output, bool includingPathways = false) { output.Id = input.Id; output.RowId = input.RowId; output.CTID = input.CTID; output.Name = input.Name; output.Description = input.Description; output.SubjectWebpage = input.SubjectWebpage; output.EntityStateId = (int)(input.EntityStateId ?? 2); //TODO - get pathways if (includingPathways) { output.Pathways = Entity_PathwayManager.GetAll(output.RowId, true); output.HasPathway = output.Pathways.Select(m => m.CTID).ToList(); } else { //really only need the pathway ids for publishing - also ctid //might just get the lite versions of a pathway? output.Pathways = Entity_PathwayManager.GetAll(output.RowId, false); //always collect for now output.HasPathway = output.Pathways.Select(m => m.CTID).ToList(); } if (IsGuidValid(input.OwningAgentUid)) { output.OwningAgentUid = ( Guid )input.OwningAgentUid; output.OwningOrganization = OrganizationManager.GetForSummary(output.OwningAgentUid); //get roles OrganizationRoleProfile orp = Entity_AgentRelationshipManager.AgentEntityRole_GetAsEnumerationFromCSV(output.RowId, output.OwningAgentUid); output.OwnerRoles = orp.AgentRole; } // output.OrganizationRole = Entity_AgentRelationshipManager.AgentEntityRole_GetAll_ToEnumeration(output.RowId, true); //confustion over OrganizationRole and OwnerRoles (enum)!!! //to.OrganizationRole = Entity_AgentRelationshipManager.AgentEntityRole_GetAll_ToEnumeration( to.RowId, true ); output.CredentialRegistryId = input.CredentialRegistryId; if (IsValidDate(input.Created)) { output.Created = ( DateTime )input.Created; } if (IsValidDate(input.LastUpdated)) { output.LastUpdated = ( DateTime )input.LastUpdated; } var relatedEntity = EntityManager.GetEntity(output.RowId, false); if (relatedEntity != null && relatedEntity.Id > 0) { output.EntityLastUpdated = relatedEntity.LastUpdated; } }
} // public static List <OrganizationRoleProfile> GetAllCombinedForTarget(int targetEntityTypeId, int recordId, int owningOrgId) { OrganizationRoleProfile orp = new OrganizationRoleProfile(); List <OrganizationRoleProfile> list = new List <OrganizationRoleProfile>(); //21-03-22 remove requirement for owningOrgId //|| owningOrgId == 0 if (targetEntityTypeId == 0 || recordId == 0) { return(list); } EnumeratedItem eitem = new EnumeratedItem(); Guid prevOrgUid = new Guid(); string prevRoleSource = ""; int prevRoleTypeId = 0; using (var context = new ViewContext()) { List <Views.Organization_CombinedConnections> agentRoles = context.Organization_CombinedConnections .Where(s => s.TargetEntityTypeId == targetEntityTypeId && s.TargetEntityBaseId == recordId //&& s.IsQARole == true && s.TargetEntityStateId > 1) .OrderBy(s => s.Organization) .ThenBy(s => s.RelationshipTypeId) .ThenBy(s => s.roleSource) .ToList(); if (agentRoles != null && agentRoles.Any()) { //for this view, we want to retrieve the QA organization info, we already have the target (ie. that is the current context). foreach (var entity in agentRoles) { //loop until change in entity type? if (prevOrgUid != entity.OrgUid) { //handle previous fill if (IsGuidValid(prevOrgUid) && prevRoleTypeId > 0) { orp.AgentRole.Items.Add(eitem); list.Add(orp); } prevOrgUid = entity.OrgUid; prevRoleSource = entity.roleSource; prevRoleTypeId = entity.RelationshipTypeId; //not sure if pertinent orp = new OrganizationRoleProfile { Id = 0, ParentId = entity.OrgId, ParentTypeId = 2, ProfileSummary = entity.Organization, AgentRole = CodesManager.GetEnumeration(CodesManager.PROPERTY_CATEGORY_ENTITY_AGENT_ROLE) }; orp.AgentRole.ParentId = entity.OrgId; orp.ActingAgent = new Organization(); //or should it be TargetOrganization - check how currently used //compare: Entity_AgentRelationshipManager.AgentEntityRole_GetAll_ToEnumeration orp.ActingAgentUid = entity.OrgUid; orp.ActingAgentId = entity.OrgId; orp.ActingAgent = new Organization() { Id = entity.OrgId, RowId = entity.OrgUid, Name = entity.Organization, SubjectWebpage = entity.AgentSubjectWebpage, Description = entity.AgentDescription, Image = entity.AgentImageUrl, EntityStateId = entity.AgentEntityStateId ?? 1, CTID = entity.AgentCTID }; orp.AgentRole.Items = new List <EnumeratedItem>(); } /* either first one for new target * or change in relationship * or change in role source * NOTE: skip the Direct checks if not QA, or at least if only owns/offers */ if (prevRoleTypeId == entity.RelationshipTypeId) { if (prevRoleSource != entity.roleSource) { //TBD if (entity.IsQARole ?? false) { if (entity.roleSource == "QAOrganization" || entity.OrgId == owningOrgId) { eitem.IsDirectAssertion = true; } else { eitem.IsIndirectAssertion = true; } } //add previous //could get a dup if there is an immediate chg in target, //orp.AgentRole.Items.Add( eitem ); prevRoleSource = entity.roleSource; continue; } } else { //if not equal, add previous, and initialize next one (fall thru) orp.AgentRole.Items.Add(eitem); } //add relationship eitem = new EnumeratedItem { Id = entity.RelationshipTypeId, Name = entity.SourceToAgentRelationship, SchemaName = entity.SchemaTag, IsQAValue = (entity.IsQARole ?? false) }; if ((entity.IsQARole ?? false) && entity.OrgId != owningOrgId) { //not sure this is correct. For QA received, it should be BYs //eitem.Name = entity.AgentToSourceRelationship; eitem.Name = entity.SourceToAgentRelationship; eitem.SchemaName = entity.SchemaTag; //eitem.SchemaName = entity.ReverseSchemaTag; } else { if (entity.RelationshipTypeId != 6 && entity.RelationshipTypeId != 7) { eitem.Name = entity.SourceToAgentRelationship; eitem.SchemaName = entity.SchemaTag; } //eitem.Name = entity.SourceToAgentRelationship; //eitem.SchemaName = entity.SchemaTag; } //eitem.CodeId = entity.RelationshipTypeId; prevRoleTypeId = entity.RelationshipTypeId; prevRoleSource = entity.roleSource; //**need additional check if from the owning org! if (entity.IsQARole ?? false) { if (entity.roleSource == "QAOrganization" || entity.OrgId == owningOrgId) { eitem.IsDirectAssertion = true; } else { eitem.IsIndirectAssertion = true; } } } // //check for remaining if (IsGuidValid(prevOrgUid) && prevRoleTypeId > 0) { orp.AgentRole.Items.Add(eitem); list.Add(orp); } } } return(list); } //
} // public static void MapFromDB(DBEntity input, ThisEntity output, bool gettingAll = true) { output.Id = input.Id; output.RowId = input.RowId; output.EntityStateId = input.EntityStateId; output.Name = input.Name; output.Description = input.Description; output.CTID = input.CTID; if (input.Created != null) { output.Created = ( DateTime )input.Created; } if (input.LastUpdated != null) { output.LastUpdated = ( DateTime )input.LastUpdated; } if (IsGuidValid(input.OwningAgentUid)) { output.OwningAgentUid = ( Guid )input.OwningAgentUid; output.OwningOrganization = OrganizationManager.GetForSummary(output.OwningAgentUid); //get roles OrganizationRoleProfile orp = Entity_AgentRelationshipManager.AgentEntityRole_GetAsEnumerationFromCSV(output.RowId, output.OwningAgentUid); output.OwnerRoles = orp.AgentRole; } // output.OrganizationRole = Entity_AgentRelationshipManager.AgentEntityRole_GetAll_ToEnumeration(output.RowId, true); // //get related .... var relatedEntity = EntityManager.GetEntity(output.RowId, false); if (relatedEntity != null && relatedEntity.Id > 0) { output.EntityLastUpdated = relatedEntity.LastUpdated; } // output.SubjectWebpage = input.SubjectWebpage; output.CredentialRegistryId = input.CredentialRegistryId ?? ""; output.LifecycleStatusType = string.IsNullOrWhiteSpace(input.LifecycleStatusType) ? "lifecycle:Active" : input.LifecycleStatusType; //output.CodedNotation = input.CodedNotation; //20-12-16 changed to a string as partial dates are possible if (!string.IsNullOrWhiteSpace(input.StartDate)) { output.StartDate = input.StartDate; } else { output.StartDate = ""; } // if (!string.IsNullOrWhiteSpace(input.EndDate)) { output.EndDate = input.EndDate; } else { output.EndDate = ""; } //derived from .... //get json and expand output.IdentifierJson = input.IdentifierJson; output.TransferValueJson = input.TransferValueJson; output.TransferValueFromJson = input.TransferValueFromJson; output.TransferValueForJson = input.TransferValueForJson; // if (!string.IsNullOrWhiteSpace(output.IdentifierJson)) { output.Identifier = JsonConvert.DeserializeObject <List <Entity_IdentifierValue> >(output.IdentifierJson); } if (!string.IsNullOrWhiteSpace(output.TransferValueJson)) { output.TransferValue = JsonConvert.DeserializeObject <List <ValueProfile> >(output.TransferValueJson); } if (!gettingAll) { return; } //the top level object may not be enough. First need to confirm if reference lopps and asmts can have detail pages. if (!string.IsNullOrWhiteSpace(output.TransferValueFromJson)) { output.TransferValueFrom = JsonConvert.DeserializeObject <List <TopLevelObject> >(output.TransferValueFromJson); var lopps = output.TransferValueFrom.Where(s => s.EntityTypeId == 7).ToList(); foreach (var item in lopps) { output.TransferValueFromLopp.Add(LearningOpportunityManager.GetForDetail(item.Id)); } var assmts = output.TransferValueFrom.Where(s => s.EntityTypeId == 3).ToList(); foreach (var item in assmts) { output.TransferValueFromAsmt.Add(AssessmentManager.GetForDetail(item.Id)); } var creds = output.TransferValueFrom.Where(s => s.EntityTypeId == 1).ToList(); foreach (var item in creds) { output.TransferValueFromCredential.Add(CredentialManager.GetForDetail(item.Id)); } } // if (!string.IsNullOrWhiteSpace(output.TransferValueForJson)) { output.TransferValueFor = JsonConvert.DeserializeObject <List <TopLevelObject> >(output.TransferValueForJson); var lopps = output.TransferValueFor.Where(s => s.EntityTypeId == 7).ToList(); foreach (var item in lopps) { output.TransferValueForLopp.Add(LearningOpportunityManager.GetForDetail(item.Id)); } var assmts = output.TransferValueFor.Where(s => s.EntityTypeId == 3).ToList(); foreach (var item in assmts) { output.TransferValueForAsmt.Add(AssessmentManager.GetForDetail(item.Id)); } var creds = output.TransferValueFor.Where(s => s.EntityTypeId == 1).ToList(); foreach (var item in creds) { output.TransferValueForCredential.Add(CredentialManager.GetForDetail(item.Id)); } } //this should be a summary level, not the full TVP output.DerivedFrom = Entity_TransferValueProfileManager.GetAll(output.RowId); // List <ProcessProfile> processes = Entity_ProcessProfileManager.GetAll(output.RowId); foreach (ProcessProfile item in processes) { if (item.ProcessTypeId == Entity_ProcessProfileManager.DEV_PROCESS_TYPE) { output.DevelopmentProcess.Add(item); } else { //unexpected } } }
} // public static List <OrganizationRoleProfile> GetAllCombinedForOrganization(Guid agentUid, ref int totalRecords, int maxRecords = 25) { OrganizationRoleProfile orp = new OrganizationRoleProfile(); List <OrganizationRoleProfile> list = new List <OrganizationRoleProfile>(); EnumeratedItem eitem = new EnumeratedItem(); Guid prevTargetUid = new Guid(); string prevRoleSource = ""; int prevRoleTypeId = 0; Entity agentEntity = EntityManager.GetEntity(agentUid); if (UtilityManager.GetAppKeyValue("envType") == "production") { //show all for now in production //maxRecords = 0; } using (var context = new ViewContext()) { //first check how long this step takes DateTime start = DateTime.Now; LoggingHelper.DoTrace(4, "GetAllCombinedForOrganization start"); List <Views.Organization_CombinedQAPerformed> agentRoles = context.Organization_CombinedQAPerformed .Where(s => s.OrgUid == agentUid && s.IsQARole == true && s.TargetEntityStateId > 1) .OrderBy(s => s.TargetEntityTypeId) .ThenBy(s => s.TargetOwningOrganizationName) .ThenBy(s => s.TargetEntityName) .ThenBy(s => s.AgentToSourceRelationship) .ThenBy(s => s.roleSource) .ToList(); DateTime end = DateTime.Now; var elasped = end.Subtract(start).TotalSeconds; LoggingHelper.DoTrace(4, string.Format("GetAllCombinedForOrganization retrieve seconds: {0}", elasped)); if (agentRoles != null && agentRoles.Count() > 0) { // totalRecords = agentRoles.Count(); //may want a fudge factor? } int cntr = 0; foreach (var entity in agentRoles) { cntr++; //loop until change in entity type? if (prevTargetUid != entity.TargetEntityUid) { //handle previous fill if (IsGuidValid(prevTargetUid) && prevRoleTypeId > 0) { orp.AgentRole.Items.Add(eitem); list.Add(orp); if (maxRecords > 0 && cntr >= maxRecords) { break; } } prevTargetUid = entity.TargetEntityUid; prevRoleSource = entity.roleSource; prevRoleTypeId = entity.RelationshipTypeId; orp = new OrganizationRoleProfile { Id = 0, ParentId = agentEntity.EntityBaseId, ParentTypeId = agentEntity.EntityTypeId, ProfileSummary = entity.TargetEntityName, AgentRole = CodesManager.GetEnumeration(CodesManager.PROPERTY_CATEGORY_ENTITY_AGENT_ROLE) }; orp.AgentRole.ParentId = entity.OrgId; orp.AgentRole.Items = new List <EnumeratedItem>(); orp.SourceEntityType = entity.TargetEntityType; if (entity.TargetEntityTypeId == CodesManager.ENTITY_TYPE_CREDENTIAL) { //17-08-27 mp - just get the basic for each entity! orp.TargetCredential = CredentialManager.GetBasic(entity.TargetEntityBaseId ?? 0); } else if (entity.TargetEntityTypeId == CodesManager.ENTITY_TYPE_ORGANIZATION) { //orp.TargetOrganization = OrganizationManager.GetBasics( entity.TargetEntityUid ); orp.TargetOrganization.Id = entity.TargetEntityBaseId ?? 0; orp.TargetOrganization.RowId = entity.TargetEntityUid; orp.TargetOrganization.Name = entity.TargetEntityName; orp.TargetOrganization.Description = entity.TargetEntityDescription; orp.TargetOrganization.EntityStateId = entity.TargetEntityStateId ?? 2; orp.TargetOrganization.SubjectWebpage = entity.TargetEntitySubjectWebpage; orp.TargetOrganization.Image = entity.TargetEntityImageUrl; } else if (entity.TargetEntityTypeId == CodesManager.ENTITY_TYPE_ASSESSMENT_PROFILE) { orp.TargetAssessment = AssessmentManager.GetBasic(entity.TargetEntityBaseId ?? 0); } else if (entity.TargetEntityTypeId == CodesManager.ENTITY_TYPE_LEARNING_OPP_PROFILE) { orp.TargetLearningOpportunity = LearningOpportunityManager.GetBasic(entity.TargetEntityBaseId ?? 0); } } /* either first one for new target * or change in relationship * or change in role source */ if (prevRoleTypeId == entity.RelationshipTypeId) { if (prevRoleSource != entity.roleSource) { if (entity.roleSource == "DirectAssertion") { eitem.IsDirectAssertion = true; } else { eitem.IsIndirectAssertion = true; } //add previous //could get a dup if there is an immediate chg in target, //orp.AgentRole.Items.Add( eitem ); prevRoleSource = entity.roleSource; continue; } } else { //if not equal, add previous, and initialize next one (fall thru) orp.AgentRole.Items.Add(eitem); } //add relationship eitem = new EnumeratedItem { Id = entity.RelationshipTypeId, Name = entity.AgentToSourceRelationship, SchemaName = entity.ReverseSchemaTag, IsQAValue = true }; //eitem.CodeId = entity.RelationshipTypeId; prevRoleTypeId = entity.RelationshipTypeId; prevRoleSource = entity.roleSource; if (entity.roleSource == "DirectAssertion") { eitem.IsDirectAssertion = true; } else { eitem.IsIndirectAssertion = true; } //eitem.Name = entity.AgentToSourceRelationship; // eitem.SchemaName = entity.ReverseSchemaTag; // orp.AgentRole.Items.Add( eitem ); } //end //check for remaining if (IsGuidValid(prevTargetUid) && orp.AgentRole.Items.Count > 0) { orp.AgentRole.Items.Add(eitem); list.Add(orp); } DateTime listEnd = DateTime.Now; elasped = listEnd.Subtract(end).TotalSeconds; LoggingHelper.DoTrace(4, string.Format("GetAllCombinedForOrganization loaded list seconds: {0}", elasped)); } return(list); } //
public static void MapFromDB_Basic(DBEntity input, ThisEntity output, bool includingComponents) { output.Id = input.Id; output.RowId = input.RowId; output.EntityStateId = ( int )(input.EntityStateId ?? 1); output.Name = input.Name; output.Description = input.Description == null ? "" : input.Description; output.CTID = input.CTID; if (IsGuidValid(input.OwningAgentUid)) { output.OwningAgentUid = ( Guid )input.OwningAgentUid; output.OwningOrganization = OrganizationManager.GetForSummary(output.OwningAgentUid); output.OrganizationId = output.OwningOrganization.Id; //get roles OrganizationRoleProfile orp = Entity_AgentRelationshipManager.AgentEntityRole_GetAsEnumerationFromCSV(output.RowId, output.OwningAgentUid); output.OwnerRoles = orp.AgentRole; } // output.OrganizationRole = Entity_AgentRelationshipManager.AgentEntityRole_GetAll_ToEnumeration(output.RowId, true); // output.SubjectWebpage = input.SubjectWebpage; if (IsValidDate(input.Created)) { output.Created = ( DateTime )input.Created; } if (IsValidDate(input.LastUpdated)) { output.LastUpdated = ( DateTime )input.LastUpdated; } if (string.IsNullOrWhiteSpace(output.CTID) || output.EntityStateId < 3) { output.IsReferenceVersion = true; return; } //===== var relatedEntity = EntityManager.GetEntity(output.RowId, false); if (relatedEntity != null && relatedEntity.Id > 0) { output.EntityLastUpdated = relatedEntity.LastUpdated; } //components if (includingComponents) { // output.ProgressionModelURI = input.HasProgressionModel; if (!string.IsNullOrWhiteSpace(output.ProgressionModelURI) && includingComponents) { //ensure this is not called always from ProgressionModel/CS or will get a stack overflow output.HasProgressionModel = ConceptSchemeManager.GetByCtid(output.ProgressionModelURI); } //include conditions //to.HasPart = PathwayComponentManager.GetAllForPathway( to.CTID, PathwayComponentManager.componentActionOfDeep ); //actual may be better to do through Entity_PathwayComponent // but only destination component is under pathway //will there be an issue with recursion? //compare //one less that parts??? //var parts1 = PathwayComponentManager.GetAllForPathway( to.CTID, PathwayComponentManager.componentActionOfDeep ); //and var parts = Entity_PathwayComponentManager.GetAll(output.RowId, PathwayComponentManager.componentActionOfDeep); //may want to split out here, do in context foreach (var item in parts) { if (item.ComponentRelationshipTypeId == PathwayComponent.PathwayComponentRelationship_HasDestinationComponent) { output.HasDestinationComponent.Add(item); } else if (item.ComponentRelationshipTypeId == PathwayComponent.PathwayComponentRelationship_HasChild) { output.HasChild.Add(item); } } //now get a unique list //var parts = to.HasPart; output.HasPart = new List <PathwayComponent>(); foreach (var item in parts) { int index = output.HasPart.FindIndex(a => a.CTID == item.CTID); if (index == -1) { output.HasPart.Add(item); } } } } //