Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/Relation.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/Relation.java	(revision 41790)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/Relation.java	(nonexistent)
@@ -1,108 +0,0 @@
-package eu.dnetlib.data.claims.migration;
-
-/**
- * Created by kiatrop on 5/2/2016.
- */
-
-import java.util.Date;
-
-/**
- * This is the old claim representation
- */
-public class Relation {
-
-    private String claimId = null;
-    private String targetId = null;
-    private String targetType = null;
-
-    private String sourceId = null;
-    private String sourceType = null;
-
-    private boolean hasDMF = false;
-    private String dmf = null;
-
-    private String collectedFrom = null;
-
-    private String claimedBy = null;
-    private Date claimDate = null;
-
-    public String getClaimId() {
-        return claimId;
-    }
-
-    public void setClaimId(String claimId) {
-        this.claimId = claimId;
-    }
-
-    public String getTargetId() {
-        return targetId;
-    }
-
-    public void setTargetId(String targetId) {
-        this.targetId = targetId;
-    }
-
-    public String getTargetType() {
-        return targetType;
-    }
-
-    public void setTargetType(String targetType) {
-        this.targetType = targetType;
-    }
-
-    public String getSourceId() {
-        return sourceId;
-    }
-
-    public void setSourceId(String sourceId) {
-        this.sourceId = sourceId;
-    }
-
-    public String getSourceType() {
-        return sourceType;
-    }
-
-    public void setSourceType(String sourceType) {
-        this.sourceType = sourceType;
-    }
-
-    public boolean isHasDMF() {
-        return hasDMF;
-    }
-
-    public void setHasDMF(boolean hasDMF) {
-        this.hasDMF = hasDMF;
-    }
-
-    public String getCollectedFrom() {
-        return collectedFrom;
-    }
-
-    public void setCollectedFrom(String collectedFrom) {
-        this.collectedFrom = collectedFrom;
-    }
-
-    public String getClaimedBy() {
-        return claimedBy;
-    }
-
-    public void setClaimedBy(String claimedBy) {
-        this.claimedBy = claimedBy;
-    }
-
-    public Date getClaimDate() {
-        return claimDate;
-    }
-
-    public void setClaimDate(Date claimDate) {
-        this.claimDate = claimDate;
-    }
-
-    public String getDmf() {
-        return dmf;
-    }
-
-    public void setDmf(String dmf) {
-        this.dmf = dmf;
-    }
-}
Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/ContextRelation.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/ContextRelation.java	(revision 41790)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/ContextRelation.java	(nonexistent)
@@ -1,95 +0,0 @@
-package eu.dnetlib.data.claims.migration;
-
-import java.util.Date;
-
-/**
- * Created by argirok on 10/2/2016.
- */
-public class ContextRelation {
-
-    private String claimId = null;
-    private String contextId = null;
-
-    private String resultId = null;
-
-    private boolean hasDMF = false;
-    private String resultDmf = null;
-    private String contextDmf = null;
-
-
-    private String collectedFrom = null;
-    private String claimedBy = null;
-    private Date claimDate = null;
-
-    public String getClaimId() {
-        return claimId;
-    }
-
-    public void setClaimId(String claimId) {
-        this.claimId = claimId;
-    }
-
-    public String getContextId() {
-        return contextId;
-    }
-
-    public void setContextId(String contextId) {
-        this.contextId = contextId;
-    }
-
-    public String getResultId() {
-        return resultId;
-    }
-
-    public void setResultId(String resultId) {
-        this.resultId = resultId;
-    }
-
-    public boolean isHasDMF() {
-        return hasDMF;
-    }
-
-    public void setHasDMF(boolean hasDMF) {
-        this.hasDMF = hasDMF;
-    }
-
-    public String getResultDmf() {
-        return resultDmf;
-    }
-
-    public void setResultDmf(String resultDmf) {
-        this.resultDmf = resultDmf;
-    }
-
-    public String getContextDmf() {
-        return contextDmf;
-    }
-
-    public void setContextDmf(String contextDmf) {
-        this.contextDmf = contextDmf;
-    }
-
-    public String getCollectedFrom() {
-        return collectedFrom;
-    }
-
-    public void setCollectedFrom(String collectedFrom) {
-        this.collectedFrom = collectedFrom;
-    }
-
-    public String getClaimedBy() {
-        return claimedBy;
-    }
-
-    public void setClaimedBy(String claimedBy) {
-        this.claimedBy = claimedBy;
-    }
-
-    public Date getClaimDate() {
-        return claimDate;
-    }
-
-    public void setClaimDate(Date claimDate) {
-        this.claimDate = claimDate;
-    }
-}
Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/Result.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/Result.java	(revision 41790)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/Result.java	(nonexistent)
@@ -1,213 +0,0 @@
-package eu.dnetlib.data.claims.migration;
-
-import eu.dnetlib.data.claimsDemo.ClaimUtils;
-
-/**
- * Created by kiatrop on 20/11/2015.
- */
-public class Result implements OpenaireEntity{
-
-    private String title;
-//external url: url+doi (if doi exists) or url from websources
-    private String externalUrl;
-    private String openaireId;
-    private String doi;
-    private String orcidworkid;
-    private String pmcid;
-    //accessRights : set by user
-    private String accessRights;
-    //bestLicence : from search
-    private String bestLicense;
-
-    private String collectedFrom;
-    private String metadataRecord;
-
-//for the metadataRecord file
-    private String recordPath;
-    private String recordFormat;
-
-    private String resultType;
-    private boolean found=false;
-    private String embargoEndDate;
-
-//Used for Datacite
-    private String oai;
-    private String provenanceaction;
-
-
-    public String getDoi() {
-		return doi;
-	}
-
-	public void setDoi(String doi) {
-		this.doi = doi;
-	}
-
-	public String getTitle() {
-        return title;
-    }
-
-    public void setTitle(String title) {
-        this.title = title;
-    }
-
-    public String getExternalUrl() {
-        return externalUrl;
-    }
-
-    public void setExternalUrl(String externalUrl) {
-        this.externalUrl = externalUrl;
-    }
-
-    public String getOpenaireId() {
-        return openaireId;
-    }
-
-    public void setOpenaireId(String openaire_id) {
-        this.openaireId = openaire_id;
-    }
-
-    public String getAccessRights() {
-        return accessRights;
-    }
-
-    public void setAccessRights(String accessRights) {
-        this.accessRights = accessRights;
-    }
-
-    public String getBestLicense() {
-        return bestLicense;
-    }
-
-    public void setBestLicense(String bestLicense) {
-        this.bestLicense = bestLicense;
-    }
-
-    public String getCollectedFrom() {
-        return collectedFrom;
-    }
-
-    public void setCollectedFrom(String collectedFrom) {
-        if(!collectedFrom.contains("____::")) {
-            if (collectedFrom.equals("Datacite")) {
-                collectedFrom = ClaimUtils.COLLECTED_FROM_DATACITE;
-
-            } else if (collectedFrom.equals("Crossref")) {
-                collectedFrom = ClaimUtils.COLLECTED_FROM_CROSSREF;
-
-            } else if (collectedFrom.equals("Orcid")) {
-                collectedFrom = ClaimUtils.COLLECTED_FROM_ORCID;
-
-            } else {
-                collectedFrom = ClaimUtils.COLLECTED_FROM_OPENAIRE;
-            }
-        }
-        this.collectedFrom = collectedFrom;
-    }
-
-    public String getMetadataRecord() {
-        return metadataRecord;
-    }
-
-    public void setMetadataRecord(String metadataRecord) {
-        this.metadataRecord = metadataRecord;
-    }
-
-    public String getResultType() {
-        return resultType;
-    }
-
-    public void setResultType(String resultType) {
-        this.resultType = resultType;
-    }
-
-
-
-    public boolean isFound() {
-        return found;
-    }
-
-    public void setFound(boolean found) {
-        this.found = found;
-    }
-
-    public String getPmcid() {
-        return pmcid;
-    }
-
-    public void setPmcid(String pmcid) {
-        this.pmcid = pmcid;
-    }
-
-    public String getOrcidworkid() {
-        return orcidworkid;
-    }
-
-    public void setOrcidworkid(String orcidworkid) {
-        this.orcidworkid = orcidworkid;
-    }
-
-    public String getEmbargoEndDate() {
-        return embargoEndDate;
-    }
-
-    public void setEmbargoEndDate(String embargoEndDate) {
-        this.embargoEndDate = embargoEndDate;
-    }
-
-    public String getOai() {
-        return oai;
-    }
-
-    public void setOai(String oai) {
-        this.oai = oai;
-    }
-
-    public String getProvenanceaction() {
-        return provenanceaction;
-    }
-
-    public void setProvenanceaction(String provenanceaction) {
-        this.provenanceaction = provenanceaction;
-    }
-
-    public String getRecordPath() {
-        return recordPath;
-    }
-
-    public void setRecordPath(String recordPath) {
-        this.recordPath = recordPath;
-    }
-
-    public String getRecordFormat() {
-        return recordFormat;
-    }
-
-    public void setRecordFormat(String recordFormat) {
-        this.recordFormat = recordFormat;
-    }
-
-    @Override
-    public String toString() {
-        return "\nResult{" +
-                "title='" + title + '\'' +
-                ",\n external_url='" + externalUrl + '\'' +
-                ",\n openaire_id='" + openaireId + '\'' +
-                ",\n doi='" + doi + '\'' +
-                ",\n pmcid='" + pmcid + '\'' +
-                ",\n orcidworkid='" + orcidworkid + '\'' +
-                ",\n accessRights='" + accessRights + '\'' +
-                ",\n embargoEndDate='" + embargoEndDate + '\'' +
-                ",\n bestLicense='" + bestLicense + '\'' +
-                ",\n collectedFrom='" + collectedFrom + '\'' +
-                ",\n oai='" + oai + '\'' +
-                ",\n provenanceaction='" + provenanceaction + '\'' +
-                ",\n metadataRecord='" + ((metadataRecord!=null)?metadataRecord.substring(0,60):null) + "...\'" +
-                ",\n recordPath='" + recordPath + '\'' +
-                ",\n recordFormat='" + recordFormat + '\'' +
-                ",\n resultType='" + resultType + '\'' +
-                '}';
-    }
-//method to ask from API of search to get the metadataRecord
-    //then parse the fields
-}
Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/Project.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/Project.java	(revision 41790)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/Project.java	(nonexistent)
@@ -1,86 +0,0 @@
-package eu.dnetlib.data.claims.migration;
-
-/**
- * Created by kiatrop on 20/11/2015.
- */
-public class Project implements OpenaireEntity{
-    private String name;
-    private String acronym;
-    private String openaireId;
-    private String funderName;
-    private String funderShortName;
-    private String funderId;
-    private boolean found=true;
-
-    public String getName() {
-        return name;
-    }
-
-    public void setName(String name) {
-        this.name = name;
-    }
-
-    public String getAcronym() {
-        return acronym;
-    }
-
-    public void setAcronym(String acronym) {
-        this.acronym = acronym;
-    }
-
-    public String getOpenaireId() {
-        return openaireId;
-    }
-
-    public void setOpenaireId(String openaireId) {
-        this.openaireId = openaireId;
-     }
-
-    public String getFunderName() {
-        return funderName;
-    }
-
-    public void setFunderName(String funderName) {
-        this.funderName = funderName;
-    }
-
-    public String getFunderId() {
-        return funderId;
-    }
-
-    public void setFunderId(String funderId) {
-        this.funderId = funderId;
-    }
-
-    public boolean isFound() {
-        return found;
-    }
-
-    public void setFound(boolean found) {
-        this.found = found;
-    }
-
-    public String getFunderShortName() {
-        return funderShortName;
-    }
-
-    public void setFunderShortName(String funderShortName) {
-        this.funderShortName = funderShortName;
-    }
-
-    @Override
-    public String toString() {
-        return "Project{" +
-                "\nname='" + name + '\'' +
-                ",\n acronym='" + acronym + '\'' +
-                ",\n openaireId='" + openaireId + '\'' +
-                ",\n funderName='" + funderName + '\'' +
-                ",\n funderShortName='" + funderShortName + '\'' +
-                ",\n funderId='" + funderId + '\'' +
-                '}';
-    }
-
-    //method to ask from API of search to get the fields
-    //then parse the fields
-
-}
Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/Claim.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/Claim.java	(revision 41790)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/Claim.java	(nonexistent)
@@ -1,89 +0,0 @@
-package eu.dnetlib.data.claims.migration;
-
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-/**
- * Created by kiatrop on 20/11/2015.
- */
-public class Claim {
-    private OpenaireEntity target;
-    private OpenaireEntity source;
-
-    private String id;
-    private String userMail;
-    private Date date;
-    private String sourceType;
-    private String targetType;
-
-    public OpenaireEntity getTarget() {
-        return target;
-    }
-
-    public void setTarget(Result target) {
-        this.target = target;
-    }
-
-    public OpenaireEntity getSource() {
-        return source;
-    }
-
-    public void setSource(OpenaireEntity source) {
-        this.source = source;
-    }
-
-    public String getId() {
-        return id;
-    }
-
-    public void setId(String id) {
-        this.id = id;
-    }
-
-    public String getUserMail() {
-        return userMail;
-    }
-
-    public void setUserMail(String userMail) {
-        this.userMail = userMail;
-    }
-
-    public Date getDate() {
-        return date;
-    }
-
-    public void setDate(Date date) {
-        this.date = date;
-    }
-
-    public String getSourceType() {
-        return sourceType;
-    }
-
-    public void setSourceType(String sourceType) {
-        this.sourceType = sourceType;
-    }
-
-    public String getTargetType() {
-        return targetType;
-    }
-
-    public void setTargetType(String targetType) {
-        this.targetType = targetType;
-    }
-
-
-    @Override
-    public String toString() {
-        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
-        return "Claim{" +
-                "\ntargetType=" + targetType+
-                ",\nsourceType=" + sourceType +
-                ",\ntarget={" +   ((target==null)?"null":target.toString())+
-                "},\n source={" + ((source==null)?"null":source.toString())  +
-                "},\n id='" + id + '\'' +
-                ", userMail='" + userMail + '\'' +
-                ", date=" + format.format(date)+
-                '}';
-    }
-}
Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/OpenaireEntity.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/OpenaireEntity.java	(revision 41790)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/OpenaireEntity.java	(nonexistent)
@@ -1,7 +0,0 @@
-package eu.dnetlib.data.claims.migration;
-/**
- * Created by argirok on 10/12/2015.
- */
-public interface OpenaireEntity {
-    public String getOpenaireId();
-}
Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/Context.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/Context.java	(revision 41790)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/Context.java	(nonexistent)
@@ -1,38 +0,0 @@
-package eu.dnetlib.data.claims.migration;
-
-/**
- * Created by kiatrop on 20/11/2015.
- */
-public class Context implements OpenaireEntity {
-	
-    private String title;
-    private String openaireId;
-
-    public String getTitle() {
-        return title;
-    }
-
-    public void setTitle(String title) {
-        this.title = title;
-    }
-
-    public String getOpenaireId() {
-        return openaireId;
-    }
-
-    public void setOpenaireId(String openaireId) {
-        this.openaireId = openaireId;
-    }
-
-    private String export(){
-        return "";
-    }
-
-    @Override
-    public String toString() {
-        return "Context{" +
-                "title='" + title + '\'' +
-                ", openaireId='" + openaireId + '\'' +
-                '}';
-    }
-}
Index: modules/uoa-claims -demo/claims-demo/uoa-claims-demo.iml
===================================================================
--- modules/uoa-claims -demo/claims-demo/uoa-claims-demo.iml	(revision 41790)
+++ modules/uoa-claims -demo/claims-demo/uoa-claims-demo.iml	(revision 41791)
@@ -4,17 +4,14 @@
     <output url="file://$MODULE_DIR$/target/classes" />
     <output-test url="file://$MODULE_DIR$/target/test-classes" />
     <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
       <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
       <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
