Search in sources :

Example 16 with TextAnnotation

use of org.eclipse.bpmn2.TextAnnotation in project opencast by opencast.

the class SolrIndexManager method addMpeg7Metadata.

/**
 * Add the mpeg 7 catalog data to the solr document.
 *
 * @param doc
 *          the input document to the solr index
 * @param mpeg7
 *          the mpeg7 catalog
 */
@SuppressWarnings("unchecked")
static void addMpeg7Metadata(SolrInputDocument doc, MediaPackage mediaPackage, Mpeg7Catalog mpeg7) {
    // Check for multimedia content
    if (!mpeg7.multimediaContent().hasNext()) {
        logger.warn("Mpeg-7 doesn't contain  multimedia content");
        return;
    }
    // Get the content duration by looking at the first content track. This
    // of course assumes that all tracks are equally long.
    MultimediaContent<? extends MultimediaContentType> mc = mpeg7.multimediaContent().next();
    MultimediaContentType mct = mc.elements().next();
    MediaTime mediaTime = mct.getMediaTime();
    Schema.setDcExtent(doc, mediaTime.getMediaDuration().getDurationInMilliseconds());
    // Check if the keywords have been filled by (manually) added dublin
    // core data. If not, look for the most relevant fields in mpeg-7.
    SortedSet<TextAnnotation> sortedAnnotations = null;
    if (!"".equals(Schema.getOcKeywords(doc))) {
        sortedAnnotations = new TreeSet<TextAnnotation>(new Comparator<TextAnnotation>() {

            @Override
            public int compare(TextAnnotation a1, TextAnnotation a2) {
                if ((RELEVANCE_BOOST * a1.getRelevance() + a1.getConfidence()) > (RELEVANCE_BOOST * a2.getRelevance() + a2.getConfidence()))
                    return -1;
                else if ((RELEVANCE_BOOST * a1.getRelevance() + a1.getConfidence()) < (RELEVANCE_BOOST * a2.getRelevance() + a2.getConfidence()))
                    return 1;
                return 0;
            }
        });
    }
    // Iterate over the tracks and extract keywords and hints
    Iterator<MultimediaContent<? extends MultimediaContentType>> mmIter = mpeg7.multimediaContent();
    int segmentCount = 0;
    while (mmIter.hasNext()) {
        MultimediaContent<?> multimediaContent = mmIter.next();
        // We need to process visual segments first, due to the way they are handled in the ui.
        for (Iterator<?> iterator = multimediaContent.elements(); iterator.hasNext(); ) {
            MultimediaContentType type = (MultimediaContentType) iterator.next();
            if (!(type instanceof Video) && !(type instanceof AudioVisual))
                continue;
            // for every segment in the current multimedia content track
            Video video = (Video) type;
            Iterator<VideoSegment> vsegments = (Iterator<VideoSegment>) video.getTemporalDecomposition().segments();
            while (vsegments.hasNext()) {
                VideoSegment segment = vsegments.next();
                StringBuffer segmentText = new StringBuffer();
                StringBuffer hintField = new StringBuffer();
                // Collect the video text elements to a segment text
                SpatioTemporalDecomposition spt = segment.getSpatioTemporalDecomposition();
                if (spt != null) {
                    for (VideoText videoText : spt.getVideoText()) {
                        if (segmentText.length() > 0)
                            segmentText.append(" ");
                        segmentText.append(videoText.getText().getText());
                    // TODO: Add hint on bounding box
                    }
                }
                // Add keyword annotations
                Iterator<TextAnnotation> textAnnotations = segment.textAnnotations();
                while (textAnnotations.hasNext()) {
                    TextAnnotation textAnnotation = textAnnotations.next();
                    Iterator<?> kwIter = textAnnotation.keywordAnnotations();
                    while (kwIter.hasNext()) {
                        KeywordAnnotation keywordAnnotation = (KeywordAnnotation) kwIter.next();
                        if (segmentText.length() > 0)
                            segmentText.append(" ");
                        segmentText.append(keywordAnnotation.getKeyword());
                    }
                }
                // Add free text annotations
                Iterator<TextAnnotation> freeIter = segment.textAnnotations();
                if (freeIter.hasNext()) {
                    Iterator<FreeTextAnnotation> freeTextIter = freeIter.next().freeTextAnnotations();
                    while (freeTextIter.hasNext()) {
                        FreeTextAnnotation freeTextAnnotation = freeTextIter.next();
                        if (segmentText.length() > 0)
                            segmentText.append(" ");
                        segmentText.append(freeTextAnnotation.getText());
                    }
                }
                // add segment text to solr document
                Schema.setSegmentText(doc, new DField<String>(segmentText.toString(), Integer.toString(segmentCount)));
                // get the segments time properties
                MediaTimePoint timepoint = segment.getMediaTime().getMediaTimePoint();
                MediaDuration duration = segment.getMediaTime().getMediaDuration();
                // TODO: define a class with hint field constants
                hintField.append("time=" + timepoint.getTimeInMilliseconds() + "\n");
                hintField.append("duration=" + duration.getDurationInMilliseconds() + "\n");
                // Look for preview images. Their characteristics are that they are
                // attached as attachments with a flavor of preview/<something>.
                String time = timepoint.toString();
                for (Attachment slide : mediaPackage.getAttachments(MediaPackageElements.PRESENTATION_SEGMENT_PREVIEW)) {
                    MediaPackageReference ref = slide.getReference();
                    if (ref != null && time.equals(ref.getProperty("time"))) {
                        hintField.append("preview");
                        hintField.append(".");
                        hintField.append(ref.getIdentifier());
                        hintField.append("=");
                        hintField.append(slide.getURI().toString());
                        hintField.append("\n");
                    }
                }
                logger.trace("Adding segment: " + timepoint.toString());
                Schema.setSegmentHint(doc, new DField<String>(hintField.toString(), Integer.toString(segmentCount)));
                // increase segment counter
                segmentCount++;
            }
        }
    }
    // Put the most important keywords into a special solr field
    if (sortedAnnotations != null) {
        Schema.setOcKeywords(doc, importantKeywordsString(sortedAnnotations).toString());
    }
}
Also used : Attachment(org.opencastproject.mediapackage.Attachment) VideoText(org.opencastproject.metadata.mpeg7.VideoText) FreeTextAnnotation(org.opencastproject.metadata.mpeg7.FreeTextAnnotation) Comparator(java.util.Comparator) Iterator(java.util.Iterator) KeywordAnnotation(org.opencastproject.metadata.mpeg7.KeywordAnnotation) TextAnnotation(org.opencastproject.metadata.mpeg7.TextAnnotation) FreeTextAnnotation(org.opencastproject.metadata.mpeg7.FreeTextAnnotation) AudioVisual(org.opencastproject.metadata.mpeg7.AudioVisual) MultimediaContentType(org.opencastproject.metadata.mpeg7.MultimediaContentType) SpatioTemporalDecomposition(org.opencastproject.metadata.mpeg7.SpatioTemporalDecomposition) MediaTimePoint(org.opencastproject.metadata.mpeg7.MediaTimePoint) MediaTimePoint(org.opencastproject.metadata.mpeg7.MediaTimePoint) MediaPackageReference(org.opencastproject.mediapackage.MediaPackageReference) VideoSegment(org.opencastproject.metadata.mpeg7.VideoSegment) Video(org.opencastproject.metadata.mpeg7.Video) MediaTime(org.opencastproject.metadata.mpeg7.MediaTime) MediaDuration(org.opencastproject.metadata.mpeg7.MediaDuration) MultimediaContent(org.opencastproject.metadata.mpeg7.MultimediaContent)

