001/** 002 * Copyright 2014 Tampere University of Technology, Pori Department 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package service.tut.pori.facebookjazz; 017 018import java.util.EnumSet; 019 020import org.apache.log4j.Logger; 021import org.quartz.JobExecutionContext; 022import org.quartz.JobExecutionException; 023 024import service.tut.pori.contentanalysis.AnalysisBackend; 025import service.tut.pori.contentanalysis.AnalysisBackend.Capability; 026import service.tut.pori.contentanalysis.PhotoAnalysisTask; 027import service.tut.pori.contentanalysis.AsyncTask; 028import service.tut.pori.contentanalysis.BackendStatus; 029import service.tut.pori.contentanalysis.PhotoTaskResponse; 030import core.tut.pori.context.ServiceInitializer; 031 032/** 033 * An implementation of ASyncTask, meant for executing a Facebook summarization feedback task. 034 * 035 * Requires a valid taskId for execution, provided in a JobExecutionContext. 036 */ 037public class FBSummarizationFeedbackTask extends AsyncTask { 038 private static final Logger LOGGER = Logger.getLogger(FBSummarizationFeedbackTask.class); 039 040 /** 041 * 042 * @param response 043 */ 044 public static void taskFinished(PhotoTaskResponse response) { 045 TaskStatus status = response.getStatus(); 046 if(status == null){ 047 LOGGER.warn("Task status not available."); 048 status = TaskStatus.UNKNOWN; 049 } 050 051 Long taskId = response.getTaskId(); 052 LOGGER.debug("Task, id: "+taskId+" finished for back-end, id: "+response.getBackendId()); 053 054 ServiceInitializer.getDAOHandler().getSQLDAO(FBTaskDAO.class).updateTaskStatus(new BackendStatus(new AnalysisBackend(response.getBackendId()), status), taskId); 055 056 ServiceInitializer.getEventHandler().publishEvent(new AsyncTaskEvent(response.getBackendId(), PhotoAnalysisTask.class, status, response.getTaskId(), TaskType.FACEBOOK_PROFILE_SUMMARIZATION_FEEDBACK)); 057 } 058 059 @Override 060 public void execute(JobExecutionContext context) throws JobExecutionException { 061 executeAddTask(EnumSet.of(Capability.USER_FEEDBACK, Capability.FACEBOOK_SUMMARIZATION), ServiceInitializer.getDAOHandler().getSQLDAO(FBTaskDAO.class), getTaskId(context.getMergedJobDataMap())); 062 } 063}