Skip to content

Commit

Permalink
Merge branch 'master' into feature/better-inttest
Browse files Browse the repository at this point in the history
# Conflicts:
#	model/model-test/src/main/java/com/evolveum/midpoint/model/test/AbstractModelIntegrationTest.java
  • Loading branch information
virgo47 committed Mar 2, 2020
2 parents ff1c49b + a2404ff commit d1e94a3
Show file tree
Hide file tree
Showing 33 changed files with 2,471 additions and 1,634 deletions.
Expand Up @@ -647,6 +647,48 @@ public static TaskType createSingleRecurrenceTask(String taskName, QName applica
return task;
}

public static boolean canSuspendTask(TaskType task, PageBase pageBase) {
return pageBase.isAuthorized(ModelAuthorizationAction.SUSPEND_TASK, task.asPrismObject())
&& (isRunnableTask(task) || isRunningTask(task))
&& !isWorkflowTask(task);
}

public static boolean canResumeTask(TaskType task, PageBase pageBase) {
return pageBase.isAuthorized(ModelAuthorizationAction.RESUME_TASK, task.asPrismObject())
&& (isSuspendedTask(task) || (isClosedTask(task) && isRecurringTask(task)))
&& !isWorkflowTask(task);
}

public static boolean canRunNowTask(TaskType task, PageBase pageBase) {
return pageBase.isAuthorized(ModelAuthorizationAction.RUN_TASK_IMMEDIATELY, task.asPrismObject())
&& (isRunnableTask(task) || (isClosedTask(task) && !isRecurringTask(task)))
&& !isWorkflowTask(task);
}

public static boolean isRunnableTask(TaskType task) {
return task != null && TaskExecutionStatusType.RUNNABLE == task.getExecutionStatus();
}

public static boolean isRunningTask(TaskType task) {
return task != null && task.getNodeAsObserved() != null;
}

public static boolean isSuspendedTask(TaskType task) {
return task != null && TaskExecutionStatusType.SUSPENDED == task.getExecutionStatus();
}

public static boolean isClosedTask(TaskType task) {
return task != null && TaskExecutionStatusType.CLOSED == task.getExecutionStatus();
}

public static boolean isRecurringTask(TaskType task) {
return task != null && TaskRecurrenceType.RECURRING == task.getRecurrence();
}

public static boolean isWorkflowTask(TaskType task) {
return task != null && TaskCategory.WORKFLOW.equals(task.getCategory());
}

