private static String getMultiStringAttributeValueAsSingle(PrismObject<ShadowType> shadow, QName attrName) { PrismContainer<?> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES); if (attributesContainer == null) { return null; } PrismProperty<String> attribute = attributesContainer.findProperty(ItemName.fromQName(attrName)); if (attribute == null) { return null; } Collection<String> realValues = attribute.getRealValues(); if (realValues == null || realValues.isEmpty()) { return null; } if (realValues.size() > 1) { throw new IllegalStateException("More than one value in attribute "+attrName); } return realValues.iterator().next(); }
public static <T> Collection<T> getAttributeValues(PrismObject<? extends ShadowType> shadow, QName name) { if (shadow == null) { throw new IllegalArgumentException("No shadow"); } PrismContainer<?> attrCont = shadow.findContainer(ShadowType.F_ATTRIBUTES); if (attrCont == null) { return null; } PrismProperty<T> attrProp = attrCont.findProperty(ItemName.fromQName(name)); if (attrProp == null) { return null; } return attrProp.getRealValues(); }
public static String getSingleStringAttributeValue(PrismObject<ShadowType> shadow, QName attrName) { PrismContainer<?> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES); if (attributesContainer == null) { return null; } PrismProperty<String> attribute = attributesContainer.findProperty(ItemName.fromQName(attrName)); if (attribute == null) { return null; } return attribute.getRealValue(); }
@Override public <T> PrismProperty<T> getExtensionProperty(QName propertyName) { if (getExtension() != null) { return getExtension().findProperty(ItemName.fromQName(propertyName)); } else { return null; } }
public static void assertPropertyDefinition(PrismContainer<?> container, QName propertyName, QName type, int minOccurs, int maxOccurs) { PrismProperty<?> findProperty = container.findProperty(ItemName.fromQName(propertyName)); PrismPropertyDefinition<?> definition = findProperty.getDefinition(); assertDefinition(definition, propertyName, type, minOccurs, maxOccurs); }
public <T> T getResourceIcfConfigurationPropertyValue(ResourceType resource, javax.xml.namespace.QName propertyQname) throws SchemaException { if (propertyQname == null) { return null; } PrismContainer<?> configurationProperties = getIcfConfigurationProperties(resource); if (configurationProperties == null) { return null; } PrismProperty<T> property = configurationProperties.findProperty(ItemName.fromQName(propertyQname)); if (property == null) { return null; } return property.getRealValue(); }
public static <T> List<T> getAttributeValues(PrismObject<? extends ShadowType> shadow, QName attrName) { PrismContainer<?> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES); if (attributesContainer == null || attributesContainer.isEmpty()) { return null; } PrismProperty<T> attr = attributesContainer.findProperty(ItemName.fromQName(attrName)); if (attr == null) { return null; } List<T> values = new ArrayList<>(); for (PrismPropertyValue<T> pval : attr.getValues()) { values.add(pval.getValue()); } if (values.isEmpty()) { return null; } return values; }
private Object findSyncTokenObject(Task syncCycle) { Object token = null; PrismProperty<?> tokenProperty = syncCycle.getExtension().findProperty(SchemaConstants.SYNC_TOKEN); if (tokenProperty != null) { Collection<?> values = tokenProperty.getRealValues(); if (values.size() > 1) { throw new IllegalStateException("Too must values in token "+tokenProperty); } token = values.iterator().next(); } return token; }
protected void assertNoAttribute(PrismObject<ResourceType> resource, ShadowType shadow, ItemName attrQname) { PrismContainer<?> attributesContainer = shadow.asPrismObject().findContainer(ShadowType.F_ATTRIBUTES); if (attributesContainer == null || attributesContainer.isEmpty()) { return; } PrismProperty attribute = attributesContainer.findProperty(attrQname); assertNull("Unexpected attribute "+attrQname+" in "+shadow+": "+attribute, attribute); }
public static <T> Collection<T> getExtensionPropertyValues(ObjectType objectType, QName propertyQname) { PrismObject<? extends ObjectType> object = objectType.asPrismObject(); PrismContainer<Containerable> extensionContainer = object.findContainer(ObjectType.F_EXTENSION); if (extensionContainer == null) { return null; } PrismProperty<T> property = extensionContainer.findProperty(ItemName.fromQName(propertyQname)); if (property == null) { return null; } return property.getRealValues(); }
protected void assertNoAttribute(PrismObject<ResourceType> resource, ShadowType shadow, QName attrQname) { PrismContainer<?> attributesContainer = shadow.asPrismObject().findContainer(ShadowType.F_ATTRIBUTES); if (attributesContainer == null || attributesContainer.isEmpty()) { return; } PrismProperty attribute = attributesContainer.findProperty(ItemName.fromQName(attrQname)); assertNull("Unexpected attribute "+attrQname+" in "+shadow+": "+attribute, attribute); }
protected String getIcfUid(PrismObject<ShadowType> shadow) { PrismContainer<Containerable> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES); assertNotNull("Null attributes in "+shadow, attributesContainer); assertFalse("Empty attributes in "+shadow, attributesContainer.isEmpty()); PrismProperty<String> icfUidProp = attributesContainer.findProperty(new ItemName(SchemaConstants.NS_ICF_SCHEMA, "uid")); assertNotNull("No ICF name attribute in "+shadow, icfUidProp); return icfUidProp.getRealValue(); }
protected void assertShadowSecondaryIdentifier(PrismObject<ShadowType> shadow, String expectedIdentifier, ResourceType resourceType, MatchingRule<String> nameMatchingRule) throws SchemaException { RefinedResourceSchema rSchema = RefinedResourceSchemaImpl.getRefinedSchema(resourceType); ObjectClassComplexTypeDefinition ocDef = rSchema.findObjectClassDefinition(shadow.asObjectable().getObjectClass()); ResourceAttributeDefinition idSecDef = ocDef.getSecondaryIdentifiers().iterator().next(); PrismContainer<Containerable> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES); PrismProperty<String> idProp = attributesContainer.findProperty(idSecDef.getName()); assertNotNull("No secondary identifier ("+idSecDef.getName()+") attribute in shadow for "+expectedIdentifier, idProp); if (nameMatchingRule == null) { assertEquals("Unexpected secondary identifier in shadow for "+expectedIdentifier, expectedIdentifier, idProp.getRealValue()); } else { PrismAsserts.assertEquals("Unexpected secondary identifier in shadow for "+expectedIdentifier, nameMatchingRule, expectedIdentifier, idProp.getRealValue()); } }
protected void assertShadowSecondaryIdentifier(PrismObject<ShadowType> shadow, String expectedIdentifier, ResourceType resourceType, MatchingRule<String> nameMatchingRule) throws SchemaException { RefinedResourceSchema rSchema = RefinedResourceSchemaImpl.getRefinedSchema(resourceType); ObjectClassComplexTypeDefinition ocDef = rSchema.findObjectClassDefinition(shadow.asObjectable().getObjectClass()); ResourceAttributeDefinition idSecDef = ocDef.getSecondaryIdentifiers().iterator().next(); PrismContainer<Containerable> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES); PrismProperty<String> idProp = attributesContainer.findProperty(idSecDef.getName()); assertNotNull("No secondary identifier ("+idSecDef.getName()+") attribute in shadow for "+expectedIdentifier, idProp); if (nameMatchingRule == null) { assertEquals("Unexpected secondary identifier in shadow for "+expectedIdentifier, expectedIdentifier, idProp.getRealValue()); } else { PrismAsserts.assertEquals("Unexpected secondary identifier in shadow for "+expectedIdentifier, nameMatchingRule, expectedIdentifier, idProp.getRealValue()); } }
private void assertConfigurationPropertyDefinition(PrismContainer container, String propertyLocalName, QName expectedType, int expectedMinOccurs, int expectedMaxOccurs, String expectedDisplayName, String expectedHelp) { QName propName = new QName(container.getDefinition().getTypeName().getNamespaceURI(),propertyLocalName); PrismProperty prop = container.findProperty(ItemName.fromQName(propName)); assertNotNull("No property "+propName, prop); PrismPropertyDefinition propDef = prop.getDefinition(); assertNotNull("No definition for property "+prop, propDef); assertConfigurationPropertyDefinition(propDef, expectedType, expectedMinOccurs, expectedMaxOccurs, expectedDisplayName, expectedHelp); }
private <O extends ObjectType, T> void assertExtension(PrismObject<O> object, QName propName, T... expectedValues) { PrismContainer<Containerable> extensionContainer = object.findContainer(ObjectType.F_EXTENSION); assertNotNull("No extension container in "+object, extensionContainer); PrismProperty<T> extensionProperty = extensionContainer.findProperty(ItemName.fromQName(propName)); assertNotNull("No extension property "+propName+" in "+object, extensionProperty); PrismAsserts.assertPropertyValues("Values of extension property "+propName, extensionProperty.getValues(), expectedValues); }
protected XMLGregorianCalendar getLastScanTimestamp(String taskOid) throws ObjectNotFoundException, SchemaException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException { PrismObject<TaskType> task = getTask(taskOid); display("Task", task); PrismContainer<?> taskExtension = task.getExtension(); assertNotNull("No task extension", taskExtension); PrismProperty<XMLGregorianCalendar> lastScanTimestampProp = taskExtension.findProperty(SchemaConstants.MODEL_EXTENSION_LAST_SCAN_TIMESTAMP_PROPERTY_NAME); assertNotNull("no lastScanTimestamp property", lastScanTimestampProp); return lastScanTimestampProp.getRealValue(); }
private void assertJackAccountShadow(LensContext<UserType> context) throws ObjectNotFoundException, SchemaException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException { Collection<LensProjectionContext> accountContexts = context.getProjectionContexts(); assertEquals(1, accountContexts.size()); LensProjectionContext accContext = accountContexts.iterator().next(); String accountOid = accContext.getOid(); assertNotNull("No OID in account context "+accContext); PrismObject<ShadowType> newAccount = getShadowModel(accountOid); assertEquals(DEFAULT_INTENT, newAccount.findProperty(ShadowType.F_INTENT).getRealValue()); assertEquals(new QName(ResourceTypeUtil.getResourceNamespace(getDummyResourceType()), "AccountObjectClass"), newAccount.findProperty(ShadowType.F_OBJECT_CLASS).getRealValue()); PrismReference resourceRef = newAccount.findReference(ShadowType.F_RESOURCE_REF); assertEquals(getDummyResourceType().getOid(), resourceRef.getOid()); PrismContainer<?> attributes = newAccount.findContainer(ShadowType.F_ATTRIBUTES); assertEquals("jack", attributes.findProperty(SchemaTestConstants.ICFS_NAME).getRealValue()); assertEquals("Jack Sparrow", attributes.findProperty(new ItemName(ResourceTypeUtil.getResourceNamespace(getDummyResourceType()), "fullname")).getRealValue()); }
@Override public <T extends Objectable> EventResult postMarshall(PrismObject<T> object, Element objectElement, OperationResult objectResult) { System.out.println("Validating resorce:"); System.out.println(object.debugDump()); object.checkConsistence(); PrismContainer<?> extensionContainer = object.getExtension(); PrismProperty<Integer> menProp = extensionContainer.findProperty(new ItemName("http://myself.me/schemas/whatever","menOnChest")); assertNotNull("No men on a dead man chest!", menProp); assertEquals("Wrong number of men on a dead man chest", (Integer)15, menProp.getAnyRealValue()); PrismPropertyDefinition menPropDef = menProp.getDefinition(); assertNotNull("Men on a dead man chest NOT defined", menPropDef); assertEquals("Wrong type for men on a dead man chest definition", DOMUtil.XSD_INT, menPropDef.getTypeName()); assertTrue("Men on a dead man chest definition not dynamic", menPropDef.isDynamic()); return EventResult.cont(); }
private void assertUserElisabethExtension(PrismObject<UserType> user) { PrismContainer<?> extension = user.getExtension(); assertContainerDefinition(extension, "extension", DOMUtil.XSD_ANY, 0, 1); PrismContainerValue<?> extensionValue = extension.getValue(); assertTrue("Extension parent", extensionValue.getParent() == extension); assertNull("Extension ID", extensionValue.getId()); // PrismProperty<String> stringType = extension.findProperty(EXTENSION_STRING_TYPE_ELEMENT); // PrismAsserts.assertPropertyValue(stringType, "BARbar", "FOObar"); // PrismPropertyDefinition stringTypePropertyDef = stringType.getDefinition(); // PrismAsserts.assertDefinition(stringTypePropertyDef, EXTENSION_STRING_TYPE_ELEMENT, DOMUtil.XSD_STRING, 0, -1); // assertNull("'Indexed' attribute on 'stringType' property is not null", stringTypePropertyDef.isIndexed()); PrismProperty<String> secondaryStringType = extension.findProperty(EXTENSION_SECONDARY_SECONDARY_STRING_TYPE_ELEMENT); PrismAsserts.assertPropertyValue(secondaryStringType, "string1"); PrismPropertyDefinition secondaryStringTypePropertyDef = secondaryStringType.getDefinition(); PrismAsserts.assertDefinition(secondaryStringTypePropertyDef, EXTENSION_SINGLE_STRING_TYPE_ELEMENT, DOMUtil.XSD_STRING, 0, -1); assertNull("'Indexed' attribute on 'secondaryStringType' property is not null", secondaryStringTypePropertyDef.isIndexed()); }