//currently use education framework
        public bool DoesEntityExist(string ctid, ref ConceptScheme entity)
        {
            bool exists = false;

            entity = EntityServices.GetByCtid(ctid);
            if (entity != null && entity.Id > 0)
            {
                return(true);
            }

            return(exists);
        }
예제 #2
0
        public bool ValidateProfile(ThisEntity profile, ref SaveStatus status)
        {
            status.HasSectionErrors = false;

            if (string.IsNullOrWhiteSpace(profile.Name))
            {
                status.AddWarning("An competency framework name must be entered");
            }

            //if we don't require url, we can't resolve potentially duplicate framework names


            return(status.WasSectionValid);
        }
예제 #3
0
        public bool Import(ThisEntity entity, ref SaveStatus status)
        {
            LoggingHelper.DoTrace(5, thisClassName + "Import entered. " + entity.Name);
            //do a get, and add to cache before updating
            if (entity.Id > 0)
            {
                //note could cause problems verifying after an import (i.e. shows cached version. Maybe remove from cache after completion.
                //var detail = GetDetail( entity.Id );
            }
            bool          isValid  = new Manager().Save(entity, ref status, true);
            List <string> messages = new List <string>();

            if (entity.Id > 0)
            {
                if (UtilityManager.GetAppKeyValue("delayingAllCacheUpdates", false) == false)
                {
                    //update cache - not applicable yet
                    //new CacheManager().PopulateEntityRelatedCaches( entity.RowId );
                    //update Elastic
                    if (Utilities.UtilityManager.GetAppKeyValue("updatingElasticIndexImmediately", false))
                    {
                        ElasticHelper.CompetencyFramework_UpdateIndex(entity.Id);
                    }
                    else
                    {
                        new SearchPendingReindexManager().Add(CodesManager.ENTITY_TYPE_CONCEPT_SCHEME, entity.Id, 1, ref messages);
                        if (messages.Count > 0)
                        {
                            status.AddWarningRange(messages);
                        }
                    }
                    new SearchPendingReindexManager().Add(CodesManager.ENTITY_TYPE_ORGANIZATION, entity.OrganizationId, 1, ref messages);
                }
                else
                {
                    new SearchPendingReindexManager().Add(CodesManager.ENTITY_TYPE_CONCEPT_SCHEME, entity.Id, 1, ref messages);
                    new SearchPendingReindexManager().Add(CodesManager.ENTITY_TYPE_ORGANIZATION, entity.OrganizationId, 1, ref messages);
                    if (messages.Count > 0)
                    {
                        status.AddWarningRange(messages);
                    }
                }
                //no caching needed yet
                //CacheManager.RemoveItemFromCache( "cframework", entity.Id );
            }

            return(isValid);
        }
예제 #4
0
        public static ThisEntity Get(int id, bool includingComponents = true)
        {
            ThisEntity entity = new ThisEntity();

            using (var context = new EntityContext())
            {
                DBEntity item = context.ConceptScheme
                                .FirstOrDefault(s => s.Id == id);

                if (item != null && item.Id > 0)
                {
                    MapFromDB(item, entity, includingComponents);
                }
            }
            return(entity);
        }
예제 #5
0
        public bool UpdateParts(ThisEntity entity, ref SaveStatus status)
        {
            bool isAllValid = true;
            Entity_AgentRelationshipManager mgr = new Entity_AgentRelationshipManager();
            Entity relatedEntity = EntityManager.GetEntity(entity.RowId);

            if (relatedEntity == null || relatedEntity.Id == 0)
            {
                status.AddError("Error - the related Entity was not found.");
                return(false);
            }
            mgr.DeleteAll(relatedEntity, ref status);
            mgr.SaveList(relatedEntity.Id, Entity_AgentRelationshipManager.ROLE_TYPE_OWNER, entity.OwnedBy, ref status);

            return(isAllValid);
        }
