Example #1
0
		void Function::setOutputFormatFromMap(const ParametersMap& pm, const string& defaultFormat)
		{
			if(pm.isDefined(PARAMETER_OUTPUT_FORMAT))
			{
				_outputFormat = pm.get<string>(PARAMETER_OUTPUT_FORMAT);
			}
			else if(pm.isDefined(PARAMETER_OUTPUT_FORMAT_COMPAT))
			{
				_outputFormat = pm.get<string>(PARAMETER_OUTPUT_FORMAT_COMPAT);
			}
			else
			{
				_outputFormat = defaultFormat;
			}

			// Shortcuts
			if(_outputFormat == "json")
			{
				_outputFormat = MimeTypes::JSON;
			}
			if(_outputFormat == "xml")
			{
				_outputFormat = MimeTypes::XML;
			}
			if(_outputFormat == "csv")
			{
				_outputFormat = MimeTypes::CSV;
			}
		}
		void FreeDRTAreaUpdateAction::_setFromParametersMap(const ParametersMap& map)
		{
			if(map.getOptional<RegistryKeyType>(PARAMETER_AREA_ID)) try
			{
				_area = FreeDRTAreaTableSync::GetEditable(map.get<RegistryKeyType>(PARAMETER_AREA_ID), *_env);
			}
			catch (ObjectNotFoundException<FreeDRTArea>&)
			{
				throw ActionException("No such area");
			}
			else
			{
				_area.reset(new FreeDRTArea);
			}

			if(map.isDefined(PARAMETER_NAME))
			{
				_name = map.get<string>(PARAMETER_NAME);
			}

			if(map.isDefined(PARAMETER_CITIES))
			{
				_cities = FreeDRTAreaTableSync::UnserializeCities(map.get<string>(PARAMETER_CITIES), *_env);
			}

			if(map.isDefined(PARAMETER_STOP_AREAS))
			{
				_stopAreas = FreeDRTAreaTableSync::UnserializeStopAreas(map.get<string>(PARAMETER_STOP_AREAS), *_env);
			}

			if(map.getDefault<RegistryKeyType>(PARAMETER_COMMERCIAL_LINE_ID, 0))
			{
				try
				{
					_line = CommercialLineTableSync::GetEditable(map.get<RegistryKeyType>(PARAMETER_COMMERCIAL_LINE_ID), *_env);
				}
				catch (ObjectNotFoundException<CommercialLine>&)
				{
					throw ActionException("No such line");
				}
			}
		}
