コード例 #1
0
ファイル: ProcessLogger.cpp プロジェクト: raphaelrpl/terrama2
RegisterId terrama2::core::ProcessLogger::start(ProcessId processId) const
{
  if(!isValid_)
    throw terrama2::core::LogException() << ErrorDescription("Error on log!");

  // send start to database
  if(tableName_.empty())
  {
    QString errMsg = QObject::tr("Can not find log table name");
    TERRAMA2_LOG_ERROR() << errMsg;
    throw terrama2::core::LogException() << ErrorDescription(errMsg);
  }

  boost::format query("INSERT INTO "+ tableName_ + " (process_id, status, start_timestamp, last_process_timestamp) VALUES(%1%, %2%, '%3%', '%4%')");

  query.bind_arg(1, processId);
  query.bind_arg(2, static_cast<int>(Status::START));
  query.bind_arg(3, TimeUtils::nowUTC()->toString());
  query.bind_arg(4, TimeUtils::nowUTC()->toString());

  std::shared_ptr< te::da::DataSourceTransactor > transactor = dataSource_->getTransactor();
  transactor->execute(query.str());

  transactor->commit();

  return transactor->getLastGeneratedId();
}
コード例 #2
0
ファイル: ProcessLogger.cpp プロジェクト: raphaelrpl/terrama2
ProcessId terrama2::core::ProcessLogger::processID(const RegisterId registerId) const
{
  if(!isValid_)
    throw terrama2::core::LogException() << ErrorDescription("Error on log!");

  if(tableName_.empty())
  {
    QString errMsg = QObject::tr("Can not find log table name. Is it setted?");
    TERRAMA2_LOG_ERROR() << errMsg;
    throw terrama2::core::LogException() << ErrorDescription(errMsg);
  }

  std::string sql = "SELECT process_id FROM "+ tableName_ + " WHERE id = " + QString::number(registerId).toStdString();

  std::shared_ptr< te::da::DataSourceTransactor > transactor = dataSource_->getTransactor();

  std::shared_ptr<te::da::DataSet> tempDataSet(transactor->query(sql));

  if(!tempDataSet)
  {
    QString errMsg = QObject::tr("Can not find log message table name!");
    TERRAMA2_LOG_ERROR() << errMsg;
    throw terrama2::core::LogException() << ErrorDescription(errMsg);
  }

  if(!tempDataSet->moveNext())
  {
    QString errMsg = QObject::tr("Error to access log message table!");
    TERRAMA2_LOG_ERROR() << errMsg;
    throw terrama2::core::LogException() << ErrorDescription(errMsg);
  }

  return tempDataSet->getInt32("process_id");
}
コード例 #3
0
ファイル: ProcessLogger.cpp プロジェクト: raphaelrpl/terrama2
std::shared_ptr< te::dt::TimeInstantTZ > terrama2::core::ProcessLogger::getDataLastTimestamp(const ProcessId processId) const
{
  if(!isValid_)
    throw terrama2::core::LogException() << ErrorDescription("Error on log!");

  if(tableName_.empty())
  {
    QString errMsg = QObject::tr("Can not find log table name. Is it setted?");
    TERRAMA2_LOG_ERROR() << errMsg;
    throw terrama2::core::LogException() << ErrorDescription(errMsg);
  }

  std::string sql = "SELECT MAX(data_timestamp) FROM "+ tableName_ + " WHERE process_id = " + std::to_string(processId);

  std::shared_ptr< te::da::DataSourceTransactor > transactor = dataSource_->getTransactor();

  std::unique_ptr<te::da::DataSet> tempDataSet(transactor->query(sql));

  if(!tempDataSet)
    return nullptr;

  size_t columnPos = te::da::GetPropertyPos(tempDataSet.get(), "max");

  if(!tempDataSet->moveNext() || tempDataSet->isNull(columnPos))
    return nullptr;

  return std::shared_ptr< te::dt::TimeInstantTZ >(dynamic_cast<te::dt::TimeInstantTZ*>(tempDataSet->getDateTime(columnPos).release()));
}
コード例 #4
0
void terrama2::core::DataAccessorOccurrenceCSV::checkFields(DataSetPtr dataSet) const
{
  bool dateTime = false;
  bool geometry = false;

  QJsonArray array = getFields(dataSet);

  for(auto item : array)
  {
    const QJsonObject& obj = item.toObject();

    int type = dataTypes.at(obj.value("type").toString().toStdString());

    if(type == te::dt::DATETIME_TYPE)
      dateTime = true;

    if(type == te::dt::GEOMETRY_TYPE)
      geometry = true;
  }

  if(!dateTime)
  {
    QString errMsg = QObject::tr("Invalid fields: Missing dateTime field!");
    TERRAMA2_LOG_ERROR() << errMsg;
    throw terrama2::core::DataAccessorException() << ErrorDescription(errMsg);
  }

  if(!geometry)
  {
    QString errMsg = QObject::tr("Invalid fields: Missing geometry field!");
    TERRAMA2_LOG_ERROR() << errMsg;
    throw terrama2::core::DataAccessorException() << ErrorDescription(errMsg);
  }
}
コード例 #5
0
ファイル: ProcessLogger.cpp プロジェクト: raphaelrpl/terrama2
void
terrama2::core::ProcessLogger::log(MessageType messageType, const std::string &description, RegisterId registerId) const
{
  if(!isValid_)
    throw terrama2::core::LogException() << ErrorDescription("Error on log!");

  if(tableName_.empty() || messagesTableName_.empty())
  {
    QString errMsg = QObject::tr("Can not find log tables names.");
    TERRAMA2_LOG_ERROR() << errMsg;
    throw terrama2::core::LogException() << ErrorDescription(errMsg);
  }

  std::shared_ptr< te::dt::TimeInstantTZ> now(TimeUtils::nowUTC());

  std::string escapedDescription(description);
  // TODO: Remove it when terralib escape work properly
  std::replace(escapedDescription.begin(), escapedDescription.end(), '\'', ' ');

  boost::format queryMessages("INSERT INTO " + messagesTableName_ + " (log_id, type, description, timestamp) VALUES(" + QString::number(registerId).toStdString() + ", %1%, '%2%', '%3%')");
  queryMessages.bind_arg(1, static_cast<int>(messageType));
  queryMessages.bind_arg(2, escapedDescription);
  queryMessages.bind_arg(3, now->toString());

  std::shared_ptr< te::da::DataSourceTransactor > transactor = dataSource_->getTransactor();
  transactor->execute(transactor->escape(queryMessages.str()));

  transactor->commit();
}
コード例 #6
0
terrama2::core::DataSetSeries terrama2::core::DataAccessorDcpToa5::getSeries(const std::string& uri,
        const terrama2::core::Filter& filter,
        terrama2::core::DataSetPtr dataSet) const