예제 #6
0
        public static ThisEntity GetByCtid(string ctid, bool includingComponents = true)
        {
            ThisEntity entity = new ThisEntity();

            if (string.IsNullOrWhiteSpace(ctid))
            {
                return(entity);
            }
            ctid = ctid.ToLower();
            using (var context = new EntityContext())
            {
                DBEntity item = context.ConceptScheme
                                .FirstOrDefault(s => s.CTID.ToLower() == ctid);
                if (item != null && item.Id > 0)
                {
                    MapFromDB(item, entity, includingComponents);
                }
            }

            return(entity);
        }
예제 #7
0
        public static void MapToDB(ThisEntity from, DBEntity to)
        {
            //want to ensure fields from create are not wiped
            if (to.Id < 1)
            {
                if (IsValidDate(from.Created))
                {
                    to.Created = from.Created;
                }
            }
            //from may not have these values
            //to.Id = from.Id;
            //to.RowId = from.RowId;
            to.OrgId              = from.OrganizationId;
            to.Name               = from.Name;
            to.EntityStateId      = from.EntityStateId;
            to.Description        = from.Description;
            to.IsProgressionModel = from.IsProgressionModel;
            to.CTID               = from.CTID;
            //make sure not overwritten
            if (!string.IsNullOrWhiteSpace(from.CredentialRegistryId))
            {
                to.CredentialRegistryId = from.CredentialRegistryId;
            }

            //watch for overwriting these new properties.
            to.Source = from.Source;
            to.PublicationStatusType = from.PublicationStatusType;


            //using last updated date from interface, as we don't have all data here.
            if (IsValidDate(from.LastUpdated))
            {
                to.LastUpdated = from.LastUpdated;
            }
        }
예제 #8
0
        public static void MapFromDB(DBEntity from, ThisEntity to, bool includingComponents = true)
        {
            to.Id             = from.Id;
            to.RowId          = from.RowId;
            to.EntityStateId  = from.EntityStateId;
            to.OrganizationId = from.OrgId;
            to.Name           = from.Name;
            to.Description    = from.Description;

            to.IsProgressionModel = from.IsProgressionModel == null ? false : (bool)from.IsProgressionModel;
            to.CTID   = from.CTID.ToLower();
            to.Source = from.Source;

            to.PublicationStatusType = from.PublicationStatusType;
            to.CredentialRegistryId  = from.CredentialRegistryId;
            if (to.OrganizationId > 0)
            {
                to.OwningOrganization = OrganizationManager.GetForSummary(to.OrganizationId);

                to.OwningAgentUid = to.OwningOrganization.RowId;
                //get roles- not sure. Can have own and offer
                //OrganizationRoleProfile orp = Entity_AgentRelationshipManager.AgentEntityRole_GetAsEnumerationFromCSV( to.RowId, to.OwningAgentUid );
                //to.OwnerRoles = orp.AgentRole;
                //if ( to.OwnerRoles.HasItems() == false )
                //{
                //	EnumeratedItem ei = Entity_AgentRelationshipManager.GetAgentRole( "Owned By" );
                //	if ( ei == null || ei.Id == 0 )
                //	{
                //		//messages.Add( string.Format( "The organization role: {0} is not valid", "OwnedBy" ) );
                //	}
                //	else
                //	{
                //		to.OwnerRoles.Items.Add( ei );
                //	}
                //}
            }
            //
            to.OrganizationRole = Entity_AgentRelationshipManager.AgentEntityRole_GetAll_ToEnumeration(to.RowId, true);
            //
            if (from.ConceptScheme_Concept != null && from.ConceptScheme_Concept.Any())
            {
                foreach (var item in from.ConceptScheme_Concept)
                {
                    to.HasConcepts.Add(new Models.Common.Concept()
                    {
                        Id           = item.Id,
                        CTID         = item.CTID,
                        PrefLabel    = item.PrefLabel,
                        Definition   = item.Definition,
                        IsTopConcept = item.IsTopConcept ?? false
                    });
                }
            }
            //
            if (includingComponents)
            {
                //how to know if this is a progression model? Or just do get anyway
                to.Pathways   = PathwayManager.GetAllForProgressionModel(to.CTID);
                to.HasPathway = to.Pathways.Select(m => m.CTID).ToList();
            }
            //
            if (IsValidDate(from.Created))
            {
                to.Created = ( DateTime )from.Created;
            }
            if (IsValidDate(from.LastUpdated))
            {
                to.LastUpdated = ( DateTime )from.LastUpdated;
            }
        }
