Skip to content

Commit

Permalink
Merge pull request #8 from hbz/html
Browse files Browse the repository at this point in the history
Html
  • Loading branch information
aquast authored Feb 19, 2024
2 parents 984c69e + cde2593 commit 2916ab2
Show file tree
Hide file tree
Showing 23 changed files with 929 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;
import java.util.Hashtable;
import java.io.File;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -25,8 +26,6 @@
public class AggregationElementOperator {
//TODO: Implement all operations on the data you wish to have ;-)
final static Logger logger = LogManager.getLogger(AggregationElementOperator.class);

private EdmImpl edmImpl = new EdmImpl();
private Rdf rdf = null;


Expand All @@ -43,8 +42,7 @@ public AggregationElementOperator(Rdf rdf) {
* @param filePath
*/
public AggregationElementOperator(String filePath) {
this.edmImpl.setFilePath(filePath);
rdf = edmImpl.deserializeXml();
rdf = EdmProvider.deserialize(new File(filePath));
}

/**
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/de/nrw/hbz/edm/impl/ConsoleImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package de.nrw.hbz.edm.impl;

import java.util.ArrayList;
import java.io.File;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -28,7 +29,7 @@ public class ConsoleImpl {
/**
* @param args
*/
String filePath = System.getProperty("user.dir") + System.getProperty("file.separator") + "src/main/resources/OaiPmh.xml";
String filePath = System.getProperty("user.dir") + System.getProperty("file.separator") + "src/test/resources/OaiPmh.xml";

//static String filePath = System.getProperty("user.dir") + System.getProperty("file.separator") + "src/main/resources/OAIBase.xml";

Expand All @@ -40,7 +41,7 @@ public static void main(String[] args) {
ConsoleImpl conImpl = new ConsoleImpl();
OaiPmhImpl impl = new OaiPmhImpl();
SerializeOaiPmh exOaiPmh = (SerializeOaiPmh) conImpl.generateExampleOaiPmh();
// impl.serializeXml(exOaiPmh);
impl.serializeXml(exOaiPmh);

if (args != null && args.length > 0) {
conImpl.filePath = args[0];
Expand All @@ -52,11 +53,11 @@ public static void main(String[] args) {
// logger.debug(resultOaiPmh.getOaiMethod().getRecord().get(0).getMetadata().getRdf().getProvidedCho());
//impl.serializeXml(resultOaiPmh);

conImpl.filePath = System.getProperty("user.dir") + System.getProperty("file.separator") + "src/main/resources/ExampleSip/EDM.xml";
conImpl.filePath = System.getProperty("user.dir") + System.getProperty("file.separator") + "src/test/resources/ExampleSip/EDM.xml";
EdmImpl edmImpl = new EdmImpl(conImpl.filePath);
Rdf resultEdm = edmImpl.deserializeXml();
Rdf resultEdm = EdmProvider.deserialize(new File(conImpl.filePath));
logger.debug(resultOaiPmh.getOaiMethod().getRecord().get(0).getMetadata().getRdf().getProvidedCho());
// edmImpl.serializeXml(resultEdm);
edmImpl.serializeXml(resultEdm);

ArrayList<String> isShownByReplacement = new ArrayList<>();
isShownByReplacement.add("https://www.q-terra.de/Part-1/000-0002.csv");
Expand Down
90 changes: 0 additions & 90 deletions src/main/java/de/nrw/hbz/edm/impl/DeserializeEdmXml.java

This file was deleted.

5 changes: 3 additions & 2 deletions src/main/java/de/nrw/hbz/edm/impl/EdmImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*/
package de.nrw.hbz.edm.impl;

import java.io.File;

import de.nrw.hbz.edm.model.Rdf;

/**
Expand All @@ -25,8 +27,7 @@ public EdmImpl(String filePath) {
* @return Rdf
*/
public Rdf deserializeXml() {
DeserializeEdmXml dsXml = new DeserializeEdmXml(filePath);
return dsXml.deserialize();
return EdmProvider.deserialize(new File(filePath));

}

Expand Down
165 changes: 165 additions & 0 deletions src/main/java/de/nrw/hbz/edm/impl/EdmProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/**
*
*/
package de.nrw.hbz.edm.impl;

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.exc.StreamReadException;
import com.fasterxml.jackson.databind.DatabindException;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;

import de.nrw.hbz.edm.model.Rdf;
import de.nrw.hbz.edm.model.deserialize.DeserializeRdf;
import de.nrw.hbz.edm.model.serialize.SerializeRdf;

/**
* A class to generate appropriate Pojo-representations from serialized EDM (Europeana Data Model) metadata
* Makes use of the jackson-Framework
*/
public class EdmProvider {

final static Logger logger = LogManager.getLogger(EdmProvider.class);

private Rdf rdf = new DeserializeRdf();
private static InputStream xmlIs = null;

/**
* loads File content into InputStream
* @return InputStream representing EDM metadata
*/
private static InputStream loadXml(File file) {
BufferedInputStream bis = null;
try {
FileInputStream fis = new FileInputStream(file);
bis = new BufferedInputStream(fis);
} catch (FileNotFoundException e) {
logger.error(e.getMessage());
}

return bis;
}

/**
* @param rdf EDM metadata as String representation
* @return InputStream representing EDM metadata
*/
private static InputStream loadXmlString(String rdfString) {

BufferedInputStream bis = null;
ByteArrayInputStream baif = new ByteArrayInputStream(rdfString.getBytes());
bis = new BufferedInputStream(baif);

return bis;
}

/**
* method takes serialized EDM as InputStream
* @param is InputStream to be used
* @return EDM as Pojos according to jackson-Framework
*/
public static Rdf deserialize(InputStream is) {
DeserializeRdf rdf = null;
xmlIs = is;
XmlMapper xmlMapper = new XmlMapper();
try {
rdf = xmlMapper.readValue(xmlIs, DeserializeRdf.class);

} catch (StreamReadException e) {
logger.error(e.getMessage());
} catch (DatabindException e) {
logger.error(e.getMessage());
} catch (IOException e) {
logger.error(e.getMessage());
}


return rdf;
}

/**
* method takes serialized EDM as File object
* @param file File to be used
* @return EDM as Pojos according to jackson-Framework
*/
public static Rdf deserialize(File file) {
DeserializeRdf rdf = null;
xmlIs = loadXml(file);
XmlMapper xmlMapper = new XmlMapper();
try {
rdf = xmlMapper.readValue(xmlIs, DeserializeRdf.class);

} catch (StreamReadException e) {
logger.error(e.getMessage());
} catch (DatabindException e) {
logger.error(e.getMessage());
} catch (IOException e) {
logger.error(e.getMessage());
}


return rdf;
}

/**
* method takes serialized EDM as String
* @param edmString the String used to deserialize
* @return EDM as Pojos according to jackson-Framework
*/
public static Rdf deserialize(String edmString) {
DeserializeRdf rdf = null;
xmlIs = loadXmlString(edmString);
XmlMapper xmlMapper = new XmlMapper();
try {
rdf = xmlMapper.readValue(xmlIs, DeserializeRdf.class);

} catch (StreamReadException e) {
logger.error(e.getMessage());
} catch (DatabindException e) {
logger.error(e.getMessage());
} catch (IOException e) {
logger.error(e.getMessage());
}
return rdf;
}

public static String serialize(Rdf edm) {
XmlMapper xmlMapper = new XmlMapper();
String xml = null;
try {
xmlMapper.writerFor(SerializeRdf.class);
xml = xmlMapper.writerWithDefaultPrettyPrinter().writeValueAsString(edm);

} catch (JsonProcessingException e) {
logger.error("Failed to serialize EDM Object: " + edm.toString());
}
return xml;
}

/**
* @return the oaiPmh
*/
public Rdf getEdm() {
return rdf;
}


/**
* @param oaiPmh the oaiPmh to set
*/
public void setEdm(Rdf rdf) {
this.rdf = rdf;
}


}
Loading

0 comments on commit 2916ab2

Please sign in to comment.