Search in sources :

Example 66 with Path

use of org.uberfire.backend.vfs.Path in project drools-wb by kiegroup.

the class GuidedRuleEditorServiceImplTest method testValidateModifyScoreAction.

@Test
public void testValidateModifyScoreAction() throws Exception {
    final Path path = mock(Path.class);
    final FreeFormLine modifyAction = new FreeFormLine();
    modifyAction.setText(MODIFY_SCORE_ACTION);
    final RuleModel model = new RuleModel();
    model.addRhsItem(modifyAction);
    service.validate(path, model);
    final ArgumentCaptor<String> capturedFileContent = ArgumentCaptor.forClass(String.class);
    verify(genericValidator).validate(eq(path), capturedFileContent.capture());
    Assertions.assertThat(capturedFileContent.getValue()).contains(MODIFY_SCORE_ACTION);
}
Also used : Path(org.uberfire.backend.vfs.Path) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 67 with Path

use of org.uberfire.backend.vfs.Path in project drools-wb by kiegroup.

the class GuidedScoreCardEditorServiceImpl method create.

@Override
public Path create(final Path context, final String fileName, final ScoreCardModel content, final String comment) {
    try {
        final Package pkg = moduleService.resolvePackage(context);
        final String packageName = (pkg == null ? null : pkg.getPackageName());
        content.setPackageName(packageName);
        final org.uberfire.java.nio.file.Path nioPath = Paths.convert(context).resolve(fileName);
        final Path newPath = Paths.convert(nioPath);
        if (ioService.exists(nioPath)) {
            throw new FileAlreadyExistsException(nioPath.toString());
        }
        ioService.write(nioPath, GuidedScoreCardXMLPersistence.getInstance().marshal(content), commentedOptionFactory.makeCommentedOption(comment));
        return newPath;
    } catch (Exception e) {
        throw ExceptionUtilities.handleException(e);
    }
}
Also used : Path(org.uberfire.backend.vfs.Path) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException) Package(org.guvnor.common.services.project.model.Package) SourceGenerationFailedException(org.kie.workbench.common.services.shared.source.SourceGenerationFailedException) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException)

Example 68 with Path

use of org.uberfire.backend.vfs.Path in project drools-wb by kiegroup.

the class GuidedRuleTemplateEditorServiceImplTest method checkConstructContentPopulateProjectCollectionTypes.

@Test
public void checkConstructContentPopulateProjectCollectionTypes() {
    final Path path = mock(Path.class);
    final Overview overview = mock(Overview.class);
    final PackageDataModelOracle oracle = mock(PackageDataModelOracle.class);
    when(path.toURI()).thenReturn("default://project/src/main/resources/mypackage/rule.template");
    when(dataModelService.getDataModel(any())).thenReturn(oracle);
    when(oracle.getPackageGlobals()).thenReturn(new HashMap<String, String>() {

        {
            put("number", "java.lang.Number");
            put("collection", "java.util.Collection");
        }
    });
    when(oracle.getModuleCollectionTypes()).thenReturn(new HashMap<String, Boolean>() {

        {
            put("java.util.List", true);
            put("java.util.Set", true);
            put("java.util.Collection", true);
            put("java.util.UnknownCollection", false);
        }
    });
    final GuidedTemplateEditorContent content = service.constructContent(path, overview);
    assertEquals(3, content.getDataModel().getCollectionTypes().size());
    assertTrue(content.getDataModel().getCollectionTypes().containsKey("java.util.Collection"));
    assertTrue(content.getDataModel().getCollectionTypes().containsKey("java.util.List"));
    assertTrue(content.getDataModel().getCollectionTypes().containsKey("java.util.Set"));
}
Also used : Path(org.uberfire.backend.vfs.Path) GuidedTemplateEditorContent(org.drools.workbench.screens.guided.template.model.GuidedTemplateEditorContent) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) Overview(org.guvnor.common.services.shared.metadata.model.Overview) Test(org.junit.Test)

Example 69 with Path

use of org.uberfire.backend.vfs.Path in project drools-wb by kiegroup.

the class GuidedScoreCardEditorServiceImplTest 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 ScoreCardModel content = mock(ScoreCardModel.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) ScoreCardModel(org.drools.workbench.models.guided.scorecard.shared.ScoreCardModel) Metadata(org.guvnor.common.services.shared.metadata.model.Metadata) Test(org.junit.Test)

Example 70 with Path

use of org.uberfire.backend.vfs.Path in project drools-wb by kiegroup.

the class NewGuidedDecisionTableHandler method createEmptyDecisionTable.

private void createEmptyDecisionTable(final Path contextPath, final String baseFileName) {
    final GuidedDecisionTable52 model = new GuidedDecisionTable52();
    model.setTableFormat(options.getTableFormat());
    model.setHitPolicy(options.getHitPolicy());
    if (GuidedDecisionTable52.HitPolicy.RESOLVED_HIT.equals(options.getHitPolicy())) {
        final MetadataCol52 metadataCol52 = new MetadataCol52();
        metadataCol52.setMetadata(GuidedDecisionTable52.HitPolicy.RESOLVED_HIT_METADATA_NAME);
        model.getMetadataCols().add(metadataCol52);
    }
    model.setTableName(baseFileName);
    final RemoteCallback<Path> onSaveSuccessCallback = getSuccessCallback(newResourcePresenter);
    busyIndicatorView.showBusyIndicator(CommonConstants.INSTANCE.Saving());
    service.call((Path path) -> {
        busyIndicatorView.hideBusyIndicator();
        onSaveSuccessCallback.callback(path);
    }, new HasBusyIndicatorDefaultErrorCallback(busyIndicatorView)).create(contextPath, buildFileName(baseFileName, resourceType), model, "");
}
Also used : MetadataCol52(org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52) Path(org.uberfire.backend.vfs.Path) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) HasBusyIndicatorDefaultErrorCallback(org.uberfire.ext.widgets.common.client.callbacks.HasBusyIndicatorDefaultErrorCallback)

Aggregations

Path (org.uberfire.backend.vfs.Path)136 Test (org.junit.Test)98 Metadata (org.guvnor.common.services.shared.metadata.model.Metadata)27 Package (org.guvnor.common.services.project.model.Package)23 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)20 FileAlreadyExistsException (org.uberfire.java.nio.file.FileAlreadyExistsException)19 ArrayList (java.util.ArrayList)13 NotificationEvent (org.uberfire.workbench.events.NotificationEvent)13 CommentedOption (org.uberfire.java.nio.base.options.CommentedOption)12 GuidedDecisionTableEditorGraphModel (org.drools.workbench.screens.guided.dtable.model.GuidedDecisionTableEditorGraphModel)11 ValidationMessage (org.guvnor.common.services.shared.validation.model.ValidationMessage)10 NewResourceSuccessEvent (org.kie.workbench.common.widgets.client.handlers.NewResourceSuccessEvent)9 Mockito.anyString (org.mockito.Mockito.anyString)9 Overview (org.guvnor.common.services.shared.metadata.model.Overview)8 PackageDataModelOracle (org.kie.soup.project.datamodel.oracle.PackageDataModelOracle)8 ObservablePath (org.uberfire.backend.vfs.ObservablePath)8 List (java.util.List)7 GuidedDecisionTableEditorContent (org.drools.workbench.screens.guided.dtable.model.GuidedDecisionTableEditorContent)7 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6