예제 #9
0
        /// <summary>
        /// Add/Update a ConceptScheme
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="messages"></param>
        /// <returns></returns>
        public bool Save(ThisEntity entity,
                         ref SaveStatus status, bool addingActivity = false)
        {
            bool isValid = true;
            int  count   = 0;

            DBEntity efEntity = new DBEntity();

            try
            {
                using (var context = new EntityContext())
                {
                    if (ValidateProfile(entity, ref status) == false)
                    {
                        return(false);
                    }

                    if (entity.Id == 0)
                    {
                        //add
                        efEntity             = new DBEntity();
                        entity.EntityStateId = 3;
                        MapToDB(entity, efEntity);

                        if (IsValidDate(status.EnvelopeCreatedDate))
                        {
                            efEntity.Created = status.LocalCreatedDate;
                        }
                        else
                        {
                            efEntity.Created = DateTime.Now;
                        }
                        //
                        if (IsValidDate(status.EnvelopeUpdatedDate))
                        {
                            efEntity.LastUpdated = status.LocalUpdatedDate;
                        }
                        else
                        {
                            efEntity.LastUpdated = DateTime.Now;
                        }

                        if (IsValidGuid(entity.RowId))
                        {
                            efEntity.RowId = entity.RowId;
                        }
                        else
                        {
                            efEntity.RowId = Guid.NewGuid();
                        }

                        context.ConceptScheme.Add(efEntity);

                        count = context.SaveChanges();

                        entity.Id    = efEntity.Id;
                        entity.RowId = efEntity.RowId;
                        if (count == 0)
                        {
                            status.AddWarning(string.Format(" Unable to add Profile: {0} <br\\> ", string.IsNullOrWhiteSpace(entity.Name) ? "no description" : entity.Name));
                        }
                        else
                        {
                            if (addingActivity)
                            {
                                //add log entry
                                SiteActivity sa = new SiteActivity()
                                {
                                    ActivityType     = "ConceptScheme",
                                    Activity         = "Import",
                                    Event            = "Add",
                                    Comment          = string.Format("New ConceptScheme was found by the import. Name: {0}, URI: {1}", entity.Name, entity.Source),
                                    ActivityObjectId = entity.Id
                                };
                                new ActivityManager().SiteActivityAdd(sa);
                            }

                            UpdateParts(entity, ref status);
                            //
                            HandleConceptsSimple(entity, ref status);
                        }
                    }
                    else
                    {
                        efEntity = context.ConceptScheme.FirstOrDefault(s => s.Id == entity.Id);
                        if (efEntity != null && efEntity.Id > 0)
                        {
                            entity.RowId = efEntity.RowId;
                            //update
                            MapToDB(entity, efEntity);

                            if (IsValidDate(status.EnvelopeCreatedDate) && status.LocalCreatedDate < efEntity.Created)
                            {
                                efEntity.Created = status.LocalCreatedDate;
                            }
                            if (IsValidDate(status.EnvelopeUpdatedDate) && status.LocalUpdatedDate != efEntity.LastUpdated)
                            {
                                efEntity.LastUpdated = status.LocalUpdatedDate;
                            }
                            //has changed?
                            if (HasStateChanged(context))
                            {
                                //NOTE UTC vs central
                                if (IsValidDate(status.EnvelopeUpdatedDate))
                                {
                                    efEntity.LastUpdated = status.LocalUpdatedDate;
                                }
                                else
                                {
                                    efEntity.LastUpdated = DateTime.Now;
                                }

                                count = context.SaveChanges();
                                if (addingActivity)
                                {
                                    //add log entry
                                    SiteActivity sa = new SiteActivity()
                                    {
                                        ActivityType     = "ConceptScheme",
                                        Activity         = "Import",
                                        Event            = "Update",
                                        Comment          = string.Format("Updated ConceptScheme found by the import. Name: {0}, URI: {1}", entity.Name, entity.Source),
                                        ActivityObjectId = entity.Id
                                    };
                                    new ActivityManager().SiteActivityAdd(sa);
                                }
                            }
                            UpdateParts(entity, ref status);
                            //
                            HandleConceptsSimple(entity, ref status);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, "ConceptSchemeManager.Save()");
            }

            return(isValid);
        }
예제 #10
0
        /// <summary>
        /// TBD-may just store the concepts as Json on concept scheme
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="userId"></param>
        /// <param name="messages"></param>
        /// <returns></returns>
        public bool HandleConceptsSimple(ThisEntity entity, ref SaveStatus status)
        {
            bool isValid = true;
            //first phase: delete all or do a replace
            var efEntity = new EM.ConceptScheme_Concept();

            if (!entity.HasConcepts.Any())
            {
                status.AddError("HandleConceptsSimple - a list of concepts/progression level mames are required for this method.");
                return(false);
            }
            using (var context = new EntityContext())
            {
                try
                {
                    var existing      = context.ConceptScheme_Concept.Where(s => s.ConceptSchemeId == entity.Id).ToList();
                    var incomingCTIDs = entity.HasConcepts.Select(x => x.CTID).ToList();
                    //delete records which are not selected
                    var notExisting = existing.Where(x => !incomingCTIDs.Contains(x.CTID)).ToList();
                    foreach (var item in notExisting)
                    {
                        context.ConceptScheme_Concept.Remove(item);
                        context.SaveChanges();
                    }
                    //only get profiles where not existing
                    var existingCTIDs    = existing.Select(x => x.CTID).ToList();
                    var newConcepts      = entity.HasConcepts.Where(y => !existingCTIDs.Contains(y.CTID)).ToList();
                    var existingConcepts = entity.HasConcepts.Where(y => existingCTIDs.Contains(y.CTID)).ToList();
                    //

                    if (existing != null && existing.Count() > 0 && entity.HasConcepts.Count() > 0)
                    {
                        //LoggingHelper.DoTrace( 6, string.Format( thisClassName + ".Replace. Existing: {0}, input: {1}, Not existing(to delete): {2}, newProfiles: {3}", existing.Count(), entity.HasConcepts.Count(), notExisting.Count(), newProfiles.Count() ) );

                        if (existing.Count() != entity.HasConcepts.Count())
                        {
                        }
                    }
                    //
                    //**need to handle updates
                    foreach (var item in existingConcepts)
                    {
                        var updateConcept = entity.HasConcepts.FirstOrDefault(s => s.CTID == item.CTID);
                        item.PrefLabel   = updateConcept.PrefLabel;
                        item.Definition  = updateConcept.Definition;
                        item.Note        = updateConcept.Note;
                        item.LastUpdated = System.DateTime.Now;
                        context.SaveChanges();
                    }
                    //
                    foreach (var item in newConcepts)
                    {
                        //if there are no existing, optimize by not doing check. What about duplicates?
                        efEntity = new EM.ConceptScheme_Concept
                        {
                            ConceptSchemeId = entity.Id,
                            PrefLabel       = item.PrefLabel,
                            Definition      = item.Definition,
                            Note            = item.Note,
                            RowId           = Guid.NewGuid(),
                            CTID            = item.CTID,
                            IsTopConcept    = true,
                            Created         = DateTime.Now,
                            LastUpdated     = DateTime.Now
                        };
                        context.ConceptScheme_Concept.Add(efEntity);
                        var count = context.SaveChanges();
                    }                     //foreach
                }

                catch (Exception ex)
                {
                    LoggingHelper.LogError(ex, thisClassName + string.Format(".HandleConceptsSimple(), ConceptScheme: {0}", entity.Name));
                    status.AddError(thisClassName + string.Format(".HandleConceptsSimple(), ConceptScheme: {0}. Message: ", entity.Name) + ex.Message);
                    isValid = false;
                }
            }
            return(isValid);
        }