information-system-model-do.../src/main/java/org/gcube/informationsystem/utils/documentation/model/relations/RelationDocumentationGenera...

81 lines
2.8 KiB
Java
Raw Normal View History

2023-01-19 18:37:12 +01:00
package org.gcube.informationsystem.utils.documentation.model.relations;
2023-01-20 17:49:41 +01:00
import java.util.Set;
2023-01-20 16:44:56 +01:00
import org.gcube.informationsystem.base.reference.AccessType;
2023-01-19 18:37:12 +01:00
import org.gcube.informationsystem.base.reference.relations.RelationElement;
import org.gcube.informationsystem.types.TypeMapper;
2023-01-20 10:27:07 +01:00
import org.gcube.informationsystem.types.reference.Type;
2023-01-20 17:49:41 +01:00
import org.gcube.informationsystem.types.reference.entities.EntityType;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
import org.gcube.informationsystem.types.reference.relations.RelationType;
2023-01-19 18:37:12 +01:00
import org.gcube.informationsystem.utils.documentation.model.DocumentationGenerator;
2023-01-20 17:49:41 +01:00
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;
2023-01-19 18:37:12 +01:00
import org.gcube.informationsystem.utils.documentation.rst.table.Table;
/**
* @author Luca Frosini (ISTI - CNR)
*/
2023-01-20 10:27:07 +01:00
public class RelationDocumentationGenerator extends DocumentationGenerator {
2023-01-19 18:37:12 +01:00
2023-01-20 10:27:07 +01:00
public RelationDocumentationGenerator(Type type) {
2023-01-22 19:44:32 +01:00
super(type, AccessType.RELATION);
this.superClassToBeExcluded = TypeMapper.getType(RelationElement.class);
setLevel(0);
2023-01-19 18:37:12 +01:00
}
2023-01-20 16:44:56 +01:00
protected RelationDocumentationGenerator(Type type, AccessType requiredType) {
super(type, requiredType);
}
2023-01-19 18:37:12 +01:00
2023-01-20 17:49:41 +01:00
protected Row getTypeDefinitionRow(RelationType<? extends EntityType, ? extends EntityType> relationType) {
Row row = new Row(RowType.NORMAL);
Cell source = new Cell();
source.setText(relationType.getSource().getName());
row.appendCell(source);
Cell relation = new Cell();
relation.setText(relationType.getName());
row.appendCell(relation);
Cell multiplicity = new Cell();
multiplicity.setText("0..n");
row.appendCell(multiplicity);
Cell target = new Cell();
target.setText(relationType.getTarget().getName());
row.appendCell(target);
Cell description = new Cell();
description.setText(relationType.getDescription());
row.appendCell(description);
for(int i=row.getCells().size(); i<requiredNumberOfColumns; i++) {
row.appendCell(description);
}
return row;
}
2023-01-19 18:37:12 +01:00
@Override
protected Table getTable() {
Table table = new Table();
2023-01-22 19:44:32 +01:00
table.appendRow(getHeadingRowCellSpan("**Definition**", requiredNumberOfColumns));
2023-01-20 17:49:41 +01:00
2023-01-22 19:44:32 +01:00
table.appendRow(getSourceTargetBoldRow());
2023-01-20 17:49:41 +01:00
@SuppressWarnings("unchecked")
RelationType<? extends EntityType, ? extends EntityType> relationType = (RelationType<? extends EntityType, ? extends EntityType>) type;
table.appendRow(getTypeDefinitionRow(relationType));
2023-01-22 19:44:32 +01:00
table.appendRow(getRowCellSpan("**Properties**", requiredNumberOfColumns));
2023-01-20 17:49:41 +01:00
Set<PropertyDefinition> properties = type.getProperties();
table = addPropertyRows(table, properties);
2023-01-20 16:44:56 +01:00
2023-01-19 18:37:12 +01:00
return table;
}
}