Skip to content
Snippets Groups Projects
testxmlstructure.cxx 5.14 KiB
Newer Older
#include <vector>
#include <iostream>

#include <QtCore/QString>
#include <QtXml/QXmlStreamWriter>
#include "productiondatabaseclient.h"
ProductionDatabase::ProductionDatabaseClient *proddbclient;

void initialize();
void screeningInfo();
void assignApds(std::string redSerial, std::string blueSerial);
void assignUnit(std::string detectorSerial, std::string crystalSerial, std::string barcode);

  initialize();
  assignApds("0607004597", "0607004598" );
  assignApds("0607004600", "0607004601" );
  assignUnit("0607004598/0607004597","790","1309009220");
  assignUnit("0607004601/0607004600","790","1309009237");
  return 0;
}

void initialize() {
  proddbclient = new ProductionDatabase::ProductionDatabaseClient();
  std::cerr << proddbclient->getVersionShort() << std::endl;
  proddbclient->queryCredentials();
  proddbclient->checkConnectivityAndCredentials();
}

void assignUnit(std::string detectorSerial, std::string crystalSerial, std::string barcode) {
  QString buffer;
  QXmlStreamWriter xml ( &buffer );

  xml.setAutoFormatting(true);
  xml.writeStartDocument( QString::fromUtf8( "1.0" ) );
  xml.writeStartElement( QString::fromUtf8( "productiondb" ) ) ;
  xml.writeTextElement( QString::fromUtf8( "detectorSerial" ), QString::fromStdString( detectorSerial ) );
  xml.writeTextElement( QString::fromUtf8( "crystalSerial" ), QString::fromStdString( crystalSerial ) );
  xml.writeTextElement( QString::fromUtf8( "barcode" ), QString::fromStdString( barcode ) );
  xml.writeEndDocument();

  std::string xmlRequest = buffer.toStdString();
  std::cerr << xmlRequest << std::endl;

  proddbclient->postXmlRequest("unit_assemble.php", xmlRequest);
}

void assignApds(std::string redSerial, std::string blueSerial) {
  QString buffer;
  QXmlStreamWriter xml ( &buffer );

  xml.setAutoFormatting(true);
  xml.writeStartDocument( QString::fromUtf8( "1.0" ) );
  xml.writeStartElement( QString::fromUtf8( "productiondb" ) ) ;
  xml.writeTextElement( QString::fromUtf8( "redSerial" ), QString::fromStdString( redSerial ) );
  xml.writeTextElement( QString::fromUtf8( "blueSerial" ), QString::fromStdString( blueSerial ) );
  xml.writeEndDocument();

  std::string xmlRequest = buffer.toStdString();
  std::cerr << xmlRequest << std::endl;

  proddbclient->postXmlRequest("detector_assemble.php", xmlRequest);
}

void screeningInfo() {
  apds.push_back(QString::fromUtf8("0608004648"));
  apds.push_back(QString::fromUtf8("APD123"));
  apds.push_back(QString::fromUtf8("APD456"));

  QString buffer;
  QXmlStreamWriter xml ( &buffer );
  xml.setAutoFormatting ( true );
  xml.writeStartDocument ( QString::fromUtf8 ( "1.0" ) );
  xml.writeStartElement ( QString::fromUtf8 ( "productiondb" ) );
  xml.writeStartElement ( QString::fromUtf8 ( "elements" ) );
  int j = 1;
  for ( auto i = apds.begin(); i != apds.end(); i++, j++ ) {
    xml.writeStartElement ( QString::fromUtf8 ( "apd" ) );
    xml.writeTextElement ( QString::fromUtf8 ( "serial" ), *i );
    xml.writeTextElement ( QString::fromUtf8 ( "u_m100_warm" ), QString::number( 100.3 + j ) );
    xml.writeTextElement ( QString::fromUtf8 ( "u_m100_cold" ), QString::number( 100.4 + j ) );
    xml.writeTextElement ( QString::fromUtf8 ( "s_m100_warm" ), QString::number( 10.3 + j ) );
    xml.writeTextElement ( QString::fromUtf8 ( "s_m100_cold" ), QString::number( 10.4 + j ) );
    xml.writeTextElement ( QString::fromUtf8 ( "u_m150_warm" ), QString::number( 150.3 + j ) );
    xml.writeTextElement ( QString::fromUtf8 ( "u_m150_cold" ), QString::number( 150.4 + j ) );
    xml.writeTextElement ( QString::fromUtf8 ( "s_m150_warm" ), QString::number( 15.3 + j ) );
    xml.writeTextElement ( QString::fromUtf8 ( "s_m150_cold" ), QString::number( 15.4 + j ) );
    xml.writeTextElement ( QString::fromUtf8 ( "u_m200_warm" ), QString::number( 200.3 + j ) );
    xml.writeTextElement ( QString::fromUtf8 ( "u_m200_cold" ), QString::number( 200.4 + j ) );
    xml.writeTextElement ( QString::fromUtf8 ( "s_m200_warm" ), QString::number( 20.3 + j ) );
    xml.writeTextElement ( QString::fromUtf8 ( "s_m200_cold" ), QString::number( 20.4 + j ) );
    xml.writeTextElement ( QString::fromUtf8 ( "u_m300_warm" ), QString::number( 300.3 + j ) );
    xml.writeTextElement ( QString::fromUtf8 ( "u_m300_cold" ), QString::number( 300.4 + j ) );
    xml.writeTextElement ( QString::fromUtf8 ( "s_m300_warm" ), QString::number( 30.3 + j ) );
    xml.writeTextElement ( QString::fromUtf8 ( "s_m300_cold" ), QString::number( 30.4 + j ) );
    xml.writeTextElement ( QString::fromUtf8 ( "ubreak_warm" ), QString::number( 30.3 + j ) );
    xml.writeTextElement ( QString::fromUtf8 ( "ubreak_cold" ), QString::number( 30.4 + j ) );
    xml.writeEndElement();
  }
  xml.writeEndDocument(); // This closes all open tags automatically.

  std::string xmlRequest = buffer.toStdString();
  std::cerr << xmlRequest << std::endl;

//  ProductionDatabase::ProductionDatabaseClient *proddbclient = new ProductionDatabase::ProductionDatabaseClient();
//  std::cerr << proddbclient->getVersionShort() << std::endl;
//  proddbclient->queryCredentials();
//  proddbclient->checkConnectivityAndCredentials();
//  proddbclient->postXmlRequest("apd_enter_characteristics.php", xmlRequest);