BP-766 remove use of apache.common.io to remove conflict with birt
diff --git a/oKBereitschaftsplanungBackend/pom.xml b/oKBereitschaftsplanungBackend/pom.xml index ec6e3da..c77446f 100644 --- a/oKBereitschaftsplanungBackend/pom.xml +++ b/oKBereitschaftsplanungBackend/pom.xml
@@ -135,13 +135,6 @@ <version>1.10</version> </dependency> - <!-- https://mvnrepository.com/artifact/commons-io/commons-io --> - <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - <version>2.6</version> - </dependency> - <!-- Dozer Mapper --> <dependency> <groupId>net.sf.dozer</groupId> @@ -261,6 +254,14 @@ <version>1.3.168</version> <scope>test</scope> </dependency> + + <!-- https://mvnrepository.com/artifact/commons-io/commons-io --> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>2.6</version> + <scope>test</scope> + </dependency> <!-- swagger --> <dependency> @@ -314,8 +315,21 @@ <groupId>org.eclipse.birt.runtime.3_7_1</groupId> <artifactId>org.apache.commons.codec</artifactId> </exclusion> + <!-- <exclusion> + <groupId>org.eclipse.birt.runtime.3_7_1</groupId> + <artifactId>org.apache.batik.pdf</artifactId> + </exclusion> --> </exclusions> </dependency> + + <!-- https://mvnrepository.com/artifact/org.eclipse.birt.runtime.3_7_1/org.apache.batik.pdf --> + <!-- <dependency> + <groupId>org.eclipse.birt.runtime.3_7_1</groupId> + <artifactId>org.apache.batik.pdf</artifactId> + <version>1.6.0m</version> + <scope>runtime</scope> + </dependency> --> + </dependencies> <profiles> @@ -512,20 +526,59 @@ </execution> </executions> </plugin> - <!-- <plugin> <groupId>com.github.kongchen</groupId> <artifactId>swagger-maven-plugin</artifactId> - <version>${swagger-maven-plugin-version}</version> <configuration> <skipSwaggerGeneration>false</skipSwaggerGeneration> - <apiSources> <apiSource> <springmvc>false</springmvc> <locations> <location>org.eclipse.openk</location> - </locations> <schemes> <shema>http</shema> </schemes> <host>localhost:9050</host> - <basePath>/mics/gridMeasures</basePath> <info> <title>plannedGridMeasures@openK - - Backend REST-Service documentation</title> <version>v1</version> <description>This - documentation contains the description of all used REST services.</description> - <termsOfService> . </termsOfService> <contact> <email>nn@pta.de</email> <name></name> - </contact> <license> <url>http://www.apache.org/licenses/LICENSE-2.0.html</url> - <name>Apache 2.0</name> </license> </info> <outputFormats>yaml</outputFormats> - <templatePath>${basedir}/templates/strapdown.html.hbs</templatePath> <outputPath>target/generated-docs/swaggerInterfaceDocumentation.html</outputPath> - <swaggerDirectory>target/generated-docs</swaggerDirectory> <securityDefinitions> - <securityDefinition> <json>/securityDefinitions.json</json> </securityDefinition> - </securityDefinitions> </apiSource> </apiSources> </configuration> </plugin> --> + <plugin> + <groupId>com.github.kongchen</groupId> + <artifactId>swagger-maven-plugin</artifactId> + <version>${swagger-maven-plugin-version}</version> + <executions> + <execution> + <goals> + <goal>generate</goal> + </goals> + <configuration> + <skipSwaggerGeneration>true</skipSwaggerGeneration> + <apiSources> + <apiSource> + <springmvc>false</springmvc> + <locations> + <location>org.eclipse.openk</location> + </locations> + <schemes> + <shema>http</shema> + </schemes> + <host>localhost:8080</host> + <basePath>/spbe/webapi</basePath> + <info> + <title>spbe@openK + - Backend REST-Service documentation</title> + <version>v1</version> + <description>This + documentation contains the description of all + used REST services.</description> + <termsOfService> . </termsOfService> + <contact> + <email>mgcUser@mettenmeier.de</email> + <name></name> + </contact> + <license> + <url>http://www.apache.org/licenses/LICENSE-2.0.html</url> + <name>Apache 2.0</name> + </license> + </info> + <outputFormats>yaml</outputFormats> + <templatePath>${basedir}/templates/strapdown.html.hbs</templatePath> + <outputPath>target/generated-docs/swaggerInterfaceDocumentation.html</outputPath> + <swaggerDirectory>target/generated-docs</swaggerDirectory> + <!-- <securityDefinitions> <securityDefinition> <json>/securityDefinitions.json</json> + </securityDefinition> </securityDefinitions> --> + </apiSource> + </apiSources> + </configuration> + + </execution> + </executions> + </plugin> + </plugins> </build> <artifactId>spbe</artifactId>
diff --git a/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/reports/ReportController.java b/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/reports/ReportController.java index c69b3ac..edf5b71 100644 --- a/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/reports/ReportController.java +++ b/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/reports/ReportController.java
@@ -37,8 +37,6 @@ import javax.servlet.http.HttpServletResponse; import javax.ws.rs.core.MediaType; -import org.apache.commons.io.FilenameUtils; -import org.apache.commons.io.IOUtils; import org.apache.http.HttpStatus; import org.apache.log4j.Logger; import org.eclipse.birt.core.framework.Platform; @@ -161,36 +159,44 @@ * Method to query all reports. * * @return + * @throws SpException */ - public List<ReportDto> getReports() { + public List<ReportDto> getReports() throws SpException { ArrayList<ReportDto> listReports = new ArrayList<>(); - init(); + try { + init(); - for (File file : fileHelper.loadFolderFromFileSystemOrResource(reportDirectory, true).listFiles()) { + for (File file : fileHelper.loadFolderFromFileSystemOrResource(reportDirectory, true).listFiles()) { - String fileExtension = FilenameUtils.getExtension(file.getAbsolutePath()); - if (allowedReports.contains(fileExtension)) { + String fileExtension = FileHelper.getFileExtension(file); + if (allowedReports.contains(fileExtension)) { - String reportName = FilenameUtils.removeExtension(file.getName()); - ReportDto reportDto = new ReportDto(); - reportDto.setReportName(reportName); + String reportName = file.getName(); + reportName = reportName.substring(0, reportName.lastIndexOf('.')); + ReportDto reportDto = new ReportDto(); + reportDto.setReportName(reportName); - int defaultDayRange = 7; - // setting default dayrange - if (reportName.equals(ReportController.REPORT_ALL_GROUPS)) { - defaultDayRange = 30; + int defaultDayRange = 7; + // setting default dayrange + if (reportName.equals(ReportController.REPORT_ALL_GROUPS)) { + defaultDayRange = 30; + } + + reportDto.setDefaultDayRange(defaultDayRange); + listReports.add(reportDto); + } - - reportDto.setDefaultDayRange(defaultDayRange); - listReports.add(reportDto); - } + + // sorting by reportname + Collections.sort(listReports, (o1, o2) -> o1.getReportName().compareTo(o2.getReportName())); + + return listReports; + } catch (Exception e) { + SpErrorEntry ee = SpExceptionEnum.DEFAULT_EXCEPTION.getEntry(); + ee.setE(e); + throw new SpException(ee); } - - // sorting by reportname - Collections.sort(listReports, (o1, o2) -> o1.getReportName().compareTo(o2.getReportName())); - - return listReports; } public File generateReport(ReportDto reportDto) throws SpException { @@ -488,7 +494,7 @@ String newHtmlBody = null; if (is != null) { - String htmlBody = IOUtils.toString(is, StandardCharsets.UTF_8.name()); + String htmlBody = FileHelper.getTextFromInputStream(is, StandardCharsets.UTF_8); newHtmlBody = MessageFormat.format(htmlBody, obj);
diff --git a/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/db/config/DbInitializer.java b/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/db/config/DbInitializer.java index 470df0a..6ffceb1 100644 --- a/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/db/config/DbInitializer.java +++ b/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/db/config/DbInitializer.java
@@ -23,7 +23,6 @@ import java.text.MessageFormat; import java.util.Properties; -import org.apache.commons.io.IOUtils; import org.apache.log4j.Logger; import org.eclipse.openk.sp.util.FileHelper; import org.springframework.stereotype.Service; @@ -135,7 +134,7 @@ String result = ""; InputStream is = fh.loadFileFromResource(fileName); if (is != null) { - result = IOUtils.toString(is, StandardCharsets.UTF_8.name()); + result = FileHelper.getTextFromInputStream(is, StandardCharsets.UTF_8); } return result; }
diff --git a/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/mail/MailRequest.java b/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/mail/MailRequest.java index 02e2a8a..62a60c7 100644 --- a/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/mail/MailRequest.java +++ b/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/mail/MailRequest.java
@@ -18,7 +18,6 @@ import java.text.MessageFormat; import java.util.Properties; -import org.apache.commons.io.IOUtils; import org.apache.commons.mail.EmailException; import org.apache.commons.mail.HtmlEmail; import org.apache.log4j.Logger; @@ -66,7 +65,7 @@ String newHtmlBody = null; if (is != null) { - String htmlBody = IOUtils.toString(is, StandardCharsets.UTF_8.name()); + String htmlBody = FileHelper.getTextFromInputStream(is, StandardCharsets.UTF_8); newHtmlBody = MessageFormat.format(htmlBody, obj); @@ -239,5 +238,6 @@ return mailGenerator.generateMail(null, mailAddress, sendersName, sendersMail, subject, body, properties); } - + + }
diff --git a/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/util/FileHelper.java b/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/util/FileHelper.java index 2627520..ddddd0b 100644 --- a/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/util/FileHelper.java +++ b/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/util/FileHelper.java
@@ -12,13 +12,21 @@ ********************************************************************************/ package org.eclipse.openk.sp.util; +import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Properties; import org.apache.log4j.Logger; +import org.eclipse.openk.sp.exceptions.SpErrorEntry; +import org.eclipse.openk.sp.exceptions.SpException; +import org.eclipse.openk.sp.exceptions.SpExceptionEnum; import org.springframework.stereotype.Service; @Service @@ -115,4 +123,38 @@ return propValue; } + /** + * Method to read the InputStream as UTF-8 String. + * + * @param is + * @return + * @throws IOException + */ + public static String getTextFromInputStream(InputStream is, Charset charset) throws IOException { + StringBuilder textBuilder = new StringBuilder(); + try (Reader reader = new BufferedReader(new InputStreamReader(is, Charset.forName(charset.name())))) { + int c = 0; + while ((c = reader.read()) != -1) { + textBuilder.append((char) c); + } + return textBuilder.toString(); + } + } + + /** + * Method to read the file extension from given file. + * + * @param f + * @return + * @throws Exception + */ + public static String getFileExtension(File f) throws SpException { + try { + String[] arrString = f.getName().split("\\."); + return arrString[arrString.length - 1]; + } catch (Exception e) { + LOGGER.error(e, e); + throw new SpException(SpExceptionEnum.DEFAULT_EXCEPTION.getEntry()); + } + } }
diff --git a/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/reports/ReportControllerTest.java b/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/reports/ReportControllerTest.java index 3b80dde..ea0ba91 100644 --- a/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/reports/ReportControllerTest.java +++ b/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/reports/ReportControllerTest.java
@@ -240,6 +240,9 @@ } catch (IOException e) { LOGGER.error(e, e); assertNull(e); + } catch (SpException e) { + LOGGER.error(e, e); + assertNull(e); } }