\r
import java.util.ArrayList;\r
import java.util.Collections;\r
+import java.util.Iterator;\r
import java.util.List;\r
import java.util.Set;\r
\r
-import org.simantics.databoard.Bindings;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.common.utils.ListUtils;\r
ArrayList<Issue> result = new ArrayList<Issue>();\r
\r
\r
+ StandardIssue noSuchVariableIssue = null;\r
// Check that all references have corresponding arrows\r
if(references != null && dependencies != null) {\r
for(String reference : references) {\r
if((variable = ValidationUtils.reach(graph, component, reference)) != null) {\r
result.add(new StandardIssue(sr.Validations_MissingLinkIssue, component, variable));\r
} else {\r
- result.add(new NoSuchVariableIssue(sr.Validations_NoSuchVariableIssue, reference, component));\r
+ if(noSuchVariableIssue == null) {\r
+ noSuchVariableIssue = new StandardIssue(sr.Validations_NoSuchVariableIssue, component);\r
+ result.add(noSuchVariableIssue);\r
+ }\r
}\r
} \r
}\r
}\r
return result;\r
}\r
- \r
+\r
/**\r
* Unused dependency description\r
* \r
}\r
\r
/**\r
- * No such variable description\r
+ * No such variable description. Finds all variables that the component refers to and adds\r
+ * their names to the issue description.\r
+ * \r
* @param graph ReadGraph\r
* @param converter\r
* @param issue Issue\r
*/\r
@SCLValue(type = "ReadGraph -> Resource -> Variable -> String")\r
public static String noSuchVariableIssueDescription(ReadGraph graph, Resource converter, Variable issue) throws DatabaseException {\r
- SysdynResource sr = SysdynResource.getInstance(graph);\r
+ IssueResource ISSUE = IssueResource.getInstance(graph);\r
Resource issueResource = issue.getRepresents(graph);\r
- String variable = graph.getPossibleRelatedValue(issueResource, sr.Validations_NoSuchVariableIssue_variableName, Bindings.STRING);\r
- return "Refers to variable " + variable + " that does not exist";\r
+ Resource list = graph.getSingleObject(issueResource, ISSUE.DependencyIssueSource2_Issue_HasContexts);\r
+ List<Resource> contexts = ListUtils.toList(graph, list);\r
+ Resource component = contexts.get(0);\r
+\r
+ // Find all variables that are linked to component with arrows\r
+ Set<String> dependencies = ValidationUtils.getDependencies(graph, component);\r
+ Set<String> references = null;\r
+\r
+ // Find all references in equations of component\r
+ try {\r
+ references = ValidationUtils.getReferences(graph, component);\r
+ } catch (SyntaxErrorException e) {\r
+ } catch (UnsupportedCharactersException e) {\r
+ } catch (UndefinedExpressionException e) {\r
+ }\r
+\r
+\r
+ ArrayList<String> result = new ArrayList<String>();\r
+ // Loop all references\r
+ if(references != null && dependencies != null) {\r
+ for(String reference : references) {\r
+ // If dependencies does not contain reference and the reference is not reachable from component, add the name\r
+ if(!dependencies.contains(reference) &&\r
+ ValidationUtils.reach(graph, component, reference) == null) {\r
+ result.add(reference);\r
+ } \r
+ }\r
+ }\r
+ if(result.size() == 0) {\r
+ return "Missing link";\r
+ } else if(result.size() == 1) {\r
+ return "Refers to unexisting variable " + result.get(0);\r
+ } else {\r
+ StringBuilder sb = new StringBuilder();\r
+ sb.append("Refers to unexisting variables ");\r
+ Iterator<String> iterator = result.iterator();\r
+ String reference;\r
+ while(iterator.hasNext()) {\r
+ reference = iterator.next();\r
+ sb.append(reference);\r
+ if(iterator.hasNext())\r
+ sb.append(", ");\r
+ }\r
+ return sb.toString();\r
+ }\r
}\r
}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.sysdyn.ui.validation;\r
-\r
-import java.text.DateFormat;\r
-import java.text.SimpleDateFormat;\r
-import java.util.Arrays;\r
-import java.util.Calendar;\r
-import java.util.UUID;\r
-\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.utils.ListUtils;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.issues.common.StandardIssue;\r
-import org.simantics.issues.ontology.IssueResource;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.sysdyn.SysdynResource;\r
-\r
-/**\r
- * Issue class for NoSuchVariableIssues. Extended from StandardIssue to allow\r
- * a string parameter containing the name of the variable in an equation that\r
- * does not correspond to any existing and reachable variable.\r
- * \r
- * @author Teemu Lempinen\r
- *\r
- */\r
-public class NoSuchVariableIssue extends StandardIssue {\r
-\r
- public String missingVariable;\r
- \r
- public NoSuchVariableIssue(Resource type, String missingVariable, Resource ... contexts) {\r
- super(type, contexts);\r
- this.missingVariable = missingVariable;\r
- }\r
- \r
- /**\r
- * Same as in StandardIssue. Added Validations_NoSuchVariableIssue_variableName.\r
- */\r
- @Override\r
- public void write(WriteGraph graph, Resource model, Resource source) throws DatabaseException {\r
- Layer0 L0 = Layer0.getInstance(graph);\r
- IssueResource IR = IssueResource.getInstance(graph);\r
- Resource issue = graph.newResource();\r
- graph.claim(issue, L0.InstanceOf, null, type);\r
- graph.claimLiteral(issue, L0.HasName, UUID.randomUUID().toString(), Bindings.STRING);\r
- graph.claim(issue, IR.DependencyIssueSource2_Issue_HasContexts, ListUtils.create(graph, L0.List, contexts));\r
- DateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");\r
- String created = format.format(Calendar.getInstance().getTime());\r
- graph.claimLiteral(issue, IR.HasCreationTime, created, Bindings.STRING);\r
- graph.claim(source, IR.Manages, issue);\r
- graph.claim(model, L0.ConsistsOf, issue);\r
- \r
- // Modification to standard issue:\r
- graph.claimLiteral(issue, SysdynResource.getInstance(graph).Validations_NoSuchVariableIssue_variableName, this.missingVariable, Bindings.STRING);\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return Arrays.toString(contexts) + " + missing: " + missingVariable; \r
- }\r
-\r
-}\r