Skip to content

Commit

Permalink
Merge branch 'master' of x:\midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Apr 14, 2016
2 parents e665a70 + 9557371 commit 94d826d
Show file tree
Hide file tree
Showing 18 changed files with 357 additions and 112 deletions.
Expand Up @@ -671,10 +671,16 @@ public static Locale getCurrentLocale(){
return locale;
}

public static String getLocalizedDate(Date date, String style){
public static String getLocalizedDate(XMLGregorianCalendar date, String style) {
return getLocalizedDate(XmlTypeConverter.toDate(date), style);
}

public static String getLocalizedDate(Date date, String style) {
if (date == null) {
return null;
}
PatternDateConverter converter = new PatternDateConverter(getLocalizedDatePattern(style), true );
return converter.convertToString(date, WebComponentUtil.getCurrentLocale());

}

public static boolean isActivationEnabled(PrismObject object) {
Expand Down
@@ -1,11 +1,10 @@
package com.evolveum.midpoint.web.component;

import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.model.PrismPropertyRealValueFromPrismObjectModel;
import com.evolveum.midpoint.web.model.PrismPropertyRealValueFromContainerableModel;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
import org.apache.wicket.markup.html.WebMarkupContainer;
Expand All @@ -21,7 +20,7 @@
* @author semancik
* @author mederly
*/
public abstract class AbstractSummaryPanel<O extends ObjectType> extends BasePanel<PrismObject<O>> {
public abstract class AbstractSummaryPanel<C extends Containerable> extends BasePanel<C> {

protected static final String ID_BOX = "summaryBox";
protected static final String ID_ICON_BOX = "summaryIconBox";
Expand All @@ -45,7 +44,7 @@ public abstract class AbstractSummaryPanel<O extends ObjectType> extends BasePan
protected WebMarkupContainer tagBox;
protected WebMarkupContainer iconBox;

public AbstractSummaryPanel(String id, IModel<PrismObject<O>> model) {
public AbstractSummaryPanel(String id, IModel<C> model) {
super(id, model);
}

Expand All @@ -56,10 +55,10 @@ protected void initLayoutCommon() {

box.add(new AttributeModifier("class", BOX_CSS_CLASS + " " + getBoxAdditionalCssClass()));

box.add(new Label(ID_DISPLAY_NAME, new PrismPropertyRealValueFromPrismObjectModel<>(getModel(), getDisplayNamePropertyName())));
box.add(new Label(ID_DISPLAY_NAME, new PrismPropertyRealValueFromContainerableModel<>(getModel(), getDisplayNamePropertyName())));

WebMarkupContainer identifierPanel = new WebMarkupContainer(ID_IDENTIFIER_PANEL);
identifierPanel.add(new Label(ID_IDENTIFIER, new PrismPropertyRealValueFromPrismObjectModel<>(getModel(), getIdentifierPropertyName())));
identifierPanel.add(new Label(ID_IDENTIFIER, new PrismPropertyRealValueFromContainerableModel<>(getModel(), getIdentifierPropertyName())));
identifierPanel.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
Expand All @@ -69,15 +68,15 @@ public boolean isVisible() {
box.add(identifierPanel);

if (getTitlePropertyName() != null) {
box.add(new Label(ID_TITLE, new PrismPropertyRealValueFromPrismObjectModel<>(getModel(), getTitlePropertyName())));
box.add(new Label(ID_TITLE, new PrismPropertyRealValueFromContainerableModel<>(getModel(), getTitlePropertyName())));
} else if (getTitleModel() != null) {
box.add(new Label(ID_TITLE, getTitleModel()));
} else {
box.add(new Label(ID_TITLE, " "));
}

if (getTitle2PropertyName() != null) {
box.add(new Label(ID_TITLE2, new PrismPropertyRealValueFromPrismObjectModel<>(getModel(), getTitle2PropertyName())));
box.add(new Label(ID_TITLE2, new PrismPropertyRealValueFromContainerableModel<>(getModel(), getTitle2PropertyName())));
} else if (getTitle2Model() != null) {
box.add(new Label(ID_TITLE2, getTitle2Model()));
} else {
Expand All @@ -87,7 +86,7 @@ public boolean isVisible() {
}

if (getTitle3PropertyName() != null) {
box.add(new Label(ID_TITLE3, new PrismPropertyRealValueFromPrismObjectModel<>(getModel(), getTitle3PropertyName())));
box.add(new Label(ID_TITLE3, new PrismPropertyRealValueFromContainerableModel<>(getModel(), getTitle3PropertyName())));
} else if (getTitle3Model() != null) {
box.add(new Label(ID_TITLE3, getTitle3Model()));
} else {
Expand Down
Expand Up @@ -20,6 +20,7 @@
import com.evolveum.midpoint.web.component.prism.ObjectWrapper;
import com.evolveum.midpoint.web.component.util.SummaryTag;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.model.ContainerableFromPrismObjectModel;
import com.evolveum.midpoint.web.model.ReadOnlyPrismObjectFromObjectWrapperModel;
import com.evolveum.midpoint.web.model.ReadOnlyWrapperModel;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
Expand All @@ -43,7 +44,7 @@ public abstract class FocusSummaryPanel<O extends ObjectType> extends AbstractSu
private IModel<ObjectWrapper<O>> wrapperModel;

public FocusSummaryPanel(String id, final IModel<ObjectWrapper<O>> model) {
super(id, new ReadOnlyPrismObjectFromObjectWrapperModel<O>(model));
super(id, new ContainerableFromPrismObjectModel<O>(new ReadOnlyPrismObjectFromObjectWrapperModel<O>(model)));

this.wrapperModel = model;
initLayoutCommon(); // calls getParentOrgModel that depends on wrapperModel
Expand Down Expand Up @@ -108,7 +109,7 @@ protected IModel<AbstractResource> getPhotoModel() {
@Override
public AbstractResource getObject() {
byte[] jpegPhoto = null;
O object = getModel().getObject().asObjectable();
O object = getModel().getObject();
if (object instanceof FocusType) {
jpegPhoto = ((FocusType) object).getJpegPhoto();
}
Expand Down
Expand Up @@ -16,14 +16,15 @@
package com.evolveum.midpoint.web.component;

import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.web.model.ContainerableFromPrismObjectModel;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import org.apache.wicket.model.IModel;

public abstract class ObjectSummaryPanel <O extends ObjectType> extends AbstractSummaryPanel<O> {
private static final long serialVersionUID = -3755521482914447912L;

public ObjectSummaryPanel(String id, final IModel<PrismObject<O>> model) {
super(id, model);
super(id, new ContainerableFromPrismObjectModel(model));
initLayoutCommon();
}

Expand Down
Expand Up @@ -15,22 +15,21 @@
*/
package com.evolveum.midpoint.web.component.util;

import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.prism.Containerable;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;

/**
* The same as SummaryTag, but based on PrismObject model, not ObjectWrapper one.
* The same as SummaryTag, but based on Containerable model, not ObjectWrapper one.
* TODO fix somehow
*
* @author semancik
* @author mederly
*/
public abstract class SummaryTagSimple<O extends ObjectType> extends Panel {
public abstract class SummaryTagSimple<C extends Containerable> extends Panel {

private static final String ID_TAG_ICON = "summaryTagIcon";
private static final String ID_TAG_LABEL = "summaryTagLabel";
Expand All @@ -41,7 +40,7 @@ public abstract class SummaryTagSimple<O extends ObjectType> extends Panel {
private String color = null;
private boolean hideTag = false;

public SummaryTagSimple(String id, final IModel<PrismObject<O>> model) {
public SummaryTagSimple(String id, final IModel<C> model) {
super(id, model);

Label tagIcon = new Label(ID_TAG_ICON, "");
Expand Down Expand Up @@ -113,13 +112,13 @@ public void setHideTag(boolean hideTag) {
this.hideTag = hideTag;
}

protected abstract void initialize(PrismObject<O> object);
protected abstract void initialize(C object);

abstract class SummaryTagModel<T> extends AbstractReadOnlyModel<T> {

IModel<PrismObject<O>> objectModel;
IModel<C> objectModel;

public SummaryTagModel(IModel<PrismObject<O>> objectModel) {
public SummaryTagModel(IModel<C> objectModel) {
this.objectModel = objectModel;
}

Expand Down
Expand Up @@ -40,10 +40,12 @@
import com.evolveum.midpoint.web.component.form.TextFormGroup;
import com.evolveum.midpoint.web.component.wizard.WizardStep;
import com.evolveum.midpoint.web.component.wizard.resource.dto.ConnectorHostTypeComparator;
import com.evolveum.midpoint.web.model.PrismPropertyRealValueFromObjectWrapperModel;
import com.evolveum.midpoint.web.model.PrismPropertyRealValueFromPrismObjectModel;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import com.evolveum.midpoint.web.model.ContainerableFromPrismObjectModel;
import com.evolveum.midpoint.web.model.PrismPropertyRealValueFromContainerableModel;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorHostType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import org.apache.commons.lang.StringUtils;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
Expand Down Expand Up @@ -103,13 +105,14 @@ protected List<PrismObject<ConnectorHostType>> load() {
}

private void initLayout() {
IModel<ResourceType> resourceContainerableModel = new ContainerableFromPrismObjectModel<>(resourceModel);
TextFormGroup name = new TextFormGroup(ID_NAME,
new PrismPropertyRealValueFromPrismObjectModel<String,ResourceType>(resourceModel, UserType.F_NAME),
new PrismPropertyRealValueFromContainerableModel<String, ResourceType>(resourceContainerableModel, UserType.F_NAME),
createStringResource("NameStep.name"), "col-md-3", "col-md-3", true);
add(name);

TextAreaFormGroup description = new TextAreaFormGroup(ID_DESCRIPTION,
new PrismPropertyRealValueFromPrismObjectModel<String,ResourceType>(resourceModel, UserType.F_DESCRIPTION),
new PrismPropertyRealValueFromContainerableModel<String, ResourceType>(resourceContainerableModel, UserType.F_DESCRIPTION),
createStringResource("NameStep.description"), "col-md-3", "col-md-3");
description.setRows(3);
add(description);
Expand Down
@@ -0,0 +1,34 @@
package com.evolveum.midpoint.web.model;

import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import org.apache.commons.lang3.Validate;
import org.apache.wicket.model.IModel;

/**
* @author mederly
*/
public class ContainerableFromPrismObjectModel<O extends ObjectType> implements IModel<O> {

private IModel<PrismObject<O>> prismObjectModel;

public ContainerableFromPrismObjectModel(IModel<PrismObject<O>> prismObjectModel) {
Validate.notNull(prismObjectModel);
this.prismObjectModel = prismObjectModel;
}

@Override
public O getObject() {
PrismObject<O> object = prismObjectModel.getObject();
return object != null ? object.asObjectable() : null;
}

@Override
public void setObject(O o) {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public void detach() {
}
}
@@ -0,0 +1,110 @@
/*
* Copyright (c) 2010-2016 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.web.model;

import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.util.exception.SchemaException;
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.ObjectType;
import org.apache.commons.lang.Validate;
import org.apache.wicket.RestartResponseException;
import org.apache.wicket.model.IModel;

import javax.xml.namespace.QName;

/**
* Model that returns property real values. This implementation works on containerable models (not wrappers).
*
* Simple implementation, now it can't handle multivalue properties.
*
* @author lazyman
* @author semancik
* @author mederly
*/
public class PrismPropertyRealValueFromContainerableModel<T, C extends Containerable> implements IModel<T> {

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

private IModel<C> model;
private ItemPath path;

public PrismPropertyRealValueFromContainerableModel(IModel<C> model, QName item) {
this(model, new ItemPath(item));
}

public PrismPropertyRealValueFromContainerableModel(IModel<C> model, ItemPath path) {
Validate.notNull(model, "Containerable model must not be null.");
Validate.notNull(path, "Item path must not be null.");

this.model = model;
this.path = path;
}

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

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

@Override
public void setObject(T object) {
try {
C obj = model.getObject();
PrismProperty<T> property = obj.asPrismContainerValue().findOrCreateProperty(path);

if (object != null) {
PrismPropertyDefinition<T> def = property.getDefinition();
if (PolyString.class.equals(def.getTypeClass())) {
object = (T) new PolyString((String) object);
}

property.setValue(new PrismPropertyValue<T>(object, OriginType.USER_ACTION, null));
} else {
PrismContainerValue parent = (PrismContainerValue) property.getParent();
parent.remove(property);
}
} catch (Exception ex) {
LoggingUtils.logException(LOGGER, "Couldn't update prism property model", ex);
}
}

@Override
public void detach() {
}

private T getRealValue(T value) {
if (value instanceof PolyString) {
value = (T) ((PolyString) value).getOrig();
}

return value;
}
}
Expand Up @@ -40,6 +40,7 @@
* @author lazyman
* @author semancik
*/
@Deprecated // use combination of PrismPropertyRealValueFromContainerableModel and ContainerableFromPrismObjectModel instead
public class PrismPropertyRealValueFromPrismObjectModel<T,O extends ObjectType> implements IModel<T> {

private static final Trace LOGGER = TraceManager.getTrace(PrismPropertyRealValueFromPrismObjectModel.class);
Expand Down

0 comments on commit 94d826d

Please sign in to comment.