use of com.evolveum.midpoint.task.api.Task in project midpoint by Evolveum.
the class PageRequestRole method loadUser.
private void loadUser() {
LOGGER.debug("Loading user and accounts.");
OperationResult result = new OperationResult(OPERATION_LOAD_USER);
try {
String userOid = SecurityUtils.getPrincipalUser().getOid();
Task task = createSimpleTask(OPERATION_LOAD_USER);
user = WebModelServiceUtils.loadObject(UserType.class, userOid, null, (PageBase) getPage(), task, result);
result.recordSuccessIfUnknown();
result.recordSuccessIfUnknown();
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load accounts", ex);
result.recordFatalError("Couldn't load accounts", ex);
} finally {
result.recomputeStatus();
}
if (!result.isSuccess() && !result.isHandledError()) {
showResult(result);
}
}
use of com.evolveum.midpoint.task.api.Task in project midpoint by Evolveum.
the class PageSelfDashboard method loadWorkItems.
private CallableResult<List<WorkItemDto>> loadWorkItems() {
LOGGER.debug("Loading work items.");
AccountCallableResult callableResult = new AccountCallableResult();
List<WorkItemDto> list = new ArrayList<>();
callableResult.setValue(list);
if (!getWorkflowManager().isEnabled()) {
return callableResult;
}
PrismObject<UserType> user = principalModel.getObject();
if (user == null) {
return callableResult;
}
Task task = createSimpleTask(OPERATION_LOAD_WORK_ITEMS);
OperationResult result = task.getResult();
callableResult.setResult(result);
try {
ObjectQuery query = QueryBuilder.queryFor(WorkItemType.class, getPrismContext()).item(WorkItemType.F_ASSIGNEE_REF).ref(user.getOid()).desc(F_CREATE_TIMESTAMP).build();
Collection<SelectorOptions<GetOperationOptions>> options = GetOperationOptions.resolveItemsNamed(new ItemPath(T_PARENT, WfContextType.F_OBJECT_REF), new ItemPath(T_PARENT, WfContextType.F_TARGET_REF));
List<WorkItemType> workItems = getModelService().searchContainers(WorkItemType.class, query, options, task, result);
for (WorkItemType workItem : workItems) {
list.add(new WorkItemDto(workItem));
}
} catch (Exception e) {
result.recordFatalError("Couldn't get list of work items.", e);
}
result.recordSuccessIfUnknown();
result.recomputeStatus();
LOGGER.debug("Finished work items loading.");
return callableResult;
}
use of com.evolveum.midpoint.task.api.Task in project midpoint by Evolveum.
the class PageAssignmentShoppingKart method getRoleCatalogOid.
private String getRoleCatalogOid() {
Task task = getPageBase().createAnonymousTask(OPERATION_LOAD_ROLE_CATALOG_REFERENCE);
OperationResult result = task.getResult();
SystemConfigurationType config;
try {
config = getPageBase().getModelInteractionService().getSystemConfiguration(result);
} catch (ObjectNotFoundException | SchemaException e) {
LOGGER.error("Error getting system configuration: {}", e.getMessage(), e);
return null;
}
if (config != null && config.getRoleManagement() != null && config.getRoleManagement().getRoleCatalogRef() != null) {
return config.getRoleManagement().getRoleCatalogRef().getOid();
}
return "";
}
use of com.evolveum.midpoint.task.api.Task in project midpoint by Evolveum.
the class ObjectWrapperTest method testEmptyPolyString.
@Test
public void testEmptyPolyString() throws Exception {
PrismObject<UserType> user = prismContext.parseObject(new File("./src/test/resources/wrapper/user.xml"));
Task task = taskManager.createTaskInstance("testEmptyPolyString");
ObjectWrapperFactory owf = new ObjectWrapperFactory(null);
ObjectWrapper<UserType> wrapper = owf.createObjectWrapper(null, null, user, ContainerStatus.MODIFYING, task);
//simulate change on honorific prefix
ContainerWrapper containerWrapper = null;
for (ContainerWrapper container : wrapper.getContainers()) {
if (container.isMain()) {
containerWrapper = container;
break;
}
}
PropertyWrapper propertyWrapper = (PropertyWrapper) containerWrapper.findPropertyWrapper(UserType.F_HONORIFIC_SUFFIX);
ValueWrapper valueWrapper = (ValueWrapper) propertyWrapper.getValues().get(0);
PolyString value = (PolyString) ((PrismPropertyValue) valueWrapper.getValue()).getValue();
Field orig = PolyString.class.getDeclaredField("orig");
orig.setAccessible(true);
orig.set(value, null);
orig.setAccessible(false);
ObjectDelta delta = wrapper.getObjectDelta();
AssertJUnit.assertNotNull(delta);
}
use of com.evolveum.midpoint.task.api.Task in project midpoint by Evolveum.
the class TestIntegrationObjectWrapperFactory method test102CreateWrapperUserEmpty.
@Test
public void test102CreateWrapperUserEmpty() throws Exception {
final String TEST_NAME = "test102CreateWrapperUserEmpty";
TestUtil.displayTestTile(TEST_NAME);
PrismObject<UserType> user = getUser(USER_EMPTY_OID);
// WHEN
TestUtil.displayWhen(TEST_NAME);
Task task = taskManager.createTaskInstance(TEST_NAME);
ObjectWrapperFactory factory = new ObjectWrapperFactory(getServiceLocator());
ObjectWrapper<UserType> objectWrapper = factory.createObjectWrapper("user display name", "user description", user, ContainerStatus.MODIFYING, task);
// THEN
TestUtil.displayThen(TEST_NAME);
IntegrationTestTools.display("Wrapper after", objectWrapper);
WrapperTestUtil.assertWrapper(objectWrapper, "user display name", "user description", user, ContainerStatus.MODIFYING);
assertEquals("wrong number of containers in " + objectWrapper, 11, objectWrapper.getContainers().size());
ContainerWrapper<UserType> mainContainerWrapper = objectWrapper.findContainerWrapper(null);
WrapperTestUtil.assertWrapper(mainContainerWrapper, "prismContainer.mainPanelDisplayName", (ItemPath) null, user, ContainerStatus.MODIFYING);
WrapperTestUtil.assertPropertyWrapper(mainContainerWrapper, UserType.F_NAME, PrismTestUtil.createPolyString(USER_EMPTY_USERNAME));
WrapperTestUtil.assertPropertyWrapper(mainContainerWrapper, UserType.F_TIMEZONE, null);
// Not sure about this
// ContainerWrapper<ActivationType> activationContainerWrapper = objectWrapper.findContainerWrapper(new ItemPath(UserType.F_ACTIVATION));
// assertNull("Unexpected activation "+activationContainerWrapper, activationContainerWrapper);
assertEquals("Wrong main container wrapper readOnly", Boolean.FALSE, (Boolean) mainContainerWrapper.isReadonly());
assertItemWrapperFullConrol(mainContainerWrapper, UserType.F_NAME, true);
// emphasized
assertItemWrapperFullConrol(mainContainerWrapper, UserType.F_GIVEN_NAME, true);
// emphasized
assertItemWrapperFullConrol(mainContainerWrapper, UserType.F_FULL_NAME, true);
// empty
assertItemWrapperFullConrol(mainContainerWrapper, UserType.F_ADDITIONAL_NAME, false);
// empty
assertItemWrapperFullConrol(mainContainerWrapper, UserType.F_LOCALITY, false);
// WHEN
objectWrapper.setShowEmpty(true);
// THEN
assertItemWrapperFullConrol(mainContainerWrapper, UserType.F_NAME, true);
// emphasized
assertItemWrapperFullConrol(mainContainerWrapper, UserType.F_GIVEN_NAME, true);
// emphasized
assertItemWrapperFullConrol(mainContainerWrapper, UserType.F_FULL_NAME, true);
// empty
assertItemWrapperFullConrol(mainContainerWrapper, UserType.F_ADDITIONAL_NAME, true);
// empty
assertItemWrapperFullConrol(mainContainerWrapper, UserType.F_LOCALITY, true);
}
Aggregations