public static void setConnectorXsdSchema(PrismObject<ConnectorType> connector, Element xsdElement) { PrismContainer<XmlSchemaType> schemaContainer; try { schemaContainer = connector.findOrCreateContainer(ConnectorType.F_SCHEMA); PrismProperty<SchemaDefinitionType> definitionProperty = schemaContainer.findOrCreateProperty(XmlSchemaType.F_DEFINITION); ObjectTypeUtil.setXsdSchemaDefinition(definitionProperty, xsdElement); } catch (SchemaException e) { // Should not happen throw new IllegalStateException("Internal schema error: "+e.getMessage(),e); } }
public static void setResourceXsdSchema(PrismObject<ResourceType> resource, Element xsdElement) { try { PrismContainer<XmlSchemaType> schemaContainer = resource.findOrCreateContainer(ResourceType.F_SCHEMA); PrismProperty<SchemaDefinitionType> definitionProperty = schemaContainer.findOrCreateProperty(XmlSchemaType.F_DEFINITION); ObjectTypeUtil.setXsdSchemaDefinition(definitionProperty, xsdElement); } catch (SchemaException e) { // Should not happen throw new IllegalStateException("Internal schema error: "+e.getMessage(),e); } }
protected void addAssignment(PrismObject<UserType> user, Long id, String description) throws SchemaException { PrismContainer<AssignmentType> assignment = user.findOrCreateContainer(UserType.F_ASSIGNMENT); PrismContainerValue<AssignmentType> assignmentValue = assignment.createNewValue(); populateAssignmentValue(assignmentValue, id, description); }
PrismObjectDefinition<UserType> userDefinition = getFooSchema(ctx).findObjectDefinitionByElementName(new QName(NS_FOO,"user")); PrismObject<UserType> user = userDefinition.instantiate(); PrismContainer<AssignmentType> assignmentContainer = user.findOrCreateContainer(UserType.F_ASSIGNMENT); PerfRecorder recorderCreateNewValue = new PerfRecorder("createNewValue"); PerfRecorder recorderFindOrCreateProperty = new PerfRecorder("findOrCreateProperty");
private ShadowType createShadow(UserType user, String resourceOid, int resourceId) throws SchemaException { ShadowType shadow = new ShadowType(); shadow.setOid(UUID.randomUUID().toString()); final String DN = "cn=" + user.getName().getOrig() + ",ou=resource" + resourceId + ",dc=example,dc=com"; shadow.setName(createPoly(DN)); shadow.setResourceRef(createRef(resourceOid, ResourceType.COMPLEX_TYPE)); shadow.setKind(ShadowKindType.ACCOUNT); shadow.setIntent("standardAccount"); shadow.setObjectClass(new QName("http://midpoint.evolveum.com/xml/ns/public/resource/instance/" + resourceOid, "AccountObjectClass")); PrismObject<ShadowType> prism = shadow.asPrismObject(); prismContext.adopt(prism); PrismContainer attributes = prism.findOrCreateContainer(ShadowType.F_ATTRIBUTES); PrismProperty property = attributes.findOrCreateProperty(SchemaConstants.ICFS_UID); property.setRealValue(UUID.randomUUID().toString()); property = attributes.findOrCreateProperty(SchemaConstants.ICFS_NAME); property.setRealValue(DN); return shadow; }
shadow1Type.setFailedOperationType(FailedOperationTypeType.ADD); shadow1Type.getAuxiliaryObjectClass().add(new QName(NS_TEST_RI, "foo")); PrismContainer<Containerable> shadow1Attrs = shadow1.findOrCreateContainer(ShadowType.F_ATTRIBUTES); shadow2Type.getAuxiliaryObjectClass().add(new QName(NS_TEST_RI, "foo")); shadow2Type.getAuxiliaryObjectClass().add(new QName(NS_TEST_RI, "bar")); PrismContainer<Containerable> shadow2Attrs = shadow2.findOrCreateContainer(ShadowType.F_ATTRIBUTES);
private <O extends ObjectType> void applyLastProvisioningTimestamp(LensContext<O> context, ObjectDelta<O> focusDelta) throws SchemaException { if (!context.hasProjectionChange()) { return; } if (focusDelta.isAdd()) { PrismObject<O> objectToAdd = focusDelta.getObjectToAdd(); PrismContainer<MetadataType> metadataContainer = objectToAdd.findOrCreateContainer(ObjectType.F_METADATA); metadataContainer.getRealValue().setLastProvisioningTimestamp(clock.currentTimeXMLGregorianCalendar()); } else if (focusDelta.isModify()) { PropertyDelta<XMLGregorianCalendar> provTimestampDelta = prismContext.deltaFactory().property().createModificationReplaceProperty( ItemPath.create(ObjectType.F_METADATA, MetadataType.F_LAST_PROVISIONING_TIMESTAMP), context.getFocusContext().getObjectDefinition(), clock.currentTimeXMLGregorianCalendar()); focusDelta.addModification(provTimestampDelta); } }
@Test public void test990AddResourceWithEmptyConnectorConfiguration() throws Exception { OperationResult result = new OperationResult("test990AddResourceWithEmptyConnectorConfiguration"); PrismObject<ResourceType> prismResource = getPrismContext().getSchemaRegistry().findObjectDefinitionByCompileTimeClass(ResourceType.class).instantiate(); PolyStringType name = new PolyStringType(); name.setOrig("Test Resource"); name.setNorm("test resource"); prismResource.asObjectable().setName(name); prismResource .findOrCreateContainer(ResourceType.F_CONNECTOR_CONFIGURATION) .findOrCreateContainer(SchemaConstants.ICF_CONFIGURATION_PROPERTIES) .createNewValue(); System.out.println("Original data before saving: " + prismResource.debugDump()); String oid = repositoryService.addObject(prismResource, null, result); PrismObject<ResourceType> fetchedResource = repositoryService.getObject(ResourceType.class, oid, null, result); System.out.println("Original data after saving: " + prismResource.debugDump()); System.out.println("Fetched data: " + fetchedResource.debugDump()); AssertJUnit.assertEquals(prismResource, fetchedResource); }
@Test public void test550UseVariables() throws Exception { final String TEST_NAME = "test550UseVariables"; TestUtil.displayTestTitle(this, TEST_NAME); // GIVEN Task task = taskManager.createTaskInstance(DOT_CLASS + TEST_NAME); OperationResult result = task.getResult(); ExecuteScriptType executeScript = parseRealValue(USE_VARIABLES_FILE); PrismContainer<Containerable> taskExtension = task.getTaskPrismObject().findOrCreateContainer(TaskType.F_EXTENSION); taskExtension .findOrCreateProperty(USER_NAME_TASK_EXTENSION_PROPERTY) .addRealValue("user1"); taskExtension .findOrCreateProperty(STUDY_GROUP_TASK_EXTENSION_PROPERTY) .addRealValues("group1", "group2", "group3"); // WHEN ExecutionContext output = scriptingExpressionEvaluator.evaluateExpression(executeScript, emptyMap(), false, task, result); // THEN dumpOutput(output, result); result.computeStatus(); PipelineData data = output.getFinalOutput(); assertEquals("Unexpected # of items in output", 1, data.getData().size()); String returned = data.getData().get(0).getValue().getRealValue(); assertEquals("Wrong returned status", "ok", returned); }
assertPropertyValue(user.findContainer(UserType.F_EXTENSION), new ItemName(NS_FOO, "bar"), "BAR"); PrismProperty<ProtectedStringType> password = user.findOrCreateContainer(UserType.F_EXTENSION).findProperty(new ItemName(NS_FOO, "password")); assertNotNull(password); assertPropertyValue(user.findOrCreateContainer(UserType.F_EXTENSION), new ItemName(NS_FOO, "num"), 42); PrismProperty<?> multi = user.findOrCreateContainer(UserType.F_EXTENSION).findProperty(new ItemName(NS_FOO, "multi")); assertEquals(3, multi.getValues().size());
PrismContainer<Containerable> meleeContextContainer = userJack.findOrCreateContainer(ItemPath.create(UserType.F_EXTENSION, EXTENSION_MELEE_CONTEXT_ELEMENT)); PrismReference opponentRef = meleeContextContainer.findOrCreateReference(EXTENSION_MELEE_CONTEXT_OPPONENT_REF_ELEMENT); PrismObject<UserType> userBarbossa = prismContext.parseObject(getFile(USER_BARBOSSA_FILE_BASENAME));
.findOrCreateContainer(ShadowType.F_ATTRIBUTES); ResourceAttributeContainerDefinition attributesContainerDefinition = attributesContainer.getDefinition(); shadow.setObjectClass(attributesContainerDefinition.getTypeName());
private PrismObject<ShadowType> createAccountShadow(String username) throws SchemaException { ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext); ObjectClassComplexTypeDefinition defaultAccountDefinition = resourceSchema.findDefaultObjectClassDefinition(ShadowKindType.ACCOUNT); ShadowType shadowType = new ShadowType(); PrismTestUtil.getPrismContext().adopt(shadowType); shadowType.setName(PrismTestUtil.createPolyStringType(username)); ObjectReferenceType resourceRef = new ObjectReferenceType(); resourceRef.setOid(resource.getOid()); shadowType.setResourceRef(resourceRef); shadowType.setObjectClass(defaultAccountDefinition.getTypeName()); PrismObject<ShadowType> shadow = shadowType.asPrismObject(); PrismContainer<Containerable> attrsCont = shadow.findOrCreateContainer(ShadowType.F_ATTRIBUTES); PrismProperty<String> icfsNameProp = attrsCont.findOrCreateProperty(SchemaConstants.ICFS_NAME); icfsNameProp.setRealValue(username); return shadow; }
PrismContainer<ActivationType> activationContainer = user.findOrCreateContainer(USER_ACTIVATION_QNAME); assertEquals(USER_ACTIVATION_QNAME, activationContainer.getElementName()); PrismAsserts.assertParentConsistency(user); if (assertDefinitions) PrismAsserts.assertDefinition(activationContainer, ACTIVATION_TYPE_QNAME, 0, 1); PrismContainer<ActivationType> activationContainerAgain = user.findOrCreateContainer(USER_ACTIVATION_QNAME); PrismAsserts.assertParentConsistency(user); if (assertDefinitions) PrismAsserts.assertDefinition(assignmentContainer, ASSIGNMENT_TYPE_QNAME, 0, -1); PrismContainer<AssignmentType> assignmentContainerAgain = user.findOrCreateContainer(USER_ASSIGNMENT_QNAME); PrismContainer<?> extensionContainer = user.findOrCreateContainer(USER_EXTENSION_QNAME); assertEquals(USER_EXTENSION_QNAME, extensionContainer.getElementName()); PrismAsserts.assertParentConsistency(user); if (assertDefinitions) PrismAsserts.assertDefinition(extensionContainer, DOMUtil.XSD_ANY, 0, 1); PrismContainer<AssignmentType> extensionContainerAgain = user.findOrCreateContainer(USER_EXTENSION_QNAME);
targetRef.getValue().setOid(ROLE_FIGHT_OID); targetRef.getValue().setTargetType(RoleType.COMPLEX_TYPE); userBefore.findOrCreateContainer(UserType.F_ASSIGNMENT).add((PrismContainerValue) cval);
.name("shadow1") .asPrismObject(); PrismContainer<Containerable> attributes = shadow.findOrCreateContainer(ShadowType.F_ATTRIBUTES);
PrismAsserts.assertPropertyValue(accObject, ShadowType.F_INTENT, SchemaConstants.INTENT_DEFAULT); PrismContainer<?> attributes = accObject.findOrCreateContainer(SchemaConstants.C_ATTRIBUTES); assertEquals("Wrong type of <attributes> definition in account", ResourceAttributeContainerDefinitionImpl.class, attributes.getDefinition().getClass()); ResourceAttributeContainerDefinition attrDef = (ResourceAttributeContainerDefinition)attributes.getDefinition();