use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType in project midpoint by Evolveum.
the class XPathScriptEvaluator method convertScalar.
/*
if (type.equals(String.class))
{
return XPathConstants.STRING;
}
if (type.equals(Double.class) || type.equals(double.class)) {
return XPathConstants.NUMBER;
}
if (type.equals(Integer.class) || type.equals(int.class)) {
return XPathConstants.NUMBER;
}
if (type.equals(Long.class) || type.equals(long.class)) {
return XPathConstants.NUMBER;
}
if (type.equals(Boolean.class) || type.equals(boolean.class)) {
return XPathConstants.BOOLEAN;
}
if (type.equals(NodeList.class)) {
if (expressionType.getReturnType() == ScriptExpressionReturnTypeType.SCALAR) {
// FIXME: is this OK?
return XPathConstants.STRING;
} else {
return XPathConstants.NODESET;
}
}
if (type.equals(Node.class)) {
return XPathConstants.NODE;
}
if (type.equals(PolyString.class) || type.equals(PolyStringType.class)) {
return XPathConstants.STRING;
}
throw new ExpressionEvaluationException("Unsupported return type " + type);
}
*/
private <T, V extends PrismValue> V convertScalar(Class<T> type, QName returnType, Object value, String contextDescription) throws ExpressionEvaluationException {
if (value instanceof ObjectReferenceType) {
return (V) ((ObjectReferenceType) value).asReferenceValue();
}
if (type.isAssignableFrom(value.getClass())) {
return (V) new PrismPropertyValue<T>((T) value);
}
try {
T resultValue = null;
if (value instanceof String) {
resultValue = XmlTypeConverter.toJavaValue((String) value, type);
} else if (value instanceof Boolean) {
resultValue = (T) value;
} else if (value instanceof Element) {
resultValue = XmlTypeConverter.convertValueElementAsScalar((Element) value, type);
} else {
throw new ExpressionEvaluationException("Unexpected scalar return type " + value.getClass().getName());
}
if (returnType.equals(PrismConstants.POLYSTRING_TYPE_QNAME) && resultValue instanceof String) {
resultValue = (T) new PolyString((String) resultValue);
}
PrismUtil.recomputeRealValue(resultValue, prismContext);
return (V) new PrismPropertyValue<T>(resultValue);
} catch (SchemaException e) {
throw new ExpressionEvaluationException("Error converting result of " + contextDescription + ": " + e.getMessage(), e);
} catch (IllegalArgumentException e) {
throw new ExpressionEvaluationException("Error converting result of " + contextDescription + ": " + e.getMessage(), e);
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType in project midpoint by Evolveum.
the class AbstractSearchExpressionEvaluator method transformSingleValue.
@Override
protected List<V> transformSingleValue(ExpressionVariables variables, PlusMinusZero valueDestination, boolean useNew, ExpressionEvaluationContext context, String contextDescription, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
// if (LOGGER.isTraceEnabled()) {
// LOGGER.trace("transformSingleValue in {}\nvariables:\n{}\nvalueDestination: {}\nuseNew: {}",
// new Object[]{contextDescription, variables.debugDump(1), valueDestination, useNew});
// }
QName targetTypeQName = getExpressionEvaluatorType().getTargetType();
if (targetTypeQName == null) {
targetTypeQName = getDefaultTargetType();
}
if (targetTypeQName != null && QNameUtil.isUnqualified(targetTypeQName)) {
targetTypeQName = getPrismContext().getSchemaRegistry().resolveUnqualifiedTypeName(targetTypeQName);
}
ObjectTypes targetType = ObjectTypes.getObjectTypeFromTypeQName(targetTypeQName);
if (targetType == null) {
throw new SchemaException("Unknown target type " + targetTypeQName + " in " + shortDebugDump());
}
Class<? extends ObjectType> targetTypeClass = targetType.getClassDefinition();
List<V> resultValues = null;
ObjectQuery query = null;
List<ItemDelta<V, D>> additionalAttributeDeltas = null;
PopulateType populateAssignmentType = getExpressionEvaluatorType().getPopulate();
if (populateAssignmentType != null) {
additionalAttributeDeltas = collectAdditionalAttributes(populateAssignmentType, outputDefinition, variables, context, contextDescription, task, result);
}
if (getExpressionEvaluatorType().getOid() != null) {
resultValues = new ArrayList<>(1);
resultValues.add(createPrismValue(getExpressionEvaluatorType().getOid(), targetTypeQName, additionalAttributeDeltas, context));
} else {
SearchFilterType filterType = getExpressionEvaluatorType().getFilter();
if (filterType == null) {
throw new SchemaException("No filter in " + shortDebugDump());
}
query = QueryJaxbConvertor.createObjectQuery(targetTypeClass, filterType, prismContext);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("XML query converted to: {}", query.debugDump());
}
query = ExpressionUtil.evaluateQueryExpressions(query, variables, context.getExpressionFactory(), prismContext, context.getContextDescription(), task, result);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Expression in query evaluated to: {}", query.debugDump());
}
query = extendQuery(query, context);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Query after extension: {}", query.debugDump());
}
resultValues = executeSearchUsingCache(targetTypeClass, targetTypeQName, query, additionalAttributeDeltas, context, contextDescription, task, context.getResult());
if (resultValues.isEmpty()) {
ObjectReferenceType defaultTargetRef = getExpressionEvaluatorType().getDefaultTargetRef();
if (defaultTargetRef != null) {
resultValues.add(createPrismValue(defaultTargetRef.getOid(), targetTypeQName, additionalAttributeDeltas, context));
}
}
}
if (resultValues.isEmpty() && getExpressionEvaluatorType().isCreateOnDemand() == Boolean.TRUE && (valueDestination == PlusMinusZero.PLUS || valueDestination == PlusMinusZero.ZERO || useNew)) {
String createdObjectOid = createOnDemand(targetTypeClass, variables, context, context.getContextDescription(), task, context.getResult());
resultValues.add(createPrismValue(createdObjectOid, targetTypeQName, additionalAttributeDeltas, context));
}
LOGGER.trace("Search expression got {} results for query {}", resultValues == null ? "null" : resultValues.size(), query);
return (List<V>) resultValues;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType in project midpoint by Evolveum.
the class ObjectHistoryTabPanel method initLayout.
private void initLayout(final LoadableModel<ObjectWrapper<F>> focusWrapperModel, final PageAdminObjectDetails<F> page) {
AuditSearchDto searchDto = new AuditSearchDto();
ObjectReferenceType ort = new ObjectReferenceType();
ort.setOid(focusWrapperModel.getObject().getOid());
searchDto.setTargetNames(asList(ort));
searchDto.setEventStage(AuditEventStageType.EXECUTION);
Map<String, Boolean> visibilityMap = new HashMap<>();
visibilityMap.put(AuditLogViewerPanel.TARGET_NAME_LABEL_VISIBILITY, false);
visibilityMap.put(AuditLogViewerPanel.TARGET_NAME_FIELD_VISIBILITY, false);
visibilityMap.put(AuditLogViewerPanel.TARGET_OWNER_LABEL_VISIBILITY, false);
visibilityMap.put(AuditLogViewerPanel.TARGET_OWNER_FIELD_VISIBILITY, false);
visibilityMap.put(AuditLogViewerPanel.EVENT_STAGE_LABEL_VISIBILITY, false);
visibilityMap.put(AuditLogViewerPanel.EVENT_STAGE_FIELD_VISIBILITY, false);
visibilityMap.put(AuditLogViewerPanel.EVENT_STAGE_COLUMN_VISIBILITY, false);
visibilityMap.put(AuditLogViewerPanel.TARGET_COLUMN_VISIBILITY, false);
visibilityMap.put(AuditLogViewerPanel.TARGET_OWNER_COLUMN_VISIBILITY, false);
AuditLogViewerPanel panel = new AuditLogViewerPanel(ID_MAIN_PANEL, page, searchDto, visibilityMap) {
@Override
protected List<IColumn<AuditEventRecordType, String>> initColumns() {
List<IColumn<AuditEventRecordType, String>> columns = super.initColumns();
IColumn<AuditEventRecordType, String> column = new MultiButtonColumn<AuditEventRecordType>(new Model(), 2) {
private final DoubleButtonColumn.BUTTON_COLOR_CLASS[] colors = { DoubleButtonColumn.BUTTON_COLOR_CLASS.INFO, DoubleButtonColumn.BUTTON_COLOR_CLASS.SUCCESS };
@Override
public String getCaption(int id) {
return "";
}
@Override
public String getButtonTitle(int id) {
switch(id) {
case 0:
return page.createStringResource("ObjectHistoryTabPanel.viewHistoricalObjectDataTitle").getString();
case 1:
return page.createStringResource("ObjectHistoryTabPanel.viewHistoricalObjectXmlTitle").getString();
}
return "";
}
@Override
public String getButtonColorCssClass(int id) {
return colors[id].toString();
}
@Override
protected String getButtonCssClass(int id) {
StringBuilder sb = new StringBuilder();
sb.append(DoubleButtonColumn.BUTTON_BASE_CLASS).append(" ");
sb.append(getButtonColorCssClass(id)).append(" ");
switch(id) {
case 0:
sb.append("fa fa-circle-o");
break;
case 1:
sb.append("fa fa-file-text-o");
break;
}
return sb.toString();
}
@Override
public void clickPerformed(int id, AjaxRequestTarget target, IModel<AuditEventRecordType> model) {
switch(id) {
case 0:
currentStateButtonClicked(target, focusWrapperModel.getObject().getOid(), model.getObject().getEventIdentifier(), WebComponentUtil.getLocalizedDate(model.getObject().getTimestamp(), DateLabelComponent.SHORT_NOTIME_STYLE), page.getCompileTimeClass());
break;
case 1:
viewObjectXmlButtonClicked(focusWrapperModel.getObject().getOid(), model.getObject().getEventIdentifier(), page.getCompileTimeClass(), WebComponentUtil.getLocalizedDate(model.getObject().getTimestamp(), DateLabelComponent.SHORT_NOTIME_STYLE));
break;
}
}
};
columns.add(column);
return columns;
}
};
panel.setOutputMarkupId(true);
add(panel);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType in project midpoint by Evolveum.
the class ResourceRelatedHandlerDto method getDeltasToExecute.
@NotNull
@Override
public Collection<ItemDelta<?, ?>> getDeltasToExecute(HandlerDtoEditableState origState, HandlerDtoEditableState currState, PrismContext prismContext) throws SchemaException {
List<ItemDelta<?, ?>> rv = new ArrayList<>();
// we can safely assume this; also that both are non-null
ResourceRelatedHandlerDto orig = (ResourceRelatedHandlerDto) origState;
ResourceRelatedHandlerDto curr = (ResourceRelatedHandlerDto) currState;
String origResourceOid = orig.getResourceRef() != null ? orig.getResourceRef().getOid() : null;
String currResourceOid = curr.getResourceRef() != null ? curr.getResourceRef().getOid() : null;
if (!StringUtils.equals(origResourceOid, currResourceOid)) {
ObjectReferenceType resourceObjectRef = new ObjectReferenceType();
resourceObjectRef.setOid(curr.getResourceRef().getOid());
resourceObjectRef.setType(ResourceType.COMPLEX_TYPE);
rv.add(DeltaBuilder.deltaFor(TaskType.class, prismContext).item(TaskType.F_OBJECT_REF).replace(resourceObjectRef.asReferenceValue()).asItemDelta());
}
if (orig.isDryRun() != curr.isDryRun()) {
addExtensionDelta(rv, SchemaConstants.MODEL_EXTENSION_DRY_RUN, curr.isDryRun(), prismContext);
}
if (orig.isRetryUnhandledErr() != curr.isRetryUnhandledErr()) {
addExtensionDelta(rv, SchemaConstants.SYNC_TOKEN_RETRY_UNHANDLED, curr.isRetryUnhandledErr(), prismContext);
}
if (orig.getKind() != curr.getKind()) {
addExtensionDelta(rv, SchemaConstants.MODEL_EXTENSION_KIND, curr.getKind(), prismContext);
}
if (!StringUtils.equals(orig.getIntent(), curr.getIntent())) {
addExtensionDelta(rv, SchemaConstants.MODEL_EXTENSION_INTENT, curr.getIntent(), prismContext);
}
if (!StringUtils.equals(orig.getObjectClass(), curr.getObjectClass())) {
QName objectClassQName = null;
for (QName q : getObjectClassList()) {
if (q.getLocalPart().equals(objectClass)) {
objectClassQName = q;
}
}
addExtensionDelta(rv, SchemaConstants.OBJECTCLASS_PROPERTY_NAME, objectClassQName, prismContext);
}
return rv;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType in project midpoint by Evolveum.
the class AccCertCaseOperationsHelper method recordDecision.
void recordDecision(String campaignOid, long caseId, long workItemId, AccessCertificationResponseType response, String comment, Task task, OperationResult result) throws SecurityViolationException, ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException {
AccessCertificationCaseType _case = queryHelper.getCase(campaignOid, caseId, task, result);
if (_case == null) {
throw new ObjectNotFoundException("Case " + caseId + " was not found in campaign " + campaignOid);
}
AccessCertificationCampaignType campaign = CertCampaignTypeUtil.getCampaign(_case);
if (campaign == null) {
throw new IllegalStateException("No owning campaign present in case " + _case);
}
AccessCertificationWorkItemType workItem = CertCampaignTypeUtil.findWorkItem(_case, workItemId);
if (workItem == null) {
throw new ObjectNotFoundException("Work item " + workItemId + " was not found in campaign " + toShortString(campaign) + ", case " + caseId);
}
if (response == AccessCertificationResponseType.NO_RESPONSE) {
response = null;
}
ObjectReferenceType responderRef = ObjectTypeUtil.createObjectRef(securityEnforcer.getPrincipal().getUser());
XMLGregorianCalendar now = clock.currentTimeXMLGregorianCalendar();
ItemPath workItemPath = new ItemPath(F_CASE, caseId, F_WORK_ITEM, workItemId);
Collection<ItemDelta<?, ?>> deltaList = DeltaBuilder.deltaFor(AccessCertificationCampaignType.class, prismContext).item(workItemPath.subPath(AccessCertificationWorkItemType.F_OUTPUT)).replace(new AbstractWorkItemOutputType().outcome(OutcomeUtils.toUri(response)).comment(comment)).item(workItemPath.subPath(AccessCertificationWorkItemType.F_OUTPUT_CHANGE_TIMESTAMP)).replace(now).item(workItemPath.subPath(AccessCertificationWorkItemType.F_PERFORMER_REF)).replace(responderRef).asItemDeltas();
ItemDelta.applyTo(deltaList, campaign.asPrismContainerValue());
String newCurrentOutcome = OutcomeUtils.toUri(computationHelper.computeOutcomeForStage(_case, campaign, campaign.getStageNumber()));
if (!ObjectUtils.equals(newCurrentOutcome, _case.getCurrentStageOutcome())) {
deltaList.add(DeltaBuilder.deltaFor(AccessCertificationCampaignType.class, prismContext).item(F_CASE, _case.asPrismContainerValue().getId(), F_CURRENT_STAGE_OUTCOME).replace(newCurrentOutcome).asItemDelta());
}
String newOverallOutcome = OutcomeUtils.toUri(computationHelper.computeOverallOutcome(_case, campaign, newCurrentOutcome));
if (!ObjectUtils.equals(newOverallOutcome, _case.getOutcome())) {
deltaList.add(DeltaBuilder.deltaFor(AccessCertificationCampaignType.class, prismContext).item(F_CASE, _case.asPrismContainerValue().getId(), F_OUTCOME).replace(newOverallOutcome).asItemDelta());
}
updateHelper.modifyObjectViaModel(AccessCertificationCampaignType.class, campaignOid, deltaList, task, result);
}
Aggregations