public void ImportPendingRecords()
        {
            string where = " [EntityStateId] = 1 ";
            int pTotalRows = 0;

            SaveStatus        status = new SaveStatus();
            List <ThisEntity> list   = LearningOpportunityManager.Search(where, "", 1, 500, ref pTotalRows);

            LoggingHelper.DoTrace(1, string.Format(thisClassName + " - ImportPendingRecords(). Processing {0} records =================", pTotalRows));
            foreach (ThisEntity item in list)
            {
                status = new SaveStatus();
                //SWP contains the resource url
                //pending records will have a  CTID, it should be used to get the envelope!
                //if ( !ImportByResourceUrl( item.SubjectWebpage, status ) )
                if (!ImportByCtid(item.CTID, status))
                {
                    //check for 404
                    LoggingHelper.DoTrace(1, string.Format("     - (). Failed to import pending record: {0}, message(s): {1}", item.Id, status.GetErrorsAsString()));
                }
                else
                {
                    LoggingHelper.DoTrace(1, string.Format("     - (). Successfully imported pending record: {0}", item.Id));
                }
            }
        }
        /// <summary>
        /// Check if the lopp for the passed credential has a connnection to a credential
        /// 21-03-02 mparsons - had an issue where an lopp was previously deleted, and so had a state of 0. Since the reason for this check is to publish an lopp, now including deleted lopps in the check
        /// </summary>
        /// <param name="loppCTID"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public static bool DoesLearningOpportunityHaveCredentialConnection(string loppCTID, ref string status)
        {
            string filter = string.Format("(base.Id in (SELECT f.[Id]   FROM [dbo].[LearningOpportunity] a " +
                                          "  inner join [Entity.LearningOpportunity]    b on a.id = b.LearningOpportunityId" +
                                          "  inner join Entity c on b.EntityId = c.Id  " +
                                          "  Inner Join [Entity.ConditionProfile] d on c.EntityUid = d.rowId " +
                                          "  Inner Join Entity e on d.EntityId = e.Id " +
                                          "  inner join Credential f on e.EntityUid = f.RowId" +
                                          "  where a.EntityStateId >= 0 and f.EntityStateId > 1  " +
                                          "  and a.CTID = '{0}' ))", loppCTID);
            int ptotalRows = 0;

            CredentialManager.ExistanceSearch(filter, ref ptotalRows);
            if (ptotalRows > 0)
            {
                return(true);
            }
            else
            {
                //fallback. If the pending entry exists, it was be put there for a valid reason - but could have been a non-credential connection.
                var lopp = LearningOpportunityManager.GetByCtid(loppCTID);
                if (lopp != null && lopp.Id > 0)
                {
                    return(true);
                }
                //probably no message needed
                return(false);
            }
        }
Example #3
0
        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);
        }
