Fixed version
This commit is contained in:
parent
2b976a081e
commit
aaa72ee15d
|
@ -4,15 +4,15 @@
|
|||
<parent>
|
||||
<groupId>org.gcube.data-publishing.gCat-Feeder</groupId>
|
||||
<artifactId>gCat-Feeder-Suite</artifactId>
|
||||
<version>1.0.1</version>
|
||||
<version>${gFeedSuiteVersion}</version>
|
||||
</parent>
|
||||
<artifactId>DataMinerAlgorithmsCrawler</artifactId>
|
||||
<name>DataMinerAlgorithmsCrawler</name>
|
||||
<description>Plugin for gCat-Feeder for DataMiner Algorithms publishing</description>
|
||||
|
||||
<properties>
|
||||
<gitBaseUrl>https://code-repo.d4science.org/gCubeSystem</gitBaseUrl>
|
||||
</properties>
|
||||
<!-- <properties> -->
|
||||
<!-- <gitBaseUrl>https://code-repo.d4science.org/gCubeSystem</gitBaseUrl> -->
|
||||
<!-- </properties> -->
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:${gitBaseUrl}/gFeed</connection>
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
<parent>
|
||||
<groupId>org.gcube.data-publishing.gCat-Feeder</groupId>
|
||||
<artifactId>gCat-Feeder-Suite</artifactId>
|
||||
<version>1.0.1</version>
|
||||
<version>${gFeedSuiteVersion}</version>
|
||||
</parent>
|
||||
<artifactId>catalogue-plugin-framework</artifactId>
|
||||
<properties>
|
||||
<gitBaseUrl>https://code-repo.d4science.org/gCubeSystem</gitBaseUrl>
|
||||
</properties>
|
||||
<!-- <properties> -->
|
||||
<!-- <gitBaseUrl>https://code-repo.d4science.org/gCubeSystem</gitBaseUrl> -->
|
||||
<!-- </properties> -->
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:${gitBaseUrl}/gFeed</connection>
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
<parent>
|
||||
<groupId>org.gcube.data-publishing.gCat-Feeder</groupId>
|
||||
<artifactId>gCat-Feeder-Suite</artifactId>
|
||||
<version>1.0.1</version>
|
||||
<version>${gFeedSuiteVersion}</version>
|
||||
</parent>
|
||||
<artifactId>collectors-plugin-framework</artifactId>
|
||||
<name>collectors-plugin-framework</name>
|
||||
<description>Framework for collectors implementations</description>
|
||||
<properties>
|
||||
<gitBaseUrl>https://code-repo.d4science.org/gCubeSystem</gitBaseUrl>
|
||||
</properties>
|
||||
<!-- <properties> -->
|
||||
<!-- <gitBaseUrl>https://code-repo.d4science.org/gCubeSystem</gitBaseUrl> -->
|
||||
<!-- </properties> -->
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:${gitBaseUrl}/gFeed</connection>
|
||||
|
|
|
@ -4,15 +4,15 @@
|
|||
<parent>
|
||||
<groupId>org.gcube.data-publishing.gCat-Feeder</groupId>
|
||||
<artifactId>gCat-Feeder-Suite</artifactId>
|
||||
<version>1.0.1</version>
|
||||
<version>${gFeedSuiteVersion}</version>
|
||||
</parent>
|
||||
<artifactId>commons</artifactId>
|
||||
<name>commons</name>
|
||||
<description>Common utilities for gCatFeeder logic</description>
|
||||
|
||||
<properties>
|
||||
<gitBaseUrl>https://code-repo.d4science.org/gCubeSystem</gitBaseUrl>
|
||||
</properties>
|
||||
<!-- <properties> -->
|
||||
<!-- <gitBaseUrl>https://code-repo.d4science.org/gCubeSystem</gitBaseUrl> -->
|
||||
<!-- </properties> -->
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:${gitBaseUrl}/gFeed</connection>
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
<parent>
|
||||
<groupId>org.gcube.data-publishing.gCat-Feeder</groupId>
|
||||
<artifactId>gCat-Feeder-Suite</artifactId>
|
||||
<version>1.0.1</version>
|
||||
<version>${gFeedSuiteVersion}</version>
|
||||
</parent>
|
||||
<artifactId>gCat-Controller</artifactId>
|
||||
<name>gCat Controller</name>
|
||||
<description>Controller implementation for GCat Service</description>
|
||||
<properties>
|
||||
<gitBaseUrl>https://code-repo.d4science.org/gCubeSystem</gitBaseUrl>
|
||||
</properties>
|
||||
<!-- <properties> -->
|
||||
<!-- <gitBaseUrl>https://code-repo.d4science.org/gCubeSystem</gitBaseUrl> -->
|
||||
<!-- </properties> -->
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:${gitBaseUrl}/gFeed</connection>
|
||||
|
|
|
@ -79,6 +79,12 @@ public class Interactions extends BaseCataloguePluginTest{
|
|||
publish(getController(),"full-algorithm.json");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOAI() throws CatalogueInteractionException, WrongObjectFormatException, PublicationException, InternalConversionException, ControllerInstantiationFault {
|
||||
Assume.assumeTrue(isTestInfrastructureEnabled());
|
||||
publish(getController(),"oai_dc_full.json");
|
||||
}
|
||||
|
||||
@Test(expected=WrongObjectFormatException.class)
|
||||
public void empties() throws CatalogueInteractionException, WrongObjectFormatException, PublicationException, ControllerInstantiationFault, InternalConversionException {
|
||||
Assume.assumeTrue(isTestInfrastructureEnabled());
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<parent>
|
||||
<groupId>org.gcube.data-publishing.gCat-Feeder</groupId>
|
||||
<artifactId>gCat-Feeder-Suite</artifactId>
|
||||
<version>1.0.1</version>
|
||||
<version>${gFeedSuiteVersion}</version>
|
||||
</parent>
|
||||
<artifactId>gCat-Feeder</artifactId>
|
||||
<name>gCat-Feeder</name>
|
||||
|
@ -13,7 +13,7 @@
|
|||
<properties>
|
||||
<webappDirectory>${project.basedir}/src/main/webapp/WEB-INF</webappDirectory>
|
||||
<distroDirectory>${project.basedir}/distro</distroDirectory>
|
||||
<gitBaseUrl>https://code-repo.d4science.org/gCubeSystem</gitBaseUrl>
|
||||
<!-- <gitBaseUrl>https://code-repo.d4science.org/gCubeSystem</gitBaseUrl> -->
|
||||
</properties>
|
||||
|
||||
<scm>
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
<parent>
|
||||
<groupId>org.gcube.data-publishing.gCat-Feeder</groupId>
|
||||
<artifactId>gCat-Feeder-Suite</artifactId>
|
||||
<version>1.0.1</version>
|
||||
<version>${gFeedSuiteVersion}</version>
|
||||
</parent>
|
||||
<artifactId>oai-harvester</artifactId>
|
||||
<name>oai-harvester</name>
|
||||
|
||||
<properties>
|
||||
<gitBaseUrl>https://code-repo.d4science.org/gCubeSystem</gitBaseUrl>
|
||||
</properties>
|
||||
<!-- <properties> -->
|
||||
<!-- <gitBaseUrl>https://code-repo.d4science.org/gCubeSystem</gitBaseUrl> -->
|
||||
<!-- </properties> -->
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:${gitBaseUrl}/gFeed</connection>
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.gcube.data.publishing.gFeed.collectors.oai.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
|
@ -23,37 +25,37 @@ public class DCRecordMetadata extends OAIMetadata{
|
|||
public static final String NS="http://purl.org/dc/elements/1.1/";
|
||||
|
||||
@XmlElement(namespace=NS)
|
||||
private String contributor;
|
||||
private List<String> contributor;
|
||||
@XmlElement(namespace=NS)
|
||||
private String coverage;
|
||||
private List<String> coverage;
|
||||
@XmlElement(namespace=NS)
|
||||
private String creator;
|
||||
private List<String> creator;
|
||||
@XmlElement(namespace=NS)
|
||||
private String date;
|
||||
private List<String> date;
|
||||
@XmlElement(namespace=NS)
|
||||
private String description;
|
||||
private List<String> description;
|
||||
@XmlElement(namespace=NS)
|
||||
private String format;
|
||||
private List<String> format;
|
||||
@XmlElement(namespace=NS)
|
||||
private String identifier;
|
||||
private List<String> identifier;
|
||||
@XmlElement(namespace=NS)
|
||||
private String language;
|
||||
private List<String> language;
|
||||
@XmlElement(namespace=NS)
|
||||
private String publisher;
|
||||
private List<String> publisher;
|
||||
|
||||
@XmlElement(namespace=NS)
|
||||
private String relation;
|
||||
private List<String> relation;
|
||||
@XmlElement(namespace=NS)
|
||||
private String rights;
|
||||
private List<String> rights;
|
||||
@XmlElement(namespace=NS)
|
||||
private String source;
|
||||
private List<String> source;
|
||||
@XmlElement(namespace=NS)
|
||||
private String subject;
|
||||
private List<String> subject;
|
||||
|
||||
@XmlElement(namespace=NS)
|
||||
private String title;
|
||||
private List<String> title;
|
||||
@XmlElement(namespace=NS)
|
||||
private String type;
|
||||
private List<String> type;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -37,12 +37,15 @@ public class GCatModel implements CatalogueFormatData {
|
|||
private static ObjectMapper mapper=new ObjectMapper();
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
private String profile=null;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
private CkanItem item;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
private ArrayList<CkanResource> resources=new ArrayList<>();
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.nio.charset.Charset;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.data.publishing.gCatFeeder.utils.Files;
|
||||
|
@ -13,6 +14,7 @@ import org.gcube.data.publishing.gFeed.collectors.oai.model.DCRecordMetadata;
|
|||
import org.gcube.data.publishing.gFeed.collectors.oai.model.OAIMetadata;
|
||||
import org.gcube.data.publishing.gFeed.collectors.oai.model.OAIRecord;
|
||||
import org.gcube.data.publishing.gFeed.collectors.oai.model.ckan.CkanItem.CKanExtraField;
|
||||
import org.gcube.data.publishing.gFeed.collectors.oai.model.ckan.CkanItem.Tag;
|
||||
import org.gcube.data.publishing.gFeed.collectors.oai.model.ckan.GCatModel.CkanResource;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -59,66 +61,65 @@ public class GCatTransformer implements DataTransformer<GCatModel,OAIRecord>{
|
|||
GCatModel toReturn = new GCatModel();
|
||||
|
||||
CkanItem item=new CkanItem();
|
||||
|
||||
item.setName(toTranslate.getHeader().getIdentifier());
|
||||
//escaping name chars
|
||||
String toSetName=toTranslate.getHeader().getIdentifier();
|
||||
toSetName=toSetName.replaceAll("[^a-z0-9_\\\\-]", "_");
|
||||
item.setName(toSetName);
|
||||
OAIMetadata meta=toTranslate.getMetadata().getMetadata();
|
||||
if(meta instanceof DCRecordMetadata) {
|
||||
String profileID="Harvested Object";
|
||||
|
||||
DCRecordMetadata dcMeta=(DCRecordMetadata) meta;
|
||||
|
||||
item.setTitle(dcMeta.getTitle());
|
||||
item.setNotes(dcMeta.getDescription());
|
||||
item.setAuthor(dcMeta.getPublisher());
|
||||
item.setMaintainer(dcMeta.getPublisher());
|
||||
item.setTitle(getFirstOrDefault(dcMeta.getTitle(),"n.a."));
|
||||
item.setNotes(getFirstOrDefault(dcMeta.getDescription(),null));
|
||||
item.setAuthor(getFirstOrDefault(dcMeta.getPublisher(),"n.a."));
|
||||
item.setMaintainer(getFirstOrDefault(dcMeta.getPublisher(),null));
|
||||
item.setVersion("n.a.");
|
||||
item.setPrivateFlag(false);
|
||||
item.setLicense_id("CC-BY-NC-SA-4.0");
|
||||
|
||||
|
||||
if(dcMeta.getSubject()!=null&&dcMeta.getSubject().isEmpty())
|
||||
for(String subject:dcMeta.getSubject())
|
||||
item.getTags().add(new Tag(subject));
|
||||
|
||||
item.getTags().add(new Tag("OAI"));
|
||||
|
||||
item.getExtras().add(new CKanExtraField("system:type", profileID));
|
||||
|
||||
if(dcMeta.getContributor()!=null)
|
||||
item.getExtras().add(new CKanExtraField(profileID+":contributor", dcMeta.getContributor()));
|
||||
if(dcMeta.getCoverage()!=null)
|
||||
item.getExtras().add(new CKanExtraField(profileID+":coverage", dcMeta.getCoverage()));
|
||||
if(dcMeta.getCreator()!=null)
|
||||
item.getExtras().add(new CKanExtraField(profileID+":creator", dcMeta.getCreator()));
|
||||
if(dcMeta.getDate()!=null)
|
||||
item.getExtras().add(new CKanExtraField(profileID+":date", dcMeta.getDate()));
|
||||
if(dcMeta.getDescription()!=null)
|
||||
item.getExtras().add(new CKanExtraField(profileID+":description", dcMeta.getDescription()));
|
||||
if(dcMeta.getFormat()!=null)
|
||||
item.getExtras().add(new CKanExtraField(profileID+":format", dcMeta.getFormat()));
|
||||
if(dcMeta.getIdentifier()!=null)
|
||||
item.getExtras().add(new CKanExtraField(profileID+":identifier", dcMeta.getIdentifier()));
|
||||
if(dcMeta.getLanguage()!=null)
|
||||
item.getExtras().add(new CKanExtraField(profileID+":language", dcMeta.getLanguage()));
|
||||
if(dcMeta.getPublisher()!=null)
|
||||
item.getExtras().add(new CKanExtraField(profileID+":publisher", dcMeta.getPublisher()));
|
||||
if(dcMeta.getRelation()!=null)
|
||||
item.getExtras().add(new CKanExtraField(profileID+":relation", dcMeta.getRelation()));
|
||||
if(dcMeta.getRights()!=null)
|
||||
item.getExtras().add(new CKanExtraField(profileID+":rights", dcMeta.getRights()));
|
||||
if(dcMeta.getSource()!=null)
|
||||
item.getExtras().add(new CKanExtraField(profileID+":source", dcMeta.getSource()));
|
||||
if(dcMeta.getSubject()!=null)
|
||||
item.getExtras().add(new CKanExtraField(profileID+":subject", dcMeta.getSubject()));
|
||||
if(dcMeta.getTitle()!=null)
|
||||
item.getExtras().add(new CKanExtraField(profileID+":title", dcMeta.getTitle()));
|
||||
if(dcMeta.getType()!=null)
|
||||
item.getExtras().add(new CKanExtraField(profileID+":type", dcMeta.getType()));
|
||||
|
||||
item.getExtras().addAll(fromList(dcMeta.getContributor(),profileID+":contributor"));
|
||||
item.getExtras().addAll(fromList(dcMeta.getCoverage(),profileID+":coverage"));
|
||||
item.getExtras().addAll(fromList(dcMeta.getCreator(),profileID+":creator"));
|
||||
item.getExtras().addAll(fromList(dcMeta.getDate(),profileID+":date"));
|
||||
item.getExtras().addAll(fromList(dcMeta.getDescription(),profileID+":description"));
|
||||
item.getExtras().addAll(fromList(dcMeta.getFormat(),profileID+":format"));
|
||||
item.getExtras().addAll(fromList(dcMeta.getIdentifier(),profileID+":identifier"));
|
||||
item.getExtras().addAll(fromList(dcMeta.getLanguage(),profileID+":language"));
|
||||
item.getExtras().addAll(fromList(dcMeta.getPublisher(),profileID+":publisher"));
|
||||
item.getExtras().addAll(fromList(dcMeta.getRelation(),profileID+":relation"));
|
||||
item.getExtras().addAll(fromList(dcMeta.getRights(),profileID+":rights"));
|
||||
item.getExtras().addAll(fromList(dcMeta.getSource(),profileID+":source"));
|
||||
item.getExtras().addAll(fromList(dcMeta.getSubject(),profileID+":subject"));
|
||||
item.getExtras().addAll(fromList(dcMeta.getTitle(),profileID+":title"));
|
||||
item.getExtras().addAll(fromList(dcMeta.getType(),profileID+":type"));
|
||||
|
||||
|
||||
try {
|
||||
URL url=new URL(dcMeta.getIdentifier());
|
||||
CkanResource res=new CkanResource("Record", url+"", url.getProtocol(), "Original record");
|
||||
|
||||
if(dcMeta.getIdentifier()!=null) {
|
||||
ArrayList<CkanResource> list=new ArrayList<>();
|
||||
for(String id:dcMeta.getIdentifier()) {
|
||||
try {
|
||||
URL url=new URL(id);
|
||||
CkanResource res=new CkanResource("Record", url+"", url.getProtocol(), "Original record");
|
||||
list.add(res);
|
||||
}catch(Throwable t) {
|
||||
log.debug("Unable to set identifier "+id+"as resource ",t);
|
||||
}
|
||||
}
|
||||
toReturn.setResources(list);
|
||||
}catch(Throwable t) {
|
||||
log.debug("Unable to set identifier "+dcMeta.getIdentifier()+"as resource ",t);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
toReturn.setItem(item);
|
||||
|
@ -126,7 +127,7 @@ public class GCatTransformer implements DataTransformer<GCatModel,OAIRecord>{
|
|||
try {
|
||||
if(useProfile)
|
||||
toReturn.setProfile(Files.readFileAsString(
|
||||
Files.getFileFromResources("HarvesterObject.xml").getAbsolutePath(),
|
||||
Files.getFileFromResources("profiles/HarvestedObject.xml").getAbsolutePath(),
|
||||
Charset.defaultCharset())); //"Harvested Object”
|
||||
}catch(Throwable t) {
|
||||
log.error("Unable to set profile ",t);
|
||||
|
@ -136,4 +137,17 @@ public class GCatTransformer implements DataTransformer<GCatModel,OAIRecord>{
|
|||
}
|
||||
|
||||
|
||||
|
||||
private static Collection<CKanExtraField> fromList(List<String> values,String name){
|
||||
ArrayList<CKanExtraField> toReturn=new ArrayList<CKanExtraField>();
|
||||
if(values!=null)
|
||||
for(String v:values)
|
||||
toReturn.add(new CKanExtraField(name,v));
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
private static String getFirstOrDefault(List<String> values,String defaultValue) {
|
||||
if(values!=null && !values.isEmpty()) return values.get(0);
|
||||
else return defaultValue;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,92 +8,92 @@
|
|||
<metadataformat type="Harvested Object">
|
||||
<metadatafield categoryref="Harvested Object">
|
||||
<fieldName>contributor</fieldName>
|
||||
<maxOccurs>*</maxOccurs>
|
||||
<mandatory>false</mandatory>
|
||||
<dataType>String</dataType>
|
||||
<maxOccurs>*</maxOccurs>
|
||||
</metadatafield>
|
||||
<metadatafield categoryref="Harvested Object">
|
||||
<fieldName>coverage</fieldName>
|
||||
<maxOccurs>*</maxOccurs>
|
||||
<mandatory>false</mandatory>
|
||||
<dataType>String</dataType>
|
||||
<maxOccurs>*</maxOccurs>
|
||||
</metadatafield>
|
||||
<metadatafield categoryref="Harvested Object">
|
||||
<fieldName>creator</fieldName>
|
||||
<maxOccurs>*</maxOccurs>
|
||||
<mandatory>false</mandatory>
|
||||
<dataType>String</dataType>
|
||||
<maxOccurs>*</maxOccurs>
|
||||
</metadatafield>
|
||||
<metadatafield categoryref="Harvested Object">
|
||||
<fieldName>date</fieldName>
|
||||
<maxOccurs>*</maxOccurs>
|
||||
<mandatory>false</mandatory>
|
||||
<dataType>String</dataType>
|
||||
<maxOccurs>*</maxOccurs>
|
||||
</metadatafield>
|
||||
<metadatafield categoryref="Harvested Object">
|
||||
<fieldName>description</fieldName>
|
||||
<maxOccurs>*</maxOccurs>
|
||||
<mandatory>false</mandatory>
|
||||
<dataType>String</dataType>
|
||||
<maxOccurs>*</maxOccurs>
|
||||
</metadatafield>
|
||||
<metadatafield categoryref="Harvested Object">
|
||||
<fieldName>format</fieldName>
|
||||
<maxOccurs>*</maxOccurs>
|
||||
<mandatory>false</mandatory>
|
||||
<dataType>String</dataType>
|
||||
<maxOccurs>*</maxOccurs>
|
||||
</metadatafield>
|
||||
<metadatafield categoryref="Harvested Object">
|
||||
<fieldName>identifier</fieldName>
|
||||
<maxOccurs>*</maxOccurs>
|
||||
<mandatory>false</mandatory>
|
||||
<dataType>String</dataType>
|
||||
<maxOccurs>*</maxOccurs>
|
||||
</metadatafield>
|
||||
<metadatafield categoryref="Harvested Object">
|
||||
<fieldName>language</fieldName>
|
||||
<maxOccurs>*</maxOccurs>
|
||||
<mandatory>false</mandatory>
|
||||
<dataType>String</dataType>
|
||||
<maxOccurs>*</maxOccurs>
|
||||
</metadatafield>
|
||||
<metadatafield categoryref="Harvested Object">
|
||||
<fieldName>publisher</fieldName>
|
||||
<maxOccurs>*</maxOccurs>
|
||||
<mandatory>false</mandatory>
|
||||
<dataType>String</dataType>
|
||||
<maxOccurs>*</maxOccurs>
|
||||
</metadatafield>
|
||||
<metadatafield categoryref="Harvested Object">
|
||||
<fieldName>relation</fieldName>
|
||||
<maxOccurs>*</maxOccurs>
|
||||
<mandatory>false</mandatory>
|
||||
<dataType>String</dataType>
|
||||
<maxOccurs>*</maxOccurs>
|
||||
</metadatafield>
|
||||
<metadatafield categoryref="Harvested Object">
|
||||
<fieldName>rights</fieldName>
|
||||
<maxOccurs>*</maxOccurs>
|
||||
<mandatory>false</mandatory>
|
||||
<dataType>String</dataType>
|
||||
<maxOccurs>*</maxOccurs>
|
||||
</metadatafield>
|
||||
<metadatafield categoryref="Harvested Object">
|
||||
<fieldName>source</fieldName>
|
||||
<maxOccurs>*</maxOccurs>
|
||||
<mandatory>false</mandatory>
|
||||
<dataType>String</dataType>
|
||||
<maxOccurs>*</maxOccurs>
|
||||
</metadatafield>
|
||||
<metadatafield categoryref="Harvested Object">
|
||||
<fieldName>subject</fieldName>
|
||||
<maxOccurs>*</maxOccurs>
|
||||
<mandatory>false</mandatory>
|
||||
<dataType>String</dataType>
|
||||
<maxOccurs>*</maxOccurs>
|
||||
</metadatafield>
|
||||
<metadatafield categoryref="Harvested Object">
|
||||
<fieldName>title</fieldName>
|
||||
<maxOccurs>*</maxOccurs>
|
||||
<mandatory>false</mandatory>
|
||||
<dataType>String</dataType>
|
||||
<maxOccurs>*</maxOccurs>
|
||||
</metadatafield>
|
||||
<metadatafield categoryref="Harvested Object">
|
||||
<fieldName>type</fieldName>
|
||||
<maxOccurs>*</maxOccurs>
|
||||
<mandatory>false</mandatory>
|
||||
<dataType>String</dataType>
|
||||
<maxOccurs>*</maxOccurs>
|
||||
</metadatafield>
|
||||
</metadataformat>
|
|
@ -1,11 +1,23 @@
|
|||
package org.gcube.application.gfeed.oai;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
import org.gcube.data.publishing.gCatFeeder.model.InternalConversionException;
|
||||
import org.gcube.data.publishing.gCatFeeder.tests.TokenSetter;
|
||||
import org.gcube.data.publishing.gCatFeeder.utils.Files;
|
||||
import org.gcube.data.publishing.gFeed.collectors.oai.model.DCRecordMetadata;
|
||||
import org.gcube.data.publishing.gFeed.collectors.oai.model.MetadataHolder;
|
||||
import org.gcube.data.publishing.gFeed.collectors.oai.model.OAIMetadata;
|
||||
import org.gcube.data.publishing.gFeed.collectors.oai.model.OAIRecord;
|
||||
import org.gcube.data.publishing.gFeed.collectors.oai.model.OAI_PMH;
|
||||
import org.gcube.data.publishing.gFeed.collectors.oai.model.ckan.GCatModel;
|
||||
import org.gcube.data.publishing.gFeed.collectors.oai.model.ckan.GCatTransformer;
|
||||
import org.gcube.gcat.client.Item;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
@ -14,9 +26,27 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||
public class CKANTest {
|
||||
|
||||
|
||||
public static void main (String args[]) {
|
||||
TokenSetter.set("/pred4s/preprod/preVRE");
|
||||
|
||||
public static void main (String args[]) throws JAXBException {
|
||||
// TokenSetter.set("/pred4s/preprod/preVRE");
|
||||
//
|
||||
//
|
||||
// File toRead=Files.getFileFromResources("resp_dc.xml");
|
||||
//
|
||||
// JAXBContext jaxbContext = JAXBContext.newInstance(OAIRecord.class,
|
||||
// MetadataHolder.class,
|
||||
// OAIMetadata.class,
|
||||
// DCRecordMetadata.class,
|
||||
// OAI_PMH.class);
|
||||
//
|
||||
// Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
|
||||
//
|
||||
// OAI_PMH response = (OAI_PMH) jaxbUnmarshaller.unmarshal(toRead);
|
||||
//
|
||||
// for(GCatModel gcat: new GCatTransformer().transform(response.getResponseRecords().getRecords())) {
|
||||
// if(gcat.)
|
||||
// }
|
||||
//
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -4,19 +4,21 @@ import static org.junit.Assert.assertTrue;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Paths;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
import org.gcube.data.publishing.gCatFeeder.model.InternalConversionException;
|
||||
import org.gcube.data.publishing.gCatFeeder.utils.Files;
|
||||
import org.gcube.data.publishing.gFeed.collectors.oai.model.DCRecordMetadata;
|
||||
import org.gcube.data.publishing.gFeed.collectors.oai.model.MetadataHolder;
|
||||
import org.gcube.data.publishing.gFeed.collectors.oai.model.OAIMetadata;
|
||||
import org.gcube.data.publishing.gFeed.collectors.oai.model.OAIRecord;
|
||||
import org.gcube.data.publishing.gFeed.collectors.oai.model.OAI_PMH;
|
||||
import org.gcube.data.publishing.gFeed.collectors.oai.model.ckan.GCatModel;
|
||||
import org.gcube.data.publishing.gFeed.collectors.oai.model.ckan.GCatTransformer;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
@ -40,12 +42,8 @@ public class ParsingTests {
|
|||
|
||||
@Test
|
||||
public void parseDC() throws JAXBException {
|
||||
File toRead=getFileFromResources("resp_dc.xml");
|
||||
|
||||
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
|
||||
|
||||
OAI_PMH response = (OAI_PMH) jaxbUnmarshaller.unmarshal(toRead);
|
||||
|
||||
OAI_PMH response=read();
|
||||
Assert.assertNotNull(response);
|
||||
Assert.assertNotNull(response.getResponseRecords().getRecords());
|
||||
|
||||
|
@ -61,29 +59,27 @@ public class ParsingTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void marshal() throws JAXBException {
|
||||
// jaxbContext.createMarshaller().marshal(new OAI_PMH("dummy"),System.out);
|
||||
public void marshal() throws JAXBException, InternalConversionException, IOException {
|
||||
OAI_PMH resp=read();
|
||||
File outF=File.createTempFile("json", ".json");
|
||||
PrintWriter out = new PrintWriter(outF);
|
||||
for(GCatModel gcat: new GCatTransformer().transform(resp.getResponseRecords().getRecords())) {
|
||||
Assert.assertNotNull(gcat.getResources());
|
||||
Assert.assertFalse(gcat.getResources().isEmpty());
|
||||
out.println(gcat.toCatalogueFormat());
|
||||
}
|
||||
out.flush();
|
||||
out.close();
|
||||
System.out.println("Output at "+outF.getAbsolutePath());
|
||||
}
|
||||
|
||||
|
||||
public static File getFileFromResources(String fileName) {
|
||||
|
||||
ClassLoader classLoader =ParsingTests.class.getClassLoader();
|
||||
|
||||
URL resource = classLoader.getResource(fileName);
|
||||
if (resource == null) {
|
||||
throw new IllegalArgumentException("file is not found!");
|
||||
} else {
|
||||
return new File(resource.getFile());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static String readFileAsString(String path, Charset encoding)
|
||||
throws IOException
|
||||
{
|
||||
byte[] encoded = java.nio.file.Files.readAllBytes(Paths.get(path));
|
||||
return new String(encoded, encoding);
|
||||
private OAI_PMH read() throws JAXBException {
|
||||
File toRead=Files.getFileFromResources("resp_dc.xml");
|
||||
|
||||
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
|
||||
|
||||
return (OAI_PMH) jaxbUnmarshaller.unmarshal(toRead);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
3
pom.xml
3
pom.xml
|
@ -8,7 +8,7 @@
|
|||
</parent>
|
||||
<groupId>org.gcube.data-publishing.gCat-Feeder</groupId>
|
||||
<artifactId>gCat-Feeder-Suite</artifactId>
|
||||
<version>1.0.1</version>
|
||||
<version>${gFeedSuiteVersion}</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>gCat-Feeder Suite</name>
|
||||
<description>gCat-Feeder Suite of components : service, plugin framework, plugins</description>
|
||||
|
@ -17,6 +17,7 @@
|
|||
<properties>
|
||||
<distroDirectory>distro</distroDirectory>
|
||||
<gitBaseUrl>https://code-repo.d4science.org/gCubeSystem</gitBaseUrl>
|
||||
<gFeedSuiteVersion>1.0.2-SNAPSHOT</gFeedSuiteVersion>
|
||||
</properties>
|
||||
|
||||
<scm>
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
<parent>
|
||||
<groupId>org.gcube.data-publishing.gCat-Feeder</groupId>
|
||||
<artifactId>gCat-Feeder-Suite</artifactId>
|
||||
<version>1.0.1</version>
|
||||
<version>${gFeedSuiteVersion}</version>
|
||||
</parent>
|
||||
<artifactId>test-commons</artifactId>
|
||||
<name>test commons</name>
|
||||
<description>Utility classes for test purposes</description>
|
||||
<properties>
|
||||
<gitBaseUrl>https://code-repo.d4science.org/gCubeSystem</gitBaseUrl>
|
||||
</properties>
|
||||
<!-- <properties> -->
|
||||
<!-- <gitBaseUrl>https://code-repo.d4science.org/gCubeSystem</gitBaseUrl> -->
|
||||
<!-- </properties> -->
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:${gitBaseUrl}/gFeed</connection>
|
||||
|
|
Loading…
Reference in New Issue