66import org .apache .logging .log4j .io .IoBuilder ;
77import org .csuc .csv .*;
88import org .csuc .marshal .*;
9+ import org .csuc .poi .XLSX2CSV ;
910import org .csuc .serialize .JaxbMarshal ;
1011import org .csuc .typesafe .semantics .ClassId ;
1112import org .csuc .typesafe .semantics .Semantics ;
1415import xmlns .org .eurocris .cerif_1 .*;
1516
1617import javax .xml .datatype .DatatypeFactory ;
18+ import java .io .FileNotFoundException ;
1719import java .io .FileOutputStream ;
1820import java .util .*;
1921
@@ -30,8 +32,8 @@ public static void main(String[] args) {
3032 new App ().doMain (args );
3133 }
3234
33- public void doMain (String [] args ) {
34- this . bean = new ArgsBean (args );
35+ private void doMain (String [] args ) {
36+ bean = new ArgsBean (args );
3537 CmdLineParser parser = new CmdLineParser (bean );
3638 try {
3739 // parse the arguments.
@@ -40,7 +42,47 @@ public void doMain(String[] args) {
4042 System .exit (1 );
4143 }
4244
45+ XLSX2CSV xlsx2CSV = null ;
4346 try {
47+ xlsx2CSV = new XLSX2CSV (bean .getInput ().toFile ());
48+ xlsx2CSV .execute ();
49+
50+ xlsx2CSV .getFiles ().forEach ((key , value ) -> {
51+ try {
52+ switch (key ) {
53+ case researchers :
54+ bean .setResearcher (value .toPath ());
55+ break ;
56+ case departments :
57+ bean .setDepartment (value .toPath ());
58+ break ;
59+ case departments_relations :
60+ bean .setRelationDepartment (value .toPath ());
61+ break ;
62+ case research_groups :
63+ bean .setResearcherGroup (value .toPath ());
64+ break ;
65+ case research_groups_relations :
66+ bean .setRelationResearcherGroup (value .toPath ());
67+ break ;
68+ case projects :
69+ bean .setProject (value .toPath ());
70+ break ;
71+ case projects_relations :
72+ bean .setRelationProject (value .toPath ());
73+ break ;
74+ case publications :
75+ bean .setPublication (value .toPath ());
76+ break ;
77+ case publication_relations :
78+ bean .setRelationPublication (value .toPath ());
79+ break ;
80+ }
81+ } catch (FileNotFoundException e ) {
82+ logger .error (e );
83+ }
84+ });
85+
4486 CERIF cerif = new CERIF ();
4587
4688 GregorianCalendar gregory = new GregorianCalendar ();
@@ -51,6 +93,7 @@ public void doMain(String[] args) {
5193 List <CfPersType > cfPersTypeList = new ArrayList <>();
5294
5395 //Researchers
96+ logger .info ("{}" , bean .getResearcher ());
5497 new CSVResearcher (bean .getResearcher ()).readCSV ().forEach (researcher -> {
5598 MarshalReseracher marshalReseracher =
5699 new MarshalReseracher (null , (String ) researcher .get (0 ),
@@ -61,98 +104,95 @@ public void doMain(String[] args) {
61104 });
62105
63106 //OrgUnits (Department)
107+ logger .info ("{} - {}" , bean .getDepartment (), bean .getRelationDepartment ());
64108 CSVDepartment csvDepartment = new CSVDepartment (bean .getDepartment (),
65109 bean .getRelationDepartment ());
66110
67- Optional .ofNullable (csvDepartment .readCSV ()).ifPresent (present ->{
68- present .forEach (department -> {
69- MarshalDepartment marshalDepartment =
70- new MarshalDepartment (
71- (String ) department .get (0 ),
72- (String ) department .get (1 ),
73- (String ) department .get (2 ),
74- (String ) department .get (3 ),
75- (String ) department .get (4 ),
76- (String ) department .get (5 ),
77- (String ) department .get (6 ),
78- csvDepartment .readCSVRelation (),
79- cfPersTypeList
80- );
81- cerif .getCfClassOrCfClassSchemeOrCfClassSchemeDescr ().add (marshalDepartment );
82- });
83- });
111+ Optional .ofNullable (csvDepartment .readCSV ()).ifPresent (present -> present .forEach (department -> {
112+ logger .info (department .get (0 ));
113+ MarshalDepartment marshalDepartment =
114+ new MarshalDepartment (
115+ (String ) department .get (0 ),
116+ (String ) department .get (1 ),
117+ (String ) department .get (2 ),
118+ (String ) department .get (3 ),
119+ (String ) department .get (4 ),
120+ (String ) department .get (5 ),
121+ (String ) department .get (6 ),
122+ csvDepartment .readCSVRelation (),
123+ cfPersTypeList
124+ );
125+ cerif .getCfClassOrCfClassSchemeOrCfClassSchemeDescr ().add (marshalDepartment );
126+ }));
84127
85128 //OrgUnits (Research Group)
129+ logger .info ("{} - {}" , bean .getResearcherGroup (), bean .getRelationResearcherGroup ());
86130 CSVResearchGroup csvResearchGroup = new CSVResearchGroup (bean .getResearcherGroup (),
87131 bean .getRelationResearcherGroup ());
88132
89- Optional .ofNullable (csvResearchGroup .readCSV ()).ifPresent (present ->{
90- present .forEach (group -> {
91- MarshalResearchGroup marshalResearchGroup = new MarshalResearchGroup (
92- (String ) group .get (0 ),
93- (String ) group .get (1 ),
94- (String ) group .get (2 ),
95- (String ) group .get (3 ),
96- (String ) group .get (4 ),
97- (String ) group .get (5 ),
98- (String ) group .get (6 ),
99- csvResearchGroup .readCSVRelation (),
100- cfPersTypeList
101- );
102- cerif .getCfClassOrCfClassSchemeOrCfClassSchemeDescr ().add (marshalResearchGroup );
103- cfPersTypeList .addAll (marshalResearchGroup .getNewCfPersType ());
104- });
105- });
133+ Optional .ofNullable (csvResearchGroup .readCSV ()).ifPresent (present -> present .forEach (group -> {
134+ MarshalResearchGroup marshalResearchGroup = new MarshalResearchGroup (
135+ (String ) group .get (0 ),
136+ (String ) group .get (1 ),
137+ (String ) group .get (2 ),
138+ (String ) group .get (3 ),
139+ (String ) group .get (4 ),
140+ (String ) group .get (5 ),
141+ (String ) group .get (6 ),
142+ csvResearchGroup .readCSVRelation (),
143+ cfPersTypeList
144+ );
145+ cerif .getCfClassOrCfClassSchemeOrCfClassSchemeDescr ().add (marshalResearchGroup );
146+ cfPersTypeList .addAll (marshalResearchGroup .getNewCfPersType ());
147+ }));
106148
107149
108150 //Projects
151+ logger .info ("{} - {}" , bean .getProject (), bean .getRelationProject ());
109152 CSVProject csvProject = new CSVProject (bean .getProject (), bean .getRelationProject ());
110- Optional .ofNullable (csvProject .readCSV ()).ifPresent (present ->{
111- present .forEach (project -> {
112- MarshalProject marshalProject = new MarshalProject (
113- (String ) project .get (0 ),
114- (String ) project .get (1 ),
115- (String ) project .get (2 ),
116- (String ) project .get (3 ),
117- (String ) project .get (4 ),
118- (String ) project .get (5 ),
119- (String ) project .get (6 ),
120- csvProject .readCSVRelation (),
121- cfPersTypeList
122- );
123- cerif .getCfClassOrCfClassSchemeOrCfClassSchemeDescr ().add (marshalProject );
124- cfPersTypeList .addAll (marshalProject .getNewCfPersType ());
125- });
126- });
153+ Optional .ofNullable (csvProject .readCSV ()).ifPresent (present -> present .forEach (project -> {
154+ MarshalProject marshalProject = new MarshalProject (
155+ (String ) project .get (0 ),
156+ (String ) project .get (1 ),
157+ (String ) project .get (2 ),
158+ (String ) project .get (3 ),
159+ (String ) project .get (4 ),
160+ (String ) project .get (5 ),
161+ (String ) project .get (6 ),
162+ csvProject .readCSVRelation (),
163+ cfPersTypeList
164+ );
165+ cerif .getCfClassOrCfClassSchemeOrCfClassSchemeDescr ().add (marshalProject );
166+ cfPersTypeList .addAll (marshalProject .getNewCfPersType ());
167+ }));
127168
128169 //Publications
170+ logger .info ("{} - {}" , bean .getPublication (), bean .getRelationPublication ());
129171 CSVPublication csvPublication = new CSVPublication (bean .getPublication (), bean .getRelationPublication ());
130172
131- Optional .ofNullable (csvPublication .readCSV ()).ifPresent (present ->{
132- present .forEach (publication -> {
133- MarshalPublication marshalPublication = new MarshalPublication (
134- (String ) publication .get (0 ),
135- (String ) publication .get (1 ),
136- (String ) publication .get (2 ),
137- (String ) publication .get (3 ),
138- (String ) publication .get (4 ),
139- (String ) publication .get (5 ),
140- (String ) publication .get (6 ),
141- (String ) publication .get (7 ),
142- (String ) publication .get (8 ),
143- (String ) publication .get (9 ),
144- (String ) publication .get (10 ),
145- (String ) publication .get (11 ),
146- (String ) publication .get (12 ),
147- (String ) publication .get (13 ),
148- (String ) publication .get (14 ),
149- csvPublication .readCSVRelation (),
150- cfPersTypeList
151- );
152- cerif .getCfClassOrCfClassSchemeOrCfClassSchemeDescr ().add (marshalPublication );
153- cfPersTypeList .addAll (marshalPublication .getNewCfPersType ());
154- });
155- });
173+ Optional .ofNullable (csvPublication .readCSV ()).ifPresent (present -> present .forEach (publication -> {
174+ MarshalPublication marshalPublication = new MarshalPublication (
175+ (String ) publication .get (0 ),
176+ (String ) publication .get (1 ),
177+ (String ) publication .get (2 ),
178+ (String ) publication .get (3 ),
179+ (String ) publication .get (4 ),
180+ (String ) publication .get (5 ),
181+ (String ) publication .get (6 ),
182+ (String ) publication .get (7 ),
183+ (String ) publication .get (8 ),
184+ (String ) publication .get (9 ),
185+ (String ) publication .get (10 ),
186+ (String ) publication .get (11 ),
187+ (String ) publication .get (12 ),
188+ (String ) publication .get (13 ),
189+ (String ) publication .get (14 ),
190+ csvPublication .readCSVRelation (),
191+ cfPersTypeList
192+ );
193+ cerif .getCfClassOrCfClassSchemeOrCfClassSchemeDescr ().add (marshalPublication );
194+ cfPersTypeList .addAll (marshalPublication .getNewCfPersType ());
195+ }));
156196
157197 cerif .getCfClassOrCfClassSchemeOrCfClassSchemeDescr ().addAll (cfPersTypeList );
158198
@@ -165,6 +205,8 @@ public void doMain(String[] args) {
165205 logger .info ("Done" );
166206 } catch (Exception e ) {
167207 logger .error (e );
208+ }finally {
209+ xlsx2CSV .deleteOnExit ();
168210 }
169211 }
170212}
0 commit comments