public static RefinedResourceSchema parse(PrismObject<ResourceType> resource, PrismContext prismContext) throws SchemaException { return parse(resource.asObjectable(), prismContext); }
public static RefinedResourceSchema getRefinedSchema(PrismObject<ResourceType> resource, PrismContext prismContext) throws SchemaException { if (resource == null){ throw new SchemaException("Could not get refined schema, resource does not exist."); } Object userDataEntry = resource.getUserData(USER_DATA_KEY_REFINED_SCHEMA); if (userDataEntry != null) { if (userDataEntry instanceof RefinedResourceSchema) { return (RefinedResourceSchema)userDataEntry; } else { throw new IllegalStateException("Expected RefinedResourceSchema under user data key "+USER_DATA_KEY_REFINED_SCHEMA+ "in "+resource+", but got "+userDataEntry.getClass()); } } else { RefinedResourceSchema refinedSchema = parse(resource, prismContext); resource.setUserData(USER_DATA_KEY_REFINED_SCHEMA, refinedSchema); return refinedSchema; } }
@Test public void test020ParseFromResourceSimple() throws Exception { final String TEST_NAME = "test020ParseFromResourceSimple"; TestUtil.displayTestTitle(TEST_NAME); // GIVEN PrismContext prismContext = createInitializedPrismContext(); PrismObject<ResourceType> resource = prismContext.parseObject(RESOURCE_SIMPLE_FILE); ResourceType resourceType = resource.asObjectable(); // WHEN RefinedResourceSchema rSchema = RefinedResourceSchemaImpl.parse(resourceType, prismContext); // THEN assertNotNull("Refined schema is null", rSchema); System.out.println("Refined schema"); System.out.println(rSchema.debugDump()); assertRefinedSchema(resourceType, rSchema, null, LayerType.SCHEMA, false, false); }
@Test public void test110ApplyAttributeDefinition() throws Exception { final String TEST_NAME = "test110ApplyAttributeDefinition"; TestUtil.displayTestTitle(TEST_NAME); // GIVEN PrismContext prismContext = createInitializedPrismContext(); PrismObject<ResourceType> resource = prismContext.parseObject(RESOURCE_COMPLEX_FILE); RefinedResourceSchema rSchema = RefinedResourceSchemaImpl.parse(resource, prismContext); System.out.println("Refined schema:"); System.out.println(rSchema.debugDump(1)); RefinedObjectClassDefinition defaultAccountDefinition = rSchema.getDefaultRefinedDefinition(ShadowKindType.ACCOUNT); assertNotNull("No refined default account definition in "+rSchema, defaultAccountDefinition); System.out.println("Refined account definition:"); System.out.println(defaultAccountDefinition.debugDump(1)); PrismObject<ShadowType> accObject = prismContext.parseObject(new File(TEST_DIR_NAME, "account-jack.xml")); PrismContainer<Containerable> attributesContainer = accObject.findContainer(ShadowType.F_ATTRIBUTES); System.out.println("Attributes container:"); System.out.println(attributesContainer.debugDump(1)); // WHEN attributesContainer.applyDefinition((PrismContainerDefinition)defaultAccountDefinition.toResourceAttributeContainerDefinition(), true); // THEN System.out.println("Parsed account:"); System.out.println(accObject.debugDump(1)); assertAccountShadow(accObject, resource, prismContext); }
@Test public void test100ParseAccount() throws Exception { final String TEST_NAME = "test100ParseAccount"; TestUtil.displayTestTitle(TEST_NAME); // GIVEN PrismContext prismContext = createInitializedPrismContext(); PrismObject<ResourceType> resource = prismContext.parseObject(RESOURCE_COMPLEX_FILE); ResourceType resourceType = resource.asObjectable(); RefinedResourceSchema rSchema = RefinedResourceSchemaImpl.parse(resourceType, prismContext); RefinedObjectClassDefinition defaultAccountDefinition = rSchema.getDefaultRefinedDefinition(ShadowKindType.ACCOUNT); assertNotNull("No refined default account definition in "+rSchema, defaultAccountDefinition); PrismObject<ShadowType> accObject = prismContext.parseObject(new File(TEST_DIR_NAME, "account-jack.xml")); // WHEN PrismObjectDefinition<ShadowType> objectDefinition = defaultAccountDefinition.getObjectDefinition(); System.out.println("Refined account definition:"); System.out.println(objectDefinition.debugDump()); accObject.applyDefinition(objectDefinition); // THEN System.out.println("Parsed account:"); System.out.println(accObject.debugDump()); assertAccountShadow(accObject, resource, prismContext); }
@Test public void test130ProtectedAccount() throws Exception { final String TEST_NAME = "test130ProtectedAccount"; TestUtil.displayTestTitle(TEST_NAME); // GIVEN PrismContext prismContext = createInitializedPrismContext(); PrismObject<ResourceType> resource = prismContext.parseObject(RESOURCE_COMPLEX_FILE); ResourceType resourceType = resource.asObjectable(); RefinedResourceSchema rSchema = RefinedResourceSchemaImpl.parse(resourceType, prismContext); assertNotNull("Refined schema is null", rSchema); assertFalse("No account definitions", rSchema.getRefinedDefinitions(ShadowKindType.ACCOUNT).isEmpty()); RefinedObjectClassDefinition rAccount = rSchema.getRefinedDefinition(ShadowKindType.ACCOUNT, (String)null); // WHEN Collection<ResourceObjectPattern> protectedAccounts = rAccount.getProtectedObjectPatterns(); // THEN assertNotNull("Null protectedAccounts", protectedAccounts); 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); }
@Test public void test120CreateShadow() throws Exception { final String TEST_NAME = "test120CreateShadow"; TestUtil.displayTestTitle(TEST_NAME); // GIVEN PrismContext prismContext = createInitializedPrismContext(); PrismObject<ResourceType> resource = prismContext.parseObject(RESOURCE_COMPLEX_FILE); ResourceType resourceType = resource.asObjectable(); RefinedResourceSchema rSchema = RefinedResourceSchemaImpl.parse(resourceType, prismContext); assertNotNull("Refined schema is null", rSchema); assertFalse("No account definitions", rSchema.getRefinedDefinitions(ShadowKindType.ACCOUNT).isEmpty()); RefinedObjectClassDefinition rAccount = rSchema.getRefinedDefinition(ShadowKindType.ACCOUNT, (String)null); // WHEN PrismObject<ShadowType> blankShadow = rAccount.createBlankShadow(); // THEN assertNotNull("No blank shadow", blankShadow); assertNotNull("No prism context in blank shadow", blankShadow.getPrismContext()); PrismObjectDefinition<ShadowType> objectDef = blankShadow.getDefinition(); assertNotNull("Blank shadow has no definition", objectDef); PrismContainerDefinition<?> attrDef = objectDef.findContainerDefinition(ShadowType.F_ATTRIBUTES); assertNotNull("Blank shadow has no definition for attributes", attrDef); assertTrue("Wrong class for attributes definition: "+attrDef.getClass(), attrDef instanceof ResourceAttributeContainerDefinition); }
@Test public void test010ParseFromResourceComplex() throws Exception { final String TEST_NAME = "test010ParseFromResourceComplex"; TestUtil.displayTestTitle(TEST_NAME); // GIVEN PrismContext prismContext = createInitializedPrismContext(); PrismObject<ResourceType> resource = prismContext.parseObject(RESOURCE_COMPLEX_FILE); ResourceType resourceType = resource.asObjectable(); // WHEN TestUtil.displayWhen(TEST_NAME); RefinedResourceSchema rSchema = RefinedResourceSchemaImpl.parse(resourceType, prismContext); // THEN TestUtil.displayThen(TEST_NAME); assertNotNull("Refined schema is null", rSchema); System.out.println("Refined schema"); System.out.println(rSchema.debugDump()); assertRefinedSchema(resourceType, rSchema, null, LayerType.MODEL, true, true); assertLayerRefinedSchema(resourceType, rSchema, LayerType.SCHEMA, LayerType.SCHEMA, true, true); assertLayerRefinedSchema(resourceType, rSchema, LayerType.MODEL, LayerType.MODEL, true, true); assertLayerRefinedSchema(resourceType, rSchema, LayerType.PRESENTATION, LayerType.PRESENTATION, true, true); RefinedObjectClassDefinition rAccount = rSchema.getRefinedDefinition(ShadowKindType.ACCOUNT, (String)null); RefinedAttributeDefinition userPasswordAttribute = rAccount.findAttributeDefinition("userPassword"); assertNotNull("No userPassword attribute", userPasswordAttribute); assertTrue("userPassword not ignored", userPasswordAttribute.isIgnored()); }
RefinedResourceSchema rSchema = RefinedResourceSchemaImpl.parse(resourceType, prismContext);