Search in sources :

Example 96 with MetaClass

use of com.haulmont.chile.core.model.MetaClass in project cuba by cuba-platform.

the class AttributeEditor method requestHint.

protected List<Suggestion> requestHint(SourceCodeEditor sender, String text, int senderCursorPosition) {
    String joinStr = joinField.getValue();
    String whereStr = whereField.getValue();
    // CAUTION: the magic entity name!  The length is three character to match "{E}" length in query
    String entityAlias = "a39";
    int queryPosition = -1;
    Class javaClassForEntity = attribute.getJavaClassForEntity();
    if (javaClassForEntity == null)
        return new ArrayList<>();
    MetaClass metaClass = metadata.getClassNN(javaClassForEntity);
    String queryStart = "select " + entityAlias + " from " + metaClass.getName() + " " + entityAlias + " ";
    StringBuilder queryBuilder = new StringBuilder(queryStart);
    if (StringUtils.isNotEmpty(joinStr)) {
        if (sender == joinField) {
            queryPosition = queryBuilder.length() + senderCursorPosition - 1;
        }
        if (!StringUtils.containsIgnoreCase(joinStr, "join") && !StringUtils.contains(joinStr, ",")) {
            queryBuilder.append("join ").append(joinStr);
            queryPosition += "join ".length();
        } else {
            queryBuilder.append(joinStr);
        }
    }
    if (StringUtils.isNotEmpty(whereStr)) {
        if (sender == whereField) {
            queryPosition = queryBuilder.length() + WHERE.length() + senderCursorPosition - 1;
        }
        queryBuilder.append(WHERE).append(whereStr);
    }
    String query = queryBuilder.toString();
    query = query.replace("{E}", entityAlias);
    return JpqlSuggestionFactory.requestHint(query, queryPosition, sender.getAutoCompleteSupport(), senderCursorPosition);
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) MetaClass(com.haulmont.chile.core.model.MetaClass)

Example 97 with MetaClass

use of com.haulmont.chile.core.model.MetaClass in project cuba by cuba-platform.

the class AttributeEditor method fillDefaultEntities.

@SuppressWarnings("unchecked")
protected void fillDefaultEntities(Class entityClass) {
    MetaClass metaClass = metadata.getClassNN(entityClass);
    if (attribute.getObjectDefaultEntityId() != null) {
        LoadContext<Entity> lc = new LoadContext<>(entityClass).setView(View.MINIMAL);
        String pkName = referenceToEntitySupport.getPrimaryKeyForLoadingEntity(metaClass);
        lc.setQueryString(format("select e from %s e where e.%s = :entityId", metaClass.getName(), pkName)).setParameter("entityId", attribute.getObjectDefaultEntityId());
        Entity entity = dataManager.load(lc);
        if (entity != null) {
            defaultEntityField.setValue(entity);
        } else {
            defaultEntityField.setValue(null);
        }
    }
}
Also used : FilterEntity(com.haulmont.cuba.security.entity.FilterEntity) Entity(com.haulmont.cuba.core.entity.Entity) MetaClass(com.haulmont.chile.core.model.MetaClass)

Example 98 with MetaClass

use of com.haulmont.chile.core.model.MetaClass in project cuba by cuba-platform.

the class View method findSystemProperties.

protected Set<String> findSystemProperties(Class entityClass) {
    Set<String> result = new LinkedHashSet<>();
    Metadata metadata = AppBeans.get(Metadata.NAME);
    MetaClass metaClass = metadata.getClassNN(entityClass);
    String pkName = metadata.getTools().getPrimaryKeyName(metaClass);
    if (pkName != null) {
        result.add(pkName);
    }
    addSystemPropertiesFrom(Creatable.class, entityClass, metaClass, metadata, result);
    addSystemPropertiesFrom(Updatable.class, entityClass, metaClass, metadata, result);
    addSystemPropertiesFrom(SoftDelete.class, entityClass, metaClass, metadata, result);
    return result;
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass)

Example 99 with MetaClass

use of com.haulmont.chile.core.model.MetaClass in project cuba by cuba-platform.

the class AbstractViewRepository method deployView.

