Skip to content

Commit

Permalink
Implemented/fixed some methods in refined OC definitions. A couple of…
Browse files Browse the repository at this point in the history
… minor fixes.
  • Loading branch information
mederly committed Oct 25, 2016
1 parent e6f9b98 commit 0c018bc
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 34 deletions.
Expand Up @@ -419,7 +419,6 @@ public List<String> getIgnoredNamespaces() {
return structuralObjectClassDefinition.getIgnoredNamespaces();
}


@Override
public LayerRefinedObjectClassDefinition forLayer(LayerType layerType) {
throw new UnsupportedOperationException("TODO implement if needed");
Expand Down Expand Up @@ -509,19 +508,19 @@ public Class getTypeClass() {

@Override
public boolean containsAttributeDefinition(ItemPathType pathType) {
return getDefinitionsStream()
return getRefinedObjectClassDefinitionsStream()
.filter(def -> containsAttributeDefinition(pathType))
.findAny()
.isPresent();
}

private Stream<RefinedObjectClassDefinition> getDefinitionsStream() {
private Stream<RefinedObjectClassDefinition> getRefinedObjectClassDefinitionsStream() {
return Stream.concat(Stream.of(structuralObjectClassDefinition), auxiliaryObjectClassDefinitions.stream());
}

@Override
public boolean containsAttributeDefinition(QName attributeName) {
return getDefinitionsStream()
return getRefinedObjectClassDefinitionsStream()
.filter(def -> containsAttributeDefinition(attributeName))
.findAny()
.isPresent();
Expand All @@ -533,8 +532,8 @@ public ObjectQuery createShadowSearchQuery(String resourceOid) throws SchemaExce
}

@Override
public PrismObject<ShadowType> createBlankShadow() {
return structuralObjectClassDefinition.createBlankShadow();
public PrismObject<ShadowType> createBlankShadow(RefinedObjectClassDefinition definition) {
return structuralObjectClassDefinition.createBlankShadow(definition);
}

@Override
Expand All @@ -544,17 +543,27 @@ public ResourceShadowDiscriminator getShadowDiscriminator() {

@Override
public Collection<? extends QName> getNamesOfAttributesWithOutboundExpressions() {
throw new UnsupportedOperationException("TODO implement if needed");
Set<QName> names = new HashSet<>();
getRefinedObjectClassDefinitionsStream().forEach(
def -> names.addAll(def.getNamesOfAttributesWithOutboundExpressions())
);
return names;
}

@Override
public Collection<? extends QName> getNamesOfAttributesWithInboundExpressions() {
throw new UnsupportedOperationException("TODO implement if needed");
Set<QName> names = new HashSet<>();
getRefinedObjectClassDefinitionsStream().forEach(
def -> names.addAll(def.getNamesOfAttributesWithInboundExpressions())
);
return names;
}

@Override
public ResourcePasswordDefinitionType getPasswordDefinition() {
throw new UnsupportedOperationException("TODO implement if needed");
public ResourcePasswordDefinitionType getPasswordDefinition() { // TODO what if there is a conflict?
return getRefinedObjectClassDefinitionsStream()
.map(def -> def.getPasswordDefinition())
.findFirst().orElse(null);
}

@NotNull
Expand Down
Expand Up @@ -311,8 +311,8 @@ public boolean isEmpty() {
}

@Override
public PrismObject<ShadowType> createBlankShadow() {
return refinedObjectClassDefinition.createBlankShadow();
public PrismObject<ShadowType> createBlankShadow(RefinedObjectClassDefinition definition) {
return refinedObjectClassDefinition.createBlankShadow(definition);
}

@Override
Expand Down
Expand Up @@ -135,7 +135,11 @@ default Collection<RefinedAssociationDefinition> getEntitlementAssociationDefini
//region Generating and matching artifacts ========================================================
PrismObjectDefinition<ShadowType> getObjectDefinition();

PrismObject<ShadowType> createBlankShadow();
default PrismObject<ShadowType> createBlankShadow() {
return createBlankShadow(this);
}

PrismObject<ShadowType> createBlankShadow(RefinedObjectClassDefinition definition);

ResourceShadowDiscriminator getShadowDiscriminator();

Expand Down
Expand Up @@ -337,7 +337,7 @@ static PrismObjectDefinition<ShadowType> constructObjectDefinition(RefinedObject
}

@Override
public PrismObject<ShadowType> createBlankShadow() {
public PrismObject<ShadowType> createBlankShadow(RefinedObjectClassDefinition definition) {
PrismObject<ShadowType> accountShadow;
try {
accountShadow = getPrismContext().createObject(ShadowType.class);
Expand All @@ -354,7 +354,7 @@ public PrismObject<ShadowType> createBlankShadow() {

// Setup definition
PrismObjectDefinition<ShadowType> newDefinition = accountShadow.getDefinition().cloneWithReplacedDefinition(
ShadowType.F_ATTRIBUTES, toResourceAttributeContainerDefinition());
ShadowType.F_ATTRIBUTES, definition.toResourceAttributeContainerDefinition());
accountShadow.setDefinition(newDefinition);

return accountShadow;
Expand Down
Expand Up @@ -342,6 +342,11 @@ public PrismContainerDefinition<C> getDefinition() {
public void setDefinition(PrismContainerDefinition<C> definition) {
checkMutability();
this.definition = definition;
if (definition != null) {
for (PrismContainerValue<C> value : getValues()) {
value.replaceComplexTypeDefinition(definition.getComplexTypeDefinition());
}
}
}

@Override
Expand Down
Expand Up @@ -1433,6 +1433,12 @@ public ComplexTypeDefinition getComplexTypeDefinition() {
return complexTypeDefinition;
}

// will correctly work only if argument is not null (otherwise the CTD will be determined on next call to getCTD)
void replaceComplexTypeDefinition(ComplexTypeDefinition complexTypeDefinition) {
this.complexTypeDefinition = complexTypeDefinition;
}


private ComplexTypeDefinition determineComplexTypeDefinition() {
PrismContainerable<C> parent = getParent();
ComplexTypeDefinition parentCTD = parent != null && parent.getDefinition() != null ?
Expand Down Expand Up @@ -1485,4 +1491,22 @@ public Class<?> getRealClass() {
public <T> T getRealValue() {
return (T) asContainerable();
}

/**
* Returns a single-valued container (with a single-valued definition) holding just this value.
* @param itemName Item name for newly-created container.
* @return
*/
public PrismContainer<C> asSingleValuedContainer(@NotNull QName itemName) throws SchemaException {
PrismContext prismContext = getPrismContext();
Validate.notNull(prismContext, "Prism context is null");

PrismContainerDefinitionImpl<C> definition = new PrismContainerDefinitionImpl<>(itemName,
getComplexTypeDefinition(), prismContext);
definition.setMaxOccurs(1);

PrismContainer<C> pc = definition.instantiate();
pc.add(clone());
return pc;
}
}
Expand Up @@ -531,6 +531,9 @@ public PrismReferenceValue asReferenceValue() {
public void setupReferenceValue(PrismReferenceValue value) {
referenceValue = value;
}
public String getOid() { // used by some scripts
return referenceValue.getOid();
}
};
}

Expand Down
Expand Up @@ -208,12 +208,7 @@ public Field get(Class c, Method m) {
private Map<Class,Map<String,String>> _findEnumFieldName = Collections.synchronizedMap(new HashMap());

<T> String findEnumFieldName(Class<T> classType, String primValue) {
return find2(_findEnumFieldName, classType, primValue, new Getter2<String,Class,String>() {
@Override
public String get(Class c, String v) {
return findEnumFieldNameUncached(c, v);
}
});
return find2(_findEnumFieldName, classType, primValue, (c, v) -> findEnumFieldNameUncached(c, v));
}

private Map<Class,Map<String,String>> _findEnumFieldValue = Collections.synchronizedMap(new HashMap());
Expand Down Expand Up @@ -567,7 +562,7 @@ private List<String> getPropOrderUncached(Class<? extends Object> beanClass) {
private <T> String findEnumFieldNameUncached(Class classType, T primValue){
for (Field field: classType.getDeclaredFields()) {
XmlEnumValue xmlEnumValue = field.getAnnotation(XmlEnumValue.class);
if (xmlEnumValue != null && xmlEnumValue.value() != null && xmlEnumValue.value().equals(primValue)) {
if (xmlEnumValue != null && xmlEnumValue.value().equals(primValue)) {
return field.getName();
}
}
Expand Down
Expand Up @@ -755,9 +755,9 @@ public void recompute() throws SchemaException {
}

if (base == null && accDelta.isModify()) {
RefinedObjectClassDefinition rAccountDef = getCompositeObjectClassDefinition();
if (rAccountDef != null) {
base = (PrismObject<ShadowType>) rAccountDef.createBlankShadow();
RefinedObjectClassDefinition rOCD = getCompositeObjectClassDefinition();
if (rOCD != null) {
base = rOCD.createBlankShadow();
}
}

Expand Down
Expand Up @@ -32,6 +32,7 @@
import com.evolveum.midpoint.model.common.expression.*;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.polystring.PrismDefaultPolyStringNormalizer;
import com.evolveum.midpoint.schema.SchemaConstantsGenerated;
import com.evolveum.midpoint.schema.util.ObjectResolver;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.exception.*;
Expand Down Expand Up @@ -77,6 +78,7 @@
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
import org.jetbrains.annotations.NotNull;

/**
* @author semancik
Expand Down Expand Up @@ -1212,21 +1214,16 @@ private static <F extends ObjectType> void checkObjectPolicy(LensFocusContext<F>
}
}

public static PrismContainer<AssignmentType> createAssignmentSingleValueContainerClone(AssignmentType assignmentType) throws SchemaException {
PrismContainerValue<AssignmentType> assignmentCVal = assignmentType.asPrismContainerValue();
PrismContainerDefinition<AssignmentType> def = assignmentCVal.getParent().getDefinition().clone();
public static PrismContainer<AssignmentType> createAssignmentSingleValueContainerClone(@NotNull AssignmentType assignmentType) throws SchemaException {
// Make it appear to be single-value. Therefore paths without segment IDs will work.
((PrismContainerDefinitionImpl) def).setMaxOccurs(1);
PrismContainer<AssignmentType> assignmentCont = def.instantiate();
assignmentCont.add(assignmentCVal.clone());
return assignmentCont;
return assignmentType.asPrismContainerValue().asSingleValuedContainer(SchemaConstantsGenerated.C_ASSIGNMENT);
}

public static AssignmentType getAssignmentType(ItemDeltaItem<PrismContainerValue<AssignmentType>,PrismContainerDefinition<AssignmentType>> assignmentIdi, boolean old) {
if (old) {
return ((PrismContainer<AssignmentType>)assignmentIdi.getItemOld()).getValue(0).asContainerable();
return assignmentIdi.getItemOld().getValue(0).asContainerable();
} else {
return ((PrismContainer<AssignmentType>)assignmentIdi.getItemNew()).getValue(0).asContainerable();
return assignmentIdi.getItemNew().getValue(0).asContainerable();
}
}

Expand Down
Expand Up @@ -334,6 +334,7 @@
<ri:cn>jan prvy</ri:cn>
<icfs:name>uid=janko nemenny,ou=people,dc=example,dc=com</icfs:name>
<ri:sn>prvy</ri:sn>
<!--<icfs:password><clearValue>janco</clearValue></icfs:password>-->
<icfs:password>janco</icfs:password>
<ri:givenName>James Jr. unchanged</ri:givenName>
<dj:givenName xmlns:dj="http://midpoint.evolveum.com/xml/ns/samples/localhostOpenDJ">James Jr.</dj:givenName>
Expand Down

0 comments on commit 0c018bc

Please sign in to comment.