Search in sources :

Example 36 with CCDDException

use of CCDD.CcddClassesDataTable.CCDDException 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();
}
Also used : GroupInformation(CCDD.CcddClassesDataTable.GroupInformation) CCDDException(CCDD.CcddClassesDataTable.CCDDException) JSONArray(org.json.simple.JSONArray) ArrayList(java.util.ArrayList) TypeDefinition(CCDD.CcddTableTypeHandler.TypeDefinition) JSONObject(org.json.simple.JSONObject) TableInformation(CCDD.CcddClassesDataTable.TableInformation)

Example 37 with CCDDException

use of CCDD.CcddClassesDataTable.CCDDException in project CCDD by nasa.

the class CcddWebDataAccessHandler method getTableFields.

/**
 ********************************************************************************************
 * Get the data field information for the specified table, or for all tables if no table name
 * is provided
 *
 * @param tableName
 *            table name and path in the format rootTable[,dataType1.variable1[,...]]. If blank
 *            then every data table's data fields are returned
 *
 * @param checkExists
 *            true to check if the specified table exists in the project database
 *
 * @return JSON encoded string containing the specified table's data fields; null if the table
 *         doesn't exist or if the project database contains no data tables
 *
 * @throws CCDDException
 *             If an error occurs while parsing the table data field data
 ********************************************************************************************
 */
@SuppressWarnings("unchecked")
private String getTableFields(String tableName, boolean checkExists) throws CCDDException {
    String response = null;
    // Check if no table name is provided (i.e., get all tables' fields)
    if (tableName.isEmpty()) {
        // Check if at least one table exists
        if (dbTable.queryTableList(ccddMain.getMainFrame()).length != 0) {
            List<String> tableNames = new ArrayList<String>();
            // Step through the data fields
            for (FieldInformation fieldInfo : fieldHandler.getFieldInformation()) {
                // table type or group data field
                if (!tableNames.contains(fieldInfo.getOwnerName()) && !fieldInfo.getOwnerName().startsWith(TYPE_DATA_FIELD_IDENT) && !fieldInfo.getOwnerName().startsWith(GROUP_DATA_FIELD_IDENT)) {
                    // Store the table name in the list
                    tableNames.add(fieldInfo.getOwnerName());
                }
            }
            JSONArray responseJA = new JSONArray();
            JSONParser parser = new JSONParser();
            response = "";
            // Step through the list of tables with data fields
            for (String name : tableNames) {
                try {
                    // Get the fields for this table as a JSON string, then format it as a JSON
                    // object so that is can be added to the response array. This is needed to
                    // get the brackets and commas in the JSON formatted string correct
                    responseJA.add(parser.parse(getTableFields(name, false)));
                } catch (ParseException pe) {
                    throw new CCDDException("error parsing table data fields");
                }
            }
            // Add the table fields to the response
            response = responseJA.toString();
        }
    } else // table exists in the database
    if (!checkExists || dbTable.isTableExists(tableName, ccddMain.getMainFrame())) {
        // Add the table name and data field information to the output
        JSONObject tableNameAndFields = new JSONObject();
        tableNameAndFields.put(JSONTags.TABLE_NAME.getTag(), tableName);
        tableNameAndFields = jsonHandler.getDataFields(tableName, JSONTags.TABLE_FIELD.getTag(), tableNameAndFields);
        response = tableNameAndFields.toString();
    }
    return response;
}
Also used : CCDDException(CCDD.CcddClassesDataTable.CCDDException) JSONObject(org.json.simple.JSONObject) ArrayList(java.util.ArrayList) JSONArray(org.json.simple.JSONArray) JSONParser(org.json.simple.parser.JSONParser) ParseException(org.json.simple.parser.ParseException) FieldInformation(CCDD.CcddClassesDataTable.FieldInformation)

Example 38 with CCDDException

use of CCDD.CcddClassesDataTable.CCDDException in project CCDD by nasa.

the class CcddWebDataAccessHandler method getGroupTables.

/**
 ********************************************************************************************
 * Get the tables associated with the specified group or application, or for all
 * groups/applications if no group name is provided
 *
 * @param groupName
 *            group name. If blank then every group's (application's) descriptions are returned
 *
 * @param applicationOnly
 *            true if only groups that represent applications should be processed
 *
 * @param includeNameTag
 *            true to include the group name item
 *
 * @param groupHandler
 *            group handler
 *
 * @return JSON encoded string containing the specified group's (application's) table members;
 *         null if the specified group/application doesn't exist or the project has no
 *         groups/applications, or blank if the specified group/application has no table member
 *         or if all groups/applications are requested but none have a table member
 *
 * @throws CCDDException
 *             If an error occurs while parsing the group tables
 ********************************************************************************************
 */
