Skip to content

Commit

Permalink
Continuing cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Oct 25, 2016
1 parent 7c5ae43 commit e6f9b98
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 72 deletions.
Expand Up @@ -33,10 +33,7 @@
import org.jetbrains.annotations.NotNull;

import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -136,18 +133,18 @@ public Integer getDisplayOrder() {
}

@Override
public RefinedAttributeDefinition<?> getDescriptionAttribute() {
public <X> RefinedAttributeDefinition<X> getDescriptionAttribute() {
return structuralObjectClassDefinition.getDescriptionAttribute();
}

@Override
public String getHelp() {
return structuralObjectClassDefinition.getHelp();
public <X> RefinedAttributeDefinition<X> getNamingAttribute() {
return structuralObjectClassDefinition.getNamingAttribute();
}

@Override
public RefinedAttributeDefinition<?> getNamingAttribute() {
return structuralObjectClassDefinition.getNamingAttribute();
public String getHelp() {
return structuralObjectClassDefinition.getHelp();
}

@NotNull
Expand Down Expand Up @@ -192,7 +189,7 @@ public boolean isRuntimeSchema() {
}

@Override
public RefinedAttributeDefinition<?> getDisplayNameAttribute() {
public <X> RefinedAttributeDefinition<X> getDisplayNameAttribute() {
return structuralObjectClassDefinition.getDisplayNameAttribute();
}

Expand Down Expand Up @@ -463,12 +460,19 @@ public RefinedAssociationDefinition findEntitlementAssociationDefinition(QName n

@Override
public Collection<? extends QName> getNamesOfAssociationsWithOutboundExpressions() {
throw new UnsupportedOperationException("TODO implement if needed");
return getAssociationDefinitions().stream()
.filter(assocDef -> assocDef.getOutboundMappingType() != null)
.map(a -> a.getName())
.collect(Collectors.toCollection(HashSet::new));
}

@Override
public boolean hasAuxiliaryObjectClass(QName expectedObjectClassName) {
throw new UnsupportedOperationException("TODO implement if needed");
if (structuralObjectClassDefinition.hasAuxiliaryObjectClass(expectedObjectClassName)) {
return true;
}
return auxiliaryObjectClassDefinitions.stream().anyMatch(
def -> QNameUtil.match(expectedObjectClassName, def.getTypeName()));
}

@Override
Expand Down
Expand Up @@ -33,6 +33,10 @@ public interface LayerRefinedObjectClassDefinition extends RefinedObjectClassDef

LayerType getLayer();

@NotNull
@Override
Collection<? extends LayerRefinedAttributeDefinition<?>> getAttributeDefinitions();

@NotNull
@Override
LayerRefinedObjectClassDefinition clone();
Expand Down
Expand Up @@ -19,6 +19,7 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import javax.xml.namespace.QName;

Expand Down Expand Up @@ -58,19 +59,17 @@ private LayerRefinedObjectClassDefinitionImpl(RefinedObjectClassDefinition refin
this.layer = layer;
}

static LayerRefinedObjectClassDefinition wrap(RefinedObjectClassDefinition rAccountDef, LayerType layer) {
if (rAccountDef == null) {
static LayerRefinedObjectClassDefinition wrap(RefinedObjectClassDefinition rOCD, LayerType layer) {
if (rOCD == null) {
return null;
}
return new LayerRefinedObjectClassDefinitionImpl(rAccountDef, layer);
return new LayerRefinedObjectClassDefinitionImpl(rOCD, layer);
}

static List<? extends LayerRefinedObjectClassDefinition> wrapCollection(Collection<? extends RefinedObjectClassDefinition> rAccountDefs, LayerType layer) {
List<LayerRefinedObjectClassDefinition> outs = new ArrayList<LayerRefinedObjectClassDefinition>(rAccountDefs.size());
for (RefinedObjectClassDefinition rAccountDef: rAccountDefs) {
outs.add(wrap(rAccountDef, layer));
}
return outs;
static List<? extends LayerRefinedObjectClassDefinition> wrapCollection(Collection<? extends RefinedObjectClassDefinition> rOCDs, LayerType layer) {
return(rOCDs.stream()
.map(rAccountDef -> wrap(rAccountDef, layer))
.collect(Collectors.toCollection(() -> new ArrayList<>(rOCDs.size()))));
}

@Override
Expand All @@ -94,7 +93,7 @@ public boolean isEmphasized() {
}

@Override
public LayerRefinedAttributeDefinition<?> getDescriptionAttribute() {
public <X> LayerRefinedAttributeDefinition<X> getDescriptionAttribute() {
// TODO optimize
return substituteLayerRefinedAttributeDefinition(refinedObjectClassDefinition.getDescriptionAttribute());
}
Expand All @@ -105,21 +104,18 @@ public List<String> getIgnoredNamespaces() {
return refinedObjectClassDefinition.getIgnoredNamespaces();
}

private LayerRefinedAttributeDefinition<?> substituteLayerRefinedAttributeDefinition(ResourceAttributeDefinition<?> attributeDef) {
LayerRefinedAttributeDefinition<?> rAttrDef = findAttributeDefinition(attributeDef.getName());
return rAttrDef;
private <X> LayerRefinedAttributeDefinition<X> substituteLayerRefinedAttributeDefinition(ResourceAttributeDefinition<?> attributeDef) {
return findAttributeDefinition(attributeDef.getName());
}

private Collection<LayerRefinedAttributeDefinition<?>> substituteLayerRefinedAttributeDefinitionCollection(Collection<? extends RefinedAttributeDefinition<?>> attributes) {
Collection<LayerRefinedAttributeDefinition<?>> retval = new ArrayList<>();
for (RefinedAttributeDefinition<?> rad : attributes) {
retval.add(substituteLayerRefinedAttributeDefinition(rad));
}
return retval;
return attributes.stream()
.map(this::substituteLayerRefinedAttributeDefinition)
.collect(Collectors.toList());
}

@Override
public LayerRefinedAttributeDefinition<?> getNamingAttribute() {
public <X> LayerRefinedAttributeDefinition<X> getNamingAttribute() {
return substituteLayerRefinedAttributeDefinition(refinedObjectClassDefinition.getNamingAttribute());
}

Expand All @@ -128,12 +124,6 @@ public String getNativeObjectClass() {
return refinedObjectClassDefinition.getNativeObjectClass();
}

@Override
public <ID extends ItemDefinition> ID findNamedItemDefinition(@NotNull QName firstName, @NotNull ItemPath rest,
@NotNull Class<ID> clazz) {
return refinedObjectClassDefinition.findNamedItemDefinition(firstName, rest, clazz);
}

@Override
public boolean isAuxiliary() {
return refinedObjectClassDefinition.isAuxiliary();
Expand All @@ -144,12 +134,20 @@ public Integer getDisplayOrder() {
return refinedObjectClassDefinition.getDisplayOrder();
}

// TODO - doesn't return layered definition (should it?)
@Override
public <ID extends ItemDefinition> ID findItemDefinition(@NotNull ItemPath path,
@NotNull Class<ID> clazz) {
return refinedObjectClassDefinition.findItemDefinition(path, clazz);
}

// TODO - doesn't return layered definition (should it?)
@Override
public <ID extends ItemDefinition> ID findNamedItemDefinition(@NotNull QName firstName, @NotNull ItemPath rest,
@NotNull Class<ID> clazz) {
return refinedObjectClassDefinition.findNamedItemDefinition(firstName, rest, clazz);
}

@Override
public boolean isDefaultInAKind() {
return refinedObjectClassDefinition.isDefaultInAKind();
Expand All @@ -176,7 +174,7 @@ public LayerRefinedObjectClassDefinition forLayer(LayerType layerType) {
}

@Override
public LayerRefinedAttributeDefinition<?> getDisplayNameAttribute() {
public <X> LayerRefinedAttributeDefinition<X> getDisplayNameAttribute() {
return substituteLayerRefinedAttributeDefinition(refinedObjectClassDefinition.getDisplayNameAttribute());
}

Expand Down Expand Up @@ -227,19 +225,18 @@ public ResourceAttributeContainer instantiate(QName name) {
return refinedObjectClassDefinition.instantiate(name);
}

@Override
public PrismPropertyDefinition findPropertyDefinition(@NotNull QName name) {
LayerRefinedAttributeDefinition def = findAttributeDefinition(name);
if (def != null) {
return def;
} else {
// actually, can there be properties other than attributes? [mederly]
return LayerRefinedAttributeDefinitionImpl.wrap((RefinedAttributeDefinition) refinedObjectClassDefinition.findPropertyDefinition(name), layer);
}
}
// @Override
// public <T> PrismPropertyDefinition<T> findPropertyDefinition(@NotNull QName name) {
// LayerRefinedAttributeDefinition<T> def = findAttributeDefinition(name);
// if (def != null) {
// return def;
// } else {
// return LayerRefinedAttributeDefinitionImpl.wrap((RefinedAttributeDefinition<T>) refinedObjectClassDefinition.findPropertyDefinition(name), layer);
// }
// }

@Override
public LayerRefinedAttributeDefinition<?> findAttributeDefinition(@NotNull QName elementQName) {
public <X> LayerRefinedAttributeDefinition<X> findAttributeDefinition(@NotNull QName elementQName) {
for (LayerRefinedAttributeDefinition definition : getAttributeDefinitions()) {
if (QNameUtil.match(definition.getName(), elementQName)) {
return definition;
Expand Down
Expand Up @@ -74,13 +74,21 @@ public void add(ItemDefinition<?> definition) {
public Collection<? extends ResourceAttributeDefinition<?>> getPrimaryIdentifiers() {
return identifiers;
}


public void addPrimaryIdentifier(ResourceAttributeDefinition<?> identifier) {
identifiers.add(identifier);
}

@NotNull
@Override
public Collection<? extends ResourceAttributeDefinition<?>> getSecondaryIdentifiers() {
return secondaryIdentifiers;
}


public void addSecondaryIdentifier(ResourceAttributeDefinition<?> identifier) {
secondaryIdentifiers.add(identifier);
}

@Override
public <X> ResourceAttributeDefinition<X> getDescriptionAttribute() {
return descriptionAttribute;
Expand Down
Expand Up @@ -73,7 +73,7 @@ public class TestDeltaConverter extends AbstractSchemaTest {
private static final ItemPath CREDENTIALS_PASSWORD_VALUE_PATH =
new ItemPath(UserType.F_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_VALUE);

@Test(enabled = false)
@Test(enabled = false) // https://jira.evolveum.com/browse/MID-3487
public void testRefWithObject() throws SchemaException, IOException, JAXBException {
System.out.println("===[ testRefWithObject ]====");

Expand Down
Expand Up @@ -174,14 +174,15 @@ public void testRoundTripResource() throws SchemaException {
containerDefinition.setNativeObjectClass("ACCOUNT");
// ... in it ordinary attribute - an identifier
ResourceAttributeDefinitionImpl xloginDef = containerDefinition.createAttributeDefinition("login", DOMUtil.XSD_STRING);
((Collection)containerDefinition.getPrimaryIdentifiers()).add(xloginDef);
containerDefinition.addPrimaryIdentifier(xloginDef);
xloginDef.setNativeAttributeName("LOGIN");
containerDefinition.setDisplayNameAttribute(xloginDef.getName());
// ... and local property with a type from another schema
ResourceAttributeDefinitionImpl xpasswdDef = containerDefinition.createAttributeDefinition("password", ProtectedStringType.COMPLEX_TYPE);
xpasswdDef.setNativeAttributeName("PASSWORD");
// ... property reference
containerDefinition.createAttributeDefinition(SchemaConstants.C_CREDENTIALS, SchemaConstants.C_CREDENTIALS_TYPE);
// TODO this is not a ResourceAttributeDefinition, it cannot be placed here!
//containerDefinition.createAttributeDefinition(SchemaConstants.C_CREDENTIALS, SchemaConstants.C_CREDENTIALS_TYPE);
// ... ignored attribute
ResourceAttributeDefinitionImpl xSepDef = containerDefinition.createAttributeDefinition("sep", DOMUtil.XSD_STRING);
xSepDef.setIgnored(true);
Expand Down Expand Up @@ -225,10 +226,10 @@ public void testRoundTripResource() throws SchemaException {
assertEquals(ProtectedStringType.COMPLEX_TYPE, passwdDef.getTypeName());
assertFalse(passwdDef.isIgnored());

PrismContainerDefinition credDef = newObjectClassDef.findContainerDefinition(new QName(SchemaConstants.NS_C,"credentials"));
assertEquals(new QName(SchemaConstants.NS_C,"credentials"), credDef.getName());
assertEquals(new QName(SchemaConstants.NS_C,"CredentialsType"), credDef.getTypeName());
assertFalse(credDef.isIgnored());
// PrismContainerDefinition credDef = newObjectClassDef.findContainerDefinition(new QName(SchemaConstants.NS_C,"credentials"));
// assertEquals(new QName(SchemaConstants.NS_C,"credentials"), credDef.getName());
// assertEquals(new QName(SchemaConstants.NS_C,"CredentialsType"), credDef.getTypeName());
// assertFalse(credDef.isIgnored());

PrismPropertyDefinition sepDef = newObjectClassDef.findPropertyDefinition(new QName(SCHEMA_NS,"sep"));
assertEquals(new QName(SCHEMA_NS,"sep"), sepDef.getName());
Expand Down
Expand Up @@ -248,9 +248,9 @@ private void assertResourceSchema(ResourceSchema unSchema) {
assertEquals(new QName(SCHEMA_NAMESPACE,"password"), passwdDef.getName());
assertEquals(ProtectedStringType.COMPLEX_TYPE, passwdDef.getTypeName());

PrismContainerDefinition<CredentialsType> credDef = objectClassDef.findContainerDefinition(new QName(SchemaConstants.NS_C,"credentials"));
assertEquals(new QName(SchemaConstants.NS_C,"credentials"), credDef.getName());
assertEquals(new QName(SchemaConstants.NS_C,"CredentialsType"), credDef.getTypeName());
// PrismContainerDefinition<CredentialsType> credDef = objectClassDef.findContainerDefinition(new QName(SchemaConstants.NS_C,"credentials"));
// assertEquals(new QName(SchemaConstants.NS_C,"credentials"), credDef.getName());
// assertEquals(new QName(SchemaConstants.NS_C,"CredentialsType"), credDef.getTypeName());
}

@Test
Expand Down Expand Up @@ -349,7 +349,8 @@ private ResourceSchema createResourceSchema() {
ResourceAttributeDefinitionImpl<String> xpasswdDef = containerDefinition.createAttributeDefinition("password", ProtectedStringType.COMPLEX_TYPE);
xpasswdDef.setNativeAttributeName("PASSWORD");
// ... property reference
containerDefinition.createAttributeDefinition(SchemaConstants.C_CREDENTIALS, SchemaConstants.C_CREDENTIALS_TYPE);
// TODO this should not go here, as it is not a ResourceAttributeDefinition
//containerDefinition.createAttributeDefinition(SchemaConstants.C_CREDENTIALS, SchemaConstants.C_CREDENTIALS_TYPE);

return schema;
}
Expand Down
Expand Up @@ -614,7 +614,7 @@ public CompositeRefinedObjectClassDefinition getCompositeObjectClassDefinition()
if (compositeObjectClassDefinition == null) {
RefinedObjectClassDefinition structuralObjectClassDefinition = getStructuralObjectClassDefinition();
if (structuralObjectClassDefinition != null) {
compositeObjectClassDefinition = new CompositeRefinedObjectClassDefinition(
compositeObjectClassDefinition = new CompositeRefinedObjectClassDefinitionImpl(
structuralObjectClassDefinition, getAuxiliaryObjectClassDefinitions());
}
}
Expand Down
Expand Up @@ -16,11 +16,7 @@

package com.evolveum.midpoint.model.impl.lens.projector;

import com.evolveum.midpoint.common.refinery.CompositeRefinedObjectClassDefinition;
import com.evolveum.midpoint.common.refinery.RefinedAssociationDefinition;
import com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition;
import com.evolveum.midpoint.common.refinery.RefinedResourceSchema;
import com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition;
import com.evolveum.midpoint.common.refinery.*;
import com.evolveum.midpoint.model.api.PolicyViolationException;
import com.evolveum.midpoint.model.api.context.SynchronizationPolicyDecision;
import com.evolveum.midpoint.model.common.mapping.Mapping;
Expand Down Expand Up @@ -323,7 +319,7 @@ public boolean isSourceless() {
throw new IllegalStateException("Structural object class definition for " + discr + " not found in the context, but it should be there");
}

RefinedObjectClassDefinition rOcDef = new CompositeRefinedObjectClassDefinition(
RefinedObjectClassDefinition rOcDef = new CompositeRefinedObjectClassDefinitionImpl(
structuralObjectClassDefinition, auxOcDefs);

if (LOGGER.isTraceEnabled()) {
Expand Down
Expand Up @@ -908,12 +908,11 @@ private void parseResourceSchema(org.identityconnectors.framework.common.objects
if (!hasUidDefinition) {
((ObjectClassComplexTypeDefinitionImpl) ocDef).add(uidDefinition);
}
((Collection<ResourceAttributeDefinition>)ocDef.getPrimaryIdentifiers()).add(uidDefinition);
((ObjectClassComplexTypeDefinitionImpl)ocDef).addPrimaryIdentifier(uidDefinition);
if (uidDefinition != nameDefinition) {
((Collection<ResourceAttributeDefinition>)ocDef.getSecondaryIdentifiers()).add(nameDefinition);
((ObjectClassComplexTypeDefinitionImpl)ocDef).addSecondaryIdentifier(nameDefinition);
}


// Add schema annotations
((ObjectClassComplexTypeDefinitionImpl) ocDef).setNativeObjectClass(objectClassInfo.getType());
((ObjectClassComplexTypeDefinitionImpl) ocDef).setDisplayNameAttribute(nameDefinition.getName());
Expand Down

0 comments on commit e6f9b98

Please sign in to comment.