Skip to content

Commit

Permalink
[2131] The validation rule I_07 should use diagram descriptors instead
Browse files Browse the repository at this point in the history
of diagrams

Bug: 2131
Change-Id: I58a46e657ba6c49b9b954bd97ed4a19e38fcb9e0
Signed-off-by: Tu Ton <minhtutonthat@gmail.com>
  • Loading branch information
minhtutonthat committed Jul 30, 2018
1 parent 868aced commit af88f09
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 129 deletions.
@@ -1,102 +1,102 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<!--
Copyright (c) 2006, 2016 THALES GLOBAL SERVICES.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html
Contributors:
Thales - initial API and implementation
-->
<plugin>
<extension
point="org.polarsys.capella.core.validation.ui.ide.capellaQuickFix">
<resolver
class="org.polarsys.capella.core.platform.sirius.sirius.validation.ddiagram.I_22_Resolver"
desc="%quickFix.I_22_Resolver.desc"
label="%quickFix.I_22_Resolver.label"
icon="icons/search16.gif">
<rules
ruleId="I_22">
</rules>
</resolver>
<resolver
class="org.polarsys.capella.core.platform.sirius.sirius.validation.ddiagram.I_23_Resolver"
desc="%quickFix.I_23_Resolver.desc"
icon="icons/search16.gif"
label="%quickFix.I_23_Resolver.label">
<rules
ruleId="I_23">
</rules>
</resolver>
</extension>
<extension point="org.eclipse.emf.validation.constraintProviders">
<constraintProvider>
<package
namespaceUri="http://www.polarsys.org/capella/core/core/1.2.0">
</package>
<constraints
categories="capella.category/integrity">
<constraint
class="org.polarsys.capella.core.platform.sirius.sirius.validation.ddiagram.CapellaElementNamingConflictDiagram"
id="I_07"
isEnabledByDefault="true"
lang="Java"
mode="Batch"
name="I_07 - Diagram Naming conflicts check"
severity="WARNING"
statusCode="1">
<message>
{0}"{1}" content has a naming conflict for: {2}.
</message>
<description>
This rule checks that a diagram doesn&apos;t contain a naming conflict.
</description>
<target
class="CapellaElement">
</target>
</constraint>
<constraint
class="org.polarsys.capella.core.platform.sirius.sirius.validation.ddiagram.CapellaElementInDescriptionNameCheck"
id="I_22"
isEnabledByDefault="false"
lang="java"
mode="Batch"
name="I_22 - HyperLink to capella element or diagram name check"
severity="ERROR"
statusCode="1">
<message>
{0}
</message>
<target
class="CapellaElement">
</target>
<description>
This rule ensures that hyperLinks to capella elements or diagrams names are up to date.
</description>
</constraint>
<constraint
class="org.polarsys.capella.core.platform.sirius.sirius.validation.ddiagram.CapellaElementInDescriptionExistanceCheck"
id="I_23"
isEnabledByDefault="false"
lang="java"
mode="Batch"
name="I_23 - HyperLink to capella element or diagram existance check"
severity="ERROR"
statusCode="1">
<message>
{0}
</message>
<target
class="CapellaElement">
</target>
<description>
This rule ensures that hyperLinks to non existing capella element or diagram are removed from the description.
</description>
</constraint>
</constraints>
</constraintProvider>
</extension>
</plugin>
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<!--
Copyright (c) 2006, 2018 THALES GLOBAL SERVICES.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html
Contributors:
Thales - initial API and implementation
-->
<plugin>
<extension
point="org.polarsys.capella.core.validation.ui.ide.capellaQuickFix">
<resolver
class="org.polarsys.capella.core.platform.sirius.sirius.validation.ddiagram.I_22_Resolver"
desc="%quickFix.I_22_Resolver.desc"
label="%quickFix.I_22_Resolver.label"
icon="icons/search16.gif">
<rules
ruleId="I_22">
</rules>
</resolver>
<resolver
class="org.polarsys.capella.core.platform.sirius.sirius.validation.ddiagram.I_23_Resolver"
desc="%quickFix.I_23_Resolver.desc"
icon="icons/search16.gif"
label="%quickFix.I_23_Resolver.label">
<rules
ruleId="I_23">
</rules>
</resolver>
</extension>
<extension point="org.eclipse.emf.validation.constraintProviders">
<constraintProvider>
<package
namespaceUri="http://www.polarsys.org/capella/core/core/1.2.0">
</package>
<constraints
categories="capella.category/integrity">
<constraint
class="org.polarsys.capella.core.platform.sirius.sirius.validation.ddiagram.CapellaElementNamingConflictDiagram"
id="I_07"
isEnabledByDefault="true"
lang="Java"
mode="Batch"
name="I_07 - Diagram Naming conflicts check"
severity="WARNING"
statusCode="1">
<message>
{0}"{1}" content has a naming conflict for: {2}.
</message>
<description>
This rule checks that a diagram doesn&apos;t contain naming conflict with other diagrams of the same type.
</description>
<target
class="CapellaElement">
</target>
</constraint>
<constraint
class="org.polarsys.capella.core.platform.sirius.sirius.validation.ddiagram.CapellaElementInDescriptionNameCheck"
id="I_22"
isEnabledByDefault="false"
lang="java"
mode="Batch"
name="I_22 - HyperLink to capella element or diagram name check"
severity="ERROR"
statusCode="1">
<message>
{0}
</message>
<target
class="CapellaElement">
</target>
<description>
This rule ensures that hyperLinks to capella elements or diagrams names are up to date.
</description>
</constraint>
<constraint
class="org.polarsys.capella.core.platform.sirius.sirius.validation.ddiagram.CapellaElementInDescriptionExistanceCheck"
id="I_23"
isEnabledByDefault="false"
lang="java"
mode="Batch"
name="I_23 - HyperLink to capella element or diagram existance check"
severity="ERROR"
statusCode="1">
<message>
{0}
</message>
<target
class="CapellaElement">
</target>
<description>
This rule ensures that hyperLinks to non existing capella element or diagram are removed from the description.
</description>
</constraint>
</constraints>
</constraintProvider>
</extension>
</plugin>
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2014 THALES GLOBAL SERVICES.
* Copyright (c) 2006, 2018 THALES GLOBAL SERVICES.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand All @@ -24,8 +24,7 @@
import org.eclipse.sirius.business.api.dialect.DialectManager;
import org.eclipse.sirius.business.api.session.Session;
import org.eclipse.sirius.business.api.session.SessionManager;
import org.eclipse.sirius.diagram.DDiagram;
import org.eclipse.sirius.viewpoint.DRepresentation;
import org.eclipse.sirius.viewpoint.DRepresentationDescriptor;
import org.polarsys.capella.common.data.modellingcore.AbstractRelationship;
import org.polarsys.capella.core.data.capellacore.CapellaElement;
import org.polarsys.capella.core.validation.rule.AbstractValidationRule;
Expand All @@ -48,18 +47,18 @@ public class CapellaElementNamingConflictDiagram extends AbstractValidationRule
private static final String TYPE_PREFIX = " ("; //$NON-NLS-1$

