Skip to content
Snippets Groups Projects
Commit e82dd350 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

main parser process excel prc-subject file

parent 25817cf5
No related branches found
No related tags found
1 merge request!1Appointments dev
...@@ -30,6 +30,11 @@ ...@@ -30,6 +30,11 @@
<groupId>org.apache.poi</groupId> <groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId> <artifactId>poi-ooxml</artifactId>
<version>3.15</version> <version>3.15</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.3.1</version>
</dependency> </dependency>
</dependencies> </dependencies>
......
package smash.appointment.parse;
import java.util.ArrayList;
import java.util.List;
public class AppointmentDao {
private List<AppointmentEntry> appointments = new ArrayList<>();
public void addAppointments(List<AppointmentEntry> appointmentsToAdd) {
appointments.addAll(appointmentsToAdd);
}
/**
* @return the appointments
* @see #appointments
*/
public List<AppointmentEntry> getAppointments() {
return appointments;
}
/**
* @param appointments the appointments to set
* @see #appointments
*/
public void setAppointments(List<AppointmentEntry> appointments) {
this.appointments = appointments;
}
}
...@@ -2,26 +2,63 @@ package smash.appointment.parse; ...@@ -2,26 +2,63 @@ package smash.appointment.parse;
import java.util.List; import java.util.List;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
public class Main { public class Main {
private static Logger logger = Logger.getLogger(Main.class); private static Logger logger = Logger.getLogger(Main.class);
public static void main(String[] args) throws Exception { SubjectDao subjectDao = new SubjectDao();
if (args.length < 2) { AppointmentDao appointmentDao = new AppointmentDao();
System.out.println("Usage: command <agenda.xlsx> <subjects.txt>");
} else { public void run(String[] args) throws Exception {
SubjectDao subjectDao = new SubjectDao();
subjectDao.readFile(args[1]); Options options = new Options();
Option agenda = Option.builder().required().argName("file").hasArg().desc("PRC agenda").longOpt("agenda").build();
XlsxCalendarProcessor processor = new XlsxCalendarProcessor(); Option subjects = Option.builder().required().argName("file").hasArg().desc("PRC subjects").longOpt("subjects").build();
processor.setSubjectDao(subjectDao); options.addOption(agenda);
options.addOption(subjects);
List<AppointmentEntry> entries = processor.processExcel(args[0]);
for (AppointmentEntry appointmentEntry : entries) { CommandLineParser parser = new DefaultParser();
logger.debug(appointmentEntry); try {
} CommandLine line = parser.parse(options, args);
String subjectsFile = line.getOptionValue("subjects");
subjectDao.addSubjects(processPrcSubjects(subjectsFile));
String agendaFile = line.getOptionValue("agenda");
appointmentDao.addAppointments(processPrcAppointments(agendaFile));
} catch (ParseException exp) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp( "java -jar file.jar", options );
}
}
private List<AppointmentEntry> processPrcAppointments(String agendaFile) throws Exception {
XlsxCalendarProcessor processor = new XlsxCalendarProcessor();
processor.setSubjectDao(subjectDao);
List<AppointmentEntry> entries = processor.processExcel(agendaFile);
for (AppointmentEntry appointmentEntry : entries) {
logger.debug(appointmentEntry);
} }
return entries;
}
public static void main(String[] args) throws Exception {
new Main().run(args);
}
private List<Subject> processPrcSubjects(String subjectsFile) throws Exception {
PrcSubjectsParser parser = new PrcSubjectsParser();
return parser.processExcel(subjectsFile);
} }
} }
...@@ -49,4 +49,10 @@ public class SubjectDao { ...@@ -49,4 +49,10 @@ public class SubjectDao {
return null; return null;
} }
public void addSubjects(List<Subject> processPrcSubjects) {
for (Subject subject : processPrcSubjects) {
addSubject(subject);
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment