Skip to content

Commit

Permalink
Fixes #50 - Add the possibility to generate an Allotrope from a singl…
Browse files Browse the repository at this point in the history
…e .ch file

- ChemStationToAllotropeMapper is now more customizable
  - In addition to the time-zone, users can now customize the date-time format and the names of the necessary files for conversion
- More metadata is read from .ch files
- Add a merge strategy option if metadata read from .ch and other files differ

Fix ChemStationToAllotropeMapper
  • Loading branch information
kevin-belellou committed Dec 17, 2024
1 parent 6cb5c6e commit 45c2635
Show file tree
Hide file tree
Showing 22 changed files with 757 additions and 1,782 deletions.
60 changes: 48 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,67 @@
# GC2ASM

[![Maven Central Version](https://img.shields.io/maven-central/v/fr.ifpen.allotropeconverters/gc2asm)][maven-central]
[![License CeCILL 2.1](https://img.shields.io/badge/License-CeCILL_2.1-green)][license]
[![Maven Central Version][maven-central-badge]][maven-central]
[![License CeCILL 2.1][license-badge]][cecill-2.1]

A Java converter from GC proprietary data to Allotrope's ASM data.


A Java converter from GC proprietary data to Allotrope's ASM data

A project from [IFP Energies Nouvelles](https://www.ifpenergiesnouvelles.com/), a public research, innovation and training organization in the fields of energy, transport and the environment
A project from [IFP Energies Nouvelles][ifpen], a public research, innovation and
training organization in the fields of energy, transport and the environment.

## Usage

```java
String filePath = pathToGCFile;
GcToAllotropeJsonConverter converter = new GcToAllotropeJsonConverter();
ObjectNode result = converter.convertFile(filePath);
import fr.ifpen.allotropeconverters.gc.GcToAllotropeJsonConverter;
import fr.ifpen.allotropeconverters.gc.chemstation.ChemStationToAllotropeMapper;
import fr.ifpen.allotropeconverters.gc.chemstation.ChemStationToAllotropeMapperBuilder;

String folderPath = "path to folder containing .ch, .xml and .txt files";
String filePath = "path to .ch file";

// Using default mapper
GcToAllotropeJsonConverter converter = new GcToAllotropeJsonConverter();

// Conversion from folder to Allotrope JSON
ObjectNode allotropeFromFolder = converter.convertFolderToAllotrope(folderPath);

// Conversion from .ch file to Allotrope JSON
ObjectNode allotropeFromFile = converter.convertChFileToAllotrope(filePath);


// ChemStation to Allotrope mapper can be customized
ChemStationToAllotropeMapperBuilder builder = new ChemStationToAllotropeMapperBuilder();
ChemStationToAllotropeMapper mapper = builder.withZoneId(ZoneId.of("Europe/Paris"))
.withChFileName("file.ch")
.withXmlFileName("file.xml")
.build();
GcToAllotropeJsonConverter customizedConverter = new GcToAllotropeJsonConverter(mapper);

// Convert folders and files
// [...]
```

## Supported files

- Chemstation V179
- Chemstation V181

## Roadmap

Support for Thermo's Chromeleon data.

## License
The code is available under the [CeCILL 2.1](https://cecill.info/licences/Licence_CeCILL_V2.1-fr.txt) licence, which is compatible with GNU GPL, GNU Affero GPL and EUPL.
The [ASM JSON schemas](https://www.allotrope.org/asm) are available under [CC-BY-NC 4.0](https://creativecommons.org/licenses/by-nc/4.0/) terms.

The code is available under the [CeCILL 2.1][cecill-2.1] license,
which is compatible with GNU GPL, GNU Affero GPL and EUPL.
The [ASM JSON schemas][asm] are available under [CC-BY-NC 4.0][cc-by-nc-4.0] terms.

[//]: # (@formatter:off)

[maven-central-badge]: https://img.shields.io/maven-central/v/fr.ifpen.allotropeconverters/gc2asm
[license-badge]: https://img.shields.io/badge/License-CeCILL_2.1-green

[maven-central]: https://central.sonatype.com/artifact/fr.ifpen.allotropeconverters/gc2asm
[license]: https://opensource.org/license/cecill-2-1
[cecill-2.1]: https://opensource.org/license/cecill-2-1
[ifpen]: https://www.ifpenergiesnouvelles.com/
[asm]: https://www.allotrope.org/asm
[cc-by-nc-4.0]: https://creativecommons.org/licenses/by-nc/4.0/
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@
<version>4.3.1</version>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.26.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,82 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import fr.ifpen.allotropeconverters.gc.chemstation.ChemStationToAllotropeMapper;
import fr.ifpen.allotropeconverters.gc.chemstation.ChemStationToAllotropeMapperBuilder;
import fr.ifpen.allotropeconverters.gc.schema.GasChromatographyTabularEmbedSchema;
import jakarta.xml.bind.JAXBException;

import java.io.IOException;
import java.time.ZoneId;
import java.time.ZoneOffset;

/**
* GcToAllotropeJsonConverter is responsible for converting gas chromatography data
* into an Allotrope-compatible JSON structure.
* <p>
* It supports conversion from .ch files
* as well as from folders containing multiple related files (.ch, .xml, and .txt).
*/
public class GcToAllotropeJsonConverter {

private final ZoneId defaultTimeZone;
private ChemStationToAllotropeMapper chemstationMapper;
private final ChemStationToAllotropeMapper chemstationMapper;

/**
* Creates a GcToAllotropeJsonConverter with a default {@link ChemStationToAllotropeMapper} from {@link ChemStationToAllotropeMapperBuilder}.
*/
public GcToAllotropeJsonConverter() {
defaultTimeZone = ZoneOffset.UTC;
this.createMapper();
this(new ChemStationToAllotropeMapperBuilder().build());
}

public GcToAllotropeJsonConverter(ZoneId defaultTimeZone) {
this.defaultTimeZone = defaultTimeZone;
this.createMapper();
/**
* Creates a GcToAllotropeJsonConverter with a custom {@link ChemStationToAllotropeMapper}.
*
* @param chemstationMapper
* mapper created from {@link ChemStationToAllotropeMapperBuilder}
*/
public GcToAllotropeJsonConverter(ChemStationToAllotropeMapper chemstationMapper) {
this.chemstationMapper = chemstationMapper;
}

private void createMapper() {
chemstationMapper = new ChemStationToAllotropeMapper(defaultTimeZone);
}

public ObjectNode convertFile(String filePath) throws JAXBException, IOException {
GasChromatographyTabularEmbedSchema embedSchema = chemstationMapper.mapToGasChromatographySchema(filePath);

private static ObjectNode schema(GasChromatographyTabularEmbedSchema embedSchema) {
ObjectMapper objectMapper = JsonMapper.builder().addModule(new JavaTimeModule()).build();

objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);

return objectMapper.valueToTree(embedSchema);
}

/**
* Converts the contents of a specified folder into an Allotrope-compatible JSON representation.
*
* @param folderPath
* the path to the folder containing the .ch, .xml and .txt files to be converted
*
* @return an ObjectNode representing the Allotrope-compatible JSON structure
*
* @throws JAXBException
* if there is an error while processing XML files during the conversion
* @throws IOException
* if there is an I/O error while reading the folder or its contents
*/
public ObjectNode convertFolderToAllotrope(String folderPath) throws JAXBException, IOException {
GasChromatographyTabularEmbedSchema embedSchema = chemstationMapper.fromFolder(folderPath);

return schema(embedSchema);
}

/**
* Converts the contents of a specified .ch file into an Allotrope-compatible JSON representation.
*
* @param chFilePath
* the file path to the .ch file to be converted
*
* @return an ObjectNode representing the Allotrope-compatible JSON structure
*
* @throws IOException
* if there is an error accessing or reading the required .ch file
*/
public ObjectNode convertChFileToAllotrope(String chFilePath) throws IOException {
GasChromatographyTabularEmbedSchema embedSchema = chemstationMapper.fromChFile(chFilePath);

return schema(embedSchema);
}
}
Loading

0 comments on commit 45c2635

Please sign in to comment.