Search in sources :

Example 11 with JavaRoasterModelDriver

use of org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver in project kie-wb-common by kiegroup.

the class FormGenerationIntegrationTest method testNestedFormsGeneration.

@Test
public void testNestedFormsGeneration() {
    when(module.getRootPath()).thenReturn(rootPathWithoutNestedForms);
    ModelDriver modelDriver = new JavaRoasterModelDriver(ioService, Paths.convert(rootPathWithoutNestedForms), moduleClassLoader, filterHolder);
    try {
        ModelDriverResult result = modelDriver.loadModel();
        dataModel = result.getDataModel();
    } catch (ModelDriverException e) {
        throw new ServiceException("It was not possible to load model for URI: " + rootPathWithoutNestedForms.toURI(), e);
    }
    when(dataModelerService.loadModel(module)).thenReturn(dataModel);
    when(commentedOptionFactory.makeCommentedOption(any())).thenReturn(commentedOption);
    final FormGenerationResult formGenerationResult = generateForm("FormGenerationTest_TwinTasks-taskform.frm", taskFormModels.get(4));
    final List<String> expectedDataObjectFormFields = Arrays.asList("nestedObjectForSubform", SUBFORM_FIELDTYPE, "nestedObjectListForMultipleSubform", MULTIPLESUBFORM_FIELDTYPE, "bigDecimalDecimalBox", DECIMALBOX_FIELDTYPE, "bigIntegerIntegerBox", INTEGERBOX_FIELDTYPE, "booleanCheckBox", CHECKBOX_FIELDTYPE, "byteIntegerBox", INTEGERBOX_FIELDTYPE, "charTextBox", TEXTBOX_FIELDTYPE, "dateDatePicker", DATEPICKER_FIELDTYPE, "doubleDecimalBox", DECIMALBOX_FIELDTYPE, "floatDecimalBox", DECIMALBOX_FIELDTYPE, "longIntegerBox", INTEGERBOX_FIELDTYPE, "stringListBox", TEXTBOX_FIELDTYPE, "intIntegerBox", INTEGERBOX_FIELDTYPE, "shortIntegerBox", INTEGERBOX_FIELDTYPE, "bigDecimalRadioGroup", DECIMALBOX_FIELDTYPE, "bigIntegerRadioGroup", INTEGERBOX_FIELDTYPE, "byteRadioGroup", INTEGERBOX_FIELDTYPE, "charRadioGroup", TEXTBOX_FIELDTYPE, "doubleSlider", DECIMALBOX_FIELDTYPE, "doubleRadioGroup", DECIMALBOX_FIELDTYPE, "floatRadioGroup", DECIMALBOX_FIELDTYPE, "intRadioGroup", INTEGERBOX_FIELDTYPE, "intSlider", INTEGERBOX_FIELDTYPE, "longRadioGroup", INTEGERBOX_FIELDTYPE, "stringPicture", TEXTBOX_FIELDTYPE, "stringRadioGroup", TEXTBOX_FIELDTYPE, "stringTextArea", TEXTBOX_FIELDTYPE, "stringTextBox", TEXTBOX_FIELDTYPE, "shortRadioGroup", INTEGERBOX_FIELDTYPE);
    final List<String> expectedNestedDataObjectFormFields = Arrays.asList("stringListBox", TEXBOX_FIELDTYPE, "doubleDecimalBox", DECIMALBOX_FIELDTYPE, "booleanCheckBox", CHECKBOX_FIELDTYPE, "dateDatePicker", DATEPICKER_FIELDTYPE, "charRadioGroup", TEXTBOX_FIELDTYPE, "doubleSlider", DECIMALBOX_FIELDTYPE, "intIntegerBox", INTEGERBOX_FIELDTYPE, "stringPicture", TEXBOX_FIELDTYPE, "stringTextArea", TEXTBOX_FIELDTYPE, "stringTextBox", TEXTBOX_FIELDTYPE);
    final FormDefinition rootForm = formGenerationResult.getRootForm();
    final List<FormDefinition> nestedForms = formGenerationResult.getNestedForms();
    final FormDefinition dataObjectForm = nestedForms.get(0);
    final FormDefinition nestedDataObjectForm = nestedForms.get(1);
    final String dataObjectFormID = dataObjectForm.getId();
    testNestedFormsHaveCorrectId(rootForm, "_dataObject1", dataObjectFormID);
    testNestedFormsHaveCorrectId(rootForm, "_dataObject2", dataObjectFormID);
    testNestedFormsHaveCorrectId(rootForm, "dataObject_", dataObjectFormID);
    final String nestedDataObjectFormID = nestedDataObjectForm.getId();
    testFormDefinition(dataObjectForm, expectedDataObjectFormFields);
    testNestedFormsHaveCorrectId(dataObjectForm, "nestedObjectForSubform", nestedDataObjectFormID);
    testFormDefinition(nestedDataObjectForm, expectedNestedDataObjectFormFields);
}
Also used : ServiceException(org.kie.workbench.common.screens.datamodeller.service.ServiceException) FormGenerationResult(org.kie.workbench.common.forms.jbpm.server.service.formGeneration.FormGenerationResult) JavaRoasterModelDriver(org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver) ModelDriver(org.kie.workbench.common.services.datamodeller.driver.ModelDriver) ModelDriverResult(org.kie.workbench.common.services.datamodeller.driver.model.ModelDriverResult) ModelDriverException(org.kie.workbench.common.services.datamodeller.driver.ModelDriverException) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) JavaRoasterModelDriver(org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver) Test(org.junit.Test)

