use of com.haulmont.cuba.core.app.PersistenceManagerService in project cuba by cuba-platform.
the class UniqueConstraintViolationPatternFactory method build.
@Override
public Object build(String value) {
Messages messages = AppBeans.get(Messages.NAME);
PersistenceManagerService pmService = AppBeans.get(PersistenceManagerService.NAME);
String defaultConstraintViolationPattern = pmService.getUniqueConstraintViolationPattern();
Pattern constraintViolationPattern;
if (StringUtils.isBlank(value)) {
constraintViolationPattern = Pattern.compile(defaultConstraintViolationPattern);
} else {
try {
constraintViolationPattern = Pattern.compile(value);
} catch (PatternSyntaxException e) {
constraintViolationPattern = Pattern.compile(defaultConstraintViolationPattern);
Logger log = LoggerFactory.getLogger(UniqueConstraintViolationPatternFactory.class);
log.warn(String.format(messages.getMainMessage("incorrectRegexp"), "cuba.uniqueConstraintViolationPattern"), e);
}
}
return constraintViolationPattern;
}
use of com.haulmont.cuba.core.app.PersistenceManagerService in project cuba by cuba-platform.
the class WebAbstractTable method addColumn.
@Override
public void addColumn(Table.Column column) {
checkNotNullArgument(column, "Column must be non null");
Object columnId = column.getId();
component.addContainerProperty(columnId, column.getType(), null);
if (StringUtils.isNotBlank(column.getDescription())) {
component.setColumnDescription(columnId, column.getDescription());
}
if (StringUtils.isNotBlank(column.getValueDescription())) {
component.setAggregationDescription(columnId, column.getValueDescription());
} else if (column.getAggregation() != null && column.getAggregation().getType() != AggregationInfo.Type.CUSTOM) {
Messages messages = AppBeans.get(Messages.NAME);
String aggregationTypeLabel;
switch(column.getAggregation().getType()) {
case AVG:
aggregationTypeLabel = "aggreagtion.avg";
break;
case COUNT:
aggregationTypeLabel = "aggreagtion.count";
break;
case SUM:
aggregationTypeLabel = "aggreagtion.sum";
break;
case MIN:
aggregationTypeLabel = "aggreagtion.min";
break;
case MAX:
aggregationTypeLabel = "aggreagtion.max";
break;
default:
throw new IllegalArgumentException(String.format("AggregationType %s is not supported", column.getAggregation().getType().toString()));
}
component.setAggregationDescription(columnId, messages.getMainMessage(aggregationTypeLabel));
}
if (!column.isSortable()) {
component.setColumnSortable(columnId, column.isSortable());
}
columns.put(columnId, column);
columnsOrder.add(column);
if (column.getWidth() != null) {
component.setColumnWidth(columnId, column.getWidth());
}
if (column.getAlignment() != null) {
component.setColumnAlignment(columnId, WebComponentsHelper.convertColumnAlignment(column.getAlignment()));
}
final String caption = getColumnCaption(columnId, column);
setColumnHeader(columnId, caption);
column.setOwner(this);
if (column.getFormatter() == null && columnId instanceof MetaPropertyPath) {
MetaProperty metaProperty = ((MetaPropertyPath) columnId).getMetaProperty();
if (Collection.class.isAssignableFrom(metaProperty.getJavaType())) {
final Formatter collectionFormatter = new CollectionFormatter();
column.setFormatter(collectionFormatter);
}
}
if (columnId instanceof MetaPropertyPath) {
PersistenceManagerService persistenceManagerService = AppBeans.get(PersistenceManagerClient.NAME);
MetaPropertyPath propertyPath = (MetaPropertyPath) columnId;
MetaProperty metaProperty = propertyPath.getMetaProperty();
MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(propertyPath);
String storeName = metadataTools.getStoreName(propertyMetaClass);
if (metadataTools.isLob(metaProperty) && !persistenceManagerService.supportsLobSortingAndFiltering(storeName)) {
component.setColumnSortable(columnId, false);
}
}
}
use of com.haulmont.cuba.core.app.PersistenceManagerService in project cuba by cuba-platform.
the class Param method createEntityLookup.
protected Component createEntityLookup(final ValueProperty valueProperty) {
Metadata metadata = AppBeans.get(Metadata.NAME);
MetaClass metaClass = metadata.getSession().getClassNN(javaClass);
ThemeConstants theme = AppBeans.get(ThemeConstantsManager.class).getConstants();
PersistenceManagerService persistenceManager = AppBeans.get(PersistenceManagerService.NAME);
LookupType type = null;
if (property != null && property.getRange().isClass()) {
type = (LookupType) metadata.getTools().getMetaAnnotationAttributes(property.getAnnotations(), Lookup.class).get("type");
}
boolean useLookupScreen = type != null ? type == LookupType.SCREEN : persistenceManager.useLookupScreen(metaClass.getName());
if (useLookupScreen) {
if (inExpr) {
ListEditor listEditor = componentsFactory.createComponent(ListEditor.class);
listEditor.setItemType(ListEditor.ItemType.ENTITY);
listEditor.setEntityName(metaClass.getName());
initListEditor(listEditor, valueProperty);
return listEditor;
} else {
PickerField picker = componentsFactory.createComponent(PickerField.class);
picker.setMetaClass(metaClass);
picker.setWidth(theme.get("cuba.gui.filter.Param.textComponent.width"));
picker.setFrame(datasource.getDsContext().getFrameContext().getFrame());
picker.addLookupAction();
picker.addClearAction();
picker.addValueChangeListener(e -> _setValue(e.getValue(), valueProperty));
picker.setValue(_getValue(valueProperty));
return picker;
}
} else {
CollectionDatasource<Entity<Object>, Object> optionsDataSource = createOptionsDataSource(metaClass);
if (inExpr) {
ListEditor listEditor = componentsFactory.createComponent(ListEditor.class);
listEditor.setItemType(ListEditor.ItemType.ENTITY);
listEditor.setEntityName(metaClass.getName());
listEditor.setUseLookupField(true);
listEditor.setEntityWhereClause(entityWhere);
initListEditor(listEditor, valueProperty);
return listEditor;
} else {
final LookupPickerField lookup = componentsFactory.createComponent(LookupPickerField.class);
lookup.addClearAction();
lookup.setWidth(theme.get("cuba.gui.filter.Param.textComponent.width"));
lookup.setOptionsDatasource(optionsDataSource);
// noinspection unchecked
optionsDataSource.addCollectionChangeListener(e -> lookup.setValue(null));
lookup.addValueChangeListener(e -> _setValue(e.getValue(), valueProperty));
lookup.setValue(_getValue(valueProperty));
return lookup;
}
}
}
use of com.haulmont.cuba.core.app.PersistenceManagerService in project cuba by cuba-platform.
the class AbstractCollectionDatasource method getSortPropertiesForPersistentAttribute.
@Nullable
protected String[] getSortPropertiesForPersistentAttribute(MetaPropertyPath propertyPath) {
String[] sortProperties = null;
MetaProperty metaProperty = propertyPath.getMetaProperty();
Range range = metaProperty.getRange();
PersistenceManagerService persistenceManagerService = AppBeans.get(PersistenceManagerClient.NAME);
if (!range.isClass()) {
// a scalar persistent attribute
MetaClass propertyMetaClass = metadata.getTools().getPropertyEnclosingMetaClass(propertyPath);
String storeName = metadata.getTools().getStoreName(propertyMetaClass);
if (!metadata.getTools().isLob(metaProperty) || persistenceManagerService.supportsLobSortingAndFiltering(storeName)) {
sortProperties = new String[1];
sortProperties[0] = propertyPath.toString();
}
} else {
// a reference attribute
if (!range.getCardinality().isMany()) {
Collection<MetaProperty> properties = metadata.getTools().getNamePatternProperties(range.asClass());
if (!properties.isEmpty()) {
sortProperties = properties.stream().filter(prop -> {
if (metadata.getTools().isPersistent(prop)) {
String storeName = metadata.getTools().getStoreName(range.asClass());
return !metadata.getTools().isLob(prop) || persistenceManagerService.supportsLobSortingAndFiltering(storeName);
}
return true;
}).map(MetadataObject::getName).map(propName -> propertyPath.toString().concat(".").concat(propName)).toArray(String[]::new);
} else {
sortProperties = new String[1];
sortProperties[0] = propertyPath.toString();
}
}
}
return sortProperties;
}
use of com.haulmont.cuba.core.app.PersistenceManagerService in project cuba by cuba-platform.
the class OpManagerImpl method availableOps.
@Override
public EnumSet<Op> availableOps(MetaClass metaClass, MetaProperty metaProperty) {
Class javaClass = metaProperty.getJavaType();
if (String.class.equals(javaClass) && metadataTools.isLob(metaProperty)) {
String storeName = metadata.getTools().getStoreName(metaClass);
PersistenceManagerService persistenceManagerService = AppBeans.get(PersistenceManagerService.class);
if (!persistenceManagerService.supportsLobSortingAndFiltering(storeName)) {
return EnumSet.of(CONTAINS, DOES_NOT_CONTAIN, NOT_EMPTY, STARTS_WITH, ENDS_WITH);
}
}
return availableOps(javaClass);
}
Aggregations