use of com.haulmont.cuba.CubaProperties in project jmix by jmix-framework.
the class AppFolderEditWindow method create.
public static FolderEditWindow create(boolean isAppFolder, boolean adding, Folder folder, TablePresentations presentations, Runnable commitHandler) {
CubaProperties cubaProperties = AppBeans.get(CubaProperties.class);
String className = isAppFolder ? cubaProperties.getAppFolderEditWindowClassName() : cubaProperties.getFolderEditWindowClassName();
if (className != null || !isAppFolder) {
return new FolderEditWindow(adding, folder, presentations, commitHandler);
} else {
return new AppFolderEditWindow(adding, (AppFolder) folder, presentations, commitHandler);
}
}
use of com.haulmont.cuba.CubaProperties 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();
}
use of com.haulmont.cuba.CubaProperties in project jmix by jmix-framework.
the class ParamWrapper method getValue.
@Override
public Object getValue() {
Object value = param.getValue();
if (value instanceof String && !StringUtils.isEmpty((String) value) && !((String) value).startsWith(ParametersHelper.CASE_INSENSITIVE_MARKER)) {
// try to wrap value for case-insensitive "like" search
if (condition instanceof PropertyCondition || condition instanceof DynamicAttributesCondition) {
String escapedValue = value.toString();
if (condition.getEntityMetaClass() != null) {
String thisStore = condition.getEntityMetaClass().getStore().getName();
CubaProperties properties = AppBeans.get(CubaProperties.class);
if (properties.getDisableEscapingLikeForDataStores() == null || !properties.getDisableEscapingLikeForDataStores().contains(thisStore)) {
escapedValue = QueryUtils.escapeForLike(escapedValue);
}
} else {
escapedValue = QueryUtils.escapeForLike(escapedValue);
}
Op op = condition.getOperator();
if (Op.CONTAINS.equals(op) || op.equals(Op.DOES_NOT_CONTAIN)) {
value = wrapValueForLike(escapedValue);
} else if (Op.STARTS_WITH.equals(op)) {
value = wrapValueForLike(escapedValue, false, true);
} else if (Op.ENDS_WITH.equals(op)) {
value = wrapValueForLike(escapedValue, true, false);
}
} else if (condition instanceof CustomCondition) {
String where = ((CustomCondition) condition).getWhere();
Op op = condition.getOperator();
Matcher matcher = LIKE_PATTERN.matcher(where);
if (matcher.find()) {
String stringValue = value.toString();
boolean escape = StringUtils.isNotEmpty(matcher.group(3));
if (escape) {
String escapeChar = matcher.group(4);
if (StringUtils.isNotEmpty(escapeChar)) {
stringValue = QueryUtils.escapeForLike(stringValue, escapeChar);
}
}
if (Op.STARTS_WITH.equals(op)) {
value = wrapValueForLike(stringValue, false, true);
} else if (Op.ENDS_WITH.equals(op)) {
value = wrapValueForLike(stringValue, true, false);
} else {
value = wrapValueForLike(stringValue);
}
}
}
} else if (value instanceof Entity) {
value = EntityValues.getId(((Entity) value));
} else if (value instanceof Collection) {
List<Object> list = new ArrayList<>(((Collection) value).size());
for (Object obj : ((Collection) value)) {
list.add(obj instanceof Entity ? EntityValues.getId(((Entity) obj)) : obj);
}
value = list;
} else if (value instanceof EnumClass) {
value = ((EnumClass) value).getId();
}
return value;
}
Aggregations