Search in sources :

Example 56 with DataObject

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

the class NestedFormsBPMNVFSFormDefinitionGeneratorServiceTest method getExpenseDataObject.

protected DataObject getExpenseDataObject() {
    DataObject expense = new DataObjectImpl(Expense.class.getPackage().toString(), Expense.class.getSimpleName());
    expense.addProperty("id", Long.class.getName(), false, null);
    expense.addProperty("date", Date.class.getName(), false, null);
    expense.addProperty("client", Client.class.getName(), false, null);
    expense.addProperty("lines", Line.class.getName(), true, List.class.getName());
    return expense;
}
Also used : DataObjectImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl) Line(org.kie.workbench.common.forms.jbpm.server.service.formGeneration.model.Line) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) Expense(org.kie.workbench.common.forms.jbpm.server.service.formGeneration.model.Expense) List(java.util.List) Client(org.kie.workbench.common.forms.jbpm.server.service.formGeneration.model.Client) Date(java.util.Date)

Example 57 with DataObject

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

the class DataModelerServiceTest method testSaveSource.

private void testSaveSource(String newPackageName, String newFileName) {
    Path dataObjectPath = PathFactory.newPath("TestDataObject", "file:///dataobjects/TestDataObject.java");
    Path srcPath = PathFactory.newPath("src", "file:///src");
    Package packageMock = mock(Package.class);
    when(packageMock.getPackageMainSrcPath()).thenReturn(srcPath);
    when(serviceHelper.ensurePackageStructure(any(Module.class), anyString())).thenReturn(packageMock);
    DataModelerSaveHelper saveHelper = mock(DataModelerSaveHelper.class);
    List<DataModelerSaveHelper> saveHelpers = Arrays.asList(saveHelper);
    when(saveHelperInstance.iterator()).thenReturn(saveHelpers.iterator());
    DataObject dataObject = new DataObjectImpl("dataobjects", "TestDataObject");
    dataModelerService.saveSource("Source", dataObjectPath, dataObject, mock(Metadata.class), "Commit message", newPackageName, newFileName);
    verify(ioService, times(1)).startBatch(any(FileSystem.class));
    if (newPackageName == null && newFileName == null) {
        verify(ioService, times(1)).write(any(org.uberfire.java.nio.file.Path.class), anyString(), anyMap(), any(CommentedOption.class));
    } else if (newPackageName != null && newFileName != null) {
        verify(ioService, times(1)).write(any(org.uberfire.java.nio.file.Path.class), anyString(), anyMap(), any(CommentedOption.class));
        verify(ioService, times(1)).move(any(org.uberfire.java.nio.file.Path.class), any(org.uberfire.java.nio.file.Path.class), any(CommentedOption.class));
    } else if (newPackageName != null) {
        verify(ioService, times(1)).write(any(org.uberfire.java.nio.file.Path.class), anyString(), anyMap(), any(CommentedOption.class));
        verify(ioService, times(1)).move(any(org.uberfire.java.nio.file.Path.class), any(org.uberfire.java.nio.file.Path.class), any(CommentedOption.class));
    } else {
        verify(renameService, times(1)).rename(any(Path.class), anyString(), anyString());
    }
    verify(saveHelper, times(1)).postProcess(any(Path.class), any(Path.class));
    verify(ioService, times(1)).endBatch();
}
Also used : Path(org.uberfire.backend.vfs.Path) Metadata(org.guvnor.common.services.shared.metadata.model.Metadata) DataObjectImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) CommentedOption(org.uberfire.java.nio.base.options.CommentedOption) FileSystem(org.uberfire.java.nio.file.FileSystem) Package(org.guvnor.common.services.project.model.Package) DataModelerSaveHelper(org.kie.workbench.common.screens.datamodeller.backend.server.helper.DataModelerSaveHelper) Module(org.guvnor.common.services.project.model.Module)

Example 58 with DataObject

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

the class DataModelerServiceImpl method delete.

@Override
public void delete(final Path path, final String comment) {
    try {
        KieModule module = moduleService.resolveModule(path);
        if (module == null) {
            logger.warn("File : " + path.toURI() + " do not belong to a valid module");
            return;
        }
        deleteService.delete(path, comment);
        String className = serviceHelper.calculateClassName(module, path);
        DataObject dataObject = new DataObjectImpl(NamingUtils.extractPackageName(className), NamingUtils.extractClassName(className));
        dataObjectDeletedEvent.fire(new DataObjectDeletedEvent(module, dataObject));
    } catch (final Exception e) {
        logger.error("File: " + path.toURI() + " couldn't be deleted due to the following error. ", e);
        throw new ServiceException("File: " + path.toURI() + " couldn't be deleted due to the following error. " + e.getMessage());
    }
}
Also used : DataObjectImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) ServiceException(org.kie.workbench.common.screens.datamodeller.service.ServiceException) DataObjectDeletedEvent(org.kie.workbench.common.screens.datamodeller.events.DataObjectDeletedEvent) KieModule(org.kie.workbench.common.services.shared.project.KieModule) 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)