@SuppressWarnings("unchecked")
private String getGroupTables(String groupName, boolean applicationOnly, boolean includeNameTag, CcddGroupHandler groupHandler) throws CCDDException {
    String response = null;
    // Check if no group name is provided (i.e., get the fields for all groups/applications)
    if (groupName.isEmpty()) {
        JSONArray responseJA = new JSONArray();
        JSONParser parser = new JSONParser();
        // Get an array containing all group/application names
        String[] groupNames = groupHandler.getGroupNames(applicationOnly);
        // Check if any groups/applications exist
        if (groupNames.length != 0) {
            // Step through each group/application name
            for (String name : groupNames) {
                try {
                    // Get the data for this group as a JSON string, then format it as a JSON
                    // object so that is can be added to the response array. This is needed to
                    // get the brackets and commas in the JSON formatted string correct
                    responseJA.add(parser.parse(getGroupTables(name, applicationOnly, true, groupHandler)));
                } catch (ParseException pe) {
                    throw new CCDDException("error parsing " + (applicationOnly ? "application" : "group") + " tables");
                }
            }
            // Convert the response array to a JSON string
            response = responseJA.toString();
        }
    } else // A group name is provided
    {
        // Get the group information for the specified group
        GroupInformation groupInfo = groupHandler.getGroupInformationByName(groupName);
        // application is requested and this group represents an application
        if (groupInfo != null && (!applicationOnly || groupInfo.isApplication())) {
            JSONArray dataJA = new JSONArray();
            // Get the list of the group's tables
            List<String> tables = groupInfo.getTablesAndAncestors();
            // Step through each table
            for (String table : tables) {
                // Add the table to the array
                dataJA.add(table);
            }
            // Add the group name and description to the list. An array is used to preserve the
            // order of the items
            JSONObject groupNameAndTable;
            // Add the group tables. If the group has no tables then the table data is blank
            groupNameAndTable = new JSONObject();
            // Check if the group name is to be included
            if (includeNameTag) {
                // Add the group name and tables to the output
                groupNameAndTable.put((applicationOnly ? JSONTags.APPLICATION_NAME.getTag() : JSONTags.GROUP_NAME.getTag()), groupName);
                groupNameAndTable.put((applicationOnly ? JSONTags.APPLICATION_TABLE.getTag() : JSONTags.GROUP_TABLE.getTag()), dataJA);
                response = groupNameAndTable.toString();
            } else // Don't include the name and table tags
            {
                // Add the tables to the output
                response = dataJA.toString();
            }
        }
    }
    return response;
}
Also used : CCDDException(CCDD.CcddClassesDataTable.CCDDException) GroupInformation(CCDD.CcddClassesDataTable.GroupInformation) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) JSONParser(org.json.simple.parser.JSONParser) ParseException(org.json.simple.parser.ParseException)

Example 39 with CCDDException

use of CCDD.CcddClassesDataTable.CCDDException in project CCDD by nasa.

the class CcddWebDataAccessHandler method getGroupDescription.

/**
 ********************************************************************************************
 * Get the description for the specified group or application, or all groups/applications with
 * a description if no group name is provided
 *
 * @param groupName
 *            group name. If blank then every group's (application's) descriptions are returned
 *
 * @param applicationOnly
 *            true if only groups that represent applications should be processed
 *
 * @param groupHandler
 *            group handler
 *
 * @return JSON encoded string containing the specified group's (application's) description;
 *         null if the specified group/application doesn't exist or the project has no
 *         groups/applications, or blank if the specified group/application has no description
 *         or if all groups/applications are requested but none have a description
 *
 * @throws CCDDException
 *             If an error occurs while parsing the group description
 ********************************************************************************************
 */
@SuppressWarnings("unchecked")
private String getGroupDescription(String groupName, boolean applicationOnly, boolean includeNameTag, CcddGroupHandler groupHandler) throws CCDDException {
    String response = null;
    // Check if no group name is provided (i.e., get the fields for all groups/applications)
    if (groupName.isEmpty()) {
        // Get an array containing all group/application names
        String[] groupNames = groupHandler.getGroupNames(applicationOnly);
        // Check if any groups/applications exist
        if (groupNames.length != 0) {
            JSONArray responseJA = new JSONArray();
            JSONParser parser = new JSONParser();
            response = "";
            // Step through each group/application name
            for (String name : groupNames) {
                try {
                    // Get the description for this group as a JSON string, then format it as a
                    // JSON object so that is can be added to the response array. This is
                    // needed to get the brackets and commas in the JSON formatted string
                    // correct
                    responseJA.add(parser.parse(getGroupDescription(name, applicationOnly, true, groupHandler)));
                } catch (ParseException pe) {
                    throw new CCDDException("error parsing " + (applicationOnly ? "application" : "group") + " description");
                }
            }
            // Convert the response array to a JSON string
            response = responseJA.toString();
        }
    } else // A group name is provided
    {
        // Get the group information for the specified group
        GroupInformation groupInfo = groupHandler.getGroupInformationByName(groupName);
        // application is requested and this group represents an application
        if (groupInfo != null && (!applicationOnly || groupInfo.isApplication())) {
            JSONObject groupNameAndDesc = new JSONObject();
            // Check if the group name is to be included
            if (includeNameTag) {
                // Add the group name and description to the output
                groupNameAndDesc.put((applicationOnly ? JSONTags.APPLICATION_NAME.getTag() : JSONTags.GROUP_NAME.getTag()), groupName);
                groupNameAndDesc.put((applicationOnly ? JSONTags.APPLICATION_DESCRIPTION.getTag() : JSONTags.GROUP_DESCRIPTION.getTag()), response);
                response = groupNameAndDesc.toString();
            } else // Don't include the name and description tags
            {
                // Get the description. If no description exists then use a blank
                response = groupInfo.getDescription() != null ? groupInfo.getDescription() : "";
            }
        }
    }
    return response;
}
Also used : CCDDException(CCDD.CcddClassesDataTable.CCDDException) GroupInformation(CCDD.CcddClassesDataTable.GroupInformation) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) JSONParser(org.json.simple.parser.JSONParser) ParseException(org.json.simple.parser.ParseException)

