Skip to content

Commit

Permalink
Schema cleanup for 4.0, removing planned items, fixing some tests, WI…
Browse files Browse the repository at this point in the history
…P (MID-5052)
  • Loading branch information
semancik committed Aug 27, 2019
1 parent 79b9c75 commit 2b31036
Show file tree
Hide file tree
Showing 138 changed files with 1,249 additions and 3,869 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2014 Evolveum
* Copyright (c) 2010-2019 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 @@ -42,7 +42,8 @@
*
*/
public class ResourceObjectPattern implements Serializable {

private static final long serialVersionUID = 1L;

private Collection<ResourceAttribute<?>> identifiers;
private RefinedObjectClassDefinition rOcDef;
private ObjectFilter objectFilter;
Expand All @@ -51,17 +52,6 @@ public ResourceObjectPattern(RefinedObjectClassDefinition rOcDef) {
this.rOcDef = rOcDef;
}

public Collection<ResourceAttribute<?>> getIdentifiers() {
if (identifiers == null) {
identifiers = new ArrayList<>();
}
return identifiers;
}

public void addIdentifier(ResourceAttribute<?> identifier) {
getIdentifiers().add(identifier);
}

public static boolean matches(PrismObject<ShadowType> shadowToMatch,
Collection<ResourceObjectPattern> protectedAccountPatterns, MatchingRuleRegistry matchingRuleRegistry,
RelationRegistry relationRegistry) throws SchemaException {
Expand Down Expand Up @@ -115,6 +105,10 @@ private boolean matches(ResourceAttribute<?> identifier, ResourceAttribute<?> at
return matchingRule.match(identifier.getRealValue(), attributeToMatch.getRealValue());
}

public ObjectFilter getObjectFilter() {
return objectFilter;
}

public void addFilter(ObjectFilter filter) {
this.objectFilter = filter;
}
Expand Down

This file was deleted.

This file was deleted.

Expand Up @@ -118,6 +118,10 @@ public ItemProcessing getProcessing() {
return structuralObjectClassDefinition.getProcessing();
}

public List<SchemaMigration> getSchemaMigrations() {
return structuralObjectClassDefinition.getSchemaMigrations();
}

@Override
public boolean isEmphasized() {
return structuralObjectClassDefinition.isEmphasized();
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2018 Evolveum
* Copyright (c) 2010-2019 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 @@ -156,10 +156,16 @@ public ItemProcessing getProcessing() {
return refinedAttributeDefinition.getProcessing(layer);
}


@Override
public ItemProcessing getProcessing(LayerType layer) {
return refinedAttributeDefinition.getProcessing(layer);
}

@Override
public List<SchemaMigration> getSchemaMigrations() {
return refinedAttributeDefinition.getSchemaMigrations();
}

@Override
public boolean canModify() {
Expand Down
Expand Up @@ -95,6 +95,11 @@ public boolean isIgnored() {
public ItemProcessing getProcessing() {
return refinedObjectClassDefinition.getProcessing();
}

@Override
public List<SchemaMigration> getSchemaMigrations() {
return refinedObjectClassDefinition.getSchemaMigrations();
}

public boolean isEmphasized() {
return refinedObjectClassDefinition.isEmphasized();
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2018 Evolveum
* Copyright (c) 2010-2019 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 @@ -794,13 +794,16 @@ public boolean isIgnored() {
return originalObjectClassDefinition.isIgnored();
}



@Override
public ItemProcessing getProcessing() {
return originalObjectClassDefinition.getProcessing();
}

@Override
public List<SchemaMigration> getSchemaMigrations() {
return originalObjectClassDefinition.getSchemaMigrations();
}

@Override
public boolean isAbstract() {
return originalObjectClassDefinition.isAbstract();
Expand Down Expand Up @@ -903,9 +906,6 @@ static RefinedObjectClassDefinition parse(ResourceObjectTypeDefinitionType entTy
RefinedObjectClassDefinition rObjectClassDef = parseRefinedObjectClass(entTypeDefType,
resourceType, rSchema, prismContext, kind, intent, kind.value(), kind.value() + " type definition '"+intent+"' in " + contextDescription);

if (entTypeDefType.getPagedSearches() != null) {
LOGGER.warn("PagedSearches element is no more supported and is ignored. Use PagedSearchCapabilityType instead. In {}", resourceType);
}
return rObjectClassDef;
}

Expand All @@ -921,33 +921,13 @@ private static ResourceObjectPattern convertToPattern(ResourceObjectPatternType
RefinedObjectClassDefinition rAccountDef, PrismContext prismContext) throws SchemaException {
ResourceObjectPattern resourceObjectPattern = new ResourceObjectPattern(rAccountDef);
SearchFilterType filterType = patternType.getFilter();
if (filterType != null) {
if (filterType == null) {
throw new SchemaException("No filter in resource object pattern");
} else {
ObjectFilter filter = prismContext.getQueryConverter().parseFilter(filterType, rAccountDef.getObjectDefinition());
resourceObjectPattern.addFilter(filter);
return resourceObjectPattern;
}

// Deprecated
if (patternType.getName() != null) {
RefinedAttributeDefinition attributeDefinition = rAccountDef.findAttributeDefinition(new QName(SchemaConstants.NS_ICF_SCHEMA,"name"));
if (attributeDefinition == null) {
throw new SchemaException("No ICF NAME attribute in schema as specified in the definition of protected objects (this is deprecated syntax anyway, convert it to filter)");
}
ResourceAttribute<String> attr = attributeDefinition.instantiate();
attr.setRealValue(patternType.getName());
resourceObjectPattern.addIdentifier(attr);
} else if (patternType.getUid() != null) {
RefinedAttributeDefinition attributeDefinition = rAccountDef.findAttributeDefinition(new QName(SchemaConstants.NS_ICF_SCHEMA,"uid"));
if (attributeDefinition == null) {
throw new SchemaException("No ICF UID attribute in schema as specified in the definition of protected objects (this is deprecated syntax anyway, convert it to filter)");
}
ResourceAttribute<String> attr = attributeDefinition.instantiate();
attr.setRealValue(patternType.getUid());
resourceObjectPattern.addIdentifier(attr);
} else {
throw new SchemaException("No filter and no deprecated name/uid in resource object pattern");
}
return resourceObjectPattern;
}

public static RefinedObjectClassDefinition parseFromSchema(ObjectClassComplexTypeDefinition objectClassDef, ResourceType resourceType,
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2017 Evolveum
* Copyright (c) 2010-2019 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 @@ -34,6 +34,8 @@

import com.evolveum.midpoint.prism.ConsistencyCheckScope;
import com.evolveum.midpoint.prism.path.ItemName;
import com.evolveum.midpoint.prism.query.EqualFilter;
import com.evolveum.midpoint.prism.query.ObjectFilter;
import com.evolveum.midpoint.prism.util.PrismTestUtil;

import com.evolveum.midpoint.schema.RelationRegistry;
Expand All @@ -54,6 +56,8 @@
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismObjectDefinition;
import com.evolveum.midpoint.prism.impl.match.MatchingRuleRegistryFactory;
import com.evolveum.midpoint.prism.match.MatchingRuleRegistry;
import com.evolveum.midpoint.prism.util.PrismAsserts;
import com.evolveum.midpoint.schema.MidPointPrismContextFactory;
import com.evolveum.midpoint.schema.constants.MidPointConstants;
Expand Down Expand Up @@ -90,11 +94,13 @@ public class TestRefinedSchema {
private static final QName OBJECT_CLASS_INETORGPERSON_QNAME = new QName(MidPointConstants.NS_RI, "inetOrgPerson");

private final RelationRegistry relationRegistry = new RelationRegistryDummyImpl();
private MatchingRuleRegistry matchingRuleRegistry;

@BeforeSuite
public void setup() throws SchemaException, SAXException, IOException {
PrettyPrinter.setDefaultNamespacePrefix(MidPointConstants.NS_MIDPOINT_PUBLIC_PREFIX);
resetPrismContext(MidPointPrismContextFactory.FACTORY);
matchingRuleRegistry = MatchingRuleRegistryFactory.createRegistry();
}

@Test
Expand Down Expand Up @@ -457,8 +463,8 @@ public void test130ProtectedAccount() throws Exception {
assertFalse("Empty protectedAccounts", protectedAccounts.isEmpty());
assertEquals("Unexpected number of protectedAccounts", 2, protectedAccounts.size());
Iterator<ResourceObjectPattern> iterator = protectedAccounts.iterator();
assertDeprecatedProtectedAccount("first protected account", iterator.next(), "uid=idm,ou=Administrators,dc=example,dc=com", rAccount);
assertDeprecatedProtectedAccount("second protected account", iterator.next(), "uid=root,ou=Administrators,dc=example,dc=com", rAccount);
assertProtectedAccount("first protected account", iterator.next(), "uid=idm,ou=Administrators,dc=example,dc=com", rAccount);
assertProtectedAccount("second protected account", iterator.next(), "uid=root,ou=Administrators,dc=example,dc=com", rAccount);
}

private void assertAttributeDefs(ResourceAttributeContainerDefinition attrsDef, ResourceType resourceType, LayerType sourceLayer, LayerType validationLayer) {
Expand Down Expand Up @@ -532,13 +538,12 @@ private void assertAttributeDef(Collection<? extends RefinedAttributeDefinition>
Assert.fail("Attribute " + name + " not found");
}

private void assertDeprecatedProtectedAccount(String message, ResourceObjectPattern protectedPattern, String identifierValue, RefinedObjectClassDefinition rAccount) throws SchemaException {
Collection<ResourceAttribute<?>> identifiers = protectedPattern.getIdentifiers();
assertNotNull("Null identifiers in "+message, identifiers);
assertEquals("Wrong number identifiers in "+message, 1, identifiers.size());
ResourceAttribute<?> identifier = identifiers.iterator().next();
assertNotNull("Null identifier in "+message, identifier);
assertEquals("Wrong identifier value in "+message, identifier.getRealValue(), identifierValue);
private void assertProtectedAccount(String message, ResourceObjectPattern protectedPattern, String identifierValue, RefinedObjectClassDefinition rAccount) throws SchemaException {
ObjectFilter filter = protectedPattern.getObjectFilter();
assertNotNull("Null objectFilter in "+message, filter);
assertTrue("Wrong filter class "+filter.getClass().getSimpleName()+" in "+message, filter instanceof EqualFilter);
assertNotNull("Null filter path in "+message, ((EqualFilter)filter).getPath());
assertEquals("Wrong filter value in "+message, identifierValue, ((EqualFilter<String>)filter).getValues().iterator().next().getValue());

// Try matching
PrismObject<ShadowType> shadow = rAccount.getObjectDefinition().instantiate();
Expand All @@ -550,9 +555,9 @@ private void assertDeprecatedProtectedAccount(String message, ResourceObjectPatt
ResourceAttribute<String> confusingAttr2 = createStringAttribute(new QName("http://whatever.com","confuseMeAgain"), "WoodchuckWouldChuckNoWoodAsWoodchuckCannotChuckWood");
attributesContainer.add(confusingAttr2);

assertTrue("Test attr not matched in "+message, protectedPattern.matches(shadow, null, relationRegistry));
assertTrue("Test attr not matched in "+message, protectedPattern.matches(shadow, matchingRuleRegistry, relationRegistry));
nameAttr.setRealValue("huhulumululul");
assertFalse("Test attr nonsense was matched in "+message, protectedPattern.matches(shadow, null, relationRegistry));
assertFalse("Test attr nonsense was matched in "+message, protectedPattern.matches(shadow, matchingRuleRegistry, relationRegistry));
}

private ResourceAttribute<String> createStringAttribute(QName attrName, String value) {
Expand Down
4 changes: 2 additions & 2 deletions infra/common/src/test/resources/refinery/account-jack.xml
Expand Up @@ -17,7 +17,7 @@

<!-- Object modification description that is changing user "jack" by adding a new account -->

<account oid="10000000-0000-0000-0000-000000000003"
<shadow oid="10000000-0000-0000-0000-000000000003"
xmlns='http://midpoint.evolveum.com/xml/ns/public/common/common-3'
xmlns:icfs="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/resource-schema-3"
xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance/10000000-0000-0000-0000-000000000003"
Expand All @@ -39,4 +39,4 @@
<ri:sn>Sparrow</ri:sn>
<ri:userPassword>ZGVhZCBtZW4gdGVsbCBubyB0YWxlcwo=</ri:userPassword>
</attributes>
</account>
</shadow>

0 comments on commit 2b31036

Please sign in to comment.