GeneralSecurityException, IllegalAccessException {
CommandLine cl = null;
cl = parseComandLine(args);
ProbeTC instance = new ProbeTC();
Device device = null;
if (cl.hasOption("b")) {
device = new Device(cl.getOptionValue("b").toLowerCase());
} else {
LOG.error("Missing broadcast AETitle");
throw new IllegalAccessException("missing broadcast AETitle");
}
Connection conn = new Connection();
device.addConnection(conn);
ApplicationEntity ae = new ApplicationEntity(cl.getOptionValue("b")
.toUpperCase());
if (cl.hasOption("d")) {
instance.setDestinationAET(cl.getOptionValue("d"));
}
if (cl.hasOption("s")) {
instance.setSourceAET(cl.getOptionValue("s"));
}
device.addApplicationEntity(ae);
ae.addConnection(conn);
instance.destination = new Connection();
configureConnect(instance.destination, instance.rq, cl, ae);
CLIUtils.configure(conn, cl);
// instance.sourceAE = new
// ApplicationEntity(cl.getOptionValue("s").split(":")[0]);
// here load the TCs
if (cl.hasOption("ldap")) {
try {
InputStream is = null;
Properties p = new Properties();
if (!cl.getOptionValue("ldap").isEmpty()) {
is = new FileInputStream(new File(
cl.getOptionValue("ldap")));
} else {
LOG.error("Missing ldap properties file");
throw new IllegalAccessException("missing ldap properties file");
}
p.load(is);
LdapDicomConfiguration conf = new LdapDicomConfiguration(p);
LOG.info("Started Loading LDAP configuration");
ArrayList<TransferCapability> tcs = null;
if(cl.hasOption("s")){
ApplicationEntity sourceAE = conf
.findApplicationEntity(instance.sourceAET);
tcs = (ArrayList<TransferCapability>) sourceAE
.getTransferCapabilities();
}
else
{
tcs = loadTCFile();
}
ArrayList<PresentationContext> pcs = addChunkedPCsandSend(
ae, device, instance, tcs);
// print accepted ones
ArrayList<PresentationContext> acceptedPCs = new ArrayList<PresentationContext>();
for (PresentationContext pc : pcs)
if (pc.isAccepted())
acceptedPCs.add(pc);
LOG.info("Probed the source ae and found the following accepted presentation contexts");
for (PresentationContext pc : acceptedPCs) {
LOG.info("PC[" + pc.getPCID() + "]\tAbstractSyntax:"
+ pc.getAbstractSyntax() + "\n with "
+ " the following Transfer-Syntax:["
+ pc.getTransferSyntax() + "]");
}
LOG.info("finished probing TCs");
if(instance.destinationAET!=null){
LOG.info("Adding Accepted TCs to configuration backend");
ApplicationEntity destinationAE = conf
.findApplicationEntity(instance.destinationAET);
Device toStore = destinationAE.getDevice();
TransferCapability[] TCs = mergeTCs(acceptedPCs);
for (TransferCapability tc : TCs)
toStore.getApplicationEntity(instance.destinationAET)
.addTransferCapability(tc);
conf.merge(toStore);
logAddedTCs(TCs, destinationAE);
conf.close();
}
System.exit(1);
} catch (ConfigurationException e) {
LOG.error("Configuration backend error - {}", e);
}
} else if (cl.hasOption("prefs")) {
// prefs
try {
PreferencesDicomConfiguration conf = new PreferencesDicomConfiguration();
LOG.info("Started Loading LDAP configuration");
ArrayList<TransferCapability> tcs = null;
if(cl.hasOption("s")){
ApplicationEntity sourceAE = conf
.findApplicationEntity(instance.sourceAET);
tcs = (ArrayList<TransferCapability>) sourceAE
.getTransferCapabilities();
}
else
{
tcs = loadTCFile();
}
ArrayList<PresentationContext> pcs = addChunkedPCsandSend(
ae, device, instance, tcs);
// print accepted ones
ArrayList<PresentationContext> acceptedPCs = new ArrayList<PresentationContext>();
for (PresentationContext pc : pcs)
if (pc.isAccepted())
acceptedPCs.add(pc);
LOG.info("Probed the source ae and found the following accepted presentation contexts");
for (PresentationContext pc : acceptedPCs) {
LOG.info("PC[" + pc.getPCID() + "]\tAbstractSyntax:"
+ pc.getAbstractSyntax() + "\n with "
+ " the following Transfer-Syntax:["
+ pc.getTransferSyntax() + "]");
}
LOG.info("finished probing TCs");
if(instance.destinationAET!=null){
LOG.info("Adding Accepted TCs to configuration backend");
ApplicationEntity destinationAE = conf
.findApplicationEntity(instance.destinationAET);
Device toStore = destinationAE.getDevice();
TransferCapability[] TCs = mergeTCs(acceptedPCs);
for (TransferCapability tc : TCs)
toStore.getApplicationEntity(instance.destinationAET)
.addTransferCapability(tc);
conf.merge(toStore);
logAddedTCs(TCs, destinationAE);
conf.close();