use of CCDD.CcddClassesDataTable.TableInformation in project CCDD by nasa.
the class CcddScriptDataAccessHandler method getTableNames.
/**
********************************************************************************************
* Get array of all table names referenced in the table data of the specified table type
*
* @param tableType
* table type (case insensitive). All structure table types are combined and are
* referenced by the type name "Structure", and all command table types are combined
* and are referenced by the type name "Command"
*
* @param prototypeOnly
* true to return only the prototype name for any child structures; false to include
* the full path for child structures
*
* @return Array of all table names, with paths for child structure tables excluded based on
* the input flag, represented by the table type; returns an empty array if an instance
* of the table type doesn't exist
********************************************************************************************
*/
public String[] getTableNames(String tableType, boolean prototypeOnly) {
List<String> names = new ArrayList<String>();
// Get the reference to the table information class for the requested table type
TableInformation tableInfo = getTableInformation(tableType);
// Check that there is data for the specified table type
if (tableInfo != null && tableInfo.getData().length != 0) {
// Step through each row in the table
for (int row = 0; row < tableInfo.getData().length; row++) {
// Calculate the column index for the table path
int pathColumn = tableInfo.getData()[row].length - PATH_COLUMN_DELTA;
// Get the table's prototype name from the path
String tableName = tableInfo.getData()[row][pathColumn];
// Check if only prototype names should be returned for child structures
if (prototypeOnly) {
// Get the prototype name form the table name
tableName = TableInformation.getPrototypeName(tableName);
}
// Check if the table name hasn't been added to the list
if (!names.contains(tableName)) {
// Store the table name
names.add(tableName);
}
}
}
return names.toArray(new String[0]);
}
use of CCDD.CcddClassesDataTable.TableInformation 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.CcddClassesDataTable.TableInformation in project CCDD by nasa.
the class CcddXTCEHandler method buildSpaceSystems.
/**
********************************************************************************************
* Build the space systems
*
* @param node
* current tree node
*
* @param variableHandler
* variable handler class reference; null if includeVariablePaths is false
*
* @param separators
* string array containing the variable path separator character(s), show/hide data
* types flag ('true' or 'false'), and data type/variable name separator
* character(s); null if includeVariablePaths is false
********************************************************************************************
*/
private void buildSpaceSystems(String[] tableNames, CcddVariableSizeAndConversionHandler variableHandler, String[] separators) {
List<StructureMemberList> memberLists = new ArrayList<StructureMemberList>();
// Step through each table name
for (String tableName : tableNames) {
// Check if this is a child (instance) table
if (!TableInformation.isPrototype(tableName)) {
// TODO THIS NEEDS TO CHANGE SO THAT INSTANCE VALUES CAN BE USED
// Get the prototype of the instance table. Only prototypes of the tables are
// used to create the space systems
tableName = TableInformation.getPrototypeName(tableName);
// created
if (getSpaceSystemByName(tableName, project.getValue()) != null) {
// Skip this table since it's space system has already been created
continue;
}
}
// Get the information from the database for the specified table
TableInformation tableInfo = dbTable.loadTableData(tableName, true, false, true, parent);
// Check if the table's data successfully loaded
if (!tableInfo.isErrorFlag()) {
// TODO IF RATE INFORMATION GETS USED THEN THE PROTOTYPE DATA IS REQUIRED. SEPARATE
// SPACE SYSTEMS FOR EACH INSTANCE MAY THEN BE NEEDED. THE SAME ISSUE APPLIES TO
// OTHER INSTANCE VALUES (E.G., MIN & MAX) - CAN'T REFERENCE THE PROTOTYPE TO GET
// THIS INFORMATION; INSTEAD NEED A SPACE SYSTEM FOR THE INSTANCE
// Get the table type and from the type get the type definition. The type
// definition can be a global parameter since if the table represents a structure,
// then all of its children are also structures, and if the table represents
// commands or other table type then it is processed within this nest level
typeDefn = tableTypeHandler.getTypeDefinition(tableInfo.getType());
// Check if the table type represents a structure or command
if (typeDefn != null && (typeDefn.isStructure() || typeDefn.isCommand())) {
// Replace all macro names with their corresponding values
tableInfo.setData(macroHandler.replaceAllMacros(tableInfo.getData()));
// Get the application ID data field value, if present
String applicationID = fieldHandler.getFieldValue(tableName, InputDataType.MESSAGE_ID);
// Get the name of the system to which this table belongs from the table's
// system path data field (if present)
String systemPath = fieldHandler.getFieldValue(tableName, InputDataType.SYSTEM_PATH);
// Initialize the parent system to be the root (top-level) system
SpaceSystemType parentSystem = project.getValue();
// Check if a system path exists
if (systemPath != null) {
// Step through each system name in the path
for (String systemName : systemPath.split("\\s*/\\s*")) {
// if present)
if (!systemName.isEmpty()) {
// Search the existing space systems for one with this system's
// name (if none exists then use the root system's name)
SpaceSystemType existingSystem = getSpaceSystemByName(systemName, parentSystem);
// Set the parent system to the existing system if found, else
// create a new space system using the name from the table's system
// path data field
parentSystem = existingSystem == null ? addSpaceSystem(parentSystem, systemName, null, classification2Attr, validationStatusAttr, versionAttr) : existingSystem;
}
}
}
// Add the space system
parentSystem = addSpaceSystem(parentSystem, tableName, tableInfo.getDescription(), classification3Attr, validationStatusAttr, versionAttr);
// Check if this is a structure table
if (typeDefn.isStructure()) {
MemberList memberList = factory.createAggregateDataTypeMemberList();
// Get the default column indices
int varColumn = typeDefn.getColumnIndexByInputType(InputDataType.VARIABLE);
int typeColumn = typeDefn.getColumnIndexByInputType(InputDataType.PRIM_AND_STRUCT);
int sizeColumn = typeDefn.getColumnIndexByInputType(InputDataType.ARRAY_INDEX);
int bitColumn = typeDefn.getColumnIndexByInputType(InputDataType.BIT_LENGTH);
int enumColumn = typeDefn.getColumnIndexByInputType(InputDataType.ENUMERATION);
int descColumn = typeDefn.getColumnIndexByInputType(InputDataType.DESCRIPTION);
int unitsColumn = typeDefn.getColumnIndexByInputType(InputDataType.UNITS);
int minColumn = typeDefn.getColumnIndexByInputType(InputDataType.MINIMUM);
int maxColumn = typeDefn.getColumnIndexByInputType(InputDataType.MAXIMUM);
// Set the flag to indicate if this is the telemetry header table
boolean isTlmHeaderTable = tableName.equals(tlmHeaderTable);
// Check if this is the telemetry header table
if (isTlmHeaderTable) {
// Store the telemetry header's path
tlmHeaderPath = systemPath;
}
// Export the parameter container for this structure
addParameterContainer(parentSystem, tableInfo, varColumn, typeColumn, sizeColumn, isTlmHeaderTable, applicationID);
// Step through each row in the structure table
for (String[] rowData : tableInfo.getData()) {
// used to define the array)
if (!ArrayVariable.isArrayMember(rowData[varColumn])) {
// Add the variable to the space system
addParameter(parentSystem, rowData[varColumn], rowData[typeColumn], rowData[sizeColumn], rowData[bitColumn], (enumColumn != -1 && !rowData[enumColumn].isEmpty() ? rowData[enumColumn] : null), (unitsColumn != -1 && !rowData[unitsColumn].isEmpty() ? rowData[unitsColumn] : null), (minColumn != -1 && !rowData[minColumn].isEmpty() ? rowData[minColumn] : null), (maxColumn != -1 && !rowData[maxColumn].isEmpty() ? rowData[maxColumn] : null), (descColumn != -1 && !rowData[descColumn].isEmpty() ? rowData[descColumn] : null), (dataTypeHandler.isString(rowData[typeColumn]) && !rowData[sizeColumn].isEmpty() ? Integer.valueOf(rowData[sizeColumn].replaceAll("^.*(\\d+)$", "$1")) : 1));
// Use the variable name to create an aggregate list member and add
// it to the member list. The list is used if this structure is
// referenced as a data type in another structure
Member member = new Member();
member.setName(rowData[varColumn]);
member.setTypeRef("/" + project.getValue().getName() + (systemPath == null || systemPath.isEmpty() ? "" : "/" + systemPath) + "/" + tableName + "/" + getNameByDataType(rowData[varColumn], rowData[typeColumn]) + TYPE);
memberList.getMember().add(member);
}
}
// Check if any variables exists in the structure table
if (!memberList.getMember().isEmpty()) {
// Create a structure member list using the table's aggregate member
// list
memberLists.add(new StructureMemberList(tableName, memberList));
}
} else // This is a command table
{
// Get the list containing the associated column indices for each argument
// grouping
commandArguments = typeDefn.getAssociatedCommandArgumentColumns(false);
// Set the flag to indicate if this is the command header table
boolean isCmdHeaderTable = tableName.equals(cmdHeaderTable);
// Check if this is the command header table
if (isCmdHeaderTable) {
// Store the command header's path
cmdHeaderPath = systemPath;
}
// Add the command(s) from this table to the parent system
addSpaceSystemCommands(parentSystem, tableInfo, tableName.equals(cmdHeaderTable), applicationID);
}
}
}
}
// Step through each table name
for (String tableName : tableNames) {
// Get the prototype for the child
tableName = TableInformation.getPrototypeName(tableName);
// Get the space system for this table
SpaceSystemType spaceSystem = getSpaceSystemByName(tableName, project.getValue());
// Check if the system was found and it has telemetry data
if (spaceSystem != null && spaceSystem.getTelemetryMetaData() != null) {
// Step through each parameter type
for (NameDescriptionType type : spaceSystem.getTelemetryMetaData().getParameterTypeSet().getStringParameterTypeOrEnumeratedParameterTypeOrIntegerParameterType()) {
// Check if the type is an aggregate (i.e., a structure reference)
if (type instanceof AggregateDataType) {
// Remove the trailing text added to the table name that flags it as a type
// or array
String typeName = type.getName().substring(0, type.getName().lastIndexOf("_"));
// Step through each structure member list
for (StructureMemberList structMemList : memberLists) {
// Check if the aggregate refers to this structure
if (typeName.equals(structMemList.structureName)) {
// Set the aggregate's member list to this structure member list
// and stop searching
((AggregateDataType) type).setMemberList(structMemList.memberList);
break;
}
}
}
}
}
}
}
Aggregations