Skip to content

Commit

Permalink
Fixing dealing with auxiliary object classes in the model (lens). Fix…
Browse files Browse the repository at this point in the history
…ing a handful of NPEs.
  • Loading branch information
semancik committed Mar 15, 2016
1 parent 2f58975 commit d4f23fc
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 43 deletions.
Expand Up @@ -25,6 +25,7 @@
import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismObjectDefinition;
import com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition;
import com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition;
import com.evolveum.midpoint.schema.util.SchemaDebugUtil;
import com.evolveum.midpoint.util.DebugUtil;
Expand Down Expand Up @@ -225,6 +226,10 @@ public PrismObjectDefinition<ShadowType> getObjectDefinition() {
return structuralObjectClassDefinition.getObjectDefinition();
}

public ObjectClassComplexTypeDefinition getObjectClassDefinition() {
return structuralObjectClassDefinition.getObjectClassDefinition();
}

public ResourceObjectReferenceType getBaseContext() {
return structuralObjectClassDefinition.getBaseContext();
}
Expand Down
Expand Up @@ -114,7 +114,7 @@ public LayerRefinedObjectClassDefinition forLayer(LayerType layerType) {

@Override
public ResourceAttributeDefinition<?> getDescriptionAttribute() {
return objectClassDefinition.getDescriptionAttribute();
return getObjectClassDefinition().getDescriptionAttribute();
}

@Override
Expand All @@ -124,17 +124,17 @@ public void setDescriptionAttribute(ResourceAttributeDefinition<?> descriptionAt

@Override
public RefinedAttributeDefinition<?> getNamingAttribute() {
return substituteRefinedAttributeDefinition(objectClassDefinition.getNamingAttribute());
return substituteRefinedAttributeDefinition(getObjectClassDefinition().getNamingAttribute());
}

@Override
public QName getTypeName() {
return objectClassDefinition.getTypeName();
return getObjectClassDefinition().getTypeName();
}

@Override
public String getNativeObjectClass() {
return objectClassDefinition.getNativeObjectClass();
return getObjectClassDefinition().getNativeObjectClass();
}

@Override
Expand Down Expand Up @@ -173,7 +173,7 @@ public void setKind(ShadowKindType kind) {
@Override
public RefinedAttributeDefinition<?> getDisplayNameAttribute() {
if (displayNameAttributeDefinition == null) {
ResourceAttributeDefinition<?> displayNameAttribute = objectClassDefinition.getDisplayNameAttribute();
ResourceAttributeDefinition<?> displayNameAttribute = getObjectClassDefinition().getDisplayNameAttribute();
if (displayNameAttribute == null) {
return null;
}
Expand Down Expand Up @@ -296,7 +296,7 @@ public Collection<ResourceObjectPattern> getProtectedObjectPatterns() {
}

public PrismContext getPrismContext() {
return resourceType.asPrismObject().getPrismContext();
return getResourceType().asPrismObject().getPrismContext();
}

@Override
Expand Down Expand Up @@ -361,7 +361,7 @@ public <X> RefinedAttributeDefinition<X> findAttributeDefinition(String elementL
}

protected String getResourceNamespace() {
return ResourceTypeUtil.getResourceNamespace(resourceType);
return ResourceTypeUtil.getResourceNamespace(getResourceType());
}

@Override
Expand Down Expand Up @@ -440,7 +440,7 @@ private void constructObjectDefinition() {
}

public RefinedAttributeDefinition<?> getAttributeDefinition(QName attributeName) {
for (RefinedAttributeDefinition<?> attrDef : attributeDefinitions) {
for (RefinedAttributeDefinition<?> attrDef : getAttributeDefinitions()) {
if (QNameUtil.match(attrDef.getName(), attributeName)) {
return attrDef;
}
Expand All @@ -450,7 +450,7 @@ public RefinedAttributeDefinition<?> getAttributeDefinition(QName attributeName)


public void add(RefinedAttributeDefinition<?> refinedAttributeDefinition) {
attributeDefinitions.add(refinedAttributeDefinition);
((Collection)getAttributeDefinitions()).add(refinedAttributeDefinition);
}

public boolean containsAttributeDefinition(ItemPathType pathType) {
Expand All @@ -459,7 +459,7 @@ public boolean containsAttributeDefinition(ItemPathType pathType) {
}

public boolean containsAttributeDefinition(QName attributeName) {
for (RefinedAttributeDefinition<?> rAttributeDef : attributeDefinitions) {
for (RefinedAttributeDefinition<?> rAttributeDef : getAttributeDefinitions()) {
if (QNameUtil.match(rAttributeDef.getName(), attributeName)) {
return true;
}
Expand Down Expand Up @@ -654,7 +654,7 @@ public void parseAttributes(RefinedResourceSchema rSchema, String contextDescrip
return;
}

parseAttributesFrom(rSchema, objectClassDefinition, false, contextDescription);
parseAttributesFrom(rSchema, getObjectClassDefinition(), false, contextDescription);
if (auxiliaryObjectClassDefinitions != null) {
for (RefinedObjectClassDefinition auxiliaryObjectClassDefinition: auxiliaryObjectClassDefinitions) {
parseAttributesFrom(rSchema, auxiliaryObjectClassDefinition, true, contextDescription);
Expand Down Expand Up @@ -759,8 +759,8 @@ public PrismObject<ShadowType> createBlankShadow() {

accountShadowType.setIntent(getIntent());
accountShadowType.setKind(getKind());
accountShadowType.setObjectClass(objectClassDefinition.getTypeName());
accountShadowType.setResourceRef(ObjectTypeUtil.createObjectRef(resourceType));
accountShadowType.setObjectClass(getObjectClassDefinition().getTypeName());
accountShadowType.setResourceRef(ObjectTypeUtil.createObjectRef(getResourceType()));

// Setup definition
PrismObjectDefinition<ShadowType> newDefinition = accountShadow.getDefinition().cloneWithReplacedDefinition(
Expand All @@ -771,7 +771,7 @@ public PrismObject<ShadowType> createBlankShadow() {
}

public ResourceShadowDiscriminator getShadowDiscriminator() {
return new ResourceShadowDiscriminator(resourceType.getOid(), getKind(), getIntent());
return new ResourceShadowDiscriminator(getResourceType().getOid(), getKind(), getIntent());
}

public Collection<? extends QName> getNamesOfAttributesWithOutboundExpressions() {
Expand Down Expand Up @@ -892,7 +892,7 @@ public AttributeFetchStrategyType getActivationFetchStrategy(QName propertyName)
}

public <T extends CapabilityType> T getEffectiveCapability(Class<T> capabilityClass) {
return ResourceTypeUtil.getEffectiveCapability(resourceType, schemaHandlingObjectTypeDefinitionType, capabilityClass);
return ResourceTypeUtil.getEffectiveCapability(getResourceType(), schemaHandlingObjectTypeDefinitionType, capabilityClass);
}

public PagedSearchCapabilityType getPagedSearches() {
Expand All @@ -910,14 +910,14 @@ public boolean isObjectCountingEnabled() {


public boolean isAuxiliary() {
return objectClassDefinition.isAuxiliary();
return getObjectClassDefinition().isAuxiliary();
}

public boolean matches(ShadowType shadowType) {
if (shadowType == null) {
return false;
}
if (!QNameUtil.match(objectClassDefinition.getTypeName(), shadowType.getObjectClass())) {
if (!QNameUtil.match(getObjectClassDefinition().getTypeName(), shadowType.getObjectClass())) {
return false;
}
if (shadowType.getKind() == null) {
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2015 Evolveum
* 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.
Expand Down Expand Up @@ -39,6 +39,7 @@
import org.jvnet.jaxb2_commons.lang.Validate;

import com.evolveum.midpoint.common.crypto.CryptoUtil;
import com.evolveum.midpoint.common.refinery.CompositeRefinedObjectClassDefinition;
import com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition;
import com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition;
import com.evolveum.midpoint.common.refinery.RefinedResourceSchema;
Expand Down Expand Up @@ -167,6 +168,7 @@ public class LensProjectionContext extends LensElementContext<ShadowType> implem

private transient RefinedObjectClassDefinition structuralObjectClassDefinition;
private transient Collection<RefinedObjectClassDefinition> auxiliaryObjectClassDefinitions;
private transient CompositeRefinedObjectClassDefinition compositeObjectClassDefinition;

private ValuePolicyType accountPasswordPolicy;

Expand Down Expand Up @@ -372,7 +374,7 @@ public void setResource(ResourceType resource) {
public PrismObjectDefinition<ShadowType> getObjectDefinition() {
if (shadowDefinition == null) {
try {
shadowDefinition = ShadowUtil.applyObjectClass(super.getObjectDefinition(), getStructuralObjectClassDefinition());
shadowDefinition = ShadowUtil.applyObjectClass(super.getObjectDefinition(), getCompositeObjectClassDefinition());
} catch (SchemaException e) {
// This should not happen
throw new SystemException(e.getMessage(), e);
Expand Down Expand Up @@ -587,6 +589,17 @@ public Collection<RefinedObjectClassDefinition> getAuxiliaryObjectClassDefinitio
}
return auxiliaryObjectClassDefinitions;
}

public CompositeRefinedObjectClassDefinition getCompositeObjectClassDefinition() throws SchemaException {
if (compositeObjectClassDefinition == null) {
RefinedObjectClassDefinition structuralObjectClassDefinition = getStructuralObjectClassDefinition();
if (structuralObjectClassDefinition != null) {
compositeObjectClassDefinition = new CompositeRefinedObjectClassDefinition(
structuralObjectClassDefinition, getAuxiliaryObjectClassDefinitions());
}
}
return compositeObjectClassDefinition;
}

private void addAuxiliaryObjectClassNames(List<QName> auxiliaryObjectClassQNames,
PrismObject<ShadowType> shadow) {
Expand Down Expand Up @@ -722,7 +735,7 @@ public void recompute() throws SchemaException {
}

if (base == null && accDelta.isModify()) {
RefinedObjectClassDefinition rAccountDef = getStructuralObjectClassDefinition();
RefinedObjectClassDefinition rAccountDef = getCompositeObjectClassDefinition();
if (rAccountDef != null) {
base = (PrismObject<ShadowType>) rAccountDef.createBlankShadow();
}
Expand Down Expand Up @@ -811,13 +824,13 @@ public ObjectDelta<ShadowType> getExecutableDelta() throws SchemaException {
// We need to convert modify delta to ADD
ObjectDelta<ShadowType> addDelta = new ObjectDelta<ShadowType>(getObjectTypeClass(),
ChangeType.ADD, getPrismContext());
RefinedObjectClassDefinition rAccount = getStructuralObjectClassDefinition();
RefinedObjectClassDefinition rObjectClassDef = getCompositeObjectClassDefinition();

if (rAccount == null) {
if (rObjectClassDef == null) {
throw new IllegalStateException("Definition for account type " + getResourceShadowDiscriminator()
+ " not found in the context, but it should be there");
}
PrismObject<ShadowType> newAccount = (PrismObject<ShadowType>) rAccount.createBlankShadow();
PrismObject<ShadowType> newAccount = (PrismObject<ShadowType>) rObjectClassDef.createBlankShadow();
addDelta.setObjectToAdd(newAccount);

if (origDelta != null) {
Expand Down
Expand Up @@ -230,7 +230,7 @@ public boolean isAuthoritative() {
ObjectDelta<ShadowType> objectDelta = new ObjectDelta<ShadowType>(ShadowType.class, ChangeType.MODIFY, prismContext);
objectDelta.setOid(projCtx.getOid());

RefinedObjectClassDefinition rOcDef = projCtx.getStructuralObjectClassDefinition();
RefinedObjectClassDefinition rOcDef = projCtx.getCompositeObjectClassDefinition();
if (rOcDef == null) {
LOGGER.error("Definition for account type {} not found in the context, but it should be there, dumping context:\n{}", discr, context.debugDump());
throw new IllegalStateException("Definition for account type " + discr + " not found in the context, but it should be there");
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2013 Evolveum
* 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.
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2015 Evolveum
* 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.
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2015 Evolveum
* 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.
Expand Down Expand Up @@ -161,15 +161,15 @@ <F extends FocusType> void processInboundFocal(LensContext<F> context, Task task
continue;
}

RefinedObjectClassDefinition accountDefinition = projectionContext.getStructuralObjectClassDefinition();
if (accountDefinition == null) {
LOGGER.error("Definition for account type {} not found in the context, but it " +
RefinedObjectClassDefinition rOcDef = projectionContext.getCompositeObjectClassDefinition();
if (rOcDef == null) {
LOGGER.error("Definition for projection type {} not found in the context, but it " +
"should be there, dumping context:\n{}", rat, context.debugDump());
throw new IllegalStateException("Definition for account type " + rat
throw new IllegalStateException("Definition for projection type " + rat
+ " not found in the context, but it should be there");
}

processInboundExpressionsForProjection(context, projectionContext, accountDefinition, aPrioriDelta, task, now, result);
processInboundExpressionsForProjection(context, projectionContext, rOcDef, aPrioriDelta, task, now, result);
}

} finally {
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2015 Evolveum
* 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.
Expand Down Expand Up @@ -104,7 +104,7 @@ public <F extends FocusType> void processOutbound(LensContext<F> context, LensPr

LOGGER.trace("Processing outbound expressions for {} starting", discr);

RefinedObjectClassDefinition rOcDef = projCtx.getStructuralObjectClassDefinition();
RefinedObjectClassDefinition rOcDef = projCtx.getCompositeObjectClassDefinition();
if (rOcDef == null) {
LOGGER.error("Definition for {} not found in the context, but it should be there, dumping context:\n{}", discr, context.debugDump());
throw new IllegalStateException("Definition for " + discr + " not found in the context, but it should be there");
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2015 Evolveum
* 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.
Expand Down Expand Up @@ -459,7 +459,7 @@ private boolean willResetIterationCounter(LensProjectionContext projectionContex
if (accountDelta == null) {
return false;
}
RefinedObjectClassDefinition oOcDef = projectionContext.getStructuralObjectClassDefinition();
RefinedObjectClassDefinition oOcDef = projectionContext.getCompositeObjectClassDefinition();
for (RefinedAttributeDefinition identifierDef: oOcDef.getIdentifiers()) {
ItemPath identifierPath = new ItemPath(ShadowType.F_ATTRIBUTES, identifierDef.getName());
if (accountDelta.findPropertyDelta(identifierPath) != null) {
Expand Down Expand Up @@ -552,7 +552,7 @@ public <F extends ObjectType> void checkSchemaAndPolicies(LensContext<F> context
return;
}

RefinedObjectClassDefinition rAccountDef = accountContext.getStructuralObjectClassDefinition();
RefinedObjectClassDefinition rAccountDef = accountContext.getCompositeObjectClassDefinition();
if (rAccountDef == null) {
throw new SchemaException("No definition for account type '"
+accountContext.getResourceShadowDiscriminator()+"' in "+accountContext.getResource());
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2015 Evolveum
* 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.
Expand Down Expand Up @@ -171,7 +171,7 @@ <F extends ObjectType> void processReconciliationFocus(LensContext<F> context,
LOGGER.trace("Starting reconciliation of {}", projCtx.getHumanReadableName());
}

RefinedObjectClassDefinition rOcDef = projCtx.getStructuralObjectClassDefinition();
RefinedObjectClassDefinition rOcDef = projCtx.getCompositeObjectClassDefinition();

Map<QName, DeltaSetTriple<ItemValueWithOrigin<PrismPropertyValue<?>,PrismPropertyDefinition<?>>>> squeezedAttributes = projCtx
.getSqueezedAttributes();
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2013 Evolveum
* 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.
Expand Down Expand Up @@ -106,7 +106,7 @@ public PrismObject getConflictingShadow() {

public void check(Task task, OperationResult result) throws SchemaException, ObjectAlreadyExistsException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException {

RefinedObjectClassDefinition projDef = projectionContext.getStructuralObjectClassDefinition();
RefinedObjectClassDefinition projOcDef = projectionContext.getCompositeObjectClassDefinition();
PrismObject<ShadowType> projectionNew = projectionContext.getObjectNew();
if (projectionNew == null) {
// This must be delete
Expand Down Expand Up @@ -140,7 +140,7 @@ public boolean confirmViolation(String oid) {
}
};

constraintsCheckingResult = provisioningService.checkConstraints(projDef, projectionNew,
constraintsCheckingResult = provisioningService.checkConstraints(projOcDef, projectionNew,
projectionContext.getResource(), projectionContext.getOid(), projectionContext.getResourceShadowDiscriminator(),
confirmer, task, result);

Expand Down
Expand Up @@ -407,7 +407,7 @@ protected <T> ObjectDelta<ShadowType> createAccountDelta(LensProjectionContext a
ResourceType resourceType = accCtx.getResource();
QName attrQName = new QName(ResourceTypeUtil.getResourceNamespace(resourceType), attributeLocalName);
ItemPath attrPath = new ItemPath(ShadowType.F_ATTRIBUTES, attrQName);
RefinedObjectClassDefinition refinedAccountDefinition = accCtx.getStructuralObjectClassDefinition();
RefinedObjectClassDefinition refinedAccountDefinition = accCtx.getCompositeObjectClassDefinition();
RefinedAttributeDefinition attrDef = refinedAccountDefinition.findAttributeDefinition(attrQName);
assertNotNull("No definition of attribute "+attrQName+" in account def "+refinedAccountDefinition, attrDef);
ObjectDelta<ShadowType> accountDelta = ObjectDelta.createEmptyModifyDelta(ShadowType.class, accountOid, prismContext);
Expand Down

0 comments on commit d4f23fc

Please sign in to comment.