@SuppressWarnings({ "rawtypes", "unchecked" }) private void applyAfterOperationAttributes(PrismObject<ShadowType> shadow, Collection<ResourceAttribute<?>> resourceAttributesAfterAdd) throws SchemaException { if (resourceAttributesAfterAdd == null) { return; } ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(shadow); for (ResourceAttribute attributeAfter : resourceAttributesAfterAdd) { ResourceAttribute attributeBefore = attributesContainer.findAttribute(attributeAfter.getElementName()); if (attributeBefore != null) { attributesContainer.remove(attributeBefore); } if (!attributesContainer.contains(attributeAfter)) { attributesContainer.add(attributeAfter.clone()); } } }
protected <T> void addAttributeToShadow(PrismObject<ShadowType> shadow, PrismObject<ResourceType> resource, String attrName, T attrValue) throws SchemaException { ResourceAttributeContainer attrs = ShadowUtil.getAttributesContainer(shadow); ResourceAttributeDefinition attrSnDef = attrs.getDefinition().findAttributeDefinition( new ItemName(ResourceTypeUtil.getResourceNamespace(resource), attrName)); ResourceAttribute<T> attr = attrSnDef.instantiate(); attr.setRealValue(attrValue); attrs.add(attr); }
Set<Attribute> convertFromResourceObjectToConnIdAttributes(ResourceAttributeContainer attributesPrism, ObjectClassComplexTypeDefinition ocDef) throws SchemaException { Collection<ResourceAttribute<?>> resourceAttributes = attributesPrism.getAttributes(); return convertFromResourceObjectToConnIdAttributes(resourceAttributes, ocDef); }
return null; ResourceAttribute<String> namingAttribute = attributesContainer.getNamingAttribute(); if (namingAttribute == null || namingAttribute.isEmpty()) { Collection<ResourceAttribute<?>> identifiers = attributesContainer.getPrimaryIdentifiers(); ResourceAttribute<String> nameAttribute = attributesContainer.findAttribute(SchemaConstants.ICFS_NAME); if (nameAttribute == null) { throw new SchemaException("Could not determine shadow name.");
repoAttributesContainer.clear(); Collection<ResourceAttribute<?>> primaryIdentifiers = attributesContainer.getPrimaryIdentifiers(); for (PrismProperty<?> p : primaryIdentifiers) { repoAttributesContainer.add(p.clone()); Collection<ResourceAttribute<?>> secondaryIdentifiers = attributesContainer.getSecondaryIdentifiers(); for (PrismProperty<?> p : secondaryIdentifiers) { repoAttributesContainer.add(p.clone()); if (associationDef.getResourceObjectAssociationType().getDirection() == ResourceObjectAssociationDirectionType.OBJECT_TO_SUBJECT) { QName valueAttributeName = associationDef.getResourceObjectAssociationType().getValueAttribute(); if (repoAttributesContainer.findAttribute(valueAttributeName) == null) { ResourceAttribute<Object> valueAttribute = attributesContainer.findAttribute(valueAttributeName); if (valueAttribute != null) { repoAttributesContainer.add(valueAttribute.clone()); repoShadowType.setObjectClass(attributesContainer.getDefinition().getTypeName());
protected void assertSyncOldShadow(PrismObject<? extends ShadowType> oldShadow, String repoName, Integer expectedNumberOfAttributes) { assertNotNull("Old shadow missing", oldShadow); assertNotNull("Old shadow does not have an OID", oldShadow.getOid()); PrismAsserts.assertClass("old shadow", ShadowType.class, oldShadow); ShadowType oldShadowType = oldShadow.asObjectable(); ResourceAttributeContainer attributesContainer = ShadowUtil .getAttributesContainer(oldShadowType); assertNotNull("No attributes container in old shadow", attributesContainer); Collection<ResourceAttribute<?>> attributes = attributesContainer.getAttributes(); assertFalse("Attributes container is empty", attributes.isEmpty()); if (expectedNumberOfAttributes != null) { assertEquals("Unexpected number of attributes", (int)expectedNumberOfAttributes, attributes.size()); } ResourceAttribute<?> icfsNameAttribute = attributesContainer.findAttribute(SchemaConstants.ICFS_NAME); assertNotNull("No ICF name attribute in old shadow", icfsNameAttribute); assertEquals("Wrong value of ICF name attribute in old shadow", repoName, icfsNameAttribute.getRealValue()); }
ResourceAttributeContainerDefinition attrContDef = attributesContainer.getDefinition(); if (attrContDef != null) { ocDef = attrContDef.getComplexTypeDefinition(); try { if (LOGGER.isTraceEnabled()) { LOGGER.trace("midPoint object before conversion:\n{}", attributesContainer.debugDump()); attributesContainer.getDefinition().getComplexTypeDefinition(), resourceSchema); for (ResourceAttribute<?> identifier: identifiers) { attributesContainer.getValue().addReplaceExisting(identifier); return AsynchronousOperationReturnValue.wrap(attributesContainer.getAttributes(), result);
public static <T> ResourceAttribute<T> getAttribute(PrismObject<? extends ShadowType> shadow, QName attrName) { return getAttributesContainer(shadow).findAttribute(attrName); }
public static ObjectClassComplexTypeDefinition getObjectClassDefinition(ShadowType shadow) { // TODO: maybe we can do something more intelligent here ResourceAttributeContainer attributesContainer = getAttributesContainer(shadow); return attributesContainer.getDefinition().getComplexTypeDefinition(); }
private void assertDeprecatedProtectedAccount(String message, ResourceObjectPattern protectedPattern, String identifierValue, RefinedObjectClassDefinition rAccount) throws SchemaException { Collection<ResourceAttribute<?>> identifiers = protectedPattern.getIdentifiers(); assertNotNull("Null identifiers in "+message, identifiers); assertEquals("Wrong number identifiers in "+message, 1, identifiers.size()); ResourceAttribute<?> identifier = identifiers.iterator().next(); assertNotNull("Null identifier in "+message, identifier); assertEquals("Wrong identifier value in "+message, identifier.getRealValue(), identifierValue); // Try matching PrismObject<ShadowType> shadow = rAccount.getObjectDefinition().instantiate(); ResourceAttributeContainer attributesContainer = ShadowUtil.getOrCreateAttributesContainer(shadow, rAccount); ResourceAttribute<String> confusingAttr1 = createStringAttribute(new QName("http://whatever.com","confuseMe"), "HowMuchWoodWouldWoodchuckChuckIfWoodchuckCouldChudkWood"); attributesContainer.add(confusingAttr1); ResourceAttribute<String> nameAttr = createStringAttribute(SchemaTestConstants.ICFS_NAME, identifierValue); attributesContainer.add(nameAttr); ResourceAttribute<String> confusingAttr2 = createStringAttribute(new QName("http://whatever.com","confuseMeAgain"), "WoodchuckWouldChuckNoWoodAsWoodchuckCannotChuckWood"); attributesContainer.add(confusingAttr2); assertTrue("Test attr not matched in "+message, protectedPattern.matches(shadow, null, relationRegistry)); nameAttr.setRealValue("huhulumululul"); assertFalse("Test attr nonsense was matched in "+message, protectedPattern.matches(shadow, null, relationRegistry)); }
resultShadowType.setObjectClass(resourceAttributesContainer.getDefinition().getTypeName()); ResourceAttributeContainer resultAttibutes = resourceAttributesContainer.clone(); accessChecker.filterGetAttributes(resultAttibutes, ctx.computeCompositeObjectClassDefinition(auxObjectClassQNames), parentResult); resultShadow.add(resultAttibutes); .getAttributesContainer(associationCVal, ShadowAssociationType.F_IDENTIFIERS); Collection<ResourceAttribute<?>> entitlementIdentifiers = identifierContainer .getAttributes(); if (entitlementIdentifiers == null || entitlementIdentifiers.isEmpty()) { throw new IllegalStateException( .getUserData(ResourceObjectConverter.FULL_SHADOW_KEY); if (entitlementShadow == null) { try {
String entryUuid = (String) resourceObject.getPrimaryIdentifier().getValue().getValue(); Entry entry = openDJController.searchAndAssertByEntryUuid(entryUuid); display("Entry before change", entry); ObjectClassComplexTypeDefinition accountDefinition = resourceObject.getDefinition().getComplexTypeDefinition(); Collection<ResourceAttribute<?>> identifiers = resourceObject.getPrimaryIdentifiers();
List<ItemDelta<?, ?>> rv = new ArrayList<>(); ResourceAttributeContainer attributes = ShadowUtil.getAttributesContainer(sourceShadow); ResourceAttributeContainerDefinition attributesDefinition = attributes.getDefinition(); if (attributesDefinition == null) { throw new IllegalStateException("No definition for " + attributes); outstandingInRepo = new ArrayList<>(); for (ResourceAttribute<?> attribute : attributes.getAttributes()) { QName attributeName = attribute.getElementName(); boolean isIdentifier = QNameUtil.matchAny(attributeName, identifiers);
throw new SchemaException("Association attribute '"+assocAttrName+"'defined in entitlement association '"+associationName+"' was not found in schema for "+resourceType); ResourceAttribute<T> assocAttr = attributesContainer.findAttribute(assocAttrName); if (assocAttr == null || assocAttr.isEmpty()) { ShadowAssociationType.F_IDENTIFIERS, entitlementDef.toResourceAttributeContainerDefinition(), prismContext); associationCVal.add(identifiersContainer); identifiersContainer.add(valueAttribute); LOGGER.trace("Assocciation attribute value resolved to valueAtrribute {} and identifiers container {}", valueAttribute, identifiersContainer);
@Test public void test500FetchObject() throws Exception { final String TEST_NAME = "test500FetchObject"; TestUtil.displayTestTitle(this, TEST_NAME); // GIVEN ResourceAttributeContainer resourceObject = createResourceObject( "uid=Teell,ou=People,dc=example,dc=com", "Teell William", "Teell"); OperationResult addResult = new OperationResult(this.getClass().getName() + "." + TEST_NAME); PrismObject<ShadowType> shadow = wrapInShadow(ShadowType.class, resourceObject); // Add a testing object cc.addObject(shadow, null, null, addResult); ObjectClassComplexTypeDefinition accountDefinition = resourceObject.getDefinition().getComplexTypeDefinition(); Collection<ResourceAttribute<?>> identifiers = resourceObject.getPrimaryIdentifiers(); // Determine object class from the schema ResourceObjectIdentification identification = new ResourceObjectIdentification(accountDefinition, identifiers, null); OperationResult result = new OperationResult(this.getClass().getName() + "." + TEST_NAME); // WHEN PrismObject<ShadowType> ro = cc.fetchObject(identification, null, null, result); // THEN AssertJUnit.assertNotNull(ro); System.out.println("Fetched object " + ro); System.out.println("Result:"); System.out.println(result.debugDump()); }
Collection<ResourceAttribute<?>> identifiers = attributesContainer.getPrimaryIdentifiers(); assertNotNull("No identifiers (null) in attributes container in "+accountJackOid, identifiers); assertFalse("No identifiers (empty) in attributes container in "+accountJackOid, identifiers.isEmpty()); ResourceAttribute<String> fullNameAttr = attributesContainer.findAttribute(dummyResourceCtl.getAttributeFullnameQName()); PrismAsserts.assertPropertyValue(fullNameAttr, ACCOUNT_JACK_DUMMY_FULLNAME); ResourceAttributeDefinition<String> fullNameAttrDef = fullNameAttr.getDefinition();
ResourceAttribute<?> simulatedStatusAttribute = null; if (statusCapabilityType.getAttribute() != null) { simulatedStatusAttribute = attributesContainer.findAttribute(statusCapabilityType.getAttribute()); || statusCapabilityType.isIgnoreAttribute()) { if (simulatedStatusAttribute != null) { attributesContainer.remove(simulatedStatusAttribute);
ResourceAttributeContainer attributesContainer = (ResourceAttributeContainer) shadowPrism .findOrCreateContainer(ShadowType.F_ATTRIBUTES); ResourceAttributeContainerDefinition attributesContainerDefinition = attributesContainer.getDefinition(); shadow.setObjectClass(attributesContainerDefinition.getTypeName()); attributesContainer.getValue().add(resourceAttribute); attributesContainer.getValue().add(resourceAttribute); + ocDef); if (attributesContainer.getValue().findItem(uidDefinition.getName()) == null) { ResourceAttribute<String> uidRoa = uidDefinition.instantiate(); uidRoa.setRealValue(uid.getUidValue()); attributesContainer.getValue().add(uidRoa);
static ResourceAttributeContainer convertFromContainer(PrismContainer<?> origAttrContainer, ObjectClassComplexTypeDefinition objectClassDefinition) throws SchemaException { if (origAttrContainer == null || origAttrContainer.getValue() == null) { return null; } QName elementName = origAttrContainer.getElementName(); ResourceAttributeContainer attributesContainer = createEmptyContainer(elementName, objectClassDefinition); for (Item item: origAttrContainer.getValue().getItems()) { if (item instanceof PrismProperty) { PrismProperty<?> property = (PrismProperty)item; QName attributeName = property.getElementName(); ResourceAttributeDefinition attributeDefinition = objectClassDefinition.findAttributeDefinition(attributeName); if (attributeDefinition == null) { throw new SchemaException("No definition for attribute "+attributeName+" in object class "+objectClassDefinition); } ResourceAttribute attribute = new ResourceAttributeImpl(attributeName, attributeDefinition , property.getPrismContext()); for(PrismPropertyValue pval: property.getValues()) { attribute.add(pval.clone()); } attributesContainer.add(attribute); attribute.applyDefinition(attributeDefinition); } else { throw new SchemaException("Cannot process item of type "+item.getClass().getSimpleName()+", attributes can only be properties"); } } return attributesContainer; }
for (ResourceAttribute<?> attribute: attributeContainer.getAttributes()) { QName attrName = attribute.getElementName(); RefinedAttributeDefinition attrDef = objectClassDefinition.findAttributeDefinition(attrName); attributeContainer.remove(attribute);