Search in sources :

Example 1 with CascadeType

use of org.kie.workbench.common.screens.datamodeller.model.jpadomain.CascadeType in project kie-wb-common by kiegroup.

the class RelationshipEditionDialog method show.

@Override
@SuppressWarnings("unchecked")
public void show() {
    DataModelerPropertyEditorFieldInfo fieldInfo = (DataModelerPropertyEditorFieldInfo) property;
    RelationType relationTypeValue = (RelationType) fieldInfo.getCurrentValue(RELATION_TYPE);
    if (relationTypeValue != null) {
        view.setRelationType(relationTypeValue.name());
    } else {
        view.setRelationType(UIUtil.NOT_SELECTED);
    }
    enableRelationDependentFields(relationTypeValue);
    cascadeAllWasClicked = false;
    setCascadeTypes((List<CascadeType>) fieldInfo.getCurrentValue(CASCADE));
    enableCascadeTypes(true, true);
    FetchMode fetchModeValue = (FetchMode) fieldInfo.getCurrentValue(FETCH);
    if (fetchModeValue != null) {
        view.setFetchMode(fetchModeValue.name());
    } else {
        view.setFetchMode(UIUtil.NOT_SELECTED);
    }
    Boolean optionalValue = (Boolean) fieldInfo.getCurrentValue(OPTIONAL);
    if (optionalValue != null) {
        view.setOptional(optionalValue);
    }
    String mappedBy = (String) fieldInfo.getCurrentValue(MAPPED_BY);
    view.setMappedBy(mappedBy);
    Boolean orphanRemovalValue = (Boolean) fieldInfo.getCurrentValue(ORPHAN_REMOVAL);
    if (orphanRemovalValue != null) {
        view.setOrphanRemoval(orphanRemovalValue);
    }
    view.setEnabled(!fieldInfo.isDisabled());
    view.show();
}
Also used : FetchMode(org.kie.workbench.common.screens.datamodeller.model.jpadomain.FetchMode) RelationType(org.kie.workbench.common.screens.datamodeller.model.jpadomain.RelationType) CascadeType(org.kie.workbench.common.screens.datamodeller.model.jpadomain.CascadeType) DataModelerPropertyEditorFieldInfo(org.kie.workbench.common.screens.datamodeller.client.model.DataModelerPropertyEditorFieldInfo)

Example 2 with CascadeType

use of org.kie.workbench.common.screens.datamodeller.model.jpadomain.CascadeType in project kie-wb-common by kiegroup.

the class JPADataObjectFieldEditorTest method valuesChangesTest.

