Search in sources :

Example 1 with ProvenanceAcquisitionType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ProvenanceAcquisitionType in project midpoint by Evolveum.

the class WebPrismUtil method createAcquition.

public static ProvenanceAcquisitionType createAcquition() {
    MidPointApplication app = MidPointApplication.get();
    ProvenanceAcquisitionType acquisitionType = new ProvenanceAcquisitionType(app.getPrismContext());
    GuiProfiledPrincipal principal = AuthUtil.getPrincipalUser();
    if (principal != null) {
        FocusType focus = principal.getFocus();
        if (focus != null) {
            acquisitionType.setActorRef(ObjectTypeUtil.createObjectRef(focus, app.getPrismContext()));
        }
    }
    acquisitionType.setChannel(GuiChannel.USER.getUri());
    acquisitionType.setTimestamp(app.getClock().currentTimeXMLGregorianCalendar());
    return acquisitionType;
}
Also used : MidPointApplication(com.evolveum.midpoint.web.security.MidPointApplication) ProvenanceAcquisitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ProvenanceAcquisitionType) GuiProfiledPrincipal(com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipal) FocusType(com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType)

Example 2 with ProvenanceAcquisitionType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ProvenanceAcquisitionType in project midpoint by Evolveum.

the class ProvenanceMetadataPanel method createAcquisitionPanel.

private WebMarkupContainer createAcquisitionPanel(IModel<PrismContainerWrapper<ProvenanceAcquisitionType>> listPropertyModel) {
    WebMarkupContainer container = new WebMarkupContainer(ID_ACQUISITION_HEADER);
    ListView<PrismContainerValueWrapper<ProvenanceAcquisitionType>> acquisition = new ListView<PrismContainerValueWrapper<ProvenanceAcquisitionType>>(ID_ACQUISITIONS, new PropertyModel<>(listPropertyModel, "values")) {

        @Override
        protected void populateItem(ListItem<PrismContainerValueWrapper<ProvenanceAcquisitionType>> listItem) {
            ProvenanceAcquisitionHeaderPanel panel = new ProvenanceAcquisitionHeaderPanel(ID_ACQUISITION, new ItemRealValueModel<>(listItem.getModel()));
            panel.setOutputMarkupId(true);
            listItem.add(panel);
        }
    };
    container.add(acquisition);
    return container;
}
Also used : ListView(org.apache.wicket.markup.html.list.ListView) ProvenanceAcquisitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ProvenanceAcquisitionType) ListItem(org.apache.wicket.markup.html.list.ListItem) PrismContainerValueWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerValueWrapper) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer)

Example 3 with ProvenanceAcquisitionType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ProvenanceAcquisitionType in project midpoint by Evolveum.

the class ProvenanceAcquisitionHeaderPanel method initLayout.

private void initLayout() {
    LinkedReferencePanel<ObjectReferenceType> source = new LinkedReferencePanel<>(ID_SOURCE, new ReadOnlyModel<>(() -> {
        ProvenanceAcquisitionType acquisitionType = getModelObject();
        if (acquisitionType == null) {
            return null;
        }
        ObjectReferenceType ref = acquisitionType.getResourceRef();
        if (ref != null && ref.getOid() != null) {
            return ref;
        }
        ObjectReferenceType originRef = acquisitionType.getOriginRef();
        if (originRef != null && originRef.getOid() != null) {
            return originRef;
        }
        return null;
    }));
    add(source);
    source.add(new VisibleBehaviour(() -> isNotEmpty(getModelObject().getResourceRef()) || isNotEmpty(getModelObject().getOriginRef())));
    ReadOnlyModel<GuiChannel> channelModel = new ReadOnlyModel<>(() -> GuiChannel.findChannel(getModelObject().getChannel()));
    WebMarkupContainer channelIcon = new WebMarkupContainer(ID_CHANNEL_ICON);
    add(channelIcon);
    channelIcon.add(AttributeAppender.replace("class", new PropertyModel<>(channelModel, "iconCssClass")));
    Label channel = new Label(ID_CHANNEL, getPageBase().createStringResource(channelModel.getObject()));
    add(channel);
    channel.add(new VisibleBehaviour(() -> getModelObject() != null && (getModelObject().getOriginRef() == null || getModelObject().getOriginRef().getOid() == null) && (getModelObject().getResourceRef() == null || getModelObject().getResourceRef().getOid() == null)));
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ProvenanceAcquisitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ProvenanceAcquisitionType) VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour) ReadOnlyModel(com.evolveum.midpoint.gui.api.model.ReadOnlyModel) LinkedReferencePanel(com.evolveum.midpoint.web.component.data.LinkedReferencePanel) PropertyModel(org.apache.wicket.model.PropertyModel) Label(org.apache.wicket.markup.html.basic.Label) GuiChannel(com.evolveum.midpoint.gui.impl.GuiChannel) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer)

