Search in sources :

Example 1 with ArrayListMultiple

use of CCDD.CcddClassesComponent.ArrayListMultiple in project CCDD by nasa.

the class CcddMessageIDHandler method getMessageIDsAndNames.

/**
 ********************************************************************************************
 * Get the list containing every message ID name and its corresponding message ID, and the
 * owning entity from every table cell, data field (table or group), and telemetry message. ID
 * names and IDs are determined by the input data type assigned to the table column or data
 * field, and are matched one-to-one by relative position; i.e., the first message ID name data
 * field for a table or group is paired with the first message ID data field, and so on. If
 * more names are defined than IDs or vice versa then a blank ID/name is paired with the
 * unmatched name/ID
 *
 * @param sortOrder
 *            order in which to sort the message ID list: BY_OWNER or BY_NAME
 *
 * @param hideProtectionFlag
 *            true to not display the flag character that protects a message ID from being
 *            changed by the auto-update methods; false to allow the flag to remain
 *
 * @param parent
 *            GUI component calling this method
 *
 * @return List containing every message ID name and its corresponding message ID, and the
 *         owning entity
 ********************************************************************************************
 */
protected List<String[]> getMessageIDsAndNames(MessageIDSortOrder sortOrder, boolean hideProtectionFlag, Component parent) {
    String id;
    ArrayListMultiple ownersNamesAndIDs = new ArrayListMultiple();
    ArrayListMultiple tableIDNames = new ArrayListMultiple();
    ArrayListMultiple tableIDs = new ArrayListMultiple();
    // Step through each table type
    for (TypeDefinition typeDefn : tableTypeHandler.getTypeDefinitions()) {
        // Step through each column that contains message ID names
        for (int idColumn : typeDefn.getColumnIndicesByInputType(InputDataType.MESSAGE_ID_NAME)) {
            // Query the database for those values in the specified message ID name column that
            // are in use in any table, including any references in the custom values table
            tableIDNames.addAll(dbTable.queryDatabase("SELECT " + "* FROM find_columns_by_name('" + typeDefn.getColumnNamesUser()[idColumn] + "', '" + typeDefn.getColumnNamesDatabase()[idColumn] + "', '{" + typeDefn.getName() + "}');", parent));
        }
        // 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 " + "* FROM find_columns_by_name('" + typeDefn.getColumnNamesUser()[idColumn] + "', '" + typeDefn.getColumnNamesDatabase()[idColumn] + "', '{" + typeDefn.getName() + "}');", parent));
        }
    }
    // Get the list of all message ID name data field values
    tableIDNames.addAll(dbTable.queryDatabase("SELECT " + 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_NAME.getInputName() + "' AND " + InternalTable.FIELDS.getColumnName(FieldsColumn.FIELD_VALUE.ordinal()) + " != '' ORDER BY OID;", parent));
    // Get the list of all message ID data field values
    tableIDs.addAll(dbTable.queryDatabase("SELECT " + 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()) + " != '' ORDER BY OID;", parent));
    // Step through each ID name
    while (tableIDNames.size() > 0) {
        // Get the ID name owner and ID name from the first list member, then remove it from
        // the ID name list
        String idOwner = tableIDNames.get(0)[0];
        String idName = tableIDNames.get(0)[1];
        tableIDNames.remove(0);
        // Get the index in the ID list of the first member with the same owner
        int index = tableIDs.indexOf(idOwner);
        // Check if a matching owner is found
        if (index != -1) {
            // Get the ID with the matching owner and remove it from the ID list
            id = hideProtectionFlag ? removeProtectionFlag(tableIDs.get(index)[1]) : tableIDs.get(index)[1];
            tableIDs.remove(index);
        } else // No matching owner exists
        {
            // Set the ID to the default (a blank)
            id = "";
        }
        // Add the owner, ID name, and ID to the list
        ownersNamesAndIDs.add(new String[] { idOwner, idName, id });
    }
    // name
    while (tableIDs.size() > 0) {
        // Get the ID owner and ID from the first list member, then remove it from the ID list
        String idOwner = tableIDs.get(0)[0];
        id = hideProtectionFlag ? removeProtectionFlag(tableIDs.get(0)[1]) : tableIDs.get(0)[1];
        tableIDs.remove(0);
        // Add the owner, default ID name (a blank), and ID to the list
        ownersNamesAndIDs.add(new String[] { idOwner, "", id });
    }
    // Get the telemetry rates, message ID names, and IDs assigned in the telemetry scheduler
    // table. This query returns only those the message names with the sub-message index
    // appended, so for parent messages without any sub-messages this retrieves the 'default'
    // sub-message name
    ArrayListMultiple tlmMsgs = new ArrayListMultiple(1);
    tlmMsgs.addAll(dbTable.queryDatabase("SELECT DISTINCT ON (3,2) 'Tlm:' || " + InternalTable.TLM_SCHEDULER.getColumnName(TlmSchedulerColumn.RATE_NAME.ordinal()) + ", regexp_replace(" + InternalTable.TLM_SCHEDULER.getColumnName(TlmSchedulerColumn.MESSAGE_NAME.ordinal()) + ", E'\\\\.', '_'), " + InternalTable.TLM_SCHEDULER.getColumnName(TlmSchedulerColumn.MESSAGE_ID.ordinal()) + " FROM " + InternalTable.TLM_SCHEDULER.getTableName() + " WHERE " + InternalTable.TLM_SCHEDULER.getColumnName(TlmSchedulerColumn.MESSAGE_NAME.ordinal()) + " ~ E'\\\\.';", parent));
    // Step through each of the telemetry messages retrieved
    for (String[] tlmMsg : tlmMsgs) {
        // Check if this message has the default sub-message name
        if (tlmMsg[1].endsWith("_0")) {
            // Get the parent message name
            String parentMsg = tlmMsg[1].substring(0, tlmMsg[1].length() - 2);
            // indicates that the parent has no 'real' sub-messages
            if (!tlmMsgs.contains(parentMsg + "_1")) {
                // Store the parent message name in place of the default sub-message name
                tlmMsg[1] = parentMsg;
            }
        }
    }
    // Add the processed telemetry message to the list
    ownersNamesAndIDs.addAll(tlmMsgs);
    // Sort the message ID list in the order specified
    switch(sortOrder) {
        case BY_OWNER:
            // Sort the message ID list by owner
            ownersNamesAndIDs.setComparisonColumn(MsgIDListColumnIndex.OWNER.ordinal());
            ownersNamesAndIDs.sort(ArrayListMultipleSortType.STRING);
            break;
        case BY_NAME:
            // Sort the message ID list by ID name
            ownersNamesAndIDs.setComparisonColumn(MsgIDListColumnIndex.MESSAGE_ID_NAME.ordinal());
            ownersNamesAndIDs.sort(ArrayListMultipleSortType.STRING);
            break;
    }
    return ownersNamesAndIDs;
}
Also used : ArrayListMultiple(CCDD.CcddClassesComponent.ArrayListMultiple) TypeDefinition(CCDD.CcddTableTypeHandler.TypeDefinition)