@Test
public void valuesChangesTest() {
    JPADataObjectFieldEditor fieldEditor = createFieldEditor();
    DataObject dataObject = context.getDataObject();
    ObjectProperty field = dataObject.getProperty("field1");
    // emulates selection of field1 in current context.
    context.setObjectProperty(field);
    // The domain editors typically reacts upon DataModelerContext changes.
    // when the context changes the editor will typically be reloaded.
    fieldEditor.onContextChange(context);
    // emulates user interactions
    // changes related to the identifier category
    fieldEditor.onIdentifierFieldChange(createFieldInfo(JPADataObjectFieldEditorView.IDENTIFIER_FIELD, null), "true");
    fieldEditor.onGeneratedValueFieldChange(createFieldInfo(JPADataObjectFieldEditorView.GENERATED_VALUE_FIELD, new Pair<String, Object>("strategy", "SEQUENCE"), new Pair<String, Object>("generator", "TheGeneratorName")), "not_used");
    fieldEditor.onSequenceGeneratorFieldChange(createFieldInfo(JPADataObjectFieldEditorView.SEQUENCE_GENERATOR_FIELD, new Pair<String, Object>(SequenceGeneratorValueHandler.NAME, "TheGeneratorName"), new Pair<String, Object>(SequenceGeneratorValueHandler.SEQUENCE_NAME, "TheSequenceName"), new Pair<String, Object>(SequenceGeneratorValueHandler.INITIAL_VALUE, 1), new Pair<String, Object>(SequenceGeneratorValueHandler.ALLOCATION_SIZE, 100)), "not_used");
    // the field should have been updated according to the values entered on the ui
    assertNotNull(field.getAnnotation(Id.class.getName()));
    assertNotNull(field.getAnnotation(GeneratedValue.class.getName()));
    assertEquals("SEQUENCE", AnnotationValueHandler.getStringValue(field, GeneratedValue.class.getName(), "strategy"));
    assertEquals("TheGeneratorName", AnnotationValueHandler.getStringValue(field, GeneratedValue.class.getName(), "generator"));
    assertNotNull(field.getAnnotation(SequenceGenerator.class.getName()));
    assertEquals("TheGeneratorName", AnnotationValueHandler.getStringValue(field, SequenceGenerator.class.getName(), SequenceGeneratorValueHandler.NAME));
    assertEquals("TheSequenceName", AnnotationValueHandler.getStringValue(field, SequenceGenerator.class.getName(), SequenceGeneratorValueHandler.SEQUENCE_NAME));
    assertEquals(1, AnnotationValueHandler.getValue(field, SequenceGenerator.class.getName(), SequenceGeneratorValueHandler.INITIAL_VALUE));
    assertEquals(100, AnnotationValueHandler.getValue(field, SequenceGenerator.class.getName(), SequenceGeneratorValueHandler.ALLOCATION_SIZE));
    // changes related to the column category
    fieldEditor.onColumnFieldChange(createFieldInfo(JPADataObjectFieldEditorView.COLUMN_NAME_FIELD, new Pair<String, Object>("name", "NewColumnName")), "NewColumnName");
    fieldEditor.onColumnFieldChange(createFieldInfo(JPADataObjectFieldEditorView.COLUMN_UNIQUE_FIELD, new Pair<String, Object>("unique", true)), "true");
    fieldEditor.onColumnFieldChange(createFieldInfo(JPADataObjectFieldEditorView.COLUMN_NULLABLE_FIELD, new Pair<String, Object>("nullable", false)), "false");
    fieldEditor.onColumnFieldChange(createFieldInfo(JPADataObjectFieldEditorView.COLUMN_INSERTABLE_FIELD, new Pair<String, Object>("insertable", false)), "false");
    fieldEditor.onColumnFieldChange(createFieldInfo(JPADataObjectFieldEditorView.COLUMN_UPDATABLE_FIELD, new Pair<String, Object>("updatable", false)), "false");
    // the field should have been updated according to the values entered on the ui
    assertNotNull(field.getAnnotation(Column.class.getName()));
    assertEquals("NewColumnName", AnnotationValueHandler.getStringValue(field, Column.class.getName(), "name"));
    assertEquals("true", AnnotationValueHandler.getStringValue(field, Column.class.getName(), "unique"));
    assertEquals("false", AnnotationValueHandler.getStringValue(field, Column.class.getName(), "nullable"));
    assertEquals("false", AnnotationValueHandler.getStringValue(field, Column.class.getName(), "insertable"));
    assertEquals("false", AnnotationValueHandler.getStringValue(field, Column.class.getName(), "updatable"));
    // changes related to the relationship
    List<CascadeType> cascadeTypes = new ArrayList<CascadeType>();
    cascadeTypes.add(CascadeType.ALL);
    fieldEditor.onRelationTypeFieldChange(createFieldInfo(JPADataObjectFieldEditorView.RELATIONSHIP_TYPE_FIELD, new Pair<String, Object>(RelationshipAnnotationValueHandler.RELATION_TYPE, RelationType.ONE_TO_MANY), new Pair<String, Object>(RelationshipAnnotationValueHandler.CASCADE, cascadeTypes), new Pair<String, Object>(RelationshipAnnotationValueHandler.FETCH, FetchMode.EAGER)), "not_used");
    // the field should have been updated according to the values entered on the ui
    List<String> expectedCascadeTypes = new ArrayList<String>();
    expectedCascadeTypes.add(CascadeType.ALL.name());
    assertNotNull(field.getAnnotation(OneToMany.class.getName()));
    assertEquals(expectedCascadeTypes, AnnotationValueHandler.getValue(field, OneToMany.class.getName(), RelationshipAnnotationValueHandler.CASCADE));
    assertEquals(FetchMode.EAGER.name(), AnnotationValueHandler.getValue(field, OneToMany.class.getName(), RelationshipAnnotationValueHandler.FETCH));
}
Also used : ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) CascadeType(org.kie.workbench.common.screens.datamodeller.model.jpadomain.CascadeType) ArrayList(java.util.ArrayList) Pair(org.uberfire.commons.data.Pair) DomainEditorBaseTest(org.kie.workbench.common.screens.datamodeller.client.widgets.DomainEditorBaseTest) Test(org.junit.Test)

