use of com.evolveum.midpoint.prism.PrismPropertyDefinition in project midpoint by Evolveum.
the class ACAttributeValuePanel method isAddVisible.
private boolean isAddVisible() {
ACValueConstructionDto dto = getModel().getObject();
ACAttributeDto attributeDto = dto.getAttribute();
PrismPropertyDefinition def = attributeDto.getDefinition();
List<ACValueConstructionDto> values = attributeDto.getValues();
if (def.getMaxOccurs() != -1 && values.size() >= def.getMaxOccurs()) {
return false;
}
//we want to show add on last item only
if (values.indexOf(dto) + 1 != values.size()) {
return false;
}
return true;
}
use of com.evolveum.midpoint.prism.PrismPropertyDefinition in project midpoint by Evolveum.
the class ACAttributeValuePanel method isRemoveVisible.
private boolean isRemoveVisible() {
ACValueConstructionDto dto = getModel().getObject();
ACAttributeDto attributeDto = dto.getAttribute();
PrismPropertyDefinition def = attributeDto.getDefinition();
List<ACValueConstructionDto> values = attributeDto.getValues();
if (values.size() <= 1) {
return false;
}
if (values.size() <= def.getMinOccurs()) {
return false;
}
return true;
}
use of com.evolveum.midpoint.prism.PrismPropertyDefinition in project midpoint by Evolveum.
the class ACAttributeValuePanel method initLayout.
private void initLayout(Form form, boolean ignoreMandatoryAttributes) {
ACValueConstructionDto dto = getModel().getObject();
PrismPropertyDefinition definition = dto.getAttribute().getDefinition();
InputPanel input = createTypedInputComponent(ID_INPUT, definition);
for (FormComponent comp : input.getFormComponents()) {
comp.setLabel(new PropertyModel(dto.getAttribute(), ACAttributeDto.F_NAME));
if (!ignoreMandatoryAttributes) {
comp.setRequired(definition.getMinOccurs() > 0);
}
comp.add(new AjaxFormComponentUpdatingBehavior("blur") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
}
});
}
add(input);
AjaxLink addLink = new AjaxLink(ID_ADD) {
@Override
public void onClick(AjaxRequestTarget target) {
addPerformed(target);
}
};
add(addLink);
addLink.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return isAddVisible();
}
});
AjaxLink removeLink = new AjaxLink(ID_REMOVE) {
@Override
public void onClick(AjaxRequestTarget target) {
removePerformed(target);
}
};
add(removeLink);
removeLink.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return isRemoveVisible();
}
});
}
use of com.evolveum.midpoint.prism.PrismPropertyDefinition in project midpoint by Evolveum.
the class AddOverwriteTest method addWithOverwriteResource.
@Test
public void addWithOverwriteResource() throws Exception {
// GIVEN
SchemaRegistry reg = prismContext.getSchemaRegistry();
PrismPropertyDefinition def = reg.findPropertyDefinitionByElementName(CapabilitiesType.F_NATIVE);
PrismObject<ResourceType> resource = prismContext.parseObject(RESOURCE_OPENDJ_FILE);
OperationResult opResult = new OperationResult("Import resource");
repositoryService.addObject(resource, null, opResult);
opResult.computeStatus();
AssertJUnit.assertTrue(opResult.isSuccess());
PrismObject<ResourceType> resourceAfterAdd = repositoryService.getObject(ResourceType.class, RESOURCE_OPENDJ_OID, null, opResult);
MidPointAsserts.assertOid(resourceAfterAdd, RESOURCE_OPENDJ_OID);
MidPointAsserts.assertVersion(resourceAfterAdd, 0);
// Precondition
assertNotNull("no schema", resourceAfterAdd.asObjectable().getSchema());
assertNotNull("no capabilities", resourceAfterAdd.asObjectable().getCapabilities());
resource.asObjectable().setSchema(null);
resource.asObjectable().setCapabilities(null);
// WHEN
repositoryService.addObject(resource, RepoAddOptions.createOverwrite(), opResult);
// THEN
opResult.computeStatus();
AssertJUnit.assertTrue(opResult.isSuccess());
PrismObject<ResourceType> resourceAfterOverwrite = repositoryService.getObject(ResourceType.class, RESOURCE_OPENDJ_OID, null, opResult);
MidPointAsserts.assertOid(resourceAfterOverwrite, RESOURCE_OPENDJ_OID);
MidPointAsserts.assertVersion(resourceAfterOverwrite, 1);
assertNull("schema not gone", resourceAfterOverwrite.asObjectable().getSchema());
assertNull("capabilities not gone", resourceAfterOverwrite.asObjectable().getCapabilities());
}
use of com.evolveum.midpoint.prism.PrismPropertyDefinition in project midpoint by Evolveum.
the class NoOpTaskHandler method run.
@Override
public TaskRunResult run(Task task) {
long progress = task.getProgress();
OperationResult opResult = new OperationResult(NoOpTaskHandler.class.getName() + ".run");
TaskRunResult runResult = new TaskRunResult();
runResult.setOperationResult(opResult);
// would be overwritten when problem is encountered
runResult.setRunResultStatus(TaskRunResultStatus.FINISHED);
PrismContainer taskExtension = task.getExtension();
PrismProperty<Integer> delayProp = taskExtension != null ? taskExtension.findProperty(SchemaConstants.NOOP_DELAY_QNAME) : null;
PrismProperty<Integer> stepsProp = taskExtension != null ? taskExtension.findProperty(SchemaConstants.NOOP_STEPS_QNAME) : null;
PrismPropertyDefinition delayPropDef = taskManagerImpl.getPrismContext().getSchemaRegistry().findPropertyDefinitionByElementName(SchemaConstants.NOOP_DELAY_QNAME);
PrismPropertyDefinition stepsPropDef = taskManagerImpl.getPrismContext().getSchemaRegistry().findPropertyDefinitionByElementName(SchemaConstants.NOOP_STEPS_QNAME);
try {
if (delayProp != null)
delayProp.applyDefinition(delayPropDef);
if (stepsProp != null)
stepsProp.applyDefinition(stepsPropDef);
} catch (SchemaException se) {
LoggingUtils.logUnexpectedException(LOGGER, "Cannot apply Prism definition to delay and/or steps property, exiting immediately.", se);
opResult.recordFatalError("Cannot apply Prism definition to delay and/or steps property, exiting immediately.", se);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return runResult;
}
long delay;
if (delayProp != null && !delayProp.getValues().isEmpty())
delay = delayProp.getValues().get(0).getValue();
else
delay = 0;
int steps;
if (stepsProp != null && !stepsProp.getValues().isEmpty())
steps = stepsProp.getValues().get(0).getValue();
else
steps = 1;
LOGGER.info("NoOpTaskHandler run starting; progress = " + progress + ", steps to be executed = " + steps + ", delay for one step = " + delay + " in task " + task.getName());
for (int i = 0; i < steps; i++) {
LOGGER.info("NoOpTaskHandler: executing step " + (i + 1) + " of " + steps + " in task " + task.getName());
// this strange construction is used to simulate non-interruptible execution of the task
long sleepUntil = System.currentTimeMillis() + delay;
for (; ; ) {
long delta = sleepUntil - System.currentTimeMillis();
if (delta > 0) {
try {
Thread.sleep(delta);
} catch (InterruptedException e) {
}
} else {
// we have slept enough
break;
}
}
progress++;
try {
task.setProgressImmediate(progress, opResult);
} catch (ObjectNotFoundException e) {
LoggingUtils.logException(LOGGER, "Cannot report progress for task {} because the task does not exist anymore.", e, task);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
break;
} catch (SchemaException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Cannot report progress for task {} because of schema exception.", e, task);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
break;
}
if (!task.canRun()) {
LOGGER.info("NoOpTaskHandler: got a shutdown request, finishing task " + task.getName());
break;
}
}
opResult.computeStatusIfUnknown();
runResult.setProgress(progress);
LOGGER.info("NoOpTaskHandler run finishing; progress = " + progress + " in task " + task.getName());
return runResult;
}
Aggregations