Coverage Report - org.jtheque.films.services.impl.utils.web.analyzers.AnalyzerUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
AnalyzerUtils
0 %
0/14
0 %
0/4
2.5
 
 1  
 package org.jtheque.films.services.impl.utils.web.analyzers;
 2  
 
 3  
 /*
 4  
  * This file is part of JTheque.
 5  
  *
 6  
  * JTheque is free software: you can redistribute it and/or modify
 7  
  * it under the terms of the GNU General Public License as published by
 8  
  * the Free Software Foundation, either version 3 of the License.
 9  
  *
 10  
  * JTheque is distributed in the hope that it will be useful,
 11  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  
  * GNU General Public License for more details.
 14  
  *
 15  
  * You should have received a copy of the GNU General Public License
 16  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 17  
  */
 18  
 
 19  
 import org.jtheque.core.managers.Managers;
 20  
 import org.jtheque.core.managers.log.ILoggingManager;
 21  
 import org.jtheque.films.persistence.od.able.Film;
 22  
 import org.jtheque.utils.io.FileException;
 23  
 import org.jtheque.utils.io.FileUtils;
 24  
 
 25  
 import java.io.File;
 26  
 
 27  
 /**
 28  
  * Utils for the analyzer.
 29  
  *
 30  
  * @author Baptiste Wicht
 31  
  */
 32  
 final class AnalyzerUtils {
 33  
     /**
 34  
      * Construct a new AnalyzerUtils.
 35  
      */
 36  
     private AnalyzerUtils() {
 37  0
         super();
 38  0
     }
 39  
 
 40  
     /**
 41  
      * Download the image of a film.
 42  
      *
 43  
      * @param film The film.
 44  
      * @param path The path to the image.
 45  
      */
 46  
     public static void downloadMiniature(Film film, String path) {
 47  0
         File folder = new File(Managers.getCore().getFolders().getApplicationFolder().getAbsolutePath() +
 48  
                 "/miniatures");
 49  
 
 50  0
         boolean ok = true;
 51  
 
 52  0
         if (!folder.exists()) {
 53  0
             ok = folder.mkdirs();
 54  
         }
 55  
 
 56  0
         if (ok) {
 57  0
             String destinationPath = org.jtheque.films.utils.FileUtils.prepareFilePath(
 58  
                     Managers.getCore().getFolders().getApplicationFolder().getAbsolutePath() +
 59  
                             "/miniatures/" + film.getTitle() + ".jpg");
 60  
 
 61  
             try {
 62  0
                 FileUtils.downloadFile(path, destinationPath);
 63  0
             } catch (FileException e) {
 64  0
                 Managers.getManager(ILoggingManager.class).getLogger(AnalyzerUtils.class).error(e);
 65  0
             }
 66  
 
 67  0
             film.setImage(destinationPath);
 68  
         }
 69  0
     }
 70  
 }