static RefinedResourceSchema getRefinedSchema(PrismObject<ResourceType> resource) throws SchemaException { return RefinedResourceSchemaImpl.getRefinedSchema(resource); }
static ResourceSchema getResourceSchema(PrismObject<ResourceType> resource, PrismContext prismContext) throws SchemaException { return RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext); } }
public static void setParsedResourceSchemaConditional(ResourceType resourceType, ResourceSchema parsedSchema) { if (hasParsedSchema(resourceType)) { return; } PrismObject<ResourceType> resource = resourceType.asPrismObject(); resource.setUserData(USER_DATA_KEY_PARSED_RESOURCE_SCHEMA, parsedSchema); }
public static RefinedResourceSchema parse(ResourceType resourceType, PrismContext prismContext) throws SchemaException { ResourceSchema originalResourceSchema = getResourceSchema(resourceType, prismContext); if (originalResourceSchema == null) { return null; } String contextDescription = "definition of "+resourceType; RefinedResourceSchemaImpl rSchema = new RefinedResourceSchemaImpl(originalResourceSchema); SchemaHandlingType schemaHandling = resourceType.getSchemaHandling(); if (schemaHandling != null) { parseObjectTypeDefsFromSchemaHandling(rSchema, resourceType, schemaHandling, schemaHandling.getObjectType(), null, prismContext, contextDescription); } parseObjectTypesFromSchema(rSchema, resourceType, prismContext, contextDescription); // We need to parse associations and auxiliary object classes in a second pass. We need to have all object classes parsed before correctly setting association // targets for (RefinedObjectClassDefinition rOcDef: rSchema.getRefinedDefinitions()) { ((RefinedObjectClassDefinitionImpl) rOcDef).parseAssociations(rSchema); ((RefinedObjectClassDefinitionImpl) rOcDef).parseAuxiliaryObjectClasses(rSchema); } // We can parse attributes only after we have all the object class info parsed (including auxiliary object classes) for (RefinedObjectClassDefinition rOcDef: rSchema.getRefinedDefinitions()) { ((RefinedObjectClassDefinitionImpl) rOcDef).parseAttributes(rSchema, contextDescription); } return rSchema; }
RefinedResourceSchemaImpl.getResourceSchema(newResource, prismContext); RefinedResourceSchemaImpl.getRefinedSchema(newResource);
/** * This basically checks if the methods do not die on NPE */ @Test public void test005ParsedSchemaSchemaless() throws Exception { final String TEST_NAME = "test005ParsedSchemaSchemaless"; TestUtil.displayTestTitle(TEST_NAME); // GIVEN OperationResult result = new OperationResult(TestDummySchemaless.class.getName() + "." + TEST_NAME); // THEN // The returned type should have the schema pre-parsed assertNotNull(RefinedResourceSchemaImpl.hasParsedSchema(resourceTypeSchemaless)); // Also test if the utility method returns the same thing ResourceSchema returnedSchema = RefinedResourceSchemaImpl.getResourceSchema(resourceTypeSchemaless, prismContext); display("Parsed resource schema", returnedSchema); assertNull("Unexpected schema after parsing", returnedSchema); }
public static RefinedResourceSchema parse(PrismObject<ResourceType> resource, PrismContext prismContext) throws SchemaException { return parse(resource.asObjectable(), prismContext); }
assertResourceCacheMissesIncrement(0); assertResourceSchemaUnchanged(RefinedResourceSchemaImpl.getResourceSchema(resourceProvisioning, prismContext)); assertRefinedResourceSchemaUnchanged(RefinedResourceSchemaImpl.getRefinedSchema(resourceProvisioning)); assertCounterIncrement(InternalCounters.RESOURCE_SCHEMA_PARSE_COUNT, 0); assertResourceCacheMissesIncrement(0); assertResourceSchemaUnchanged(RefinedResourceSchemaImpl.getResourceSchema(resourceProvisioning, prismContext)); assertRefinedResourceSchemaUnchanged(RefinedResourceSchemaImpl.getRefinedSchema(resourceProvisioning)); assertCounterIncrement(InternalCounters.RESOURCE_SCHEMA_PARSE_COUNT, 0);
@Test public void test022ParsedSchema() throws Exception { final String TEST_NAME = "test022ParsedSchema"; displayTestTitle(TEST_NAME); // GIVEN // THEN // The returned type should have the schema pre-parsed assertNotNull(RefinedResourceSchemaImpl.hasParsedSchema(resourceType)); // Also test if the utility method returns the same thing ResourceSchema returnedSchema = RefinedResourceSchemaImpl.getResourceSchema(resourceType, prismContext); display("Parsed resource schema", returnedSchema); // Check whether it is reusing the existing schema and not parsing it // all over again // Not equals() but == ... we want to really know if exactly the same // object instance is returned assertTrue("Broken caching", returnedSchema == RefinedResourceSchemaImpl.getResourceSchema(resourceType, prismContext)); assertSchemaSanity(returnedSchema, resourceType); rememberResourceSchema(returnedSchema); assertSteadyResource(); }
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; } }
public static RefinedResourceSchema getRefinedSchema(PrismObject<ResourceType> resource) throws SchemaException, ConfigurationException { RefinedResourceSchema refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource); if (refinedSchema == null) { throw new ConfigurationException("No schema for "+resource); } return refinedSchema; }
assertResourceCacheMissesIncrement(0); assertResourceSchemaUnchanged(RefinedResourceSchemaImpl.getResourceSchema(resourceProvisioning, prismContext)); assertRefinedResourceSchemaUnchanged(RefinedResourceSchemaImpl.getRefinedSchema(resourceProvisioning)); assertCounterIncrement(InternalCounters.RESOURCE_SCHEMA_PARSE_COUNT, 0);
public static ResourceSchema getResourceSchema(ResourceType resourceType, PrismContext prismContext) throws SchemaException { PrismObject<ResourceType> resource = resourceType.asPrismObject(); return getResourceSchema(resource, prismContext); }
/** * Make sure that the refined schema haven't destroyed cached resource schema. * Also make sure that the caching in object's user data works well. */ @Test public void test024ParsedSchemaAgain() throws Exception { final String TEST_NAME = "test024ParsedSchemaAgain"; displayTestTitle(TEST_NAME); // GIVEN // THEN // The returned type should have the schema pre-parsed assertNotNull(RefinedResourceSchemaImpl.hasParsedSchema(resourceType)); // Also test if the utility method returns the same thing ResourceSchema returnedSchema = RefinedResourceSchemaImpl.getResourceSchema(resourceType, prismContext); display("Parsed resource schema", returnedSchema); assertSchemaSanity(returnedSchema, resourceType); assertResourceSchemaUnchanged(returnedSchema); assertSteadyResource(); }
@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); }
public RefinedResourceSchema getRefinedResourceSchema() throws SchemaException { if (resource == null) { return null; } return RefinedResourceSchemaImpl.getRefinedSchema(resource, LayerType.MODEL, getNotNullPrismContext()); }
assertResourceCacheMissesIncrement(0); assertResourceSchemaUnchanged(RefinedResourceSchemaImpl.getResourceSchema(resourceProvisioning, prismContext)); assertRefinedResourceSchemaUnchanged(RefinedResourceSchemaImpl.getRefinedSchema(resourceProvisioning)); assertCounterIncrement(InternalCounters.RESOURCE_SCHEMA_PARSE_COUNT, 0); assertResourceCacheMissesIncrement(0); assertResourceSchemaUnchanged(RefinedResourceSchemaImpl.getResourceSchema(resourceProvisioning, prismContext)); assertRefinedResourceSchemaUnchanged(RefinedResourceSchemaImpl.getRefinedSchema(resourceProvisioning)); assertCounterIncrement(InternalCounters.RESOURCE_SCHEMA_PARSE_COUNT, 0);
private ResourceSchema getResourceSchema() throws SchemaException { return RefinedResourceSchemaImpl.getResourceSchema(resource, getNotNullPrismContext()); }
/** * This basically checks if the methods do not die on NPE */ @Test public void test105ParsedSchemaStaticSchema() throws Exception { final String TEST_NAME = "test105ParsedSchemaStaticSchema"; TestUtil.displayTestTitle(TEST_NAME); // GIVEN OperationResult result = new OperationResult(TestDummySchemaless.class.getName() + "." + TEST_NAME); // THEN // The returned type should have the schema pre-parsed assertNotNull(RefinedResourceSchemaImpl.hasParsedSchema(resourceStaticSchema.asObjectable())); // Also test if the utility method returns the same thing ResourceSchema returnedSchema = RefinedResourceSchemaImpl.getResourceSchema(resourceStaticSchema.asObjectable(), prismContext); display("Parsed resource schema", returnedSchema); assertNotNull("Null resource schema", returnedSchema); assertStaticSchemaSanity(returnedSchema); }
@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); }