Search in sources :

Example 96 with MetaProperty

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();
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 97 with MetaProperty

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;
        }
    }
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) PropertyDatasource(com.haulmont.cuba.gui.data.PropertyDatasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) NestedDatasource(com.haulmont.cuba.gui.data.NestedDatasource) ExtendedEntities(io.jmix.core.ExtendedEntities) Entity(io.jmix.core.Entity) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) NestedDatasource(com.haulmont.cuba.gui.data.NestedDatasource) MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 98 with MetaProperty

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();
}
Also used : UserSessionSource(com.haulmont.cuba.core.global.UserSessionSource) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) Datatype(io.jmix.core.metamodel.datatype.Datatype) TemporalType(javax.persistence.TemporalType)

Example 99 with MetaProperty

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();
    }
}
Also used : MessageTools(io.jmix.core.MessageTools) MetadataTools(io.jmix.core.MetadataTools) MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 100 with MetaProperty

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();
}
Also used : MetadataTools(io.jmix.core.MetadataTools) CubaProperties(com.haulmont.cuba.CubaProperties) KeyValueMetaClass(io.jmix.core.impl.keyvalue.KeyValueMetaClass) Metadata(com.haulmont.cuba.core.global.Metadata) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) PersistenceManagerClient(com.haulmont.cuba.client.sys.PersistenceManagerClient) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Aggregations

MetaProperty (io.jmix.core.metamodel.model.MetaProperty)267 MetaClass (io.jmix.core.metamodel.model.MetaClass)162 MetaPropertyPath (io.jmix.core.metamodel.model.MetaPropertyPath)53 Nullable (javax.annotation.Nullable)36 Range (io.jmix.core.metamodel.model.Range)23 Autowired (org.springframework.beans.factory.annotation.Autowired)23 Collectors (java.util.stream.Collectors)22 java.util (java.util)20 Component (org.springframework.stereotype.Component)18 Entity (io.jmix.core.Entity)17 EntityValues (io.jmix.core.entity.EntityValues)17 io.jmix.core (io.jmix.core)16 Logger (org.slf4j.Logger)15 LoggerFactory (org.slf4j.LoggerFactory)15 ArrayList (java.util.ArrayList)12 Collection (java.util.Collection)12 EntityValueSource (io.jmix.ui.component.data.meta.EntityValueSource)10 Metadata (io.jmix.core.Metadata)9 KeyValueMetaClass (io.jmix.core.impl.keyvalue.KeyValueMetaClass)9 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)8