Listing search criteria
You use methods in the ODCriteria class to list the search criteria for a specified folder.
About this task
The following example demonstrates how to use ODCriteria methods to list the search criteria for a specified folder. For each search field, this example lists the name of the search field, the default operator, the operators that are valid for the field, the field type, and any default search values. The default values are listed by the ODCriteria.getSearchValues method. Fixed search values are listed for any search fields that are defined as FixedChoice or Segment.
This example demonstrates the following ODCriteria
methods:
- getName
- getOperator
- getValidOperators
- getType
- getDefaultFmt
- getDisplayFmt
- getDisplayFmtQual
- getMaxEntryChars
- getMaxDisplayChars
- getMinSearchValue
- getMaxSearchValue
- getDBFieldNames
- getDBFieldMask
- getSearchValues
- getFixedValues
- isUpdateable
- isRequired
- isDefaultValueAvailable
- isDefaultValueFixed
This example demonstrates the following ODServer methods:
- initialize
- logon
- openFolder
- logoff
- terminate
- getName
- getDescription
- getNumApplGroups
- getApplGroupNames
- getNumCriteria
- getCriteria
- close
This example uses the following runtime parameters:
- Server name
- Port
- User Id
- Password
- Folder name
Example of accessing search criteria:
import java.util.*;
import java.io.*;
import com.ibm.edms.od.*;
public class TcListCriteria
{
public static void main ( String argv[] )
{
ODServer odServer;
ODFolder odFolder;
ODCriteria odCrit;
Enumeration crit_enum;
String[] value_vec;
String[] search_values, fixed_values, database_fields;
Object[] appl_grps;
int[] valid_oprs;
int j, k, opr;
char field_type;
//----------
// If too few parameters, display syntax and get out
//----------
if ( argv.length < 5 )
{
System.out.println( "usage: java TcListCriteria <server> <port> <userid> <password> <folder>" );
return;
}
try
{
//----------
// Set the stage
//----------
System.out.println( "Test case TcListCriteria started." );
System.out.println( "This test case should:" );
System.out.println( " Logon to the specified server" );
System.out.println( " Open the specified folder" );
System.out.println( " Display the folder name and description" );
System.out.println( " Display the number and names of folder application groups" );
System.out.println( " Display the number of folder criteria" );
System.out.println( " For each criteria, display the" );
System.out.println( " Name" );
System.out.println( " Default operator" );
System.out.println( " Valid operators" );
System.out.println( " Field Type" );
System.out.println( " Required, DefaultValueAvailable, and DefaultValueFixed (true/false) flags" );
System.out.println( " Maximum Entry Characters" );
System.out.println( " Maximum Display Characters" );
System.out.println( " Number and names of database fields" );
System.out.println( " Default values (by ODCrit.getSearchValues method)" );
System.out.println( " Default values (by ODCrit.getValues method)" );
System.out.println( " Fixed values (only for FixedChoice and Segment criteria)" );
System.out.println( "" );
System.out.println( "Ensure that none of the operators indicates 'Unknown operator'," );
System.out.println( "that none of the field types indicates 'Unknown type', that the" );
System.out.println( "default values are the same for each method, and that all" );
System.out.println( "information is the same as that displayed using the Windows Client." );
System.out.println( "" );
System.out.println( "---------------------------------------------------" );
System.out.println( "" );
ODConfig odConfig = new ODConfig();
if(odConfig != null)
{
odServer = new ODServer(odConfig );
odServer.initialize( "TcListCriteria.java" );
System.out.println( "Logging on to " + argv[0] + " server with user " + argv[2] + "..." );
odServer.setPort(Integer.parseInt(argv[1]));
odServer.logon( argv[0], argv[2], argv[3]);
//----------
// Open the specified folder and display its name and description
//----------
System.out.println( "Opening " + argv[4] + " folder..." );
odFolder = odServer.openFolder( argv[4] );
System.out.println( "Name='" + odFolder.getName( ) + "' Desc='" + odFolder.getDescription( ) + "'" );
//----------
// Display number and names of application groups
//----------
System.out.println( "There is(are) " + odFolder.getNumApplGroups( ) +
" application group(s) in the folder:" );
appl_grps = odFolder.getApplGroupNames( );
for ( j = 0; j < appl_grps.length; j++ )
System.out.println( " " + appl_grps[j].toString( ) );
//----------
// For each folder criteria,
//----------
System.out.println( "There are " + odFolder.getNumCriteria( ) + " criteria:" );
for ( crit_enum = odFolder.getCriteria( ); crit_enum.hasMoreElements( ); )
{
//----------
// Display criteria name
//----------
System.out.println( "" );
odCrit = (ODCriteria)crit_enum.nextElement( );
System.out.println( odCrit.getName( ) );
//----------
// Display default operator
//----------
opr = odCrit.getOperator( );
System.out.println( " Default operator: " );
System.out.println( " " + getOperatorName( opr ) );
//----------
// Display valid operators
//----------
valid_oprs = odCrit.getValidOperators() ;
System.out.println( " Valid operators:" );
for ( j = 0; j < valid_oprs.length; j++ )
System.out.println( " " + getOperatorName( valid_oprs[j] ) );
//----------
// Display field type
//----------
field_type = odCrit.getType( );
System.out.println( " Type:" );
System.out.println( " " + getTypeName( field_type ) );
//----------
// Display field format for Date
//----------
if ( odCrit.getDefaultFmt() != null)
{
System.out.println(" Date Format:" );
System.out.println(" DefaultDisplay Fmt " + odCrit.getDefaultFmt());
System.out.println(" Display Fmt " + odCrit.getDisplayFmt());
}
System.out.println(" DisplayFmtQualifier " + odCrit.getDisplayFmtQual());
//----------
// Display field id mask info
//----------
System.out.println( " FieldIdMask:" );
System.out.println( " Required=" + odCrit.isRequired( ) +
" Default=" + odCrit.isDefaultValueAvailable( ) +
" Fixed Default=" + odCrit.isDefaultValueFixed( ) );
//----------
// Display max entry chars
//----------
System.out.println( " MaxEntryChars:" );
System.out.println( " " + odCrit.getMaxEntryChars( ) );
//----------
// Display max display chars
//----------
System.out.println( " MaxDisplayChars:" );
System.out.println( " " + odCrit.getMaxDisplayChars( ) );
//----------
// Display min search values
//----------
System.out.println( " MinSearchValue:" );
System.out.println( " " + odCrit.getMinSearchValue( ) );
//----------
// Display max search values
//----------
System.out.println( " MaxSearchValue:" );
System.out.println( " " + odCrit.getMaxSearchValue( ) );
//----------
// Display the database field names
//----------
System.out.println(" Database fields:");
for (j = 0; j < appl_grps.length; j++)
{
database_fields = odCrit.getDBFieldNames((String)appl_grps[j]);
if(database_fields == null)
System.out.println("No DBFields Defined");
else
{
System.out.println(" " + database_fields.length + " for ApplGroup '" +
(String)appl_grps[j] + "':");
for (k = 0; k < database_fields.length; k++)
{
System.out.println(" DB Field Name = " +
(database_fields[k].equals("") ? "[empty string]" : database_fields[k]));
long fieldMask = odCrit.getDBFieldMask((String)appl_grps[j],database_fields[k]);
System.out.println(" Field Mask - " + fieldMask);
System.out.println( " Application ID Field = " +
((fieldMask & ODConstant.OD_FLDMSK_APPL )== 0
? false : true ));
boolean update_field = odCrit.isUpdateable((String)appl_grps[j], database_fields[k]);
if (update_field)
System.out.println(" Field is Updateable" );
}
}
}
//----------
// Display default value(s) using ODCrit.getValues( )
//----------
value_vec = odCrit.getSearchValues( );
System.out.println(" Default Value(s) (ODCrit.getValues method):");
System.out.println( " '" + value_vec[ 0 ] + "'" );
System.out.println( " '" + value_vec[ 1 ] + "'" );
//----------
// Display default value(s) using ODCrit.getSearchValues( )
//----------
search_values = odCrit.getSearchValues( );
System.out.println(" Default Values (ODCrit.getSearchValues method):");
for ( j = 0; j < search_values.length; j++ )
System.out.println(" '" + search_values[j] + "'" );
//----------
// Display fixed choices
//----------
switch ( field_type )
{
case ODConstant.InputTypeChoice:
case ODConstant.InputTypeSegment:
fixed_values = odCrit.getFixedValues( );
System.out.println(" Fixed Values (only for field types FixedChoice and Segment):");
for ( j = 0; j < fixed_values.length; j++ )
System.out.println(" '" + fixed_values[j] + "'" );
break;
}
}
//----------
// Cleanup
//----------
odFolder.close( );
odServer.logoff( );
odServer.terminate( );
System.out.println( "" );
System.out.println( "---------------------------------------------------" );
System.out.println( "" );
System.out.println( "Test case TcListCriteria completed -" );
System.out.println( " analyze and compare results to Windows Client if required" );
System.out.println( "" );
}
}
catch ( ODException e )
{
System.out.println( "ODException: " + e );
System.out.println( " id = " + e.getErrorId( ) );
System.out.println( " msg = " + e.getErrorMsg( ) );
e.printStackTrace( );
}
catch ( Exception e2 )
{
System.out.println( "exception: " + e2 );
e2.printStackTrace( );
}
}
static String getOperatorName( int oper )
{
String str;
switch( oper )
{
case ODConstant.OPEqual:
str = "Equal";
break;
case ODConstant.OPNotEqual:
str = "Not Equal";
break;
case ODConstant.OPLessThan:
str = "Less Than";
break;
case ODConstant.OPLessThanEqual:
str = "Less Than or Equal";
break;
case ODConstant.OPGreaterThan:
str = "Greater Than";
break;
case ODConstant.OPGreaterThanEqual:
str = "Greater Than or Equal";
break;
case ODConstant.OPIn:
str = "In";
break;
case ODConstant.OPNotIn:
str = "Not In";
break;
case ODConstant.OPLike:
str = "Like";
break;
case ODConstant.OPNotLike:
str = "Not Like";
break;
case ODConstant.OPBetween:
str = "Between";
break;
case ODConstant.OPNotBetween:
str = "Not Between";
break;
default:
str = "*** Unknown operator";
break;
}
return str;
}
static String getTypeName( char type )
{
String str;
switch( type )
{
case ODConstant.InputTypeNormal:
str = "Normal";
break;
case ODConstant.InputTypeTextSearch:
str = "TextSearch";
break;
case ODConstant.InputTypeNoteTextSearch:
str = "NoteTextSearch";
break;
case ODConstant.InputTypeNoteColor:
str = "NoteColor";
break;
case ODConstant.InputTypeChoice:
str = "FixedChoice";
break;
case ODConstant.InputTypeSegment:
str = "Segment";
break;
default:
str = "*** Unknown type";
break;
}
return str;
}
}