|
|
|
@ -3,11 +3,13 @@ package org.gcube.informationsystem.utils.documentation.model;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
|
import org.gcube.informationsystem.base.reference.Element;
|
|
|
|
|
import org.gcube.informationsystem.types.TypeMapper;
|
|
|
|
|
import org.gcube.informationsystem.types.reference.Type;
|
|
|
|
|
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
|
|
|
|
|
import org.gcube.informationsystem.utils.documentation.rst.Section;
|
|
|
|
|
import org.gcube.informationsystem.utils.documentation.rst.Section.SectionType;
|
|
|
|
|
import org.gcube.informationsystem.utils.documentation.rst.table.Cell;
|
|
|
|
|
import org.gcube.informationsystem.utils.documentation.rst.table.Row;
|
|
|
|
|
import org.gcube.informationsystem.utils.documentation.rst.table.RowType;
|
|
|
|
|
import org.gcube.informationsystem.utils.documentation.rst.table.Table;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
@ -15,20 +17,124 @@ import org.slf4j.LoggerFactory;
|
|
|
|
|
/**
|
|
|
|
|
* @author Luca Frosini (ISTI - CNR)
|
|
|
|
|
*/
|
|
|
|
|
public abstract class DocumentationGenerator<E extends Element> {
|
|
|
|
|
public abstract class DocumentationGenerator {
|
|
|
|
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(DocumentationGenerator.class);
|
|
|
|
|
|
|
|
|
|
protected final Class<E> clz;
|
|
|
|
|
protected final Type type;
|
|
|
|
|
protected final String superClassToBeExcluded;
|
|
|
|
|
|
|
|
|
|
protected DocumentationGenerator(Class<E> clz, String superClassToBeExcluded) {
|
|
|
|
|
this.clz = clz;
|
|
|
|
|
this.type = TypeMapper.createTypeDefinition(clz);
|
|
|
|
|
protected DocumentationGenerator(Type type, String superClassToBeExcluded) {
|
|
|
|
|
this.type = type;
|
|
|
|
|
this.superClassToBeExcluded = superClassToBeExcluded;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected Row getPropertiesBoldRow() {
|
|
|
|
|
Row row = new Row(RowType.NORMAL);
|
|
|
|
|
Cell name = new Cell();
|
|
|
|
|
name.setText("**Name**");
|
|
|
|
|
row.appendCell(name);
|
|
|
|
|
Cell type = new Cell();
|
|
|
|
|
type.setText("**Type**");
|
|
|
|
|
row.appendCell(type);
|
|
|
|
|
Cell attributes = new Cell();
|
|
|
|
|
attributes.setText("**Attributes**");
|
|
|
|
|
row.appendCell(attributes);
|
|
|
|
|
Cell description = new Cell();
|
|
|
|
|
description.setText("**Description**");
|
|
|
|
|
row.appendCell(description);
|
|
|
|
|
return row;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected Row getPropertiesHeadingRow() {
|
|
|
|
|
Row row = new Row(RowType.HEADING);
|
|
|
|
|
Cell name = new Cell();
|
|
|
|
|
name.setText("Name");
|
|
|
|
|
row.appendCell(name);
|
|
|
|
|
Cell type = new Cell();
|
|
|
|
|
type.setText("Type");
|
|
|
|
|
row.appendCell(type);
|
|
|
|
|
Cell attributes = new Cell();
|
|
|
|
|
attributes.setText("Attributes");
|
|
|
|
|
row.appendCell(attributes);
|
|
|
|
|
Cell description = new Cell();
|
|
|
|
|
description.setText("Description");
|
|
|
|
|
row.appendCell(description);
|
|
|
|
|
return row;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected String getPropertyAttributes(PropertyDefinition propertyDefinition) {
|
|
|
|
|
StringBuffer stringBuffer = new StringBuffer();
|
|
|
|
|
|
|
|
|
|
boolean mandatory = propertyDefinition.isMandatory();
|
|
|
|
|
stringBuffer.append("``Mandatory:");
|
|
|
|
|
stringBuffer.append(mandatory);
|
|
|
|
|
|
|
|
|
|
boolean readOnly = propertyDefinition.isReadonly();
|
|
|
|
|
stringBuffer.append("`` ``ReadOnly:");
|
|
|
|
|
stringBuffer.append(readOnly);
|
|
|
|
|
|
|
|
|
|
boolean notNull = propertyDefinition.isNotnull();
|
|
|
|
|
stringBuffer.append("`` ``NotNull:");
|
|
|
|
|
stringBuffer.append(notNull);
|
|
|
|
|
|
|
|
|
|
String regex = propertyDefinition.getRegexp();
|
|
|
|
|
if(regex!=null && regex.compareTo("")!=0) {
|
|
|
|
|
stringBuffer.append("`` ``Regex:");
|
|
|
|
|
stringBuffer.append(regex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Integer max = propertyDefinition.getMax();
|
|
|
|
|
if(max!=null) {
|
|
|
|
|
stringBuffer.append("`` ``Max:");
|
|
|
|
|
stringBuffer.append(max);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Integer min = propertyDefinition.getMin();
|
|
|
|
|
if(min!=null) {
|
|
|
|
|
stringBuffer.append("`` ``Min:");
|
|
|
|
|
stringBuffer.append(min);
|
|
|
|
|
}
|
|
|
|
|
stringBuffer.append("``");
|
|
|
|
|
return stringBuffer.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected Row getPropertyRow(PropertyDefinition propertyDefinition) {
|
|
|
|
|
Row row = new Row(RowType.NORMAL);
|
|
|
|
|
Cell name = new Cell();
|
|
|
|
|
name.setText(propertyDefinition.getName());
|
|
|
|
|
row.appendCell(name);
|
|
|
|
|
Cell type = new Cell();
|
|
|
|
|
type.setText(propertyDefinition.getType());
|
|
|
|
|
row.appendCell(type);
|
|
|
|
|
Cell attributes = new Cell();
|
|
|
|
|
attributes.setText(getPropertyAttributes(propertyDefinition));
|
|
|
|
|
row.appendCell(attributes);
|
|
|
|
|
Cell description = new Cell();
|
|
|
|
|
description.setText(propertyDefinition.getDescription());
|
|
|
|
|
row.appendCell(description);
|
|
|
|
|
return row;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected Row getNoPropertyRow() {
|
|
|
|
|
return getRowCellSpan("This type does not define any additional attributes.", 4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected Row addCellSpanToRow(Row row, String content, int cellSpan) {
|
|
|
|
|
Cell cellToSpan = new Cell();
|
|
|
|
|
cellToSpan.setText(content);
|
|
|
|
|
for(int i=0; i<cellSpan; i++) {
|
|
|
|
|
row.appendCell(cellToSpan);
|
|
|
|
|
}
|
|
|
|
|
return row;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected Row getRowCellSpan(String content, int cellSpan) {
|
|
|
|
|
Row row = new Row(RowType.NORMAL);
|
|
|
|
|
return addCellSpanToRow(row, content, cellSpan);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* E.g. GCubeProperty extends Property
|
|
|
|
|
*/
|
|
|
|
@ -38,7 +144,9 @@ public abstract class DocumentationGenerator<E extends Element> {
|
|
|
|
|
stringBuffer.append(type.getName());
|
|
|
|
|
stringBuffer.append("**");
|
|
|
|
|
Set<String> superClasses = type.getSuperClasses();
|
|
|
|
|
superClasses.remove(superClassToBeExcluded);
|
|
|
|
|
if(superClassToBeExcluded!=null) {
|
|
|
|
|
superClasses.remove(superClassToBeExcluded);
|
|
|
|
|
}
|
|
|
|
|
if(superClasses.size()>0){
|
|
|
|
|
stringBuffer.append(" ``extends`` ");
|
|
|
|
|
boolean first = true;
|
|
|
|
@ -84,7 +192,6 @@ public abstract class DocumentationGenerator<E extends Element> {
|
|
|
|
|
|
|
|
|
|
protected abstract Table getTable();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public StringBuffer generateSection() {
|
|
|
|
|
StringBuffer stringBuffer = new StringBuffer();
|
|
|
|
|
stringBuffer.append("\n");
|
|
|
|
|