public bool ProcessEnvelope(ReadEnvelope item, SaveStatus status)
        {
            if (item == null || string.IsNullOrWhiteSpace(item.EnvelopeIdentifier))
            {
                status.AddError("A valid ReadEnvelope must be provided.");
                return(false);
            }

            DateTime createDate         = new DateTime();
            DateTime envelopeUpdateDate = new DateTime();

            if (DateTime.TryParse(item.NodeHeaders.CreatedAt.Replace("UTC", "").Trim(), out createDate))
            {
                status.SetEnvelopeCreated(createDate);
            }
            if (DateTime.TryParse(item.NodeHeaders.UpdatedAt.Replace("UTC", "").Trim(), out envelopeUpdateDate))
            {
                status.SetEnvelopeUpdated(envelopeUpdateDate);
            }
            status.DocumentOwnedBy = item.documentOwnedBy;

            if (item.documentPublishedBy != null)
            {
                if (item.documentOwnedBy == null || (item.documentPublishedBy != item.documentOwnedBy))
                {
                    status.DocumentPublishedBy = item.documentPublishedBy;
                }
            }
            else
            {
                //will need to check elsewhere
                //OR as part of import check if existing one had 3rd party publisher
            }
            string payload            = item.DecodedResource.ToString();
            string envelopeIdentifier = item.EnvelopeIdentifier;
            string ctdlType           = RegistryServices.GetResourceType(payload);
            string envelopeUrl        = RegistryServices.GetEnvelopeUrl(envelopeIdentifier);

            //Already done in  RegistryImport
            //LoggingHelper.WriteLogFile( UtilityManager.GetAppKeyValue( "logFileTraceLevel", 5 ), item.EnvelopeCetermsCtid + "_assessment", payload, "", false );

            if (ImportServiceHelpers.IsAGraphResource(payload))
            {
                //if ( payload.IndexOf( "\"en\":" ) > 0 )
                return(ImportV3(payload, envelopeIdentifier, status));
                //else
                //    return ImportV2( payload, envelopeIdentifier, status );
            }
            else
            {
                status.AddError(thisClassName + ".ImportByResourceUrl - 2019-05-01 ONLY GRAPH BASED IMPORTS ARE HANDLED");
                return(false);

                //LoggingHelper.DoTrace( 5, "		envelopeUrl: " + envelopeUrl );
                //            LoggingHelper.WriteLogFile( 1, "asmt_" + item.EnvelopeIdentifier, payload, "", false );
                //            input = JsonConvert.DeserializeObject<InputEntity>( item.DecodedResource.ToString() );

                //            return Import( input, envelopeIdentifier, status );
            }
        }
        public bool ProcessEnvelope(ReadEnvelope item, SaveStatus status)
        {
            if (item == null || string.IsNullOrWhiteSpace(item.EnvelopeIdentifier))
            {
                status.AddError(thisClassName + " A valid ReadEnvelope must be provided.");
                return(false);
            }

            DateTime createDate         = new DateTime();
            DateTime envelopeUpdateDate = new DateTime();

            if (DateTime.TryParse(item.NodeHeaders.CreatedAt.Replace("UTC", "").Trim(), out createDate))
            {
                status.SetEnvelopeCreated(createDate);
            }
            if (DateTime.TryParse(item.NodeHeaders.UpdatedAt.Replace("UTC", "").Trim(), out envelopeUpdateDate))
            {
                status.SetEnvelopeUpdated(envelopeUpdateDate);
            }

            string payload            = item.DecodedResource.ToString();
            string envelopeIdentifier = item.EnvelopeIdentifier;
            string ctdlType           = RegistryServices.GetResourceType(payload);
            string envelopeUrl        = RegistryServices.GetEnvelopeUrl(envelopeIdentifier);

            LoggingHelper.DoTrace(5, "		envelopeUrl: "+ envelopeUrl);
            LoggingHelper.WriteLogFile(UtilityManager.GetAppKeyValue("logFileTraceLevel", 5), item.EnvelopeCetermsCtid + "_ConceptScheme", payload, "", false);

            //just store input for now
            return(Import(payload, envelopeIdentifier, status));

            //return true;
        } //
        public bool ProcessEnvelope(ReadEnvelope item, SaveStatus status)
        {
            if (item == null || string.IsNullOrWhiteSpace(item.EnvelopeIdentifier))
            {
                status.AddError("A valid ReadEnvelope must be provided.");
                return(false);
            }
            //
            DateTime createDate         = new DateTime();
            DateTime envelopeUpdateDate = new DateTime();

            if (DateTime.TryParse(item.NodeHeaders.CreatedAt.Replace("UTC", "").Trim(), out createDate))
            {
                status.SetEnvelopeCreated(createDate);
            }
            if (DateTime.TryParse(item.NodeHeaders.UpdatedAt.Replace("UTC", "").Trim(), out envelopeUpdateDate))
            {
                status.SetEnvelopeUpdated(envelopeUpdateDate);
            }
            status.DocumentOwnedBy = item.documentOwnedBy;
            if (item.documentOwnedBy != null && item.documentPublishedBy != null && item.documentPublishedBy != item.documentOwnedBy)
            {
                status.DocumentPublishedBy = item.documentPublishedBy;
            }
            //
            string payload = item.DecodedResource.ToString();

            status.EnvelopeId = item.EnvelopeIdentifier;
            string ctdlType = RegistryServices.GetResourceType(payload);

            //string envelopeUrl = RegistryServices.GetEnvelopeUrl( status.EnvelopeId );
            //Already done in  RegistryImport
            //LoggingHelper.WriteLogFile( UtilityManager.GetAppKeyValue( "logFileTraceLevel", 5 ), item.EnvelopeCetermsCtid + "_organization", payload, "", false );


            if (ImportServiceHelpers.IsAGraphResource(payload))
            {
                //if ( payload.IndexOf( "\"en\":" ) > 0 )
                return(ImportV3(payload, status));
                //else
                //    return ImportV2( payload, envelopeIdentifier, status );
            }
            else
            {
                status.AddError("Importing of an organization resource payload is no longer supported. Please provide a /graph/ input.");
                //LoggingHelper.DoTrace( 5, "		envelopeUrl: " + envelopeUrl );
                //LoggingHelper.WriteLogFile( 1, "org_" + item.EnvelopeIdentifier, payload, "", false );
                //input = JsonConvert.DeserializeObject<InputEntity>( item.DecodedResource.ToString() );

                //return Import( input, envelopeIdentifier, status );
                return(false);
            }
        }
        public bool ProcessEnvelope(ReadEnvelope item, SaveStatus status)
        {
            if (item == null || string.IsNullOrWhiteSpace(item.EnvelopeIdentifier))
            {
                status.AddError(thisClassName + " A valid ReadEnvelope must be provided.");
                return(false);
            }

            DateTime createDate         = new DateTime();
            DateTime envelopeUpdateDate = new DateTime();

            if (DateTime.TryParse(item.NodeHeaders.CreatedAt.Replace("UTC", "").Trim(), out createDate))
            {
                status.SetEnvelopeCreated(createDate);
            }
            if (DateTime.TryParse(item.NodeHeaders.UpdatedAt.Replace("UTC", "").Trim(), out envelopeUpdateDate))
            {
                status.SetEnvelopeUpdated(envelopeUpdateDate);
            }
            status.DocumentOwnedBy = item.documentOwnedBy;

            if (item.documentPublishedBy != null)
            {
                if (item.documentOwnedBy == null || (item.documentPublishedBy != item.documentOwnedBy))
                {
                    status.DocumentPublishedBy = item.documentPublishedBy;
                }
            }
            else
            {
                //will need to check elsewhere
                //OR as part of import check if existing one had 3rd party publisher
            }
            string payload            = item.DecodedResource.ToString();
            string envelopeIdentifier = item.EnvelopeIdentifier;
            string ctdlType           = RegistryServices.GetResourceType(payload);
            string envelopeUrl        = RegistryServices.GetEnvelopeUrl(envelopeIdentifier);

            LoggingHelper.DoTrace(5, "		envelopeUrl: "+ envelopeUrl);
            LoggingHelper.WriteLogFile(UtilityManager.GetAppKeyValue("logFileTraceLevel", 5), item.EnvelopeCetermsCtid + "_competencyFrameswork", payload, "", false);
            //input = JsonConvert.DeserializeObject<InputGraph>( item.DecodedResource.ToString() );

            //InputEntity framework = GetFramework( input.Graph );
            //LoggingHelper.DoTrace( 5, "		framework name: " + framework.name.ToString() );

            //just store input for now
            return(Import(payload, envelopeIdentifier, status));

            //return true;
        } //
