if (request == null) {
throw new MissingRequest(GET_ADJACENT_KAM_NODES_REQUEST);
}
// Make sure a KamNode was specified
KamNode kamNode = request.getKamNode();
if (null == kamNode) {
throw new RequestException("KamNode payload is missing");
}
// See if we got a DirectionType to use
org.openbel.framework.api.EdgeDirectionType direction =
null;
EdgeDirectionType edgeDirectionType = request.getDirection();
if (null != edgeDirectionType) {
direction = convert(edgeDirectionType);
}
// Get the real Kam from the KamCache
KamStoreObjectRef kamElementRef;
try {
kamElementRef = Converter.decodeNode(kamNode);
} catch (InvalidIdException e) {
throw new RequestException("Error processing KAM node", e);
}
org.openbel.framework.api.Kam objKam;
final KamInfo kamInfo = getKamInfo(kamElementRef,
"Error processing KAM node");
objKam = kamCacheService.getKam(kamInfo.getName());
// Get the Dialect (may be null)
final Dialect dialect = getDialect(request.getDialect());
if (dialect != null) {
objKam = new KamDialect(objKam, dialect);
}
if (objKam == null) {
throw new RequestException("Error processing KAM node",
new InvalidIdException(kamElementRef.getEncodedString()));
}
final org.openbel.framework.api.NodeFilter nodes =
convertNodeFilterInRequest(
request.getNodeFilter(), objKam);
final org.openbel.framework.api.EdgeFilter edges =
convertEdgeFilterInRequest(
request.getEdgeFilter(), objKam);
// Get the real KamNode from the Kam
Integer elemid = kamElementRef.getKamStoreObjectId();
org.openbel.framework.api.Kam.KamNode objKamNode;
objKamNode = objKam.findNode(elemid);
// Process the request
GetAdjacentKamNodesResponse response =
OBJECT_FACTORY.createGetAdjacentKamNodesResponse();
// Get the adjacent nodes
Set<org.openbel.framework.api.Kam.KamNode> adjnodes;
if (direction == null) {
adjnodes = objKam.getAdjacentNodes(objKamNode, edges, nodes);
} else {
adjnodes = objKam.getAdjacentNodes(objKamNode, direction, edges,
nodes);
}
for (org.openbel.framework.api.Kam.KamNode node : adjnodes) {
KamNode kn = convert(kamInfo, node);
response.getKamNodes().add(kn);
}
return response;
}