3232import de .fraunhofer .iosb .ilt .frostserver .model .ModelRegistry ;
3333import de .fraunhofer .iosb .ilt .frostserver .property .EntityPropertyMain ;
3434import de .fraunhofer .iosb .ilt .frostserver .property .NavigationProperty ;
35+ import de .fraunhofer .iosb .ilt .frostserver .property .type .PropertyType ;
36+ import de .fraunhofer .iosb .ilt .frostserver .property .type .TypeComplex ;
3537import java .io .IOException ;
3638import java .io .Writer ;
3739import java .util .ArrayList ;
4042import java .util .List ;
4143import java .util .Map ;
4244import java .util .Set ;
45+ import java .util .TreeSet ;
4346import java .util .UUID ;
4447import net .time4j .Moment ;
4548import org .apache .commons .lang3 .StringUtils ;
5053public class MxGraphGenerator {
5154
5255 private static final String STYLE_LIST = "swimlane;fontStyle=0;childLayout=stackLayout;horizontal=1;startSize=30;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=1;marginBottom=0;whiteSpace=wrap;html=1;fillColor=#98D095;strokeColor=#82b366;swimlaneFillColor=#E3F7E2;" ;
53- private static final String STYLE_LIST_ITEM = "text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden ;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap ;html=1;" ;
56+ private static final String STYLE_LIST_ITEM = "text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=visible ;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;html=1;" ;
5457 private static final String STYLE_CONNECTOR = "endArrow=classic;startArrow=classic;html=1;rounded=0;" ;
5558 private static final String STYLE_LABEL = "edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];labelBackgroundColor=none;fontSize=10;spacingLeft=1;spacing=3;spacingRight=2;" ;
5659
@@ -85,9 +88,17 @@ public void generate(Writer writer, ModelRegistry model, boolean isAdmin) throws
8588 root .addMxCell (cellOne );
8689
8790 final Set <EntityType > entityTypes = model .getEntityTypes (isAdmin );
91+ final Set <String > complexTypes = new TreeSet <>();
8892 maxWidth = (int ) Math .round (Math .ceil (Math .sqrt (entityTypes .size ())));
8993 for (EntityType et : entityTypes ) {
90- addEntityType (et , cellOne , root );
94+ addEntityType (et , cellOne , root , complexTypes );
95+ }
96+ final Map <String , PropertyType > propertyTypes = model .getPropertyTypes ();
97+ for (String name : complexTypes ) {
98+ PropertyType value = propertyTypes .get (name );
99+ if (value instanceof TypeComplex tc ) {
100+ addComplexPropertyType (tc , cellOne , root );
101+ }
91102 }
92103
93104 MxGraphModel gm = new MxGraphModel ()
@@ -106,7 +117,7 @@ public void generate(Writer writer, ModelRegistry model, boolean isAdmin) throws
106117 xmlMapper .writeValue (writer , mxFile );
107118 }
108119
109- private void addEntityType (EntityType et , MxCell cellOne , Root root ) {
120+ private void addEntityType (EntityType et , MxCell cellOne , Root root , Set < String > complexTypes ) {
110121 etCount ++;
111122 globalX ++;
112123 if (globalX >= maxWidth ) {
@@ -136,6 +147,9 @@ private void addEntityType(EntityType et, MxCell cellOne, Root root) {
136147 for (EntityPropertyMain ep : entityProperties ) {
137148 addEntityProperty (listItemY , typeCell , ep , root );
138149 listItemY += BOX_HEIGHT_ITEM ;
150+ if (ep .getType () instanceof TypeComplex ) {
151+ complexTypes .add (ep .getType ().getName ());
152+ }
139153 }
140154 for (NavigationProperty np : et .getNavigationEntities ()) {
141155 addNavLink (np , et , typeCell , cellOne , root );
@@ -145,6 +159,56 @@ private void addEntityType(EntityType et, MxCell cellOne, Root root) {
145159 }
146160 }
147161
162+ private void addComplexPropertyType (TypeComplex tc , MxCell cellOne , Root root ) {
163+ etCount ++;
164+ globalX ++;
165+ if (globalX >= maxWidth ) {
166+ globalX = 0 ;
167+ globalY += rowHeight + DISTANCE ;
168+ rowHeight = DISTANCE ;
169+ }
170+ Map <String , PropertyType > properties = tc .getProperties ();
171+ int boxHeight = BOX_HEIGHT_BASE + properties .size () * BOX_HEIGHT_ITEM ;
172+ if (boxHeight > rowHeight ) {
173+ rowHeight = boxHeight ;
174+ }
175+ MxGeometry cellGeom = new MxGeometry ()
176+ .setWidth (BOX_WIDTH )
177+ .setHeight (boxHeight )
178+ .setX (globalX * (BOX_WIDTH + DISTANCE ))
179+ .setY (globalY );
180+ MxCell typeCell = new MxCell ()
181+ .setValue (tc .getName ())
182+ .setStyle (STYLE_LIST )
183+ .setParent (cellOne .getId ())
184+ .setVertex (1 )
185+ .setMxGeometry (cellGeom );
186+ root .addMxCell (typeCell );
187+
188+ int listItemY = BOX_HEIGHT_BASE ;
189+ for (Map .Entry <String , PropertyType > prop : properties .entrySet ()) {
190+ final String name = prop .getKey ();
191+ final PropertyType type = prop .getValue ();
192+ addPropertyType (listItemY , typeCell , name , type , tc .isRequired (name ), root );
193+ listItemY += BOX_HEIGHT_ITEM ;
194+ }
195+ }
196+
197+ private void addPropertyType (int listItemY , MxCell typeCell , String name , PropertyType pt , boolean required , Root root ) {
198+ MxGeometry propGeom = new MxGeometry ()
199+ .setWidth (BOX_WIDTH )
200+ .setHeight (BOX_HEIGHT_ITEM )
201+ .setY (listItemY );
202+ MxCell propCell = new MxCell ()
203+ .setParent (typeCell .getId ())
204+ .setValue (createText (name , pt .getName (), required ))
205+ .setStyle (STYLE_LIST_ITEM )
206+ .setVertex (1 )
207+ .setConnectable (0 )
208+ .setMxGeometry (propGeom );
209+ root .addMxCell (propCell );
210+ }
211+
148212 private void addEntityProperty (int listItemY , MxCell typeCell , EntityPropertyMain ep , Root root ) {
149213 MxGeometry propGeom = new MxGeometry ()
150214 .setWidth (BOX_WIDTH )
@@ -172,7 +236,18 @@ private String createTextForEp(EntityPropertyMain ep) {
172236 }
173237 }
174238 }
175- return name + ": " + StringUtils .replace (ep .getType ().getName (), "Edm." , "" );
239+ return createText (name , ep .getType ().getName (), ep .isRequired ());
240+ }
241+
242+ private String createText (String name , String typeName , boolean required ) {
243+ StringBuilder result = new StringBuilder ();
244+ if (required ) {
245+ result .append ("+ " );
246+ } else {
247+ result .append (" " );
248+ }
249+ result .append (name ).append (": " ).append (StringUtils .replace (typeName , "Edm." , "" ));
250+ return result .toString ();
176251 }
177252
178253 private void addNavLink (NavigationProperty np , EntityType et , MxCell typeCell , MxCell cellOne , Root root ) {
0 commit comments