package gov.nih.nci.ncia.annotations;

import java.io.File;

import org.rsna.ctp.objects.XmlObject;
import org.rsna.ctp.objects.ZipObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.springframework.beans.factory.annotation.Qualifier;

/**
 * As an XML annotation is submitted, look at content to see what kind it is
 * and provide a processor object that knows how to deal with it.
 *
 * <P>There's probably alot of opportunity to make this more extensible,
 * but no need for prototype...just supporting AIM or "traditional" (i.e. LIDC) annotations.
 */
public class AnnotationRecognizerImpl implements AnnotationRecognizer {

	public AnnotationSubmissionProcessor recognizeAnnotation(ZipObject file,
	  	                                                     File storedFile) {
        return traditionalAnnotationSubmissionProcessor;
    }

	public AnnotationSubmissionProcessor recognizeAnnotation(XmlObject file,
			                                                 File storedFile) {

        if(isAIMAnnotation(file, storedFile)) {
        	System.out.println("AIM annotation is recognized:"+aimAnnotationSubmissionProcessor);
        	return aimAnnotationSubmissionProcessor;
		}
        else {
        	return traditionalAnnotationSubmissionProcessor;
        }
	}

	////////////////////////////////////////PRIVATE//////////////////////////////////////
	@Autowired
	@Qualifier("aimAnnotationSubmissionProcessor")
	private AnnotationSubmissionProcessor  aimAnnotationSubmissionProcessor;

	@Autowired
	@Qualifier("traditionalAnnotationSubmissionProcessor")
	private AnnotationSubmissionProcessor  traditionalAnnotationSubmissionProcessor;

	private boolean isAIMAnnotation(XmlObject file, File storedFile) {
		Document document = file.getDocument();
		Element documentElement = document.getDocumentElement();

		System.out.println("isAim:"+documentElement.getLocalName()+","+documentElement.getNamespaceURI());

		return documentElement.getLocalName().equals("ImageAnnotation") &&
		       documentElement.getNamespaceURI().equals("gme://caCORE.caCORE/3.2/edu.northwestern.radiology.AIM");
	}
}

@@ -877,24 +877,83 @@
 redFile) %7B%0D%0A
+%09%09System.out.println(%22zip:%22+file+%22, stored:%22+storedFile);%0D%0A
         retu
@@ -1191,20 +1191,8 @@
 file
-, storedFile
 )) %7B
@@ -1870,25 +1870,8 @@
 file
-, File storedFile
 ) %7B%0D

fix pmd