Search in sources :

Example 1 with DomainHandler

use of org.kie.workbench.common.screens.datamodeller.backend.server.handler.DomainHandler 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 2 with DomainHandler

use of org.kie.workbench.common.screens.datamodeller.backend.server.handler.DomainHandler in project kie-wb-common by kiegroup.

the class DataModelerServiceImpl method createJavaFile.

@Override
public Path createJavaFile(final Path context, final String fileName, final String comment, final Map<String, Object> options) {
    final org.uberfire.java.nio.file.Path nioPath = Paths.convert(context).resolve(fileName);
    final Path newPath = Paths.convert(nioPath);
    if (ioService.exists(nioPath)) {
        throw new FileAlreadyExistsException(nioPath.toString());
    }
    try {
        final Package currentPackage = moduleService.resolvePackage(context);
        String packageName = currentPackage.getPackageName();
        String className = fileName.substring(0, fileName.indexOf(".java"));
        final KieModule currentModule = moduleService.resolveModule(context);
        DataObject dataObject = new DataObjectImpl(packageName, className);
        Iterator<DomainHandler> it = domainHandlers != null ? domainHandlers.iterator() : null;
        while (it != null && it.hasNext()) {
            it.next().setDefaultValues(dataObject, options);
        }
        String source = createJavaSource(dataObject);
        ioService.write(nioPath, source, serviceHelper.makeCommentedOption(comment));
        dataObjectCreatedEvent.fire(new DataObjectCreatedEvent(currentModule, dataObject));
        return newPath;
    } catch (Exception e) {
        // uncommon error.
        logger.error("It was not possible to create Java file, for path: " + context.toURI() + ", fileName: " + fileName, e);
        throw new ServiceException("It was not possible to create Java file, for path: " + context.toURI() + ", fileName: " + fileName, e);
    }
}
Also used : Path(org.uberfire.backend.vfs.Path) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException) 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) DataObjectImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DataObjectCreatedEvent(org.kie.workbench.common.screens.datamodeller.events.DataObjectCreatedEvent) ServiceException(org.kie.workbench.common.screens.datamodeller.service.ServiceException) DomainHandler(org.kie.workbench.common.screens.datamodeller.backend.server.handler.DomainHandler) Package(org.guvnor.common.services.project.model.Package) KieModule(org.kie.workbench.common.services.shared.project.KieModule)

Aggregations

DomainHandler (org.kie.workbench.common.screens.datamodeller.backend.server.handler.DomainHandler)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Package (org.guvnor.common.services.project.model.Package)1 DataObjectCreatedEvent (org.kie.workbench.common.screens.datamodeller.events.DataObjectCreatedEvent)1 ServiceException (org.kie.workbench.common.screens.datamodeller.service.ServiceException)1 AnnotationDefinition (org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition)1 DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)1 DataObjectImpl (org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl)1 ModelDriverException (org.kie.workbench.common.services.datamodeller.driver.ModelDriverException)1 JavaRoasterModelDriver (org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver)1 KieModule (org.kie.workbench.common.services.shared.project.KieModule)1 Path (org.uberfire.backend.vfs.Path)1 FileAlreadyExistsException (org.uberfire.java.nio.file.FileAlreadyExistsException)1