com.sage.orion.sdata.servlet.swtservice
Class UIDefinitionResourceKind

java.lang.Object
  extended by com.sage.orion.sdata.servlet.JDBCResourceKind
      extended by com.sage.orion.sdata.servlet.swtservice.UIDefinitionResourceKind
All Implemented Interfaces:
ResourceKind
Direct Known Subclasses:
LandingPageResourceKind

public class UIDefinitionResourceKind
extends JDBCResourceKind

This class is a special resource kind class for UI definitions. Since UI definition files can get very large (for example, 95K for the showcase's main UI definition), the files are stored in the appropriate directory structure within the servlet rather than in a database. The directory structure takes into account version, language, category, user ID, and company ID. Non-customized UI definition files are stored in the category's directory while customized ones are stored in the user-specific directories under the category directory. The special value of "-" can be passed in for the language and/or user ID, where "-" means that the sign on information will be used to determine the actual the language and user ID. (The concept of "-" is similar to the concept of using "-" as the default dataset in an SData URL). The UI definition file's name is the UI definition's name followed by a ".xml" file extension. (Note that this name may be different than the value of the "id" attribute in the UI definition's root "ui" element). When a "get" request is received, the UI definition will be retrieved from files stored in that directory structure. When a "put" request is received, the UI definition will be stored in the appropriate file within that directory structure.

Currently, this resource kind only supports GET and PUT requests. Note that a PUT request may end up creating a new file, but that detail is hidden from the caller.

In terms of GET, this resource kind only supports a GET request for a single UI definition resource, where that GET is done by key. The key to use is 'version;languageCode;category;userID;name'. For example, the key might be 'portal61a;-;portal;-;SwtPortalUIDefinition' to get the UI definition for the currently signed-on user in their language, or 'portal61a;fra;portal;ADMIN;SwtPortalUIDefinition' to get the UI definition for ADMIN assuming the French language.

This resource kind follows a fallback scheme to try to find an appropriate UI definition resource. It starts by looking for that user's customized version of the UI definition for the specified language. If that customized version isn't found, it then looks for the default version of the UI definition for the specified language. If neither of those files is found and if the specified language isn't the default of "eng" (the one for English), this resource kind will fall back to "eng" and try a similar search for the UI definition. For example, when the key is 'portal61a;fra;portal;ADMIN;SwtPortalUIDefinition', the resource kind will first look for SwtPortalUIDefinition.xml in the portal61a\fra\portal\ADMIN\SAMINC directory (SAMINC is the current dataset) within the directory where UI definitions are stored the servlet. The search would continue in portal61a\fra\portal, then portal61a\eng\portal\ADMIN\SAMINC, and finally in portal61a\eng\portal.

In terms of PUT (update), this resource kind supports a PUT request for a single UI definition resource, where that PUT is done by key. The key to use for the PUT request is the same key that would be used for a GET request.

The PUT request will take the UI definition (passed in as part of the PUT payload) and save it as the user's customized version of the UI definition for the specified language. If such a file already exists, that existing file will be overwritten with the updated UI definition. If the file does not yet exist, it will be created. (Even though a new file gets created, we still count it as a PUT because we are updating an already existing UI definition - after all, the non-customized version has to exist before we can get it and later save it as a customized version). Note that the default (non-customized) version of the UI definition is never touched. For example, when user ADMIN is logged in as a French ("fra") user, doing a PUT with key 'portal61a;-;portal;-;SwtPortalUIDefinition' would save the UI definition (passed in through the payload) as the SwtPortalUIDefinition.xml file in the portal61a\fra\portal\ADMIN\SAMINC directory (SAMINC is the current dataset).

NOTE: UI developers who change UI definitions will first need to copy the changed definitions to the appropriate directory structure within the portal configuration area (under the directory where Tomcat is installed). Then, they will need to stop and restart Tomcat. The language directories (e.g. the "eng" directories) must be lower-cased.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.sage.orion.sdata.servlet.JDBCResourceKind
JDBCResourceKind.HTTPMethodsAuthorizator, JDBCResourceKind.ResourceAuthorizator, JDBCResourceKind.ResourceDataAuthorizator
 
Field Summary
 
Fields inherited from class com.sage.orion.sdata.servlet.JDBCResourceKind
ADD, ALTER_TABLE, AND, CLOSE_BRACE, COMMA, CONSTRAINT, DEFAULT, DEFAULT_LANGUAGE_CODE, DELETE_FROM, DROP, DROP_TABLE, FROM, NOT_NULL, OPEN_BRACE, PRIMARY_KEY, SELECT, UICONTENT_SQL_SELECT_STMT, VARCHAR_50, WHERE
 
Constructor Summary
UIDefinitionResourceKind(ApplicationContext context, ConnectionPool connectionPool, java.lang.String authToken)
          Constructor
 
Method Summary
protected  boolean canGetOnData(SDataRequest request, java.sql.Connection connection)
          Indicates whether the user has the privilege to GET the data specified in the request.
protected  boolean canPutOnData(SDataRequest request, java.sql.Connection connection)
          Indicates whether the user has the privilege to PUT the data specified in the request.
protected  ResourceResponse doGet(SDataRequest request, java.sql.Connection connection)
          This method takes appropriate action and generates ResourceResponse based on the specified request
protected  ResourceResponse doPut(SDataRequest request, java.sql.Connection connection)
          Handles the PUT request, which is for updating records.
protected  SchemaResponse doSchema(SDataRequest request, java.sql.Connection connection)
          Handles the GET request for the special $schema operator.
protected  ResourceResponse doTemplate(SDataRequest request, java.sql.Connection connection)
          Handles the GET request for the special $template operator.
protected  java.util.List<FieldDefinition> getAllFields()
          returns a list of FieldDefinitions in the ResourceKind
protected  java.lang.String getCalculateFieldValue(java.lang.String value, SDataRequest request, java.sql.ResultSet resultSet, int fieldIndex)
          Get the value of the calculated field, if it is a regular (non-calculated) field then the original value will be returned unchanged
protected  org.w3c.dom.Document getFileAsNormalizedDOM(java.io.File inputFilePath, boolean useLock)
           Gets the specified input file's contents as a normalized DOM document, and if specified, locking the file in a shared ("for reading") manner while getting that content.
 java.lang.String getName()
          
protected  java.lang.String[] getPrimaryKey()
          Get the primary key of the underlying JDBC table for which one JDBCResourceKindImpl is created
protected  java.lang.String getTableName()
          Get the JDBC table name for which ResourceKindImpl is created
 boolean isUserSpecificResource()
          Indicates whether the resource is user specific or not.
protected  org.w3c.dom.Document parseFile(java.io.File inputFilePath, javax.xml.parsers.DocumentBuilder documentBuilder, boolean useLock)
           Uses the specified document builder to parse the specified input file into a "plain" DOM document (with no other transformations such as normalization done), and if specified, locking the file in a shared ("for reading") manner during the parse.
protected  boolean supportDelete()
          Indicates whether the ResourceKind in general supports DELETE or not.
protected  boolean supportGet()
          Indicates whether the ResourceKind in general supports GET or not.
protected  boolean supportPost()
          Indicates whether the ResourceKind in general supports POST or not.
protected  boolean supportPut()
          Indicates whether the ResourceKind in general supports PUT or not.
 
Methods inherited from class com.sage.orion.sdata.servlet.JDBCResourceKind
addCompanyIDField, addRecordsForAllCompanies, buildUserFilter, canDelete, canDeleteOnData, canGet, canPost, canPostOnData, canPut, createPreparedEntryGetStatement, doDelete, doPost, fillResultSetResourceElement, findUIContentTextValueInDB, focusOnResultSet, freeConnection, getApplicationContext, getAuthToken, getCaseInsensitiveColumns, getColumnNamesFromList, getCompanyIDField, getCompanyIDForFilter, getConnection, getCurrentRequest, getCurrentUser, getCustomizedQuery, getDatabaseType, getDefaultFeedCount, getFieldData, getFieldSchemaIdentity, getFieldSchemaName, getFieldSchemaType, getIncludeColumns, getInstance, getKeyValueForKeyName, getMaxFeedCount, getOrderByClause, getOrderByClauseForKeyField, getPreparedStatement, getQueryStringForParam, getResourceKindFieldsCount, getResultRecordAndCreateResponse, getSchema, getTemplate, getTransText, getUserIDField, getUserIDForFilter, handleRequest, maintainTable, moveRecordPointerToKeyInURL, requiresCompanyIdInjection, requiresSignon, requiresUserIdInjection, shutdown, splitKeyIntoSegments, splitResourceSelectorKeyIntoSegments
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UIDefinitionResourceKind

public UIDefinitionResourceKind(ApplicationContext context,
                                ConnectionPool connectionPool,
                                java.lang.String authToken)
Constructor

Parameters:
context - SData application context
connectionPool - connectionPool of the underline DB
authToken - the authentication token
Method Detail

doSchema

protected SchemaResponse doSchema(SDataRequest request,
                                  java.sql.Connection connection)
Handles the GET request for the special $schema operator.

Overrides:
doSchema in class JDBCResourceKind
Parameters:
request - The input SDataRequest for the GET of the special $schema operator.
connection - The JDBC connection object which provides a gateway to access underlying DB.
Returns:
The SData response containing the schema for that resource kind.

doTemplate

protected ResourceResponse doTemplate(SDataRequest request,
                                      java.sql.Connection connection)
                               throws java.sql.SQLException
Handles the GET request for the special $template operator.

Overrides:
doTemplate in class JDBCResourceKind
Parameters:
request - The input SDataRequest for the GET of the special $template operator.
connection - The JDBC connection object which provides a gateway to access underlying DB.
Returns:
The SData response containing the template entry (think of it as a "new record" buffer with blank defaults).
Throws:
java.sql.SQLException - SQLException

doGet

protected ResourceResponse doGet(SDataRequest request,
                                 java.sql.Connection connection)
                          throws java.sql.SQLException
This method takes appropriate action and generates ResourceResponse based on the specified request

Overrides:
doGet in class JDBCResourceKind
Parameters:
request - the SDataRequest
connection - the JDBC connection object which provides a gateway to access underlying DB
Returns:
The ResourceResponse
Throws:
java.sql.SQLException - SQLException

doPut

protected ResourceResponse doPut(SDataRequest request,
                                 java.sql.Connection connection)
                          throws java.sql.SQLException
Handles the PUT request, which is for updating records. Normally a Put web request is used to submit huge amount of data/secret data in the form of a Stream say ByteStream

Overrides:
doPut in class JDBCResourceKind
Parameters:
request - the request Object having the entry object for the JDBC ResourceKind Put request
connection - the JDBC connection object which provides a gateway to access underlying DB
Returns:
A ResourceResponse which is a Java object and having the ability to be added into the web(HttpServletResponse) response (addToResponse)
Throws:
java.sql.SQLException - SQLException

getFileAsNormalizedDOM

protected org.w3c.dom.Document getFileAsNormalizedDOM(java.io.File inputFilePath,
                                                      boolean useLock)

Gets the specified input file's contents as a normalized DOM document, and if specified, locking the file in a shared ("for reading") manner while getting that content.

NOTE: This method does not return null - it throws an exception if it encounters a problem.

Parameters:
inputFilePath - The File object representing the path to input file.
useLock - Whether or not to lock the file (in a shared manner) during the parse.
Returns:
The specified input file's contents as a normalized DOM document

parseFile

protected org.w3c.dom.Document parseFile(java.io.File inputFilePath,
                                         javax.xml.parsers.DocumentBuilder documentBuilder,
                                         boolean useLock)
                                  throws java.io.IOException,
                                         org.xml.sax.SAXException

Uses the specified document builder to parse the specified input file into a "plain" DOM document (with no other transformations such as normalization done), and if specified, locking the file in a shared ("for reading") manner during the parse.

NOTE: We block until the lock is obtained.

Parameters:
inputFilePath - The File object representing the path to the input file.
documentBuilder - The DOM document builder used to parse the input file.
useLock - Whether or not to lock the file (in a shared manner) during the parse.
Returns:
The "plain" DOM representation of the input file's content.
Throws:
java.lang.NullPointerException - Null arguments were passed in.
java.io.IOException - A problem happened while trying to access the input file.
org.xml.sax.SAXException - A problem happened while trying to parse the input file's content.

getPrimaryKey

protected java.lang.String[] getPrimaryKey()
Get the primary key of the underlying JDBC table for which one JDBCResourceKindImpl is created

Specified by:
getPrimaryKey in class JDBCResourceKind
Returns:
the primary key

getTableName

protected java.lang.String getTableName()
Get the JDBC table name for which ResourceKindImpl is created

Specified by:
getTableName in class JDBCResourceKind
Returns:
the JDBC table name

getName

public java.lang.String getName()


getAllFields

protected java.util.List<FieldDefinition> getAllFields()
returns a list of FieldDefinitions in the ResourceKind

Specified by:
getAllFields in class JDBCResourceKind
Returns:
FieldDefinition list

getCalculateFieldValue

protected java.lang.String getCalculateFieldValue(java.lang.String value,
                                                  SDataRequest request,
                                                  java.sql.ResultSet resultSet,
                                                  int fieldIndex)
Get the value of the calculated field, if it is a regular (non-calculated) field then the original value will be returned unchanged

Specified by:
getCalculateFieldValue in class JDBCResourceKind
Parameters:
value - value of the field
request - the input SDataRequest
resultSet - resultSet returned by query
fieldIndex - fieldIndex - 0-based
Returns:
the value of the field

isUserSpecificResource

public boolean isUserSpecificResource()
Indicates whether the resource is user specific or not. If the resource is user specific, it generally requires user sign on.

Specified by:
isUserSpecificResource in class JDBCResourceKind
Returns:
True if the resource is user specific, false otherwise.

supportDelete

protected boolean supportDelete()
Indicates whether the ResourceKind in general supports DELETE or not.

Specified by:
supportDelete in class JDBCResourceKind
Returns:
True if the ResourceKind supports DELETE, false otherwise.

supportGet

protected boolean supportGet()
Indicates whether the ResourceKind in general supports GET or not.

Specified by:
supportGet in class JDBCResourceKind
Returns:
True if the ResourceKind supports GET, false otherwise.

supportPost

protected boolean supportPost()
Indicates whether the ResourceKind in general supports POST or not.

Specified by:
supportPost in class JDBCResourceKind
Returns:
True if the ResourceKind supports POST, false otherwise.

supportPut

protected boolean supportPut()
Indicates whether the ResourceKind in general supports PUT or not.

Specified by:
supportPut in class JDBCResourceKind
Returns:
True if the ResourceKind supports PUT, false otherwise.

canGetOnData

protected boolean canGetOnData(SDataRequest request,
                               java.sql.Connection connection)
                        throws java.sql.SQLException
Indicates whether the user has the privilege to GET the data specified in the request.

Overrides:
canGetOnData in class JDBCResourceKind
Parameters:
request - The GET request.
connection - The database connection.
Returns:
True is the user has the privilege to GET the data specified in the request.
Throws:
java.sql.SQLException - SQLException

canPutOnData

protected boolean canPutOnData(SDataRequest request,
                               java.sql.Connection connection)
                        throws java.sql.SQLException
Indicates whether the user has the privilege to PUT the data specified in the request.

Overrides:
canPutOnData in class JDBCResourceKind
Parameters:
request - The PUT request.
connection - The database connection.
Returns:
True is the user has the privilege to PUT the data specified in the request.
Throws:
java.sql.SQLException - SQLException


Copyright © 2011 Sage Software, Inc. All rights reserved.