Commit 1e54977a authored by Summer Stapleton's avatar Summer Stapleton Committed by Makayla Shepherd
Browse files

Cleaned up the code, cleaned up the directories and added documentation to spiceinit.xml

parent 5a7c026f
Loading
Loading
Loading
Loading
+7 −10
Original line number Diff line number Diff line
@@ -153,13 +153,8 @@ namespace Isis {
        throw IException(IException::Unknown, p_response->value("Error").toString(), _FILEINFO_);
      }

      QFile finalOutput("output.txt");
      finalOutput.open(QIODevice::WriteOnly);
      finalOutput.write( doc.toJson() );
      finalOutput.close();

      // Make sure we can get the log out of it before continuing
      // applicationLog();
      applicationLog();
    }
    catch(IException &) {
      p_error = new QString();
@@ -516,13 +511,15 @@ namespace Isis {
    QString value = p_response->value(jsonName).toString();
    QByteArray decoded = QByteArray::fromHex(value.toUtf8().constData());

    QFile finalOutput(tableName + ".txt");
    finalOutput.open(QIODevice::WriteOnly);
    finalOutput.write(decoded);
    finalOutput.close();
    QFile tableOutput(tableName + ".txt");
    tableOutput.open(QIODevice::WriteOnly);
    tableOutput.write(decoded);
    tableOutput.close();

    Table *table = new Table(tableName,tableName + ".txt");
    
    tableOutput.remove();

    return table;
  }
};
+39 −9
Original line number Diff line number Diff line
@@ -286,6 +286,10 @@
      Updated spiceinit to remove code dealing with the CubeSupported Pvl Keyword, from the ShapeModel group in the IsisPreferences file, 
      which has been removed.
    </change>
    <change name="Summer Stapleton" date="2018-01-12">
      Added information into the "WEB" parameter description of the new JSON format for server 
      communication.
    </change>
  </history>

  <oldName>
@@ -318,15 +322,41 @@
          Use the ISIS SPICE Web Service
        </brief>
        <description>
          <p>
            This option uses the ISIS SPICE Website to get the most up to
            date kernels available. The ATTACH parameter must be enabled for this option. Manually
            specifying kernel files is not allowed when this option is used. This service may
          be temporarily unavailable when new Isis releases are being
          distributed. Any mismatch in Isis version will cause this option to fail; only
          the most recent version of ISIS is supported. An active internet
          connection is required to use this service. Running with this option is slower than downloading the SPICE data locally (download all of $ISIS3DATA) and running spiceinit
          with the local data. This data can take up a lot of space. The size of the download
          will depend heavily on the mission and instrument of your input file.
            be temporarily unavailable when new Isis releases are being distributed. An active 
            internet connection is required to use this service. Running with this option is slower 
            than downloading the SPICE data locally (downloading all of $ISIS3DATA) and running 
            spiceinit with the local data. This data can take up a lot of space, however.
          </p>
          <p> 
            All requests to and responses from the server are implemented using JSON (JavaScript 
            Object Notation) format. For more information on JSON formatting, visit 
            <a href="https://www.json.org/">json.org</a>. An example of a simple request is as follows:
          </p>
          <pre>
            
            {
              "cknadir": false,
              "ckpredicted": false,
              "ckrecon": true,
              "cksmithed": false,
              "endPad": 0,
              "label": &lt;cube label&gt;,
              "shape": "system",
              "spkpredicted": false,
              "spkrecon": true,
              "spksmithed": false,
              "startPad": 0
            }
          
          </pre>
          <p>
            The size of the response download will depend heavily on the mission and instrument of 
            your input file.
          </p>
        </description>
        <exclusions>
          <item>ATTACH</item>
+17 −71
Original line number Diff line number Diff line
@@ -51,7 +51,6 @@ double g_endPad = 0.0;
QString g_shapeKernelStr;