Example 2 with ArrayListMultiple

use of CCDD.CcddClassesComponent.ArrayListMultiple in project CCDD by nasa.

the class CcddLinkManagerHandler method getInvalidatedLinkMembers.

/**
 ********************************************************************************************
 * Get a list of link member variables that are no longer valid for the telemetry scheduler
 * table due to the addition of one or more new member variables. If a telemetry message
 * references a linked variable, and a new variable is added to the link definition, then the
 * message no longer references all of the variables that are linked. Since the additional
 * variable(s) may not fit within the message's maximum size, all of the variable in the link
 * are removed from the message(s). The user must add the linked variables back to the messages
 * using the telemetry scheduler
 *
 * @return List of link member variables that are no longer valid for the telemetry scheduler
 *         table due to the addition of one or more new member variables; and empty list if no
 *         links are invalid
 ********************************************************************************************
 */
protected List<String> getInvalidatedLinkMembers() {
    List<String> checkedLinks = new ArrayList<String>();
    List<String> invalidatedLinks = new ArrayList<String>();
    CcddLinkHandler oldLinkHndlr = new CcddLinkHandler(ccddMain, committedLinks);
    CcddLinkHandler newLinkHndlr = linkTree.getLinkHandler();
    // Step through each link by name
    for (String linkName : oldLinkHndlr.getLinkNamesByRate(rateName)) {
        // pass when a variable is transferred from one link to another
        if (!checkedLinks.contains(linkName)) {
            boolean isLinkInvalid = false;
            // Add the link to the list of those checked so that is isn't checked again
            checkedLinks.add(linkName);
            // Get the link definitions for this link name
            ArrayListMultiple oldDefns = new ArrayListMultiple(LinksColumn.MEMBER.ordinal());
            oldDefns.addAll(oldLinkHndlr.getLinkDefinitionsByName(linkName, rateName));
            // Check if the link had any variables assigned to it
            if (!oldDefns.isEmpty()) {
                // Get the name of the link to which the variable now belongs (this may be
                // another link)
                String newLinkName = newLinkHndlr.getVariableLink(oldDefns.get(0)[LinksColumn.MEMBER.ordinal()], rateName);
                // Check if the variable is still a member of a link
                if (newLinkName != null) {
                    // processed (e.g., the variable is not within the original link)
                    if (!checkedLinks.contains(newLinkName)) {
                        // Add the link to the list of those checked so that is isn't checked
                        // again
                        checkedLinks.add(newLinkName);
                    }
                    // Get the link definitions of the link for which the variable is currently
                    // a member
                    List<String[]> newDefns = newLinkHndlr.getLinkDefinitionsByName(newLinkName, rateName);
                    // members than before
                    if (newDefns.size() <= oldDefns.size()) {
                        // Step through each of the link's original definitions
                        for (String[] newDefn : newDefns) {
                            // all of the same members it had before
                            if (!oldDefns.contains(newDefn[LinksColumn.MEMBER.ordinal()])) {
                                // Set the flag to indicate the link has new members and stop
                                // searching
                                isLinkInvalid = true;
                                break;
                            }
                        }
                    } else // The link containing the variable has more members than before
                    {
                        // Set the flag to indicate the link has new members
                        isLinkInvalid = true;
                    }
                    // Check if the link has new members
                    if (isLinkInvalid) {
                        // Step through the new link definitions
                        for (String[] newDefn : newDefns) {
                            // Add the variable to the invalidated links list
                            invalidatedLinks.add(newDefn[LinksColumn.MEMBER.ordinal()]);
                        }
                    }
                }
            }
        }
    }
    return invalidatedLinks;
}
Also used : ArrayListMultiple(CCDD.CcddClassesComponent.ArrayListMultiple) ArrayList(java.util.ArrayList)