Example 17 with TextAnnotation

use of org.eclipse.bpmn2.TextAnnotation in project opencast by opencast.

the class SolrIndexManager method getMaxRelevance.

/**
 * Gets the maximum relevance for a given keyword in the text annotation.
 *
 * @param keyword
 * @param sortedAnnotations
 * @return The maximum relevance value.
 */
static double getMaxRelevance(String keyword, SortedSet<TextAnnotation> sortedAnnotations) {
    double max = 0.0;
    String needle = null;
    TextAnnotation textAnnotation = null;
    Iterator<TextAnnotation> textAnnotations = sortedAnnotations.iterator();
    while (textAnnotations.hasNext()) {
        textAnnotation = textAnnotations.next();
        Iterator<KeywordAnnotation> keywordAnnotations = textAnnotation.keywordAnnotations();
        while (keywordAnnotations.hasNext()) {
            KeywordAnnotation ann = keywordAnnotations.next();
            needle = ann.getKeyword().toLowerCase();
            if (keyword.equals(needle)) {
                if (max < textAnnotation.getRelevance()) {
                    max = textAnnotation.getRelevance();
                }
            }
        }
    }
    return max;
}
Also used : KeywordAnnotation(org.opencastproject.metadata.mpeg7.KeywordAnnotation) TextAnnotation(org.opencastproject.metadata.mpeg7.TextAnnotation) FreeTextAnnotation(org.opencastproject.metadata.mpeg7.FreeTextAnnotation)

Example 18 with TextAnnotation

use of org.eclipse.bpmn2.TextAnnotation in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method unmarshallItem.