RequestHandler::RequestHandler(QObject* parent)
    :HttpRequestHandler(parent)
{
@@ -81,8 +80,6 @@ void RequestHandler::service(HttpRequest& request, HttpResponse& response)
    //! Read the spiceinit parameters
    void parseParameters(QJsonObject jsonObject);

    //! Convert a table into an xml tag
    QString tableToXml(QString tableName, QString file);
    QByteArray spiceResponse;
    QByteArray path=request.getPath();
    qDebug("Conroller: path=%s",path.data());
@@ -111,8 +108,6 @@ void RequestHandler::service(HttpRequest& request, HttpResponse& response)
        QString otherVersion;

        if ( !hexCode.isEmpty() ) {


          // Parse the Json with Qt's JSON parser
          QJsonDocument document;
          QString error;
@@ -120,11 +115,6 @@ void RequestHandler::service(HttpRequest& request, HttpResponse& response)
          document = QJsonDocument::fromJson(hexCode);
          QJsonObject jsonObject = document.object();

          QFile finalOutput("output.txt");
          finalOutput.open(QIODevice::WriteOnly);
          finalOutput.write( document.toJson() );
          finalOutput.close();

          parseParameters(jsonObject);

          // Get the cube label
@@ -147,10 +137,10 @@ void RequestHandler::service(HttpRequest& request, HttpResponse& response)
        // Get the directory where the system missions translation table is.
        QString transFile = p.MissionData("base", "translations/MissionName2DataDir.trn");


        // Get the mission translation manager ready
        PvlToPvlTranslationManager missionXlater(label, transFile);
        //label.write("label_after_PvlToPvlTranslationManager.txt");
        label.write("label_after_PvlToPvlTranslationManager.txt");

        // Get the mission name so we can search the correct DB's for kernels
        QString mission = missionXlater.Translate("MissionName");

@@ -185,10 +175,7 @@ void RequestHandler::service(HttpRequest& request, HttpResponse& response)
        ck        = ckKernels.spacecraftPointing(label);
        spk       = spkKernels.spacecraftPosition(label);


        if (g_ckNadir) {


          // Only add nadir if no spacecraft pointing found
          QStringList nadirCk;
          nadirCk.push_back("Nadir");
@@ -198,7 +185,6 @@ void RequestHandler::service(HttpRequest& request, HttpResponse& response)
          }
          // if no queue exists, create a nadir queue
          else {

            priority_queue<Kernel> nadirQueue;
            nadirQueue.push( Kernel( (Kernel::Type)0, nadirCk ) );
            ck.push_back(nadirQueue);
@@ -207,39 +193,30 @@ void RequestHandler::service(HttpRequest& request, HttpResponse& response)

        // Get shape kernel
        if (g_shapeKernelStr == "system") {

          dem = baseKernels.dem(label);


        }


        else if (g_shapeKernelStr != "ellipsoid") {
          stringstream demPvlKeyStream;
          demPvlKeyStream << "ShapeModel = " + g_shapeKernelStr;
          PvlKeyword key;
          demPvlKeyStream >> key;


          for (int value = 0; value < key.size(); value++) {
            dem.push_back(key[value]);
          }

        }


        bool kernelSuccess = false;

        if (ck.size() == 0 || ck.at(0).size() == 0) {
//          throw IException(IException::Unknown,
//                           "No Camera Kernel found for the image [" +
//                            ui.GetFileName("FROM") + "]",
//                           _FILEINFO_);
         throw IException(IException::Unknown,
                          "No Camera Kernel found for the image.",
                          _FILEINFO_);
        }

        FileName inputLabels;


        while (ck.at(0).size() != 0 && !kernelSuccess) {
          // create an empty kernel
          Kernel realCkKernel;
@@ -298,31 +275,17 @@ void RequestHandler::service(HttpRequest& request, HttpResponse& response)
        else {
          spiceResponse = packageKernels("kernels" );
        }
//        remove( inputLabels.expanded().toLatin1() ); //clean up
        p.EndProcess();
      }
      catch (IException &e) {
        
        // We failed at something, delete the temp files...

        QFile pointingFile("kernels.pointing");
        if ( pointingFile.exists() ) pointingFile.remove();
        // Clean up
        remove( inputLabels.expanded().toLatin1() );
        remove("kernels.pointing");
        remove("kernels.position");
        remove("kernels.bodyrot");
        remove("kernels.sun");
        remove("label_after_PvlToPvlTranslationManager.txt");
        remove("lab.txt");
        
        QFile positionFile("kernels.position");
        if ( positionFile.exists() ) positionFile.remove();

        QFile bodyRotFile("kernels.bodyrot");
        if ( bodyRotFile.exists() ) bodyRotFile.remove();

        QFile sunFile("kernels.sun");
        if ( sunFile.exists() ) sunFile.remove();

        QJsonObject errorData;
        errorData.insert("Error", e.what());

        QJsonDocument doc(errorData);
        spiceResponse.clear();
        QByteArray spiceResponse = QByteArray( doc.toJson() );
        p.EndProcess();
      }
      catch (...) {

@@ -340,12 +303,7 @@ void RequestHandler::service(HttpRequest& request, HttpResponse& response)
        QFile sunFile("kernels.sun");
        if ( sunFile.exists() ) sunFile.remove();

        QJsonObject errorData;
        errorData.insert("Error", "Unknown error occurred");

        QJsonDocument doc(errorData);
        spiceResponse.clear();
        QByteArray spiceResponse = QByteArray( doc.toJson() );
        throw;
      }

    // Return a simple HTML document
@@ -360,6 +318,7 @@ void RequestHandler::service(HttpRequest& request, HttpResponse& response)
    }
}


bool tryKernels(Cube &cube, Pvl &lab, Process &p,
                Kernel lk, Kernel pck,
                Kernel targetSpk, Kernel ck,
@@ -461,7 +420,6 @@ bool tryKernels(Cube &cube, Pvl &lab, Process &p,
  if ( currentKernels.hasKeyword("EndPadding") )
    currentKernels.deleteKeyword("EndPadding");


  // Add any time padding the user specified to the spice group
  if (g_startPad > DBL_EPSILON)
    currentKernels.addKeyword( PvlKeyword("StartPadding", toString(g_startPad), "seconds") );
@@ -469,7 +427,6 @@ bool tryKernels(Cube &cube, Pvl &lab, Process &p,
  if (g_endPad > DBL_EPSILON)
    currentKernels.addKeyword( PvlKeyword("EndPadding", toString(g_endPad), "seconds") );


  currentKernels.addKeyword(
      PvlKeyword( "CameraVersion", toString( CameraFactory::CameraVersion(cube) ) ), Pvl::Replace);

@@ -621,16 +578,5 @@ QByteArray packageKernels(QString toFile) {

  QByteArray jsonHexedTables( doc.toJson() );

  QFile finalOutput("finalOutput.txt");
  finalOutput.open(QIODevice::WriteOnly);
  finalOutput.write(jsonHexedTables.constData());
  finalOutput.close();

  //QFile finalsOutput("toFile.txt");
  //finalsOutput.open(QIODevice::WriteOnly);
  //QString raw(doc.rawData(sizeOfData));
  //finalsOutput.write(raw.);
  //finalsOutput.close();

  return jsonHexedTables;
}