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