public BaseElement unmarshallItem(JsonParser parser, String preProcessingData) throws JsonParseException, IOException {
    String resourceId = null;
    Map<String, String> properties = null;
    String stencil = null;
    List<BaseElement> childElements = new ArrayList<BaseElement>();
    List<String> outgoing = new ArrayList<String>();
    while (parser.nextToken() != JsonToken.END_OBJECT) {
        String fieldname = parser.getCurrentName();
        parser.nextToken();
        if ("resourceId".equals(fieldname)) {
            resourceId = parser.getText();
        } else if ("properties".equals(fieldname)) {
            properties = unmarshallProperties(parser);
        } else if ("stencil".equals(fieldname)) {
            // "stencil":{"id":"Task"},
            parser.nextToken();
            parser.nextToken();
            stencil = parser.getText();
            parser.nextToken();
        } else if ("childShapes".equals(fieldname)) {
            while (parser.nextToken() != JsonToken.END_ARRAY) {
                // open the
                // object
                // the childShapes element is a json array. We opened the
                // array.
                childElements.add(unmarshallItem(parser, preProcessingData));
            }
        } else if ("bounds".equals(fieldname)) {
            // bounds: {"lowerRight":{"x":484.0,"y":198.0},"upperLeft":{"x":454.0,"y":168.0}}
            parser.nextToken();
            parser.nextToken();
            parser.nextToken();
            parser.nextToken();
            Integer x2 = parser.getIntValue();
            parser.nextToken();
            parser.nextToken();
            Integer y2 = parser.getIntValue();
            parser.nextToken();
            parser.nextToken();
            parser.nextToken();
            parser.nextToken();
            parser.nextToken();
            Integer x1 = parser.getIntValue();
            parser.nextToken();
            parser.nextToken();
            Integer y1 = parser.getIntValue();
            parser.nextToken();
            parser.nextToken();
            Bounds b = DcFactory.eINSTANCE.createBounds();
            b.setX(x1);
            b.setY(y1);
            b.setWidth(x2 - x1);
            b.setHeight(y2 - y1);
            this._bounds.put(resourceId, b);
        } else if ("dockers".equals(fieldname)) {
            // "dockers":[{"x":50,"y":40},{"x":353.5,"y":115},{"x":353.5,"y":152},{"x":50,"y":40}],
            List<Point> dockers = new ArrayList<Point>();
            JsonToken nextToken = parser.nextToken();
            boolean end = JsonToken.END_ARRAY.equals(nextToken);
            while (!end) {
                nextToken = parser.nextToken();
                nextToken = parser.nextToken();
                Integer x = parser.getIntValue();
                parser.nextToken();
                parser.nextToken();
                Integer y = parser.getIntValue();
                Point point = DcFactory.eINSTANCE.createPoint();
                point.setX(x);
                point.setY(y);
                dockers.add(point);
                parser.nextToken();
                nextToken = parser.nextToken();
                end = JsonToken.END_ARRAY.equals(nextToken);
            }
            this._dockers.put(resourceId, dockers);
        } else if ("outgoing".equals(fieldname)) {
            while (parser.nextToken() != JsonToken.END_ARRAY) {
                // {resourceId: oryx_1AAA8C9A-39A5-42FC-8ED1-507A7F3728EA}
                parser.nextToken();
                parser.nextToken();
                outgoing.add(parser.getText());
                parser.nextToken();
            }
            // pass on the array
            parser.skipChildren();
        } else if ("target".equals(fieldname)) {
            // we already collected that info with the outgoing field.
            parser.skipChildren();
        // "target": {
        // "resourceId": "oryx_A75E7546-DF71-48EA-84D3-2A8FD4A47568"
        // }
        // add to the map:
        // parser.nextToken(); // resourceId:
        // parser.nextToken(); // the value we want to save
        // targetId = parser.getText();
        // parser.nextToken(); // }, closing the object
        }
    }
    properties.put("resourceId", resourceId);
    boolean customElement = isCustomElement(properties.get("tasktype"), preProcessingData);
    BaseElement baseElt = this.createBaseElement(stencil, properties.get("tasktype"), customElement);
    // register the sequence flow targets.
    if (baseElt instanceof SequenceFlow) {
        _sequenceFlowTargets.addAll(outgoing);
    }
    _outgoingFlows.put(baseElt, outgoing);
    _objMap.put(baseElt, // keep the object around to do connections
    resourceId);
    _idMap.put(resourceId, baseElt);
    // baseElt.setId(resourceId); commented out as bpmn2 seems to create
    // duplicate ids right now.
    applyProperties(baseElt, properties, preProcessingData);
    if (baseElt instanceof Definitions) {
        Process rootLevelProcess = null;
        if (childElements == null || childElements.size() < 1) {
            if (rootLevelProcess == null) {
                rootLevelProcess = Bpmn2Factory.eINSTANCE.createProcess();
                // set the properties and item definitions first
                if (properties.get("vardefs") != null && properties.get("vardefs").length() > 0) {
                    String[] vardefs = properties.get("vardefs").split(",\\s*");
                    for (String vardef : vardefs) {
                        Property prop = Bpmn2Factory.eINSTANCE.createProperty();
                        ItemDefinition itemdef = Bpmn2Factory.eINSTANCE.createItemDefinition();
                        // check if we define a structure ref in the definition
                        if (vardef.contains(":")) {
                            String[] vardefParts = vardef.split(":\\s*");
                            prop.setId(vardefParts[0]);
                            itemdef.setId("_" + prop.getId() + "Item");
                            boolean haveKPI = false;
                            String kpiValue = "";
                            if (vardefParts.length == 3) {
                                itemdef.setStructureRef(vardefParts[1]);
                                if (vardefParts[2].equals("true")) {
                                    haveKPI = true;
                                    kpiValue = vardefParts[2];
                                }
                            }
                            if (vardefParts.length == 2) {
                                if (vardefParts[1].equals("true") || vardefParts[1].equals("false")) {
                                    if (vardefParts[1].equals("true")) {
                                        haveKPI = true;
                                        kpiValue = vardefParts[1];
                                    }
                                } else {
                                    itemdef.setStructureRef(vardefParts[1]);
                                }
                            }
                            if (haveKPI) {
                                Utils.setMetaDataExtensionValue(prop, "customKPI", wrapInCDATABlock(kpiValue));
                            }
                        } else {
                            prop.setId(vardef);
                            itemdef.setId("_" + prop.getId() + "Item");
                        }
                        prop.setItemSubjectRef(itemdef);
                        rootLevelProcess.getProperties().add(prop);
                        ((Definitions) baseElt).getRootElements().add(itemdef);
                    }
                }
                if (properties.get("adhocprocess") != null && properties.get("adhocprocess").equals("true")) {
                    ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
                    EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "adHoc", false, false);
                    SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("adhocprocess"));
                    rootLevelProcess.getAnyAttribute().add(extensionEntry);
                }
                if (properties.get("customdescription") != null && properties.get("customdescription").length() > 0) {
                    Utils.setMetaDataExtensionValue(rootLevelProcess, "customDescription", wrapInCDATABlock(properties.get("customdescription")));
                }
                rootLevelProcess.setId(properties.get("id"));
                applyProcessProperties(rootLevelProcess, properties);
                ((Definitions) baseElt).getRootElements().add(rootLevelProcess);
            }
        } else {
            for (BaseElement child : childElements) {
                // } else {
                if (child instanceof SequenceFlow) {
                    // for some reason sequence flows are placed as root elements.
                    // find if the target has a container, and if we can use it:
                    List<String> ids = _outgoingFlows.get(child);
                    FlowElementsContainer container = null;
                    for (String id : ids) {
                        // yes, we iterate, but we'll take the first in the list that will work.
                        Object obj = _idMap.get(id);
                        if (obj instanceof EObject && ((EObject) obj).eContainer() instanceof FlowElementsContainer) {
                            container = (FlowElementsContainer) ((EObject) obj).eContainer();
                            break;
                        }
                    }
                    if (container != null) {
                        container.getFlowElements().add((SequenceFlow) child);
                        continue;
                    }
                }
                if (child instanceof Task || child instanceof SequenceFlow || child instanceof Gateway || child instanceof Event || child instanceof Artifact || child instanceof DataObject || child instanceof SubProcess || child instanceof Lane || child instanceof CallActivity || child instanceof TextAnnotation) {
                    if (rootLevelProcess == null) {
                        rootLevelProcess = Bpmn2Factory.eINSTANCE.createProcess();
                        // set the properties and item definitions first
                        if (properties.get("vardefs") != null && properties.get("vardefs").length() > 0) {
                            String[] vardefs = properties.get("vardefs").split(",\\s*");
                            for (String vardef : vardefs) {
                                Property prop = Bpmn2Factory.eINSTANCE.createProperty();
                                ItemDefinition itemdef = Bpmn2Factory.eINSTANCE.createItemDefinition();
                                // check if we define a structure ref in the definition
                                if (vardef.contains(":")) {
                                    String[] vardefParts = vardef.split(":\\s*");
                                    prop.setId(vardefParts[0]);
                                    itemdef.setId("_" + prop.getId() + "Item");
                                    boolean haveKPI = false;
                                    String kpiValue = "";
                                    if (vardefParts.length == 3) {
                                        itemdef.setStructureRef(vardefParts[1]);
                                        if (vardefParts[2].equals("true")) {
                                            haveKPI = true;
                                            kpiValue = vardefParts[2];
                                        }
                                    }
                                    if (vardefParts.length == 2) {
                                        if (vardefParts[1].equals("true") || vardefParts[1].equals("false")) {
                                            if (vardefParts[1].equals("true")) {
                                                haveKPI = true;
                                                kpiValue = vardefParts[1];
                                            }
                                        } else {
                                            itemdef.setStructureRef(vardefParts[1]);
                                        }
                                    }
                                    if (haveKPI) {
                                        Utils.setMetaDataExtensionValue(prop, "customKPI", wrapInCDATABlock(kpiValue));
                                    }
                                } else {
                                    prop.setId(vardef);
                                    itemdef.setId("_" + prop.getId() + "Item");
                                }
                                prop.setItemSubjectRef(itemdef);
                                rootLevelProcess.getProperties().add(prop);
                                ((Definitions) baseElt).getRootElements().add(itemdef);
                            }
                        }
                        if (properties.get("adhocprocess") != null && properties.get("adhocprocess").equals("true")) {
                            ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
                            EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "adHoc", false, false);
                            SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("adhocprocess"));
                            rootLevelProcess.getAnyAttribute().add(extensionEntry);
                        }
                        if (properties.get("customdescription") != null && properties.get("customdescription").length() > 0) {
                            Utils.setMetaDataExtensionValue(rootLevelProcess, "customDescription", wrapInCDATABlock(properties.get("customdescription")));
                        }
                        rootLevelProcess.setId(properties.get("id"));
                        applyProcessProperties(rootLevelProcess, properties);
                        ((Definitions) baseElt).getRootElements().add(rootLevelProcess);
                    }
                }
                if (child instanceof Task) {
                    rootLevelProcess.getFlowElements().add((Task) child);
                } else if (child instanceof CallActivity) {
                    rootLevelProcess.getFlowElements().add((CallActivity) child);
                } else if (child instanceof RootElement) {
                    ((Definitions) baseElt).getRootElements().add((RootElement) child);
                } else if (child instanceof SequenceFlow) {
                    rootLevelProcess.getFlowElements().add((SequenceFlow) child);
                } else if (child instanceof Gateway) {
                    rootLevelProcess.getFlowElements().add((Gateway) child);
                } else if (child instanceof Event) {
                    rootLevelProcess.getFlowElements().add((Event) child);
                } else if (child instanceof TextAnnotation) {
                    rootLevelProcess.getFlowElements().add((TextAnnotation) child);
                } else if (child instanceof Artifact) {
                    rootLevelProcess.getArtifacts().add((Artifact) child);
                } else if (child instanceof DataObject) {
                    // bubble up data objects
                    // rootLevelProcess.getFlowElements().add(0, (DataObject) child);
                    rootLevelProcess.getFlowElements().add((DataObject) child);
                // ItemDefinition def = ((DataObject) child).getItemSubjectRef();
                // if (def != null) {
                // if (def.eResource() == null) {
                // ((Definitions) rootLevelProcess.eContainer()).getRootElements().add(0, def);
                // }
                // Import imported = def.getImport();
                // if (imported != null && imported.eResource() == null) {
                // ((Definitions) rootLevelProcess.eContainer()).getImports().add(0, imported);
                // }
                // }
                } else if (child instanceof SubProcess) {
                    rootLevelProcess.getFlowElements().add((SubProcess) child);
                } else if (child instanceof Lane) {
                // lanes handled later
                } else {
                    _logger.error("Don't know what to do of " + child);
                }
            // }
            }
        }
    } else if (baseElt instanceof Process) {
        for (BaseElement child : childElements) {
            if (child instanceof Lane) {
                if (((Process) baseElt).getLaneSets().isEmpty()) {
                    ((Process) baseElt).getLaneSets().add(Bpmn2Factory.eINSTANCE.createLaneSet());
                }
                ((Process) baseElt).getLaneSets().get(0).getLanes().add((Lane) child);
                addLaneFlowNodes((Process) baseElt, (Lane) child);
            } else if (child instanceof Artifact) {
                ((Process) baseElt).getArtifacts().add((Artifact) child);
            } else {
                _logger.error("Don't know what to do of " + child);
            }
        }
    } else if (baseElt instanceof SubProcess) {
        for (BaseElement child : childElements) {
            if (child instanceof FlowElement) {
                ((SubProcess) baseElt).getFlowElements().add((FlowElement) child);
            } else if (child instanceof Artifact) {
                ((SubProcess) baseElt).getArtifacts().add((Artifact) child);
            } else {
                _logger.error("Subprocess - don't know what to do of " + child);
            }
        }
    } else if (baseElt instanceof Message) {
    // we do not support base-element messages from the json. They are created dynamically for events that use them.
    } else if (baseElt instanceof Lane) {
        for (BaseElement child : childElements) {
            if (child instanceof FlowNode) {
                ((Lane) baseElt).getFlowNodeRefs().add((FlowNode) child);
            } else // }
            if (child instanceof Artifact) {
                _artifacts.add((Artifact) child);
            } else {
                _logger.error("Don't know what to do of " + childElements);
            }
        }
        _lanes.add((Lane) baseElt);
    } else {
        if (!childElements.isEmpty()) {
            _logger.error("Don't know what to do of " + childElements + " with " + baseElt);
        }
    }
    return baseElt;
}
Also used : ServiceTask(org.eclipse.bpmn2.ServiceTask) ReceiveTask(org.eclipse.bpmn2.ReceiveTask) SendTask(org.eclipse.bpmn2.SendTask) GlobalTask(org.eclipse.bpmn2.GlobalTask) BusinessRuleTask(org.eclipse.bpmn2.BusinessRuleTask) Task(org.eclipse.bpmn2.Task) ScriptTask(org.eclipse.bpmn2.ScriptTask) UserTask(org.eclipse.bpmn2.UserTask) Message(org.eclipse.bpmn2.Message) SequenceFlow(org.eclipse.bpmn2.SequenceFlow) ArrayList(java.util.ArrayList) ItemDefinition(org.eclipse.bpmn2.ItemDefinition) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) SubProcess(org.eclipse.bpmn2.SubProcess) Process(org.eclipse.bpmn2.Process) CallActivity(org.eclipse.bpmn2.CallActivity) EAttributeImpl(org.eclipse.emf.ecore.impl.EAttributeImpl) ExclusiveGateway(org.eclipse.bpmn2.ExclusiveGateway) Gateway(org.eclipse.bpmn2.Gateway) InclusiveGateway(org.eclipse.bpmn2.InclusiveGateway) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) List(java.util.List) JsonToken(com.fasterxml.jackson.core.JsonToken) SimpleFeatureMapEntry(org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry) TextAnnotation(org.eclipse.bpmn2.TextAnnotation) Property(org.eclipse.bpmn2.Property) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) SubProcess(org.eclipse.bpmn2.SubProcess) Bounds(org.eclipse.dd.dc.Bounds) Definitions(org.eclipse.bpmn2.Definitions) Lane(org.eclipse.bpmn2.Lane) FlowElementsContainer(org.eclipse.bpmn2.FlowElementsContainer) Point(org.eclipse.dd.dc.Point) Artifact(org.eclipse.bpmn2.Artifact) BaseElement(org.eclipse.bpmn2.BaseElement) DataObject(org.eclipse.bpmn2.DataObject) RootElement(org.eclipse.bpmn2.RootElement) FlowElement(org.eclipse.bpmn2.FlowElement) StartEvent(org.eclipse.bpmn2.StartEvent) Event(org.eclipse.bpmn2.Event) CatchEvent(org.eclipse.bpmn2.CatchEvent) BoundaryEvent(org.eclipse.bpmn2.BoundaryEvent) ThrowEvent(org.eclipse.bpmn2.ThrowEvent) EndEvent(org.eclipse.bpmn2.EndEvent) EObject(org.eclipse.emf.ecore.EObject) DataObject(org.eclipse.bpmn2.DataObject) ExtendedMetaData(org.eclipse.emf.ecore.util.ExtendedMetaData) FlowNode(org.eclipse.bpmn2.FlowNode)

