Ejemplo n.º 1
0
        private bool ValidateProfile(PathwaySet profile, ref SaveStatus status, bool validatingUrls = true)
        {
            status.HasSectionErrors = false;

            if (string.IsNullOrWhiteSpace(profile.Name))
            {
                status.AddError("Error: A PathwaySet Name is required.");
            }
            if (!IsGuidValid(profile.OwningAgentUid))
            {
                //first determine if this is populated in edit mode
                status.AddError("An owning organization must be provided.");
            }

            if (string.IsNullOrWhiteSpace(profile.Description))
            {
                status.AddWarning("A PathwaySet Description must be entered");
            }
            if (string.IsNullOrWhiteSpace(profile.SubjectWebpage))
            {
                status.AddError("A Subject Webpage name must be entered");
            }

            else if (validatingUrls && !IsUrlValid(profile.SubjectWebpage, ref commonStatusMessage))
            {
                status.AddError("The PathwaySet Subject Webpage is invalid. " + commonStatusMessage);
            }


            return(status.WasSectionValid);
        }
        //public bool SaveList( List<ThisEntity> list, Guid parentUid, ref SaveStatus status )
        //{
        //	if ( list == null || list.Count == 0 )
        //		return true;

        //	bool isAllValid = true;
        //	foreach ( ThisEntity item in list )
        //	{
        //		Save( item, parentUid, ref status );
        //	}

        //	return isAllValid;
        //}

        public bool SaveList(List <CredentialAlignmentObjectProfile> list, Guid parentUid, ref SaveStatus status)
        {
            if (!IsValidGuid(parentUid))
            {
                status.AddError(string.Format("A valid parent identifier was not provided to the {0}.Add method.", thisClassName));
                return(false);
            }

            Entity parent = EntityManager.GetEntity(parentUid);

            if (parent == null || parent.Id == 0)
            {
                status.AddError("Error - the parent entity was not found.");
                return(false);
            }
            DeleteAll(parent, ref status);

            if (list == null || list.Count == 0)
            {
                return(true);
            }
            ThisEntity entity     = new ThisEntity();
            bool       isAllValid = true;

            foreach (CredentialAlignmentObjectProfile item in list)
            {
                entity = new ThisEntity();
                MapToAlignmentObject(item, entity);
                Save(entity, parent, ref status);
            }

            return(isAllValid);
        }
Ejemplo n.º 3
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);
            }

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

            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 );
            }
        }
Ejemplo n.º 4
0
        public bool ValidateProfile(ThisEntity profile, ref bool isEmpty, ref SaveStatus status)
        {
            status.HasSectionErrors = false;

            isEmpty = false;
            //check if empty

            //&& ( profile.EstimatedCost == null || profile.EstimatedCost.Count == 0 )
            if (string.IsNullOrWhiteSpace(profile.ProfileName))
            {
                status.AddError("A Condition Manifest name must be entered");
            }
            if (string.IsNullOrWhiteSpace(profile.Description))
            {
                status.AddWarning("A Condition Manifest Description must be entered");
            }

            //not sure if this will be selected, or by context
            if (!IsValidGuid(profile.OwningAgentUid))
            {
                status.AddError("An owning organization must be selected");
            }

            if (!IsUrlValid(profile.SubjectWebpage, ref commonStatusMessage))
            {
                status.AddWarning("The Subject Webpage Url is invalid " + commonStatusMessage);
            }

            return(!status.HasSectionErrors);
        }
        public bool UpdateModifiedDate(Guid entityUid, ref SaveStatus status)
        {
            bool isValid = false;

            if (!IsValidGuid(entityUid))
            {
                status.AddError(thisClassName + ".UpdateModifiedDate(). Error - missing a valid identifier for the Entity");
                return(false);
            }
            using (var context = new EntityContext())
            {
                DBentity efEntity = context.Entity
                                    .FirstOrDefault(s => s.EntityUid == entityUid);

                if (efEntity != null && efEntity.Id > 0)
                {
                    efEntity.LastUpdated = DateTime.Now;
                    int count = context.SaveChanges();
                    if (count >= 0)
                    {
                        isValid = true;
                        LoggingHelper.DoTrace(7, thisClassName + string.Format(".UpdateModifiedDate - update last updated for TypeId: {0}, BaseId: {1}", efEntity.EntityTypeId, efEntity.EntityBaseId));
                    }
                }
                else
                {
                    status.AddError(thisClassName + ".UpdateModifiedDate(). Error - Entity  was not found.");
                    LoggingHelper.LogError(thisClassName + string.Format(".UpdateModifiedDate - record was not found. entityUid: {0}", entityUid), true);
                }
            }

            return(isValid);
        }///