Example 3 with ArrayListMultiple

use of CCDD.CcddClassesComponent.ArrayListMultiple in project CCDD by nasa.

the class CcddScriptHandler method getScriptAssociationData.

/**
 ********************************************************************************************
 * Retrieve the script associations stored in the database and from these build the array for
 * display and selection of the script associations
 *
 * @param allowSelectDisabled
 *            true if disabled associations can be selected; false if not. In the script
 *            manager disabled associations are selectable so that these can be deleted if
 *            desired. Scripts that are selected and disabled are ignored when executing
 *            scripts
 *
 * @param parent
 *            GUI component calling this method
 *
 * @return Object array containing the script associations
 ********************************************************************************************
 */
private Object[][] getScriptAssociationData(boolean allowSelectDisabled, Component parent) {
    List<Object[]> associationsData = new ArrayList<Object[]>();
    // Read the stored script associations from the database
    List<String[]> committedAssociations = dbTable.retrieveInformationTable(InternalTable.ASSOCIATIONS, parent);
    // Get the list of table names and their associated table type
    ArrayListMultiple protoNamesAndTableTypes = new ArrayListMultiple();
    protoNamesAndTableTypes.addAll(dbTable.queryTableAndTypeList(parent));
    // Load the group information from the database
    CcddGroupHandler groupHandler = new CcddGroupHandler(ccddMain, null, parent);
    // Create a list to contain the variables (dataType.variableName) that have been verified
    // to exist. This reduces the number of database transactions in the event the same
    // variable is used in multiple associations
    List<String> verifiedVars = new ArrayList<String>();
    // Step through each script association
    for (String[] assn : committedAssociations) {
        AvailabilityType availableStatus = AvailabilityType.AVAILABLE;
        int numVerifications = 0;
        StringBuilder verifications = new StringBuilder("");
        try {
            // Get the list of association table paths
            List<String> tablePaths = getAssociationTablePaths(assn[AssociationsColumn.MEMBERS.ordinal()].toString(), groupHandler, parent);
            // Check if at least one table is assigned to this script association
            if (!tablePaths.isEmpty()) {
                // Step through each table referenced in this association
                for (String tablePath : tablePaths) {
                    String parentTable = "";
                    // Step through each data type and variable name pair
                    for (String variable : tablePath.split(",")) {
                        // Split the variable reference into the data type and variable name
                        String[] typeAndVar = variable.split(Pattern.quote("."));
                        // Check if the variable hasn't already been verified to exist
                        if (!verifiedVars.contains(variable)) {
                            // Locate the table's prototype in the list
                            int index = protoNamesAndTableTypes.indexOf(typeAndVar[0]);
                            // Check if the prototype table doesn't exist
                            if (index == -1) {
                                throw new CCDDException();
                            }
                            // root table, so there is no variable name)
                            if (typeAndVar.length == 2) {
                                // Get the table's type definition
                                TypeDefinition typeDefn = ccddMain.getTableTypeHandler().getTypeDefinition(protoNamesAndTableTypes.get(index)[2]);
                                // Check if the table doesn't represent a structure
                                if (!typeDefn.isStructure()) {
                                    throw new CCDDException();
                                }
                                // Get the name of the column that represents the variable name
                                String varColumn = typeDefn.getDbColumnNameByInputType(InputDataType.VARIABLE);
                                // Add the command to verify the existence of the variable in
                                // the parent table to the overall verification command for
                                // this association
                                verifications.append("SELECT " + varColumn + " FROM " + parentTable + " WHERE " + varColumn + " = '" + typeAndVar[1] + "' UNION ALL ");
                                numVerifications++;
                                // Add the variable to the list of those verified to exist
                                verifiedVars.add(variable);
                            }
                        }
                        // Store the data type, which is the parent for the next variable (if
                        // any)
                        parentTable = typeAndVar[0];
                    }
                }
                // Check if there are any variables to verify
                if (numVerifications != 0) {
                    // Complete the verification command
                    verifications = CcddUtilities.removeTrailer(verifications, "UNION ALL ").append(";");
                    // Query the tables for the variables to be checked
                    List<String[]> result = dbTable.queryDatabase(verifications.toString(), parent);
                    // were found
                    if (result == null || result.size() != numVerifications) {
                        throw new CCDDException();
                    }
                }
            }
        } catch (CCDDException ce) {
            // The script file or associated table doesn't exist; set the flag to indicate the
            // association isn't available
            availableStatus = AvailabilityType.TABLE_MISSING;
        }
        // Add the association to the script associations list
        associationsData.add(new Object[] { assn[AssociationsColumn.NAME.ordinal()], assn[AssociationsColumn.DESCRIPTION.ordinal()], assn[AssociationsColumn.SCRIPT_FILE.ordinal()], CcddUtilities.highlightDataType(assn[AssociationsColumn.MEMBERS.ordinal()]), availableStatus });
    }
    return associationsData.toArray(new Object[0][0]);
}
Also used : CCDDException(CCDD.CcddClassesDataTable.CCDDException) ArrayListMultiple(CCDD.CcddClassesComponent.ArrayListMultiple) ArrayList(java.util.ArrayList) TypeDefinition(CCDD.CcddTableTypeHandler.TypeDefinition) AvailabilityType(CCDD.CcddConstants.AvailabilityType)

