Search in sources :

Example 1 with CommentedOption

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."));
            }
        }
    }
}
Also used : CommentedOption(org.uberfire.java.nio.base.options.CommentedOption) ConfigGroup(org.guvnor.structure.server.config.ConfigGroup) ConfigType(org.guvnor.structure.server.config.ConfigType)

Example 2 with CommentedOption

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());
}
Also used : PowerMockito.mockStatic(org.powermock.api.mockito.PowerMockito.mockStatic) Mock(org.mockito.Mock) URISyntaxException(java.net.URISyntaxException) RunWith(org.junit.runner.RunWith) Captor(org.mockito.Captor) ArgumentCaptor(org.mockito.ArgumentCaptor) CommentedOptionFactory(org.guvnor.common.services.backend.util.CommentedOptionFactory) Matchers.eq(org.mockito.Matchers.eq) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Matchers.anyObject(org.mockito.Matchers.anyObject) PowerMockRunner(org.powermock.modules.junit4.PowerMockRunner) RenameService(org.uberfire.ext.editor.commons.service.RenameService) Path(org.uberfire.backend.vfs.Path) DeleteService(org.uberfire.ext.editor.commons.service.DeleteService) Before(org.junit.Before) OutputStream(java.io.OutputStream) Event(javax.enterprise.event.Event) PowerMockito.verifyStatic(org.powermock.api.mockito.PowerMockito.verifyStatic) Assert.assertNotNull(org.junit.Assert.assertNotNull) CommentedOption(org.uberfire.java.nio.base.options.CommentedOption) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) DecisionTableXLSConversionService(org.drools.workbench.screens.dtablexls.service.DecisionTableXLSConversionService) Mockito.when(org.mockito.Mockito.when) AuthenticationService(org.jboss.errai.security.shared.service.AuthenticationService) ResourceOpenedEvent(org.uberfire.workbench.events.ResourceOpenedEvent) File(java.io.File) GenericValidator(org.guvnor.common.services.backend.validation.GenericValidator) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) Matchers.any(org.mockito.Matchers.any) IOUtils(org.apache.commons.io.IOUtils) Mockito.never(org.mockito.Mockito.never) User(org.jboss.errai.security.shared.api.identity.User) DecisionTableParseException(org.drools.template.parser.DecisionTableParseException) IOService(org.uberfire.io.IOService) CopyService(org.uberfire.ext.editor.commons.service.CopyService) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) CommentedOptionFactoryImpl(org.guvnor.common.services.backend.util.CommentedOptionFactoryImpl) CommentedOption(org.uberfire.java.nio.base.options.CommentedOption)

Example 3 with CommentedOption

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);
    }
}
Also used : ServiceException(org.kie.workbench.common.screens.datamodeller.service.ServiceException) CommentedOption(org.uberfire.java.nio.base.options.CommentedOption) GenerationResult(org.kie.workbench.common.screens.datamodeller.model.GenerationResult) 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 4 with CommentedOption

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));
}
Also used : Path(org.uberfire.backend.vfs.Path) SimpleFileSystemProvider(org.uberfire.java.nio.fs.file.SimpleFileSystemProvider) CommentedOption(org.uberfire.java.nio.base.options.CommentedOption) TestFormModelHandlerManager(org.kie.workbench.common.forms.jbpm.server.service.formGeneration.test.TestFormModelHandlerManager) FormModelSynchronizationUtilImpl(org.kie.workbench.common.forms.editor.service.shared.model.impl.FormModelSynchronizationUtilImpl) Before(org.junit.Before)

Example 5 with CommentedOption

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();
}
Also used : CommentedOption(org.uberfire.java.nio.base.options.CommentedOption) TestFileSystem(org.guvnor.test.TestFileSystem) FileSystem(org.uberfire.java.nio.file.FileSystem) ProjectScreenModel(org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel) Test(org.junit.Test)

Aggregations

CommentedOption (org.uberfire.java.nio.base.options.CommentedOption)11 Test (org.junit.Test)6 Path (org.uberfire.backend.vfs.Path)3 HashMap (java.util.HashMap)2 Metadata (org.guvnor.common.services.shared.metadata.model.Metadata)2 Before (org.junit.Before)2 Path (org.uberfire.java.nio.file.Path)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 URISyntaxException (java.net.URISyntaxException)1 Consumer (java.util.function.Consumer)1 Event (javax.enterprise.event.Event)1 IOUtils (org.apache.commons.io.IOUtils)1 DecisionTableParseException (org.drools.template.parser.DecisionTableParseException)1 DecisionTableXLSConversionService (org.drools.workbench.screens.dtablexls.service.DecisionTableXLSConversionService)1 CommentedOptionFactory (org.guvnor.common.services.backend.util.CommentedOptionFactory)1 CommentedOptionFactoryImpl (org.guvnor.common.services.backend.util.CommentedOptionFactoryImpl)1