Ejemplo n.º 6
0
        /// <summary>
        /// Persist Entity Credential
        /// </summary>
        /// <param name="parentUid"></param>
        /// <param name="credentialId"></param>
        /// <param name="relationshipTypeId">1-HasPart; 2-IsPartOf; 3-IsETPLResource</param>
        /// <param name="newId">Return record id of the new record</param>
        /// <param name="status"></param>
        /// <returns></returns>
        public bool Add(Guid parentUid, int credentialId, int relationshipTypeId,
                        ref int newId,
                        ref SaveStatus status)
        {
            if (!IsValidGuid(parentUid))
            {
                status.AddError("Error: the parent identifier was not provided.");
            }

            if (credentialId < 1)
            {
                status.AddError("Error: a valid credential was not provided.");
                return(false);
            }

            Entity parent = EntityManager.GetEntity(parentUid);

            if (parent == null || parent.Id == 0)
            {
                //status.AddError( "Error - the parent entity was not found." );
                return(false);
            }

            return(Add(parent, credentialId, relationshipTypeId, ref newId, ref status));
        }
        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 SaveList(List <ThisEntity> list, Credential credential, ref SaveStatus status)
        {
            if (credential == null || credential.Id < 1)
            {
                status.AddError("Error: the credential identifier was not provided.");
                return(false);
            }

            DBEntity efEntity = new DBEntity();
            Entity   parent   = EntityManager.GetEntity(credential.RowId);

            if (parent == null || parent.Id == 0)
            {
                status.AddError("Error - the parent entity was not found.");
                return(false);
            }
            DeleteAll(parent, ref status);

            if (list == null || list.Count == 0)
            {
                return(true);
            }

            status.HasSectionErrors = false;
            foreach (ThisEntity item in list)
            {
                Save(item, parent, ref status);
            }

            return(status.WasSectionValid);
        }         //
