Skip to content

Commit

Permalink
Merge pull request #5 from laurentC35/multi-model
Browse files Browse the repository at this point in the history
Multi model
  • Loading branch information
laurentC35 authored Feb 26, 2020
2 parents 21e474b + beacbe9 commit 66e1d0c
Show file tree
Hide file tree
Showing 33 changed files with 22,307 additions and 70 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Upload Release Asset

on:
push:
tags:
- 'v*'

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Build with Maven
run: mvn install -DskipTests=true -Dmaven.javadoc.skip=true -Djar.finalName="eno-core" -B -V --file pom.xml
- name: Test with Maven
run: mvn test -B --file pom.xml
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: target/eno-core.jar
asset_name: eno-core.jar
asset_content_type: application/java-archive
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: java
jdk:
- openjdk8
- openjdk11

install:
- mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V
Expand Down
49 changes: 26 additions & 23 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>fr.insee.eno</groupId>
<artifactId>eno-core</artifactId>
<version>2.0.0</version>
<version>2.0.1</version>
<packaging>jar</packaging>

<name>Eno – Questionnaire generator</name>
Expand Down Expand Up @@ -53,6 +53,8 @@
<fop.version>2.2</fop.version>
<xalan.version>2.7.1</xalan.version>
<slf4j.version>1.7.25</slf4j.version>
<eclipse.version>2.6.0</eclipse.version>
<jaxb-api.version>2.3.1</jaxb-api.version>

<apache-commons.version>3.5</apache-commons.version>
<junit.version>4.12</junit.version>
Expand All @@ -62,8 +64,8 @@
<source.plugin.version>3.0.1</source.plugin.version>
<javadoc.plugin.version>3.0.0</javadoc.plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<compiler.source>1.8</compiler.source>
<compiler.target>1.8</compiler.target>
<compiler.source>11</compiler.source>
<compiler.target>11</compiler.target>
</properties>

<dependencies>
Expand Down Expand Up @@ -102,23 +104,6 @@
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>

<!-- Jaxb -->
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.moxy</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>

<!-- Test dependencies -->
<dependency>
Expand All @@ -145,14 +130,32 @@
<version>${log4j-slf4j.version}</version>
<scope>test</scope>
</dependency>

