Skip to content

Commit

Permalink
Move Item/PrismValue impl classes to impl dir
Browse files Browse the repository at this point in the history
Looks like these classes need to be referenced directly from the
schema module, though.
  • Loading branch information
mederly committed Dec 4, 2018
1 parent 2b8a8e9 commit 636251b
Show file tree
Hide file tree
Showing 134 changed files with 604 additions and 821 deletions.
Expand Up @@ -107,6 +107,7 @@ public <C extends Containerable> ShadowAssociationWrapper createAssociationWrapp
LOGGER.debug("Association for {} is not supported", association.getComplexTypeDefinition().getTypeClass());
return null;
}
PrismContext prismContext = modelServiceLocator.getPrismContext();
result = new OperationResult(CREATE_ASSOCIATION_WRAPPER);
//we need to switch association wrapper to single value
//the transformation will be as following:
Expand Down Expand Up @@ -142,7 +143,8 @@ public <C extends Containerable> ShadowAssociationWrapper createAssociationWrapp

List<ItemWrapper> associationValuesWrappers = new ArrayList<>();
for (RefinedAssociationDefinition refinedAssocationDefinition: refinedAssociationDefinitions) {
MutablePrismReferenceDefinition shadowRefDef = modelServiceLocator.getPrismContext().definitionFactory().createReferenceDefinition(refinedAssocationDefinition.getName(), ObjectReferenceType.COMPLEX_TYPE);
MutablePrismReferenceDefinition shadowRefDef = prismContext
.definitionFactory().createReferenceDefinition(refinedAssocationDefinition.getName(), ObjectReferenceType.COMPLEX_TYPE);
shadowRefDef.toMutable().setMaxOccurs(-1);
shadowRefDef.setTargetTypeName(ShadowType.COMPLEX_TYPE);
PrismReference shadowAss = shadowRefDef.instantiate();
Expand Down Expand Up @@ -183,15 +185,17 @@ public <C extends Containerable> ShadowAssociationWrapper createAssociationWrapp
itemPath = ShadowType.F_ASSOCIATION;
}

ReferenceWrapper associationValueWrapper = new ReferenceWrapper(shadowValueWrapper, shadowAss, isItemReadOnly(association.getDefinition(), shadowValueWrapper), shadowAss.isEmpty() ? ValueStatus.ADDED : ValueStatus.NOT_CHANGED, itemPath);
ReferenceWrapper associationValueWrapper = new ReferenceWrapper(shadowValueWrapper, shadowAss,
isItemReadOnly(association.getDefinition(), shadowValueWrapper),
shadowAss.isEmpty() ? ValueStatus.ADDED : ValueStatus.NOT_CHANGED, itemPath, prismContext);
String displayName = refinedAssocationDefinition.getDisplayName();
if (displayName == null) {
displayName = refinedAssocationDefinition.getName().getLocalPart();
}
associationValueWrapper.setDisplayName(displayName);

associationValueWrapper.setFilter(WebComponentUtil.createAssociationShadowRefFilter(refinedAssocationDefinition,
modelServiceLocator.getPrismContext(), resource.getOid()));
prismContext, resource.getOid()));

