Skip to content

Commit

Permalink
Refactoring UCF. ResourceObjectReferenceType. Basic support for baseC…
Browse files Browse the repository at this point in the history
…ontext. Untested.
  • Loading branch information
semancik committed Feb 25, 2015
1 parent 343127b commit ed3e8ba
Show file tree
Hide file tree
Showing 15 changed files with 491 additions and 73 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 @@ -40,6 +40,7 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceActivationDefinitionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceBidirectionalMappingType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectAssociationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
Expand Down Expand Up @@ -615,8 +616,13 @@ public void add(RefinedAttributeDefinition refinedAttributeDefinition) {
public void parseAssociations(RefinedResourceSchema rSchema) {
throw new UnsupportedOperationException();
}

@Override
public ResourceObjectReferenceType getBaseContext() {
return refinedObjectClassDefinition.getBaseContext();
}

@Override
protected String debugDump(int indent, LayerType layer) {
return refinedObjectClassDefinition.debugDump(indent, layer);
}
Expand Down
@@ -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 @@ -31,7 +31,9 @@
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.PrettyPrinter;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SystemException;
import com.evolveum.midpoint.util.logging.Trace;
Expand Down Expand Up @@ -69,6 +71,7 @@ public class RefinedObjectClassDefinition extends ObjectClassComplexTypeDefiniti
private Collection<ResourceObjectPattern> protectedObjectPatterns;
private List<RefinedAttributeDefinition> attributeDefinitions;
private Collection<RefinedAssociationDefinition> associations = new ArrayList<RefinedAssociationDefinition>();
private ResourceObjectReferenceType baseContext;

/**
* Refined object definition. The "any" parts are replaced with appropriate schema (e.g. resource schema)
Expand Down Expand Up @@ -352,7 +355,15 @@ public PrismObjectDefinition<ShadowType> getObjectDefinition() {
return objectDefinition;
}

private void constructObjectDefinition() {
public ResourceObjectReferenceType getBaseContext() {
return baseContext;
}

public void setBaseContext(ResourceObjectReferenceType baseContext) {
this.baseContext = baseContext;
}

private void constructObjectDefinition() {
// Almost-shallow clone of object definition and complex type
PrismObjectDefinition<ShadowType> originalObjectDefinition =
getSchemaRegistry().findObjectDefinitionByCompileTimeClass(ShadowType.class);
Expand Down Expand Up @@ -537,6 +548,10 @@ private static RefinedObjectClassDefinition parseRefinedObjectClass(ResourceObje
rOcDef.setDefault(objectClassDef.isDefaultInAKind());
}

if (schemaHandlingObjDefType.getBaseContext() != null) {
rOcDef.setBaseContext(schemaHandlingObjDefType.getBaseContext());
}

for (ResourceAttributeDefinition road : objectClassDef.getAttributeDefinitions()) {
String attrContextDescription = road.getName() + ", in " + contextDescription;
ResourceAttributeDefinitionType attrDefType = findAttributeDefinitionType(road.getName(), schemaHandlingObjDefType,
Expand Down Expand Up @@ -761,6 +776,37 @@ public AttributeFetchStrategyType getActivationFetchStrategy(QName propertyName)
return biType.getFetchStrategy();
}

public static RefinedObjectClassDefinition determineObjectClassDefinition(PrismObject<ShadowType> shadow, ResourceType resource) throws SchemaException, ConfigurationException {
ShadowType shadowType = shadow.asObjectable();
RefinedResourceSchema refinedSchema = RefinedResourceSchema.getRefinedSchema(resource, resource.asPrismObject().getPrismContext());
if (refinedSchema == null) {
throw new ConfigurationException("No schema defined for "+resource);
}


RefinedObjectClassDefinition objectClassDefinition = null;
ShadowKindType kind = shadowType.getKind();
String intent = shadowType.getIntent();
QName objectClass = shadow.asObjectable().getObjectClass();
if (kind != null) {
objectClassDefinition = refinedSchema.getRefinedDefinition(kind, intent);
}
if (objectClassDefinition == null) {
// Fallback to objectclass only
if (objectClass == null) {
throw new SchemaException("No kind nor objectclass definied in "+shadow);
}
objectClassDefinition = refinedSchema.findRefinedDefinitionByObjectClassQName(kind, objectClass);
}

if (objectClassDefinition == null) {
throw new SchemaException("Definition for "+shadow+" not found (objectClass=" + PrettyPrinter.prettyPrint(objectClass) +
", kind="+kind+", intent='"+intent+"') in schema of " + resource);
}

return objectClassDefinition;
}

public boolean matches(ShadowType shadowType) {
if (shadowType == null) {
return false;
Expand Down
@@ -0,0 +1,43 @@
/**
* Copyright (c) 2015 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.schema.processor;

import java.util.Collection;

/**
* @author semancik
*
*/
public class ResourceObjectIdentification {

private ObjectClassComplexTypeDefinition objectClassDefinition;
private Collection<? extends ResourceAttribute<?>> identifiers;
// TODO: identification strategy

public ResourceObjectIdentification(ObjectClassComplexTypeDefinition objectClassDefinition, Collection<? extends ResourceAttribute<?>> identifiers) {
this.objectClassDefinition = objectClassDefinition;
this.identifiers = identifiers;
}

public Collection<? extends ResourceAttribute<?>> getIdentifiers() {
return identifiers;
}

public ObjectClassComplexTypeDefinition getObjectClassDefinition() {
return objectClassDefinition;
}

}
@@ -0,0 +1,42 @@
/**
* Copyright (c) 2015 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.schema.processor;

/**
* @author semancik
*
*/
public class SearchHierarchyConstraints {

ResourceObjectIdentification baseContext;
SearchHierarchyScope scope;

public SearchHierarchyConstraints(ResourceObjectIdentification baseContext, SearchHierarchyScope scope) {
super();
this.baseContext = baseContext;
this.scope = scope;
}

public ResourceObjectIdentification getBaseContext() {
return baseContext;
}

public SearchHierarchyScope getScope() {
return scope;
}


}
@@ -0,0 +1,24 @@
/**
* Copyright (c) 2015 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.schema.processor;

/**
* @author semancik
*
*/
public enum SearchHierarchyScope {
ONE, SUBTREE;
}
Expand Up @@ -67,6 +67,23 @@ public static Collection<ResourceAttribute<?>> getSecondaryIdentifiers(PrismObje
return attributesContainer.getSecondaryIdentifiers();
}

public static ResourceAttribute<?> getSecondaryIdentifier(ObjectClassComplexTypeDefinition objectClassDefinition,
Collection<? extends ResourceAttribute<?>> identifiers) throws SchemaException {
if (identifiers == null) {
return null;
}
ResourceAttribute<?> secondaryIdentifier = null;
for (ResourceAttribute<?> identifier: identifiers) {
if (identifier.getDefinition().isIdentifier(objectClassDefinition)) {
if (secondaryIdentifier != null) {
throw new SchemaException("More than one secondary identifier in "+objectClassDefinition);
}
secondaryIdentifier = identifier;
}
}
return secondaryIdentifier;
}

public static ResourceAttribute<String> getNamingAttribute(ShadowType shadow){
return getNamingAttribute(shadow.asPrismObject());
}
Expand Down

0 comments on commit ed3e8ba

Please sign in to comment.