Example 59 with DataObject

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

the class JPADomainHandler method setDefaultValues.

@Override
public void setDefaultValues(DataObject dataObject, Map<String, Object> portableParams) {
    if (portableParams != null) {
        Object currentValue = portableParams.get("persistable");
        boolean isPersistable = Boolean.valueOf(currentValue != null ? currentValue.toString() : null);
        currentValue = portableParams.get("tableName");
        String tableName = currentValue != null ? currentValue.toString() : null;
        if (isPersistable) {
            // add default parameters for a persistable data object
            JavaRoasterModelDriver modelDriver = new JavaRoasterModelDriver();
            // mark the class as Entity
            dataObject.addAnnotation(new AnnotationImpl(modelDriver.getConfiguredAnnotation(Entity.class.getName())));
            if (tableName != null && !"".equals(tableName.trim())) {
                Annotation tableAnnotation = new AnnotationImpl(modelDriver.getConfiguredAnnotation(Table.class.getName()));
                tableAnnotation.setValue("name", tableName.trim());
                dataObject.addAnnotation(tableAnnotation);
            }
            // add the by default id field
            ObjectProperty id = dataObject.addProperty("id", Long.class.getName());
            id.addAnnotation(new AnnotationImpl(modelDriver.getConfiguredAnnotation(Id.class.getName())));
            // set the by default generated value annotation.
            String generatorName = createDefaultGeneratorName(dataObject.getName());
            Annotation generatedValue = new AnnotationImpl(modelDriver.getConfiguredAnnotation(GeneratedValue.class.getName()));
            generatedValue.setValue("generator", generatorName);
            generatedValue.setValue("strategy", GenerationType.AUTO.name());
            id.addAnnotation(generatedValue);
            // set by default sequence generator
            Annotation sequenceGenerator = new AnnotationImpl(modelDriver.getConfiguredAnnotation(SequenceGenerator.class.getName()));
            String sequenceName = createDefaultSequenceName(dataObject.getName());
            sequenceGenerator.setValue("name", generatorName);
            sequenceGenerator.setValue("sequenceName", sequenceName);
            id.addAnnotation(sequenceGenerator);
            boolean isAuditable = portableParams.containsKey("audited") ? Boolean.valueOf(portableParams.get("audited").toString()) : false;
            if (isAuditable) {
                Annotation audited = new AnnotationImpl(modelDriver.getConfiguredAnnotation(Audited.class.getName()));
                audited.setValue("targetAuditMode", RelationTargetAuditMode.NOT_AUDITED.name());
                dataObject.addAnnotation(audited);
            }
        }
    }
}
Also used : ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) Entity(javax.persistence.Entity) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) Id(javax.persistence.Id) AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) JavaRoasterModelDriver(org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation)

Example 60 with DataObject

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

DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)95 Test (org.junit.Test)45 ObjectProperty (org.kie.workbench.common.services.datamodeller.core.ObjectProperty)40 DataModel (org.kie.workbench.common.services.datamodeller.core.DataModel)29 Annotation (org.kie.workbench.common.services.datamodeller.core.Annotation)28 DataObjectImpl (org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl)21 ArrayList (java.util.ArrayList)17 AnnotationValuesAnnotation (org.kie.workbench.common.services.datamodeller.annotations.AnnotationValuesAnnotation)17 ClassAnnotation (org.kie.workbench.common.services.datamodeller.annotations.ClassAnnotation)17 EnumsAnnotation (org.kie.workbench.common.services.datamodeller.annotations.EnumsAnnotation)17 MarkerAnnotation (org.kie.workbench.common.services.datamodeller.annotations.MarkerAnnotation)17 PrimitivesAnnotation (org.kie.workbench.common.services.datamodeller.annotations.PrimitivesAnnotation)17 TestAnnotation (org.kie.workbench.common.services.datamodeller.parser.test.TestAnnotation)17 AnnotationImpl (org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl)16 DomainEditorBaseTest (org.kie.workbench.common.screens.datamodeller.client.widgets.DomainEditorBaseTest)15 MethodImpl (org.kie.workbench.common.services.datamodeller.core.impl.MethodImpl)12 List (java.util.List)11 TypeImpl (org.kie.workbench.common.services.datamodeller.core.impl.TypeImpl)11 Method (org.kie.workbench.common.services.datamodeller.core.Method)10 Generated (javax.annotation.Generated)8