Service Interceptor Guide

Is anyone aware of a guide to writing service interceptors?  I have the REST API Documentation which has a small section, but really looking for information on what references I need to include, how to setup the development environment, any actions such as user authentication that need to be completed?

A HelloWorld interceptor tutorial that goes through these would be so helpful if anyone has one...

Parents
  • Hi All,

    Good day.

    Is there any one have a clear ideas about how to set up the plugin configurations?

    it is not hard to write .net code, it is not hard to test the .net code.

    But finally when I put the custom plugins into the REST, it is very hard to figure out where when and what is happening.

    from user point view, things are clear, like 1, if someone already had a mobile in the system, stop insert same mobile number, 2, or stop same email address entry.

    The REST API document is missing the detail how client calls REST.

    also there is something not in the document. what is RegEx? like this:

    2014-12-09 16:30:44.3753|Debug|Verb and Placement matched but RegEx for URI match '^CRM/Constituents/[^/]*/Snapshot(/)?$' didn't match the actual URI 'ReferenceData/SystemDefaults/Summary'.

    I can see the REST structure is very complicated.

    is there some documents about this part of REST?

    have fun

    Ben

     

     

     

  • $organization in reply to Ben Gu

    HI All,

    Good day.

    is there anyone can tell me why same codes worked with "POST" method (insert) didn't work with "PUT" method(update)?

    is there something different inside REST between "POST" URI and "PUT" URI?

    Thank you very much for your help.

    have fun

    Ben

  • $organization in reply to Ben Gu

    namespace MTC_REST.TessituraPlugins.ConstituentService
    {
        public class DupEmailLoginPreventionSnapshot
        {
            public static PluginData Operation(PluginData input)
            {
                string update = string.Empty;
                string insert = string.Empty;
                update = @"PUT";
                insert = @"POST";
                if (input.Verb == insert)
                {
                    var constituent = SerializationHelper.Deserialize<ConstituentSnapshot>(input.Data);
                    var myEmail = input.Data;
                    if (myEmail.Name.ToString().ToLower().Contains("electronicaddress"))
                    {
                        string EmailAddress = string.Empty;
                        int mycheck = 0;
                        EmailAddress = constituent.ElectronicAddress.Address.ToString();
                        mycheck = checkEmail(EmailAddress);
                        if (mycheck > 0)
                        {
                            throw new PluginValidationException("Email Address is already under another account " + mycheck.ToString() + ". It is not allowed for this account.");
                        }
                    }
                    return input;
                }

                else if (input.Verb == update)///this part codes have the same logic but it never hit by plugin.
                {
                    var constituentUpdate = SerializationHelper.Deserialize<ConstituentSnapshot>(input.Data);
                    var myEmailUpdate = input.Data;
                    if (myEmailUpdate.Name.ToString().ToLower().Contains("electronicaddress"))
                    {
                        string EmailAddress = string.Empty;
                        int mycheck = 0;
                        EmailAddress = constituentUpdate.ElectronicAddress.Address.ToString();
                        mycheck = checkEmail(EmailAddress);
                        if (mycheck > 0)
                        {
                            throw new PluginValidationException("Email Address is already under another account " + mycheck.ToString() + ". It is not allowed for this account.");
                        }
                    }

                    return input;
                }
                else
                {
                    return input;
                }
            }

            public static int checkEmail(string emailaddress)
            {

                string tmp = string.Empty;
                int myreturn = 0;
                var sqlCommandHelper = new SqlCommandHelper();
                var sqlStatement = "dbo.LP_MTC_INTERCEPTION_STOP_EMAIL_LOGIN_DUP";
                var parameters = new Dictionary<string, string>();
                parameters.Add("@EMAILADDRESS", emailaddress);
                System.Data.DataSet ds=  sqlCommandHelper.ExecuteSqlCommandReturnDataSet(sqlStatement, parameters, true);
                System.Data.DataTable tb = ds.Tables[0];
                if (tb.Rows.Count>0)
                {
                    tmp = tb.Rows[0]["customer_no"].ToString();
                }
                if (tmp.Trim().Length > 0)
                {
                    myreturn =Convert.ToInt32( tmp.Trim().ToString());
                }
                return myreturn;
            }
        }
    }

Reply
  • $organization in reply to Ben Gu

    namespace MTC_REST.TessituraPlugins.ConstituentService
    {
        public class DupEmailLoginPreventionSnapshot
        {
            public static PluginData Operation(PluginData input)
            {
                string update = string.Empty;
                string insert = string.Empty;
                update = @"PUT";
                insert = @"POST";
                if (input.Verb == insert)
                {
                    var constituent = SerializationHelper.Deserialize<ConstituentSnapshot>(input.Data);
                    var myEmail = input.Data;
                    if (myEmail.Name.ToString().ToLower().Contains("electronicaddress"))
                    {
                        string EmailAddress = string.Empty;
                        int mycheck = 0;
                        EmailAddress = constituent.ElectronicAddress.Address.ToString();
                        mycheck = checkEmail(EmailAddress);
                        if (mycheck > 0)
                        {
                            throw new PluginValidationException("Email Address is already under another account " + mycheck.ToString() + ". It is not allowed for this account.");
                        }
                    }
                    return input;
                }

                else if (input.Verb == update)///this part codes have the same logic but it never hit by plugin.
                {
                    var constituentUpdate = SerializationHelper.Deserialize<ConstituentSnapshot>(input.Data);
                    var myEmailUpdate = input.Data;
                    if (myEmailUpdate.Name.ToString().ToLower().Contains("electronicaddress"))
                    {
                        string EmailAddress = string.Empty;
                        int mycheck = 0;
                        EmailAddress = constituentUpdate.ElectronicAddress.Address.ToString();
                        mycheck = checkEmail(EmailAddress);
                        if (mycheck > 0)
                        {
                            throw new PluginValidationException("Email Address is already under another account " + mycheck.ToString() + ". It is not allowed for this account.");
                        }
                    }

                    return input;
                }
                else
                {
                    return input;
                }
            }

            public static int checkEmail(string emailaddress)
            {

                string tmp = string.Empty;
                int myreturn = 0;
                var sqlCommandHelper = new SqlCommandHelper();
                var sqlStatement = "dbo.LP_MTC_INTERCEPTION_STOP_EMAIL_LOGIN_DUP";
                var parameters = new Dictionary<string, string>();
                parameters.Add("@EMAILADDRESS", emailaddress);
                System.Data.DataSet ds=  sqlCommandHelper.ExecuteSqlCommandReturnDataSet(sqlStatement, parameters, true);
                System.Data.DataTable tb = ds.Tables[0];
                if (tb.Rows.Count>0)
                {
                    tmp = tb.Rows[0]["customer_no"].ToString();
                }
                if (tmp.Trim().Length > 0)
                {
                    myreturn =Convert.ToInt32( tmp.Trim().ToString());
                }
                return myreturn;
            }
        }
    }

Children
No Data