package org.fedorahosted.flies.core.rest;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

import net.openl10n.api.ContentType;
import net.openl10n.api.rest.document.Document;
import net.openl10n.api.rest.project.Project;

import org.fedorahosted.flies.core.model.ProjectIteration;
import org.jboss.seam.Component;
import org.jboss.seam.annotations.Name;

@Name("projectIterationResource")
public class ProjectIterationResourceImpl implements ProjectIterationResource{

	private ProjectIteration projectIteration;
	
	public void setProjectIteration(ProjectIteration projectIteration) {
		this.projectIteration = projectIteration;
	}

	@Override
	public Project get(String extensions) {
		Project p = new Project("id", "name", "summary");
		if(extensions != null && extensions.contains("docs")){
			p.getDocuments().add( new Document("/path/to/doc.txt", ContentType.TextPlain ) );
		}
		return p;
	}
	
	@Override
	public DocumentResource getDocument(String documentId) {
		DocumentResourceImpl docRes = (DocumentResourceImpl) Component.getInstance(DocumentResourceImpl.class, true);
		//docRes.setProject();
		return DocumentResourceImpl.getProxyWrapper(docRes);
	}
	
	
	// hack to allow sub-resource in resteasy
	public static ProjectIterationResource getProxyWrapper(final ProjectIterationResource instance){
		return new ProjectIterationResource(){

			@Override
			public Project get(String extensions) {
				return instance.get(extensions);
			}
			
			@Override
			public DocumentResource getDocument(String documentId) {
				return instance.getDocument(documentId);
			}
			
		};
	}	
	
}

@@ -32,24 +32,47 @@
 core.rest;%0A%0A
+import java.util.Set;%0A%0A
 import javax
@@ -83,16 +83,16 @@
 rs.GET;%0A
-
 import j
@@ -266,24 +266,68 @@
 t.Project;%0A%0A
+import org.apache.commons.lang.StringUtils;%0A
 import org.f
@@ -447,16 +447,64 @@
 .Name;%0A%0A
+import com.google.common.collect.ImmutableSet;%0A%0A
 @Name(%22p
@@ -810,31 +810,24 @@
 t(String ext
-ensions
 ) %7B%0A%09%09Projec
@@ -870,16 +870,91 @@
 mary%22);%0A
+%09%09Set%3CString%3E extensions = ImmutableSet.of( StringUtils.split(ext, ',') );%0A
 %09%09if(ext

split extensions up into a string-set