Example 40 with CCDDException

use of CCDD.CcddClassesDataTable.CCDDException in project CCDD by nasa.

the class CcddWebDataAccessHandler method getVariableNames.

/**
 ********************************************************************************************
 * Get the variable names, both in application format and altered based on the user-provided
 * parameters
 *
 * @param variablePath
 *            variable path + name for which to return the converted path; blank to provide the
 *            paths for all variables
 *
 * @param parameters
 *            comma-separated string containing the variable path separator character(s),
 *            show/hide data types flag ('true' or 'false'), and data type/variable name
 *            separator character(s); blank to use the default separators
 *
 * @return JSON encoded string containing the variable names; blank if the project doesn't
 *         contain any variables and null if any input parameter is invalid
 *
 * @throws CCDDException
 *             If an illegal separator character(s) or invalid show/hide data type flag value
 *             is detected
 ********************************************************************************************
 */
@SuppressWarnings("unchecked")
private String getVariableNames(String variablePath, String parameters) throws CCDDException {
    String response = null;
    // Parse the variable path separators
    String[] separators = getVariablePathSeparators(parameters);
    // Check if all the input parameters are present and that they're in the expected formats
    if (separators != null) {
        JSONObject responseJO = new JSONObject();
        response = "";
        // Get the individual parameters and format them if needed
        String varPathSeparator = separators[0];
        boolean hideDataTypes = Boolean.valueOf(separators[1]);
        String typeNameSeparator = separators[2];
        // Check if a variable path is specified
        if (!variablePath.isEmpty()) {
            // Store the variable path and name in the application and user-specified formats
            responseJO.put(variablePath, variableHandler.getFullVariableName(variablePath, varPathSeparator, hideDataTypes, typeNameSeparator));
        } else // Get the conversion for all variables
        {
            // Step through each row in the variables table
            for (int row = 0; row < variableHandler.getAllVariableNames().size(); row++) {
                // Store the variable paths and names in the application and user-specified
                // formats
                responseJO.put(variableHandler.getAllVariableNames().get(row).toString(), variableHandler.getFullVariableName(variableHandler.getAllVariableNames().get(row).toString(), varPathSeparator, hideDataTypes, typeNameSeparator));
            }
        }
        response = responseJO.toString();
    } else // Illegal separator character(s) or invalid show/hide data type flag value
    {
        throw new CCDDException("illegal separator character(s) or invalid show/hide data type flag value");
    }
    return response;
}
Also used : CCDDException(CCDD.CcddClassesDataTable.CCDDException) JSONObject(org.json.simple.JSONObject)

Aggregations

CCDDException (CCDD.CcddClassesDataTable.CCDDException)44 ArrayList (java.util.ArrayList)17 TypeDefinition (CCDD.CcddTableTypeHandler.TypeDefinition)13 JSONObject (org.json.simple.JSONObject)12 FileEnvVar (CCDD.CcddClassesComponent.FileEnvVar)11 JSONArray (org.json.simple.JSONArray)11 JScrollPane (javax.swing.JScrollPane)10 JComponent (javax.swing.JComponent)9 Component (java.awt.Component)8 ParseException (org.json.simple.parser.ParseException)8 IOException (java.io.IOException)7 TableCellRenderer (javax.swing.table.TableCellRenderer)7 JSONParser (org.json.simple.parser.JSONParser)7 GroupInformation (CCDD.CcddClassesDataTable.GroupInformation)6 GridBagConstraints (java.awt.GridBagConstraints)6 GridBagLayout (java.awt.GridBagLayout)6 Insets (java.awt.Insets)6 JPanel (javax.swing.JPanel)6 TableDefinition (CCDD.CcddClassesDataTable.TableDefinition)5 TableInformation (CCDD.CcddClassesDataTable.TableInformation)5