Search in sources :

Example 21 with AnnotationValuePairDefinition

use of org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition in project kie-wb-common by kiegroup.

the class JavaRoasterModelDriver method addAnnotationMemberValue.

private void addAnnotationMemberValue(AnnotationSource annotationSource, AnnotationValuePairDefinition valuePairDefinition, Annotation annotation) {
    AnnotationSource targetAnnotation = annotationSource.addAnnotationValue(valuePairDefinition.getName());
    targetAnnotation.setName(annotation.getClassName());
    if (!annotation.getAnnotationDefinition().isMarker()) {
        for (AnnotationValuePairDefinition memberDefinition : annotation.getAnnotationDefinition().getValuePairs()) {
            Object value = annotation.getValue(memberDefinition.getName());
            if (value != null) {
                addMemberValue(targetAnnotation, memberDefinition, value);
            }
        }
    }
}
Also used : AnnotationSource(org.jboss.forge.roaster.model.source.AnnotationSource) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) AnnotationValuePairDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition)

Example 22 with AnnotationValuePairDefinition

use of org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition in project kie-wb-common by kiegroup.

the class JavaRoasterModelDriver method addAnnotation.

public AnnotationSource<?> addAnnotation(AnnotationTargetSource annotationTargetSource, Annotation annotation) {
    AnnotationSource<?> newAnnotationSource = annotationTargetSource.addAnnotation();
    newAnnotationSource.setName(annotation.getClassName());
    AnnotationDefinition annotationDefinition = annotation.getAnnotationDefinition();
    if (!annotationDefinition.isMarker()) {
        for (AnnotationValuePairDefinition memberDefinition : annotationDefinition.getValuePairs()) {
            Object value = annotation.getValue(memberDefinition.getName());
            if (value != null) {
                addMemberValue(newAnnotationSource, memberDefinition, value);
            }
        }
    }
    return newAnnotationSource;
}
Also used : AnnotationDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) AnnotationValuePairDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition)

Example 23 with AnnotationValuePairDefinition

use of org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition in project kie-wb-common by kiegroup.

the class ValuePairEditorPageTest method testPageInitialization.

@Test
public void testPageInitialization() {
    modelerServiceCaller = new CallerMock<DataModelerService>(modelerService);
    ValuePairEditorPage editorPage = new ValuePairEditorPage(view, valuePairEditorProvider, modelerServiceCaller, wizardPageStatusChangeEvent);
    editorPage.prepareView();
    AnnotationDefinition annotationDefinition = DriverUtils.buildAnnotationDefinition(Entity.class);
    AnnotationValuePairDefinition valuePairDefinition = annotationDefinition.getValuePair("name");
    when(valuePairEditorProvider.getValuePairEditor(valuePairDefinition)).thenReturn(valuePairEditor);
    editorPage.init(annotationDefinition, valuePairDefinition, ElementType.FIELD, kieModule);
    // the view should be properly initialized with the corresponding editor.
    verify(view, times(1)).setValuePairEditor(valuePairEditor);
    // the "name" value pair is not mandatory, so the page is completed.
    WizardTestUtil.assertPageComplete(true, editorPage);
}
Also used : AnnotationDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition) DataModelerService(org.kie.workbench.common.screens.datamodeller.service.DataModelerService) AnnotationValuePairDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition) Test(org.junit.Test)

Example 24 with AnnotationValuePairDefinition

use of org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition in project kie-wb-common by kiegroup.

the class MultipleBooleanValuePairEditorTest method testEditorLoad.

@Test
public void testEditorLoad() {
    booleanEditors.clear();
    List<Boolean> originalValues = new ArrayList<Boolean>();
    originalValues.add(Boolean.FALSE);
    originalValues.add(Boolean.FALSE);
    originalValues.add(Boolean.TRUE);
    originalValues.add(Boolean.TRUE);
    MultipleBooleanValuePairEditor multiBooleanEditor = new MultipleBooleanValuePairEditorExtended(multipleEditorView);
    AnnotationValuePairDefinition valuePairDefinition = annotationDefinition.getValuePair("booleanArrayParam1");
    multiBooleanEditor.init(valuePairDefinition);
    verify(multipleEditorView, times(1)).setValuePairLabel(valuePairDefinition.getName());
    verify(multipleEditorView, times(1)).showValuePairRequiredIndicator(false);
    when(multipleEditorView.getItemEditors()).thenReturn(booleanEditors);
    multiBooleanEditor.setValue(originalValues);
    // four individual editors should have been created.
    assertEquals(4, booleanEditors.size());
    // and populated with the corresponding value
    verify(singleEditorView, times(2)).setSelectedValue("true");
    verify(singleEditorView, times(2)).setSelectedValue("false");
    assertTrue(multiBooleanEditor.isValid());
    assertEquals(originalValues, multiBooleanEditor.getValue());
}
Also used : ArrayList(java.util.ArrayList) AnnotationValuePairDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition) Test(org.junit.Test)

Example 25 with AnnotationValuePairDefinition

use of org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition in project kie-wb-common by kiegroup.

the class MultipleEnumValuePairEditorTest method testEditorLoad.

@Test
public void testEditorLoad() {
    MultipleEnumValuePairEditor enumEditor = new MultipleEnumValuePairEditorExtended(view);
    AnnotationValuePairDefinition valuePairDefinition = annotationDefinition.getValuePair("enumArrayParam1");
    enumEditor.init(valuePairDefinition);
    verify(view, times(1)).setValuePairLabel(valuePairDefinition.getName());
    verify(view, times(1)).showValuePairRequiredIndicator(false);
    verify(view, times(1)).addOptionEditor(optionEditors.get(TestEnums.ENUM1.VALUE1.name()));
    verify(view, times(1)).addOptionEditor(optionEditors.get(TestEnums.ENUM1.VALUE2.name()));
    verify(view, times(1)).addOptionEditor(optionEditors.get(TestEnums.ENUM1.VALUE3.name()));
    verify(view, times(1)).addOptionEditor(optionEditors.get("{}"));
}
Also used : AnnotationValuePairDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition) Test(org.junit.Test)

Aggregations

AnnotationValuePairDefinition (org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition)33 Test (org.junit.Test)22 ArrayList (java.util.ArrayList)8 AnnotationDefinition (org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition)8 DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)4 AnnotationImpl (org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl)4 AnnotationSource (org.jboss.forge.roaster.model.source.AnnotationSource)3 DataModelerService (org.kie.workbench.common.screens.datamodeller.service.DataModelerService)3 Annotation (org.kie.workbench.common.services.datamodeller.core.Annotation)3 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entity (javax.persistence.Entity)1 ValuePair (org.jboss.forge.roaster.model.ValuePair)1 AdvancedAnnotationListEditorView (org.kie.workbench.common.screens.datamodeller.client.widgets.advanceddomain.annotationlisteditor.AdvancedAnnotationListEditorView)1 GenerationTools (org.kie.workbench.common.services.datamodeller.codegen.GenerationTools)1 AnnotationDefinitionRequest (org.kie.workbench.common.services.datamodeller.driver.model.AnnotationDefinitionRequest)1 AnnotationDefinitionResponse (org.kie.workbench.common.services.datamodeller.driver.model.AnnotationDefinitionResponse)1 AnnotationDescr (org.kie.workbench.common.services.datamodeller.parser.descr.AnnotationDescr)1 ElementValueDescr (org.kie.workbench.common.services.datamodeller.parser.descr.ElementValueDescr)1 ElementValuePairDescr (org.kie.workbench.common.services.datamodeller.parser.descr.ElementValuePairDescr)1