use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.
the class AbstractUcfDummyTest method assertPropertyValue.
protected static void assertPropertyValue(PrismContainer<?> container, String propName, Object propValue) {
ItemName propQName = new ItemName(SchemaConstantsGenerated.NS_COMMON, propName);
PrismAsserts.assertPropertyValue(container, propQName, propValue);
}
use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.
the class Expression method processInnerVariables.
private VariablesMap processInnerVariables(VariablesMap variables, String contextDescription, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
if (expressionType == null) {
// shortcut
return variables;
}
VariablesMap newVariables = new VariablesMap();
// We need to add actor variable before we switch user identity (runAs)
ExpressionUtil.addActorVariable(newVariables, securityContextManager, prismContext);
boolean actorDefined = newVariables.get(ExpressionConstants.VAR_ACTOR) != null;
for (Entry<String, TypedValue> entry : variables.entrySet()) {
String key = entry.getKey();
if (ExpressionConstants.VAR_ACTOR.equals(key) && actorDefined) {
// avoid pointless warning about redefined value of actor
continue;
}
newVariables.put(key, entry.getValue());
if (variables.isAlias(key)) {
newVariables.registerAlias(key, variables.getAliasResolution(key));
}
}
for (ExpressionVariableDefinitionType variableDefType : expressionType.getVariable()) {
String varName = variableDefType.getName().getLocalPart();
if (varName == null) {
throw new SchemaException("No variable name in expression in " + contextDescription);
}
if (variableDefType.getObjectRef() != null) {
ObjectReferenceType ref = variableDefType.getObjectRef();
ref.setType(prismContext.getSchemaRegistry().qualifyTypeName(ref.getType()));
ObjectType varObject = objectResolver.resolve(ref, ObjectType.class, null, "variable " + varName + " in " + contextDescription, task, result);
newVariables.addVariableDefinition(varName, varObject, varObject.asPrismObject().getDefinition());
} else if (variableDefType.getValue() != null) {
// Only string is supported now
Object valueObject = variableDefType.getValue();
if (valueObject instanceof String) {
MutablePrismPropertyDefinition<Object> def = prismContext.definitionFactory().createPropertyDefinition(new ItemName(SchemaConstants.NS_C, varName), PrimitiveType.STRING.getQname());
newVariables.addVariableDefinition(varName, valueObject, def);
} else if (valueObject instanceof Element) {
MutablePrismPropertyDefinition<Object> def = prismContext.definitionFactory().createPropertyDefinition(new ItemName(SchemaConstants.NS_C, varName), PrimitiveType.STRING.getQname());
newVariables.addVariableDefinition(varName, ((Element) valueObject).getTextContent(), def);
} else if (valueObject instanceof RawType) {
ItemName varQName = new ItemName(SchemaConstants.NS_C, varName);
MutablePrismPropertyDefinition<Object> def = prismContext.definitionFactory().createPropertyDefinition(varQName, PrimitiveType.STRING.getQname());
newVariables.addVariableDefinition(varName, ((RawType) valueObject).getParsedValue(null, varQName), def);
} else {
throw new SchemaException("Unexpected type " + valueObject.getClass() + " in variable definition " + varName + " in " + contextDescription);
}
} else if (variableDefType.getPath() != null) {
ItemPath itemPath = variableDefType.getPath().getItemPath();
TypedValue resolvedValueAndDefinition = ExpressionUtil.resolvePathGetTypedValue(itemPath, variables, false, null, objectResolver, prismContext, contextDescription, task, result);
newVariables.put(varName, resolvedValueAndDefinition);
} else {
throw new SchemaException("No value for variable " + varName + " in " + contextDescription);
}
}
return newVariables;
}
use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.
the class SqaleRepoSearchTest method initObjects.
@BeforeClass
public void initObjects() throws Exception {
OperationResult result = createOperationResult();
// org structure
org1Oid = repositoryService.addObject(new OrgType(prismContext).name("org-1").asPrismObject(), null, result);
org11Oid = repositoryService.addObject(new OrgType(prismContext).name("org-1-1").parentOrgRef(org1Oid, OrgType.COMPLEX_TYPE).asPrismObject(), null, result);
org111Oid = repositoryService.addObject(new OrgType(prismContext).name("org-1-1-1").parentOrgRef(org11Oid, OrgType.COMPLEX_TYPE, relation2).subtype("newWorkers").asPrismObject(), null, result);
org112Oid = repositoryService.addObject(new OrgType(prismContext).name("org-1-1-2").parentOrgRef(org11Oid, OrgType.COMPLEX_TYPE, relation1).subtype("secret").asPrismObject(), null, result);
org12Oid = repositoryService.addObject(new OrgType(prismContext).name("org-1-2").parentOrgRef(org1Oid, OrgType.COMPLEX_TYPE).asPrismObject(), null, result);
org2Oid = repositoryService.addObject(new OrgType(prismContext).name("org-2").asPrismObject(), null, result);
org21Oid = repositoryService.addObject(new OrgType(prismContext).name("org-2-1").costCenter("5").parentOrgRef(org2Oid, OrgType.COMPLEX_TYPE).policySituation("situationC").asPrismObject(), null, result);
orgXOid = repositoryService.addObject(new OrgType(prismContext).name("org-X").displayOrder(30).parentOrgRef(org12Oid, OrgType.COMPLEX_TYPE).parentOrgRef(org21Oid, OrgType.COMPLEX_TYPE, SchemaConstants.ORG_MANAGER).asPrismObject(), null, result);
// shadow, owned by user-3
ShadowType shadow1 = new ShadowType(prismContext).name("shadow-1").pendingOperation(new PendingOperationType().attemptNumber(1)).pendingOperation(new PendingOperationType().attemptNumber(2)).resourceRef(resourceOid, // what relation is used for shadow->resource?
ResourceType.COMPLEX_TYPE).objectClass(SchemaConstants.RI_ACCOUNT_OBJECT_CLASS).kind(ShadowKindType.ACCOUNT).intent("intent").tag("tag").extension(new ExtensionType(prismContext));
addExtensionValue(shadow1.getExtension(), "string", "string-value");
ItemName shadowAttributeName = new ItemName("https://example.com/p", "string-mv");
ShadowAttributesHelper attributesHelper = new ShadowAttributesHelper(shadow1).set(shadowAttributeName, DOMUtil.XSD_STRING, "string-value1", "string-value2");
shadowAttributeDefinition = attributesHelper.getDefinition(shadowAttributeName);
shadow1Oid = repositoryService.addObject(shadow1.asPrismObject(), null, result);
// another shadow just to check we don't select shadow1 accidentally/randomly
repositoryService.addObject(new ShadowType(prismContext).name("shadow-2").asPrismObject(), null, result);
// tasks
task1Oid = repositoryService.addObject(new TaskType(prismContext).name("task-1").executionState(TaskExecutionStateType.RUNNABLE).asPrismObject(), null, result);
task2Oid = repositoryService.addObject(new TaskType(prismContext).name("task-2").executionState(TaskExecutionStateType.CLOSED).schedule(new ScheduleType(prismContext).recurrence(TaskRecurrenceType.RECURRING)).asPrismObject(), null, result);
// users
creatorOid = repositoryService.addObject(new UserType(prismContext).name("creator").asPrismObject(), null, result);
modifierOid = repositoryService.addObject(new UserType(prismContext).name("modifier").asPrismObject(), null, result);
UserType user1 = new UserType(prismContext).name("user-1").fullName("User Name 1").metadata(new MetadataType(prismContext).creatorRef(creatorOid, UserType.COMPLEX_TYPE, relation1).createChannel("create-channel").createTimestamp(asXMLGregorianCalendar(1L)).modifierRef(modifierOid, UserType.COMPLEX_TYPE, relation2).modifyChannel("modify-channel").modifyTimestamp(asXMLGregorianCalendar(2L))).subtype("workerA").subtype("workerC").policySituation("situationA").policySituation("situationC").activation(new ActivationType(prismContext).validFrom("2021-07-04T00:00:00Z").validTo("2022-07-04T00:00:00Z")).assignment(new AssignmentType(prismContext).lifecycleState("assignment1-1").orgRef(org1Oid, OrgType.COMPLEX_TYPE, relation1).activation(new ActivationType(prismContext).validFrom("2021-03-01T00:00:00Z").validTo("2022-07-04T00:00:00Z")).subtype("ass-subtype-2")).assignment(new AssignmentType(prismContext).lifecycleState("assignment1-2").order(1)).operationExecution(new OperationExecutionType(prismContext).taskRef(task2Oid, TaskType.COMPLEX_TYPE).status(OperationResultStatusType.FATAL_ERROR).timestamp("2021-09-01T00:00:00Z")).operationExecution(new OperationExecutionType(prismContext).taskRef(task1Oid, TaskType.COMPLEX_TYPE).status(OperationResultStatusType.SUCCESS).timestamp("2021-10-01T00:00:00Z")).extension(new ExtensionType(prismContext));
ExtensionType user1Extension = user1.getExtension();
addExtensionValue(user1Extension, "string", "string-value");
addExtensionValue(user1Extension, "int", 1);
addExtensionValue(user1Extension, "long", 2L);
addExtensionValue(user1Extension, "short", (short) 3);
addExtensionValue(user1Extension, "decimal", new BigDecimal("12345678901234567890.12345678901234567890"));
addExtensionValue(user1Extension, "double", Double.MAX_VALUE);
addExtensionValue(user1Extension, "float", Float.MAX_VALUE);
addExtensionValue(user1Extension, "boolean", true);
addExtensionValue(user1Extension, "enum", BeforeAfterType.AFTER);
addExtensionValue(// 2021-09-30 before noon
user1Extension, // 2021-09-30 before noon
"dateTime", asXMLGregorianCalendar(Instant.ofEpochMilli(1633_000_000_000L)));
addExtensionValue(user1Extension, "poly", PolyString.fromOrig("poly-value"));
addExtensionValue(user1Extension, "ref", ref(org21Oid, OrgType.COMPLEX_TYPE, relation1));
addExtensionValue(user1Extension, "string-mv", "string-value1", "string-value2");
addExtensionValue(// nonsense semantics, sorry about it
user1Extension, // nonsense semantics, sorry about it
"enum-mv", OperationResultStatusType.WARNING, OperationResultStatusType.SUCCESS);
addExtensionValue(user1Extension, "int-mv", 47, 31);
addExtensionValue(user1Extension, "ref-mv", // type is nullable if provided in schema
ref(org1Oid, null, relation2), // default relation
ref(org2Oid, OrgType.COMPLEX_TYPE));
addExtensionValue(user1Extension, "string-ni", "not-indexed-item");
ExtensionType user1AssignmentExtension = new ExtensionType(prismContext);
user1.assignment(new AssignmentType(prismContext).lifecycleState("assignment1-3-ext").extension(user1AssignmentExtension));
addExtensionValue(user1AssignmentExtension, "integer", BigInteger.valueOf(47));
user1Oid = repositoryService.addObject(user1.asPrismObject(), null, result);
UserType user2 = new UserType(prismContext).name("user-2").parentOrgRef(orgXOid, OrgType.COMPLEX_TYPE).parentOrgRef(org11Oid, OrgType.COMPLEX_TYPE, relation1).subtype("workerA").activation(new ActivationType(prismContext).validFrom("2021-03-01T00:00:00Z").validTo("2022-07-04T00:00:00Z")).metadata(new MetadataType(prismContext).createTimestamp(asXMLGregorianCalendar(2L))).operationExecution(new OperationExecutionType(prismContext).taskRef(task1Oid, TaskType.COMPLEX_TYPE).status(OperationResultStatusType.FATAL_ERROR).timestamp("2021-11-01T00:00:00Z")).operationExecution(new OperationExecutionType(prismContext).taskRef(task1Oid, TaskType.COMPLEX_TYPE).status(OperationResultStatusType.SUCCESS).timestamp("2021-12-01T00:00:00Z")).operationExecution(new OperationExecutionType(prismContext).taskRef(task1Oid, TaskType.COMPLEX_TYPE).status(OperationResultStatusType.PARTIAL_ERROR).timestamp("2022-01-01T00:00:00Z")).extension(new ExtensionType(prismContext));
ExtensionType user2Extension = user2.getExtension();
addExtensionValue(user2Extension, "string", "other-value...");
addExtensionValue(// 2021-10-01 ~15PM
user2Extension, // 2021-10-01 ~15PM
"dateTime", asXMLGregorianCalendar(Instant.ofEpochMilli(1633_100_000_000L)));
addExtensionValue(user2Extension, "int", 2);
// positive, close to zero
addExtensionValue(user2Extension, "double", Double.MIN_VALUE);
addExtensionValue(user2Extension, "float", 0f);
addExtensionValue(user2Extension, "ref", ref(orgXOid, OrgType.COMPLEX_TYPE));
addExtensionValue(user2Extension, "string-mv", "string-value2", "string-value3");
addExtensionValue(user2Extension, "poly", PolyString.fromOrig("poly-value-user2"));
addExtensionValue(user2Extension, "enum-mv", OperationResultStatusType.UNKNOWN, OperationResultStatusType.SUCCESS);
addExtensionValue(user2Extension, "poly-mv", PolyString.fromOrig("poly-value1"), PolyString.fromOrig("poly-value2"));
user2Oid = repositoryService.addObject(user2.asPrismObject(), null, result);
UserType user3 = new UserType(prismContext).name("user-3").costCenter("50").parentOrgRef(orgXOid, OrgType.COMPLEX_TYPE).parentOrgRef(org21Oid, OrgType.COMPLEX_TYPE, relation1).policySituation("situationA").assignment(new AssignmentType(prismContext).lifecycleState("ls-user3-ass1").metadata(new MetadataType(prismContext).createApproverRef(user1Oid, UserType.COMPLEX_TYPE, ORG_DEFAULT)).activation(new ActivationType(prismContext).validFrom("2021-01-01T00:00:00Z")).subtype("ass-subtype-1").subtype("ass-subtype-2")).linkRef(shadow1Oid, ShadowType.COMPLEX_TYPE).assignment(new AssignmentType(prismContext).activation(new ActivationType(prismContext).validTo("2022-01-01T00:00:00Z"))).operationExecution(new OperationExecutionType(prismContext).taskRef(task1Oid, TaskType.COMPLEX_TYPE).status(OperationResultStatusType.WARNING).timestamp("2021-08-01T00:00:00Z")).extension(new ExtensionType(prismContext));
ExtensionType user3Extension = user3.getExtension();
addExtensionValue(user3Extension, "int", 10);
addExtensionValue(// 2021-10-02 ~19PM
user3Extension, // 2021-10-02 ~19PM
"dateTime", asXMLGregorianCalendar(Instant.ofEpochMilli(1633_200_000_000L)));
user3Oid = repositoryService.addObject(user3.asPrismObject(), null, result);
user4Oid = repositoryService.addObject(new UserType(prismContext).name("user-4").givenName("John").fullName("John").costCenter("51").parentOrgRef(org111Oid, OrgType.COMPLEX_TYPE).subtype("workerB").policySituation("situationB").organization(// orgs and ous are polys stored in JSONB arrays
"org-1").organization("org-2").organizationalUnit("ou-1").organizationalUnit("ou-2").asPrismObject(), null, result);
// other objects
case1Oid = repositoryService.addObject(new CaseType(prismContext).name("case-1").state("closed").closeTimestamp(asXMLGregorianCalendar(321L)).workItem(new CaseWorkItemType(prismContext).id(41L).createTimestamp(asXMLGregorianCalendar(10000L)).closeTimestamp(asXMLGregorianCalendar(10100L)).deadline(asXMLGregorianCalendar(10200L)).originalAssigneeRef(user3Oid, UserType.COMPLEX_TYPE).performerRef(user3Oid, UserType.COMPLEX_TYPE).stageNumber(1).assigneeRef(user1Oid, UserType.COMPLEX_TYPE, ORG_DEFAULT).assigneeRef(user2Oid, UserType.COMPLEX_TYPE, ORG_DEFAULT).output(new AbstractWorkItemOutputType(prismContext).outcome("OUTCOME one"))).workItem(new CaseWorkItemType(prismContext).id(42L).createTimestamp(asXMLGregorianCalendar(20000L)).closeTimestamp(asXMLGregorianCalendar(20100L)).deadline(asXMLGregorianCalendar(20200L)).originalAssigneeRef(user1Oid, UserType.COMPLEX_TYPE).performerRef(user1Oid, UserType.COMPLEX_TYPE).stageNumber(2).output(new AbstractWorkItemOutputType(prismContext).outcome("OUTCOME two"))).asPrismObject(), null, result);
accCertCampaign1Oid = repositoryService.addObject(new AccessCertificationCampaignType(prismContext).name("acc-1").stageNumber(// mandatory, also for containers
0).iteration(// mandatory with default 1, also for containers
1)._case(new AccessCertificationCaseType(prismContext).id(1L).stageNumber(1).iteration(1).workItem(new AccessCertificationWorkItemType(prismContext).stageNumber(11).iteration(1)).workItem(new AccessCertificationWorkItemType(prismContext).stageNumber(12).iteration(1)))._case(new AccessCertificationCaseType(prismContext).id(2L).stageNumber(2).iteration(2).workItem(new AccessCertificationWorkItemType(prismContext).stageNumber(21).iteration(1)).workItem(new AccessCertificationWorkItemType(prismContext).stageNumber(22).iteration(1))).asPrismObject(), null, result);
connector1Oid = repositoryService.addObject(new ConnectorType(prismContext).name("conn-1").connectorBundle("com.connector.package").connectorType("ConnectorTypeClass").connectorVersion("1.2.3").framework(SchemaConstants.UCF_FRAMEWORK_URI_BUILTIN).connectorHostRef(connectorHostOid, ConnectorHostType.COMPLEX_TYPE).targetSystemType("type1").targetSystemType("type2").asPrismObject(), null, result);
connector2Oid = repositoryService.addObject(new ConnectorType(prismContext).name("conn-2").connectorBundle("com.connector.package").connectorType("ConnectorTypeClass").connectorVersion("1.2.3").framework(SchemaConstants.UCF_FRAMEWORK_URI_BUILTIN).asPrismObject(), null, result);
roleOid = repositoryService.addObject(new RoleType(prismContext).name("role-ass-vs-ind").assignment(new AssignmentType(prismContext).lifecycleState("role-ass-lc")).inducement(new AssignmentType(prismContext).lifecycleState("role-ind-lc")).asPrismObject(), null, result);
// objects for OID range tests
List.of("00000000-1000-0000-0000-000000000000", "00000000-1000-0000-0000-000000000001", "10000000-1000-0000-0000-000000000000", "10000000-1000-0000-0000-100000000000", "10ffffff-ffff-ffff-ffff-ffffffffffff", "11000000-0000-0000-0000-000000000000", "11000000-1000-0000-0000-100000000000", "11000000-1000-0000-0000-100000000001", "11ffffff-ffff-ffff-ffff-fffffffffffe", "11ffffff-ffff-ffff-ffff-ffffffffffff", "20ffffff-ffff-ffff-ffff-ffffffffffff", "ff000000-0000-0000-0000-000000000000", "ffffffff-ffff-ffff-ffff-ffffffffffff").forEach(oid -> {
try {
repositoryService.addObject(new ServiceType(prismContext).oid(oid).name(oid).costCenter("OIDTEST").asPrismObject(), null, result);
} catch (Exception e) {
throw new RuntimeException(e);
}
});
assertThatOperationResult(result).isSuccess();
}
use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.
the class SqaleRepoModifyObjectTest method test503AddingAndDeletingValuesFromSingleExtensionItem.
@Test
public void test503AddingAndDeletingValuesFromSingleExtensionItem() throws Exception {
OperationResult result = createOperationResult();
MUser originalRow = selectObjectByOid(QUser.class, user1Oid);
given("delta adding and deleting values from a single extension item");
ObjectDelta<UserType> delta = prismContext.deltaFor(UserType.class).item(FocusType.F_EXTENSION, new QName("string-mv")).delete("s1", "s5", "s6").item(FocusType.F_EXTENSION, new QName("string-mv")).add("s5", "s7").asObjectDelta(user1Oid);
when("modifyObject is called");
repositoryService.modifyObject(UserType.class, user1Oid, delta.getModifications(), result);
then("operation is successful");
assertThatOperationResult(result).isSuccess();
and("serialized form (fullObject) is updated");
UserType user = repositoryService.getObject(UserType.class, user1Oid, null, result).asObjectable();
assertThat(user.getVersion()).isEqualTo(String.valueOf(originalRow.version + 1));
ExtensionType extension = user.getExtension();
Item<?, ?> item = extension.asPrismContainerValue().findItem(new ItemName("string-mv"));
assertThat(item).isNotNull();
// noinspection unchecked
assertThat((Collection<String>) item.getRealValues()).containsExactlyInAnyOrder("s2", "s3", "s4", "s7");
and("externalized column is updated");
ExtensionType extensionContainer = user.getExtension();
MUser row = selectObjectByOid(QUser.class, user1Oid);
assertThat(row.version).isEqualTo(originalRow.version + 1);
assertThat(row.ext).isNotNull();
assertThat(Jsonb.toMap(row.ext)).containsEntry(// changed
extensionKey(extensionContainer, "string-mv"), List.of("s2", "s3", "s4", "s7")).containsEntry(extensionKey(extensionContainer, "int"), // preserved
47).containsEntry(extensionKey(extensionContainer, "poly-mv"), List.of(Map.of("o", "poly-ext1", "n", "polyext1"), Map.of("o", "poly-ext2", "n", "polyext2")));
}
use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.
the class RAnyConverterStaticTest method testAttributesLong.
@Test
public void testAttributesLong() throws Exception {
Session session = getFactory().openSession();
ItemName valueName = new ItemName(NS_FOO_RESOURCE, "uid");
ItemDefinition def = getDefinition(GenericObjectType.class, valueName);
AssertJUnit.assertNull(def);
Element value = createAttributeValue(valueName, "xsd:long", "123");
Object realValue = RAnyConverter.getRealRepoValue(def, value, prismContext);
AssertJUnit.assertEquals(123L, realValue);
session.close();
}
Aggregations