Example 19 with TextAnnotation

use of org.eclipse.bpmn2.TextAnnotation in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method createDiagram.

private void createDiagram(Definitions def) {
    for (RootElement rootElement : def.getRootElements()) {
        if (rootElement instanceof Process) {
            Process process = (Process) rootElement;
            BpmnDiFactory factory = BpmnDiFactory.eINSTANCE;
            BPMNDiagram diagram = factory.createBPMNDiagram();
            BPMNPlane plane = factory.createBPMNPlane();
            plane.setBpmnElement(process);
            diagram.setPlane(plane);
            // first process flowNodes
            for (FlowElement flowElement : process.getFlowElements()) {
                if (flowElement instanceof FlowNode) {
                    createBpmnShapeForElement(factory, plane, flowElement);
                    if (flowElement instanceof BoundaryEvent) {
                        createDockersForBoundaryEvent((BoundaryEvent) flowElement);
                    }
                    // check if its a subprocess
                    if (flowElement instanceof SubProcess) {
                        createSubProcessDiagram(plane, flowElement, factory);
                    }
                } else if (flowElement instanceof DataObject) {
                    createBpmnShapeForElement(factory, plane, flowElement);
                } else if (flowElement instanceof SequenceFlow) {
                    createBpmnEdgeForSequenceFlow(factory, plane, (SequenceFlow) flowElement);
                }
            }
            // then process artifacts
            if (process.getArtifacts() != null) {
                List<Association> incompleteAssociations = new ArrayList<Association>();
                for (Artifact artifact : process.getArtifacts()) {
                    // if (artifact instanceof TextAnnotation || artifact instanceof Group) {
                    if (artifact instanceof Group) {
                        createBpmnShapeForElement(factory, plane, artifact);
                    }
                    if (artifact instanceof Association) {
                        Association association = (Association) artifact;
                        if (association.getSourceRef() != null && association.getTargetRef() != null) {
                            createBpmnEdgeForAssociation(factory, plane, association);
                        } else {
                            incompleteAssociations.add(association);
                        }
                    }
                }
                if (!incompleteAssociations.isEmpty()) {
                    for (Association incompleteAssociation : incompleteAssociations) {
                        process.getArtifacts().remove(incompleteAssociation);
                    }
                }
            }
            // finally process lanes
            if (process.getLaneSets() != null && process.getLaneSets().size() > 0) {
                for (LaneSet ls : process.getLaneSets()) {
                    for (Lane lane : ls.getLanes()) {
                        createBpmnShapeForElement(factory, plane, lane);
                    }
                }
            }
            def.getDiagrams().add(diagram);
        }
    }
}
Also used : AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) SubProcess(org.eclipse.bpmn2.SubProcess) Group(org.eclipse.bpmn2.Group) BoundaryEvent(org.eclipse.bpmn2.BoundaryEvent) SequenceFlow(org.eclipse.bpmn2.SequenceFlow) ArrayList(java.util.ArrayList) Lane(org.eclipse.bpmn2.Lane) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) SubProcess(org.eclipse.bpmn2.SubProcess) Process(org.eclipse.bpmn2.Process) LaneSet(org.eclipse.bpmn2.LaneSet) BpmnDiFactory(org.eclipse.bpmn2.di.BpmnDiFactory) Artifact(org.eclipse.bpmn2.Artifact) BPMNDiagram(org.eclipse.bpmn2.di.BPMNDiagram) RootElement(org.eclipse.bpmn2.RootElement) DataObject(org.eclipse.bpmn2.DataObject) Association(org.eclipse.bpmn2.Association) DataOutputAssociation(org.eclipse.bpmn2.DataOutputAssociation) DataInputAssociation(org.eclipse.bpmn2.DataInputAssociation) FlowElement(org.eclipse.bpmn2.FlowElement) BPMNPlane(org.eclipse.bpmn2.di.BPMNPlane) FlowNode(org.eclipse.bpmn2.FlowNode)

