package com.sap.mentors.lemonaid.jobs;

import java.io.IOException;

import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sap.mentors.lemonaid.entities.Mentor;
import com.sap.mentors.lemonaid.external.GravatarImage;
import com.sap.mentors.lemonaid.repository.MentorRepository;
import com.sap.mentors.lemonaid.utils.MentorUtils;

@Service
@Transactional
@DisallowConcurrentExecution
public class GravatarJob implements Job {
    
	private static final Logger log = LoggerFactory.getLogger(GravatarJob.class);

	@Autowired GravatarImage gravatar;
	@Autowired MentorRepository mentorRepository;
	@Autowired MentorUtils mentorUtils;

    @Override
	public void execute(JobExecutionContext arg0) throws JobExecutionException {
		log.info("Setting photoUrl of mentors - Start");
		long startTime = System.currentTimeMillis();
    	for (Mentor mentor : mentorRepository.findAll()) {
    		try {
				mentor.setPhotoUrl(mentorUtils.getImageOfMentor(mentor));
	    		mentorRepository.save(mentor);
			} catch (IOException e) {
				log.warn("Error occurred while refreshing photo of mentor '" + mentor.getId() + "': " + e.getMessage());
			}
    	}
		log.info("Setting photoUrl of mentors - End. Duration: " + Long.toString(System.currentTimeMillis() - startTime) + "ms");
	}

}
@@ -758,20 +758,16 @@
 s Job %7B%0A
-    
 %0A%09privat
@@ -850,17 +850,18 @@
 utowired
- 
+%0A%09
 Gravatar
@@ -883,25 +883,26 @@
 %0A%09@Autowired
- 
+%0A%09
 MentorReposi
@@ -935,17 +935,18 @@
 utowired
- 
+%0A%09
 MentorUt
@@ -963,20 +963,17 @@
 Utils;%0A%0A
-    
+%09
 @Overrid
@@ -1150,20 +1150,17 @@
 llis();%0A
-    
+%09
 %09for (Me
@@ -1203,20 +1203,17 @@
 ll()) %7B%0A
-    
+%09
 %09%09try %7B%0A
@@ -1275,20 +1275,17 @@
 tor));%0A%09
-    
+%09
 %09%09mentor
@@ -1456,12 +1456,9 @@
 %09%09%7D%0A
-    
+%09
 %09%7D%0A%09

Format source