Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Apr 1, 2020
2 parents 57aa870 + 71c25c8 commit e0254e2
Show file tree
Hide file tree
Showing 33 changed files with 504 additions and 129 deletions.
Expand Up @@ -621,7 +621,7 @@ public static TaskType createSingleRecurrenceTask(String taskName, QName applica

ObjectReferenceType ownerRef = new ObjectReferenceType();
ownerRef.setOid(owner.getOid());
ownerRef.setType(owner.getFocus().COMPLEX_TYPE);
ownerRef.setType(UserType.COMPLEX_TYPE);
task.setOwnerRef(ownerRef);

task.setBinding(TaskBindingType.LOOSE);
Expand Down Expand Up @@ -1116,7 +1116,11 @@ public static String getTranslatedPolyString(PolyString value, LocalizationServi
if (localizationService == null){
localizationService = MidPointApplication.get().getLocalizationService();
}
return localizationService.translate(value, getCurrentLocale(), true);
String translatedValue = localizationService.translate(value, getCurrentLocale(), true);
if (StringUtils.isNotEmpty(translatedValue)){
return translatedValue;
}
return value.getOrig();
}

public static <O extends ObjectType> String getName(ObjectReferenceType ref, PageBase pageBase, String operation) {
Expand Down
Expand Up @@ -11,6 +11,7 @@
import java.util.*;

import com.evolveum.midpoint.prism.PrismReferenceValue;
import com.evolveum.midpoint.schema.ObjectDeltaOperation;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
Expand Down Expand Up @@ -184,15 +185,18 @@ public static <O extends ObjectType> List<ObjectReferenceType> createObjectRefer
return null;
}

public static String runTask(TaskType taskToRun, Task operationalTask, OperationResult parentResult, PageBase pageBase){
public static <O extends ObjectType> String runTask(TaskType taskToRun, Task operationalTask, OperationResult parentResult, PageBase pageBase){
try {
ObjectDelta<TaskType> delta = DeltaFactory.Object.createAddDelta(taskToRun.asPrismObject());
pageBase.getPrismContext().adopt(delta);
pageBase.getModelService().executeChanges(MiscUtil.createCollection(delta), null,
Collection<ObjectDeltaOperation<?>> deltaOperationRes = pageBase.getModelService().executeChanges(MiscUtil.createCollection(delta), null,
operationalTask, parentResult);
if (StringUtils.isEmpty(delta.getOid()) && deltaOperationRes != null && !deltaOperationRes.isEmpty()){
ObjectDeltaOperation deltaOperation = deltaOperationRes.iterator().next();
delta.setOid(deltaOperation.getObjectDelta().getOid());
}
parentResult.recordInProgress();
parentResult.setBackgroundTaskOid(delta.getOid());
pageBase.showResult(parentResult);
return delta.getOid();
} catch (ObjectAlreadyExistsException | ObjectNotFoundException | SchemaException
| ExpressionEvaluationException | CommunicationException | ConfigurationException
Expand Down
Expand Up @@ -20,7 +20,9 @@ <h3><div wicket:id="repositoryQueryLabel"/></h3>
<div id="objectType" wicket:id="objectType"></div>
</div>
<div class="form-group" wicket:id="distinct" style="margin-bottom: 15px; width:100%"/>
<br/> <!-- couldn't put this into form-group, so leaving it standalone -->
<div class="form-group" style="margin-bottom: 10px">
<div class="col-lg-12" wicket:id="viewButtonPanel" ></div>
</div>
<textarea wicket:id="editorMidPoint" style="margin-bottom: 10px"></textarea>
<div class="form-group" style="margin-top: 10px">
<label for="querySample" class="small"><wicket:message key="PageRepositoryQuery.chooseSample"/></label>
Expand Down
Expand Up @@ -37,6 +37,7 @@
import com.evolveum.midpoint.web.component.AceEditor;
import com.evolveum.midpoint.web.component.AjaxSubmitButton;
import com.evolveum.midpoint.web.component.form.CheckFormGroup;
import com.evolveum.midpoint.web.component.input.DataLanguagePanel;
import com.evolveum.midpoint.web.component.input.DropDownChoicePanel;
import com.evolveum.midpoint.web.component.input.QNameChoiceRenderer;
import com.evolveum.midpoint.web.component.search.Search;
Expand Down Expand Up @@ -109,6 +110,7 @@ public class PageRepositoryQuery extends PageAdminConfiguration {
private static final String ID_DISTINCT = "distinct";
private static final String ID_HIBERNATE_PARAMETERS_NOTE = "hibernateParametersNote";
private static final String ID_INCOMPLETE_RESULTS_NOTE = "incompleteResultsNote";
private static final String ID_VIEW_BUTTON_PANEL = "viewButtonPanel";

private static final String SAMPLES_DIR = "query-samples";
private static final List<String> SAMPLES = Arrays.asList(
Expand Down Expand Up @@ -138,8 +140,19 @@ public class PageRepositoryQuery extends PageAdminConfiguration {
private final NonEmptyModel<RepoQueryDto> model = new NonEmptyWrapperModel<>(new Model<>(new RepoQueryDto()));
private final boolean isAdmin;

private String dataLanguage;

enum Action {TRANSLATE_ONLY, EXECUTE_MIDPOINT, EXECUTE_HIBERNATE }

@Override
protected void onInitialize() {
super.onInitialize();
if (dataLanguage == null) {
dataLanguage = determineDataLanguage();
}
initLayout();
}

public PageRepositoryQuery() {
this(null, null);
}
Expand All @@ -156,8 +169,6 @@ public PageRepositoryQuery(QName objectType, String queryText) {
admin = false;
}
isAdmin = admin;

initLayout();
}

private void initLayout() {
Expand Down Expand Up @@ -219,6 +230,25 @@ protected void onUpdate(AjaxRequestTarget target) {
midPointQueryButtonBar.setOutputMarkupId(true);
mainForm.add(midPointQueryButtonBar);

DataLanguagePanel<QueryType> dataLanguagePanel =
new DataLanguagePanel<QueryType>(ID_VIEW_BUTTON_PANEL, dataLanguage, QueryType.class, PageRepositoryQuery.this) {
private static final long serialVersionUID = 1L;

@Override
protected void onLanguageSwitched(AjaxRequestTarget target, int updatedIndex, String updatedLanguage,
String objectString) {
model.getObject().setMidPointQuery(objectString);
dataLanguage = updatedLanguage;
target.add(mainForm);
}
@Override
protected String getObjectStringRepresentation() {
return model.getObject().getMidPointQuery();
}
};
dataLanguagePanel.setOutputMarkupId(true);
mainForm.add(dataLanguagePanel);

AjaxSubmitButton executeMidPoint = new AjaxSubmitButton(ID_EXECUTE_MIDPOINT, createStringResource("PageRepositoryQuery.button.translateAndExecute")) {
@Override
protected void onError(AjaxRequestTarget target) {
Expand Down Expand Up @@ -280,7 +310,20 @@ protected void onUpdate(AjaxRequestTarget target) {
try {
String localTypeName = StringUtils.substringBefore(sampleName, "_");
model.getObject().setObjectType(new QName(SchemaConstants.NS_C, localTypeName));
model.getObject().setMidPointQuery(IOUtils.toString(is, StandardCharsets.UTF_8));
String xml = IOUtils.toString(is, StandardCharsets.UTF_8);
String serialization;
if (PrismContext.LANG_XML.equals(dataLanguage)) {
serialization = xml;
} else {
PrismContext prismContext = getPrismContext();
try {
QueryType parsed = prismContext.parserFor(xml).xml().parseRealValue(QueryType.class);
serialization = prismContext.serializerFor(dataLanguage).serializeRealValue(parsed);
} catch (Throwable t) {
serialization = "Couldn't serialize sample: " + t.getMessage();
}
}
model.getObject().setMidPointQuery(serialization);
model.getObject().setHibernateQuery("");
model.getObject().setHibernateParameters("");
model.getObject().setQueryResultObject(null);
Expand Down Expand Up @@ -506,7 +549,7 @@ private void updateRequestWithMidpointQuery(RepositoryQueryDiagRequest request,
if (clazz == null) {
throw new SchemaException("Couldn't find compile-time class for object type of " + objectType);
}
QueryType queryType = prismContext.parserFor(queryText).xml().parseRealValue(QueryType.class);
QueryType queryType = prismContext.parserFor(queryText).language(dataLanguage).parseRealValue(QueryType.class);
request.setType(clazz);
ObjectQuery objectQuery = prismContext.getQueryConverter().createObjectQuery(clazz, queryType);
ObjectQuery queryWithExprEvaluated = ExpressionUtil.evaluateQueryExpressions(objectQuery, new ExpressionVariables(),
Expand Down
Expand Up @@ -92,15 +92,6 @@ protected void onUpdatePerformed(AjaxRequestTarget target) {
}
}

PrismObjectWrapperFactory<TaskType> wrapperFactory = TaskBasicTabPanel.this.getPageBase().findObjectWrapperFactory(getTask().asPrismObject().getDefinition());
Task task = getPageBase().createSimpleTask(OPERATION_UPDATE_WRAPPER);
OperationResult result = task.getResult();
WrapperContext ctx = new WrapperContext(task, result);
try {
wrapperFactory.updateWrapper(TaskBasicTabPanel.this.getModelObject(), ctx);
} catch (SchemaException e) {
LOGGER.error("Unexpected problem occurs during updating wrapper. Reason: {}", e.getMessage(), e);
}
updateHandlerPerformed(target);

}
Expand Down
Expand Up @@ -22,10 +22,10 @@
<div class="prism-properties">
<div>
<div class="stripe">
<div class="row prism-property">
<div class="row prism-property" style="margin-right: 0px; margin-left: 0px;">
<div class="col-lg-2 col-md-4 col-xs-12 prism-property-label " wicket:id="header"/>
<div class="col-lg-10 col-md-8 col-xs-12 prism-property-value" wicket:id="values">
<div class="row">
<div class="row" style="margin-right: 0px; margin-left: 0px;">
<div class="col-xs-10" wicket:id="valueContainer">
<form wicket:id="form">
<div wicket:id="input"/>
Expand Down
Expand Up @@ -340,21 +340,21 @@ private ModelExecuteOptions createOptions() {
private void onMultiUserRequestPerformed(AjaxRequestTarget target) {
OperationResult result = new OperationResult(OPERATION_REQUEST_ASSIGNMENTS);
Task operationalTask = createSimpleTask(OPERATION_REQUEST_ASSIGNMENTS);

String executionTaskOid = null;
try {
TaskType task = WebComponentUtil.createSingleRecurrenceTask(
createStringResource(OPERATION_REQUEST_ASSIGNMENTS).getString(),
UserType.COMPLEX_TYPE,
getTaskQuery(), prepareDelta(null, result), createOptions(), TaskCategory.EXECUTE_CHANGES, PageAssignmentsList.this);
WebModelServiceUtils.runTask(task, operationalTask, result, PageAssignmentsList.this);
executionTaskOid = WebModelServiceUtils.runTask(task, operationalTask, result, PageAssignmentsList.this);
} catch (SchemaException e) {
result.recordFatalError(result.getOperation(), e);
result.setMessage(createStringResource("PageAssignmentsList.requestError").getString());
LoggingUtils.logUnexpectedException(LOGGER,
"Failed to execute operaton " + result.getOperation(), e);
target.add(getFeedbackPanel());
}
if (hasBackgroundTaskOperation(result)) {
if (hasBackgroundTaskOperation(result) || StringUtils.isNotEmpty(executionTaskOid)) {
result.setMessage(createStringResource("PageAssignmentsList.requestInProgress").getString());
showResult(result);
clearStorage();
Expand Down
Expand Up @@ -42,7 +42,9 @@ public RoleCatalogTabPanel(String id, RoleManagementConfigurationType roleManage

@Override
protected void initLeftSidePanel(){
getRoleCatalogStorage().setSelectedOid(roleCatalogOid);
if (StringUtils.isEmpty(getRoleCatalogStorage().getSelectedOid())) {
getRoleCatalogStorage().setSelectedOid(roleCatalogOid);
}

WebMarkupContainer treePanelContainer = new WebMarkupContainer(ID_TREE_PANEL_CONTAINER);
treePanelContainer.setOutputMarkupId(true);
Expand Down
Expand Up @@ -19,6 +19,8 @@
import com.evolveum.midpoint.util.annotation.Experimental;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;

import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang.StringUtils;

import java.io.Serializable;
Expand Down Expand Up @@ -337,7 +339,20 @@ public String debugDump(int indent) {

@Override
public void shortDump(StringBuilder sb) {
sb.append(orig);
if (MapUtils.isNotEmpty(getLang()) || getTranslation() != null && StringUtils.isNotEmpty(getTranslation().getKey())){
sb.append("orig=" + orig);
} else {
sb.append(orig);
}
if (getTranslation() != null) {
sb.append("; translation.key=" + getTranslation().getKey());
}
if (MapUtils.isNotEmpty(getLang())) {
sb.append("; lang:");
getLang().keySet().forEach(langKey -> {
sb.append(" " + langKey + "=" + getLang().get(langKey) + ",");
});
}
}

public static String getOrig(PolyString s) {
Expand Down
Expand Up @@ -33,6 +33,8 @@
import com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType;
import com.evolveum.prism.xml.ns._public.types_3.RawType;
import com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType;

import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -587,11 +589,15 @@ public String toHumanReadableString() {
// (displaying the aux information in user-visible context). But for e.g. deltas we need this information.
PolyString ps = (PolyString) this.value;
StringBuilder sb = new StringBuilder();
sb.append("orig=" + ps.getOrig());
if (MapUtils.isNotEmpty(ps.getLang()) || ps.getTranslation() != null && StringUtils.isNotEmpty(ps.getTranslation().getKey())){
sb.append("orig=" + ps.getOrig());
} else {
sb.append(ps.getOrig());
}
if (ps.getTranslation() != null) {
sb.append(", translation="+ps.getTranslation().getKey());
sb.append(", translation.key=" + ps.getTranslation().getKey());
}
if (ps.getLang() != null) {
if (MapUtils.isNotEmpty(ps.getLang())) {
sb.append("; lang:");
ps.getLang().keySet().forEach(langKey -> {
sb.append(" " + langKey + "=" + ps.getLang().get(langKey) + ",");
Expand Down
Expand Up @@ -56,25 +56,12 @@ public class CustomFunctions {
private FunctionLibraryType library;
private ExpressionProfile expressionProfile;
private PrismContext prismContext;
/**
* Operation result existing at the initialization time. It is used only if we cannot obtain current operation
* result in any other way.
*/
private OperationResult initializationTimeResult;
/**
* Operation result existing at the initialization time. It is used only if we cannot obtain current operation
* result in any other way.
*/
private Task initializationTimeTask;

public CustomFunctions(FunctionLibraryType library, ExpressionFactory expressionFactory, ExpressionProfile expressionProfile,
OperationResult result, Task task) {
public CustomFunctions(FunctionLibraryType library, ExpressionFactory expressionFactory, ExpressionProfile expressionProfile) {
this.library = library;
this.expressionFactory = expressionFactory;
this.expressionProfile = expressionProfile;
this.prismContext = expressionFactory.getPrismContext();
this.initializationTimeResult = result;
this.initializationTimeTask = task;
}

/**
Expand All @@ -91,22 +78,20 @@ public <V extends PrismValue, D extends ItemDefinition> Object execute(String fu
if (ctx.getTask() != null) {
task = ctx.getTask();
} else {
LOGGER.warn("No task in ScriptExpressionEvaluationContext for the current thread found. Using "
+ "initialization-time task: {}", initializationTimeTask);
task = initializationTimeTask;
// We shouldn't use task of unknown provenience.
throw new IllegalStateException("No task in ScriptExpressionEvaluationContext for the current thread found");
}
if (ctx.getResult() != null) {
result = ctx.getResult();
} else {
LOGGER.warn("No operation result in ScriptExpressionEvaluationContext for the current thread found. Using "
+ "initialization-time op. result");
result = initializationTimeResult;
// Better throwing an exception than introducing memory leak if initialization-time result is used.
// This situation should never occur anyway.
throw new IllegalStateException("No operation result in ScriptExpressionEvaluationContext for the current thread found");
}
} else {
LOGGER.warn("No ScriptExpressionEvaluationContext for current thread found. Using initialization-time task "
+ "and operation result: {}", initializationTimeTask);
task = initializationTimeTask;
result = initializationTimeResult;
// Better throwing an exception than introducing memory leak if initialization-time result is used.
// This situation should never occur anyway.
throw new IllegalStateException("No ScriptExpressionEvaluationContext for current thread found");
}

List<ExpressionType> functions = library.getFunction().stream().filter(expression -> functionName.equals(expression.getName())).collect(Collectors.toList());
Expand Down
Expand Up @@ -181,8 +181,8 @@ public <V extends PrismValue> List<V> evaluate(ScriptExpressionEvaluationContext
context.setTrace(null);
}
context.setResult(result); // a bit of hack: this is to provide some tracing of script evaluation
ScriptExpressionEvaluationContext oldContext = context.setupThreadLocal();
try {
context.setupThreadLocal();

List<V> expressionResult = evaluator.evaluate(context);
if (context.getTrace() != null) {
Expand All @@ -197,7 +197,7 @@ public <V extends PrismValue> List<V> evaluate(ScriptExpressionEvaluationContext
result.recordFatalError(ex.getMessage(), ex);
throw ex;
} finally {
context.cleanupThreadLocal();
context.cleanupThreadLocal(oldContext);
result.computeStatusIfUnknown();
context.setResult(parentResult); // a bit of hack
}
Expand Down

0 comments on commit e0254e2

Please sign in to comment.