Search in sources :

Example 6 with Metadata

use of org.guvnor.common.services.shared.metadata.model.Metadata in project drools-wb by kiegroup.

the class GuidedDecisionTableEditorServiceImpl method save.

@Override
public Path save(final Path resource, final GuidedDecisionTable52 model, final Metadata metadata, final String comment) {
    try {
        final Package pkg = moduleService.resolvePackage(resource);
        final String packageName = (pkg == null ? null : pkg.getPackageName());
        model.setPackageName(packageName);
        Metadata currentMetadata = metadataService.getMetadata(resource);
        ioService.write(Paths.convert(resource), GuidedDTXMLPersistence.getInstance().marshal(model), metadataService.setUpAttributes(resource, metadata), commentedOptionFactory.makeCommentedOption(comment));
        fireMetadataSocialEvents(resource, currentMetadata, metadata);
        return resource;
    } catch (Exception e) {
        throw ExceptionUtilities.handleException(e);
    }
}
Also used : Metadata(org.guvnor.common.services.shared.metadata.model.Metadata) Package(org.guvnor.common.services.project.model.Package) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException)

Example 7 with Metadata

use of org.guvnor.common.services.shared.metadata.model.Metadata in project drools-wb by kiegroup.

the class GuidedDecisionTableEditorServiceImplTest method checkSave.

@Test
@SuppressWarnings("unchecked")
public void checkSave() {
    final Path path = mock(Path.class);
    final GuidedDecisionTable52 model = new GuidedDecisionTable52();
    final Metadata metadata = mock(Metadata.class);
    final String comment = "comment";
    when(path.toURI()).thenReturn("default://project/src/main/resources/mypackage/dtable.gdst");
    service.save(path, model, metadata, comment);
    verify(ioService, times(1)).write(any(org.uberfire.java.nio.file.Path.class), any(String.class), any(Map.class), any(CommentedOption.class));
    assertEquals("mypackage", model.getPackageName());
}
Also used : Path(org.uberfire.backend.vfs.Path) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) CommentedOption(org.uberfire.java.nio.base.options.CommentedOption) Metadata(org.guvnor.common.services.shared.metadata.model.Metadata) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 8 with Metadata

use of org.guvnor.common.services.shared.metadata.model.Metadata in project drools-wb by kiegroup.

the class GuidedDecisionTableEditorServiceImplTest method checkSaveAndUpdateGraphEntries.

@Test
@SuppressWarnings("unchecked")
public void checkSaveAndUpdateGraphEntries() {
    // Setup Decision Table
    final Path path = mock(Path.class);
    final GuidedDecisionTable52 model = new GuidedDecisionTable52();
    final Metadata metadata = mock(Metadata.class);
    final String comment = "comment";
    final String headPathUri = "default://project/src/main/resources/mypackage/dtable.gdst";
    final String versionPathUri = "default://0123456789@project/src/main/resources/mypackage/dtable.gdst";
    when(path.toURI()).thenReturn(headPathUri);
    when(path.getFileName()).thenReturn("dtable.gdst");
    // Setup Decision Table versions
    final List<VersionRecord> versions = new ArrayList<>();
    versions.add(new PortableVersionRecord("0123456789", "manstis", "manstis@email.com", "comment", Calendar.getInstance().getTime(), versionPathUri));
    when(versionRecordService.load(any(org.uberfire.java.nio.file.Path.class))).thenReturn(versions);
    // Setup Decision Table Graph
    final URI dtGraphPathUri = URI.create("default://project/src/main/resources/mypackage/graph1.gdst-set");
    final org.uberfire.java.nio.file.Path dtGraphPath = mock(org.uberfire.java.nio.file.Path.class);
    when(dtGraphPath.toUri()).thenReturn(dtGraphPathUri);
    when(dtGraphPath.getFileName()).thenReturn(dtGraphPath);
    when(dtGraphPath.getFileSystem()).thenReturn(fileSystem);
    final List<org.uberfire.java.nio.file.Path> dtGraphPaths = new ArrayList<>();
    dtGraphPaths.add(dtGraphPath);
    when(ioService.newDirectoryStream(any(org.uberfire.java.nio.file.Path.class), any(FileExtensionFilter.class))).thenReturn(new MockDirectoryStream(dtGraphPaths));
    final GuidedDecisionTableEditorGraphModel dtGraphModel = new GuidedDecisionTableEditorGraphModel();
    dtGraphModel.getEntries().add(new GuidedDecisionTableEditorGraphModel.GuidedDecisionTableGraphEntry(path, path));
    when(dtableGraphService.load(any(Path.class))).thenReturn(dtGraphModel);
    // Test save
    service.saveAndUpdateGraphEntries(path, model, metadata, comment);
    verify(ioService, times(1)).startBatch(any(FileSystem.class));
    verify(ioService, times(1)).write(any(org.uberfire.java.nio.file.Path.class), any(String.class), any(Map.class), any(CommentedOption.class));
    verify(ioService, times(1)).endBatch();
    assertEquals("mypackage", model.getPackageName());
    assertEquals(1, dtGraphModel.getEntries().size());
    assertEquals(versions.get(0).uri(), dtGraphModel.getEntries().iterator().next().getPathVersion().toURI());
}
Also used : Path(org.uberfire.backend.vfs.Path) GuidedDecisionTableEditorGraphModel(org.drools.workbench.screens.guided.dtable.model.GuidedDecisionTableEditorGraphModel) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) Metadata(org.guvnor.common.services.shared.metadata.model.Metadata) ArrayList(java.util.ArrayList) URI(java.net.URI) PortableVersionRecord(org.uberfire.ext.editor.commons.version.impl.PortableVersionRecord) VersionRecord(org.uberfire.java.nio.base.version.VersionRecord) CommentedOption(org.uberfire.java.nio.base.options.CommentedOption) FileSystem(org.uberfire.java.nio.file.FileSystem) FileExtensionFilter(org.guvnor.common.services.backend.file.FileExtensionFilter) PortableVersionRecord(org.uberfire.ext.editor.commons.version.impl.PortableVersionRecord) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 9 with Metadata