protected View deployView(Element rootElem, Element viewElem, Set<ViewInfo> visited) {
    String viewName = getViewName(viewElem);
    MetaClass metaClass = getMetaClass(viewElem);
    ViewInfo info = new ViewInfo(metaClass.getJavaClass(), viewName);
    if (visited.contains(info)) {
        throw new DevelopmentException(String.format("Views cannot have cyclic references. View %s for class %s", viewName, metaClass.getName()));
    }
    View v = retrieveView(metaClass, viewName, visited);
    boolean overwrite = Boolean.parseBoolean(viewElem.attributeValue("overwrite"));
    String extended = viewElem.attributeValue("extends");
    List<String> ancestors = null;
    if (isNotBlank(extended)) {
        ancestors = splitExtends(extended);
    }
    if (!overwrite && ancestors != null) {
        overwrite = ancestors.contains(viewName);
    }
    if (v != null && !overwrite) {
        return v;
    }
    boolean systemProperties = Boolean.valueOf(viewElem.attributeValue("systemProperties"));
    View.ViewParams viewParam = new View.ViewParams().entityClass(metaClass.getJavaClass()).name(viewName);
    if (isNotEmpty(ancestors)) {
        List<View> ancestorsViews = ancestors.stream().map(a -> getAncestorView(metaClass, a, visited)).collect(Collectors.toList());
        viewParam.src(ancestorsViews);
    }
    viewParam.includeSystemProperties(systemProperties);
    View view = new View(viewParam);
    visited.add(info);
    loadView(rootElem, viewElem, view, systemProperties, visited);
    visited.remove(info);
    storeView(metaClass, view);
    if (overwrite) {
        replaceOverridden(view);
    }
    return view;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) Document(org.dom4j.Document) java.util(java.util) Dom4j(com.haulmont.bali.util.Dom4j) ReflectionHelper(com.haulmont.bali.util.ReflectionHelper) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) LoggerFactory(org.slf4j.LoggerFactory) DocumentHelper(org.dom4j.DocumentHelper) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) SAXReader(org.dom4j.io.SAXReader) MetaClass(com.haulmont.chile.core.model.MetaClass) com.haulmont.cuba.core.global(com.haulmont.cuba.core.global) Inject(javax.inject.Inject) DocumentException(org.dom4j.DocumentException) Splitter(com.google.common.base.Splitter) Nullable(javax.annotation.Nullable) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Logger(org.slf4j.Logger) Range(com.haulmont.chile.core.model.Range) StrTokenizer(org.apache.commons.lang.text.StrTokenizer) MetaProperty(com.haulmont.chile.core.model.MetaProperty) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) Preconditions(com.haulmont.bali.util.Preconditions) StandardCharsets(java.nio.charset.StandardCharsets) StringUtils.isNotBlank(org.apache.commons.lang.StringUtils.isNotBlank) IOUtils(org.apache.commons.io.IOUtils) StopWatch(org.perf4j.StopWatch) CollectionUtils.isNotEmpty(org.apache.commons.collections4.CollectionUtils.isNotEmpty) Element(org.dom4j.Element) Entity(com.haulmont.cuba.core.entity.Entity) InputStream(java.io.InputStream) MetaClass(com.haulmont.chile.core.model.MetaClass)

Example 100 with MetaClass

use of com.haulmont.chile.core.model.MetaClass in project cuba by cuba-platform.

the class AbstractViewRepository method getAncestorView.

protected View getAncestorView(MetaClass metaClass, String ancestor, Set<ViewInfo> visited) {
    View ancestorView = retrieveView(metaClass, ancestor, visited);
    if (ancestorView == null) {
        ExtendedEntities extendedEntities = metadata.getExtendedEntities();
        MetaClass originalMetaClass = extendedEntities.getOriginalMetaClass(metaClass);
        if (originalMetaClass != null) {
            ancestorView = retrieveView(originalMetaClass, ancestor, visited);
        }
        if (ancestorView == null) {
            // Last resort - search for all ancestors
            for (MetaClass ancestorMetaClass : metaClass.getAncestors()) {
                if (ancestorMetaClass.equals(metaClass)) {
                    ancestorView = retrieveView(ancestorMetaClass, ancestor, visited);
                    if (ancestorView != null)
                        break;
                }
            }
        }
        if (ancestorView == null) {
            throw new DevelopmentException("No ancestor view found: " + ancestor + " for " + metaClass.getName());
        }
    }
    return ancestorView;
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass)

Aggregations

MetaClass (com.haulmont.chile.core.model.MetaClass)302 MetaProperty (com.haulmont.chile.core.model.MetaProperty)103 Entity (com.haulmont.cuba.core.entity.Entity)54 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)36 Nullable (javax.annotation.Nullable)25 BaseGenericIdEntity (com.haulmont.cuba.core.entity.BaseGenericIdEntity)24 Element (org.dom4j.Element)21 java.util (java.util)18 Inject (javax.inject.Inject)17 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)16 Test (org.junit.Test)15 EntityManager (com.haulmont.cuba.core.EntityManager)14 CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)14 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)13 Metadata (com.haulmont.cuba.core.global.Metadata)13 Logger (org.slf4j.Logger)13 LoggerFactory (org.slf4j.LoggerFactory)13 MetadataTools (com.haulmont.cuba.core.global.MetadataTools)12 Collectors (java.util.stream.Collectors)11 Range (com.haulmont.chile.core.model.Range)10