-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #871 from lonvia/json-export-opensearch
Implement missing JSON export for OpenSearch version
- Loading branch information
Showing
5 changed files
with
63 additions
and
23 deletions.
There are no files selected for viewing
49 changes: 43 additions & 6 deletions
49
app/opensearch/src/main/java/de/komoot/photon/JsonDumper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,59 @@ | ||
package de.komoot.photon; | ||
|
||
import org.apache.commons.lang3.NotImplementedException; | ||
import com.fasterxml.jackson.core.JsonEncoding; | ||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.core.Version; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.module.SimpleModule; | ||
import de.komoot.photon.opensearch.PhotonDocSerializer; | ||
import org.slf4j.Logger; | ||
|
||
import java.io.FileNotFoundException; | ||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
public class JsonDumper implements Importer { | ||
private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(JsonDumper.class); | ||
|
||
public JsonDumper(String filename, String[] languages, String[] extraTags) throws FileNotFoundException { | ||
throw new NotImplementedException(); | ||
final JsonGenerator generator; | ||
|
||
public JsonDumper(String filename, String[] languages, String[] extraTags) throws IOException { | ||
final var module = new SimpleModule("PhotonDocSerializer", | ||
new Version(1, 0, 0, null, null, null)); | ||
module.addSerializer(PhotonDoc.class, new PhotonDocSerializer(languages, extraTags)); | ||
|
||
final ObjectMapper mapper = new ObjectMapper(); | ||
mapper.registerModule(module); | ||
|
||
if ("-".equals(filename)) { | ||
generator = mapper.getFactory().createGenerator(System.out, JsonEncoding.UTF8); | ||
} else { | ||
generator = mapper.getFactory().createGenerator(new File(filename), JsonEncoding.UTF8); | ||
} | ||
generator.writeStartObject(); | ||
generator.writeObjectField("id", "Photon Dump Header"); | ||
generator.writeObjectField("version", PhotonDocSerializer.FORMAT_VERSION); | ||
generator.writeEndObject(); | ||
} | ||
|
||
@Override | ||
public void add(PhotonDoc doc, int objectId) { | ||
throw new NotImplementedException(); | ||
try { | ||
generator.writeStartObject(); | ||
generator.writeObjectField("id", doc.getUid(objectId)); | ||
generator.writeObjectField("document", doc); | ||
generator.writeEndObject(); | ||
} catch (IOException e) { | ||
LOGGER.error("Error writing json file", e); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public void finish() { | ||
throw new NotImplementedException(); | ||
try { | ||
generator.close(); | ||
} catch (IOException e) { | ||
LOGGER.warn("Error while closing output file", e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Configuration status="error"> | ||
<Appenders> | ||
<Console name="stdout" target="SYSTEM_OUT"> | ||
<PatternLayout pattern="%d [%t] %-5p %c - %m%n" /> | ||
</Console> | ||
<Async name="ASYNC" bufferSize="500"> | ||
<AppenderRef ref="stdout"/> | ||
</Async> | ||
</Appenders> | ||
<Loggers> | ||
<Logger name="de.komoot.photon" level="info"/> | ||
<Root level="warn"> | ||
<AppenderRef ref="ASYNC" /> | ||
</Root> | ||
</Loggers> | ||
<Appenders> | ||
<Console name="stderr" target="SYSTEM_ERR"> | ||
<PatternLayout pattern="%d [%t] %-5p %c - %m%n" /> | ||
</Console> | ||
<Async name="ASYNC" bufferSize="500"> | ||
<AppenderRef ref="stderr"/> | ||
</Async> | ||
</Appenders> | ||
<Loggers> | ||
<Logger name="de.komoot.photon" level="info"/> | ||
<Root level="warn"> | ||
<AppenderRef ref="ASYNC" /> | ||
</Root> | ||
</Loggers> | ||
</Configuration> |