Creating Custom Folder Entities
  • Updated on 09 Dec 2013
  • 3 minutes to read
  • Print
  • Dark
    Light

Creating Custom Folder Entities

  • Print
  • Dark
    Light

Custom Folder Entities are special objects that can 'reside' in a Decisions folder. If you are just looking to easily store data in a table a simple ORM object (described i) may be all you need. However, if you are looking for expanded functionality you may want to create a Custom Folder Entity. Below is a list of some of the benefits this entity provides.

  • Your entity will inherit some basic fields like DateCreated, DateModified, CreatedBy, ModifiedBy which will be automatically updated by Decisions when you interact with this object.
  • Your data will be protected by being able to participate in the Logical Delete methodology employeed by the Decisions platform. In other words when you delete a folder entity, the entity is only logically deleted (an IsDeleted flag is set to true), so that your data is recoverable if later you want to "undelete" the entity.
  • Your entity will be able to 'live' inside of Decisions folders. This means that you entities can be logically grouped inside the Decisions portal and that they will show up in the default "All Entities" reports.
  • Your entity can have custom actions associated with it (an action to Edit your entity is described below).

To begin, you will need to create a new class that inherits from AbstractFolderEntity .

 [ORMEntity("quote")] //
[DataContract]
[Exportable]
public class Quote : AbstractFolderEntity

You will write your object in the same way as described in the ORM Basics article. Below is a sample for the Quote  entitythat we will build. ```
[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;
}
}


Now that you've written the fields of your folder entity, you can attach actions to your entity. These action will show up in menus in the Decisions portal when this entity is selected. Below is an example of how to attach an "Edit" action to your entity.

public override BaseActionType[] GetActions(AbstractUserContext userContext, EntityActionType[] types)
{
List actions = new List();

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));
}

}


And here is how the EditQuote method would look.

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 orm = new ORM();
var myentity = orm.Fetch(entityId);
myentity.EntityName = quote;
orm.Store(myentity);
}

Now you have a fully functional folder entity. However, you don't have an easy way to create one in the portal. One way to easily create an action to create your new folder entity is by creating a Folder Behavior. The article [Creating Custom Folder Behavior](http://documentation.decisions.com/sdk/creating-custom-folder-behavior) more fully describes how to create a folder behavior. Below is an example of how you would write one with an action to create this new folder entity.

namespace DecisionsSampleCustomFolderEntity
{
class QuoteHolderFolderBehavior : DefaultFolderBehavior
{
public override BaseActionType[] GetFolderActions(Folder folder, BaseActionType[] proposedActions, EntityActionType[] types)
{
List actions = new List((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);
        }
    }
}

}




Was this article helpful?