-      <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
       <excludeFolder url="file://$MODULE_DIR$/target" />
     </content>
     <orderEntry type="inheritedJdk" />
     <orderEntry type="sourceFolder" forTests="false" />
-    <orderEntry type="library" name="Maven: eu.dnetlib:cnr-cql-utils:1.0.1" level="project" />
-    <orderEntry type="library" name="Maven: eu.dnetlib:dnet-data-provision-rmi:1.0.0" level="project" />
-    <orderEntry type="library" name="Maven: eu.dnetlib:cnr-blackboard-common:1.0.0" level="project" />
-    <orderEntry type="library" name="Maven: eu.dnetlib:cnr-notifications-common:1.1.0" level="project" />
     <orderEntry type="library" name="Maven: junit:junit:4.8.2" level="project" />
     <orderEntry type="library" name="Maven: eu.dnetlib:uoa-commons:1.2.0-SNAPSHOT" level="project" />
     <orderEntry type="library" name="Maven: com.sun.xml.bind:jaxb-core:2.2.7" level="project" />
@@ -26,22 +23,16 @@
     <orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.6.6" level="project" />
     <orderEntry type="library" name="Maven: com.unboundid:unboundid-ldapsdk:1.1.3" level="project" />
     <orderEntry type="library" name="Maven: apache:commons-logging:1.1.1" level="project" />
+    <orderEntry type="library" name="Maven: log4j:log4j:1.2.17" level="project" />
     <orderEntry type="library" name="Maven: eu.dnetlib:uoa-api:1.2.0-SNAPSHOT" level="project" />
     <orderEntry type="library" name="Maven: eu.dnetlib:dnet-actionmanager-api:3.0.0" level="project" />
-    <orderEntry type="library" name="Maven: eu.dnetlib:uoa-domain:1.2.0-SNAPSHOT" level="project" />
-    <orderEntry type="library" name="Maven: org.hibernate:hibernate-entitymanager:3.5.6-Final" level="project" />
-    <orderEntry type="library" name="Maven: org.hibernate:hibernate-core:3.5.6-Final" level="project" />
-    <orderEntry type="library" name="Maven: antlr:antlr:2.7.6" level="project" />
-    <orderEntry type="library" name="Maven: commons-collections:commons-collections:3.1" level="project" />
-    <orderEntry type="library" name="Maven: javax.transaction:jta:1.1" level="project" />
-    <orderEntry type="library" name="Maven: cglib:cglib:2.2" level="project" />
-    <orderEntry type="library" name="Maven: javassist:javassist:3.9.0.GA" level="project" />
-    <orderEntry type="library" name="Maven: org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.0.Final" level="project" />
-    <orderEntry type="library" name="Maven: org.hibernate:hibernate-annotations:3.5.6-Final" level="project" />
-    <orderEntry type="library" name="Maven: org.hibernate:hibernate-commons-annotations:3.2.0.Final" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework:spring-context-support:4.0.0.RELEASE" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework:spring-context:4.0.0.RELEASE" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework:spring-expression:4.0.0.RELEASE" level="project" />
+    <orderEntry type="library" name="Maven: eu.dnetlib:cnr-rmi-api:2.3.0" level="project" />
+    <orderEntry type="library" name="Maven: org.apache.cxf:cxf-api:2.7.8" level="project" />
+    <orderEntry type="library" name="Maven: org.codehaus.woodstox:woodstox-core-asl:4.2.0" level="project" />
+    <orderEntry type="library" name="Maven: org.codehaus.woodstox:stax2-api:3.1.1" level="project" />
+    <orderEntry type="library" name="Maven: org.apache.ws.xmlschema:xmlschema-core:2.0.3" level="project" />
+    <orderEntry type="library" name="Maven: org.apache.geronimo.specs:geronimo-javamail_1.4_spec:1.7.1" level="project" />
+    <orderEntry type="library" name="Maven: wsdl4j:wsdl4j:1.6.3" level="project" />
     <orderEntry type="library" name="Maven: eu.dnetlib:cnr-misc-utils:1.0.0" level="project" />
     <orderEntry type="library" name="Maven: commons-lang:commons-lang:2.6" level="project" />
     <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.8" level="project" />
@@ -53,17 +44,21 @@
     <orderEntry type="library" name="Maven: jgrapht:jgrapht:0.7.2" level="project" />
     <orderEntry type="library" name="Maven: net.sf.ehcache:ehcache:2.8.0" level="project" />
     <orderEntry type="library" name="Maven: com.google.guava:guava:18.0" level="project" />
-    <orderEntry type="library" name="Maven: eu.dnetlib:cnr-spring-utils:1.0.0" level="project" />
-    <orderEntry type="library" name="Maven: commons-io:commons-io:2.4" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework:spring-aop:4.0.0.RELEASE" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework:spring-web:4.0.0.RELEASE" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework:spring-webmvc:4.0.0.RELEASE" level="project" />
-    <orderEntry type="library" name="Maven: jparsec:jparsec:2.0" level="project" />
-    <orderEntry type="library" name="Maven: org.antlr:stringtemplate:3.2" level="project" />
-    <orderEntry type="library" name="Maven: org.antlr:antlr:2.7.7" level="project" />
-    <orderEntry type="library" name="Maven: runcc:runcc:0.7" level="project" />
-    <orderEntry type="library" name="Maven: commons-dbcp:commons-dbcp:1.4" level="project" />
-    <orderEntry type="library" name="Maven: commons-pool:commons-pool:1.5.4" level="project" />
+    <orderEntry type="library" name="Maven: org.springframework:spring-test:4.0.0.RELEASE" level="project" />
+    <orderEntry type="library" name="Maven: org.springframework:spring-core:4.0.0.RELEASE" level="project" />
+    <orderEntry type="library" name="Maven: commons-logging:commons-logging:1.1.1" level="project" />
+    <orderEntry type="library" name="Maven: eu.dnetlib:uoa-domain:1.2.0-SNAPSHOT" level="project" />
+    <orderEntry type="library" name="Maven: org.hibernate:hibernate-entitymanager:3.5.6-Final" level="project" />
+    <orderEntry type="library" name="Maven: org.hibernate:hibernate-core:3.5.6-Final" level="project" />
+    <orderEntry type="library" name="Maven: antlr:antlr:2.7.6" level="project" />
+    <orderEntry type="library" name="Maven: commons-collections:commons-collections:3.1" level="project" />
+    <orderEntry type="library" name="Maven: javax.transaction:jta:1.1" level="project" />
+    <orderEntry type="library" name="Maven: org.hibernate:hibernate-annotations:3.5.6-Final" level="project" />
+    <orderEntry type="library" name="Maven: org.hibernate:hibernate-commons-annotations:3.2.0.Final" level="project" />
+    <orderEntry type="library" name="Maven: org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.0.Final" level="project" />
+    <orderEntry type="library" name="Maven: cglib:cglib:2.2" level="project" />
+    <orderEntry type="library" name="Maven: asm:asm:3.3.1" level="project" />
+    <orderEntry type="library" name="Maven: javassist:javassist:3.9.0.GA" level="project" />
     <orderEntry type="library" name="Maven: com.google.gwt:gwt-user:2.7.0" level="project" />
     <orderEntry type="library" name="Maven: javax.validation:validation-api:1.0.0.GA" level="project" />
     <orderEntry type="library" name="Maven: javax.validation:validation-api:sources:1.0.0.GA" level="project" />
@@ -74,7 +69,6 @@
     <orderEntry type="library" name="Maven: apache:oro:2.0.8" level="project" />
     <orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-frontend-jaxws:2.7.8" level="project" />
     <orderEntry type="library" name="Maven: xml-resolver:xml-resolver:1.2" level="project" />
-    <orderEntry type="library" name="Maven: asm:asm:3.3.1" level="project" />
     <orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-core:2.7.8" level="project" />
     <orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-bindings-soap:2.7.8" level="project" />
     <orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-databinding-jaxb:2.7.8" level="project" />
@@ -84,45 +78,49 @@
     <orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-ws-addr:2.7.8" level="project" />
     <orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-ws-policy:2.7.8" level="project" />
     <orderEntry type="library" name="Maven: org.apache.neethi:neethi:3.0.2" level="project" />
+    <orderEntry type="library" name="Maven: org.springframework:spring-context:4.0.0.RELEASE" level="project" />
+    <orderEntry type="library" name="Maven: org.springframework:spring-aop:4.0.0.RELEASE" level="project" />
+    <orderEntry type="library" name="Maven: aopalliance:aopalliance:1.0" level="project" />
+    <orderEntry type="library" name="Maven: org.springframework:spring-beans:4.0.0.RELEASE" level="project" />
+    <orderEntry type="library" name="Maven: org.springframework:spring-expression:4.0.0.RELEASE" level="project" />
     <orderEntry type="library" name="Maven: eu.dnetlib:cnr-service-common:1.0.0" level="project" />
+    <orderEntry type="library" name="Maven: org.antlr:stringtemplate:3.2" level="project" />
+    <orderEntry type="library" name="Maven: org.antlr:antlr:2.7.7" level="project" />
     <orderEntry type="library" name="Maven: opensymphony:quartz:1.6.6" level="project" />
+    <orderEntry type="library" name="Maven: org.springframework:spring-tx:4.0.0.RELEASE" level="project" />
+    <orderEntry type="library" name="Maven: eu.dnetlib:cnr-spring-utils:1.0.0" level="project" />
+    <orderEntry type="library" name="Maven: commons-io:commons-io:2.4" level="project" />
+    <orderEntry type="library" name="Maven: org.springframework:spring-web:4.0.0.RELEASE" level="project" />
+    <orderEntry type="library" name="Maven: org.springframework:spring-webmvc:4.0.0.RELEASE" level="project" />
+    <orderEntry type="library" name="Maven: jparsec:jparsec:2.0" level="project" />
+    <orderEntry type="library" name="Maven: runcc:runcc:0.7" level="project" />
+    <orderEntry type="library" name="Maven: org.springframework:spring-context-support:4.0.0.RELEASE" level="project" />
+    <orderEntry type="library" name="Maven: commons-dbcp:commons-dbcp:1.4" level="project" />
+    <orderEntry type="library" name="Maven: commons-pool:commons-pool:1.5.4" level="project" />
     <orderEntry type="library" name="Maven: eu.dnetlib:uoa-clients:1.2.0-SNAPSHOT" level="project" />
-    <orderEntry type="library" name="Maven: eu.dnetlib:cnr-rmi-api:2.3.0" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.cxf:cxf-api:2.7.8" level="project" />
-    <orderEntry type="library" name="Maven: org.codehaus.woodstox:woodstox-core-asl:4.2.0" level="project" />
-    <orderEntry type="library" name="Maven: org.codehaus.woodstox:stax2-api:3.1.1" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.ws.xmlschema:xmlschema-core:2.0.3" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.geronimo.specs:geronimo-javamail_1.4_spec:1.7.1" level="project" />
-    <orderEntry type="library" name="Maven: wsdl4j:wsdl4j:1.6.3" level="project" />
     <orderEntry type="library" name="Maven: eu.dnetlib:dnet-datasource-manager-rmi:4.0.0" level="project" />
     <orderEntry type="library" name="Maven: eu.dnetlib:cnr-enabling-database-api:1.0.0" level="project" />
     <orderEntry type="library" name="Maven: eu.dnetlib:dnet-index-client:1.1.0" level="project" />
+    <orderEntry type="library" name="Maven: com.google.code.gson:gson:2.4" level="project" />
     <orderEntry type="library" name="Maven: com.mycila:xmltool:3.3" level="project" />
-    <orderEntry type="library" name="Maven: eu.dnetlib:cnr-cql-utils:1.0.2-SNAPSHOT" level="project" />
+    <orderEntry type="library" name="Maven: eu.dnetlib:cnr-cql-utils:1.0.1" level="project" />
     <orderEntry type="library" name="Maven: org.apache.lucene:lucene-queryparser:4.9.0" level="project" />
     <orderEntry type="library" name="Maven: org.apache.lucene:lucene-core:4.9.0" level="project" />
     <orderEntry type="library" name="Maven: org.apache.lucene:lucene-queries:4.9.0" level="project" />
     <orderEntry type="library" name="Maven: org.apache.lucene:lucene-sandbox:4.9.0" level="project" />
     <orderEntry type="library" name="Maven: org.z3950.zing:cql-java:1.7" level="project" />
-    <orderEntry type="library" name="Maven: eu.dnetlib:dnet-data-provision-rmi:1.0.1-SNAPSHOT" level="project" />
+    <orderEntry type="library" name="Maven: eu.dnetlib:dnet-data-provision-rmi:1.0.0" level="project" />
     <orderEntry type="library" name="Maven: org.apache.ant:ant:1.8.2" level="project" />
     <orderEntry type="library" name="Maven: org.apache.ant:ant-launcher:1.8.2" level="project" />
     <orderEntry type="library" name="Maven: org.springframework:spring-jdbc:4.0.0.RELEASE" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework:spring-beans:4.0.0.RELEASE" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework:spring-core:4.0.0.RELEASE" level="project" />
