Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding fix for basic expression field
- Loading branch information
Showing
5 changed files
with
113 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
195 changes: 96 additions & 99 deletions
195
...mpl/factory/ConditionExpressionModel.java → ...int/gui/impl/factory/ExpressionModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,96 @@ | ||
/* | ||
* Copyright (c) 2020 Evolveum and contributors | ||
* | ||
* This work is dual-licensed under the Apache License 2.0 | ||
* and European Union Public License. See LICENSE file for details. | ||
*/ | ||
package com.evolveum.midpoint.gui.impl.factory; | ||
|
||
import com.evolveum.midpoint.web.util.ExpressionUtil; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType; | ||
|
||
import com.evolveum.prism.xml.ns._public.types_3.RawType; | ||
|
||
import org.apache.commons.collections4.CollectionUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.wicket.model.IModel; | ||
|
||
import com.evolveum.midpoint.gui.api.page.PageBase; | ||
import com.evolveum.midpoint.util.exception.SchemaException; | ||
import com.evolveum.midpoint.util.logging.LoggingUtils; | ||
import com.evolveum.midpoint.util.logging.Trace; | ||
import com.evolveum.midpoint.util.logging.TraceManager; | ||
import com.evolveum.prism.xml.ns._public.query_3.SearchFilterType; | ||
|
||
import javax.xml.bind.JAXBElement; | ||
import java.util.List; | ||
|
||
public class ConditionExpressionModel implements IModel<String> { | ||
|
||
private static final Trace LOGGER = TraceManager.getTrace(ConditionExpressionModel.class); | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
private IModel<ExpressionType> baseModel; | ||
private PageBase pageBase; | ||
|
||
public ConditionExpressionModel(IModel<ExpressionType> valueWrapper, PageBase pageBase) { | ||
this.baseModel = valueWrapper; | ||
this.pageBase = pageBase; | ||
} | ||
|
||
@Override | ||
public void detach() { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Override | ||
public String getObject() { | ||
try { | ||
ExpressionType value = baseModel.getObject(); | ||
if (value == null) { | ||
return null; | ||
} | ||
|
||
List<JAXBElement<?>> evaluatros = value.getExpressionEvaluator(); | ||
//should be one | ||
if (CollectionUtils.isEmpty(evaluatros)) { | ||
return null; | ||
} | ||
if (evaluatros.size() > 1) { | ||
LOGGER.warn("More than one evaluator found. getting first of them"); | ||
} | ||
|
||
JAXBElement<?> evaluator = evaluatros.get(0); | ||
if (evaluator == null) { | ||
return null; | ||
} | ||
|
||
return ExpressionUtil.serialize(evaluator, pageBase.getPrismContext()); | ||
|
||
} catch (SchemaException e) { | ||
// TODO handle!!!! | ||
LoggingUtils.logUnexpectedException(LOGGER, "Cannot serialize filter", e); | ||
// getSession().error("Cannot serialize filter"); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public void setObject(String object) { | ||
if (StringUtils.isBlank(object)) { | ||
baseModel.setObject(null); | ||
return; | ||
} | ||
|
||
try { | ||
ExpressionType condition = new ExpressionType(); | ||
ExpressionUtil.parseExpressionEvaluators(object, condition, pageBase.getPrismContext()); | ||
// ExpressionType condition = pageBase.getPrismContext().parserFor(object).parseRealValue(); | ||
baseModel.setObject(condition); | ||
} catch (Exception e) { | ||
// TODO handle!!!! | ||
LoggingUtils.logUnexpectedException(LOGGER, "Cannot parse filter", e); | ||
// getSession().error("Cannot parse filter"); | ||
} | ||
|
||
} | ||
} | ||
/* | ||
* Copyright (c) 2020 Evolveum and contributors | ||
* | ||
* This work is dual-licensed under the Apache License 2.0 | ||
* and European Union Public License. See LICENSE file for details. | ||
*/ | ||
package com.evolveum.midpoint.gui.impl.factory; | ||
|
||
import com.evolveum.midpoint.web.util.ExpressionUtil; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType; | ||
|
||
import org.apache.commons.collections4.CollectionUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.wicket.model.IModel; | ||
|
||
import com.evolveum.midpoint.gui.api.page.PageBase; | ||
import com.evolveum.midpoint.util.exception.SchemaException; | ||
import com.evolveum.midpoint.util.logging.LoggingUtils; | ||
import com.evolveum.midpoint.util.logging.Trace; | ||
import com.evolveum.midpoint.util.logging.TraceManager; | ||
|
||
import javax.xml.bind.JAXBElement; | ||
import java.util.List; | ||
|
||
public class ExpressionModel implements IModel<String> { | ||
|
||
private static final Trace LOGGER = TraceManager.getTrace(ExpressionModel.class); | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
private IModel<ExpressionType> baseModel; | ||
private PageBase pageBase; | ||
|
||
public ExpressionModel(IModel<ExpressionType> valueWrapper, PageBase pageBase) { | ||
this.baseModel = valueWrapper; | ||
this.pageBase = pageBase; | ||
} | ||
|
||
@Override | ||
public void detach() { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Override | ||
public String getObject() { | ||
try { | ||
ExpressionType value = baseModel.getObject(); | ||
if (value == null) { | ||
return null; | ||
} | ||
|
||
List<JAXBElement<?>> evaluatros = value.getExpressionEvaluator(); | ||
//should be one | ||
if (CollectionUtils.isEmpty(evaluatros)) { | ||
return null; | ||
} | ||
if (evaluatros.size() > 1) { | ||
LOGGER.warn("More than one evaluator found. getting first of them"); | ||
} | ||
|
||
JAXBElement<?> evaluator = evaluatros.get(0); | ||
if (evaluator == null) { | ||
return null; | ||
} | ||
|
||
return ExpressionUtil.serialize(evaluator, pageBase.getPrismContext()); | ||
|
||
} catch (SchemaException e) { | ||
// TODO handle!!!! | ||
LoggingUtils.logUnexpectedException(LOGGER, "Cannot serialize filter", e); | ||
// getSession().error("Cannot serialize filter"); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public void setObject(String object) { | ||
if (StringUtils.isBlank(object)) { | ||
baseModel.setObject(null); | ||
return; | ||
} | ||
|
||
try { | ||
ExpressionType condition = new ExpressionType(); | ||
ExpressionUtil.parseExpressionEvaluators(object, condition, pageBase.getPrismContext()); | ||
// ExpressionType condition = pageBase.getPrismContext().parserFor(object).parseRealValue(); | ||
baseModel.setObject(condition); | ||
} catch (Exception e) { | ||
// TODO handle!!!! | ||
LoggingUtils.logUnexpectedException(LOGGER, "Cannot parse filter", e); | ||
// getSession().error("Cannot parse filter"); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters