Пример #1
0
        public bool DoesComponentExist(string ctid, ref OutputComponent entity)
        {
            bool exists = false;

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

            return(exists);
        }
Пример #2
0
        //currently
        public bool DoesEntityExist(string ctid, ref ThisEntity entity)
        {
            bool exists = false;

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

            return(exists);
        }
        public static ThisEntityDetail GetDetailByCtidForAPI(string ctid, bool skippingCache = false)
        {
            var output = EntityHelper.PathwaySetGetByCtid(ctid);

            return(MapToAPI(output));
        }
Пример #4
0
        }         //

        public bool Import(string payload, string envelopeIdentifier, SaveStatus status)
        {
            LoggingHelper.DoTrace(6, "ImportPathways - entered.");
            List <string>  messages          = new List <string>();
            bool           importSuccessfull = false;
            EntityServices mgr = new EntityServices();
            //
            InputEntity input           = new InputEntity();
            var         inputComponents = new List <InputComponent>();
            var         mainEntity      = new Dictionary <string, object>();
            //
            Dictionary <string, object> dictionary = RegistryServices.JsonToDictionary(payload);
            object graph = dictionary["@graph"];
            //serialize the graph object
            var glist = JsonConvert.SerializeObject(graph);

            //parse graph in to list of objects
            JArray graphList = JArray.Parse(glist);
            var    bnodes    = new List <BNode>();
            int    cntr      = 0;

            foreach (var item in graphList)
            {
                cntr++;
                if (cntr == 1)
                {
                    var main = item.ToString();
                    //may not use this. Could add a trace method
                    mainEntity = RegistryServices.JsonToDictionary(main);
                    input      = JsonConvert.DeserializeObject <InputEntity>(main);
                }
                else
                {
                    //may have blank nodes?
                    var bn = item.ToString();
                    bnodes.Add(JsonConvert.DeserializeObject <BNode>(bn));
                    var child = item.ToString();
                    if (child.IndexOf("_:") > -1)
                    {
                        bnodes.Add(JsonConvert.DeserializeObject <BNode>(child));
                    }
                    else if (child.IndexOf("Component") > -1)
                    {
                        inputComponents.Add(JsonConvert.DeserializeObject <InputComponent>(child));
                    }
                    else
                    {
                        //unexpected
                        Dictionary <string, object> unexpected = RegistryServices.JsonToDictionary(child);
                        object unexpectedType = unexpected["@type"];
                        status.AddError("Unexpected document type");
                    }
                }
            }

            MappingHelperV3 helper = new MappingHelperV3(CodesManager.ENTITY_TYPE_PATHWAY);

            helper.entityBlankNodes  = bnodes;
            helper.CurrentEntityCTID = input.CTID;
            helper.CurrentEntityName = input.Name.ToString();

            status.EnvelopeId = envelopeIdentifier;
            try
            {
                string ctid           = input.CTID;
                string referencedAtId = input.CtdlId;

                LoggingHelper.DoTrace(5, "		name: "+ input.Name.ToString());
                LoggingHelper.DoTrace(6, "		url: "+ input.SubjectWebpage);
                LoggingHelper.DoTrace(5, "		ctid: "+ input.CTID);
                LoggingHelper.DoTrace(6, "		@Id: "+ input.CtdlId);
                status.Ctid = ctid;

                if (status.DoingDownloadOnly)
                {
                    return(true);
                }


                if (!DoesEntityExist(input.CTID, ref output))
                {
                    //TODO - perhaps create a pending pathway immediately

                    //set the rowid now, so that can be referenced as needed
                    output.RowId = Guid.NewGuid();
                    LoggingHelper.DoTrace(1, string.Format(thisClassName + ".ImportV3(). Record was NOT found using CTID: '{0}'", input.CTID));
                }
                else
                {
                    LoggingHelper.DoTrace(1, string.Format(thisClassName + ".ImportV3(). Found record: '{0}' using CTID: '{1}'", input.Name, input.CTID));
                }
                helper.currentBaseObject = output;

                output.Name           = helper.HandleLanguageMap(input.Name, output, "Name");
                output.Description    = helper.HandleLanguageMap(input.Description, output, "Description");
                output.SubjectWebpage = input.SubjectWebpage;
                output.CTID           = input.CTID;
                //TBD handling of referencing third party publisher
                if (!string.IsNullOrWhiteSpace(status.DocumentPublishedBy))
                {
                    //output.PublishedByOrganizationCTID = status.DocumentPublishedBy;
                    var porg = OrganizationManager.GetSummaryByCtid(status.DocumentPublishedBy);
                    if (porg != null && porg.Id > 0)
                    {
                        //TODO - store this in a json blob??????????
                        //this will result in being added to Entity.AgentRelationship
                        output.PublishedBy = new List <Guid>()
                        {
                            porg.RowId
                        };
                    }
                    else
                    {
                        //if publisher not imported yet, all publishee stuff will be orphaned
                        var entityUid = Guid.NewGuid();
                        var statusMsg = "";
                        var resPos    = referencedAtId.IndexOf("/resources/");
                        var swp       = referencedAtId.Substring(0, (resPos + "/resources/".Length)) + status.DocumentPublishedBy;
                        int orgId     = new OrganizationManager().AddPendingRecord(entityUid, status.DocumentPublishedBy, swp, ref statusMsg);
                    }
                }
                else
                {
                    //may need a check for existing published by to ensure not lost
                    if (output.Id > 0)
                    {
                        if (output.OrganizationRole != null && output.OrganizationRole.Any())
                        {
                            var publishedByList = output.OrganizationRole.Where(s => s.RoleTypeId == 30).ToList();
                            if (publishedByList != null && publishedByList.Any())
                            {
                                var pby = publishedByList[0].ActingAgentUid;
                                output.PublishedBy = new List <Guid>()
                                {
                                    publishedByList[0].ActingAgentUid
                                };
                            }
                        }
                    }
                }
                //warning this gets set to blank if doing a manual import by ctid
                output.CredentialRegistryId = envelopeIdentifier;

                //BYs - do owned and offered first
                output.OfferedBy = helper.MapOrganizationReferenceGuids("Pathway.OfferedBy", input.OfferedBy, ref status);
                //note need to set output.OwningAgentUid to the first entry
                output.OwnedBy = helper.MapOrganizationReferenceGuids("Pathway.OwnedBy", input.OwnedBy, ref status);
                if (output.OwnedBy != null && output.OwnedBy.Count > 0)
                {
                    output.OwningAgentUid        = output.OwnedBy[0];
                    helper.CurrentOwningAgentUid = output.OwnedBy[0];
                }
                else
                {
                    //add warning?
                    if (output.OfferedBy == null && output.OfferedBy.Count == 0)
                    {
                        status.AddWarning("document doesn't have an owning or offering organization.");
                    }
                }
                //hasPart could contain all components. The API should have done a validation
                //not clear if necessary to do anything here
                //this would be a first step to create pending records?
                if (input.HasPart != null && input.HasPart.Count() > 0)
                {
                    output.HasPartList = helper.MapEntityReferenceGuids("Pathway.HasPart", input.HasPart, CodesManager.ENTITY_TYPE_PATHWAY_COMPONENT, ref status);
                }
                //
                output.HasChildList       = helper.MapEntityReferenceGuids("Pathway.HasChild", input.HasChild, CodesManager.ENTITY_TYPE_PATHWAY_COMPONENT, ref status);
                output.HasDestinationList = helper.MapEntityReferenceGuids("Pathway.HasDestination", input.HasDestinationComponent, CodesManager.ENTITY_TYPE_PATHWAY_COMPONENT, ref status);

                //has progression model
                //TODO - IMPORT CONCEPT SCHEMES
                // will need to check if related scheme has been imported.
                output.ProgressionModelURI = ResolutionServices.ExtractCtid(input.HasProgressionModel);

                output.Keyword = helper.MapToTextValueProfile(input.Keyword, output, "Keyword");
                output.Subject = helper.MapCAOListToTextValueProfile(input.Subject, CodesManager.PROPERTY_CATEGORY_SUBJECT);
                //Industries/occupations
                output.Industries  = helper.MapCAOListToCAOProfileList(input.IndustryType);
                output.Occupations = helper.MapCAOListToCAOProfileList(input.OccupationType);

                //may need to save the pathway and then handle components
                //or do a create pending for hasDestination and any hasChild (actually already done by MapEntityReferenceGuids)

                //=== if any messages were encountered treat as warnings for now
                if (messages.Count > 0)
                {
                    status.SetMessages(messages, true);
                }
                //components now or after save ?
                foreach (var item in inputComponents)
                {
                    var c = ImportComponent(item, output, bnodes, status);
                    output.HasPart.Add(c);
                }                //

                //adding common import pattern
                importSuccessfull = mgr.Import(output, ref status);
                //
                status.DocumentId    = output.Id;
                status.DetailPageUrl = string.Format("~/pathway/{0}", output.Id);
                status.DocumentRowId = output.RowId;
                //if record was added to db, add to/or set EntityResolution as resolved
                int ierId = new ImportManager().Import_EntityResolutionAdd(referencedAtId,
                                                                           ctid,
                                                                           CodesManager.ENTITY_TYPE_PATHWAY,
                                                                           output.RowId,
                                                                           output.Id,
                                                                           (output.Id > 0),
                                                                           ref messages,
                                                                           output.Id > 0);
                //just in case - not sure if applicable, as will want to do components if the pathway exists
                if (status.HasErrors)
                {
                    importSuccessfull = false;
                    //email an error report, and/or add to activity log?
                }
                //
                //if ( output.Id > 0 )
                //{
                //	foreach ( var item in inputComponents )
                //	{
                //		var c=ImportComponent( item, output, bnodes, status );
                //		output.HasPart.Add( c );
                //	}//
                //	//call method to handle components
                //}
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, string.Format("Exception encountered in envelopeId: {0}", envelopeIdentifier), false, "Pathway Import exception");
            }

            return(importSuccessfull);
        }
Пример #5
0
        public static ThisEntityDetail GetDetailForAPI(int id, bool skippingCache = false)
        {
            var output = EntityHelper.GetDetail(id, skippingCache);

            return(MapToAPI(output));
        }