public static void setAttribute(PrismObject<ShadowType> account, QName attrName, QName typeName, PrismContext prismContext, String value) throws SchemaException { PrismContainer<Containerable> attributesContainer = account.findContainer(ShadowType.F_ATTRIBUTES); ResourceAttributeDefinition attrDef = ObjectFactory.createResourceAttributeDefinition(attrName, typeName, prismContext); ResourceAttribute attribute = attrDef.instantiate(); attribute.setRealValue(value); attributesContainer.add(attribute); }
public static ResourceAttribute<?> fixAttributePath(ResourceAttribute<?> attribute) throws SchemaException { if (attribute == null) { return null; } if (attribute.getPath().startsWithName(ShadowType.F_ATTRIBUTES)) { return attribute; } ResourceAttribute<?> fixedAttribute = attribute.clone(); ResourceAttributeContainer container = ObjectFactory.createResourceAttributeContainer(ShadowType.F_ATTRIBUTES, null, attribute.getPrismContext()); container.createNewValue().add(fixedAttribute); return fixedAttribute; }
default ResourceAttributeContainerDefinition toResourceAttributeContainerDefinition(QName elementName) { return ObjectFactory.createResourceAttributeContainerDefinition(elementName, this, getPrismContext()); }
setResourceSchema(ObjectFactory.createResourceSchema(getSchemaNamespace(), prismContext)); MutableResourceAttributeDefinition attrDef = ObjectFactory.createResourceAttributeDefinition( attrXsdName, attrXsdType, prismContext); uidDefinition = ObjectFactory.createResourceAttributeDefinition(SchemaConstants.ICFS_UID, DOMUtil.XSD_STRING, prismContext);
private <T> void setAttribute(PrismObject<ShadowType> account, String attrName, T val) throws SchemaException { PrismContainer<Containerable> attrsCont = account.findContainer(ShadowType.F_ATTRIBUTES); ResourceAttribute<T> attr = ObjectFactory.createResourceAttribute( dummyResourceCtl.getAttributeQName(attrName), null, prismContext); attr.setRealValue(val); attrsCont.add(attr); }
protected PrismObject<ShadowType> repoAddShadowFromFile(File file, OperationResult parentResult) throws SchemaException, ObjectAlreadyExistsException, EncryptionException, IOException { OperationResult result = parentResult.createSubresult(AbstractIntegrationTest.class.getName() + ".repoAddShadowFromFile"); result.addParam("file", file.getPath()); LOGGER.debug("addShadowFromFile: {}", file); PrismObject<ShadowType> object = prismContext.parseObject(file); PrismContainer<Containerable> attrCont = object.findContainer(ShadowType.F_ATTRIBUTES); for (PrismProperty<?> attr: attrCont.getValue().getProperties()) { if (attr.getDefinition() == null) { ResourceAttributeDefinition<String> attrDef = ObjectFactory.createResourceAttributeDefinition(attr.getElementName(), DOMUtil.XSD_STRING, prismContext); attr.setDefinition((PrismPropertyDefinition) attrDef); } } addBasicMetadata(object); LOGGER.trace("Adding object:\n{}", object.debugDump()); repoAddObject(object, "from file "+file, result); result.recordSuccess(); return object; }
private void transplantIdentifiers(PrismContainerValue<ShadowAssociationType> association, PrismObject<ShadowType> repoShadow) throws SchemaException { PrismContainer<Containerable> identifiersContainer = association .findContainer(ShadowAssociationType.F_IDENTIFIERS); if (identifiersContainer == null) { ResourceAttributeContainer origContainer = ShadowUtil.getAttributesContainer(repoShadow); identifiersContainer = ObjectFactory.createResourceAttributeContainer(ShadowAssociationType.F_IDENTIFIERS, origContainer.getDefinition(), prismContext); association.add(identifiersContainer); } Collection<ResourceAttribute<?>> identifiers = ShadowUtil.getPrimaryIdentifiers(repoShadow); for (ResourceAttribute<?> identifier : identifiers) { identifiersContainer.add(identifier.clone()); } Collection<ResourceAttribute<?>> secondaryIdentifiers = ShadowUtil .getSecondaryIdentifiers(repoShadow); for (ResourceAttribute<?> identifier : secondaryIdentifiers) { identifiersContainer.add(identifier.clone()); } }
private static void applyObjectClass(PrismObject<? extends ShadowType> shadow, ObjectClassComplexTypeDefinition objectClassDefinition) throws SchemaException { PrismContainer<?> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES); ResourceAttributeContainerDefinition racDef = ObjectFactory.createResourceAttributeContainerDefinition( ShadowType.F_ATTRIBUTES, objectClassDefinition, objectClassDefinition.getPrismContext()); attributesContainer.applyDefinition((PrismContainerDefinition) racDef, true); }
@Test public void test610SearchDummyAccountsNameSubstring() throws Exception { final String TEST_NAME = "test610SearchDummyAccountsNameSubstring"; displayTestTitle(TEST_NAME); // GIVEN Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassFilterPrefix(RESOURCE_DUMMY_OID, new QName(RESOURCE_DUMMY_NAMESPACE, "AccountObjectClass"), prismContext) .and().item(ItemPath.create(ShadowType.F_ATTRIBUTES, SchemaConstants.ICFS_NAME), ObjectFactory.createResourceAttributeDefinition(SchemaConstants.ICFS_NAME, DOMUtil.XSD_STRING, prismContext)) .contains("s") .build(); // WHEN displayWhen(TEST_NAME); SearchResultList<PrismObject<ShadowType>> objects = modelService.searchObjects(ShadowType.class, query, null, task, result); // THEN displayThen(TEST_NAME); result.computeStatus(); TestUtil.assertSuccess(result); display("Found", objects); assertEquals("Wrong number of objects found", 6, objects.size()); }
private void toAssociation(PrismObject<ShadowType> shadow, ShadowAssociationType shadowAssociationType) { shadowAssociationType.setShadowRef(new ObjectReferenceType().oid(shadow.getOid()).type(ShadowType.COMPLEX_TYPE)); // We also need to add identifiers here. Otherwise the delta won't match the shadow association. // And therefore new values won't be computed correctly (MID-4948) // This is not a clean systemic solution. But there was no time for a better solution before 3.9 release. try { ResourceAttributeContainer shadowAttributesContainer = ShadowUtil.getAttributesContainer(shadow); ResourceAttributeContainer identifiersContainer = ObjectFactory.createResourceAttributeContainer( ShadowAssociationType.F_IDENTIFIERS, shadowAttributesContainer.getDefinition(), prismContext); shadowAssociationType.asPrismContainerValue().add(identifiersContainer); Collection<ResourceAttribute<?>> shadowIdentifiers = ShadowUtil.getAllIdentifiers(shadow); for (ResourceAttribute<?> shadowIdentifier : shadowIdentifiers) { identifiersContainer.add(shadowIdentifier.clone()); } } catch (SchemaException e) { // Should not happen throw new SystemException(e.getMessage(), e); } }
@Override public boolean handle(PrismObject<ShadowType> entitlementShadow) { PrismContainerValue<ShadowAssociationType> associationCVal = associationContainer.createNewValue(); associationCVal.asContainerable().setName(associationName); Collection<ResourceAttribute<?>> entitlementIdentifiers = ShadowUtil.getAllIdentifiers(entitlementShadow); try { ResourceAttributeContainer identifiersContainer = ObjectFactory.createResourceAttributeContainer( ShadowAssociationType.F_IDENTIFIERS, entitlementDef.toResourceAttributeContainerDefinition(), prismContext); associationCVal.add(identifiersContainer); identifiersContainer.getValue().addAll(Item.cloneCollection(entitlementIdentifiers)); // Remember the full shadow in user data. This is used later as an optimization to create the shadow in repo identifiersContainer.setUserData(ResourceObjectConverter.FULL_SHADOW_KEY, entitlementShadow); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Processed entitlement-to-subject association for account {} and entitlement {}", ShadowUtil.getHumanReadableName(resourceObject), ShadowUtil.getHumanReadableName(entitlementShadow)); } } catch (SchemaException e) { throw new TunnelException(e); } return true; } };
ResourceAttributeContainer identifiersContainer = ObjectFactory.createResourceAttributeContainer( ShadowAssociationType.F_IDENTIFIERS, entitlementDef.toResourceAttributeContainerDefinition(), prismContext); associationCVal.add(identifiersContainer);