diff options
Diffstat (limited to 'src/main')
16 files changed, 14 insertions, 917 deletions
diff --git a/src/main/java/org/onap/clamp/clds/util/XmlTools.java b/src/main/java/org/onap/clamp/clds/util/XmlTools.java deleted file mode 100644 index a7d4ed9fb..000000000 --- a/src/main/java/org/onap/clamp/clds/util/XmlTools.java +++ /dev/null @@ -1,78 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2019 Nokia. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * - */ - -package org.onap.clamp.clds.util; - -import java.io.StringWriter; -import javax.xml.XMLConstants; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; -import org.apache.batik.anim.dom.SVGDOMImplementation; -import org.apache.batik.dom.GenericDOMImplementation; -import org.apache.batik.util.SVGConstants; -import org.w3c.dom.DOMImplementation; -import org.w3c.dom.Document; - -public class XmlTools { - - /** - * Private constructor to avoid creating instances of util class. - */ - private XmlTools(){ - } - - /** - * Transforms document to XML string. - * - * @param doc XML document - * @return XML string - */ - public static String exportXmlDocumentAsString(Document doc) { - try { - TransformerFactory tf = TransformerFactory.newInstance(); - tf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); - Transformer transformer = tf.newTransformer(); - transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); - StringWriter writer = new StringWriter(); - transformer.transform(new DOMSource(doc), new StreamResult(writer)); - return writer.getBuffer().toString(); - } catch (TransformerException e) { - throw new RuntimeException(e); - } - } - - /** - * Creates empty svg document. - * - * @return Document - */ - public static Document createEmptySvgDocument() { - DOMImplementation domImplementation = GenericDOMImplementation.getDOMImplementation(); - String svgNs = SVGDOMImplementation.SVG_NAMESPACE_URI; - return domImplementation.createDocument(svgNs, SVGConstants.SVG_SVG_TAG, null); - } -} diff --git a/src/main/java/org/onap/clamp/clds/util/drawing/AwtUtils.java b/src/main/java/org/onap/clamp/clds/util/drawing/AwtUtils.java deleted file mode 100755 index a4a5a3847..000000000 --- a/src/main/java/org/onap/clamp/clds/util/drawing/AwtUtils.java +++ /dev/null @@ -1,93 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2019 Nokia. All rights - * reserved. - * ================================================================================ - * Modifications Copyright (c) 2019 Samsung - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * Modifications copyright (c) 2019 AT&T. - * =================================================================== - * - */ - -package org.onap.clamp.clds.util.drawing; - -import java.awt.Color; -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.Graphics2D; -import java.awt.Point; -import java.awt.Rectangle; - -public class AwtUtils { - private static final int ARROW_W = 4; - private static final int ARROW_H = 2; - private static final int FONT_SIZE = 12; - private static final int FONT_STYLE = Font.PLAIN; - private static final String FONT_FACE = "SansSerif"; - private static final Color TRANSPARENT = new Color(0.0f, 0.0f, 0.0f, 0.0f); - private static final int TEXT_PADDING = 5; - - private AwtUtils() { - } - - static void rectWithText(Graphics2D g2d, String text, Point point, int width, int height) { - Rectangle rect = new Rectangle(point.x, point.y, width, height); - g2d.draw(rect); - Color oldColor = g2d.getColor(); - g2d.setColor(TRANSPARENT); - g2d.fill(rect); - g2d.setColor(oldColor); - addText(g2d, text, rect); - } - - static void drawArrow(Graphics2D g2d, Point from, Point to, int lineThickness) { - int x2 = to.x - lineThickness; - g2d.drawLine(from.x, from.y, x2 - lineThickness, to.y); - g2d.drawPolygon(new int[] { x2 - ARROW_W, x2 - ARROW_W, x2 }, - new int[] { to.y - ARROW_H, to.y + ARROW_H, to.y }, 3); - g2d.fillPolygon(new int[] { x2 - ARROW_W, x2 - ARROW_W, x2 }, - new int[] { to.y - ARROW_H, to.y + ARROW_H, to.y }, 3); - } - - private static void addText(Graphics2D g2d, String text, Rectangle rect) { - int textBoundingBoxLimit = rect.width - 2 * TEXT_PADDING; - Font font = new Font(FONT_FACE, FONT_STYLE, FONT_SIZE); - font = scaleFontToFit(text, textBoundingBoxLimit, g2d, font); - Font oldFont = g2d.getFont(); - - g2d.setFont(font); - g2d.setColor(Color.BLACK); - FontMetrics fm1 = g2d.getFontMetrics(); - float x1 = rect.x + (float) (rect.width - fm1.stringWidth(text)) / 2; - float y1 = rect.y + (float) (rect.height - fm1.getHeight()) / 2 + fm1.getAscent(); - g2d.drawString(text, x1, y1); - - g2d.setFont(oldFont); - } - - private static Font scaleFontToFit(String text, int width, Graphics2D g2d, Font font) { - float fontSize = font.getSize(); - float stringWidth = g2d.getFontMetrics(font).stringWidth(text); - if (stringWidth <= width) { - return font; - } - fontSize = (width / stringWidth) * fontSize; - return font.deriveFont(fontSize); - } - -} diff --git a/src/main/java/org/onap/clamp/clds/util/drawing/ClampGraph.java b/src/main/java/org/onap/clamp/clds/util/drawing/ClampGraph.java deleted file mode 100755 index 6b97de8e6..000000000 --- a/src/main/java/org/onap/clamp/clds/util/drawing/ClampGraph.java +++ /dev/null @@ -1,48 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2019 Nokia. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * - */ - -package org.onap.clamp.clds.util.drawing; - -import java.util.Objects; -import org.onap.clamp.clds.util.XmlTools; - -public class ClampGraph { - private final DocumentBuilder documentBuilder; - private String svg; - - ClampGraph(DocumentBuilder documentBuilder) { - this.documentBuilder = documentBuilder; - } - - /** - * Returns svg string. - * - * @return svg string - */ - public String getAsSvg() { - if (Objects.isNull(svg) || svg.isEmpty()) { - svg = XmlTools.exportXmlDocumentAsString(this.documentBuilder.getGroupingDocument()); - } - return svg; - } -} diff --git a/src/main/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilder.java b/src/main/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilder.java deleted file mode 100755 index 6cf342f2c..000000000 --- a/src/main/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilder.java +++ /dev/null @@ -1,107 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2019 Nokia. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * Modifications copyright (c) 2019 AT&T - * =================================================================== - * - */ - -package org.onap.clamp.clds.util.drawing; - -import java.util.HashSet; -import java.util.Set; -import org.onap.clamp.loop.template.LoopElementModel; -import org.onap.clamp.policy.microservice.MicroServicePolicy; -import org.onap.clamp.policy.operational.OperationalPolicy; - -public class ClampGraphBuilder { - private Set<OperationalPolicy> policies = new HashSet<>(); - private String collector; - private Set<MicroServicePolicy> microServices = new HashSet<>(); - private Set<LoopElementModel> loopElementModels = new HashSet<>(); - private final Painter painter; - - public ClampGraphBuilder(Painter painter) { - this.painter = painter; - } - - public ClampGraphBuilder collector(String collector) { - this.collector = collector; - return this; - } - - public ClampGraphBuilder addPolicy(OperationalPolicy policy) { - this.policies.add(policy); - return this; - } - - public ClampGraphBuilder addAllPolicies(Set<OperationalPolicy> policies) { - this.policies.addAll(policies); - return this; - } - - public ClampGraphBuilder addMicroService(MicroServicePolicy ms) { - microServices.add(ms); - return this; - } - - public ClampGraphBuilder addAllMicroServices(Set<MicroServicePolicy> msList) { - microServices.addAll(msList); - return this; - } - - /** - * This method adds all loop element specified in input to the current structure. - * - * @param loopElementModels A set of LoopElementModels - * @return Return the current ClampGraphBuilder - */ - public ClampGraphBuilder addAllLoopElementModels(Set<LoopElementModel> loopElementModels) { - for (LoopElementModel elem : loopElementModels) { - this.addLoopElementModel(elem); - } - return this; - } - - /** - * This method adds one loop element specified in input to the current structure. - * - * @param loopElementModel A LoopElementModels - * @return Return the current ClampGraphBuilder - */ - public ClampGraphBuilder addLoopElementModel(LoopElementModel loopElementModel) { - if (LoopElementModel.MICRO_SERVICE_TYPE.equals(loopElementModel.getLoopElementType())) { - microServices.add(new MicroServicePolicy(loopElementModel.getName(), - loopElementModel.getPolicyModels().first(), false,null,loopElementModel,null,null)); - } else if (LoopElementModel.OPERATIONAL_POLICY_TYPE.equals(loopElementModel.getLoopElementType())) { - policies.add(new OperationalPolicy(loopElementModel.getName(), null, null, - loopElementModel.getPolicyModels().first(), loopElementModel, null, null)); - } - return this; - } - - /** - * Build the SVG. - * - * @return Clamp graph (SVG) - */ - public ClampGraph build() { - return new ClampGraph(painter.doPaint(collector, microServices, policies)); - } -} diff --git a/src/main/java/org/onap/clamp/clds/util/drawing/DocumentBuilder.java b/src/main/java/org/onap/clamp/clds/util/drawing/DocumentBuilder.java deleted file mode 100644 index 7c624be0f..000000000 --- a/src/main/java/org/onap/clamp/clds/util/drawing/DocumentBuilder.java +++ /dev/null @@ -1,67 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2019 Nokia. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * - */ - -package org.onap.clamp.clds.util.drawing; - -import org.apache.batik.svggen.SVGGraphics2D; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -public class DocumentBuilder { - private final Document groupingDocument; - private final Document documentFactory; - - static final String DATA_ELEMENT_ID_ATTRIBUTE = "data-element-id"; - static final String DATA_ELEMENT_GROUPING_ATTRIBUTE = "data-grouping-id"; - static final String DATA_FOR_UI_ATTRIBUTE = "data-for-ui"; - - DocumentBuilder(Document groupingDocument, Document documentFactory) { - this.groupingDocument = groupingDocument; - this.documentFactory = documentFactory; - } - - void pushChangestoDocument(SVGGraphics2D g2d, String dataElementId) { - pushChangestoDocument(g2d, dataElementId,null,null); - } - - void pushChangestoDocument(SVGGraphics2D g2d, String dataElementId, String dataGroupingId, String dataForUI) { - Element element = - this.documentFactory.createElementNS(SVGGraphics2D.SVG_NAMESPACE_URI, - SVGGraphics2D.SVG_G_TAG); - element.setAttribute(DATA_ELEMENT_ID_ATTRIBUTE, dataElementId); - if (dataGroupingId != null) { - element.setAttribute(DATA_ELEMENT_GROUPING_ATTRIBUTE, dataGroupingId); - } - if (dataForUI != null) { - element.setAttribute(DATA_FOR_UI_ATTRIBUTE, dataForUI); - } - g2d.getRoot(element); - Node node = this.groupingDocument.importNode(element, true); - this.groupingDocument.getDocumentElement().appendChild(node); - } - - Document getGroupingDocument() { - return groupingDocument; - } -} diff --git a/src/main/java/org/onap/clamp/clds/util/drawing/ImageBuilder.java b/src/main/java/org/onap/clamp/clds/util/drawing/ImageBuilder.java deleted file mode 100644 index 72df90f2b..000000000 --- a/src/main/java/org/onap/clamp/clds/util/drawing/ImageBuilder.java +++ /dev/null @@ -1,138 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2019 Nokia. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * - */ - -package org.onap.clamp.clds.util.drawing; - -import java.awt.BasicStroke; -import java.awt.Point; -import java.awt.Shape; -import java.awt.Stroke; -import java.awt.geom.Ellipse2D; -import java.util.UUID; - -import org.apache.batik.svggen.SVGGraphics2D; - -public class ImageBuilder { - - public static final int POLICY_LINE_RATIO = 2; - public static final int COLLECTOR_LINE_RATIO = 6; - public static final float MS_LINE_TO_HEIGHT_RATIO = 0.75f; - public static final float ARROW_TO_BASELINE_RATIO = 0.75f; - - private Point currentPoint; - private final int baseLength; - private final int rectHeight; - private final SVGGraphics2D g2d; - private final DocumentBuilder documentBuilder; - - private static final int LINE_THICKNESS = 2; - private static final int CIRCLE_RADIUS = 17; - - ImageBuilder(SVGGraphics2D svgGraphics2D, DocumentBuilder documentBuilder, Point startingPoint, int baseLength, - int rectHeight) { - this.g2d = svgGraphics2D; - this.documentBuilder = documentBuilder; - this.currentPoint = new Point(startingPoint); - this.baseLength = baseLength; - this.rectHeight = rectHeight; - } - - ImageBuilder rectangle(String dataElementId, RectTypes rectType, String boxText, String groupingId, String uiData) { - Point next = new Point(currentPoint.x + baseLength, currentPoint.y); - Point point = coordinatesForRectangle(currentPoint, next); - - handleBasedOnRectType(rectType, boxText, point, baseLength, rectHeight); - - documentBuilder.pushChangestoDocument(g2d, dataElementId, groupingId, uiData); - currentPoint = next; - return this; - } - - ImageBuilder arrow() { - String dataElementId = "Arrow-" + UUID.randomUUID().toString(); - Point to = new Point(currentPoint.x + (int) (baseLength * ARROW_TO_BASELINE_RATIO), currentPoint.y); - AwtUtils.drawArrow(g2d, currentPoint, to, LINE_THICKNESS); - documentBuilder.pushChangestoDocument(g2d, dataElementId); - currentPoint = to; - return this; - } - - ImageBuilder circle(String dataElementId, int lineThickness) { - Shape circleStart = new Ellipse2D.Double(currentPoint.x, ((double) currentPoint.y) - CIRCLE_RADIUS, - 2.0 * CIRCLE_RADIUS, 2.0 * CIRCLE_RADIUS); - - Stroke oldStroke = g2d.getStroke(); - g2d.setStroke(new BasicStroke(lineThickness)); - g2d.draw(circleStart); - g2d.setStroke(oldStroke); - documentBuilder.pushChangestoDocument(g2d, dataElementId); - Point to = new Point(currentPoint.x + 2 * CIRCLE_RADIUS, currentPoint.y); - currentPoint = to; - return this; - } - - DocumentBuilder getDocumentBuilder() { - return documentBuilder; - } - - private void handleBasedOnRectType(RectTypes rectType, String text, Point point, int width, int height) { - AwtUtils.rectWithText(g2d, text, point, width, height); - switch (rectType) { - case COLECTOR: - drawVerticalLineForCollector(point, width, height); - break; - case MICROSERVICE: - drawHorizontalLineForMicroService(point, width, height); - break; - case POLICY: - drawDiagonalLineForPolicy(point, width, height); - break; - default: - } - } - - private void drawVerticalLineForCollector(Point point, int width, int height) { - g2d.drawLine(point.x + width / COLLECTOR_LINE_RATIO, point.y, point.x + width / COLLECTOR_LINE_RATIO, - point.y + height); - } - - private void drawHorizontalLineForMicroService(Point point, int width, int height) { - int pointY = calculateMsHorizontalLineYCoordinate(point, height); - g2d.drawLine(point.x, pointY, point.x + width, pointY); - } - - private void drawDiagonalLineForPolicy(Point point, int width, int height) { - g2d.drawLine(point.x, point.y + height / POLICY_LINE_RATIO, point.x + width / POLICY_LINE_RATIO, point.y); - } - - private int calculateMsHorizontalLineYCoordinate(Point point, int height) { - return (int) (point.y * height * MS_LINE_TO_HEIGHT_RATIO); - } - - private Point coordinatesForRectangle(Point from, Point next) { - int pointX = from.x; - int pointY = from.y - next.y + LINE_THICKNESS / 2; - return new Point(pointX, pointY); - } - -} diff --git a/src/main/java/org/onap/clamp/clds/util/drawing/InvalidStateException.java b/src/main/java/org/onap/clamp/clds/util/drawing/InvalidStateException.java deleted file mode 100644 index 91af9f1a4..000000000 --- a/src/main/java/org/onap/clamp/clds/util/drawing/InvalidStateException.java +++ /dev/null @@ -1,30 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2019 Nokia. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * - */ - -package org.onap.clamp.clds.util.drawing; - -public class InvalidStateException extends RuntimeException { - public InvalidStateException(String message) { - super(message); - } -} diff --git a/src/main/java/org/onap/clamp/clds/util/drawing/Painter.java b/src/main/java/org/onap/clamp/clds/util/drawing/Painter.java deleted file mode 100755 index ff7d2c215..000000000 --- a/src/main/java/org/onap/clamp/clds/util/drawing/Painter.java +++ /dev/null @@ -1,105 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2019 Nokia. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * Modifications copyright (c) 2019 AT&T - * =================================================================== - * - */ - -package org.onap.clamp.clds.util.drawing; - -import java.awt.BasicStroke; -import java.awt.Color; -import java.awt.Point; -import java.awt.RenderingHints; -import java.util.Set; -import org.apache.batik.svggen.SVGGraphics2D; -import org.onap.clamp.policy.microservice.MicroServicePolicy; -import org.onap.clamp.policy.operational.OperationalPolicy; - -public class Painter { - private final int canvasSize; - private final SVGGraphics2D g2d; - private final DocumentBuilder documentBuilder; - - private static final int DEFAULT_CANVAS_SIZE = 900; - private static final int SLIM_LINE = 2; - private static final int THICK_LINE = 4; - private static final double RECT_RATIO = 3.0 / 2.0; - private static final int CIRCLE_RADIUS = 17; - private static final int MINIMUM_BASE_LENGTH = 120; - - /** - * Constructor to create instance of Painter. - * - * @param svgGraphics2D svg graphics - * @param documentBuilder document builder - */ - public Painter(SVGGraphics2D svgGraphics2D, DocumentBuilder documentBuilder) { - this.g2d = svgGraphics2D; - this.documentBuilder = documentBuilder; - this.canvasSize = DEFAULT_CANVAS_SIZE; - } - - DocumentBuilder doPaint(String collector, Set<MicroServicePolicy> microServices, Set<OperationalPolicy> policies) { - int numOfRectangles = 2 + microServices.size(); - int numOfArrows = numOfRectangles + 1; - int baseLength = (canvasSize - 2 * CIRCLE_RADIUS) / (numOfArrows + numOfRectangles); - if (baseLength < MINIMUM_BASE_LENGTH) { - baseLength = MINIMUM_BASE_LENGTH; - } - int rectHeight = (int) (baseLength / RECT_RATIO); - - adjustGraphics2DProperties(); - - Point origin = new Point(1, rectHeight / 2); - ImageBuilder ib = new ImageBuilder(g2d, documentBuilder, origin, baseLength, rectHeight); - - doTheActualDrawing(collector, microServices, policies, ib); - - return ib.getDocumentBuilder(); - } - - private void doTheActualDrawing(String collector, Set<MicroServicePolicy> microServices, - Set<OperationalPolicy> policies, - ImageBuilder ib) { - ib.circle("start-circle", SLIM_LINE).arrow().rectangle(collector, RectTypes.COLECTOR, collector, null, null); - - for (MicroServicePolicy ms : microServices) { - ib.arrow().rectangle(ms.getName(), - RectTypes.MICROSERVICE, ms.getPolicyModel().getPolicyAcronym(), - ms.getLoopElementModel() != null ? ms.getLoopElementModel().getName() : null, - ms.getLoopElementModel() != null ? ms.getLoopElementModel().getName() : null); - } - for (OperationalPolicy policy : policies) { - ib.arrow().rectangle(policy.getName(), RectTypes.POLICY, policy.getPolicyModel().getPolicyAcronym(), - policy.getLoopElementModel() != null ? policy.getLoopElementModel().getName() : null, - policy.getLoopElementModel() != null ? policy.getLoopElementModel().getName() : null); - } - ib.arrow().circle("stop-circle", THICK_LINE); - } - - private void adjustGraphics2DProperties() { - g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); - g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB); - g2d.setStroke(new BasicStroke(SLIM_LINE)); - g2d.setPaint(Color.BLACK); - } - -} diff --git a/src/main/java/org/onap/clamp/clds/util/drawing/RectTypes.java b/src/main/java/org/onap/clamp/clds/util/drawing/RectTypes.java deleted file mode 100644 index e69324325..000000000 --- a/src/main/java/org/onap/clamp/clds/util/drawing/RectTypes.java +++ /dev/null @@ -1,28 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2019 Nokia. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * - */ - -package org.onap.clamp.clds.util.drawing; - -enum RectTypes { - COLECTOR, MICROSERVICE, POLICY -}
\ No newline at end of file diff --git a/src/main/java/org/onap/clamp/clds/util/drawing/SvgLoopGenerator.java b/src/main/java/org/onap/clamp/clds/util/drawing/SvgLoopGenerator.java deleted file mode 100644 index f289d9798..000000000 --- a/src/main/java/org/onap/clamp/clds/util/drawing/SvgLoopGenerator.java +++ /dev/null @@ -1,75 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2019 Nokia. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * Modifications copyright (c) 2019 AT&T - * =================================================================== - * - */ - -package org.onap.clamp.clds.util.drawing; - -import java.util.HashSet; -import java.util.Set; -import org.apache.batik.svggen.SVGGraphics2D; -import org.onap.clamp.clds.util.XmlTools; -import org.onap.clamp.loop.Loop; -import org.onap.clamp.loop.template.LoopElementModel; -import org.onap.clamp.loop.template.LoopTemplate; -import org.onap.clamp.loop.template.LoopTemplateLoopElementModel; -import org.w3c.dom.Document; - -public class SvgLoopGenerator { - /** - * Generate the SVG images from the loop. - * - * @param loop The loop object, so it won't use the loop template - * @return A String containing the SVG - */ - public static String getSvgImage(Loop loop) { - SVGGraphics2D svgGraphics2D = new SVGGraphics2D(XmlTools.createEmptySvgDocument()); - Document document = XmlTools.createEmptySvgDocument(); - DocumentBuilder dp = new DocumentBuilder(document, svgGraphics2D.getDOMFactory()); - Painter painter = new Painter(svgGraphics2D, dp); - ClampGraphBuilder cgp = new ClampGraphBuilder(painter).collector("VES"); - cgp.addAllMicroServices(loop.getMicroServicePolicies()); - ClampGraph cg = cgp.addAllPolicies(loop.getOperationalPolicies()).build(); - return cg.getAsSvg(); - } - - /** - * Generate the SVG images from the loop template. - * - * @param loopTemplate The loop template - * @return A String containing the SVG - */ - public static String getSvgImage(LoopTemplate loopTemplate) { - SVGGraphics2D svgGraphics2D = new SVGGraphics2D(XmlTools.createEmptySvgDocument()); - Document document = XmlTools.createEmptySvgDocument(); - DocumentBuilder dp = new DocumentBuilder(document, svgGraphics2D.getDOMFactory()); - Painter painter = new Painter(svgGraphics2D, dp); - ClampGraphBuilder cgp = new ClampGraphBuilder(painter).collector("VES"); - Set<LoopElementModel> elementModelsSet = new HashSet<>(); - for (LoopTemplateLoopElementModel elementModelLink:loopTemplate.getLoopElementModelsUsed()) { - elementModelsSet.add(elementModelLink.getLoopElementModel()); - } - ClampGraph cg = cgp.addAllLoopElementModels(elementModelsSet).build(); - return cg.getAsSvg(); - } - -} diff --git a/src/main/java/org/onap/clamp/loop/Loop.java b/src/main/java/org/onap/clamp/loop/Loop.java index 081331337..36f74221e 100644 --- a/src/main/java/org/onap/clamp/loop/Loop.java +++ b/src/main/java/org/onap/clamp/loop/Loop.java @@ -51,7 +51,6 @@ import org.hibernate.annotations.Type; import org.hibernate.annotations.TypeDef; import org.hibernate.annotations.TypeDefs; import org.onap.clamp.clds.tosca.update.ToscaConverterWithDictionarySupport; -import org.onap.clamp.clds.util.drawing.SvgLoopGenerator; import org.onap.clamp.dao.model.jsontype.StringJsonUserType; import org.onap.clamp.loop.common.AuditEntity; import org.onap.clamp.loop.components.external.DcaeComponent; @@ -88,9 +87,6 @@ public class Loop extends AuditEntity implements Serializable { @Column(name = "dcae_deployment_status_url") private String dcaeDeploymentStatusUrl; - @Column(columnDefinition = "MEDIUMTEXT", name = "svg_representation") - private String svgRepresentation; - @Expose @Type(type = "json") @Column(columnDefinition = "json", name = "global_properties_json") @@ -145,9 +141,8 @@ public class Loop extends AuditEntity implements Serializable { /** * Constructor. */ - public Loop(String name, String svgRepresentation) { + public Loop(String name) { this.name = name; - this.svgRepresentation = svgRepresentation; this.lastComputedState = LoopState.DESIGN; this.globalPropertiesJson = new JsonObject(); initializeExternalComponents(); @@ -160,7 +155,7 @@ public class Loop extends AuditEntity implements Serializable { * @param loopTemplate The loop template from which a new loop instance must be created */ public Loop(String name, LoopTemplate loopTemplate, ToscaConverterWithDictionarySupport toscaConverter) { - this(name, ""); + this(name); this.setLoopTemplate(loopTemplate); this.setModelService(loopTemplate.getModelService()); loopTemplate.getLoopElementModelsUsed().forEach(element -> { @@ -201,14 +196,6 @@ public class Loop extends AuditEntity implements Serializable { this.dcaeDeploymentStatusUrl = dcaeDeploymentStatusUrl; } - public String getSvgRepresentation() { - return svgRepresentation; - } - - void setSvgRepresentation(String svgRepresentation) { - this.svgRepresentation = svgRepresentation; - } - public LoopState getLastComputedState() { return lastComputedState; } @@ -251,37 +238,31 @@ public class Loop extends AuditEntity implements Serializable { /** * This method adds an operational policy to the loop. - * It re-computes the Svg as well. * * @param opPolicy the operationalPolicy to add */ public void addOperationalPolicy(OperationalPolicy opPolicy) { operationalPolicies.add(opPolicy); opPolicy.setLoop(this); - this.setSvgRepresentation(SvgLoopGenerator.getSvgImage(this)); } /** * This method removes an operational policy to the loop. - * It re-computes the Svg as well. * * @param opPolicy the operationalPolicy to add */ public void removeOperationalPolicy(OperationalPolicy opPolicy) { operationalPolicies.remove(opPolicy); - this.setSvgRepresentation(SvgLoopGenerator.getSvgImage(this)); } /** * This method adds an micro service policy to the loop. - * It re-computes the Svg as well. * * @param microServicePolicy the micro service to add */ public void addMicroServicePolicy(MicroServicePolicy microServicePolicy) { microServicePolicies.add(microServicePolicy); microServicePolicy.getUsedByLoops().add(this); - this.setSvgRepresentation(SvgLoopGenerator.getSvgImage(this)); } public void addLog(LoopLog log) { diff --git a/src/main/java/org/onap/clamp/loop/LoopController.java b/src/main/java/org/onap/clamp/loop/LoopController.java index fad93bc7d..603726f56 100644 --- a/src/main/java/org/onap/clamp/loop/LoopController.java +++ b/src/main/java/org/onap/clamp/loop/LoopController.java @@ -169,17 +169,6 @@ public class LoopController { } /** - * Get the SVG representation of the loop. - * - * @param loopName The loop name - * @return The SVG representation - */ - public String getSvgRepresentation(String loopName) { - Loop loop = loopService.getLoop(loopName); - return loop != null ? loop.getSvgRepresentation() : null; - } - - /** * Refresh the Operational Policy Json representation of the loop. * * @param loop The loop diff --git a/src/main/java/org/onap/clamp/loop/common/AuditEntity.java b/src/main/java/org/onap/clamp/loop/common/AuditEntity.java index bf9d10d74..7ce12ec6b 100644 --- a/src/main/java/org/onap/clamp/loop/common/AuditEntity.java +++ b/src/main/java/org/onap/clamp/loop/common/AuditEntity.java @@ -24,14 +24,11 @@ package org.onap.clamp.loop.common; import com.google.gson.annotations.Expose; - import java.time.Instant; import java.time.temporal.ChronoUnit; - import javax.persistence.Column; import javax.persistence.EntityListeners; import javax.persistence.MappedSuperclass; - import org.springframework.data.annotation.CreatedBy; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedBy; @@ -40,7 +37,6 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener; /** * This class is the parent of the hibernate entities requiring to be audited. - * */ @MappedSuperclass @EntityListeners(AuditingEntityListener.class) @@ -72,20 +68,21 @@ public class AuditEntity { /** * createdDate setter. - * + * * @param createdDate The created Date object */ public void setCreatedDate(Instant createdDate) { if (createdDate != null) { this.createdDate = createdDate.truncatedTo(ChronoUnit.SECONDS); - } else { + } + else { this.createdDate = null; } } /** * updatedDate getter. - * + * * @return the updatedDate */ public Instant getUpdatedDate() { @@ -94,20 +91,21 @@ public class AuditEntity { /** * updatedDate setter. - * + * * @param updatedDate updatedDate to set */ public void setUpdatedDate(Instant updatedDate) { if (updatedDate != null) { this.updatedDate = updatedDate.truncatedTo(ChronoUnit.SECONDS); - } else { + } + else { this.updatedDate = null; } } /** * updatedBy getter. - * + * * @return the updatedBy */ public String getUpdatedBy() { @@ -116,7 +114,7 @@ public class AuditEntity { /** * updatedBy setter. - * + * * @param updatedBy the updatedBy */ public void setUpdatedBy(String updatedBy) { @@ -125,7 +123,7 @@ public class AuditEntity { /** * createdBy getter. - * + * * @return the createdBy */ public String getCreatedBy() { @@ -134,7 +132,7 @@ public class AuditEntity { /** * createdBy setter. - * + * * @param createdBy the createdBy to set */ public void setCreatedBy(String createdBy) { diff --git a/src/main/java/org/onap/clamp/loop/template/LoopTemplate.java b/src/main/java/org/onap/clamp/loop/template/LoopTemplate.java index a7bbd9dd3..6f896f3d4 100644 --- a/src/main/java/org/onap/clamp/loop/template/LoopTemplate.java +++ b/src/main/java/org/onap/clamp/loop/template/LoopTemplate.java @@ -39,7 +39,6 @@ import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; import org.hibernate.annotations.SortNatural; -import org.onap.clamp.clds.util.drawing.SvgLoopGenerator; import org.onap.clamp.loop.common.AuditEntity; import org.onap.clamp.loop.service.Service; @@ -69,9 +68,6 @@ public class LoopTemplate extends AuditEntity implements Serializable { @Column(columnDefinition = "MEDIUMTEXT", name = "blueprint_yaml") private String blueprint; - @Column(columnDefinition = "MEDIUMTEXT", name = "svg_representation") - private String svgRepresentation; - @Expose @OneToMany( cascade = CascadeType.ALL, @@ -164,24 +160,6 @@ public class LoopTemplate extends AuditEntity implements Serializable { } /** - * svgRepresentation getter. - * - * @return the svgRepresentation - */ - public String getSvgRepresentation() { - return svgRepresentation; - } - - /** - * svgRepresentation setter. - * - * @param svgRepresentation the svgRepresentation to set - */ - public void setSvgRepresentation(String svgRepresentation) { - this.svgRepresentation = svgRepresentation; - } - - /** * loopElementModelsUsed getter. * * @return the loopElementModelsUsed @@ -260,7 +238,6 @@ public class LoopTemplate extends AuditEntity implements Serializable { new LoopTemplateLoopElementModel(this, loopElementModel, listPosition); this.loopElementModelsUsed.add(jointEntry); loopElementModel.getUsedByLoopTemplates().add(jointEntry); - this.setSvgRepresentation(SvgLoopGenerator.getSvgImage(this)); } /** @@ -303,16 +280,13 @@ public class LoopTemplate extends AuditEntity implements Serializable { * @param name The loop template name id * @param blueprint The blueprint containing all microservices (legacy * case) - * @param svgRepresentation The svg representation of that loop template * @param maxInstancesAllowed The maximum number of instances that can be * created from that template * @param service The service associated to that loop template */ - public LoopTemplate(String name, String blueprint, String svgRepresentation, - Integer maxInstancesAllowed, Service service) { + public LoopTemplate(String name, String blueprint, Integer maxInstancesAllowed, Service service) { this.name = name; this.setBlueprint(blueprint); - this.svgRepresentation = svgRepresentation; this.maximumInstancesAllowed = maxInstancesAllowed; this.modelService = service; diff --git a/src/main/java/org/onap/clamp/loop/template/LoopTemplatesService.java b/src/main/java/org/onap/clamp/loop/template/LoopTemplatesService.java index 09bc80f89..29382137e 100644 --- a/src/main/java/org/onap/clamp/loop/template/LoopTemplatesService.java +++ b/src/main/java/org/onap/clamp/loop/template/LoopTemplatesService.java @@ -49,17 +49,6 @@ public class LoopTemplatesService { return loopTemplatesRepository.save(loopTemplate); } - - /** - * Get the SVG representation of the loopTemplate. - * - * @param templateName The loopTemplate name - * @return The SVG representation in xml - */ - public String getSvgRepresentation(String templateName) { - return loopTemplatesRepository.findById(templateName).orElse(new LoopTemplate()).getSvgRepresentation(); - } - public List<String> getLoopTemplateNames() { return loopTemplatesRepository.getAllLoopTemplateNames(); } diff --git a/src/main/resources/clds/camel/rest/clamp-api-v2.xml b/src/main/resources/clds/camel/rest/clamp-api-v2.xml index 86a64f665..99e92f5be 100644 --- a/src/main/resources/clds/camel/rest/clamp-api-v2.xml +++ b/src/main/resources/clds/camel/rest/clamp-api-v2.xml @@ -66,39 +66,6 @@ </doTry> </route> </get> - <get uri="/v2/loop/svgRepresentation/{loopName}" - outType="java.lang.String" produces="application/xml"> - <route> - <removeHeaders pattern="*" excludePattern="loopName" /> - <doTry> - <to - uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=startLog(*, 'Get SVG Representation')" /> - <to - uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','read')" /> - <to - uri="bean:org.onap.clamp.loop.LoopController?method=getSvgRepresentation(${header.loopName})" /> - <to - uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=endLog()" /> - <doCatch> - <exception>java.lang.Exception</exception> - <handled> - <constant>true</constant> - </handled> - <to - uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=errorLog()" /> - <log loggingLevel="ERROR" - message="GET SVG request failed for loop: ${header.loopName}, ${exception.stacktrace}" /> - - <setHeader headerName="CamelHttpResponseCode"> - <constant>500</constant> - </setHeader> - <setBody> - <simple>GET SVG For loop FAILED</simple> - </setBody> - </doCatch> - </doTry> - </route> - </get> <post uri="/v2/loop/updateGlobalProperties/{loopName}" type="com.google.gson.JsonObject" consumes="application/json" @@ -1328,38 +1295,6 @@ </doTry> </route> </get> - <get uri="/v2/templates/{templateName}/svgRepresentation" - outType="java.lang.String" produces="application/xml"> - <route> - <removeHeaders pattern="*" excludePattern="templateName" /> - <doTry> - <to - uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=startLog(*, 'Get SVG Representation for Loop template')" /> - <to - uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'template','','read')" /> - <to - uri="bean:org.onap.clamp.loop.template.LoopTemplatesService?method=getSvgRepresentation(${header.templateName})" /> - <to - uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=endLog()" /> - <doCatch> - <exception>java.lang.Exception</exception> - <handled> - <constant>true</constant> - </handled> - <to - uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=errorLog()" /> - <log loggingLevel="ERROR" - message="GET SVG for template failed for template: ${header.templateName}, ${exception.stacktrace}" /> - <setHeader headerName="CamelHttpResponseCode"> - <constant>500</constant> - </setHeader> - <setBody> - <simple>GET SVG for Template FAILED</simple> - </setBody> - </doCatch> - </doTry> - </route> - </get> <get uri="/v2/clampInformation" outType="org.onap.clamp.clds.model.ClampInformation" produces="application/json"> <to |