diff options
author | jmisinco | 2011-10-25 19:41:48 +0000 |
---|---|---|
committer | Roberto E. Escobar | 2011-10-25 19:41:48 +0000 |
commit | b6703308972661be790b5e8d574aca1214e05368 (patch) | |
tree | 40a9e7afd40eed06c2b688c90bb1daa44d8d86d1 /plugins/org.eclipse.osee.display.presenter | |
parent | 1cf87e13eff5fe9a7b9c9dcc69d403b511adab99 (diff) | |
download | org.eclipse.osee-b6703308972661be790b5e8d574aca1214e05368.tar.gz org.eclipse.osee-b6703308972661be790b5e8d574aca1214e05368.tar.xz org.eclipse.osee-b6703308972661be790b5e8d574aca1214e05368.zip |
feature[ats_18K4T]: Integration of ORCS and UI
Diffstat (limited to 'plugins/org.eclipse.osee.display.presenter')
5 files changed, 184 insertions, 113 deletions
diff --git a/plugins/org.eclipse.osee.display.presenter/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.display.presenter/META-INF/MANIFEST.MF index 5f4c19db7fc..e8cca7f05a8 100644 --- a/plugins/org.eclipse.osee.display.presenter/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.display.presenter/META-INF/MANIFEST.MF @@ -5,7 +5,8 @@ Bundle-SymbolicName: org.eclipse.osee.display.presenter Bundle-Version: 0.9.9.qualifier Bundle-Vendor: Eclipse Open System Engineering Environment Bundle-RequiredExecutionEnvironment: JavaSE-1.6 -Import-Package: org.eclipse.core.runtime, +Import-Package: com.google.common.collect, + org.eclipse.core.runtime, org.eclipse.osee.display.api.components, org.eclipse.osee.display.api.data, org.eclipse.osee.display.api.search, @@ -16,6 +17,7 @@ Import-Package: org.eclipse.core.runtime, org.eclipse.osee.framework.core.model.type, org.eclipse.osee.framework.jdk.core.type, org.eclipse.osee.framework.jdk.core.util, + org.eclipse.osee.logger, org.eclipse.osee.orcs, org.eclipse.osee.orcs.data, org.eclipse.osee.orcs.search diff --git a/plugins/org.eclipse.osee.display.presenter/src/org/eclipse/osee/display/presenter/ArtifactProviderImpl.java b/plugins/org.eclipse.osee.display.presenter/src/org/eclipse/osee/display/presenter/ArtifactProviderImpl.java index d585240b3c7..b185ea4500c 100644 --- a/plugins/org.eclipse.osee.display.presenter/src/org/eclipse/osee/display/presenter/ArtifactProviderImpl.java +++ b/plugins/org.eclipse.osee.display.presenter/src/org/eclipse/osee/display/presenter/ArtifactProviderImpl.java @@ -10,17 +10,13 @@ *******************************************************************************/ package org.eclipse.osee.display.presenter; -import java.util.ArrayList; import java.util.Collection; +import java.util.Date; import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Set; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.TimeUnit; import org.eclipse.osee.display.api.search.ArtifactProvider; import org.eclipse.osee.framework.core.data.IArtifactToken; import org.eclipse.osee.framework.core.data.IAttributeType; @@ -40,6 +36,7 @@ import org.eclipse.osee.orcs.search.Match; import org.eclipse.osee.orcs.search.QueryBuilder; import org.eclipse.osee.orcs.search.QueryFactory; import org.eclipse.osee.orcs.search.StringOperator; +import com.google.common.collect.MapMaker; /** * @author John Misinco @@ -47,25 +44,17 @@ import org.eclipse.osee.orcs.search.StringOperator; public class ArtifactProviderImpl implements ArtifactProvider { private final OrcsApi oseeApi; - private final ApplicationContext context; - private final Graph graph; - - protected static final List<String> notAllowed = new ArrayList<String>(); - static { - notAllowed.add("Technical Approaches"); - notAllowed.add("Technical Performance Parameters"); - notAllowed.add("Recent Imports"); - notAllowed.add("Test"); - notAllowed.add("Interface Requirements"); - notAllowed.add("Test Procedures"); - } + private final ConcurrentMap<ReadableArtifact, ReadableArtifact> parentCache; + private final ArtifactSanitizer sanitizer; public ArtifactProviderImpl(OrcsApi oseeApi, ApplicationContext context) { this.oseeApi = oseeApi; this.context = context; this.graph = oseeApi.getGraph(context); + this.parentCache = new MapMaker().initialCapacity(500).expiration(30, TimeUnit.MINUTES).makeMap(); + sanitizer = new ArtifactSanitizer(this); } protected QueryFactory getFactory() { @@ -74,17 +63,18 @@ public class ArtifactProviderImpl implements ArtifactProvider { @Override public ReadableArtifact getArtifactByArtifactToken(IOseeBranch branch, IArtifactToken token) throws OseeCoreException { - return sanitizeResult(getArtifactByGuid(branch, token.getGuid())); + return getArtifactByGuid(branch, token.getGuid()); } @Override public ReadableArtifact getArtifactByGuid(IOseeBranch branch, String guid) throws OseeCoreException { - return sanitizeResult(getFactory().fromBranch(branch).andGuidsOrHrids(guid).getResults().getOneOrNull()); + return sanitizer.sanitizeArtifact(getFactory().fromBranch(branch).andGuidsOrHrids(guid).getResults().getOneOrNull()); } @Override public List<Match<ReadableArtifact, ReadableAttribute<?>>> getSearchResults(IOseeBranch branch, boolean nameOnly, String searchPhrase) throws OseeCoreException { List<Match<ReadableArtifact, ReadableAttribute<?>>> filtered; + System.out.println("begin getSearchResults: " + new Date().toString()); IAttributeType type = nameOnly ? CoreAttributeTypes.Name : QueryBuilder.ANY_ATTRIBUTE_TYPE; @@ -92,74 +82,35 @@ public class ArtifactProviderImpl implements ArtifactProvider { builder.and(type, StringOperator.TOKENIZED_ANY_ORDER, CaseType.IGNORE_CASE, searchPhrase); List<Match<ReadableArtifact, ReadableAttribute<?>>> results = builder.getMatches().getList(); - filtered = sanitizeSearchResults(results); + System.out.println("end1 getSearchResults: " + new Date().toString()); + filtered = sanitizer.sanitizeSearchResults(results); + System.out.println("end2 getSearchResults: " + new Date().toString()); return filtered; } - private List<Match<ReadableArtifact, ReadableAttribute<?>>> sanitizeSearchResults(List<Match<ReadableArtifact, ReadableAttribute<?>>> toSanitize) { - int numProcessors = Runtime.getRuntime().availableProcessors(); - int partitionSize = toSanitize.size() / numProcessors; - int remainder = toSanitize.size() % numProcessors; - ExecutorService executor = Executors.newFixedThreadPool(numProcessors); - int startIndex = 0; - int endIndex = 0; - List<ResultsCallable> workers = new LinkedList<ResultsCallable>(); - List<Match<ReadableArtifact, ReadableAttribute<?>>> toReturn = - new LinkedList<Match<ReadableArtifact, ReadableAttribute<?>>>(); - - for (int i = 0; i < numProcessors; i++) { - startIndex = endIndex; - endIndex = startIndex + partitionSize; - if (i == 0) { - endIndex += remainder; - } - ResultsCallable worker = new ResultsCallable(toSanitize.subList(startIndex, endIndex)); - workers.add(worker); - } - - try { - for (Future<List<Match<ReadableArtifact, ReadableAttribute<?>>>> future : executor.invokeAll(workers)) { - toReturn.addAll(future.get()); - } - } catch (Exception ex) { - // - } - - return toReturn; - - } - - private ReadableArtifact sanitizeResult(ReadableArtifact result) throws OseeCoreException { - boolean allowed = true; - ReadableArtifact current = result; - while (current != null) { - if (notAllowed.contains(current.getName())) { - allowed = false; - break; - } - current = graph.getParent(current); - } - if (allowed) { - return result; - } else { - return null; - } - } - @Override public List<ReadableArtifact> getRelatedArtifacts(ReadableArtifact art, IRelationTypeSide relationTypeSide) throws OseeCoreException { - return graph.getRelatedArtifacts(art, relationTypeSide); + return sanitizer.sanitizeArtifacts(graph.getRelatedArtifacts(art, relationTypeSide)); } @Override public ReadableArtifact getRelatedArtifact(ReadableArtifact art, IRelationTypeSide relationTypeSide) throws OseeCoreException { - return graph.getRelatedArtifact(art, relationTypeSide); + return sanitizer.sanitizeArtifact(graph.getRelatedArtifact(art, relationTypeSide)); } @Override public ReadableArtifact getParent(ReadableArtifact art) throws OseeCoreException { - return getRelatedArtifact(art, CoreRelationTypes.Default_Hierarchical__Parent); + ReadableArtifact parent = null; + if (parentCache.containsKey(art)) { + parent = parentCache.get(art); + } else { + parent = getRelatedArtifact(art, CoreRelationTypes.Default_Hierarchical__Parent); + if (parent != null) { + parentCache.put(art, parent); + } + } + return sanitizer.sanitizeArtifact(parent); } @Override @@ -172,25 +123,4 @@ public class ArtifactProviderImpl implements ArtifactProvider { return toReturn; } - private class ResultsCallable implements Callable<List<Match<ReadableArtifact, ReadableAttribute<?>>>> { - - List<Match<ReadableArtifact, ReadableAttribute<?>>> toSanitize; - - public ResultsCallable(List<Match<ReadableArtifact, ReadableAttribute<?>>> toSanitize) { - this.toSanitize = toSanitize; - } - - @Override - public List<Match<ReadableArtifact, ReadableAttribute<?>>> call() throws Exception { - Iterator<Match<ReadableArtifact, ReadableAttribute<?>>> it = toSanitize.iterator(); - while (it.hasNext()) { - Match<ReadableArtifact, ReadableAttribute<?>> match = it.next(); - ReadableArtifact matchedArtifact = match.getItem(); - if (sanitizeResult(matchedArtifact) == null) { - it.remove(); - } - } - return toSanitize; - } - } } diff --git a/plugins/org.eclipse.osee.display.presenter/src/org/eclipse/osee/display/presenter/ArtifactSanitizer.java b/plugins/org.eclipse.osee.display.presenter/src/org/eclipse/osee/display/presenter/ArtifactSanitizer.java new file mode 100644 index 00000000000..a6bcbfbd94b --- /dev/null +++ b/plugins/org.eclipse.osee.display.presenter/src/org/eclipse/osee/display/presenter/ArtifactSanitizer.java @@ -0,0 +1,129 @@ +/******************************************************************************* + * Copyright (c) 2011 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.display.presenter; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import org.eclipse.osee.display.api.search.ArtifactProvider; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.orcs.data.ReadableArtifact; +import org.eclipse.osee.orcs.data.ReadableAttribute; +import org.eclipse.osee.orcs.search.Match; + +/** + * @author John Misinco + */ +public class ArtifactSanitizer { + + protected final ArtifactProvider provider; + + public ArtifactSanitizer(ArtifactProvider provider) { + this.provider = provider; + } + + protected static final List<String> notAllowed = new ArrayList<String>(); + static { + notAllowed.add("Technical Approaches"); + notAllowed.add("Technical Performance Parameters"); + notAllowed.add("Recent Imports"); + notAllowed.add("Test"); + notAllowed.add("Interface Requirements"); + notAllowed.add("Test Procedures"); + } + + public List<Match<ReadableArtifact, ReadableAttribute<?>>> sanitizeSearchResults(List<Match<ReadableArtifact, ReadableAttribute<?>>> toSanitize) { + int numProcessors = Runtime.getRuntime().availableProcessors(); + int partitionSize = toSanitize.size() / numProcessors; + int remainder = toSanitize.size() % numProcessors; + ExecutorService executor = Executors.newFixedThreadPool(numProcessors); + int startIndex = 0; + int endIndex = 0; + List<ResultsCallable> workers = new LinkedList<ResultsCallable>(); + List<Match<ReadableArtifact, ReadableAttribute<?>>> toReturn = + new LinkedList<Match<ReadableArtifact, ReadableAttribute<?>>>(); + + for (int i = 0; i < numProcessors; i++) { + startIndex = endIndex; + endIndex = startIndex + partitionSize; + if (i == 0) { + endIndex += remainder; + } + ResultsCallable worker = new ResultsCallable(toSanitize.subList(startIndex, endIndex)); + workers.add(worker); + } + + try { + for (Future<List<Match<ReadableArtifact, ReadableAttribute<?>>>> future : executor.invokeAll(workers)) { + toReturn.addAll(future.get()); + } + } catch (Exception ex) { + // + } + + return toReturn; + + } + + public ReadableArtifact sanitizeArtifact(ReadableArtifact result) throws OseeCoreException { + boolean allowed = true; + ReadableArtifact current = result; + while (current != null) { + if (notAllowed.contains(current.getName())) { + allowed = false; + break; + } + current = provider.getParent(current); + } + if (allowed) { + return result; + } else { + return null; + } + } + + public List<ReadableArtifact> sanitizeArtifacts(List<ReadableArtifact> arts) throws OseeCoreException { + Iterator<ReadableArtifact> it = arts.iterator(); + while (it.hasNext()) { + if (sanitizeArtifact(it.next()) == null) { + it.remove(); + } + } + return arts; + } + + private class ResultsCallable implements Callable<List<Match<ReadableArtifact, ReadableAttribute<?>>>> { + + List<Match<ReadableArtifact, ReadableAttribute<?>>> toSanitize; + + public ResultsCallable(List<Match<ReadableArtifact, ReadableAttribute<?>>> toSanitize) { + this.toSanitize = toSanitize; + } + + @Override + public List<Match<ReadableArtifact, ReadableAttribute<?>>> call() throws Exception { + Iterator<Match<ReadableArtifact, ReadableAttribute<?>>> it = toSanitize.iterator(); + while (it.hasNext()) { + Match<ReadableArtifact, ReadableAttribute<?>> match = it.next(); + ReadableArtifact matchedArtifact = match.getItem(); + if (sanitizeArtifact(matchedArtifact) == null) { + it.remove(); + } + } + return toSanitize; + } + } +} diff --git a/plugins/org.eclipse.osee.display.presenter/src/org/eclipse/osee/display/presenter/SearchPresenterImpl.java b/plugins/org.eclipse.osee.display.presenter/src/org/eclipse/osee/display/presenter/SearchPresenterImpl.java index ef985012f0b..83b35720bb2 100644 --- a/plugins/org.eclipse.osee.display.presenter/src/org/eclipse/osee/display/presenter/SearchPresenterImpl.java +++ b/plugins/org.eclipse.osee.display.presenter/src/org/eclipse/osee/display/presenter/SearchPresenterImpl.java @@ -44,6 +44,7 @@ import org.eclipse.osee.framework.core.model.type.RelationType; import org.eclipse.osee.framework.jdk.core.type.MatchLocation; import org.eclipse.osee.framework.jdk.core.util.Lib; import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.logger.Log; import org.eclipse.osee.orcs.data.ReadableArtifact; import org.eclipse.osee.orcs.data.ReadableAttribute; import org.eclipse.osee.orcs.search.Match; @@ -57,9 +58,11 @@ public class SearchPresenterImpl<T extends SearchHeaderComponent, K extends View private final static String SIDE_A_KEY = "sideAName"; private final static String SIDE_B_KEY = "sideBName"; + protected final Log logger; - public SearchPresenterImpl(ArtifactProvider artifactProvider) { + public SearchPresenterImpl(ArtifactProvider artifactProvider, Log logger) { this.artifactProvider = artifactProvider; + this.logger = logger; } @Override @@ -76,7 +79,7 @@ public class SearchPresenterImpl<T extends SearchHeaderComponent, K extends View return; } - // options.setDisplayOptions(new DisplayOptions(params.isVerbose())); + options.setDisplayOptions(new DisplayOptions(params.isVerbose())); List<Match<ReadableArtifact, ReadableAttribute<?>>> searchResults = null; try { @@ -91,6 +94,7 @@ public class SearchPresenterImpl<T extends SearchHeaderComponent, K extends View try { processSearchResults(searchResults, searchResultsComp, params); } catch (Exception ex) { + logger.error(ex, "Error in processSearchResults"); setErrorMessage(searchResultsComp, Lib.exceptionToString(ex)); return; } @@ -127,7 +131,7 @@ public class SearchPresenterImpl<T extends SearchHeaderComponent, K extends View value = getParametersAsEncodedUrl(params); oseeNavigator.navigateArtifactPage("/" + value); } catch (UnsupportedEncodingException ex) { - // setErrorMessage(artifact, Lib.exceptionToString(ex)); + logger.error(ex, "Error in selectArtifact"); } } @@ -151,8 +155,9 @@ public class SearchPresenterImpl<T extends SearchHeaderComponent, K extends View ReadableArtifact displayArt = null; try { displayArt = artifactProvider.getArtifactByGuid(TokenFactory.createBranch(branch, ""), art); - } catch (Exception e) { - setErrorMessage(artHeaderComp, String.format("Error while loading artifact[%s] from branch:[%s]", art, branch)); + } catch (Exception ex) { + logger.error(ex, "Error in initArtifactPage"); + setErrorMessage(artHeaderComp, Lib.exceptionToString(ex)); return; } if (displayArt == null) { @@ -163,8 +168,9 @@ public class SearchPresenterImpl<T extends SearchHeaderComponent, K extends View ViewArtifact artifact = null; try { artifact = convertToViewArtifact(displayArt, true); - } catch (Exception e) { - setErrorMessage(artHeaderComp, String.format("Error while converting [%s] from branch:[%s]", art, branch)); + } catch (Exception ex) { + logger.error(ex, "Error in initArtifactPage"); + setErrorMessage(artHeaderComp, Lib.exceptionToString(ex)); return; } @@ -175,8 +181,9 @@ public class SearchPresenterImpl<T extends SearchHeaderComponent, K extends View Collection<RelationType> relationTypes = null; try { relationTypes = artifactProvider.getValidRelationTypes(displayArt); - } catch (Exception e) { - setErrorMessage(relComp, String.format("Error loading relation types for: [%s]", displayArt.getName())); + } catch (Exception ex) { + logger.error(ex, "Error in initArtifactPage"); + setErrorMessage(relComp, Lib.exceptionToString(ex)); return; } for (RelationType relTypeSide : relationTypes) { @@ -191,7 +198,8 @@ public class SearchPresenterImpl<T extends SearchHeaderComponent, K extends View try { attributeTypes = displayArt.getAttributeTypes(); } catch (Exception ex) { - setErrorMessage(attrComp, String.format("Error loading attributes for: [%s]", displayArt.getName())); + logger.error(ex, "Error in initArtifactPage"); + setErrorMessage(attrComp, Lib.exceptionToString(ex)); return; } for (IAttributeType attrType : attributeTypes) { @@ -202,7 +210,8 @@ public class SearchPresenterImpl<T extends SearchHeaderComponent, K extends View attrComp.addAttribute(attrType.getName(), value.getDisplayableString()); } } catch (Exception ex) { - setErrorMessage(attrComp, String.format("Error loading attributes for: [%s]", displayArt.getName())); + logger.error(ex, "Error in initArtifactPage"); + setErrorMessage(attrComp, Lib.exceptionToString(ex)); return; } } @@ -231,8 +240,8 @@ public class SearchPresenterImpl<T extends SearchHeaderComponent, K extends View artifactProvider.getRelatedArtifacts(sourceArt, TokenFactory.createRelationTypeSide(RelationSide.SIDE_B, type.getGuid(), type.getName())); } catch (Exception ex) { - setErrorMessage(relationComponent, - String.format("Error loading relations for artifact[%s]", artifact.getGuid())); + logger.error(ex, "Error in selectRelationType"); + setErrorMessage(relationComponent, Lib.exceptionToString(ex)); return; } @@ -258,8 +267,8 @@ public class SearchPresenterImpl<T extends SearchHeaderComponent, K extends View relationComponent.addRightRelated(id); } } catch (Exception ex) { - setErrorMessage(relationComponent, - String.format("Error adding artifact[%s] to relation relation component", artifact.getGuid())); + logger.error(ex, "Error in selectRelationType"); + setErrorMessage(relationComponent, Lib.exceptionToString(ex)); return; } } @@ -393,6 +402,7 @@ public class SearchPresenterImpl<T extends SearchHeaderComponent, K extends View @Override public void selectSearch(String url, K params, SearchNavigator navigator) { + //do nothing for now } } diff --git a/plugins/org.eclipse.osee.display.presenter/src/org/eclipse/osee/display/presenter/Utility.java b/plugins/org.eclipse.osee.display.presenter/src/org/eclipse/osee/display/presenter/Utility.java index 8cde81925f5..d69f1b4e831 100644 --- a/plugins/org.eclipse.osee.display.presenter/src/org/eclipse/osee/display/presenter/Utility.java +++ b/plugins/org.eclipse.osee.display.presenter/src/org/eclipse/osee/display/presenter/Utility.java @@ -102,7 +102,7 @@ public final class Utility { url.append(encode(entry.getKey())); url.append("="); url.append(encode(entry.getValue())); - url.append("?"); + url.append("&"); } catch (UnsupportedEncodingException ex) { // } |