Example #4
0
        //
        /// <summary>
        /// Handle component import
        /// TODO - should a save be done for each component or wait until the end
        /// </summary>
        /// <param name="input"></param>
        /// <param name="pathway"></param>
        /// <param name="bnodes"></param>
        /// <param name="status">TODO - do we want to continue using the pathway SaveStatus?</param>
        /// <returns></returns>
        public OutputComponent ImportComponent(InputComponent input, ThisEntity pathway, List <BNode> bnodes, SaveStatus status)
        {
            MappingHelperV3 helper = new MappingHelperV3(CodesManager.ENTITY_TYPE_PATHWAY_COMPONENT);

            //do we need to reference blank nodes here? - if so pass to this method
            helper.entityBlankNodes  = bnodes;
            helper.CurrentEntityCTID = input.CTID;
            helper.CurrentEntityName = input.Name.ToString();
            OutputComponent output = new OutputComponent();

            //
            LoggingHelper.DoTrace(5, "======== Component ======== ");
            LoggingHelper.DoTrace(5, "		type: "+ input.PathwayComponentType.ToString());
            LoggingHelper.DoTrace(5, "		name: "+ (input.Name ?? new JInput.LanguageMap("componentNameMissing")).ToString());
            LoggingHelper.DoTrace(5, "		ctid: "+ input.CTID);
            LoggingHelper.DoTrace(6, "		@Id: "+ input.CtdlId);

            try
            {
                //add/updating Pathway
                if (!DoesComponentExist(input.CTID, ref output))
                {
                    //set the rowid now, so that can be referenced as needed
                    //no, the guid comes from the resolving of entity references
                    //actually OK, as earlier references would result in a pending record
                    output.RowId = Guid.NewGuid();
                }
                helper.currentBaseObject = output;
                if (input.CTID == "ce-fa6c139f-0615-401f-9920-6ec8c445baca")
                {
                }
                //initialize json properties
                output.JsonProperties = new PathwayComponentProperties();
                //
                output.PathwayComponentType = input.PathwayComponentType;
                output.Name           = helper.HandleLanguageMap(input.Name, output, "Name");
                output.Description    = helper.HandleLanguageMap(input.Description, output, "Description");
                output.SubjectWebpage = input.SubjectWebpage;
                output.SourceData     = input.SourceData;

                if (!string.IsNullOrWhiteSpace(output.SourceData) && output.SourceData.IndexOf("/resources/") > 0)
                {
                    var ctid = ResolutionServices.ExtractCtid(output.SourceData);
                    if (!string.IsNullOrWhiteSpace(ctid))
                    {
                        if (output.PathwayComponentType.ToLower().IndexOf("credential") > -1)
                        {
                            var target = CredentialManager.GetMinimumByCtid(ctid);
                            if (target != null && target.Id > 0)
                            {
                                //this approach 'buries' the cred from external references like credential in pathway
                                output.SourceCredential = new TopLevelEntityReference()
                                {
                                    Id             = target.Id,
                                    Name           = target.Name,
                                    Description    = target.Description,
                                    CTID           = target.CTID,
                                    SubjectWebpage = target.SubjectWebpage,
                                    //RowId = target.RowId
                                };
                                output.JsonProperties.SourceCredential = output.SourceCredential;
                            }
                        }
                        else if (output.PathwayComponentType.ToLower().IndexOf("assessmentcomp") > -1)
                        {
                            var target = AssessmentManager.GetSummaryByCtid(ctid);
                            if (target != null && target.Id > 0)
                            {
                                //may not really need this, just the json
                                output.SourceAssessment = new TopLevelEntityReference()
                                {
                                    Id             = target.Id,
                                    Name           = target.Name,
                                    Description    = target.Description,
                                    CTID           = target.CTID,
                                    SubjectWebpage = target.SubjectWebpage,
                                    //RowId = target.RowId
                                };
                                output.JsonProperties.SourceAssessment = output.SourceAssessment;
                            }
                        }
                        else if (output.PathwayComponentType.ToLower().IndexOf("coursecomp") > -1)
                        {
                            var target = LearningOpportunityManager.GetByCtid(ctid);
                            if (target != null && target.Id > 0)
                            {
                                //may not really need this, just the json
                                output.SourceLearningOpportunity = new TopLevelEntityReference()
                                {
                                    Id             = target.Id,
                                    Name           = target.Name,
                                    Description    = target.Description,
                                    CTID           = target.CTID,
                                    SubjectWebpage = target.SubjectWebpage,
                                    //RowId = target.RowId
                                };
                                output.JsonProperties.SourceLearningOpportunity = output.SourceLearningOpportunity;
                            }
                        }
                    }
                }

                output.CTID        = input.CTID;
                output.PathwayCTID = pathway.CTID;


                //output.CodedNotation = input.CodedNotation;
                output.Identifier = helper.MapIdentifierValueListInternal(input.Identifier);
                if (output.Identifier != null && output.Identifier.Count() > 0)
                {
                    output.IdentifierJson = JsonConvert.SerializeObject(output.Identifier, MappingHelperV3.GetJsonSettings());
                }
                //
                output.ComponentDesignationList = helper.MapCAOListToList(input.ComponentDesignation);

                //
                output.CredentialType = input.CredentialType;
                output.CreditValue    = helper.HandleValueProfileList(input.CreditValue, output.PathwayComponentType + ".CreditValue");

                //TBD - how to handle. Will need to have imported the concept scheme/concept
                if (input.HasProgressionLevel != null && input.HasProgressionLevel.Any())
                {
                    foreach (var item in input.HasProgressionLevel)
                    {
                        output.HasProgressionLevels.Add(ResolutionServices.ExtractCtid(item));
                    }
                }

                output.PointValue = helper.HandleQuantitiveValue(input.PointValue, output.PathwayComponentType + ".PointValue");

                //
                output.ProgramTerm = helper.HandleLanguageMap(input.ProgramTerm, output, "ProgramTerm");
                //need to get relationshiptype to store-> this can be done by manager
                //3
                output.HasChildList = helper.MapEntityReferenceGuids("PathwayComponent.HasChild", input.HasChild, CodesManager.ENTITY_TYPE_PATHWAY_COMPONENT, ref status);
                //2
                output.HasIsChildOfList = helper.MapEntityReferenceGuids("PathwayComponent.IsChildOf", input.IsChildOf, CodesManager.ENTITY_TYPE_PATHWAY_COMPONENT, ref status);

                output.HasPrerequisiteList = helper.MapEntityReferenceGuids("PathwayComponent.Prerequisite", input.Prerequisite, CodesManager.ENTITY_TYPE_PATHWAY_COMPONENT, ref status);
                output.HasPreceedsList     = helper.MapEntityReferenceGuids("PathwayComponent.Preceeds", input.Preceeds, CodesManager.ENTITY_TYPE_PATHWAY_COMPONENT, ref status);

                //populate JSON properties
                output.JsonProperties.ComponentDesignationList = output.ComponentDesignationList;
                output.JsonProperties.CreditValue = output.CreditValue;
                output.JsonProperties.Identifier  = output.Identifier;
                output.JsonProperties.PointValue  = output.PointValue;

                //
                if (input.HasCondition != null && input.HasCondition.Count() > 0)
                {
                    output.HasCondition = new List <PathwayComponentCondition>();
                    foreach (var item in input.HasCondition)
                    {
                        //var jcc = JsonConvert.DeserializeObject<JInput.ComponentCondition>( item.ToString() );
                        var cc = new PathwayComponentCondition();
                        cc.Name                   = helper.HandleLanguageMap(item.Name, cc, "ComponentCondition.Name");
                        cc.Description            = helper.HandleLanguageMap(item.Description, cc, "ComponentCondition.Description");
                        cc.RequiredNumber         = item.RequiredNumber;
                        cc.PathwayCTID            = pathway.CTID;
                        cc.HasTargetComponentList = helper.MapEntityReferenceGuids("ComponentCondition.TargetComponent", item.TargetComponent, CodesManager.ENTITY_TYPE_PATHWAY_COMPONENT, ref status);

                        output.HasCondition.Add(cc);
                    }
                }
            } catch (Exception ex)
            {
                LoggingHelper.LogError(ex, "ImportPathways.ImportComponent");
                //status.AddError( string.Format( "ImportPathways.ImportComponent. ComponentType: {0}, Name: {1}, Message: {2}", output.ComponentTypeId, output.Name, ex.Message ) );
            }
            //then save
            return(output);
        }
