Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    operationBinding criteria/value and server side DsRequest

    Smartclient power 8.2p

    in a datasource I'm using an operation binding like this:
    Code:
        <operationBindings>
            <operationBinding operationType="fetch">
                <criteria fieldName="NOME_GRUPPO" value="whatever">
                </criteria>
            </operationBinding>
        </operationBindings>
    then, server side, I create a DsRequest on that datasource, and I noticed that getCriteria() doesn't return the criteria in the operationBinding.
    Actually the docs says "A list of DSRequestModifiers that will be used to modify the criteria of each DSRequest that uses this operationBinding." so this seems correct.
    Not handy though, because I'd like to add another criteria, to the criteria defined in the operation binding, to set it in the server side generated DsRequest.
    I managed to do that this way:
    Code:
    Criterion[] criterions = ...//another criteria
    
    DSRequest dsRequest = new DSRequest("GRUPPI", "fetch");
            Map operationBinding = dsRequest.getDataSource().getOperationBinding("fetch");
            Map dsRequestModifier = (Map) operationBinding.get("criteria");
            SimpleCriterion operationBindingCriteria = new SimpleCriterion((String) dsRequestModifier.get("fieldName"), "equals", dsRequestModifier.get("value"));
            AdvancedCriteria advancedCriteria = new AdvancedCriteria(DefaultOperators.And, new Criterion[]{
                new OrCriterion(criterions),
                operationBindingCriteria
            });
    is there a simpler/more correct approach?
    Last edited by claudiobosticco; 4 Jan 2012, 03:31.

    #2
    If you create a new DSRequest server-side, criteria specified in the OperationBinding are merged into the DSRequest when you execute() it. There doesn't appear to be a need for this code at all - just put whatever criteria you want in the DSRequest and it's already going to be automatically merged with criteria from the operationBinding.

    Comment


      #3
      unfortunately this automatic merging is not occurring.

      this is the datasource definition:
      Code:
      <DataSource ID="GRUPPI" dataFormat="iscServer" serverType="sql" dbName="dbJFrame" schema="DBJFRAME" tableName="GRUPPI"
      			requiresAuthentication="true"
      			>
          <fields> 
              <field sqlType="decimal" primaryKey="true" sqlLength="0" name="ID_REC" type="sequence" hidden="true">
                  <sequenceName>SEQUENCE_REC</sequenceName>
              </field>
              <field name="NOME_GRUPPO" type="text" required="true" length="20"/>
              <field name="DES_GRUPPO" type="text" required="true" length="30"/>
              <field name="DES_GRUPPO_EN" type="text" required="true" length="30"/>
              <field name="ID_APP" type="text" required="true" length="20"/>
          </fields>
          <operationBindings>
              <operationBinding operationType="fetch">
                  <criteria fieldName="ID_APP" value="JpcQuery"></criteria>
              </operationBinding>
          </operationBindings>
      </DataSource>
      this is the server side code where the datasource is used to create a DsRequest, and where a new AdvancedCriteria is created and set (is it correct?):
      Code:
      		Collection<GrantedAuthority> authorities = userDetails.getAuthorities();
              Criterion[] criterions = new Criterion[authorities.size()];
      		int i = 0;
      		for (GrantedAuthority grantedAuthority : authorities) {
      			criterions[i++] = new SimpleCriterion("NOME_GRUPPO", "equals", grantedAuthority.getAuthority());
      		}
      		AdvancedCriteria advancedCriteria = new AdvancedCriteria(DefaultOperators.Or, criterions);
              DSRequest dsRequest = new DSRequest("GRUPPI", "fetch");
              dsRequest.setCriteria(advancedCriteria);
      		roles = dsRequest.execute().getDataList();
      and this is the server side log:
      Code:
      === 2012-01-04 12:04:20,969 [c-24] DEBUG ProcessedFileCache - STALE object for file 'F:\iscSDK\tools\visualBuilder\workspace\JpcQuery\out\artifacts\JpcQuery_Web_exploded\shared\ds\GRUPPI.ds.xml', reloading (file timestamp 1325674891218, cache timestamp 1325674805421)
      === 2012-01-04 12:04:20,969 [c-24] DEBUG XML - Parsed XML from F:\iscSDK\tools\visualBuilder\workspace\JpcQuery\out\artifacts\JpcQuery_Web_exploded\shared\ds\GRUPPI.ds.xml: 0ms
      === 2012-01-04 12:04:20,969 [c-24] DEBUG AppBase - [builtinApplication.null] No userTypes defined, allowing anyone access to all operations for this application
      === 2012-01-04 12:04:20,969 [c-24] DEBUG AppBase - [builtinApplication.null] No public zero-argument method named '_null' found, performing generic datasource operation
      === 2012-01-04 12:04:20,969 [c-24] INFO  SQLDataSource - [builtinApplication.null] Performing fetch operation with
      	criteria: {value:"ROLE_ADMIN",fieldName:"NOME_GRUPPO",operator:"equals",_constructor:"AdvancedCriteria"}	values: {value:"ROLE_ADMIN",fieldName:"NOME_GRUPPO",operator:"equals",_constructor:"AdvancedCriteria"}
      === 2012-01-04 12:04:20,984 [c-24] INFO  SQLDataSource - [builtinApplication.null] derived query: SELECT $defaultSelectClause FROM $defaultTableClause WHERE $defaultWhereClause
      === 2012-01-04 12:04:20,984 [c-24] INFO  SQLDataSource - [builtinApplication.null] Executing SQL query on 'dbJFrame': SELECT GRUPPI.DES_GRUPPO, GRUPPI.DES_GRUPPO_EN, GRUPPI.ID_APP, GRUPPI.ID_REC, GRUPPI.NOME_GRUPPO FROM DBJFRAME.GRUPPI WHERE (GRUPPI.NOME_GRUPPO = 'ROLE_ADMIN' AND GRUPPI.NOME_GRUPPO IS NOT NULL)
      === 2012-01-04 12:04:21,016 [c-24] DEBUG PoolableSQLConnectionFactory - [builtinApplication.null] Returning pooled Connection
      === 2012-01-04 12:04:21,031 [c-24] INFO  SQLDriver - [builtinApplication.null] Executing SQL query on 'dbJFrame': SELECT GRUPPI.DES_GRUPPO, GRUPPI.DES_GRUPPO_EN, GRUPPI.ID_APP, GRUPPI.ID_REC, GRUPPI.NOME_GRUPPO FROM DBJFRAME.GRUPPI WHERE (GRUPPI.NOME_GRUPPO = 'ROLE_ADMIN' AND GRUPPI.NOME_GRUPPO IS NOT NULL)
      === 2012-01-04 12:04:21,031 [c-24] INFO  DSResponse - [builtinApplication.null] DSResponse: List with 2 items

      Comment


        #4
        fyi, I'm using SC_SNAPSHOT-2011-12-23

        Comment


          #5
          Sorry, a <criteria> tag will not currently work if the request contains AdvancedCriteria (this is queued to be fixed, no ETA yet). However the criteria you are putting together can be represented as simple Criteria - use a Map, one key "NOME_GRUPPO", value should be a List of Strings of the values that should match.

          Comment


            #6
            I'm encountering a similar problem with operation binding criteria and server-side testing of a datasource.

            Isomorphic SmartClient Framework (SC_SNAPSHOT-2012-02-02_v8.2p/PowerEdition Deployment 2012-02-02)

            ds.xml file:
            Code:
            <DataSource
                ID="ApplicationSettingsDMI" 
                title="Application Settings"
                serverConstructor="com.Atlantic.AtlanticScheduler.server.GUI.SecondaryTCATDataDMI"  
            	dropExtraFields="true"    
                >
            
            
                <fields>
                    <field name="id" type="int"     title="key"   required="true"	hidden="true" primaryKey="true"/>    
                    <field name="scheduleStartDate"  type="DateTime"	title="Schedule Start Date"  	required="true"/>  
                    <field name="horizonEndDate" type="DateTime" title="Horizon End Date"	/>               
                    <field name="scheduleTimeSliceInHours"	type="int"     title="Time Slice (hrs)"     required="true"   />
                     <validators>
            			<validator type="integerRange" min="4" max="48" errorMessage="Time Slice Must be Between 4-48" />
            		</validators>
                    <field name="scheduleTimeHorizonInDays" type="int"     title="Time Horizon (days)"  required="true" /> 
                    <validators>
            			<validator type="integerRange" min="1" max="180" errorMessage="Time Horizon Must be Between 1-180" />
            		</validators>    
            		<field name="showScheduleBoardGroups" type="boolean"  title="Show Fac Groups on SchedulingBoard" required="true"/>
                    <field name="scheduleOperationGroups" type="boolean"  title="Schedule Operation Groups"  required="true" />
                    <field name="demandActivityDefaultFacility"	 type="text"     title="Demand Activity Default Facility"  	length="64"	/>  
                    <field name="scheduleFileSuffix"	 type="text"     title="Schedule File Suffix"  	length="10"	/>   
                    <field name="fifiTableName"	type="text" title="FifiTable"  canedit="false"/>
                         
                </fields>
            
            	<operationBindings>
            		<operationBinding operationType="fetch">
            			<criteria fieldName="fifiTableName" value="ApplicationSettings"/>
            		</operationBinding>
            	</operationBindings>
             
            
              
            </DataSource>
            Server-side test:
            Code:
            try {
            			logger.info("Testing ApplicationSettingsDMI");				
            			DSRequest req = new DSRequest("ApplicationSettingsDMI", "fetch");
            			Map critMap = req.getCriteria();
            			logger.info("Criteria after loading datasource is "+critMap);			
            			req.setCriteria("id", "1");
            			DSResponse resp = req.execute();
            Output from test:
            Code:
            16:48:41,152  INFO ApplicationSettingsDMITest:32 - Criteria after loading datasource is {}
            16:48:41,271  INFO SecondaryTCATDataDMI:56 - In SecondaryTCATDataDMI constructor
            16:48:41,284  INFO SecondaryTCATDataDMI:77 - Running secondary data fetch.  
            16:48:41,284  INFO SecondaryTCATDataDMI:80 - Criteria passed to fetch is {id=1}
            It doesn't appear that the operation binding criteria is being appended as expected.

            Comment


              #7
              The criteria are applied when you execute() the DSRequest and not before. Note, the feature of automatically merging AdvancedCriteria in a DSRequest with criteria specified in an <operationBinding> has also now been implemented in 8.2p builds (see smartclient.com/builds).

              Comment


                #8
                The last line of the code I posted runs DSRequest.execute(). The server-side datasource code replies that the DSRequest criteria contains "1" only, the Criteria I added to the DSRequest. The additional criteria added in the ds.xml file doesn't appear to be appended.

                Am I missing something?

                Comment


                  #9
                  Custom Data source to go with above issue:

                  Code:
                  public class SecondaryTCATDataDMI extends BasicDataSource {
                  	public static Logger logger = Logger.getLogger("com.Atlantic.AtlanticScheduler.server.GUI.SecondaryTCATDataDMI");
                  
                  	/**
                  	 * Base constructor
                  	 * 
                  	 */
                  	public SecondaryTCATDataDMI() {
                  		super();
                  		logger.info("In SecondaryTCATDataDMI constructor");
                  	}
                  
                  	
                  
                  	public DSResponse executeFetch(DSRequest req) throws Exception {
                  		logger.info("Running secondary data fetch.  ");
                  		DSResponse resp = new DSResponse();
                  		try {
                  			logger.info("Criteria passed to fetch is "+req.getCriteria());
                  			AdvancedCriteria advCrit = req.getAdvancedCriteria();
                  			logger.info("Advanced crit are "+advCrit);
                  			FifiObjectTable fifiTable = getFifiTableFromDSRequestCriteria(req);

                  Comment


                    #10
                    Sorry, to clarify, the criteria on the operationBinding is considered a security setting, it is applied to client-originated requests only. Server-initiated requests (new DSRequest() in server code) are intentionally not restricted.

                    Comment


                      #11
                      Any recommendations on how to simulate a client-side request for unit testing purposes?

                      Comment


                        #12
                        Use Selenium for a full-cycle test; you'll want to check the correct response client-side anyway, as well as check other security features like role-based access control.

                        Comment


                          #13
                          Originally posted by Isomorphic
                          The criteria are applied when you execute() the DSRequest and not before. Note, the feature of automatically merging AdvancedCriteria in a DSRequest with criteria specified in an <operationBinding> has also now been implemented in 8.2p builds (see smartclient.com/builds).
                          I'm trying my original sample with SC_SNAPSHOT-2012-03-05_v8.2p/PowerEdition but the automatic merging is still not occurring.

                          maybe is it implemented in 8.3d branches only?

                          Comment

                          Working...
                          X