Search in sources :

Example 6 with AnnotationDefinition

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

the class GenerationEngineTest method setup.

@Before
public void setup() {
    try {
        InputStream in = this.getClass().getResourceAsStream("GenerationTestResults.properties");
        results.load(in);
        in.close();
        Set<String> propertyNames = results.stringPropertyNames();
        for (String property : propertyNames) {
            String newProperty = results.getProperty(property).replaceAll("\n", System.getProperty("line.separator"));
            results.setProperty(property, newProperty);
        }
        engine = GenerationEngine.getInstance();
        dataModelOracleDriver = DataModelOracleModelDriver.getInstance();
        annotationDefinitions = new HashMap<String, AnnotationDefinition>(5);
        List<AnnotationDefinition> configuredAnnotations = dataModelOracleDriver.getConfiguredAnnotations();
        for (AnnotationDefinition annotationDefinition : configuredAnnotations) {
            annotationDefinitions.put(annotationDefinition.getClassName(), annotationDefinition);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : AnnotationDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition) InputStream(java.io.InputStream) Before(org.junit.Before)

Example 7 with AnnotationDefinition

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

the class JavaRoasterModelDriver method resolveAnnotationSource.

public org.kie.workbench.common.services.datamodeller.driver.model.AnnotationSource resolveAnnotationSource(Annotation annotation) {
    org.kie.workbench.common.services.datamodeller.driver.model.AnnotationSource annotationSource = new org.kie.workbench.common.services.datamodeller.driver.model.AnnotationSource();
    // TODO this method can be optimized and likely migrated to Roaster. Should be reviewed when we evaluate
    // the removal of Velocity.
    GenerationTools generationTools = new GenerationTools();
    AnnotationDefinition annotationDefinition;
    StringBuilder annotationCode = new StringBuilder();
    annotationCode.append("@");
    annotationCode.append(annotation.getClassName());
    if ((annotationDefinition = annotation.getAnnotationDefinition()) != null) {
        if (!annotationDefinition.isMarker()) {
            annotationCode.append(generationTools.resolveAnnotationType(annotation));
        }
        if (annotationDefinition.getValuePairs() != null) {
            Object value;
            String valuePairCode;
            for (AnnotationValuePairDefinition valuePairDefinition : annotationDefinition.getValuePairs()) {
                if ((value = annotation.getValue(valuePairDefinition.getName())) != null) {
                    valuePairCode = generationTools.resolveMemberTypeExpression(valuePairDefinition, value);
                } else {
                    valuePairCode = null;
                }
                annotationSource.withValuePairSource(valuePairDefinition.getName(), valuePairCode);
            }
        }
    }
    annotationSource.withSource(annotationCode.toString());
    return annotationSource;
}
Also used : GenerationTools(org.kie.workbench.common.services.datamodeller.codegen.GenerationTools) AnnotationDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition) AnnotationValuePairDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition) AnnotationSource(org.jboss.forge.roaster.model.source.AnnotationSource) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject)

Example 8 with AnnotationDefinition

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

the class DataModelOracleModelDriver method createAnnotation.

private org.kie.workbench.common.services.datamodeller.core.Annotation createAnnotation(Annotation annotationToken) throws ModelDriverException {
    AnnotationDefinition annotationDefinition = getConfiguredAnnotation(annotationToken.getQualifiedTypeName());
    org.kie.workbench.common.services.datamodeller.core.Annotation annotation = null;
    if (annotationDefinition != null) {
        AnnotationDriver annotationDriver = getAnnotationDriver(annotationDefinition.getClassName());
        if (annotationDriver != null) {
            annotation = annotationDriver.buildAnnotation(annotationDefinition, annotationToken);
        } else {
            logger.warn("AnnotationDriver for annotation: " + annotationToken.getQualifiedTypeName() + " is not configured for this driver");
        }
    } else {
        logger.warn("Annotation: " + annotationToken.getQualifiedTypeName() + " is not configured for this driver.");
    }
    return annotation;
}
Also used : AnnotationDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition) AnnotationDriver(org.kie.workbench.common.services.datamodeller.driver.AnnotationDriver)

Example 9 with AnnotationDefinition

use of org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition 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 10 with AnnotationDefinition

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

the class DataModelTestUtil method createAnnotation.

public Annotation createAnnotation(Map<String, AnnotationDefinition> systemAnnotations, String className, String memberName, Object value) {
    AnnotationDefinition annotationDefinition = systemAnnotations.get(className);
    Annotation annotation = new AnnotationImpl(annotationDefinition);
    if (memberName != null) {
        annotation.setValue(memberName, value);
    }
    return annotation;
}
Also used : AnnotationDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition) AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation)

Aggregations

AnnotationDefinition (org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition)21 AnnotationValuePairDefinition (org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition)8 Annotation (org.kie.workbench.common.services.datamodeller.core.Annotation)6 DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)5 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 AnnotationImpl (org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl)4 DataModelerService (org.kie.workbench.common.screens.datamodeller.service.DataModelerService)3 ArrayList (java.util.ArrayList)2 AnnotationSource (org.jboss.forge.roaster.model.source.AnnotationSource)2 AnnotationDriver (org.kie.workbench.common.services.datamodeller.driver.AnnotationDriver)2 JavaRoasterModelDriver (org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver)2 KieModule (org.kie.workbench.common.services.shared.project.KieModule)2 InputStream (java.io.InputStream)1 List (java.util.List)1 Before (org.junit.Before)1 Description (org.kie.api.definition.type.Description)1 ClassTypeResolver (org.kie.soup.project.datamodel.commons.types.ClassTypeResolver)1 DomainHandler (org.kie.workbench.common.screens.datamodeller.backend.server.handler.DomainHandler)1 DataModelerContext (org.kie.workbench.common.screens.datamodeller.client.DataModelerContext)1