Example #5
0
        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);
        }
Example #6
0
        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 static Guid ResolveEntityByRegistryAtIdToGuid(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());

                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 ) )
                    return(( Guid )item.EntityUid);

                    //add activity or error
                    //return 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(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)
            {
                //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(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
            {
                //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);
        }
        /// <summary>
        /// Get all learning opportunties for the parent
        /// Uses the parent Guid to retrieve the related Entity, then uses the EntityId to retrieve the child objects.
        /// </summary>
        /// <param name="parentUid"></param>
        /// <param name="forProfilesList"></param>
        /// <returns></returns>
        public static List <ThisEntity> LearningOpps_GetAll(Guid parentUid,
                                                            bool forProfilesList,
                                                            bool isForCredentialDetails = false, int relationshipTypeId = 1)
        {
            List <ThisEntity> list   = new List <ThisEntity>();
            ThisEntity        entity = new ThisEntity();

            Entity parent = EntityManager.GetEntity(parentUid);

            if (parent == null || parent.Id == 0)
            {
                return(list);
            }
            //TODO - this was left over from the publisher, needs to be cleaned up
            bool includingProperties = isForCredentialDetails;
            bool includingProfiles   = false;

            if (isForCredentialDetails)
            {
                includingProperties = true;
                includingProfiles   = true;
            }
            LoggingHelper.DoTrace(7, string.Format("Entity_LearningOpps_GetAll: parentUid:{0} entityId:{1}, e.EntityTypeId:{2}", parentUid, parent.Id, parent.EntityTypeId));
            try
            {
                using (var context = new EntityContext())
                {
                    List <DBEntity> results = context.Entity_LearningOpportunity
                                              .Where(s => s.EntityId == parent.Id && s.RelationshipTypeId == relationshipTypeId)
                                              .OrderBy(s => s.LearningOpportunity.Name)
                                              .ToList();

                    if (results != null && results.Count > 0)
                    {
                        foreach (DBEntity item in results)
                        {
                            entity = new ThisEntity();
                            if (item.LearningOpportunity != null && item.LearningOpportunity.EntityStateId > 1)
                            {
                                if (forProfilesList || isForCredentialDetails)
                                {
                                    LearningOpportunityManager.MapFromDB_Basic(item.LearningOpportunity, entity,
                                                                               true);

                                    if (isForCredentialDetails)
                                    {
                                        entity.EstimatedDuration = DurationProfileManager.GetAll(entity.RowId);
                                        LearningOpportunityManager.MapFromDB_HasPart(entity, false);
                                        LearningOpportunityManager.MapFromDB_Competencies(entity);
                                    }
                                    list.Add(entity);
                                }
                                else
                                {
                                    if (CacheManager.IsLearningOpportunityAvailableFromCache(item.LearningOpportunityId, ref entity))
                                    {
                                        list.Add(entity);
                                    }
                                    else
                                    {
                                        //TODO - is this section used??
                                        //to determine minimum needed for a or detail page
                                        LearningOpportunityManager.MapFromDB(item.LearningOpportunity, entity,
                                                                             includingProperties,
                                                                             includingProfiles,
                                                                             false //includeWhereUsed
                                                                             );
                                        list.Add(entity);
                                        if (entity.HasPart.Count > 0)
                                        {
                                            CacheManager.AddLearningOpportunityToCache(entity);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    return(list);
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + string.Format(".LearningOpps_GetAll. Guid: {0}, parentType: {1} ({2}), ", parentUid, parent.EntityType, parent.EntityBaseId));
            }
            return(list);
        }
Example #9
0
        }         //

        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(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
                }
            }
        }
        /// <summary>
        /// Get all learning opportunties for the parent
        /// Uses the parent Guid to retrieve the related Entity, then uses the EntityId to retrieve the child objects.
        /// </summary>
        /// <param name="parentUid"></param>
        /// <param name="forProfilesList"></param>
        /// <returns></returns>
        public static List <ThisEntity> LearningOpps_GetAll(Guid parentUid,
                                                            bool forProfilesList,
                                                            bool isForCredentialDetails = false)
        {
            List <ThisEntity> list   = new List <ThisEntity>();
            ThisEntity        entity = new ThisEntity();

            Entity parent = EntityManager.GetEntity(parentUid);

            if (parent == null || parent.Id == 0)
            {
                return(list);
            }
            //TODO - this was left over from the publisher, needs to be cleaned up
            bool includingProperties = isForCredentialDetails;
            bool includingProfiles   = false;

            if (isForCredentialDetails)
            {
                includingProperties = true;
                includingProfiles   = true;
            }
            LoggingHelper.DoTrace(7, string.Format("Entity_LearningOpps_GetAll: parentUid:{0} entityId:{1}, e.EntityTypeId:{2}", parentUid, parent.Id, parent.EntityTypeId));
            try
            {
                using (var context = new EntityContext())
                {
                    List <DBEntity> results = context.Entity_LearningOpportunity
                                              .Where(s => s.EntityId == parent.Id)
                                              .OrderBy(s => s.LearningOpportunity.Name)
                                              .ToList();

                    if (results != null && results.Count > 0)
                    {
                        foreach (DBEntity item in results)
                        {
                            entity = new ThisEntity();
                            if (item.LearningOpportunity != null && item.LearningOpportunity.EntityStateId > 1)
                            {
                                if (forProfilesList || isForCredentialDetails)
                                {
                                    LearningOpportunityManager.MapFromDB_Basic(item.LearningOpportunity, entity,
                                                                               true);

                                    //entity.Id = item.LearningOpportunityId;
                                    //                           entity.RowId = item.LearningOpportunity.RowId;

                                    //                           entity.Name = item.LearningOpportunity.Name;
                                    //                           entity.Description = item.LearningOpportunity.Description == null ? "" : item.LearningOpportunity.Description;
                                    //entity.EntityStateId = ( int )( item.LearningOpportunity.EntityStateId ?? 1 );
                                    //entity.SubjectWebpage = item.LearningOpportunity.SubjectWebpage;
                                    //                           entity.CTID = item.LearningOpportunity.CTID;
                                    //also get costs - really only need the profile list view
                                    //entity.EstimatedCost = CostProfileManager.GetAllForList( entity.RowId );
                                    //entity.CommonCosts = Entity_CommonCostManager.GetAll( entity.RowId );
                                    //get durations - need this for search and compare
                                    //entity.EstimatedDuration = DurationProfileManager.GetAll( entity.RowId );
                                    if (isForCredentialDetails)
                                    {
                                        entity.EstimatedDuration = DurationProfileManager.GetAll(entity.RowId);
                                        LearningOpportunityManager.MapFromDB_HasPart(entity, false);
                                        LearningOpportunityManager.MapFromDB_Competencies(entity);
                                    }
                                    list.Add(entity);
                                }
                                else
                                {
                                    if (CacheManager.IsLearningOpportunityAvailableFromCache(item.LearningOpportunityId, ref entity))
                                    {
                                        list.Add(entity);
                                    }
                                    else
                                    {
                                        //TODO - is this section used??
                                        //to determine minimum needed for a or detail page
                                        LearningOpportunityManager.MapFromDB(item.LearningOpportunity, entity,
                                                                             includingProperties,
                                                                             includingProfiles,
                                                                             false //includeWhereUsed
                                                                             );
                                        list.Add(entity);
                                        if (entity.HasPart.Count > 0)
                                        {
                                            CacheManager.AddLearningOpportunityToCache(entity);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    return(list);
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + ".LearningOpps_GetAll");
            }
            return(list);
        }