Пример #1
0
        //
        public bool ImportByCtid(string ctid, 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(ctid))
            {
                status.AddError("ImportByCtid - a valid ctid must be provided");
                return(false);
            }

            string statusMessage = "";
            string ctdlType      = "";

            //string payload = "";
            try
            {
                ReadEnvelope envelope = RegistryServices.GetEnvelopeByCtid(ctid, ref statusMessage, ref ctdlType);
                if (envelope == null || string.IsNullOrWhiteSpace(envelope.EnvelopeType))
                {
                    string defCommunity = UtilityManager.GetAppKeyValue("defaultCommunity");
                    string community    = UtilityManager.GetAppKeyValue("additionalCommunity");
                    if (defCommunity != community)
                    {
                        envelope = RegistryServices.GetEnvelopeByCtid(ctid, ref statusMessage, ref ctdlType, community);
                    }
                }
                if (envelope != null && !string.IsNullOrWhiteSpace(envelope.EnvelopeIdentifier))
                {
                    return(ImportEnvelope(envelope, ctdlType, status));
                }
                else
                {
                    status.AddError(string.Format("ImportHelperServices.ImportByCTID. Registry Envelope was not found for: {0}", ctid));
                    return(false);
                }

                /*======OLD ===================
                 * payload = GetResourceGraphByCtid( ctid, ref ctdlType, ref statusMessage );
                 * if (string.IsNullOrWhiteSpace(payload))
                 * {
                 *      string defCommunity = UtilityManager.GetAppKeyValue( "defaultCommunity" );
                 *      string community = UtilityManager.GetAppKeyValue( "additionalCommunity" );
                 *      if ( defCommunity != community )
                 *              payload = GetResourceGraphByCtid( ctid, ref ctdlType, ref statusMessage, community );
                 * }
                 * if ( !string.IsNullOrWhiteSpace( payload ) )
                 * {
                 * LoggingHelper.WriteLogFile( 5, ctid + "_ImportByCtid.json", payload, "", false );
                 * LoggingHelper.DoTrace( 4, string.Format( "RegistryServices.ImportByCtid ctdlType: {0}, ctid: {1} ", ctdlType, ctid ) );
                 * ctdlType = ctdlType.Replace( "ceterms:", "" );
                 * switch ( ctdlType.ToLower() )
                 * {
                 * case "credentialorganization":
                 * case "qacredentialorganization":
                 * case "organization":
                 * return new ImportOrganization().ImportByPayload( payload, status );
                 * //break;CredentialOrganization
                 * case "assessmentprofile":
                 * return new ImportAssessment().ImportByPayload( payload, status );
                 * //break;
                 * case "learningopportunityprofile":
                 * return new ImportLearningOpportunties().ImportByPayload( payload, status );
                 * //break;
                 * case "conditionmanifest":
                 * return new ImportConditionManifests().ImportByPayload( payload, status );
                 * //break;
                 * case "costmanifest":
                 * return new ImportCostManifests().ImportByPayload( payload, status );
                 *              case "competencyframework":
                 *                      return new ImportCompetencyFramesworks().Import( payload, "", status );
                 *              case "conceptscheme":
                 *              case "skos:conceptscheme":
                 *                      return new ImportConceptSchemes().Import( payload, "", status );
                 *              case "pathway":
                 *                      return new ImportPathways().Import( payload, "", status );
                 *              case "pathwayset":
                 *                      return new ImportPathwaySets().Import( payload, "", status );
                 *              case "transfervalue":
                 *              case "transfervalueprofile":
                 *                      return new ImportTransferValue().Import( payload, "", status );
                 *              //break;
                 *              default:
                 * //default to credential
                 * return new ImportCredential().ImportByPayload( payload, status );
                 * //break;
                 * }
                 * }
                 * else
                 * return false;
                 */
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, string.Format("ImportCredential.ImportByCtid(). ctdlType: {0}", ctdlType));
                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);
            }
        }