Ejemplo n.º 9
0
        public bool SaveList(List <ThisEntity> list, Guid parentUid, int IdentityValueTypeId, ref SaveStatus status)
        {
            if (!IsValidGuid(parentUid))
            {
                status.AddError(string.Format("A valid parent identifier was not provided to the {0}.Add method.", thisClassName));
                return(false);
            }


            Entity parent = EntityManager.GetEntity(parentUid);

            if (parent == null || parent.Id == 0)
            {
                status.AddError("Error - the parent entity was not found.");
                return(false);
            }
            DeleteAll(parent, ref status);

            if (list == null || list.Count == 0)
            {
                return(true);
            }

            bool isAllValid = true;

            foreach (ThisEntity item in list)
            {
                item.IdentityValueTypeId = IdentityValueTypeId;
                Add(parent, item, ref status);
            }

            return(isAllValid);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Add an Entity_IdentifierValueManager
        /// </summary>
        /// <param name="parentUid"></param>
        /// <param name="entity"></param>
        /// <param name="messages"></param>
        /// <returns></returns>
        private int Add(Entity parent,
                        ThisEntity entity,
                        ref SaveStatus status)
        {
            int id    = 0;
            int count = 0;

            //Entity parent = EntityManager.GetEntity( parentUid );
            if (parent == null || parent.Id == 0)
            {
                status.AddError("Error - the parent entity was not found.");
                return(0);
            }
            using (var context = new EntityContext())
            {
                DBEntity efEntity = new DBEntity();
                try
                {
                    efEntity = new DBEntity();

                    MapToDB(entity, efEntity);
                    efEntity.EntityId = parent.Id;
                    efEntity.Created  = System.DateTime.Now;

                    context.Entity_IdentifierValue.Add(efEntity);

                    // submit the change to database
                    count = context.SaveChanges();
                    if (count > 0)
                    {
                        id = efEntity.Id;
                        return(efEntity.Id);
                    }
                    else
                    {
                        //?no info on error
                        status.AddError("Error - the add was not successful.");
                        string message = thisClassName + string.Format(".Add Failed", "Attempted to add a Entity_IdentifierValue for a profile. The process appeared to not work, but there was no exception, so we have no message, or no clue. Parent Profile: {0}, Type: {1}, learningOppId: {2}, createdById: {3}", parent.EntityUid, parent.EntityType, entity.IdentifierType);
                        EmailManager.NotifyAdmin(thisClassName + ".Add Failed", message);
                    }
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException dbex)
                {
                    string message = HandleDBValidationError(dbex, thisClassName + ".Add() ", "Entity_Entity_IdentifierValue");
                    status.AddError("Error - the save was not successful. " + message);
                    LoggingHelper.LogError(dbex, thisClassName + string.Format(".Save(), Parent: {0} ({1})", parent.EntityBaseName, parent.EntityBaseId));
                }
                catch (Exception ex)
                {
                    string message = FormatExceptions(ex);
                    status.AddError("Error - the save was not successful. " + message);
                    LoggingHelper.LogError(ex, thisClassName + string.Format(".Save(), Parent: {0} ({1})", parent.EntityBaseName, parent.EntityBaseId));
                }
            }
            return(id);
        }
        private int HandleComponentCondition(PathwayComponentCondition input, Pathway pathway, PathwayComponent component, ref SaveStatus status)
        {
            int           newId         = 0;
            List <string> messages      = new List <string>();
            string        statusMessage = "";

            input.ParentComponentId = component.Id;
            if (pccm.Save(input, ref messages))
            {
                newId = input.Id;
                activityMgr.SiteActivityAdd(new SiteActivity()
                {
                    ActivityType     = "PathwayComponent",
                    Activity         = "Import",
                    Event            = "Add",
                    Comment          = string.Format("Added PathwayComponentCondition via Import: '{0}' for Component: '{1}'", input.Name, component.Name),
                    ActivityObjectId = newId,
                });
            }
            else
            {
                status.AddErrorRange(messages);
            }

            if (newId == 0 || (!string.IsNullOrWhiteSpace(statusMessage) && statusMessage != "successful"))
            {
                status.AddError(string.Format("Row: Issue encountered updating pathway ComponentCondition: {0} for Component: '{1}': {2}", input.Name, component.Name, statusMessage));
                return(0);
            }
            //==================================================


            //handle target components - better organization to move this to HandleComponentCondition since all components should now exist
            List <PathwayComponent> profiles = new List <PathwayComponent>();

            messages = new List <string>();
            foreach (var tc in input.HasTargetComponentList)
            {
                var targetComponent = PathwayComponentManager.Get(tc);
                if (targetComponent == null || targetComponent.Id == 0)
                {
                    //shouldn't happen here - although the add attempt could have failed?
                    status.AddError(string.Format("The target pathway component: {0} for ConditionComponent: {1} was not found. This could have been due the an issue adding the component - which should have resulted in an earlier error message.", tc, input.Name));
                    continue;
                }
                profiles.Add(targetComponent);
            }
            //now replace relationships
            if (!epcmgr.Replace(input.RowId, PathwayComponent.PathwayComponentRelationship_TargetComponent, profiles, ref status))
            {
                //status.AddErrorRange( messages );
            }

            return(newId);
        }
        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);
            }
        }
        /// <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>
        /// Delete all EarningsProfiles for parent
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public bool DeleteAll(Guid parentUid, ref SaveStatus status)
        {
            bool   isValid = true;
            int    count   = 0;
            Entity parent  = EntityManager.GetEntity(parentUid);

            if (parent == null || parent.Id == 0)
            {
                status.AddError(thisClassName + ".DeleteAll Error - the provided target parent entity was not provided.");
                return(false);
            }
            if (parent == null || parent.Id == 0)
            {
                status.AddError(thisClassName + ". Error - the provided target parent entity was not provided.");
                return(false);
            }
            using (var context = new EntityContext())
            {
                //check if target is a reference object and is only in use here
                var results = context.Entity_EarningsProfile
                              .Where(s => s.EntityId == parent.Id)
                              .OrderBy(s => s.Created)
                              .ToList();
                if (results == null || results.Count == 0)
                {
                    return(true);
                }

                foreach (var item in results)
                {
                    if (item.EarningsProfile != null && item.EarningsProfile.EntityStateId > 0)
                    {
                        var messages = new List <string>();
                        new EarningsProfileManager().Delete(item.Id, ref messages);
                        if (messages.Any())
                        {
                            status.AddErrorRange(messages);
                        }
                        continue;
                    }
                    context.Entity_EarningsProfile.Remove(item);
                    count = context.SaveChanges();
                    if (count > 0)
                    {
                    }
                }
            }

            return(isValid);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Retrieve an resource from the registry by ctid and do import
        /// </summary>
        /// <param name="ctid"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public bool ImportByCtid(string ctid, SaveStatus status)
        {
            if (string.IsNullOrWhiteSpace(ctid))
            {
                status.AddError(thisClassName + ".ImportByCtid - a valid ctid must be provided");
                return(false);
            }

            //this is currently specific, assumes envelop contains a credential
            //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
            {
                //probably always want to get by envelope
                ReadEnvelope envelope = RegistryServices.GetEnvelopeByCtid(ctid, ref statusMessage, ref ctdlType);
                if (envelope != null && !string.IsNullOrWhiteSpace(envelope.EnvelopeIdentifier))
                {
                    return(CustomProcessEnvelope(envelope, status));
                }
                else
                {
                    return(false);
                }
                //string payload = RegistryServices.GetResourceByCtid( ctid, ref ctdlType, ref statusMessage );

                //if ( !string.IsNullOrWhiteSpace( payload ) )
                //{
                //	input = JsonConvert.DeserializeObject<InputEntity>( payload.ToString() );
                //	//ctdlType = RegistryServices.GetResourceType( payload );
                //	return Import( mgr, input, "", status );
                //}
                //else
                //	return false;
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + string.Format(".ImportByCtid(). CTID: {0}", ctid));
                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 GetEnvelopePayload(ReadEnvelope item, SaveStatus status, ref string payload)
        {
            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.EnvelopeCreatedDate = createDate;
            }
            if (DateTime.TryParse(item.NodeHeaders.UpdatedAt.Replace("UTC", "").Trim(), out envelopeUpdateDate))
            {
                status.EnvelopeUpdatedDate = envelopeUpdateDate;
            }
            //
            payload = item.DecodedResource.ToString();
            string envelopeIdentifier = item.EnvelopeIdentifier;
            string ctdlType           = RegistryServices.GetResourceType(payload);

            //string envelopeUrl = RegistryServices.GetEnvelopeUrl( envelopeIdentifier );


            return(true);
        }
        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;
        } //
