use of com.haulmont.cuba.security.entity.FilterEntity in project cuba by cuba-platform.
the class FilterEditor method init.
@Override
public void init(Map<String, Object> params) {
super.init(params);
if (Boolean.TRUE.equals(useShortConditionForm)) {
setCaption(messages.getMainMessage("filter.editor.captionShortForm"));
}
getDialogOptions().setWidth(theme.get("cuba.gui.filterEditor.dialog.width")).setHeight(theme.get("cuba.gui.filterEditor.dialog.height")).setResizable(true);
filterEntity = (FilterEntity) params.get("filterEntity");
if (filterEntity == null) {
throw new RuntimeException("Filter entity was not passed to filter editor");
}
filter = (Filter) params.get("filter");
ConditionsTree paramConditions = (ConditionsTree) params.get("conditions");
conditions = paramConditions.createCopy();
refreshConditionsDs();
conditionsTree.expandTree();
if (!messages.getMainMessage("filter.adHocFilter").equals(filterEntity.getName())) {
filterName.setValue(filterEntity.getName());
}
availableForAllCb.setValue(filterEntity.getUser() == null);
defaultCb.setValue(filterEntity.getIsDefault());
applyDefaultCb.setValue(filterEntity.getApplyDefault());
globalDefaultCb.setValue(filterEntity.getGlobalDefault());
if (filterEntity.getUser() != null) {
globalDefaultCb.setEnabled(false);
}
if (!userSessionSource.getUserSession().isSpecificPermitted(GLOBAL_FILTER_PERMISSION)) {
availableForAllCb.setVisible(false);
availableForAllLabel.setVisible(false);
globalDefaultCb.setVisible(false);
globalDefaultLabel.setVisible(false);
}
availableForAllCb.addValueChangeListener(e -> {
Boolean isFilterAvailableForAll = (Boolean) e.getValue();
globalDefaultCb.setEnabled(isFilterAvailableForAll);
if (!isFilterAvailableForAll) {
globalDefaultCb.setValue(null);
}
});
Configuration configuration = AppBeans.get(Configuration.NAME);
boolean manualApplyRequired = filter.getManualApplyRequired() != null ? filter.getManualApplyRequired() : configuration.getConfig(ClientConfig.class).getGenericFilterManualApplyRequired();
if (!manualApplyRequired) {
applyDefaultCb.setVisible(manualApplyRequired);
applyDefaultLabel.setVisible(manualApplyRequired);
}
if (filterEntity.getFolder() != null) {
defaultCb.setVisible(false);
defaultLabel.setVisible(false);
}
conditionsDs.addItemChangeListener(e -> {
if (!treeItemChangeListenerEnabled) {
return;
}
// commit previously selected condition
if (activeConditionFrame != null) {
List<Validatable> validatables = new ArrayList<>();
Collection<Component> frameComponents = ComponentsHelper.getComponents(activeConditionFrame);
for (Component frameComponent : frameComponents) {
if (frameComponent instanceof Validatable) {
validatables.add((Validatable) frameComponent);
}
}
if (validate(validatables)) {
activeConditionFrame.commit();
} else {
treeItemChangeListenerEnabled = false;
conditionsTree.setSelected(e.getPrevItem());
treeItemChangeListenerEnabled = true;
return;
}
}
if (e.getItem() == null) {
activeConditionFrame = null;
} else {
if (e.getItem() instanceof PropertyCondition) {
activeConditionFrame = propertyConditionFrame;
} else if (e.getItem() instanceof DynamicAttributesCondition) {
activeConditionFrame = dynamicAttributesConditionFrame;
} else if (e.getItem() instanceof CustomCondition) {
activeConditionFrame = customConditionFrame;
} else if (e.getItem() instanceof GroupCondition) {
activeConditionFrame = groupConditionFrame;
} else if (e.getItem() instanceof FtsCondition) {
activeConditionFrame = ftsConditionFrame;
} else {
log.warn("Conditions frame for condition with type " + e.getItem().getClass().getSimpleName() + " not found");
}
}
propertyConditionFrame.setVisible(false);
customConditionFrame.setVisible(false);
dynamicAttributesConditionFrame.setVisible(false);
groupConditionFrame.setVisible(false);
ftsConditionFrame.setVisible(false);
if (activeConditionFrame != null) {
activeConditionFrame.setVisible(true);
activeConditionFrame.setCondition(e.getItem());
if (Boolean.TRUE.equals(useShortConditionForm)) {
for (String componentName : componentsToHideInShortForm) {
Component component = activeConditionFrame.getComponent(componentName);
if (component != null) {
if (BooleanUtils.isTrue(showConditionHiddenOption) && componentsForHiddenOption.contains(componentName)) {
continue;
}
component.setVisible(false);
}
}
}
}
});
addConditionHelper = new AddConditionHelper(filter, BooleanUtils.isTrue(hideDynamicAttributes), BooleanUtils.isTrue(hideCustomConditions), condition -> {
AbstractCondition item = conditionsDs.getItem();
if (item != null && item instanceof GroupCondition) {
Node<AbstractCondition> newNode = new Node<>(condition);
Node<AbstractCondition> selectedNode = conditions.getNode(item);
selectedNode.addChild(newNode);
refreshConditionsDs();
conditionsTree.expand(item.getId());
} else {
conditions.getRootNodes().add(new Node<>(condition));
refreshConditionsDs();
}
conditionsTree.setSelected(condition);
});
FilterHelper filterHelper = AppBeans.get(FilterHelper.class);
filterHelper.initConditionsDragAndDrop(conditionsTree, conditions);
if (Boolean.TRUE.equals(useShortConditionForm)) {
filterPropertiesGrid.setVisible(false);
}
}
use of com.haulmont.cuba.security.entity.FilterEntity in project cuba by cuba-platform.
the class FilterSelectWindow method init.
@SuppressWarnings("unchecked")
@Override
public void init(Map<String, Object> params) {
ThemeConstants theme = themeConstantsManager.getConstants();
getDialogOptions().setHeight(theme.get("cuba.gui.filterSelect.dialog.height")).setWidth(theme.get("cuba.gui.filterSelect.dialog.width")).setResizable(true);
filterEntitiesTable.addGeneratedColumn("name", new Table.ColumnGenerator<FilterEntity>() {
@Override
public Component generateCell(FilterEntity entity) {
Label label = componentsFactory.createComponent(Label.class);
String caption;
if (Strings.isNullOrEmpty(entity.getCode())) {
caption = InstanceUtils.getInstanceName(entity);
} else {
caption = messages.getMainMessage(entity.getCode());
}
label.setValue(caption);
captionsMap.put(entity, caption);
return label;
}
});
filterEntities = (List<FilterEntity>) params.get("filterEntities");
fillDatasource(null);
filterEntitiesTable.setItemClickAction(new AbstractAction("selectByDblClk") {
@Override
public void actionPerform(Component component) {
select();
}
@Override
public String getCaption() {
return messages.getMainMessage("filter.filterSelect.select");
}
});
FilterHelper filterHelper = AppBeans.get(FilterHelper.class);
filterHelper.addTextChangeListener(nameFilterField, new FilterHelper.TextChangeListener() {
@Override
public void textChanged(String text) {
fillDatasource(text);
}
});
}
use of com.haulmont.cuba.security.entity.FilterEntity in project cuba by cuba-platform.
the class AttributeEditor method openConstraintWizard.
public void openConstraintWizard() {
Class entityClass = attribute.getJavaClassForEntity();
if (entityClass == null) {
showNotification(getMessage("selectEntityType"));
return;
}
MetaClass metaClass = metadata.getClassNN(entityClass);
FakeFilterSupport fakeFilterSupport = new FakeFilterSupport(this, metaClass);
final Filter fakeFilter = fakeFilterSupport.createFakeFilter();
final FilterEntity filterEntity = fakeFilterSupport.createFakeFilterEntity(attribute.getFilterXml());
final ConditionsTree conditionsTree = fakeFilterSupport.createFakeConditionsTree(fakeFilter, filterEntity);
Map<String, Object> params = new HashMap<>();
params.put("filter", fakeFilter);
params.put("filterEntity", filterEntity);
params.put("conditions", conditionsTree);
params.put("useShortConditionForm", true);
FilterEditor filterEditor = (FilterEditor) openWindow("filterEditor", WindowManager.OpenType.DIALOG, params);
filterEditor.addCloseListener(actionId -> {
if (!COMMIT_ACTION_ID.equals(actionId))
return;
FilterParser filterParser1 = AppBeans.get(FilterParser.class);
filterEntity.setXml(filterParser1.getXml(filterEditor.getConditions(), Param.ValueProperty.DEFAULT_VALUE));
if (filterEntity.getXml() != null) {
Element element = Dom4j.readDocument(filterEntity.getXml()).getRootElement();
com.haulmont.cuba.core.global.filter.FilterParser filterParser = new com.haulmont.cuba.core.global.filter.FilterParser(element);
String jpql = new SecurityJpqlGenerator().generateJpql(filterParser.getRoot());
attribute.setWhereClause(jpql);
Set<String> joins = filterParser.getRoot().getJoins();
if (!joins.isEmpty()) {
String joinsStr = new StrBuilder().appendWithSeparators(joins, " ").toString();
attribute.setJoinClause(joinsStr);
}
attribute.setFilterXml(filterEntity.getXml());
}
});
}
use of com.haulmont.cuba.security.entity.FilterEntity in project cuba by cuba-platform.
the class ConstraintEditor method openWizard.
public void openWizard() {
String entityNameValue = entityName.getValue();
if (StringUtils.isBlank(entityNameValue)) {
showNotification(getMessage("notification.entityIsEmpty"), NotificationType.HUMANIZED);
entityName.requestFocus();
return;
}
FakeFilterSupport fakeFilterSupport = new FakeFilterSupport(this, metadata.getSession().getClass(entityNameValue));
WindowInfo windowInfo = windowConfig.getWindowInfo("filterEditor");
Map<String, Object> params = new HashMap<>();
Constraint constraint = getItem();
final Filter fakeFilter = fakeFilterSupport.createFakeFilter();
final FilterEntity filterEntity = fakeFilterSupport.createFakeFilterEntity(constraint.getFilterXml());
final ConditionsTree conditionsTree = fakeFilterSupport.createFakeConditionsTree(fakeFilter, filterEntity);
params.put("filter", fakeFilter);
params.put("filterEntity", filterEntity);
params.put("conditions", conditionsTree);
params.put("useShortConditionForm", true);
params.put("hideDynamicAttributes", constraint.getCheckType() != ConstraintCheckType.DATABASE);
params.put("hideCustomConditions", constraint.getCheckType() != ConstraintCheckType.DATABASE);
FilterEditor filterEditor = (FilterEditor) windowManagerProvider.get().openWindow(windowInfo, WindowManager.OpenType.DIALOG, params);
filterEditor.addCloseListener(actionId -> {
if (!COMMIT_ACTION_ID.equals(actionId))
return;
FilterParser filterParser1 = AppBeans.get(FilterParser.class);
// todo eude rename com.haulmont.cuba.gui.components.filter.FilterParser
filterEntity.setXml(filterParser1.getXml(filterEditor.getConditions(), Param.ValueProperty.DEFAULT_VALUE));
if (filterEntity.getXml() != null) {
Element element = Dom4j.readDocument(filterEntity.getXml()).getRootElement();
com.haulmont.cuba.core.global.filter.FilterParser filterParser = new com.haulmont.cuba.core.global.filter.FilterParser(element);
Constraint item = getItem();
if (item.getCheckType().database()) {
String jpql = new SecurityJpqlGenerator().generateJpql(filterParser.getRoot());
constraint.setWhereClause(jpql);
Set<String> joins = filterParser.getRoot().getJoins();
if (!joins.isEmpty()) {
String joinsStr = new StrBuilder().appendWithSeparators(joins, " ").toString();
constraint.setJoinClause(joinsStr);
}
}
if (item.getCheckType().memory()) {
String groovy = new GroovyGenerator().generateGroovy(filterParser.getRoot());
constraint.setGroovyScript(groovy);
}
constraint.setFilterXml(filterEntity.getXml());
}
});
}
use of com.haulmont.cuba.security.entity.FilterEntity in project cuba by cuba-platform.
the class FilterDelegateImpl method getDefaultFilter.
protected FilterEntity getDefaultFilter(List<FilterEntity> filters) {
Window window = ComponentsHelper.getWindow(filter);
// First check if there is parameter with name equal to this filter component id, containing a filter code to apply
Map<String, Object> params = filter.getFrame().getContext().getParams();
String code = (String) params.get(filter.getId());
if (!StringUtils.isBlank(code)) {
for (FilterEntity filter : filters) {
if (code.equals(filter.getCode()))
return filter;
}
}
// No 'filter' parameter found, load default filter
SettingsImpl settings = new SettingsImpl(window.getId());
String componentPath = ComponentsHelper.getFilterComponentPath(filter);
String[] strings = ValuePathHelper.parse(componentPath);
String name = ValuePathHelper.format((String[]) ArrayUtils.subarray(strings, 1, strings.length));
Element e = settings.get(name).element("defaultFilter");
if (e != null) {
String defIdStr = e.attributeValue("id");
Boolean applyDefault = Boolean.valueOf(e.attributeValue("applyDefault"));
if (!StringUtils.isBlank(defIdStr)) {
UUID defaultId = null;
try {
defaultId = UUID.fromString(defIdStr);
} catch (IllegalArgumentException ex) {
//
}
if (defaultId != null) {
for (FilterEntity filter : filters) {
if (defaultId.equals(filter.getId())) {
filter.setIsDefault(true);
filter.setApplyDefault(applyDefault);
return filter;
}
}
}
}
}
FilterEntity globalDefaultFilter = filters.stream().filter(filterEntity -> Boolean.TRUE.equals(filterEntity.getGlobalDefault())).findAny().orElse(null);
return globalDefaultFilter;
}
Aggregations