Skip to content

Commit 3ef6f56

Browse files
#16 [ Modeler ] Complete validation (incomplete)
1 parent 2d3792e commit 3ef6f56

File tree

7 files changed

+469
-11
lines changed

7 files changed

+469
-11
lines changed

plugins/net.roboconf.eclipse.modeler/description/graph.odesign

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<description:Group xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:description="http://www.eclipse.org/sirius/description/1.1.0" xmlns:description_1="http://www.eclipse.org/sirius/diagram/description/1.1.0" xmlns:style="http://www.eclipse.org/sirius/diagram/description/style/1.1.0" xmlns:tool="http://www.eclipse.org/sirius/diagram/description/tool/1.1.0" xmlns:tool_1="http://www.eclipse.org/sirius/description/tool/1.1.0" xmlns:validation="http://www.eclipse.org/sirius/description/validation/1.1.0" name="graph" version="10.1.3.201511131800">
2+
<description:Group xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:description="http://www.eclipse.org/sirius/description/1.1.0" xmlns:description_1="http://www.eclipse.org/sirius/diagram/description/1.1.0" xmlns:style="http://www.eclipse.org/sirius/diagram/description/style/1.1.0" xmlns:tool="http://www.eclipse.org/sirius/diagram/description/tool/1.1.0" xmlns:tool_1="http://www.eclipse.org/sirius/description/tool/1.1.0" name="graph" version="10.1.3.201511131800">
33
<ownedViewpoints name="graph" label="Roboconf Graphs" modelFileExtension="graph-ui" icon="/net.roboconf.eclipse.modeler/icons/16x16/roboconf_16x16.jpg">
44
<ownedRepresentations xsi:type="description_1:DiagramDescription" name="Diagram" domainClass="Configuration" enablePopupBars="true">
55
<metamodel href="platform:/plugin/org.occiware.clouddesigner.occi/model/OCCI.ecore#/"/>
66
<metamodel href="../../net.roboconf.eclipse/occi.graph.model/model/roboconf-graph.ecore#/"/>
7-
<validationSet>
8-
<ownedRules xsi:type="validation:SemanticValidationRule" name="facet cannot inherit from components" level="ERROR" message="Facets cannot inherit from components." targetClass="roboconfgraph.RoboconfInheritanceLink">
9-
<audits auditExpression="aql:if( self.source. oclIsKindOf(roboconfgraph::RoboconfFacet)) then self.target.oclIsKindOf(roboconfgraph::RoboconfComponent)"/>
10-
</ownedRules>
11-
<ownedRules xsi:type="validation:SemanticValidationRule" name="a component cannot inherit from more than one component" level="ERROR" targetClass="roboconfgraph.RoboconfComponent">
12-
<audits auditExpression="aql:container.links->select(i | i.oclIsKindOf(roboconfgraph::RoboconfInheritanceLink)->filter(j | j.target.oclIsKindOf(roboconfgraph::RoboconfComponent).size() &lt;= 1"/>
13-
</ownedRules>
14-
</validationSet>
157
<defaultLayer name="Default">
168
<nodeMappings name="component" labelDirectEdit="//@ownedViewpoints[name='graph']/@ownedRepresentations[name='Diagram']/@defaultLayer/@toolSections.1/@ownedTools[name='editName']" doubleClickDescription="//@ownedViewpoints[name='graph']/@ownedRepresentations[name='Diagram']/@defaultLayer/@toolSections.2/@ownedTools[name='select%20image']" domainClass="roboconfgraph.RoboconfComponent">
179
<style xsi:type="style:WorkspaceImageDescription" labelSize="12" showIcon="false" tooltipExpression="feature:name" sizeComputationExpression="16" resizeKind="NSEW" roundedCorner="true" workspacePath="/net.roboconf.eclipse.modeler/icons/16x16/default-component.svg">
@@ -45,8 +37,6 @@
4537
<firstModelOperations xsi:type="tool_1:CreateInstance" typeName="roboconfgraph.RoboconfComponent" referenceName="resources">
4638
<subModelOperations xsi:type="tool_1:SetValue" featureName="name" valueExpression="aql:'Component '+container.resources->filter(roboconfgraph::RoboconfComponent)->size()"/>
4739
<subModelOperations xsi:type="tool_1:SetValue" featureName="title" valueExpression="aql:instance.id"/>
48-
<subModelOperations xsi:type="tool_1:ChangeContext" browseExpression="aql:self"/>
49-
<subModelOperations xsi:type="tool_1:ExternalJavaActionCall" name="Set installer name" action="//@ownedViewpoints[name='graph']/@ownedRepresentations[name='Diagram']/@defaultLayer/@toolSections.2/@ownedTools[name='Set%20Installer%20Name']"/>
5040
</firstModelOperations>
5141
</initialOperation>
5242
</ownedTools>