Ejemplo n.º 18
0
        /// <summary>
        /// For isPartOf, the list is the entity where the credential is a part of.
        /// Get the entity,
        /// </summary>
        /// <param name="parentList">List of credential Ids for the parent where is part of</param>
        /// <param name="parentUid"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public bool SaveIsPartOfList(List <int> parentList, int credentialId, ref SaveStatus status)
        {
            if (parentList == null || parentList.Count == 0)
            {
                return(true);
            }
            int  newId      = 0;
            bool isAllValid = true;

            foreach (int parentCredentialId in parentList)
            {
                Entity partOfEntity = EntityManager.GetEntity(1, parentCredentialId);
                if (partOfEntity == null || partOfEntity.Id == 0)
                {
                    status.AddError(string.Format(thisClassName + ".SaveIsPartOfList(). Error - the related part Of (parent) credential was not found. parentCredentialId: {0}, credentialId: {1}", parentCredentialId, credentialId));
                    continue;
                }

                Add(partOfEntity, credentialId, BaseFactory.RELATIONSHIP_TYPE_IS_PART_OF, ref newId, ref status);
                if (newId == 0)
                {
                    isAllValid = false;
                }
            }

            return(isAllValid);
        }
Ejemplo n.º 19
0
        public void AddLanguages(List <ThisEntity> profiles,
                                 Guid parentUid,
                                 int parentTypeId,
                                 ref SaveStatus status,
                                 int categoryId)
        {
            if (profiles == null || profiles.Count == 0)
            {
                return;
            }
            Entity parent = EntityManager.GetEntity(parentUid);

            if (parent == null || parent.Id == 0)
            {
                status.AddError(thisClassName + string.Format(". Error - the parent entity was not found. parentUid: {0}", parentUid));
                return;
            }
            EnumeratedItem code      = new EnumeratedItem();
            string         textValue = "";

            foreach (var item in profiles)
            {
                if (string.IsNullOrWhiteSpace(item.TextValue))
                {
                    continue;
                }
                code = CodesManager.GetLanguage(item.TextValue);
                if (code.Id > 0)
                {
                    textValue = string.Format("{0} ", code.Name);
                    AddTextValue(textValue, parent.Id, ref status, categoryId);
                }
            }
        } //