Example 4 with ArrayListMultiple

use of CCDD.CcddClassesComponent.ArrayListMultiple in project CCDD by nasa.

the class CcddRateParameterHandler method getRatesInUse.

/**
 ********************************************************************************************
 * Get the array of the sample rate values for the specified rate column name with those rates
 * not assigned to any telemetry parameter in the structure tables grayed out
 *
 * @param rateName
 *            rate column name
 *
 * @param parent
 *            GUI component calling this method
 *
 * @return Array of the sample rate values for the specified rate column name with those rates
 *         not assigned to any telemetry parameter in the structure tables grayed out; an empty
 *         array if the rate name isn't valid
 ********************************************************************************************
 */
protected String[] getRatesInUse(String rateName, Component parent) {
    String[] availableRates = new String[0];
    // Create the string array list using the second column (rate values) for comparison
    // purposes
    ArrayListMultiple ratesInUse = new ArrayListMultiple(1);
    // Get the rate information for the specified rate
    RateInformation rateInfo = getRateInformationByRateName(rateName);
    // Check if the rate name is recognized
    if (rateInfo != null) {
        // Get a copy of the array of sample rates for this rate. If a copy isn't used then the
        // stored sample rates can be altered to show as disabled below; subsequent calls to
        // get the sample rates will have the disable tags
        availableRates = Arrays.copyOf(rateInfo.getSampleRates(), rateInfo.getSampleRates().length);
        // Query the database for those values of the specified rate that are in use in all
        // tables with a table type representing a structure, including any references in the
        // custom values table. Only unique rate values are returned
        ratesInUse.addAll(dbTable.queryDatabase("SELECT DISTINCT ON (2) * FROM find_columns_by_name('" + rateName + "', '" + DefaultColumn.convertVisibleToDatabase(rateName, InputDataType.RATE, true) + "', '{" + Arrays.toString(tableTypeHandler.getStructureTableTypes()).replaceAll("[\\[\\]]", "") + "}');", parent));
        // Step through the available sample rates
        for (int index = 0; index < availableRates.length; index++) {
            // Check if the rate isn't used by any telemetry parameter
            if (!ratesInUse.contains(availableRates[index])) {
                // Flag the rate as disabled
                availableRates[index] = DISABLED_TEXT_COLOR + availableRates[index];
            }
        }
    }
    return availableRates;
}
Also used : ArrayListMultiple(CCDD.CcddClassesComponent.ArrayListMultiple) RateInformation(CCDD.CcddClassesDataTable.RateInformation)