-    <orderEntry type="library" name="Maven: commons-logging:commons-logging:1.1.1" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework:spring-tx:4.0.0.RELEASE" level="project" />
-    <orderEntry type="library" name="Maven: aopalliance:aopalliance:1.0" level="project" />
     <orderEntry type="library" scope="TEST" name="Maven: org.mockito:mockito-core:1.9.5" level="project" />
-    <orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
+    <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
     <orderEntry type="library" scope="TEST" name="Maven: org.objenesis:objenesis:1.0" level="project" />
-    <orderEntry type="library" name="Maven: eu.dnetlib:cnr-blackboard-common:1.0.1-SNAPSHOT" level="project" />
-    <orderEntry type="library" name="Maven: eu.dnetlib:cnr-notifications-common:1.1.1-SNAPSHOT" level="project" />
+    <orderEntry type="library" name="Maven: eu.dnetlib:cnr-blackboard-common:1.0.0" level="project" />
+    <orderEntry type="library" name="Maven: eu.dnetlib:cnr-notifications-common:1.1.0" level="project" />
     <orderEntry type="library" name="Maven: postgresql:postgresql:9.1-901.jdbc4" level="project" />
-    <orderEntry type="library" name="Maven: com.google.code.gson:gson:2.4" level="project" />
     <orderEntry type="library" name="Maven: javax.mail:mail:1.4" level="project" />
     <orderEntry type="library" name="Maven: javax.activation:activation:1.1" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework:spring-test:4.0.0.RELEASE" level="project" />
-    <orderEntry type="library" name="Maven: log4j:log4j:1.2.17" level="project" />
   </component>
-</module>
\ No newline at end of file
+</module>
+
Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/handler/ProjectHandler.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/handler/ProjectHandler.java	(revision 41790)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/handler/ProjectHandler.java	(revision 41791)
@@ -1,6 +1,6 @@
 package eu.dnetlib.data.claims.migration.handler;
 
-import eu.dnetlib.data.claims.migration.Project;
+import eu.dnetlib.data.claims.migration.entity.Project;
 import eu.dnetlib.data.claims.migration.parser.OafParser;
 import eu.dnetlib.data.claimsDemo.QueryGenerator;
 import eu.dnetlib.data.claimsDemo.SearchUtils;
@@ -26,12 +26,12 @@
     public Project fetchProjectByOaf(String oaf) throws Exception {
         return oafParser.oaf2Project(oaf);
     }
