Search in sources :

Example 71 with PrismPropertyDefinition

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;
}
Also used : PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition)

Example 72 with PrismPropertyDefinition

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;
}
Also used : PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition)

Example 73 with PrismPropertyDefinition

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();
        }
    });
}
Also used : AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) FormComponent(org.apache.wicket.markup.html.form.FormComponent) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) InputPanel(com.evolveum.midpoint.web.component.prism.InputPanel) PropertyModel(org.apache.wicket.model.PropertyModel) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink)

Example 74 with PrismPropertyDefinition

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());
}
Also used : PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) Test(org.testng.annotations.Test)

Example 75 with PrismPropertyDefinition

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;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PrismContainer(com.evolveum.midpoint.prism.PrismContainer) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Aggregations

PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)134 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)93 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)82 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)62 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)61 Test (org.testng.annotations.Test)60 PrismObject (com.evolveum.midpoint.prism.PrismObject)24 QName (javax.xml.namespace.QName)23 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)19 PrismPropertyDefinitionImpl (com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl)18 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)15 Task (com.evolveum.midpoint.task.api.Task)12 ArrayList (java.util.ArrayList)12 ExpressionEvaluationContext (com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext)11 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)9 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)8 PrismContext (com.evolveum.midpoint.prism.PrismContext)8 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)8 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)7 File (java.io.File)7