package eu.cloudopting.web.rest;

import javax.annotation.security.RolesAllowed;
import javax.inject.Inject;
import javax.jcr.Repository;
import javax.jcr.Session;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import eu.cloudopting.security.AuthoritiesConstants;
import eu.cloudopting.store.StoreService;

//http://lab1.cloudopting.org:8083/repository/default/organization_key/XVS_NEWT/template/go.png
//http%3A%2F%2Flab1.cloudopting.org%3A8083%2Frepository%2Fdefault%2Forganization_key%2FXVS_NEWT%2Ftemplate%2Fgo.png
//http://localhost:8080/jr/img?jcrPath=http%3A%2F%2Flab1.cloudopting.org%3A8083%2Frepository%2Fdefault%2Forganization_key%2FXVS_NEWT%2Ftemplate%2Fgo.png


@RestController
@RequestMapping("/jr")
public class JcrImageResource {

	private final Logger log = LoggerFactory.getLogger(JcrImageResource.class);
	
	@Autowired(required = true)
	private StoreService storeService;
	
	@Inject 
	private Repository repo;
		
	@Inject
	private Session session;
    
    /**
     * JackRabbit Repository URL
     */
    @Value("${spring.jcr.repo_http}")
	private String jrHttp;
	
	@RequestMapping(value = "/img", method = RequestMethod.GET)
	@RolesAllowed(AuthoritiesConstants.ANONYMOUS)
	public final String getJcrImage(@RequestParam("jcrPath") String jcrPath) {
		String jrRepositoryBase = "http://lab1.cloudopting.org:8083/repository/default/";
		if (storeService!=null){
			jrRepositoryBase = jrHttp;
		}else{
			String s = "Store Service NOT injected!";
			if (log!=null){
				log.error(s);
			}else{
				System.out.println(s);
			}
		}
		String relativePath = StringUtils.removeStart(jcrPath, jrRepositoryBase); 
		return relativePath;
	}
	
	public Logger getLog() {
		return log;
	}

	public StoreService getStoreService() {
		return storeService;
	}

	@Required
	public void setStoreService(StoreService storeService) {
		this.storeService = storeService;
	}
	
}
@@ -1314,34 +1314,14 @@
 %09%0A%09@
-Autowired(required = true)
+Inject
 %0A%09pr
@@ -1821,17 +1821,20 @@
 ;%0A%09%09if (
-s
+getS
 toreServ
@@ -1836,16 +1836,18 @@
 eService
+()
 !=null)%7B
@@ -2231,119 +2231,8 @@
 ce;%0A
+
 %09%7D
-%0A%0A%09@Required%0A%09public void setStoreService(StoreService storeService) %7B%0A%09%09this.storeService = storeService;%0A%09%7D%0A%09
 %0A%7D

Fix StoreService injection problem