plugins/net.roboconf.eclipse.modeler/plugin.xml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,85 @@
163163
</command>
164164
</menuContribution>
165165
</extension>
166+
<extension
167+
point="org.eclipse.emf.validation.constraintProviders">
168+
<constraintProvider
169+
cache="true">
170+
<package
171+
namespaceUri="http://roboconf.net/graph/ecore">
172+
</package>
173+
<constraints
174+
categories="net.roboconf.eclipse.modeler.emfconstraints">
175+
<constraint
176+
class="net.roboconf.eclipse.modeler.emfconstraints.InheritanceConstraint"
177+
id="net.roboconf.eclipse.modeler.InheritanceConstraint"
178+
isEnabledByDefault="true"
179+
lang="java"
180+
mode="Batch"
181+
name="Verify constraints about direct inheritance"
182+
severity="ERROR"
183+
statusCode="1">
184+
<message>
185+
{0}
186+
</message>
187+
<target
188+
class="RoboconfFacet">
189+
</target>
190+
</constraint>
191+
<constraint
192+
class="net.roboconf.eclipse.modeler.emfconstraints.TransitiveInheritanceConstraint"
193+
id="net.roboconf.eclipse.modeler.TransitiveInheritanceConstraint"
194+
isEnabledByDefault="true"
195+
lang="java"
196+
mode="Batch"
197+
name="A facet or a component cannot directly or indirectly inherit from themsleves"
198+
severity="ERROR"
199+
statusCode="1">
200+
<message>
201+
{0}
202+
</message>
203+
<target
204+
class="RoboconfFacet">
205+
</target>
206+
</constraint>
207+
<constraint
208+
class="net.roboconf.eclipse.modeler.emfconstraints.TransitiveParentshipConstraint"
209+
id="net.roboconf.eclipse.modeler.SelfParentshipConstraint"
210+
isEnabledByDefault="true"
211+
lang="java"
212+
mode="Batch"
213+
name="A facet or a component cannot directly or indirectly have themselves as a children"
214+
severity="ERROR"
215+
statusCode="1">
216+
<message>
217+
{0}
218+
</message>
219+
<target
220+
class="RoboconfFacet">
221+
</target>
222+
</constraint>
223+
<constraint
224+
class="net.roboconf.eclipse.modeler.emfconstraints.SelfDependencyConstraint"
225+
id="net.roboconf.eclipse.modeler.SelfDependencyConstraint"
226+
isEnabledByDefault="true"
227+
lang="java"
228+
mode="Batch"
229+
name="A facet or a component cannot have a dependency to themselves unless the dependency is optional"
230+
severity="ERROR"
231+
statusCode="1">
232+
<message>
233+
{0}
234+
</message>
235+
<target
236+
class="RoboconfFacet">
237+
</target>
238+
</constraint>
239+
</constraints>
240+
</constraintProvider>
241+
<category
242+
id="net.roboconf.eclipse.modeler.emfconstraints"
243+
mandatory="true"
244+
name="EMF Constraints for Roboconf OCCI Model">
245+
</category>
246+
</extension>
166247
</plugin>
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/**
2+
* Copyright 2016 Linagora, Université Joseph Fourier, Floralis
3+
*
4+
* The present code is developed in the scope of the joint LINAGORA -
5+
* Université Joseph Fourier - Floralis research program and is designated
6+
* as a "Result" pursuant to the terms and conditions of the LINAGORA
7+
* - Université Joseph Fourier - Floralis research program. Each copyright
8+
* holder of Results enumerated here above fully & independently holds complete
9+
* ownership of the complete Intellectual Property rights applicable to the whole
10+
* of said Results, and may freely exploit it in any manner which does not infringe
11+
* the moral rights of the other copyright holders.
12+
*
13+
* Licensed under the Apache License, Version 2.0 (the "License");
14+
* you may not use this file except in compliance with the License.
15+
* You may obtain a copy of the License at
16+
*
17+
* http://www.apache.org/licenses/LICENSE-2.0
18+
*
19+
* Unless required by applicable law or agreed to in writing, software
20+
* distributed under the License is distributed on an "AS IS" BASIS,
21+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22+
* See the License for the specific language governing permissions and
23+
* limitations under the License.
24+
*/
25+
26+
package net.roboconf.eclipse.modeler.emfconstraints;
27+
28+
import java.util.HashSet;
29+
import java.util.Set;
30+
31+
import org.eclipse.core.runtime.IStatus;
32+
import org.eclipse.emf.ecore.EObject;
33+
import org.eclipse.emf.validation.AbstractModelConstraint;
34+
import org.eclipse.emf.validation.EMFEventType;
35+
import org.eclipse.emf.validation.IValidationContext;
36+
import org.occiware.clouddesigner.occi.Link;
37+
import org.occiware.clouddesigner.occi.Resource;
38+
39+
import net.roboconf.eclipse.occi.graph.roboconfgraph.RoboconfComponent;
40+
import net.roboconf.eclipse.occi.graph.roboconfgraph.RoboconfFacet;
41+
42+
/**
43+
* @author Vincent Zurczak - Linagora
44+
*/
45+
public abstract class AbstractRoboconfModelConstraint extends AbstractModelConstraint {
46+
47+
@Override
48+
public IStatus validate( IValidationContext ctx ) {
49+
50+
EObject objectToCheck = ctx.getTarget();
51+
EMFEventType typeEvenement = ctx.getEventType();
52+
if( typeEvenement == EMFEventType.NULL ) {
53+
54+
String errorMsg = null;
55+
if( objectToCheck instanceof RoboconfComponent )
56+
errorMsg = validate((RoboconfComponent) objectToCheck);
57+
else if( objectToCheck instanceof RoboconfFacet )
58+
errorMsg = validate((RoboconfFacet) objectToCheck);
59+
60+
if( errorMsg != null )
61+
return ctx.createFailureStatus( new Object[] { errorMsg });
62+
}
63+
64+
return ctx.createSuccessStatus();
65+
}
66+
67+
68+
/**
69+
* @param component a non-null component
70+
* @return an error message, or null if everything is fine
71+
*/
72+
public abstract String validate( RoboconfComponent component );
73+
74+
75+
/**
76+
* @param component a non-null facet
77+
* @return an error message, or null if everything is fine
78+
*/
79+
public abstract String validate( RoboconfFacet facet );
80+
81+
82+
/**
83+
* Start from a given type and follow the relations of a given type.
84+
* @param facet a non-null type (facet or component)
85+
* @return a non-null set of resources
86+
*/
87+
protected Set<Resource> filterTargetsByLink( RoboconfFacet facet, Class<? extends Link> clazz ) {
88+
89+
Set<Resource> linkTargets = new HashSet<> ();
90+
Set<Resource> alreadyProcessed = new HashSet<> ();
91+
92+
Set<Resource> toProcess = new HashSet<> ();
93+
toProcess.add( facet );
94+
95+
while( ! toProcess.isEmpty()) {
96+
Resource f = toProcess.iterator().next();
97+
toProcess.remove( f );
98+
alreadyProcessed.add( f );
99+
100+
for( Link link : f.getLinks()) {
101+
if( clazz.isAssignableFrom( link.getClass())) {
102+
103+
linkTargets.add( link.getTarget());
104+
if( ! alreadyProcessed.contains( link.getTarget()))
105+
toProcess.add( link.getTarget());
106+
}
107+
}
108+
}
109+
110+
return linkTargets;
111+
}
112+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/**
2+
* Copyright 2016 Linagora, Université Joseph Fourier, Floralis
3+
*
4+
* The present code is developed in the scope of the joint LINAGORA -
5+
* Université Joseph Fourier - Floralis research program and is designated
6+
* as a "Result" pursuant to the terms and conditions of the LINAGORA
7+
* - Université Joseph Fourier - Floralis research program. Each copyright
8+
* holder of Results enumerated here above fully & independently holds complete
9+
* ownership of the complete Intellectual Property rights applicable to the whole
10+
* of said Results, and may freely exploit it in any manner which does not infringe
11+
* the moral rights of the other copyright holders.
12+
*
13+
* Licensed under the Apache License, Version 2.0 (the "License");
14+
* you may not use this file except in compliance with the License.
15+
* You may obtain a copy of the License at
16+
*
17+
* http://www.apache.org/licenses/LICENSE-2.0
18+
*
19+
* Unless required by applicable law or agreed to in writing, software
20+
* distributed under the License is distributed on an "AS IS" BASIS,
21+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22+
* See the License for the specific language governing permissions and
23+
* limitations under the License.
24+
*/
25+
26+
package net.roboconf.eclipse.modeler.emfconstraints;
27+
28+
import org.occiware.clouddesigner.occi.Link;
29+
import org.occiware.clouddesigner.occi.Resource;
30+
31+
import net.roboconf.eclipse.occi.graph.roboconfgraph.RoboconfComponent;
32+
import net.roboconf.eclipse.occi.graph.roboconfgraph.RoboconfFacet;
33+
import net.roboconf.eclipse.occi.graph.roboconfgraph.RoboconfInheritanceLink;
34+
35+
/**
36+
* Inheritances constraints.
37+
* <p>
38+
* Facets can only inherit from facets and a component can only inherit
39+
* from facets and from a single component.
40+
* </p>
41+
*
42+
* @author Vincent Zurczak - Linagora
43+
*/
44+
public class InheritanceConstraint extends AbstractRoboconfModelConstraint {
45+
46+
@Override
47+
public String validate( RoboconfComponent component ) {
48+
49+
int cpt = 0;
50+
for( Link link : component.getLinks()) {
51+
if( !( link instanceof RoboconfInheritanceLink ))
52+
continue;
53+
54+
Resource res = link.getTarget();
55+
if( res instanceof RoboconfComponent )
56+
cpt ++;
57+
}
58+
59+
String result = cpt <= 1 ? null : "A component can only inherit from facets and from a single component.";
60+
return result;
61+
}
62+
63+
64+
@Override
65+
public String validate( RoboconfFacet facet ) {
66+
67+
String result = null;
68+
for( Link link : facet.getLinks()) {
69+
if( !( link instanceof RoboconfInheritanceLink ))
70+
continue;
71+
72+
if( link.getTarget() instanceof RoboconfComponent ) {
73+
result = "A facet can only inherit from facets.";
74+
break;
75+
}
76+
}
77+
78+
return result;
79+
}
80+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* Copyright 2016 Linagora, Université Joseph Fourier, Floralis
3+
*
4+
* The present code is developed in the scope of the joint LINAGORA -
5+
* Université Joseph Fourier - Floralis research program and is designated
6+
* as a "Result" pursuant to the terms and conditions of the LINAGORA
7+
* - Université Joseph Fourier - Floralis research program. Each copyright
8+
* holder of Results enumerated here above fully & independently holds complete
9+
* ownership of the complete Intellectual Property rights applicable to the whole
10+
* of said Results, and may freely exploit it in any manner which does not infringe
11+
* the moral rights of the other copyright holders.
12+
*
13+
* Licensed under the Apache License, Version 2.0 (the "License");
14+
* you may not use this file except in compliance with the License.
15+
* You may obtain a copy of the License at
16+
*
17+
* http://www.apache.org/licenses/LICENSE-2.0
18+
*
19+
* Unless required by applicable law or agreed to in writing, software
20+
* distributed under the License is distributed on an "AS IS" BASIS,
21+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22+
* See the License for the specific language governing permissions and
23+
* limitations under the License.
24+
*/
25+
26+
package net.roboconf.eclipse.modeler.emfconstraints;
27+
28+
import org.occiware.clouddesigner.occi.Link;
29+
30+
import net.roboconf.eclipse.occi.graph.roboconfgraph.RoboconfComponent;
31+
import net.roboconf.eclipse.occi.graph.roboconfgraph.RoboconfFacet;
32+
import net.roboconf.eclipse.occi.graph.roboconfgraph.RoboconfRuntimeLink;
33+
34+
/**
35+
* A Roboconf type cannot depend on it self unless the dependency is optional.
36+
* @author Vincent Zurczak - Linagora
37+
*/
38+
public class SelfDependencyConstraint extends AbstractRoboconfModelConstraint {
39+
40+
@Override
41+
public String validate( RoboconfComponent component ) {
42+
return validate( component, "component" );
43+
}
44+
45+
@Override
46+
public String validate( RoboconfFacet facet ) {
47+
return validate( facet, "facet" );
48+
}
49+
50+
51+
private String validate( RoboconfFacet facet, String type ) {
52+
53+
String result = null;
54+
for( Link link : facet.getLinks()) {
55+
if( !( link instanceof RoboconfRuntimeLink ))
56+
continue;
57+
58+
// if( link.getTarget().equals( facet )
59+
// && ! ((RoboconfRuntimeLink) link).) {
60+
// result = "A facet can only inherit from facets.";
61+
// break;
62+
// }
63+
}
64+
65+
return result;
66+
}
67+
}

0 commit comments

Comments
 (0)