Example 3 with CascadeType

use of org.kie.workbench.common.screens.datamodeller.model.jpadomain.CascadeType in project kie-wb-common by kiegroup.

the class RelationshipAnnotationValueHandler method setCascade.

public void setCascade(List<CascadeType> cascade) {
    if (cascade != null) {
        List<Object> cascadeTypes = new ArrayList<Object>(cascade.size());
        for (CascadeType cascadeType : cascade) {
            cascadeTypes.add(cascadeType.name());
        }
        annotation.setValue(CASCADE, cascadeTypes);
    } else {
        annotation.removeValue(CASCADE);
    }
}
Also used : CascadeType(org.kie.workbench.common.screens.datamodeller.model.jpadomain.CascadeType) ArrayList(java.util.ArrayList)

Example 4 with CascadeType

use of org.kie.workbench.common.screens.datamodeller.model.jpadomain.CascadeType in project kie-wb-common by kiegroup.

the class RelationshipEditionDialogTest method testShow.

@Test
public void testShow() {
    RelationType relationTypeValue = RelationType.ONE_TO_MANY;
    List<CascadeType> cascadeTypeValue = Arrays.asList(CascadeType.DETACH, CascadeType.MERGE);
    FetchMode fetchModeValue = FetchMode.EAGER;
    Boolean optionalValue = Boolean.TRUE;
    String mappedByValue = "mappedByValue";
    Boolean orphanRemovalValue = Boolean.FALSE;
    when(fieldInfo.getCurrentValue(RelationshipAnnotationValueHandler.RELATION_TYPE)).thenReturn(relationTypeValue);
    when(fieldInfo.getCurrentValue(RelationshipAnnotationValueHandler.CASCADE)).thenReturn(cascadeTypeValue);
    when(fieldInfo.getCurrentValue(RelationshipAnnotationValueHandler.FETCH)).thenReturn(fetchModeValue);
    when(fieldInfo.getCurrentValue(RelationshipAnnotationValueHandler.OPTIONAL)).thenReturn(optionalValue);
    when(fieldInfo.getCurrentValue(RelationshipAnnotationValueHandler.MAPPED_BY)).thenReturn(mappedByValue);
    when(fieldInfo.getCurrentValue(RelationshipAnnotationValueHandler.ORPHAN_REMOVAL)).thenReturn(orphanRemovalValue);
    when(fieldInfo.isDisabled()).thenReturn(false);
    dialog.setProperty(fieldInfo);
    dialog.show();
    verify(view).setRelationType(relationTypeValue.name());
    verifyRelationDependentFields(relationTypeValue);
    verifyCascadeTypesWhereSet(cascadeTypeValue);
    verify(view).setFetchMode(fetchModeValue.name());
    verify(view).setOptional(optionalValue);
    verify(view).setMappedBy(mappedByValue);
    verify(view).setOrphanRemoval(orphanRemovalValue);
    verify(view).setEnabled(!fieldInfo.isDisabled());
    verify(view).show();
}
Also used : FetchMode(org.kie.workbench.common.screens.datamodeller.model.jpadomain.FetchMode) RelationType(org.kie.workbench.common.screens.datamodeller.model.jpadomain.RelationType) CascadeType(org.kie.workbench.common.screens.datamodeller.model.jpadomain.CascadeType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) Test(org.junit.Test)

Example 5 with CascadeType

