    [cmr.message-queue.services.queue :as queue])
   (:import
    (com.amazonaws ClientConfiguration)
-   (com.amazonaws.auth.policy Condition Policy Principal Statement Statement$Effect)
+   (com.amazonaws.auth.policy Condition Policy Principal Resource Statement Statement$Effect)
    (com.amazonaws.auth.policy.actions SQSActions)
    (com.amazonaws.auth.policy.conditions ConditionFactory)
    (com.amazonaws.services.sns AmazonSNSClient)

       q-arn (get-queue-arn sqs-client q-name)
       q-url (.getQueueUrl (.getQueueUrl sqs-client q-name))
       ;; create an access policy to allow the topic to publish to the queue
       access-policy (sns-to-sqs-access-policy sns-client sqs-client queue-name exchange-names)
       q-attrs (HashMap. {"Policy" access-policy})

       ;; create and empty SetQueueAttributesRequest object and then set the attributes on it
       set-queue-attrs-request (doto (SetQueueAttributesRequest.)
                                     (.setAttributes q-attrs)
                                     (.setQueueUrl q-url))]

  "Returns an access policy allowing the given SNS topic to publish to the given SQS queue."
  [sns-client sqs-client queue-name exchange-names]
  (let [conditions (topic-conditions sns-client exchange-names)
        queue-arn (get-queue-arn sqs-client queue-name)
        resource (Resource. queue-arn)
        statement (doto (Statement. Statement$Effect/Allow)
                        (.withPrincipals (into-array Principal [Principal/AllUsers]))
                        (.withActions (into-array SQSActions [SQSActions/SendMessage]))
                        (.withResources (into-array Resource [resource]))
                        (.withConditions (into-array Condition conditions)))
        policy (.withStatements (Policy.) (into-array Statement [statement]))]
    (.toJson policy)))
