Beispiel #1
0
        //public bool Import( InputEntity input, string envelopeIdentifier, SaveStatus status )
        //{
        //	List<string> messages = new List<string>();
        //	bool importSuccessfull = false;
        //          EntityServices mgr = new EntityServices();
        //          //try
        //          //{
        //          //input = JsonConvert.DeserializeObject<InputEntity>( item.DecodedResource.ToString() );
        //          string ctid = input.Ctid;
        //	string referencedAtId = input.CtdlId;
        //	LoggingHelper.DoTrace( 5, "		name: " + input.Name );
        //	LoggingHelper.DoTrace( 6, "		url: " + input.CostDetails );
        //	LoggingHelper.DoTrace( 5, "		ctid: " + input.Ctid );
        //	LoggingHelper.DoTrace( 5, "		@Id: " + input.CtdlId );
        //          status.Ctid = ctid;

        //          if ( status.DoingDownloadOnly )
        //              return true;

        //          if ( !DoesEntityExist( input.Ctid, ref output ) )
        //	{
        //		output.RowId = Guid.NewGuid();
        //	}

        //	//re:messages - currently passed to mapping but no errors are trapped??
        //	//				- should use SaveStatus and skip import if errors encountered (vs warnings)

        //	output.Name = input.Name;
        //	output.Description = input.Description;

        //	output.CTID = input.Ctid;
        //	output.CredentialRegistryId = envelopeIdentifier;
        //	output.CostDetails = input.CostDetails;

        //	output.OwningAgentUid = MappingHelper.MapOrganizationReferencesGuid( input.CostManifestOf, ref status );

        //	output.StartDate = MappingHelper.MapDate( input.StartDate, "StartDate", ref status );
        //	output.EndDate = MappingHelper.MapDate( input.EndDate, "StartDate", ref status );

        //	output.EstimatedCosts = MappingHelper.FormatCosts( input.EstimatedCost, ref status );

        //	status.DocumentId = output.Id;
        //	status.DocumentRowId = output.RowId;

        //	//=== if any messages were encountered treat as warnings for now
        //	if ( messages.Count > 0 )
        //		status.SetMessages( messages, true );

        //	importSuccessfull = mgr.Import( output, ref status );
        //	//just in case
        //	if ( status.HasErrors )
        //		importSuccessfull = false;

        //	//if record was added to db, add to/or set EntityResolution as resolved
        //	int ierId = new ImportManager().Import_EntityResolutionAdd( referencedAtId,
        //				ctid,
        //				CodesManager.ENTITY_TYPE_COST_MANIFEST,
        //				output.RowId,
        //				output.Id,
        //				false,
        //				ref messages,
        //				output.Id > 0 );
        // //     }
        //	//catch ( Exception ex )
        //	//{

        // //             LoggingHelper.LogError( ex, string.Format( "Exception encountered in envelopeId: {0}", envelopeIdentifier ), false, "Finder Import exception" );
        //	//}

        //	return importSuccessfull;
        //}

        public bool ImportV3(string payload, string envelopeIdentifier, SaveStatus status)
        {
            InputEntityV3 input      = new InputEntityV3();
            var           bnodes     = new List <BNodeV3>();
            var           mainEntity = new Dictionary <string, object>();

            //status.AddWarning( "The resource uses @graph and is not handled yet" );

            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);
            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 <InputEntityV3>(main);
                }
                else
                {
                    var bn = item.ToString();
                    bnodes.Add(JsonConvert.DeserializeObject <BNodeV3>(bn));
                }
            }

            List <string>   messages          = new List <string>();
            bool            importSuccessfull = false;
            EntityServices  mgr    = new EntityServices();
            MappingHelperV3 helper = new MappingHelperV3(20);

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

            string ctid           = input.CTID;
            string referencedAtId = input.CtdlId;

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

            if (status.DoingDownloadOnly)
            {
                return(true);
            }
            try
            {
                if (!DoesEntityExist(input.CTID, ref output))
                {
                    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.CTID = input.CTID;
                output.CredentialRegistryId = envelopeIdentifier;
                output.CostDetails          = input.CostDetails;

                output.OwningAgentUid        = helper.MapOrganizationReferencesGuid("CostManifest.OwningAgentUid", input.CostManifestOf, ref status);
                helper.CurrentOwningAgentUid = output.OwningAgentUid;
                //
                output.StartDate = helper.MapDate(input.StartDate, "StartDate", ref status);
                output.EndDate   = helper.MapDate(input.EndDate, "StartDate", ref status);

                output.EstimatedCost = helper.FormatCosts(input.EstimatedCost, ref status);

                status.DocumentId    = output.Id;
                status.DocumentRowId = output.RowId;

                //=== if any messages were encountered treat as warnings for now
                if (messages.Count > 0)
                {
                    status.SetMessages(messages, true);
                }

                importSuccessfull = mgr.Import(output, ref status);
                //just in case
                if (status.HasErrors)
                {
                    importSuccessfull = false;
                }

                //if record was added to db, add to/or set EntityResolution as resolved
                int ierId = new ImportManager().Import_EntityResolutionAdd(referencedAtId,
                                                                           ctid,
                                                                           CodesManager.ENTITY_TYPE_COST_MANIFEST,
                                                                           output.RowId,
                                                                           output.Id,
                                                                           false,
                                                                           ref messages,
                                                                           output.Id > 0);
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, string.Format("CostManifest ImportV3. Exception encountered for CTID: {0}", ctid), false, "CostManifest Import exception");
            }
            finally
            {
            }

            return(importSuccessfull);
        }
