public PrismContainerValue<?> getExtensionContainerValue() { PrismContainer<?> extension = getExtension(); if (extension == null || extension.getValues().isEmpty()) { return null; } else { return extension.getValue(); } }
public static AssignmentType getAssignmentToBeModified(PrismContainer<AssignmentType> assignmentsOld, Long id) { if (id == null && assignmentsOld.size() == 1) { return assignmentsOld.getValue().asContainerable(); } PrismContainerValue<AssignmentType> value = assignmentsOld.getValue(id); if (value == null) { throw new IllegalStateException("No assignment value with id " + id + " in user old"); } return value.asContainerable(); }
public static <T extends Containerable> PrismContainerValue<T> getFieldContainerValue(PrismContainerValue<?> parent, QName fieldName) { Validate.notNull(parent, "Container value must not be null."); Validate.notNull(fieldName, "Field QName must not be null."); PrismContainer<T> container = parent.findItem(ItemName.fromQName(fieldName), PrismContainer.class); return container != null ? container.getValue() : null; }
private static void mergeExtensionContainers(Item<PrismContainerValue<AssignmentType>,PrismContainerDefinition<AssignmentType>> dstItem, PrismContainer<Containerable> srcExtension) throws SchemaException { if (dstItem == null) { return; } PrismContainer<AssignmentType> dstContainer = (PrismContainer<AssignmentType>) dstItem; if (srcExtension != null && !srcExtension.isEmpty()) { PrismContainer<?> dstExtensionContainer = dstContainer.findOrCreateContainer(AssignmentType.F_EXTENSION); PrismContainerValue<?> dstExtensionContainerValue = dstExtensionContainer.getValues().isEmpty() ? dstExtensionContainer.createNewValue() : dstExtensionContainer.getValue(); ObjectTypeUtil.mergeExtension(dstExtensionContainerValue, srcExtension.getValue()); } }
private boolean isEquivalentAddDelta(PrismObject<ShadowType> object1, PrismObject<ShadowType> object2) { PrismContainer attributes1 = object1.findContainer(ShadowType.F_ATTRIBUTES); PrismContainer attributes2 = object2.findContainer(ShadowType.F_ATTRIBUTES); if (attributes1 == null || attributes2 == null || attributes1.size() != 1 || attributes2.size() != 1) { // suspicious cases return false; } return attributes1.getValue().equivalent(attributes2.getValue()); }
public void setExtensionRealValues(PrismContainerValue<?> containerValue, Map<String, Object> map) throws SchemaException { PrismContainer<Containerable> ext = containerValue.findOrCreateContainer(ObjectType.F_EXTENSION); Map<QName, Object> qnameKeyedMap = new HashMap<>(); map.forEach((uri, value) -> qnameKeyedMap.put(QNameUtil.uriToQName(uri, true), value)); List<Item<?, ?>> items = ObjectTypeUtil.mapToExtensionItems(qnameKeyedMap, ext.getDefinition(), prismContext); for (Item<?, ?> item : items) { ext.getValue().addReplaceExisting(item); } }
private void reconcileProjectionAttributes( LensProjectionContext projCtx, Map<QName, DeltaSetTriple<ItemValueWithOrigin<PrismPropertyValue<?>,PrismPropertyDefinition<?>>>> squeezedAttributes, RefinedObjectClassDefinition rOcDef) throws SchemaException { PrismObject<ShadowType> shadowNew = projCtx.getObjectNew(); PrismContainer attributesContainer = shadowNew.findContainer(ShadowType.F_ATTRIBUTES); Collection<QName> attributeNames = squeezedAttributes != null ? MiscUtil.union(squeezedAttributes.keySet(), attributesContainer.getValue().getPropertyNames()) : attributesContainer.getValue().getPropertyNames(); for (QName attrName : attributeNames) { reconcileProjectionAttribute(attrName, projCtx, squeezedAttributes, rOcDef, shadowNew, attributesContainer); } }
protected void assertNumberOfAttributes(PrismObject<ShadowType> shadow, Integer expectedNumberOfAttributes) { PrismContainer<Containerable> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES); assertNotNull("No attributes in repo shadow "+shadow, attributesContainer); List<Item<?,?>> attributes = attributesContainer.getValue().getItems(); assertFalse("Empty attributes in repo shadow "+shadow, attributes.isEmpty()); if (expectedNumberOfAttributes != null) { assertEquals("Unexpected number of attributes in repo shadow "+shadow, (int)expectedNumberOfAttributes, attributes.size()); } }
public static <T> void assertPropertyValue(PrismContainer<?> container, ItemPath propPath, T... realPropValues) { PrismContainerValue<?> containerValue = container.getValue(); assertSame("Wrong parent for value of container "+container, container, containerValue.getParent()); assertPropertyValue(containerValue, propPath, realPropValues); }
@Deprecated protected void assertPasswordMetadata(PrismObject<UserType> user, boolean create, XMLGregorianCalendar start, XMLGregorianCalendar end, String actorOid, String channel) { PrismContainer<MetadataType> metadataContainer = user.findContainer(PATH_CREDENTIALS_PASSWORD_METADATA); assertNotNull("No password metadata in "+user, metadataContainer); MetadataType metadataType = metadataContainer.getValue().asContainerable(); assertMetadata("password metadata in "+user, metadataType, create, false, start, end, actorOid, channel); }
private PrismValue fixEmptyContainerValue(PrismContainerValue pcv, ItemPath path, PrismObject objectOld) { if (pcv.getId() == null || CollectionUtils.isNotEmpty(pcv.getItems())) { return pcv; } PrismContainer oldContainer = objectOld.findContainer(path); if (oldContainer == null) { return pcv; } PrismContainerValue oldValue = oldContainer.getValue(pcv.getId()); return oldValue != null ? oldValue : pcv; }
protected void assertNumberOfAttributes(PrismObject<ShadowType> shadow, Integer expectedNumberOfAttributes) { PrismContainer<Containerable> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES); assertNotNull("No attributes in repo shadow "+shadow, attributesContainer); List<Item<?,?>> attributes = attributesContainer.getValue().getItems(); assertFalse("Empty attributes in repo shadow "+shadow, attributes.isEmpty()); if (expectedNumberOfAttributes != null) { assertEquals("Unexpected number of attributes in repo shadow "+shadow, (int)expectedNumberOfAttributes, attributes.size()); } }
public static <T> void assertPropertyValueMatch(PrismContainer<?> container, ItemPath propQName, MatchingRule<T> matchingRule, T... realPropValues) throws SchemaException { PrismContainerValue<?> containerValue = container.getValue(); assertSame("Wrong parent for value of container "+container, container, containerValue.getParent()); assertPropertyValueMatch(containerValue, propQName, matchingRule, realPropValues); }
public <CC extends Containerable> PrismContainerValueAsserter<CC,? extends PrismContainerValueAsserter<C,RA>> containerSingle(QName subcontainerQName) { PrismContainer<CC> container = findContainer(subcontainerQName); assertNotNull("No container "+subcontainerQName+" in "+desc(), container); PrismContainerValue<CC> pval = container.getValue(); PrismContainerValueAsserter<CC,PrismContainerValueAsserter<C,RA>> asserter = new PrismContainerValueAsserter<>(pval, this, subcontainerQName.getLocalPart() + " in " + desc()); copySetupTo(asserter); return asserter; }
protected void assertPasswordMetadata(PrismObject<UserType> user, QName credentialType, boolean create, XMLGregorianCalendar start, XMLGregorianCalendar end, String actorOid, String channel) { PrismContainer<MetadataType> metadataContainer = user.findContainer(ItemPath.create(UserType.F_CREDENTIALS, credentialType, PasswordType.F_METADATA)); assertNotNull("No password metadata in "+user, metadataContainer); MetadataType metadataType = metadataContainer.getValue().asContainerable(); assertMetadata("password metadata in "+user, metadataType, create, false, start, end, actorOid, channel); }
@Test public void testFindAssignment() throws SchemaException, SAXException, IOException { final String TEST_NAME = "testFindAssignment"; System.out.println("===[ "+TEST_NAME+" ]==="); // GIVEN ItemPath path = UserType.F_ASSIGNMENT; // WHEN PrismContainer<AssignmentType> container = findUserContainer(path); // THEN PrismContainerValue<AssignmentType> value2 = container.getValue(USER_ASSIGNMENT_2_ID); assertEquals("Wrong value2 description (path="+path+")", "Assignment 2", value2.findProperty(AssignmentType.F_DESCRIPTION).getRealValue()); }
private <C extends Containerable> C resolvePolicyTypeFromSecurityPolicy(Class<C> type, QName path, PrismObject<UserType> user, Task task, OperationResult parentResult) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException { SecurityPolicyType securityPolicyType = getSecurityPolicy(user, task, parentResult); if (securityPolicyType == null) { return null; } PrismContainer<C> container = securityPolicyType.asPrismObject().findContainer(ItemName.fromQName(path)); if (container == null) { return null; } PrismContainerValue<C> containerValue = container.getValue(); parentResult.recordSuccess(); return containerValue.asContainerable(); }
private ObjectDelta createDelta(ResourceType resourceType) throws ScriptExecutionException { PrismContainer<XmlSchemaType> schemaContainer = resourceType.asPrismObject().findContainer(ResourceType.F_SCHEMA); if (schemaContainer == null || schemaContainer.isEmpty()) { return null; } return prismContext.deltaFactory().object().createModificationDeleteContainer( ResourceType.class, resourceType.getOid(), ResourceType.F_SCHEMA, schemaContainer.getValue().clone()); } }
public ShadowAttributesAsserter<R> assertAny() { assertNotNull("No attributes container in "+desc(), getAttributesContainer()); PrismContainerValue<ShadowAttributesType> containerValue = getAttributesContainer().getValue(); assertNotNull("No attributes container avlue in "+desc(), containerValue); assertFalse("No attributes in "+desc(), containerValue.isEmpty()); return this; }
@Test public void testAssignmentExtensionValueProperty() throws Exception { System.out.println("===[ testAssignmentExtensionValueProperty ]==="); // GIVEN PrismContainer<AssignmentType> assignmentExtensionContainer = parseUserAssignmentContainer(); PrismContainerValue<AssignmentType> assignmentExtensionContainerValue = assignmentExtensionContainer.getValue(); // WHEN PrismProperty<String> assignmentExtensionStringProperty = assignmentExtensionContainerValue.findOrCreateProperty(EXTENSION_STRING_TYPE_ELEMENT); // THEN assertNotNull("stringType is null", assignmentExtensionStringProperty); assertNotNull("stringType has no definition", assignmentExtensionStringProperty.getDefinition()); PrismAsserts.assertDefinition(assignmentExtensionStringProperty.getDefinition(), EXTENSION_STRING_TYPE_ELEMENT, DOMUtil.XSD_STRING, 0, -1); }