Search in sources :

Example 1 with MessageDetail

use of io.jmix.graphql.schema.messages.MessageDetail in project jmix by jmix-framework.

the class MessagesDataFetcher method getEntityMessages.

protected List<MessageDetail> getEntityMessages(MetaClass metaClass, Locale locale) {
    List<MessageDetail> messages = new ArrayList<>();
    CrudEntityContext entityContext = new CrudEntityContext(metaClass);
    accessManager.applyRegisteredConstraints(entityContext);
    String metaClassName = metaClass.getName();
    if (entityContext.isReadPermitted()) {
        String entityCaption = messageTools.getEntityCaption(metaClass, locale);
        messages.add(new MessageDetail(metaClassName, entityCaption));
    }
    for (MetaProperty metaProperty : metaClass.getProperties()) {
        EntityAttributeContext attributeContext = new EntityAttributeContext(metaClass, metaProperty.getName());
        accessManager.applyRegisteredConstraints(attributeContext);
        if (attributeContext.canView()) {
            String propertyCaption = messageTools.getPropertyCaption(metaProperty, locale);
            messages.add(new MessageDetail(metaClassName + "." + metaProperty.getName(), propertyCaption));
        }
    }
    return messages;
}
Also used : CrudEntityContext(io.jmix.core.accesscontext.CrudEntityContext) EntityAttributeContext(io.jmix.core.accesscontext.EntityAttributeContext) ArrayList(java.util.ArrayList) MessageDetail(io.jmix.graphql.schema.messages.MessageDetail) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 2 with MessageDetail

use of io.jmix.graphql.schema.messages.MessageDetail in project jmix by jmix-framework.

the class MessagesDataFetcher method getEnumMessages.

protected List<MessageDetail> getEnumMessages(Class<?> enumClass, Locale locale) {
    List<MessageDetail> enumMessages = new ArrayList<>();
    String classCaption;
    if (locale == null) {
        classCaption = messages.getMessage(enumClass, enumClass.getSimpleName());
    } else {
        classCaption = messages.getMessage(enumClass, enumClass.getSimpleName(), locale);
    }
    enumMessages.add(new MessageDetail(enumClass.getName(), classCaption));
    Object[] enumConstants = enumClass.getEnumConstants();
    for (Object enumConstant : enumConstants) {
        Enum<?> enumValue = (Enum<?>) enumConstant;
        String msgKey = enumClass.getName() + "." + enumValue.name();
        String msgValue;
        if (locale == null) {
            msgValue = messages.getMessage(enumValue);
        } else {
            msgValue = messages.getMessage(enumValue, locale);
        }
        enumMessages.add(new MessageDetail(msgKey, msgValue));
    }
    return enumMessages;
}
Also used : ArrayList(java.util.ArrayList) MessageDetail(io.jmix.graphql.schema.messages.MessageDetail)

Aggregations

MessageDetail (io.jmix.graphql.schema.messages.MessageDetail)2 ArrayList (java.util.ArrayList)2 CrudEntityContext (io.jmix.core.accesscontext.CrudEntityContext)1 EntityAttributeContext (io.jmix.core.accesscontext.EntityAttributeContext)1 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)1