Skip to content

Commit

Permalink
Merge branch 'master' into feature/schema-cleanup-4
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Sep 2, 2019
2 parents 1449b99 + 8dca396 commit dbc4e54
Show file tree
Hide file tree
Showing 40 changed files with 572 additions and 186 deletions.
Expand Up @@ -211,6 +211,7 @@ public class GuiStyleConstants {
public static final String BLUE_COLOR = "color-blue";

public static final String CLASS_ICON_SIGN_OUT = "fa fa-sign-out";

public static final String CLASS_ICON_CLAIM = "fa fa-paper-plane-o";


}
Expand Up @@ -58,13 +58,6 @@ protected Iterator<String> getChoices(String input) {

}

@Override
protected void onConfigure() {
super.onConfigure();
itemDefinitionAsStringModel.setObject(null);
}


};

input.add(new OnChangeAjaxBehavior() {
Expand Down
Expand Up @@ -7,6 +7,7 @@

import javax.xml.namespace.QName;

import com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnBlurAjaxFormUpdatingBehaviour;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.markup.html.WebMarkupContainer;
Expand Down Expand Up @@ -64,6 +65,16 @@ public ItemPathPanel(String id, ItemPathType itemPath) {

}

@Override
protected void onConfigure(){
super.onConfigure();
if (getModelObject() == null || getModelObject().getItemDef() == null){
ItemPathSegmentPanel itemPathSegmentPanel = getItemPathSegmentPanel();
if (itemPathSegmentPanel != null){
itemPathSegmentPanel.getBaseFormComponent().getDefaultModel().setObject(null);
}
}
}
private void initLayout() {
initItemPathPanel();

Expand All @@ -87,15 +98,7 @@ public boolean isVisible() {

});

ItemPathSegmentPanel itemDefPanel = new ItemPathSegmentPanel(ID_DEFINITION,
new IModel<ItemPathDto>() {

private static final long serialVersionUID = 1L;
public ItemPathDto getObject() {
return ItemPathPanel.this.getModelObject();
}

}) {
ItemPathSegmentPanel itemDefPanel = new ItemPathSegmentPanel(ID_DEFINITION, getModel()) {

private static final long serialVersionUID = 1L;

Expand All @@ -109,6 +112,7 @@ protected void onUpdateAutoCompletePanel(AjaxRequestTarget target) {
ItemPathPanel.this.onUpdate(ItemPathPanel.this.getModelObject());
}
};
itemDefPanel.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
itemDefPanel.setOutputMarkupId(true);
itemPathPanel.add(itemDefPanel);

Expand All @@ -118,7 +122,6 @@ protected void onUpdateAutoCompletePanel(AjaxRequestTarget target) {
@Override
public void onClick(AjaxRequestTarget target) {
refreshItemPathPanel(new ItemPathDto(ItemPathPanel.this.getModelObject()), true, target);

}

};
Expand Down Expand Up @@ -287,4 +290,8 @@ protected void onUpdate(ItemPathDto itemPathDto) {

}

protected ItemPathSegmentPanel getItemPathSegmentPanel(){
return (ItemPathSegmentPanel) get(ID_ITEM_PATH).get(ID_DEFINITION);
}

}
Expand Up @@ -6,6 +6,7 @@

import javax.xml.namespace.QName;

import com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnBlurAjaxFormUpdatingBehaviour;
import org.apache.commons.lang.StringUtils;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
Expand Down Expand Up @@ -85,7 +86,7 @@ protected void onUpdateAutoComplete(AjaxRequestTarget target,
}

};
// itemDefPanel.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
itemDefPanel.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
itemDefPanel.setOutputMarkupId(true);
add(itemDefPanel);
}
Expand Down Expand Up @@ -146,7 +147,7 @@ public boolean validate() {
}

public Component getBaseFormComponent() {
return get(ID_DEFINITION);
return ((AutoCompleteItemDefinitionPanel)get(ID_DEFINITION)).getBaseFormComponent();
}


Expand Down
Expand Up @@ -57,6 +57,7 @@
import com.evolveum.midpoint.prism.util.PolyStringUtils;
import com.evolveum.midpoint.repo.api.CacheDispatcher;
import com.evolveum.midpoint.repo.api.CounterManager;
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.repo.common.ObjectResolver;
import com.evolveum.midpoint.repo.common.expression.Expression;
import com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext;
Expand Down Expand Up @@ -529,6 +530,10 @@ public RelationRegistry getRelationRegistry() {
return getMidpointApplication().getRelationRegistry();
}

