Conditions { public boolean match(String sendingHost, String sendingAET, String receivingHost, String receivingAET, Attributes attrs) { for (Map.Entry<String, Pattern> entry : map.entrySet()) { String tagPath = entry.getKey(); Pattern pattern = entry.getValue(); boolean ne = tagPath.endsWith("!"); if (ne) tagPath = tagPath.substring(0, tagPath.length()-1); int valPos = 0; if (tagPath.endsWith("]")) { String[] tagPathWithValPos = tagPath.split("\\["); tagPath = tagPathWithValPos[0]; valPos = Integer.parseInt(tagPathWithValPos[1].substring(0, tagPathWithValPos[1].length() - 1)); } switch (tagPath) { case RECEIVING_APPLICATION_ENTITY_TITLE: if (ne ? (receivingAET != null && pattern.matcher(receivingAET).matches()) : (receivingAET == null || !pattern.matcher(receivingAET).matches())) return false; break; case RECEIVING_HOSTNAME: if (ne ? (receivingHost != null && pattern.matcher(receivingHost).matches()) : (receivingHost == null || !pattern.matcher(receivingHost).matches())) return false; break; case SENDING_APPLICATION_ENTITY_TITLE: if (ne ? (sendingAET != null && pattern.matcher(sendingAET).matches()) : (sendingAET == null || !pattern.matcher(sendingAET).matches())) return false; break; case SENDING_HOSTNAME: if (ne ? (sendingHost != null && pattern.matcher(sendingHost).matches()) : (sendingHost == null || !pattern.matcher(sendingHost).matches())) return false; break; default: if (!match(attrs, TagUtils.parseTagPath(tagPath), pattern, 0, ne, valPos)) return false; } } return true; } Conditions(String... props); void setReceivingAETitle(String value); void setNotReceivingAETitle(String value); void setReceivingHostname(String value); void setNotReceivingHostname(String value); void setSendingAETitle(String value); void setNotSendingAETitle(String value); void setSendingHostname(String value); void setNotSendingHostname(String value); void setCondition(String tagPath, String value); Map<String,Pattern> getMap(); boolean match(String sendingHost, String sendingAET,
            String receivingHost, String receivingAET, Attributes attrs); @Override String toString(); @Override boolean equals(Object obj); static final String RECEIVING_APPLICATION_ENTITY_TITLE; static final String RECEIVING_HOSTNAME; static final String SENDING_APPLICATION_ENTITY_TITLE; static final String SENDING_HOSTNAME; }
@Test public void match() throws Exception { Attributes empty = new Attributes(); Conditions hostname = new Conditions("SendingHostname=storescu"); assertTrue(hostname.match("storescu", null, null, null, empty)); assertFalse(hostname.match("dcmqrscp", null, null, null, empty)); assertFalse(hostname.match("dcmqrscp", null, null, null, empty)); Conditions nothostname = new Conditions("SendingHostname!=storescu"); assertFalse(nothostname.match("storescu", null, null, null, empty)); assertTrue(nothostname.match("dcmqrscp", null, null, null, empty)); assertTrue(nothostname.match(null, null, null, null, empty)); Conditions sending = new Conditions("SendingApplicationEntityTitle=STORESCU"); assertTrue(sending.match(null, "STORESCU", null, null, empty)); assertFalse(sending.match(null, "DCMQRSCP", null, null, empty)); assertFalse(sending.match(null, null, null, null, empty)); Conditions notsending = new Conditions("SendingApplicationEntityTitle!=STORESCU"); assertFalse(notsending.match(null, "STORESCU", null, null, empty)); assertTrue(notsending.match(null, "DCMQRSCP", null, null, empty)); assertTrue(notsending.match(null, null, null, null, empty)); Conditions receiving = new Conditions("ReceivingApplicationEntityTitle=DCM4CHEE"); assertTrue(receiving.match(null, null, null, "DCM4CHEE", empty)); assertFalse(receiving.match(null, null, null, "DCMQRSCP", empty)); assertFalse(receiving.match(null, null, null, null, empty)); Conditions notreceiving = new Conditions("ReceivingApplicationEntityTitle!=DCM4CHEE"); assertFalse(notreceiving.match(null, null, null, "DCM4CHEE", empty)); assertTrue(notreceiving.match(null, null, null, "DCMQRSCP", empty)); assertTrue(notreceiving.match(null, null, null, null, empty)); Attributes ct = modality("CT"); Attributes mr = modality("MR"); Attributes emptyModality = modality(null); Conditions modality = new Conditions("Modality=CT"); assertTrue(modality.match(null, null, null, null, ct)); assertFalse(modality.match(null, null, null, null, mr)); assertFalse(modality.match(null, null, null, null, emptyModality)); assertFalse(modality.match(null, null, null, null, empty)); Conditions notmodality = new Conditions("Modality!=CT"); assertFalse(notmodality.match(null, null, null, null, ct)); assertTrue(notmodality.match(null, null, null, null, mr)); assertTrue(notmodality.match(null, null, null, null, emptyModality)); assertTrue(notmodality.match(null, null, null, null, empty)); Conditions nomodality = new Conditions("Modality!=.+"); assertFalse(nomodality.match(null, null, null, null, ct)); assertFalse(nomodality.match(null, null, null, null, mr)); assertTrue(nomodality.match(null, null, null, null, emptyModality)); assertTrue(nomodality.match(null, null, null, null, empty)); Attributes spsItemCT = spsItem(ct); Attributes spsItemMR = spsItem(mr); Attributes spsItemEmpty = spsItem(empty); Conditions spsItem = new Conditions("00400100.Modality=CT"); assertTrue(spsItem.match(null, null, null, null, spsItemCT)); assertFalse(spsItem.match(null, null, null, null, spsItemMR)); assertFalse(spsItem.match(null, null, null, null, spsItemEmpty)); assertFalse(spsItem.match(null, null, null, null, empty)); Conditions notSpsItem = new Conditions("00400100.Modality!=CT"); assertFalse(notSpsItem.match(null, null, null, null, spsItemCT)); assertTrue(notSpsItem.match(null, null, null, null, spsItemMR)); assertTrue(notSpsItem.match(null, null, null, null, spsItemEmpty)); assertTrue(notSpsItem.match(null, null, null, null, empty)); }