Skip to content
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# The version number.
set(AGENT_VERSION_MAJOR 2)
set(AGENT_VERSION_MINOR 5)
set(AGENT_VERSION_MINOR 6)
set(AGENT_VERSION_PATCH 0)
set(AGENT_VERSION_BUILD 11)
set(AGENT_VERSION_BUILD 0)
set(AGENT_VERSION_RC "")

# This minimum version is to support Visual Studio 2019 and C++ feature checking and FetchContent
Expand Down
2 changes: 2 additions & 0 deletions agent_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ set(AGENT_SOURCES
# src/sink/rest_sink HEADER_FILE_ONLY

"${SOURCE_DIR}/sink/rest_sink/cached_file.hpp"
"${SOURCE_DIR}/sink/rest_sink/error.hpp"
"${SOURCE_DIR}/sink/rest_sink/file_cache.hpp"
"${SOURCE_DIR}/sink/rest_sink/parameter.hpp"
"${SOURCE_DIR}/sink/rest_sink/request.hpp"
Expand All @@ -274,6 +275,7 @@ set(AGENT_SOURCES

# src/sink/rest_sink SOURCE_FILES_ONLY

"${SOURCE_DIR}/sink/rest_sink/error.cpp"
"${SOURCE_DIR}/sink/rest_sink/file_cache.cpp"
"${SOURCE_DIR}/sink/rest_sink/rest_service.cpp"
"${SOURCE_DIR}/sink/rest_sink/server.cpp"
Expand Down
24 changes: 12 additions & 12 deletions src/mtconnect/entity/data_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ namespace mtconnect::entity {
return m_key == other.m_key && m_removed == other.m_removed && sameValue(other);
}

std::string m_key; ///< The key of the entry
T m_value; ///< The value of the entry
bool m_removed; ///< boolean indicator if this entry is removed.
std::string m_key; //! The key of the entry
T m_value; //! The value of the entry
bool m_removed; //! boolean indicator if this entry is removed.
};

/// @brief A set of data set entries
Expand Down Expand Up @@ -171,10 +171,10 @@ namespace mtconnect::entity {
/// @brief Data Set Value type enumeration
enum class TabelCellType : std::uint16_t
{
EMPTY = 0x0, ///< monostate for no value
STRING = 0x02, ///< string value
INTEGER = 0x3, ///< 64 bit integer
DOUBLE = 0x4 ///< double
EMPTY = 0x0, //! monostate for no value
STRING = 0x02, //! string value
INTEGER = 0x3, //! 64 bit integer
DOUBLE = 0x4 //! double
};

/// @brief Table Cell value variant
Expand Down Expand Up @@ -216,11 +216,11 @@ namespace mtconnect::entity {
/// @brief Data Set Value type enumeration
enum class DataSetValueType : std::uint16_t
{
EMPTY = 0x0, ///< monostate for no value
TABLE_ROW = 0x01, ///< data set member for tables
STRING = 0x02, ///< string value
INTEGER = 0x3, ///< 64 bit integer
DOUBLE = 0x4 ///< double
EMPTY = 0x0, //! monostate for no value
TABLE_ROW = 0x01, //! data set member for tables
STRING = 0x02, //! string value
INTEGER = 0x3, //! 64 bit integer
DOUBLE = 0x4 //! double
};

/// @brief Data set value variant
Expand Down
37 changes: 13 additions & 24 deletions src/mtconnect/printer/json_printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "mtconnect/entity/json_printer.hpp"
#include "mtconnect/logging.hpp"
#include "mtconnect/printer/json_printer_helper.hpp"
#include "mtconnect/sink/rest_sink/error.hpp"
#include "mtconnect/version.h"

using namespace std;
Expand Down Expand Up @@ -117,14 +118,17 @@ namespace mtconnect::printer {
}

std::string JsonPrinter::printErrors(const uint64_t instanceId, const unsigned int bufferSize,
const uint64_t nextSeq, const ProtoErrorList &list,
const uint64_t nextSeq, const entity::EntityList &list,
bool pretty,
const std::optional<std::string> requestId) const
{
defaultSchemaVersion();
auto version = IntSchemaVersion(*m_schemaVersion);

StringBuffer output;
RenderJson(output, m_pretty || pretty, [&](auto &writer) {
entity::JsonPrinter printer(writer, m_jsonVersion);

AutoJsonObject obj(writer);
{
AutoJsonObject obj(writer, "MTConnectError");
Expand All @@ -136,34 +140,19 @@ namespace mtconnect::printer {
m_modelChangeTime, m_validation, requestId);
}
{
if (m_jsonVersion > 1)
obj.Key("Errors");
entity::EntityList errors;
if (version < SCHEMA_VERSION(2, 6))
{
AutoJsonObject obj(writer, "Errors");
for (auto &err : list)
{
AutoJsonArray ary(writer, "Error");
for (auto &e : list)
{
AutoJsonObject obj(writer);
string s(e.second);
obj.AddPairs("errorCode", e.first, "value", trim(s));
}
auto re = dynamic_pointer_cast<sink::rest_sink::Error>(err);
errors.emplace_back(re->makeLegacyError());
}
}
else
{
AutoJsonArray obj(writer, "Errors");
{
for (auto &e : list)
{
AutoJsonObject obj(writer);
{
AutoJsonObject obj(writer, "Error");
string s(e.second);
obj.AddPairs("errorCode", e.first, "value", trim(s));
}
}
}
}
errors = list;
printer.printEntityList(errors);
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/mtconnect/printer/json_printer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace mtconnect::printer {

std::string printErrors(
const uint64_t instanceId, const unsigned int bufferSize, const uint64_t nextSeq,
const ProtoErrorList &list, bool pretty = false,
const entity::EntityList &list, bool pretty = false,
const std::optional<std::string> requestId = std::nullopt) const override;

std::string printProbe(
Expand Down
14 changes: 9 additions & 5 deletions src/mtconnect/printer/printer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,29 @@ namespace mtconnect {
/// @param[in] instanceId the instance id
/// @param[in] bufferSize the buffer size
/// @param[in] nextSeq the next sequence
/// @param[in] errorCode an error code
/// @param[in] errorText the error text
/// @param[in] error the error being reported
/// @param[in] pretty `true` if content should be pretty printed
/// @param[in] requestId optional request id to include in the header
/// @return the error document
virtual std::string printError(
const uint64_t instanceId, const unsigned int bufferSize, const uint64_t nextSeq,
const std::string &errorCode, const std::string &errorText, bool pretty = false,
entity::EntityPtr error, bool pretty = false,
const std::optional<std::string> requestId = std::nullopt) const
{
return printErrors(instanceId, bufferSize, nextSeq, {{errorCode, errorText}});
return printErrors(instanceId, bufferSize, nextSeq, entity::EntityList {error}, pretty,
requestId);
}
/// @brief Generate an MTConnect Error document with a error list
/// @param[in] instanceId the instance id
/// @param[in] bufferSize the buffer size
/// @param[in] nextSeq the next sequence
/// @param[in] list the list of errors
/// @param[in] pretty `true` if content should be pretty printed
/// @param[in] requestId optional request id to include in the header
/// @return the MTConnect Error document
virtual std::string printErrors(
const uint64_t instanceId, const unsigned int bufferSize, const uint64_t nextSeq,
const ProtoErrorList &list, bool pretty = false,
const entity::EntityList &list, bool pretty = false,
const std::optional<std::string> requestId = std::nullopt) const = 0;
/// @brief Generate an MTConnect Devices document
/// @param[in] instanceId the instance id
Expand Down
23 changes: 15 additions & 8 deletions src/mtconnect/printer/xml_printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "mtconnect/device_model/configuration/configuration.hpp"
#include "mtconnect/device_model/device.hpp"
#include "mtconnect/logging.hpp"
#include "mtconnect/sink/rest_sink/error.hpp"
#include "mtconnect/version.h"
#include "xml_printer.hpp"

Expand Down Expand Up @@ -343,7 +344,7 @@ namespace mtconnect::printer {
}

std::string XmlPrinter::printErrors(const uint64_t instanceId, const unsigned int bufferSize,
const uint64_t nextSeq, const ProtoErrorList &list,
const uint64_t nextSeq, const entity::EntityList &list,
bool pretty, const std::optional<std::string> requestId) const
{
string ret;
Expand All @@ -357,9 +358,18 @@ namespace mtconnect::printer {

{
AutoElement e1(writer, "Errors");
entity::XmlPrinter printer;

auto version = IntSchemaVersion(*m_schemaVersion);
for (auto &e : list)
{
addSimpleElement(writer, "Error", e.second, {{"errorCode", e.first}});
entity::EntityPtr err {e};
if (version < SCHEMA_VERSION(2, 6))
{
auto re = dynamic_pointer_cast<sink::rest_sink::Error>(err);
err = re->makeLegacyError();
}
printer.print(writer, err, m_errorNsSet);
}
}
closeElement(writer); // MTConnectError
Expand Down Expand Up @@ -679,12 +689,9 @@ namespace mtconnect::printer {
if (requestId)
addAttribute(writer, "requestId", *requestId);

int major, minor;
char c;
stringstream v(*m_schemaVersion);
v >> major >> c >> minor;
auto schemaVersion = IntSchemaVersion(*m_schemaVersion);

if (major > 1 || (major == 1 && minor >= 7))
if (schemaVersion >= SCHEMA_VERSION(1, 7))
{
addAttribute(writer, "deviceModelChangeTime", m_modelChangeTime);
}
Expand All @@ -708,7 +715,7 @@ namespace mtconnect::printer {
addAttribute(writer, "lastSequence", to_string(lastSeq));
}

if (major < 2 && aType == eDEVICES && count && !count->empty())
if (schemaVersion < SCHEMA_VERSION(2, 0) && aType == eDEVICES && count && !count->empty())
{
AutoElement ele(writer, "AssetCounts");

Expand Down
4 changes: 2 additions & 2 deletions src/mtconnect/printer/xml_printer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace mtconnect {

std::string printErrors(
const uint64_t instanceId, const unsigned int bufferSize, const uint64_t nextSeq,
const ProtoErrorList &list, bool pretty = false,
const entity::EntityList &list, bool pretty = false,
const std::optional<std::string> requestId = std::nullopt) const override;

std::string printProbe(
Expand All @@ -64,7 +64,7 @@ namespace mtconnect {
const uint64_t anInstanceId, const unsigned int bufferSize, const unsigned int assetCount,
const asset::AssetList &asset, bool pretty = false,
const std::optional<std::string> requestId = std::nullopt) const override;
std::string mimeType() const override { return "text/xml"; }
std::string mimeType() const override { return "application/mtconnect+xml"; }

/// @brief Print a single device in XML
/// @param device A device poiinter
Expand Down
120 changes: 120 additions & 0 deletions src/mtconnect/sink/rest_sink/error.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
//
// Copyright Copyright 2009-2024, AMT – The Association For Manufacturing Technology (“AMT”)
// All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#include "error.hpp"

#include "mtconnect/entity/factory.hpp"

namespace mtconnect::sink::rest_sink {
using namespace mtconnect::entity;
using namespace std;

const std::string Error::nameForCode(ErrorCode code)
{
switch (code)
{
case ErrorCode::ASSET_NOT_FOUND:
return "AssetNotFound";

case ErrorCode::INTERNAL_ERROR:
return "InternalError";

case ErrorCode::INVALID_REQUEST:
return "InvalidRequest";

case ErrorCode::INVALID_URI:
return "InvalidURI";

case ErrorCode::INVALID_XPATH:
return "InvalidXPath";

case ErrorCode::NO_DEVICE:
return "NoDevice";

case ErrorCode::OUT_OF_RANGE:
return "OutOfRange";

case ErrorCode::QUERY_ERROR:
return "QueryError";

case ErrorCode::TOO_MANY:
return "TooMany";

case ErrorCode::UNAUTHORIZED:
return "Unauthorized";

case ErrorCode::UNSUPPORTED:
return "Unsupported";

case ErrorCode::INVALID_PARAMETER_VALUE:
return "InvalidParameterValue";

case ErrorCode::INVALID_QUERY_PARAMETER:
return "InvalidQueryParameter";
}

return "InternalError";
}

const std::string Error::enumForCode(ErrorCode code)
{
switch (code)
{
case ErrorCode::ASSET_NOT_FOUND:
return "ASSET_NOT_FOUND";

case ErrorCode::INTERNAL_ERROR:
return "INTERNAL_ERROR";

case ErrorCode::INVALID_REQUEST:
return "INVALID_REQUEST";

case ErrorCode::INVALID_URI:
return "INVALID_URI";

case ErrorCode::INVALID_XPATH:
return "INVALID_XPATH";

case ErrorCode::NO_DEVICE:
return "NO_DEVICE";

case ErrorCode::OUT_OF_RANGE:
return "OUT_OF_RANGE";

case ErrorCode::QUERY_ERROR:
return "QUERY_ERROR";

case ErrorCode::TOO_MANY:
return "TOO_MANY";

case ErrorCode::UNAUTHORIZED:
return "UNAUTHORIZED";

case ErrorCode::UNSUPPORTED:
return "UNSUPPORTED";

case ErrorCode::INVALID_PARAMETER_VALUE:
return "INVALID_PARAMETER_VALUE";

case ErrorCode::INVALID_QUERY_PARAMETER:
return "INVALID_QUERY_PARAMETER";
}

return "InternalError";
}

} // namespace mtconnect::sink::rest_sink
Loading
Loading