Example 20 with TextAnnotation

use of org.eclipse.bpmn2.TextAnnotation in project kie-wb-common by kiegroup.

the class Bpmn2JsonMarshaller method marshallNode.

protected void marshallNode(FlowNode node, Map<String, Object> properties, String stencil, BPMNPlane plane, JsonGenerator generator, float xOffset, float yOffset) throws JsonGenerationException, IOException {
    if (properties == null) {
        properties = new LinkedHashMap<String, Object>();
    }
    putDocumentationProperty(node, properties);
    if (node.getName() != null) {
        properties.put(NAME, StringEscapeUtils.unescapeXml(node.getName()));
    } else {
        if (node instanceof TextAnnotation) {
            if (((TextAnnotation) node).getText() != null) {
                properties.put(NAME, ((TextAnnotation) node).getText());
            } else {
                properties.put(NAME, "");
            }
        } else {
            properties.put(NAME, "");
        }
    }
    // overwrite name if elementname extension element is present
    String elementName = Utils.getMetaDataValue(node.getExtensionValues(), "elementname");
    if (elementName != null) {
        properties.put("name", elementName);
    }
    marshallProperties(properties, generator);
    generator.writeObjectFieldStart("stencil");
    generator.writeObjectField("id", stencil);
    generator.writeEndObject();
    generator.writeArrayFieldStart("childShapes");
    generator.writeEndArray();
    generator.writeArrayFieldStart("outgoing");
    for (SequenceFlow outgoing : node.getOutgoing()) {
        generator.writeStartObject();
        generator.writeObjectField("resourceId", outgoing.getId());
        generator.writeEndObject();
    }
    // we need to also add associations as outgoing elements
    Process process = (Process) plane.getBpmnElement();
    writeAssociations(process, node.getId(), generator);
    // and boundary events for activities
    List<BoundaryEvent> boundaryEvents = new ArrayList<BoundaryEvent>();
    findBoundaryEvents(process, boundaryEvents);
    for (BoundaryEvent be : boundaryEvents) {
        if (be.getAttachedToRef().getId().equals(node.getId())) {
            generator.writeStartObject();
            generator.writeObjectField("resourceId", be.getId());
            generator.writeEndObject();
        }
    }
    generator.writeEndArray();
    // boundary events have a docker
    if (node instanceof BoundaryEvent) {
        Iterator<FeatureMap.Entry> iter = node.getAnyAttribute().iterator();
        boolean foundDockerInfo = false;
        while (iter.hasNext()) {
            FeatureMap.Entry entry = iter.next();
            if (entry.getEStructuralFeature().getName().equals("dockerinfo")) {
                foundDockerInfo = true;
                String dockerInfoStr = String.valueOf(entry.getValue());
                if (dockerInfoStr != null && dockerInfoStr.length() > 0) {
                    if (dockerInfoStr.endsWith("|")) {
                        dockerInfoStr = dockerInfoStr.substring(0, dockerInfoStr.length() - 1);
                        String[] dockerInfoParts = dockerInfoStr.split("\\|");
                        String infoPartsToUse = dockerInfoParts[0];
                        String[] infoPartsToUseParts = infoPartsToUse.split("\\^");
                        if (infoPartsToUseParts != null && infoPartsToUseParts.length > 0) {
                            generator.writeArrayFieldStart("dockers");
                            generator.writeStartObject();
                            generator.writeObjectField("x", Double.valueOf(infoPartsToUseParts[0]));
                            generator.writeObjectField("y", Double.valueOf(infoPartsToUseParts[1]));
                            generator.writeEndObject();
                            generator.writeEndArray();
                        }
                    }
                }
            }
        }
        // backwards compatibility to older versions -- BZ 1196259
        if (!foundDockerInfo) {
            // find the edge associated with this boundary event
            for (DiagramElement element : plane.getPlaneElement()) {
                if (element instanceof BPMNEdge && ((BPMNEdge) element).getBpmnElement() == node) {
                    List<Point> waypoints = ((BPMNEdge) element).getWaypoint();
                    if (waypoints != null && waypoints.size() > 0) {
                        // one per boundary event
                        Point p = waypoints.get(0);
                        if (p != null) {
                            generator.writeArrayFieldStart("dockers");
                            generator.writeStartObject();
                            generator.writeObjectField("x", p.getX());
                            generator.writeObjectField("y", p.getY());
                            generator.writeEndObject();
                            generator.writeEndArray();
                        }
                    }
                }
            }
        }
    }
    BPMNShape shape = (BPMNShape) findDiagramElement(plane, node);
    Bounds bounds = shape.getBounds();
    correctEventNodeSize(shape);
    generator.writeObjectFieldStart("bounds");
    generator.writeObjectFieldStart("lowerRight");
    generator.writeObjectField("x", bounds.getX() + bounds.getWidth() - xOffset);
    generator.writeObjectField("y", bounds.getY() + bounds.getHeight() - yOffset);
    generator.writeEndObject();
    generator.writeObjectFieldStart("upperLeft");
    generator.writeObjectField("x", bounds.getX() - xOffset);
    generator.writeObjectField("y", bounds.getY() - yOffset);
    generator.writeEndObject();
    generator.writeEndObject();
}
Also used : BoundaryEvent(org.eclipse.bpmn2.BoundaryEvent) SequenceFlow(org.eclipse.bpmn2.SequenceFlow) Bounds(org.eclipse.dd.dc.Bounds) ArrayList(java.util.ArrayList) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) Process(org.eclipse.bpmn2.Process) SubProcess(org.eclipse.bpmn2.SubProcess) Point(org.eclipse.dd.dc.Point) BPMNShape(org.eclipse.bpmn2.di.BPMNShape) FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) DiagramElement(org.eclipse.dd.di.DiagramElement) Entry(java.util.Map.Entry) DataObject(org.eclipse.bpmn2.DataObject) TextAnnotation(org.eclipse.bpmn2.TextAnnotation) BPMNEdge(org.eclipse.bpmn2.di.BPMNEdge)

