Skip to content

Commit

Permalink
Handler-specific task panels for various handlers (livesync, recon, i…
Browse files Browse the repository at this point in the history
…mport, recompute, exec changes, bulk actions, delete, shadow check, scanners) - almost done. Attempt to make container wrapper usable without object wrapper.
  • Loading branch information
mederly committed Apr 8, 2016
1 parent fcfac75 commit 1c3bdb7
Show file tree
Hide file tree
Showing 66 changed files with 2,382 additions and 746 deletions.
Expand Up @@ -30,6 +30,7 @@
import com.evolveum.midpoint.prism.query.ObjectPaging;
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.schema.SchemaConstantsGenerated;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
Expand All @@ -52,6 +53,7 @@
import com.evolveum.midpoint.web.page.PageDialog;
import com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnBlurAjaxFormUpdatingBehaviour;
import com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnChangeAjaxFormUpdatingBehavior;
import com.evolveum.midpoint.web.page.admin.reports.PageReport;
import com.evolveum.midpoint.web.page.admin.resources.PageResource;
import com.evolveum.midpoint.web.page.admin.roles.PageRole;
import com.evolveum.midpoint.web.page.admin.server.PageTaskEdit;
Expand Down Expand Up @@ -1083,21 +1085,38 @@ public static void dispatchToObjectDetailsPage(ObjectReferenceType objectRef, Pa
page.setResponsePage(new PageResource(parameters, page));
} else if (TaskType.COMPLEX_TYPE.equals(type)) {
page.setResponsePage(new PageTaskEdit(parameters)); // TODO: "back" page
} else if (ReportType.COMPLEX_TYPE.equals(type)) {
page.setResponsePage(PageReport.class, parameters);
} else {
// nothing to do
}
}

public static boolean hasDetailsPage(PrismObject<?> object) {
Class<?> clazz = object.getCompileTimeClass();
return hasDetailsPage(clazz);
}

public static boolean hasDetailsPage(Class<?> clazz) {
if (clazz == null) {
return false;
}

return AbstractRoleType.class.isAssignableFrom(clazz) ||
UserType.class.isAssignableFrom(clazz) ||
ResourceType.class.isAssignableFrom(clazz) ||
TaskType.class.isAssignableFrom(clazz);
TaskType.class.isAssignableFrom(clazz) ||
ReportType.class.isAssignableFrom(clazz);
}

public static boolean hasDetailsPage(ObjectReferenceType ref) {
if (ref == null) {
return false;
}
ObjectTypes t = ObjectTypes.getObjectTypeFromTypeQName(ref.getType());
if (t == null) {
return false;
}
return hasDetailsPage(t.getClassDefinition());
}

@NotNull
Expand Down
Expand Up @@ -26,6 +26,7 @@

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
import org.jetbrains.annotations.Nullable;

import javax.xml.namespace.QName;

Expand All @@ -52,19 +53,33 @@ public class ContainerWrapper<C extends Containerable> implements ItemWrapper, S

private PrismContainerDefinition<C> containerDefinition;

