ORM: Creating Custom Folder Entities
- 04 Oct 2022
- 2 Minutes to read
- Print
- DarkLight
ORM: Creating Custom Folder Entities
- Updated on 04 Oct 2022
- 2 Minutes to read
- Print
- DarkLight
Article summary
Did you find this summary helpful?
Thank you for your feedback
Overview
Custom Folder Entities are special objects that can reside in a Decisions Folder. A Custom Folder Entity offers several benefits if a user wants expanded functionality when storing data. These benefits include:
- The entity will inherit some basic fields like DateCreated, DateModified, CreatedBy, and ModifiedBy, which will be automatically updated by Decisions when interacting with the object.
- Data will be protected by participating in the Logical Delete methodology employed by Decisions. When a Folder entity is deleted, the entity is only logically deleted (an IsDeleted flag is set to true). The data is recoverable if later it is necessary to restore the entity.
- The entity will be able to exist inside of Decisions folders. The entities can be logically grouped inside the Decisions portal and appear in the default All Entities reports.
- The entity can have custom actions associated with it.
Example
This example will demonstrate how to create a Quote Folder Entity.
- Create a new class that inherits from AbstractFolderEntity.
[ORMEntity("quote")] // [DataContract] [Exportable] public class Quote : AbstractFolderEntity
- Write an ORM object.
[ORMPrimaryKeyField] private string quoteId; [DataMember] [ExcludeInDescription] [PropertyHidden] public string QuoteId { get { return quoteId; } set { quoteId = value; } } [DataMember] [PropertyClassification("Quote", 1)] [EmptyStringRule] public override string EntityName { get { return base.EntityName; } set { base.EntityName = value; } } [PropertyHidden] [ExcludeInDescription] public override string EntityDescription { get { return base.EntityDescription; } set { base.EntityDescription = value; } }
- Attach an action to the entity.Actions will show up in menus in the Decisions Portal when this entity is selected. The code snippet below demonstrates attaching an Edit action to the entity.
public override BaseActionType[] GetActions(AbstractUserContext userContext, EntityActionType[] types) { List<BaseActionType> actions = new List<BaseActionType>(); Account userAccount = userContext.GetAccount(); FolderPermission perms = FolderService.Instance.GetAccountEffectivePermission(new SystemUserContext(), this.EntityFolderID, userAccount.AccountID); if (FolderPermission.CanAdministrate == (FolderPermission.CanAdministrate & perms)) { actions.Add(new GetStringAction("Edit Quote", "Edits a Quote", new InvokeServiceParamMethod<string>(EditQuote), "Edit Quote", "Enter Quote", EntityName, GetTextType.LongText)); } return actions.ToArray(); }
The EditQuote method will resemble the below code snippet.public void EditQuote(AbstractUserContext user, string entityId, string quote) { if (entityId == null) throw new ArgumentNullException("entityId"); if (quote == null) throw new ArgumentNullException("quote"); if (quote.Trim() == string.Empty) throw new ArgumentException("Quote cannot be empty", "quote"); ORM<Quote> orm = new ORM<Quote>(); var myEntity = orm.Fetch(entityId); myEntity.EntityName = quote; orm.Store(myEntity); }
Create an Action to Create Folder Entity
One way to easily create an action to create a new Folder Entity is by creating a Folder Behavior. Below is an example demonstrating how to write one with an action to create the new Folder Entity.
To learn more about creating custom Folder Behaviors, click here
public class QuoteHolderFolderBehavior : DefaultFolderBehavior
{
public override BaseActionType[] GetFolderActions(Folder folder, BaseActionType[] proposedActions, EntityActionType[] types)
{
List<BaseActionType> actions = new List<BaseActionType>((proposedActions ?? new BaseActionType[0]));
//actions.Add(new OpenUrlAction("Open Decisions.com", "Clicking this action will open http://www.decisions.com", "http://www.decisions.com"));
actions.Add(new GetStringAction("Add Quote", "Adds a Quote",
new InvokeServiceParamMethod<string>(CreateQuote), "Add Quote",
"Enter Quote", null, GetTextType.LongText));
return actions.ToArray();
}
public override bool? CanBeRootFolder()
{
return true;
}
public override bool CanBeSetByUser()
{
return true;
}
public void CreateQuote(AbstractUserContext user, string entityFolderID, string quote)
{
if (entityFolderID == null)
throw new ArgumentNullException("entityFolderID");
if (quote == null)
throw new ArgumentNullException("quote");
if (quote.Trim() == string.Empty)
throw new ArgumentException("Quote cannot be empty", "quote");
ORM<Quote> orm = new ORM<Quote>();
Quote quotesData = new Quote();
quotesData.EntityName = quote;
quotesData.EntityFolderID = entityFolderID;
try
{
orm.Store(quotesData);
}
catch (Exception ex)
{
throw new Exception(string.Format("error saving Quote {0}", quote), ex);
}
}
}
ORM Basics
Was this article helpful?