Skip to content

Commit

Permalink
Refactoring Item, ItemDelta and some other: adding definition to as a…
Browse files Browse the repository at this point in the history
… type parameter. Also fixing parts of refined schema (MID-2285)
  • Loading branch information
semancik committed Apr 7, 2015
1 parent 20f27bd commit 0f0a11f
Show file tree
Hide file tree
Showing 177 changed files with 2,106 additions and 1,721 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2013 Evolveum
* Copyright (c) 2010-2015 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 @@ -27,6 +27,7 @@
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
Expand Down Expand Up @@ -372,10 +373,11 @@ private void discoverConnectorsPerformed(AjaxRequestTarget target) {

private void discoverConnectors(ConnectorHostType host) {
PageBase page = (PageBase) getPage();
OperationResult result = new OperationResult(OPERATION_DISCOVER_CONNECTORS);
Task task = page.createSimpleTask(OPERATION_DISCOVER_CONNECTORS);
OperationResult result = task.getResult();
try {
ModelService model = page.getModelService();
model.discoverConnectors(host, result);
model.discoverConnectors(host, task, result);
} catch (Exception ex) {
LoggingUtils.logException(LOGGER, "Couldn't discover connectors", ex);
} finally {
Expand Down
Expand Up @@ -49,6 +49,7 @@
import com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem;
import com.evolveum.midpoint.web.component.util.LoadableModel;
import com.evolveum.midpoint.web.component.util.SelectableBean;
import com.evolveum.midpoint.web.page.PageBase;
import com.evolveum.midpoint.web.page.admin.configuration.PageDebugView;
import com.evolveum.midpoint.web.page.admin.configuration.component.HeaderMenuAction;
import com.evolveum.midpoint.web.page.admin.resources.component.ContentPanel;
Expand Down Expand Up @@ -592,7 +593,9 @@ private void deleteResourceConfirmedPerformed(AjaxRequestTarget target) {
private void discoveryRemotePerformed(AjaxRequestTarget target) {
target.add(getFeedbackPanel());

OperationResult result = new OperationResult(OPERATION_CONNECTOR_DISCOVERY);
PageBase page = (PageBase) getPage();
Task task = page.createSimpleTask(OPERATION_CONNECTOR_DISCOVERY);
OperationResult result = task.getResult();
List<SelectableBean<ConnectorHostType>> selected = WebMiscUtil.getSelectedData(getConnectorHostTable());
if (selected.isEmpty()) {
warn(getString("pageResources.message.noHostSelected"));
Expand All @@ -602,7 +605,7 @@ private void discoveryRemotePerformed(AjaxRequestTarget target) {
for (SelectableBean<ConnectorHostType> bean : selected) {
ConnectorHostType host = bean.getValue();
try {
getModelService().discoverConnectors(host, result);
getModelService().discoverConnectors(host, task, result);
} catch (Exception ex) {
result.recordFatalError("Fail to discover connectors on host '" + host.getHostname()
+ ":" + host.getPort() + "'", ex);
Expand Down
Expand Up @@ -195,7 +195,7 @@ protected int internalSize() {
}

private AccountContentDto createAccountContentDto(PrismObject<ShadowType> object, OperationResult result)
throws SchemaException, SecurityViolationException {
throws SchemaException, SecurityViolationException, ConfigurationException {

AccountContentDto dto = new AccountContentDto();
dto.setAccountName(WebMiscUtil.getName(object));
Expand Down Expand Up @@ -231,7 +231,7 @@ protected void addInlineMenuToDto(AccountContentDto dto) {
}

private PrismObject<UserType> loadOwner(String accountOid, OperationResult result)
throws SecurityViolationException, SchemaException {
throws SecurityViolationException, SchemaException, ConfigurationException {

Task task = getPage().createSimpleTask(OPERATION_LOAD_OWNER);
try {
Expand Down
Expand Up @@ -926,7 +926,7 @@ private void savePerformed(AjaxRequestTarget target) {
}

private List<ObjectDelta<? extends ObjectType>> prepareChanges(Task updatedTask) {
Collection<ItemDelta<?>> modifications = updatedTask.getPendingModifications();
Collection<? extends ItemDelta<?,?>> modifications = updatedTask.getPendingModifications();
List<ObjectDelta<? extends ObjectType>> retval = new ArrayList<ObjectDelta<? extends ObjectType>>();
retval.add(ObjectDelta.createModifyDelta(updatedTask.getOid(), modifications, TaskType.class, getPrismContext()));
return retval;
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2014 Evolveum
* Copyright (c) 2010-2015 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 @@ -94,10 +94,10 @@ public static <X> Collection<X> getPropertyStaticRealValues(ExpressionType expre
}


public static <V extends PrismValue> Item<V> parseValueElements(Collection<?> valueElements, ItemDefinition outputDefinition,
public static <IV extends PrismValue,ID extends ItemDefinition> Item<IV,ID> parseValueElements(Collection<?> valueElements, ID outputDefinition,
String contextDescription, PrismContext prismContext) throws SchemaException {

Item<V> output = null;
Item<IV,ID> output = null;
XNodeProcessor xnodeProcessor = prismContext.getXnodeProcessor();

for (Object valueElement: valueElements) {
Expand All @@ -120,7 +120,7 @@ public static <V extends PrismValue> Item<V> parseValueElements(Collection<?> va
RawType rawType = (RawType)jaxbElement.getValue();

//Item<V> elementItem = xnodeProcessor.parseItem(rawType.getXnode(), outputDefinition.getName(), outputDefinition);
Item<V> elementItem = rawType.getParsedItem(outputDefinition);
Item<IV,ID> elementItem = rawType.getParsedItem(outputDefinition);
if (output == null) {
output = elementItem;
} else {
Expand All @@ -130,7 +130,7 @@ public static <V extends PrismValue> Item<V> parseValueElements(Collection<?> va
return output;
}

public static <V extends PrismValue> List<JAXBElement<RawType>> serializeValueElements(Item<V> item, String contextDescription) throws SchemaException {
public static <IV extends PrismValue,ID extends ItemDefinition> List<JAXBElement<RawType>> serializeValueElements(Item<IV,ID> item, String contextDescription) throws SchemaException {
if (item == null) {
return null;
}
Expand Down
Expand Up @@ -237,7 +237,7 @@ public void visit(Visitable visitable){
checkEncrypted(pval);
}
};
for (ItemDelta<?> delta: modifications) {
for (ItemDelta<?,?> delta: modifications) {
try {
delta.accept(visitor);
} catch (IllegalStateException e) {
Expand Down
Expand Up @@ -23,6 +23,7 @@

import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismPropertyDefinition;
import com.evolveum.midpoint.prism.delta.ItemDelta;
import com.evolveum.midpoint.prism.delta.PropertyDelta;
import com.evolveum.midpoint.prism.path.ItemPath;
Expand Down Expand Up @@ -349,12 +350,12 @@ public void setDynamic(boolean dynamic) {
}

@Override
public boolean isValidFor(QName elementQName, Class<? extends ItemDefinition> clazz) {
public boolean isValidFor(QName elementQName, Class clazz) {
return isValidFor(elementQName, clazz, false);
}

@Override
public boolean isValidFor(QName elementQName, Class<? extends ItemDefinition> clazz, boolean caseInsensitive) {
public boolean isValidFor(QName elementQName, Class clazz, boolean caseInsensitive) {
return refinedAttributeDefinition.isValidFor(elementQName, clazz, caseInsensitive);
}

Expand Down
Expand Up @@ -311,7 +311,7 @@ public void testApplyAttributeDefinition() throws JAXBException, SchemaException
System.out.println(attributesContainer.debugDump());

// WHEN
attributesContainer.applyDefinition(defaultAccountDefinition.toResourceAttributeContainerDefinition(), true);
attributesContainer.applyDefinition((PrismContainerDefinition)defaultAccountDefinition.toResourceAttributeContainerDefinition(), true);

// THEN
System.out.println("Parsed account:");
Expand Down
Expand Up @@ -217,7 +217,7 @@ public <T extends ItemDefinition> T findItemDefinition(QName name, Class<T> claz
return null;
}

public <T extends ItemDefinition> T findItemDefinition(ItemPath path, Class<T> clazz) {
public <ID extends ItemDefinition> ID findItemDefinition(ItemPath path, Class<ID> clazz) {
while (!path.isEmpty() && !(path.first() instanceof NameItemPathSegment)) {
path = path.rest();
}
Expand All @@ -227,7 +227,7 @@ public <T extends ItemDefinition> T findItemDefinition(ItemPath path, Class<T> c
QName firstName = ((NameItemPathSegment)path.first()).getName();
for (ItemDefinition def : getDefinitions()) {
if (firstName.equals(def.getName())) {
return def.findItemDefinition(path.rest(), clazz);
return (ID) def.findItemDefinition(path.rest(), clazz);
}
}
return null;
Expand Down
44 changes: 24 additions & 20 deletions infra/prism/src/main/java/com/evolveum/midpoint/prism/Item.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2014 Evolveum
* Copyright (c) 2010-2015 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 @@ -48,7 +48,7 @@
*
* @author Radovan Semancik
*/
public abstract class Item<V extends PrismValue> implements Itemable, DebugDumpable, Visitable, PathVisitable, Serializable, Revivable {
public abstract class Item<V extends PrismValue, D extends ItemDefinition> implements Itemable, DebugDumpable, Visitable, PathVisitable, Serializable, Revivable {

private static final long serialVersionUID = 510000191615288733L;

Expand All @@ -57,7 +57,7 @@ public abstract class Item<V extends PrismValue> implements Itemable, DebugDumpa
// It may not work perfectly, but basic things should work
protected QName elementName;
protected PrismValue parent;
protected ItemDefinition definition;
protected D definition;
private List<V> values = new ArrayList<V>();
private transient Map<String,Object> userData = new HashMap<>();;

Expand Down Expand Up @@ -85,7 +85,7 @@ public abstract class Item<V extends PrismValue> implements Itemable, DebugDumpa
* The constructors should be used only occasionally (if used at all).
* Use the factory methods in the ResourceObjectDefintion instead.
*/
Item(QName elementName, ItemDefinition definition, PrismContext prismContext) {
Item(QName elementName, D definition, PrismContext prismContext) {
super();
this.elementName = elementName;
this.definition = definition;
Expand All @@ -100,7 +100,7 @@ public abstract class Item<V extends PrismValue> implements Itemable, DebugDumpa
*
* @return applicable property definition
*/
public ItemDefinition getDefinition() {
public D getDefinition() {
return definition;
}

Expand Down Expand Up @@ -145,7 +145,7 @@ public void setElementName(QName elementName) {
*
* @param definition the definition to set
*/
public void setDefinition(ItemDefinition definition) {
public void setDefinition(D definition) {
checkDefinition(definition);
this.definition = definition;
}
Expand Down Expand Up @@ -433,7 +433,7 @@ public void normalize() {
/**
* Merge all the values of other item to this item.
*/
public void merge(Item<V> otherItem) throws SchemaException {
public void merge(Item<V,D> otherItem) throws SchemaException {
for (V otherValue: otherItem.getValues()) {
if (!contains(otherValue)) {
add((V) otherValue.clone());
Expand All @@ -443,19 +443,19 @@ public void merge(Item<V> otherItem) throws SchemaException {

public abstract Object find(ItemPath path);

public abstract <X extends PrismValue> PartiallyResolvedItem<X> findPartial(ItemPath path);
public abstract <IV extends PrismValue,ID extends ItemDefinition> PartiallyResolvedItem<IV,ID> findPartial(ItemPath path);

public Collection<? extends ItemDelta> diff(Item<V> other) {
public Collection<? extends ItemDelta> diff(Item<V,D> other) {
return diff(other, true, false);
}

public Collection<? extends ItemDelta> diff(Item<V> other, boolean ignoreMetadata, boolean isLiteral) {
public Collection<? extends ItemDelta> diff(Item<V,D> other, boolean ignoreMetadata, boolean isLiteral) {
Collection<? extends ItemDelta> itemDeltas = new ArrayList<ItemDelta>();
diffInternal(other, itemDeltas, ignoreMetadata, isLiteral);
return itemDeltas;
}

protected void diffInternal(Item<V> other, Collection<? extends ItemDelta> deltas,
protected void diffInternal(Item<V,D> other, Collection<? extends ItemDelta> deltas,
boolean ignoreMetadata, boolean isLiteral) {
ItemDelta delta = createDelta();
if (other == null) {
Expand Down Expand Up @@ -508,7 +508,7 @@ protected void diffInternal(Item<V> other, Collection<? extends ItemDelta> delta
}
}

protected ItemDelta<V> fixupDelta(ItemDelta<V> delta, Item<V> other,
protected ItemDelta<V,D> fixupDelta(ItemDelta<V,D> delta, Item<V,D> other,
boolean ignoreMetadata) {
return delta;
}
Expand All @@ -517,9 +517,9 @@ protected ItemDelta<V> fixupDelta(ItemDelta<V> delta, Item<V> other,
* Creates specific subclass of ItemDelta appropriate for type of item that this definition
* represents (e.g. PropertyDelta, ContainerDelta, ...)
*/
public abstract ItemDelta<V> createDelta();
public abstract ItemDelta<V,D> createDelta();

public abstract ItemDelta<V> createDelta(ItemPath path);
public abstract ItemDelta<V,D> createDelta(ItemPath path);

@Override
public void accept(Visitor visitor) {
Expand All @@ -540,11 +540,11 @@ public void accept(Visitor visitor, ItemPath path, boolean recursive) {
}
}

public void applyDefinition(ItemDefinition definition) throws SchemaException {
public void applyDefinition(D definition) throws SchemaException {
applyDefinition(definition, true);
}

public void applyDefinition(ItemDefinition definition, boolean force) throws SchemaException {
public void applyDefinition(D definition, boolean force) throws SchemaException {
if (definition != null) {
checkDefinition(definition);
}
Expand Down Expand Up @@ -584,6 +584,10 @@ protected void copyValues(Item clone) {
clone.userData = MiscUtil.cloneMap(this.userData);
}

protected void propagateDeepCloneDefinition(boolean ultraDeep, D clonedDefinition) {
// nothing to do by default
}

public static <T extends Item> Collection<T> cloneCollection(Collection<T> items) {
Collection<T> clones = new ArrayList<T>(items.size());
for (T item: items) {
Expand Down Expand Up @@ -669,7 +673,7 @@ public void checkConsistenceInternal(Itemable rootItem, boolean requireDefinitio
}
}

protected abstract void checkDefinition(ItemDefinition def);
protected abstract void checkDefinition(D def);

public void assertDefinitions() throws SchemaException {
assertDefinitions("");
Expand Down Expand Up @@ -732,7 +736,7 @@ public boolean equalsRealValue(Object obj) {
return false;
if (getClass() != obj.getClass())
return false;
Item<?> other = (Item<?>) obj;
Item<?,?> other = (Item<?,?>) obj;
if (elementName == null) {
if (other.elementName != null)
return false;
Expand Down Expand Up @@ -787,7 +791,7 @@ public boolean equals(Object obj) {
return false;
if (getClass() != obj.getClass())
return false;
Item<?> other = (Item<?>) obj;
Item<?,?> other = (Item<?,?>) obj;
if (definition == null) {
if (other.definition != null)
return false;
Expand All @@ -814,7 +818,7 @@ public boolean match(Object obj) {
return false;
if (getClass() != obj.getClass())
return false;
Item<?> other = (Item<?>) obj;
Item<?,?> other = (Item<?,?>) obj;
if (definition == null) {
if (other.definition != null)
return false;
Expand Down

0 comments on commit 0f0a11f

Please sign in to comment.