Skip to content

Commit

Permalink
Parse JSON settings if needed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mailaender committed Jan 12, 2022
1 parent 964bbca commit 4a97f41
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.chemclipse.csd.model;bundle-version="0.8.0",
org.eclipse.chemclipse.wsd.model;bundle-version="0.8.0",
org.eclipse.chemclipse.pdfbox.extensions;bundle-version="0.8.0",
org.eclipse.swtchart.export;bundle-version="0.8.0"
org.eclipse.swtchart.export;bundle-version="0.8.0",
com.fasterxml.jackson.core.jackson-databind;bundle-version="2.9.93",
com.fasterxml.jackson.core.jackson-core;bundle-version="2.9.9",
org.apache.commons.lang;bundle-version="2.6.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Import-Package: com.fasterxml.jackson.annotation;version="2.7.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Contributors:
* Dr. Philip Wenig - initial API and implementation
* Christoph Läubrich - Settings support
* Matthias Mailänder - parse JSON settings
*******************************************************************************/
package net.openchrom.xxd.converter.supplier.pdf.ui.io;

Expand All @@ -23,6 +24,7 @@
import java.util.Map;
import java.util.Set;

import org.apache.commons.lang.StringUtils;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.graphics.image.JPEGFactory;
Expand Down Expand Up @@ -56,6 +58,10 @@
import org.eclipse.chemclipse.wsd.model.core.IChromatogramWSD;
import org.eclipse.core.runtime.IProgressMonitor;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.MismatchedInputException;

import net.openchrom.xxd.converter.supplier.pdf.ui.io.generic.ImageRunnableGeneric;
import net.openchrom.xxd.converter.supplier.pdf.ui.settings.ReportSettingsGeneric;

Expand Down Expand Up @@ -285,6 +291,20 @@ private ImageRunnableGeneric createImages(IChromatogram<? extends IPeak> chromat
return imageRunnable;
}

private static boolean isJSON(String tree) {

try {
final ObjectMapper mapper = new ObjectMapper();
mapper.readTree(tree);
return true;
} catch(JsonProcessingException e) {
return false;
} catch(IOException e) {
logger.warn(e);
return false;
}
}

private PDTable getHeaderDataTable(Map<String, String> headerDataMap) {

PDTable pdTable = new PDTable();
Expand All @@ -294,10 +314,31 @@ private PDTable getHeaderDataTable(Map<String, String> headerDataMap) {
pdTable.addColumn("Value", 95.0f);
//
for(Map.Entry<String, String> entry : headerDataMap.entrySet()) {
List<String> row = new ArrayList<>();
row.add(normalizeText(entry.getKey()));
row.add(normalizeText(entry.getValue()));
pdTable.addDataRow(row);
String name = entry.getKey();
String value = entry.getValue();
if(isJSON(value)) {
final ObjectMapper mapper = new ObjectMapper();
try {
MethodSettings methodSettings = mapper.readValue(value, MethodSettings.class);
for(String key : methodSettings.getSettings().keySet()) {
name = StringUtils.join(StringUtils.splitByCharacterTypeCamelCase(key), ' ');
value = methodSettings.getSettings().get(key).toString();
List<String> row = new ArrayList<>();
row.add(StringUtils.capitalize(name));
row.add(normalizeText(value));
pdTable.addDataRow(row);
}
} catch(MismatchedInputException e) {
// ignore
} catch(IOException e) {
logger.warn(e);
}
} else {
List<String> row = new ArrayList<>();
row.add(normalizeText(name));
row.add(normalizeText(value));
pdTable.addDataRow(row);
}
}
//
return pdTable;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*******************************************************************************
* Copyright (c) 2022 Lablicate GmbH.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Matthias Mailänder - initial API and implementation
*******************************************************************************/
package net.openchrom.xxd.converter.supplier.pdf.ui.io;

import java.util.LinkedHashMap;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonAnySetter;

public class MethodSettings {

Map<String, Object> settings = new LinkedHashMap<>();

@JsonAnySetter
void setSettings(String name, Object value) {

settings.put(name, value);
}

public Map<String, Object> getSettings() {

return settings;
}
}

0 comments on commit 4a97f41

Please sign in to comment.