-    public String generateSaveQueryForProject(Project project){
+/*    public String generateSaveQueryForProject(Project project){
         return queryGenerator.generateInsertProjectQuery(project.getOpenaireId(),project.getName(),project.getAcronym(),project.getFunderId(),project.getFunderName(),project.getFunderShortName());
     }
     public void saveProject(Project project) throws Exception {
         sqlDAO.executePreparedQuery(generateSaveQueryForProject(project));
-    }
+    }*/
     public OafParser getOafParser() {
         return oafParser;
     }
Index: modules/uoa-claims -demo/claims-demo/src/test/java/eu/dnetlib/data/claims/migration/parser/ExternalParserTest.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/test/java/eu/dnetlib/data/claims/migration/parser/ExternalParserTest.java	(revision 41790)
+++ modules/uoa-claims -demo/claims-demo/src/test/java/eu/dnetlib/data/claims/migration/parser/ExternalParserTest.java	(revision 41791)
@@ -1,6 +1,6 @@
 package eu.dnetlib.data.claims.migration.parser;
 
-import eu.dnetlib.data.claims.migration.Result;
+import eu.dnetlib.data.claims.migration.entity.Result;
 import eu.dnetlib.data.claimsDemo.ClaimUtils;
 import org.junit.Assert;
 import org.junit.Test;
Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/handler/RelationHandler.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/handler/RelationHandler.java	(revision 41790)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/handler/RelationHandler.java	(revision 41791)
@@ -1,6 +1,6 @@
 package eu.dnetlib.data.claims.migration.handler;
 
-import eu.dnetlib.data.claims.migration.Relation;
+import eu.dnetlib.data.claims.migration.entity.Relation;
 import eu.dnetlib.data.claims.migration.parser.RelationParser;
 import eu.dnetlib.data.claimsDemo.QueryGenerator;
 import eu.dnetlib.data.claimsDemo.SqlDAO;
@@ -20,7 +20,7 @@
 
     public List<Relation> fetchAllRelations() throws Exception {
         List<Relation> relations = null;
-        ResultSet rs = sqlDAO.executePreparedQuery(queryGenerator.generateSelectRelationEnrichedWithDMFClaimsQuery(-1));
+        ResultSet rs = sqlDAO.executePreparedQuery(queryGenerator.generateSelectRelationEnrichedWithDMFClaimsQuery(50));
 //        ResultSet rs = sqlDAO.executePreparedQuery(queryGenerator.generateSelectRelationClaimByIDEnrichedWithDMFClaimsQuery(-1,"169590"));
         relations = new ArrayList<Relation>();
 
Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/handler/FetchClaimHandler.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/handler/FetchClaimHandler.java	(nonexistent)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/handler/FetchClaimHandler.java	(revision 41791)
@@ -0,0 +1,136 @@
+package eu.dnetlib.data.claims.migration.handler;
+
+import eu.dnetlib.data.claims.migration.JsonldBuilder;
+import eu.dnetlib.data.claims.migration.entity.*;
+import eu.dnetlib.data.claimsDemo.ClaimUtils;
+import eu.dnetlib.data.claimsDemo.QueryGenerator;
+import eu.dnetlib.data.claimsDemo.SqlDAO;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * Created by argirok on 9/3/2016.
+ */
+public class FetchClaimHandler {
+
+    SqlDAO sqlDAO = null;
+
+    public FetchClaimHandler(){
+//        ApplicationContext context = new ClassPathXmlApplicationContext("eu/dnetlib/data/claims/migration/springContext-claimsDemo.xml");
+//        sqlDAO = context.getBean(SqlDAO.class);
+
+    }
+    public String claims2JSON(List<Claim> claims) throws Exception {
+        return JsonldBuilder.toJsonld(claims);
+    }
+
+    public List<Claim> fetchClaimsByUser(String user) throws Exception {
+        ResultSet rs = sqlDAO.executePreparedQuery(QueryGenerator.generateFetchClaimsByUser(user));
+        return fetchClaimsByResultSet(rs);
+    }
+
+    public List<Claim> fetchClaimsByDate(String dateFrom, String dataTo) throws Exception {
+        ResultSet rs = sqlDAO.executePreparedQuery(QueryGenerator.generateFetchClaimsByDate(dateFrom, dataTo));
+        return fetchClaimsByResultSet(rs);
+    }
+    public List<Claim> fetchClaimsByProject(String openaireId) throws Exception {
+        ResultSet rs = sqlDAO.executePreparedQuery(QueryGenerator.generateFetchClaimsByProject(openaireId));
+        return fetchClaimsByResultSet(rs);
+    }
+    public List<Claim> fetchClaimsByFunder(String openaireId) throws Exception {
+        ResultSet rs = sqlDAO.executePreparedQuery(QueryGenerator.generateFetchClaimsByFunder(openaireId));
+        return fetchClaimsByResultSet(rs);
+    }
+    public List<Claim> fetchClaimsByResult(String openaireId) throws Exception {
+        ResultSet rs = sqlDAO.executePreparedQuery(QueryGenerator.generateFetchClaimsByResult(openaireId));
+        return fetchClaimsByResultSet(rs);
+    }
+    public List<Claim> fetchClaimsByResultSet(ResultSet rs) throws Exception {
+        List<Claim> claims= new ArrayList<Claim>();
+        while(rs.next()) {
+            Claim claim= new Claim();
+            claims.add(claim);
+            claim.setId(rs.getString(1));
+            claim.setDate(new Date());
+            claim.setUserMail(rs.getString(3));
+            claim.setSourceType(rs.getString(4));
+            claim.setTargetType(rs.getString(5));
+            claim.setSemantics(rs.getString(6));
+            claim.setSource(buildEntity(rs,7,claim.getSourceType()));
+            claim.setTarget(buildEntity(rs,17,claim.getTargetType()));
+
+        }
+        return claims;
+    }
+
+    /**
+     *
+     * @param rs
+     * @param index
+     * @return
+     * @throws SQLException
+     */
+    private static Result buildResult(ResultSet rs, Integer index) throws SQLException {
+        Result result = new Result();
+        result.setOpenaireId(rs.getString(index));
+        result.setTitle(rs.getString(index + 1));
+        result.setResultType(rs.getString(index + 2));
+        result.setDoi(rs.getString(index + 3));
+        result.setOrcidworkid(rs.getString(index + 4));
+        result.setAccessRights(rs.getString(index + 5));
+        result.setEmbargoEndDate(rs.getString(index + 6));
+        result.setBestLicense(rs.getString(index + 7));
+        result.setExternalUrl(rs.getString(index + 8));
+        result.setCollectedFrom(rs.getString(index + 9));
+        return result;
+
+    }
+    private static Project buildProject(ResultSet rs, Integer index) throws SQLException {
+        Project project = new Project();
+        project.setOpenaireId(rs.getString(index));
+        project.setName(rs.getString(index + 1));
+        project.setAcronym(rs.getString(index + 2));
+        project.setFunderId(rs.getString(index + 3));
+        project.setFunderName(rs.getString(index + 4));
+        project.setFunderShortName(rs.getString(index + 5));
+        return project;
+
+    }
+    private static Context buildContext(ResultSet rs, Integer index) throws SQLException {
+        Context context = new Context();
+        context.setOpenaireId(rs.getString(index));
+        context.setTitle(rs.getString(index + 1));
+        return context;
+
+    }
+    private static OpenaireEntity buildEntity(ResultSet rs, Integer index, String type) throws SQLException {
+        OpenaireEntity openaireEntity = null;
+        if(type == null){
+            openaireEntity = null;
+        }else if(type.equals(ClaimUtils.PUBLICATION)||type.equals(ClaimUtils.DATASET)) {
+            openaireEntity= buildResult(rs, index);
+        }else if(type.equals(ClaimUtils.PROJECT)){
+            openaireEntity = buildProject(rs,index);
+        }else if(type.equals(ClaimUtils.CONTEXT)){
+            openaireEntity = buildContext(rs,index);
+        }
+        return openaireEntity;
+    }
+
+    public SqlDAO getSqlDAO() {
+        return sqlDAO;
+    }
+
+    public void setSqlDAO(SqlDAO sqlDAO) {
+        this.sqlDAO = sqlDAO;
+    }
+
+
+
+}
Index: modules/uoa-claims -demo/claims-demo/src/test/java/eu/dnetlib/data/claims/migration/parser/OafParserTest.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/test/java/eu/dnetlib/data/claims/migration/parser/OafParserTest.java	(revision 41790)
+++ modules/uoa-claims -demo/claims-demo/src/test/java/eu/dnetlib/data/claims/migration/parser/OafParserTest.java	(revision 41791)
@@ -1,8 +1,8 @@
 package eu.dnetlib.data.claims.migration.parser;
 
-import eu.dnetlib.data.claims.migration.Result;
+import eu.dnetlib.data.claims.migration.entity.Result;
 import eu.dnetlib.data.claimsDemo.ClaimUtils;
-import eu.dnetlib.data.claims.migration.Project;
+import eu.dnetlib.data.claims.migration.entity.Project;
 import org.junit.Assert;
 import org.junit.Test;
 import org.xml.sax.SAXException;
@@ -55,9 +55,25 @@
             "                       schemename=\"dnet:pid_types\">orcidworkid_test</pid>\n" +
     "                  <bestlicense classid=\"EMBARGO\" classname=\"Open Access\" schemeid=\"dnet:access_modes\"\n" +
             "                               schemename=\"dnet:access_modes\"/>\n" +
+//            "\t\t                <children>\n" +
+//            "\t\t\t                  <instance id=\"opendoar____::c0f971d8cd24364f2029fcb9ac7b71f5\">\n" +
+//            "\t\t\t                     <licence classid=\"EMBARGO\" classname=\"Open Access\" schemeid=\"dnet:access_modes\"\n" +
+//            "                                 schemename=\"dnet:access_modes\"/>\n" +
+//            "                        <instancetype classid=\"0001\" classname=\"Article\" schemeid=\"dnet:publication_resource\"\n" +
+//            "                                      schemename=\"dnet:publication_resource\"/>\n" +
+//            "                        <hostedby name=\"CyberLeninka - Russian open access scientific library\"\n" +
+//            "                                  id=\"opendoar____::c0f971d8cd24364f2029fcb9ac7b71f5\"/>\n" +
+//            "\t\t\t\t                    <webresource>\n" +
+//            "\t\t\t\t                       <url>http://cyberleninka.ru/article/n/postkonversionnaya-asistoliya-zheludochkov-serdtsa-u-bolnyh-infarktom-miokarda-i-vozmozhnosti-ee-profilaktiki</url>\n" +
+//            "\t\t\t\t                    </webresource>\n" +
+//            "\t\t\t\t                    <webresource>\n" +
+//            "\t\t\t\t                       <url>http://cyberleninka.ru/article_covers/5969541.png</url>\n" +
+//            "\t\t\t\t                    </webresource>\n" +
+//            "\t\t\t                  </instance>\n" +
+//            "\t\t                </children>\n" +
             "\t\t                <children>\n" +
             "\t\t\t                  <instance id=\"opendoar____::c0f971d8cd24364f2029fcb9ac7b71f5\">\n" +
-            "\t\t\t                     <licence classid=\"EMBARGO\" classname=\"Open Access\" schemeid=\"dnet:access_modes\"\n" +
+            "\t\t\t                     <licence classid=\"CLOSED\" classname=\"Open Access\" schemeid=\"dnet:access_modes\"\n" +
             "                                 schemename=\"dnet:access_modes\"/>\n" +
             "                        <instancetype classid=\"0001\" classname=\"Article\" schemeid=\"dnet:publication_resource\"\n" +
             "                                      schemename=\"dnet:publication_resource\"/>\n" +
@@ -64,7 +80,7 @@
             "                        <hostedby name=\"CyberLeninka - Russian open access scientific library\"\n" +
             "                                  id=\"opendoar____::c0f971d8cd24364f2029fcb9ac7b71f5\"/>\n" +
             "\t\t\t\t                    <webresource>\n" +
-            "\t\t\t\t                       <url>http://cyberleninka.ru/article/n/postkonversionnaya-asistoliya-zheludochkov-serdtsa-u-bolnyh-infarktom-miokarda-i-vozmozhnosti-ee-profilaktiki</url>\n" +
+            "\t\t\t\t                       <url>h CLOSED_ACCESS_URL</url>\n" +
             "\t\t\t\t                    </webresource>\n" +
             "\t\t\t\t                    <webresource>\n" +
             "\t\t\t\t                       <url>http://cyberleninka.ru/article_covers/5969541.png</url>\n" +
@@ -84,6 +100,7 @@
     @Test
     public void oaf2PublicationTest() throws Exception, ParserConfigurationException, SAXException, XPathExpressionException, IOException, TransformerException {
         Result result = OafParser.oaf2Result(publicationOaf);
+        System.out.println(result.getExternalUrl());
         Assert.assertNull(result.getAccessRights());
         Assert.assertEquals("EMBARGO",result.getBestLicense());
         Assert.assertEquals("infrastruct_::openaire", result.getCollectedFrom());
Index: modules/uoa-claims -demo/claims-demo/src/test/java/eu/dnetlib/data/claims/migration/parser/DMFParserTest.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/test/java/eu/dnetlib/data/claims/migration/parser/DMFParserTest.java	(revision 41790)
+++ modules/uoa-claims -demo/claims-demo/src/test/java/eu/dnetlib/data/claims/migration/parser/DMFParserTest.java	(revision 41791)
@@ -1,12 +1,14 @@
 package eu.dnetlib.data.claims.migration.parser;
 
-import eu.dnetlib.data.claims.migration.Context;
-import eu.dnetlib.data.claims.migration.Result;
+import eu.dnetlib.data.claims.migration.entity.Context;
+import eu.dnetlib.data.claims.migration.entity.Result;
+import eu.dnetlib.data.claims.migration.handler.DMFContextHandler;
 import org.junit.Assert;
 import org.junit.Test;
 import org.xml.sax.SAXException;
 
 import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.xpath.XPathExpressionException;
 import java.io.IOException;
 
 /**
@@ -96,8 +98,9 @@
             "</record>";
 
     @Test
-    public void dmf2ContextTest() throws IOException, SAXException, ParserConfigurationException {
-        Context context = DMFParser.dmf2Context(contextDmf);
+    public void dmf2ContextTest() throws IOException, SAXException, ParserConfigurationException, XPathExpressionException {
+        DMFParser dmfParser= new DMFParser();
+        Context context = DMFContextHandler.fetchContextById(contextDmf);
 
         Assert.assertEquals("egi::country::gr", context.getOpenaireId());
         Assert.assertEquals("EGI> EGI Countries> Greece", context.getTitle());
Index: modules/uoa-claims -demo/claims-demo/src/test/java/eu/dnetlib/data/claims/migration/parser/RelationParserTest.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/test/java/eu/dnetlib/data/claims/migration/parser/RelationParserTest.java	(revision 41790)
+++ modules/uoa-claims -demo/claims-demo/src/test/java/eu/dnetlib/data/claims/migration/parser/RelationParserTest.java	(revision 41791)
@@ -1,6 +1,6 @@
 package eu.dnetlib.data.claims.migration.parser;
 
-import eu.dnetlib.data.claims.migration.Relation;
+import eu.dnetlib.data.claims.migration.entity.Relation;
 import eu.dnetlib.data.claimsDemo.ClaimUtils;
 import org.junit.Assert;
 import org.junit.Test;
Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/Test.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/Test.java	(revision 41790)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/Test.java	(revision 41791)
@@ -1,5 +1,8 @@
 package eu.dnetlib.data.claims.migration;
 
+import eu.dnetlib.data.claims.migration.entity.Project;
+import eu.dnetlib.data.claims.migration.entity.Result;
+
 import java.util.Calendar;
 
 public class Test {
Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/ClaimValidation.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/ClaimValidation.java	(revision 41790)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/ClaimValidation.java	(revision 41791)
@@ -1,14 +1,16 @@
 package eu.dnetlib.data.claims.migration;
 
+import eu.dnetlib.data.claims.migration.entity.Claim;
+import eu.dnetlib.data.claims.migration.entity.Context;
+import eu.dnetlib.data.claims.migration.entity.OpenaireEntity;
+import eu.dnetlib.data.claims.migration.entity.Project;
+import eu.dnetlib.data.claims.migration.entity.Result;
 import eu.dnetlib.data.claimsDemo.ClaimUtils;
-import eu.dnetlib.data.claimsDemo.SearchUtils;
 
 import java.io.BufferedWriter;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.PrintWriter;
-import java.sql.Timestamp;
-import java.util.Date;
 
 /**
  * Created by argirok on 21/1/2016.
Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/JsonldBuilder.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/JsonldBuilder.java	(revision 41790)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/JsonldBuilder.java	(revision 41791)
@@ -2,8 +2,8 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
+import eu.dnetlib.data.claims.migration.entity.Claim;
+import eu.dnetlib.data.claims.migration.entity.Result;
 import org.springframework.web.client.RestTemplate;
 
 import com.google.gson.Gson;
@@ -16,7 +16,7 @@
 		
 		String retString = gson.toJson(claim);
 		
-	/*	final String uri = "http://localhost:9090/oa/insertClaim";
+	/*	final String uri = "http://localhost:9090/oa/buildAndInsertClaim";
 		 
 	 
 	    RestTemplate restTemplate = new RestTemplate();
@@ -36,6 +36,16 @@
         String retString = gson.toJson(claim);
         return retString;
     }
+    public static String toJsonld(List<Claim> claims) {
+
+        GsonBuilder gsonBuilder = new GsonBuilder();
+        gsonBuilder.setPrettyPrinting();
+        gsonBuilder.setDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
+        Gson gson =gsonBuilder.create();
+
+         String retString = gson.toJson(claims);
+        return retString;
+    }
 	public static void bulkLoad(List<String> claims) {
 		
 		final String uri = "http://localhost:9090/oa/insertClaim";
Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claimsDemo/TestClass.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claimsDemo/TestClass.java	(revision 41790)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claimsDemo/TestClass.java	(revision 41791)
@@ -5,12 +5,18 @@
  */
 
 
-//import eu.dnetlib.data.claims.migration.Claim;
 
-import eu.dnetlib.data.claims.migration.*;
+
+import eu.dnetlib.data.claims.migration.ClaimValidation;
+import eu.dnetlib.data.claims.migration.JsonldBuilder;
+import eu.dnetlib.data.claims.migration.Migration;
+import eu.dnetlib.data.claims.migration.entity.Claim;
+import eu.dnetlib.data.claims.migration.entity.Context;
+import eu.dnetlib.data.claims.migration.entity.OpenaireEntity;
+import eu.dnetlib.data.claims.migration.entity.Project;
+import eu.dnetlib.data.claims.migration.entity.Result;
 import eu.dnetlib.data.claims.migration.handler.*;
 import eu.dnetlib.data.claims.migration.parser.DMFParser;
-import eu.dnetlib.data.claims.migration.parser.OafParser;
 import org.apache.log4j.BasicConfigurator;
 import org.apache.log4j.Logger;
 import org.junit.Before;
@@ -28,6 +34,12 @@
 import javax.xml.xpath.XPathExpressionException;
 import java.io.IOException;
 import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
 
 import static junit.framework.Assert.assertNotNull;
 
@@ -41,10 +53,8 @@
 	private Logger log = Logger.getLogger(this.getClass());
 
 
-    @Autowired
 	private SqlDAO sqlDAO;
 
-    @Autowired
     private QueryGenerator queryGenerator;
 
     RelationHandler relationHandler = null;
@@ -56,6 +66,7 @@
     ExternalRecordHandler externalRecordHandler = null;
     ResultHandler resultHandler = null;
 
+    FetchClaimHandler fetchClaimHandler = null;
     ClaimHandler claimHandler = null;
     ClaimValidation claimValidation = new ClaimValidation();
 
@@ -63,7 +74,6 @@
     @Before
 	public void init() throws Exception {
 		BasicConfigurator.configure();
-		assertNotNull(sqlDAO);
         ApplicationContext context = new ClassPathXmlApplicationContext("eu/dnetlib/data/claims/migration/springContext-claimsDemo.xml");
         relationHandler = context.getBean(RelationHandler.class);
         contextRelationHandler = context.getBean(ContextRelationHandler.class);
@@ -74,24 +84,97 @@
         indexResultHandler = context.getBean(IndexResultHandler.class);
         resultHandler = context.getBean(ResultHandler.class);
         claimHandler = context.getBean(ClaimHandler.class);
+        sqlDAO = context.getBean(SqlDAO.class);
+        queryGenerator = context.getBean(QueryGenerator.class);
+        fetchClaimHandler = context.getBean(FetchClaimHandler.class);
 
+
+        assertNotNull(sqlDAO);
+
 	}
+    @Test
+    public void testJson(){
+        Claim claim = new Claim();
+        Project project= new Project();
+        claim.setDate(Calendar.getInstance().getTime());
+        claim.setId("claimId");
+        claim.setUserMail("claim mail");
 
+        project.setFunderName("EC");
+        project.setOpenaireId("openaireID1234");
+        project.setName("PrTitle");
+        claim.setSource(project);
+        Result result = new Result();
+        result.setAccessRights("accessRights");
+        result.setCollectedFrom("collectedFrom");
+        result.setExternalUrl("external_url");
+        result.setOpenaireId("openaire_id");
+        result.setTitle("title");
+        result.setResultType("type");
+        result.setMetadataRecord("xmlString");
+        claim.setTarget(result);
+        System.out.println("test");
+        System.out.println(JsonldBuilder.toJsonld(claim));
+    }
 
-	@Test
+    @Test
+    public void testFetch() throws Exception {
+
+        try {
+            List<Claim> claims = null;
+//            claims = claimFetcher.getFetchClaimHandler().fetchClaimsByUser("i.fava@cineca.it");
+
+            claims = fetchClaimHandler.fetchClaimsByProject("corda_______::ab9c77ce02967b24fc9c1a74276e4677");
+//            claims = claimFetcher.getFetchClaimHandler().fetchClaimsByFunder("fct_________::FCT");
+//            claims = fetchClaimHandler.fetchClaimsByResult("dedup_wf_001::541b1cef0d38d519e98a3b7a5b60bc75");
+            System.out.println(fetchClaimHandler.claims2JSON(claims));
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+    @Test
+    public void testInsert() throws Exception {
+        //String user, String date, String sourceType, String sourceId, String sourceCollectedFrom, String targetType, String targetId, String targetCollectedFrom) throws Exception {
+//acm_________::31e0e5e7cbd6e2556336d7e795f55c49
+//dedup_wf_001::64ca1e3a4d1590456ad3dd7df8a18cd7
+        claimHandler.buildAndInsertClaim("argirok@di.uoa.gr",new Date(), "context","corda_______::c0f1e1b0fcf3dfa9eb043ef9a90ae384",null,"publication","acm_________::31e0e5e7cbd6e2556336d7e795f55c49","openaire");
+    }
+    @Test
+    public void testDelete() throws Exception {
+        //String user, String date, String sourceType, String sourceId, String sourceCollectedFrom, String targetType, String targetId, String targetCollectedFrom) throws Exception {
+//acm_________::31e0e5e7cbd6e2556336d7e795f55c49
+//dedup_wf_001::64ca1e3a4d1590456ad3dd7df8a18cd7
+        claimHandler.buildAndInsertClaim("argirok@di.uoa.gr",new Date(), "project","corda_______::c0f1e1b0fcf3dfa9eb043ef9a90ae384",null,"publication","acm_________::31e0e5e7cbd6e2556336d7e795f55c49","openaire");
+    }
+
+    @Test
 	public void testJob() throws Exception {
+        String selectcountDMFClaims =" Select count(*) from claims_view  where type='dmf2actions' and xml NOT ILIKE '%<oaf:concept%' ";
+        String selectCountConceptClaims =" Select count(*) from claims_view  where ( type='dmf2actions' or type='updates2actions' ) and xml LIKE '%<oaf:concept%' ";
+        String selectCountRelationClaims =" Select count(*) from claims_view  where type='rels2actions'  ";
 
-        ResultSet rs = sqlDAO.executePreparedQuery(queryGenerator.generateSelectCountConceptClaimsQuery(-1));
+        ResultSet rs = sqlDAO.executePreparedQuery(selectCountConceptClaims);
 
         while(rs.next()) {
             log.info("Concept claims: "+rs.getInt(1));
         }
-         rs = sqlDAO.executePreparedQuery(queryGenerator.generateSelectCountRelationClaimsQuery(-1));
+         rs = sqlDAO.executePreparedQuery(selectCountRelationClaims);
 
         while(rs.next()) {
             log.info("Relation claims: "+rs.getInt(1));
         }
+         rs = sqlDAO.executePreparedQuery("Select count(*) from claim");
 
+        while(rs.next()) {
+            log.info("Migrated claims: "+rs.getInt(1));
+        }
+        rs = sqlDAO.executePreparedQuery("Select count(*) from result");
+
+        while(rs.next()) {
+            log.info("Results: "+rs.getInt(1));
+        }
+
 	}
 
     @Test
Index: modules/uoa-claims -demo/claims-demo/src/main/resources/eu/dnetlib/data/claims/migration/springContext-claimsDemo.xml
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/resources/eu/dnetlib/data/claims/migration/springContext-claimsDemo.xml	(revision 41790)
+++ modules/uoa-claims -demo/claims-demo/src/main/resources/eu/dnetlib/data/claims/migration/springContext-claimsDemo.xml	(revision 41791)
@@ -26,7 +26,9 @@
 
 
     <!--Handlers -->
-
+    <bean id="fetchClaimHandler" class="eu.dnetlib.data.claims.migration.handler.FetchClaimHandler">
+        <property name="sqlDAO" ref="sqlDao"/>
+    </bean>
     <bean id="claimHandler" class="eu.dnetlib.data.claims.migration.handler.ClaimHandler">
         <property name="sqlDAO" ref="sqlDao"/>
         <property name="queryGenerator" ref="queryGenerator"/>
Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/ClaimFetcher.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/ClaimFetcher.java	(nonexistent)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/ClaimFetcher.java	(revision 41791)
@@ -0,0 +1,54 @@
+package eu.dnetlib.data.claims.migration;
+
+import eu.dnetlib.data.claims.migration.entity.Claim;
+
+import eu.dnetlib.data.claims.migration.handler.FetchClaimHandler;
+
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import java.sql.ResultSet;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+* Created by argirok on 9/3/2016.
+*/
+public class ClaimFetcher {
+    private FetchClaimHandler fetchClaimHandler = null;
+
+
+    public ClaimFetcher(){
+        ApplicationContext context = new ClassPathXmlApplicationContext("eu/dnetlib/data/claims/migration/springContext-claimsDemo.xml");
+        fetchClaimHandler = context.getBean(FetchClaimHandler.class);
+
+    }
+
+
+
+    public FetchClaimHandler getFetchClaimHandler() {
+        return fetchClaimHandler;
+    }
+
+    public void setFetchClaimHandler(FetchClaimHandler fetchClaimHandler) {
+        this.fetchClaimHandler = fetchClaimHandler;
+    }
+
+    public static void main(String[] args) {
+
+        ClaimFetcher claimFetcher = new ClaimFetcher();
+
+        try {
+            List<Claim> claims = null;
+//            claims = claimFetcher.getFetchClaimHandler().fetchClaimsByUser("i.fava@cineca.it");
+
+//            claims = claimFetcher.getFetchClaimHandler().fetchClaimsByProject("corda_______::ab9c77ce02967b24fc9c1a74276e4677");
+//            claims = claimFetcher.getFetchClaimHandler().fetchClaimsByFunder("fct_________::FCT");
+            claims = claimFetcher.getFetchClaimHandler().fetchClaimsByResult("dedup_wf_001::541b1cef0d38d519e98a3b7a5b60bc75");
+            System.out.println(claimFetcher.getFetchClaimHandler().claims2JSON(claims));
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}
Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/Migration.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/Migration.java	(revision 41790)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/Migration.java	(revision 41791)
@@ -1,8 +1,8 @@
 package eu.dnetlib.data.claims.migration;
 
+import eu.dnetlib.data.claims.migration.entity.*;
 import eu.dnetlib.data.claims.migration.handler.*;
 import eu.dnetlib.data.claimsDemo.ClaimUtils;
-import org.apache.commons.io.FileUtils;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
@@ -65,7 +65,7 @@
                 source= buildProject(relation.getSourceId(),relation.getClaimId());
                 claim.setSourceType(ClaimUtils.PROJECT);
             } else if (relation.getSourceType().equals(ClaimUtils.CONTEXT)) {
-                Context context = dmfContextHandler.fetchContextById(relation.getSourceId());
+                Context context = dmfContextHandler.fetchContextByIdFromDmf(relation.getSourceId());
                 source = context;
                 claim.setSourceType(ClaimUtils.CONTEXT);
             } else if (relation.getSourceType().equals(ClaimUtils.DATASET) || relation.getSourceType().equals(ClaimUtils.PUBLICATION)) {
@@ -331,7 +331,7 @@
      */
     private void saveClaims(List<Claim> claims) throws Exception {
         for(Claim claim : claims){
-            if(claim.getTargetType().equals(ClaimUtils.DATASET)||claim.getTargetType().equals(ClaimUtils.PUBLICATION)){
+           /* if(claim.getTargetType().equals(ClaimUtils.DATASET)||claim.getTargetType().equals(ClaimUtils.PUBLICATION)){
                 String path = resultHandler.exportMetadataFileForResult((Result)claim.getTarget());
                 ((Result) claim.getTarget()).setRecordPath(path);
             }
@@ -338,12 +338,15 @@
             if(claim.getSourceType().equals(ClaimUtils.DATASET)||claim.getSourceType().equals(ClaimUtils.PUBLICATION)){
                 String path = resultHandler.exportMetadataFileForResult((Result)claim.getSource());
                 ((Result) claim.getSource()).setRecordPath(path);
-            }
+            }*/
+            claim = claimHandler.exportMedatataForClaim(claim);
             claimHandler.saveClaim(claim);
         }
 
     }
 
+
+
     public static void main(String[] args) {
 
         Migration migration = new Migration();
@@ -350,8 +353,8 @@
         try {
 
             List<Claim> claims = null;
-            claims = migration.createContextRelationClaims();
-//            claims = migration.createRelationsClaims();
+//            claims = migration.createContextRelationClaims();
+            claims = migration.createRelationsClaims();
 
             migration.printStatistics(claims);
             migration.saveClaims(claims);
Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/entity/OpenaireEntity.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/entity/OpenaireEntity.java	(nonexistent)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/entity/OpenaireEntity.java	(revision 41791)
@@ -0,0 +1,8 @@
+package eu.dnetlib.data.claims.migration.entity;
+/**
+ * Created by argirok on 10/12/2015.
+ */
+public interface OpenaireEntity {
+    public String getOpenaireId();
+
+}
Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/entity/ContextRelation.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/entity/ContextRelation.java	(nonexistent)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/entity/ContextRelation.java	(revision 41791)
@@ -0,0 +1,95 @@
+package eu.dnetlib.data.claims.migration.entity;
+
+import java.util.Date;
+
+/**
+ * Created by argirok on 10/2/2016.
+ */
+public class ContextRelation {
+
+    private String claimId = null;
+    private String contextId = null;
+
+    private String resultId = null;
+
+    private boolean hasDMF = false;
+    private String resultDmf = null;
+    private String contextDmf = null;
+
+
+    private String collectedFrom = null;
+    private String claimedBy = null;
+    private Date claimDate = null;
+
+    public String getClaimId() {
+        return claimId;
+    }
+
+    public void setClaimId(String claimId) {
+        this.claimId = claimId;
+    }
+
+    public String getContextId() {
+        return contextId;
+    }
+
+    public void setContextId(String contextId) {
+        this.contextId = contextId;
+    }
+
+    public String getResultId() {
+        return resultId;
+    }
+
+    public void setResultId(String resultId) {
+        this.resultId = resultId;
+    }
+
+    public boolean isHasDMF() {
+        return hasDMF;
+    }
+
+    public void setHasDMF(boolean hasDMF) {
+        this.hasDMF = hasDMF;
+    }
+
+    public String getResultDmf() {
+        return resultDmf;
+    }
+
+    public void setResultDmf(String resultDmf) {
+        this.resultDmf = resultDmf;
+    }
+
+    public String getContextDmf() {
+        return contextDmf;
+    }
+
+    public void setContextDmf(String contextDmf) {
+        this.contextDmf = contextDmf;
+    }
+
+    public String getCollectedFrom() {
+        return collectedFrom;
+    }
+
+    public void setCollectedFrom(String collectedFrom) {
+        this.collectedFrom = collectedFrom;
+    }
+
+    public String getClaimedBy() {
+        return claimedBy;
+    }
+
+    public void setClaimedBy(String claimedBy) {
+        this.claimedBy = claimedBy;
+    }
+
+    public Date getClaimDate() {
+        return claimDate;
+    }
+
+    public void setClaimDate(Date claimDate) {
+        this.claimDate = claimDate;
+    }
+}
Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/entity/Context.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/entity/Context.java	(nonexistent)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/entity/Context.java	(revision 41791)
@@ -0,0 +1,39 @@
+package eu.dnetlib.data.claims.migration.entity;
+
+/**
+
+
+ import eu.dnetlib.data.claims.migration.entity.OpenaireEntity; Created by kiatrop on 20/11/2015.
+ */
+public class Context implements   OpenaireEntity{
+private String title;
+    private String openaireId;
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    public String getOpenaireId() {
+        return openaireId;
+    }
+
+    public void setOpenaireId(String openaireId) {
+        this.openaireId = openaireId;
+    }
+
+    private String export(){
+        return "";
+    }
+
+    @Override
+    public String toString() {
+        return "Context{" +
+                "title='" + title + '\'' +
+                ", openaireId='" + openaireId + '\'' +
+                '}';
+    }
+}
Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/entity/Claim.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/entity/Claim.java	(nonexistent)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/entity/Claim.java	(revision 41791)
@@ -0,0 +1,102 @@
+package eu.dnetlib.data.claims.migration.entity;
+
+import java.text.SimpleDateFormat;
+
+import com.google.gson.annotations.SerializedName;
+import eu.dnetlib.data.claims.migration.entity.OpenaireEntity;
+
+import java.util.Date;
+
+/**
+ * Created by kiatrop on 20/11/2015.
+ */
+ public class Claim {
+
+    private String id;
+    private String userMail;
+    private Date date;
+    private String sourceType;
+    private String targetType;
+    private String semantics;
+    private OpenaireEntity source;
+    private OpenaireEntity target;
+
+
+    public OpenaireEntity getTarget() {
+        return target;
+    }
+
+    public void setTarget(OpenaireEntity target) {
+        this.target = target;
+    }
+
+    public OpenaireEntity getSource() {
+        return source;
+    }
+
+    public void setSource(OpenaireEntity source) {
+        this.source = source;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getUserMail() {
+        return userMail;
+    }
+
+    public void setUserMail(String userMail) {
+        this.userMail = userMail;
+    }
+
+    public Date getDate() {
+        return date;
+    }
+
+    public void setDate(Date date) {
+        this.date = date;
+    }
+
+    public String getSourceType() {
+        return sourceType;
+    }
+
+    public void setSourceType(String sourceType) {
+        this.sourceType = sourceType;
+    }
+
+    public String getTargetType() {
+        return targetType;
+    }
+
+    public void setTargetType(String targetType) {
+        this.targetType = targetType;
+    }
+
+    public String getSemantics() {
+        return semantics;
+    }
+
+    public void setSemantics(String semantics) {
+        this.semantics = semantics;
+    }
+
+    @Override
+    public String toString() {
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
+        return "Claim{" +
+                "\ntargetType=" + targetType+
+                ",\nsourceType=" + sourceType +
+                ",\ntarget={" +   ((target==null)?"null":target.toString())+
+                "},\n source={" + ((source==null)?"null":source.toString())  +
+                "},\n id='" + id + '\'' +
+                ", userMail='" + userMail + '\'' +
+                ", date=" + format.format(date)+
+                '}';
+    }
+}
Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/entity/Project.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/entity/Project.java	(nonexistent)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/entity/Project.java	(revision 41791)
@@ -0,0 +1,88 @@
+package eu.dnetlib.data.claims.migration.entity;
+
+/**
+
+
+ import eu.dnetlib.data.claims.migration.entity.OpenaireEntity; Created by kiatrop on 20/11/2015.
+ */
+public class Project implements  OpenaireEntity{
+    private String name;
+    private String acronym;
+    private String openaireId;
+    private String funderName;
+    private String funderShortName;
+    private String funderId;
+//    private boolean found=true;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getAcronym() {
+        return acronym;
+    }
+
+    public void setAcronym(String acronym) {
+        this.acronym = acronym;
+    }
+
+    public String getOpenaireId() {
+        return openaireId;
+    }
+
+    public void setOpenaireId(String openaireId) {
+        this.openaireId = openaireId;
+     }
+
+    public String getFunderName() {
+        return funderName;
+    }
+
+    public void setFunderName(String funderName) {
+        this.funderName = funderName;
+    }
+
+    public String getFunderId() {
+        return funderId;
+    }
+
+    public void setFunderId(String funderId) {
+        this.funderId = funderId;
+    }
+/*
+    public boolean isFound() {
+        return found;
+    }
+
+    public void setFound(boolean found) {
+        this.found = found;
+    }*/
+
+    public String getFunderShortName() {
+        return funderShortName;
+    }
+
+    public void setFunderShortName(String funderShortName) {
+        this.funderShortName = funderShortName;
+    }
+
+    @Override
+    public String toString() {
+        return "Project{" +
+                "\nname='" + name + '\'' +
+                ",\n acronym='" + acronym + '\'' +
+                ",\n openaireId='" + openaireId + '\'' +
+                ",\n funderName='" + funderName + '\'' +
+                ",\n funderShortName='" + funderShortName + '\'' +
+                ",\n funderId='" + funderId + '\'' +
+                '}';
+    }
+
+    //method to ask from API of search to get the fields
+    //then parse the fields
+
+}
Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/entity/Relation.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/entity/Relation.java	(nonexistent)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/entity/Relation.java	(revision 41791)
@@ -0,0 +1,108 @@
+package eu.dnetlib.data.claims.migration.entity;
+
+/**
+ * Created by kiatrop on 5/2/2016.
+ */
+
+import java.util.Date;
+
+/**
+ * This is the old claim representation
+ */
+public class Relation {
+
+    private String claimId = null;
+    private String targetId = null;
+    private String targetType = null;
+
+    private String sourceId = null;
+    private String sourceType = null;
+
+    private boolean hasDMF = false;
+    private String dmf = null;
+
+    private String collectedFrom = null;
+
+    private String claimedBy = null;
+    private Date claimDate = null;
+
+    public String getClaimId() {
+        return claimId;
+    }
+
+    public void setClaimId(String claimId) {
+        this.claimId = claimId;
+    }
+
+    public String getTargetId() {
+        return targetId;
+    }
+
+    public void setTargetId(String targetId) {
+        this.targetId = targetId;
+    }
+
+    public String getTargetType() {
+        return targetType;
+    }
+
+    public void setTargetType(String targetType) {
+        this.targetType = targetType;
+    }
+
+    public String getSourceId() {
+        return sourceId;
+    }
+
+    public void setSourceId(String sourceId) {
+        this.sourceId = sourceId;
+    }
+
+    public String getSourceType() {
+        return sourceType;
+    }
+
+    public void setSourceType(String sourceType) {
+        this.sourceType = sourceType;
+    }
+
+    public boolean isHasDMF() {
+        return hasDMF;
+    }
+
+    public void setHasDMF(boolean hasDMF) {
+        this.hasDMF = hasDMF;
+    }
+
+    public String getCollectedFrom() {
+        return collectedFrom;
+    }
+
+    public void setCollectedFrom(String collectedFrom) {
+        this.collectedFrom = collectedFrom;
+    }
+
+    public String getClaimedBy() {
+        return claimedBy;
+    }
+
+    public void setClaimedBy(String claimedBy) {
+        this.claimedBy = claimedBy;
+    }
+
+    public Date getClaimDate() {
+        return claimDate;
+    }
+
+    public void setClaimDate(Date claimDate) {
+        this.claimDate = claimDate;
+    }
+
+    public String getDmf() {
+        return dmf;
+    }
+
+    public void setDmf(String dmf) {
+        this.dmf = dmf;
+    }
+}
Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/entity/Result.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/entity/Result.java	(nonexistent)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/entity/Result.java	(revision 41791)
@@ -0,0 +1,212 @@
+package eu.dnetlib.data.claims.migration.entity;
+
+import eu.dnetlib.data.claimsDemo.ClaimUtils;
+
+/**
+ * Created by kiatrop on 20/11/2015.
+ */
+public class Result implements  OpenaireEntity{
+    private String title;
+//external url: url+doi (if doi exists) or url from websources
+    private String externalUrl;
+    private String openaireId;
+    private String doi;
+    private String orcidworkid;
+    private String pmcid;
+    //accessRights : set by user
+    private String accessRights;
+    //bestLicence : from search
+    private String bestLicense;
+
+    private String collectedFrom;
+    private String metadataRecord;
+
+//for the metadataRecord file
+    private String recordPath;
+    private String recordFormat;
+
+    private String resultType;
+//    private boolean found=false;
+    private String embargoEndDate;
+
+//Used for Datacite
+    private String oai;
+    private String provenanceaction;
+
+
+    public String getDoi() {
+		return doi;
+	}
+
+	public void setDoi(String doi) {
+		this.doi = doi;
+	}
+
+	public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    public String getExternalUrl() {
+        return externalUrl;
+    }
+
+    public void setExternalUrl(String externalUrl) {
+        this.externalUrl = externalUrl;
+    }
+
+    public String getOpenaireId() {
+        return openaireId;
+    }
+
+    public void setOpenaireId(String openaire_id) {
+        this.openaireId = openaire_id;
+    }
+
+    public String getAccessRights() {
+        return accessRights;
+    }
+
+    public void setAccessRights(String accessRights) {
+        this.accessRights = accessRights;
+    }
+
+    public String getBestLicense() {
+        return bestLicense;
+    }
+
+    public void setBestLicense(String bestLicense) {
+        this.bestLicense = bestLicense;
+    }
+
+    public String getCollectedFrom() {
+        return collectedFrom;
+    }
+
+    public void setCollectedFrom(String collectedFrom) {
+        if(!collectedFrom.contains("____::")) {
+            if (collectedFrom.equals("Datacite")) {
+                collectedFrom = ClaimUtils.COLLECTED_FROM_DATACITE;
+
+            } else if (collectedFrom.equals("Crossref")) {
+                collectedFrom = ClaimUtils.COLLECTED_FROM_CROSSREF;
+
+            } else if (collectedFrom.equals("Orcid")) {
+                collectedFrom = ClaimUtils.COLLECTED_FROM_ORCID;
+
+            } else {
+                collectedFrom = ClaimUtils.COLLECTED_FROM_OPENAIRE;
+            }
+        }
+        this.collectedFrom = collectedFrom;
+    }
+
+    public String getMetadataRecord() {
+        return metadataRecord;
+    }
+
+    public void setMetadataRecord(String metadataRecord) {
+        this.metadataRecord = metadataRecord;
+    }
+
+    public String getResultType() {
+        return resultType;
+    }
+
+    public void setResultType(String resultType) {
+        this.resultType = resultType;
+    }
+
+
+
+/*    public boolean isFound() {
+        return found;
+    }
+
+    public void setFound(boolean found) {
+        this.found = found;
+    }*/
+
+    public String getPmcid() {
+        return pmcid;
+    }
+
+    public void setPmcid(String pmcid) {
+        this.pmcid = pmcid;
+    }
+
+    public String getOrcidworkid() {
+        return orcidworkid;
+    }
+
+    public void setOrcidworkid(String orcidworkid) {
+        this.orcidworkid = orcidworkid;
+    }
+
+    public String getEmbargoEndDate() {
+        return embargoEndDate;
+    }
+
+    public void setEmbargoEndDate(String embargoEndDate) {
+        this.embargoEndDate = embargoEndDate;
+    }
+
+    public String getOai() {
+        return oai;
+    }
+
+    public void setOai(String oai) {
+        this.oai = oai;
+    }
+
+    public String getProvenanceaction() {
+        return provenanceaction;
+    }
+
+    public void setProvenanceaction(String provenanceaction) {
+        this.provenanceaction = provenanceaction;
+    }
+
+    public String getRecordPath() {
+        return recordPath;
+    }
+
+    public void setRecordPath(String recordPath) {
+        this.recordPath = recordPath;
+    }
+
+    public String getRecordFormat() {
+        return recordFormat;
+    }
+
+    public void setRecordFormat(String recordFormat) {
+        this.recordFormat = recordFormat;
+    }
+
+    @Override
+    public String toString() {
+        return "\nResult{" +
+                "title='" + title + '\'' +
+                ",\n external_url='" + externalUrl + '\'' +
+                ",\n openaire_id='" + openaireId + '\'' +
+                ",\n doi='" + doi + '\'' +
+                ",\n pmcid='" + pmcid + '\'' +
+                ",\n orcidworkid='" + orcidworkid + '\'' +
+                ",\n accessRights='" + accessRights + '\'' +
+                ",\n embargoEndDate='" + embargoEndDate + '\'' +
+                ",\n bestLicense='" + bestLicense + '\'' +
+                ",\n collectedFrom='" + collectedFrom + '\'' +
+                ",\n oai='" + oai + '\'' +
+                ",\n provenanceaction='" + provenanceaction + '\'' +
+                ",\n metadataRecord='" + ((metadataRecord!=null)?metadataRecord.substring(0,60):null) + "...\'" +
+                ",\n recordPath='" + recordPath + '\'' +
+                ",\n recordFormat='" + recordFormat + '\'' +
+                ",\n resultType='" + resultType + '\'' +
+                '}';
+    }
+//method to ask from API of search to get the metadataRecord
+    //then parse the fields
+}
Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/parser/OafParser.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/parser/OafParser.java	(revision 41790)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/parser/OafParser.java	(revision 41791)
@@ -1,7 +1,7 @@
 package eu.dnetlib.data.claims.migration.parser;
 
-import eu.dnetlib.data.claims.migration.Project;
-import eu.dnetlib.data.claims.migration.Result;
+import eu.dnetlib.data.claims.migration.entity.Project;
+import eu.dnetlib.data.claims.migration.entity.Result;
 import eu.dnetlib.data.claimsDemo.ClaimUtils;
 import org.w3c.dom.Document;
 import org.w3c.dom.NodeList;
@@ -12,7 +12,6 @@
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
 import javax.xml.transform.TransformerException;
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMSource;
@@ -144,7 +143,7 @@
              result.setMetadataRecord(writer.toString());
             result.setCollectedFrom(ClaimUtils.COLLECTED_FROM_OPENAIRE);
             result.setRecordFormat(ClaimUtils.FORMAT_XML);
-            result.setFound(true);
+//            result.setFound(true);
 
         }
 
@@ -194,7 +193,7 @@
                 project.setFunderId(nl.item(0).getNodeValue());
             }
 
-            project.setFound(true);
+//            project.setFound(true);
 
         }
 
Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/parser/DMFParser.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/parser/DMFParser.java	(revision 41790)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/parser/DMFParser.java	(revision 41791)
@@ -1,7 +1,7 @@
 package eu.dnetlib.data.claims.migration.parser;
 
-import eu.dnetlib.data.claims.migration.Context;
-import eu.dnetlib.data.claims.migration.Result;
+import eu.dnetlib.data.claims.migration.entity.Context;
+import eu.dnetlib.data.claims.migration.entity.Result;
 import eu.dnetlib.data.claimsDemo.ClaimUtils;
 import eu.dnetlib.data.claimsDemo.ContextUtils;
 import org.w3c.dom.Document;
@@ -89,39 +89,7 @@
         return r;
     }
 
-    static public Context dmf2Context(String xml) {
-        Context context = new Context();
-        try {
-            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
-            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
-            InputSource inputSource = new InputSource(new StringReader(xml));
-            Document document = dBuilder.parse(inputSource);
-            XPathFactory xPathfactory = XPathFactory.newInstance();
-            XPath xpath = xPathfactory.newXPath();
-            NodeList nl = (NodeList) xpath.compile("//*[local-name()='concept']/@id").evaluate(document, XPathConstants.NODESET);
-            if (nl.getLength() > 0) {
-                context.setOpenaireId(nl.item(0).getNodeValue());
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        buildContext(context);
-        return context;
 
-    }
-
-    static private void buildContext(Context context) {
-        if (context != null && context.getOpenaireId() != null) {
-            try {
-                context.setTitle(ContextUtils.extractEgiLabel(context.getOpenaireId()));
-
-            } catch (Exception e) {
-                e.printStackTrace();
-                System.err.println("ContextUtils: Couldn't get Egi label for id " + context.getOpenaireId());
-            }
-        }
-    }
-
     /**
      *
      * @param xml of a context DMF
Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/parser/RelationParser.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/parser/RelationParser.java	(revision 41790)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/parser/RelationParser.java	(revision 41791)
@@ -1,6 +1,6 @@
 package eu.dnetlib.data.claims.migration.parser;
 
-import eu.dnetlib.data.claims.migration.Relation;
+import eu.dnetlib.data.claims.migration.entity.Relation;
 import eu.dnetlib.data.claimsDemo.ClaimUtils;
 import org.apache.log4j.Logger;
 import org.w3c.dom.Document;
Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/parser/ExternalRecordParser.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/parser/ExternalRecordParser.java	(revision 41790)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/parser/ExternalRecordParser.java	(revision 41791)
@@ -1,6 +1,6 @@
 package eu.dnetlib.data.claims.migration.parser;
 
-import eu.dnetlib.data.claims.migration.Result;
+import eu.dnetlib.data.claims.migration.entity.Result;
 import eu.dnetlib.data.claimsDemo.ClaimUtils;
 import org.w3c.dom.Document;
 import org.w3c.dom.NodeList;
@@ -50,7 +50,7 @@
             result= new Result();
             result.setMetadataRecord(json);
             result.setRecordFormat(ClaimUtils.FORMAT_JSON);
-            result.setFound(true);
+//            result.setFound(true);
             result.setCollectedFrom(ClaimUtils.COLLECTED_FROM_CROSSREF);
             Response.Message.Item item= obj.getMessage().getItems().get(0);
             if(item.getTitle()!=null && item.getTitle().size()>0){
@@ -145,7 +145,7 @@
                 result.setMetadataRecord(writer.toString());
                 result.setRecordFormat(ClaimUtils.FORMAT_XML);
                 result.setCollectedFrom(ClaimUtils.COLLECTED_FROM_ORCID);
-                result.setFound(true);
+//                result.setFound(true);
             }
 
         } catch (Exception e) {
@@ -191,7 +191,7 @@
                 result.setMetadataRecord(xml);
                 result.setRecordFormat(ClaimUtils.FORMAT_XML);
                 result.setCollectedFrom(ClaimUtils.COLLECTED_FROM_DATACITE);
-                result.setFound(true);
+//                result.setFound(true);
             }
         } catch (Exception e) {
             e.printStackTrace();
Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/handler/ExternalRecordHandler.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/handler/ExternalRecordHandler.java	(revision 41790)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/handler/ExternalRecordHandler.java	(revision 41791)
@@ -1,6 +1,6 @@
 package eu.dnetlib.data.claims.migration.handler;
 
-import eu.dnetlib.data.claims.migration.Result;
+import eu.dnetlib.data.claims.migration.entity.Result;
 import eu.dnetlib.data.claims.migration.parser.ExternalRecordParser;
 import eu.dnetlib.data.claimsDemo.SearchUtils;
 
Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/handler/ContextRelationHandler.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/handler/ContextRelationHandler.java	(revision 41790)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/handler/ContextRelationHandler.java	(revision 41791)
@@ -1,6 +1,6 @@
 package eu.dnetlib.data.claims.migration.handler;
 
-import eu.dnetlib.data.claims.migration.ContextRelation;
+import eu.dnetlib.data.claims.migration.entity.ContextRelation;
 import eu.dnetlib.data.claims.migration.parser.DMFParser;
 import eu.dnetlib.data.claimsDemo.QueryGenerator;
 import eu.dnetlib.data.claimsDemo.SqlDAO;
@@ -21,7 +21,7 @@
     public List<ContextRelation> fetchAllConceptRelations() throws Exception {
         List<ContextRelation> relations = null;
 //          ResultSet rs = sqlDAO.executePreparedQuery(queryGenerator.generateQueryForTesting(-1,"169112"));
-        ResultSet rs = sqlDAO.executePreparedQuery(queryGenerator.generateSelectConceptClaimsEnrichedWithDMFClaimsQuery(-1));
+        ResultSet rs = sqlDAO.executePreparedQuery(queryGenerator.generateSelectConceptClaimsEnrichedWithDMFClaimsQuery(2));
         relations = new ArrayList<ContextRelation>();
 
         while(rs.next()) {
Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/handler/ClaimHandler.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/handler/ClaimHandler.java	(revision 41790)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/handler/ClaimHandler.java	(revision 41791)
@@ -1,13 +1,13 @@
 package eu.dnetlib.data.claims.migration.handler;
 
-import eu.dnetlib.data.claims.migration.Claim;
-import eu.dnetlib.data.claims.migration.Context;
-import eu.dnetlib.data.claims.migration.Project;
-import eu.dnetlib.data.claims.migration.Result;
+import eu.dnetlib.data.claims.migration.ClaimValidation;
+import eu.dnetlib.data.claims.migration.entity.*;
+import eu.dnetlib.data.claims.migration.parser.DMFParser;
 import eu.dnetlib.data.claimsDemo.ClaimUtils;
 import eu.dnetlib.data.claimsDemo.QueryGenerator;
 import eu.dnetlib.data.claimsDemo.SqlDAO;
 
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -21,6 +21,10 @@
     DMFContextHandler dmfContextHandler = null;
     ProjectHandler projectHandler = null;
 
+    /**
+     * Saves a list of claims in DB
+     * @param claims
+     */
     public void saveClaims(List<Claim> claims){
         for(Claim claim:claims){
             try {
@@ -34,20 +38,136 @@
    public String  generateSaveQueryForClaim(Claim claim){
 
        String query= null;
-       if (claim.getSourceType().equals(ClaimUtils.CONTEXT)) {
+       /*if (claim.getSourceType().equals(ClaimUtils.CONTEXT)) {
            query = queryGenerator.generateInsertClaimContextQuery(resultHandler.generateSaveQueryForResult(((Result)claim.getTarget())),dmfContextHandler.generateSaveQueryForContext ((Context) claim.getSource()), claim);
        } else if (claim.getSourceType().equals(ClaimUtils.PROJECT)) {
            query = queryGenerator.generateInsertClaimProjectQuery(resultHandler.generateSaveQueryForResult((Result)claim.getTarget()), projectHandler.generateSaveQueryForProject((Project) claim.getSource()), claim);
        } else{
            query = queryGenerator.generateInsertClaimResultQuery(resultHandler.generateSaveQueryForResult((Result)claim.getTarget()), resultHandler.generateSaveQueryForResult((Result) claim.getSource()), claim);
-       }
+       }*/
+       query = queryGenerator.generateInsertFullClaimQuery(claim);
        return query;
    }
-
+    /**
+     * saves a claim in DB
+     * @param claim
+     * @throws Exception
+     */
     public void saveClaim(Claim claim) throws Exception {
         sqlDAO.executeUpdateQuery(generateSaveQueryForClaim(claim));
     }
 
+    /**
+     * Gets the main information for a claim relation - builds a claim object
+     * exports metadata
+     * and saves the claim relations in the DB
+     * @param user
+     * @param date
+     * @param sourceType
+     * @param sourceId
+     * @param sourceCollectedFrom
+     * @param targetType
+     * @param targetId
+     * @param targetCollectedFrom
+     * @throws Exception
+     */
+    public void buildAndInsertClaim(String user, Date date, String sourceType, String sourceId, String sourceCollectedFrom, String targetType, String targetId, String targetCollectedFrom) throws Exception {
+        Claim claim = buildClaim(user,date,sourceType,sourceId,sourceCollectedFrom, targetType, targetId, targetCollectedFrom);
+        ClaimValidation claimValidation = new ClaimValidation();
+        System.out.print(claim.toString());
+        if(claimValidation.validateClaim(claim)) {
+            claim = exportMedatataForClaim(claim);
+            saveClaim(claim);
+        }
+    }
+
+    /**
+     * Gets the main information of a relation claim and
+     * builds a claim object
+     * @param user
+     * @param date
+     * @param sourceType publication, dataset, project, context
+     * @param sourceId openaireId, doi or orcid workid
+     * @param sourceCollectedFrom only for source with type publication, dataset
+     * @param targetType publication, dataset, project, context
+     * @param targetId openaireId, doi or orcid workid
+     * @param targetCollectedFrom only for target with type publication, dataset
+     * @return a claim object
+     * @throws Exception
+     */
+    private Claim buildClaim(String user,Date date, String sourceType,String sourceId,String sourceCollectedFrom,  String targetType,String targetId,String targetCollectedFrom ) throws Exception {
+        Claim claim = new Claim();
+        claim.setUserMail(user);
+        claim.setDate(date);
+        //date
+        claim.setSourceType(sourceType);
+        claim.setTargetType(targetType);
+        claim.setSource(buildOpenaireEntity(sourceId,sourceType,sourceCollectedFrom));
+        claim.setTarget(buildOpenaireEntity(targetId,targetType,targetCollectedFrom));
+        //TODO from external sources need an OPenaireID
+
+        return claim;
+
+    }
+
+    /**
+     * Gets the main information of an openaire entity
+     * and returns a full  object
+     * @param id
+     * @param type
+     * @param collectedFrom
+     * @return openaire Entity (Context, Result, Project)
+     * @throws Exception
+     */
+    private OpenaireEntity buildOpenaireEntity(String id, String type, String collectedFrom) throws Exception {
+        if(type==null){
+            return null;
+        }
+        else if(type.equals(ClaimUtils.CONTEXT)){
+            return DMFContextHandler.fetchContextById(id);
+        }else if (type.equals(ClaimUtils.PROJECT)){
+            return projectHandler.fetchProjectByID(id);
+        }else if (type.equals(ClaimUtils.PUBLICATION)||type.equals(ClaimUtils.DATASET)){
+            ExternalRecordHandler externalRecordHandler = new ExternalRecordHandler();
+            if(collectedFrom == null){
+                return null;
+            }else if(collectedFrom.equals(ClaimUtils.CROSSREF)){
+                return externalRecordHandler.fetchResultfromCrossref(id);
+            }else if (collectedFrom.equals(ClaimUtils.DATACITE)){
+                return externalRecordHandler.fetchResultfromDatacite(id);
+            }else if (collectedFrom.equals(ClaimUtils.ORCID)){
+                return externalRecordHandler.fetchResultfromOrcid(id);
+            }else if (collectedFrom.equals(ClaimUtils.OPENAIRE)){
+                IndexResultHandler indexResultHandler = new IndexResultHandler();
+                return indexResultHandler.fetchResultById(id);
+            }
+        }
+        return null;
+    }
+
+
+    /**
+     * Exports the metadata for the source and the target of a claim and sets the proper field
+     * @param claim
+     * @return claim with the proper metadata path of the result of source and target
+     */
+    public Claim exportMedatataForClaim(Claim claim){
+        if(claim.getTargetType().equals(ClaimUtils.DATASET)||claim.getTargetType().equals(ClaimUtils.PUBLICATION)){
+            String path = resultHandler.exportMetadataFileForResult((Result)claim.getTarget());
+            ((Result) claim.getTarget()).setRecordPath(path);
+        }
+        if(claim.getSourceType().equals(ClaimUtils.DATASET)||claim.getSourceType().equals(ClaimUtils.PUBLICATION)){
+            String path = resultHandler.exportMetadataFileForResult((Result)claim.getSource());
+            ((Result) claim.getSource()).setRecordPath(path);
+        }
+        return claim;
+
+    }
+
+    public void deleteClaim(String user, String claimId){
+        //TODO
+    }
+
     public SqlDAO getSqlDAO() {
         return sqlDAO;
     }
Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/handler/DMFResultHandler.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/handler/DMFResultHandler.java	(revision 41790)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/handler/DMFResultHandler.java	(revision 41791)
@@ -1,6 +1,6 @@
 package eu.dnetlib.data.claims.migration.handler;
 
-import eu.dnetlib.data.claims.migration.Result;
+import eu.dnetlib.data.claims.migration.entity.Result;
 import eu.dnetlib.data.claims.migration.parser.DMFParser;
 import eu.dnetlib.data.claimsDemo.*;
 import org.xml.sax.SAXException;
Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/handler/IndexResultHandler.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/handler/IndexResultHandler.java	(revision 41790)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/handler/IndexResultHandler.java	(revision 41791)
@@ -1,6 +1,6 @@
 package eu.dnetlib.data.claims.migration.handler;
 
-import eu.dnetlib.data.claims.migration.Result;
+import eu.dnetlib.data.claims.migration.entity.Result;
 import eu.dnetlib.data.claims.migration.parser.OafParser;
 import eu.dnetlib.data.claimsDemo.SearchUtils;
 
Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/handler/DMFContextHandler.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/handler/DMFContextHandler.java	(revision 41790)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/handler/DMFContextHandler.java	(revision 41791)
@@ -1,10 +1,15 @@
 package eu.dnetlib.data.claims.migration.handler;
 
-import eu.dnetlib.data.claims.migration.Context;
+import eu.dnetlib.data.claims.migration.entity.Context;
 import eu.dnetlib.data.claims.migration.parser.DMFParser;
+import eu.dnetlib.data.claimsDemo.ContextUtils;
 import eu.dnetlib.data.claimsDemo.QueryGenerator;
 import eu.dnetlib.data.claimsDemo.SqlDAO;
+import org.xml.sax.SAXException;
 
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.xpath.XPathExpressionException;
+import java.io.IOException;
 import java.sql.ResultSet;
 
 /**
@@ -25,16 +30,32 @@
         return rs.getString("xml");
     }
 
-    public Context fetchContextByDMF(String xml)  {
-        return dmfParser.dmf2Context(xml);
+    public Context fetchContextByDMF(String xml) throws ParserConfigurationException, SAXException, XPathExpressionException, IOException {
+        return fetchContextById(dmfParser.getContextIdFromDMF(xml));
     }
 
-    public Context fetchContextById(String id) throws Exception {
+    public Context fetchContextByIdFromDmf(String id) throws Exception {
         return fetchContextByDMF(fetchDMFContext(id));
     }
 
-    public String generateSaveQueryForContext(Context context){
+    static public Context fetchContextById(String openaireId) {
+        Context context = new Context();
+        if(openaireId == null ){
+            return null;
+        }
+        context.setOpenaireId(openaireId);
+        try {
+            context.setTitle(ContextUtils.extractEgiLabel(context.getOpenaireId()));
 
+        } catch (Exception e) {
+            e.printStackTrace();
+            System.err.println("ContextUtils: Couldn't get Egi label for id " + context.getOpenaireId());
+        }
+        return context;
+
+    }
+/*    public String generateSaveQueryForContext(Context context){
+
         return queryGenerator.generateInsertContextQuery(context.getOpenaireId(),context.getTitle());
     }
 
@@ -41,7 +62,7 @@
     public void saveContext(Context context) throws Exception {
 
         sqlDAO.executePreparedQuery(generateSaveQueryForContext(context));
-    }
+    }*/
 
     public SqlDAO getSqlDAO() {
         return sqlDAO;
Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/handler/ResultHandler.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/handler/ResultHandler.java	(revision 41790)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/handler/ResultHandler.java	(revision 41791)
@@ -1,6 +1,6 @@
 package eu.dnetlib.data.claims.migration.handler;
 
-import eu.dnetlib.data.claims.migration.Result;
+import eu.dnetlib.data.claims.migration.entity.Result;
 import eu.dnetlib.data.claimsDemo.ClaimUtils;
 import eu.dnetlib.data.claimsDemo.QueryGenerator;
 import eu.dnetlib.data.claimsDemo.SqlDAO;
@@ -16,12 +16,12 @@
     SqlDAO sqlDAO = null;
     QueryGenerator queryGenerator = null;
 
-    public String generateSaveQueryForResult(Result result){
+/*    public String generateSaveQueryForResult(Result result){
         return queryGenerator.generateInsertResultQuery(result.getOpenaireId(),result.getResultType(),result.getTitle(),result.getCollectedFrom(),result.getExternalUrl(),result.getDoi(), result.getOrcidworkid(), result.getAccessRights(),result.getEmbargoEndDate(),result.getBestLicense(),result.getRecordPath(), result.getRecordFormat());
     }
     public void saveResult(Result result) throws Exception {
         sqlDAO.executePreparedQuery(generateSaveQueryForResult(result));
-    }
+    }*/
 
     public String exportMetadataFileForResult(Result result)  {
         if(result.getOpenaireId()!=null && result.getMetadataRecord()!=null){
Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claimsDemo/SqlDAO.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claimsDemo/SqlDAO.java	(revision 41790)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claimsDemo/SqlDAO.java	(revision 41791)
@@ -100,6 +100,7 @@
 
 		{
 			log.error(e.getMessage());
+            log.error("Query is : "+q);
 			throw new Exception(e);
 		}
 
Index: modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claimsDemo/QueryGenerator.java
===================================================================
--- modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claimsDemo/QueryGenerator.java	(revision 41790)
+++ modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claimsDemo/QueryGenerator.java	(revision 41791)
@@ -1,6 +1,10 @@
 package eu.dnetlib.data.claimsDemo;
 
-import eu.dnetlib.data.claims.migration.*;
+import eu.dnetlib.data.claims.migration.entity.Claim;
+import eu.dnetlib.data.claims.migration.entity.Context;
+import eu.dnetlib.data.claims.migration.entity.OpenaireEntity;
+import eu.dnetlib.data.claims.migration.entity.Project;
+import eu.dnetlib.data.claims.migration.entity.Result;
 
 import java.text.SimpleDateFormat;
 import java.util.Date;
@@ -10,7 +14,7 @@
 /**
   ** Insert Queries **
   **/
-    public String generateInsertResultQuery(String openaire_id, String result_type, String title, String collected_from , String external_url, String doi, String orcidworkid, String access_rights , String embargo_end_date, String best_license, String record_path, String record_format) {
+    private String generateInsertResultQuery(String openaire_id, String result_type, String title, String collected_from , String external_url, String doi, String orcidworkid, String access_rights , String embargo_end_date, String best_license, String record_path, String record_format) {
         if(title!=null&&title.contains("'")){
             title=title.replace("'","''");
         }
@@ -87,7 +91,7 @@
                 "    where not exists (select openaire_id from result where openaire_id='"+openaire_id+"')\n" +
                 "    RETURNING openaire_id";
     }
-    public String generateInsertProjectQuery(String openaire_id, String name, String acronym, String funder_id, String funder_name, String funder_acronym) {
+    private String generateInsertProjectQuery(String openaire_id, String name, String acronym, String funder_id, String funder_name, String funder_acronym) {
         if(name!=null) {
             name = name.replace("'", "''");
         }
@@ -128,7 +132,7 @@
                 "    where not exists (select openaire_id from project where openaire_id='"+openaire_id+"')\n" +
                 "    RETURNING openaire_id";
     }
-    public String generateInsertContextQuery(String openaire_id, String name) {
+    private String generateInsertContextQuery(String openaire_id, String name) {
         String fields="openaire_id";
         if(name!=null){
             fields+=",name";
@@ -147,9 +151,17 @@
         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
         String dateStr=null;
         dateStr=(format.format(date));
+        String fields="claim_date,claimedBy,source_type,target_type, source_id, target_id";
+        if(semantics!=null){
+            fields+=",semantics";
+        }
+        String values="'"+dateStr+"','"+claimedBy+"','"+source_type+"', '"+target_type+"','"+source_id+"','"+target_id+"'";
+        if(semantics!=null){
+            values+=",'"+semantics+"'";
+        }
 
-        return "            INSERT INTO claim( claim_date,claimedBy,source_type,target_type, source_id, target_id, semantics)\n" +
-                "    VALUES ( '"+dateStr+"','"+claimedBy+"','"+source_type+"', '"+target_type+"','"+source_id+"','"+target_id+"','"+semantics+"')\n" +
+        return "     INSERT INTO claim( "+fields+")\n" +
+                "    VALUES ( "+values+")\n" +
                 "    RETURNING id, source_id, target_id\n";
     }
 
@@ -185,7 +197,7 @@
 
     }
     private String generateInsertEntityQuery(OpenaireEntity openaireEntity, String type){
-        String query="has_target_";
+        String query=null;
         if(type==null){
             return null;
         }
@@ -195,7 +207,7 @@
         }else if(type.equals(ClaimUtils.PROJECT)){
             Project project=(Project)openaireEntity;
             query=generateInsertProjectQuery(project.getOpenaireId(),project.getName(),project.getAcronym(),project.getFunderId(),project.getFunderName(),project.getFunderShortName());
-        }else if(type.equals(ClaimUtils.DATASET)||type.equals(ClaimUtils.PUBLICATION)){
+        }else if(type.equals(ClaimUtils.CONTEXT)){
             Context context= (Context)openaireEntity;
             query=generateInsertContextQuery(context.getOpenaireId(),context.getTitle());
         }
@@ -209,9 +221,9 @@
         }
         if(type==null){
             return null;
-        }else if(type.equals("publication")||type.equals("dataset")){
+        }else if(type.equals(ClaimUtils.PUBLICATION)||type.equals(ClaimUtils.DATASET)){
             tablename=tablename+"result";
-        }else if(type.equals("project")||type.equals("context")){
+        }else if(type.equals(ClaimUtils.PROJECT)||type.equals(ClaimUtils.CONTEXT)){
             tablename+=type;
         }
         return tablename;
@@ -242,27 +254,17 @@
      */
     private String createSemanticsType(String sourceType,String targetType){
         String semantics=null;
-        //resultResult_publicationDataset_isRelatedTo
-        semantics="resultResult_"+targetType+sourceType+"_isRelatedTo";
-       /* if(sourceType.equals(ClaimUtils.PUBLICATION)){
-            semantics="resultResult_publication";
-            if(targetType.equals(ClaimUtils.DATASET)){
-                semantics+="Dataset"+"_isRelatedTo";
-            }else if(targetType.equals(ClaimUtils.PUBLICATION)){
-                semantics+="Publication"+"_isRelatedTo";
-            }
-        }else if(sourceType.equals(ClaimUtils.DATASET)){
-            semantics="resultResult_dataset";
-            if(targetType.equals(ClaimUtils.DATASET)){
-                semantics+="Dataset"+"_isRelatedTo";
-            }else if(targetType.equals(ClaimUtils.PUBLICATION)){
-                semantics+="Publication"+"_isRelatedTo";
-            }
-        }*/
+        if((targetType.equals(ClaimUtils.PUBLICATION)||targetType.equals(ClaimUtils.DATASET))&&(sourceType.equals(ClaimUtils.PUBLICATION)||sourceType.equals(ClaimUtils.DATASET))){
+            semantics="resultResult_"+targetType+sourceType+"_isRelatedTo";
+        }
+        else if((targetType.equals(ClaimUtils.PUBLICATION)||targetType.equals(ClaimUtils.DATASET))&&(sourceType.equals(ClaimUtils.PROJECT))){
+            semantics="resultProject_outcome_isProducedBy";
+        }
 
+
         return semantics;
     }
-    public  String generateInsertClaimResultQuery(Result targetResult, Result sourceResult, Claim claim) {
+   /* public  String generateInsertClaimResultQuery(Result targetResult, Result sourceResult, Claim claim) {
 
         return generateInsertClaimResultQuery(generateInsertResultQuery(targetResult.getOpenaireId(), targetResult.getResultType(), targetResult.getTitle(), targetResult.getCollectedFrom(), targetResult.getExternalUrl(), targetResult.getDoi(),targetResult.getOrcidworkid(), targetResult.getAccessRights(), targetResult.getEmbargoEndDate(), targetResult.getBestLicense(), targetResult.getRecordPath(), targetResult.getRecordFormat()),
                 generateInsertResultQuery(sourceResult.getOpenaireId(), sourceResult.getResultType(), sourceResult.getTitle(), sourceResult.getCollectedFrom(), sourceResult.getExternalUrl(), sourceResult.getDoi(), sourceResult.getOrcidworkid(), sourceResult.getAccessRights(), targetResult.getEmbargoEndDate(), sourceResult.getBestLicense(), sourceResult.getRecordPath(),sourceResult.getRecordFormat()),claim);
@@ -310,7 +312,7 @@
                 "    SELECT id, target_id\n" +
                 "    FROM   ins3;";
     }
-
+*/
     /**
      ** Delete Tables Queries **
      **/
@@ -405,24 +407,13 @@
      **/
 
 
-    public String generateSelectDMFClaimsQuery(Integer limit) {
-        return " Select * from claims_view  where type='dmf2actions' and xml NOT ILIKE '%<oaf:concept%' "+(limit>0?" limit "+limit:"");
-    }
     public String generateSelectDMFByIdQuery(String id) {
         return " Select * from claims_view  where type='dmf2actions' and xml NOT ILIKE '%<oaf:concept%' and  resultid='"+id+"'  order by date desc limit 1";
     }
+
     public String generateSelectConceptDMFClaimsQuery(Integer limit) {
         return " Select * from claims_view  where ( type='dmf2actions' or type='updates2actions' ) and xml LIKE '%<oaf:concept%' "+(limit>0?" limit "+limit:"");
     }
-    public String generateSelectCountConceptClaimsQuery(Integer limit ) {
-        return " Select count(*) from claims_view where  ( type='dmf2actions' or type='updates2actions' ) and xml LIKE '%<oaf:concept%' "+(limit>0?" limit "+limit:"");
-
-    }
-    public String generateSelectCountRelationClaimsQuery(Integer limit) {
-        return " Select count(*) from claims_view  where type='rels2actions'  "+(limit>0?" limit "+limit:"");
-
-    }
-
     /**
      *
      * @param limit : for limit > 0 the query adds limit clause, for limit < 0 query skips limit clause
@@ -457,23 +448,158 @@
                 +(limit>0?" limit "+limit:"");
     }
 
-    //used just for Testing
-    public static String generateSelectClaimByIdQuery(String id) {
-        return " Select * from claims_view  where id='"+id+"'";
 
-    }
     public static String generateSelectConceptClaimByIdQuery(String id) {
         return " Select * from claims_view  where ( type='dmf2actions' or type='updates2actions' ) and xml LIKE '%<oaf:concept%' and id='"+id+"'";
 
     }
-/*
     public static String generateSelectRelationClaimByIdQuery(String id) {
         return " Select * from claims_view  where type='rels2actions' and id='"+id+"'";
 
     }
-*/
 
+
     /**
      ** Select - Fetch Queries *New* Database **
      **/
+
+    public static String generateFetchClaimsByUser(String user) {
+        return generateSelectClaimQueryAsUnionOfAllRelations(" claim.claimedBy='" + user + "'");
+
+    }
+    public static String generateFetchClaimsByDate(String dateFrom, String dateTo) {
+        return generateSelectClaimQueryAsUnionOfAllRelations(" claim.claim_date >= '" + dateFrom + "' and claim.claim_date <= '" + dateTo + "' ");
+    }
+    public static String generateFetchClaimsByProject(String projectId) {
+        return " ( " +generateSelectclaimQuery(ClaimUtils.PROJECT,ClaimUtils.PUBLICATION, "source.openaire_id ='"+projectId+"'")+" )";
+    }
+    public static String generateFetchClaimsByFunder(String funderId) {
+        return " ( " +generateSelectclaimQuery(ClaimUtils.PROJECT,ClaimUtils.PUBLICATION, "source.funder_id ='"+funderId+"'")+" )";
+
+    }
+    public static String generateFetchClaimsByResult(String resultId) {
+        String specificWhereClause=" ( source.openaire_id = '"+resultId+"'  or target.openaire_id = '"+resultId+"' )";
+        return " ( " +generateSelectclaimQuery(ClaimUtils.PUBLICATION,ClaimUtils.PUBLICATION, specificWhereClause)+" ) \nunion "+
+                " ( " +generateSelectclaimQuery(ClaimUtils.PROJECT,ClaimUtils.PUBLICATION, specificWhereClause)+" ) \nunion "+
+                " ( " +generateSelectclaimQuery(ClaimUtils.CONTEXT,ClaimUtils.PUBLICATION, specificWhereClause)+" ) ";
+
+    }
+
+
+    private static String getClaimFields() {
+        return " claim.id, claim.claim_date, claim.claimedBy, claim.source_type, claim.target_type, claim.semantics ";
+    }
+    private static String getResultFields(String tableAlias) {
+        return " "+tableAlias+".openaire_id, "+tableAlias+".title, "+tableAlias+".result_type, "+tableAlias+".doi, "+tableAlias+".orcidworkid, "+tableAlias+".access_rights, "+tableAlias+".embargo_end_date, "+tableAlias+".best_license, "+tableAlias+".external_url,  "+tableAlias+".collected_from  ";
+    }
+    private static String getProjectFields(String tableAlias) {
+        return " "+tableAlias+".openaire_id, "+tableAlias+".name, "+tableAlias+".acronym, "+tableAlias+".funder_id, "+tableAlias+".funder_name, null as field6, null as field7, null as field8, null as field9, null as field10 ";
+    }
+    private static String getContextFields(String tableAlias) {
+        return " "+tableAlias+".openaire_id, "+tableAlias+".name, null as field3, null as field4, null as field5, null as field6, null as field7, null as field8, null as field9, null as field10 ";
+    }
+    private static String getFieldsPerType(String type, String tableAlias){
+        String fields= null;
+        if (type == null){
+
+        }else if (type.equals(ClaimUtils.PUBLICATION)||type.equals(ClaimUtils.DATASET)){
+            fields=getResultFields(tableAlias);
+        }else if (type.equals(ClaimUtils.PROJECT)){
+            fields=getProjectFields(tableAlias);
+        }else if (type.equals(ClaimUtils.CONTEXT)){
+            fields=getContextFields(tableAlias);
+        }
+        return fields;
+    }
+    private static String generateSelectclaimQuery(String sourceType, String targetType, String specificWhereClause) {
+        if(sourceType == null || targetType == null){
+            return null;
+        }
+        /*
+        " select "+getClaimFields()+" ,"+getFieldsPerType(sourceType, "source")+" , "+getFieldsPerType(targetType,"target")+
+                " \nfrom claim, "+getTypeForTable(sourceType)+" as source, "+getTypeForTable(targetType)+" as target \n" +
+                "where claim.source_id = source.openaire_id and claim.target_id = target.openaire_id "+((specificWhereClause==null)?"":" and "+specificWhereClause+" ");
+         */
+        return " select "+getClaimFields()+" ,"+getFieldsPerType(sourceType, "source")+" , "+getFieldsPerType(targetType,"target")+
+                " \nfrom claim, "+getTypeForTable(sourceType)+" as source, has_source_"+getTypeForTable(sourceType)+", has_target_"+getTypeForTable(targetType)+", "+getTypeForTable(targetType)+" as target \n" +
+                "where claim.id =  has_source_"+getTypeForTable(sourceType)+".claim_id and   has_source_"+getTypeForTable(sourceType)+".openaire_id = source.openaire_id " +
+                "and claim.id =  has_target_"+getTypeForTable(targetType)+".claim_id and   has_target_"+getTypeForTable(targetType)+".openaire_id  = target.openaire_id "+
+                ((specificWhereClause==null)?"":" and "+specificWhereClause+" ");
+    }
+    private static String generateSelectClaimQueryAsUnionOfAllRelations(String specificWhereClause) {
+        //TODO eliminate unions  based on the to
+        // ClaimUtils.PUBLICATION or ClaimUtils.DATASET  it
+        return " ( " +generateSelectclaimQuery(ClaimUtils.PUBLICATION,ClaimUtils.PUBLICATION, specificWhereClause)+" ) \nunion "+
+                " ( " +generateSelectclaimQuery(ClaimUtils.PROJECT,ClaimUtils.PUBLICATION, specificWhereClause)+" ) \nunion "+
+                " ( " +generateSelectclaimQuery(ClaimUtils.CONTEXT,ClaimUtils.PUBLICATION, specificWhereClause)+" ) ";
+
+
+    }
+    private static String getTypeForTable(String type){
+        if(type == null){
+            return null;
+        }
+        if(type.equals(ClaimUtils.PUBLICATION)||type.equals(ClaimUtils.DATASET)){
+            return "result";
+        }else{
+            return type;
+        }
+    }
+    /**
+     ** Update - Queries *New* Database **
+     **/
+
+    private static void updateResult(){
+
+    }
+    private static void updateProject(){
+
+    }
+    /**
+     ** Delete - Queries *New* Database **
+     **/
+
+    private void deleteFullClaim(String id, String user, String sourceType, String targetType){
+//        String targetQuery =null;
+//        String sourceQuery=null;
+//        targetQuery=generateInsertEntityQuery(claim.getTarget(),claim.getTargetType());
+//        sourceQuery=generateInsertEntityQuery(claim.getSource(),claim.getSourceType());
+//        return generateInsertFullClaimQuery(targetQuery,sourceQuery,claim);
+//
+        String s = "DELETE FROM has_source_"+getTableName(true,sourceType)+" WHERE openaire_id = 10" +
+                "BEGIN;\n" +
+                "WITH source AS ( " +
+                "DELETE FROM "+getTableName(true,sourceType)+" WHERE EXISTS \n" +
+                "    (SELECT 1 FROM "+getTableName(true,sourceType)+" WHERE claim_id = "+id+" );\n" +
+                "    RETURNING openaire_id\n" +
+                "    )"+
+                "DELETE FROM "+sourceType+" WHERE NOT EXISTS \n" +
+                "    (SELECT 1 FROM "+getTableName(true,sourceType)+" , source WHERE openaire_id = 'source.openaire_id' join "+"SELECT 1 FROM "+getTableName(false,sourceType)+" , source WHERE openaire_id = 'source.openaire_id'  );\n" +
+                "WITH target AS ( " +
+                "DELETE FROM "+getTableName(false,targetType)+" WHERE EXISTS \n" +
+                "    (SELECT 1 FROM "+getTableName(false,targetType)+" WHERE claim_id = "+id+" );\n" +
+                "    RETURNING openaire_id\n" +
+                "    )"+
+                "DELETE FROM "+targetType+" WHERE NOT EXISTS \n" +
+                "    (SELECT 1 FROM "+getTableName(true,targetType)+" , source WHERE openaire_id = 'target.openaire_id' join "+"SELECT 1 FROM "+getTableName(false,targetType)+" , source WHERE openaire_id = 'target.openaire_id'  );\n" +
+
+                "WITH source AS ( " +
+                "DELETE FROM "+getTableName(true,sourceType)+" WHERE EXISTS \n" +
+                "    (SELECT 1 FROM "+getTableName(true,sourceType)+" WHERE claim_id = "+id+" );\n" +
+                "    RETURNING openaire_id\n" +
+                "    )"+
+
+                "DELETE FROM claim where id = "+id+";\n" +
+                "COMMIT";
+    }
+//    "drop table  if exists has_source_context;\n" +
+//            "drop table if exists has_source_project;\n" +
+//            "drop table if exists has_source_result;\n" +
+//            "drop table if exists has_target_project;\n" +
+//            "drop table if exists has_target_result;\n" +
+//            "drop table if exists claim;\n" +
+//            "drop table if exists project;\n" +
+//            "drop table if exists result;\n" +
+//            "drop table if exists context;\n" +
+//            "\n ";
 }
\ No newline at end of file
Index: modules/uoa-claims -demo/claims-demo
===================================================================
--- modules/uoa-claims -demo/claims-demo	(revision 41790)
+++ modules/uoa-claims -demo/claims-demo	(revision 41791)

Property changes on: modules/uoa-claims -demo/claims-demo
___________________________________________________________________
Modified: svn:ignore
## -1,5 +1 ##
 uoa-claims-demo.iml
-target
-.settings
-.project
-.classpath
