/** * Uses the parsed {@link ChainManager} to build a Map * representing the current snapshot of the active enhancement chains. * * @param chainManager The chain manager used to build the snapshot * @return the map with the names as key and an Entry with the {@link ServiceReference} * and the {@link Chain} instance as value. */ public static Map<String,Map.Entry<ServiceReference,Chain>> buildChainsMap(ChainManager chainManager) { Map<String,Map.Entry<ServiceReference,Chain>> chains = new HashMap<String,Map.Entry<ServiceReference,Chain>>(); for(String chainName : chainManager.getActiveChainNames()){ ServiceReference chainRef = chainManager.getReference(chainName); if(chainRef != null){ Chain chain = chainManager.getChain(chainRef); if(chain != null){ Map<ServiceReference,Chain> m = Collections.singletonMap(chainRef, chain); chains.put(chainName, m.entrySet().iterator().next()); } } } return chains; } /**
public GenericEnhancerUiResource(String chainName, EnhancementJobManager jobManager, EnhancementEngineManager engineManager, ChainManager chainManager, ContentItemFactory ciFactory, Serializer serializer, LayoutConfiguration layoutConfiguration, UriInfo uriInfo) { super(jobManager, engineManager, chainManager, ciFactory, layoutConfiguration, uriInfo); this.serializer = serializer; //this.queryEngine = queryEngine; if(chainName == null){ chain = chainManager.getDefault(); } else { this.chain = chainManager.getChain(chainName); } if(this.chain == null){ throw new WebApplicationException(Response.Status.NOT_FOUND); } }
@Override protected State consume(String line) throws IOException { if(ctx.currentBenchmark.getChain() == null){ Chain chain = chainManager.getChain(line); if(chain != null){ ctx.currentBenchmark.setChain(chain); } //defined chain not active } //do not override return this; }
/** * Create the RDF data for the currently active Enhancement {@link Chain}s.<p> * Note the the parsed rootUrl MUST already consider offsets configured * for the Stanbol RESTful service. When called from within a * {@link BaseStanbolResource} the following code segment should be used:<p> * <code><pre> * String rootUrl = uriInfo.getBaseUriBuilder().path(getRootUrl()).build().toString(); * </pre></code> * @param chainManager the enhancement chain manager. * @param graph the RDF graph to add the triples * @param rootUrl the root URL used by the current request */ public static void addActiveChains(ChainManager chainManager, Graph graph, String rootUrl) { addActiveChains(buildChainsMap(chainManager).values(), chainManager.getDefault(), graph, rootUrl); } /**
private void enhance(ContentItem ci, String chainName) throws StoreException { try { if (chainName == null || chainName.trim().isEmpty()) { jobManager.enhanceContent(ci); } else { Chain chain = chainManager.getChain(chainName.trim()); if (chain == null) { String msg = String.format("Failed to get chain with name: %s", chainName); log.error(msg); throw new StoreException(msg); } jobManager.enhanceContent(ci, chain); } } catch (EnhancementException e) { String msg = String.format("Cannot enhance content with id: %s", ci.getUri().getUnicodeString()); log.error(msg, e); throw new StoreException(msg, e); } }
/** * Create the RDF data for the currently active Enhancement {@link Chain}s.<p> * Note the the parsed rootUrl MUST already consider offsets configured * for the Stanbol RESTful service. When called from within a * {@link BaseStanbolResource} the following code segment should be used:<p> * <code><pre> * String rootUrl = uriInfo.getBaseUriBuilder().path(getRootUrl()).build().toString(); * </pre></code> * @param chainManager the enhancement chain manager. * @param graph the RDF graph to add the triples * @param rootUrl the root URL used by the current request */ public static void addActiveChains(ChainManager chainManager, Graph graph, String rootUrl) { addActiveChains(buildChainsMap(chainManager).values(), chainManager.getDefault(), graph, rootUrl); } /**
/** * Uses the parsed {@link ChainManager} to build a Map * representing the current snapshot of the active enhancement chains. * * @param chainManager The chain manager used to build the snapshot * @return the map with the names as key and an Entry with the {@link ServiceReference} * and the {@link Chain} instance as value. */ public static Map<String,Map.Entry<ServiceReference,Chain>> buildChainsMap(ChainManager chainManager) { Map<String,Map.Entry<ServiceReference,Chain>> chains = new HashMap<String,Map.Entry<ServiceReference,Chain>>(); for(String chainName : chainManager.getActiveChainNames()){ ServiceReference chainRef = chainManager.getReference(chainName); if(chainRef != null){ Chain chain = chainManager.getChain(chainRef); if(chain != null){ Map<ServiceReference,Chain> m = Collections.singletonMap(chainRef, chain); chains.put(chainName, m.entrySet().iterator().next()); } } } return chains; } /**
public GenericEnhancerUiResource(String chainName, EnhancementJobManager jobManager, EnhancementEngineManager engineManager, ChainManager chainManager, ContentItemFactory ciFactory, Serializer serializer, LayoutConfiguration layoutConfiguration, UriInfo uriInfo) { super(jobManager, engineManager, chainManager, ciFactory, layoutConfiguration, uriInfo); this.serializer = serializer; //this.queryEngine = queryEngine; if(chainName == null){ chain = chainManager.getDefault(); } else { this.chain = chainManager.getChain(chainName); } if(this.chain == null){ throw new WebApplicationException(Response.Status.NOT_FOUND); } }
List<? extends Benchmark> benchmarks = parser.parse(new StringReader(content)); if(chainName != null && !chainName.isEmpty()){ Chain chain = chainManager.getChain(chainName); if(chain == null){ response.setStatus(404);
@Override public List<EnhancementEngine> getActiveEngines() { //This implementation return the list of active engined for the default //Chain in the order they would be executed Chain defaultChain = chainManager.getDefault(); if(defaultChain == null){ throw new IllegalStateException("Currently no enhancement chain is " + "active. Please configure a Chain or enable the default chain"); } ImmutableGraph ep; try { ep = defaultChain.getExecutionPlan(); } catch (ChainException e) { throw new IllegalStateException("Unable to get Execution Plan for " + "default enhancement chain (name: '"+defaultChain.getName()+ "'| class: '"+defaultChain.getClass()+"')!",e); } return ExecutionPlanHelper.getActiveEngines(engineManager,ep); }
@Override public void enhanceContent(ContentItem ci) throws EnhancementException { Chain defaultChain = chainManager.getDefault(); if(defaultChain == null){ throw new ChainException("Unable to enhance ContentItem '"+ci.getUri()+ "' because currently no enhancement chain is active. Please" + "configure a Chain or enable the default chain"); } enhanceContent(ci, defaultChain); }
boolean isDefaultChain = chain.equals(chainManager.getDefault()); EnhancementJob job = new EnhancementJob(ci, chain.getName(), chain.getExecutionPlan(),isDefaultChain);