Search in sources :

Example 1 with DriverError

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

the class DataModelerServiceHelperTest method testToDataModelerErrorFromDriverError.

@Test
public void testToDataModelerErrorFromDriverError() {
    ArrayList<DriverError> driverErrors = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        driverErrors.add(new DriverError(i, "message" + i, mock(Path.class), i, i));
    }
    List<DataModelerError> result = serviceHelper.toDataModelerError(driverErrors);
    assertEquals(driverErrors.size(), result.size());
    for (int i = 0; i < driverErrors.size(); i++) {
        assertErrorEquals(driverErrors.get(i), result.get(i));
    }
}
Also used : DataModelerError(org.kie.workbench.common.screens.datamodeller.model.DataModelerError) ArrayList(java.util.ArrayList) DriverError(org.kie.workbench.common.services.datamodeller.driver.model.DriverError) Test(org.junit.Test)

Example 2 with DriverError

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

the class DataModelerServiceImpl method resolveDefinitionRequest.

@Override
public AnnotationDefinitionResponse resolveDefinitionRequest(AnnotationDefinitionRequest definitionRequest, KieModule kieModule) {
    JavaRoasterModelDriver modelDriver = new JavaRoasterModelDriver();
    ClassLoader classLoader = classLoaderHelper.getModuleClassLoader(kieModule);
    ClassTypeResolver classTypeResolver = DriverUtils.createClassTypeResolver(classLoader);
    AnnotationDefinitionResponse definitionResponse = new AnnotationDefinitionResponse();
    try {
        AnnotationDefinition annotationDefinition = modelDriver.buildAnnotationDefinition(definitionRequest.getClassName(), classTypeResolver);
        definitionResponse.withAnnotationDefinition(annotationDefinition);
    } catch (ModelDriverException e) {
        DriverError driverError = new DriverError(e.getMessage());
        definitionResponse.addError(driverError);
    }
    return definitionResponse;
}
Also used : AnnotationDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition) AnnotationDefinitionResponse(org.kie.workbench.common.services.datamodeller.driver.model.AnnotationDefinitionResponse) ModelDriverException(org.kie.workbench.common.services.datamodeller.driver.ModelDriverException) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) JavaRoasterModelDriver(org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver) DriverError(org.kie.workbench.common.services.datamodeller.driver.model.DriverError)

Example 3 with DriverError

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

the class DataModelerServiceImpl method validateValuePair.

@Override
public List<ValidationMessage> validateValuePair(String annotationClassName, ElementType target, String valuePairName, String literalValue) {
    // Currently we only validate the syntax but additional checks may be added.
    List<ValidationMessage> validationMessages = new ArrayList<ValidationMessage>();
    JavaRoasterModelDriver modelDriver = new JavaRoasterModelDriver();
    Pair<AnnotationSource<JavaClassSource>, List<DriverError>> parseResult = modelDriver.parseAnnotationWithValuePair(annotationClassName, target, valuePairName, literalValue);
    if (parseResult.getK2() != null && parseResult.getK2().size() > 0) {
        ValidationMessage validationMessage;
        for (DriverError driverError : parseResult.getK2()) {
            validationMessage = new ValidationMessage();
            validationMessage.setText(driverError.getMessage());
            validationMessage.setColumn(driverError.getColumn());
            validationMessage.setLine(driverError.getLine());
            validationMessage.setLevel(Level.ERROR);
            validationMessages.add(validationMessage);
        }
    }
    return validationMessages;
}
Also used : ValidationMessage(org.guvnor.common.services.shared.validation.model.ValidationMessage) ArrayList(java.util.ArrayList) AnnotationSource(org.jboss.forge.roaster.model.source.AnnotationSource) List(java.util.List) ArrayList(java.util.ArrayList) JavaRoasterModelDriver(org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver) DriverError(org.kie.workbench.common.services.datamodeller.driver.model.DriverError)

Example 4 with DriverError

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

the class JavaRoasterModelDriver method addSyntaxErrors.