Example 4 with ProvenanceAcquisitionType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ProvenanceAcquisitionType in project midpoint by Evolveum.

the class TestMappingMetadata method testAddJackRestWithTimestamp.

/**
 * Jack has acquisition origins: user, rest
 * Sparrow has acquisition origins: user
 *
 *    (see user-jack-metadata.xml)
 *
 * Delta: add givenName Jack (rest+timestamp).
 *
 * Expected result: user, rest+timestamp (in zero set, because no real value is being added).
 */
@Test
public void testAddJackRestWithTimestamp() throws Exception {
    XMLGregorianCalendar now = XmlTypeConverter.createXMLGregorianCalendar();
    PrismPropertyValue<PolyString> jackRestWithTs = evaluator.getPrismContext().itemFactory().createPropertyValue(new PolyString("Jack"));
    // noinspection unchecked
    ((PrismContainer<ValueMetadataType>) (PrismContainer) jackRestWithTs.getValueMetadata()).createNewValue().asContainerable().beginProvenance().beginAcquisition().originRef("rest", ServiceType.COMPLEX_TYPE).timestamp(now);
    ObjectDelta<UserType> delta = evaluator.getPrismContext().deltaFor(UserType.class).item(UserType.F_GIVEN_NAME).add(jackRestWithTs).asObjectDelta(null);
    MappingImpl<PrismPropertyValue<PolyString>, PrismPropertyDefinition<PolyString>> mapping = evaluate(MAPPING_SCRIPT_FULLNAME_METADATA_XML, delta);
    PrismValueDeltaSetTriple<PrismPropertyValue<PolyString>> outputTriple = mapping.getOutputTriple();
    displayDumpable("triple", outputTriple);
    PrismAsserts.assertTripleZero(outputTriple, PrismTestUtil.createPolyString("Jack Sparrow"));
    PrismAsserts.assertTripleNoPlus(outputTriple);
    PrismAsserts.assertTripleNoMinus(outputTriple);
    PrismPropertyValue<PolyString> jackSparrow = MiscUtil.extractSingleton(outputTriple.getZeroSet());
    assertOrigins(jackSparrow, "user", "rest");
    List<ProvenanceAcquisitionType> acquisitions = ((ValueMetadataType) jackSparrow.getValueMetadata().getValue().asContainerable()).getProvenance().getAcquisition();
    XMLGregorianCalendar timestamp = acquisitions.stream().filter(acq -> acq.getOriginRef().getOid().equals("rest")).findAny().orElseThrow(() -> new AssertionError("no origin rest value")).getTimestamp();
    assertThat(timestamp).isEqualTo(now);
}
Also used : java.util(java.util) DeltaFactory(com.evolveum.midpoint.prism.delta.DeltaFactory) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Test(org.testng.annotations.Test) ModelExpressionThreadLocalHolder(com.evolveum.midpoint.model.common.expression.ModelExpressionThreadLocalHolder) ExpressionEnvironment(com.evolveum.midpoint.model.common.expression.ExpressionEnvironment) com.evolveum.midpoint.model.api.context(com.evolveum.midpoint.model.api.context) DeltaSetTriple(com.evolveum.midpoint.prism.delta.DeltaSetTriple) PrismTestUtil(com.evolveum.midpoint.prism.util.PrismTestUtil) PrismValueDeltaSetTriple(com.evolveum.midpoint.prism.delta.PrismValueDeltaSetTriple) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) XmlTypeConverter(com.evolveum.midpoint.prism.xml.XmlTypeConverter) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) TEST_DIR(com.evolveum.midpoint.model.common.mapping.MappingTestEvaluator.TEST_DIR) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) PrismTestUtil.getPrismContext(com.evolveum.midpoint.prism.util.PrismTestUtil.getPrismContext) AbstractModelCommonTest(com.evolveum.midpoint.model.common.AbstractModelCommonTest) PrismAsserts(com.evolveum.midpoint.prism.util.PrismAsserts) BeforeClass(org.testng.annotations.BeforeClass) IOException(java.io.IOException) MiscUtil(com.evolveum.midpoint.util.MiscUtil) Task(com.evolveum.midpoint.task.api.Task) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) AssertJUnit.fail(org.testng.AssertJUnit.fail) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) ExpressionTestUtil(com.evolveum.midpoint.model.common.expression.ExpressionTestUtil) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) Nullable(org.jetbrains.annotations.Nullable) ObjectTreeDeltas(com.evolveum.midpoint.schema.ObjectTreeDeltas) TestResource(com.evolveum.midpoint.test.TestResource) Stream(java.util.stream.Stream) ExpressionProfile(com.evolveum.midpoint.schema.expression.ExpressionProfile) SAXException(org.xml.sax.SAXException) ProgressInformation(com.evolveum.midpoint.model.api.ProgressInformation) NotNull(org.jetbrains.annotations.NotNull) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Test(org.testng.annotations.Test) AbstractModelCommonTest(com.evolveum.midpoint.model.common.AbstractModelCommonTest)

