Search in sources :

Example 1 with TrainCsvSwitchLists

use of jmri.jmrit.operations.trains.TrainCsvSwitchLists in project JMRI by JMRI.

the class RunSwitchListChangesAction method doAction.

/**
     * Creates a custom switch list for each location that is selected and
     * there's new work for that location.
     * <p>
     * common code see RunSwitchListAction.java
     * @param isChanged if set true only locations with changes will get a custom switch list.
     */
@SuppressFBWarnings(value = { "UC_USELESS_CONDITION", "RpC_REPEATED_CONDITIONAL_TEST" }, justification = "isChanged = false when called from RunSwitchListAction")
protected void doAction(boolean isChanged) {
    if (getAutomationItem() != null) {
        if (!Setup.isGenerateCsvSwitchListEnabled()) {
            log.warn("Generate CSV Switch List isn't enabled!");
            finishAction(false);
            return;
        }
        // we do need one of these!
        if (!TrainCustomSwitchList.instance().excelFileExists()) {
            log.warn("Manifest creator file not found!, directory name: {}, file name: {}", TrainCustomSwitchList.instance().getDirectoryName(), TrainCustomSwitchList.instance().getFileName());
            finishAction(false);
            return;
        }
        setRunning(true);
        TrainSwitchLists trainSwitchLists = new TrainSwitchLists();
        TrainCsvSwitchLists trainCsvSwitchLists = new TrainCsvSwitchLists();
        // this can wait thread
        if (!TrainCustomManifest.instance().checkProcessReady()) {
            log.warn("Timeout waiting for excel manifest program to complete previous operation, timeout value: {} seconds", Control.excelWaitTime);
        }
        // this can wait thread
        if (!TrainCustomSwitchList.instance().checkProcessReady()) {
            log.warn("Timeout waiting for excel switch list program to complete previous operation, timeout value: {} seconds", Control.excelWaitTime);
        }
        if (TrainCustomSwitchList.instance().doesCommonFileExist()) {
            log.warn("Switch List CSV common file exists!");
        }
        for (Location location : LocationManager.instance().getLocationsByNameList()) {
            if (location.isSwitchListEnabled() && (!isChanged || (isChanged && location.getStatus().equals(Location.MODIFIED)))) {
                // also build the regular switch lists so they can be used
                if (!Setup.isSwitchListRealTime()) {
                    trainSwitchLists.buildSwitchList(location);
                }
                File csvFile = trainCsvSwitchLists.buildSwitchList(location);
                if (csvFile == null || !csvFile.exists()) {
                    log.error("CSV switch list file was not created for location {}", location.getName());
                    finishAction(false);
                    return;
                }
                TrainCustomSwitchList.instance().addCVSFile(csvFile);
            }
        }
        // Processes the CSV Manifest files using an external custom program.
        boolean status = TrainCustomSwitchList.instance().process();
        if (status) {
            try {
                // wait up to 60 seconds per file
                status = TrainCustomSwitchList.instance().waitForProcessToComplete();
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } else {
            log.info("No switch list changes found");
        }
        // set trains switch lists printed
        TrainManager.instance().setTrainsSwitchListStatus(Train.PRINTED);
        finishAction(status);
    }
}
Also used : TrainCsvSwitchLists(jmri.jmrit.operations.trains.TrainCsvSwitchLists) TrainSwitchLists(jmri.jmrit.operations.trains.TrainSwitchLists) File(java.io.File) Location(jmri.jmrit.operations.locations.Location) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 File (java.io.File)1 Location (jmri.jmrit.operations.locations.Location)1 TrainCsvSwitchLists (jmri.jmrit.operations.trains.TrainCsvSwitchLists)1 TrainSwitchLists (jmri.jmrit.operations.trains.TrainSwitchLists)1