use of CCDD.CcddTableTypeHandler.TypeDefinition in project CCDD by nasa.
the class CcddWebDataAccessHandler method getTelemetryInformation.
/**
********************************************************************************************
* Get the path, data type, bit length, description, units, data stream information, and
* enumeration information for each telemetered variable matching the specified filters
*
* @param telemetryFilter
* group (or application) name, data stream name, and/or rate value filter(s). A
* table must belong to the specified group in order for its telemetered variables
* to be returned; blank to get all telemetered variables (regardless of group). A
* variable must have a rate assigned for the specified data stream in order to be
* included; blank to include all data streams. A variable's rate must match the
* specified rate in order to be included; blank to include the variable regardless
* of the rate value
*
* @return JSON encoded string containing the path, data type, bit length, description, units,
* data stream name(s), and enumeration(s) for each telemetered variable matching the
* specified filters; empty array if no variables are telemetered
*
* @throws CCDDException
* If an invalid group name, data stream name, or rate value format is detected
********************************************************************************************
*/
@SuppressWarnings("unchecked")
private String getTelemetryInformation(String telemetryFilter) throws CCDDException {
JSONArray telemetryJA = new JSONArray();
TypeDefinition typeDefn = null;
String groupFilter = "";
String streamFilter = "";
String rateFilter = "";
int variableNameIndex = -1;
int dataTypeIndex = -1;
int bitLengthIndex = -1;
List<Integer> rateIndices = null;
List<Integer> enumerationIndices = null;
int descriptionIndex = -1;
int unitsIndex = -1;
List<String> allTableNameList = new ArrayList<String>();
// Table type name for the previous table type loaded
String lastType = "";
// Get the array of data stream names
String[] dataStreamNames = rateHandler.getDataStreamNames();
// Check if a filter is specified
if (!telemetryFilter.isEmpty()) {
// Separate the filter parameters
String[] filter = getParts(telemetryFilter, ",", 3, true);
// if present, is in the expected format
if ((filter[1].isEmpty() || Arrays.asList(dataStreamNames).contains(filter[1])) && (filter[2].isEmpty() || filter[2].matches("\\d+(?:$|(?:\\.|\\s*/\\s*)\\d+)"))) {
// Store the group name, stream name, and rate filters
groupFilter = filter[0];
streamFilter = filter[1];
rateFilter = filter[2];
// Check if a group name filter is specified
if (!groupFilter.isEmpty()) {
// Create a group handler and extract the table names belonging to the group
CcddGroupHandler groupHandler = new CcddGroupHandler(ccddMain, null, ccddMain.getMainFrame());
GroupInformation groupInfo = groupHandler.getGroupInformationByName(groupFilter);
// Check if the group doesn't exist
if (groupInfo == null) {
throw new CCDDException("unrecognized group name");
}
// Get the tables associated with the group
allTableNameList = groupInfo.getTablesAndAncestors();
}
} else // Unrecognized data stream name or invalid rate value format
{
throw new CCDDException("unrecognized stream name or invalid rate value format");
}
}
// Check if no group filter is in effect
if (groupFilter.isEmpty()) {
// Get a list of all root and child tables
tableTreeType = TableTreeType.INSTANCE_TABLES;
allTableNameList = getTableList();
}
// Step through each structure table
for (String table : allTableNameList) {
// Get the information from the database for the specified table
TableInformation tableInfo = dbTable.loadTableData(table, false, false, false, ccddMain.getMainFrame());
// Check if the table loaded successfully
if (!tableInfo.isErrorFlag()) {
// Get the table's type definition
typeDefn = tableTypeHandler.getTypeDefinition(tableInfo.getType());
// Check if the table represents a structure
if (typeDefn.isStructure()) {
// every table
if (!tableInfo.getType().equals(lastType)) {
String descColName;
String unitsColName;
descriptionIndex = -1;
unitsIndex = -1;
// Store the table type name
lastType = tableInfo.getType();
// Get the variable name column
variableNameIndex = typeDefn.getColumnIndexByInputType(InputDataType.VARIABLE);
// Get the data type column
dataTypeIndex = typeDefn.getColumnIndexByInputType(InputDataType.PRIM_AND_STRUCT);
// Get the bit length column
bitLengthIndex = typeDefn.getColumnIndexByInputType(InputDataType.BIT_LENGTH);
// Check if a data stream filter is in effect
if (!streamFilter.isEmpty()) {
// Get the index of the rate column corresponding to the data stream
// filter
rateIndices = new ArrayList<Integer>();
// Get the index of the rate column with the corresponding data stream
// name
int rateIndex = typeDefn.getColumnIndexByUserName(rateHandler.getRateInformationByStreamName(streamFilter).getRateName());
// Check if the table has the specified rate column
if (rateIndex != -1) {
// Add the rate column index to the list
rateIndices.add(typeDefn.getColumnIndexByUserName(rateHandler.getRateInformationByStreamName(streamFilter).getRateName()));
}
} else // Include all data streams
{
// Get the indices for all rate columns
rateIndices = typeDefn.getColumnIndicesByInputType(InputDataType.RATE);
}
// Get the enumeration column(s)
enumerationIndices = typeDefn.getColumnIndicesByInputType(InputDataType.ENUMERATION);
// Check if a description column exists
if ((descColName = typeDefn.getColumnNameByInputType(InputDataType.DESCRIPTION)) != null) {
// Get the description column
descriptionIndex = typeDefn.getColumnIndexByUserName(descColName);
}
// Check if a units column exists
if ((unitsColName = typeDefn.getColumnNameByInputType(InputDataType.UNITS)) != null) {
// Get the units column
unitsIndex = typeDefn.getColumnIndexByUserName(unitsColName);
}
}
// values
if (isReplaceMacro) {
// Replace all macros in the table
tableInfo.setData(ccddMain.getMacroHandler().replaceAllMacros(tableInfo.getData()));
}
// Step through each variable in the structure table
for (int row = 0; row < tableInfo.getData().length; row++) {
JSONObject structureJO = new JSONObject();
String cellValue;
// on this row is skipped
if (!(cellValue = tableInfo.getData()[row][variableNameIndex]).isEmpty()) {
boolean hasRate = false;
// Step through the relevant rate columns
for (Integer rateIndex : rateIndices) {
// rate filter value (or no filter is in effect)
if (!tableInfo.getData()[row][rateIndex].isEmpty() && (rateFilter.isEmpty() || tableInfo.getData()[row][rateIndex].equals(rateFilter))) {
hasRate = true;
// Store the rate in the JSON output
structureJO.put(typeDefn.getColumnNamesUser()[rateIndex], tableInfo.getData()[row][rateIndex]);
}
}
// Check if a variable matching the rate filters exists
if (hasRate) {
// Store the name of the structure table from which this variable
// is taken
structureJO.put("Structure Table Name", table);
// Store the variable name in the JSON output
structureJO.put(typeDefn.getColumnNamesUser()[variableNameIndex], cellValue);
// Check if the data type is present
if (!(cellValue = tableInfo.getData()[row][dataTypeIndex]).isEmpty()) {
// Store the data type in the JSON output
structureJO.put(typeDefn.getColumnNamesUser()[dataTypeIndex], cellValue);
}
// Check if the bit length is present
if (!(cellValue = tableInfo.getData()[row][bitLengthIndex]).isEmpty()) {
// Store the bit length in the JSON output
structureJO.put(typeDefn.getColumnNamesUser()[bitLengthIndex], cellValue);
}
// Step through each enumeration column
for (Integer enumerationIndex : enumerationIndices) {
// Check if the enumeration is present
if (!(cellValue = tableInfo.getData()[row][enumerationIndex]).isEmpty()) {
// Store the enumeration in the JSON output
structureJO.put(typeDefn.getColumnNamesUser()[enumerationIndex], cellValue);
}
}
// Check if the description is present
if (descriptionIndex != -1 && !(cellValue = tableInfo.getData()[row][descriptionIndex]).isEmpty()) {
// Store the description in the JSON output
structureJO.put(typeDefn.getColumnNamesUser()[descriptionIndex], cellValue);
}
// Check if the units is present
if (unitsIndex != -1 && !(cellValue = tableInfo.getData()[row][unitsIndex]).isEmpty()) {
// Store the units in the JSON output
structureJO.put(typeDefn.getColumnNamesUser()[descriptionIndex], cellValue);
}
// Add the variable to the JSON array
telemetryJA.add(structureJO);
}
}
}
}
}
}
return telemetryJA.toString();
}
use of CCDD.CcddTableTypeHandler.TypeDefinition in project CCDD by nasa.
the class CcddWebDataAccessHandler method getStructureSize.
/**
********************************************************************************************
* Get the number of bytes for the prototype of the specified structure table, or for all
* prototype structure tables if no table is specified
*
* @param tableName
* structure table name or path
*
* @return JSON encoded string containing the structure table name(s) and corresponding size(s)
* in bytes; null if a table name is specified and the table doesn't exist or isn't a
* structure, or if no structure tables exist in the project database
********************************************************************************************
*/
@SuppressWarnings("unchecked")
private String getStructureSize(String tableName) {
String response = null;
JSONObject responseJO = null;
JSONArray responseJA = new JSONArray();
// Get the list of table names and their associated table type
ArrayListMultiple protoNamesAndTableTypes = new ArrayListMultiple();
protoNamesAndTableTypes.addAll(dbTable.queryTableAndTypeList(ccddMain.getMainFrame()));
// Get the specified table's prototype table name
String prototypeName = TableInformation.getPrototypeName(tableName);
// Flag indicating if a single table is requested
boolean isSingle = !prototypeName.isEmpty();
// Step through each prototype table name/type
for (String[] namesAndType : protoNamesAndTableTypes) {
// specified name
if (!isSingle || prototypeName.equalsIgnoreCase(namesAndType[0])) {
// Get the table's type definition
TypeDefinition typeDefn = tableTypeHandler.getTypeDefinition(namesAndType[2]);
// Check if the table represents a structure
if (typeDefn.isStructure()) {
responseJO = new JSONObject();
// Check if the link handler exists
if (linkHandler == null) {
// Create a link handler
linkHandler = new CcddLinkHandler(ccddMain, ccddMain.getMainFrame());
}
// Store the table name and its size in bytes
responseJO.put(JSONTags.TABLE_NAME.getTag(), (isSingle ? tableName : namesAndType[0]));
responseJO.put(JSONTags.TABLE_BYTE_SIZE.getTag(), variableHandler.getDataTypeSizeInBytes(namesAndType[0]));
// Check if only one table is being processed
if (isSingle) {
// Stop searching
break;
}
// More than one table is in the response; add the name and size to the array
responseJA.add(responseJO);
}
}
}
// none is specified
if (responseJO != null) {
// Set the response based of if a single or multiple types are included in the
// response. If single then the JSON object is used to prevent the extraneous brackets
// from enclosing the response
response = (isSingle) ? responseJO.toString() : responseJA.toString();
}
return response;
}
use of CCDD.CcddTableTypeHandler.TypeDefinition in project CCDD by nasa.
the class CcddWebDataAccessHandler method getSearchResults.
/**
********************************************************************************************
* Perform a search for the specified text in the data and internal tables
*
* @param searchCriteria
* attribute containing the search constraints in the format <search text>,<ignore
* case (true or false)>,<allow regular expression (true or false)>,<data table
* cells only (true or false)><,search table column names>. The 'ignore case' and
* 'data table cells only' flags default to false if not provided. The last
* criterion is optional and allows the search to be constrained to specific columns
* in the data tables. The column names must be comma-separated (if more than one)
* and are case sensitive
*
* @return JSON encoded string containing the search results. An empty string if no matches are
* found, and null if the search parameters are missing or invalid
********************************************************************************************
*/
@SuppressWarnings("unchecked")
private String getSearchResults(String searchCriteria) {
String response = null;
// Separate the search criteria string into the search text, ignore case flag, allow
// regular expression, search data table cells only flag, and the column names in which to
// search
String[] parameter = getParts(searchCriteria, ",", 5, true);
String searchText = parameter[0];
String ignoreCase = parameter[1];
String allowRegex = parameter[2];
String dataTablesOnly = parameter[3];
String searchColumns = parameter[4];
// Check if the flag to ignore case isn't present
if (ignoreCase.isEmpty()) {
// Default to constraining matches by text case
ignoreCase = "false";
}
// Check if the flag to search only the data tables isn't present
if (dataTablesOnly.isEmpty()) {
// Default to searching the entire project database (data and internal table
// references)
dataTablesOnly = "false";
}
// Check if all the input parameters are present and that they're in the expected formats
if (!searchText.isEmpty() && ignoreCase.matches(TRUE_OR_FALSE) && dataTablesOnly.matches(TRUE_OR_FALSE)) {
String dbColumns = "";
JSONArray searchJA = new JSONArray();
// Check if one or more column names to which the search is constrained is provided
if (!searchColumns.isEmpty()) {
// Step through each column name
for (String column : getParts(searchColumns, ",", -1, true)) {
// Step through each defined table type
for (TypeDefinition typeDefn : tableTypeHandler.getTypeDefinitions()) {
// Step through each visible column in the table type
for (int index = NUM_HIDDEN_COLUMNS; index < typeDefn.getColumnCountDatabase(); ++index) {
// definition
if (column.equals(typeDefn.getColumnNamesUser()[index])) {
// Add the column's corresponding database name to the column
// constraints string. Stop searching since column names can't be
// duplicated within a table
dbColumns += typeDefn.getColumnNamesDatabase()[index] + ",";
break;
}
}
// Even if a match is found in one table type definition the search is
// allowed to continue in other definitions. Under certain circumstances
// involving structure table types it's possible for the database column
// name to be the same in two table types, but have different visible names
}
dbColumns = CcddUtilities.removeTrailer(dbColumns, ",");
}
}
// Create a search handler to perform the search
CcddSearchHandler searchHandler = new CcddSearchHandler(ccddMain, SearchDialogType.TABLES);
// Perform the search and step through the results, if any
for (Object[] searchResult : searchHandler.searchTablesOrScripts(searchText, Boolean.valueOf(ignoreCase), Boolean.valueOf(allowRegex), Boolean.valueOf(dataTablesOnly), dbColumns)) {
// Store each search result in a JSON object and add it to the search results array
JSONObject searchJO = new JSONObject();
searchJO.put(SearchResultsColumnInfo.OWNER.getColumnName(SearchDialogType.TABLES), searchResult[SearchResultsColumnInfo.OWNER.ordinal()]);
searchJO.put(SearchResultsColumnInfo.LOCATION.getColumnName(SearchDialogType.TABLES), searchResult[SearchResultsColumnInfo.LOCATION.ordinal()]);
searchJO.put(SearchResultsColumnInfo.CONTEXT.getColumnName(SearchDialogType.TABLES), searchResult[SearchResultsColumnInfo.CONTEXT.ordinal()]);
searchJA.add(searchJO);
}
response = searchJA.toString();
}
return response;
}
use of CCDD.CcddTableTypeHandler.TypeDefinition in project CCDD by nasa.
the class CcddMessageIDHandler method getMessageIDsInUse.
/**
********************************************************************************************
* Create the list of message IDs that are reserved or are already in use
*
* @param includeStructures
* true to include message IDs assigned to tables that represent structures
*
* @param includeCommands
* true to include message IDs assigned to tables that represent commands
*
* @param includeOthers
* true to include message IDs assigned to tables that do not represent structures
* or commands
*
* @param includeGroups
* true to include message IDs assigned to groups
*
* @param useTlmMsgIDsFromDb
* true to include message IDs assigned to telemetry messages stored in the project
* database; false to use the IDs from the currently open telemetry scheduler
*
* @param isOverwriteTlmMsgIDs
* true to allow overwriting the telemetry message IDs for the currently selected
* data stream in the open telemetry scheduler; false to not allow overwriting. This
* value is only used if useTlmMsgIDsFromDb is false
*
* @param tlmSchedulerDlg
* Reference to the currently open telemetry scheduler. This value is only used if
* useTlmMsgIDsFromDb is false, in which case it can be set to null
*
* @param isGetDuplicates
* true to create a list of duplicate IDs. The flags for including tables and for
* using the telemetry message IDs from the database should be set to true when
* getting the list of duplicates
*
* @param parent
* GUI component calling this method
********************************************************************************************
*/
protected List<Integer> getMessageIDsInUse(boolean includeStructures, boolean includeCommands, boolean includeOthers, boolean includeGroups, boolean useTlmMsgIDsFromDb, boolean isOverwriteTlmMsgIDs, CcddTelemetrySchedulerDialog tlmSchedulerDlg, boolean isGetDuplicates, Component parent) {
List<String[]> tableIDs = new ArrayList<String[]>();
// Empty the duplicates list in case this isn't the first execution of this method
duplicates.clear();
potentialDuplicates.clear();
// Get the list of reserved message ID values
idsInUse = rsvMsgIDHandler.getReservedMsgIDs();
// Step through each table type
for (TypeDefinition typeDefn : tableTypeHandler.getTypeDefinitions()) {
// Step through each column that contains message IDs
for (int idColumn : typeDefn.getColumnIndicesByInputType(InputDataType.MESSAGE_ID)) {
// Query the database for those values in the specified message ID column that are
// in use in any table, including any references in the custom values table
tableIDs.addAll(dbTable.queryDatabase("SELECT" + (isGetDuplicates ? " " : " DISTINCT ON (2) ") + "* FROM find_columns_by_name('" + typeDefn.getColumnNamesUser()[idColumn] + "', '" + typeDefn.getColumnNamesDatabase()[idColumn] + "', '{" + typeDefn.getName() + "}');", parent));
}
}
// Get the list of all message ID data field values
tableIDs.addAll(dbTable.queryDatabase("SELECT" + (isGetDuplicates ? " " : " DISTINCT ON (2) ") + InternalTable.FIELDS.getColumnName(FieldsColumn.OWNER_NAME.ordinal()) + ", " + InternalTable.FIELDS.getColumnName(FieldsColumn.FIELD_VALUE.ordinal()) + " FROM " + InternalTable.FIELDS.getTableName() + " WHERE " + InternalTable.FIELDS.getColumnName(FieldsColumn.FIELD_TYPE.ordinal()) + " = '" + InputDataType.MESSAGE_ID.getInputName() + "' AND " + InternalTable.FIELDS.getColumnName(FieldsColumn.FIELD_VALUE.ordinal()) + " != '';", parent));
// Get the list of tables representing structures
structureTables = Arrays.asList(dbTable.getPrototypeTablesOfType(TYPE_STRUCTURE));
// Get the list of tables representing commands
commandTables = Arrays.asList(dbTable.getPrototypeTablesOfType(TYPE_COMMAND));
// Get the list of tables representing table types other than structures and commands
otherTables = Arrays.asList(dbTable.getPrototypeTablesOfType(TYPE_OTHER));
// Step through each data field message ID
for (String[] tableOwnerAndID : tableIDs) {
// Replace any macro in the message ID with the corresponding text
tableOwnerAndID[1] = macroHandler.getMacroExpansion(tableOwnerAndID[1]);
// IDs are to be included
if (tableOwnerAndID[1].endsWith(PROTECTED_MSG_ID_IDENT) || (includeStructures && structureTables.contains(TableInformation.getPrototypeName(tableOwnerAndID[0]))) || (includeCommands && commandTables.contains(tableOwnerAndID[0])) || (includeOthers && otherTables.contains(tableOwnerAndID[0]))) {
// Get the IDs in use in the table cells and data fields, and update the duplicates
// list (if the flag is set)
updateUsageAndDuplicates("Table", tableOwnerAndID, isGetDuplicates);
} else // be included
if (includeGroups && tableOwnerAndID[0].startsWith(GROUP_DATA_FIELD_IDENT)) {
// Get the IDs in use in the group data fields, and update the duplicates list (if
// the flag is set)
updateUsageAndDuplicates("Group", tableOwnerAndID, isGetDuplicates);
}
}
// Check if telemetry message IDs should be obtained from the database
if (useTlmMsgIDsFromDb) {
// Get the telemetry message IDs assigned in the telemetry scheduler table
List<String[]> tlmIDs = dbTable.queryDatabase("SELECT DISTINCT ON (2) " + InternalTable.TLM_SCHEDULER.getColumnName(TlmSchedulerColumn.RATE_NAME.ordinal()) + " || ', ' || " + InternalTable.TLM_SCHEDULER.getColumnName(TlmSchedulerColumn.MESSAGE_NAME.ordinal()) + ", " + InternalTable.TLM_SCHEDULER.getColumnName(TlmSchedulerColumn.MESSAGE_ID.ordinal()) + " FROM " + InternalTable.TLM_SCHEDULER.getTableName() + " WHERE " + InternalTable.TLM_SCHEDULER.getColumnName(TlmSchedulerColumn.MESSAGE_ID.ordinal()) + " != '' AND " + InternalTable.TLM_SCHEDULER.getColumnName(TlmSchedulerColumn.MESSAGE_NAME.ordinal()) + " !~ E'^.+\\\\..*$';", parent);
// Step through each telemetry message ID
for (String[] tlmMsgNameAndID : tlmIDs) {
// Check if the list of duplicate message IDs is to be created
if (isGetDuplicates) {
// Replace the rate name with its corresponding stream name when displaying
// duplicate IDs
String rateName = tlmMsgNameAndID[0].replaceFirst(",.*", "");
String streamName = rateHandler.getRateInformationByRateName(rateName).getStreamName();
tlmMsgNameAndID[0] = tlmMsgNameAndID[0].replaceFirst(rateName, streamName);
}
// Update the IDs in use in the telemetry messages, and update the duplicates list
// (if the flag is set)
updateUsageAndDuplicates("Message", tlmMsgNameAndID, isGetDuplicates);
}
} else // telemetry scheduler but not yet stored them to the database
if (tlmSchedulerDlg != null) {
// Step through each data stream
for (CcddSchedulerHandler schHndlr : tlmSchedulerDlg.getSchedulerHandlers()) {
// overwrite check box is not selected
if (!schHndlr.equals(tlmSchedulerDlg.getSchedulerHandler()) || !isOverwriteTlmMsgIDs) {
// Step through each message for this data stream
for (Message message : schHndlr.getSchedulerEditor().getCurrentMessages()) {
// Check if the message has an ID
if (!message.getID().isEmpty()) {
// Add the message ID to the list of existing ID values
idsInUse.add(Integer.decode(message.getID()));
}
// Step through each of the message's sub-messages
for (Message subMessage : message.getSubMessages()) {
// Check if the sub-message has an ID
if (!subMessage.getID().isEmpty()) {
// Add the sub-message ID to the list of existing ID values
idsInUse.add(Integer.decode(subMessage.getID()));
}
}
}
}
}
}
return idsInUse;
}
Aggregations