Example 5 with ProvenanceAcquisitionType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ProvenanceAcquisitionType in project midpoint by Evolveum.

the class TestMappingMetadata method testAddJackRestWithTimestampWithExisting.

/**
 * Jack has acquisition origins: user, rest
 * Sparrow has acquisition origins: user
 * target (Jack Sparrow) has origins: user, rest (in the form of m:user+rest).
 *
 *    (see user-jack-metadata.xml)
 *
 * Delta: add givenName Jack (rest+timestamp).
 *
 * Expected result: user, rest+timestamp (in zero set, because no real value is being added).
 */
@Test
public void testAddJackRestWithTimestampWithExisting() throws Exception {
    XMLGregorianCalendar now = XmlTypeConverter.createXMLGregorianCalendar();
    PrismPropertyValue<PolyString> jackRestWithTs = evaluator.getPrismContext().itemFactory().createPropertyValue(new PolyString("Jack"));
    // noinspection unchecked
    ((PrismContainer<ValueMetadataType>) (PrismContainer) jackRestWithTs.getValueMetadata()).createNewValue().asContainerable().beginProvenance().beginAcquisition().originRef("rest", ServiceType.COMPLEX_TYPE).timestamp(now);
    ObjectDelta<UserType> delta = evaluator.getPrismContext().deltaFor(UserType.class).item(UserType.F_GIVEN_NAME).add(jackRestWithTs).asObjectDelta(null);
    MappingImpl<PrismPropertyValue<PolyString>, PrismPropertyDefinition<PolyString>> mapping = evaluate(MAPPING_SCRIPT_FULLNAME_METADATA_XML, delta, existingValuesCustomizer(createJackSparrowOriginal()));
    PrismValueDeltaSetTriple<PrismPropertyValue<PolyString>> outputTriple = mapping.getOutputTriple();
    displayDumpable("triple", outputTriple);
    PrismAsserts.assertTripleZero(outputTriple, PrismTestUtil.createPolyString("Jack Sparrow"));
    PrismAsserts.assertTripleNoPlus(outputTriple);
    PrismAsserts.assertTripleNoMinus(outputTriple);
    PrismPropertyValue<PolyString> jackSparrow = MiscUtil.extractSingleton(outputTriple.getZeroSet());
    assertOrigins(jackSparrow, "user", "rest");
    List<ProvenanceAcquisitionType> acquisitions = ((ValueMetadataType) jackSparrow.getValueMetadata().getValue().asContainerable()).getProvenance().getAcquisition();
    XMLGregorianCalendar timestamp = acquisitions.stream().filter(acq -> acq.getOriginRef().getOid().equals("rest")).findAny().orElseThrow(() -> new AssertionError("no origin rest value")).getTimestamp();
    assertThat(timestamp).isEqualTo(now);
}
Also used : java.util(java.util) DeltaFactory(com.evolveum.midpoint.prism.delta.DeltaFactory) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Test(org.testng.annotations.Test) ModelExpressionThreadLocalHolder(com.evolveum.midpoint.model.common.expression.ModelExpressionThreadLocalHolder) ExpressionEnvironment(com.evolveum.midpoint.model.common.expression.ExpressionEnvironment) com.evolveum.midpoint.model.api.context(com.evolveum.midpoint.model.api.context) DeltaSetTriple(com.evolveum.midpoint.prism.delta.DeltaSetTriple) PrismTestUtil(com.evolveum.midpoint.prism.util.PrismTestUtil) PrismValueDeltaSetTriple(com.evolveum.midpoint.prism.delta.PrismValueDeltaSetTriple) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) XmlTypeConverter(com.evolveum.midpoint.prism.xml.XmlTypeConverter) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) TEST_DIR(com.evolveum.midpoint.model.common.mapping.MappingTestEvaluator.TEST_DIR) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) PrismTestUtil.getPrismContext(com.evolveum.midpoint.prism.util.PrismTestUtil.getPrismContext) AbstractModelCommonTest(com.evolveum.midpoint.model.common.AbstractModelCommonTest) PrismAsserts(com.evolveum.midpoint.prism.util.PrismAsserts) BeforeClass(org.testng.annotations.BeforeClass) IOException(java.io.IOException) MiscUtil(com.evolveum.midpoint.util.MiscUtil) Task(com.evolveum.midpoint.task.api.Task) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) AssertJUnit.fail(org.testng.AssertJUnit.fail) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) ExpressionTestUtil(com.evolveum.midpoint.model.common.expression.ExpressionTestUtil) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) Nullable(org.jetbrains.annotations.Nullable) ObjectTreeDeltas(com.evolveum.midpoint.schema.ObjectTreeDeltas) TestResource(com.evolveum.midpoint.test.TestResource) Stream(java.util.stream.Stream) ExpressionProfile(com.evolveum.midpoint.schema.expression.ExpressionProfile) SAXException(org.xml.sax.SAXException) ProgressInformation(com.evolveum.midpoint.model.api.ProgressInformation) NotNull(org.jetbrains.annotations.NotNull) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Test(org.testng.annotations.Test) AbstractModelCommonTest(com.evolveum.midpoint.model.common.AbstractModelCommonTest)

