use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.
the class MockSingleTaskHandler method run.
@Override
public TaskRunResult run(Task task) {
LOGGER.info("MockSingle.run starting (id = " + id + ")");
long progress = task.getProgress();
OperationResult opResult = new OperationResult(MockSingleTaskHandler.class.getName() + ".run");
TaskRunResult runResult = new TaskRunResult();
runResult.setOperationResult(opResult);
// TODO
progress++;
opResult.recordSuccess();
// This "run" is finished. But the task goes on ...
runResult.setRunResultStatus(TaskRunResultStatus.FINISHED);
runResult.setProgress(progress);
hasRun = true;
if ("L1".equals(id)) {
PrismProperty<Boolean> l1flag = task.getExtensionProperty(L1_FLAG_QNAME);
if (l1flag == null || l1flag.getRealValue() == false) {
LOGGER.info("L1 handler, first run - scheduling L2 handler");
ScheduleType l2Schedule = new ScheduleType();
l2Schedule.setInterval(2);
task.pushHandlerUri(TestQuartzTaskManagerContract.L2_TASK_HANDLER_URI, l2Schedule, TaskBinding.TIGHT, ((TaskQuartzImpl) task).createExtensionDelta(l1FlagDefinition, true));
try {
task.savePendingModifications(opResult);
} catch (Exception e) {
throw new SystemException("Cannot schedule L2 handler", e);
}
runResult.setRunResultStatus(TaskRunResultStatus.RESTART_REQUESTED);
} else {
LOGGER.info("L1 handler, not the first run (progress = " + progress + ", l1Flag = " + l1flag.getRealValue() + "), exiting.");
}
} else if ("L2".equals(id)) {
if (progress == 5) {
LOGGER.info("L2 handler, fourth run - scheduling L3 handler");
task.pushHandlerUri(TestQuartzTaskManagerContract.L3_TASK_HANDLER_URI, new ScheduleType(), null);
try {
task.savePendingModifications(opResult);
} catch (Exception e) {
throw new SystemException("Cannot schedule L3 handler", e);
}
runResult.setRunResultStatus(TaskRunResultStatus.RESTART_REQUESTED);
} else if (progress < 5) {
LOGGER.info("L2 handler, progress = " + progress + ", continuing.");
} else if (progress > 5) {
LOGGER.info("L2 handler, progress too big, i.e. " + progress + ", exiting.");
try {
((TaskQuartzImpl) task).finishHandler(opResult);
} catch (Exception e) {
throw new SystemException("Cannot finish L2 handler", e);
}
}
} else if ("L3".equals(id)) {
LOGGER.info("L3 handler, simply exiting. Progress = " + progress);
} else if ("WFS".equals(id)) {
PrismProperty<Boolean> wfsFlag = task.getExtensionProperty(WFS_FLAG_QNAME);
if (wfsFlag == null || wfsFlag.getRealValue() == false) {
LOGGER.info("Wait-for-subtasks creating subtasks...");
Task t1 = task.createSubtask();
t1.setHandlerUri(TestQuartzTaskManagerContract.L3_TASK_HANDLER_URI);
taskManager.switchToBackground(t1, opResult);
Task t2 = task.createSubtask();
t2.setHandlerUri(TestQuartzTaskManagerContract.SINGLE_TASK_HANDLER_URI);
taskManager.switchToBackground(t2, opResult);
try {
ArrayList<ItemDelta<?, ?>> deltas = new ArrayList<>();
deltas.add(((TaskQuartzImpl) task).createExtensionDelta(wfsFlagDefinition, true));
runResult = ((TaskQuartzImpl) task).waitForSubtasks(2, deltas, opResult);
runResult.setProgress(1);
} catch (Exception e) {
throw new SystemException("WaitForSubtasks failed.", e);
}
} else {
LOGGER.info("Wait-for-subtasks seems to finish successfully; progress = " + progress + ", wfsFlag = " + wfsFlag.getRealValue());
}
}
LOGGER.info("MockSingle.run stopping");
return runResult;
}
use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.
the class TestScience method test100JackAssignRoleStatistics.
@Test
public void test100JackAssignRoleStatistics() throws Exception {
final String TEST_NAME = "test100JackAssignRoleStatistics";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestScience.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
assignRole(USER_JACK_OID, ROLE_STATISTICS_OID);
PrismObject<UserType> userJack = repositoryService.getObject(UserType.class, USER_JACK_OID, null, result);
AssertJUnit.assertNotNull("User jack not found", userJack);
UserType jackType = userJack.asObjectable();
IntegrationTestTools.display("User Jack", jackType);
AssertJUnit.assertEquals("Wrong number of link refs", 3, jackType.getLinkRef().size());
assertUserJack(userJack);
assertLinks(userJack, 3);
String accountStatsOid = getLinkRefOid(userJack, RESOURCE_DUMMY_STATS_OID);
String accountUnixOid = getLinkRefOid(userJack, RESOURCE_DUMMY_UNIX_OID);
String accountOpenDjOid = getLinkRefOid(userJack, RESOURCE_OPENDJ_AD_SIMULATION_OID);
PrismObject<ShadowType> shadowStats = provisioningService.getObject(ShadowType.class, accountStatsOid, null, task, result);
IntegrationTestTools.display("Stats account: ", shadowStats);
PrismObject<ShadowType> shadowUnix = provisioningService.getObject(ShadowType.class, accountUnixOid, null, task, result);
IntegrationTestTools.display("Unix account: ", shadowUnix);
PrismObject<ShadowType> shadowOpenDj = provisioningService.getObject(ShadowType.class, accountOpenDjOid, null, task, result);
IntegrationTestTools.display("AD account: ", shadowOpenDj);
//internalId on unix dummy resource and title on openDJ simulation must be the same
PrismProperty unixId = shadowUnix.findProperty(new ItemPath(ShadowType.F_ATTRIBUTES, UNIX_INTERNAL_ID));
assertNotNull("No " + UNIX_INTERNAL_ID + " in " + shadowUnix, unixId);
PrismProperty openDjSyncedId = shadowOpenDj.findProperty(new ItemPath(ShadowType.F_ATTRIBUTES, new QName(NS_RESOURCE_INSTANCE, "title")));
assertNotNull("No 'title' in " + shadowOpenDj, openDjSyncedId);
PrismAsserts.assertEquals("Unix id was not synced to the opendj properly.", String.valueOf(unixId.getAnyRealValue()), openDjSyncedId.getAnyRealValue());
PrismProperty<Integer> generatedValue = userJack.findExtensionItem(SCIENCE_EXTENSION_UID_QNAME);
assertNotNull("Generated id value must not be null", generatedValue);
assertFalse("Generated value must not be empty", generatedValue.isEmpty());
}
use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.
the class ConnIdConfigurationTransformer method transformConnectorTimeoutsConfiguration.
private void transformConnectorTimeoutsConfiguration(APIConfiguration apiConfig, PrismContainer<?> connectorTimeoutsContainer) throws SchemaException {
if (connectorTimeoutsContainer == null || connectorTimeoutsContainer.getValue() == null) {
return;
}
for (PrismProperty prismProperty : connectorTimeoutsContainer.getValue().getProperties()) {
QName propertQName = prismProperty.getElementName();
if (SchemaConstants.NS_ICF_CONFIGURATION.equals(propertQName.getNamespaceURI())) {
String opName = propertQName.getLocalPart();
Class<? extends APIOperation> apiOpClass = ConnectorFactoryConnIdImpl.resolveApiOpClass(opName);
if (apiOpClass != null) {
apiConfig.setTimeout(apiOpClass, parseInt(prismProperty));
} else {
throw new SchemaException("Unknown operation name " + opName + " in " + ConnectorFactoryConnIdImpl.CONNECTOR_SCHEMA_TIMEOUTS_XML_ELEMENT_NAME);
}
}
}
}
use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.
the class TaskQuartzImpl method createExtensionDelta.
public ItemDelta<?, ?> createExtensionDelta(PrismPropertyDefinition definition, Object realValue) {
PrismProperty<?> property = (PrismProperty<?>) definition.instantiate();
property.setRealValue(realValue);
PropertyDelta propertyDelta = PropertyDelta.createModificationReplaceProperty(new ItemPath(TaskType.F_EXTENSION, property.getElementName()), definition, realValue);
// propertyDelta.setValuesToReplace(PrismValue.cloneCollection(property.getValues()));
return propertyDelta;
}
use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.
the class RawTypeUtil method getParsedItem.
public static <IV extends PrismValue, ID extends ItemDefinition> Item<IV, ID> getParsedItem(ID itemDefinition, List<RawType> values, QName elementQName, PrismContainerDefinition containerDef) throws SchemaException {
Item<IV, ID> subItem = null;
List<IV> parsedValues = new ArrayList<IV>();
for (RawType rawValue : values) {
if (itemDefinition == null && containerDef != null) {
itemDefinition = (ID) ((PrismContextImpl) containerDef.getPrismContext()).getPrismUnmarshaller().locateItemDefinition(containerDef, elementQName, rawValue.getXnode());
}
IV parsed = rawValue.getParsedValue(itemDefinition, elementQName);
if (parsed != null) {
parsedValues.add(parsed);
}
}
PrismContext prismContext = null;
if (containerDef != null) {
prismContext = containerDef.getPrismContext();
}
if (prismContext == null && itemDefinition != null) {
prismContext = itemDefinition.getPrismContext();
}
if (itemDefinition == null) {
PrismProperty property = new PrismProperty(elementQName, prismContext);
property.addAll(PrismValue.cloneCollection(parsedValues));
return property;
}
if (itemDefinition instanceof PrismPropertyDefinition<?>) {
// property
PrismProperty<?> property = ((PrismPropertyDefinition<?>) itemDefinition).instantiate();
for (IV val : parsedValues) {
property.add((PrismPropertyValue) val.clone());
}
subItem = (Item<IV, ID>) property;
} else if (itemDefinition instanceof PrismContainerDefinition<?>) {
PrismContainer<?> container = ((PrismContainerDefinition<?>) itemDefinition).instantiate();
for (IV val : parsedValues) {
container.add((PrismContainerValue) val.clone());
}
subItem = (Item<IV, ID>) container;
} else if (itemDefinition instanceof PrismReferenceDefinition) {
// TODO
PrismReference reference = ((PrismReferenceDefinition) itemDefinition).instantiate();
for (IV val : parsedValues) {
PrismReferenceValue ref;
if (val instanceof PrismReferenceValue) {
ref = (PrismReferenceValue) val.clone();
} else if (val instanceof PrismContainerValue) {
// this is embedded (full) object
Containerable c = ((PrismContainerValue) val).asContainerable();
if (!(c instanceof Objectable)) {
throw new IllegalStateException("Content of " + itemDefinition + " is a Containerable but not Objectable: " + c);
}
Objectable o = (Objectable) c;
ref = new PrismReferenceValue();
ref.setObject(o.asPrismObject());
} else {
throw new IllegalStateException("Content of " + itemDefinition + " is neither PrismReferenceValue nor PrismContainerValue: " + val);
}
reference.merge(ref);
}
subItem = (Item<IV, ID>) reference;
} else {
throw new IllegalArgumentException("Unsupported definition type " + itemDefinition.getClass());
}
return subItem;
}
Aggregations