public RepositoryService getRepositoryService() {
return getMidpointApplication().getRepositoryService();
}

public ExpressionFactory getExpressionFactory() {
return getMidpointApplication().getExpressionFactory();
}
Expand Down Expand Up @@ -1324,6 +1329,14 @@ public static StringResourceModel createStringResourceStatic(Component component
return new StringResourceModel(resourceKey, component).setModel(new Model<String>())
.setDefaultValue(resourceKey).setParameters(objects);
}

public StringResourceModel createStringResourceDefault(String defaultKey, PolyStringType polystringKey, Object... objects) {
if (polystringKey == null) {
return createStringResource(defaultKey);
} else {
return createStringResource(polystringKey, objects);
}
}

public OpResult showResult(OperationResult result, String errorMessageKey) {
return showResult(result, errorMessageKey, true);
Expand Down Expand Up @@ -1856,6 +1869,7 @@ public String getBubbleLabel() {
addMenuItem(item, "PageAdmin.menu.top.caseWorkItems.listAll", GuiStyleConstants.CLASS_OBJECT_WORK_ITEM_ICON, PageCaseWorkItemsAll.class);
addMenuItem(item, "PageAdmin.menu.top.caseWorkItems.list", PageCaseWorkItemsAllocatedToMe.class);
addMenuItem(item, "PageAdmin.menu.top.workItems.listAttorney", PageAttorneySelection.class);
addMenuItem(item, "PageWorkItemsClaimable.title", PageWorkItemsClaimable.class);

createFocusPageViewMenu(item.getItems(), "PageAdmin.menu.top.caseWorkItems.view", PageCaseWorkItem.class);

Expand Down Expand Up @@ -2282,17 +2296,14 @@ private void addCollectionsMenuItems(List<MenuItem> menu, QName type, Class<? ex
if (objectViews == null) {
return;
}
objectViews.sort(Comparator.comparing(o -> (o.getDisplay() != null && PolyStringUtils.isNotEmpty(o.getDisplay().getPluralLabel())
? createStringResource(o.getDisplay().getPluralLabel()).getString()
: createStringResource("MenuItem.noName").getString() )));
objectViews.sort(Comparator.comparingInt(o -> (ObjectUtils.defaultIfNull(o.getDisplayOrder(), Integer.MAX_VALUE))));
List<MenuItem> collectionMenuItems = new ArrayList<>(objectViews.size());
objectViews.forEach(objectView -> {
CollectionRefSpecificationType collection = objectView.getCollection();
if (collection == null) {
CollectionRefSpecificationType collectionRefSpec = objectView.getCollection();
if (collectionRefSpec == null) {
return;
}

ObjectReferenceType collectionRef = collection.getCollectionRef();
ObjectReferenceType collectionRef = collectionRefSpec.getCollectionRef();
if (collectionRef == null) {
return;
}
Expand All @@ -2313,10 +2324,9 @@ private void addCollectionsMenuItems(List<MenuItem> menu, QName type, Class<? ex
PageParameters pageParameters = new PageParameters();
pageParameters.add(PARAMETER_OBJECT_COLLECTION_NAME, objectView.getViewIdentifier());

MenuItem userViewMenu = new MenuItem(viewDisplayType != null && PolyStringUtils.isNotEmpty(viewDisplayType.getPluralLabel())
? createStringResource(viewDisplayType.getPluralLabel())
: createStringResource("MenuItem.noName"),
WebComponentUtil.getIconCssClass(viewDisplayType), redirectToPage, pageParameters, null){
MenuItem userViewMenu = new MenuItem(
createStringResourceDefault("MenuItem.noName", WebComponentUtil.getCollectionLabel(viewDisplayType, collectionRefSpec, objectType)),
WebComponentUtil.getIconCssClass(viewDisplayType), redirectToPage, pageParameters, null) {
private static final long serialVersionUID = 1L;

@Override
Expand All @@ -2331,9 +2341,17 @@ public boolean isMenuActive(WebPage page) {
return false;
}
};
menu.add(userViewMenu);

userViewMenu.setDisplayOrder(objectView.getDisplayOrder());
collectionMenuItems.add(userViewMenu);
});

// We need to sort after we get all the collections. Only then we have correct collection labels.
// We do not want to determine the labels twice.

// TODO: can this be combined in a single sort?
collectionMenuItems.sort(Comparator.comparing(o -> o.getNameModel().getObject()));
collectionMenuItems.sort(Comparator.comparingInt(o -> ObjectUtils.defaultIfNull(o.getDisplayOrder(), Integer.MAX_VALUE)));
menu.addAll(collectionMenuItems);
}

public PrismObject<UserType> loadUserSelf() {
Expand Down
Expand Up @@ -32,11 +32,7 @@
import com.evolveum.midpoint.gui.impl.prism.PrismContainerValueWrapper;
import com.evolveum.midpoint.gui.impl.prism.PrismPropertyValueWrapper;
import com.evolveum.midpoint.gui.impl.prism.PrismPropertyWrapper;
import com.evolveum.midpoint.model.api.AssignmentObjectRelation;
import com.evolveum.midpoint.model.api.ModelExecuteOptions;
import com.evolveum.midpoint.model.api.ModelInteractionService;
import com.evolveum.midpoint.model.api.ModelPublicConstants;
import com.evolveum.midpoint.model.api.RoleSelectionSpecification;
import com.evolveum.midpoint.model.api.*;
import com.evolveum.midpoint.model.api.authentication.CompiledObjectCollectionView;
import com.evolveum.midpoint.model.api.util.ResourceUtils;
import com.evolveum.midpoint.model.api.visualizer.Scene;
Expand Down Expand Up @@ -2503,6 +2499,32 @@ public static DisplayType getNewObjectDisplayTypeFromCollectionView(CompiledObje
}
return view != null ? view.getDisplay() : null;
}

/**
* Returns name of the collection suitable to be displayed in the menu or other labels.
* E.g. "All tasks", "Active employees".
*/
public static PolyStringType getCollectionLabel(DisplayType viewDisplayType, CollectionRefSpecificationType collectionRefSpec ,ObjectType collectionRefTarget) {
if (viewDisplayType != null) {
PolyStringType viewPluralLabel = viewDisplayType.getPluralLabel();
if (viewPluralLabel != null) {
return viewPluralLabel;
}
PolyStringType viewLabel = viewDisplayType.getLabel();
if (viewLabel != null) {
return viewLabel;
}
}
if (collectionRefTarget != null) {
if (collectionRefTarget instanceof ObjectCollectionType) {
// MID-5709
// TODO: use collectionRefTarget.getDisplay() first - when the schema is updated
}
// TODO: try to use archetype policy?
return collectionRefTarget.getName();
}
return null;
}

public static ItemVisibility checkShadowActivationAndPasswordVisibility(ItemWrapper<?, ?, ?,?> itemWrapper,
ShadowType shadowType) {
Expand Down Expand Up @@ -3606,6 +3628,35 @@ public static void workItemApproveActionPerformed(AjaxRequestTarget target, Case
pageBase.processResult(target, result, false);
}

public static void claimWorkItemActionPerformed(CaseWorkItemType workItemToClaim,
String operation, AjaxRequestTarget target, PageBase pageBase){
Task task = pageBase.createSimpleTask(operation);
OperationResult mainResult = task.getResult();
WorkflowService workflowService = pageBase.getWorkflowService();
OperationResult result = mainResult.createSubresult(operation);
try {
workflowService.claimWorkItem(WorkItemId.of(workItemToClaim), task, result);
result.computeStatusIfUnknown();
} catch (ObjectNotFoundException | SecurityViolationException | RuntimeException | SchemaException |
ObjectAlreadyExistsException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
result.recordPartialError(pageBase.createStringResource("pageWorkItems.message.partialError.claimed").getString(), e);
}
if (mainResult.isUnknown()) {
mainResult.recomputeStatus();
}

if (mainResult.isSuccess()) {
mainResult.recordStatus(OperationResultStatus.SUCCESS,
pageBase.createStringResource("pageWorkItems.message.success.claimed").getString());
}

pageBase.showResult(mainResult);

pageBase.resetWorkItemCountModel();
target.add(pageBase);

}

public static void assumePowerOfAttorneyIfRequested(OperationResult result, PrismObject<UserType> powerDonor, PageBase pageBase) {
if (powerDonor != null) {
WebModelServiceUtils.assumePowerOfAttorney(powerDonor, pageBase.getModelInteractionService(), pageBase.getTaskManager(), result);
Expand Down
Expand Up @@ -17,8 +17,8 @@

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org">
<wicket:panel>
<div wicket:id="localizedValueContainer" class="row prism-property">
<div class="col-md-3" style="padding-left: 0px !important;" wicket:id="localizedValueLabel" />
<div wicket:id="localizedValueContainer" class="row">
<div class="col-md-3" style="padding-left: 0px !important; padding-top: 5px;" wicket:id="localizedValueLabel" />
<div wicket:id="localizedValueWithButton" class="input-group">
<div class="col-lg-11 col-md-11 col-xs-11 pull-left" style="padding: 0px !important;" wicket:id="localizedValue"/>
<div class="col-lg-1 col-md-1 col-xs-1 pull-right" style="padding: 0px !important;">
Expand All @@ -28,8 +28,8 @@
</div>
</div>
</div>
<div wicket:id="originValueContainer" class="row prism-property">
<div class="col-md-3" style="padding-left: 0px !important;" wicket:id="originValueLabel" />
<div wicket:id="originValueContainer" class="row">
<div class="col-md-3" style="padding-left: 0px !important; padding-top: 5px;" wicket:id="originValueLabel" />
<div wicket:id="origValueWithButton" class="input-group">
<div class="col-lg-11 col-md-11 col-xs-11 pull-left" style="padding: 0px !important;" wicket:id="origValue"/>
<div class="col-lg-1 col-md-1 col-xs-1 pull-right" style="padding: 0px !important;">
Expand All @@ -41,7 +41,7 @@
</div>
<div wicket:id="fullDataContainer">
<div class="row prism-property">
<div class="col-md-3" style="padding-left: 0px !important;"><wicket:message key="PolyStringEditorPanel.keyLabel" /></div>
<div class="col-md-3" style="padding-left: 0px !important; padding-top: 5px;"><wicket:message key="PolyStringEditorPanel.keyLabel" /></div>
<div class="col-md-9" style="padding: 0px !important;" wicket:id="keyValue"/>
</div>
<div class="row prism-property">
Expand Down
Expand Up @@ -91,6 +91,7 @@ private void initLayout(){

WebMarkupContainer localizedValueContainer = new WebMarkupContainer(ID_LOCALIZED_VALUE_CONTAINER);
localizedValueContainer.setOutputMarkupId(true);
localizedValueContainer.add(getInputFieldClassAppenderForContainer());
localizedValueContainer.add(new VisibleBehaviour(() -> showFullData || StringUtils.isNotEmpty(localizedValue)));
add(localizedValueContainer);

Expand Down Expand Up @@ -126,6 +127,7 @@ public void onClick(AjaxRequestTarget target) {

WebMarkupContainer originValueContainer = new WebMarkupContainer(ID_ORIGIN_VALUE_CONTAINER);
originValueContainer.setOutputMarkupId(true);
originValueContainer.add(getInputFieldClassAppenderForContainer());
originValueContainer.add(new VisibleBehaviour(() -> showFullData || StringUtils.isEmpty(localizedValue)));
add(originValueContainer);

Expand Down Expand Up @@ -399,6 +401,15 @@ private void showHideLanguagesPerformed(AjaxRequestTarget target){
target.add(PolyStringEditorPanel.this);
}

private AttributeAppender getInputFieldClassAppenderForContainer(){
return AttributeModifier.append("class", new LoadableModel<String>() {
@Override
protected String load() {
return showFullData ? "prism-property" : "";
}
});
}

private AttributeAppender getInputFieldClassAppender(){
return AttributeModifier.append("class", new LoadableModel<String>() {
@Override
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2017 Evolveum
* Copyright (c) 2010-2019 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,6 +38,12 @@ public class BaseMenuItem implements Serializable {
private VisibleEnableBehaviour visibleEnable;
private Class<? extends WebPage>[] aliases;
private String iconClass;
/**
* Optional field that can be used for sorting. Used for some dynamic submenus, such as collections.
* It does not affect the display of menu item in any way. It is just a convenient intermediary place to store
* the order for sorting the items before adding them to menu.
*/
private transient Integer displayOrder;

public BaseMenuItem(IModel<String> name, Class<? extends WebPage> page) {
this(name, "", page, null, null);
Expand Down Expand Up @@ -80,8 +86,16 @@ public VisibleEnableBehaviour getVisibleEnable() {
public String getIconClass() {
return iconClass;
}

public Integer getDisplayOrder() {
return displayOrder;
}

public void setDisplayOrder(Integer displayOrder) {
this.displayOrder = displayOrder;
}

public boolean isMenuActive(WebPage page) {
public boolean isMenuActive(WebPage page) {
if (page == null) {
return false;
}
Expand Down

0 comments on commit dbc4e54

Please sign in to comment.