2019-04-01 15:30:16 +02:00
|
|
|
|
package org.gcube.data.publishing.gCatFeeder.collectors.dm.model.ckan;
|
|
|
|
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
|
|
import org.gcube.data.publishing.gCatFeeder.collectors.dm.model.InternalAlgorithmDescriptor;
|
|
|
|
|
import org.gcube.data.publishing.gCatFeeder.model.CatalogueFormatData;
|
|
|
|
|
import org.gcube.data.publishing.gCatFeeder.model.InternalConversionException;
|
|
|
|
|
import org.gcube.data.publishing.gCatFeeder.utils.ContextUtils;
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
|
|
|
|
|
import lombok.Getter;
|
|
|
|
|
import lombok.NoArgsConstructor;
|
|
|
|
|
import lombok.Setter;
|
|
|
|
|
|
|
|
|
|
@NoArgsConstructor
|
|
|
|
|
@Getter
|
|
|
|
|
@Setter
|
|
|
|
|
public class GCatModel implements CatalogueFormatData {
|
|
|
|
|
|
|
|
|
|
private static ObjectMapper mapper=new ObjectMapper();
|
|
|
|
|
|
|
|
|
|
private static String profileXML=null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void setProfile(String toSet) {
|
|
|
|
|
profileXML=toSet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public GCatModel(InternalAlgorithmDescriptor desc) {
|
|
|
|
|
item=new CkanItem();
|
2019-04-01 16:23:05 +02:00
|
|
|
|
item.setAuthor(desc.getAuthor());
|
2019-04-01 15:30:16 +02:00
|
|
|
|
item.setDescription(desc.getDescription());
|
|
|
|
|
item.setTitle(desc.getName()+" in "+ContextUtils.getCurrentScopeName());
|
|
|
|
|
item.setLicense("CC-BY-NC-SA-4.0");
|
2019-04-01 16:23:05 +02:00
|
|
|
|
item.setMaintainer(desc.getMaintainer());
|
2019-04-01 15:30:16 +02:00
|
|
|
|
item.setName(item.getTitle().toLowerCase().toLowerCase().replaceAll(" ", "_"));
|
|
|
|
|
for(String tag:desc.getTags()) {
|
|
|
|
|
item.getTags().add(fixTag(tag));
|
|
|
|
|
}
|
|
|
|
|
item.getExtras().add(new CKanExtraField("system", "Algorithm"));
|
2019-04-01 16:23:05 +02:00
|
|
|
|
|
|
|
|
|
// TODO ADD PARAMETERS
|
|
|
|
|
|
|
|
|
|
// TODO ADD RESOURCES
|
|
|
|
|
|
2019-04-01 15:30:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String profile=profileXML;
|
|
|
|
|
|
|
|
|
|
private CkanItem item=null;
|
|
|
|
|
private ArrayList<CkanResource> resources=new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String toCatalogueFormat() throws InternalConversionException {
|
|
|
|
|
try{
|
|
|
|
|
ByteArrayOutputStream baos=new ByteArrayOutputStream();
|
|
|
|
|
mapper.writeValue(baos, this);
|
|
|
|
|
return baos.toString();
|
|
|
|
|
}catch(Throwable t) {
|
|
|
|
|
throw new InternalConversionException("Unable to convert",t);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* (Common) Title
|
|
|
|
|
* (Common) Description
|
|
|
|
|
* (Common) Tags: free list of keywords
|
|
|
|
|
* (Common) License
|
|
|
|
|
* (Common) Visibility: either public or private
|
|
|
|
|
* (Common) Version
|
|
|
|
|
* (Common) Author: the creator of metadata. Only one occurrence is supported;
|
|
|
|
|
* (Common) Maintainer:
|
|
|
|
|
* (Method specific) Creator: the author of the method (with email and ORCID). Repeatable field;
|
|
|
|
|
* (Method specific) Creation date: when the method has been released;
|
|
|
|
|
* (Method specific) Input: Repeatable field;
|
|
|
|
|
* (Method specific) Output: Repeatable field;
|
|
|
|
|
* (Method specific) RelatedPaper: a reference to an associated paper;
|
|
|
|
|
* (Method specific) Restrictions On Use: an optional text
|
|
|
|
|
* (Method specific) Attribution requirements: the text to use to acknowledge method usage;
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static final String fixTag(String toFix) {
|
|
|
|
|
String fixedTag=toFix.replaceAll(":", " ").
|
|
|
|
|
replaceAll("[\\(\\)\\\\/]", "-").replaceAll("[’']","_");
|
|
|
|
|
if(fixedTag.length()>100)
|
|
|
|
|
fixedTag=fixedTag.substring(0,96)+"...";
|
|
|
|
|
return fixedTag.trim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|