package com.dstsystems.hackathon.autotempo.main;

import com.dstsystems.hackathon.autotempo.models.*;
import com.dstsystems.hackathon.autotempo.service.AppointmentServiceImpl;
import com.dstsystems.hackathon.autotempo.service.FirstMatchRuleSetProcessor;
import com.dstsystems.hackathon.autotempo.service.UserProfileService;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * Created by user on 06/11/2015.
 */
public class Main {

    private static Date generateDateFromString( String dateInString ) {
        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
        Date date = new Date();
        try {
            date = sdf.parse(dateInString);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }

    public static void main(String[] args) {

        AppointmentServiceImpl appointmentService = new AppointmentServiceImpl();
        UserProfileService userProfileService = new UserProfileService();

        // To get appointments.
        ExchangeUserProfileModel xchangeUserProfile = userProfileService.getExChangeUserProfile("src/test/resources/user.profile");
        Date startDate = generateDateFromString( "11/07/2015" );
        Date endDate = generateDateFromString( "11/07/2015" );
        try {
            List<AppointmentModel> appointmetList = appointmentService.downloadExchangeAppointments(xchangeUserProfile, startDate, endDate);
            SimpleCategoryMappingRule rule = new SimpleCategoryMappingRule();
            rule.setComment("Test comment");
            rule.setIssueKey("INT-1");
            rule.setAccountKey("ATT02");
            rule.setCategory("INTERNAL");

            RuleSet ruleSet = new RuleSet();
            ruleSet.setRuleList(Arrays.asList((Rule) rule));

            for (int i = 0; i < appointmetList.size(); i++ )
            {
                AppointmentModel appointmentModel = appointmetList.get(i);

                WorklogModel worklogModel = new WorklogModel();
                new FirstMatchRuleSetProcessor().process(worklogModel, appointmentModel, ruleSet);

                System.out.println( worklogModel.getAccountKey() );

                System.out.println( worklogModel.getComment() );

                System.out.println( worklogModel.getIssueKey() );


            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }


}

@@ -517,24 +517,101 @@
 ass Main %7B%0A%0A
+    public static final String DEFAULT_USER_PROFILE_PATH = %22/user.profile%22;%0A%0A
     private 
@@ -645,17 +645,16 @@
 mString(
- 
 String d
@@ -1133,24 +1133,166 @@
 Service();%0A%0A
+        String userProfilePath = DEFAULT_USER_PROFILE_PATH;%0A%0A        if (args%5B0%5D != null) %7B%0A            userProfilePath = args%5B0%5D;%0A        %7D%0A%0A
         // T
@@ -1411,41 +1411,23 @@
 ile(
-%22src/test/resources/
 user
-.p
+P
 rofile
-%22
+Path
 );%0A 
@@ -1607,24 +1607,25 @@
 l%3E appointme
+n
 tList = appo
@@ -1725,345 +1725,43 @@
     
-SimpleCategoryMappingRule rule = new SimpleCategoryMappingRule();%0A            rule.setComment(%22Test comment%22);%0A            rule.setIssueKey(%22INT-1%22);%0A            rule.setAccountKey(%22ATT02%22);%0A            rule.setCategory(%22INTERNAL%22);%0A%0A            RuleSet ruleSet = new RuleSet();%0A            ruleSet.setRuleList(Arrays.asList((Rule) rule)
+RuleSet ruleSet = getSimpleRuleSet(
 );%0A%0A
@@ -1797,24 +1797,25 @@
  %3C appointme
+n
 tList.size()
@@ -1897,16 +1897,17 @@
 ppointme
+n
 tList.ge
@@ -2279,17 +2279,16 @@
 y() );%0A%0A
-%0A
         
@@ -2376,11 +2376,414 @@
 %0A    %7D%0A%0A
+    private static RuleSet getSimpleRuleSet() %7B%0A        SimpleCategoryMappingRule rule = new SimpleCategoryMappingRule();%0A        rule.setComment(%22Test comment%22);%0A        rule.setIssueKey(%22INT-1%22);%0A        rule.setAccountKey(%22ATT02%22);%0A        rule.setCategory(%22INTERNAL%22);%0A%0A        RuleSet ruleSet = new RuleSet();%0A        ruleSet.setRuleList(Arrays.asList((Rule) rule));%0A        return ruleSet;%0A    %7D%0A%0A
 %0A%7D%0A

Modify main to accept UserProfile path