Skip to content

Commit

Permalink
allow to registering mappings on innerTreeNodes: #273
Browse files Browse the repository at this point in the history
  • Loading branch information
ck-c8y committed Oct 8, 2024
1 parent 2eef803 commit bfad6cd
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -571,11 +571,13 @@ public List<Mapping> resolveMappingInbound(String tenant, String topic) throws R
.map(mn -> mn.getMapping()).collect(Collectors.toList());
}

// public List<Mapping> resolveMappingInbound(String tenant, String topic, String connectorIdent)
// throws ResolveException {
// List<Mapping> resolvedMappings = resolveMappingInbound(tenant, topic);
// resolvedMappings.removeIf(m -> !getDeploymentMapEntry(tenant, m.ident).contains(connectorIdent));
// return resolvedMappings;
// public List<Mapping> resolveMappingInbound(String tenant, String topic,
// String connectorIdent)
// throws ResolveException {
// List<Mapping> resolvedMappings = resolveMappingInbound(tenant, topic);
// resolvedMappings.removeIf(m -> !getDeploymentMapEntry(tenant,
// m.ident).contains(connectorIdent));
// return resolvedMappings;
// }

public void resetSnoop(String tenant, String id) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public static MappingTreeNode createMappingNode(MappingTreeNode parent, String l
node.setTenant(parent.getTenant());
node.setAbsolutePath(parent.getAbsolutePath() + level);
node.setDepthIndex(parent.getDepthIndex() + 1);
node.setMapping(mapping);
node.setMappingNode(true);
return node;
}
Expand Down Expand Up @@ -158,18 +157,37 @@ private void addMapping(Mapping mapping, List<String> levels, int currentLevel)
tenant, currentPathMonitoring, getLevel(), getAbsolutePath());
MappingTreeNode child;
if (getChildNodes().containsKey(levels.get(currentLevel))) {
if (specificChildren.size() == 1) {
if (!specificChildren.get(0).isMappingNode()) {
child = specificChildren.get(0);
} else {
throw new ResolveException(String.format(
"Could not add mapping to tree, since at this node is already blocked by mappingId : %s",
specificChildren.get(0).toString()));
}
} else {
// if (specificChildren.size() == 1) {
// if (!specificChildren.get(0).isMappingNode()) {
// child = specificChildren.get(0);
// } else {
// throw new ResolveException(String.format(
// "Could not add mapping to tree, since at this node is already blocked by
// mappingId : %s",
// specificChildren.get(0).toString()));
// }
// } else {
// throw new ResolveException(String.format(
// "Could not add mapping to tree, multiple mappings are only allowed at the end
// of the tree. This node already contains: %s nodes",
// specificChildren.size()));
// }

// find the one node that is an inner node, so that we can descend further in
// the tree
List<MappingTreeNode> innerNodes = specificChildren.stream()
.filter(node -> !node.isMappingNode())
.collect(Collectors.toList());
if (innerNodes != null && innerNodes.size() > 1) {
throw new ResolveException(String.format(
"Could not add mapping to tree, multiple mappings are only allowed at the end of the tree. This node already contains: %s nodes",
specificChildren.size()));
"multiple inner nodes are registered : %s",
specificChildren.toString()));
} else if (innerNodes.size() == 1) {
child = innerNodes.get(0);
} else {
child = MappingTreeNode.createInnerNode(this, levels.get(currentLevel));
specificChildren.add(child);
getChildNodes().put(levels.get(currentLevel), specificChildren);
}
} else {
child = MappingTreeNode.createInnerNode(this, levels.get(currentLevel));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,32 @@
@Slf4j
public class MappingTreeNodeSerializer extends StdSerializer<MappingTreeNode> {

public MappingTreeNodeSerializer() {
this(null);
}

public MappingTreeNodeSerializer(Class<MappingTreeNode> t) {
super(t);
}

@Override
public void serialize(
MappingTreeNode value, JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonProcessingException {
log.debug("Serializing node {}, {}", value.getLevel(), value.getAbsolutePath());
jgen.writeStartObject();
jgen.writeNumberField("depthIndex", value.getDepthIndex());
jgen.writeStringField("level", value.getLevel());
jgen.writeStringField("parentNode",
(value.getParentNode() != null ? value.getParentNode().getAbsolutePath() : "null"));
jgen.writeStringField("absolutePath", value.getAbsolutePath());
if (value.isMappingNode()) {
provider.defaultSerializeField("mapping", value.getMapping(), jgen);
} else {
provider.defaultSerializeField("childNodes", value.getChildNodes(), jgen);
}
jgen.writeEndObject();

}
public MappingTreeNodeSerializer() {
this(null);
}

public MappingTreeNodeSerializer(Class<MappingTreeNode> t) {
super(t);
}

@Override
public void serialize(
MappingTreeNode value, JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonProcessingException {
log.debug("Serializing node {}, {}", value.getLevel(), value.getAbsolutePath());
jgen.writeStartObject();
jgen.writeNumberField("depthIndex", value.getDepthIndex());
jgen.writeStringField("level", value.getLevel());
jgen.writeStringField("parentNode",
(value.getParentNode() != null ? value.getParentNode().getAbsolutePath() : "null"));
jgen.writeStringField("absolutePath", value.getAbsolutePath());
if (value.isMappingNode()) {
provider.defaultSerializeField("mapping", value.getMapping(), jgen);
} else {
provider.defaultSerializeField("childNodes", value.getChildNodes(), jgen);
}
jgen.writeEndObject();

}

}

0 comments on commit bfad6cd

Please sign in to comment.