package es.tid.ps.profile;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;

import es.tid.ps.profile.categoryextraction.CategoryExtractionJob;
import es.tid.ps.profile.export.mongodb.ExporterJob;
import es.tid.ps.profile.userprofile.UserProfileJob;

/**
 * Application entry point. Configures and chains mapreduce jobs.
 *
 * @author dmicol, sortega
 */
public class IndividualProfileMain extends Configured implements Tool {
    @Override
    public int run(String[] args)
            throws IOException, ClassNotFoundException, InterruptedException {
        if (args.length < 3 || args.length > 4) {
            throw new IllegalArgumentException("Mandatory parameters: "
                    + "weblogs_path categories_path profile_path [mongo_url]");
        }

        Path webLogsPath = new Path(args[0]);
        Path categoriesPath = new Path(args[1]);
        Path profilePath = new Path(args[2]);

        CategoryExtractionJob ceJob = new CategoryExtractionJob(this.getConf());
        ceJob.configure(webLogsPath, categoriesPath);
        if (!ceJob.waitForCompletion(true)) {
            return 1;
        }
        UserProfileJob upJob = new UserProfileJob(this.getConf());
        upJob.configure(categoriesPath, profilePath);
        if (!upJob.waitForCompletion(true)) {
            return 1;
        }

        if (args.length == 4) {
            String mongoUrl = args[3];
            ExporterJob exJob = new ExporterJob(this.getConf());
            exJob.configure(profilePath, mongoUrl);
            if (!exJob.waitForCompletion(true)) {
                return 1;
            }
        }

        return 0;
    }

    public static void main(String[] args) {
        try {
            int res = ToolRunner.run(new Configuration(),
                    new IndividualProfileMain(), args);
            System.exit(res);
        } catch (Exception ex) {
            ex.printStackTrace(System.err);
            System.exit(1);
        }
    }
}

@@ -600,16 +600,228 @@
  Tool %7B%0A
+    private static final String TMP_DIR = %22/tmp/individualprofile%22;%0A    private static final String CATEGORIES_PATH = TMP_DIR + %22/categories%22;%0A    private static final String PROFILE_PATH = TMP_DIR + %22profile%22;%0A%0A
     @Ove
@@ -965,17 +965,17 @@
 ength %3C 
-3
+1
  %7C%7C args
@@ -984,17 +984,17 @@
 ength %3E 
-4
+2
 ) %7B%0A    
@@ -1101,37 +1101,8 @@
 ath 
-categories_path profile_path 
 %5Bmon
@@ -1212,15 +1212,23 @@
 ath(
-args%5B1%5D
+CATEGORIES_PATH
 );%0A 
@@ -1266,15 +1266,20 @@
 ath(
-args%5B2%5D
+PROFILE_PATH
 );%0A%0A
@@ -1483,32 +1483,33 @@
 rn 1;%0A        %7D%0A
+%0A
         UserProf
@@ -1684,32 +1684,71 @@
 n 1;%0A        %7D%0A%0A
+        // Perform the MongoDB export.%0A
         if (args
@@ -1762,9 +1762,9 @@
  == 
-4
+2
 ) %7B%0A

Remove unnecessary parameters from the invidual profile.