use of org.karnak.backend.dicom.ForwardDestination in project karnak by OsiriX-Foundation.
the class CStoreSCPService method store.
@Override
protected void store(Association as, PresentationContext pc, Attributes rq, PDVInputStream data, Attributes rsp) throws IOException {
Optional<ForwardDicomNode> sourceNode = destinations.keySet().stream().filter(n -> n.getForwardAETitle().equals(as.getCalledAET())).findFirst();
if (sourceNode.isEmpty()) {
throw new IllegalStateException("Cannot find the forward AeTitle " + as.getCalledAET());
}
ForwardDicomNode fwdNode = sourceNode.get();
List<ForwardDestination> destList = destinations.get(fwdNode);
if (destList == null || destList.isEmpty()) {
throw new IllegalStateException("No DICOM destinations for " + fwdNode);
}
DicomNode callingNode = DicomNode.buildRemoteDicomNode(as);
Set<DicomNode> srcNodes = fwdNode.getAcceptedSourceNodes();
boolean valid = srcNodes.isEmpty() || srcNodes.stream().anyMatch(n -> n.getAet().equals(callingNode.getAet()) && (!n.isValidateHostname() || n.equalsHostname(callingNode.getHostname())));
if (!valid) {
rsp.setInt(Tag.Status, VR.US, Status.NotAuthorized);
LOGGER.error("Refused: not authorized (124H). Source node: {}. SopUID: {}", callingNode, rq.getString(Tag.AffectedSOPInstanceUID));
return;
}
rsp.setInt(Tag.Status, VR.US, status);
try {
Params p = new Params(rq.getString(Tag.AffectedSOPInstanceUID), rq.getString(Tag.AffectedSOPClassUID), pc.getTransferSyntax(), priority, data, as);
// Update transfer status of destinations
updateTransferStatus(destList);
forwardService.storeMultipleDestination(fwdNode, destList, p);
} catch (Exception e) {
throw new DicomServiceException(Status.ProcessingFailure, e);
}
}
use of org.karnak.backend.dicom.ForwardDestination in project karnak by OsiriX-Foundation.
the class GatewaySetUpService method reloadGatewayPersistence.
public void reloadGatewayPersistence() {
List<ForwardNodeEntity> list = new ArrayList<>(forwardNodeRepo.findAll());
for (ForwardNodeEntity forwardNodeEntity : list) {
ForwardDicomNode fwdSrcNode = new ForwardDicomNode(forwardNodeEntity.getFwdAeTitle(), null, forwardNodeEntity.getId());
addAcceptedSourceNodes(fwdSrcNode, forwardNodeEntity);
List<ForwardDestination> dstList = new ArrayList<>(forwardNodeEntity.getDestinationEntities().size());
for (DestinationEntity dstNode : forwardNodeEntity.getDestinationEntities()) {
addDestinationNode(dstList, fwdSrcNode, dstNode);
}
destMap.put(fwdSrcNode, dstList);
}
}
use of org.karnak.backend.dicom.ForwardDestination in project karnak by OsiriX-Foundation.
the class EchoServiceTest method should_retrieve_status_destinations.
@Test
void should_retrieve_status_destinations() throws IOException {
// Init data
ForwardDicomNode forwardDicomNode = new ForwardDicomNode("fwdAeTitle");
Optional<ForwardDicomNode> forwardDicomNodeOpt = Optional.of(forwardDicomNode);
DicomNode dicomNode = new DicomNode("fwdAeTitle", 1111);
ForwardDestination forwardDestination = new DicomForwardDestination(forwardDicomNode, dicomNode);
WebForwardDestination webForwardDestination = new WebForwardDestination(forwardDicomNode, "http://test.com");
List<ForwardDestination> forwardDestinations = Arrays.asList(forwardDestination, webForwardDestination);
DicomState dicomState = new DicomState();
dicomState.setStatus(444);
// Mock
Mockito.when(gatewaySetUpServiceMock.getDestinationNode(Mockito.anyString())).thenReturn(forwardDicomNodeOpt);
Mockito.when(gatewaySetUpServiceMock.getDestinations(Mockito.any(ForwardDicomNode.class))).thenReturn(forwardDestinations);
MockedStatic<Echo> echoMock = Mockito.mockStatic(Echo.class);
echoMock.when(() -> Echo.process(Mockito.any(AdvancedParams.class), Mockito.any(ForwardDicomNode.class), Mockito.any(DicomNode.class))).thenReturn(dicomState);
// Call service
List<DestinationEcho> destinationEchos = echoService.retrieveStatusConfiguredDestinations("fwdAeTitle");
// Test results
Mockito.verify(gatewaySetUpServiceMock, Mockito.times(1)).getDestinationNode(Mockito.anyString());
assertEquals(2, destinationEchos.size());
assertEquals("fwdAeTitle", destinationEchos.get(0).getAet());
assertEquals(444, destinationEchos.get(0).getStatus());
assertEquals("http://test.com/studies", destinationEchos.get(1).getUrl());
assertEquals(0, destinationEchos.get(1).getStatus());
}
use of org.karnak.backend.dicom.ForwardDestination in project karnak by OsiriX-Foundation.
the class EchoServlet method doGet.
@Override
public void doGet(HttpServletRequest req, HttpServletResponse res) {
res.setContentType("text/xml");
PrintWriter out = null;
try {
out = res.getWriter();
} catch (IOException e) {
String errorMsg = "Cannot write response";
LOGGER.error(errorMsg);
ServletUtil.sendResponseError(res, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, errorMsg);
return;
}
String aet = req.getParameter("srcAET");
if (globalConfig == null) {
String errorMsg = "Missing 'GlobalConfig' from current ServletContext";
LOGGER.error(errorMsg);
ServletUtil.sendResponseError(res, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, errorMsg);
return;
}
// Echo service, only work for the out stream configuration
AdvancedParams params = new AdvancedParams();
ConnectOptions connectOptions = new ConnectOptions();
connectOptions.setConnectTimeout(3000);
connectOptions.setAcceptTimeout(5000);
params.setConnectOptions(connectOptions);
StringBuilder sb = new StringBuilder("<destinations>");
Optional<ForwardDicomNode> srcNode = globalConfig.getDestinationNode(aet);
if (srcNode.isPresent()) {
List<ForwardDestination> list = globalConfig.getDestinations(srcNode.get());
for (ForwardDestination val : list) {
if (val instanceof DicomForwardDestination) {
DicomNode calledNode = ((DicomForwardDestination) val).getStreamSCU().getCalledNode();
// TODO isUseAetDest
DicomState dicomState = Echo.process(params, srcNode.get(), calledNode);
sb.append("<destination ");
sb.append("aet=");
sb.append(calledNode.getAet());
sb.append(">");
sb.append(dicomState.getStatus());
sb.append("</destination>\n");
} else if (val instanceof WebForwardDestination) {
WebForwardDestination d = (WebForwardDestination) val;
sb.append("<destination ");
sb.append("url=");
sb.append(d.getRequestURL());
sb.append(">");
// To implement
// sb.append(d.getStowRS().);
sb.append("</destination>\n");
}
}
}
sb.append("</destinations>\n");
out.println(sb);
}
Aggregations