All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jn.esmvc.model.utils.ESModels Maven / Gradle / Ivy

package com.jn.esmvc.model.utils;

import com.jn.esmvc.model.*;
import com.jn.langx.util.Preconditions;

public class ESModels {
    public static final String INDEX_DEFAULT_TYPE = "_doc";
    public static final ESModelIdGenerator defaultModelIdGenerator = new ESModelIdGenerator();

    public static String getIndex(Class modelClass) {
        try {
            Index indexAnnotation = modelClass.getAnnotation(Index.class);
            return indexAnnotation.value();
        } catch (Throwable ex) {
            throw new IllegalArgumentException("Can't find an annotation in class [" + modelClass.getCanonicalName() + "]");
        }
    }

    public static String getType(Class modelClass) {
        try {
            Type typeAnnotation = modelClass.getAnnotation(Type.class);
            if (typeAnnotation == null) {
                return INDEX_DEFAULT_TYPE;
            }
            return typeAnnotation.value();
        } catch (Throwable ex) {
            throw new IllegalArgumentException("Can't find an annotation in class [" + modelClass.getCanonicalName() + "]");
        }
    }

    public static  String getId(MODEL model) {
        return getId(model, defaultModelIdGenerator);
    }

    public static  String getId(MODEL model, ESDocumentIdGenerator documentIdGenerator) {
        Preconditions.checkNotNull(documentIdGenerator);
        return documentIdGenerator.get(model);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy