use of com.evolveum.midpoint.prism.PrismReferenceValue in project midpoint by Evolveum.
the class WorkItemProvider method createTaskQuery.
// primitive 'query interpreter'
// returns null if no results should be returned
private TaskQuery createTaskQuery(ObjectQuery query, boolean includeVariables, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult result) throws SchemaException {
FilterComponents components = factorOutQuery(query, F_ASSIGNEE_REF, F_CANDIDATE_REF, F_EXTERNAL_ID);
List<ObjectFilter> remainingClauses = components.getRemainderClauses();
if (!remainingClauses.isEmpty()) {
throw new SchemaException("Unsupported clause(s) in search filter: " + remainingClauses);
}
final ItemPath WORK_ITEM_ID_PATH = new ItemPath(F_EXTERNAL_ID);
final ItemPath ASSIGNEE_PATH = new ItemPath(F_ASSIGNEE_REF);
final ItemPath CANDIDATE_PATH = new ItemPath(F_CANDIDATE_REF);
final ItemPath CREATED_PATH = new ItemPath(WorkItemType.F_CREATE_TIMESTAMP);
final Map.Entry<ItemPath, Collection<? extends PrismValue>> workItemIdFilter = components.getKnownComponent(WORK_ITEM_ID_PATH);
final Map.Entry<ItemPath, Collection<? extends PrismValue>> assigneeFilter = components.getKnownComponent(ASSIGNEE_PATH);
final Map.Entry<ItemPath, Collection<? extends PrismValue>> candidateRolesFilter = components.getKnownComponent(CANDIDATE_PATH);
TaskQuery taskQuery = activitiEngine.getTaskService().createTaskQuery();
if (workItemIdFilter != null) {
Collection<? extends PrismValue> filterValues = workItemIdFilter.getValue();
if (filterValues.size() > 1) {
throw new IllegalArgumentException("In a query there must be exactly one value for workItemId: " + filterValues);
}
taskQuery = taskQuery.taskId(((PrismPropertyValue<String>) filterValues.iterator().next()).getValue());
}
if (assigneeFilter != null) {
taskQuery = addAssigneesToQuery(taskQuery, assigneeFilter);
}
if (candidateRolesFilter != null) {
// TODO what about candidate users? (currently these are not supported)
List<String> candidateGroups = MiscDataUtil.prismRefsToStrings((Collection<PrismReferenceValue>) candidateRolesFilter.getValue());
if (!candidateGroups.isEmpty()) {
taskQuery = taskQuery.taskCandidateGroupIn(candidateGroups);
} else {
// no groups -> no result
return null;
}
}
if (query != null && query.getPaging() != null) {
ObjectPaging paging = query.getPaging();
if (paging.getOrderingInstructions().size() > 1) {
throw new UnsupportedOperationException("Ordering by more than one property is not supported: " + paging.getOrderingInstructions());
} else if (paging.getOrderingInstructions().size() == 1) {
ItemPath orderBy = paging.getOrderBy();
if (CREATED_PATH.equivalent(orderBy)) {
taskQuery = taskQuery.orderByTaskCreateTime();
} else {
throw new UnsupportedOperationException("Ordering by " + orderBy + " is not currently supported");
}
switch(paging.getDirection()) {
case DESCENDING:
taskQuery = taskQuery.desc();
break;
case ASCENDING:
default:
taskQuery = taskQuery.asc();
break;
}
}
}
if (includeVariables) {
return taskQuery.includeTaskLocalVariables().includeProcessVariables();
} else {
return taskQuery;
}
}
use of com.evolveum.midpoint.prism.PrismReferenceValue in project midpoint by Evolveum.
the class AbstractIntegrationTest method assertNotLinked.
protected void assertNotLinked(PrismObject<UserType> user, String accountOid) throws ObjectNotFoundException, SchemaException {
PrismReference linkRef = user.findReference(UserType.F_LINK_REF);
if (linkRef == null) {
return;
}
boolean found = false;
for (PrismReferenceValue val : linkRef.getValues()) {
if (val.getOid().equals(accountOid)) {
found = true;
}
}
assertFalse("User " + user + " IS linked to account " + accountOid + " but not expecting it", found);
}
use of com.evolveum.midpoint.prism.PrismReferenceValue in project midpoint by Evolveum.
the class TestOrgSync method assertResponsibility.
private String assertResponsibility(PrismObject<UserType> user, String respName) throws SchemaException, ObjectNotFoundException, SecurityViolationException, CommunicationException, ConfigurationException, DirectoryException, ExpressionEvaluationException {
String respRoleName = "R_" + respName;
PrismObject<RoleType> respRole = searchObjectByName(RoleType.class, respRoleName);
assertNotNull("No role for responsibility " + respName);
display("Responsibility role for " + respName, respRole);
assertAssignedRole(user, respRole.getOid());
PrismReferenceValue linkRef = getSingleLinkRef(respRole);
PrismObject<ShadowType> shadow = getShadowModel(linkRef.getOid());
display("Role " + respRoleName + " shadow", shadow);
// TODO assert shadow content
String groupDn = "cn=" + respRoleName + ",ou=groups," + openDJController.getSuffix();
Entry groupEntry = openDJController.fetchAndAssertEntry(groupDn, "groupOfUniqueNames");
display("Group entry", groupEntry);
PrismReferenceValue accountLinkRef = getLinkRef(user, RESOURCE_OPENDJ_OID);
PrismObject<ShadowType> accountShadow = getShadowModel(accountLinkRef.getOid());
String accountDn = IntegrationTestTools.getSecondaryIdentifier(accountShadow);
openDJController.assertUniqueMember(groupEntry, accountDn);
IntegrationTestTools.assertAssociation(accountShadow, OPENDJ_ASSOCIATION_GROUP_NAME, shadow.getOid());
return respRole.getOid();
}
use of com.evolveum.midpoint.prism.PrismReferenceValue in project midpoint by Evolveum.
the class TestOrgSync method assertBasicRoleAndResources.
private void assertBasicRoleAndResources(PrismObject<UserType> user) throws ObjectNotFoundException, SchemaException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
assertAssignedRole(user, ROLE_BASIC_OID);
PrismReferenceValue linkRef = getLinkRef(user, RESOURCE_OPENDJ_OID);
PrismObject<ShadowType> shadow = getShadowModel(linkRef.getOid());
display("OpenDJ shadow linked to " + user, shadow);
// TODO assert shadow content
}
use of com.evolveum.midpoint.prism.PrismReferenceValue in project midpoint by Evolveum.
the class RAuditEventRecord method toRepo.
public static RAuditEventRecord toRepo(AuditEventRecord record, PrismContext prismContext) throws DtoTranslationException {
Validate.notNull(record, "Audit event record must not be null.");
Validate.notNull(prismContext, "Prism context must not be null.");
RAuditEventRecord repo = new RAuditEventRecord();
if (record.getRepoId() != null) {
repo.setId(record.getRepoId());
}
repo.setChannel(record.getChannel());
if (record.getTimestamp() != null) {
repo.setTimestamp(new Timestamp(record.getTimestamp()));
}
repo.setEventStage(RAuditEventStage.toRepo(record.getEventStage()));
repo.setEventType(RAuditEventType.toRepo(record.getEventType()));
repo.setSessionIdentifier(record.getSessionIdentifier());
repo.setEventIdentifier(record.getEventIdentifier());
repo.setHostIdentifier(record.getHostIdentifier());
repo.setRemoteHostAddress(record.getRemoteHostAddress());
repo.setNodeIdentifier(record.getNodeIdentifier());
repo.setParameter(record.getParameter());
repo.setMessage(RUtil.trimString(record.getMessage(), AuditService.MAX_MESSAGE_SIZE));
if (record.getOutcome() != null) {
repo.setOutcome(RUtil.getRepoEnumValue(record.getOutcome().createStatusType(), ROperationResultStatus.class));
}
repo.setTaskIdentifier(record.getTaskIdentifier());
repo.setTaskOID(record.getTaskOID());
repo.setResult(record.getResult());
try {
if (record.getTarget() != null) {
PrismReferenceValue target = record.getTarget();
repo.setTargetName(getOrigName(target));
repo.setTargetOid(target.getOid());
repo.setTargetType(ClassMapper.getHQLTypeForQName(target.getTargetType()));
}
if (record.getTargetOwner() != null) {
PrismObject targetOwner = record.getTargetOwner();
repo.setTargetOwnerName(getOrigName(targetOwner));
repo.setTargetOwnerOid(targetOwner.getOid());
}
if (record.getInitiator() != null) {
PrismObject<UserType> initiator = record.getInitiator();
repo.setInitiatorName(getOrigName(initiator));
repo.setInitiatorOid(initiator.getOid());
}
for (ObjectDeltaOperation<?> delta : record.getDeltas()) {
if (delta == null) {
continue;
}
ObjectDelta<?> objectDelta = delta.getObjectDelta();
for (ItemDelta<?, ?> itemDelta : objectDelta.getModifications()) {
ItemPath path = itemDelta.getPath();
if (path != null) {
// TODO what if empty?
CanonicalItemPath canonical = CanonicalItemPath.create(path, objectDelta.getObjectTypeClass(), prismContext);
for (int i = 0; i < canonical.size(); i++) {
RAuditItem changedItem = RAuditItem.toRepo(repo, canonical.allUpToIncluding(i).asString());
repo.getChangedItems().add(changedItem);
}
}
}
RObjectDeltaOperation rDelta = RObjectDeltaOperation.toRepo(repo, delta, prismContext);
rDelta.setTransient(true);
rDelta.setRecord(repo);
repo.getDeltas().add(rDelta);
}
for (Map.Entry<String, Set<String>> propertyEntry : record.getProperties().entrySet()) {
for (String propertyValue : propertyEntry.getValue()) {
repo.getPropertyValues().add(RAuditPropertyValue.toRepo(repo, propertyEntry.getKey(), RUtil.trimString(propertyValue, AuditService.MAX_PROPERTY_SIZE)));
}
}
for (Map.Entry<String, Set<AuditReferenceValue>> referenceEntry : record.getReferences().entrySet()) {
for (AuditReferenceValue referenceValue : referenceEntry.getValue()) {
repo.getReferenceValues().add(RAuditReferenceValue.toRepo(repo, referenceEntry.getKey(), referenceValue));
}
}
} catch (Exception ex) {
throw new DtoTranslationException(ex.getMessage(), ex);
}
return repo;
}
Aggregations