use of org.uberfire.java.nio.base.options.CommentedOption in project kie-wb-common by kiegroup.
the class ConfigGroupsMigrationService method groupConfigGroupsByType.
private void groupConfigGroupsByType() {
final org.uberfire.java.nio.file.Path systemDir = ioService.get(systemRepository.getUri());
for (ConfigType oldType : ConfigType.values()) {
final String oldExt = oldType.getExt();
final DirectoryStream<org.uberfire.java.nio.file.Path> foundConfigs = getDirectoryStreamForFilesWithParticularExtension(systemDir, oldExt);
final ConfigType newType = getNewType(oldType);
final org.uberfire.java.nio.file.Path newTypeDir = systemDir.resolve(newType.getDir());
if (!ioService.exists(newTypeDir)) {
ioService.createDirectory(newTypeDir);
}
final Iterator<org.uberfire.java.nio.file.Path> it = foundConfigs.iterator();
while (it.hasNext()) {
final org.uberfire.java.nio.file.Path oldPath = it.next();
final String newExt = newType.getExt();
final String oldFileName = Paths.convert(oldPath).getFileName();
final String newFileName = FileNameUtil.removeExtension(oldFileName, oldExt.substring(1)) + newExt;
final org.uberfire.java.nio.file.Path newPath = newTypeDir.resolve(newFileName);
ioService.move(oldPath, newPath);
if (!newType.equals(oldType)) {
final String content = ioService.readAllString(newPath);
final ConfigGroup configGroup = marshaller.unmarshall(content);
configGroup.setType(newType);
ioService.write(newPath, marshaller.marshall(configGroup), new CommentedOption(getIdentityName(), "Updated configuration type."));
}
}
}
}
use of org.uberfire.java.nio.base.options.CommentedOption in project drools-wb by kiegroup.
the class DecisionTableXLSServiceImplTest method assertCommentedOption.
private void assertCommentedOption() {
this.service = getServiceWithValidationOverride((tempFile) -> {
// Do nothing; tests do not use a *real* XLS file
});
final CommentedOption commentedOption = commentedOptionArgumentCaptor.getValue();
assertNotNull(commentedOption);
assertEquals("user", commentedOption.getName());
assertEquals("123", commentedOption.getSessionId());
}
use of org.uberfire.java.nio.base.options.CommentedOption in project kie-wb-common by kiegroup.
the class DataModelerServiceImpl method saveModel.
@Override
public GenerationResult saveModel(final DataModel dataModel, final KieModule module, final boolean overwrite, final String commitMessage) {
Long startTime = System.currentTimeMillis();
boolean onBatch = false;
try {
// Start IOService bath processing. IOService batch processing causes a blocking operation on the file system
// to it must be treated carefully.
CommentedOption option = serviceHelper.makeCommentedOption(commitMessage);
ioService.startBatch(Paths.convert(module.getRootPath()).getFileSystem());
onBatch = true;
generateModel(dataModel, module, option);
onBatch = false;
ioService.endBatch();
Long endTime = System.currentTimeMillis();
if (logger.isDebugEnabled()) {
logger.debug("Time elapsed when saving " + module.getModuleName() + ": " + (endTime - startTime) + " ms");
}
GenerationResult result = new GenerationResult();
result.setGenerationTime(endTime - startTime);
return result;
} catch (Exception e) {
logger.error("An error was produced during data model adf, dataModel: " + dataModel + ", path: " + module.getRootPath(), e);
if (onBatch) {
try {
logger.warn("IOService batch method is still on, trying to end batch processing.");
ioService.endBatch();
logger.warn("IOService batch method is was successfully finished. The user will still get the exception, but the batch processing was finished.");
} catch (Exception ex) {
logger.error("An error was produced when the IOService.endBatch processing was executed.", ex);
}
}
throw new ServiceException("Data model couldn't be generated due to the following error. " + e);
}
}
use of org.uberfire.java.nio.base.options.CommentedOption in project kie-wb-common by kiegroup.
the class BPMNVFSFormDefinitionGeneratorServiceTest method setup.
@Before
public void setup() throws IOException {
when(projectService.resolveModule(any())).thenReturn(module);
when(projectClassLoaderHelper.getModuleClassLoader(module)).thenReturn(this.getClass().getClassLoader());
source = mock(Path.class);
simpleFileSystemProvider = new SimpleFileSystemProvider();
simpleFileSystemProvider.forceAsDefault();
when(source.toURI()).thenReturn("default:///src/main/resources/test.frm");
when(commentedOptionFactory.makeCommentedOption(anyString())).then(invocationOnMock -> new CommentedOption("1", invocationOnMock.getArguments()[0].toString()));
formModelHandlerManager = new TestFormModelHandlerManager(projectService, projectClassLoaderHelper, fieldManager, dataObjectFinderService);
service = new BPMNVFSFormDefinitionGeneratorService(fieldManager, formModelHandlerManager, formFinderService, formSerializer, ioService, commentedOptionFactory, new FormModelSynchronizationUtilImpl(fieldManager, templateGenerator));
}
use of org.uberfire.java.nio.base.options.CommentedOption in project kie-wb-common by kiegroup.
the class ProjectScreenModelSaverTest method testBatchSave.
@Test
public void testBatchSave() throws Exception {
final CommentedOption commentedOption = new CommentedOption("hello");
when(commentedOptionFactory.makeCommentedOption("message")).thenReturn(commentedOption);
saver.save(pathToPom, new ProjectScreenModel(), DeploymentMode.FORCED, "message");
verify(ioService).startBatch(any(FileSystem.class), eq(commentedOption));
verify(ioService).endBatch();
}
Aggregations