diff options
author | Ryan D. Brooks | 2017-02-13 16:19:11 +0000 |
---|---|---|
committer | Ryan D. Brooks | 2020-12-15 22:28:05 +0000 |
commit | 4da6392273866bf766ca15d65280c6b1abeb5c02 (patch) | |
tree | a9f4aebc90781716e16d201536e06ed5e9cf72ce | |
parent | 90aadfd51d5c69299a6a75951282c3c58c719212 (diff) | |
download | org.eclipse.osee-4da6392273866bf766ca15d65280c6b1abeb5c02.tar.gz org.eclipse.osee-4da6392273866bf766ca15d65280c6b1abeb5c02.tar.xz org.eclipse.osee-4da6392273866bf766ca15d65280c6b1abeb5c02.zip |
refactor: deep search
Change-Id: I9208928d0b69f3d9e724debf6022107784529aa0
10 files changed, 169 insertions, 1 deletions
diff --git a/plugins/org.eclipse.osee.define.rest/src/org/eclipse/osee/define/rest/internal/SystemSafetyResource.java b/plugins/org.eclipse.osee.define.rest/src/org/eclipse/osee/define/rest/internal/SystemSafetyResource.java index 3d55e34de47..4000d860740 100644 --- a/plugins/org.eclipse.osee.define.rest/src/org/eclipse/osee/define/rest/internal/SystemSafetyResource.java +++ b/plugins/org.eclipse.osee.define.rest/src/org/eclipse/osee/define/rest/internal/SystemSafetyResource.java @@ -14,6 +14,11 @@ package org.eclipse.osee.define.rest.internal; import javax.ws.rs.DefaultValue; +import static org.eclipse.osee.framework.core.enums.CoreArtifactTypes.AbstractSoftwareRequirement; +import static org.eclipse.osee.framework.core.enums.CoreAttributeTypes.Name; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; @@ -27,7 +32,10 @@ import org.eclipse.osee.app.OseeAppletPage; import org.eclipse.osee.framework.core.data.ArtifactId; import org.eclipse.osee.framework.core.data.BranchId; import org.eclipse.osee.framework.jdk.core.type.IResourceRegistry; +import org.eclipse.osee.framework.jdk.core.type.Pair; import org.eclipse.osee.orcs.OrcsApi; +import org.eclipse.osee.orcs.data.ArtifactReadable; +import org.eclipse.osee.orcs.search.QueryBuilder; /** * @author Ryan D. Brooks @@ -91,4 +99,34 @@ public final class SystemSafetyResource { OseeAppletPage pageUtil = new OseeAppletPage(orcsApi.getQueryFactory().branchQuery()); return pageUtil.realizeApplet(resourceRegistry, "systemSafetyReport.html", getClass()); } + } + // private static final String[] names = new String[] {"{COMM NCO PRESET NVM VALIDATION}", "{FM NVM VALIDATION}"}; + + @Path("deep") + @GET + @Produces(MediaType.TEXT_HTML) + public String deep(@QueryParam("branch") BranchId branch, @QueryParam("name") String nameIn) { + StringBuilder strB = new StringBuilder(10000); + String[] names = new String[] {nameIn}; + List<Pair<ArtifactId, String>> values = + orcsApi.getQueryFactory().deepQuery().andIsOfType(AbstractSoftwareRequirement).collect(Name); + for (String oldName : names) { + String fuzzyName = + "\\{?" + oldName.toUpperCase().trim().replaceAll("[_ ]", ".?").replaceAll("[{}]", "") + "\\}?"; + Matcher matcher = Pattern.compile(fuzzyName).matcher(""); + + for (Pair<ArtifactId, String> entry : values) { + String name = entry.getSecond().toUpperCase().trim(); + matcher.reset(name); + if (matcher.matches()) { + ArtifactId artifactId = entry.getFirst(); + QueryBuilder builder = orcsApi.getQueryFactory().fromBranch(branch); + ArtifactReadable art = builder.andId(artifactId).getResults().getAtMostOneOrNull(); + if (art != null) { + strB.append(entry.getSecond() + ", " + artifactId + ", " + art.getName() + "<br/>"); + } + } + } + } + return strB.toString(); } diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/QueryEngine.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/QueryEngine.java index d3e0fbe6ca8..0e66b2d85b0 100644 --- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/QueryEngine.java +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/QueryEngine.java @@ -21,6 +21,7 @@ import org.eclipse.osee.framework.core.data.Branch; import org.eclipse.osee.framework.core.executor.CancellableCallable; import org.eclipse.osee.orcs.OrcsSession; import org.eclipse.osee.orcs.data.ArtifactReadable; +import org.eclipse.osee.orcs.search.DeepQuery; import org.eclipse.osee.orcs.data.TransactionReadable; import org.eclipse.osee.orcs.search.QueryFactory; import org.eclipse.osee.orcs.search.TupleQuery; @@ -59,4 +60,6 @@ public interface QueryEngine { Map<ArtifactId, ArtifactReadable> asArtifactMap(QueryData queryData, QueryFactory queryFactory); List<ArtifactReadable> asArtifacts(QueryData queryData, QueryFactory queryFactory); + + DeepQuery createDeepQuery(); }
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/QueryFactoryImpl.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/QueryFactoryImpl.java index de8412d4e50..f65f0dd3ec9 100644 --- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/QueryFactoryImpl.java +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/QueryFactoryImpl.java @@ -33,6 +33,7 @@ import org.eclipse.osee.orcs.core.ds.QueryData; import org.eclipse.osee.orcs.core.ds.QueryEngine; import org.eclipse.osee.orcs.search.ApplicabilityQuery; import org.eclipse.osee.orcs.search.BranchQuery; +import org.eclipse.osee.orcs.search.DeepQuery; import org.eclipse.osee.orcs.search.QueryBuilder; import org.eclipse.osee.orcs.search.QueryFactory; import org.eclipse.osee.orcs.search.TransactionQuery; @@ -205,4 +206,9 @@ public class QueryFactoryImpl implements QueryFactory { public ApplicabilityQuery applicabilityQuery() { return new ApplicabilityQueryImpl(applicabilityDsQuery, this, orcsApi); } + + @Override + public DeepQuery deepQuery() { + return queryEngine.createDeepQuery(); + } }
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/QueryModule.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/QueryModule.java index 469a9bf1fdc..57cfbebf915 100644 --- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/QueryModule.java +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/QueryModule.java @@ -56,6 +56,7 @@ public class QueryModule implements HasStatistics<QueryStatistics> { tupleQuery = queryEngine.createTupleQuery(); applicabilityDsQuery = queryEngine.createApplicabilityDsQuery(); this.tokenService = tokenService; + this.queryEngine = queryEngine; } public QueryFactory createQueryFactory(OrcsSession session) { diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/DeepQueryImpl.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/DeepQueryImpl.java new file mode 100644 index 00000000000..ddfdaa475d1 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/DeepQueryImpl.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2017 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.db.internal.search.engines; + +import static org.eclipse.osee.jdbc.JdbcConstants.JDBC__MAX_FETCH_SIZE; +import java.util.ArrayList; +import java.util.List; +import org.eclipse.osee.framework.core.data.ArtifactId; +import org.eclipse.osee.framework.core.data.ArtifactTypeId; +import org.eclipse.osee.framework.core.data.AttributeTypeId; +import org.eclipse.osee.framework.jdk.core.type.Pair; +import org.eclipse.osee.jdbc.JdbcClient; +import org.eclipse.osee.jdbc.JdbcStatement; +import org.eclipse.osee.orcs.data.ArtifactTypes; +import org.eclipse.osee.orcs.db.internal.sql.join.IdJoinQuery; +import org.eclipse.osee.orcs.search.DeepQuery; + +/** + * @author Ryan D. Brooks + */ +public class DeepQueryImpl implements DeepQuery { + private static final String SELECT_ATTRIBUTE_VALUES = + "select att.art_id, value from osee_attribute att, osee_artifact art, osee_join_id jid where attr_type_id = ? and value is not null and att.art_id = art.art_id and art_type_id = jid.id and jid.query_id = ?"; + private final JdbcClient jdbcClient; + private final ArtifactTypes artifactTypeService; + private final IdJoinQuery arifactTypeJoin; + + public DeepQueryImpl(JdbcClient jdbcClient, ArtifactTypes artifactTypeService, IdJoinQuery arifactTypeJoin) { + this.jdbcClient = jdbcClient; + this.artifactTypeService = artifactTypeService; + this.arifactTypeJoin = arifactTypeJoin; + } + + @Override + public DeepQuery andIsOfType(ArtifactTypeId... artifactTypes) { + for (ArtifactTypeId artifactType : artifactTypes) { + for (ArtifactTypeId type : artifactTypeService.getAllDescendantTypes(artifactType)) { + arifactTypeJoin.add(type); + } + } + return this; + } + + @Override + public List<Pair<ArtifactId, String>> collect(AttributeTypeId attributeType) { + List<Pair<ArtifactId, String>> attributeValues = new ArrayList<>(10000); + arifactTypeJoin.store(); + + try (JdbcStatement chStmt = jdbcClient.getStatement()) { + chStmt.runPreparedQuery(JDBC__MAX_FETCH_SIZE, SELECT_ATTRIBUTE_VALUES, attributeType, + arifactTypeJoin.getQueryId()); + while (chStmt.next()) { + attributeValues.add(new Pair<>(ArtifactId.valueOf(chStmt.getLong("art_id")), chStmt.getString("value"))); + } + } finally { + arifactTypeJoin.delete(); + } + return attributeValues; + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/QueryEngineImpl.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/QueryEngineImpl.java index d773ce2a340..1f0e5f70db8 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/QueryEngineImpl.java +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/QueryEngineImpl.java @@ -62,6 +62,7 @@ import org.eclipse.osee.orcs.db.internal.sql.SelectiveArtifactSqlWriter; import org.eclipse.osee.orcs.db.internal.sql.SqlHandlerFactory; import org.eclipse.osee.orcs.db.internal.sql.join.SqlJoinFactory; import org.eclipse.osee.orcs.search.QueryFactory; +import org.eclipse.osee.orcs.search.DeepQuery; import org.eclipse.osee.orcs.search.TupleQuery; /** @@ -79,6 +80,8 @@ public class QueryEngineImpl implements QueryEngine { private final SqlHandlerFactory handlerFactory; private final OrcsTokenService tokenService; private final IResourceManager resourceManager; + private final TupleQuery tupleQuery; + private final ArtifactTypes artifactTypeService; public QueryEngineImpl(QueryCallableFactory artifactQueryEngineFactory, QuerySqlContextFactory branchSqlContextFactory, QuerySqlContextFactory txSqlContextFactory, QueryCallableFactory allQueryEngineFactory, JdbcClient jdbcClient, SqlJoinFactory sqlJoinFactory, SqlHandlerFactory handlerFactory, SqlObjectLoader sqlObjectLoader, OrcsTokenService tokenService, KeyValueStore keyValue, IResourceManager resourceManager) { this.artifactQueryEngineFactory = artifactQueryEngineFactory; @@ -92,6 +95,7 @@ public class QueryEngineImpl implements QueryEngine { this.keyValue = keyValue; this.handlerFactory = handlerFactory; this.resourceManager = resourceManager; + this.tupleQuery = new TupleQueryImpl(jdbcClient, sqlJoinFactory, keyValue, tokenService); } @Override @@ -151,7 +155,12 @@ public class QueryEngineImpl implements QueryEngine { @Override public TupleQuery createTupleQuery() { - return new TupleQueryImpl(jdbcClient, sqlJoinFactory, keyValue, tokenService); + return tupleQuery; + } + +@Override + public DeepQuery createDeepQuery() { + return new DeepQueryImpl(jdbcClient, artifactTypeService, sqlJoinFactory.createIdJoinQuery()); } @Override diff --git a/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/BranchEndpoint.java b/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/BranchEndpoint.java index e7865a75809..75bc261d0aa 100644 --- a/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/BranchEndpoint.java +++ b/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/BranchEndpoint.java @@ -240,4 +240,8 @@ public interface BranchEndpoint { @Path("log") @Consumes({MediaType.TEXT_PLAIN}) Response logBranchActivity(String comment); + + @PUT + @Path("{branch}/deep/attribute/{attributeType}") + Response deepAttribute(@PathParam("branch") BranchId branch, @PathParam("attributeType") AttributeTypeId attributeType, String[] values); }
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/BranchEndpointImpl.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/BranchEndpointImpl.java index 0bbfb8eaf54..19b1a879c45 100644 --- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/BranchEndpointImpl.java +++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/BranchEndpointImpl.java @@ -910,4 +910,9 @@ public class BranchEndpointImpl implements BranchEndpoint { rel.setTypeId(chStmt.getString("rel_link_type_id")); return rel; } + + @Override + public Response deepAttribute(BranchId branch, AttributeTypeId attributeType, String[] values) { + return null; + } }
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/search/DeepQuery.java b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/search/DeepQuery.java new file mode 100644 index 00000000000..ee338cb7550 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/search/DeepQuery.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2017 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.search; + +import java.util.List; +import org.eclipse.osee.framework.core.data.ArtifactId; +import org.eclipse.osee.framework.core.data.ArtifactTypeId; +import org.eclipse.osee.framework.core.data.AttributeTypeId; +import org.eclipse.osee.framework.jdk.core.type.Pair; + +/** + * Queries that are not restricted by branch + * + * @author Ryan D. Brooks + */ +public interface DeepQuery { + + /** + * Search criteria that finds a given artifact type using type inheritance + */ + DeepQuery andIsOfType(ArtifactTypeId... artifactTypes); + + List<Pair<ArtifactId, String>> collect(AttributeTypeId attributeType); +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/search/QueryFactory.java b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/search/QueryFactory.java index b0a81584252..c3023f3f5b9 100644 --- a/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/search/QueryFactory.java +++ b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/search/QueryFactory.java @@ -35,4 +35,6 @@ public interface QueryFactory { ApplicabilityQuery applicabilityQuery(); QueryBuilder fromOrcsScript(String orcsScript); + + DeepQuery deepQuery(); }
\ No newline at end of file |