@Test public void views_should_be_generated_for_all_annotations() throws Exception { Map<String, DesignDocument.View> result = gen.generateViews(new TestRepo()); assertTrue(result.containsKey("view_1")); assertTrue(result.containsKey("view_2")); assertTrue(result.containsKey("view_3")); assertTrue(result.containsKey("by_name")); assertTrue(result.containsKey("by_lastName")); assertTrue(result.containsKey("by_domainName")); assertEquals(expectedArrayMapFunction, result.get("by_domainName").getMap()); assertTrue(result.containsKey("by_account")); assertEquals(expectedByAccountFunction, result.get("by_account").getMap()); assertTrue(result.containsKey("all")); DesignDocument.View all = result.get("all"); assertEquals(ALL_VIEW_FUNCTION, all.getMap()); assertTrue(result.containsKey("by_special")); assertNull("reduce function should not be defined", result.get("by_special").getReduce()); assertTrue(result.containsKey("by_special2")); assertFalse("map function should be loaded from file in classpath", result.get("by_special2").getMap().startsWith("classpath:")); assertTrue("reduce function should be loaded from file in classpath", result.get("by_special2").getReduce().indexOf("keys") > -1); assertTrue(result.containsKey("by_complicated")); assertEquals(expectedComplicatedMapFunction, result.get("by_complicated").getMap()); assertEquals(expectedComplicatedReduceFunction, result.get("by_complicated").getReduce()); assertTrue(result.containsKey("by_special3")); assertFalse("map function should be loaded from file in classpath", result.get("by_special3").getMap().startsWith("classpath:")); assertNull("reduce function should not be defined", result.get("by_special3").getReduce()); ObjectMapper mapper = new ObjectMapper(); mapper.writeValueAsString(result); }
public Map<String, DesignDocument.View> generateViews( final Object repository) { final Map<String, DesignDocument.View> views = new HashMap<String, DesignDocument.View>(); final Class<?> repositoryClass = repository.getClass(); final Class<?> handledType = repository instanceof CouchDbRepositorySupport<?> ? ((CouchDbRepositorySupport<?>) repository) .getHandledType() : null; createDeclaredViews(views, repositoryClass); eachMethod(repositoryClass, new Predicate<Method>() { public boolean apply(Method input) { if (hasAnnotation(input, GenerateView.class)) { generateView(views, input, handledType); } return false; } }); if (handledType != null) { views.putAll(generateViewsFromPersistentType(handledType)); } return views; }
SimpleViewGenerator { public Map<String, DesignDocument.View> generateViews( final Object repository) { final Map<String, DesignDocument.View> views = new HashMap<String, DesignDocument.View>(); final Class<?> repositoryClass = repository.getClass(); final Class<?> handledType = repository instanceof CouchDbRepositorySupport<?> ? ((CouchDbRepositorySupport<?>) repository) .getHandledType() : null; createDeclaredViews(views, repositoryClass); eachMethod(repositoryClass, new Predicate<Method>() { public boolean apply(Method input) { if (hasAnnotation(input, GenerateView.class)) { generateView(views, input, handledType); } return false; } }); if (handledType != null) { views.putAll(generateViewsFromPersistentType(handledType)); } return views; } }
SimpleViewGenerator { public Map<String, DesignDocument.View> generateViews( final Object repository) { final Map<String, DesignDocument.View> views = new HashMap<String, DesignDocument.View>(); final Class<?> repositoryClass = repository.getClass(); final Class<?> handledType = repository instanceof CouchDbRepositorySupport<?> ? ((CouchDbRepositorySupport<?>) repository) .getHandledType() : null; createDeclaredViews(views, repositoryClass); eachMethod(repositoryClass, new Predicate<Method>() { public boolean apply(Method input) { if (hasAnnotation(input, GenerateView.class)) { generateView(views, input, handledType); } return false; } }); if (handledType != null) { views.putAll(generateViewsFromPersistentType(handledType)); } return views; }  }
SimpleViewGenerator { public Map<String, DesignDocument.View> generateViews( final Object repository) { final Map<String, DesignDocument.View> views = new HashMap<String, DesignDocument.View>(); final Class<?> repositoryClass = repository.getClass(); final Class<?> handledType = repository instanceof CouchDbRepositorySupport<?> ? ((CouchDbRepositorySupport<?>) repository) .getHandledType() : null; createDeclaredViews(views, repositoryClass); eachMethod(repositoryClass, new Predicate<Method>() { public boolean apply(Method input) { if (hasAnnotation(input, GenerateView.class)) { generateView(views, input, handledType); } return false; } }); if (handledType != null) { views.putAll(generateViewsFromPersistentType(handledType)); } return views; }  DesignDocument.View generateFindByView(String propertyName,
			String typeDiscriminator); DesignDocument.View generateFindByIterableView(String propertyName,
			String typeDiscriminator); DesignDocument.View generateDocRefsAsSetWithOrderByView(
			String backRef, String fieldName, String orderBy,
			String typeDiscriminator); DesignDocument.View generateDocRefsAsSetView(String backRef,
			String fieldName, String typeDiscriminator); Map<String, DesignDocument.View> generateViews(
			final Object repository); Map<String, DesignDocument.View> generateViewsFromPersistentType(
			final Class<?> persistentType); boolean shouldLoadFunctionFromClassPath(String function); static DesignDocument.View loadViewFromString(ObjectMapper objectMapper, String json); }
SimpleViewGenerator { public Map<String, DesignDocument.View> generateViews( final Object repository) { final Map<String, DesignDocument.View> views = new HashMap<String, DesignDocument.View>(); final Class<?> repositoryClass = repository.getClass(); final Class<?> handledType = repository instanceof CouchDbRepositorySupport<?> ? ((CouchDbRepositorySupport<?>) repository) .getHandledType() : null; createDeclaredViews(views, repositoryClass); eachMethod(repositoryClass, new Predicate<Method>() { public boolean apply(Method input) { if (hasAnnotation(input, GenerateView.class)) { generateView(views, input, handledType); } return false; } }); if (handledType != null) { views.putAll(generateViewsFromPersistentType(handledType)); } return views; }  DesignDocument.View generateFindByView(String propertyName,
			String typeDiscriminator); DesignDocument.View generateFindByIterableView(String propertyName,
			String typeDiscriminator); DesignDocument.View generateDocRefsAsSetWithOrderByView(
			String backRef, String fieldName, String orderBy,
			String typeDiscriminator); DesignDocument.View generateDocRefsAsSetView(String backRef,
			String fieldName, String typeDiscriminator); Map<String, DesignDocument.View> generateViews(
			final Object repository); Map<String, DesignDocument.View> generateViewsFromPersistentType(
			final Class<?> persistentType); boolean shouldLoadFunctionFromClassPath(String function); static DesignDocument.View loadViewFromString(ObjectMapper objectMapper, String json);  }