use of io.jmix.core.Entity in project jmix by jmix-framework.
the class ParameterTransformerImpl method loadEntity.
protected Entity loadEntity(EntityParameterValue parameter) {
Class entityClass = metadata.getClass(parameter.getMetaClassName()).getJavaClass();
FluentLoader.ById loader = dataManager.load(entityClass).id(java.util.UUID.fromString(parameter.getEntityId()));
if (parameter.getFetchPlanName() != null) {
loader.fetchPlan(parameter.getFetchPlanName());
}
return (Entity) loader.optional().orElse(null);
}
use of io.jmix.core.Entity in project jmix by jmix-framework.
the class JmixEclipseLinkQuery method getQuery.
private JpaQuery<E> getQuery() {
if (query == null) {
FetchPlan fetchPlan = fetchPlans.isEmpty() ? null : fetchPlans.get(0);
if (isNative) {
log.trace("Creating SQL query: {}", queryString);
if (resultClass == null)
query = (JpaQuery) entityManager.createNativeQuery(queryString);
else {
if (!Entity.class.isAssignableFrom(resultClass)) {
throw new IllegalArgumentException("Non-entity result class for native query is not supported" + " by EclipseLink: " + resultClass);
}
Class effectiveClass = extendedEntities.getEffectiveClass(resultClass);
query = (JpaQuery) entityManager.createNativeQuery(queryString, effectiveClass);
}
} else {
log.trace("Creating JPQL query: {}", queryString);
transformedQueryString = transformQueryString();
log.trace("Transformed JPQL query: {}", transformedQueryString);
processParams(transformedQueryString);
Class effectiveClass = getEffectiveResultClass();
query = buildJPAQuery(transformedQueryString, effectiveClass);
if (fetchPlan != null) {
MetaClass metaClass = metadata.getClass(fetchPlan.getEntityClass());
if (!metadataTools.isCacheable(metaClass) || !singleResultExpected) {
query.setHint(QueryHints.REFRESH, HintValues.TRUE);
query.setHint(QueryHints.REFRESH_CASCADE, CascadePolicy.CascadeByMapping);
}
}
}
if (flushMode == null) {
if (fetchPlan != null && !fetchPlan.loadPartialEntities()) {
query.setFlushMode(FlushModeType.AUTO);
} else {
query.setFlushMode(FlushModeType.COMMIT);
}
} else {
query.setFlushMode(flushMode);
}
boolean nullParam = false;
for (Param param : params) {
param.apply(query);
if (param.value == null)
nullParam = true;
}
addMacroParams(query);
// disable SQL caching to support "is null" generation
if (nullParam)
query.setHint(QueryHints.PREPARE, HintValues.FALSE);
// nested collections in some cases
if (maxResults != null && !singleResultExpected)
query.setMaxResults(maxResults);
if (firstResult != null && !singleResultExpected)
query.setFirstResult(firstResult);
if (lockMode != null)
query.setLockMode(lockMode);
if (hints != null) {
for (Map.Entry<String, Object> hint : hints.entrySet()) {
hintsProcessor.applyQueryHint(query, hint.getKey(), hint.getValue());
}
}
for (int i = 0; i < fetchPlans.size(); i++) {
if (i == 0)
fetchGroupMgr.setFetchPlan(query, queryString, fetchPlans.get(i), singleResultExpected);
else
fetchGroupMgr.addFetchPlan(query, queryString, fetchPlans.get(i), singleResultExpected);
}
}
return query;
}
use of io.jmix.core.Entity in project jmix by jmix-framework.
the class CubaLinkCellClickListener method accept.
@Override
public void accept(Table.Column.ClickEvent clickEvent) {
if (!clickEvent.isText()) {
return;
}
Table.Column column = (Table.Column) clickEvent.getSource();
Entity rowItem = (Entity) clickEvent.getItem();
if (column.getXmlDescriptor() != null) {
String invokeMethodName = column.getXmlDescriptor().attributeValue("linkInvoke");
if (StringUtils.isNotEmpty(invokeMethodName)) {
callControllerInvoke(rowItem, column.getStringId(), invokeMethodName);
return;
}
}
Entity entity;
Object value = EntityValues.getValueEx(rowItem, column.getStringId());
if (value instanceof Entity) {
entity = (Entity) value;
} else {
entity = rowItem;
}
WindowManager wm;
Window window = (Window) CubaComponentsHelper.getWindowImplementation(table);
if (window == null) {
throw new IllegalStateException("Please specify Frame for Table");
} else {
wm = window.getWindowManager();
}
Messages messages = applicationContext.getBean(Messages.class);
if (entity instanceof SoftDelete && ((SoftDelete) entity).isDeleted()) {
wm.showNotification(messages.getMainMessage("OpenAction.objectIsDeleted"), Frame.NotificationType.HUMANIZED);
return;
}
if (window.getFrameOwner() instanceof LegacyFrame) {
LegacyFrame frameOwner = (LegacyFrame) window.getFrameOwner();
DataSupplier dataSupplier = frameOwner.getDsContext().getDataSupplier();
entity = dataSupplier.reload(entity, View.MINIMAL);
} else {
DataManager dataManager = applicationContext.getBean(DataManager.class);
entity = dataManager.reload(entity, View.MINIMAL);
}
WindowConfig windowConfig = applicationContext.getBean(WindowConfig.class);
String windowAlias = null;
if (column.getXmlDescriptor() != null) {
windowAlias = column.getXmlDescriptor().attributeValue("linkScreen");
}
if (StringUtils.isEmpty(windowAlias)) {
windowAlias = windowConfig.getEditorScreenId(applicationContext.getBean(Metadata.class).getClass(entity));
}
WindowManager.OpenType screenOpenType = WindowManager.OpenType.THIS_TAB;
if (column.getXmlDescriptor() != null) {
String openTypeAttribute = column.getXmlDescriptor().attributeValue("linkScreenOpenType");
if (StringUtils.isNotEmpty(openTypeAttribute)) {
screenOpenType = WindowManager.OpenType.valueOf(openTypeAttribute);
}
}
AbstractEditor editor = (AbstractEditor) wm.openEditor(windowConfig.getWindowInfo(windowAlias), entity, screenOpenType);
editor.addCloseListener(actionId -> {
// move focus to component
table.focus();
if (Window.COMMIT_ACTION_ID.equals(actionId)) {
Entity editorItem = editor.getItem();
handleEditorCommit(editorItem, rowItem, column.getStringId());
}
});
}
use of io.jmix.core.Entity in project jmix by jmix-framework.
the class FilterEditor method init.
@Override
public void init(Map<String, Object> params) {
super.init(params);
if (Boolean.TRUE.equals(useShortConditionForm)) {
setCaption(messages.getMessage("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("conditionsTree");
conditions = paramConditions.createCopy();
refreshConditionsDs();
conditionsTree.expandTree();
MetaProperty property = metadata.getClassNN(FilterEntity.class).getProperty("name");
Map<String, Object> annotations = property.getAnnotations();
Integer maxLength = (Integer) annotations.get("length");
if (maxLength != null) {
filterName.setMaxLength(maxLength);
}
if (!messages.getMessage("filter.adHocFilter").equals(filterEntity.getName())) {
filterName.setValue(filterEntity.getName());
}
availableForAllCb.setValue(filterEntity.getUsername() == null);
defaultCb.setValue(filterEntity.getIsDefault());
applyDefaultCb.setValue(filterEntity.getApplyDefault());
globalDefaultCb.setValue(filterEntity.getGlobalDefault());
if (filterEntity.getUsername() != null) {
globalDefaultCb.setEnabled(false);
}
if (!security.isSpecificPermitted(GLOBAL_FILTER_PERMISSION)) {
availableForAllCb.setVisible(false);
availableForAllLabel.setVisible(false);
globalDefaultCb.setVisible(false);
globalDefaultLabel.setVisible(false);
}
availableForAllCb.addValueChangeListener(e -> {
Boolean isFilterAvailableForAll = e.getValue();
globalDefaultCb.setEnabled(isFilterAvailableForAll);
if (!isFilterAvailableForAll) {
globalDefaultCb.setValue(null);
}
});
boolean manualApplyRequired = filter.getManualApplyRequired() != null ? filter.getManualApplyRequired() : AppBeans.get(CubaProperties.class).isGenericFilterManualApplyRequired();
if (!manualApplyRequired) {
applyDefaultCb.setVisible(manualApplyRequired);
applyDefaultLabel.setVisible(manualApplyRequired);
}
if (!(filter.getFrame().getFrameOwner() instanceof LegacyFrame)) {
ScreenSettingsFacet settingsFacet = UiControllerUtils.getFacet(filter.getFrame(), ScreenSettingsFacet.class);
if (settingsFacet == null) {
defaultCb.setVisible(false);
defaultLabel.setVisible(false);
}
}
if (filterEntity.getFolder() != null) {
availableForAllCb.setVisible(false);
availableForAllLabel.setVisible(false);
globalDefaultCb.setVisible(false);
globalDefaultLabel.setVisible(false);
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);
} 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 io.jmix.core.Entity in project jmix by jmix-framework.
the class ListEditorPopupWindow method createComponentForEntity.
protected Field createComponentForEntity() {
Preconditions.checkNotNullArgument(entityName, messages.getMainMessage("entityNameParamNotDefined"));
MetaClass metaClass = metadata.getClassNN(entityName);
Field<?> componentForEntity;
if (BooleanUtils.isNotTrue(useLookupField)) {
PickerField pickerField = uiComponents.create(PickerField.class);
pickerField.setMetaClass(metaClass);
PickerField.LookupAction lookupAction;
if (!Strings.isNullOrEmpty(entityJoinClause) || !Strings.isNullOrEmpty(entityWhereClause)) {
lookupAction = dynamicAttributesGuiTools.createLookupAction(pickerField, entityJoinClause, entityWhereClause);
pickerField.addAction(lookupAction);
} else {
lookupAction = pickerField.addLookupAction();
if (!Strings.isNullOrEmpty(lookupScreen)) {
lookupAction.setLookupScreen(lookupScreen);
}
}
componentForEntity = pickerField;
lookupAction.setAfterLookupSelectionHandler(items -> {
if (items != null && items.size() > 0) {
for (Object item : items) {
if (item != null && !valueExists(item)) {
this.addValueToLayout(item, ListEditorHelper.getValueCaption(item, itemType, timeZone));
}
}
}
componentForEntity.setValue(null);
});
} else {
LookupField lookupField = uiComponents.create(LookupField.class);
CollectionDatasource optionsDs;
if (!Strings.isNullOrEmpty(entityJoinClause) || !Strings.isNullOrEmpty(entityWhereClause)) {
optionsDs = dynamicAttributesGuiTools.createOptionsDatasourceForLookup(metaClass, entityJoinClause, entityWhereClause);
} else {
optionsDs = DsBuilder.create().setMetaClass(metaClass).setViewName(View.MINIMAL).buildCollectionDatasource();
optionsDs.refresh();
}
lookupField.setOptionsDatasource(optionsDs);
lookupField.setOptionCaptionProvider(optionCaptionProvider);
componentForEntity = lookupField;
componentForEntity.addValueChangeListener(e -> {
Entity selectedEntity = (Entity) e.getValue();
if (selectedEntity != null && !valueExists(selectedEntity)) {
this.addValueToLayout(selectedEntity, ListEditorHelper.getValueCaption(selectedEntity, itemType, timeZone, optionCaptionProvider));
}
componentForEntity.setValue(null);
});
}
return componentForEntity;
}
Aggregations