Esempio n. 1
0
	WebResponse* GetPreviewHandler::Execute(WebRequest* pWebRequest, User* pUser)
	{
		GetPreviewRequest* pRequest = static_cast<GetPreviewRequest*>(pWebRequest);

		const char* sourceName = pRequest->GetSourceName();
		const char* dataSetName= pRequest->GetDataSetName();

		if(sourceName==NULL)
		{
			const char* msg = "Parameter [sourceName] is NULL";
			GLogger* pLogger = augeGetLoggerInstance();
			pLogger->Error(msg, __FILE__, __LINE__);
			WebExceptionResponse* pExpResponse = augeCreateWebExceptionResponse();
			pExpResponse->SetMessage(msg);
			return pExpResponse;
		}

		Workspace* pWorkspace = NULL;
		ConnectionManager* pConnectionManager = augeGetConnectionManagerInstance();
		pWorkspace = pConnectionManager->GetWorkspace(pUser->GetID(), sourceName);
		if( pWorkspace==NULL )
		{
			char msg[AUGE_PATH_MAX] = {0};
			g_sprintf(msg, "Cannot load datasource [%s].", sourceName);
			GLogger* pLogger = augeGetLoggerInstance();
			pLogger->Error(msg, __FILE__, __LINE__);
			WebExceptionResponse* pExpResponse = augeCreateWebExceptionResponse();
			pExpResponse->SetMessage(msg);
			return pExpResponse;
		}

		DataSet* pDataSet = pWorkspace->OpenDataSet(dataSetName);
		if(pDataSet==NULL)
		{
			char msg[AUGE_PATH_MAX] = {0};
			g_sprintf(msg, "Cannot load data set [%s].", dataSetName);
			GLogger* pLogger = augeGetLoggerInstance();
			pLogger->Error(msg, __FILE__, __LINE__);
			WebExceptionResponse* pExpResponse = augeCreateWebExceptionResponse();
			pExpResponse->SetMessage(msg);
			return pExpResponse;
		}

		WebResponse* pWebResponse = NULL;
		switch(pDataSet->GetType())
		{
		case augeDataSetFeature:
			{
				FeatureClass* pFeatureClass = static_cast<FeatureClass*>(pDataSet);
				char img_sfix[AUGE_EXT_MAX] = {0};
				char img_path[AUGE_PATH_MAX] = {0};
				auge_get_image_suffix(pRequest->GetMimeType(), img_sfix, AUGE_EXT_MAX);
				WebContext* pWebContext = augeGetWebContextInstance();
				auge_make_path(img_path, NULL, pWebContext->GetCacheMapPath(), pFeatureClass->GetUUID(), img_sfix);
				if(!g_access(img_path, 4))
				{
					GetPreviewResponse* pMapResponse = new GetPreviewResponse(pRequest);
					pMapResponse->SetPath(img_path);
					pWebResponse = pMapResponse;
				}
				else
				{
					pWebResponse = DrawFeature(pFeatureClass,pRequest);
				}
			}			
			break;
		case augeDataSetRaster:
			break;
		}

		return pWebResponse;
	}