diff --git a/emf_datamodel/model/iPos_Datamodel.aird b/emf_datamodel/model/iPos_Datamodel.aird index 3b55cb5b7e207f87639f402db7e6486ef46de5a2..daf35f0f2aed888c08b25f077b8b38106da7bf48 100644 --- a/emf_datamodel/model/iPos_Datamodel.aird +++ b/emf_datamodel/model/iPos_Datamodel.aird @@ -5,7 +5,7 @@ <semanticResources>iPos_Datamodel.genmodel</semanticResources> <ownedViews xmi:type="viewpoint:DView" uid="_EpwecAQNEey-kNQ7esRa_g"> <viewpoint xmi:type="description:Viewpoint" href="platform:/plugin/org.eclipse.emf.ecoretools.design/description/ecore.odesign#//@ownedViewpoints[name='Design']"/> - <ownedRepresentationDescriptors xmi:type="viewpoint:DRepresentationDescriptor" uid="_Et4wgAQNEey-kNQ7esRa_g" name="iPos_Datamodel" repPath="#_Es-xkAQNEey-kNQ7esRa_g" changeId="9e1b7476-c4ed-4af9-bf42-c1e58844c8c1"> + <ownedRepresentationDescriptors xmi:type="viewpoint:DRepresentationDescriptor" uid="_Et4wgAQNEey-kNQ7esRa_g" name="iPos_Datamodel" repPath="#_Es-xkAQNEey-kNQ7esRa_g" changeId="5e294dee-965d-4b3c-986d-efa88a70016f"> <description xmi:type="description_1:DiagramDescription" href="platform:/plugin/org.eclipse.emf.ecoretools.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities']"/> <target xmi:type="ecore:EPackage" href="iPos_Datamodel.ecore#/"/> </ownedRepresentationDescriptors> @@ -630,6 +630,10 @@ <styles xmi:type="notation:FontStyle" xmi:id="_91n0IRr1EeyPOIo-WqURQQ" fontColor="2697711" fontName="Segoe UI" fontHeight="8"/> <layoutConstraint xmi:type="notation:Location" xmi:id="_91n0Ihr1EeyPOIo-WqURQQ"/> </children> + <children xmi:type="notation:Node" xmi:id="_iS0HQCXpEeyb5750APOSQw" type="3010" element="_iRkKECXpEeyb5750APOSQw"> + <styles xmi:type="notation:FontStyle" xmi:id="_iS0HQSXpEeyb5750APOSQw" fontColor="2697711" fontName="Segoe UI" fontHeight="8"/> + <layoutConstraint xmi:type="notation:Location" xmi:id="_iS0HQiXpEeyb5750APOSQw"/> + </children> <styles xmi:type="notation:SortingStyle" xmi:id="_Ml864QcsEey-kNQ7esRa_g"/> <styles xmi:type="notation:FilteringStyle" xmi:id="_Ml864gcsEey-kNQ7esRa_g"/> </children> @@ -2766,7 +2770,7 @@ <arrangeConstraints>KEEP_LOCATION</arrangeConstraints> <arrangeConstraints>KEEP_SIZE</arrangeConstraints> <arrangeConstraints>KEEP_RATIO</arrangeConstraints> - <ownedStyle xmi:type="diagram:FlatContainerStyle" uid="_GrDD1SB0EeyaJIyxidrtuQ" borderSize="1" borderSizeComputationExpression="1" backgroundStyle="Liquid" foregroundColor="255,252,216"> + <ownedStyle xmi:type="diagram:FlatContainerStyle" uid="_kGqDfiXpEeyb5750APOSQw" borderSize="1" borderSizeComputationExpression="1" backgroundStyle="Liquid" foregroundColor="255,252,216"> <description xmi:type="style:FlatContainerStyleDescription" href="platform:/plugin/org.eclipse.emf.ecoretools.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities']/@defaultLayer/@containerMappings[name='EC%20EClass']/@style"/> </ownedStyle> <actualMapping xmi:type="description_1:ContainerMapping" href="platform:/plugin/org.eclipse.emf.ecoretools.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities']/@defaultLayer/@containerMappings[name='EC%20EClass']"/> @@ -2786,6 +2790,14 @@ </ownedStyle> <actualMapping xmi:type="description_1:NodeMapping" href="platform:/plugin/org.eclipse.emf.ecoretools.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities']/@defaultLayer/@containerMappings[name='EC%20EClass']/@subNodeMappings[name='EC%20EAttribute']"/> </ownedElements> + <ownedElements xmi:type="diagram:DNodeListElement" uid="_iRkKECXpEeyb5750APOSQw" name="id : EString" tooltipText=""> + <target xmi:type="ecore:EAttribute" href="iPos_Datamodel.ecore#//POI/id"/> + <semanticElements xmi:type="ecore:EAttribute" href="iPos_Datamodel.ecore#//POI/id"/> + <ownedStyle xmi:type="diagram:BundledImage" uid="_kGwKFSXpEeyb5750APOSQw" labelAlignment="LEFT"> + <description xmi:type="style:BundledImageDescription" href="platform:/plugin/org.eclipse.emf.ecoretools.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities']/@defaultLayer/@containerMappings[name='EC%20EClass']/@subNodeMappings[name='EC%20EAttribute']/@style"/> + </ownedStyle> + <actualMapping xmi:type="description_1:NodeMapping" href="platform:/plugin/org.eclipse.emf.ecoretools.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities']/@defaultLayer/@containerMappings[name='EC%20EClass']/@subNodeMappings[name='EC%20EAttribute']"/> + </ownedElements> </ownedDiagramElements> <ownedDiagramElements xmi:type="diagram:DEdge" uid="_RCvPUgcsEey-kNQ7esRa_g" name="[1..1] position" sourceNode="_Mlx7wAcsEey-kNQ7esRa_g" targetNode="_foX_AAQjEey-kNQ7esRa_g"> <target xmi:type="ecore:EReference" href="iPos_Datamodel.ecore#//POI/position"/> diff --git a/emf_datamodel/model/iPos_Datamodel.ecore b/emf_datamodel/model/iPos_Datamodel.ecore index c52f2a43b1630c4f375980c943bd145a8503d1a6..f18d51462d84ce8589589c0ea331c805539169cc 100644 --- a/emf_datamodel/model/iPos_Datamodel.ecore +++ b/emf_datamodel/model/iPos_Datamodel.ecore @@ -216,6 +216,7 @@ <eTypeArguments eClassifier="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> </eGenericType> </eStructuralFeatures> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="id" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> </eClassifiers> <eClassifiers xsi:type="ecore:EClass" name="EventFilterCondition"> <eStructuralFeatures xsi:type="ecore:EAttribute" name="timeCondition" eType="#//StringArray" diff --git a/emf_datamodel/model/iPos_Datamodel.genmodel b/emf_datamodel/model/iPos_Datamodel.genmodel index 18b60791953fd6f6a293ba85eba4b38515dae812..26de11f17c0366df16d3193417fb8151f788b2a7 100644 --- a/emf_datamodel/model/iPos_Datamodel.genmodel +++ b/emf_datamodel/model/iPos_Datamodel.genmodel @@ -167,6 +167,7 @@ <genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference iPos_Datamodel.ecore#//POI/position"/> <genFeatures createChild="false" ecoreFeature="ecore:EAttribute iPos_Datamodel.ecore#//POI/description"/> <genFeatures createChild="false" ecoreFeature="ecore:EAttribute iPos_Datamodel.ecore#//POI/data"/> + <genFeatures createChild="false" ecoreFeature="ecore:EAttribute iPos_Datamodel.ecore#//POI/id"/> </genClasses> <genClasses ecoreClass="iPos_Datamodel.ecore#//EventFilterCondition"> <genFeatures createChild="false" ecoreFeature="ecore:EAttribute iPos_Datamodel.ecore#//EventFilterCondition/timeCondition"/> diff --git a/init_Industrierobotik.txt b/init_Industrierobotik.txt new file mode 100644 index 0000000000000000000000000000000000000000..708c89989ccb40c6086ea836f0a524328d9ee9e5 --- /dev/null +++ b/init_Industrierobotik.txt @@ -0,0 +1,5 @@ +{"frames": [{"id": "cobot1_door_zone", "space": [{"position": {"refSystemId": "ROOT", "point": {"x": 2.0,"y": 0.0,"z": 0.0}, "accuracy": 1.0}, "orientation": {"x": 1.0,"y": 0.5,"z": 1.0, "w": 1.5}, "x": 4.0, "y": 4.0, "z":6.0}]}, {"id": "cobot1_window_zone", "space": [{"position": {"refSystemId": "ROOT", "point": {"x": 2.0,"y": 4.0,"z": 0.0}, "accuracy": 1.0}, "orientation": {"x": 1.0,"y": 0.5,"z": 1.0, "w": 1.5}, "x": 2.0, "y": 2.0, "z":6.0}]} ]} +{"refSystems": [{"id": "ROOT"}, {"id": "CETI_ROOT", "position": {"refSystemId": "ROOT", "point": {"x": 3.05,"y": 2.08,"z": 0.0}, "accuracy": 1.0}, "orientation": {"x": 0.0,"y": 0.0,"z": 0.0, "w": 0.0}}]} +{"objectConfigs": [{"agentId": "Employee1", "sensorId": "UWB_1", "agentType": "HUMAN", "sensorType": "UWB"}, {"agentId": "Employee2", "sensorId": "UWB_2", "agentType": "HUMAN", "sensorType": "UWB"}]} +{"pois": [{"id": "UWB_BEACON_1", "description": "Beacon_Position", "data": {"type" : "UWB"}, "position": {"refSystemId": "ROOT", "point": {"x": 3.1,"y": 0.5,"z": 0.0}, "accuracy": 1.0} }, {"id": "UWB_BEACON_2", "description": "Beacon_Position", "data": {"type" : "UWB"}, "position": {"refSystemId": "ROOT", "point": {"x": -0.3,"y": 4.5,"z": 0.0}, "accuracy": 1.0} } ]} +{"monitoringRequests": [{"frameId": "cobot1_door_zone", "monitoringTaskId": "Human_at_Door_Side"}, {"frameId": "cobot1_window_zone", "monitoringTaskId": "Human_at_Window_Side"}]} \ No newline at end of file diff --git a/init_Sensordatenfusion.txt b/init_Sensordatenfusion.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/main/java/ipos/project/DataModellntegration/SimpleSceneIntegration/SimpleSceneIntegration.java b/src/main/java/ipos/project/DataModellntegration/SimpleSceneIntegration/SimpleSceneIntegration.java index af5fd0b9a79b09b5688f53a069836312423daa52..c5026c95c73379d7b48d3f4d423df0495af9c6a6 100644 --- a/src/main/java/ipos/project/DataModellntegration/SimpleSceneIntegration/SimpleSceneIntegration.java +++ b/src/main/java/ipos/project/DataModellntegration/SimpleSceneIntegration/SimpleSceneIntegration.java @@ -1,15 +1,25 @@ package ipos.project.DataModellntegration.SimpleSceneIntegration; +import com.google.protobuf.InvalidProtocolBufferException; import ipos.models.SimpleScene; +import ipos.project.DataModellntegration.SimpleSceneIntegration.api.MqttRequestHandler; import ipos.project.DataModellntegration.SimpleSceneIntegration.service.SimpleSceneTransformer; import ipos.project.DataModellntegration.SimpleSceneIntegration.service.impl.ExternalPubServiceImpl; import ipos.project.DataModellntegration.iPos_Datamodel.PositionEvent; +import ipos.project.UseCaseController.Administration; import ipos.project.mapper.ProtoJsonMap; import org.apache.logging.log4j.LogManager; import org.eclipse.paho.client.mqttv3.MqttMessage; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + @Component public class SimpleSceneIntegration { // private static final Logger LOG = LoggerFactory.getLogger(SimpleSceneIntegration.class); @@ -18,6 +28,42 @@ public class SimpleSceneIntegration { //@Autowired public static ExternalPubServiceImpl mqttService; + public static void init(){ + Administration.initialize(); + } + + public static void init(String path_to_init_data_file){ + Administration.initialize(); // clears WorldModel + File initFile = new File("./init_Industrierobotik.txt"); + try { + for (String line : readLines(initFile)) { + SimpleScene.IposConfigWrapper iposConfigWrapper = ProtoJsonMap.fromJson(line, SimpleScene.IposConfigWrapper.class); + MqttRequestHandler.handleConfigWrapper(iposConfigWrapper); + } + }catch (InvalidProtocolBufferException e) { + LOG.error("Error trying to read JSON into protobuf-objects: "); + e.printStackTrace(); + } + } + + /** + * As opposed to the Stream<String>-approach using this approach reads the lines in order + * @param initFile + * @return + */ + private static List<String> readLines(File initFile) { + List<String> lines = new ArrayList<>(); + try(BufferedReader br = new BufferedReader(new FileReader(initFile))) { // br is automatically closed at the end of try-scope + for (String line; (line = br.readLine()) != null; ){ + lines.add(line); + } + } catch (IOException e) { + LOG.error("Error while reading the text file: "); + e.printStackTrace(); + } + return lines; + } + @Autowired public SimpleSceneIntegration(ExternalPubServiceImpl mqttService_){ mqttService = mqttService_; @@ -35,20 +81,19 @@ public class SimpleSceneIntegration { }*/ public static void receiveMessage(PositionEvent positionEvent, String monitoringTaskId, String type) { - // LOG.info("receiveMessage get: " + positionEvent); //String jsonPos = ProtoJsonMap.toJson(positionEvent); // we can translate a class into a string using several methods: 1) `.toString()` 2) `JsonFormat` in `ProtoJsonMap` if (positionEvent != null) { - // LOG.info("received internal-positionEvent: monitoringTaskId: " + monitoringTaskId + " positionEvent: " + positionEvent.toString()); SimpleScene.IposPositionEvent posEvent_proto = SimpleSceneTransformer.posEvent_internal2Proto(positionEvent, type); - // LOG.info("obtained protobuf-positionEvent:" + posEvent_proto.toString()); MqttMessage mqttMessage = mqttService.createMqttMsg(posEvent_proto, 0, false); - // LOG.info("publishing mqttMessage:" + mqttMessage.toString() + " on topic: " + monitoringTaskId); - mqttService.publish(monitoringTaskId, mqttMessage); - LOG.info("publishing protobuf mqttMessage. JSON-representation:" + ProtoJsonMap.toJson(posEvent_proto) + " on topic: " + monitoringTaskId); + // publishes protobuf over MQTT + // mqttService.publish(monitoringTaskId, mqttMessage); + // LOG.info("publishing protobuf mqttMessage. JSON-representation:" + ProtoJsonMap.toJson(posEvent_proto) + " on topic: " + monitoringTaskId); + + // publishes JSON over MQTT + mqttService.publish(monitoringTaskId, ProtoJsonMap.toJson(posEvent_proto), 0, false); + LOG.info("publishing JSON mqttMessage:" + ProtoJsonMap.toJson(posEvent_proto) + " on topic: " + monitoringTaskId); - //LOG.info("publishing mqttMessage:" + ProtoJsonMap.toJson(posEvent_proto) + " on topic: " + monitoringTaskId); - // mqttService.publish(monitoringTaskId, ProtoJsonMap.toJson(posEvent_proto), 0, false); }else{ LOG.warn("Warning: SimpleScene: Received empty PositionEvent"); } diff --git a/src/main/java/ipos/project/DataModellntegration/SimpleSceneIntegration/api/MqttRequestHandler.java b/src/main/java/ipos/project/DataModellntegration/SimpleSceneIntegration/api/MqttRequestHandler.java index 7bee87cc87332fe77c5cb48f4fa8e4995aab0e2a..d316f8df12ca436b0e9fa6cd55ddb23d77025dce 100644 --- a/src/main/java/ipos/project/DataModellntegration/SimpleSceneIntegration/api/MqttRequestHandler.java +++ b/src/main/java/ipos/project/DataModellntegration/SimpleSceneIntegration/api/MqttRequestHandler.java @@ -36,21 +36,25 @@ public class MqttRequestHandler implements Handler { // TODO: Zwischen JSON und Protobuf unterscheiden können SimpleScene.IposConfigWrapper iposConfigWrapper = ProtoJsonMap.fromJson(message.toString(), SimpleScene.IposConfigWrapper.class); // IposMonitoringRequest monReqProto = IposMonitoringRequest.parseFrom(message.getPayload()); - LOG.info("IposConfigWrapper received: \n" - + iposConfigWrapper.toString()); - // Annahme: iposConfigWrapper enthält für leere Felder leere Listen und nicht null - processMonitoringRequests(iposConfigWrapper); - processRefSystems(iposConfigWrapper.getRefSystemsList()); - processFrameConfigs(iposConfigWrapper.getFramesList()); // should be done not before refSystem-processing, as it might require one of the processed refSystems - processObjectConfigs(iposConfigWrapper.getObjectConfigsList()); - processPois(iposConfigWrapper.getPoisList()); - - // this.jmsTemplate.convertAndSend("/request123", monReqInternal); // submit request to the internal broker + handleConfigWrapper(iposConfigWrapper); } catch (InvalidProtocolBufferException e) { e.printStackTrace(); } } + public static void handleConfigWrapper(SimpleScene.IposConfigWrapper iposConfigWrapper) { + LOG.info("IposConfigWrapper received: \n" + + iposConfigWrapper.toString()); + // Annahme: iposConfigWrapper enthält für leere Felder leere Listen und nicht null + processMonitoringRequests(iposConfigWrapper); + processRefSystems(iposConfigWrapper.getRefSystemsList()); + processFrameConfigs(iposConfigWrapper.getFramesList()); // should be done not before refSystem-processing, as it might require one of the processed refSystems + processObjectConfigs(iposConfigWrapper.getObjectConfigsList()); + processPois(iposConfigWrapper.getPoisList()); + + // this.jmsTemplate.convertAndSend("/request123", monReqInternal); // submit request to the internal broker + } + /* private SimpleScene.IposConfigWrapper replaceNullByEmptyList(SimpleScene.IposConfigWrapper configWrapper) { SimpleScene.IposConfigWrapper.Builder configWrapper_NoNull = SimpleScene.IposConfigWrapper.newBuilder(); @@ -58,28 +62,28 @@ public class MqttRequestHandler implements Handler { } */ - private void processPois(List<SimpleScene.POI> poisList) { + private static void processPois(List<SimpleScene.POI> poisList) { for (SimpleScene.POI poi : poisList){ POI poi_internal = SimpleSceneTransformer.poi_SScene2Internal(poi); Administration.handlePoi(poi_internal); } } - private void processRefSystems(List<SimpleScene.RefSystem> refSystemsList) { + private static void processRefSystems(List<SimpleScene.RefSystem> refSystemsList) { for (SimpleScene.RefSystem refSystem : refSystemsList){ ReferenceSystem refSystem_internal = SimpleSceneTransformer.refSystem_SScene2Internal(refSystem); Administration.handleRefSystem(refSystem_internal); } } - private void processObjectConfigs(List<SimpleScene.IposObjectConfig> objectConfigsList) { + private static void processObjectConfigs(List<SimpleScene.IposObjectConfig> objectConfigsList) { for( SimpleScene.IposObjectConfig objConfig : objectConfigsList){ Agent agent = SimpleSceneTransformer.agent_SScene2Internal(objConfig); Administration.handleAgent(agent); } } - private void processFrameConfigs(List<SimpleScene.IposFrameConfig> frames){ + private static void processFrameConfigs(List<SimpleScene.IposFrameConfig> frames){ /* if (null == frames){ LOG.info("ConfigWrapper-message contains no Frame-definitions"); @@ -92,7 +96,7 @@ public class MqttRequestHandler implements Handler { } } - private void processMonitoringRequests(SimpleScene.IposConfigWrapper iposConfigWrapper) { + private static void processMonitoringRequests(SimpleScene.IposConfigWrapper iposConfigWrapper) { for (IposMonitoringRequest monReq : iposConfigWrapper.getMonitoringRequestsList()){ MonitoringRequest monReqInternal = SimpleSceneTransformer.monReq_SScene2Internal(monReq); PositionMonitoring.receiveMessage(monReqInternal); diff --git a/src/main/java/ipos/project/DataModellntegration/SimpleSceneIntegration/service/SimpleSceneTransformer.java b/src/main/java/ipos/project/DataModellntegration/SimpleSceneIntegration/service/SimpleSceneTransformer.java index 43dd1a52552aab190d7c6838f1324bb055c16871..4f9b62869eb3417b855ead852e5fd70d9b5ce0c0 100644 --- a/src/main/java/ipos/project/DataModellntegration/SimpleSceneIntegration/service/SimpleSceneTransformer.java +++ b/src/main/java/ipos/project/DataModellntegration/SimpleSceneIntegration/service/SimpleSceneTransformer.java @@ -121,7 +121,7 @@ public class SimpleSceneTransformer { } private static Orientation orientation_SScene2Internal(SimpleScene.IposSimpleOrientation orientation_proto) { - Quaternion orientation = (Quaternion) modelFactory.createOrientation(); + Quaternion orientation = modelFactory.createQuaternion(); orientation.setX(orientation_proto.getX()); orientation.setY(orientation_proto.getY()); orientation.setZ(orientation_proto.getZ()); @@ -172,8 +172,8 @@ public class SimpleSceneTransformer { public static ReferenceSystem refSystem_SScene2Internal(SimpleScene.RefSystem refSystem_proto) { ReferenceSystem refSystem = modelFactory.createReferenceSystem(); - refSystem.setId(refSystem.getId()); - refSystem.setName(refSystem.getId()); + refSystem.setId(refSystem_proto.getId()); + refSystem.setName(refSystem_proto.getId()); if (null != refSystem_proto.getPosition() && null != refSystem_proto.getOrientation()) { refSystem.setOrigin(placing_SScene2Internal(refSystem_proto.getPosition(), refSystem_proto.getOrientation())); } @@ -182,6 +182,7 @@ public class SimpleSceneTransformer { public static POI poi_SScene2Internal(SimpleScene.POI poi_proto) { POI poi = modelFactory.createPOI(); + poi.setId(poi_proto.getId()); poi.setDescription(poi_proto.getDescription()); poi.setData(poi_proto.getDataMap()); poi.setPosition(position_SScene2Internal(poi_proto.getPosition())); diff --git a/src/main/java/ipos/project/DataModellntegration/iPos_Datamodel/IPos_DatamodelPackage.java b/src/main/java/ipos/project/DataModellntegration/iPos_Datamodel/IPos_DatamodelPackage.java index 9584236628340a4d6f02cfca00454e7ffc68c09c..ab41f0eac36cb3ff6df0c3148bb72014e5a1c386 100644 --- a/src/main/java/ipos/project/DataModellntegration/iPos_Datamodel/IPos_DatamodelPackage.java +++ b/src/main/java/ipos/project/DataModellntegration/iPos_Datamodel/IPos_DatamodelPackage.java @@ -2282,6 +2282,15 @@ public interface IPos_DatamodelPackage extends EPackage { */ int POI__DATA = 2; + /** + * The feature id for the '<em><b>Id</b></em>' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + int POI__ID = 3; + /** * The number of structural features of the '<em>POI</em>' class. * <!-- begin-user-doc --> @@ -2289,7 +2298,7 @@ public interface IPos_DatamodelPackage extends EPackage { * @generated * @ordered */ - int POI_FEATURE_COUNT = 3; + int POI_FEATURE_COUNT = 4; /** * The number of operations of the '<em>POI</em>' class. @@ -3769,6 +3778,17 @@ public interface IPos_DatamodelPackage extends EPackage { */ EAttribute getPOI_Data(); + /** + * Returns the meta object for the attribute '{@link ipos.project.DataModellntegration.iPos_Datamodel.POI#getId <em>Id</em>}'. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the meta object for the attribute '<em>Id</em>'. + * @see ipos.project.DataModellntegration.iPos_Datamodel.POI#getId() + * @see #getPOI() + * @generated + */ + EAttribute getPOI_Id(); + /** * Returns the meta object for class '{@link ipos.project.DataModellntegration.iPos_Datamodel.EventFilterCondition <em>Event Filter Condition</em>}'. * <!-- begin-user-doc --> @@ -5045,6 +5065,14 @@ public interface IPos_DatamodelPackage extends EPackage { */ EAttribute POI__DATA = eINSTANCE.getPOI_Data(); + /** + * The meta object literal for the '<em><b>Id</b></em>' attribute feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + EAttribute POI__ID = eINSTANCE.getPOI_Id(); + /** * The meta object literal for the '{@link ipos.project.DataModellntegration.iPos_Datamodel.impl.EventFilterConditionImpl <em>Event Filter Condition</em>}' class. * <!-- begin-user-doc --> diff --git a/src/main/java/ipos/project/DataModellntegration/iPos_Datamodel/POI.java b/src/main/java/ipos/project/DataModellntegration/iPos_Datamodel/POI.java index f04848973526be84a96ed7718f6a28021ae0bc01..d2740a1e68e33311e4618a76f7877521fcacb629 100644 --- a/src/main/java/ipos/project/DataModellntegration/iPos_Datamodel/POI.java +++ b/src/main/java/ipos/project/DataModellntegration/iPos_Datamodel/POI.java @@ -18,6 +18,7 @@ import org.eclipse.emf.ecore.EObject; * <li>{@link ipos.project.DataModellntegration.iPos_Datamodel.POI#getPosition <em>Position</em>}</li> * <li>{@link ipos.project.DataModellntegration.iPos_Datamodel.POI#getDescription <em>Description</em>}</li> * <li>{@link ipos.project.DataModellntegration.iPos_Datamodel.POI#getData <em>Data</em>}</li> + * <li>{@link ipos.project.DataModellntegration.iPos_Datamodel.POI#getId <em>Id</em>}</li> * </ul> * * @see ipos.project.DataModellntegration.iPos_Datamodel.IPos_DatamodelPackage#getPOI() @@ -91,4 +92,26 @@ public interface POI extends EObject { */ void setData(Map<String, String> value); + /** + * Returns the value of the '<em><b>Id</b></em>' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the value of the '<em>Id</em>' attribute. + * @see #setId(String) + * @see ipos.project.DataModellntegration.iPos_Datamodel.IPos_DatamodelPackage#getPOI_Id() + * @model + * @generated + */ + String getId(); + + /** + * Sets the value of the '{@link ipos.project.DataModellntegration.iPos_Datamodel.POI#getId <em>Id</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @param value the new value of the '<em>Id</em>' attribute. + * @see #getId() + * @generated + */ + void setId(String value); + } // POI diff --git a/src/main/java/ipos/project/DataModellntegration/iPos_Datamodel/impl/IPos_DatamodelPackageImpl.java b/src/main/java/ipos/project/DataModellntegration/iPos_Datamodel/impl/IPos_DatamodelPackageImpl.java index ff856f8b09db1811b63ca6be2afe9566b6c9d48e..9f1fd854ef434375256b5c648cf43874704f3088 100644 --- a/src/main/java/ipos/project/DataModellntegration/iPos_Datamodel/impl/IPos_DatamodelPackageImpl.java +++ b/src/main/java/ipos/project/DataModellntegration/iPos_Datamodel/impl/IPos_DatamodelPackageImpl.java @@ -1597,6 +1597,15 @@ public class IPos_DatamodelPackageImpl extends EPackageImpl implements IPos_Data return (EAttribute) poiEClass.getEStructuralFeatures().get(2); } + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public EAttribute getPOI_Id() { + return (EAttribute) poiEClass.getEStructuralFeatures().get(3); + } + /** * <!-- begin-user-doc --> * <!-- end-user-doc --> @@ -1946,6 +1955,7 @@ public class IPos_DatamodelPackageImpl extends EPackageImpl implements IPos_Data createEReference(poiEClass, POI__POSITION); createEAttribute(poiEClass, POI__DESCRIPTION); createEAttribute(poiEClass, POI__DATA); + createEAttribute(poiEClass, POI__ID); eventFilterConditionEClass = createEClass(EVENT_FILTER_CONDITION); createEAttribute(eventFilterConditionEClass, EVENT_FILTER_CONDITION__TIME_CONDITION); @@ -2384,6 +2394,9 @@ public class IPos_DatamodelPackageImpl extends EPackageImpl implements IPos_Data initEAttribute(getPOI_Data(), g1, "data", null, 0, 1, ipos.project.DataModellntegration.iPos_Datamodel.POI.class, IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); + initEAttribute(getPOI_Id(), ecorePackage.getEString(), "id", null, 0, 1, + ipos.project.DataModellntegration.iPos_Datamodel.POI.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, + !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); initEClass(eventFilterConditionEClass, EventFilterCondition.class, "EventFilterCondition", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); diff --git a/src/main/java/ipos/project/DataModellntegration/iPos_Datamodel/impl/POIImpl.java b/src/main/java/ipos/project/DataModellntegration/iPos_Datamodel/impl/POIImpl.java index 047844d73e0688f0fa586aa364cf57f8b43fb4e5..407f12489808d0e1c9072676bda2c93481e446c9 100644 --- a/src/main/java/ipos/project/DataModellntegration/iPos_Datamodel/impl/POIImpl.java +++ b/src/main/java/ipos/project/DataModellntegration/iPos_Datamodel/impl/POIImpl.java @@ -27,6 +27,7 @@ import org.eclipse.emf.ecore.impl.MinimalEObjectImpl; * <li>{@link ipos.project.DataModellntegration.iPos_Datamodel.impl.POIImpl#getPosition <em>Position</em>}</li> * <li>{@link ipos.project.DataModellntegration.iPos_Datamodel.impl.POIImpl#getDescription <em>Description</em>}</li> * <li>{@link ipos.project.DataModellntegration.iPos_Datamodel.impl.POIImpl#getData <em>Data</em>}</li> + * <li>{@link ipos.project.DataModellntegration.iPos_Datamodel.impl.POIImpl#getId <em>Id</em>}</li> * </ul> * * @generated @@ -72,6 +73,26 @@ public class POIImpl extends MinimalEObjectImpl.Container implements POI { */ protected Map<String, String> data; + /** + * The default value of the '{@link #getId() <em>Id</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getId() + * @generated + * @ordered + */ + protected static final String ID_EDEFAULT = null; + + /** + * The cached value of the '{@link #getId() <em>Id</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getId() + * @generated + * @ordered + */ + protected String id = ID_EDEFAULT; + /** * <!-- begin-user-doc --> * <!-- end-user-doc --> @@ -174,6 +195,27 @@ public class POIImpl extends MinimalEObjectImpl.Container implements POI { eNotify(new ENotificationImpl(this, Notification.SET, IPos_DatamodelPackage.POI__DATA, oldData, data)); } + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public String getId() { + return id; + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public void setId(String newId) { + String oldId = id; + id = newId; + if (eNotificationRequired()) + eNotify(new ENotificationImpl(this, Notification.SET, IPos_DatamodelPackage.POI__ID, oldId, id)); + } + /** * <!-- begin-user-doc --> * <!-- end-user-doc --> @@ -190,6 +232,8 @@ public class POIImpl extends MinimalEObjectImpl.Container implements POI { return getDescription(); case IPos_DatamodelPackage.POI__DATA: return getData(); + case IPos_DatamodelPackage.POI__ID: + return getId(); } return super.eGet(featureID, resolve, coreType); } @@ -212,6 +256,9 @@ public class POIImpl extends MinimalEObjectImpl.Container implements POI { case IPos_DatamodelPackage.POI__DATA: setData((Map<String, String>) newValue); return; + case IPos_DatamodelPackage.POI__ID: + setId((String) newValue); + return; } super.eSet(featureID, newValue); } @@ -233,6 +280,9 @@ public class POIImpl extends MinimalEObjectImpl.Container implements POI { case IPos_DatamodelPackage.POI__DATA: setData((Map<String, String>) null); return; + case IPos_DatamodelPackage.POI__ID: + setId(ID_EDEFAULT); + return; } super.eUnset(featureID); } @@ -251,6 +301,8 @@ public class POIImpl extends MinimalEObjectImpl.Container implements POI { return DESCRIPTION_EDEFAULT == null ? description != null : !DESCRIPTION_EDEFAULT.equals(description); case IPos_DatamodelPackage.POI__DATA: return data != null; + case IPos_DatamodelPackage.POI__ID: + return ID_EDEFAULT == null ? id != null : !ID_EDEFAULT.equals(id); } return super.eIsSet(featureID); } @@ -270,6 +322,8 @@ public class POIImpl extends MinimalEObjectImpl.Container implements POI { result.append(description); result.append(", data: "); result.append(data); + result.append(", id: "); + result.append(id); result.append(')'); return result.toString(); } diff --git a/src/main/java/ipos/project/Functionality/DataServices.java b/src/main/java/ipos/project/Functionality/DataServices.java new file mode 100644 index 0000000000000000000000000000000000000000..a93c0a25a61469d97cd609332500591206da4e78 --- /dev/null +++ b/src/main/java/ipos/project/Functionality/DataServices.java @@ -0,0 +1,205 @@ +package ipos.project.Functionality; + +import ipos.project.DataModellntegration.iPos_Datamodel.*; +import ipos.project.entity.IWorldModelAccess; +import ipos.project.entity.LocalObjectWorldModel; +import org.apache.logging.log4j.LogManager; + +import java.util.List; +import java.util.Map; + +public class DataServices { + private static org.apache.logging.log4j.Logger LOG = LogManager.getLogger(); + private static IPos_DatamodelFactory modelFactory = IPos_DatamodelFactory.eINSTANCE; + + private static IWorldModelAccess wma; + + public static void clearWorldModel(){ + wma = new LocalObjectWorldModel(); + } + + public static ReferenceSystem getReferenceSystemByIdOrNull(String refSystemId) { + for (ReferenceSystem refSystem : wma.getAllRefSystems()){ + if(refSystem.getId().equals(refSystemId)){ + return refSystem; + } + } + return null; + } + + public static LocalizableObject getLObjectByIdOrNull(String lObjectId) { + for (Agent agent : wma.getAllAgents()){ + for (LocalizableObject lObject : agent.getLObject()){ + if (lObject.getId().equals(lObjectId)){ + return lObject; + } + } + } + return null; + } + + public static Zone getZoneByIdOrNull(String zoneId){ + for (var zone : wma.getAllZones()){ + if(zone.getId().equals(zoneId)){ + return zone; + } + } + return null; + } + + public static void addZone(Zone zone_input) { + for (Zone zone_loaded : wma.getAllZones()){ + if (zone_loaded.getId().equals(zone_input.getId())){ + LOG.warn("Zone " + zone_input.getId() + " could not be added to world model, as it already contains" + + "a zone with the same id"); + return; + } + } + wma.addZone(zone_input); + } + + public static void addAgent(Agent agent_input) { + for (Agent agent_loaded : wma.getAllAgents()){ + if (agent_loaded.getId().equals(agent_input.getId())){ + Agent agent_merged = mergeAgents(agent_loaded, agent_input); + wma.removeAgent(agent_loaded.getId()); + wma.addAgent(agent_merged); + } + } + wma.addAgent(agent_input); + } + + /** + * Keeps those LocalizableObjects that are currently connected to the loaded agent + * and adds those LocalizableObjects that are additionally connected to the input-agent. + * @param agent_loaded + * @param agent_input + * @return + */ + private static Agent mergeAgents(Agent agent_loaded, Agent agent_input) { + List<LocalizableObject> lObjects_loaded = agent_loaded.getLObject(); + List<LocalizableObject> lObjects_input = agent_input.getLObject(); + for (LocalizableObject lObject_input : lObjects_input){ + if (!containsLObjectId(lObjects_loaded, lObject_input.getId())){ + lObjects_loaded.add(lObject_input); + } + } + return agent_loaded; + } + + private static boolean containsLObjectId(List<LocalizableObject> lObjects, String id) { + for (LocalizableObject lObject : lObjects){ + if(lObject.getId().equals(id)){ + return true; + } + } + return false; + } + + public static void addRefSystem(ReferenceSystem refSystem_input) { + for (ReferenceSystem refSystem_loaded : wma.getAllRefSystems()){ + if (refSystem_loaded.getId().equals(refSystem_input.getId())){ + LOG.warn("Reference system " + refSystem_input.getId() + " could not be added to world model, as it already contains" + + "a reference system with the same id"); + return; + } + } + wma.addRefSystem(refSystem_input); + } + + public static void addPoi(POI poi_input) { + for (POI poi_loaded : wma.getAllPois()){ + if (poi_loaded.getId().equals(poi_input.getId())){ + LOG.warn("POI " + poi_input.getId() + " could not be added to world model, as it already contains" + + "a poi with the same id"); + return; + } + } + wma.addPoi(poi_input); + } + + public static POI createPOI(Position position, String description, Map<String, String> data){ + POI poi = modelFactory.createPOI(); + poi.setPosition(position); + poi.setDescription(description); + poi.setData(data); + return poi; + } + + public static Agent createAgent(String id, String type){ + Agent agent = modelFactory.createAgent(); + agent.setId(id); + agent.setAgentType(type); + return agent; + } + + public static LocalizableObject createLobject(String id, String sensorType, Agent agent, Placing currentPlacing){ + LocalizableObject lobject = modelFactory.createLocalizableObject(); + lobject.setAgent(agent); + lobject.setId(id); + lobject.setSensorType(sensorType); + lobject.setCurrentPlacing(currentPlacing); + return lobject; + } + + public static Placing createPlacing(Position position, Orientation orientation){ + Placing placing = modelFactory.createPlacing(); + placing.setPosition(position); + placing.setOrientation(orientation); + return placing; + } + + public static Position createPosition(Point3D point3D, Float accuracy, ReferenceSystem refSystem){ + Position position = modelFactory.createPosition(); + position.setPoint(point3D); + Gaussian accrcy = modelFactory.createGaussian(); + accrcy.setConfidenceInterval(accuracy); + position.setAccuracy(accrcy); + position.setReferenceSystem(refSystem); + return position; + } + + public static Point3D createPoint3D(float x, float y, float z){ + Point3D point3D = modelFactory.createPoint3D(); + point3D.setX(x); + point3D.setY(y); + point3D.setZ(z); + return point3D; + } + + public static ReferenceSystem createReferenceSystem(String name, String id, Placing origin){ + ReferenceSystem refSystem = modelFactory.createReferenceSystem(); + refSystem.setName(name); + refSystem.setId(id); + refSystem.setOrigin(origin); + return refSystem; + } + + public static Zone createZone(String name, String id, List<Space> spaces){ + Zone zone = modelFactory.createZone(); + zone.setName(name); + zone.setId(id); + for (var space : spaces) { + zone.getSpace().add(space); + } + return zone; + } + + public static Space createSpace(float x, float y, float z, Placing centrePoint){ + Space space = modelFactory.createSpace(); + space.setX(x); + space.setY(y); + space.setZ(z); + space.setCentrePoint(centrePoint); + return space; + } + + public static Quaternion createOrientation(float x, float y, float z, float w){ + Quaternion quaternion = modelFactory.createQuaternion(); + quaternion.setX(x); + quaternion.setY(y); + quaternion.setZ(z); + quaternion.setW(w); + return quaternion; + } +} diff --git a/src/main/java/ipos/project/Functionality/eventfilter/eventFilter.java b/src/main/java/ipos/project/Functionality/eventfilter/eventFilter.java index 6a3f15585faeb7eca785199f1e23a628c02eb777..d9a64274f8603e88f44f88a39ef127114722001d 100644 --- a/src/main/java/ipos/project/Functionality/eventfilter/eventFilter.java +++ b/src/main/java/ipos/project/Functionality/eventfilter/eventFilter.java @@ -1,5 +1,6 @@ package ipos.project.Functionality.eventfilter; +import ipos.project.Functionality.DataServices; import ipos.project.Functionality.eventfilter.Cell.Quaternion; import ipos.project.Functionality.eventfilter.Cell.Vector3; import ipos.project.DataModellntegration.iPos_Datamodel.*; @@ -28,21 +29,6 @@ public class eventFilter { return this.monitoringTaskId; } - // kommt später raus, Zugriff auf Weltmodell erfolgt eigentlich über Komponente DataRetrieval - private static WorldModel wm; - public static void setWM(WorldModel worldModel){ - wm = worldModel; - } - private LocalizableObject getLObjectBySensorIdOrNull(String sensorId){ - for (var agent : wm.getAgent()){ - for (var lObject : agent.getLObject()) { - if (lObject.getId().equals(sensorId)) { - return lObject; - } - } - } - return null; - } //Conditions: unique conditions are defined as single values, Parallel conditions are defined in lists. //initial value: 0 (for float and int) and empty (for arrays), it's not always possible to determine the status of the filter with just the condition value, so a filterStructure is defined to register which conditions are active. @@ -109,7 +95,7 @@ public class eventFilter { public boolean process(PositionEvent event) throws ParseException { IPos_DatamodelFactory dataModelFactory = IPos_DatamodelFactory.eINSTANCE; - LocalizableObject lObject = getLObjectBySensorIdOrNull(event.getLObjectId()); + LocalizableObject lObject = DataServices.getLObjectByIdOrNull(event.getLObjectId()); boolean flag = false; //false for pass, true for block if (null == event.getPlacing() || null == event.getPlacing().getPosition() || null == event.getPlacing().getPosition().getPoint()){ System.out.println("EventFilter: Warning: Received event with unknown Position. Sensor-id: " + event.getLObjectId()); diff --git a/src/main/java/ipos/project/Functionality/eventfilter/readConfig.java b/src/main/java/ipos/project/Functionality/eventfilter/readConfig.java index d93a535ccfed1f0226f1e7c1ff73af3b0bb70fc0..c038fa7b2b1b8c2c29a17fca3eab669b5d9d6454 100644 --- a/src/main/java/ipos/project/Functionality/eventfilter/readConfig.java +++ b/src/main/java/ipos/project/Functionality/eventfilter/readConfig.java @@ -1,5 +1,6 @@ package ipos.project.Functionality.eventfilter; import ipos.project.DataModellntegration.iPos_Datamodel.*; +import ipos.project.Functionality.DataServices; import org.apache.logging.log4j.LogManager; import org.json.JSONArray; import org.json.JSONObject; @@ -12,7 +13,7 @@ import java.util.List; public class readConfig { // kommt später raus, Zugriff auf Weltmodell erfolgt eigentlich über Komponente DataRetrieval - private static WorldModel wm; + // private static WorldModel wm; private static org.apache.logging.log4j.Logger LOG = LogManager.getLogger(); /** @@ -25,7 +26,7 @@ public class readConfig { // TODO: support other criteria than "position_condition_cell" //float delta_monReq = monReq.getDelta(); String frameId_monReq = monReq.getFrameId(); - Zone zone_monReq = retrieveZoneOrNull(frameId_monReq); + Zone zone_monReq = DataServices.getZoneByIdOrNull(frameId_monReq); if (null == zone_monReq){ LOG.warn("MonitoringRequest contained an invalid Zone-id"); return false; @@ -52,20 +53,6 @@ public class readConfig { return position_condition_cell; } - private static Zone retrieveZoneOrNull(String zoneId){ - List<Zone> knownZones = wm.getZoneMap().get(0).getZone(); - for (var zone : knownZones){ - if(zone.getId().equals(zoneId)){ - return zone; - } - } - return null; - } - - public static void setWM(WorldModel worldModel){ - wm = worldModel; - } - public static void readFilterConfigFromJson (String json_file, EventFilterCondition config) throws Exception { //Time condition: One time condition consist of two timestamp in format "yyyy-MM-dd HH:mm:ss.SSS", if the timestamp of the position event falls in between, the event passes. diff --git a/src/main/java/ipos/project/MainApp.java b/src/main/java/ipos/project/MainApp.java index e4358e31a3c02fcb6c989c5a7bede932a297dc38..67d159a249d72f599186e3cc957abde10fddb435 100644 --- a/src/main/java/ipos/project/MainApp.java +++ b/src/main/java/ipos/project/MainApp.java @@ -2,6 +2,7 @@ package ipos.project; import ipos.project.DataModellntegration.SimpleSceneIntegration.SimpleSceneIntegration; import ipos.project.Functionality.eventfilter.TestEventFilter; +import ipos.project.UseCaseController.Administration; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.domain.EntityScan; @@ -14,13 +15,13 @@ import java.text.ParseException; // @EnableJpaRepositories("ipos.project.models.SimpleScene.*") @EnableJpaRepositories("ipos.project.DataModellntegration.iPos_Datamodel.impl") public class MainApp { - public static void main(String[] args) throws ParseException { - // TestEventFilter.test(); + public static final String INDUSTRIEROBOTIK_FILE = "./init_Industrierobotik.txt"; + public static final String SENSORDATENFUSION_FILE = "./init_Sensordatenfusion.txt"; + + public static void main(String[] args) throws ParseException { SpringApplication.run(MainApp.class, args); - System.out.println("MainApp: Attempting to send mqtt-testmessage"); - SimpleSceneIntegration.mqttService.publish("UWB", "Testnachricht", 0, false); - SimpleSceneIntegration.mqttService.publish("Human_at_Window_Side", "Testnachricht", 0, false); - SimpleSceneIntegration.mqttService.publish("Human_at_Door_Side", "Testnachricht", 0, false); - System.out.println("sent mqtt-testmessage"); + // SimpleSceneIntegration.init(); + SimpleSceneIntegration.init(INDUSTRIEROBOTIK_FILE); + //SimpleSceneIntegration.init(SENSORDATENFUSION_FILE); } } diff --git a/src/main/java/ipos/project/UseCaseController/Administration.java b/src/main/java/ipos/project/UseCaseController/Administration.java new file mode 100644 index 0000000000000000000000000000000000000000..827ea2056a882d53d9a67b621ac5b44c8c10675d --- /dev/null +++ b/src/main/java/ipos/project/UseCaseController/Administration.java @@ -0,0 +1,43 @@ +package ipos.project.UseCaseController; + +import ipos.project.DataModellntegration.iPos_Datamodel.Agent; +import ipos.project.DataModellntegration.iPos_Datamodel.POI; +import ipos.project.DataModellntegration.iPos_Datamodel.ReferenceSystem; +import ipos.project.DataModellntegration.iPos_Datamodel.Zone; +import ipos.project.Functionality.DataServices; +import org.apache.logging.log4j.LogManager; +import org.springframework.stereotype.Component; + + +@Component +public class Administration { + private static org.apache.logging.log4j.Logger LOG = LogManager.getLogger(); + + public Administration(){} + + public static void initialize(){ + DataServices.clearWorldModel(); + } + + public static void handleZone(Zone zone){ + LOG.info("handling zone-object: " + zone.toString()); + DataServices.addZone(zone); + } + + public static void handleAgent(Agent agent) { + LOG.info("handling agent-object: " + agent.toString()); + DataServices.addAgent(agent); + } + + public static void handleRefSystem(ReferenceSystem refSystem) { + // muss checken, ob das RefSystem auf das ggf. verwiesen wird - tatsächlich existiert. Falls nicht: Speicherung ablehnen + LOG.info("handling refSystem-object: " + refSystem.toString()); + DataServices.addRefSystem(refSystem); + } + + public static void handlePoi(POI poi) { + // muss checken, ob das RefSystem auf das verwiesen wird - tatsächlich existiert. Falls nicht: Speicherung ablehnen + LOG.info("handling poi-object: " + poi.toString()); + DataServices.addPoi(poi); + } +} diff --git a/src/main/java/ipos/project/UseCaseController/PositionMonitoring.java b/src/main/java/ipos/project/UseCaseController/PositionMonitoring.java index 4738688fa8b544b65e3be58e081f9784389b9a94..af7cffc5c41fa44db6dcddc9ec8d1d636611d542 100644 --- a/src/main/java/ipos/project/UseCaseController/PositionMonitoring.java +++ b/src/main/java/ipos/project/UseCaseController/PositionMonitoring.java @@ -2,6 +2,7 @@ package ipos.project.UseCaseController; import ipos.project.DataModellntegration.SimpleSceneIntegration.SimpleSceneIntegration; import ipos.project.DataModellntegration.iPos_Datamodel.*; +import ipos.project.Functionality.DataServices; import ipos.project.Functionality.eventfilter.eventFilter; import ipos.project.Functionality.eventfilter.readConfig; import org.apache.logging.log4j.LogManager; @@ -19,7 +20,6 @@ import java.util.*; public class PositionMonitoring { private static org.apache.logging.log4j.Logger LOG = LogManager.getLogger(); - private static WorldModel wm; private static List<eventFilter> eventFilters = new ArrayList<eventFilter>(); private static Map<String, List<String>> zonePopulation = new HashMap<String, List<String>>(); private static IPos_DatamodelFactory modelFactory = IPos_DatamodelFactory.eINSTANCE; @@ -32,28 +32,7 @@ public class PositionMonitoring { public static final String ZONE_ID_DOOR = "cobot1_door_zone"; public static final String ZONE_ID_WINDOW = "cobot1_window_zone"; - public PositionMonitoring(){ - ReferenceSystem rootRefSystem = createReferenceSystem("ROOT", "ROOT", null); - List<Space> doorSpaces = new LinkedList<Space>(Arrays.asList(createSpace(2.0f, 2.0f, 6.0f, createPlacing(createPosition(createPoint3D(2.0f, 0.0f, 0f), 1f, rootRefSystem), createOrientation(0f, 0f, 0f, 0f))))); - List<Space> windowSpaces = new LinkedList<Space>(Arrays.asList(createSpace(2.0f, 2.0f, 6.0f, createPlacing(createPosition(createPoint3D(2.0f, 4.0f, 0f), 1f, rootRefSystem), createOrientation(0f, 0f, 0f, 0f))))); - Zone doorZone = createZone(ZONE_ID_DOOR, ZONE_ID_DOOR, doorSpaces); - Zone windowZone = createZone(ZONE_ID_WINDOW, ZONE_ID_WINDOW,windowSpaces); - wm = modelFactory.createWorldModel(); - wm.getReferenceSystem().add(rootRefSystem); - wm.getPois().add(createPOI(createPosition(createPoint3D(1.4f, 2.0f, 0f), 1f, wm.getReferenceSystem().get(0)), "UWBToken1", new HashMap<String,String>())); - wm.getPois().add(createPOI(createPosition(createPoint3D(3.7f, -2.0f, 0f), 1f, wm.getReferenceSystem().get(0)), "UWBToken2", new HashMap<String,String>())); - wm.getPois().add(createPOI(createPosition(createPoint3D(-2.4f, -0.5f, 0f), 1f, wm.getReferenceSystem().get(0)), "UWBToken3", new HashMap<String,String>())); - wm.getZoneMap().add(modelFactory.createZoneMap()); - wm.getZoneMap().get(0).getZone().add(doorZone); - wm.getZoneMap().get(0).getZone().add(windowZone); - wm.getAgent().add(createAgent("Employee1", "HUMAN")); - wm.getAgent().get(0).getLObject().add(createLobject("UWB_1", "UWB", wm.getAgent().get(0), null)); - - MonitoringRequest doorMonReq = createMonitoringRequest(ZONE_ID_DOOR, TOPIC_DOOR); - MonitoringRequest windowMonReq = createMonitoringRequest(ZONE_ID_WINDOW, TOPIC_WINDOW); - receiveMessage(doorMonReq); - receiveMessage(windowMonReq); - } + public PositionMonitoring(){} private MonitoringRequest createMonitoringRequest(String frameId, String monitoringTaskId) { MonitoringRequest monReq = modelFactory.createMonitoringRequest(); @@ -63,109 +42,12 @@ public class PositionMonitoring { } public static LocalizableObject getLObjectByIdOrNull(String lObjectId){ - for (Agent agent : wm.getAgent()){ - for (LocalizableObject lObject : agent.getLObject()){ - if (lObject.getId().equals(lObjectId)){ - return lObject; - } - } - } - return null; - } + return DataServices.getLObjectByIdOrNull(lObjectId); + } public static ReferenceSystem getReferenceSystemByIdOrNull(String refSystemId){ - for (ReferenceSystem refSystem : wm.getReferenceSystem()){ - if(refSystem.getId().equals(refSystemId)){ - return refSystem; - } - } - return null; - } - - private POI createPOI(Position position, String description, Map<String, String> data){ - POI poi = modelFactory.createPOI(); - poi.setPosition(position); - poi.setDescription(description); - poi.setData(data); - return poi; - } - - private Agent createAgent(String id, String type){ - Agent agent = modelFactory.createAgent(); - agent.setId(id); - agent.setAgentType(type); - return agent; - } - - private LocalizableObject createLobject(String id, String sensorType, Agent agent, Placing currentPlacing){ - LocalizableObject lobject = modelFactory.createLocalizableObject(); - lobject.setAgent(agent); - lobject.setId(id); - lobject.setSensorType(sensorType); - lobject.setCurrentPlacing(currentPlacing); - return lobject; - } - - private Placing createPlacing(Position position, Orientation orientation){ - Placing placing = modelFactory.createPlacing(); - placing.setPosition(position); - placing.setOrientation(orientation); - return placing; - } - - private Position createPosition(Point3D point3D, Float accuracy, ReferenceSystem refSystem){ - Position position = modelFactory.createPosition(); - position.setPoint(point3D); - Gaussian accrcy = modelFactory.createGaussian(); - accrcy.setConfidenceInterval(accuracy); - position.setAccuracy(accrcy); - position.setReferenceSystem(refSystem); - return position; - } - - private Point3D createPoint3D(float x, float y, float z){ - Point3D point3D = modelFactory.createPoint3D(); - point3D.setX(x); - point3D.setY(y); - point3D.setZ(z); - return point3D; - } - - private ReferenceSystem createReferenceSystem(String name, String id, Placing origin){ - ReferenceSystem refSystem = modelFactory.createReferenceSystem(); - refSystem.setName(name); - refSystem.setId(id); - refSystem.setOrigin(origin); - return refSystem; - } - - private Zone createZone(String name, String id, List<Space> spaces){ - Zone zone = modelFactory.createZone(); - zone.setName(name); - zone.setId(id); - for (var space : spaces) { - zone.getSpace().add(space); - } - return zone; - } - - private Space createSpace(float x, float y, float z, Placing centrePoint){ - Space space = modelFactory.createSpace(); - space.setX(x); - space.setY(y); - space.setZ(z); - space.setCentrePoint(centrePoint); - return space; - } - - private Quaternion createOrientation(float x, float y, float z, float w){ - Quaternion quaternion = modelFactory.createQuaternion(); - quaternion.setX(x); - quaternion.setY(y); - quaternion.setZ(z); - quaternion.setW(w); - return quaternion; - } + return DataServices.getReferenceSystemByIdOrNull(refSystemId); + } @JmsListener(destination = "/positions123", containerFactory = "jmsListenFactory") public void receiveMessage(IposPosition pos) { @@ -176,9 +58,7 @@ public class PositionMonitoring { public static void receiveMessage(MonitoringRequest monReq) { LOG.info("Received MonitoringRequest <" + monReq + ">"); eventFilter filter = new eventFilter(monReq.getMonitoringTaskId()); - filter.setWM(wm); EventFilterCondition config = modelFactory.createEventFilterCondition(); - readConfig.setWM(wm); if (! readConfig.readFilterConfigFromMonitoringRequest(monReq, config)){ return; // monitoringRequest could not be read } diff --git a/src/main/java/ipos/project/entity/IWorldModelAccess.java b/src/main/java/ipos/project/entity/IWorldModelAccess.java new file mode 100644 index 0000000000000000000000000000000000000000..400ed55769468913cd6534199ffb2b6e50e836bd --- /dev/null +++ b/src/main/java/ipos/project/entity/IWorldModelAccess.java @@ -0,0 +1,30 @@ +package ipos.project.entity; + +import ipos.project.DataModellntegration.iPos_Datamodel.*; + +import java.util.List; + +public interface IWorldModelAccess { + + /** + * Shall return empty list there are currently no objects of the respective kind stored in the world model + * @return + */ + public List<Agent> getAllAgents(); + + public List<ReferenceSystem> getAllRefSystems(); + + void removeAgent(String id); + + void addAgent(Agent agent_merged); + + List<Zone> getAllZones(); + + void addZone(Zone zone_input); + + void addRefSystem(ReferenceSystem refSystem_input); + + List<POI> getAllPois(); + + void addPoi(POI poi_input); +} diff --git a/src/main/java/ipos/project/entity/LocalObjectWorldModel.java b/src/main/java/ipos/project/entity/LocalObjectWorldModel.java new file mode 100644 index 0000000000000000000000000000000000000000..8e0dea14861306280ce3bdf7fea1fe56816e6ef4 --- /dev/null +++ b/src/main/java/ipos/project/entity/LocalObjectWorldModel.java @@ -0,0 +1,86 @@ +package ipos.project.entity; + +import ipos.project.DataModellntegration.iPos_Datamodel.*; + +import java.util.List; + +public class LocalObjectWorldModel implements IWorldModelAccess { + + private static IPos_DatamodelFactory modelFactory = IPos_DatamodelFactory.eINSTANCE; + WorldModel wm; + + public LocalObjectWorldModel(){ + wm = modelFactory.createWorldModel(); + wm.getZoneMap().add(modelFactory.createZoneMap()); // zonemaps are currently not supported + } + + @Override + public List<Agent> getAllAgents() { + return wm.getAgent(); + } + + @Override + public List<ReferenceSystem> getAllRefSystems() { + return wm.getReferenceSystem(); + } + + @Override + public void removeAgent(String id) { + for (Agent agent : wm.getAgent()){ + if(agent.getId().equals(id)){ + wm.getAgent().remove(agent); + return; + } + } + } + + /** + * Assumption: The calling code made sure that there are currently no agents + * with the same id contained in the world model. + * @param agent + */ + @Override + public void addAgent(Agent agent) { + wm.getAgent().add(agent); + } + + @Override + public List<Zone> getAllZones() { + return wm.getZoneMap().get(0).getZone(); + } + + /** + * Assumption: The calling code made sure that there are currently no zones + * with the same id contained in the world model. + * @param zone + */ + @Override + public void addZone(Zone zone) { + wm.getZoneMap().get(0).getZone().add(zone); + } + + /** + * Assumption: The calling code made sure that there are currently no refSystems + * with the same id contained in the world model. + * @param refSystem + */ + @Override + public void addRefSystem(ReferenceSystem refSystem) { + wm.getReferenceSystem().add(refSystem); + } + + @Override + public List<POI> getAllPois() { + return wm.getPois(); + } + + /** + * Assumption: The calling code made sure that there are currently no pois + * with the same id contained in the world model. + * @param poi + */ + @Override + public void addPoi(POI poi) { + wm.getPois().add(poi); + } +}