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);
}
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);
}
}
}
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;
}
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;
}
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;
}
Aggregations