Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
changed version to 0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ymamakis committed Aug 4, 2016
1 parent 8d6e3b1 commit 470d1b2
Show file tree
Hide file tree
Showing 13 changed files with 184 additions and 189 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>enrichment-parent</artifactId>
<groupId>eu.europeana.enrichment</groupId>
<version>0.1-SNAPSHOT</version>
<version>0.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<packaging>jar</packaging>
Expand All @@ -16,7 +16,7 @@
<dependency>
<groupId>eu.europeana.enrichment</groupId>
<artifactId>enrichment-framework-common</artifactId>
<version>0.1-SNAPSHOT</version>
<version>0.1</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -143,7 +143,7 @@
</plugins>
</build>
<properties>
<enrichment.version>0.1-SNAPSHOT</enrichment.version>
<enrichment.version>0.1</enrichment.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
package eu.europeana.enrichment.rest.client;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;

import co.freeside.betamax.Betamax;
import co.freeside.betamax.Recorder;
import co.freeside.betamax.TapeMode;
import eu.europeana.enrichment.api.external.EntityClass;
import eu.europeana.enrichment.api.external.EntityWrapper;
import eu.europeana.enrichment.api.external.InputValue;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

public class EnrichmentDriverTest {

Expand All @@ -31,7 +30,7 @@ public void test() throws JsonGenerationException, JsonMappingException,
Properties props = new Properties();
props.load(new FileInputStream("src/test/resources/test.properties"));
String basePath = props.getProperty("base.path");
EnrichmentDriver driver = new EnrichmentDriver(basePath+"/enrich");
EnrichmentDriver driver = new EnrichmentDriver(basePath+"/");
List<InputValue> values = prepareValues();

List<EntityWrapper> lst = driver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>enrichment-parent</artifactId>
<groupId>eu.europeana.enrichment</groupId>
<version>0.1-SNAPSHOT</version>
<version>0.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<packaging>jar</packaging>
Expand Down Expand Up @@ -61,7 +61,7 @@
</plugins>
</build>
<properties>
<enrichment.version>0.1-SNAPSHOT</enrichment.version>
<enrichment.version>0.1</enrichment.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>enrichment-parent</artifactId>
<groupId>eu.europeana.enrichment</groupId>
<version>0.1-SNAPSHOT</version>
<version>0.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<packaging>war</packaging>
Expand All @@ -22,12 +22,12 @@
<dependency>
<groupId>eu.europeana.enrichment</groupId>
<artifactId>enrichment-framework-common</artifactId>
<version>0.1-SNAPSHOT</version>
<version>0.1</version>
</dependency>
<dependency>
<groupId>eu.europeana.enrichment</groupId>
<artifactId>enrichment-framework-client</artifactId>
<version>0.1-SNAPSHOT</version>
<version>0.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>enrichment-parent</artifactId>
<groupId>eu.europeana.enrichment</groupId>
<version>0.1-SNAPSHOT</version>
<version>0.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>enrichment-framework-knowledgebase</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
/**
* Generic Template that converts the RDF representation of a contextual Class to Europeana compatible POJO
*
* @author Yorgos.Mamakis@ europeana.eu
* @param <S> Implementation Class of a Contextual Entity
* @author Yorgos.Mamakis@ europeana.eu
*/
public abstract class Template<S extends ContextualClassImpl> {

Expand All @@ -51,6 +51,7 @@ private void appendValue(S obj, String methodName, Object value) {
if (StringUtils.equals(method.getName(), methodName)) {
type = method.getParameterTypes()[0];
found = method;
break;
}
}
if (type.isAssignableFrom(String[].class)) {
Expand All @@ -67,6 +68,11 @@ private void appendValue(S obj, String methodName, Object value) {
found.invoke(obj, (Object) finalArray);
}
}
if (type.isAssignableFrom(Float.class)) {

found.invoke(obj, Float.parseFloat(((AttributeHolder)value).elementValue));

}
if (type.isAssignableFrom(Map.class)) {
Map<String, List<String>> vals = (Map<String, List<String>>) getter
.invoke(obj);
Expand Down Expand Up @@ -129,75 +135,75 @@ private void appendValue(S obj, String methodName, Object value) {

/**
* Method that parses the EDM/XML representation of contextual Entity and returns a POJO
* @param obj The Europeana Compatible Java class for a contextual entity
* @param resourceUri The URI of the contextual class
* @param xml The EDM/XML representation of the contextual class
*
* @param obj The Europeana Compatible Java class for a contextual entity
* @param resourceUri The URI of the contextual class
* @param xml The EDM/XML representation of the contextual class
* @param methodMapping The mapping between the EDM fields and the Java setter
* @return The populated POJO
*/
protected S parse(S obj, String resourceUri, String xml,
Map<String, String> methodMapping) {
//System.out.println ("before "+ xml+"\n end before");



//to be optimized
xml=xml.replace("&#55296;", "");
xml=xml.replace("&#55362;", "");
xml=xml.replace("&#55363;", "");
xml=xml.replace("&#55364;", "");
xml=xml.replace("&#55378;", "");
xml=xml.replace("&#55381;", "");
xml=xml.replace("&#55384;", "");
xml=xml.replace("&#55391;", "");
xml=xml.replace("&#55394;", "");
xml=xml.replace("&#55629;", "");
xml=xml.replace("&#56256;", "");
xml=xml.replace("&#56322;", "");
xml=xml.replace("&#56351;", "");
xml=xml.replace("&#56384;", "");
xml=xml.replace("&#56394;", "");
xml=xml.replace("&#56513;", "");
xml=xml.replace("&#56648;", "");
xml=xml.replace("&#56657;", "");
xml=xml.replace("&#56786;", "");
xml=xml.replace("&#56855;", "");
xml=xml.replace("&#57086;", "");
xml=xml.replace("&#57113;", "");
xml=xml.replace("&#57121;", "");
xml=xml.replace("&#57136;", "");
xml=xml.replace("&#57137;", "");
xml=xml.replace("&#57138;", "");
xml=xml.replace("&#57139;", "");
xml=xml.replace("&#57140;", "");
xml=xml.replace("&#57142;", "");
xml=xml.replace("&#57143;", "");
xml=xml.replace("&#57144;", "");
xml=xml.replace("&#57145;", "");
xml=xml.replace("&#57146;", "");
xml=xml.replace("&#57147;", "");
xml=xml.replace("&#57148;", "");
xml=xml.replace("&#57149;", "");
xml=xml.replace("&#57150;", "");
xml=xml.replace("&#57151;", "");
xml=xml.replace("&#57152;", "");
xml=xml.replace("&#57154;", "");
xml=xml.replace("&#57155;", "");
xml=xml.replace("&#57156;", "");
xml=xml.replace("&#57157;", "");
xml=xml.replace("&#57158;", "");
xml=xml.replace("&#57159;", "");
xml=xml.replace("&#57161;", "");
xml=xml.replace("&#57271;", "");
xml=xml.replace("&#57279;", "");
Map<String, String> methodMapping) {
//System.out.println ("before "+ xml+"\n end before");


//to be optimized
xml = xml.replace("&#55296;", "");
xml = xml.replace("&#55362;", "");
xml = xml.replace("&#55363;", "");
xml = xml.replace("&#55364;", "");
xml = xml.replace("&#55378;", "");
xml = xml.replace("&#55381;", "");
xml = xml.replace("&#55384;", "");
xml = xml.replace("&#55391;", "");
xml = xml.replace("&#55394;", "");
xml = xml.replace("&#55629;", "");
xml = xml.replace("&#56256;", "");
xml = xml.replace("&#56322;", "");
xml = xml.replace("&#56351;", "");
xml = xml.replace("&#56384;", "");
xml = xml.replace("&#56394;", "");
xml = xml.replace("&#56513;", "");
xml = xml.replace("&#56648;", "");
xml = xml.replace("&#56657;", "");
xml = xml.replace("&#56786;", "");
xml = xml.replace("&#56855;", "");
xml = xml.replace("&#57086;", "");
xml = xml.replace("&#57113;", "");
xml = xml.replace("&#57121;", "");
xml = xml.replace("&#57136;", "");
xml = xml.replace("&#57137;", "");
xml = xml.replace("&#57138;", "");
xml = xml.replace("&#57139;", "");
xml = xml.replace("&#57140;", "");
xml = xml.replace("&#57142;", "");
xml = xml.replace("&#57143;", "");
xml = xml.replace("&#57144;", "");
xml = xml.replace("&#57145;", "");
xml = xml.replace("&#57146;", "");
xml = xml.replace("&#57147;", "");
xml = xml.replace("&#57148;", "");
xml = xml.replace("&#57149;", "");
xml = xml.replace("&#57150;", "");
xml = xml.replace("&#57151;", "");
xml = xml.replace("&#57152;", "");
xml = xml.replace("&#57154;", "");
xml = xml.replace("&#57155;", "");
xml = xml.replace("&#57156;", "");
xml = xml.replace("&#57157;", "");
xml = xml.replace("&#57158;", "");
xml = xml.replace("&#57159;", "");
xml = xml.replace("&#57161;", "");
xml = xml.replace("&#57271;", "");
xml = xml.replace("&#57279;", "");

//
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
inputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
inputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
InputStream in = new ByteArrayInputStream(xml.getBytes(Charset.forName("UTF-8")));
//String xml10pattern = "[^"
//

XMLInputFactory inputFactory = XMLInputFactory.newInstance();
inputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
inputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
InputStream in = new ByteArrayInputStream(xml.getBytes(Charset.forName("UTF-8")));
//String xml10pattern = "[^"
//+ "\u0009\r\n"
//+ "\u0020-\uD7FF"
//+ "\uE000-\uFFFD"
Expand All @@ -212,7 +218,7 @@ protected S parse(S obj, String resourceUri, String xml,
StartElement startElement = event.asStartElement();
String qElem = startElement.getName().getPrefix() + ":"
+ startElement.getName().getLocalPart();

if (methodMapping.containsKey(qElem)) {
if (isRoot) {
appendValue(obj, methodMapping.get(qElem),
Expand All @@ -222,12 +228,12 @@ protected S parse(S obj, String resourceUri, String xml,

Attribute attr = startElement
.getAttributeByName(new QName(RDF_NAMESPACE,
"resource"));
"resource"));
Attribute langAttr = startElement
.getAttributeByName(new QName(XML_NAMESPACE, "lang"));
Attribute about = startElement
.getAttributeByName(new QName(RDF_NAMESPACE,
"about"));
"about"));
if (attr != null) {
AttributeHolder attribute = new AttributeHolder();
attribute.setAttributeName(RDF_RESOURCE);
Expand All @@ -242,15 +248,15 @@ protected S parse(S obj, String resourceUri, String xml,
attribute.setAttributeValue(langAttr
.getValue());
}
event = eventReader.nextEvent();

event = eventReader.nextEvent();
if (!event.isEndElement()) {
attribute.setElementValue(event
attribute.setElementValue(event
.asCharacters().getData());
appendValue(obj, methodMapping.get(qElem),
attribute);
}

}
}
}
Expand All @@ -260,19 +266,20 @@ protected S parse(S obj, String resourceUri, String xml,
}
return obj;
} catch (XMLStreamException | FactoryConfigurationError e) {
log.log(Level.SEVERE, e.getMessage()+" \n"+xml);
log.log(Level.SEVERE, e.getMessage() + " \n" + xml);
}
return null;
}

/**
* Contextual class specific method that needs to be invoked to access the parse() method
* @param xml The XML that contains the EDM/XML to be converted
*
* @param xml The XML that contains the EDM/XML to be converted
* @param resourceUri The Resource URI of the original Controlled Vocabulary Resource
* @return
* @return
*/
public abstract S transform (String xml, String resourceUri);
public abstract S transform(String xml, String resourceUri);

class AttributeHolder {

private String attributeName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>enrichment-parent</artifactId>
<groupId>eu.europeana.enrichment</groupId>
<version>0.1-SNAPSHOT</version>
<version>0.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<packaging>war</packaging>
Expand All @@ -16,12 +16,12 @@
<dependency>
<groupId>eu.europeana.enrichment</groupId>
<artifactId>enrichment-framework-common</artifactId>
<version>0.1-SNAPSHOT</version>
<version>0.1</version>
</dependency>
<dependency>
<groupId>eu.europeana.enrichment</groupId>
<artifactId>enrichment-framework-service</artifactId>
<version>0.1-SNAPSHOT</version>
<version>0.1</version>
</dependency>
<dependency>
<groupId>org.mongojack</groupId>
Expand Down Expand Up @@ -191,7 +191,7 @@

<properties>

<enrichment.version>0.1-SNAPSHOT</enrichment.version>
<enrichment.version>0.1</enrichment.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
Expand Down
Loading

0 comments on commit 470d1b2

Please sign in to comment.