Ejemplo n.º 20
0
        public bool ValidateProfile(ThisEntity profile, ref SaveStatus status)
        {
            status.HasSectionErrors = false;

            if (string.IsNullOrWhiteSpace(profile.Name))
            {
                status.AddError("An Pathway name must be entered");
            }
            if (string.IsNullOrWhiteSpace(profile.Description))
            {
                status.AddWarning("An Pathway Description must be entered");
            }
            if (!IsValidGuid(profile.OwningAgentUid))
            {
                status.AddWarning("An owning organization must be selected");
            }

            if (string.IsNullOrWhiteSpace(profile.SubjectWebpage))
            {
                status.AddWarning("Error - A Subject Webpage name must be entered");
            }

            else if (!IsUrlValid(profile.SubjectWebpage, ref commonStatusMessage))
            {
                status.AddWarning("The Pathway Subject Webpage is invalid. " + commonStatusMessage);
            }

            return(status.WasSectionValid);
        }
        public bool SaveList(List <int> list, Guid parentUid, ref SaveStatus status)
        {
            //first do a deleteAll
            Entity parent = EntityManager.GetEntity(parentUid);

            if (parent == null || parent.Id == 0)
            {
                status.AddError("Error - the parent entity was not found.");
                return(false);
            }
            DeleteAll(parent, ref status);

            if (list == null || list.Count == 0)
            {
                return(true);
            }

            bool isAllValid = true;

            foreach (int item in list)
            {
                Save(parent, item, ref status);
            }

            return(isAllValid);
        }
        }         //

        /// <summary>
        /// Delete all pathways for a parent, typically a pathwaySet
        /// </summary>
        /// <param name="parentUid"></param>
        /// <param name="recordId"></param>
        /// <param name="statusMessage"></param>
        /// <returns></returns>
        public bool DeleteAll(Guid parentUid, ref SaveStatus status)
        {
            bool isValid = false;

            //need to get Entity.Id
            Entity parent = EntityManager.GetEntity(parentUid);

            if (parent == null || parent.Id == 0)
            {
                status.AddError("Error - the parent entity was not found.");
                return(false);
            }
            try
            {
                using (var context = new EntityContext())
                {
                    context.Entity_HasPathway.RemoveRange(context.Entity_HasPathway.Where(s => s.EntityId == parent.Id));
                    int count = context.SaveChanges();
                    if (count >= 0)
                    {
                        isValid = true;
                    }
                    else
                    {
                        //may not be any?
                        //may be should to a read check first?
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + ".DeleteAll( Guid parentUid, ref SaveStatus status )");
            }
            return(isValid);
        }
        private void ReplacePathwayComponentRelationships(int componentNbr, Guid parentComponentUid, List <Guid> input, Pathway pathway, int pathwayComponentRelationship, string property, ref SaveStatus status)
        {
            var pclist = new List <PathwayComponent>();

            foreach (var pcGuid in input)
            {
                //look up component
                var pc = PathwayComponentManager.Get(pcGuid, PathwayComponentManager.componentActionOfNone);
                if (pc != null && pc.Id > 0)
                {
                    pclist.Add(pc);
                }
                else
                {
                    //???
                    status.AddError(string.Format("Component: {0}. Error unable to find PathwayComponent for relationship: {1} using pvGUID: {1}.", componentNbr, pathwayComponentRelationship, pcGuid));
                }
            }
            //do replace
            if (!epcmgr.Replace(parentComponentUid, pathwayComponentRelationship, pclist, ref status))
            {
                //nothing more to report?
                //status.AddError( string.Format( "Component: {0}, Issue encountered replacing {1} component relationships.", componentNbr, property ));
            }
        }
Ejemplo n.º 24
0
        //public bool DeleteAll( Entity parent, ref SaveStatus status, DateTime? lastUpdated = null )
        //{
        //	bool isValid = true;
        //	if ( parent == null || parent.Id == 0 )
        //	{
        //		status.AddError( thisClassName + ". Error - the provided target parent entity was not provided." );
        //		return false;
        //	}
        //	int expectedDeleteCount = 0;
        //	try
        //	{
        //		using ( var context = new EntityContext() )
        //		{
        //			var results = context.Entity_CostProfile.Where( s => s.EntityId == parent.Id && ( lastUpdated == null || s.LastUpdated < lastUpdated ) )
        //		.ToList();
        //			if ( results == null || results.Count == 0 )
        //				return true;
        //			expectedDeleteCount = results.Count;

        //			foreach ( var item in results )
        //			{
        //				context.Entity_CostProfile.Remove( item );
        //				var count = context.SaveChanges();
        //				if ( count > 0 )
        //				{

        //				}
        //			}
        //		}
        //	}
        //	catch ( System.Data.Entity.Infrastructure.DbUpdateConcurrencyException dbcex )
        //	{
        //		if ( dbcex.Message.IndexOf( "an unexpected number of rows (0)" ) > 0 )
        //		{
        //			//don't know why this happens, quashing for now.
        //			LoggingHelper.DoTrace( 1, string.Format( thisClassName + ".DeleteAll. Parent type: {0}, ParentId: {1}, expectedDeletes: {2}. Message: {3}", parent.EntityTypeId, parent.EntityBaseId, expectedDeleteCount, dbcex.Message ) );
        //		}
        //		else
        //		{
        //			var msg = BaseFactory.FormatExceptions( dbcex );
        //			LoggingHelper.DoTrace( 1, string.Format( thisClassName + ".DeleteAll. ParentType: {0}, baseId: {1}, DbUpdateConcurrencyException: {2}", parent.EntityType, parent.EntityBaseId, msg ) );
        //		}

        //	}
        //	catch ( Exception ex )
        //	{
        //		var msg = BaseFactory.FormatExceptions( ex );
        //		LoggingHelper.DoTrace( 1, string.Format( thisClassName + ".DeleteAll. ParentType: {0}, baseId: {1}, exception: {2}", parent.EntityType, parent.EntityBaseId, msg ) );
        //	}
        //	return isValid;
        //}
        //
        private bool UpdateParts(ThisEntity entity, ref SaveStatus status)
        {
            bool isAllValid = true;

            //
            try
            {
                if (new Entity_ReferenceManager().Add(entity.Condition, entity.RowId, CodesManager.ENTITY_TYPE_COST_PROFILE, ref status, CodesManager.PROPERTY_CATEGORY_CONDITION_ITEM, false) == false)
                {
                    isAllValid = false;
                }

                //JurisdictionProfile
                Entity_JurisdictionProfileManager jpm = new Entity_JurisdictionProfileManager();
                jpm.SaveList(entity.Jurisdiction, entity.RowId, Entity_JurisdictionProfileManager.JURISDICTION_PURPOSE_SCOPE, ref status);
            }
            catch (Exception ex)
            {
                LoggingHelper.DoTrace(1, thisClassName + ".UpdateParts(). Exception while processing condition/jurisdiction. " + ex.Message);
                status.AddError(ex.Message);
            }


            if (entity.Items != null && entity.Items.Count > 0)
            {
                new CostProfileItemManager().SaveList(entity.Items, entity.Id, ref status);
            }

            return(isAllValid);
        }
        private bool UpdateParts(ThisEntity entity, ref SaveStatus status)
        {
            bool   isAllValid    = true;
            Entity relatedEntity = EntityManager.GetEntity(entity.RowId);

            if (relatedEntity == null || relatedEntity.Id == 0)
            {
                status.AddError("Error - the related Entity was not found.");
                return(false);
            }

            EntityPropertyManager mgr = new EntityPropertyManager();

            //first clear all properties
            mgr.DeleteAll(relatedEntity, ref status);
            //
            if (mgr.AddProperties(entity.ExternalInputType, entity.RowId, CodesManager.ENTITY_TYPE_PROCESS_PROFILE, CodesManager.PROPERTY_CATEGORY_EXTERNAL_INPUT_TYPE, false, ref status) == false)
            {
                isAllValid = false;
            }
            if (mgr.AddProperties(entity.DataCollectionMethodType, entity.RowId, CodesManager.ENTITY_TYPE_PROCESS_PROFILE, CodesManager.PROPERTY_CATEGORY_DATA_COLLECTION_METHOD_TYPE, false, ref status) == false)
            {
                isAllValid = false;
            }

            if (HandleTargets(entity, relatedEntity, ref status) == false)
            {
                isAllValid = false;
            }
            //
            return(isAllValid);
        }
Ejemplo n.º 26
0
        public bool DeleteAll(Entity parent, ref SaveStatus status)
        {
            bool isValid = true;

            //Entity parent = EntityManager.GetEntity( parentUid );
            if (parent == null || parent.Id == 0)
            {
                status.AddError(thisClassName + ". Error - the provided target parent entity was not provided.");
                return(false);
            }
            using (var context = new EntityContext())
            {
                context.Entity_IdentifierValue.RemoveRange(context.Entity_IdentifierValue.Where(s => s.EntityId == parent.Id));
                int count = context.SaveChanges();
                if (count > 0)
                {
                    isValid = true;
                }
                else
                {
                    //if doing a delete on spec, may not have been any properties
                }
            }

            return(isValid);
        }
Ejemplo n.º 27
0
        public bool UpdateParts(ThisEntity entity, ref SaveStatus status)
        {
            status.HasSectionErrors = false;
            Entity relatedEntity = EntityManager.GetEntity(entity.RowId);

            if (relatedEntity == null || relatedEntity.Id == 0)
            {
                status.AddError("Error - the related Entity was not found.");
                return(false);
            }

            //ConditionProfile
            Entity_ConditionProfileManager emanager = new Entity_ConditionProfileManager();

            //deleteall is handled in SaveList
            //emanager.DeleteAll( relatedEntity, ref status );

            emanager.SaveList(entity.Requires, Entity_ConditionProfileManager.ConnectionProfileType_Requirement, entity.RowId, ref status);
            emanager.SaveList(entity.Recommends, Entity_ConditionProfileManager.ConnectionProfileType_Recommendation, entity.RowId, ref status);
            emanager.SaveList(entity.Corequisite, Entity_ConditionProfileManager.ConnectionProfileType_Corequisite, entity.RowId, ref status);
            emanager.SaveList(entity.EntryCondition, Entity_ConditionProfileManager.ConnectionProfileType_EntryCondition, entity.RowId, ref status);
            emanager.SaveList(entity.Renewal, Entity_ConditionProfileManager.ConnectionProfileType_Renewal, entity.RowId, ref status);

            return(status.WasSectionValid);
        }         //
        }           //

        /// <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("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(ProcessEnvelope(envelope, status));
                }
                else
                {
                    return(false);
                }
            } catch (Exception ex)
            {
                LoggingHelper.LogError(ex, "ImportCredential.ImportByEnvelopeId()");
                return(false);
            }
        }
