Skip to content

Commit

Permalink
Fixed MID-1946 and MID-1948.
Browse files Browse the repository at this point in the history
Fixed No compile-time class in PC(...activation) error while adding a shadow with an activation.
Added few comments, fixed some typos.
  • Loading branch information
mederly committed Jun 20, 2014
1 parent d6b9304 commit a9a7d90
Show file tree
Hide file tree
Showing 14 changed files with 143 additions and 133 deletions.
Expand Up @@ -26,6 +26,7 @@
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.PageBase;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationCapabilityType;
import com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationStatusCapabilityType;
Expand Down Expand Up @@ -71,29 +72,29 @@ public class ContainerWrapper<T extends PrismContainer> implements ItemWrapper,

private PrismContainerDefinition containerDefinition;

public ContainerWrapper(ObjectWrapper object, T container, ContainerStatus status, ItemPath path) {
public ContainerWrapper(ObjectWrapper object, T container, ContainerStatus status, ItemPath path, PageBase pageBase) {
Validate.notNull(container, "Prism object must not be null.");
Validate.notNull(status, "Container status must not be null.");
Validate.notNull(pageBase, "pageBase must not be null.");

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

protected PrismContainerDefinition getContainerDefinition(){
// if (object.getEditedDefinition() != null){
if (main){
protected PrismContainerDefinition getContainerDefinition() {
if (main) {
return object.getDefinition();
}
} else {
return object.getDefinition().findContainerDefinition(path);

}
}

OperationResult getResult() {
Expand Down Expand Up @@ -121,9 +122,6 @@ public T getItem() {
}

public List<PropertyWrapper> getProperties() {
if (properties == null) {
properties = createProperties();
}
return properties;
}

Expand All @@ -137,7 +135,7 @@ public PropertyWrapper findPropertyWrapper(QName name) {
return null;
}

private List<PropertyWrapper> createProperties() {
private List<PropertyWrapper> createProperties(PageBase pageBase) {
result = new OperationResult(CREATE_PROPERTIES);

List<PropertyWrapper> properties = new ArrayList<PropertyWrapper>();
Expand All @@ -147,23 +145,18 @@ private List<PropertyWrapper> createProperties() {
Class clazz = parent.getCompileTimeClass();
if (ShadowType.class.isAssignableFrom(clazz)) {
QName name = containerDefinition.getName();
// QName name = container.getDefinition().getName();


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

if (definition == null){
if (definition == null) {
PrismReference resourceRef = parent.findReference(ShadowType.F_RESOURCE_REF);
PrismObject<ResourceType> resource = resourceRef.getValue().getObject();
RefinedResourceSchema refinedSchema = RefinedResourceSchema.getRefinedSchema(resource,
LayerType.PRESENTATION, parent.getPrismContext());

PrismProperty<QName> objectClassProp = parent.findProperty(ShadowType.F_OBJECT_CLASS);
QName objectClass = objectClassProp != null ? objectClassProp.getRealValue() : null;
definition = refinedSchema.findRefinedDefinitionByObjectClassQName(ShadowKindType.ACCOUNT, objectClass)
.toResourceAttributeContainerDefinition();


definition = pageBase.getModelInteractionService()
.getEditObjectClassDefinition(object.getObject(), resource).toResourceAttributeContainerDefinition();

if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Refined account def:\n{}", definition.debugDump());
}
Expand All @@ -177,11 +170,9 @@ private List<PropertyWrapper> createProperties() {
}
} else {
definition = containerDefinition;
// definition = container.getDefinition();
}
} else {
definition = containerDefinition;
// definition = container.getDefinition();
}

if (definition == null) {
Expand Down Expand Up @@ -219,20 +210,14 @@ private List<PropertyWrapper> createProperties() {
PrismProperty<Object> temp = def.instantiate();

String value = formatAssignmentBrief(assignmentType);
// if (assignmentType.getTarget() != null) {
// value = assignmentType.getTarget().getName().getOrig();
// } else {
// PrismReference targetRef = pcv.findReference(AssignmentType.F_TARGET_REF);
// value = targetRef.getValue().getOid();
// }

temp.setValue(new PrismPropertyValue<Object>(value));
properties.add(new PropertyWrapper(this, temp, this.isReadonly(), ValueStatus.NOT_CHANGED)); // todo this.isReadOnly() - is that OK? (originally it was the default behavior for all cases)
}

} else if (isShadowAssociation()){
if (object.getAssociations() != null){
for (PrismProperty property : object.getAssociations()){
} else if (isShadowAssociation()) {
if (object.getAssociations() != null) {
for (PrismProperty property : object.getAssociations()) {
//TODO: fix this -> for now, read only is supported..
PropertyWrapper propertyWrapper = new PropertyWrapper(this, property, true, ValueStatus.NOT_CHANGED);
properties.add(propertyWrapper);
Expand Down Expand Up @@ -262,16 +247,21 @@ private List<PropertyWrapper> createProperties() {
continue;
}

if (isShadowAssociation()){
if (isShadowAssociation()) {
continue;
}

PrismProperty property = container.findProperty(def.getName());
boolean propertyIsReadOnly;
if (object.getStatus() == ContainerStatus.MODIFYING) { // decision is based on parent object status, not this container's one (because container can be added also to an existing object)
propertyIsReadOnly = !def.canModify();
} else {
propertyIsReadOnly = !def.canAdd();
}
if (property == null) {
boolean readWrite = def.canAdd() || (isPassword(def) && def.canModify());
properties.add(new PropertyWrapper(this, def.instantiate(), !readWrite, ValueStatus.ADDED));
properties.add(new PropertyWrapper(this, def.instantiate(), propertyIsReadOnly, ValueStatus.ADDED));
} else {
properties.add(new PropertyWrapper(this, property, !def.canModify(), ValueStatus.NOT_CHANGED));
properties.add(new PropertyWrapper(this, property, propertyIsReadOnly, ValueStatus.NOT_CHANGED));
}

}
Expand Down Expand Up @@ -387,32 +377,25 @@ boolean isPropertyVisible(PropertyWrapper property) {
if (skipProperty(def) || def.isIgnored() || def.isOperational()) {
return false;
}

if (ContainerStatus.ADDING == getStatus() && def.canAdd()){
return true;

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

// otherwise, object.getStatus() is MODIFYING

if (ContainerStatus.MODIFYING == getStatus() && def.canModify()){
property.setReadonly(false); // this might be too late [mederly]
if (def.canModify()) {
return showEmpty(property);
}

if (ContainerStatus.MODIFYING == getStatus() && !def.canModify()){
if (def.canRead()){
property.setReadonly(true); // this might be too late [mederly]
} else {
if (def.canRead()) {
return showEmpty(property);
}
return false;
}

if (!def.canRead()){
return false;
}

return showEmpty(property);
}

private boolean showEmpty(PropertyWrapper property){
private boolean showEmpty(PropertyWrapper property) {
ObjectWrapper object = getObject();

List<ValueWrapper> values = property.getValues();
Expand Down Expand Up @@ -521,8 +504,8 @@ private boolean skipProperty(PrismPropertyDefinition def) {

public boolean isReadonly() {
PrismContainerDefinition def = getContainerDefinition();
if (def != null){
return (def.canRead() && !def.canAdd() && !def.canModify());
if (def != null) {
return (def.canRead() && !def.canAdd() && !def.canModify()); // todo take into account the containing object status (adding vs. modifying)
}
return readonly;
}
Expand Down

0 comments on commit a9a7d90

Please sign in to comment.