Skip to content

Commit

Permalink
Use placeholder (null IFilter) and continue converting when SIMPL con…
Browse files Browse the repository at this point in the history
…version fails to find filter
  • Loading branch information
jmarquisbq committed Dec 5, 2023
1 parent 2204f3d commit b35e179
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 21 deletions.
10 changes: 7 additions & 3 deletions src/complex/Pipeline/Pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,10 +859,14 @@ Result<Pipeline> Pipeline::FromSIMPLJson(const nlohmann::json& json, FilterList*

if(filterResult.invalid())
{
return ConvertInvalidResult<Pipeline>(std::move(filterResult));
auto pipelineFilter = std::make_unique<PipelineFilter>(nullptr);
pipelineFilter->setComments(PipelineFilter::CreateErrorComments(filterResult.errors(), "Filter conversion error: "));
pipeline.push_back(std::move(pipelineFilter));
}
else
{
pipeline.push_back(std::move(filterResult.value()));
}

pipeline.push_back(std::move(filterResult.value()));
}

return {std::move(pipeline)};
Expand Down
72 changes: 54 additions & 18 deletions src/complex/Pipeline/PipelineFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ constexpr StringLiteral k_FilterKey = "filter";
constexpr StringLiteral k_FilterNameKey = "name";
constexpr StringLiteral k_FilterUuidKey = "uuid";
constexpr StringLiteral k_FilterCommentsKey = "comments";
constexpr StringLiteral k_UnknownFilterValue = "UnknownFilter";

constexpr StringLiteral k_SIMPLFilterUuidKey = "Filter_Uuid";
constexpr StringLiteral k_SIMPLFilterHumanNameKey = "Filter_Human_Label";

