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

  • $organization in reply to Ben Gu

    USE [impresario]
    GO
    /****** Object:  StoredProcedure [dbo].[LP_MTC_INTERCEPTION_STOP_EMAIL_LOGIN_DUP]    Script Date: 12/15/2014 08:49:00 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO

    ALTER procedure [dbo].[LP_MTC_INTERCEPTION_STOP_EMAIL_LOGIN_DUP]
    @EMAILADDRESS VARCHAR(200)=NULL
    AS
    /*

    [LP_MTC_INTERCEPTION_STOP_EMAIL_LOGIN_DUP] 'b.gu@mtc.com.au'
    */
    BEGIN
        DECLARE @TMP INT
        SET @TMP =0
        IF EXISTS(SELECT TOP 1 * FROM LTR_ACCEPTABLE_DUP_EMAILS WHERE EMAILADDRESS=@EMAILADDRESS)
            BEGIN
                    SET @TMP =-1
            END
        ELSE
            BEGIN
                IF NOT EXISTS(SELECT TOP 1 * FROM T_EADDRESS WHERE address=@EMAILADDRESS AND inactive='N'    )
                BEGIN
                    SET @TMP =-1
                END
                ELSE
                BEGIN
                    SELECT TOP 1 @TMP=customer_no FROM T_EADDRESS  WHERE address=@EMAILADDRESS AND inactive='N'
                END
            END
            
        Select @TMP as customer_no
        RETURN;

    END



    [edited by: Ben Gu at 4:50 PM (GMT -6) on 14 Dec 2014]
  • $organization in reply to Ben Gu

    <PluginConfigs>
        <PluginConfig>
            <UriMatch>CRM/ElectronicAddresses</UriMatch>
            <Verb>POST</Verb>
            <FullPluginName>MTC_REST.TessituraPlugins.ConstituentService.DupEmailLoginPrevention</FullPluginName>
            <PluginPlacement>PRE</PluginPlacement>
        </PluginConfig>
        <PluginConfig>
            <UriMatch>CRM/ElectronicAddresses</UriMatch>
            <Verb>PUT</Verb>
            <FullPluginName>MTC_REST.TessituraPlugins.ConstituentService.DupEmailLoginPrevention</FullPluginName>
            <PluginPlacement>PRE</PluginPlacement>
        </PluginConfig>    
        <PluginConfig>
            <UriMatch>CRM/Constituents/*/Snapshot</UriMatch>
            <Verb>POST</Verb>
            <FullPluginName>MTC_REST.TessituraPlugins.ConstituentService.DupEmailLoginPreventionSnapshot</FullPluginName>
            <PluginPlacement>PRE</PluginPlacement>
        </PluginConfig>    <PluginConfig>
            <UriMatch>CRM/Constituents/*/Snapshot</UriMatch>
            <Verb>PUT</Verb>
            <FullPluginName>MTC_REST.TessituraPlugins.ConstituentService.DupEmailLoginPreventionSnapshot</FullPluginName>
            <PluginPlacement>PRE</PluginPlacement>
        </PluginConfig>
        <PluginConfig>
            <UriMatch>CRM/Constituents/*/Snapshot</UriMatch>
            <Verb>GET</Verb>
            <FullPluginName>MTC_REST.TessituraPlugins.ConstituentService.HelloInterceptor</FullPluginName>
            <PluginPlacement>POST</PluginPlacement>
        </PluginConfig>
    </PluginConfigs>



    [edited by: Ben Gu at 4:52 PM (GMT -6) on 14 Dec 2014]
  • $organization in reply to Ben Gu

    namespace MTC_REST.TessituraPlugins.ConstituentService
    {
        public class DupEmailLoginPrevention
        {
            public static PluginData Operation(PluginData input)
            {
                string update = string.Empty;
                string insert = string.Empty;
                update = @"PUT";
                insert = @"POST";
                if (input.Verb == insert)
                {
                    var Email = SerializationHelper.Deserialize<ElectronicAddress>(input.Data);
                    var myEmail=input.Data;
                    if (myEmail.Name.ToString().ToLower().Contains("electronicaddress"))
                    {
                        string EmailAddress = string.Empty;
                        int mycheck = 0;
                        EmailAddress = Email.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)
                {
                    var Email = SerializationHelper.Deserialize<ElectronicAddress>(input.Data);
                    var myEmail = input.Data;
                    if (myEmail.Name.ToString().ToLower().Contains("electronicaddress"))
                    {
                        string EmailAddress = string.Empty;
                        int mycheck = 0;
                        EmailAddress = Email.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;
            }
        }
    }



    [edited by: Ben Gu at 4:59 PM (GMT -6) on 14 Dec 2014]
  • $organization in reply to Ben Gu

    Hi All,

    Good day.

    those are the code for my plugin.

    LTR_ACCEPTABLE_DUP_EMAILS is a custom table keeping duplicated emails exceptions.

    The plugin worked on POST method, but it never worked on PUT method.

    Am I missing something?

    have fun

    Ben

  • $organization in reply to Ben Gu

    Hi All,

    Good day.

    Patrick Drew from Sydney Theatre Company told me the trick.

    if plugin uses PUT method, the config  should have a * included.

    if plugin uses POST method, the config should not have a * included.

     

    Here is an example from Patrick.

    Normal 0 false false false EN-AU ZH-CN X-NONE MicrosoftInternetExplorer4

     

    Scenario

    Verb

    URI

    Placement

    New constituent record created

    POST

    CRM/Constituents/Snapshot

    PRE

    Existing constituent record, email updated from general tab

    PUT

    CRM/ElectronicAddresses/*

    PRE

    Existing constituent record, email added from contact details tab

    POST

    CRM/ElectronicAddresses

    PRE

     

    Thank you Patrcik.

     

    Have fun.

    Ben

     

  • Hi Ben,

    We've lodged a TASK ticket for a very similar issue.  I don't think it's appearing in the Tessitura known defects list yet, but will be there soon as reference #71283.

    The issue is that plugins fired from the General Tab are unable to return Validation Exception messages to the application and instead throw the errors you are seeing.  There is no fix at this point.

    Cheers
    Sarah 

Reply
  • Hi Ben,

    We've lodged a TASK ticket for a very similar issue.  I don't think it's appearing in the Tessitura known defects list yet, but will be there soon as reference #71283.

    The issue is that plugins fired from the General Tab are unable to return Validation Exception messages to the application and instead throw the errors you are seeing.  There is no fix at this point.

    Cheers
    Sarah 

Children
No Data