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;
}
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();
}
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());
}
}
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);
}
}
}
}
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);
}
}
Aggregations