use of com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType in project midpoint by Evolveum.
the class ResourceCarefulAntUtil method createNewXmlSchemaDef.
private static SchemaDefinitionType createNewXmlSchemaDef(File resourceFile, int iteration, PrismContext prismContext) throws SchemaException {
PrismObject<ResourceType> resource = parseResource(resourceFile, prismContext);
XmlSchemaType schema = resource.asObjectable().getSchema();
SchemaDefinitionType def;
if (schema == null) {
def = new SchemaDefinitionType();
def.getAny().add(DOMUtil.createElement(DOMUtil.XSD_SCHEMA_ELEMENT));
} else {
def = schema.getDefinition();
// TODO: modify it somehow
}
return def;
}
use of com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType in project midpoint by Evolveum.
the class TestJaxbConstruction method testResourceConstruction.
@Test
public void testResourceConstruction() throws Exception {
System.out.println("\n\n ===[ testResourceConstruction ]===\n");
// GIVEN
PrismContext prismContext = PrismTestUtil.getPrismContext();
ResourceType resourceType = new ResourceType();
prismContext.adopt(resourceType);
PrismObject<ResourceType> resource = resourceType.asPrismObject();
assertNotNull("No object definition after adopt", resource.getDefinition());
// name: PolyString
resourceType.setName(new PolyStringType("Môj risórs"));
PrismProperty<PolyString> fullNameProperty = resource.findProperty(ResourceType.F_NAME);
PolyString fullName = fullNameProperty.getRealValue();
assertEquals("Wrong name orig", "Môj risórs", fullName.getOrig());
assertEquals("Wrong name norm", "moj risors", fullName.getNorm());
// description: setting null value
resourceType.setDescription(null);
PrismProperty<String> descriptionProperty = resource.findProperty(UserType.F_DESCRIPTION);
assertNull("Unexpected description property " + descriptionProperty, descriptionProperty);
// description: setting null value
resourceType.setDescription("blah blah");
descriptionProperty = resource.findProperty(UserType.F_DESCRIPTION);
assertEquals("Wrong description value", "blah blah", descriptionProperty.getRealValue());
// description: resetting null value
resourceType.setDescription(null);
descriptionProperty = resource.findProperty(UserType.F_DESCRIPTION);
assertNull("Unexpected description property (after reset) " + descriptionProperty, descriptionProperty);
// Extension
ExtensionType extension = new ExtensionType();
resourceType.setExtension(extension);
resource.checkConsistence();
PrismContainer<Containerable> extensionContainer = resource.findContainer(GenericObjectType.F_EXTENSION);
checkExtension(extensionContainer, "resource extension after setExtension");
checkExtension(extension, "resource extension after setExtension");
// Schema
XmlSchemaType xmlSchemaType = new XmlSchemaType();
CachingMetadataType cachingMetadata = new CachingMetadataType();
cachingMetadata.setSerialNumber("serial123");
xmlSchemaType.setCachingMetadata(cachingMetadata);
resourceType.setSchema(xmlSchemaType);
SchemaDefinitionType schemaDefinition = new SchemaDefinitionType();
Element xsdSchemaElement = DOMUtil.createElement(DOMUtil.XSD_SCHEMA_ELEMENT);
schemaDefinition.getAny().add(xsdSchemaElement);
xmlSchemaType.setDefinition(schemaDefinition);
PrismContainer<Containerable> schemaContainer = resource.findContainer(ResourceType.F_SCHEMA);
assertNotNull("No schema container", schemaContainer);
// TODO
// Schema: null
resourceType.setSchema(null);
schemaContainer = resource.findContainer(ResourceType.F_SCHEMA);
assertNull("Unexpected schema container", schemaContainer);
}
use of com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType in project midpoint by Evolveum.
the class TestJaxbSanity method testUnmarshallAndEqualsResourceSchema.
@Test
public void testUnmarshallAndEqualsResourceSchema() throws JAXBException, SchemaException, FileNotFoundException {
System.out.println("\n\n ===[testUnmarshallAndEqualsResourceSchema]===\n");
// GIVEN
ResourceType resource1Type = JaxbTestUtil.getInstance().unmarshalObject(new File(RESOURCE_OPENDJ_FILENAME), ResourceType.class);
assertNotNull(resource1Type);
SchemaDefinitionType schemaDefinition1 = resource1Type.getSchema().getDefinition();
ResourceType resource2Type = JaxbTestUtil.getInstance().unmarshalObject(new File(RESOURCE_OPENDJ_FILENAME), ResourceType.class);
assertNotNull(resource2Type);
SchemaDefinitionType schemaDefinition2 = resource2Type.getSchema().getDefinition();
// WHEN
boolean equals = schemaDefinition1.equals(schemaDefinition2);
// THEN
assertTrue("Schema definition not equal", equals);
assertEquals("Hashcode does not match", schemaDefinition1.hashCode(), schemaDefinition2.hashCode());
}
use of com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType in project midpoint by Evolveum.
the class ResourceUtils method deleteSchema.
public static void deleteSchema(PrismObject<ResourceType> resource, ModelService modelService, PrismContext prismContext, Task task, OperationResult parentResult) throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, SecurityViolationException {
PrismContainer<XmlSchemaType> schemaContainer = resource.findContainer(ResourceType.F_SCHEMA);
if (schemaContainer != null && schemaContainer.getValue() != null) {
PrismProperty<SchemaDefinitionType> definitionProperty = schemaContainer.findProperty(XmlSchemaType.F_DEFINITION);
if (definitionProperty != null && !definitionProperty.isEmpty()) {
PrismPropertyValue<SchemaDefinitionType> definitionValue = definitionProperty.getValue().clone();
ObjectDelta<ResourceType> deleteSchemaDefinitionDelta = ObjectDelta.createModificationDeleteProperty(ResourceType.class, resource.getOid(), new ItemPath(ResourceType.F_SCHEMA, XmlSchemaType.F_DEFINITION), prismContext, // TODO ...or replace with null?
definitionValue.getValue());
// delete schema
modelService.executeChanges(Collections.<ObjectDelta<? extends ObjectType>>singleton(deleteSchemaDefinitionDelta), null, task, parentResult);
}
}
}
use of com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType in project midpoint by Evolveum.
the class PrismUnmarshaller method parseProperty.
@NotNull
private <T> PrismProperty<T> parseProperty(@NotNull XNode node, @NotNull QName itemName, @Nullable PrismPropertyDefinition<T> itemDefinition, @NotNull ParsingContext pc) throws SchemaException {
Validate.isTrue(!(node instanceof RootXNode));
PrismProperty<T> property = itemDefinition != null ? itemDefinition.instantiate() : new PrismProperty<>(itemName, prismContext);
if (node instanceof ListXNode && !node.isHeterogeneousList()) {
ListXNode listNode = (ListXNode) node;
if (itemDefinition != null && !itemDefinition.isMultiValue() && listNode.size() > 1) {
throw new SchemaException("Attempt to store multiple values in single-valued property " + itemName);
}
for (XNode subNode : listNode) {
PrismPropertyValue<T> pval = parsePropertyValue(subNode, itemDefinition, pc);
addItemValueIfPossible(property, pval, pc);
}
} else if (node instanceof MapXNode || node instanceof PrimitiveXNode || node.isHeterogeneousList()) {
PrismPropertyValue<T> pval = parsePropertyValue(node, itemDefinition, pc);
if (pval != null) {
property.add(pval);
}
} else if (node instanceof SchemaXNode) {
SchemaDefinitionType schemaDefType = getBeanUnmarshaller().unmarshalSchemaDefinitionType((SchemaXNode) node);
@SuppressWarnings("unchecked") PrismPropertyValue<T> val = new PrismPropertyValue(schemaDefType);
addItemValueIfPossible(property, val, pc);
} else {
throw new IllegalArgumentException("Cannot parse property from " + node);
}
return property;
}
Aggregations