use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.
the class PageTaskAdd method createTask.
private TaskType createTask(TaskAddDto dto) throws SchemaException {
TaskType task = new TaskType();
MidPointPrincipal owner = SecurityUtils.getPrincipalUser();
ObjectReferenceType ownerRef = new ObjectReferenceType();
ownerRef.setOid(owner.getOid());
ownerRef.setType(owner.getUser().COMPLEX_TYPE);
task.setOwnerRef(ownerRef);
task.setCategory(dto.getCategory());
String handlerUri = getTaskManager().getHandlerUriForCategory(dto.getCategory());
if (handlerUri == null) {
throw new SystemException("Cannot determine task handler URI for category " + dto.getCategory());
}
task.setHandlerUri(handlerUri);
ObjectReferenceType objectRef;
if (dto.getResource() != null) {
objectRef = new ObjectReferenceType();
objectRef.setOid(dto.getResource().getOid());
objectRef.setType(ResourceType.COMPLEX_TYPE);
task.setObjectRef(objectRef);
}
task.setName(WebComponentUtil.createPolyFromOrigString(dto.getName()));
task.setRecurrence(dto.getReccuring() ? TaskRecurrenceType.RECURRING : TaskRecurrenceType.SINGLE);
task.setBinding(dto.getBound() ? TaskBindingType.TIGHT : TaskBindingType.LOOSE);
ScheduleType schedule = new ScheduleType();
schedule.setInterval(dto.getInterval());
schedule.setCronLikePattern(dto.getCron());
schedule.setEarliestStartTime(MiscUtil.asXMLGregorianCalendar(dto.getNotStartBefore()));
schedule.setLatestStartTime(MiscUtil.asXMLGregorianCalendar(dto.getNotStartAfter()));
schedule.setMisfireAction(dto.getMisfireAction());
task.setSchedule(schedule);
if (dto.getSuspendedState()) {
task.setExecutionStatus(TaskExecutionStatusType.SUSPENDED);
} else {
task.setExecutionStatus(TaskExecutionStatusType.RUNNABLE);
}
if (dto.getThreadStop() != null) {
task.setThreadStopAction(dto.getThreadStop());
} else {
// fill-in default
if (dto.getRunUntilNodeDown() == true) {
task.setThreadStopAction(ThreadStopActionType.CLOSE);
} else {
task.setThreadStopAction(ThreadStopActionType.RESTART);
}
}
if (dto.isDryRun()) {
PrismObject<TaskType> prismTask = task.asPrismObject();
ItemPath path = new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_DRY_RUN);
PrismProperty dryRun = prismTask.findOrCreateProperty(path);
SchemaRegistry registry = getPrismContext().getSchemaRegistry();
PrismPropertyDefinition def = registry.findPropertyDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_DRY_RUN);
dryRun.setDefinition(def);
dryRun.setRealValue(true);
}
if (dto.getFocusType() != null) {
PrismObject<TaskType> prismTask = task.asPrismObject();
ItemPath path = new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_OBJECT_TYPE);
PrismProperty focusType = prismTask.findOrCreateProperty(path);
focusType.setRealValue(dto.getFocusType());
}
if (dto.getKind() != null) {
PrismObject<TaskType> prismTask = task.asPrismObject();
ItemPath path = new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_KIND);
PrismProperty kind = prismTask.findOrCreateProperty(path);
SchemaRegistry registry = getPrismContext().getSchemaRegistry();
PrismPropertyDefinition def = registry.findPropertyDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_KIND);
kind.setDefinition(def);
kind.setRealValue(dto.getKind());
}
if (dto.getIntent() != null && StringUtils.isNotEmpty(dto.getIntent())) {
PrismObject<TaskType> prismTask = task.asPrismObject();
ItemPath path = new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_INTENT);
PrismProperty intent = prismTask.findOrCreateProperty(path);
SchemaRegistry registry = getPrismContext().getSchemaRegistry();
PrismPropertyDefinition def = registry.findPropertyDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_INTENT);
intent.setDefinition(def);
intent.setRealValue(dto.getIntent());
}
if (dto.getObjectClass() != null && StringUtils.isNotEmpty(dto.getObjectClass())) {
PrismObject<TaskType> prismTask = task.asPrismObject();
ItemPath path = new ItemPath(TaskType.F_EXTENSION, SchemaConstants.OBJECTCLASS_PROPERTY_NAME);
PrismProperty objectClassProperty = prismTask.findOrCreateProperty(path);
QName objectClass = null;
for (QName q : model.getObject().getObjectClassList()) {
if (q.getLocalPart().equals(dto.getObjectClass())) {
objectClass = q;
}
}
SchemaRegistry registry = getPrismContext().getSchemaRegistry();
PrismPropertyDefinition def = registry.findPropertyDefinitionByElementName(SchemaConstants.OBJECTCLASS_PROPERTY_NAME);
objectClassProperty.setDefinition(def);
objectClassProperty.setRealValue(objectClass);
}
return task;
}
use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.
the class ColumnUtils method getDefaultTaskColumns.
public static <T extends ObjectType> List<IColumn<SelectableBean<T>, String>> getDefaultTaskColumns() {
List<IColumn<SelectableBean<T>, String>> columns = new ArrayList<IColumn<SelectableBean<T>, String>>();
columns.add(new AbstractColumn<SelectableBean<T>, String>(createStringResource("TaskType.kind")) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(Item<ICellPopulator<SelectableBean<T>>> cellItem, String componentId, IModel<SelectableBean<T>> rowModel) {
SelectableBean<TaskType> object = (SelectableBean<TaskType>) rowModel.getObject();
PrismProperty<ShadowKindType> pKind = object.getValue() != null ? object.getValue().asPrismObject().findProperty(new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_KIND)) : null;
if (pKind != null) {
cellItem.add(new Label(componentId, WebComponentUtil.createLocalizedModelForEnum(pKind.getRealValue(), cellItem)));
} else {
cellItem.add(new Label(componentId));
}
}
});
columns.add(new AbstractColumn<SelectableBean<T>, String>(createStringResource("TaskType.intent")) {
@Override
public void populateItem(Item<ICellPopulator<SelectableBean<T>>> cellItem, String componentId, IModel<SelectableBean<T>> rowModel) {
SelectableBean<TaskType> object = (SelectableBean<TaskType>) rowModel.getObject();
PrismProperty<String> pIntent = object.getValue() != null ? object.getValue().asPrismObject().findProperty(new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_INTENT)) : null;
if (pIntent != null) {
cellItem.add(new Label(componentId, pIntent.getRealValue()));
} else {
cellItem.add(new Label(componentId));
}
}
});
columns.add(new AbstractColumn<SelectableBean<T>, String>(createStringResource("TaskType.objectClass")) {
@Override
public void populateItem(Item<ICellPopulator<SelectableBean<T>>> cellItem, String componentId, IModel<SelectableBean<T>> rowModel) {
SelectableBean<TaskType> object = (SelectableBean<TaskType>) rowModel.getObject();
PrismProperty<QName> pObjectClass = object.getValue() != null ? object.getValue().asPrismObject().findProperty(new ItemPath(TaskType.F_EXTENSION, SchemaConstants.OBJECTCLASS_PROPERTY_NAME)) : null;
if (pObjectClass != null) {
cellItem.add(new Label(componentId, pObjectClass.getRealValue().getLocalPart()));
} else {
cellItem.add(new Label(componentId, ""));
}
}
});
List<ColumnTypeDto<String>> columnsDefs = Arrays.asList(new ColumnTypeDto<String>("TaskType.executionStatus", TaskType.F_EXECUTION_STATUS.getLocalPart(), SelectableBean.F_VALUE + ".executionStatus", false));
columns.addAll(ColumnUtils.<SelectableBean<T>>createColumns(columnsDefs));
return columns;
}
use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.
the class TestDiffEquals method testDiffShadow.
@Test
public void testDiffShadow() throws Exception {
System.out.println("\n\n===[ testDiffShadow ]===\n");
PrismContext prismContext = PrismTestUtil.getPrismContext();
PrismObject<ShadowType> shadow1 = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(ShadowType.class).instantiate();
ShadowType shadow1Type = shadow1.asObjectable();
shadow1Type.setName(new PolyStringType("Whatever"));
shadow1Type.setFailedOperationType(FailedOperationTypeType.ADD);
shadow1Type.getAuxiliaryObjectClass().add(new QName(NS_TEST_RI, "foo"));
PrismContainer<Containerable> shadow1Attrs = shadow1.findOrCreateContainer(ShadowType.F_ATTRIBUTES);
ShadowType shadow2Type = new ShadowType();
PrismObject<ShadowType> shadow2 = shadow2Type.asPrismObject();
prismContext.adopt(shadow2Type);
shadow2Type.setName(new PolyStringType("Whatever"));
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);
PrismProperty<String> attrEntryUuid = new PrismProperty<>(new QName(NS_TEST_RI, "entryUuid"), prismContext);
PrismPropertyDefinition<String> attrEntryUuidDef = new PrismPropertyDefinitionImpl<>(new QName(NS_TEST_RI, "entryUuid"), DOMUtil.XSD_STRING, prismContext);
attrEntryUuid.setDefinition(attrEntryUuidDef);
shadow2Attrs.add(attrEntryUuid);
attrEntryUuid.addRealValue("1234-5678-8765-4321");
PrismProperty<String> attrDn = new PrismProperty<>(new QName(NS_TEST_RI, "dn"), prismContext);
PrismPropertyDefinition<String> attrDnDef = new PrismPropertyDefinitionImpl<>(new QName(NS_TEST_RI, "dn"), DOMUtil.XSD_STRING, prismContext);
attrDn.setDefinition(attrDnDef);
shadow2Attrs.add(attrDn);
attrDn.addRealValue("uid=foo,o=bar");
System.out.println("Shadow 1");
System.out.println(shadow1.debugDump(1));
System.out.println("Shadow 2");
System.out.println(shadow2.debugDump(1));
// WHEN
ObjectDelta<ShadowType> delta = shadow1.diff(shadow2);
// THEN
assertNotNull("No delta", delta);
System.out.println("Delta");
System.out.println(delta.debugDump(1));
PrismAsserts.assertIsModify(delta);
PrismAsserts.assertPropertyDelete(delta, ShadowType.F_FAILED_OPERATION_TYPE, FailedOperationTypeType.ADD);
PrismAsserts.assertPropertyAdd(delta, ShadowType.F_AUXILIARY_OBJECT_CLASS, new QName(NS_TEST_RI, "bar"));
PrismAsserts.assertContainerAdd(delta, ShadowType.F_ATTRIBUTES, shadow2Attrs.getValue().clone());
PrismAsserts.assertModifications(delta, 3);
}
use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.
the class WebComponentUtil method createSingleRecurrenceTask.
public static TaskType createSingleRecurrenceTask(String taskName, QName applicableType, ObjectQuery query, ObjectDelta delta, ModelExecuteOptions options, String category, PageBase pageBase) throws SchemaException {
TaskType task = new TaskType();
MidPointPrincipal owner = SecurityUtils.getPrincipalUser();
ObjectReferenceType ownerRef = new ObjectReferenceType();
ownerRef.setOid(owner.getOid());
ownerRef.setType(owner.getUser().COMPLEX_TYPE);
task.setOwnerRef(ownerRef);
task.setBinding(TaskBindingType.LOOSE);
task.setCategory(category);
task.setExecutionStatus(TaskExecutionStatusType.RUNNABLE);
task.setRecurrence(TaskRecurrenceType.SINGLE);
task.setThreadStopAction(ThreadStopActionType.RESTART);
task.setHandlerUri(pageBase.getTaskService().getHandlerUriForCategory(category));
ScheduleType schedule = new ScheduleType();
schedule.setMisfireAction(MisfireActionType.EXECUTE_IMMEDIATELY);
task.setSchedule(schedule);
task.setName(WebComponentUtil.createPolyFromOrigString(taskName));
PrismObject<TaskType> prismTask = task.asPrismObject();
ItemPath path = new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_OBJECT_QUERY);
PrismProperty objectQuery = prismTask.findOrCreateProperty(path);
QueryType queryType = QueryJaxbConvertor.createQueryType(query, pageBase.getPrismContext());
objectQuery.addRealValue(queryType);
path = new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_OBJECT_TYPE);
PrismProperty objectType = prismTask.findOrCreateProperty(path);
objectType.setRealValue(applicableType);
if (delta != null) {
path = new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_OBJECT_DELTA);
PrismProperty objectDelta = prismTask.findOrCreateProperty(path);
objectDelta.setRealValue(DeltaConvertor.toObjectDeltaType(delta));
}
if (options != null) {
prismTask.findOrCreateProperty(new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_EXECUTE_OPTIONS)).setRealValue(options.toModelExecutionOptionsType());
}
return task;
}
use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.
the class RunReportPopupPanel method runConfirmPerformed.
// private void addFormUpdatingBehavior(FormComponent parent, String id, final IModel<JasperReportParameterDto> model) {
// Component c = parent.get(id);
// if (c == null) {
// return;
// }
// c.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
// }
private void runConfirmPerformed(AjaxRequestTarget target, IModel<ReportDto> model) {
ReportDto reportDto = model.getObject();
PrismContainerDefinition<ReportParameterType> paramContainerDef = getPrismContext().getSchemaRegistry().findContainerDefinitionByElementName(ReportConstants.REPORT_PARAMS_PROPERTY_NAME);
PrismContainer<ReportParameterType> paramContainer;
try {
paramContainer = paramContainerDef.instantiate();
ReportParameterType reportParam = new ReportParameterType();
PrismContainerValue<ReportParameterType> reportParamValue = reportParam.asPrismContainerValue();
reportParamValue.revive(getPrismContext());
paramContainer.add(reportParamValue);
List<JasperReportParameterDto> params = getParametersView().getModelObject();
for (JasperReportParameterDto paramDto : params) {
if (paramDto.getValue() == null) {
continue;
}
List<JasperReportValueDto> values = paramDto.getValue();
Class<?> paramClass = paramDto.getType();
boolean multivalue = false;
if (List.class.isAssignableFrom(paramClass)) {
paramClass = paramDto.getNestedType();
if (paramClass == null) {
getSession().error("Nested type for list must be defined!");
target.add(getPageBase().getFeedbackPanel());
return;
}
}
QName typeName = getPrismContext().getSchemaRegistry().determineTypeForClass(paramClass);
PrismPropertyDefinitionImpl<?> def = new PrismPropertyDefinitionImpl<>(new QName(ReportConstants.NS_EXTENSION, paramDto.getName()), typeName, getPrismContext());
def.setDynamic(true);
def.setRuntimeSchema(true);
// TODO multivalue is always 'false' here ...
def.setMaxOccurs(multivalue ? -1 : 1);
PrismProperty prop = def.instantiate();
for (JasperReportValueDto paramValue : values) {
Object realValue = paramValue.getValue();
if (realValue == null) {
continue;
}
if (AuditEventType.class.isAssignableFrom(paramClass)) {
paramClass = AuditEventTypeType.class;
realValue = AuditEventType.fromAuditEventType((AuditEventType) realValue);
} else if (AuditEventStage.class.isAssignableFrom(paramClass)) {
paramClass = AuditEventStageType.class;
realValue = AuditEventStage.fromAuditEventStage((AuditEventStage) realValue);
}
prop.addRealValue(realValue);
}
if (!prop.isEmpty()) {
reportParamValue.add(prop);
}
}
} catch (SchemaException | ClassNotFoundException e) {
OperationResult result = new OperationResult("Parameters serialization");
result.recordFatalError("Could not serialize parameters");
getPageBase().showResult(result);
return;
}
runConfirmPerformed(target, reportDto.getObject().asObjectable(), paramContainer);
}
Aggregations