Skip to content

Commit 7a1b286

Browse files
authored
chore: Now using goJF and formatted repo (openequella#24)
1 parent 872d576 commit 7a1b286

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+8356
-7835
lines changed

build.gradle

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
plugins {
2+
id 'com.github.sherter.google-java-format' version '0.8'
3+
}
4+
15
apply plugin: 'eclipse'
26
apply plugin: 'java'
37

src/main/java/org/apereo/openequella/tools/toolbox/AttachmentHashDriver.java

+11-10
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@
2323
import org.apereo.openequella.tools.toolbox.utils.GeneralUtils;
2424

2525
public class AttachmentHashDriver {
26-
private static Logger LOGGER = LogManager.getLogger(AttachmentHashDriver.class);
26+
private static Logger LOGGER = LogManager.getLogger(AttachmentHashDriver.class);
2727

28-
public void execute(String[] args) {
29-
if (args.length < 2) {
30-
LOGGER.error("No parameters found! AttachmentHash parameters - [req] config file, [req] att-uuid");
31-
return;
32-
}
33-
34-
final int res = GeneralUtils.findHash(args[1]);
35-
LOGGER.info("Hash is [{}]", res);
28+
public void execute(String[] args) {
29+
if (args.length < 2) {
30+
LOGGER.error(
31+
"No parameters found! AttachmentHash parameters - [req] config file, [req] att-uuid");
32+
return;
3633
}
37-
}
34+
35+
final int res = GeneralUtils.findHash(args[1]);
36+
LOGGER.info("Hash is [{}]", res);
37+
}
38+
}

src/main/java/org/apereo/openequella/tools/toolbox/CheckFilesDriver.java

+125-122
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
package org.apereo.openequella.tools.toolbox;
2020

21+
import java.io.File;
22+
import java.util.ArrayList;
23+
import java.util.List;
2124
import org.apache.logging.log4j.LogManager;
2225
import org.apache.logging.log4j.Logger;
2326
import org.apereo.openequella.tools.toolbox.checkFiles.CheckFilesDbHandler;
@@ -26,149 +29,149 @@
2629
import org.apereo.openequella.tools.toolbox.checkFiles.ResultsRow;
2730
import org.apereo.openequella.tools.toolbox.utils.CheckFilesUtils;
2831

29-
import java.io.File;
30-
import java.util.ArrayList;
31-
import java.util.List;
32-
33-
3432
/**
3533
* Consider log4j pattern:
3634
*
37-
* <Appenders>
38-
* <Appender type="Console" name="STDOUT">
39-
* <Layout type="PatternLayout" pattern="%d %-5p [%c{1}]: %m%n"/>
40-
* </Appender>
41-
* </Appenders>
42-
*
35+
* <p><Appenders> <Appender type="Console" name="STDOUT"> <Layout type="PatternLayout" pattern="%d
36+
* %-5p [%c{1}]: %m%n"/> </Appender> </Appenders>
4337
*/
44-
4538
public class CheckFilesDriver {
46-
private static Logger LOGGER = LogManager.getLogger(CheckFilesDriver.class);
47-
48-
public List<String> execute(String[] args) {
49-
List<String> results = new ArrayList<>();
50-
try {
51-
52-
if((args.length > 1) && args[1].equals("-compare")) {
53-
compareReports(args);
54-
} else if((args.length > 0) && args[0].endsWith(".properties")) {
55-
runCheck(args[0]);
56-
} else {
57-
LOGGER.error("ERROR - CheckFiles needs at least the configuration file as a parameter.");
58-
return results;
59-
}
60-
} catch (Exception e) {
61-
LOGGER.error(e.getMessage());
62-
e.printStackTrace();
63-
}
64-
39+
private static Logger LOGGER = LogManager.getLogger(CheckFilesDriver.class);
40+
41+
public List<String> execute(String[] args) {
42+
List<String> results = new ArrayList<>();
43+
try {
44+
45+
if ((args.length > 1) && args[1].equals("-compare")) {
46+
compareReports(args);
47+
} else if ((args.length > 0) && args[0].endsWith(".properties")) {
48+
runCheck(args[0]);
49+
} else {
50+
LOGGER.error("ERROR - CheckFiles needs at least the configuration file as a parameter.");
6551
return results;
52+
}
53+
} catch (Exception e) {
54+
LOGGER.error(e.getMessage());
55+
e.printStackTrace();
6656
}
6757

68-
private static void compareReports(String[] args) {
69-
LOGGER.info("### Starting oEQ-Toolbox:CheckFiles Report Comparison...");
70-
endCompare: {
71-
if(args.length != 4) {
72-
LOGGER.error("### Must invoke with two filenames/paths. Instead found [{}]: [{}]", args.length , args);
73-
break endCompare;
74-
}
75-
File r1 = new File(args[2]);
76-
File r2 = new File(args[3]);
77-
if(!r1.exists()) {
78-
LOGGER.error("### First file [{}] does not exist.", args[2]);
79-
break endCompare;
80-
}
81-
if(!r2.exists()) {
82-
LOGGER.error("### Second file [{}] does not exist.", args[3]);
83-
break endCompare;
84-
}
85-
86-
ResultComparison cr = CheckFilesUtils.looseCompare(r1, r2);
87-
88-
if(cr == null) {
89-
LOGGER.error("### Error comparing files.");
90-
break endCompare;
91-
}
92-
93-
if(cr.areReportsEqual()) {
94-
LOGGER.info("Reports ARE similar (in terms of resultant attachments)!");
95-
} else {
96-
LOGGER.info("Reports are NOT similar (in terms of resultant attachments)! Listing differences...");
97-
LOGGER.info("Extra rows in the first report ({}):", cr.getFirstName());
98-
for(ResultsRow rr : cr.getOnlyInFirst()) {
99-
LOGGER.info("\t- {}", rr);
100-
}LOGGER.info("Extra rows in the second report ({}):", cr.getSecondName());
101-
for(ResultsRow rr : cr.getOnlyInSecond()) {
102-
LOGGER.info("\t- {}", rr);
103-
}
104-
}
58+
return results;
59+
}
60+
61+
private static void compareReports(String[] args) {
62+
LOGGER.info("### Starting oEQ-Toolbox:CheckFiles Report Comparison...");
63+
endCompare:
64+
{
65+
if (args.length != 4) {
66+
LOGGER.error(
67+
"### Must invoke with two filenames/paths. Instead found [{}]: [{}]",
68+
args.length,
69+
args);
70+
break endCompare;
71+
}
72+
File r1 = new File(args[2]);
73+
File r2 = new File(args[3]);
74+
if (!r1.exists()) {
75+
LOGGER.error("### First file [{}] does not exist.", args[2]);
76+
break endCompare;
77+
}
78+
if (!r2.exists()) {
79+
LOGGER.error("### Second file [{}] does not exist.", args[3]);
80+
break endCompare;
81+
}
82+
83+
ResultComparison cr = CheckFilesUtils.looseCompare(r1, r2);
84+
85+
if (cr == null) {
86+
LOGGER.error("### Error comparing files.");
87+
break endCompare;
88+
}
89+
90+
if (cr.areReportsEqual()) {
91+
LOGGER.info("Reports ARE similar (in terms of resultant attachments)!");
92+
} else {
93+
LOGGER.info(
94+
"Reports are NOT similar (in terms of resultant attachments)! Listing differences...");
95+
LOGGER.info("Extra rows in the first report ({}):", cr.getFirstName());
96+
for (ResultsRow rr : cr.getOnlyInFirst()) {
97+
LOGGER.info("\t- {}", rr);
98+
}
99+
LOGGER.info("Extra rows in the second report ({}):", cr.getSecondName());
100+
for (ResultsRow rr : cr.getOnlyInSecond()) {
101+
LOGGER.info("\t- {}", rr);
105102
}
106-
LOGGER.info("### CheckFiles Report Comparison ended.");
103+
}
107104
}
105+
LOGGER.info("### CheckFiles Report Comparison ended.");
106+
}
108107

109-
private static void runCheck(String propertiesFilenameStr) {
110-
LOGGER.info("### Starting CheckFiles report run...");
111-
LOGGER.info("### Checking configs from {}...", propertiesFilenameStr);
108+
private static void runCheck(String propertiesFilenameStr) {
109+
LOGGER.info("### Starting CheckFiles report run...");
110+
LOGGER.info("### Checking configs from {}...", propertiesFilenameStr);
112111

113-
Config.reset();
114-
Config.getInstance().init(propertiesFilenameStr);
112+
Config.reset();
113+
Config.getInstance().init(propertiesFilenameStr);
115114

116-
if (!setup()) {
117-
LOGGER.fatal("### Setup check failed. Exiting...");
118-
return;
119-
}
120-
LOGGER.info("### Config check passed.");
121-
122-
if(!run()) {
123-
LOGGER.fatal("### Something went wrong running the report. Exiting...");
124-
ReportManager.getInstance().failFast();
125-
return;
126-
}
127-
128-
if(!finalizeRun()) {
129-
LOGGER.fatal("### Something went wrong finalizing the report. Exiting...");
130-
return;
131-
}
115+
if (!setup()) {
116+
LOGGER.fatal("### Setup check failed. Exiting...");
117+
return;
118+
}
119+
LOGGER.info("### Config check passed.");
132120

133-
LOGGER.info("### CheckFiles {} report completed.",
134-
Config.get(Config.CF_MODE));
121+
if (!run()) {
122+
LOGGER.fatal("### Something went wrong running the report. Exiting...");
123+
ReportManager.getInstance().failFast();
124+
return;
135125
}
136126

137-
public static boolean setup() {
138-
return setup(false);
127+
if (!finalizeRun()) {
128+
LOGGER.fatal("### Something went wrong finalizing the report. Exiting...");
129+
return;
139130
}
140131

141-
public static boolean setup(boolean noFiles) {
142-
ReportManager.reset();
143-
if(!Config.getInstance().isValidConfig()) {
144-
LOGGER.warn("Config is not valid. Failing setup.");
145-
return false;
132+
LOGGER.info("### CheckFiles {} report completed.", Config.get(Config.CF_MODE));
133+
}
134+
135+
public static boolean setup() {
136+
return setup(false);
137+
}
138+
139+
public static boolean setup(boolean noFiles) {
140+
ReportManager.reset();
141+
if (!Config.getInstance().isValidConfig()) {
142+
LOGGER.warn("Config is not valid. Failing setup.");
143+
return false;
144+
}
145+
ReportManager.getInstance().setup(noFiles);
146+
if (!ReportManager.getInstance().isValid()) {
147+
LOGGER.warn("Report Manager is not valid. Failing setup.");
148+
return false;
149+
}
150+
return true;
151+
}
152+
153+
public static boolean run() {
154+
switch (Config.getCheckFilesTypeConfig()) {
155+
case REST:
156+
{
157+
LOGGER.error("REST mode has not been reimplemented. Exiting.");
158+
// return (new AttachmentPingHandler()).execute();
159+
return false;
146160
}
147-
ReportManager.getInstance().setup(noFiles);
148-
if (!ReportManager.getInstance().isValid()) {
149-
LOGGER.warn("Report Manager is not valid. Failing setup.");
150-
return false;
161+
case DB_BATCH_ITEMS_PER_ITEM_ATTS:
162+
case DB_ALL_ITEMS_ALL_ATTS:
163+
{
164+
return (new CheckFilesDbHandler()).execute();
151165
}
152-
return true;
153-
}
154-
155-
public static boolean run() {
156-
switch(Config.getCheckFilesTypeConfig()) {
157-
case REST: {
158-
LOGGER.error("REST mode has not been reimplemented. Exiting.");
159-
//return (new AttachmentPingHandler()).execute();
160-
return false;
161-
} case DB_BATCH_ITEMS_PER_ITEM_ATTS:
162-
case DB_ALL_ITEMS_ALL_ATTS: {
163-
return (new CheckFilesDbHandler()).execute();
164-
} default: {
165-
LOGGER.error("Unknown CheckFiles mode of [{}]...", Config.get(Config.CF_MODE));
166-
return false;
167-
}
166+
default:
167+
{
168+
LOGGER.error("Unknown CheckFiles mode of [{}]...", Config.get(Config.CF_MODE));
169+
return false;
168170
}
169171
}
172+
}
170173

171-
public static boolean finalizeRun() {
172-
return ReportManager.getInstance().finalizeReporting();
173-
}
174+
public static boolean finalizeRun() {
175+
return ReportManager.getInstance().finalizeReporting();
176+
}
174177
}

0 commit comments

Comments
 (0)