<!-- Jaxb -->
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.moxy</artifactId>
<version>${eclipse.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>${eclipse.version}</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>${jaxb-api.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<version>3.8.0</version>
<configuration>
<source>${compiler.source}</source>
<target>${compiler.target}</target>
Expand All @@ -171,7 +174,7 @@
</goals>
<configuration>
<packageName>fr.insee.eno.parameters</packageName>
<encoding>UTF-8</encoding>
<encoding>UTF-8</encoding>
<xjbSources>
<xjbSource>src/main/resources/params/schemas/jaxb/bindings.xjb</xjbSource>
</xjbSources>
Expand All @@ -192,7 +195,7 @@
<inputEncoding>UTF-8</inputEncoding>
<outputEncoding>UTF-8</outputEncoding>
<argLine>-Dfile.encoding=UTF-8
-Djavax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory</argLine>
-Djavax.xml.bind.JAXBContextFactory=org.eclipse.persistence.jaxb.JAXBContextFactory</argLine>
</configuration>
</plugin>
<plugin>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fr/insee/eno/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private Constants() {
/********************** Pre-processing ******************/
/********************************************************/
public static final String PRE_PROCESSING_FOLDER = "/xslt/pre-processing";

public static final String UTIL_DDI_SPLITTING_XSL = UTIL_FOLDER_PATH + "/ddi/splitting.xsl";
/******************* DDI - Pre-processing ****************/
public static final String DDI_DEREFERENCING_XSL = PRE_PROCESSING_FOLDER + "/ddi/dereferencing.xsl";
public static final String UTIL_DDI_DEREFERENCING_XSL = UTIL_FOLDER_PATH + "/ddi/dereferencing.xsl";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import fr.insee.eno.GenerationService;
import fr.insee.eno.generation.DDI2FRGenerator;
import fr.insee.eno.generation.DDI2JSGenerator;
import fr.insee.eno.generation.DDI2ODTGenerator;
Expand Down Expand Up @@ -51,6 +50,7 @@
import fr.insee.eno.preprocessing.DDITitlingPreprocessor;
import fr.insee.eno.preprocessing.PoguesXMLPreprocessorGoToTreatment;
import fr.insee.eno.preprocessing.Preprocessor;
import fr.insee.eno.service.GenerationService;

public class PipeLineGeneratorImpl implements PipelineGenerator {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.List;

import fr.insee.eno.GenerationService;
import fr.insee.eno.generation.Generator;
import fr.insee.eno.parameters.InFormat;
import fr.insee.eno.parameters.OutFormat;
Expand All @@ -11,6 +10,7 @@
import fr.insee.eno.parameters.PreProcessing;
import fr.insee.eno.postprocessing.Postprocessor;
import fr.insee.eno.preprocessing.Preprocessor;
import fr.insee.eno.service.GenerationService;

public interface PipelineGenerator {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public File process(File inputFile, byte[] parametersFile, String survey, String

@Override
public boolean accept(File dir, String name) {
return !name.startsWith("null");
return !name.startsWith("null") && name.endsWith(".tmp");
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package fr.insee.eno.preprocessing;

import java.io.File;
import java.io.FilenameFilter;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import fr.insee.eno.Constants;
import fr.insee.eno.exception.EnoGenerationException;
import fr.insee.eno.transform.xsl.XslTransformation;

/**
* A DDI specific preprocessor.
*/
public class DDISplittingPreprocessor {

private static final Logger LOGGER = LoggerFactory.getLogger(DDISplittingPreprocessor.class);

private XslTransformation saxonService = new XslTransformation();

public List<File> splitDDI(File inputFile, String survey) throws Exception {
LOGGER.info("DDI splitting preprocessing Target : START");

String sUB_TEMP_FOLDER = Constants.sUB_TEMP_FOLDER(survey);
// ----- Dereferencing
LOGGER.debug("Dereferencing : -Input : " + inputFile + " -Output : " + Constants.tEMP_NULL_TMP(sUB_TEMP_FOLDER)
+ " -Stylesheet : " + Constants.UTIL_DDI_SPLITTING_XSL + " -Parameters : " + sUB_TEMP_FOLDER);

InputStream isDDI_DEREFERENCING_XSL = Constants.getInputStreamFromPath(Constants.UTIL_DDI_SPLITTING_XSL);
InputStream isInputFile = FileUtils.openInputStream(inputFile);
OutputStream osTEMP_NULL_TMP = FileUtils.openOutputStream(Constants.tEMP_NULL_TMP(sUB_TEMP_FOLDER));

try {
saxonService.transformDereferencing(isInputFile, isDDI_DEREFERENCING_XSL, osTEMP_NULL_TMP,
Constants.sUB_TEMP_FOLDER_FILE(survey));
}catch(Exception e) {
throw new EnoGenerationException("An error was occured during the " + toString() + " transformation. "+e.getMessage());
}

isInputFile.close();
isDDI_DEREFERENCING_XSL.close();
osTEMP_NULL_TMP.close();
// ----- Cleaning
LOGGER.debug("Cleaning target");
File f = Constants.sUB_TEMP_FOLDER_FILE(survey);
File[] matchCleaningInput = f.listFiles(new FilenameFilter() {

@Override
public boolean accept(File dir, String name) {
return !name.startsWith("null");
}
});

List<File> outputFiles = new ArrayList<File>();

LOGGER.debug("Searching matching files in : " + sUB_TEMP_FOLDER);
for (File file : matchCleaningInput) {
if(!file.isDirectory()) {
LOGGER.debug("Found : " + file.getAbsolutePath());
outputFiles.add(file);
}
}
if(outputFiles.size()==0) {
throw new EnoGenerationException("DDI Splitting produced no file.");
}

LOGGER.debug("DDI splitting preprocessing : END");
return outputFiles;
}

public String toString() {
return "DDI splitting preprocessor";
}


}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fr.insee.eno;
package fr.insee.eno.service;

import java.io.ByteArrayOutputStream;
import java.io.File;
Expand All @@ -14,6 +14,7 @@
import com.google.common.io.Files;
import com.google.inject.Inject;

import fr.insee.eno.Constants;
import fr.insee.eno.generation.Generator;
import fr.insee.eno.postprocessing.Postprocessor;
import fr.insee.eno.preprocessing.Preprocessor;
Expand All @@ -34,13 +35,16 @@ public class GenerationService {
private byte[] metadata;
private byte[] specificTreatment;
private byte[] mapping;

private boolean cleaningFolder;

@Inject
public GenerationService(final Preprocessor[] preprocessors, final Generator generator,
final Postprocessor[] postprocessors) {
this.preprocessors = preprocessors;
this.generator = generator;
this.postprocessors = postprocessors;
this.cleaningFolder = true;
}

@Inject
Expand All @@ -49,6 +53,7 @@ public GenerationService(final Preprocessor preprocessor, final Generator genera
this.preprocessors = new Preprocessor[] { preprocessor };
this.generator = generator;
this.postprocessors = postprocessors;
this.cleaningFolder = true;
}

@Inject
Expand All @@ -57,6 +62,7 @@ public GenerationService(final Preprocessor preprocessor, final Generator genera
this.preprocessors = new Preprocessor[] { preprocessor };
this.generator = generator;
this.postprocessors = new Postprocessor[] { postprocessor };
this.cleaningFolder = true;
}

/**
Expand All @@ -75,7 +81,9 @@ public File generateQuestionnaire(File inputFile, String surveyName) throws Exce

String tempFolder = System.getProperty("java.io.tmpdir") + "/" + surveyName;
logger.debug("Temp folder: " + tempFolder);
cleanTempFolder(surveyName);
if(cleaningFolder) {
cleanTempFolder(surveyName);
}
File preprocessResultFileName = null;

preprocessResultFileName = this.preprocessors[0].process(inputFile, parameters, surveyName,generator.in2out());
Expand Down Expand Up @@ -140,6 +148,12 @@ public byte[] getSpecificTreatment() {
public byte[] getMapping() {
return mapping;
}

public void setCleaningFolder(boolean cleaning) {
this.cleaningFolder = cleaning;
}



/**
* Clean the temp dir if it exists
Expand All @@ -148,7 +162,6 @@ public byte[] getMapping() {
*
*/
public void cleanTempFolder(String name) throws IOException {
FolderCleaner cleanService = new FolderCleaner();
if (Constants.TEMP_FOLDER_PATH != null) {
File folderTemp = new File(Constants.TEMP_FOLDER_PATH + "/" + name);
cleanTempFolder(folderTemp);
Expand Down
Loading

0 comments on commit 66e1d0c

Please sign in to comment.