Example 12 with JavaRoasterModelDriver

use of org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver in project kie-wb-common by kiegroup.

the class DataModelerServiceImpl method updateJavaClassSource.

private void updateJavaClassSource(DataObject dataObject, JavaClassSource javaClassSource, Map<String, String> renames, List<String> deletions, ClassTypeResolver classTypeResolver) throws Exception {
    if (javaClassSource == null || !javaClassSource.isClass()) {
        logger.warn("A null javaClassSource or javaClassSouce is not a Class, no processing will be done. javaClassSource: " + javaClassSource + " className: " + (javaClassSource != null ? javaClassSource.getName() : null));
        return;
    }
    JavaRoasterModelDriver modelDriver = new JavaRoasterModelDriver(filterHolder);
    UpdateInfo updateInfo = new UpdateInfo();
    if (renames != null) {
        for (Map.Entry<String, String> entry : renames.entrySet()) {
            updateInfo.addClassRename(entry.getKey(), entry.getValue());
        }
    }
    if (deletions != null) {
        for (String deletion : deletions) {
            updateInfo.addDeletedClass(deletion);
        }
    }
    modelDriver.updateSource(javaClassSource, dataObject, updateInfo, classTypeResolver);
}
Also used : Map(java.util.Map) HashMap(java.util.HashMap) JavaRoasterModelDriver(org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver) UpdateInfo(org.kie.workbench.common.services.datamodeller.driver.impl.UpdateInfo)

Example 13 with JavaRoasterModelDriver

use of org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver in project kie-wb-common by kiegroup.

the class DataModelerServiceImpl method resolveParseRequest.

@Override
public AnnotationParseResponse resolveParseRequest(AnnotationParseRequest parseRequest, KieModule kieModule) {
    JavaRoasterModelDriver modelDriver = new JavaRoasterModelDriver();
    Pair<Annotation, List<DriverError>> driverResult = modelDriver.parseAnnotationWithValuePair(parseRequest.getAnnotationClassName(), parseRequest.getTarget(), parseRequest.getValuePairName(), parseRequest.getValuePairLiteralValue(), classLoaderHelper.getModuleClassLoader(kieModule));
    AnnotationParseResponse response = new AnnotationParseResponse(driverResult.getK1());
    response.withErrors(driverResult.getK2());
    return response;
}
Also used : AnnotationParseResponse(org.kie.workbench.common.services.datamodeller.driver.model.AnnotationParseResponse) List(java.util.List) ArrayList(java.util.ArrayList) JavaRoasterModelDriver(org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation)

Example 14 with JavaRoasterModelDriver

use of org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver in project kie-wb-common by kiegroup.

the class DataModelerServiceImpl method getAnnotationDefinitions.