nlohmann::json CreateFilterJson(std::string_view uuid, std::string_view name, nlohmann::json argsArray, std::string_view comments)
{
Expand Down Expand Up @@ -155,8 +157,16 @@ bool PipelineFilter::preflight(DataStructure& data, RenamedPaths& renamedPaths,
IFilter::MessageHandler messageHandler{[this](const IFilter::Message& message) { this->notifyFilterMessage(message); }};

clearFaultState();
IFilter::PreflightResult result = m_Filter->preflight(data, getArguments(), messageHandler, shouldCancel);
m_Warnings = std::move(result.outputActions.warnings());
IFilter::PreflightResult result;
if(m_Filter != nullptr)
{
result = m_Filter->preflight(data, getArguments(), messageHandler, shouldCancel);
m_Warnings = std::move(result.outputActions.warnings());
}
else
{
m_Warnings.push_back(Warning{-10, "This filter is just a placeholder! The original filter could not be found. See the filter comments for more details."});
}
setHasWarnings(!m_Warnings.empty());
m_PreflightValues = std::move(result.outputValues);
if(result.outputActions.invalid())
Expand Down Expand Up @@ -241,10 +251,18 @@ bool PipelineFilter::execute(DataStructure& data, const std::atomic_bool& should

IFilter::MessageHandler messageHandler{[this](const IFilter::Message& message) { this->notifyFilterMessage(message); }};

IFilter::ExecuteResult result = m_Filter->execute(data, getArguments(), this, messageHandler, shouldCancel);
m_PreflightValues = std::move(result.outputValues);
IFilter::ExecuteResult result;
if(m_Filter != nullptr)
{
result = m_Filter->execute(data, getArguments(), this, messageHandler, shouldCancel);
m_Warnings = result.result.warnings();
}
else
{
m_Warnings.push_back(Warning{-11, "This filter is just a placeholder! The original filter could not be found. See the filter comments for more details."});
}

m_Warnings = result.result.warnings();
m_PreflightValues = std::move(result.outputValues);

if(result.result.invalid())
{
Expand Down Expand Up @@ -444,7 +462,7 @@ const std::vector<IFilter::PreflightValue>& PipelineFilter::getPreflightValues()

std::unique_ptr<AbstractPipelineNode> PipelineFilter::deepCopy() const
{
return std::make_unique<PipelineFilter>(m_Filter->clone(), m_Arguments);
return m_Filter == nullptr ? std::make_unique<PipelineFilter>(nullptr, m_Arguments) : std::make_unique<PipelineFilter>(m_Filter->clone(), m_Arguments);
}

void PipelineFilter::notifyFilterMessage(const IFilter::Message& message)
Expand Down Expand Up @@ -478,6 +496,10 @@ void PipelineFilter::notifyRenamedPaths(const RenamedPaths& renamedPathPairs)

nlohmann::json PipelineFilter::toJsonImpl() const
{
if(m_Filter == nullptr)
{
return CreateFilterJson("", k_UnknownFilterValue, nlohmann::json{}, m_Comments);
}
return CreateFilterJson(m_Filter->uuid().str(), m_Filter->name(), m_Filter->toJson(m_Arguments), m_Comments);
}

Expand Down Expand Up @@ -511,7 +533,24 @@ Result<std::unique_ptr<PipelineFilter>> PipelineFilter::FromJson(const nlohmann:
{
return MakeErrorResult<std::unique_ptr<PipelineFilter>>(-3, "UUID value is not a string");
}

const bool isDisabled = ReadDisabledState(json);
std::string comments;
if(json.contains(k_FilterCommentsKey.view()))
{
comments = json[k_FilterCommentsKey];
}
auto filterName = filterNameObject.get<std::string>();

if(filterName == k_UnknownFilterValue)
{
auto pipelineFilter = std::make_unique<PipelineFilter>(nullptr);
pipelineFilter->setDisabled(isDisabled);
pipelineFilter->setComments(comments);
Result<std::unique_ptr<PipelineFilter>> result{std::move(pipelineFilter)};
return result;
}

auto uuidString = uuidObject.get<std::string>();
std::optional<Uuid> uuid = Uuid::FromString(uuidString);
if(!uuid.has_value())
Expand All @@ -530,8 +569,6 @@ Result<std::unique_ptr<PipelineFilter>> PipelineFilter::FromJson(const nlohmann:
}

const auto& argsJson = json[k_ArgsKey];
const bool isDisabled = ReadDisabledState(json);

auto argsResult = filter->fromJson(argsJson);

if(argsResult.invalid())
Expand All @@ -543,12 +580,7 @@ Result<std::unique_ptr<PipelineFilter>> PipelineFilter::FromJson(const nlohmann:

auto pipelineFilter = std::make_unique<PipelineFilter>(std::move(filter), std::move(argsResult.value()));
pipelineFilter->setDisabled(isDisabled);

if(json.contains(k_FilterCommentsKey.view()))
{
pipelineFilter->setComments(json[k_FilterCommentsKey]);
}

pipelineFilter->setComments(comments);
Result<std::unique_ptr<PipelineFilter>> result{std::move(pipelineFilter)};
result.warnings() = std::move(argsResult.warnings());
return result;
Expand Down Expand Up @@ -605,14 +637,13 @@ complex::WarningCollection convertErrors(const complex::ErrorCollection& errors,
return std::move(warnings);
}

std::string createErrorComments(const complex::ErrorCollection& errors, const std::string& filterName)
std::string PipelineFilter::CreateErrorComments(const complex::ErrorCollection& errors, const std::string& prefix)
{
if(errors.empty())
{
return "";
}

std::string prefix = "Parameter conversion error: ";
std::string output;
for(const auto& error : errors)
{
Expand Down Expand Up @@ -640,7 +671,12 @@ Result<std::unique_ptr<PipelineFilter>> PipelineFilter::FromSIMPLJson(const nloh

if(!simplData.has_value())
{
return MakeErrorResult<std::unique_ptr<PipelineFilter>>(-3, fmt::format("Unable to parse find conversion data for filter '{}'", uuidString));
std::string filterName = fmt::format("with uuid {}", uuidString);
if(json.contains(k_SIMPLFilterHumanNameKey))
{
filterName = fmt::format("{} with uuid {}", json[k_SIMPLFilterHumanNameKey].get<std::string>(), uuidString);
}
return MakeErrorResult<std::unique_ptr<PipelineFilter>>(-3, fmt::format("Unable to find conversion data for filter '{}'", filterName));
}

IFilter::UniquePointer filter = filterList.createFilter(simplData->complexUuid);
Expand Down Expand Up @@ -668,7 +704,7 @@ Result<std::unique_ptr<PipelineFilter>> PipelineFilter::FromSIMPLJson(const nloh
if(argumentsResult.invalid())
{
warnings = convertErrors(argumentsResult.errors(), filterName);
pipelineFilter->setComments(createErrorComments(argumentsResult.errors(), filterName));
pipelineFilter->setComments(CreateErrorComments(argumentsResult.errors(), "Parameter conversion error: "));
}

return {std::move(pipelineFilter), std::move(warnings)};
Expand Down
8 changes: 8 additions & 0 deletions src/complex/Pipeline/PipelineFilter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ class COMPLEX_EXPORT PipelineFilter : public AbstractPipelineNode
*/
static Result<std::unique_ptr<PipelineFilter>> FromSIMPLJson(const nlohmann::json& json, const FilterList& filterList);

/**
* @brief Creates a comment string from the errors collection
* @param errors The errors to convert to strings for storing in a comment
* @param prefix The comment string prefix for each of the errors
* @return The converted comment string containing all of the errors
*/
static std::string CreateErrorComments(const complex::ErrorCollection& errors, const std::string& prefix);

/**
* @brief Constructs a PipelineFilter with the provided filter and arguments.
* If no Arguments are provided, a default empty value will be used instead.
Expand Down

0 comments on commit b35e179

Please sign in to comment.