Skip to content

Commit

Permalink
Merge branch 'feature/node-sticky-tasks'
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Jul 31, 2017
2 parents 26800a2 + 6a8a7ca commit 5a7e264
Show file tree
Hide file tree
Showing 76 changed files with 1,676 additions and 333 deletions.
2 changes: 1 addition & 1 deletion build-system/pom.xml
Expand Up @@ -59,7 +59,7 @@
<junit.version>4.8.2</junit.version>
<opendj.version>2.6.2</opendj.version>
<mockito.version>1.10.8</mockito.version>
<quartz.version>2.2.3</quartz.version>
<quartz.version>2.3.0.e1</quartz.version>
<selenium.version>1.0.1</selenium.version>
<slf4j.version>1.7.12</slf4j.version>
<spring.version>4.2.5.RELEASE</spring.version>
Expand Down
1 change: 1 addition & 0 deletions config/sql/quartz/tables_postgres.sql
Expand Up @@ -41,6 +41,7 @@ CREATE TABLE qrtz_triggers
NEXT_FIRE_TIME BIGINT NULL,
PREV_FIRE_TIME BIGINT NULL,
PRIORITY INTEGER NULL,
REQUIRED_CAP VARCHAR(200) NULL,
TRIGGER_STATE VARCHAR(16) NOT NULL,
TRIGGER_TYPE VARCHAR(8) NOT NULL,
START_TIME BIGINT NOT NULL,
Expand Down
Expand Up @@ -42,6 +42,9 @@ public class ComponentConstants {
public static final QName UI_FOCUS_TAB_ASSIGNMENTS = new QName(NS_COMPONENTS_PREFIX, "focusTabAssignments");
public static final String UI_FOCUS_TAB_ASSIGNMENTS_URL = QNameUtil.qNameToUri(UI_FOCUS_TAB_ASSIGNMENTS);

public static final QName UI_FOCUS_TAB_POLICY_RULES = new QName(NS_COMPONENTS_PREFIX, "focusTabPolicyRules");
public static final String UI_FOCUS_TAB_POLICY_RULES_URL = QNameUtil.qNameToUri(UI_FOCUS_TAB_POLICY_RULES);

public static final QName UI_FOCUS_TAB_TASKS = new QName(NS_COMPONENTS_PREFIX, "focusTabTasks");
public static final String UI_FOCUS_TAB_TASKS_URL = QNameUtil.qNameToUri(UI_FOCUS_TAB_TASKS);

Expand Down
Expand Up @@ -97,8 +97,8 @@ public class GuiStyleConstants {
public static final String CLASS_APPROVAL_OUTCOME_ICON_REJECTED_COLORED = "fa fa-times text-danger";
public static final String CLASS_APPROVAL_OUTCOME_ICON_IN_PROGRESS_COLORED = "fa fa-clock-o text-info";

public static final String CLASS_ICON_EXPAND = "fa fa-plus";
public static final String CLASS_ICON_COLLAPSE = "fa fa-minus";
public static final String CLASS_ICON_EXPAND = "fa fa-chevron-left";
public static final String CLASS_ICON_COLLAPSE = "fa fa-chevron-down";
public static final String CLASS_ICON_SORT_AMOUNT_ASC = "fa fa-sort-amount-asc";
public static final String CLASS_ICON_SORT_ALPHA_ASC = "fa fa-sort-alpha-asc";
public static final String CLASS_ICON_SHOW_EMPTY_FIELDS = "fa fa-square-o";
Expand Down Expand Up @@ -147,5 +147,6 @@ public class GuiStyleConstants {
public static final String CLASS_CIRCLE_FULL = "fa fa-circle";

public static final String CLASS_FILE_TEXT = "fa fa-file-text-o";
public static final String CLASS_POLICY_RULES = "fa fa-balance-scale";

}
Expand Up @@ -38,8 +38,9 @@
* @author semancik
*/
public class BasePanel<T> extends Panel {
private static final long serialVersionUID = 1L;

private IModel<T> model;
private IModel<T> model;

public BasePanel(String id) {
this(id, null);
Expand Down
@@ -1,5 +1,5 @@
<!--
~ Copyright (c) 2010-2014 Evolveum
~ Copyright (c) 2010-2017 Evolveum
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand All @@ -26,8 +26,8 @@
<wicket:message key="OperationResultPanel.showTask"/>
</a>
<div class="box-tools pull-right">
<div wicket:id="showAll" class="btn btn-box-tool fa fa-plus"></div>
<div wicket:id="hideAll" class="btn btn-box-tool fa fa-minus"></div>
<div wicket:id="showAll" class="btn btn-box-tool fa fa-chevron-left"></div>
<div wicket:id="hideAll" class="btn btn-box-tool fa fa-chevron-down"></div>
<div wicket:id="downloadXml" class="btn btn-box-tool fa fa-download"></div>
<div wicket:id="close" data-widget="remove" class="btn btn-box-tool fa fa-times"></div>
</div>
Expand Down
Expand Up @@ -271,6 +271,9 @@ public abstract class PageBase extends WebPage implements ModelServiceLocator {

// No need to store this in the session. Retrieval is cheap.
private transient AdminGuiConfigurationType adminGuiConfiguration;

// No need for this to store in session. It is used only during single init and render.
private transient Task pageTask;

public PageBase(PageParameters parameters) {
super(parameters);
Expand Down Expand Up @@ -500,6 +503,14 @@ public AdminGuiConfigurationType getAdminGuiConfiguration() {
return adminGuiConfiguration;
}

@Override
public Task getPageTask() {
if (pageTask == null) {
pageTask = createSimpleTask(this.getClass().getName());
}
return pageTask;
}

public MidpointFormValidatorRegistry getFormValidatorRegistry() {
return formValidatorRegistry;
}
Expand Down
Expand Up @@ -18,6 +18,7 @@
import com.evolveum.midpoint.model.api.ModelInteractionService;
import com.evolveum.midpoint.model.api.ModelService;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.repo.common.expression.ExpressionFactory;
import com.evolveum.midpoint.security.api.SecurityEnforcer;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AdminGuiConfigurationType;
Expand All @@ -39,10 +40,19 @@ public interface ModelServiceLocator {

Task createSimpleTask(String operationName);

/**
* Returns a task, that is used to retrieve and render the entire content
* of the page. A single task is created to render the whole page, so
* the summary result can be collected in the task result.
*/
Task getPageTask();

PrismContext getPrismContext();

SecurityEnforcer getSecurityEnforcer();

ExpressionFactory getExpressionFactory();

/**
* Returns adminGuiConfiguraiton applicable to currently logged-in user.
* Strictly speaking, this can be retrieved from modelInteractionService.
Expand Down
@@ -0,0 +1,173 @@
/*
* Copyright (c) 2010-2017 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.evolveum.midpoint.gui.impl.model;

import com.evolveum.midpoint.gui.api.util.ModelServiceLocator;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.delta.PrismValueDeltaSetTriple;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.repo.common.expression.Expression;
import com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext;
import com.evolveum.midpoint.repo.common.expression.ExpressionFactory;
import com.evolveum.midpoint.repo.common.expression.ExpressionVariables;
import com.evolveum.midpoint.schema.constants.ExpressionConstants;
import com.evolveum.midpoint.schema.internals.InternalsConfig;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.util.exception.ExpressionEvaluationException;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SystemException;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.page.error.PageError;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.GuiFlexibleLabelType;

import org.apache.commons.lang.Validate;
import org.apache.poi.ss.formula.functions.T;
import org.apache.wicket.RestartResponseException;
import org.apache.wicket.model.IModel;

import java.util.Collection;

import javax.xml.namespace.QName;

/**
* Model that returns string value for a flexible label. The label value defaults to
* the value of a fixed property. But if an expression is specified then the value
* is determined by the expression.
* This implementation works on containerable models (not wrappers).
*
* @author semancik
*/
public class FlexibleLabelModel<C extends Containerable> implements IModel<String> {
private static final long serialVersionUID = 1L;

private static final Trace LOGGER = TraceManager.getTrace(FlexibleLabelModel.class);

private IModel<C> model;
private ItemPath path;
private GuiFlexibleLabelType configuration;
private ModelServiceLocator serviceLocator;

public FlexibleLabelModel(IModel<C> model, QName item, ModelServiceLocator serviceLocator, GuiFlexibleLabelType configuration) {
this(model, new ItemPath(item), serviceLocator, configuration);
}

public FlexibleLabelModel(IModel<C> model, ItemPath path, ModelServiceLocator serviceLocator, GuiFlexibleLabelType configuration) {
Validate.notNull(model, "Containerable model must not be null.");
Validate.notNull(path, "Item path must not be null.");

this.model = model;
this.path = path;
this.configuration = configuration;
this.serviceLocator = serviceLocator;
}

@Override
public String getObject() {
if (configuration == null) {
return getDefaultValue();
} else {
ExpressionType expressionType = configuration.getExpression();
if (expressionType == null) {
return getDefaultValue();
} else {
Task task = serviceLocator.getPageTask();
OperationResult result = task.getResult();
String contextDesc = "flexible label "+path+" expression";
try {
return getExpressionValue(expressionType, contextDesc, task, result);
} catch (SchemaException | ExpressionEvaluationException | ObjectNotFoundException e) {
result.recordFatalError(e);
LoggingUtils.logUnexpectedException(LOGGER, contextDesc, e, path);
if (InternalsConfig.nonCriticalExceptionsAreFatal()) {
throw new SystemException(e.getMessage(), e);
} else {
return "[Expression error]";
}
}
}
}
}

private String getDefaultValue() {
C object = model.getObject();
PrismProperty<?> property;
try {
property = object.asPrismContainerValue().findOrCreateProperty(path);
} catch (SchemaException ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't create property in path {}", ex, path);
//todo show message in page error [lazyman]
throw new RestartResponseException(PageError.class);
}

return getStringRealValue(property != null ? property.getRealValue() : null);
}

private String getExpressionValue(ExpressionType expressionType, String contextDesc, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {

C object = model.getObject();
ExpressionFactory expressionFactory = serviceLocator.getExpressionFactory();
PrismPropertyDefinition<String> outputDefinition = new PrismPropertyDefinitionImpl<>(ExpressionConstants.OUTPUT_ELEMENT_NAME,
DOMUtil.XSD_STRING, object.asPrismContainerValue().getPrismContext());
Expression<PrismPropertyValue<String>,PrismPropertyDefinition<String>> expression = expressionFactory.makeExpression(expressionType, outputDefinition, contextDesc, task, result);
ExpressionVariables variables = new ExpressionVariables();
variables.addVariableDefinition(ExpressionConstants.VAR_OBJECT, object);
addAdditionalExpressionVariables(variables);
ExpressionEvaluationContext context = new ExpressionEvaluationContext(null, variables, contextDesc, task, result);
PrismValueDeltaSetTriple<PrismPropertyValue<String>> outputTriple = expression.evaluate(context);
if (outputTriple == null) {
return "";
}
Collection<PrismPropertyValue<String>> outputValues = outputTriple.getNonNegativeValues();
if (outputValues.isEmpty()) {
return "";
}
if (outputValues.size() > 1) {
throw new SchemaException("Expression "+contextDesc+" produced more than one value");
}
return outputValues.iterator().next().getRealValue();
}

protected void addAdditionalExpressionVariables(ExpressionVariables variables) {
}

@Override
public void setObject(String object) {
throw new UnsupportedOperationException("Model is read-only");
}

@Override
public void detach() {
}

private <T> String getStringRealValue(T value) {
if (value == null) {
return "";
}
if (value instanceof PolyString) {
return ((PolyString) value).getOrig();
}

return value.toString();
}
}

0 comments on commit 5a7e264

Please sign in to comment.