Ejemplo n.º 1
0
        public bool SaveList(int parentId, int roleId, List <Guid> targetUids, ref SaveStatus status)
        {
            if (targetUids == null || targetUids.Count == 0 || roleId < 1)
            {
                return(true);
            }
            Entity parentEntity = EntityManager.GetEntity(parentId);
            Entity_AgentRelationshipManager emgr = new Entity_AgentRelationshipManager();

            bool isAllValid = true;

            foreach (Guid targetUid in targetUids)
            {
                Entity targetEntity = EntityManager.GetEntity(targetUid);

                Save(parentId, targetUid, roleId, ref status);

                //check for add to AgentRelationship, if present
                //we don't know what the target is, so can't create a pending record!!!
                //NO SHOULD NOT DO THIS, OTHERWISE HAVE DIRECT AND INDIRECT FROM ONE TRANSACTION
                if (targetEntity.Id > 0)
                {
                    //emgr.Save( targetEntity.Id, parentEntity.EntityUid, roleId, ref status );
                }
            }
            return(isAllValid);
        } //
Ejemplo n.º 2
0
        /// <summary>
        /// Save list of assertions
        /// TODO - need to handle change of owner. The old owner is not being deleted.
        /// </summary>
        /// <param name="parentId"></param>
        /// <param name="roleId"></param>
        /// <param name="targetUids"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public bool SaveList(int parentId, int roleId, List <Guid> targetUids, ref SaveStatus status)
        {
            if (targetUids == null || targetUids.Count == 0 || roleId < 1)
            {
                return(true);
            }
            Entity parentEntity = EntityManager.GetEntity(parentId);
            Entity_AgentRelationshipManager emgr = new Entity_AgentRelationshipManager();
            var  searchPendingReindexManager     = new SearchPendingReindexManager();
            var  messages   = new List <string>();
            bool isAllValid = true;

            foreach (Guid targetUid in targetUids)
            {
                Entity targetEntity = EntityManager.GetEntity(targetUid);

                Save(parentId, targetUid, roleId, ref status);

                //check for add to AgentRelationship, if present
                //we don't know what the target is, so can't create a pending record!!!
                //NO SHOULD NOT DO THIS, OTHERWISE HAVE DIRECT AND INDIRECT FROM ONE TRANSACTION
                //20-11-20 mp	- scenario is that QA org adds assertion, which may not exist from target perspecitive
                //				- so this does need to happen. What are the cautions?
                //				- or don't do explicitly, and have the search handle both sides!
                //21-02-02 mp - need to add all targets to be reindexed.
                if (targetEntity.Id > 0)
                {
                    emgr.Save(targetEntity.Id, parentEntity.EntityUid, roleId, ref status);

                    searchPendingReindexManager.Add(targetEntity.EntityTypeId, targetEntity.EntityBaseId, 1, ref messages);
                }
                ;
            }
            return(isAllValid);
        } //
Ejemplo n.º 3
0
 /// <summary>
 /// Get agent roles for learning opportunities
 /// </summary>
 /// <param name="interfaceType"></param>
 /// <returns></returns>
 //public MC.Enumeration GetLearningOppAgentRoles( MC.EnumerationType interfaceType )
 //{
 //    MC.Enumeration e = Entity_AgentRelationshipManager.GetCommonPlusQAAgentRoles( false );
 //    e.InterfaceType = interfaceType;
 //    e.ShowOtherValue = true;
 //    return e;
 //}
 public MC.Enumeration GetCommonPlusQAAgentRoles(MC.EnumerationType interfaceType)
 {
     MC.Enumeration e = Entity_AgentRelationshipManager.GetCommonPlusQAAgentRoles(false);
     e.InterfaceType  = interfaceType;
     e.ShowOtherValue = true;
     return(e);
 }
Ejemplo n.º 4
0
        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;
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 6
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);

            //initial plan is store whole payload as json

            Entity_ReferenceFrameworkManager erfm = new Entity_ReferenceFrameworkManager();

            erfm.DeleteAll(relatedEntity, ref status);

            if (erfm.SaveList(relatedEntity.Id, CodesManager.PROPERTY_CATEGORY_SOC, entity.Occupations, ref status) == false)
            {
                isAllValid = false;
            }
            if (erfm.SaveList(relatedEntity.Id, CodesManager.PROPERTY_CATEGORY_NAICS, entity.Industries, ref status) == false)
            {
                isAllValid = false;
            }

            //
            Entity_ReferenceManager erm = new Entity_ReferenceManager();

            erm.DeleteAll(relatedEntity, ref status);
            if (erm.Add(entity.Subject, entity.RowId, CodesManager.ENTITY_TYPE_PATHWAY, ref status, CodesManager.PROPERTY_CATEGORY_SUBJECT, false) == false)
            {
                isAllValid = false;
            }

            if (erm.Add(entity.Keyword, entity.RowId, CodesManager.ENTITY_TYPE_PATHWAY, ref status, CodesManager.PROPERTY_CATEGORY_KEYWORD, false) == false)
            {
                isAllValid = false;
            }

            return(isAllValid);
        }
