Exemple #1
0
        public static MC.Enumeration MapRatingsListToEnumermation(List <string> input)
        {
            //TBD = do we need anything for emumeration, or just items?
            MC.Enumeration output = new workIT.Models.Common.Enumeration();
            if (input == null || input.Count == 0)
            {
                return(output);
            }
            string ctdlType = "";
            string status   = "";

            foreach (var item in input)
            {
                string resource = RegistryServices.GetResourceByUrl(item, ref ctdlType, ref status);

                var rating = Newtonsoft.Json.JsonConvert.DeserializeObject <RatingEntity>(resource);

                if (rating != null && (rating.Name != null))
                {
                    output.Items.Add(new workIT.Models.Common.EnumeratedItem()
                    {
                        SchemaName  = rating.Type ?? "",
                        Name        = rating.Name.ToString(),
                        Description = rating.Description.ToString(),

                        URL = rating.CtdlId
                    });;
                }
            }
            return(output);
        }         //
Exemple #2
0
        }         //

        public List <MC.CredentialAlignmentObjectProfile> MapCAOListToCAOProfileList(List <string> input, ref List <string> messages)
        {
            List <MC.CredentialAlignmentObjectProfile> output = new List <workIT.Models.Common.CredentialAlignmentObjectProfile>();

            MC.CredentialAlignmentObjectProfile entity = new MC.CredentialAlignmentObjectProfile();

            if (input == null || input.Count == 0)
            {
                return(output);
            }
            string ctdlType = "";
            string status   = "";

            foreach (var item in input)
            {
                string resource = RegistryServices.GetResourceByUrl(item, ref ctdlType, ref status);
                if (string.IsNullOrWhiteSpace(resource))
                {
                    messages.Add(string.Format("NavyServices.MapCAOListToCAOProfileList. Unable to resolve Rating URL: {0}", item));
                    continue;
                }
                var rating = Newtonsoft.Json.JsonConvert.DeserializeObject <RatingEntity>(resource);

                if (rating != null && (rating.Name != null))
                {
                    entity = new MC.CredentialAlignmentObjectProfile()
                    {
                        TargetNode    = rating.CtdlId,
                        CodedNotation = rating.CodedNotation ?? ""
                    };

                    entity.TargetNodeName            = HandleLanguageMap(rating.Name, currentBaseObject, "TargetNodeName");
                    entity.TargetNodeName_Map        = lastLanguageMapString;
                    entity.TargetNodeDescription     = HandleLanguageMap(rating.Description, currentBaseObject, "TargetNodeDescription", false);
                    entity.TargetNodeDescription_Map = lastLanguageMapString;

                    //if ( !string.IsNullOrWhiteSpace( item.Framework ) )
                    //{
                    //	if ( item.Framework.ToLower().IndexOf( "credentialengineregistry.org/resources/ce-" ) == -1
                    //		&& item.Framework.ToLower().IndexOf( "credentialengineregistry.org/graph/ce-" ) == -1 )
                    //	{
                    //		entity.SourceUrl = item.Framework;
                    //	}
                    //	else
                    //	{
                    //		entity.FrameworkUri = item.Framework;
                    //	}
                    //}
                    output.Add(entity);
                }
            }
            return(output);
        }
        /// <summary>
        /// Retrieve an envelop from the registry and do import
        /// </summary>
        /// <param name="envelopeId"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        //public bool ImportByEnvelopeId( string envelopeId, SaveStatus status )
        //{
        //	//this is currently specific, assumes envelop contains a credential
        //	//can use the hack fo GetResourceType to determine the type, and then call the appropriate import method

        //	if ( string.IsNullOrWhiteSpace( envelopeId ) )
        //	{
        //		status.AddError( thisClassName + ".ImportByEnvelope - a valid envelope id must be provided" );
        //		return false;
        //	}

        //	string statusMessage = "";
        //	//EntityServices mgr = new EntityServices();
        //	string ctdlType = "";
        //	try
        //	{
        //		ReadEnvelope envelope = RegistryServices.GetEnvelope( envelopeId, ref statusMessage, ref ctdlType );
        //		if ( envelope != null && !string.IsNullOrWhiteSpace( envelope.EnvelopeIdentifier ) )
        //		{
        //			return CustomProcessEnvelope( envelope, status );
        //		}
        //		else
        //			return false;
        //	}
        //	catch ( Exception ex )
        //	{
        //		LoggingHelper.LogError( ex, thisClassName + ".ImportByEnvelopeId()" );
        //		status.AddError( ex.Message );
        //		if ( ex.Message.IndexOf( "Path '@context', line 1" ) > 0 )
        //		{
        //			status.AddWarning( "The referenced registry document is using an old schema. Please republish it with the latest schema!" );
        //		}
        //		return false;
        //	}
        //}

        public bool ImportByResourceUrl(string resourceUrl, SaveStatus status)
        {
            if (string.IsNullOrWhiteSpace(resourceUrl))
            {
                status.AddError(thisClassName + ".ImportByResourceUrl - a valid resourceUrl must be provided");
                return(false);
            }
            //this is currently specific, assumes envelop contains an organization
            //can use the hack for GetResourceType to determine the type, and then call the appropriate import method
            string statusMessage = "";
            //EntityServices mgr = new EntityServices();
            string ctdlType = "";

            try
            {
                string payload = RegistryServices.GetResourceByUrl(resourceUrl, ref ctdlType, ref statusMessage);

                if (!string.IsNullOrWhiteSpace(payload))
                {
                    if (ImportServiceHelpers.IsAGraphResource(payload))
                    {
                        //if ( payload.IndexOf( "\"en\":" ) > 0 )
                        return(ImportV3(payload, "", status));
                        //else
                        //    return ImportV2( payload, "", status );
                    }
                    else
                    {
                        status.AddError(thisClassName + ".ImportByResourceUrl - 2019-05-01 ONLY GRAPH BASED IMPORTS ARE HANDLED");
                        return(false);
                        //input = JsonConvert.DeserializeObject<InputEntity>( payload.ToString() );
                        //                  return Import( input, "", status );
                    }
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + ".ImportByResourceUrl()");
                status.AddError(ex.Message);
                if (ex.Message.IndexOf("Path '@context', line 1") > 0)
                {
                    status.AddWarning("The referenced registry document is using an old schema. Please republish it with the latest schema!");
                }
                return(false);
            }
        }
        /// <summary>
        /// NOTE: this will have to be updated to get by /graph/
        /// </summary>
        /// <param name="resourceUrl"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public bool ImportByResourceUrl(string resourceUrl, SaveStatus status)
        {
            //this is currently specific, assumes envelop contains a credential
            //can use the hack fo GetResourceType to determine the type, and then call the appropriate import method
            string         statusMessage = "";
            EntityServices mgr           = new EntityServices();
            string         ctdlType      = "";
            string         payload       = "";

            try
            {
                payload = RegistryServices.GetResourceByUrl(resourceUrl, ref ctdlType, ref statusMessage);

                if (!string.IsNullOrWhiteSpace(payload))
                {
                    return(ImportV3(payload, "", status));
                }
                else
                {
                    status.AddError(statusMessage);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.IndexOf("Unexpected character encountered while parsing") > -1)
                {
                    //usually indicates the schema is old
                    //now what
                    Dictionary <string, object> dictionary = RegistryServices.JsonToDictionary(payload);
                }
                else
                {
                    LoggingHelper.LogError(ex, thisClassName + ".ImportByResourceUrl()");
                }

                return(false);
            }
        }