Search in sources :

Example 1 with DataDefinitionImpl

use of com.qcadoo.model.internal.DataDefinitionImpl in project qcadoo by qcadoo.

the class ModelXmlToDefinitionConverterImpl method getModelDefinition.

private DataDefinitionImpl getModelDefinition(final XMLStreamReader reader, final String pluginIdentifier) {
    String modelName = getStringAttribute(reader, "name");
    LOG.info("Reading model " + modelName + " for plugin " + pluginIdentifier);
    DataDefinitionImpl dataDefinition = new DataDefinitionImpl(pluginIdentifier, modelName, dataAccessService);
    dataDefinition.setDeletable(getBooleanAttribute(reader, "deletable", true));
    dataDefinition.setInsertable(getBooleanAttribute(reader, "insertable", true));
    dataDefinition.setUpdatable(getBooleanAttribute(reader, "updatable", true));
    dataDefinition.setActivable(getBooleanAttribute(reader, "activable", false));
    dataDefinition.setAuditable(getBooleanAttribute(reader, "auditable", false));
    if (dataDefinition.isAuditable()) {
        addAuditFields(dataDefinition);
    }
    dataDefinition.setVersionable(getBooleanAttribute(reader, VersionableConstants.VERSIONABLE_ATTRIBUTE_NAME, false));
    if (dataDefinition.isVersionable()) {
        addVersionFields(dataDefinition);
    }
    dataDefinition.setFullyQualifiedClassName(ClassNameUtils.getFullyQualifiedClassName(pluginIdentifier, modelName));
    return dataDefinition;
}
Also used : DataDefinitionImpl(com.qcadoo.model.internal.DataDefinitionImpl)

Example 2 with DataDefinitionImpl

use of com.qcadoo.model.internal.DataDefinitionImpl in project qcadoo by qcadoo.

the class ModelXmlToDefinitionConverterImpl method getDataDefinition.

private DataDefinition getDataDefinition(final XMLStreamReader reader, final String pluginIdentifier) throws XMLStreamException, HookInitializationException, ModelXmlParsingException {
    DataDefinitionImpl dataDefinition = getModelDefinition(reader, pluginIdentifier);
    LOG.info("Creating dataDefinition " + dataDefinition);
    parseElementChildren(reader, TAG_MODEL, childTag -> {
        if (TAG_FIELDS.equals(getTagStarted(reader))) {
            parseFields(reader, dataDefinition);
        }
        if (TAG_HOOKS.equals(getTagStarted(reader))) {
            parseHooks(reader, dataDefinition);
        }
        String tag = getTagStarted(reader);
        if (tag != null) {
            addOtherElement(reader, dataDefinition, tag);
        }
    });
    dataDefinitionService.save(dataDefinition);
    return dataDefinition;
}
Also used : DataDefinitionImpl(com.qcadoo.model.internal.DataDefinitionImpl)

Example 3 with DataDefinitionImpl

use of com.qcadoo.model.internal.DataDefinitionImpl in project qcadoo by qcadoo.

the class ModelXmlToDefinitionConverterTest method shouldSetHooks.

@Test
public void shouldSetHooks() {
    DataDefinitionImpl dataDefImpl = (DataDefinitionImpl) dataDefinition;
    testListHookDefinition(dataDefImpl.getCreateHooks(), CustomHook.class, "createHook");
    testListHookDefinition(dataDefImpl.getUpdateHooks(), CustomHook.class, "updateHook");
    testListHookDefinition(dataDefImpl.getSaveHooks(), CustomHook.class, "hook");
    testListHookDefinition(dataDefImpl.getCopyHooks(), CustomHook.class, "copyHook");
    testListHookDefinition(dataDefImpl.getDeleteHooks(), CustomHook.class, "deleteHook");
}
Also used : DataDefinitionImpl(com.qcadoo.model.internal.DataDefinitionImpl) TransactionMockAwareTest(com.qcadoo.model.TransactionMockAwareTest) Test(org.junit.Test)

Example 4 with DataDefinitionImpl

use of com.qcadoo.model.internal.DataDefinitionImpl in project qcadoo by qcadoo.

the class ModelXmlToDefinitionConverterTest method shouldSetEntityValidators.

@Test
public void shouldSetEntityValidators() {
    assertEquals(1, ((DataDefinitionImpl) dataDefinition).getValidators().size());
    EntityHookDefinition validator = ((DataDefinitionImpl) dataDefinition).getValidators().get(0);
    assertThat(validator, instanceOf(CustomEntityValidator.class));
    testHookDefinition(validator, "entityHook", CustomHook.class, "validate");
}
Also used : DataDefinitionImpl(com.qcadoo.model.internal.DataDefinitionImpl) CustomEntityValidator(com.qcadoo.model.internal.validators.CustomEntityValidator) EntityHookDefinition(com.qcadoo.model.internal.api.EntityHookDefinition) TransactionMockAwareTest(com.qcadoo.model.TransactionMockAwareTest) Test(org.junit.Test)

Aggregations

DataDefinitionImpl (com.qcadoo.model.internal.DataDefinitionImpl)4 TransactionMockAwareTest (com.qcadoo.model.TransactionMockAwareTest)2 Test (org.junit.Test)2 EntityHookDefinition (com.qcadoo.model.internal.api.EntityHookDefinition)1 CustomEntityValidator (com.qcadoo.model.internal.validators.CustomEntityValidator)1