in source/jobs/JobDocument.cpp [32:128]
void PlainJobDocument::LoadFromJobDocument(const JsonView &json)
{
const char *jsonKey = JSON_KEY_VERSION;
if (json.ValueExists(jsonKey) && json.GetJsonObject(jsonKey).IsString())
{
version = json.GetString(jsonKey).c_str();
}
jsonKey = JSON_KEY_INCLUDESTDOUT;
if (json.ValueExists(jsonKey) && json.GetJsonObject(jsonKey).IsString())
{
includeStdOut = json.GetString(jsonKey) == "true";
}
if (version.empty())
{
// Converting Old Job Document schema to new Job Document schema
version = OLD_SCHEMA_VERSION;
jsonKey = JSON_KEY_OPERATION;
if (json.ValueExists(jsonKey) && json.GetJsonObject(jsonKey).IsString())
{
JobAction jobAction;
// Save Job Action name and handler field value with operation field value
jobAction.name = json.GetString(jsonKey).c_str();
jobAction.input.handler = jobAction.name;
jsonKey = JSON_KEY_ARGS;
if (json.ValueExists(jsonKey) && json.GetJsonObject(jsonKey).IsListType())
{
jobAction.input.args = ParseToVectorString(json.GetJsonObject(jsonKey));
}
// Old Schema only supports runHandler type of action
jobAction.type = ACTION_TYPE_RUN_HANDLER;
jsonKey = JSON_KEY_ALLOWSTDERR;
if (json.ValueExists(jsonKey) && json.GetJsonObject(jsonKey).IsIntegerType())
{
jobAction.allowStdErr = json.GetInteger(jsonKey);
}
jsonKey = JSON_KEY_PATH;
if (json.ValueExists(jsonKey) && json.GetJsonObject(jsonKey).IsString())
{
jobAction.input.path = json.GetString(jsonKey).c_str();
}
steps.push_back(jobAction);
}
}
else
{
// Job received with new Job Document Schema structure
jsonKey = JSON_KEY_CONDITIONS;
if (json.ValueExists(jsonKey) && json.GetJsonObject(jsonKey).IsListType())
{
conditions = std::vector<PlainJobDocument::JobCondition>();
for (const auto &condition : json.GetArray(jsonKey))
{
JobCondition temp;
temp.LoadFromJobDocument(condition);
conditions->push_back(temp);
}
}
jsonKey = JSON_KEY_STEPS;
if (json.ValueExists(jsonKey) && json.GetJsonObject(jsonKey).IsListType())
{
for (const auto &action : json.GetArray(jsonKey))
{
const char *jsonKeyTwo = JSON_KEY_ACTION;
if (action.ValueExists(jsonKeyTwo))
{
JobAction temp;
temp.LoadFromJobDocument(action.GetJsonObject(jsonKeyTwo));
steps.push_back(temp);
}
}
}
jsonKey = JSON_KEY_FINALSTEP;
if (json.ValueExists(jsonKey))
{
const char *jsonKeyTwo = JSON_KEY_ACTION;
const auto &finalAction = json.GetJsonObject(jsonKey);
if (finalAction.ValueExists(jsonKeyTwo))
{
JobAction temp;
temp.LoadFromJobDocument(finalAction.GetJsonObject(jsonKeyTwo));
finalStep = temp;
}
}
}
}