public ContainerWrapper(ObjectWrapper objectWrapper, PrismContainer<C> container, ContainerStatus status, ItemPath path) {
public ContainerWrapper(ObjectWrapper objectWrapper, PrismContainer<C> container, ContainerStatus status, ItemPath path) {
Validate.notNull(container, "container must not be null.");
Validate.notNull(status, "Container status must not be null.");

this.objectWrapper = objectWrapper;
this.container = container;
this.status = status;
this.path = path;
main = path == null;
readonly = objectWrapper.isReadonly(); // [pm] this is quite questionable
showInheritedObjectAttributes = objectWrapper.isShowInheritedObjectAttributes();
// have to be after setting "main" property
containerDefinition = getItemDefinition();
}

public ContainerWrapper(PrismContainer<C> container, ContainerStatus status, boolean readOnly) {
Validate.notNull(container, "container must not be null.");
Validate.notNull(container.getDefinition(), "container definition must not be null.");
Validate.notNull(status, "Container status must not be null.");

this.objectWrapper = objectWrapper;
this.container = container;
this.containerDefinition = container.getDefinition();
this.status = status;
this.path = path;
this.path = null;
main = path == null;
readonly = objectWrapper.isReadonly(); // [pm] this is quite questionable
showInheritedObjectAttributes = objectWrapper.isShowInheritedObjectAttributes();
// have to be after setting "main" property
containerDefinition = getItemDefinition();
this.readonly = readOnly;
showInheritedObjectAttributes = false;
}

public void revive(PrismContext prismContext) throws SchemaException {
Expand All @@ -83,14 +98,18 @@ public void revive(PrismContext prismContext) throws SchemaException {

@Override
public PrismContainerDefinition<C> getItemDefinition() {
if (containerDefinition != null) {
return containerDefinition;
}
if (main) {
return objectWrapper.getDefinition();
} else {
return objectWrapper.getDefinition().findContainerDefinition(path);
}
}

ObjectWrapper getObject() {
@Nullable
ObjectWrapper getObject() {
return objectWrapper;
}

Expand Down Expand Up @@ -139,7 +158,7 @@ boolean isItemVisible(ItemWrapper item) {

// we decide not according to status of this container, but according to
// the status of the whole object
if (objectWrapper.getStatus() == ContainerStatus.ADDING) {
if (objectWrapper != null && objectWrapper.getStatus() == ContainerStatus.ADDING) {
return def.canAdd();
}

Expand All @@ -155,7 +174,11 @@ boolean isItemVisible(ItemWrapper item) {
}
}

private boolean showEmpty(ItemWrapper item) {
public boolean isShowInheritedObjectAttributes() {
return showInheritedObjectAttributes;
}

private boolean showEmpty(ItemWrapper item) {
ObjectWrapper objectWrapper = getObject();
List<ValueWrapper> valueWrappers = item.getValues();
boolean isEmpty;
Expand All @@ -170,7 +193,7 @@ private boolean showEmpty(ItemWrapper item) {
isEmpty = true;
}
}
return objectWrapper.isShowEmpty() || !isEmpty;
return (objectWrapper == null || objectWrapper.isShowEmpty()) || !isEmpty;
}

@Override
Expand Down Expand Up @@ -351,4 +374,5 @@ public String debugDump(int indent) {
DebugUtil.debugDump(sb, properties, indent + 2, false);
return sb.toString();
}

}
Expand Up @@ -94,6 +94,18 @@ public <T extends PrismContainer> ContainerWrapper createContainerWrapper(Object
return cWrapper;
}

public <T extends PrismContainer> ContainerWrapper createContainerWrapper(T container, ContainerStatus status, boolean readonly) {

result = new OperationResult(CREATE_PROPERTIES);

ContainerWrapper cWrapper = new ContainerWrapper(container, status, readonly);

List<ItemWrapper> properties = createProperties(cWrapper, result);
cWrapper.setProperties(properties);

return cWrapper;
}

private List<ItemWrapper> createProperties(ContainerWrapper cWrapper, OperationResult result) {
ObjectWrapper objectWrapper = cWrapper.getObject();
PrismContainer container = cWrapper.getItem();
Expand All @@ -102,50 +114,54 @@ private List<ItemWrapper> createProperties(ContainerWrapper cWrapper, OperationR
List<ItemWrapper> properties = new ArrayList<>();

PrismContainerDefinition definition;
PrismObject parent = objectWrapper.getObject();
Class clazz = parent.getCompileTimeClass();
if (ShadowType.class.isAssignableFrom(clazz)) {
QName name = containerDefinition.getName();

if (ShadowType.F_ATTRIBUTES.equals(name)) {
try {
definition = objectWrapper.getRefinedAttributeDefinition();

if (definition == null) {
PrismReference resourceRef = parent.findReference(ShadowType.F_RESOURCE_REF);
PrismObject<ResourceType> resource = resourceRef.getValue().getObject();

definition = modelServiceLocator
.getModelInteractionService()
.getEditObjectClassDefinition((PrismObject<ShadowType>) objectWrapper.getObject(), resource,
AuthorizationPhaseType.REQUEST)
.toResourceAttributeContainerDefinition();

if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Refined account def:\n{}", definition.debugDump());
}
}
} catch (Exception ex) {
LoggingUtils.logException(LOGGER,
"Couldn't load definitions from refined schema for shadow", ex);
result.recordFatalError(
"Couldn't load definitions from refined schema for shadow, reason: "
+ ex.getMessage(), ex);

return properties;
}
} else {
definition = containerDefinition;
}
} else if (ResourceType.class.isAssignableFrom(clazz)) {
if (containerDefinition != null) {
definition = containerDefinition;
} else {
definition = container.getDefinition();
}
} else {
definition = containerDefinition;
}
if (objectWrapper == null) {
definition = containerDefinition;
} else {
PrismObject parent = objectWrapper.getObject();
Class clazz = parent.getCompileTimeClass();
if (ShadowType.class.isAssignableFrom(clazz)) {
QName name = containerDefinition.getName();

if (ShadowType.F_ATTRIBUTES.equals(name)) {
try {
definition = objectWrapper.getRefinedAttributeDefinition();

if (definition == null) {
PrismReference resourceRef = parent.findReference(ShadowType.F_RESOURCE_REF);
PrismObject<ResourceType> resource = resourceRef.getValue().getObject();

definition = modelServiceLocator
.getModelInteractionService()
.getEditObjectClassDefinition((PrismObject<ShadowType>) objectWrapper.getObject(), resource,
AuthorizationPhaseType.REQUEST)
.toResourceAttributeContainerDefinition();

if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Refined account def:\n{}", definition.debugDump());
}
}
} catch (Exception ex) {
LoggingUtils.logException(LOGGER,
"Couldn't load definitions from refined schema for shadow", ex);
result.recordFatalError(
"Couldn't load definitions from refined schema for shadow, reason: "
+ ex.getMessage(), ex);

return properties;
}
} else {
definition = containerDefinition;
}
} else if (ResourceType.class.isAssignableFrom(clazz)) {
if (containerDefinition != null) {
definition = containerDefinition;
} else {
definition = container.getDefinition();
}
} else {
definition = containerDefinition;
}
}

if (definition == null) {
LOGGER.error("Couldn't get property list from null definition {}",
Expand Down Expand Up @@ -224,7 +240,7 @@ private List<ItemWrapper> createProperties(ContainerWrapper cWrapper, OperationR
}
}

PrismReference resourceRef = parent.findReference(ShadowType.F_RESOURCE_REF);
PrismReference resourceRef = objectWrapper.getObject().findReference(ShadowType.F_RESOURCE_REF);
PrismObject<ResourceType> resource = resourceRef.getValue().getObject();

// HACK. The revive should not be here. Revive is no good. The next use of the resource will
Expand All @@ -239,7 +255,7 @@ private List<ItemWrapper> createProperties(ContainerWrapper cWrapper, OperationR
CompositeRefinedObjectClassDefinition rOcDef;
try {
refinedSchema = RefinedResourceSchema.getRefinedSchema(resource);
rOcDef = refinedSchema.determineCompositeObjectClassDefinition(parent);
rOcDef = refinedSchema.determineCompositeObjectClassDefinition(objectWrapper.getObject());
} catch (SchemaException e) {
throw new SystemException(e.getMessage(), e);
}
Expand Down Expand Up @@ -278,7 +294,7 @@ private List<ItemWrapper> createProperties(ContainerWrapper cWrapper, OperationR
if (def.isIgnored() || skipProperty(def)) {
continue;
}
if (!objectWrapper.isShowInheritedObjectAttributes()
if (!cWrapper.isShowInheritedObjectAttributes()
&& INHERITED_OBJECT_ATTRIBUTES.contains(def.getName())) {
continue;
}
Expand All @@ -297,7 +313,7 @@ private List<ItemWrapper> createProperties(ContainerWrapper cWrapper, OperationR
// decision is based on parent object status, not this
// container's one (because container can be added also
// to an existing object)
if (objectWrapper.getStatus() == ContainerStatus.MODIFYING) {
if (objectWrapper == null || objectWrapper.getStatus() == ContainerStatus.MODIFYING) {

propertyIsReadOnly = !def.canModify();
} else {
Expand All @@ -322,7 +338,7 @@ private List<ItemWrapper> createProperties(ContainerWrapper cWrapper, OperationR
// decision is based on parent object status, not this
// container's one (because container can be added also
// to an existing object)
if (objectWrapper.getStatus() == ContainerStatus.MODIFYING) {
if (objectWrapper == null || objectWrapper.getStatus() == ContainerStatus.MODIFYING) {

propertyIsReadOnly = !def.canModify();
} else {
Expand Down Expand Up @@ -350,6 +366,9 @@ private List<ItemWrapper> createProperties(ContainerWrapper cWrapper, OperationR

private boolean isShadowAssociation(ContainerWrapper cWrapper) {
ObjectWrapper oWrapper = cWrapper.getObject();
if (oWrapper == null) {
return false;
}
PrismContainer container = cWrapper.getItem();

if (!ShadowType.class.isAssignableFrom(oWrapper.getObject().getCompileTimeClass())) {
Expand All @@ -365,6 +384,9 @@ private boolean isShadowAssociation(ContainerWrapper cWrapper) {

private boolean isShadowActivation(ContainerWrapper cWrapper) {
ObjectWrapper oWrapper = cWrapper.getObject();
if (oWrapper == null) {
return false;
}
PrismContainer container = cWrapper.getItem();

if (!ShadowType.class.isAssignableFrom(oWrapper.getObject().getCompileTimeClass())) {
Expand Down
Expand Up @@ -30,7 +30,7 @@
</div>
</div>
</div>
<div class="attributeComponent box-body" style="padding: 0;">
<div class="attributeComponent box-body attributeComponent" style="padding: 0;">
<div wicket:id="properties">
<div class="row" wicket:id="property"/>
</div>
Expand Down
Expand Up @@ -114,8 +114,7 @@ private void initLayout(final IModel<ContainerWrapper> model, final Form form) {

@Override
public boolean isVisible() {
//
return true;
return isShowHeader();
}
});

Expand Down Expand Up @@ -194,7 +193,7 @@ public int compare(PropertyOrReferenceWrapper pw1, PropertyOrReferenceWrapper pw
// headerLabelModel = new StringResourceModel(resourceKey, this);
ContainerWrapper wrappper = model.getObject();
ObjectWrapper objwrapper = wrappper.getObject();
final String key = objwrapper.getDisplayName();
final String key = objwrapper != null ? objwrapper.getDisplayName() : "";

headerLabelModel = new IModel<String>() {
@Override
Expand Down
Expand Up @@ -252,6 +252,9 @@ private boolean hasPendingModification(IModel<IW> model) {
}
ObjectWrapper objectWrapper = containerWrapper.getObject();

if (objectWrapper == null) {
return false;
}
PrismObject prismObject = objectWrapper.getObject();
if (!ShadowType.class.isAssignableFrom(prismObject.getCompileTimeClass())) {
return false;
Expand Down

0 comments on commit 1c3bdb7

Please sign in to comment.