Announcement

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

    Display AdvancedCriteria query results as XML format

    Hi,

    I would like to transform an AdvancedCriteria object to an Hibernate Query in order to display the entries in .xml format. What would be the best way to implement this?

    At the moment, the users create a filter with FilterBuilder and AdvancedCriteria, the filter is executed as an SQL query with Hibernate and the results of the query are presented in a ListGrid. This follows the implementation as in:

    SmartGWT EE Showcase - FilterBuilder+SQL

    This works fine. However, I would like to make the following additions:
    1. The results of the query are presented in .xml format in a separate tab
    2. Users can also query the database with a URL, i.e. the URL is transformed into an AdvancedCriteria object.

    Any ideas on how to implement 1. and 2.?

    BTW, the export as XML won't do, since I want to give the proper format to the results.

    Thanks in advance,

    Oriol

    Using SmartGWT Power Edition.
    Last edited by oespanyol; 4 Sep 2014, 00:58. Reason: Modify URL

    #2
    Hi Oriol,

    1) see EE Custom Export sample.
    2) sounds like you need a servlet that reads your query string and creates an AdvancedCriteria object from it. Then create a new DSRequest and set the criteria.

    Best regards,
    Blama

    Comment


      #3
      For 1) Thanks, yes this is what I am looking for. However, I imported the code of the sample into my application but the .rpc call reports 404 not found error.

      The URL that the export is trying to access is:
      http://localhost:8080/umsw/external/announcementHibernateOperations.rpc/Results.csv/Results.csv?isc_rpc=1&isc_v=v9.1p_2014-09-03&isc_tnum=13

      I am surprised to see that there are two instances of 'Results.csv'. However, I see that the sample code produces something similar. So I assume the URL is correct.

      The DSRequest looks like this:
      Code:
      {
          dataSource:"extAnnList", 
          operationType:"fetch", 
          data:{
              download_filename:"Results.csv"
          }, 
          sortBy:[
              "-annNumber"
          ], 
          textMatchStyle:"substring", 
          showPrompt:false, 
          oldValues:{
              download_filename:"Results.csv"
          }, 
          requestId:"extAnnList$62713", 
          fallbackToEval:false, 
          exportAs:"csv", 
          exportDisplay:"window", 
          exportRawValues:true, 
          exportFilename:"Results.csv", 
          downloadResult:true, 
          downloadToNewWindow:true, 
          download_filename:"Results.csv", 
          lastClientEventThreadCode:"MUP1", 
          bypassCache:true
      }
      which seems correct to me.

      Generated by the following client side code:

      Code:
              final DynamicForm exportForm = new DynamicForm();  
              exportForm.setWidth(300);  
        
              SelectItem exportTypeItem = new SelectItem("exportType", "Export Type");  
              exportTypeItem.setWidth("*");  
              exportTypeItem.setDefaultToFirstOption(true);  
        
              LinkedHashMap<String,String> valueMap = new LinkedHashMap<String,String>();  
              valueMap.put("csv", "CSV (Excel)");  
              valueMap.put("xml", "XML");  
              valueMap.put("json", "JSON");  
              valueMap.put("xls", "XLS (Excel97)");  
              valueMap.put("ooxml", "XLSX (Excel2007/OOXML)");  
        
              exportTypeItem.setValueMap(valueMap);  
        
              exportForm.setItems(exportTypeItem);  
        
              IButton exportButton = new IButton("Export");  
              exportButton.addClickHandler(new ClickHandler() {  
                  public void onClick(com.smartgwt.client.widgets.events.ClickEvent event) {  
                      String exportAs = (String) exportForm.getField("exportType").getValue();
                      // exportAs is either XML or CSV, which we can do with requestProperties  
                      DSRequest dsRequestProperties = new DSRequest();  
                      dsRequestProperties.setExportAs((ExportFormat)EnumUtil.getEnum(ExportFormat.values(), exportAs));  
                      dsRequestProperties.setExportDisplay(ExportDisplay.WINDOW);
                      extUserAnnList.exportData(dsRequestProperties);
                  }  
              });
      This is the data source I am trying to export
      Code:
      <DataSource
          ID="extAnnList"
          serverType="sql"
          tableName="ANNOUNCEMENTS"    
      >
          <fields>
              <field name="id"                type="sequence"  hidden="true"                   primaryKey="true"					 />
              <field name="annNumber"       	type="long"		 title="Announcement Number"										 />
              <field name="seqNumber"       	type="long"		 title="Sequence Number"											 />
              <field name="updateToSeqNumber" type="long"		 title="Update to Sequence Number"									 />
              <field name="revisionNumber"    type="long"      title="Revision Number"											 />
              <field name="annTypeName"       type="text"      title="Announcement Type"       length="128"        required="true" />
              <field name="subjectName"       type="text"      title="Subject"                 length="128"        required="true" />        
              <field name="satelliteName"     type="text"      title="Satellite"               length="128"                        />
              <field name="orbitText"         type="text"      title="Orbit"                   length="128"                        />
              <field name="opServGroupText"   type="text"      title="Operational Service Groups"                                  />
              <field name="opServText"        type="text"      title="Operational Service"                                         />
              <field name="prodGroupText"     type="text"      title="Product Group"                                               />
              <field name="subsystemName"     type="text"      title="Subsystem"               length="128"                        />
              <field name="componentName"     type="text"      title="Component"               length="128"                        />
              <field name="impactName"        type="text"      title="Impact"                  length="128"                        />
              <field name="annStartDateTime"  type="datetime"  title="Start Date"                                  required="true" />
              <field name="annEndDateTime"    type="datetime"  title="End Date"                                                    />
              <field name="valEndDateTime"    type="datetime"	 title="Valid End Date"												 />
              <field name="valStartDateTime"  type="datetime"	 title="Valid Start Date"											 />
              <field name="annStatusName"     type="text"      title="Announcement Status"     length="128"                        />
              <field name="text"              type="text"      title="Text"                    length="8192"        				 />
              <field name="ready"             type="integer"   title="Ready"								        				 />  
              <field name="send"              type="integer"   title="Send"								        				 />
              <field name="released"          type="integer"   title="Released"							        				 />
          </fields>
      </DataSource>
      I see from the samples that no modifications are needed for the out-of-the box .csv export, which is what I am testing before I do the .xml

      So I am assuming the problem must be in the web.xml:
      Code:
      <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
      	version="2.4">
      
      	<!-- Start : Dynamic Compression -->
      	<filter>
      		<filter-name>CompressionFilter</filter-name>
      		<filter-class>com.isomorphic.servlet.CompressionFilter</filter-class>
      	</filter>
      
      	<!-- CompressionFilter for dynamic compression -->
      	<filter-mapping>
      		<filter-name>CompressionFilter</filter-name>
      		<url-pattern>/*</url-pattern>
      	</filter-mapping>
      	<!-- End : Dynamic Compression -->
      
      	<!-- Start : Spring Security -->
      	<filter>
      		<filter-name>springSecurityFilterChain</filter-name>
      		<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
      	</filter>
      
      	<filter-mapping>
      		<filter-name>springSecurityFilterChain</filter-name>
      		<url-pattern>/*</url-pattern>
      	</filter-mapping>
      	<!-- End : Spring Security -->
      	
      	<!-- Start : Custom Authentication Server -->
      	<servlet>
              <servlet-name>authServlet</servlet-name>
              <servlet-class>eum.ums.server.auth.AuthServiceImpl</servlet-class>
          </servlet>
      
          <servlet-mapping>
              <servlet-name>authServlet</servlet-name>
              <url-pattern>/admin/auth</url-pattern>
              <url-pattern>/external/auth</url-pattern>
          </servlet-mapping>
          <!-- End : Custom Authentication Server -->
      
      
      	<servlet>
      		<servlet-name>admin</servlet-name>
      		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
      		<load-on-startup>1</load-on-startup>
      	</servlet>
      
      	<servlet>
      		<servlet-name>main</servlet-name>
      		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
      		<load-on-startup>1</load-on-startup>
      	</servlet>
      
      
      	<!-- The IDACall servlet handles all Built-in DataSource operations -->
      	<servlet>
      		<servlet-name>IDACall</servlet-name>
      		<servlet-class>com.isomorphic.servlet.IDACall</servlet-class>
      	</servlet>
      
      	<!-- The RESTHandler servlet is like IDACall, but for REST requests -->
      	<servlet>
      		<servlet-name>RESTHandler</servlet-name>
      		<servlet-class>com.isomorphic.servlet.RESTHandler</servlet-class>
      	</servlet>
      
      	<!-- The DataSourceLoader servlet returns Javascript representations of 
      		the dataSources whose ID's are passed to it - it is an alternative to using 
      		the <loadDS> JSP tag -->
      	<servlet>
      		<servlet-name>DataSourceLoader</servlet-name>
      		<servlet-class>com.isomorphic.servlet.DataSourceLoader</servlet-class>
      	</servlet>
      
      	<!-- The screenLoader servlet loads screen definitions in javascript notation -->
      	<servlet>
      		<servlet-name>screenLoader</servlet-name>
      		<servlet-class>com.isomorphic.servlet.ScreenLoaderServlet</servlet-class>
      	</servlet>
      
      	<!-- The FileDownload servlet downloads static files, like a webserver -->
      	<servlet>
      		<servlet-name>FileDownload</servlet-name>
      		<servlet-class>com.isomorphic.servlet.FileDownload</servlet-class>
      	</servlet>
      
      	<!-- Init: initializes SmartGWT framework. Note that we invoke the Init 
      		logic from both a Listener and a load-on-startup Servlet in this file - see 
      		the client-side documentation topic "com.smartgwt.client.docs.ServerInit" 
      		for a discussion of this. -->
      	<listener>
      		<listener-class>com.isomorphic.base.InitListener</listener-class>
      	</listener>
      
      	<context-param>
      		<param-name>contextConfigLocation</param-name>
      		<param-value>/WEB-INF/admin-servlet.xml</param-value>
      	</context-param>
      
      	<listener>
      		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      	</listener>
      
      	<servlet>
      		<servlet-name>Init</servlet-name>
      		<servlet-class>com.isomorphic.base.Init</servlet-class>
      		<load-on-startup>1</load-on-startup>
      	</servlet>
      
      	<servlet>
      		<servlet-name>HttpProxy</servlet-name>
      		<servlet-class>com.isomorphic.servlet.HttpProxyServlet</servlet-class>
      	</servlet>
      
      	<!-- RPCManager uses this URL by default for Built-in DataSource operations -->
      	<servlet-mapping>
      		<servlet-name>IDACall</servlet-name>
      		<url-pattern>/admin/sc/IDACall/*</url-pattern>
      	</servlet-mapping>
      
      	<servlet-mapping>
      		<servlet-name>RESTHandler</servlet-name>
      		<url-pattern>/admin/sc/RESTHandler/*</url-pattern>
      	</servlet-mapping>
      
      	<!-- DataSourceLoader requests -->
      	<servlet-mapping>
      		<servlet-name>DataSourceLoader</servlet-name>
      		<url-pattern>/admin/sc/DataSourceLoader</url-pattern>
      	</servlet-mapping>
      
      	<!-- The screenLoader servlet loads screen definitions in javascript notation -->
      	<servlet-mapping>
      		<servlet-name>screenLoader</servlet-name>
      		<url-pattern>/admin/sc/screenLoader</url-pattern>
      	</servlet-mapping>
      
      	<servlet-mapping>
      		<servlet-name>HttpProxy</servlet-name>
      		<url-pattern>/admin/sc/HttpProxy/*</url-pattern>
      	</servlet-mapping>
      
      	<!-- Use FileDownload servlet to download all static content that's part 
      		of the skin, such as image files, so we can set Expires headers and other 
      		cache control directives. In a production deployment, you'd want to use a 
      		webserver such as Apache to do this. -->
      	<servlet-mapping>
      		<servlet-name>FileDownload</servlet-name>
      		<url-pattern>/admin/sc/skins/*</url-pattern>
      	</servlet-mapping>
      
      	<!-- serve ISC modules compressed, with expires headers -->
      	<servlet-mapping>
      		<servlet-name>FileDownload</servlet-name>
      		<url-pattern>/admin/sc/system/modules/*</url-pattern>
      	</servlet-mapping>
      
      	<!-- serve ISC development modules compressed, with expires headers -->
      	<servlet-mapping>
      		<servlet-name>FileDownload</servlet-name>
      		<url-pattern>/admin/sc/system/development/*</url-pattern>
      	</servlet-mapping>
      
      	<!-- serve skin assets with expires headers -->
      	<servlet-mapping>
      		<servlet-name>FileDownload</servlet-name>
      		<url-pattern>/admin/sc/system/reference/skin/*</url-pattern>
      	</servlet-mapping>
      
      	<!-- serve the contents of the helpers/ directory with expires headers -->
      	<servlet-mapping>
      		<servlet-name>FileDownload</servlet-name>
      		<url-pattern>/admin/sc/system/helpers/*</url-pattern>
      	</servlet-mapping>
      
      	<servlet-mapping>
      		<servlet-name>admin</servlet-name>
      		<url-pattern>*.rpc</url-pattern>
      	</servlet-mapping>
      
      	<servlet-mapping>
      		<servlet-name>main</servlet-name>
      		<url-pattern>*.xml</url-pattern>
      		<url-pattern>*.xhtml</url-pattern>
      	</servlet-mapping>
      
      	<!-- General config -->
      	<session-config>
      		<session-timeout>30</session-timeout>
      	</session-config>
      
      	<jsp-config>
      		<!-- Isomorphic JSP tags -->
      		<taglib>
      			<taglib-uri>isomorphic</taglib-uri>
      			<taglib-location>/WEB-INF/iscTaglib.xml</taglib-location>
      		</taglib>
      	</jsp-config>
      
      	<mime-mapping>
      		<extension>manifest</extension>
      		<mime-type>text/cache-manifest</mime-type>
      	</mime-mapping>
      
      </web-app>
      But I couldn't find it yet. Any ideas?

      Any help appreciated.

      Oriol

      Comment


        #4
        Hi Oriol,

        I'm not using neither Spring nor Hibernate, so I won't be of any help here.

        Best regards,
        Blama

        Comment


          #5
          Originally posted by Blama View Post
          Hi Oriol,

          I'm not using neither Spring nor Hibernate, so I won't be of any help here.

          Best regards,
          Blama
          Thanks anyway!

          Comment


            #6
            On this:

            For 1) Thanks, yes this is what I am looking for. However, I imported the code of the sample into my application but the .rpc call reports 404 not found error.

            The URL that the export is trying to access is:
            http://localhost:8080/umsw/external/announcementHibernateOperations.rpc/Results.csv/Results.csv?isc_rpc=1&isc_v=v9.1p_2014-09-03&isc_tnum=13

            I am surprised to see that there are two instances of 'Results.csv'. However, I see that the sample code produces something similar. So I assume the URL is correct.
            We have to put the filename into the export URL to work around bugs in IE.

            You'll note how the default IDACall servlet is registered for *all paths under IDACall* in the web.xml we ship with the SDK. Do the same thing for your custom servlet and it will fix this issue.

            On your #2 requirement, see the QuickStart Guide's mention of RestHandler and the RestHandler docs. With this servlet installed, you already have a way to query the database from a URL and receive XML or JSON responses, with no effort, works for all DataSources.

            Comment


              #7
              Originally posted by Isomorphic View Post
              On this:
              You'll note how the default IDACall servlet is registered for *all paths under IDACall* in the web.xml we ship with the SDK. Do the same thing for your custom servlet and it will fix this issue.
              Yes and no :-)

              I just realized that for my case, the .rpc calls are not captured by the following section of the web.xml
              Code:
              	<servlet-mapping>
              		<servlet-name>IDACall</servlet-name>		
              		<url-pattern>/admin/sc/IDACall/*</url-pattern>
              	</servlet-mapping>
              However, since the URL I am trying to access is like:
              http://localhost:8080/umsw/external/announcementHibernateOperations.rpc/Results.csv

              I can try to explicitly capture this request adding the following <url-pattern> to the IDACall of the web.xml
              Code:
              	<servlet-mapping>
              		<servlet-name>IDACall</servlet-name>		
              		<url-pattern>/admin/sc/IDACall/*</url-pattern>
              	        <url-pattern>*.csv</url-pattern>
              	</servlet-mapping>
              Which successfully captures and processes the request.

              I am wondering if the following entry of my web.xml interferes with the nominal behavior:
              Code:
              <servlet-mapping>
              	<servlet-name>admin</servlet-name>
              	<url-pattern>*.rpc</url-pattern>
              </servlet-mapping>
              which is below the previous entry on the web.xml (see post entry above for the web.xml)

              Otherwise, I will have to end up doing something like:

              Code:
              	<servlet-mapping>
              		<servlet-name>IDACall</servlet-name>		
              		<url-pattern>/admin/sc/IDACall/*</url-pattern>
              	        <url-pattern>*.csv</url-pattern>
              	        <url-pattern>*.xml</url-pattern>
              	        <url-pattern>*.json</url-pattern>
              	</servlet-mapping>
              Which is not very nice and limits future expansions of the application.

              Any ideas on how to address this?

              Thanks in advance.

              Comment


                #8
                Well, there's the obvious suggestion of not using the .rpc extension for this Servlet, or using a different actionURL just for export.

                Basically we're not sure for what purpose you're using these extensions or why you would perceive the various obvious approaches as having any drawbacks.

                Comment


                  #9
                  Yes, you are right. I just thought that I was doing something wrong or not optimally.
                  Thanks!

                  Comment

                  Working...
                  X