information-system-model/src/main/java/org/gcube/informationsystem/queries/templates/impl/entities/QueryTemplateImpl.java

91 lines
2.2 KiB
Java

package org.gcube.informationsystem.queries.templates.impl.entities;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
import org.gcube.informationsystem.base.impl.entities.EntityElementImpl;
import org.gcube.informationsystem.queries.templates.reference.entities.QueryTemplate;
import org.gcube.informationsystem.queries.templates.reference.properties.TemplateVariable;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=QueryTemplate.NAME)
public class QueryTemplateImpl extends EntityElementImpl implements QueryTemplate {
/**
* Generated Serial version UID
*/
private static final long serialVersionUID = -1096809036997782113L;
protected String name;
protected String description;
protected ObjectMapper objectMapper;
protected JsonNode template;
protected Map<String, TemplateVariable> templateVariables;
public QueryTemplateImpl() {
this.templateVariables = new HashMap<>();
this.objectMapper = new ObjectMapper();
}
@Override
public String getName() {
return name;
}
@Override
public void setName(String name) {
this.name = name;
}
@Override
public String getDescription() {
return description;
}
@Override
public void setDescription(String description) {
this.description = description;
}
@Override
public String getTemplateAsString() throws JsonProcessingException {
return objectMapper.writeValueAsString(template);
}
@Override
public void setTemplate(String template) throws JsonProcessingException, IOException {
this.template = objectMapper.readTree(template);
}
@Override
public JsonNode getTemplate() {
return template;
}
@Override
public void setTemplate(JsonNode template) {
this.template = template;
}
@Override
public Map<String, TemplateVariable> getTemplateVariables() {
return templateVariables;
}
@Override
public void addTemplateVariable(TemplateVariable templateVariable) {
String name = templateVariable.getName();
this.templateVariables.put(name, templateVariable);
}
}