/
Main.java
171 lines (145 loc) · 6.25 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package customSortServerV4;
import java.util.ArrayList;
public class Main {
static boolean testingInWindows=false; //BEFORE COMPILING TO JAR:Switch to false before execution in Ubuntu.
public static void main(String[] args) {
// TODO Auto-generated method stub
String filepath=ReadTasks.getFilePath(testingInWindows);
ArrayList<String> lines=ReadTasks.readFile(filepath);
ArrayList<Task> unSortedTaskList = ReadTasks.separarateLines(lines);
ArrayList<Task> sortedTaskList = ReadTasks.separarateLines(lines);
//Print description and uuids of unsorted tasklist:
for (int i=0;i<unSortedTaskList.size();i++) {
System.out.println(unSortedTaskList.get(i).getDescription()+" and task uuid = "+unSortedTaskList.get(i).getUuid());
}
//Get urgency and add it to tasks
addUrgency(unSortedTaskList);
//Sort taskList:
sortedTaskList =CreateSorts.mainSort(unSortedTaskList);
//Print description and uuids of unsorted tasklist:
for (int i=0;i<sortedTaskList.size();i++) {
System.out.println(sortedTaskList.get(i).getDescription()+" and task uuid = "+sortedTaskList.get(i).getUuid());
}
//Create customSortUDA in tw:
createUDA(hardCoded.getNameOfCustomSortParameter(), hardCoded.getNameOfCustomSortParameterLabel(),hardCoded.getCustomSortDataType());
//create customReport
createCustomReport(hardCoded.getCustomReportName());
//Run a command and store the output:
//commandOutput=RunCommands.runCommands();
//Print command output and return urgency
}
/**
* This method:
* 0. iterates through the tasks,
* 1. Gets the uuid of the tasks
* 2. Creates per task a command task <uuid>
* 3. executes a unix command that returns the task properties.
* 4. Stores the output of that command
* 5. gets the Urgency
* 6. Stores the urgency to that task.
* @param unSortedTaskList
*/
private static void addUrgency(ArrayList<Task> taskList) {
String uuid=null;
String command=null;
double urgency;
ArrayList<ArrayList<String>> commandOutput = new ArrayList<ArrayList<String>>();
//Loop through taskList
for (int i = 0;i<taskList.size();i++) {
//get uuid
uuid=taskList.get(i).getUuid();
//create command
command = hardCoded.getSudo()+"task "+uuid;
//run command
commandOutput=RunCommands.runCommands(command);
//print output and get urgency:
urgency=ReadCommandOutput.splitOutput(commandOutput,true);
//store urgency in task
taskList.get(i).setUrgency(urgency);
}
}
/**
* This method:
* 0. iterates through the (sorted) tasks,
* 1. Gets the uuid of the tasks
* 2. Creates per task a command task <uuid> customSort:+i
* 3. executes a unix command that returns the task properties.
* 4. Stores the output of that command
* 5. gets the Urgency
* 6. Stores the urgency to that task.
* @param unSortedTaskList
*/
private static void setCustomSort(ArrayList<Task> taskList) {
String uuid=null;
String command=null;
double urgency;
ArrayList<ArrayList<String>> commandOutput = new ArrayList<ArrayList<String>>();
//Loop through taskList
for (int i = 0;i<taskList.size();i++) {
//get uuid
uuid=taskList.get(i).getUuid();
//create command
command = hardCoded.getSudo()+"task "+uuid;
System.out.println("Running command:"+command);
//run command
commandOutput=RunCommands.runCommands(command);
//print output and get urgency:
urgency=ReadCommandOutput.splitOutput(commandOutput,true);
System.out.println("Urgency="+urgency);
//store urgency in task
taskList.get(i).setUrgency(urgency);
}
}
/**
* Method creates a user defined Attribute if the data type is correct
* Thows error datatype is not correct.
* TODO: write proper exception
* @param udaName
* @param label
* @param type
*/
private static void createUDA(String udaName, String label,String type) {
if (type.equals("numeric") || type.equals("string") || type.equals("date") || type.equals("duration")){
// RunCommands.runCommands(hardCoded.getSudo()+"yes | task config uda."+udaName+".type "+type);
// RunCommands.runCommands(hardCoded.getSudo()+"yes | task config uda."+udaName+".label"+ label);
RunCommands.runCommands(hardCoded.getSudo()+"task config uda."+udaName+".type "+type);
RunCommands.runCommands(hardCoded.getSudo()+"task config uda."+udaName+".label"+ label);
}else {
try {
throw new Exception();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
private static void createCustomReport(String reportName) {
int commandDimensions=6;
String[] commands =new String[commandDimensions];
// commands[0]=hardCoded.getSudo()+"yes | task config report."+reportName+".description 'Custom sorted list of all tasks.'";
// commands[1]=hardCoded.getSudo()+"yes | task config report."+reportName+".columns 'id,depends,due,priority,urgency,duration,project,recur,tags,description,start'";
// commands[2]=hardCoded.getSudo()+"yes | task config report."+reportName+".labels 'id,dep,due,prio,urgy,dura,proj,again,tag, descr,start'";
// commands[3]=hardCoded.getSudo()+"yes | task config report."+reportName+".sort 'customSort+'";
// commands[4]=hardCoded.getSudo()+"yes | task config report."+reportName+".filter 'status:pending";
commands[0]=hardCoded.getSudo()+"task config report."+reportName+".description 'Custom sorted list of all tasks.'";
commands[1]=hardCoded.getSudo()+"task config report."+reportName+".columns 'id,depends,due,priority,urgency,duration,project,recur,tags,description,start'";
commands[2]=hardCoded.getSudo()+"task config report."+reportName+".labels 'id,dep,due,prio,urgy,dura,proj,again,tag, descr,start'";
commands[3]=hardCoded.getSudo()+"task config report."+reportName+".sort 'customSort+'";
commands[4]=hardCoded.getSudo()+"task config report."+reportName+".filter 'status:pending";
//run commands if the reportname is not empty:
if (reportName!=null && reportName.length()>0) {
for (int i=0;i<commandDimensions;i++) {
RunCommands.runCommands(commands[i]);
}
}
}
public static boolean isTestingInWindows() {
return testingInWindows;
}
public static void setTestingInWindows(boolean testingInWindows) {
Main.testingInWindows = testingInWindows;
}
public static ArrayList<Task> createSortingCommands(ArrayList<Task> unsorted){
return null;
}
}