Ejemplo n.º 7
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(thisClassName + " - Error - the parent entity was not found.");
                return(false);
            }
            mgr.DeleteAll(relatedEntity, ref status);

            mgr.SaveList(relatedEntity.Id, Entity_AgentRelationshipManager.ROLE_TYPE_OFFERED_BY, entity.OfferedBy, ref status);
            mgr.SaveList(relatedEntity.Id, Entity_AgentRelationshipManager.ROLE_TYPE_OWNER, entity.OwnedBy, ref status);

            var epmgr = new Entity_PathwayManager();
            //handle pathways - using replace
            //actually just use typical pattern of delete all and then add
            //could be extreme
            //epmgr.DeleteAll( parent.EntityUid, ref status );
            var list = new List <int>();

            //check if we should get the list of ids easier
            foreach (var item in entity.HasPathwayList)
            {
                var p = PathwayManager.GetBasic(item);
                if (p != null && p.Id > 0)
                {
                    list.Add(p.Id);
                }
                else
                {
                    //??
                    status.AddError(thisClassName + string.Format(" - Error - the pathway using Guid: {0} entity was not found.", item.ToString()));
                }
            }
            if (!new Entity_PathwayManager().Replace(entity.RowId, 1, list, ref status))
            {
                isAllValid = false;
            }

            return(isAllValid);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Do delete based on import of deleted documents
        /// </summary>
        /// <param name="credentialRegistryId">NOT CURRENTLY HANDLED</param>
        /// <param name="ctid"></param>
        /// <param name="statusMessage"></param>
        /// <returns></returns>
        public bool Delete(string ctid, ref string statusMessage)
        {
            bool isValid = true;

            if (string.IsNullOrWhiteSpace(ctid))
            {
                statusMessage = thisClassName + ".Delete() Error - a valid CTID must be provided";
                return(false);
            }
            using (var context = new EntityContext())
            {
                try
                {
                    context.Configuration.LazyLoadingEnabled = false;
                    var efEntity = context.CompetencyFramework
                                   .FirstOrDefault(s => s.CTID == ctid);

                    if (efEntity != null && efEntity.Id > 0)
                    {
                        //TODO - may need a check for existing alignments
                        Guid rowId   = efEntity.RowId;
                        var  orgCtid = efEntity.OrganizationCTID ?? "";
                        //need to remove from Entity.
                        //-using before delete trigger - verify won't have RI issues
                        string msg = string.Format(" CompetencyFramework Id: {0}, Name: {1}, Ctid: {2}", efEntity.Id, efEntity.Name, efEntity.CTID);
                        //leaving as virtual?
                        //need to check for in use.
                        //context.CompetencyFramework.Remove( efEntity );
                        efEntity.EntityStateId = 0;
                        efEntity.LastUpdated   = System.DateTime.Now;

                        int count = context.SaveChanges();
                        if (count >= 0)
                        {
                            new ActivityManager().SiteActivityAdd(new SiteActivity()
                            {
                                ActivityType = "CompetencyFramework",
                                Activity     = "Import",
                                Event        = "Delete",
                                Comment      = msg
                            });
                            isValid = true;

                            //add pending request
                            List <String> messages = new List <string>();
                            new SearchPendingReindexManager().AddDeleteRequest(CodesManager.ENTITY_TYPE_COMPETENCY_FRAMEWORK, efEntity.Id, ref messages);

                            //delete all relationships
                            workIT.Models.SaveStatus        status = new SaveStatus();
                            Entity_AgentRelationshipManager earmgr = new Entity_AgentRelationshipManager();
                            earmgr.DeleteAll(rowId, ref status);
                            //also check for any relationships
                            //There could be other orgs from relationships to be reindexed as well!
                        }
                        if (!string.IsNullOrWhiteSpace(orgCtid))
                        {
                            List <String> messages = new List <string>();
                            //mark owning org for updates
                            //	- nothing yet from frameworks
                            var org = OrganizationManager.GetSummaryByCtid(orgCtid);
                            if (org != null && org.Id > 0)
                            {
                                new SearchPendingReindexManager().Add(CodesManager.ENTITY_TYPE_ORGANIZATION, org.Id, 1, ref messages);

                                //also check for any relationships
                                new Entity_AgentRelationshipManager().ReindexAgentForDeletedArtifact(org.RowId);
                            }
                            else
                            {
                                //issue with org ctid not found
                            }
                        }
                    }
                    else
                    {
                        statusMessage = thisClassName + ".Delete() Warning No action taken, as the record was not found.";
                    }
                }
                catch (Exception ex)
                {
                    LoggingHelper.LogError(ex, thisClassName + ".Delete(envelopeId)");
                    statusMessage = FormatExceptions(ex);
                    isValid       = false;
                    if (statusMessage.ToLower().IndexOf("the delete statement conflicted with the reference constraint") > -1)
                    {
                        statusMessage = thisClassName + "Error: this record cannot be deleted as it is being referenced by other items, such as roles or credentials. These associations must be removed before this assessment can be deleted.";
                    }
                }
            }
            return(isValid);
        }