use of org.guvnor.common.services.shared.metadata.model.Metadata in project drools-wb by kiegroup.

the class GuidedDecisionTableEditorServiceImplTest method testSaveAndRename.

@Test
public void testSaveAndRename() throws Exception {
    final Path path = mock(Path.class);
    final String newFileName = "newFileName";
    final Metadata metadata = mock(Metadata.class);
    final GuidedDecisionTable52 content = mock(GuidedDecisionTable52.class);
    final String comment = "comment";
    service.saveAndRename(path, newFileName, metadata, content, comment);
    verify(saveAndRenameService).saveAndRename(path, newFileName, metadata, content, comment);
}
Also used : Path(org.uberfire.backend.vfs.Path) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) Metadata(org.guvnor.common.services.shared.metadata.model.Metadata) Test(org.junit.Test)

Example 10 with Metadata

use of org.guvnor.common.services.shared.metadata.model.Metadata in project drools-wb by kiegroup.

the class BaseGuidedDecisionTableEditorPresenter method onSave.

@Override
public void onSave(final GuidedDecisionTableView.Presenter dtPresenter, final String commitMessage) {
    final ObservablePath path = dtPresenter.getCurrentPath();
    final GuidedDecisionTable52 model = dtPresenter.getModel();
    final Metadata metadata = dtPresenter.getOverview().getMetadata();
    service.call(getSaveSuccessCallback(dtPresenter, model.hashCode()), new HasBusyIndicatorDefaultErrorCallback(view)).saveAndUpdateGraphEntries(path, model, metadata, commitMessage);
}
Also used : GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) Metadata(org.guvnor.common.services.shared.metadata.model.Metadata) HasBusyIndicatorDefaultErrorCallback(org.uberfire.ext.widgets.common.client.callbacks.HasBusyIndicatorDefaultErrorCallback) ObservablePath(org.uberfire.backend.vfs.ObservablePath)

Aggregations

Metadata (org.guvnor.common.services.shared.metadata.model.Metadata)62 Test (org.junit.Test)45 Path (org.uberfire.backend.vfs.Path)35 FileAlreadyExistsException (org.uberfire.java.nio.file.FileAlreadyExistsException)13 ProjectScreenModel (org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel)9 Package (org.guvnor.common.services.project.model.Package)7 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)6 HashMap (java.util.HashMap)5 POM (org.guvnor.common.services.project.model.POM)5 ProjectImports (org.guvnor.common.services.project.model.ProjectImports)5 ObservablePath (org.uberfire.backend.vfs.ObservablePath)5 CommentedOption (org.uberfire.java.nio.base.options.CommentedOption)5 Overview (org.guvnor.common.services.shared.metadata.model.Overview)4 WhiteList (org.kie.workbench.common.services.shared.whitelist.WhiteList)4 Map (java.util.Map)3 GuidedDecisionTableView (org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTableView)3 InvalidateDMOPackageCacheEvent (org.guvnor.common.services.project.builder.events.InvalidateDMOPackageCacheEvent)3 MavenRepositoryMetadata (org.guvnor.common.services.project.model.MavenRepositoryMetadata)3 KModuleModel (org.kie.workbench.common.services.shared.kmodule.KModuleModel)3 Mockito.anyString (org.mockito.Mockito.anyString)3