public static void iterativeExecuteBulkAction(PageBase pageBase, ExecuteScriptType script, Task task, OperationResult result )
throws SchemaException, SecurityViolationException, ObjectNotFoundException, ExpressionEvaluationException,
CommunicationException, ConfigurationException{
Expand Down
Expand Up @@ -59,14 +59,14 @@ public static class EmbeddedTomcat {
private int port;

@Value("${server.servlet.context-path}")
private String servletPath;
private String contextPath;

@Autowired
private SystemObjectCache systemObjectCache;

@Bean
public TomcatServletWebServerFactory tomcatEmbeddedServletContainerFactory() {
MidPointTomcatServletWebServerFactory tomcat = new MidPointTomcatServletWebServerFactory(servletPath, systemObjectCache);
MidPointTomcatServletWebServerFactory tomcat = new MidPointTomcatServletWebServerFactory(contextPath, systemObjectCache);

if(enableAjp) {
Connector ajpConnector = new Connector("AJP/1.3");
Expand Down
Expand Up @@ -41,12 +41,12 @@ public class MidPointTomcatServletWebServerFactory extends TomcatServletWebServe

private int backgroundProcessorDelay;

private String servletPath;
private String contextPath;

private SystemObjectCache systemObjectCache;

public MidPointTomcatServletWebServerFactory(String servletPath, SystemObjectCache systemObjectCache){
this.servletPath = servletPath;
public MidPointTomcatServletWebServerFactory(String contextPath, SystemObjectCache systemObjectCache){
this.contextPath = contextPath;
this.systemObjectCache = systemObjectCache;
}

Expand Down Expand Up @@ -94,9 +94,9 @@ public Response createResponse() {
if (protocolHandler instanceof AbstractAjpProtocol<?>) {
int packetSize = ((AbstractAjpProtocol<?>) protocolHandler).getPacketSize();
return new MidpointResponse(packetSize - org.apache.coyote.ajp.Constants.SEND_HEAD_LEN,
servletPath, systemObjectCache);
contextPath, systemObjectCache);
} else {
return new MidpointResponse(servletPath, systemObjectCache);
return new MidpointResponse(contextPath, systemObjectCache);
}
}
};
Expand Down
Expand Up @@ -28,17 +28,17 @@ public class MidpointResponse extends Response {

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

private String servletPath;
private String contextPath;
private SystemObjectCache systemObjectCache;

public MidpointResponse(String servletPath, SystemObjectCache systemObjectCache) {
this(OutputBuffer.DEFAULT_BUFFER_SIZE, servletPath, systemObjectCache);
}

public MidpointResponse(int outputBufferSize, String servletPath, SystemObjectCache systemObjectCache) {
public MidpointResponse(int outputBufferSize, String contextPath, SystemObjectCache systemObjectCache) {
super(outputBufferSize);

this.servletPath = servletPath;
this.contextPath = contextPath;
this.systemObjectCache = systemObjectCache;
}

Expand All @@ -49,15 +49,17 @@ public void setHeader(String name, String value) {
if (publicUrlPrefix != null && StringUtils.isNotBlank(value)) {
if (value.startsWith(".")) {
value = publicUrlPrefix + value.substring(1);
} else if (StringUtils.isBlank(servletPath)) {
} else if (StringUtils.isBlank(contextPath)) {
if (value.startsWith("/")) {
value = publicUrlPrefix + value;
} else {
String partAfterSchema = value.substring(value.indexOf("://") + 3);
value = publicUrlPrefix + partAfterSchema.substring(partAfterSchema.indexOf("/"));
}
} else if (value.contains(servletPath + "/")) {
value = publicUrlPrefix + value.substring(value.indexOf(servletPath) + servletPath.length());
} else if (value.contains(contextPath + "/")) {
String partAfterHostname = value.substring(value.indexOf("://") + 3);
partAfterHostname = partAfterHostname.substring(partAfterHostname.indexOf("/"));
value = publicUrlPrefix + partAfterHostname.substring(partAfterHostname.indexOf(contextPath) + contextPath.length());
}
}
}
Expand Down
Expand Up @@ -72,7 +72,7 @@ public Component getHeader(String componentId) {
private Component getPanel(String componentId, IModel<T> rowModel,
int numberOfButtons, boolean isHeaderPanel) {
List<InlineMenuItem> filteredMenuItems = new ArrayList<>();
List<InlineMenuItem> cloneMenuItems = cloneColumnMenuActionIfUse(menuItems);
List<InlineMenuItem> cloneMenuItems = cloneColumnMenuActionIfUse(menuItems, rowModel);
for (InlineMenuItem menuItem : (rowModel != null && rowModel.getObject() instanceof InlineMenuable ?
((InlineMenuable)rowModel.getObject()).getMenuItems() : cloneMenuItems)){
if (isHeaderPanel && !menuItem.isHeaderMenuItem()){
Expand All @@ -97,14 +97,14 @@ private Component getPanel(String componentId, IModel<T> rowModel,
List<ButtonInlineMenuItem> buttonMenuItems = new ArrayList<>();
menuItems.forEach(menuItem -> {
if (menuItem instanceof ButtonInlineMenuItem){
if (isHeaderPanel && !menuItem.isHeaderMenuItem()){
if (isHeaderPanel && !menuItem.isHeaderMenuItem() || !menuItem.getVisible().getObject()){
return;
}
buttonMenuItems.add((ButtonInlineMenuItem) menuItem);
}
});

return new MenuMultiButtonPanel<T>(componentId, rowModel, numberOfButtons, Model.ofList(filteredMenuItems)) {
return new MenuMultiButtonPanel<T>(componentId, rowModel, buttonMenuItems.size(), Model.ofList(filteredMenuItems)) {

private static final long serialVersionUID = 1L;

Expand Down Expand Up @@ -247,10 +247,11 @@ private boolean isPanelVisible(boolean isHeaderPanel){
return false;
}

private List<InlineMenuItem> cloneColumnMenuActionIfUse(List<InlineMenuItem> menuItems) {
private List<InlineMenuItem> cloneColumnMenuActionIfUse(List<InlineMenuItem> menuItems, IModel<T> rowModel) {
List<InlineMenuItem> clonedMenuItems = new ArrayList<InlineMenuItem>(menuItems.size());
for (InlineMenuItem item : menuItems) {
if (item.getAction() instanceof ColumnMenuAction) {
((ColumnMenuAction)item.getAction()).setRowModel(rowModel);
InlineMenuItem clonedItem;
ColumnMenuAction clonedAction = new ColumnMenuAction() {

Expand All @@ -273,6 +274,7 @@ public void onError(AjaxRequestTarget target) {
}

};
clonedAction.setRowModel(rowModel);
if (item instanceof ButtonInlineMenuItem) {
clonedItem = new ButtonInlineMenuItem(item.getLabel(), item.isSubmit()) {

Expand Down
Expand Up @@ -2,14 +2,12 @@

import com.evolveum.midpoint.gui.api.GuiStyleConstants;
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.gui.api.prism.ItemWrapper;
import com.evolveum.midpoint.gui.api.prism.PrismContainerWrapper;
import com.evolveum.midpoint.gui.api.prism.PrismObjectWrapper;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.impl.prism.ItemEditabilityHandler;
import com.evolveum.midpoint.gui.impl.prism.ItemPanelSettingsBuilder;
import com.evolveum.midpoint.gui.impl.prism.ItemVisibilityHandler;
import com.evolveum.midpoint.model.api.ModelAuthorizationAction;
import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
Expand Down Expand Up @@ -160,7 +158,7 @@ public void onClick(AjaxRequestTarget target) {
afterOperation(target, result);
}
};
suspend.add(new VisibleBehaviour(this::canSuspend));
suspend.add(new VisibleBehaviour(() -> WebComponentUtil.canSuspendTask(getTask(), PageTask.this)));
suspend.add(AttributeAppender.append("class", "btn-danger"));
repeatingView.add(suspend);

Expand All @@ -173,7 +171,7 @@ public void onClick(AjaxRequestTarget target) {
}
};
resume.add(AttributeAppender.append("class", "btn-primary"));
resume.add(new VisibleBehaviour(this::canResume));
resume.add(new VisibleBehaviour(() -> WebComponentUtil.canResumeTask(getTask(), PageTask.this)));
repeatingView.add(resume);

AjaxButton runNow = new AjaxButton(repeatingView.newChildId(), createStringResource("pageTaskEdit.button.runNow")) {
Expand All @@ -186,7 +184,7 @@ public void onClick(AjaxRequestTarget target) {
}
};
runNow.add(AttributeAppender.append("class", "btn-success"));
runNow.add(new VisibleBehaviour(this::canRunNow));
runNow.add(new VisibleBehaviour(() -> WebComponentUtil.canRunNowTask(getTask(), PageTask.this)));
repeatingView.add(runNow);

AjaxIconButton refreshNow = new AjaxIconButton(repeatingView.newChildId(), new Model<>("fa fa-refresh"), createStringResource("autoRefreshPanel.refreshNow")) {
Expand Down Expand Up @@ -301,65 +299,6 @@ private String createResumePauseButton() {
return "fa fa-play";
}

private boolean canSuspend() {
PrismObject<TaskType> task = getObjectWrapper().getObject();
TaskType taskType = task.asObjectable();
return isAuthorized(ModelAuthorizationAction.SUSPEND_TASK, task)
&& isRunnable(taskType) || isRunning()
&& !isWorkflow(task.asObjectable());
}

private boolean canResume() {
PrismObject<TaskType> task = getObjectWrapper().getObject();
TaskType taskType = task.asObjectable();
return isAuthorized(ModelAuthorizationAction.RESUME_TASK, task)
&& (isSuspended(taskType) || (isClosed(taskType) && isRecurring(taskType)))
&& !isWorkflow(taskType);
}


private boolean canRunNow() {
PrismObject<TaskType> task = getObjectWrapper().getObject();
TaskType taskType = task.asObjectable();
return isAuthorized(ModelAuthorizationAction.RUN_TASK_IMMEDIATELY, task)
&& (isRunnable(taskType) || (isClosed(taskType) && !isRecurring(taskType)))
&& !isWorkflow(taskType);
}

private boolean isRunnable(TaskType task) {
return TaskExecutionStatusType.RUNNABLE == task.getExecutionStatus();
}

private boolean isRunning() {
PrismObject<TaskType> task = getObjectWrapper().getObject();
TaskType taskType = task.asObjectable();
return taskType.getNodeAsObserved() != null;
}

private boolean isNotRunning(){
return !isRunning();
}

private boolean isSuspended(TaskType task) {
return TaskExecutionStatusType.SUSPENDED == task.getExecutionStatus();
}

private boolean isClosed(TaskType task) {
return TaskExecutionStatusType.CLOSED == task.getExecutionStatus();
}

private boolean isRecurring(TaskType task) {
return TaskRecurrenceType.RECURRING == task.getRecurrence();
}

private boolean isWorkflow(TaskType task) {
return TaskCategory.WORKFLOW.equals(task.getCategory());
}

private TaskType getTask(){
return getObjectWrapper().getObject().asObjectable();
}

private IModel<TaskType> createSummaryPanelModel() {
return isEditingFocus() ?

Expand Down Expand Up @@ -533,10 +472,14 @@ private ItemVisibility getBasicTabVisibility(ItemPath path) {
}

private ItemEditabilityHandler getTaskEditabilityHandler(){
ItemEditabilityHandler editableHandler = wrapper -> !isRunning();
ItemEditabilityHandler editableHandler = wrapper -> !WebComponentUtil.isRunningTask(getTask());
return editableHandler;
}

private TaskType getTask(){
return getObjectWrapper().getObject().asObjectable();
}

@Override
protected Class<? extends Page> getRestartResponsePage() {
return PageTasks.class;
Expand Down Expand Up @@ -573,7 +516,7 @@ protected boolean shouldTrigger() {

@Override
public int getRefreshInterval() {
TaskType task = getObjectWrapper().getObject().asObjectable();
TaskType task = getTask();
TaskDtoExecutionStatus exec = TaskDtoExecutionStatus.fromTaskExecutionStatus(task.getExecutionStatus(), task.getNodeAsObserved() != null);
if (exec == null) {
return REFRESH_INTERVAL_IF_CLOSED;
Expand Down Expand Up @@ -613,9 +556,13 @@ public void refresh(AjaxRequestTarget target) {

}

private boolean isNotRunning(){
return !WebComponentUtil.isRunningTask(getTask());
}

public boolean isRefreshEnabled() {
if (refreshEnabled == null) {
return isRunning();
return WebComponentUtil.isRunningTask(getTask());
}

return refreshEnabled;
Expand Down

0 comments on commit d1e94a3

Please sign in to comment.