@Test public void testPersistSelector() throws Exception { Assert.assertTrue(resourceA.shouldPersist(serviceParams)); Assert.assertFalse(resourceB.shouldPersist(serviceParams)); }
@Override public boolean shouldPersist(CollectionResource resource) { log().debug("shouldPersist: checking resource " + resource); if (m_parameterCollection == null) { log().warn("shouldPersist: no parameters defined; the resource will be persisted."); return true; } EvaluatorContextVisitor visitor = new EvaluatorContextVisitor(); resource.visit(visitor); ExpressionParser parser = new SpelExpressionParser(); for (Parameter param : m_parameterCollection) { if (param.getKey().equals(MATCH_EXPRESSION)) { Expression exp = parser.parseExpression(param.getValue()); boolean shouldPersist = false; try { shouldPersist = exp.getValue(visitor.getEvaluationContext(), Boolean.class); } catch (Exception e) { log().warn("shouldPersist: can't evaluate expression " + param.getValue() + " for resource " + resource + " because: " + e.getMessage()); } log().debug("shouldPersist: checking " + param.getValue() + " ? " + shouldPersist); if (shouldPersist) return true; } } return false; }
PersistRegexSelectorStrategy implements PersistenceSelectorStrategy { @Override public boolean shouldPersist(CollectionResource resource) { log().debug("shouldPersist: checking resource " + resource); if (m_parameterCollection == null) { log().warn("shouldPersist: no parameters defined; the resource will be persisted."); return true; } EvaluatorContextVisitor visitor = new EvaluatorContextVisitor(); resource.visit(visitor); ExpressionParser parser = new SpelExpressionParser(); for (Parameter param : m_parameterCollection) { if (param.getKey().equals(MATCH_EXPRESSION)) { Expression exp = parser.parseExpression(param.getValue()); boolean shouldPersist = false; try { shouldPersist = exp.getValue(visitor.getEvaluationContext(), Boolean.class); } catch (Exception e) { log().warn("shouldPersist: can't evaluate expression " + param.getValue() + " for resource " + resource + " because: " + e.getMessage()); } log().debug("shouldPersist: checking " + param.getValue() + " ? " + shouldPersist); if (shouldPersist) return true; } } return false; } }
PersistRegexSelectorStrategy implements PersistenceSelectorStrategy { @Override public boolean shouldPersist(CollectionResource resource) { log().debug("shouldPersist: checking resource " + resource); if (m_parameterCollection == null) { log().warn("shouldPersist: no parameters defined; the resource will be persisted."); return true; } EvaluatorContextVisitor visitor = new EvaluatorContextVisitor(); resource.visit(visitor); ExpressionParser parser = new SpelExpressionParser(); for (Parameter param : m_parameterCollection) { if (param.getKey().equals(MATCH_EXPRESSION)) { Expression exp = parser.parseExpression(param.getValue()); boolean shouldPersist = false; try { shouldPersist = exp.getValue(visitor.getEvaluationContext(), Boolean.class); } catch (Exception e) { log().warn("shouldPersist: can't evaluate expression " + param.getValue() + " for resource " + resource + " because: " + e.getMessage()); } log().debug("shouldPersist: checking " + param.getValue() + " ? " + shouldPersist); if (shouldPersist) return true; } } return false; }  }
PersistRegexSelectorStrategy implements PersistenceSelectorStrategy { @Override public boolean shouldPersist(CollectionResource resource) { log().debug("shouldPersist: checking resource " + resource); if (m_parameterCollection == null) { log().warn("shouldPersist: no parameters defined; the resource will be persisted."); return true; } EvaluatorContextVisitor visitor = new EvaluatorContextVisitor(); resource.visit(visitor); ExpressionParser parser = new SpelExpressionParser(); for (Parameter param : m_parameterCollection) { if (param.getKey().equals(MATCH_EXPRESSION)) { Expression exp = parser.parseExpression(param.getValue()); boolean shouldPersist = false; try { shouldPersist = exp.getValue(visitor.getEvaluationContext(), Boolean.class); } catch (Exception e) { log().warn("shouldPersist: can't evaluate expression " + param.getValue() + " for resource " + resource + " because: " + e.getMessage()); } log().debug("shouldPersist: checking " + param.getValue() + " ? " + shouldPersist); if (shouldPersist) return true; } } return false; }  @Override boolean shouldPersist(CollectionResource resource); @Override void setParameters(List<Parameter> parameterCollection); ThreadCategory log(); }
PersistRegexSelectorStrategy implements PersistenceSelectorStrategy { @Override public boolean shouldPersist(CollectionResource resource) { log().debug("shouldPersist: checking resource " + resource); if (m_parameterCollection == null) { log().warn("shouldPersist: no parameters defined; the resource will be persisted."); return true; } EvaluatorContextVisitor visitor = new EvaluatorContextVisitor(); resource.visit(visitor); ExpressionParser parser = new SpelExpressionParser(); for (Parameter param : m_parameterCollection) { if (param.getKey().equals(MATCH_EXPRESSION)) { Expression exp = parser.parseExpression(param.getValue()); boolean shouldPersist = false; try { shouldPersist = exp.getValue(visitor.getEvaluationContext(), Boolean.class); } catch (Exception e) { log().warn("shouldPersist: can't evaluate expression " + param.getValue() + " for resource " + resource + " because: " + e.getMessage()); } log().debug("shouldPersist: checking " + param.getValue() + " ? " + shouldPersist); if (shouldPersist) return true; } } return false; }  @Override boolean shouldPersist(CollectionResource resource); @Override void setParameters(List<Parameter> parameterCollection); ThreadCategory log(); static final String MATCH_EXPRESSION; static final String MATCH_STRATEGY; static final String MATCH_BEHAVIOR; }