EMMA Coverage Report (generated Mon Jan 28 16:15:17 GMT 2013)
[all classes][org.springframework.data.elasticsearch.core.mapping]

COVERAGE SUMMARY FOR SOURCE FILE [SimpleElasticsearchPersistentEntity.java]

nameclass, %method, %block, %line, %
SimpleElasticsearchPersistentEntity.java100% (1/1)75%  (3/4)72%  (57/79)73%  (10.9/15)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SimpleElasticsearchPersistentEntity100% (1/1)75%  (3/4)72%  (57/79)73%  (10.9/15)
setApplicationContext (ApplicationContext): void 0%   (0/1)0%   (0/18)0%   (0/4)
SimpleElasticsearchPersistentEntity (TypeInformation): void 100% (1/1)93%  (51/55)99%  (8.9/9)
getIndexName (): String 100% (1/1)100% (3/3)100% (1/1)
getIndexType (): String 100% (1/1)100% (3/3)100% (1/1)

1/*
2 * Copyright 2012 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.springframework.data.elasticsearch.core.mapping;
17 
18import org.springframework.beans.BeansException;
19import org.springframework.context.ApplicationContext;
20import org.springframework.context.ApplicationContextAware;
21import org.springframework.context.expression.BeanFactoryAccessor;
22import org.springframework.context.expression.BeanFactoryResolver;
23import org.springframework.data.elasticsearch.annotations.Document;
24import org.springframework.data.mapping.model.BasicPersistentEntity;
25import org.springframework.data.util.TypeInformation;
26import org.springframework.expression.spel.support.StandardEvaluationContext;
27import org.springframework.util.Assert;
28 
29import java.util.Locale;
30 
31import static org.springframework.util.StringUtils.hasText;
32 
33/**
34 * Elasticsearch specific {@link org.springframework.data.mapping.PersistentEntity} implementation holding
35 *
36 * @param <T>
37 */
38public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntity<T, ElasticsearchPersistentProperty> implements
39        ElasticsearchPersistentEntity<T>, ApplicationContextAware {
40 
41    private final StandardEvaluationContext context;
42    private String indexName;
43    private String indexType;
44 
45    public SimpleElasticsearchPersistentEntity(TypeInformation<T> typeInformation) {
46        super(typeInformation);
47        this.context = new StandardEvaluationContext();
48        Class<T> clazz = typeInformation.getType();
49        Assert.isTrue(clazz.isAnnotationPresent(Document.class),
50                clazz.getSimpleName() + " is not a Document. Make sure the document class is annotated with @Document(indexName=\"foo\")");
51        Document document = clazz.getAnnotation(Document.class);
52        Assert.hasText(document.indexName(), " Unknown indexName. Make sure the indexName is defined. e.g @Document(indexName=\"foo\")");
53        this.indexName = typeInformation.getType().getAnnotation(Document.class).indexName();
54        this.indexType = hasText(document.type())? document.type() : clazz.getSimpleName().toLowerCase(Locale.ENGLISH);
55    }
56 
57    @Override
58    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
59        context.addPropertyAccessor(new BeanFactoryAccessor());
60        context.setBeanResolver(new BeanFactoryResolver(applicationContext));
61        context.setRootObject(applicationContext);
62    }
63 
64    @Override
65    public String getIndexName() {
66        return indexName;
67    }
68 
69    @Override
70    public String getIndexType() {
71        return indexType;
72    }
73}

[all classes][org.springframework.data.elasticsearch.core.mapping]
EMMA 2.0.5312 (C) Vladimir Roubtsov