package org.zoneproject.extractor.plugin.extractarticlescontent;

/*
 * #%L
 * ZONE-plugin-ExtractArticlesContent
 * %%
 * Copyright (C) 2012 ZONE-project
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * #L%
 */

import org.zoneproject.extractor.utils.Item;
import org.zoneproject.extractor.utils.Prop;
import org.zoneproject.extractor.utils.VirtuosoDatabase;
import org.zoneproject.extractor.utils.ZoneOntology;

/**
 *
 * @author Desclaux Christophe <christophe@zouig.org>
 */
public class App 
{
    private static final org.apache.log4j.Logger  logger = org.apache.log4j.Logger.getLogger(App.class);
    public static String PLUGIN_URI = ZoneOntology.PLUGIN_EXTRACT_ARTICLES_CONTENT;
    public static String PLUGIN_RESULT_URI = ZoneOntology.PLUGIN_EXTRACT_ARTICLES_CONTENT_RES;
    
    public App(){
        String [] tmp = {};
        App.main(tmp);
    }
     /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Item[] items = null;
        do{
            items = VirtuosoDatabase.getItemsNotAnotatedForOnePlugin(PLUGIN_URI,100);
            logger.info("ExtractArticlesContent has "+items.length+" items to annotate");
            for(Item item : items){
                VirtuosoDatabase.addAnnotation(item.getUri(), new Prop(App.PLUGIN_URI,"true"));
                if(item.uri.startsWith("https://twitter.com/")){
                    continue;
                }
                new DownloadThread(item).start();
            }
        }while(items.length > 0);
    }
}

@@ -1839,24 +1839,414 @@
 items)%7B%0A    
+            App.startThread(item);%0A            %7D%0A        %7Dwhile(items.length %3E 0);%0A    %7D%0A    private static void startThread(Item item) %7B%0A        startThread(item,0);%0A    %7D%0A    private static void startThread(Item item, int restartLevel) %7B%0A        if(restartLevel %3E 5) %7B%0A            logger.warn(%22annotation process imposible for %22+item.getUri());%0A            return;%0A        %7D%0A        try%7B%0A
             
@@ -2337,20 +2337,16 @@
         
-    
 if(item.
@@ -2406,26 +2406,16 @@
     
-   
- continue;%0A    
+return;%0A
     
@@ -2435,21 +2435,16 @@
         
-    
- 
 new Down
@@ -2481,47 +2481,209 @@
     
-    %7D%0A        %7Dwhile(items.length %3E 0);
+%7Dcatch (com.hp.hpl.jena.shared.JenaException ex)%7B%0A            logger.warn(%22annotation process because of virtuoso partial error %22+item.getUri());%0A            startThread(item,restartLevel+1);%0A        %7D
 %0A   

work on the threadsafe extractarticlescontent