use of CCDD.CcddConstants.AvailabilityType 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]);
}
Aggregations