for (ValueWrapper valueWrapper : associationValueWrapper.getValues()) {
valueWrapper.setEditEnabled(isEmpty(valueWrapper));
Expand Down Expand Up @@ -394,23 +398,27 @@ private <T, C extends Containerable> PropertyWrapper<T> createPropertyWrapper(
if (ExpressionType.COMPLEX_TYPE.equals(def.getTypeName())){
if (property == null) {
PrismProperty newProperty = def.instantiate();
return new ExpressionWrapper(cWrapper, newProperty, propertyIsReadOnly, ValueStatus.ADDED, cWrapper.getPath().append(newProperty.getPath()));
return new ExpressionWrapper(cWrapper, newProperty, propertyIsReadOnly, ValueStatus.ADDED, cWrapper.getPath().append(newProperty.getPath()),
modelServiceLocator.getPrismContext());
} else {
return new ExpressionWrapper(cWrapper, property, propertyIsReadOnly, cWrapper.getStatus() == ValueStatus.ADDED ? ValueStatus.ADDED: ValueStatus.NOT_CHANGED, property.getPath());
return new ExpressionWrapper(cWrapper, property, propertyIsReadOnly, cWrapper.getStatus() == ValueStatus.ADDED ? ValueStatus.ADDED: ValueStatus.NOT_CHANGED, property.getPath(),
modelServiceLocator.getPrismContext());
}
}
if (property == null) {
PrismProperty<T> newProperty = def.instantiate();
// We cannot just get path from newProperty.getPath(). The property is not added to the container, so it does not know its path.
// Definitions are reusable, they do not have paths either.
ItemPath propPath = cWrapper.getPath().append(newProperty.getElementName());
return new PropertyWrapper(cWrapper, newProperty, propertyIsReadOnly, ValueStatus.ADDED, propPath);
return new PropertyWrapper(cWrapper, newProperty, propertyIsReadOnly, ValueStatus.ADDED, propPath, modelServiceLocator.getPrismContext());
}
return new PropertyWrapper(cWrapper, property, propertyIsReadOnly, cWrapper.getStatus() == ValueStatus.ADDED ? ValueStatus.ADDED: ValueStatus.NOT_CHANGED, property.getPath());
return new PropertyWrapper(cWrapper, property, propertyIsReadOnly, cWrapper.getStatus() == ValueStatus.ADDED ? ValueStatus.ADDED: ValueStatus.NOT_CHANGED, property.getPath(),
modelServiceLocator.getPrismContext());
}

private <C extends Containerable> ReferenceWrapper createReferenceWrapper(PrismReferenceDefinition def, ContainerValueWrapper<C> cWrapper, boolean onlyEmpty) {


PrismContext prismContext = modelServiceLocator.getPrismContext();
PrismContainerValue<C> containerValue = cWrapper.getContainerValue();

PrismReference reference = containerValue.findReference(def.getName());
Expand All @@ -424,11 +432,11 @@ private <C extends Containerable> ReferenceWrapper createReferenceWrapper(PrismR
if (reference == null) {
PrismReference newReference = def.instantiate();
refWrapper = new ReferenceWrapper(cWrapper, newReference, propertyIsReadOnly,
ValueStatus.ADDED, cWrapper.getPath().append(newReference.getElementName()));
ValueStatus.ADDED, cWrapper.getPath().append(newReference.getElementName()), prismContext);
} else {

refWrapper = new ReferenceWrapper(cWrapper, reference, propertyIsReadOnly,
cWrapper.getStatus() == ValueStatus.ADDED ? ValueStatus.ADDED: ValueStatus.NOT_CHANGED, reference.getPath());
cWrapper.getStatus() == ValueStatus.ADDED ? ValueStatus.ADDED: ValueStatus.NOT_CHANGED, reference.getPath(), prismContext);
}

//TODO: other special cases?
Expand All @@ -439,8 +447,8 @@ private <C extends Containerable> ReferenceWrapper createReferenceWrapper(PrismR
}

if (QNameUtil.match(AbstractRoleType.F_TENANT_REF, def.getName())) {
refWrapper.setFilter(modelServiceLocator.getPrismContext().queryFactory().createEqual(OrgType.F_TENANT, null, null,
modelServiceLocator.getPrismContext(), Boolean.TRUE));
refWrapper.setFilter(prismContext.queryFactory().createEqual(OrgType.F_TENANT, null, null,
prismContext, Boolean.TRUE));
}

return refWrapper;
Expand Down
Expand Up @@ -19,8 +19,9 @@ public class ExpressionWrapper<T> extends PropertyWrapper<T> {
private static final Trace LOGGER = TraceManager.getTrace(ExpressionWrapper.class);
private ConstructionType construction;

public ExpressionWrapper(@Nullable ContainerValueWrapper container, PrismProperty property, boolean readonly, ValueStatus status, ItemPath path) {
super(container, property, readonly, status, path);
public ExpressionWrapper(@Nullable ContainerValueWrapper container, PrismProperty property, boolean readonly,
ValueStatus status, ItemPath path, PrismContext prismContext) {
super(container, property, readonly, status, path, prismContext);

PrismContainer outboundPrismContainer = container.getContainer().getItem();
if (outboundPrismContainer != null) {
Expand Down
Expand Up @@ -1057,6 +1057,7 @@ private void addValue(AjaxRequestTarget target) {
}

private void removeValue(AjaxRequestTarget target) {
PrismContext prismContext = getPrismContext();
ValueWrapper wrapper = getModel().getObject();
PropertyOrReferenceWrapper propertyWrapper = (PropertyOrReferenceWrapper) wrapper.getItem();
LOGGER.debug("Removing value of {}", propertyWrapper);
Expand All @@ -1079,9 +1080,9 @@ private void removeValue(AjaxRequestTarget target) {
int count = countUsableValues(propertyWrapper);
if (count == 0 && !hasEmptyPlaceholder(propertyWrapper)) {
if (inputPanel instanceof ValueChoosePanel) {
values.add(new ValueWrapper(propertyWrapper, new PrismReferenceValueImpl(null), ValueStatus.ADDED));
values.add(new ValueWrapper(propertyWrapper, prismContext.itemFactory().createPrismReferenceValue(), ValueStatus.ADDED, prismContext));
} else {
values.add(new ValueWrapper(propertyWrapper, new PrismPropertyValueImpl(null), ValueStatus.ADDED));
values.add(new ValueWrapper(propertyWrapper, prismContext.itemFactory().createPrismPropertyValue(), ValueStatus.ADDED, prismContext));
}
}
ListView parent = findParent(ListView.class);
Expand Down
Expand Up @@ -62,7 +62,10 @@ public abstract class PropertyOrReferenceWrapper<I extends Item<? extends PrismV
private boolean showEmpty;
private ItemPath path;

public PropertyOrReferenceWrapper(@Nullable ContainerValueWrapper containerValue, I item, boolean readonly, ValueStatus status, ItemPath path) {
protected transient PrismContext prismContext;

public PropertyOrReferenceWrapper(@Nullable ContainerValueWrapper containerValue, I item, boolean readonly,
ValueStatus status, ItemPath path, PrismContext prismContext) {
Validate.notNull(item, "Item must not be null.");
Validate.notNull(status, "Item status must not be null.");

Expand All @@ -71,6 +74,7 @@ public PropertyOrReferenceWrapper(@Nullable ContainerValueWrapper containerValue
this.status = status;
this.readonly = readonly;
this.path = path;
this.prismContext = prismContext;
}

@Override
Expand All @@ -85,6 +89,7 @@ public void revive(PrismContext prismContext) throws SchemaException {
if (getItemDefinition() != null) {
getItemDefinition().revive(prismContext);
}
this.prismContext = prismContext;
}

@Override
Expand Down
Expand Up @@ -39,14 +39,15 @@ public class PropertyWrapper<T> extends PropertyOrReferenceWrapper<PrismProperty
private static final long serialVersionUID = -6347026284758253783L;
private LookupTableType predefinedValues;

public PropertyWrapper(@Nullable ContainerValueWrapper container, PrismProperty<T> property, boolean readonly, ValueStatus status) {
super(container, property, readonly, status, null);
public PropertyWrapper(@Nullable ContainerValueWrapper container, PrismProperty<T> property, boolean readonly, ValueStatus status, PrismContext prismContext) {
super(container, property, readonly, status, null, prismContext);

values = createValues();
}

public PropertyWrapper(@Nullable ContainerValueWrapper container, PrismProperty<T> property, boolean readonly, ValueStatus status, ItemPath path) {
super(container, property, readonly, status, path);
public PropertyWrapper(@Nullable ContainerValueWrapper container, PrismProperty<T> property, boolean readonly,
ValueStatus status, ItemPath path, PrismContext prismContext) {
super(container, property, readonly, status, path, prismContext);

values = createValues();
}
Expand All @@ -56,7 +57,7 @@ private List<ValueWrapper> createValues() {
List<ValueWrapper> values = new ArrayList<>();

for (PrismValue prismValue : item.getValues()) {
values.add(new ValueWrapper<T>(this, prismValue, ValueStatus.NOT_CHANGED));
values.add(new ValueWrapper<T>(this, prismValue, ValueStatus.NOT_CHANGED, prismContext));
}

int minOccurs = getItemDefinition().getMinOccurs();
Expand All @@ -77,48 +78,17 @@ public ValueWrapper<T> createAddedValue() {

ValueWrapper wrapper;
if (SchemaConstants.T_POLY_STRING_TYPE.equals(definition.getTypeName())) {
wrapper = new ValueWrapper(this, new PrismPropertyValueImpl<>(new PolyString("")),
new PrismPropertyValueImpl<>(new PolyString("")), ValueStatus.ADDED);
// } else if (isUser() && isThisPropertyActivationEnabled()) {
// wrapper = new ValueWrapper(this, new PrismPropertyValue(null),
// new PrismPropertyValue(null), ValueStatus.ADDED);
wrapper = new ValueWrapper(this, prismContext.itemFactory().createPrismPropertyValue(new PolyString("")),
prismContext.itemFactory().createPrismPropertyValue(new PolyString("")), ValueStatus.ADDED,
prismContext);
} else {
wrapper = new ValueWrapper(this, new PrismPropertyValueImpl<>(null), ValueStatus.ADDED);
wrapper = new ValueWrapper(this, prismContext.itemFactory().createPrismPropertyValue(), ValueStatus.ADDED,
prismContext);
}

return wrapper;
}

// private boolean isUser() {
// if (getContainerValue() == null) {
// return false;
// }
// ObjectWrapper wrapper = getContainerValue().getContainer().getObject();
// if (wrapper == null) {
// return false;
// }
// PrismObject object = wrapper.getObject();
//
// return UserType.class.isAssignableFrom(object.getCompileTimeClass());
// }

// private boolean isThisPropertyActivationEnabled() {
// if (!ItemPath.create(UserType.F_ACTIVATION).equivalent(container.getPath())) {
// return false;
// }
//
// if (!ActivationType.F_ADMINISTRATIVE_STATUS.equals(item.getElementName())) {
// return false;
// }
//
//// if (container.getContainer().getObject() == null || ContainerStatus.MODIFYING.equals(container.getContainer().getObject().getStatus())) {
//// //when modifying then we don't want to create "true" value for c:activation/c:enabled, only during add
//// return false;
//// }
//
// return true;
// }

@Override
public String toString() {
StringBuilder builder = new StringBuilder();
Expand Down
Expand Up @@ -15,10 +15,7 @@
*/
package com.evolveum.midpoint.web.component.prism;

import com.evolveum.midpoint.prism.PrismReference;
import com.evolveum.midpoint.prism.PrismReferenceDefinition;
import com.evolveum.midpoint.prism.PrismReferenceValue;
import com.evolveum.midpoint.prism.PrismReferenceValueImpl;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.query.ObjectFilter;
import com.evolveum.midpoint.util.DebugUtil;
Expand All @@ -39,12 +36,13 @@ public class ReferenceWrapper extends PropertyOrReferenceWrapper<PrismReference,

private List<QName> targetTypes;

public ReferenceWrapper(@Nullable ContainerValueWrapper container, PrismReference reference, boolean readonly, ValueStatus status) {
super(container, reference, readonly, status, null);
public ReferenceWrapper(@Nullable ContainerValueWrapper container, PrismReference reference, boolean readonly, ValueStatus status, PrismContext prismContext) {
super(container, reference, readonly, status, null, prismContext);
}

public ReferenceWrapper(@Nullable ContainerValueWrapper container, PrismReference reference, boolean readonly, ValueStatus status, ItemPath path) {
super(container, reference, readonly, status, path);
public ReferenceWrapper(@Nullable ContainerValueWrapper container, PrismReference reference, boolean readonly,
ValueStatus status, ItemPath path, PrismContext prismContext) {
super(container, reference, readonly, status, path, prismContext);
}

public List<ValueWrapper> getValues() {
Expand All @@ -59,7 +57,7 @@ private List<ValueWrapper> createValues() {

for (PrismReferenceValue prismValue : item.getValues()) {

values.add(new ValueWrapper(this, prismValue, ValueStatus.NOT_CHANGED));
values.add(new ValueWrapper(this, prismValue, ValueStatus.NOT_CHANGED, prismContext));
}

int minOccurs = getItemDefinition().getMinOccurs();
Expand All @@ -84,8 +82,8 @@ public List<QName> getTargetTypes() {

@Override
public ValueWrapper createAddedValue() {
PrismReferenceValue prv = new PrismReferenceValueImpl();
return new ValueWrapper(this, prv, ValueStatus.ADDED);
PrismReferenceValue prv = prismContext.itemFactory().createPrismReferenceValue();
return new ValueWrapper(this, prv, ValueStatus.ADDED, prismContext);
}

public ObjectFilter getFilter() {
Expand Down
Expand Up @@ -46,16 +46,17 @@ public class ValueWrapper<T> implements Serializable, DebugDumpable {
private ValueStatus status;
private boolean isEditEnabled = true;

public ValueWrapper(PropertyOrReferenceWrapper property, PrismValue value) {
this(property, value, ValueStatus.NOT_CHANGED);
public ValueWrapper(PropertyOrReferenceWrapper property, PrismValue value, PrismContext prismContext) {
this(property, value, ValueStatus.NOT_CHANGED, prismContext);
}

public ValueWrapper(PropertyOrReferenceWrapper propertyWrapper, PrismValue prismValue, ValueStatus status) {
this(propertyWrapper, prismValue, null, status);
public ValueWrapper(PropertyOrReferenceWrapper propertyWrapper, PrismValue prismValue, ValueStatus status,
PrismContext prismContext) {
this(propertyWrapper, prismValue, null, status, prismContext);
}

public ValueWrapper(PropertyOrReferenceWrapper propertyWrapper, PrismValue value, PrismValue oldValue,
ValueStatus status) {
ValueStatus status, PrismContext prismContext) {
Validate.notNull(propertyWrapper, "Property wrapper must not be null.");
Validate.notNull(value, "Property value must not be null.");

Expand All @@ -68,7 +69,7 @@ public ValueWrapper(PropertyOrReferenceWrapper propertyWrapper, PrismValue value
T val = ((PrismPropertyValue<T>) value).getValue();
if (val instanceof PolyString) {
PolyString poly = (PolyString) val;
this.value = new PrismPropertyValueImpl<>(new PolyString(poly.getOrig(), poly.getNorm()),
this.value = prismContext.itemFactory().createPrismPropertyValue(new PolyString(poly.getOrig(), poly.getNorm()),
value.getOriginType(), value.getOriginObject());
} else if (val instanceof ProtectedStringType) {
this.value = value.clone();
Expand All @@ -86,11 +87,11 @@ public ValueWrapper(PropertyOrReferenceWrapper propertyWrapper, PrismValue value
}

if (oldValue == null && value instanceof PrismPropertyValue && ValueStatus.ADDED == propertyWrapper.getStatus()) {
oldValue = new PrismPropertyValueImpl<>(null);
oldValue = prismContext.itemFactory().createPrismPropertyValue();
}

if (oldValue == null && value instanceof PrismReferenceValue && ValueStatus.ADDED == propertyWrapper.getStatus()) {
oldValue = new PrismReferenceValueImpl();
oldValue = prismContext.itemFactory().createPrismReferenceValue();
}

if (oldValue == null && value instanceof PrismReferenceValue && ValueStatus.ADDED != propertyWrapper.getStatus()) {
Expand All @@ -103,7 +104,7 @@ public ValueWrapper(PropertyOrReferenceWrapper propertyWrapper, PrismValue value
PolyString poly = (PolyString)val;
val = (T) new PolyString(poly.getOrig(), poly.getNorm());
}
oldValue = new PrismPropertyValueImpl<>(CloneUtil.clone(val), this.value.getOriginType(), this.value.getOriginObject());
oldValue = prismContext.itemFactory().createPrismPropertyValue(CloneUtil.clone(val), this.value.getOriginType(), this.value.getOriginObject());
}

this.oldValue = oldValue;
Expand Down

0 comments on commit 636251b

Please sign in to comment.