@Override
public IStatus validate(IValidationContext ctx_p) {
EObject eObj = ctx_p.getTarget();
EMFEventType eType = ctx_p.getEventType();
if (eType == EMFEventType.NULL) {
public IStatus validate(IValidationContext ctx) {
EObject eObj = ctx.getTarget();
EMFEventType eType = ctx.getEventType();
if (eType == EMFEventType.NULL && eObj instanceof CapellaElement) {

// Do not check "naming conflicts" under scenarios and capabilities
if (eObj instanceof CapellaElement) {

// This collection will store the conflicts statuses
Collection<IStatus> statuses = new ArrayList<IStatus>();
Collection<IStatus> statuses = new ArrayList<>();
boolean hasConflict = false;
// Creates a Map which will map each type with a list of the instances names of this type
Map<String, List<String>> typesAndNames = new HashMap<String, List<String>>();
Map<String, List<String>> typesAndNames = new HashMap<>();
CapellaElement elt = (CapellaElement) eObj;

// look for diagram naming conflict
Expand All @@ -68,33 +67,30 @@ public IStatus validate(IValidationContext ctx_p) {
final Session curSession = SessionManager.INSTANCE.getSession(elt);
if (curSession != null) {
// get all diagram element contained by given element
final Collection<DRepresentation> allRepresentations = DialectManager.INSTANCE.getRepresentations(elt, curSession);
for (DRepresentation dRepresentation : allRepresentations) {
if (dRepresentation instanceof DDiagram) {
DDiagram diagram = (DDiagram) dRepresentation;
// Gets the name and the type of the current element
String currentElementName = diagram.getName();
String currentElementType = diagram.eClass().getName();
hasConflict = checkTheNamingConflict(ctx_p, statuses, hasConflict, typesAndNames, elt, currentElementName, currentElementType);
}
final Collection<DRepresentationDescriptor> allRepresentationDescriptors = DialectManager.INSTANCE.getRepresentationDescriptors(elt, curSession);
for (DRepresentationDescriptor dRepresentationDescriptor : allRepresentationDescriptors) {
String currentElementName = dRepresentationDescriptor.getName();
if (dRepresentationDescriptor.getDescription() != null) {
String currentElementType = dRepresentationDescriptor.getDescription().getName();
hasConflict |= checkTheNamingConflict(ctx, statuses, typesAndNames, elt, currentElementName, currentElementType);
}
}
}
}

if (hasConflict) {
// There are conflicts
// Returns them as a multiStatuses status
return ConstraintStatus.createMultiStatus(ctx_p, statuses);
return ConstraintStatus.createMultiStatus(ctx, statuses);
}
}
}
// No conflict found
return ctx_p.createSuccessStatus();
return ctx.createSuccessStatus();
}

/**
* create failure message if any naming conflict
* @param ctx_p
* @param ctx
* @param statuses
* @param hasConflict
* @param typesAndNames
Expand All @@ -103,13 +99,13 @@ public IStatus validate(IValidationContext ctx_p) {
* @param currentElementType
* @return
*/
private boolean checkTheNamingConflict(IValidationContext ctx_p, Collection<IStatus> statuses, boolean hasConflict_p,
private boolean checkTheNamingConflict(IValidationContext ctx, Collection<IStatus> statuses,
Map<String, List<String>> typesAndNames, CapellaElement elt, String currentElementName, String currentElementType) {
boolean hasConflict = hasConflict_p;
boolean hasConflict = false;
if (!typesAndNames.containsKey(currentElementType)) {
// This type doesn't have a map entry
// Creates the map entry for the type
List<String> names = new ArrayList<String>();
List<String> names = new ArrayList<>();
names.add(currentElementName);
typesAndNames.put(currentElementType, names);
} else {
Expand All @@ -124,7 +120,7 @@ private boolean checkTheNamingConflict(IValidationContext ctx_p, Collection<ISta
alreadyExist = true;
// Creates a conflict status
String currentConflict = TYPE_PREFIX + currentElementType + TYPE_SUFFIX + currentElementName;
IStatus failureStatus = createFailureStatus(ctx_p, new Object[] { elt.eClass().getName(), elt.getLabel(), currentConflict });
IStatus failureStatus = createFailureStatus(ctx, new Object[] { elt.eClass().getName(), elt.getLabel(), currentConflict });
statuses.add(failureStatus);
break;
}
Expand Down

0 comments on commit af88f09

Please sign in to comment.