use of org.guvnor.common.services.project.model.Package in project drools-wb by kiegroup.
the class NewDecisionTableXLSHandlerTest method testSuccessMultiByteProjectNameAndFileName.
@Test
public void testSuccessMultiByteProjectNameAndFileName() {
final String fileName = "あああ";
final Package pkg = mock(Package.class);
final Path resourcesPath = PathFactory.newPath("resources", "default://" + encode("ああ") + "/src/main/resources");
when(pkg.getPackageMainResourcesPath()).thenReturn(resourcesPath);
handler.create(pkg, fileName, newResourcePresenter);
verify(uploadWidget, times(1)).submit(eq(resourcesPath), eq(fileName + "." + decisionTableXLSResourceType.getSuffix()), any(String.class), successCmdCaptor.capture(), failureCmdCaptor.capture());
successCmdCaptor.getValue().execute();
verify(busyIndicatorView, times(1)).hideBusyIndicator();
verify(newResourcePresenter, times(1)).complete();
verify(mockNotificationEvent, times(1)).fire(any(NotificationEvent.class));
verify(placeManager, times(1)).goTo(newPathCaptor.capture());
assertEquals("default://%E3%81%82%E3%81%82/src/main/resources/%E3%81%82%E3%81%82%E3%81%82.xls", newPathCaptor.getValue().toURI());
}
use of org.guvnor.common.services.project.model.Package in project drools-wb by kiegroup.
the class NewDecisionTableXLSHandlerTest method testSuccessMultiByteProjectName.
@Test
public void testSuccessMultiByteProjectName() {
final String fileName = "fileName";
final Package pkg = mock(Package.class);
final Path resourcesPath = PathFactory.newPath("resources", "default://あああ/src/main/resources");
when(pkg.getPackageMainResourcesPath()).thenReturn(resourcesPath);
handler.create(pkg, fileName, newResourcePresenter);
verify(uploadWidget, times(1)).submit(eq(resourcesPath), eq(fileName + "." + decisionTableXLSResourceType.getSuffix()), any(String.class), successCmdCaptor.capture(), failureCmdCaptor.capture());
successCmdCaptor.getValue().execute();
verify(busyIndicatorView, times(1)).hideBusyIndicator();
verify(newResourcePresenter, times(1)).complete();
verify(mockNotificationEvent, times(1)).fire(any(NotificationEvent.class));
verify(placeManager, times(1)).goTo(newPathCaptor.capture());
assertEquals("default://あああ/src/main/resources/fileName.xls", newPathCaptor.getValue().toURI());
}
use of org.guvnor.common.services.project.model.Package in project drools-wb by kiegroup.
the class GlobalsEditorServiceImpl method createInternal.
private Path createInternal(final Path context, final String fileName, final GlobalsModel content, final String comment, final boolean generate) {
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());
}
if (generate) {
Metadata metadata = MetadataBuilder.newMetadata().withGenerated(true).build();
ioService.write(nioPath, GlobalsPersistence.getInstance().marshal(content), metadataService.configAttrs(new HashMap<>(), metadata), commentedOptionFactory.makeCommentedOption(comment));
} else {
ioService.write(nioPath, GlobalsPersistence.getInstance().marshal(content), commentedOptionFactory.makeCommentedOption(comment));
}
return newPath;
} catch (Exception e) {
throw ExceptionUtilities.handleException(e);
}
}
use of org.guvnor.common.services.project.model.Package in project drools-wb by kiegroup.
the class DRLTextEditorServiceImpl method assertPackageName.
// Check if the DRL contains a Package declaration, appending one if it does not exist
@Override
public String assertPackageName(final String drl, final Path resource) {
try {
final String existingPackageName = PackageNameParser.parsePackageName(drl);
if (!"".equals(existingPackageName)) {
return drl;
}
final Package pkg = moduleService.resolvePackage(resource);
final String requiredPackageName = (pkg == null ? null : pkg.getPackageName());
final HasPackageName mockHasPackageName = new HasPackageName() {
@Override
public String getPackageName() {
return requiredPackageName;
}
@Override
public void setPackageName(final String packageName) {
// Nothing to do here
}
};
final StringBuilder sb = new StringBuilder();
PackageNameWriter.write(sb, mockHasPackageName);
sb.append(drl);
return sb.toString();
} catch (Exception e) {
throw ExceptionUtilities.handleException(e);
}
}
use of org.guvnor.common.services.project.model.Package in project drools-wb by kiegroup.
the class DslFileIndexer method getIndexBuilder.
@Override
protected DefaultIndexBuilder getIndexBuilder(Path path) {
final Module module = moduleService.resolveModule(Paths.convert(path));
if (module == null) {
logger.error("Unable to index " + path.toUri().toString() + ": module could not be resolved.");
return null;
}
final Package pkg = moduleService.resolvePackage(Paths.convert(path));
if (pkg == null) {
logger.error("Unable to index " + path.toUri().toString() + ": package could not be resolved.");
return null;
}
// responsible for basic index info: module name, branch, etc
return new DefaultIndexBuilder(Paths.convert(path).getFileName(), module, pkg) {
@Override
public DefaultIndexBuilder addGenerator(final IndexElementsGenerator generator) {
// Don't include the rule created to parse DSL
if (generator instanceof Resource && ((Resource) generator).getResourceFQN().endsWith(MOCK_RULE_NAME)) {
return this;
}
return super.addGenerator(generator);
}
};
}
Aggregations