//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RiuWellImportWizard::updateFieldsModel()
{
    QString fileName = jsonFieldsFilePath();

    if (QFile::exists(fileName))
    {
        JsonReader jsonReader;
        QMap<QString, QVariant> jsonMap = jsonReader.decodeFile(fileName);

        QStringList regions;
        QStringList fields;
        QStringList edmIds;
        QMapIterator<QString, QVariant> it(jsonMap);
        while (it.hasNext())
        {
            it.next();

            // If we have an array, skip to next node
            if (it.key() == "length")
                continue;

            QMap<QString, QVariant> fieldMap = it.value().toMap();

            regions.push_back(fieldMap["region"].toString());
            fields.push_back(fieldMap["name"].toString());
            edmIds.push_back(fieldMap["edmId"].toString());
        }

        m_wellPathImportObject->updateRegions(regions, fields, edmIds);
        m_wellPathImportObject->updateConnectedEditors();
    }
}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RiuWellImportWizard::downloadFields()
{
    QString wellFileName = jsonWellsFilePath();
    if (QFile::exists(wellFileName))
    {
        QFile::remove(wellFileName);
    }

    QString completeUrlText = m_webServiceAddress + "/resinsight/projects";
    QString destinationFileName = jsonFieldsFilePath();

    m_currentDownloadState = DOWNLOAD_FIELDS;
    issueHttpRequestToFile(completeUrlText, destinationFileName);

    return;
}