Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid W. Miller2021-01-18 17:57:11 +0000
committerDavid Miller2021-01-20 16:13:54 +0000
commit317ec648c51a5bebb9aca8281820bde97e0913b3 (patch)
tree37a5f225132117963e23e17e357c3d43d17472be
parent5e322fe24cd5c094507bf08e50aa6e68ae0b93f0 (diff)
downloadorg.eclipse.osee-317ec648c51a5bebb9aca8281820bde97e0913b3.tar.gz
org.eclipse.osee-317ec648c51a5bebb9aca8281820bde97e0913b3.tar.xz
org.eclipse.osee-317ec648c51a5bebb9aca8281820bde97e0913b3.zip
feature[TW18475]: Improve ability to generate generic report
Change-Id: I7cca4e06fe9ed0f9e8ec8f69f6703d6fabcbfe2d Signed-off-by: David W. Miller <david.w.miller6@boeing.com>
-rw-r--r--plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/GenericReport.java6
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writers/GenericReportBuilder.java20
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writers/TemplateParser.java31
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writers/reflection/GenericMethodInvoker.java1
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writers/reflection/TemplateReflector.java23
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writers/reflection/TemplateVisitor.java11
6 files changed, 79 insertions, 13 deletions
diff --git a/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/GenericReport.java b/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/GenericReport.java
index bc798286a02..4a72bdd60ce 100644
--- a/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/GenericReport.java
+++ b/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/GenericReport.java
@@ -23,7 +23,11 @@ public interface GenericReport {
public GenericReport level(String levelName, QueryBuilder addedQuery);
- public GenericReport column(String columnName);
+ public GenericReport level(String levelName, String typeName);
+
+ public GenericReport column(String columName);
+
+ public GenericReport column(String columnName, String typeName);
public GenericReport column(String columnName, AttributeTypeToken type);
diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writers/GenericReportBuilder.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writers/GenericReportBuilder.java
index 342fef0ff4c..f4f5fa4d34a 100644
--- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writers/GenericReportBuilder.java
+++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writers/GenericReportBuilder.java
@@ -64,12 +64,32 @@ public class GenericReportBuilder implements GenericReport {
}
@Override
+ public GenericReport level(String levelName, String typeName) {
+ int depth = 0;
+ if (currentLevel != null) {
+ depth = currentLevel.getDepth() + 1;
+ }
+ currentLevel = new ReportLevel(levelName);
+ currentLevel.setDepth(depth);
+ reportLevels.add(currentLevel);
+ query = query.andIsOfType(orcsApi.tokenService().getArtifactType(typeName));
+ return this;
+ }
+
+ @Override
public GenericReport column(String columnName) {
currentLevel.column(columnName);
return this;
}
@Override
+ public GenericReport column(String columnName, String typeName) {
+ AttributeTypeToken type = orcsApi.tokenService().getAttributeType(typeName);
+ currentLevel.column(columnName, type);
+ return this;
+ }
+
+ @Override
public GenericReport column(String columnName, AttributeTypeToken type) {
currentLevel.column(columnName, type);
return this;
diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writers/TemplateParser.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writers/TemplateParser.java
index 175cffab7a3..8d3d4b376dd 100644
--- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writers/TemplateParser.java
+++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writers/TemplateParser.java
@@ -20,12 +20,15 @@ import java.util.ListIterator;
import org.eclipse.jdt.core.compiler.IProblem;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.Expression;
+import org.eclipse.jdt.core.dom.ImportDeclaration;
import org.eclipse.jdt.core.dom.MethodInvocation;
import org.eclipse.osee.framework.core.data.ArtifactId;
import org.eclipse.osee.framework.core.data.BranchId;
import org.eclipse.osee.framework.core.data.IOseeBranch;
+import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.core.enums.CoreBranches;
+import org.eclipse.osee.framework.core.enums.CoreRelationTypes;
import org.eclipse.osee.framework.jdk.core.result.XResultData;
import org.eclipse.osee.orcs.OrcsApi;
import org.eclipse.osee.orcs.data.ArtifactReadable;
@@ -40,6 +43,7 @@ import org.eclipse.osee.orcs.search.QueryFactory;
* @author David W. Miller
*/
public final class TemplateParser {
+ private final OrcsApi orcsApi;
private final QueryFactory queryApi;
private final IOseeBranch branch;
private final ArtifactId view;
@@ -47,6 +51,7 @@ public final class TemplateParser {
private final XResultData results;
public TemplateParser(OrcsApi orcsApi, BranchId branch, ArtifactId view, ArtifactId templateArt, XResultData results) {
+ this.orcsApi = orcsApi;
this.queryApi = orcsApi.getQueryFactory();
this.branch = orcsApi.getQueryFactory().branchQuery().andId(branch).getResultsAsId().getExactlyOne();
this.view = view;
@@ -75,7 +80,9 @@ public final class TemplateParser {
parsedCode.accept(visitor);
List<MethodInvocation> methods = visitor.getInvocations();
+ List<ImportDeclaration> imports = visitor.getImports();
TemplateReflector reflector = new TemplateReflector(report, results);
+ setReflectionClasses(reflector, imports);
ListIterator<MethodInvocation> iterator = methods.listIterator();
while (iterator.hasNext()) {
MethodInvocation method = iterator.next();
@@ -96,6 +103,10 @@ public final class TemplateParser {
}
if (methodName.equals("query")) {
report = reflector.invokeStack(report);
+ } else if (methodName.equals("level")) {
+ invoker.set(methodName, arguments);
+ reflector.pushMethod(invoker);
+ report = reflector.invokeStack(report);
} else if (invoker.set(methodName, arguments)) {
reflector.pushMethod(invoker);
} else {
@@ -104,6 +115,26 @@ public final class TemplateParser {
}
}
+ private void setReflectionClasses(TemplateReflector reflector, List<ImportDeclaration> imports) {
+ // get all imports related to artifact, attribute and relation types
+ // assumes the class names have ArtifactType, AttributeType, or RelationType somewhere in the name
+ reflector.setAllowedReflectionClass(CoreArtifactTypes.class);
+ reflector.setAllowedReflectionClass(CoreAttributeTypes.class);
+ reflector.setAllowedReflectionClass(CoreRelationTypes.class);
+ for (ImportDeclaration imp : imports) {
+ String impName = imp.getName().getFullyQualifiedName();
+ if (impName.contains("AttributeType") || impName.contains("ArtifactType") || impName.contains(
+ "RelationType")) {
+ try {
+ Class<?> clazz = Class.forName(impName);
+ reflector.setAllowedReflectionClass(clazz);
+ } catch (ClassNotFoundException ex) {
+ results.logf("classloader could not find %s", impName);
+ }
+ }
+ }
+ }
+
private void setPathsForParser(ASTParserUtil parser) {
// add known paths
try {
diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writers/reflection/GenericMethodInvoker.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writers/reflection/GenericMethodInvoker.java
index 1f30a5e016f..a622395bbe2 100644
--- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writers/reflection/GenericMethodInvoker.java
+++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writers/reflection/GenericMethodInvoker.java
@@ -74,6 +74,7 @@ public class GenericMethodInvoker<T> {
} else {
argsMatch = false;
+ arguments.clear();
break;
}
}
diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writers/reflection/TemplateReflector.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writers/reflection/TemplateReflector.java
index 59d2eb435a4..4b54e167fc1 100644
--- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writers/reflection/TemplateReflector.java
+++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writers/reflection/TemplateReflector.java
@@ -28,9 +28,6 @@ import org.eclipse.jdt.core.dom.MethodInvocation;
import org.eclipse.jdt.core.dom.NumberLiteral;
import org.eclipse.jdt.core.dom.QualifiedName;
import org.eclipse.jdt.core.dom.StringLiteral;
-import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
-import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
-import org.eclipse.osee.framework.core.enums.CoreRelationTypes;
import org.eclipse.osee.framework.jdk.core.result.XResultData;
import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException;
import org.eclipse.osee.orcs.rest.model.GenericReport;
@@ -43,6 +40,7 @@ public class TemplateReflector {
Stack<GenericMethodInvoker<GenericReport>> realMethods = new Stack<>();
private final GenericReport report;
private final XResultData results;
+ private final ArrayList<Class<?>> allowedReflectors = new ArrayList<>();
public TemplateReflector(GenericReport report, XResultData results) {
this.report = report;
@@ -114,10 +112,14 @@ public class TemplateReflector {
return toReturn;
}
+ public void setAllowedReflectionClass(Class<?> clazz) {
+ allowedReflectors.add(clazz);
+ }
+
private Object getArgumentFromQualifiedName(QualifiedName qname) {
- Object o = null;
String qualifier = qname.getQualifier().toString();
String name = qname.getName().toString();
+
try {
Class<?> clazz = getClassFromWhiteList(qualifier);
Field field = clazz.getDeclaredField(name);
@@ -125,18 +127,15 @@ public class TemplateReflector {
} catch (Exception ex) {
results.errorf("Failed to get argument for %s, full error: %s", qname, ex.toString());
}
- return o;
+ return null;
}
private Class<?> getClassFromWhiteList(String className) {
Class<?> toReturn = null;
-
- if (CoreArtifactTypes.class.getName().endsWith(className)) {
- toReturn = CoreArtifactTypes.class;
- } else if (CoreAttributeTypes.class.getName().endsWith(className)) {
- toReturn = CoreAttributeTypes.class;
- } else if (CoreRelationTypes.class.getName().endsWith(className)) {
- toReturn = CoreRelationTypes.class;
+ for (Class<?> clazz : allowedReflectors) {
+ if (clazz.getName().endsWith(className)) {
+ toReturn = clazz;
+ }
}
return toReturn;
}
diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writers/reflection/TemplateVisitor.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writers/reflection/TemplateVisitor.java
index 5f1fcbba191..f2eb06d96de 100644
--- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writers/reflection/TemplateVisitor.java
+++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writers/reflection/TemplateVisitor.java
@@ -16,6 +16,7 @@ package org.eclipse.osee.orcs.rest.internal.writers.reflection;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jdt.core.dom.ASTVisitor;
+import org.eclipse.jdt.core.dom.ImportDeclaration;
import org.eclipse.jdt.core.dom.MethodInvocation;
/**
@@ -23,13 +24,23 @@ import org.eclipse.jdt.core.dom.MethodInvocation;
*/
public class TemplateVisitor extends ASTVisitor {
List<MethodInvocation> methods = new ArrayList<>();
+ List<ImportDeclaration> imports = new ArrayList<>();
public List<MethodInvocation> getInvocations() {
return methods;
}
+ public List<ImportDeclaration> getImports() {
+ return imports;
+ }
+
@Override
public boolean visit(MethodInvocation node) {
return methods.add(node);
}
+
+ @Override
+ public boolean visit(ImportDeclaration node) {
+ return imports.add(node);
+ }
}

Back to the top