Example 5 with ArrayListMultiple

use of CCDD.CcddClassesComponent.ArrayListMultiple in project CCDD by nasa.

the class CcddDbTableCommandHandler method getCustomValues.

/**
 ********************************************************************************************
 * Perform the database query to load the rows from the custom values table that match the
 * specified column name and column value
 *
 * @param columnName
 *            name to match in the custom values table 'column name' column
 *
 * @param columnValue
 *            value to match in the custom values table 'value' column; null or blank to match
 *            any value
 *
 * @param parent
 *            GUI component calling this method
 *
 * @return List containing arrays with the row data (table path, column name, and value) from
 *         the custom values table for those rows that match the specified column name and
 *         column value
 ********************************************************************************************
 */
protected List<String[]> getCustomValues(String columnName, String columnValue, Component parent) {
    List<String[]> customValues = new ArrayListMultiple();
    try {
        // Get the row data from the custom values table for all columns with a matching column
        // name and column value
        ResultSet rowData = dbCommand.executeDbQuery("SELECT * FROM " + InternalTable.VALUES.getTableName() + " WHERE " + ValuesColumn.COLUMN_NAME.getColumnName() + " = '" + columnName + "'" + (columnValue == null || columnValue.isEmpty() ? "" : " AND " + ValuesColumn.VALUE.getColumnName() + " = '" + columnValue + "'") + ";", parent);
        // Step through each of the query results
        while (rowData.next()) {
            // Add the row data from the matching row to the array list
            customValues.add(new String[] { rowData.getString(ValuesColumn.TABLE_PATH.getColumnName()), rowData.getString(ValuesColumn.COLUMN_NAME.getColumnName()), rowData.getString(ValuesColumn.VALUE.getColumnName()) });
        }
        rowData.close();
    } catch (SQLException se) {
        // Inform the user that loading the custom values failed
        eventLog.logFailEvent(parent, "Cannot load data from the custom values table; cause '" + se.getMessage() + "'", "<html><b>Cannot load data from the custom values table");
    }
    return customValues;
}
Also used : SQLException(java.sql.SQLException) ArrayListMultiple(CCDD.CcddClassesComponent.ArrayListMultiple) ResultSet(java.sql.ResultSet)

Aggregations

ArrayListMultiple (CCDD.CcddClassesComponent.ArrayListMultiple)14 TypeDefinition (CCDD.CcddTableTypeHandler.TypeDefinition)4 ArrayList (java.util.ArrayList)3 Component (java.awt.Component)2 GridBagConstraints (java.awt.GridBagConstraints)2 GridBagLayout (java.awt.GridBagLayout)2 Insets (java.awt.Insets)2 BoxLayout (javax.swing.BoxLayout)2 JPanel (javax.swing.JPanel)2 JScrollPane (javax.swing.JScrollPane)2 JSONArray (org.json.simple.JSONArray)2 JSONObject (org.json.simple.JSONObject)2 AutoCompleteTextField (CCDD.CcddClassesComponent.AutoCompleteTextField)1 MultilineLabel (CCDD.CcddClassesComponent.MultilineLabel)1 ToolTipTreeNode (CCDD.CcddClassesComponent.ToolTipTreeNode)1 CCDDException (CCDD.CcddClassesDataTable.CCDDException)1 GroupInformation (CCDD.CcddClassesDataTable.GroupInformation)1 RateInformation (CCDD.CcddClassesDataTable.RateInformation)1 TableTypeDefinition (CCDD.CcddClassesDataTable.TableTypeDefinition)1 AvailabilityType (CCDD.CcddConstants.AvailabilityType)1