use of org.kie.workbench.common.screens.datamodeller.model.jpadomain.CascadeType in project kie-wb-common by kiegroup.

the class JPADataObjectFieldEditor method onRelationTypeFieldChange.

@Override
public void onRelationTypeFieldChange(DataModelerPropertyEditorFieldInfo fieldInfo, String newValue) {
    if (getObjectField() != null) {
        Annotation oldRelation = getCurrentRelationshipAnnotation(getObjectField());
        RelationshipAnnotationValueHandler oldRelationHandler = oldRelation != null ? new RelationshipAnnotationValueHandler(oldRelation) : null;
        Annotation newRelation;
        RelationType newRelationType = (RelationType) fieldInfo.getCurrentValue(RelationshipAnnotationValueHandler.RELATION_TYPE);
        List<CascadeType> newCascadeTypes = (List<CascadeType>) fieldInfo.getCurrentValue(RelationshipAnnotationValueHandler.CASCADE);
        FetchMode newFetchMode = (FetchMode) fieldInfo.getCurrentValue(RelationshipAnnotationValueHandler.FETCH);
        Boolean newOptional = (Boolean) fieldInfo.getCurrentValue(RelationshipAnnotationValueHandler.OPTIONAL);
        String newMappedBy = DataModelerUtils.nullTrim((String) fieldInfo.getCurrentValue(RelationshipAnnotationValueHandler.MAPPED_BY));
        Boolean newOrphanRemoval = (Boolean) fieldInfo.getCurrentValue(RelationshipAnnotationValueHandler.ORPHAN_REMOVAL);
        // and add the new one. This may alter the annotations order for the given field, but it's not a problem.
        if (oldRelationHandler != null) {
            commandBuilder.buildFieldAnnotationRemoveCommand(getContext(), getName(), getDataObject(), getObjectField(), oldRelationHandler.getClassName()).execute();
        }
        newRelation = RelationshipAnnotationValueHandler.createAnnotation(newRelationType, newCascadeTypes, newFetchMode, newOptional, newMappedBy, newOrphanRemoval, getContext().getAnnotationDefinitions());
        if (newRelation != null) {
            getObjectField().addAnnotation(newRelation);
            commandBuilder.buildFieldAnnotationAddCommand(getContext(), getName(), getDataObject(), getObjectField(), newRelation).execute();
        }
    }
}
Also used : FetchMode(org.kie.workbench.common.screens.datamodeller.model.jpadomain.FetchMode) RelationType(org.kie.workbench.common.screens.datamodeller.model.jpadomain.RelationType) CascadeType(org.kie.workbench.common.screens.datamodeller.model.jpadomain.CascadeType) RelationshipAnnotationValueHandler(org.kie.workbench.common.screens.datamodeller.client.handlers.jpadomain.util.RelationshipAnnotationValueHandler) ArrayList(java.util.ArrayList) List(java.util.List) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation)

Aggregations

CascadeType (org.kie.workbench.common.screens.datamodeller.model.jpadomain.CascadeType)5 ArrayList (java.util.ArrayList)3 FetchMode (org.kie.workbench.common.screens.datamodeller.model.jpadomain.FetchMode)3 RelationType (org.kie.workbench.common.screens.datamodeller.model.jpadomain.RelationType)3 Test (org.junit.Test)2 List (java.util.List)1 RelationshipAnnotationValueHandler (org.kie.workbench.common.screens.datamodeller.client.handlers.jpadomain.util.RelationshipAnnotationValueHandler)1 DataModelerPropertyEditorFieldInfo (org.kie.workbench.common.screens.datamodeller.client.model.DataModelerPropertyEditorFieldInfo)1 DomainEditorBaseTest (org.kie.workbench.common.screens.datamodeller.client.widgets.DomainEditorBaseTest)1 Annotation (org.kie.workbench.common.services.datamodeller.core.Annotation)1 DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)1 ObjectProperty (org.kie.workbench.common.services.datamodeller.core.ObjectProperty)1 ArgumentMatchers.anyBoolean (org.mockito.ArgumentMatchers.anyBoolean)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 Pair (org.uberfire.commons.data.Pair)1