Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Feb 19, 2019
2 parents 39d8dad + 1dd110f commit e6cfb8f
Show file tree
Hide file tree
Showing 27 changed files with 201 additions and 342 deletions.
Expand Up @@ -2556,8 +2556,11 @@ public static boolean isSubscriptionIdCorrect(String subscriptionId){
String expDateStr = subscriptionId.substring(2, 6);
dateFormat = new SimpleDateFormat("MMyy");
Date expDate = dateFormat.parse(expDateStr);
Calendar expireCalendarValue = Calendar.getInstance();
expireCalendarValue.setTime(expDate);
expireCalendarValue.add(Calendar.MONTH, 1);
Date currentDate = new Date(System.currentTimeMillis());
if (expDate.before(currentDate)) {
if (expireCalendarValue.getTime().before(currentDate) || expireCalendarValue.getTime().equals(currentDate)) {
return false;
}
} catch (Exception ex) {
Expand Down Expand Up @@ -3151,6 +3154,16 @@ public static DisplayType createDisplayType(String iconCssClass, String iconColo
return displayType;
}

public static <O extends ObjectType> DisplayType getArchetypePolicyDisplayType(O object, PageBase pageBase) {
if (object != null) {
ArchetypePolicyType archetypePolicy = WebComponentUtil.getArchetypeSpecification(object.asPrismObject(), pageBase);
if (archetypePolicy != null) {
return archetypePolicy.getDisplay();
}
}
return null;
}

public static IModel<String> getIconUrlModel(IconType icon){
if (icon == null || StringUtils.isEmpty(icon.getImageUrl())){
return Model.of();
Expand Down
Expand Up @@ -12,9 +12,8 @@ public class SystemConfigurationSummaryPanel extends ObjectSummaryPanel<SystemCo

private static final long serialVersionUID = 1L;

public SystemConfigurationSummaryPanel(String id, Class type, IModel<PrismObject<SystemConfigurationType>> model, ModelServiceLocator serviceLocator) {
public SystemConfigurationSummaryPanel(String id, Class type, IModel<SystemConfigurationType> model, ModelServiceLocator serviceLocator) {
super(id, type, model, serviceLocator);
initLayoutCommon(serviceLocator);
}

@Override
Expand Down
Expand Up @@ -17,17 +17,16 @@

import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.gui.api.util.ModelServiceLocator;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.impl.model.FlexibleLabelModel;
import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.prism.PrismContainer;
import com.evolveum.midpoint.prism.path.ItemName;
import com.evolveum.midpoint.repo.common.expression.ExpressionVariables;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.GuiFlexibleLabelType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SummaryPanelSpecificationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import org.apache.commons.lang.StringUtils;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
import org.apache.wicket.markup.html.WebMarkupContainer;
Expand Down Expand Up @@ -69,13 +68,15 @@ public abstract class AbstractSummaryPanel<C extends Containerable> extends Base
protected WebMarkupContainer tagBox;
protected WebMarkupContainer iconBox;

public AbstractSummaryPanel(String id, IModel<C> model, ModelServiceLocator serviceLocator, SummaryPanelSpecificationType configuration) {
public AbstractSummaryPanel(String id, IModel<C> model, SummaryPanelSpecificationType configuration) {
super(id, model);
this.configuration = configuration;
setOutputMarkupId(true);
}

protected void initLayoutCommon(ModelServiceLocator serviceLocator) {
@Override
protected void onInitialize() {
super.onInitialize();

box = new WebMarkupContainer(ID_BOX);
add(box);
Expand All @@ -85,13 +86,13 @@ protected void initLayoutCommon(ModelServiceLocator serviceLocator) {
if (getDisplayNameModel() != null) {
box.add(new Label(ID_DISPLAY_NAME, getDisplayNameModel()));
} else if (getDisplayNamePropertyName() != null) {
box.add(new Label(ID_DISPLAY_NAME, createLabelModel(getDisplayNamePropertyName(), SummaryPanelSpecificationType.F_DISPLAY_NAME, serviceLocator)));
box.add(new Label(ID_DISPLAY_NAME, createLabelModel(getDisplayNamePropertyName(), SummaryPanelSpecificationType.F_DISPLAY_NAME)));
} else {
box.add(new Label(ID_DISPLAY_NAME, " "));
}

WebMarkupContainer identifierPanel = new WebMarkupContainer(ID_IDENTIFIER_PANEL);
identifierPanel.add(new Label(ID_IDENTIFIER, createLabelModel(getIdentifierPropertyName(), SummaryPanelSpecificationType.F_IDENTIFIER, serviceLocator)));
identifierPanel.add(new Label(ID_IDENTIFIER, createLabelModel(getIdentifierPropertyName(), SummaryPanelSpecificationType.F_IDENTIFIER)));
identifierPanel.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;

Expand All @@ -105,15 +106,15 @@ public boolean isVisible() {
if (getTitleModel() != null) {
box.add(new Label(ID_TITLE, getTitleModel()));
} else if (getTitlePropertyName() != null) {
box.add(new Label(ID_TITLE, createLabelModel(getTitlePropertyName(), SummaryPanelSpecificationType.F_TITLE_1, serviceLocator)));
box.add(new Label(ID_TITLE, createLabelModel(getTitlePropertyName(), SummaryPanelSpecificationType.F_TITLE_1)));
} else {
box.add(new Label(ID_TITLE, " "));
}

if (getTitle2Model() != null) {
box.add(new Label(ID_TITLE2, getTitle2Model()));
} else if (getTitle2PropertyName() != null) {
box.add(new Label(ID_TITLE, createLabelModel(getTitle2PropertyName(), SummaryPanelSpecificationType.F_TITLE_2, serviceLocator)));
box.add(new Label(ID_TITLE, createLabelModel(getTitle2PropertyName(), SummaryPanelSpecificationType.F_TITLE_2)));
} else {
Label label = new Label(ID_TITLE2, " ");
label.setVisible(false);
Expand All @@ -123,14 +124,14 @@ public boolean isVisible() {
if (getTitle3Model() != null) {
box.add(new Label(ID_TITLE3, getTitle3Model()));
} else if (getTitle3PropertyName() != null) {
box.add(new Label(ID_TITLE, createLabelModel(getTitle3PropertyName(), SummaryPanelSpecificationType.F_TITLE_3, serviceLocator)));
box.add(new Label(ID_TITLE, createLabelModel(getTitle3PropertyName(), SummaryPanelSpecificationType.F_TITLE_3)));
} else {
Label label = new Label(ID_TITLE3, " ");
label.setVisible(false);
box.add(label);
}

final IModel<String> parentOrgModel = getParentOrgModel(serviceLocator);
final IModel<String> parentOrgModel = getParentOrgModel();
Label parentOrgLabel = new Label(ID_ORGANIZATION, parentOrgModel);
parentOrgLabel.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
Expand All @@ -144,8 +145,12 @@ public boolean isVisible() {
iconBox = new WebMarkupContainer(ID_ICON_BOX);
box.add(iconBox);

if (getIconBoxAdditionalCssClass() != null) {
iconBox.add(new AttributeModifier("class", ICON_BOX_CSS_CLASS + " " + getIconBoxAdditionalCssClass()));
String archetypePolicyAdditionalCssClass = getArchetypePolicyAdditionalCssClass();
String iconAdditionalCssClass = getIconBoxAdditionalCssClass();
if (StringUtils.isNotEmpty(archetypePolicyAdditionalCssClass)){
iconBox.add(AttributeModifier.append("style", "color: " + archetypePolicyAdditionalCssClass + ";"));
} else if (StringUtils.isNotEmpty(iconAdditionalCssClass)) {
iconBox.add(new AttributeModifier("class", ICON_BOX_CSS_CLASS + " " + iconAdditionalCssClass));
}

Label icon = new Label(ID_ICON, "");
Expand Down Expand Up @@ -174,12 +179,12 @@ public boolean isVisible() {
box.add(tagBox);
}

private FlexibleLabelModel<C> createLabelModel(QName modelPropertyName, QName configurationPropertyName, ModelServiceLocator serviceLocator) {
return createFlexibleLabelModel(modelPropertyName, serviceLocator, getLabelConfiguration(configurationPropertyName));
private FlexibleLabelModel<C> createLabelModel(QName modelPropertyName, QName configurationPropertyName) {
return createFlexibleLabelModel(modelPropertyName, getLabelConfiguration(configurationPropertyName));
}

private FlexibleLabelModel<C> createFlexibleLabelModel(QName modelPropertyName, ModelServiceLocator serviceLocator, GuiFlexibleLabelType configuration) {
return new FlexibleLabelModel<C>(getModel(), ItemName.fromQName(modelPropertyName), serviceLocator, configuration) {
private FlexibleLabelModel<C> createFlexibleLabelModel(QName modelPropertyName, GuiFlexibleLabelType configuration) {
return new FlexibleLabelModel<C>(getModel(), ItemName.fromQName(modelPropertyName), getPageBase(), configuration) {
private static final long serialVersionUID = 1L;
@Override
protected void addAdditionalExpressionVariables(ExpressionVariables variables) {
Expand Down Expand Up @@ -217,6 +222,14 @@ public Component getTag(String id) {
return tagBox.get(id);
}

protected String getArchetypePolicyAdditionalCssClass(){
if (getModelObject() instanceof ObjectType){
DisplayType displayType = WebComponentUtil.getArchetypePolicyDisplayType((ObjectType) getModelObject(), getPageBase());
return WebComponentUtil.getIconColor(displayType);
}
return "";
}

protected abstract String getIconCssClass();

protected abstract String getIconBoxAdditionalCssClass();
Expand Down Expand Up @@ -263,10 +276,10 @@ protected boolean isIdentifierVisible() {
return true;
}

protected IModel<String> getParentOrgModel(ModelServiceLocator serviceLocator) {
protected IModel<String> getParentOrgModel() {
GuiFlexibleLabelType config = getLabelConfiguration(SummaryPanelSpecificationType.F_ORGANIZATION);
if (config != null) {
return createFlexibleLabelModel(ObjectType.F_PARENT_ORG_REF, serviceLocator, config);
return createFlexibleLabelModel(ObjectType.F_PARENT_ORG_REF, config);
} else {
return getDefaltParentOrgModel();
}
Expand Down
Expand Up @@ -16,6 +16,7 @@
package com.evolveum.midpoint.web.component;

import com.evolveum.midpoint.gui.api.GuiStyleConstants;
import com.evolveum.midpoint.gui.api.model.ReadOnlyModel;
import com.evolveum.midpoint.gui.api.util.ModelServiceLocator;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.polystring.PolyString;
Expand All @@ -40,6 +41,7 @@
import org.apache.wicket.request.resource.ByteArrayResource;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
Expand All @@ -51,21 +53,25 @@ public abstract class FocusSummaryPanel<O extends ObjectType> extends ObjectSumm

private static final String ID_ACTIVATION_TAG = "activationTag";

private IModel<ObjectWrapper<O>> wrapperModel;
// private IModel<ObjectWrapper<O>> wrapperModel;

public FocusSummaryPanel(String id, Class<O> type, final IModel<ObjectWrapper<O>> model, ModelServiceLocator serviceLocator) {
super(id, type, new ReadOnlyPrismObjectFromObjectWrapperModel<>(model), serviceLocator);
public FocusSummaryPanel(String id, Class<O> type, final IModel<O> model, ModelServiceLocator serviceLocator) {
super(id, type, model, serviceLocator);

this.wrapperModel = model;
initLayoutCommon(serviceLocator); // calls getParentOrgModel that depends on wrapperModel
// this.wrapperModel = model;
}

@Override
protected void onInitialize(){
super.onInitialize();

SummaryTag<O> tagActivation = new SummaryTag<O>(ID_ACTIVATION_TAG, model) {
SummaryTag<O> tagActivation = new SummaryTag<O>(ID_ACTIVATION_TAG, getModel()) {
private static final long serialVersionUID = 1L;

@Override
protected void initialize(ObjectWrapper<O> wrapper) {
protected void initialize(O object) {
ActivationType activation = null;
O object = wrapper.getObject().asObjectable();
// O object = object.asObjectable();
if (object instanceof FocusType) {
activation = ((FocusType)object).getActivation();
}
Expand Down Expand Up @@ -102,34 +108,27 @@ public boolean isVisible() {

@Override
protected IModel<String> getDefaltParentOrgModel() {
return new ReadOnlyWrapperModel<String,O>(wrapperModel) {
private static final long serialVersionUID = 1L;

@Override
public String getObject() {
Collection<PrismObject<OrgType>> parentOrgs = getWrapper().getParentOrgs();
if (parentOrgs.isEmpty()) {
return "";
}
// Kinda hack now .. "functional" orgType always has preference
// this whole thing should be driven by an expression later on
for (PrismObject<OrgType> org: parentOrgs) {
OrgType orgType = org.asObjectable();
if (FocusTypeUtil.determineSubTypes(org).contains("functional")) {
return PolyString.getOrig(orgType.getDisplayName());
}
return new ReadOnlyModel<String>(() -> {
List<OrgType> parentOrgs = FocusSummaryPanel.this.getModel().getObject().getParentOrg();
if (parentOrgs.isEmpty()) {
return "";
}
// Kinda hack now .. "functional" orgType always has preference
// this whole thing should be driven by an expression later on
for (OrgType orgType : parentOrgs) {
if (FocusTypeUtil.determineSubTypes(orgType).contains("functional")) {
return PolyString.getOrig(orgType.getDisplayName());
}
// Just use the first one as a fallback
return PolyString.getOrig(parentOrgs.iterator().next().asObjectable().getDisplayName());
}
};
// Just use the first one as a fallback
return PolyString.getOrig(parentOrgs.iterator().next().getDisplayName());
});
}

@Override
protected void addAdditionalExpressionVariables(ExpressionVariables variables) {
Collection<PrismObject<OrgType>> parentOrgs = wrapperModel.getObject().getParentOrgs();
Collection<OrgType> parentOrgTypes = parentOrgs.stream().map(o -> o.asObjectable()).collect(Collectors.toList());
variables.addVariableDefinition(ExpressionConstants.VAR_ORGS, parentOrgTypes);
List<OrgType> parentOrgs = getModelObject().getParentOrg();
variables.addVariableDefinition(ExpressionConstants.VAR_ORGS, parentOrgs);
}

@Override
Expand Down Expand Up @@ -160,16 +159,16 @@ protected boolean isActivationVisible() {
public static void addSummaryPanel(MarkupContainer parentComponent, PrismObject<FocusType> focus, ObjectWrapper<FocusType> focusWrapper, String id, ModelServiceLocator serviceLocator) {
if (focus.getCompileTimeClass().equals(UserType.class)) {
parentComponent.add(new UserSummaryPanel(id,
new Model<ObjectWrapper<UserType>>((ObjectWrapper) focusWrapper), serviceLocator));
Model.of((UserType)focus.asObjectable()), serviceLocator));
} else if (focus.getCompileTimeClass().equals(RoleType.class)) {
parentComponent.add(new RoleSummaryPanel(id,
new Model<ObjectWrapper<RoleType>>((ObjectWrapper) focusWrapper), serviceLocator));
Model.of((RoleType)focus.asObjectable()), serviceLocator));
} else if (focus.getCompileTimeClass().equals(OrgType.class)) {
parentComponent.add(new OrgSummaryPanel(id,
new Model<ObjectWrapper<OrgType>>((ObjectWrapper) focusWrapper), serviceLocator));
Model.of((OrgType)focus.asObjectable()), serviceLocator));
} else if (focus.getCompileTimeClass().equals(ServiceType.class)) {
parentComponent.add(new ServiceSummaryPanel(id,
new Model<ObjectWrapper<ServiceType>>((ObjectWrapper) focusWrapper), serviceLocator));
Model.of((ServiceType)focus.asObjectable()), serviceLocator));
}
}
}
Expand Up @@ -28,8 +28,8 @@
public abstract class ObjectSummaryPanel<O extends ObjectType> extends AbstractSummaryPanel<O> {
private static final long serialVersionUID = -3755521482914447912L;

public ObjectSummaryPanel(String id, Class<O> type, final IModel<PrismObject<O>> model, ModelServiceLocator serviceLocator) {
super(id, new ContainerableFromPrismObjectModel<>(model), serviceLocator, determineConfig(type, serviceLocator.getCompiledUserProfile()));
public ObjectSummaryPanel(String id, Class<O> type, final IModel<O> model, ModelServiceLocator serviceLocator) {
super(id, model, determineConfig(type, serviceLocator.getCompiledUserProfile()));
}

private static <O extends ObjectType> SummaryPanelSpecificationType determineConfig(Class<O> type, CompiledUserProfile compiledUserProfile) {
Expand Down
Expand Up @@ -121,7 +121,7 @@ public static <O extends ObjectType> IColumn<SelectableBean<O>, String> createIc

@Override
public void populateItem(Item<ICellPopulator<SelectableBean<O>>> cellItem, String componentId, IModel<SelectableBean<O>> rowModel) {
DisplayType displayType = getDisplayTypeForRowObject(rowModel, pageBase);
DisplayType displayType = WebComponentUtil.getArchetypePolicyDisplayType(rowModel.getObject().getValue(), pageBase);
if (displayType != null){
String disabledStyle = "";
if (rowModel.getObject().getValue() instanceof FocusType) {
Expand Down Expand Up @@ -156,17 +156,6 @@ public IModel<String> getDataModel(IModel<SelectableBean<O>> rowModel) {

}

private static <O extends ObjectType> DisplayType getDisplayTypeForRowObject(IModel<SelectableBean<O>> rowModel, PageBase pageBase){
O object = rowModel.getObject().getValue();
if (object != null) {
ArchetypePolicyType archetypePolicy = WebComponentUtil.getArchetypeSpecification(object.asPrismObject(), pageBase);
if (archetypePolicy != null) {
return archetypePolicy.getDisplay();
}
}
return null;
}

private static <T extends ObjectType> String getIconColumnValue(IModel<SelectableBean<T>> rowModel){
T object = rowModel.getObject().getValue();
if (object == null){
Expand Down

0 comments on commit e6cfb8f

Please sign in to comment.