Example #3
0
void JunctionUpdateAction::_setFromParametersMap(const ParametersMap& map)
{
    if(map.isDefined(PARAMETER_JUNCTION_ID))
    {
        try
        {
            _junction = JunctionTableSync::GetEditable(map.get<RegistryKeyType>(PARAMETER_JUNCTION_ID), *_env);
        }
        catch (ObjectNotFoundException<Junction>&)
        {
            throw ActionException("No such junction");
        }
    }
    else
    {
        _junction = boost::shared_ptr<Junction>(new Junction);
    }

    if(map.isDefined(PARAMETER_FROM_ID))
    {
        try
        {
            _from = StopPointTableSync::GetEditable(map.get<RegistryKeyType>(PARAMETER_FROM_ID), *_env);
        }
        catch(ObjectNotFoundException<StopPoint>&)
        {
            throw ActionException("No such from stop point");
        }
    }

    if(map.isDefined(PARAMETER_TO_ID))
    {
        try
        {
            _to = StopPointTableSync::GetEditable(map.get<RegistryKeyType>(PARAMETER_TO_ID), *_env);
        }
        catch(ObjectNotFoundException<StopPoint>&)
        {
            throw ActionException("No such to stop point");
        }
    }

    if(map.isDefined(PARAMETER_LENGTH))
    {
        _length = map.get<double>(PARAMETER_LENGTH);
    }

    if(map.isDefined(PARAMETER_TIME))
    {
        _duration = minutes(map.get<long>(PARAMETER_TIME));
    }

    if(map.isDefined(PARAMETER_BIDIRECTIONAL))
    {
        _bidirectional = map.getDefault<bool>(PARAMETER_BIDIRECTIONAL);
    }
}
Example #4
0
		void ImportFunction::_setFromParametersMap(const ParametersMap& map)
		{
			// Import
			RegistryKeyType importId(map.get<RegistryKeyType>(PARAMETER_IMPORT_ID));
			try
			{
				boost::shared_ptr<const Import> import(ImportTableSync::Get(importId, *_env));
				if(!import->get<DataSource>())
				{
					throw RequestException("The id system of the specified import is not defined.");
				}

				// Log path
				bool outputLogs(map.getDefault<bool>(PARAMETER_OUTPUT_LOGS, false));

				// Min log force
				ImportLogLevel minLogLevel(import->get<MinLogLevel>());
				if(map.isDefined(PARAMETER_MIN_LOG_LEVEL))
				{
					minLogLevel = static_cast<ImportLogLevel>(map.get<int>(PARAMETER_MIN_LOG_LEVEL));
				}

				// Log path force
				string logPath(import->get<LogPath>());
				if(map.isDefined(PARAMETER_LOG_PATH))
				{
					logPath = map.get<string>(PARAMETER_LOG_PATH);
				}
				
				// Logger generation
				if(outputLogs)
				{
					// Importer generation
					_importer = import->getImporter(
						*_env,
						minLogLevel,
						logPath,
						_output,
						_result
					);
				}
				else
				{
					// Importer generation
					_importer = import->getImporter(
						*_env,
						minLogLevel,
						logPath,
						optional<ostream&>(),
						_result
					);
				}

				_importer->setFromParametersMap(map, true);

				_doImport = map.isTrue(PARAMETER_DO_IMPORT);
				_importDone = _importer->beforeParsing();
				_importDone &= _importer->parseFiles();
				_importDone &=_importer->afterParsing();
			}
			catch(ObjectNotFoundException<DataSource> e)
			{
				throw RequestException("Datasource not found");
			}
			catch(Exception e)
			{
				throw RequestException("Load failed : " + e.getMessage());
			}
		}
		void ScenariosListFunction::_setFromParametersMap(const ParametersMap& map)
		{
			_showTemplates = map.get<bool>(PARAMETER_SHOW_TEMPLATES);

			if(_showTemplates)
			{
				optional<RegistryKeyType> id(
					map.getOptional<RegistryKeyType>(PARAMETER_FOLDER_ID)
				);

				if (id)
				{
					try
					{
						_parentFolder = ScenarioFolderTableSync::Get(*id, *_env);
					}
					catch (ObjectNotFoundException<ScenarioFolder>&)
					{
						throw RequestException("Bad folder ID");
					}
				}
			}
			else
			{
				if(map.isDefined(PARAMETER_CURRENTLY_DISPLAYED))
				{
					_showCurrentlyDisplayed = map.get<bool>(PARAMETER_CURRENTLY_DISPLAYED);
				}
				else
				{
					_showCurrentlyDisplayed = optional<bool>();
				}
			}

			// CMS page for the display
			try
			{
				optional<RegistryKeyType> id(map.getOptional<RegistryKeyType>(PARAMETER_CMS_TEMPLATE_ID));
				if(id)
				{
					_cmsTemplate = Env::GetOfficialEnv().get<Webpage>(*id);
				}
			}
			catch (ObjectNotFoundException<Webpage>& e)
			{
				throw RequestException("No such CMS template : "+ e.getMessage());
			}

			// Section in
			if(!map.getDefault<string>(PARAMETER_SECTION_IN).empty())
			{
				try
				{
					_sectionIn = *Env::GetOfficialEnv().get<MessagesSection>(map.get<RegistryKeyType>(PARAMETER_SECTION_IN));
				}
				catch (bad_lexical_cast&)
				{
					throw RequestException("No such section");
				}
				catch(ObjectNotFoundException<MessagesSection>&)
				{
					throw RequestException("No such section");
				}
			}

			// Section out
			if(!map.getDefault<string>(PARAMETER_SECTION_OUT).empty())
			{
				try
				{
					_sectionOut = *Env::GetOfficialEnv().get<MessagesSection>(map.get<RegistryKeyType>(PARAMETER_SECTION_OUT));
				}
				catch (bad_lexical_cast&)
				{
					throw RequestException("No such section");
				}
				catch(ObjectNotFoundException<MessagesSection>&)
				{
					throw RequestException("No such section");
				}
			}

			// Text search
			string textSearch(map.getDefault<string>(PARAMETER_TEXT_SEARCH));
			if(!textSearch.empty())
			{
				_textSearch = textSearch;
			}

			// Archives only
			if(map.isDefined(PARAMETER_ARCHIVES))
			{
				_archivesOnly = map.getDefault<bool>(PARAMETER_ARCHIVES, false);
			}
		}