Ejemplo n.º 9
0
        public bool Delete(string envelopeId, string ctid, ref string statusMessage)
        {
            bool isValid = true;

            if ((string.IsNullOrWhiteSpace(envelopeId) || !IsValidGuid(envelopeId)) &&
                string.IsNullOrWhiteSpace(ctid))
            {
                statusMessage = thisClassName + ".Delete() Error - a valid envelope identifier must be provided - OR  valid CTID";
                return(false);
            }
            if (string.IsNullOrWhiteSpace(envelopeId))
            {
                envelopeId = "SKIP ME";
            }
            if (string.IsNullOrWhiteSpace(ctid))
            {
                ctid = "SKIP ME";
            }
            int  orgId  = 0;
            Guid orgUid = new Guid();

            using (var context = new EntityContext())
            {
                try
                {
                    context.Configuration.LazyLoadingEnabled = false;
                    DBEntity efEntity = context.PathwaySet
                                        .FirstOrDefault(s => s.CredentialRegistryId == envelopeId ||
                                                        (s.CTID == ctid)
                                                        );

                    if (efEntity != null && efEntity.Id > 0)
                    {
                        Guid rowId = efEntity.RowId;
                        if (IsValidGuid(efEntity.OwningAgentUid))
                        {
                            Organization org = OrganizationManager.GetBasics(( Guid )efEntity.OwningAgentUid);
                            orgId  = org.Id;
                            orgUid = org.RowId;
                        }
                        //need to remove from Entity.
                        //-using before delete trigger - verify won't have RI issues
                        string msg = string.Format(" PathwaySet. Id: {0}, Name: {1}, Ctid: {2}.", efEntity.Id, efEntity.Name, efEntity.CTID);
                        //18-04-05 mparsons - change to set inactive, and notify - seems to have been some incorrect deletes
                        //context.Pathway.Remove( efEntity );
                        efEntity.EntityStateId = 0;
                        efEntity.LastUpdated   = System.DateTime.Now;
                        int count = context.SaveChanges();
                        if (count > 0)
                        {
                            new ActivityManager().SiteActivityAdd(new SiteActivity()
                            {
                                ActivityType     = "PathwaySet",
                                Activity         = "Import",
                                Event            = "Delete",
                                Comment          = msg,
                                ActivityObjectId = efEntity.Id
                            });
                            isValid = true;
                            //add pending request
                            List <String> messages = new List <string>();
                            new SearchPendingReindexManager().AddDeleteRequest(CodesManager.ENTITY_TYPE_PATHWAY_SET, efEntity.Id, ref messages);
                            //mark owning org for updates (actually should be covered by ReindexAgentForDeletedArtifact
                            new SearchPendingReindexManager().Add(CodesManager.ENTITY_TYPE_ORGANIZATION, orgId, 1, ref messages);

                            //delete all relationships
                            workIT.Models.SaveStatus        status = new SaveStatus();
                            Entity_AgentRelationshipManager earmgr = new Entity_AgentRelationshipManager();
                            earmgr.DeleteAll(rowId, ref status);
                            //also check for any relationships
                            //There could be other orgs from relationships to be reindexed as well!

                            //also check for any relationships
                            new Entity_AgentRelationshipManager().ReindexAgentForDeletedArtifact(orgUid);
                        }
                    }
                    else
                    {
                        statusMessage = thisClassName + ".Delete() Warning No action taken, as the record was not found.";
                    }
                }
                catch (Exception ex)
                {
                    LoggingHelper.LogError(ex, thisClassName + ".Delete(envelopeId)");
                    isValid       = false;
                    statusMessage = FormatExceptions(ex);
                    if (statusMessage.ToLower().IndexOf("the delete statement conflicted with the reference constraint") > -1)
                    {
                        statusMessage = "Error: this PathwaySet cannot be deleted as it is being referenced by other items, such as roles or credentials. These associations must be removed before this PathwaySet can be deleted.";
                    }
                }
            }
            return(isValid);
        }
        }         //

        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 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);
            //consider storing the class properties as Json!

            //derived from
            //where to store this? It commonly require Entity.TransferValueProfile
            var etvlMgr = new Entity_TransferValueProfileManager();

            etvlMgr.SaveList(entity.DerivedFromForImport, entity.RowId, ref status);


            //delete all Entity.Lopp, .Cred, and .Assessment relationships, and then add?
            //would be convenient if a delete wasn't necessary
            //NOTE: this will leave orphan reference objects. Will need to clean up.
            //could check if target is a reference. If so delete, or check if there are other references
            //NOTE: this should have been done in TransferValueServices.HandlingExistingEntity - is done corrently, remove this
            Entity_CredentialManager ecm = new Entity_CredentialManager();

            ecm.DeleteAll(relatedEntity, ref status);
            //
            var eam = new Entity_AssessmentManager();

            eam.DeleteAll(relatedEntity, ref status);
            //
            var elom = new Entity_LearningOpportunityManager();

            elom.DeleteAll(relatedEntity, ref status);
            //
            var etvp = new Entity_TransferValueProfileManager();

            etvp.DeleteAll(relatedEntity, ref status);
            //
            foreach (var item in entity.TransferValueFromImport)
            {
                int newId = 0;
                var from  = EntityManager.GetEntity(item, false);
                if (from == null || from.Id == 0)
                {
                    status.AddError(string.Format("{0}.UpdateParts - TransferValueFromImport. TVP: {1}. An entity was not found for GUID: {2}", thisClassName, entity.Id, item));
                    continue;
                }
                if (from.EntityTypeId == 1)
                {
                    ecm.Add(entity.RowId, from.EntityBaseId, BaseFactory.RELATIONSHIP_TYPE_IS_PART_OF, ref newId, ref status);
                }
                else if (from.EntityTypeId == 3)
                {
                    eam.Add(entity.RowId, from.EntityBaseId, BaseFactory.RELATIONSHIP_TYPE_IS_PART_OF, false, ref status);
                }
                else if (from.EntityTypeId == 7)
                {
                    elom.Add(entity.RowId, from.EntityBaseId, BaseFactory.RELATIONSHIP_TYPE_IS_PART_OF, false, ref status);
                }
            }

            foreach (var item in entity.TransferValueForImport)
            {
                int newId = 0;
                var from  = EntityManager.GetEntity(item, false);
                if (from == null || from.Id == 0)
                {
                    //??
                    status.AddError(string.Format("{0}.UpdateParts - TransferValueForImport. TVP: {1}. An entity was not found for GUID: {2}", thisClassName, entity.Id, item));
                    continue;
                }
                if (from.EntityTypeId == 1)
                {
                    ecm.Add(entity.RowId, from.EntityBaseId, BaseFactory.RELATIONSHIP_TYPE_HAS_PART, ref newId, ref status);
                }
                else if (from.EntityTypeId == 3)
                {
                    eam.Add(entity.RowId, from.EntityBaseId, BaseFactory.RELATIONSHIP_TYPE_HAS_PART, false, ref status);
                }
                else if (from.EntityTypeId == 7)
                {
                    elom.Add(entity.RowId, from.EntityBaseId, BaseFactory.RELATIONSHIP_TYPE_HAS_PART, false, ref status);
                }
            }

            foreach (var item in entity.DerivedFromForImport)
            {
                var from = Get(item);
                if (from == null || from.Id == 0)
                {
                    //??
                    status.AddError(string.Format("{0}.UpdateParts - DerivedFromForImport. TVP: {1}. A TVP was not found for ID: {2}", thisClassName, entity.Id, item));
                    continue;
                }
                //check that not the same as current TVP
                if (from.Id == entity.Id)
                {
                    status.AddError(string.Format("{0}.UpdateParts - DerivedFromForImport. TVP: {1}. The DerivedFrom TVP Id ({2}) is the same as the current TVP ID", thisClassName, entity.Id, item));
                    continue;
                }
                etvp.Add(entity.RowId, item, ref status);
            }

            //ProcessProfile
            Entity_ProcessProfileManager ppm = new Factories.Entity_ProcessProfileManager();

            ppm.DeleteAll(relatedEntity, ref status);
            try
            {
                ppm.SaveList(entity.DevelopmentProcess, Entity_ProcessProfileManager.DEV_PROCESS_TYPE, entity.RowId, ref status);
            }
            catch (Exception ex)
            {
                string message = FormatExceptions(ex);
                LoggingHelper.LogError(ex, thisClassName + string.Format(".AddProfiles() - ProcessProfiles. id: {0}", entity.Id));
                status.AddWarning(thisClassName + ".AddProfiles(). Exceptions encountered handling ProcessProfiles. " + message);
            }
            return(isAllValid);
        }
Ejemplo n.º 12
0
        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);
                    }
                }
            }
        }         //
Ejemplo n.º 13
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;
            }
        }