{
    std::string mask = getMask(dataSet);
    std::string folder = getFolder(dataSet);

    QTemporaryDir tempBaseDir;
    if(!tempBaseDir.isValid())
    {
        QString errMsg = QObject::tr("Can't create temporary folder.");
        TERRAMA2_LOG_ERROR() << errMsg;
        throw DataAccessException() << ErrorDescription(errMsg);
    }

    QDir tempDir(tempBaseDir.path());
    tempDir.mkdir(QString::fromStdString(folder));
    tempDir.cd(QString::fromStdString(folder));

    QUrl url((uri+"/"+folder+"/"+mask).c_str());
    QFileInfo originalInfo(url.path());

    QFile file(url.path());
    QFile tempFile(tempDir.path()+"/"+originalInfo.fileName());
    if(!file.open(QIODevice::ReadOnly))
    {
        QString errMsg = QObject::tr("Can't open file: dataset %1.").arg(dataSet->id);
        TERRAMA2_LOG_ERROR() << errMsg;
        throw DataAccessException() << ErrorDescription(errMsg);
    }

    if(!tempFile.open(QIODevice::ReadWrite))
    {
        QString errMsg = QObject::tr("Can't open temporary file: dataset %1.").arg(dataSet->id);
        TERRAMA2_LOG_ERROR() << errMsg;
        throw DataAccessException() << ErrorDescription(errMsg);
    }

    file.readLine();//ignore first line
    tempFile.write(file.readLine()); //headers line

    //ignore third and fourth lines
    file.readLine();
    file.readLine();

    //read all file
    tempFile.write(file.readAll()); //headers line

    //update file path
    std::string tempUri = "file://"+tempBaseDir.path().toStdString();

    file.close();
    tempFile.close();

    auto dataSeries = terrama2::core::DataAccessorFile::getSeries(tempUri, filter, dataSet);

    return dataSeries;
}
コード例 #7
0
void terrama2::core::DataStoragerTiff::store(DataSetSeries series, DataSetPtr outputDataSet) const
{
  if(!outputDataSet.get() || !series.syncDataSet.get())
  {
    QString errMsg = QObject::tr("Mandatory parameters not provided.");
    TERRAMA2_LOG_ERROR() << errMsg;
    throw DataStoragerException() << ErrorDescription(errMsg);
  }

  QUrl uri(QString::fromStdString(dataProvider_->uri));
  auto path = uri.path().toStdString();
  try
  {
    std::string mask = getMask(outputDataSet);

    auto dataset = series.syncDataSet->dataset();
    size_t rasterColumn = te::da::GetFirstPropertyPos(dataset.get(), te::dt::RASTER_TYPE);
    if(!isValidColumn(rasterColumn))
    {
      QString errMsg = QObject::tr("No raster attribute.");
      TERRAMA2_LOG_ERROR() << errMsg;
      throw DataStoragerException() << ErrorDescription(errMsg);
    }

    size_t timestampColumn = te::da::GetFirstPropertyPos(dataset.get(), te::dt::DATETIME_TYPE);

    dataset->moveBeforeFirst();
    while(dataset->moveNext())
    {
      std::shared_ptr<te::rst::Raster> raster(dataset->isNull(rasterColumn) ? nullptr : dataset->getRaster(rasterColumn).release());
      std::shared_ptr<te::dt::DateTime> timestamp;
      if(!isValidColumn(timestampColumn) || dataset->isNull(timestampColumn))
        timestamp = nullptr;
      else
        timestamp.reset(dataset->getDateTime(timestampColumn).release());

      if(!raster.get())
      {
        QString errMsg = QObject::tr("Null raster found.");
        TERRAMA2_LOG_ERROR() << errMsg;
        continue;
      }

      std::string filename = replaceMask(mask, timestamp, outputDataSet);

      std::string output = path + "/" + filename;
      te::rp::Copy2DiskRaster(*raster, output);
    }
  }
  catch(const DataStoragerException&)
  {
    throw;
  }
  catch(...)
  {
    //TODO: fix DataStoragerTiff catch
  }
}
コード例 #8
0
ファイル: CurlPtr.cpp プロジェクト: edelatin/terrama2
std::vector<std::string> terrama2::core::CurlPtr::getListFiles(std::string url,
                                                               size_t(*write_vector)(void *ptr, size_t size, size_t nmemb, void *data),
                                                               std::string block)
{
  std::vector<std::string> vectorFiles;
  curl_easy_setopt(curl_, CURLOPT_URL, url.c_str());
  curl_easy_setopt(curl_, CURLOPT_DIRLISTONLY, 1);
  curl_easy_setopt(curl_, CURLOPT_WRITEFUNCTION, write_vector);
  curl_easy_setopt(curl_, CURLOPT_WRITEDATA, (void *)&block);

  CURLcode status = curl_easy_perform(curl_);

  if (status == CURLE_OK)
  {
    boost::split(vectorFiles, block, boost::is_any_of("\n"));

    if(!vectorFiles.empty() && vectorFiles.back().empty())
      vectorFiles.pop_back();
  }
  else
  {
    QString errMsg = QObject::tr("Could not list files in the FTP server. \n\n");
    errMsg.append(curl_easy_strerror(status));

    TERRAMA2_LOG_ERROR() << errMsg;
    throw DataRetrieverException() << ErrorDescription(errMsg);
  }

  return vectorFiles;
}
コード例 #9
0
terrama2::core::DataSeriesSemantics terrama2::core::SemanticsManager::addSemantics(const std::string& code,
                                                                                   const std::string& name,
                                                                                   const DataSeriesType& dataSeriesType,
                                                                                   const DataSeriesTemporality& dataSeriesTemporality,
                                                                                   const DataFormat& format,
                                                                                   const std::vector<DataProviderType>& providersTypeList,
                                                                                   const std::unordered_map<std::string, std::string>& metadata)
{
  auto it = semanticsMap_.find(code);
  if(it != semanticsMap_.cend())
  {
    QString errMsg = QObject::tr("Semantics %1 already registered.").arg(name.c_str());
    TERRAMA2_LOG_ERROR() << errMsg.toStdString();
    throw terrama2::core::SemanticsException() << ErrorDescription(errMsg);
  }

  DataSeriesSemantics semantics;
  semantics.code = code;
  semantics.name = name;
  semantics.dataSeriesType = dataSeriesType;
  semantics.temporality = dataSeriesTemporality;
  semantics.dataFormat = format;
  semantics.providersTypeList = providersTypeList;
  semantics.metadata = metadata;

  semanticsMap_[code] = semantics;

  return semantics;
}
コード例 #10
0
void terrama2::services::alert::core::AdditionalDataHelper::addAdditionalAttributesColumns(std::shared_ptr<te::da::DataSetType> alertDataSetType) const
{
  if(!isDataReady_)
  {
    throw AdditionalDataException() << ErrorDescription(QObject::tr("Data not loaded.\nCall AdditionalDataHelper::prepareData."));
  }

  for(const auto& data : dataMap_)
  {
    const auto& dataSet = data.first;
    const auto& dataSetSeries = data.second;

    for(const auto& attribute : additionalData_.attributes)
    {
      try
      {
        std::string name = dataSeries_->name+"_"+attribute+"_"+std::to_string(dataSet->id);
        auto teDataSetType = dataSetSeries.teDataSetType;
        auto property = teDataSetType->getProperty(attribute);
        auto newProperty = property->clone();
        newProperty->setName(name);
        alertDataSetType->add(newProperty);
      }
      catch(...)
      {
        TERRAMA2_LOG_WARNING() << QObject::tr("Attribute %1 not found in dataset %2").arg(QString::fromStdString(attribute)).arg(dataSet->id);
      }
    }
  }
}
コード例 #11
0
void terrama2::services::alert::core::AdditionalDataHelper::addAdditionalValues(te::mem::DataSetItem* item, const std::string& fkValue) const
{
  if(!isDataReady_)
  {
    throw AdditionalDataException() << ErrorDescription(QObject::tr("Data not loaded.\nCall AdditionalDataHelper::prepareData."));
  }

  for(auto data : dataMap_)
  {
    const auto& dataSet = data.first;
    auto dataSetSeries = data.second;
    auto teDataSet = dataSetSeries.syncDataSet->dataset();

    auto mapper = mapperMap_.at(dataSet);


    for(const auto& attribute : additionalData_.attributes)
    {
      auto value = mapper->getValue(fkValue, attribute);

      std::string columnName = dataSeries_->name+"_"+attribute+"_"+std::to_string(dataSet->id);
      if(value.get())
        item->setValue(columnName, value->clone());
      else
        item->setValue(columnName, nullptr);
    }
  }
}
コード例 #12
0
/* function: "write_png(bmp, path[, color_type, text_dict])\n
Writes the bitmap as a png at the given path.\n
Raises OSError on failure.\n
\n
Optional parameters:\n
 - color_type: A constant from the png-module (e.g. png.RGB_ALPHA)\n
 - text_dict: A dictionary of key-strings to value-strings\n
   for png tEXt meta-data."
name: "write_png" */
static void write_png_py(const FilePath& p,
  const Bitmap& bmp,
  const Optional<int>& rawColorType,
  const Optional<png_tEXt_map>& maybeTextChunks)
{
  const auto defaultType = static_cast<int>(PngColorType::RGB_ALPHA);

  const auto colorType =
    to_enum<PngColorType>(rawColorType.Or(defaultType)).Visit(
      [](const PngColorType t){
        return t;
      },
      []() -> PngColorType{
        throw ValueError("color_type out of range.");
      });

  auto r = maybeTextChunks.Visit(
    [&](const png_tEXt_map& textChunks){
      return write_png(p, bmp, colorType, textChunks);
    },
    [&](){
      return write_png(p, bmp, colorType);
    });

  if (!r.Successful()){
    throw OSError(r.ErrorDescription());
  }
}
コード例 #13
0
// get generic socket error info string about last error
CTString CCommunicationInterface::GetSocketError(INDEX iError)
{
  CTString strError;
  strError.PrintF(TRANSV("Socket %d, Error %d (%s)"),
    cci_hSocket, iError, ErrorDescription(&SocketErrors, iError));
  return strError;
};
コード例 #14
0
terrama2::core::DataRetrieverFTP::DataRetrieverFTP(DataProviderPtr dataprovider, CurlPtr&& curlwrapper)
  : DataRetriever(dataprovider),
    curlwrapper_(std::move(curlwrapper))
{
  temporaryFolder_ = "/tmp/terrama2-download/";
  scheme_ = "file://";

  // Create the directory where you will download the files.
  QDir dir(temporaryFolder_.c_str());
  if (!dir.exists())
    dir.mkpath(temporaryFolder_.c_str());

  CURLcode status;
  curlwrapper_.init();

  // Verifies that the FTP address is valid
  try
  {
    std::string url = dataprovider->uri.c_str();

    status = curlwrapper_.verifyURL(url);

    if (status != CURLE_OK)
    {
      QString errMsg = QObject::tr("FTP address is invalid. \n\n");
      errMsg.append(curl_easy_strerror(status));

      TERRAMA2_LOG_ERROR() << errMsg;
      throw DataRetrieverException() << ErrorDescription(errMsg);
    }
  }
  catch(const std::exception& e)
  {
    QString errMsg = QObject::tr("FTP address is invalid! \n\n Details: \n");
    errMsg.append(e.what());

    TERRAMA2_LOG_ERROR() << errMsg;
    throw DataRetrieverException() << ErrorDescription(errMsg);
  }
  catch(...)
  {
    throw DataRetrieverException() << ErrorDescription(QObject::tr("Unknown Error, FTP address is invalid!"));
  }

}
コード例 #15
0
void terrama2::core::DataAccessorJsonCemaden::retrieveDataCallback(const DataRetrieverPtr /*dataRetriever*/,
                                                                    DataSetPtr /*dataSet*/,
                                                                    const Filter& /*filter*/,
                                                                    std::shared_ptr<FileRemover> /*remover*/,
                                                                    std::function<void(const std::string &, const std::string &)> /*processFile*/) const
{
  QString errMsg = QObject::tr("Invalid method call.");
  throw NotRetrivableException() << ErrorDescription(errMsg);
}
コード例 #16
0
ファイル: DataRetriever.cpp プロジェクト: raphaelrpl/terrama2
std::string terrama2::core::DataRetriever::retrieveData(const std::string& query,
                                                        const Filter& filter,
                                                        std::shared_ptr<terrama2::core::FileRemover> remover,
                                                        const std::string& temporaryFolder,
                                                        const std::string& folderPath)
{
  QString errMsg = QObject::tr("Non retrievable DataRetriever.");
  throw NotRetrivableException() << ErrorDescription(errMsg);
}
コード例 #17
0
ファイル: DataRetriever.cpp プロジェクト: raphaelrpl/terrama2
terrama2::core::DataRetriever::DataRetriever(DataProviderPtr dataProvider)
  : dataProvider_(dataProvider)
{
  if(!dataProvider_.get())
  {
    QString errMsg = QObject::tr("Mandatory parameters not provided.");
    TERRAMA2_LOG_ERROR() << errMsg;
    throw DataRetrieverException() << ErrorDescription(errMsg);
  }
}
コード例 #18
0
ファイル: ProcessLogger.cpp プロジェクト: raphaelrpl/terrama2
void terrama2::core::ProcessLogger::addValue(const std::string& tag, const std::string& value, RegisterId registerId) const
{
  if(!isValid_)
    throw terrama2::core::LogException() << ErrorDescription("Error on log!");

  if(tableName_.empty())
  {
    QString errMsg = QObject::tr("Can not find log table name. Is it setted?");
    TERRAMA2_LOG_ERROR() << errMsg;
    throw terrama2::core::LogException() << ErrorDescription(errMsg);
  }

  std::string sql = "SELECT data FROM "+ tableName_ + " WHERE id = " + QString::number(registerId).toStdString();

  std::shared_ptr< te::da::DataSourceTransactor > transactor = dataSource_->getTransactor();

  std::shared_ptr<te::da::DataSet> tempDataSet(transactor->query(sql));

  if(!tempDataSet)
  {
    QString errMsg = QObject::tr("Can not find log message table name!");
    TERRAMA2_LOG_ERROR() << errMsg;
    throw terrama2::core::LogException() << ErrorDescription(errMsg);
  }

  if(!tempDataSet->moveNext())
  {
    QString errMsg = QObject::tr("Error to access log message table!");
    TERRAMA2_LOG_ERROR() << errMsg;
    throw terrama2::core::LogException() << ErrorDescription(errMsg);
  }

  QByteArray readJson = tempDataSet->getAsString("data").c_str();

  QJsonDocument docJson(QJsonDocument::fromJson(readJson));
  QJsonObject obj = docJson.object();
  QString qtag = QString::fromStdString(tag);
  QJsonArray array = obj[qtag].toArray();
  array.push_back(QString::fromStdString(value));
  obj.insert(qtag, array);

  updateData(registerId, obj);
}
コード例 #19
0
terrama2::core::DataAccessorWildFireEvent::DataAccessorWildFireEvent(DataProviderPtr dataProvider, DataSeriesPtr dataSeries, const bool checkSemantics)
: DataAccessor(dataProvider, dataSeries),
  DataAccessorGeometricObjectOGR(dataProvider, dataSeries, false)
{
 if(checkSemantics && dataSeries->semantics.driver != dataAccessorType())
 {
   QString errMsg = QObject::tr("Wrong DataSeries semantics.");
   TERRAMA2_LOG_ERROR() << errMsg;
   throw WrongDataSeriesSemanticsException()  << ErrorDescription(errMsg);
 }
}
コード例 #20
0
terrama2::core::DataAccessorStaticDataOGR::DataAccessorStaticDataOGR(DataProviderPtr dataProvider, DataSeriesPtr dataSeries, const Filter& filter)
: DataAccessor(dataProvider, dataSeries, filter),
  DataAccessorFile(dataProvider, dataSeries, filter)
{
 if(dataSeries->semantics.code != "STATIC_DATA-ogr")
 {
   QString errMsg = QObject::tr("Wrong DataSeries semantics.");
   TERRAMA2_LOG_ERROR() << errMsg;
   throw WrongDataSeriesSemanticsException()  << ErrorDescription(errMsg);
 }
}
コード例 #21
0
terrama2::core::DataSeriesSemantics terrama2::core::SemanticsManager::getSemantics(const std::string& semanticsCode)
{
  auto it = semanticsMap_.find(semanticsCode);
  if(it == semanticsMap_.cend())
  {
    QString errMsg = QObject::tr("Semantics %1 not registered.").arg(semanticsCode.c_str());
    TERRAMA2_LOG_ERROR() << errMsg.toStdString();
    throw terrama2::core::SemanticsException() << ErrorDescription(errMsg);
  }

  return it->second;
}
コード例 #22
0
terrama2::core::DataAccessorOccurrenceLightning::DataAccessorOccurrenceLightning(DataProviderPtr dataProvider, DataSeriesPtr dataSeries, const bool checkSemantics)
  : DataAccessor(dataProvider, dataSeries, false),
    DataAccessorOccurrence(dataProvider, dataSeries, false),
    DataAccessorFile(dataProvider, dataSeries, false)
{
  if(checkSemantics && dataSeries->semantics.code != dataAccessorType())
  {
    QString errMsg = QObject::tr("Wrong DataSeries semantics.");
    TERRAMA2_LOG_ERROR() << errMsg;
    throw WrongDataSeriesSemanticsException() << ErrorDescription(errMsg);
  }
}
コード例 #23
0
terrama2::core::DataAccessorGDAL::DataAccessorGDAL(DataProviderPtr dataProvider, DataSeriesPtr dataSeries, const bool checkSemantics)
 : DataAccessor(dataProvider, dataSeries),
   DataAccessorGrid(dataProvider, dataSeries),
   DataAccessorFile(dataProvider, dataSeries)
{
  if(checkSemantics && dataSeries->semantics.driver != dataAccessorType())
  {
    QString errMsg = QObject::tr("Wrong DataSeries semantics.");
    TERRAMA2_LOG_ERROR() << errMsg;
    throw WrongDataSeriesSemanticsException()  << ErrorDescription(errMsg);
  }
}
コード例 #24
0
ファイル: NotifierFactory.cpp プロジェクト: TerraMA2/terrama2
void terrama2::services::alert::core::NotifierFactory::remove(const std::string& notifierCode)
{
  std::map<std::string, FactoryFnctType>::const_iterator it = factoriesMap_.find(notifierCode);
  if(it == factoriesMap_.end())
  {
    QString errMsg = QObject::tr("There is no registered notifier factory named : %1.").arg(QString::fromStdString(notifierCode));
    TERRAMA2_LOG_ERROR() << errMsg.toStdString();
    throw terrama2::services::alert::NotifierException() << ErrorDescription(errMsg);
  }

  factoriesMap_.erase(it);
}
コード例 #25
0
ファイル: NotifierFactory.cpp プロジェクト: TerraMA2/terrama2
void terrama2::services::alert::core::NotifierFactory::add(const std::string& notifierCode, FactoryFnctType f)
{
  auto it = factoriesMap_.find(notifierCode);
  if(it != factoriesMap_.end())
  {
    QString errMsg = QObject::tr("A notifier with this name already exists: %1.").arg(QString::fromStdString(notifierCode));
    TERRAMA2_LOG_ERROR() << errMsg.toStdString();
    throw terrama2::services::alert::NotifierException() << ErrorDescription(errMsg);
  }

  factoriesMap_[notifierCode] = f;
}
コード例 #26
0
terrama2::core::DataAccessorStaticDataPostGIS::DataAccessorStaticDataPostGIS(DataProviderPtr dataProvider, DataSeriesPtr dataSeries, const bool checkSemantics)
 : DataAccessor(dataProvider, dataSeries, false),
   DataAccessorGeometricObject(dataProvider, dataSeries, false),
   DataAccessorPostGIS(dataProvider, dataSeries, false)
{
  if(checkSemantics && dataSeries->semantics.code != dataAccessorType())
  {
    QString errMsg = QObject::tr("Wrong DataSeries semantics.");
    TERRAMA2_LOG_ERROR() << errMsg;
    throw WrongDataSeriesSemanticsException()  << ErrorDescription(errMsg);
  }
}
コード例 #27
0
ファイル: nifpgaw.cpp プロジェクト: vpaeder/pynifpga
bool nifpga::HandleStatus(NiFpga_Status status) {
	lastStatus = status;
	if (status < 0) {
		std::cout << "[ERROR]: " << status << std::endl;
		std::cout << ErrorDescription(status) << std::endl;
		return false;
	}
	if (status > 0) {
		std::cout << "[WARNING]: " << status << std::endl;
	}
	return true;
}
コード例 #28
0
ファイル: formatter.cpp プロジェクト: jklimke/logog
	LOGOG_STRING &FormatterGCC::Format( const Topic &topic )
	{

		TOPIC_FLAGS flags;
		flags = topic.GetTopicFlags();

		m_sMessageBuffer.clear();

		if ( flags & TOPIC_FILE_NAME_FLAG )
		{
			m_sMessageBuffer.append( topic.FileName() );
			m_sMessageBuffer.append( ':' );
		}

		if ( flags & TOPIC_LINE_NUMBER_FLAG )
		{
			m_sIntBuffer.assign( topic.LineNumber() );
			m_sMessageBuffer.append( m_sIntBuffer );

			m_sMessageBuffer.append( ": ");
		}

		if ( flags & TOPIC_LEVEL_FLAG )
		{
			m_sMessageBuffer.append( ErrorDescription( topic.Level()));
			m_sMessageBuffer.append( ": ");
		}

		if ( flags & TOPIC_GROUP_FLAG )
		{
			m_sMessageBuffer.append( "{");
			m_sMessageBuffer.append( topic.Group() );
			m_sMessageBuffer.append( "} ");
		}

		if ( flags & TOPIC_CATEGORY_FLAG )
		{
			m_sMessageBuffer.append( "[");
			m_sMessageBuffer.append( topic.Category() );
			m_sMessageBuffer.append( "] ");
		}

		if ( flags & TOPIC_MESSAGE_FLAG )
		{
			m_sMessageBuffer.append( topic.Message() );
			m_sMessageBuffer.append( '\n' );
		}

		m_sMessageBuffer.append( (char)NULL );

		return m_sMessageBuffer;
	}
コード例 #29
0
ファイル: Utils.cpp プロジェクト: TerraMA2/terrama2
std::string terrama2::core::getTableNameProperty(terrama2::core::DataSetPtr dataSet)
{
  try
  {
    return dataSet->format.at("table_name");
  }
  catch(...)
  {
    QString errMsg = QObject::tr("Undefined table name in dataset: %1.").arg(dataSet->id);
    TERRAMA2_LOG_ERROR() << errMsg;
    throw UndefinedTagException() << ErrorDescription(errMsg);
  }
}
コード例 #30
0
ファイル: Utils.cpp プロジェクト: TerraMA2/terrama2
std::string terrama2::core::getMask(DataSetPtr dataSet)
{
  try
  {
    return dataSet->format.at("mask");
  }
  catch(const std::out_of_range& /*e*/)
  {
    QString errMsg = QObject::tr("Undefined mask in dataset: %1.").arg(dataSet->id);
    TERRAMA2_LOG_ERROR() << errMsg;
    throw UndefinedTagException() << ErrorDescription(errMsg);
  }
}