98 lines
2.9 KiB
Java
98 lines
2.9 KiB
Java
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();
|
||
item.setAuthor(desc.getAuthor());
|
||
item.setDescription(desc.getDescription());
|
||
item.setTitle(desc.getName()+" in "+ContextUtils.getCurrentScopeName());
|
||
item.setLicense("CC-BY-NC-SA-4.0");
|
||
item.setMaintainer(desc.getMaintainer());
|
||
item.setName(item.getTitle().toLowerCase().toLowerCase().replaceAll(" ", "_"));
|
||
for(String tag:desc.getTags()) {
|
||
item.getTags().add(fixTag(tag));
|
||
}
|
||
item.getExtras().add(new CKanExtraField("system", "Algorithm"));
|
||
|
||
// TODO ADD PARAMETERS
|
||
|
||
// TODO ADD RESOURCES
|
||
|
||
}
|
||
|
||
|
||
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();
|
||
}
|
||
|
||
|
||
}
|