Aggregations

ArrayList (java.util.ArrayList)10 TextAnnotation (org.kie.workbench.common.dmn.api.definition.v1_1.TextAnnotation)9 FreeTextAnnotation (org.opencastproject.metadata.mpeg7.FreeTextAnnotation)7 TextAnnotation (org.opencastproject.metadata.mpeg7.TextAnnotation)7 List (java.util.List)6 View (org.kie.workbench.common.stunner.core.graph.content.view.View)6 KeywordAnnotation (org.opencastproject.metadata.mpeg7.KeywordAnnotation)4 Iterator (java.util.Iterator)3 Entry (java.util.Map.Entry)3 AdHocSubProcess (org.eclipse.bpmn2.AdHocSubProcess)3 BoundaryEvent (org.eclipse.bpmn2.BoundaryEvent)3 DataObject (org.eclipse.bpmn2.DataObject)3 Process (org.eclipse.bpmn2.Process)3 SequenceFlow (org.eclipse.bpmn2.SequenceFlow)3 SubProcess (org.eclipse.bpmn2.SubProcess)3 TextAnnotation (org.kie.dmn.model.v1_1.TextAnnotation)3 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.v1_1.BusinessKnowledgeModel)3 Decision (org.kie.workbench.common.dmn.api.definition.v1_1.Decision)3 InputData (org.kie.workbench.common.dmn.api.definition.v1_1.InputData)3 KnowledgeSource (org.kie.workbench.common.dmn.api.definition.v1_1.KnowledgeSource)3