Aggregations

ProvenanceAcquisitionType (com.evolveum.midpoint.xml.ns._public.common.common_3.ProvenanceAcquisitionType)3 ModelExecuteOptions (com.evolveum.midpoint.model.api.ModelExecuteOptions)2 ProgressInformation (com.evolveum.midpoint.model.api.ProgressInformation)2 com.evolveum.midpoint.model.api.context (com.evolveum.midpoint.model.api.context)2 AbstractModelCommonTest (com.evolveum.midpoint.model.common.AbstractModelCommonTest)2 ExpressionEnvironment (com.evolveum.midpoint.model.common.expression.ExpressionEnvironment)2 ExpressionTestUtil (com.evolveum.midpoint.model.common.expression.ExpressionTestUtil)2 ModelExpressionThreadLocalHolder (com.evolveum.midpoint.model.common.expression.ModelExpressionThreadLocalHolder)2 TEST_DIR (com.evolveum.midpoint.model.common.mapping.MappingTestEvaluator.TEST_DIR)2 com.evolveum.midpoint.prism (com.evolveum.midpoint.prism)2 DeltaFactory (com.evolveum.midpoint.prism.delta.DeltaFactory)2 DeltaSetTriple (com.evolveum.midpoint.prism.delta.DeltaSetTriple)2 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)2 PrismValueDeltaSetTriple (com.evolveum.midpoint.prism.delta.PrismValueDeltaSetTriple)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 PrismAsserts (com.evolveum.midpoint.prism.util.PrismAsserts)2 PrismTestUtil (com.evolveum.midpoint.prism.util.PrismTestUtil)2 PrismTestUtil.getPrismContext (com.evolveum.midpoint.prism.util.PrismTestUtil.getPrismContext)2 XmlTypeConverter (com.evolveum.midpoint.prism.xml.XmlTypeConverter)2 ObjectTreeDeltas (com.evolveum.midpoint.schema.ObjectTreeDeltas)2