#include "interface_wms2ecc_impl.h" #include "exercises_handler.h" #include #include #include #include #include namespace WarehouseManagement { IWMS2ECC_Impl::IWMS2ECC_Impl(const std::shared_ptr &exercisesHandler) : m_logger(getLogger("Wms2Ecc")) , m_exercisesHandler(exercisesHandler) { connect(m_exercisesHandler.get(), &ExercisesHandler::registrationReturnValue, this, &IWMS2ECC_Impl::onRegistrationReturnValue); } IWMS2ECC::Exercise IWMS2ECC_Impl::convert(const ExerciseManagement::Exercise &ex) { IWMS2ECC::Exercise ret; ret.id = ex.id; ret.name = QString::fromStdString(ex.name); if (ex.state == ExerciseManagement::ExerciseState::Started || ex.state == ExerciseManagement::ExerciseState::Paused) ret.actExercise = 1; else ret.actExercise = 0; ret.start = ex.beginTime / 1000; ret.end = ex.endTime / 1000; ret.stateAsString = ExerciseManagement::toString(ex.state); return ret; } IWMS2ECC::PlayerInfo IWMS2ECC_Impl::convert(const ParticipantManagement::Participant &part, int exerciseId, const QMap &allParticipants) const { IWMS2ECC::PlayerInfo pi; pi.alias = QString::fromStdString(part.identification); pi.assignState = convert(part.assignState); pi.designator = QString::fromStdString(part.designator); if (part.equipmentNumber.is_set()) pi.equipNo = part.equipmentNumber.get(); else if (part.assignState == ParticipantManagement::ParticipantAssignState::HandoutExcon) pi.equipNo = 0; pi.exerciseId = exerciseId; pi.forceId = part.partyId; DEBUG_LOG(m_logger) << "Force Id = " << pi.forceId; pi.info = QString::fromStdString(part.info); pi.parentPlayerId = part.superiorId; pi.playerId = part.id; pi.playerState = part.isDeleted ? IWMS2ECC::PlayerState::DELETED : IWMS2ECC::PlayerState::FOUND; pi.tactIdent = QString::fromStdString(part.tacticalIdentifier); const ParticipantManagement::Type partType = m_exercisesHandler->participantType(part.typeId); if (partType.id == part.typeId) { pi.equipTypeId = partType.equipmentTypeId; pi.typeClassId = convert(partType.typeClass); TRACE_LOG(m_logger) << "Found participant type with id " << part.typeId << ", " << pi.typeClassId << ", " << pi.equipTypeId; } else WARNING_LOG(m_logger) << "Can not find participant type with id " << part.typeId; pi.typeId = part.typeId; pi.isDeleted = part.isDeleted; pi.hierarchy = m_exercisesHandler->getHierarchyFromParticipant(part.id, exerciseId, allParticipants); const ParticipantManagement::Party party = m_exercisesHandler->getParty(part.partyId, exerciseId); pi.forceName = QString::fromStdString(party.name); pi.symbolColor = party.color; DEBUG_LOG(m_logger) << "party.name: " << pi.forceName; DEBUG_LOG(m_logger) << "symbolColor: " << pi.symbolColor << ", playerId: " << pi.playerId << ", exerciseId: " << exerciseId; return pi; } IWMS2ECC::exerciseMap IWMS2ECC_Impl::getExercises() const { const QMap exMap = m_exercisesHandler->getExercises(); IWMS2ECC::exerciseMap retMap; for (const ExerciseManagement::Exercise &ex : exMap) { if (ex.sendToWMS) retMap.insert(ex.id, convert(ex)); } INFO_LOG(m_logger) << "IN getExercises, exMap.size(): " << exMap.size() << ", retMap.size: " << retMap.size(); return retMap; } IWMS2ECC::Exercise IWMS2ECC_Impl::getActualExercise() const { return IWMS2ECC::Exercise(); } int IWMS2ECC_Impl::getPlayerId(int equipNo, int exerciseId) const { Q_ASSERT(false); Q_UNUSED(equipNo); Q_UNUSED(exerciseId); return -1; } int IWMS2ECC_Impl::getEquipNo(int playerId, int exerciseId) const { Q_ASSERT(false); Q_UNUSED(playerId); Q_UNUSED(exerciseId); return -1; } QMap IWMS2ECC_Impl::getAllPlayers(int exerciseId) const { return getAllParticipants(exerciseId); } QMap IWMS2ECC_Impl::getAllParticipants(int exerciseId) const { INFO_LOG(m_logger) << "IN getAllParticipants"; QMap retMap; const QMap map = m_exercisesHandler->getParticipants(exerciseId); INFO_LOG(m_logger) << "getAllPlayers map.size() : " << map.size(); for (const ParticipantManagement::Participant &exePart : map) { IWMS2ECC::PlayerInfo pi = convert(exePart, exerciseId, map); pi.playerId = (exerciseId * 1000000) + pi.playerId; pi.parentPlayerId = (exerciseId * 1000000) + pi.parentPlayerId; if (pi.playerState == PlayerState::FOUND) retMap.insert(pi.playerId, pi); } return retMap; } QMap IWMS2ECC_Impl::getAllVehicles(int exerciseId) const { Q_ASSERT(false); Q_UNUSED(exerciseId); return {}; } IWMS2ECC::RegisterReturnValue IWMS2ECC_Impl::registerPlayer(int playerId, int equipNo, const IWMS2ECC::PlayerAssignState &playerAssignState, const QString &alias, const QString &info, int exerciseId) { ParticipantManagement::ParticipantAssignState assignState = convert(playerAssignState); m_exercisesHandler->registerParticipant(exerciseId, playerId, assignState, equipNo, alias, info); return IWMS2ECC::RegistrationFailed; } void IWMS2ECC_Impl::onRegistrationReturnValue(int exerciseId, qint32 participantId, ParticipantManagement::RegisterReturnValue retValue) { INFO_LOG(m_logger) << "IN onRegistrationReturnValue "; INFO_LOG(m_logger) << "exerciseId: " << exerciseId << ", participantId: " << participantId << ", retValue: " << retValue; emit registrationReturnValue(exerciseId, participantId, convert(retValue)); } IWMS2ECC::UnregisterReturnValue IWMS2ECC_Impl::unregister(int equipNo, int exerciseId) { if (!m_exercisesHandler->unregisterParticipant(exerciseId, equipNo)) return IWMS2ECC::UnregisterFailed; return IWMS2ECC::UnregisterOk; } IWMS2ECC::PlayerInfo IWMS2ECC_Impl::getPlayerInfo(int playerId, int exerciseId) { DEBUG_LOG(m_logger) << "IN getPlayerInfo: " << " playerId = " << playerId << ", exerciseId = " << exerciseId; if (playerId <= 0 || exerciseId <= 0) { WARNING_LOG(m_logger) << "Invalid Player (0,0)"; IWMS2ECC::PlayerInfo pi; pi.playerState = NOT_FOUND; return pi; } ParticipantManagement::Participant part = m_exercisesHandler->getParticipant(playerId, exerciseId); IWMS2ECC::PlayerInfo pi; if (part.assignState == ParticipantManagement::ParticipantAssignState::HandoutExcon) { pi.playerState = NOT_FOUND; return pi; } pi = convert(part, exerciseId); pi.forceName = QString::fromStdString(m_exercisesHandler->getParty(part.partyId, exerciseId).name); pi.playerState = FOUND; INFO_LOG(m_logger) << "Player (" << pi.playerId << "," << exerciseId << ") found: " << "AssignState: " << pi.assignState << ", forceName: " << pi.forceName; return pi; } QMap IWMS2ECC_Impl::getEquipRequirements(int exerciseId) const { const QMap map = m_exercisesHandler->getParticipants(exerciseId); INFO_LOG(m_logger) << "getAllPlayers map.size() : " << map.size(); QMap reqPartTypes; for (const ParticipantManagement::Participant &part : map) { if (part.isDeleted) continue; reqPartTypes[part.typeId]++; } QMap reqEquipTypes; QMap::ConstIterator cIt = reqPartTypes.constBegin(); for (; cIt != reqPartTypes.constEnd(); ++cIt) { const int typeId = cIt.key(); const ParticipantManagement::Type partType = m_exercisesHandler->participantType(typeId); if (partType.id == typeId) { DEBUG_LOG(m_logger) << "Key: " << typeId; ParticipantManagement::TypeClass typeClass = partType.typeClass; int equipTypeId = partType.equipmentTypeId; if (typeClass != ParticipantManagement::TypeClass::Unit && typeClass != ParticipantManagement::TypeClass::SupportUnit) { reqEquipTypes[equipTypeId] = cIt.value(); DEBUG_LOG(m_logger) << "equipTypeId: " << equipTypeId << ", amount: " << cIt.value(); } } else WARNING_LOG(m_logger) << "Can not find participant type with id " << typeId; } return reqEquipTypes; } int IWMS2ECC_Impl::getTypeClassId(int equipTypeId) const { return convert(m_exercisesHandler->typeClassIdFromEquipmentTypeId(equipTypeId)); } QByteArray IWMS2ECC_Impl::getSymbol(int symbolId, int exerciseId, const QColor &color, int role) const { Q_ASSERT(false); Q_UNUSED(symbolId); Q_UNUSED(exerciseId); Q_UNUSED(color); Q_UNUSED(role); return {}; } IWMS2ECC::EquipmentType IWMS2ECC_Impl::convert(const ParticipantManagement::EquipmentType &et) { IWMS2ECC::EquipmentType ret; ret.id = et.id; ret.name = QString::fromStdString(et.name); ret.minEquipNo = et.minEquipNo; ret.maxEquipNo = et.maxEquipNo; ret.specialType = static_cast(et.wmsTypeClass); ret.taVulnerabilityModelId = et.traVulnerabilityModelId; ret.taPlayerTypeId = et.traPlayerTypeId; ret.deletedInWMS = et.deletedInWms; return ret; } ParticipantManagement::EquipmentType IWMS2ECC_Impl::convert(const IWMS2ECC::EquipmentType &et) { ParticipantManagement::EquipmentType ret; ret.id = et.id; ret.name = et.name.toStdString(); ret.minEquipNo = et.minEquipNo; ret.maxEquipNo = et.maxEquipNo; ParticipantManagement::WmsTypeClass wmsTypeClass = convert(et.specialType); ret.wmsTypeClass = wmsTypeClass; ret.traVulnerabilityModelId = et.taVulnerabilityModelId; ret.traPlayerTypeId = et.taPlayerTypeId; ret.deletedInWms = et.deletedInWMS; return ret; } ParticipantManagement::WmsTypeClass IWMS2ECC_Impl::convert(int specialType) { switch (specialType) { case 0: return ParticipantManagement::WmsTypeClass::None; case 1: return ParticipantManagement::WmsTypeClass::Building; case 2: return ParticipantManagement::WmsTypeClass::Vehicle; case 3: return ParticipantManagement::WmsTypeClass::Human; case 4: return ParticipantManagement::WmsTypeClass::TargetVehicle; case 5: return ParticipantManagement::WmsTypeClass::TargetHuman; case 6: return ParticipantManagement::WmsTypeClass::Airborne; case 7: return ParticipantManagement::WmsTypeClass::VehicleMarker; default: Q_ASSERT(false); break; } return ParticipantManagement::WmsTypeClass::None; } ParticipantManagement::TypeClass IWMS2ECC_Impl::convertTypeClass(int typeClass) { switch (typeClass) { case 1: return ParticipantManagement::TypeClass::Unit; case 2: return ParticipantManagement::TypeClass::VehicleWithGear; case 3: case 4: return ParticipantManagement::TypeClass::GroundVehicle; case 5: return ParticipantManagement::TypeClass::Human; case 6: case 7: return ParticipantManagement::TypeClass::SupportEntity; case 8: return ParticipantManagement::TypeClass::Aircraft; case 10: return ParticipantManagement::TypeClass::SupportUnit; default: Q_ASSERT(false); break; } return ParticipantManagement::TypeClass::Unit; } int IWMS2ECC_Impl::convert(ParticipantManagement::TypeClass typeClass) { switch (typeClass) { case ParticipantManagement::TypeClass::Unknown: return 0; case ParticipantManagement::TypeClass::Unit: return 1; case ParticipantManagement::TypeClass::Human: return 5; case ParticipantManagement::TypeClass::VehicleWithGear: case ParticipantManagement::TypeClass::WeaponSystem: return 2; case ParticipantManagement::TypeClass::GroundVehicle: return 3; case ParticipantManagement::TypeClass::SupportUnit: return 10; case ParticipantManagement::TypeClass::SupportEntity: return 7; case ParticipantManagement::TypeClass::Aircraft: return 8; default: Q_ASSERT(false); break; } return 1; } bool IWMS2ECC_Impl::setEquipmentType(const EquipmentType &et) { std::vector vEquipTypes; const ParticipantManagement::EquipmentType &etData = convert(et); vEquipTypes.push_back(etData); return m_exercisesHandler->modifyEquipmentTypes(vEquipTypes); } bool IWMS2ECC_Impl::setEquipmentTypes(const equipTypeMap &map) { INFO_LOG(m_logger) << "IN setEquipmentTypes: equipMap.size: " << map.size(); std::vector vEquipTypes; vEquipTypes.reserve(map.size()); for (const IWMS2ECC::EquipmentType &et : map) vEquipTypes.push_back(convert(et)); return m_exercisesHandler->modifyEquipmentTypes(vEquipTypes); } IWMS2ECC::PlayerAssignState IWMS2ECC_Impl::convert(const ParticipantManagement::ParticipantAssignState &state) { switch (state) { case ParticipantManagement::ParticipantAssignState::NotAssigned: return IWMS2ECC::NOT_ASSIGNED; case ParticipantManagement::ParticipantAssignState::AssignedWms: return IWMS2ECC::ASSIGNED; case ParticipantManagement::ParticipantAssignState::HandoutWms: return IWMS2ECC::HANDOUT_WMS; case ParticipantManagement::ParticipantAssignState::HandoutExcon: return IWMS2ECC::HANDOUT_EXCON; case ParticipantManagement::ParticipantAssignState::ExconWmsOverruled: return IWMS2ECC::HANDOUT_EXCON_OVERRULED_WMS; } Q_ASSERT(false); return IWMS2ECC::UNDEFINED; } ParticipantManagement::ParticipantAssignState IWMS2ECC_Impl::convert(const IWMS2ECC::PlayerAssignState &state) { switch (state) { case IWMS2ECC::UNDEFINED: return ParticipantManagement::ParticipantAssignState::NotAssigned; case IWMS2ECC::NOT_ASSIGNED: return ParticipantManagement::ParticipantAssignState::NotAssigned; case IWMS2ECC::ASSIGNED: return ParticipantManagement::ParticipantAssignState::AssignedWms; case IWMS2ECC::HANDOUT_WMS: return ParticipantManagement::ParticipantAssignState::HandoutWms; case IWMS2ECC::HANDOUT_EXCON: return ParticipantManagement::ParticipantAssignState::HandoutExcon; case IWMS2ECC::HANDOUT_EXCON_OVERRULED_WMS: return ParticipantManagement::ParticipantAssignState::ExconWmsOverruled; } Q_ASSERT(false); return ParticipantManagement::ParticipantAssignState::NotAssigned; } IWMS2ECC::RegisterReturnValue IWMS2ECC_Impl::convert(const ParticipantManagement::RegisterReturnValue retValue) { switch (retValue) { case ParticipantManagement::RegisterReturnValue::AssignmentIncorrect: return IWMS2ECC::AssignmentIncorrect; case ParticipantManagement::RegisterReturnValue::PlayerDeleted: return IWMS2ECC::PlayerDeleted; case ParticipantManagement::RegisterReturnValue::PlayerNotFound: return IWMS2ECC::PlayerNotFound; case ParticipantManagement::RegisterReturnValue::RegistrationFailed: return IWMS2ECC::RegistrationFailed; case ParticipantManagement::RegisterReturnValue::RegistrationOk: return IWMS2ECC::RegistrationOk; case ParticipantManagement::RegisterReturnValue::EquipNoAlreadyAssigned: return IWMS2ECC::EquipNoAlreadyAssigned; } Q_ASSERT(false); return IWMS2ECC::RegistrationFailed; } }