Skip to content

Commit

Permalink
dbdoc plantuml output
Browse files Browse the repository at this point in the history
  • Loading branch information
llsand committed May 9, 2019
1 parent 9b24c56 commit e724099
Show file tree
Hide file tree
Showing 12 changed files with 255 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import de.oc.dbdoc.ant.Tableregistry;
import de.oc.dbdoc.export.DotExport;
import de.oc.dbdoc.export.DotWriterImpl;
import de.oc.dbdoc.export.PlantUmlWriterImpl;
import de.oc.dbdoc.graphdata.Graph;
import de.oc.dbdoc.graphdata.GraphForDiagram;
import de.oc.dbdoc.graphdata.GraphForSingleTable;
Expand All @@ -35,6 +36,8 @@
*/
public class Main
{
private static boolean isPlantuml;

public static class GraphRef
{
private Graph _graph;
Expand Down Expand Up @@ -109,8 +112,9 @@ public static String readFile( File pFile )

}

public static void writeDiagramsRecursive( Diagram pRootDiagram, Styles pStyles, Schema pSchema, String pHtmlOutDir, String pDotOutDir, String pTableSourcefileFolder, Tableregistry pTableregistry, boolean pIsSvg )
public static void writeDiagramsRecursive( Diagram pRootDiagram, Styles pStyles, Schema pSchema, String pHtmlOutDir, String pDotOutDir, String pTableSourcefileFolder, Tableregistry pTableregistry, boolean pIsSvg, boolean pIsPlantuml )
{
isPlantuml = pIsPlantuml;
try
{
GraphForDiagram lRootGraph = new GraphForDiagram( pRootDiagram, pStyles, null, pTableregistry );
Expand Down Expand Up @@ -216,11 +220,19 @@ public static String getNameFromLabel( String pLabel )

private static void _writeSingleGraph( GraphRef pGraphRef, Schema pSchema, String pHtmlOutDir, String pDotOutDir, String pTableSourcefileFolder, Tableregistry pTableregistry, boolean pIsSvg ) throws Exception
{
System.out.println( "writing graph: " + getFileNameForGraph( pGraphRef, pGraphRef.getGraph().getDotExecutable() ) );
_writeHTML( pHtmlOutDir, pGraphRef, pSchema, pTableSourcefileFolder, pTableregistry, pIsSvg );
FileWriter lFileWriter = new FileWriter( pDotOutDir + "/" + getFileNameForGraph( pGraphRef, pGraphRef.getGraph().getDotExecutable() ) );
new DotExport().export( pGraphRef.getGraph(), pSchema, new DotWriterImpl( lFileWriter ), pGraphRef.isOutref() );
lFileWriter.close();
if(isPlantuml){
System.out.println( "writing graph: " + getFileNameForGraph( pGraphRef, "plantuml" ) );
FileWriter lPlantUmlFileWriter = new FileWriter( pHtmlOutDir + "/" + getFileNameForGraph( pGraphRef, "plantuml" ) );
new DotExport().export( pGraphRef.getGraph(), pSchema, new PlantUmlWriterImpl( lPlantUmlFileWriter ), pGraphRef.isOutref() );
lPlantUmlFileWriter.close();
}
else {
System.out.println( "writing graph: " + getFileNameForGraph( pGraphRef, pGraphRef.getGraph().getDotExecutable() ) );
_writeHTML(pHtmlOutDir, pGraphRef, pSchema, pTableSourcefileFolder, pTableregistry, pIsSvg);
FileWriter lFileWriter = new FileWriter(pDotOutDir + "/" + getFileNameForGraph(pGraphRef, pGraphRef.getGraph().getDotExecutable()));
new DotExport().export(pGraphRef.getGraph(), pSchema, new DotWriterImpl(lFileWriter), pGraphRef.isOutref());
lFileWriter.close();
}
}

private static boolean _hasOutrefVersion( Graph pGraph, Schema pSchema )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void execute( Parameters pParameters )
Schema lSchema = new DbLoader().loadSchema( _diagram, lExtensionHandlerImpl.loadSyexModel(), _tableregistry );
lSchema.mergeAssociations();

Main.writeDiagramsRecursive( _diagram, _styles, lSchema, _outfolder, _tmpfolder, pParameters.getModelFile() + "/tables", _tableregistry, _svg );
Main.writeDiagramsRecursive( _diagram, _styles, lSchema, _outfolder, _tmpfolder, pParameters.getModelFile() + "/tables", _tableregistry, _svg, pParameters.getDbdocPlantuml() );
}
catch( Exception e )
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
package de.oc.dbdoc.export;

import java.io.PrintWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import de.oc.dbdoc.Main;
import de.oc.dbdoc.graphdata.Graph;
import de.oc.dbdoc.schemadata.Association;
import de.oc.dbdoc.schemadata.Column;
import de.oc.dbdoc.schemadata.Table;

public class PlantUmlWriterImpl implements DotWriter
{
private PrintWriter lPrintWriter;

public PlantUmlWriterImpl( Writer pWriter )
{
lPrintWriter = new PrintWriter( pWriter );
}

private void println( String pString )
{
lPrintWriter.println( pString );
}

private void print( String pString )
{
lPrintWriter.print( pString );
}

public void printHeaderStart( String pStyleForGraph )
{
println( "@startuml" );
}

public void printHeaderEnd()
{
println( "@enduml" );
}

public void printGraph( Graph pGraph, String pCommonStyle, boolean pIsOutref )
{
println( "package \""+pGraph.getLabel()+"\" {" );
println("}" );
}

public void printSubGraphStartFilled( Graph pGraph, boolean pOutRefsOnly )
{
printSubGraphStart( pGraph, "filled", pOutRefsOnly );
}

private void printSubGraphStart( Graph pGraph, String pStyle, boolean pIsOutref )
{
print( "package \""+pGraph.getLabel()+"\" " );
Map<String, String> lStyleMap = parseStyle(pGraph.getStyleForGraph());
if(lStyleMap.containsKey("package")){
print( lStyleMap.get("package") + " " );
}
println( "{" );
}

public void printSubGraphEnd()
{
println( "}" );
}

public void printSubGraphStartDashed( Graph pGraph, boolean pOutRefsOnly )
{
printSubGraphStart( pGraph, "dashed", pOutRefsOnly );
}

public void printGraphAssociation( DotExport.GraphAssociation pGraphAssociation )
{
print( Main.getNameFromLabel( pGraphAssociation.getGraphTo().getLabel() ) );
if( pGraphAssociation._bidirectional )
{
print( " - " );
}
else
{
print( " <-- " );
}
println( Main.getNameFromLabel( pGraphAssociation.getGraphFrom().getLabel() ) );
/*print( " [label=\"\", taillabel=\"\", headlabel=\"\", style=\"dashed\"" );*/
}

private Map<String,String> parseStyle(String pStyle){
Map<String,String> lReturn = new HashMap<>();

String lLastKey = null;
String lLastValue = null;

String[] lStyles = pStyle.split(",");
for( int i=0;i<lStyles.length;i++ ) {
String lStyle =lStyles[i];
String lName ;
String lValue;

if(lStyle.contains("=")) {
lName = lStyle.split("=")[0];
lValue = lStyle.substring(lName.length() + 1, lStyle.length());
lLastValue = lValue;
}
else {
lName = lLastKey;
lValue = lLastValue +","+ lStyle;
}
lLastKey = lName;
lReturn.put(lName,lValue.substring(1,lValue.length()-1));
}

return lReturn;
}

public void printTable( Table pTable, List<Association> pVisibleAssociation, boolean pIsOutref, String pStyle, List<Column> pFilteredColumns )
{
print("class "+ pTable.getName() );
Map<String, String> lStyleMap = parseStyle(pStyle);
if(lStyleMap.containsKey("class")){
print( " " + lStyleMap.get("class") );
}

println( " {" );

boolean lColumnsFiltered = pFilteredColumns.size() != pTable.getColumns().size();

Iterator<Column> lColumnIterator = pFilteredColumns.iterator();
while( lColumnIterator.hasNext() )
{
Column lColumn = lColumnIterator.next();

print( lColumn.getColumnType() );
print( " " );
println( lColumn.getColumnName() );
}

if( lColumnsFiltered )
{
println( "\"...\"" );
}

println( "}" );
}

public void printAssociation( Association pAssociation, Graph pGraph ) {
print(pAssociation.getTableTo().getName());
if (pAssociation.getMultiplicityTextTo().length() > 0) {
print(" \"" + pAssociation.getMultiplicityTextTo() + "\" ");
}
if(pAssociation.isDirected()) {
print(" <-- ");
} else {
print(" - ");
}
if (pAssociation.getMultiplicityTextFrom().length() > 0){
print(" \"" + pAssociation.getMultiplicityTextFrom() + "\" ");
}
print( pAssociation.getTableFrom().getName() );
if( pAssociation.getAssociationName().length() <= 20 )
{
print( " : "+ pAssociation.getAssociationName() );
}
println("");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public Schema loadSchema( Diagram pRootDiagram, Model pModel, Tableregistry pTab

lSchema.addTable( lTable );

pTable.getColumns().forEach( pColumn -> lTable.addColumn( new Column( pColumn.getName() ) ) );
pTable.getColumns().forEach( pColumn -> lTable.addColumn( new Column( pColumn.getName(), pColumn.getObject_type() != null ? pColumn.getObject_type() : pColumn.getData_type().getName() ) ) );
}
} );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
public class Column
{
private String _columnName;
private String _columnType;

public Column( String pColumnName )
public Column( String pColumnName, String pColumnType )
{
_columnName = pColumnName;
_columnType = pColumnType;

_columnName = _columnName.replaceAll("ß", "SS");
_columnName = _columnName.replaceAll("Ä", "AE");
Expand All @@ -28,4 +30,9 @@ public String getColumnName()
{
return _columnName;
}

public String getColumnType()
{
return _columnType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ private enum Mode
private Table createTable( String pTableName )
{
Table lTable = new Table( pTableName );
lTable.addColumn( new Column( COLUMN_NAME_ID ) );
lTable.addColumn( new Column( COLUMN_NAME_REF ) );
lTable.addColumn( new Column( COLUMN_NAME_3 ) );
lTable.addColumn( new Column( COLUMN_NAME_ID, "type" ) );
lTable.addColumn( new Column( COLUMN_NAME_REF, "type" ) );
lTable.addColumn( new Column( COLUMN_NAME_3, "type" ) );

_schema.addTable( lTable );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ public class ParameterDefaults {
public static final String viewextractmode = "text";
public static boolean sqlplustable = false;
public static boolean orderColumnsByName = false;

public static boolean dbdocPlantuml = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ public static enum FailOnErrorMode
protected String _charsetName = StandardCharsets.UTF_8.name();
protected String _charsetNameSqlLog = null;

protected boolean _dbdocPlantuml = false;

private AdditionalExtensionFactory _additionalExtensionFactory = new AdditionalExtensionFactory()
{
@SuppressWarnings( "unchecked" )
Expand Down Expand Up @@ -485,4 +487,9 @@ public Charset getEncodingForSqlLog()
{
return _charsetNameSqlLog == null ? getEncoding() : Charset.forName( _charsetNameSqlLog );
}

public boolean getDbdocPlantuml()
{
return _dbdocPlantuml;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,12 @@ public void setCreateIndexOnline( boolean pCreateIndexOnline )
_createIndexOnline = pCreateIndexOnline;
}


public void setDbdocPlantuml( boolean pDbdocPlantuml )
{
_dbdocPlantuml = pDbdocPlantuml;
}

public static ParametersCall createWithDefaults()
{
ParametersCall lReturn = new ParametersCall();
Expand Down Expand Up @@ -298,6 +304,8 @@ public static ParametersCall createWithDefaults()

lReturn.setOrcasJdbcConnectParameters(lReturn.getJdbcConnectParameters());

lReturn.setDbdocPlantuml(ParameterDefaults.dbdocPlantuml);

return lReturn;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public abstract class BaseOrcasTask extends DefaultTask
lParametersCall.setMultiSchemaDbaViews( project.orcasconfiguration.multischemadbaviews );
lParametersCall.setMultiSchemaExcludewhereowner( project.orcasconfiguration.multischemaexcludewhereowner );

lParametersCall.setDbdocPlantuml( project.orcasconfiguration.dbdocPlantuml );

if( project.orcasconfiguration.extensionHandler != null )
{
lParametersCall.setExtensionHandler( project.orcasconfiguration.extensionHandler );
Expand Down
Loading

0 comments on commit e724099

Please sign in to comment.