2019-06-03 07:33:16 -05:00
|
|
|
#include "RiaGrpcProjectService.h"
|
2019-05-20 06:21:02 -05:00
|
|
|
|
|
|
|
#include "RiaApplication.h"
|
|
|
|
#include "RiaGrpcCallbacks.h"
|
|
|
|
#include "RiaSocketTools.h"
|
|
|
|
|
|
|
|
#include "RimCase.h"
|
|
|
|
#include "RimCaseCollection.h"
|
|
|
|
#include "RimEclipseCase.h"
|
|
|
|
#include "RimEclipseCaseCollection.h"
|
|
|
|
#include "RimGeoMechCase.h"
|
|
|
|
#include "RimGridView.h"
|
|
|
|
#include "RimIdenticalGridCaseGroup.h"
|
|
|
|
#include "RimOilField.h"
|
|
|
|
#include "RimProject.h"
|
|
|
|
|
|
|
|
#include "cafSelectionManager.h"
|
|
|
|
|
2019-06-03 07:33:16 -05:00
|
|
|
#include "Case.grpc.pb.h"
|
2019-05-20 06:21:02 -05:00
|
|
|
|
|
|
|
using grpc::ServerCompletionQueue;
|
|
|
|
using grpc::ServerContext;
|
|
|
|
using grpc::Status;
|
|
|
|
|
|
|
|
using namespace rips;
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-06-03 07:33:16 -05:00
|
|
|
Status RiaGrpcProjectService::GetCurrentCase(ServerContext* context, const rips::Empty* request, rips::CaseRequest* reply)
|
2019-05-20 06:21:02 -05:00
|
|
|
{
|
|
|
|
RimGridView* view = RiaApplication::instance()->activeGridView();
|
|
|
|
if (view)
|
|
|
|
{
|
|
|
|
RimCase* currentCase = view->ownerCase();
|
|
|
|
if (currentCase)
|
|
|
|
{
|
|
|
|
reply->set_id(currentCase->caseId());
|
|
|
|
return Status::OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Status(grpc::NOT_FOUND, "No current case found");
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-06-03 07:33:16 -05:00
|
|
|
Status RiaGrpcProjectService::GetSelectedCases(ServerContext* context, const rips::Empty* request, rips::CaseInfoArray* reply)
|
2019-05-20 06:21:02 -05:00
|
|
|
{
|
|
|
|
std::vector<RimCase*> cases;
|
|
|
|
caf::SelectionManager::instance()->objectsByType(&cases);
|
|
|
|
|
|
|
|
if (cases.empty())
|
|
|
|
{
|
|
|
|
return Status(grpc::NOT_FOUND, "No cases selected");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (RimCase* rimCase : cases)
|
|
|
|
{
|
|
|
|
qint64 caseId = rimCase->caseId();
|
|
|
|
qint64 caseGroupId = -1;
|
|
|
|
QString caseName, caseType;
|
|
|
|
RiaSocketTools::getCaseInfoFromCase(rimCase, caseId, caseName, caseType, caseGroupId);
|
|
|
|
|
2019-06-03 07:33:16 -05:00
|
|
|
rips::CaseInfo* caseInfo = reply->add_data();
|
2019-05-20 06:21:02 -05:00
|
|
|
caseInfo->set_id(caseId);
|
|
|
|
caseInfo->set_group_id(caseGroupId);
|
|
|
|
caseInfo->set_name(caseName.toStdString());
|
|
|
|
caseInfo->set_type(caseType.toStdString());
|
|
|
|
}
|
|
|
|
return Status::OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
grpc::Status
|
2019-06-03 07:33:16 -05:00
|
|
|
RiaGrpcProjectService::GetAllCaseGroups(grpc::ServerContext* context, const rips::Empty* request, rips::CaseGroups* reply)
|
2019-05-20 06:21:02 -05:00
|
|
|
{
|
|
|
|
RimProject* proj = RiaApplication::instance()->project();
|
|
|
|
RimEclipseCaseCollection* analysisModels =
|
|
|
|
(proj && proj->activeOilField()) ? proj->activeOilField()->analysisModels() : nullptr;
|
|
|
|
if (analysisModels)
|
|
|
|
{
|
|
|
|
for (RimIdenticalGridCaseGroup* cg : analysisModels->caseGroups())
|
|
|
|
{
|
2019-06-03 07:33:16 -05:00
|
|
|
rips::CaseGroup* caseGroup = reply->add_case_groups();
|
2019-05-20 06:21:02 -05:00
|
|
|
caseGroup->set_id(cg->groupId());
|
|
|
|
caseGroup->set_name(cg->name().toStdString());
|
|
|
|
}
|
|
|
|
return Status::OK;
|
|
|
|
}
|
|
|
|
return Status(grpc::NOT_FOUND, "No case groups found");
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-06-03 07:33:16 -05:00
|
|
|
grpc::Status RiaGrpcProjectService::GetAllCases(grpc::ServerContext* context, const rips::Empty* request, rips::CaseInfoArray* reply)
|
2019-05-20 06:21:02 -05:00
|
|
|
{
|
|
|
|
std::vector<RimCase*> cases;
|
|
|
|
RiaApplication::instance()->project()->allCases(cases);
|
|
|
|
|
|
|
|
if (cases.empty())
|
|
|
|
{
|
|
|
|
return Status(grpc::NOT_FOUND, "No cases found");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (RimCase* rimCase : cases)
|
|
|
|
{
|
|
|
|
qint64 caseId = rimCase->caseId();
|
|
|
|
qint64 caseGroupId = -1;
|
|
|
|
QString caseName, caseType;
|
|
|
|
RiaSocketTools::getCaseInfoFromCase(rimCase, caseId, caseName, caseType, caseGroupId);
|
|
|
|
|
2019-06-03 07:33:16 -05:00
|
|
|
rips::CaseInfo* caseInfo = reply->add_data();
|
2019-05-20 06:21:02 -05:00
|
|
|
caseInfo->set_id(caseId);
|
|
|
|
caseInfo->set_group_id(caseGroupId);
|
|
|
|
caseInfo->set_name(caseName.toStdString());
|
|
|
|
caseInfo->set_type(caseType.toStdString());
|
|
|
|
}
|
|
|
|
return Status::OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
grpc::Status
|
2019-06-03 07:33:16 -05:00
|
|
|
RiaGrpcProjectService::GetCasesInGroup(grpc::ServerContext* context, const rips::CaseGroup* request, rips::CaseInfoArray* reply)
|
2019-05-20 06:21:02 -05:00
|
|
|
{
|
|
|
|
RimProject* proj = RiaApplication::instance()->project();
|
|
|
|
RimEclipseCaseCollection* analysisModels =
|
|
|
|
(proj && proj->activeOilField()) ? proj->activeOilField()->analysisModels() : nullptr;
|
|
|
|
if (analysisModels)
|
|
|
|
{
|
|
|
|
int groupId = request->id();
|
|
|
|
RimIdenticalGridCaseGroup* caseGroup = nullptr;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < analysisModels->caseGroups().size(); i++)
|
|
|
|
{
|
|
|
|
RimIdenticalGridCaseGroup* cg = analysisModels->caseGroups()[i];
|
|
|
|
|
|
|
|
if (groupId == cg->groupId())
|
|
|
|
{
|
|
|
|
caseGroup = cg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<RimCase*> cases;
|
|
|
|
if (caseGroup)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < caseGroup->statisticsCaseCollection()->reservoirs.size(); i++)
|
|
|
|
{
|
|
|
|
cases.push_back(caseGroup->statisticsCaseCollection()->reservoirs[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < caseGroup->caseCollection()->reservoirs.size(); i++)
|
|
|
|
{
|
|
|
|
cases.push_back(caseGroup->caseCollection()->reservoirs[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!cases.empty())
|
|
|
|
{
|
|
|
|
for (RimCase* rimCase : cases)
|
|
|
|
{
|
|
|
|
qint64 caseId = rimCase->caseId();
|
|
|
|
qint64 caseGroupId = -1;
|
|
|
|
QString caseName, caseType;
|
|
|
|
RiaSocketTools::getCaseInfoFromCase(rimCase, caseId, caseName, caseType, caseGroupId);
|
|
|
|
|
2019-06-03 07:33:16 -05:00
|
|
|
rips::CaseInfo* caseInfo = reply->add_data();
|
2019-05-20 06:21:02 -05:00
|
|
|
caseInfo->set_id(caseId);
|
|
|
|
caseInfo->set_group_id(caseGroupId);
|
|
|
|
caseInfo->set_name(caseName.toStdString());
|
|
|
|
caseInfo->set_type(caseType.toStdString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Status(grpc::NOT_FOUND, "No cases found");
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-06-03 07:33:16 -05:00
|
|
|
std::vector<RiaGrpcCallbackInterface*> RiaGrpcProjectService::createCallbacks()
|
2019-05-20 06:21:02 -05:00
|
|
|
{
|
2019-06-03 07:33:16 -05:00
|
|
|
typedef RiaGrpcProjectService Self;
|
2019-05-20 06:21:02 -05:00
|
|
|
|
|
|
|
return {
|
2019-06-03 07:33:16 -05:00
|
|
|
new RiaGrpcUnaryCallback<Self, Empty, CaseRequest>(this, &Self::GetCurrentCase, &Self::RequestGetCurrentCase),
|
|
|
|
new RiaGrpcUnaryCallback<Self, Empty, CaseInfoArray>(this, &Self::GetSelectedCases, &Self::RequestGetSelectedCases),
|
|
|
|
new RiaGrpcUnaryCallback<Self, Empty, CaseGroups>(this, &Self::GetAllCaseGroups, &Self::RequestGetAllCaseGroups),
|
|
|
|
new RiaGrpcUnaryCallback<Self, Empty, CaseInfoArray>(this, &Self::GetAllCases, &Self::RequestGetAllCases),
|
|
|
|
new RiaGrpcUnaryCallback<Self, CaseGroup, CaseInfoArray>(this, &Self::GetCasesInGroup, &Self::RequestGetCasesInGroup)};
|
2019-05-20 06:21:02 -05:00
|
|
|
}
|
|
|
|
|
2019-06-03 07:33:16 -05:00
|
|
|
static bool RiaGrpcProjectService_init =
|
|
|
|
RiaGrpcServiceFactory::instance()->registerCreator<RiaGrpcProjectService>(typeid(RiaGrpcProjectService).hash_code());
|