ArchiveThread.java [tools/CopyArchiveFiles/src/copyarchivefiles] Revision: 881bb2ce49f94beddba0611dc75b3c1f655ce3f8  Date: Tue Dec 17 11:40:32 MST 2019
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package copyarchivefiles;

import archives.MongoArchive;
import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import models.ModelArchive;
import models.WEPSModelArchive.WEPSMetaData;

/**
 *
 * @author <a href="mailto:shaun.case@colostate.edu">Shaun Case</a>
 */
public class ArchiveThread extends Thread {

    protected String suid;
    protected CountDownLatch latch;
    protected String dbLocation;
    protected MongoArchive mongoArchive;
    protected ArrayList<ModelArchive> tArchive;
    protected ModelArchive model;
    protected String errorMessage;

    public ArchiveThread(String _suid, String _dbLocation, CountDownLatch _latch) throws Exception {
        suid = _suid;
        latch = _latch;
        dbLocation = _dbLocation;
        if (dbLocation.contains("mongodb://")) {
            mongoArchive = new MongoArchive(dbLocation);
        }
    }

    @Override
    public void run() {

        try {
            tArchive = mongoArchive.getArchivesByFilter("_id", suid, 1, true);
        } catch (Exception ex) {
            errorMessage += "#\nCannot get that suid, " + suid + ", from the archive:  " + ex.getMessage() + "\n\n" + ex.toString();
        }

        if (tArchive.isEmpty()) {
            errorMessage += "#\nCould not find an archived model in the archive for that suid and mongodb location.";
        } else {

            model = tArchive.get(0);

            try {
                mongoArchive.shutdown();
            } catch (Exception ex) {
                errorMessage += "#\nCould not shutdown mongo archive at: " + dbLocation + "\n\n" + ex.toString();
            }
        }

        if ((null != errorMessage) && !errorMessage.isEmpty()) {
            System.err.println(suid + ": " + errorMessage);
        }
        
        latch.countDown();
    }

}