Beispiel #2
0
        public bool Import(InputEntity input, string envelopeIdentifier, SaveStatus status)
        {
            List <string>  messages          = new List <string>();
            bool           importSuccessfull = false;
            EntityServices mgr = new EntityServices();
            //try
            //{
            //input = JsonConvert.DeserializeObject<InputEntity>( item.DecodedResource.ToString() );
            string ctid           = input.Ctid;
            string referencedAtId = input.CtdlId;

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

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

            if (!DoesEntityExist(input.Ctid, ref output))
            {
                output.RowId = Guid.NewGuid();
            }

            //re:messages - currently passed to mapping but no errors are trapped??
            //				- should use SaveStatus and skip import if errors encountered (vs warnings)

            output.Name        = input.Name;
            output.Description = input.Description;

            output.CTID = input.Ctid;
            output.CredentialRegistryId = envelopeIdentifier;
            output.CostDetails          = input.CostDetails;

            output.OwningAgentUid = MappingHelper.MapOrganizationReferencesGuid(input.CostManifestOf, ref status);

            output.StartDate = MappingHelper.MapDate(input.StartDate, "StartDate", ref status);
            output.EndDate   = MappingHelper.MapDate(input.EndDate, "StartDate", ref status);

            output.EstimatedCosts = MappingHelper.FormatCosts(input.EstimatedCost, ref status);

            status.DocumentId    = output.Id;
            status.DocumentRowId = output.RowId;

            //=== if any messages were encountered treat as warnings for now
            if (messages.Count > 0)
            {
                status.SetMessages(messages, true);
            }

            importSuccessfull = mgr.Import(output, ref status);
            //just in case
            if (status.HasErrors)
            {
                importSuccessfull = false;
            }

            //if record was added to db, add to/or set EntityResolution as resolved
            int ierId = new ImportManager().Import_EntityResolutionAdd(referencedAtId,
                                                                       ctid,
                                                                       CodesManager.ENTITY_TYPE_COST_MANIFEST,
                                                                       output.RowId,
                                                                       output.Id,
                                                                       false,
                                                                       ref messages,
                                                                       output.Id > 0);

            //     }
            //catch ( Exception ex )
            //{

            //             LoggingHelper.LogError( ex, string.Format( "Exception encountered in envelopeId: {0}", envelopeIdentifier ), false, "Finder Import exception" );
            //}

            return(importSuccessfull);
        }