Example #6
0
		void WebPageMenuFunction::_setFromParametersMap(const ParametersMap& map)
		{
			string targetStr(map.getDefault<string>(PARAMETER_ROOT_ID));
			ParametersMap::Trim(targetStr);
			if(!targetStr.empty() && targetStr[0] >= '0' && targetStr[0] <= '9')
			{
				_rootId = map.getOptional<RegistryKeyType>(PARAMETER_ROOT_ID);
				if(_rootId)
				{
					if(decodeTableId(*_rootId) == Webpage::CLASS_NUMBER) try
					{
						_root = Env::GetOfficialEnv().get<Webpage>(*_rootId).get();
					}
					catch (ObjectNotFoundException<Webpage>&)
					{
						throw RequestException("No such root page");
					}
					else if(decodeTableId(*_rootId) == Website::CLASS_NUMBER) try
					{
						_rootSite = Env::GetOfficialEnv().get<Website>(*_rootId).get();
					}
					catch (ObjectNotFoundException<Webpage>&)
					{
						throw RequestException("No such root site");
					}
				}
			}
			else if(!targetStr.empty())
			{	// Page by smart URL
				_root = getSite()->getPageBySmartURL(targetStr);
				if(!_root)
				{
					throw RequestException("No such web page");
				}
				_rootId = _root->getKey();
			}

			_minDepth = map.getDefault<size_t>(PARAMETER_MIN_DEPTH, 1);
			_maxDepth = map.getDefault<size_t>(PARAMETER_MAX_DEPTH, _minDepth);

			// Max number
			_maxNumber = map.getOptional<size_t>(PARAMETER_MAX_NUMBER);

			// CMS output
			if(map.isDefined(PARAMETER_ITEM_PAGE_ID))
			{
				RegistryKeyType pageId(map.get<RegistryKeyType>(PARAMETER_ITEM_PAGE_ID));
				try
				{
					_itemPage = Env::GetOfficialEnv().get<Webpage>(pageId);
				}
				catch(ObjectNotFoundException<Webpage>&)
				{
					throw RequestException("No such page "+ lexical_cast<string>(pageId));
				}
			}
			else if(!map.getDefault<string>(PARAMETER_OUTPUT_FORMAT).empty())
			{
				_outputFormat = map.get<string>(PARAMETER_OUTPUT_FORMAT);
			}
			else
			{
				// Old output (deprecated)
				for(size_t i(_minDepth); i<=_maxDepth; ++i)
				{
					MenuDefinition_ curMenuDefinition;
					curMenuDefinition.beginning = map.getDefault<string>(PARAMETER_BEGINNING + lexical_cast<string>(i));
					curMenuDefinition.ending = map.getDefault<string>(PARAMETER_ENDING + lexical_cast<string>(i));
					if(map.getOptional<string>(PARAMETER_BEGINNING_SELECTED + lexical_cast<string>(i)))
					{
						curMenuDefinition.beginningSelected = map.get<string>(PARAMETER_BEGINNING_SELECTED + lexical_cast<string>(i));
					}
					else
					{
						curMenuDefinition.beginningSelected = curMenuDefinition.beginning;
					}
					if(map.getOptional<string>(PARAMETER_ENDING_SELECTED + lexical_cast<string>(i)))
					{
						curMenuDefinition.endingSelected = map.getDefault<string>(PARAMETER_ENDING_SELECTED + lexical_cast<string>(i));
					}
					else
					{
						curMenuDefinition.endingSelected = curMenuDefinition.ending;
					}
					curMenuDefinition.beginningBeforeSubmenu = map.getDefault<string>(PARAMETER_BEGINNING_BEFORE_SUBMENU + lexical_cast<string>(i));
					curMenuDefinition.endingAfterSubmenu = map.getDefault<string>(PARAMETER_ENDING_AFTER_SUBMENU + lexical_cast<string>(i));
					_menuDefinition[i] = curMenuDefinition;
				}
			}

			// Raw data
			_rawData = map.getDefault<bool>(PARAMETER_RAW_DATA, false);
		}