Ejemplo n.º 29
0
 public static MP.TransferValueProfile HandlingExistingEntity(string ctid, ref SaveStatus status)
 {
     MP.TransferValueProfile entity = new MP.TransferValueProfile();
     //warning-
     entity = TransferValueProfileManager.GetByCtid(ctid);
     if (entity != null && entity.Id > 0)
     {
         Entity relatedEntity = EntityManager.GetEntity(entity.RowId);
         if (relatedEntity == null || relatedEntity.Id == 0)
         {
             status.AddError(string.Format("Error - the related Entity for transfer value: '{0}' ({1}), was not found.", entity.Name, entity.Id));
             return(entity);
         }
         //we know for this type, there will entity.learningopp, entity.assessment and entity.credential relationships, and quick likely blank nodes.
         //delete related entity if a reference
         //there are for and from relationships!! - OK in this case it will be all
         new Entity_AssessmentManager().DeleteAll(relatedEntity, ref status);
         new Entity_CredentialManager().DeleteAll(relatedEntity, ref status);
         new Entity_LearningOpportunityManager().DeleteAll(relatedEntity, ref status);
         //also
         entity.TransferValueFor  = new List <TopLevelObject>();
         entity.TransferValueFrom = new List <TopLevelObject>();
     }
     return(entity);
 }