@Override
public Map<String, AnnotationDefinition> getAnnotationDefinitions() {
    Map<String, AnnotationDefinition> annotations = new HashMap<String, AnnotationDefinition>();
    // add additional annotations configured by external domains
    Iterator<DomainHandler> it = domainHandlers != null ? domainHandlers.iterator() : null;
    DomainHandler domainHandler;
    List<List<AnnotationDefinition>> allDomainsAnnotations = new ArrayList<List<AnnotationDefinition>>();
    while (it != null && it.hasNext()) {
        domainHandler = it.next();
        allDomainsAnnotations.add(domainHandler.getManagedAnnotations());
    }
    List<AnnotationDefinition> coreAnnotationDefinitions = (new JavaRoasterModelDriver()).getConfiguredAnnotations();
    allDomainsAnnotations.add(coreAnnotationDefinitions);
    for (List<AnnotationDefinition> annotationDefinitionList : allDomainsAnnotations) {
        if (annotationDefinitionList != null) {
            for (AnnotationDefinition annotationDefinition : annotationDefinitionList) {
                annotations.put(annotationDefinition.getClassName(), annotationDefinition);
            }
        }
    }
    return annotations;
}
Also used : AnnotationDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DomainHandler(org.kie.workbench.common.screens.datamodeller.backend.server.handler.DomainHandler) List(java.util.List) ArrayList(java.util.ArrayList) JavaRoasterModelDriver(org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver)

Example 15 with JavaRoasterModelDriver

use of org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver in project kie-wb-common by kiegroup.

the class DataModelerServiceImpl method resolveSaveSource.

private GenerationResult resolveSaveSource(final String source, final Path path, final DataObject dataObject) {
    GenerationResult result = new GenerationResult();
    KieModule module;
    String updatedSource;
    try {
        module = moduleService.resolveModule(path);
        if (module == null) {
            logger.warn("File : " + path.toURI() + " do not belong to a valid module");
            result.setSource(source);
            return result;
        }
        if (dataObject != null) {
            // the source needs to be updated with the DataObject definition prior to save
            result = updateSource(source, path, dataObject);
            updatedSource = result.getSource();
        } else {
            // if the dataObject wasn't provided the source is already prepared to be saved and likely
            // it's not parsed at the ui. So we will save the provided source and try to parse the data object
            updatedSource = source;
        }
        if (dataObject == null) {
            ClassLoader classLoader = classLoaderHelper.getModuleClassLoader(module);
            JavaRoasterModelDriver modelDriver = new JavaRoasterModelDriver(ioService, Paths.convert(path), classLoader, filterHolder);
            ModelDriverResult driverResult = modelDriver.loadDataObject(source, Paths.convert(path));
            if (driverResult.hasErrors()) {
                result.setErrors(serviceHelper.toDataModelerError(driverResult.getErrors()));
            } else {
                if (driverResult.getDataModel().getDataObjects().size() > 0) {
                    result.setDataObject(driverResult.getDataModel().getDataObjects().iterator().next());
                }
            }
        }
        result.setSource(updatedSource);
        return result;
    } catch (Exception e) {
        logger.error("Source file couldn't be updated, path: " + path.toURI() + ", dataObject: " + (dataObject != null ? dataObject.getClassName() : null) + ".", e);
        throw new ServiceException("Source file couldn't be updated, path: " + path.toURI() + ", dataObject: " + (dataObject != null ? dataObject.getClassName() : null) + ".", e);
    }
}
Also used : ServiceException(org.kie.workbench.common.screens.datamodeller.service.ServiceException) GenerationResult(org.kie.workbench.common.screens.datamodeller.model.GenerationResult) ModelDriverResult(org.kie.workbench.common.services.datamodeller.driver.model.ModelDriverResult) KieModule(org.kie.workbench.common.services.shared.project.KieModule) JavaRoasterModelDriver(org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver) ModelDriverException(org.kie.workbench.common.services.datamodeller.driver.ModelDriverException) ServiceException(org.kie.workbench.common.screens.datamodeller.service.ServiceException) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException)

Aggregations

JavaRoasterModelDriver (org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver)22 ModelDriverResult (org.kie.workbench.common.services.datamodeller.driver.model.ModelDriverResult)13 Test (org.junit.Test)11 Path (org.uberfire.java.nio.file.Path)10 ArrayList (java.util.ArrayList)9 List (java.util.List)9 DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)9 AnnotationDefinition (org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition)8 Entity (javax.persistence.Entity)7 BufferedReader (java.io.BufferedReader)6 File (java.io.File)6 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 InputStreamReader (java.io.InputStreamReader)6 URI (java.net.URI)6 Arrays (java.util.Arrays)6 Collections (java.util.Collections)6 Matcher (java.util.regex.Matcher)6 Generated (javax.annotation.Generated)6 Instance (javax.enterprise.inject.Instance)6