private void addSyntaxErrors(DriverResult result, Path file, List<SyntaxError> syntaxErrors) {
    DriverError error;
    for (SyntaxError syntaxError : syntaxErrors) {
        error = new DriverError(syntaxError.getDescription(), Paths.convert(file));
        error.setLine(syntaxError.getLine());
        error.setColumn(syntaxError.getColumn());
        result.addError(error);
    }
}
Also used : SyntaxError(org.jboss.forge.roaster.model.SyntaxError) DriverError(org.kie.workbench.common.services.datamodeller.driver.model.DriverError)

Example 5 with DriverError

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

the class JavaRoasterModelDriver method parseAnnotationWithValuePair.

public Pair<AnnotationSource<JavaClassSource>, List<DriverError>> parseAnnotationWithValuePair(String annotationClassName, ElementType target, String valuePairName, String literalValue) {
    List<DriverError> syntaxErrors = new ArrayList<DriverError>();
    String annotationStr = "@" + annotationClassName + "(" + valuePairName + "=" + literalValue + " )";
    String stub;
    AnnotationSource<JavaClassSource> annotation = null;
    if (ElementType.TYPE.equals(target)) {
        stub = annotationStr + " public class Stub { }";
    } else {
        stub = "public class Stub { " + annotationStr + " int dummy; }";
    }
    JavaClassSource temp = (JavaClassSource) Roaster.parse(JavaClass.class, stub);
    if (temp.getSyntaxErrors() != null && temp.getSyntaxErrors().size() > 0) {
        for (org.jboss.forge.roaster.model.SyntaxError syntaxError : temp.getSyntaxErrors()) {
            syntaxErrors.add(new DriverError(syntaxError.getDescription(), syntaxError.getLine(), syntaxError.getColumn()));
        }
    } else if (ElementType.TYPE.equals(target)) {
        annotation = temp.getAnnotation(annotationClassName);
    } else {
        annotation = temp.getField("dummy").getAnnotation(annotationClassName);
    }
    if (annotation == null) {
        syntaxErrors.add(new DriverError("Annotation value pair could not be parsed."));
    }
    return new Pair<>(annotation, syntaxErrors);
}
Also used : JavaClass(org.jboss.forge.roaster.model.JavaClass) ArrayList(java.util.ArrayList) JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource) SyntaxError(org.jboss.forge.roaster.model.SyntaxError) DriverError(org.kie.workbench.common.services.datamodeller.driver.model.DriverError) Pair(org.uberfire.commons.data.Pair)

Aggregations

DriverError (org.kie.workbench.common.services.datamodeller.driver.model.DriverError)12 ArrayList (java.util.ArrayList)7 ModelDriverException (org.kie.workbench.common.services.datamodeller.driver.ModelDriverException)6 IOException (java.io.IOException)4 ParserException (org.jboss.forge.roaster.ParserException)4 List (java.util.List)3 SyntaxError (org.jboss.forge.roaster.model.SyntaxError)2 AnnotationSource (org.jboss.forge.roaster.model.source.AnnotationSource)2 JavaClassSource (org.jboss.forge.roaster.model.source.JavaClassSource)2 ClassTypeResolver (org.kie.soup.project.datamodel.commons.types.ClassTypeResolver)2 DataModelerError (org.kie.workbench.common.screens.datamodeller.model.DataModelerError)2 DataModel (org.kie.workbench.common.services.datamodeller.core.DataModel)2 JavaRoasterModelDriver (org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver)2 ModelDriverResult (org.kie.workbench.common.services.datamodeller.driver.model.ModelDriverResult)2 Pair (org.uberfire.commons.data.Pair)2 ValidationMessage (org.guvnor.common.services.shared.validation.model.ValidationMessage)1 PublishBatchMessagesEvent (org.guvnor.messageconsole.events.PublishBatchMessagesEvent)1 SystemMessage (org.guvnor.messageconsole.events.SystemMessage)1 JavaClass (org.jboss.forge.roaster.model.JavaClass)1 JavaEnumSource (org.jboss.forge.roaster.model.source.JavaEnumSource)1