From df4ffe84afca74f35cbe0186c109218917a817f5 Mon Sep 17 00:00:00 2001 From: Jeffrey Phillips Freeman <jeffrey.freeman@syncleus.com> Date: Fri, 7 Sep 2018 03:25:16 +0200 Subject: [PATCH] feat: added graphdb models fr the world. --- .../storage/graphdb/model/FloorModelData.java | 104 ++++++++++++++++++ .../storage/graphdb/model/RoomModelData.java | 97 ++++++++++++++++ .../storage/graphdb/model/WorldModelData.java | 85 ++++++++++++++ 3 files changed, 286 insertions(+) create mode 100644 src/main/java/com/syncleus/aethermud/storage/graphdb/model/FloorModelData.java create mode 100644 src/main/java/com/syncleus/aethermud/storage/graphdb/model/RoomModelData.java create mode 100644 src/main/java/com/syncleus/aethermud/storage/graphdb/model/WorldModelData.java diff --git a/src/main/java/com/syncleus/aethermud/storage/graphdb/model/FloorModelData.java b/src/main/java/com/syncleus/aethermud/storage/graphdb/model/FloorModelData.java new file mode 100644 index 00000000..bb523d11 --- /dev/null +++ b/src/main/java/com/syncleus/aethermud/storage/graphdb/model/FloorModelData.java @@ -0,0 +1,104 @@ +/** + * Copyright 2017 - 2018 Syncleus, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.syncleus.aethermud.storage.graphdb.model; + +import com.google.common.collect.Sets; +import com.syncleus.aethermud.storage.graphdb.DataUtils; +import com.syncleus.ferma.annotations.Adjacency; +import com.syncleus.ferma.annotations.GraphElement; +import com.syncleus.ferma.ext.AbstractInterceptingVertexFrame; +import org.apache.commons.beanutils.PropertyUtils; +import org.apache.tinkerpop.gremlin.structure.Direction; +import com.syncleus.aethermud.world.model.RoomModelData; + +import java.lang.reflect.InvocationTargetException; +import java.util.*; + +@GraphElement +public abstract class FloorModelData extends AbstractInterceptingVertexFrame { + + @Adjacency(label = "roomModel", direction = Direction.OUT) + public abstract RoomModelData addRoomModelData(RoomModelData roomModels); + + @Adjacency(label = "roomModel", direction = Direction.OUT) + public abstract void removeRoomModelData(RoomModelData stats); + + @Adjacency(label = "roomModel", direction = Direction.OUT) + public abstract <N extends RoomModelData> Iterator<? extends N> getRoomModelDatasIterator(Class<? extends N> type); + + public Set<RoomModelData> getRoomModelDatas() { + return Collections.unmodifiableSet(Sets.newHashSet(this.getRoomModelDatasIterator(RoomModelData.class))); + } + + public void setRoomModelDatas(Set<RoomModelData> roomModels) { + DataUtils.setAllElements(roomModels, () -> this.getRoomModelDatasIterator(RoomModelData.class), roomModelData -> this.addRoomModelData(roomModelData), () -> {} ); + } + + public RoomModelData createRoomModelData() { + final RoomModelData roomModel = this.getGraph().addFramedVertex(RoomModelData.class); + this.addEffectData(roomModel); + return roomModel; + } + + @Property("rawMatrixCsv") + public abstract String getRawMatrixCsv(); + + @Property("rawMatrixCsv") + public abstract void setRawMatrixCsv(String rawMatrixCsv); + + @Property("name") + public abstract String getName(); + + @Property("name") + public abstract void setName(String name); + + @Property("id") + public abstract Integer getId(); + + @Property("id") + public abstract void setId(Integer id); + + public static void copyFloorModel(FloorModelData dest, FloorModel src) { + try { + PropertyUtils.copyProperties(dest, src); + + for(RoomModelData data : dest.getRoomModelDatas()) + data.remove(); + if( src.getRoomModelDatas() != null ) + for(RoomModelData roomModelData : src.getRoomModelDatas()) + RoomModelData.copyFloorModel(dest.createRoomModelData(), roomModelData); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + throw new IllegalStateException("Could not copy properties", e); + } + } + + public static FloorModel copyFloorModel(FloorModelData src) { + FloorModel retVal = new FloorModel(); + try { + PropertyUtils.copyProperties(retVal, src); + + Set<RoomModel> roomModels = new HashSet<>(); + if( src.getRoomModelDatas() != null ) + for(RoomModelData roomModelData : src.getRoomModelDatas()) + roomModels.add(RoomModelData.copyRoomModel(roomModelData)); + retVal.setRoomModels(Collections.unmodifiableSet(roomModels)); + + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + throw new IllegalStateException("Could not copy properties", e); + } + return retVal; + } +} diff --git a/src/main/java/com/syncleus/aethermud/storage/graphdb/model/RoomModelData.java b/src/main/java/com/syncleus/aethermud/storage/graphdb/model/RoomModelData.java new file mode 100644 index 00000000..d708a914 --- /dev/null +++ b/src/main/java/com/syncleus/aethermud/storage/graphdb/model/RoomModelData.java @@ -0,0 +1,97 @@ +/** + * Copyright 2017 - 2018 Syncleus, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.syncleus.aethermud.storage.graphdb.model; + +import com.syncleus.aethermud.storage.graphdb.DataUtils; +import com.syncleus.ferma.annotations.GraphElement; +import com.syncleus.ferma.ext.AbstractInterceptingVertexFrame; +import org.apache.commons.beanutils.PropertyUtils; + +import java.lang.reflect.InvocationTargetException; +import java.util.Map; +import java.util.Set; + + +@GraphElement +public abstract class RoomModelData extends AbstractInterceptingVertexFrame { + + @Property("areaNames") + public Set<String> getAreaNames(); + + @Property("areaNames") + public void setAreaNames(Set<String> areaNames); + + @Property("floorId") + public int getFloorId(); + + @Property("floorId") + public void setFloorId(int floorId); + + @Property("roomTags") + public Set<String> getRoomTags(); + + @Property("roomTags") + public void setRoomTags(Set<String> roomTags); + + @Property("roomId") + public int getRoomId(); + + @Property("roomId") + public void setRoomId(int roomId); + + @Property("roomDescription") + public String getRoomDescription(); + + @Property("roomDescription") + public void setRoomDescription(String roomDescription); + + @Property("roomTitle") + public String getRoomTitle(); + + @Property("roomTitle") + public void setRoomTitle(String roomTitle); + + @Property("enterExitNames") + public Map<String, String> getEnterExitNames(); + + @Property("enterExitNames") + public void setEnterExitNames(Map<String, String> enterExitNames); + + @Property("notables") + public Map<String, String> getNotables(); + + @Property("notables") + public void setNotables(Map<String, String> notables); + + + public static void copyRoomModel(RoomModelData dest, RoomModel src) { + try { + PropertyUtils.copyProperties(dest, src); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + throw new IllegalStateException("Could not copy properties", e); + } + } + + public static RoomModel copyRoomModel(RoomModelData src) { + RoomModel retVal = new RoomModel(); + try { + PropertyUtils.copyProperties(retVal, src); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + throw new IllegalStateException("Could not copy properties", e); + } + return retVal; + } +} diff --git a/src/main/java/com/syncleus/aethermud/storage/graphdb/model/WorldModelData.java b/src/main/java/com/syncleus/aethermud/storage/graphdb/model/WorldModelData.java new file mode 100644 index 00000000..a5cf004b --- /dev/null +++ b/src/main/java/com/syncleus/aethermud/storage/graphdb/model/WorldModelData.java @@ -0,0 +1,85 @@ +/** + * Copyright 2017 - 2018 Syncleus, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.syncleus.aethermud.storage.graphdb.model; + +import com.google.common.collect.Sets; +import com.syncleus.aethermud.storage.graphdb.DataUtils; +import com.syncleus.ferma.annotations.Adjacency; +import com.syncleus.ferma.annotations.GraphElement; +import com.syncleus.ferma.ext.AbstractInterceptingVertexFrame; +import org.apache.commons.beanutils.PropertyUtils; +import org.apache.tinkerpop.gremlin.structure.Direction; +import com.syncleus.aethermud.world.model.FloorModelData; + +import java.lang.reflect.InvocationTargetException; +import java.util.*; + +@GraphElement +public abstract class WorldModelData extends AbstractInterceptingVertexFrame { + @Adjacency(label = "floorModel", direction = Direction.OUT) + public abstract FloorModelData addFloorModelData(FloorModelData floorModels); + + @Adjacency(label = "floorModel", direction = Direction.OUT) + public abstract void removeFloorModelData(FloorModelData stats); + + @Adjacency(label = "floorModel", direction = Direction.OUT) + public abstract <N extends FloorModelData> Iterator<? extends N> getFloorModelDatasIterator(Class<? extends N> type); + + public Set<FloorModelData> getFloorModelDatas() { + return Collections.unmodifiableSet(Sets.newHashSet(this.getFloorModelDatasIterator(FloorModelData.class))); + } + + public void setFloorModelDatas(Set<FloorModelData> floorModels) { + DataUtils.setAllElements(floorModels, () -> this.getFloorModelDatasIterator(FloorModelData.class), floorModelData -> this.addFloorModelData(floorModelData), () -> {} ); + } + + public FloorModelData createFloorModelData() { + final FloorModelData floorModel = this.getGraph().addFramedVertex(FloorModelData.class); + this.addEffectData(floorModel); + return floorModel; + } + + public static void copyWorldModel(WorldModelData dest, WorldModel src) { + try { + PropertyUtils.copyProperties(dest, src); + + for(FloorModelData data : dest.getFloorModelDatas()) + data.remove(); + if( src.getFloorModelDatas() != null ) + for(FloorModelData floorModelData : src.getFloorModelDatas()) + FloorModelData.copyFloorModel(dest.createFloorModelData(), floorModelData); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + throw new IllegalStateException("Could not copy properties", e); + } + } + + public static WorldModel copyWorldModel(WorldModelData src) { + WorldModel retVal = new WorldModel(); + try { + PropertyUtils.copyProperties(retVal, src); + + Set<FloorModel> floorModels = new HashSet<>(); + if( src.getFloorModelDatas() != null ) + for(FloorModelData floorModelData : src.getFloorModelDatas()) + floorModels.add(FloorModelData.copyFloorModel(floorModelData)); + retVal.setFloorModels(Collections.unmodifiableSet(floorModels)); + + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + throw new IllegalStateException("Could not copy properties", e); + } + return retVal; + } +} -- GitLab