use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.
the class AbstractManagedConnectorInstance method applyConfigurationToConfigurationClass.
private void applyConfigurationToConfigurationClass(PrismContainerValue<?> configurationContainer) throws ConfigurationException {
BeanWrapper connectorBean = new BeanWrapperImpl(this);
PropertyDescriptor connectorConfigurationProp = UcfUtil.findAnnotatedProperty(connectorBean, ManagedConnectorConfiguration.class);
if (connectorConfigurationProp == null) {
return;
}
Class<?> configurationClass = connectorConfigurationProp.getPropertyType();
Object configurationObject;
try {
configurationObject = configurationClass.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new ConfigurationException("Cannot instantiate configuration " + configurationClass);
}
BeanWrapper configurationClassBean = new BeanWrapperImpl(configurationObject);
for (Item<?, ?> configurationItem : configurationContainer.getItems()) {
if (!(configurationItem instanceof PrismProperty<?>)) {
throw new ConfigurationException("Only properties are supported for now");
}
PrismProperty<?> configurationProperty = (PrismProperty<?>) configurationItem;
Object realValue = configurationProperty.getRealValue();
configurationClassBean.setPropertyValue(configurationProperty.getElementName().getLocalPart(), realValue);
}
connectorBean.setPropertyValue(connectorConfigurationProp.getName(), configurationObject);
}
use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.
the class PageTaskController method deleteSyncTokenPerformed.
public void deleteSyncTokenPerformed(AjaxRequestTarget target) {
LOGGER.debug("Deleting sync token.");
OperationResult result = new OperationResult(PageTaskEdit.OPERATION_DELETE_SYNC_TOKEN);
Task operationTask = parentPage.createSimpleTask(PageTaskEdit.OPERATION_DELETE_SYNC_TOKEN);
try {
final TaskDto taskDto = parentPage.getTaskDto();
final PrismProperty property = taskDto.getExtensionProperty(SchemaConstants.SYNC_TOKEN);
if (property == null) {
// should be treated by isVisible
result.recordWarning("Token is not present in this task.");
} else {
final ObjectDelta<? extends ObjectType> delta = (ObjectDelta<? extends ObjectType>) DeltaBuilder.deltaFor(TaskType.class, parentPage.getPrismContext()).item(new ItemPath(TaskType.F_EXTENSION, SchemaConstants.SYNC_TOKEN), property.getDefinition()).replace().asObjectDelta(parentPage.getTaskDto().getOid());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Deleting sync token:\n{}", delta.debugDump());
}
parentPage.getModelService().executeChanges(Collections.<ObjectDelta<? extends ObjectType>>singleton(delta), null, operationTask, result);
result.recomputeStatus();
}
} catch (Exception ex) {
result.recomputeStatus();
result.recordFatalError("Couldn't delete sync token from the task.", ex);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't delete sync token from the task.", ex);
}
afterStateChangingOperation(target, result);
}
use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.
the class PageForgotPassword method createDynamicFormQuery.
private ObjectQuery createDynamicFormQuery(Form form) {
DynamicFormPanel<UserType> userDynamicPanel = (DynamicFormPanel<UserType>) form.get(createComponentPath(ID_DYNAMIC_LAYOUT, ID_DYNAMIC_FORM));
List<ItemPath> filledItems = userDynamicPanel.getChangedItems();
PrismObject<UserType> user;
try {
user = userDynamicPanel.getObject();
} catch (SchemaException e1) {
getSession().error(getString("pageForgetPassword.message.usernotfound"));
throw new RestartResponseException(PageForgotPassword.class);
}
List<EqualFilter> filters = new ArrayList<>();
for (ItemPath path : filledItems) {
PrismProperty property = user.findProperty(path);
EqualFilter filter = EqualFilter.createEqual(path, property.getDefinition(), null);
filter.setValue(property.getAnyValue().clone());
filters.add(filter);
}
return ObjectQuery.createObjectQuery(AndFilter.createAnd((List) filters));
}
use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.
the class WebComponentUtil method getEffectiveName.
public static <O extends ObjectType> String getEffectiveName(PrismObject<O> object, QName propertyName) {
if (object == null) {
return null;
}
PrismProperty prop = object.findProperty(propertyName);
if (prop != null) {
Object realValue = prop.getRealValue();
if (prop.getDefinition().getTypeName().equals(DOMUtil.XSD_STRING)) {
return (String) realValue;
} else if (realValue instanceof PolyString) {
return WebComponentUtil.getOrigStringFromPoly((PolyString) realValue);
}
}
PolyString name = getValue(object, ObjectType.F_NAME, PolyString.class);
return name != null ? name.getOrig() : null;
}
use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.
the class RunReportPopupPanel method createLookupTableRows.
private <O extends ObjectType> List<LookupTableRowType> createLookupTableRows(JasperReportParameterDto param, String input) {
ItemPath label = null;
ItemPath key = null;
List<LookupTableRowType> rows = new ArrayList<>();
JasperReportParameterPropertiesDto properties = param.getProperties();
if (properties == null) {
return null;
}
String pLabel = properties.getLabel();
if (pLabel != null) {
label = new ItemPath(pLabel);
}
String pKey = properties.getKey();
if (pKey != null) {
key = new ItemPath(pKey);
}
String pTargetType = properties.getTargetType();
Class<O> targetType = null;
if (pTargetType != null) {
try {
targetType = (Class<O>) Class.forName(pTargetType);
} catch (ClassNotFoundException e) {
error("Error while creating lookup table for input parameter: " + param.getName() + ", " + e.getClass().getSimpleName() + " (" + e.getMessage() + ")");
//e.printStackTrace();
}
}
if (label != null && targetType != null && input != null) {
OperationResult result = new OperationResult(OPERATION_LOAD_RESOURCES);
Task task = createSimpleTask(OPERATION_LOAD_RESOURCES);
Collection<PrismObject<O>> objects;
ObjectQuery query = QueryBuilder.queryFor(targetType, getPrismContext()).item(new QName(SchemaConstants.NS_C, pLabel)).startsWith(input).matching(new QName(SchemaConstants.NS_MATCHING_RULE, "origIgnoreCase")).maxSize(AUTO_COMPLETE_BOX_SIZE).build();
try {
objects = getPageBase().getModelService().searchObjects(targetType, query, SelectorOptions.createCollection(GetOperationOptions.createNoFetch()), task, result);
for (PrismObject<O> o : objects) {
Object realKeyValue = null;
PrismProperty labelItem = o.findProperty(label);
//TODO: e.g. support not only for property, but also ref, container..
if (labelItem == null || labelItem.isEmpty()) {
continue;
}
PrismProperty keyItem = o.findProperty(key);
if ("oid".equals(pKey)) {
realKeyValue = o.getOid();
}
if (realKeyValue == null && (keyItem == null || keyItem.isEmpty())) {
continue;
}
//TODO: support for single/multivalue value
if (!labelItem.isSingleValue()) {
continue;
}
Object realLabelValue = labelItem.getRealValue();
realKeyValue = (realKeyValue == null) ? keyItem.getRealValue() : realKeyValue;
// TODO: take definition into account
QName typeName = labelItem.getDefinition().getTypeName();
LookupTableRowType row = new LookupTableRowType();
if (realKeyValue != null) {
row.setKey(convertObjectToPolyStringType(realKeyValue).getOrig());
} else {
throw new SchemaException("Cannot create lookup table with null key for label: " + realLabelValue);
}
row.setLabel(convertObjectToPolyStringType(realLabelValue));
rows.add(row);
}
return rows;
} catch (SchemaException | ObjectNotFoundException | SecurityViolationException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
error("Error while creating lookup table for input parameter: " + param.getName() + ", " + e.getClass().getSimpleName() + " (" + e.getMessage() + ")");
//e.printStackTrace();
}
}
return rows;
}
Aggregations