Search in sources :

Example 6 with CommentedOption

use of org.uberfire.java.nio.base.options.CommentedOption in project kie-wb-common by kiegroup.

the class PackageNameWhiteListSaverTest method testSave.

@Test
public void testSave() throws Exception {
    final Path path = testFileSystem.createTempFile("whitelist");
    final WhiteList whiteList = new WhiteList();
    whiteList.add("org.drools");
    whiteList.add("org.guvnor");
    final Metadata metadata = new Metadata();
    final String comment = "comment";
    final HashMap<String, Object> attributes = new HashMap<String, Object>();
    when(metadataService.setUpAttributes(path, metadata)).thenReturn(attributes);
    final CommentedOption commentedOption = mock(CommentedOption.class);
    when(commentedOptionFactory.makeCommentedOption("comment")).thenReturn(commentedOption);
    saver.save(path, whiteList, metadata, comment);
    ArgumentCaptor<String> whiteListTextArgumentCaptor = ArgumentCaptor.forClass(String.class);
    verify(ioService).write(any(org.uberfire.java.nio.file.Path.class), whiteListTextArgumentCaptor.capture(), eq(attributes), eq(commentedOption));
    final String whiteListAsText = whiteListTextArgumentCaptor.getValue();
    assertTrue(whiteListAsText.contains("org.drools"));
    assertTrue(whiteListAsText.contains("org.guvnor"));
}
Also used : Path(org.uberfire.backend.vfs.Path) HashMap(java.util.HashMap) CommentedOption(org.uberfire.java.nio.base.options.CommentedOption) WhiteList(org.kie.workbench.common.services.shared.whitelist.WhiteList) Metadata(org.guvnor.common.services.shared.metadata.model.Metadata) Test(org.junit.Test)

Example 7 with CommentedOption

use of org.uberfire.java.nio.base.options.CommentedOption in project kie-wb-common by kiegroup.

the class DMNContentServiceImplTest method saveContent.

@Test
public void saveContent() {
    final String content = "<xml/>";
    final Metadata metadata = mock(Metadata.class);
    final String comment = "Commit message.";
    final Map<String, Object> attributes = new HashMap<>();
    final CommentedOption commentedOption = mock(CommentedOption.class);
    when(metadataService.setUpAttributes(path, metadata)).thenReturn(attributes);
    when(commentedOptionFactory.makeCommentedOption(comment)).thenReturn(commentedOption);
    service.saveContent(path, content, metadata, comment);
    verify(ioService).write(convertedPath, content, attributes, commentedOption);
}
Also used : HashMap(java.util.HashMap) CommentedOption(org.uberfire.java.nio.base.options.CommentedOption) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) Metadata(org.guvnor.common.services.shared.metadata.model.Metadata) Test(org.junit.Test)

Example 8 with CommentedOption

use of org.uberfire.java.nio.base.options.CommentedOption in project kie-wb-common by kiegroup.

the class MigrationConfigurationServiceImpl method updateConfiguration.

@Override
public boolean updateConfiguration(final ConfigGroup configGroup) {
    if (ConfigType.SPACE.equals(configGroup.getType())) {
        configGroup.setType(ConfigType.ORGANIZATIONAL_UNIT);
    }
    String filename = configGroup.getName().replaceAll(INVALID_FILENAME_CHARS, "_");
    final Path filePath = ioService.get(systemRepository.getUri()).resolve(filename + configGroup.getType().getExt());
    final CommentedOption commentedOption = new CommentedOption(getIdentityName(), "Updated config " + filePath.getFileName());
    saveConfiguration(configGroup, filePath, commentedOption);
    configGroupsByTypeWithoutNamespace.remove(configGroup.getType());
    return true;
}
Also used : Path(org.uberfire.java.nio.file.Path) CommentedOption(org.uberfire.java.nio.base.options.CommentedOption)

Example 9 with CommentedOption

use of org.uberfire.java.nio.base.options.CommentedOption in project kie-wb-common by kiegroup.

the class MigrationConfigurationServiceImpl method addConfiguration.

@Override
public boolean addConfiguration(final ConfigGroup configGroup) {
    if (ConfigType.SPACE.equals(configGroup.getType())) {
        configGroup.setType(ConfigType.ORGANIZATIONAL_UNIT);
    }
    String filename = configGroup.getName().replaceAll(INVALID_FILENAME_CHARS, "_");
    final Path filePath = ioService.get(systemRepository.getUri()).resolve(filename + configGroup.getType().getExt());
    // avoid duplicated writes to not cause cyclic cluster sync
    if (ioService.exists(filePath)) {
        return true;
    }
    final CommentedOption commentedOption = new CommentedOption(getIdentityName(), "Created config " + filePath.getFileName());
    saveConfiguration(configGroup, filePath, commentedOption);
    configGroupsByTypeWithoutNamespace.remove(configGroup.getType());
    return true;
}
Also used : Path(org.uberfire.java.nio.file.Path) CommentedOption(org.uberfire.java.nio.base.options.CommentedOption)

Example 10 with CommentedOption

use of org.uberfire.java.nio.base.options.CommentedOption in project kie-wb-common by kiegroup.

the class AbstractVFSDiagramService method create.

public Path create(final Path path, final String name, final String defSetId, final Metadata metadata) {
    final DefinitionSetService services = getServiceById(defSetId);
    if (null == services) {
        throw new IllegalStateException("No backend Definition Set services for [" + defSetId + "]");
    }
    final String fName = buildFileName(name, services.getResourceType());
    final org.uberfire.java.nio.file.Path kiePath = convertToNioPath(path).resolve(fName);
    if (getIoService().exists(kiePath)) {
        throw new FileAlreadyExistsException(kiePath.toString());
    }
    try {
        final D diagram = factoryManager.newDiagram(name, defSetId, metadata);
        final String[] raw = serialize(diagram);
        getIoService().write(kiePath, raw[0], new CommentedOption(identity.getIdentifier()));
        return convertToBackendPath(kiePath);
    } catch (final Exception e) {
        LOG.error("Cannot create diagram in path [" + kiePath + "]", e);
    }
    return null;
}
Also used : FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException) CommentedOption(org.uberfire.java.nio.base.options.CommentedOption) DefinitionSetService(org.kie.workbench.common.stunner.core.definition.service.DefinitionSetService) DiagramParsingException(org.kie.workbench.common.stunner.core.diagram.DiagramParsingException) IOException(org.uberfire.java.nio.IOException) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException)

Aggregations

CommentedOption (org.uberfire.java.nio.base.options.CommentedOption)19 Test (org.junit.Test)11 Path (org.uberfire.backend.vfs.Path)8 Metadata (org.guvnor.common.services.shared.metadata.model.Metadata)6 HashMap (java.util.HashMap)3 Before (org.junit.Before)2 ProjectMetadata (org.kie.workbench.common.stunner.project.diagram.ProjectMetadata)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 Map (java.util.Map)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