use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.
the class CreateAction method isPermitted.
/**
* Check permissions for Action
*/
@Override
protected boolean isPermitted() {
if (target == null || target.getDatasource() == null) {
return false;
}
CollectionDatasource ownerDatasource = target.getDatasource();
MetaClass metaClass = ownerDatasource.getMetaClass();
boolean createPermitted = security.isEntityOpPermitted(metaClass, EntityOp.CREATE);
if (!createPermitted) {
return false;
}
if (ownerDatasource instanceof PropertyDatasource) {
PropertyDatasource propertyDatasource = (PropertyDatasource) ownerDatasource;
MetaClass parentMetaClass = propertyDatasource.getMaster().getMetaClass();
MetaProperty metaProperty = propertyDatasource.getProperty();
boolean attrPermitted = security.isEntityAttrPermitted(parentMetaClass, metaProperty.getName(), EntityAttrAccess.MODIFY);
if (!attrPermitted) {
return false;
}
}
return super.isPermitted();
}
use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.
the class ExcludeAction method doRemove.
@SuppressWarnings("unchecked")
@Override
protected void doRemove(Set<Entity> selected, boolean autocommit) {
CollectionDatasource ds = target.getDatasource();
if (ds instanceof NestedDatasource) {
// Clear reference to master entity
Datasource masterDs = ((NestedDatasource) ds).getMaster();
MetaProperty metaProperty = ((NestedDatasource) ds).getProperty();
if (masterDs != null && metaProperty != null) {
MetaProperty inverseProp = metaProperty.getInverse();
if (inverseProp != null) {
ExtendedEntities extendedEntities = metadata.getExtendedEntities();
Class inversePropClass = extendedEntities.getEffectiveClass(inverseProp.getDomain());
Class dsClass = extendedEntities.getEffectiveClass(ds.getMetaClass());
if (inversePropClass.isAssignableFrom(dsClass)) {
for (Entity item : selected) {
EntityValues.setValue(item, inverseProp.getName(), null);
}
}
}
}
}
for (Entity item : selected) {
ds.modifyItem(item);
ds.excludeItem(item);
}
if (autocommit && (ds.getCommitMode() != Datasource.CommitMode.PARENT)) {
try {
ds.commit();
} catch (RuntimeException e) {
ds.refresh();
throw e;
}
}
}
use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.
the class FilterConditionUtils method formatParamValue.
public static String formatParamValue(Param param, Object value) {
// noinspection unchecked
Datatype datatype = Datatypes.get(param.getJavaClass());
MetaProperty property = param.getProperty();
if (property != null) {
TemporalType tt = (TemporalType) property.getAnnotations().get(MetadataTools.TEMPORAL_ANN_NAME);
if (tt == TemporalType.DATE) {
datatype = Datatypes.getNN(java.sql.Date.class);
}
}
if (datatype != null) {
UserSessionSource userSessionSource = AppBeans.get(UserSessionSource.class);
return datatype.format(value, userSessionSource.getLocale());
}
return value.toString();
}
use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.
the class FilterConditionUtils method getPropertyLocCaption.
public static String getPropertyLocCaption(MetaClass metaClass, String propertyPath) {
MessageTools messageTools = AppBeans.get(MessageTools.class);
MetaPropertyPath mpp = metaClass.getPropertyPath(propertyPath);
if (mpp == null) {
return propertyPath;
} else {
MetadataTools metadataTools = AppBeans.get(MetadataTools.class);
MetaProperty[] metaProperties = mpp.getMetaProperties();
StringBuilder sb = new StringBuilder();
MetaPropertyPath parentMpp = null;
MetaClass tempMetaClass;
for (int i = 0; i < metaProperties.length; i++) {
if (i == 0) {
parentMpp = new MetaPropertyPath(metaClass, metaProperties[i]);
tempMetaClass = metaClass;
} else {
parentMpp = new MetaPropertyPath(parentMpp, metaProperties[i]);
tempMetaClass = metadataTools.getPropertyEnclosingMetaClass(parentMpp);
}
sb.append(messageTools.getPropertyCaption(tempMetaClass, metaProperties[i].getName()));
if (i < metaProperties.length - 1) {
sb.append(".");
}
}
return sb.toString();
}
}
use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.
the class PropertyCondition method updateText.
@Override
protected void updateText() {
Metadata metadata = AppBeans.get(Metadata.class);
MetadataTools metadataTools = metadata.getTools();
String nameToUse = !Strings.isNullOrEmpty(propertiesPath) ? propertiesPath : name;
boolean useCrossDataStoreRefId = false;
boolean stringType = false;
String thisStore = metaClass.getStore().getName();
MetaPropertyPath propertyPath = metaClass.getPropertyPath(name);
if (propertyPath != null) {
MetaProperty metaProperty = propertyPath.getMetaProperty();
String refIdProperty = metadataTools.getCrossDataStoreReferenceIdProperty(thisStore, propertyPath.getMetaProperty());
if (refIdProperty != null) {
useCrossDataStoreRefId = true;
int lastdDot = nameToUse.lastIndexOf('.');
if (lastdDot == -1) {
nameToUse = refIdProperty;
} else {
nameToUse = nameToUse.substring(0, lastdDot + 1) + refIdProperty;
}
}
stringType = String.class.equals(metaProperty.getJavaType());
}
if (operator == Op.DATE_INTERVAL) {
text = dateIntervalConditionToJpql(nameToUse);
return;
}
StringBuilder sb = new StringBuilder();
StringBuilder sbJoin = new StringBuilder();
if (operator == Op.NOT_IN) {
sb.append("((");
}
String path = (metaClass instanceof KeyValueMetaClass && Strings.isNullOrEmpty(propertiesPath)) ? entityAlias : entityAlias + "." + nameToUse;
String joinAlias = nameToUse.replace(".", "_") + RandomStringUtils.randomAlphabetic(5);
if (Param.Type.ENTITY == param.getType() && !useCrossDataStoreRefId) {
String primaryKeyName = metadataTools.getPrimaryKeyName(metadata.getClassNN(param.getJavaClass()));
if (operator == Op.NOT_IN) {
sbJoin.append("left join ").append(path).append(" ").append(joinAlias);
sb.append(joinAlias).append(".").append(primaryKeyName);
} else {
sb.append(path).append(".").append(primaryKeyName);
}
} else {
sb.append(path);
}
if (operator != Op.NOT_EMPTY) {
PersistenceManagerClient persistenceManager = AppBeans.get(PersistenceManagerClient.class);
if (operator == Op.EQUAL && stringType) /*&& persistenceManager.emulateEqualsByLike(thisStore)*/
{
sb.append(" ").append(Op.CONTAINS.forJpql());
} else if (operator == Op.NOT_EQUAL && stringType) /*&& persistenceManager.emulateEqualsByLike(thisStore)*/
{
sb.append(" ").append(Op.DOES_NOT_CONTAIN.forJpql());
} else {
sb.append(" ").append(operator.forJpql());
}
}
if (!operator.isUnary()) {
sb.append(" :").append(param.getName());
if (operator == Op.ENDS_WITH || operator == Op.STARTS_WITH || operator == Op.CONTAINS || operator == Op.DOES_NOT_CONTAIN) {
CubaProperties properties = AppBeans.get(CubaProperties.class);
if (properties.getDisableEscapingLikeForDataStores() == null || !properties.getDisableEscapingLikeForDataStores().contains(thisStore)) {
sb.append(" ESCAPE '").append(QueryUtils.ESCAPE_CHARACTER).append("' ");
}
}
if (operator == Op.NOT_IN) {
if (Param.Type.ENTITY == param.getType() && !useCrossDataStoreRefId) {
String primaryKeyName = metadataTools.getPrimaryKeyName(metadata.getClassNN(param.getJavaClass()));
sb.append(") or (").append(joinAlias).append(".").append(primaryKeyName).append(" is null)) ");
} else {
sb.append(") or (").append(path).append(" is null)) ");
}
}
}
if (operator == Op.NOT_EMPTY) {
sb.append(BooleanUtils.isTrue((Boolean) param.getValue()) ? " is not null" : " is null");
}
text = sb.toString();
join = sbJoin.toString();
}
Aggregations