Ejemplo n.º 30
0
        //public bool DeleteAll( Entity parent, ref SaveStatus status )
        //{
        //	bool isValid = true;
        //	//Entity parent = EntityManager.GetEntity( parentUid );
        //	if ( parent == null || parent.Id == 0 )
        //	{
        //		status.AddError( thisClassName + ".DeleteAll Error - the provided target parent entity was not provided." );
        //		return false;
        //	}
        //	using ( var context = new EntityContext() )
        //	{
        //		context.HoldersProfile.RemoveRange( context.HoldersProfile.Where( s => s.EntityId == parent.Id ) );
        //		int count = context.SaveChanges();
        //		if ( count > 0 )
        //		{
        //			isValid = true;
        //		}
        //		else
        //		{
        //			//if doing a delete on spec, may not have been any properties
        //		}
        //	}

        //	return isValid;
        //}
        /// <summary>
        /// Parts:
        /// - Jurisdiction
        /// - DataSetProfile
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public bool UpdateParts(ThisEntity entity, ref SaveStatus status)
        {
            bool   isAllValid    = true;
            Entity relatedEntity = EntityManager.GetEntity(entity.RowId);

            if (relatedEntity == null || relatedEntity.Id == 0)
            {
                status.AddError("Error - the related Entity was not found.");
                return(false);
            }

            //JurisdictionProfile
            Entity_JurisdictionProfileManager jpm = new Entity_JurisdictionProfileManager();

            //do deletes - NOTE: other jurisdictions are added in: UpdateAssertedIns
            jpm.DeleteAll(relatedEntity, ref status);
            if (!jpm.SaveList(entity.Jurisdiction, entity.RowId, Entity_JurisdictionProfileManager.JURISDICTION_PURPOSE_SCOPE, ref status))
            {
                isAllValid = false;
            }
            //datasetProfiles
            if (!new DataSetProfileManager().SaveList(entity.RelevantDataSet, relatedEntity, ref status))
            {
                isAllValid = false;
            }

            return(isAllValid);
        }