Ejemplo n.º 5
0
        public bool ProcessEnvelope(ReadEnvelope item, SaveStatus status)
        {
            if (item == null || string.IsNullOrWhiteSpace(item.EnvelopeIdentifier))
            {
                status.AddError("A valid ReadEnvelope must be provided.");
                return(false);
            }
            //
            DateTime createDate         = new DateTime();
            DateTime envelopeUpdateDate = new DateTime();

            if (DateTime.TryParse(item.NodeHeaders.CreatedAt.Replace("UTC", "").Trim(), out createDate))
            {
                status.SetEnvelopeCreated(createDate);
            }
            if (DateTime.TryParse(item.NodeHeaders.UpdatedAt.Replace("UTC", "").Trim(), out envelopeUpdateDate))
            {
                status.SetEnvelopeUpdated(envelopeUpdateDate);
            }
            //
            string payload            = item.DecodedResource.ToString();
            string envelopeIdentifier = item.EnvelopeIdentifier;
            string ctdlType           = RegistryServices.GetResourceType(payload);
            string envelopeUrl        = RegistryServices.GetEnvelopeUrl(envelopeIdentifier);

            LoggingHelper.WriteLogFile(UtilityManager.GetAppKeyValue("logFileTraceLevel", 5), item.EnvelopeCetermsCtid + "_costManifest", payload, "", false);

            if (ImportServiceHelpers.IsAGraphResource(payload))
            {
                //if ( payload.IndexOf( "\"en\":" ) > 0 )
                return(ImportV3(payload, "", status));
                //else
                //    return ImportV2( payload, "", status );
            }
            else
            {
                status.AddError("A valid graph object must be provided for a cost manifest.");
                return(false);
                //LoggingHelper.DoTrace( 5, "		envelopeUrl: " + envelopeUrl );
                //            LoggingHelper.WriteLogFile( 1, "costManifest_" + item.EnvelopeIdentifier, payload, "", false );
                //            input = JsonConvert.DeserializeObject<InputEntity>( item.DecodedResource.ToString() );

                //            return Import( input, envelopeIdentifier, status );
            }
        }
        public bool ProcessEnvelope(ReadEnvelope item, string registryEntityType, int entityTypeId, int cntr, bool doingDownloadOnly = false)
        {
            bool importSuccessfull = false;

            if (item == null || item.DecodedResource == null)
            {
                return(false);
            }

            int newImportId = 0;
            var status      = new SaveStatus
            {
                DoingDownloadOnly = doingDownloadOnly,
                ValidationGroup   = string.Format("{0} Import", registryEntityType)
            };

            DateTime started            = DateTime.Now;
            DateTime envelopeUpdateDate = new DateTime();
            DateTime createDate         = new DateTime();

            if (DateTime.TryParse(item.NodeHeaders.CreatedAt.Replace("UTC", "").Trim(), out createDate))
            {
                status.SetEnvelopeCreated(createDate);
            }
            if (DateTime.TryParse(item.NodeHeaders.UpdatedAt.Replace("UTC", "").Trim(), out envelopeUpdateDate))
            {
                status.SetEnvelopeUpdated(envelopeUpdateDate);
            }

            LoggingHelper.DoTrace(2, string.Format("{0}. {1} CTID {2}, Updated: {3} ", cntr, registryEntityType, item.EnvelopeCetermsCtid, envelopeUpdateDate.ToString()));
            var messages = new List <string>();

            string importError = "";

            importSuccessfull = false;
            //var documentPublishedBy = item.documentPublishedBy ?? ""
            //======================================================
            //21-01-28 mp - moving common code back here to improve maintenance
            if (item.documentPublishedBy != null)
            {
                //only providing DocumentPublishedBy where apparantly a 3PP
                if (item.documentOwnedBy == null || (item.documentPublishedBy != item.documentOwnedBy))
                {
                    status.DocumentPublishedBy = item.documentPublishedBy;
                }
            }
            else
            {
                //will need to check elsewhere
                //OR as part of import check if existing one had 3rd party publisher
            }

            string payload = item.DecodedResource.ToString();

            status.EnvelopeId = item.EnvelopeIdentifier;
            var    ctid             = item.EnvelopeCetermsCtid;
            var    envelopeCtdlType = item.EnvelopeCtdlType;
            string ctdlType         = RegistryServices.GetResourceType(payload);

            //string envelopeUrl = RegistryServices.GetEnvelopeUrl( envelopeIdentifier );
            LoggingHelper.WriteLogFile(UtilityManager.GetAppKeyValue("logFileTraceLevel", 5), item.EnvelopeCetermsCtid + "_" + ctdlType, payload, "", false);
            //
            try
            {
                switch (entityTypeId)
                {
                case 1:
                    //importSuccessfull = credImportMgr.ProcessEnvelope( item, status );
                    if (ctdlType.IndexOf("Organization") > -1 || ctdlType.IndexOf("LearningOpportunity") > -1 || ctdlType.IndexOf("Assessment") > -1)
                    {
                        //how can this happen????
                        //- expected as the FTS search will also search blank nodes
                        importError = string.Format("*****WHILE DOING A CREDENTIAL IMPORT (#{0}), A RECORD OF TYPE: '{1}', CTID: '{2}' WAS ENCOUNTERED! *********************", cntr, ctdlType, ctid);
                        //status.AddError( importError );
                        //LoggingHelper.DoTrace( 1, importError );
                    }
                    //else if ( ctdlType != envelopeCtdlType )
                    //{
                    //	LoggingHelper.DoTrace( 1, "___skipping blank node" );
                    //}
                    else
                    {
                        importSuccessfull = credImportMgr.ImportV3(payload, status);
                    }

                    break;

                case 2:
                    //importSuccessfull = orgImportMgr.ProcessEnvelope( item, status );
                    if (ctdlType.IndexOf("Organization") > -1)
                    {
                        importSuccessfull = orgImportMgr.ImportV3(payload, status);
                    }
                    else
                    {
                        //how can this happen????
                        importError = string.Format("*****WHILE DOING AN ORGANIZATION IMPORT (#{0}), A RECORD OF TYPE: '{1}', CTID: '{2}' WAS ENCOUNTERED! *********************", cntr, ctdlType, ctid);
                        status.AddError(importError);
                        LoggingHelper.DoTrace(1, importError);
                    }
                    break;

                case 3:
                    if (ctdlType.IndexOf("Assessment") > -1)
                    {
                        importSuccessfull = asmtImportMgr.ProcessEnvelope(item, status);
                    }
                    else
                    {
                        //how can this happen????
                        importError = string.Format("*****WHILE DOING AN Assessment IMPORT (#{0}), A RECORD OF TYPE: '{1}', CTID: '{2}' WAS ENCOUNTERED! *********************", cntr, ctdlType, ctid);
                        status.AddError(importError);
                        LoggingHelper.DoTrace(1, importError);
                    }

                    break;

                case 7:
                    if (ctdlType.IndexOf("LearningOpportunity") > -1)
                    {
                        importSuccessfull = loppImportMgr.ProcessEnvelope(item, status);
                    }
                    else
                    {
                        //how can this happen????
                        //importError = string.Format( "*****WHILE DOING A LearningOpportunity IMPORT (#{0}), A RECORD OF TYPE: '{1}', CTID: '{2}' WAS ENCOUNTERED! *********************", cntr, ctdlType, ctid );
                        //status.AddError( importError );
                        //LoggingHelper.DoTrace( 1, importError );
                    }
                    break;

                case 8:        //
                    if (ctdlType.IndexOf("Pathway") > -1)
                    {
                        importSuccessfull = pathwayImportMgr.ProcessEnvelope(item, status);
                    }
                    else
                    {
                        //how can this happen????
                        //importError = string.Format( "*****WHILE DOING A Pathway IMPORT (#{0}), A RECORD OF TYPE: '{1}', CTID: '{2}' WAS ENCOUNTERED! *********************", cntr, ctdlType, ctid );
                        //status.AddError( importError );
                        //LoggingHelper.DoTrace( 1, importError );
                    }
                    break;

                case 9:        //
                    DisplayMessages(string.Format("{0}. Rubrics ({1}) are not handled at this time. ", cntr, entityTypeId));
                    return(true);

                case 10:
                case 17:
                    if (ctdlType.IndexOf("CompetencyFramework") > -1)
                    {
                        importSuccessfull = cfImportMgr.ProcessEnvelope(item, status);
                    }
                    else
                    {
                        //how can this happen????
                        //importError = string.Format( "*****WHILE DOING A CompetencyFramework IMPORT (#{0}), A RECORD OF TYPE: '{1}', CTID: '{2}' WAS ENCOUNTERED! *********************", cntr, ctdlType, ctid );
                        //status.AddError( importError );
                        //LoggingHelper.DoTrace( 1, importError );
                    }

                    break;

                case 11:        //concept scheme
                    //DisplayMessages( string.Format( "{0}. Concept Schemes ({1}) are not handled at this time. ", cntr, entityTypeId ) );
                    importSuccessfull = new ImportConceptSchemes().ProcessEnvelope(item, status);
                    return(true);

                case 19:
                    importSuccessfull = cndManImportMgr.ProcessEnvelope(item, status);
                    break;

                case 20:
                    importSuccessfull = cstManImportMgr.ProcessEnvelope(item, status);
                    break;

                case 23:
                    importSuccessfull = new ImportPathwaySets().ProcessEnvelope(item, status);
                    //DisplayMessages( string.Format( "{0}. PathwaySets ({1}) are not handled at this time. ", cntr, entityTypeId ) );

                    break;

                case 26:
                    importSuccessfull = tvpImportMgr.ProcessEnvelope(item, status);
                    //DisplayMessages( string.Format( "{0}. TransferValueProfiles ({1}) are not handled at this time. ", cntr, entityTypeId ) );

                    break;

                default:
                    DisplayMessages(string.Format("{0}. RegistryImport. Unhandled Entity type encountered: {1} ", cntr, entityTypeId));
                    break;
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.IndexOf("Path '@context', line 1") > 0)
                {
                    importError = "The referenced registry document is using an old schema. Please republish it with the latest schema!";
                    status.AddError(importError);
                }
                else
                {
                    LoggingHelper.LogError(ex, string.Format(registryEntityType + " Exception encountered in envelopeId: {0}", item.EnvelopeIdentifier), true, "CredentialFinder Import exception");
                    status.AddError(ex.Message);
                    importError = ex.Message;
                }

                //make continue on exceptions an option
                //exceptionCtr++;
                //if ( maxExceptions > 0 && exceptionCtr > maxExceptions )
                //{
                //    //arbitrarily stop if large number of exceptions
                //    importNote = string.Format( thisClassName + " - {0} Many exceptions ({1}) were encountered during import - abandoning.", entityType, exceptionCtr );
                //    //Console.WriteLine( importNote );
                //    LoggingHelper.DoTrace( 1, importNote );
                //    LoggingHelper.LogError( importNote, true, thisClassName + "- many exceptions" );
                //    isComplete = true;
                //    break;
                //}
            }
            finally
            {
                if (!importSuccessfull)
                {
                    if (string.IsNullOrWhiteSpace(importError))
                    {
                        importError = string.Join("\r\n", status.GetAllMessages().ToArray());
                    }
                }
                //store document
                //add indicator of success
                newImportId = importMgr.Add(item, entityTypeId, status.Ctid, importSuccessfull, importError, ref messages);
                if (newImportId > 0 && status.Messages != null && status.Messages.Count > 0)
                {
                    //add indicator of current recored
                    string msg = string.Format("========= Messages for {4}, EnvelopeIdentifier: {0}, ctid: {1}, Id: {2}, rowId: {3} =========", item.EnvelopeIdentifier, status.Ctid, status.DocumentId, status.DocumentRowId, registryEntityType);
                    //ensure status has info on the current context, so can be include in messages. Or N/A. The message has the Import.Staging record as the parent
                    importMgr.AddMessages(newImportId, status, ref messages);
                }

                TimeSpan duration = DateTime.Now.Subtract(started);
                LoggingHelper.DoTrace(2, string.Format("         Total Duration: {0:N2} seconds ", duration.TotalSeconds));
            }             //finally


            return(importSuccessfull);
        }