Commit 660c7b42 authored by Romain Bioteau's avatar Romain Bioteau
Browse files

feat(accessControl) localize validation messages

Closes BS-17371
parent 9aa59b93
......@@ -97,17 +97,21 @@ public class ContractInputCompletionProposalComputerTest {
contract.getInputs().add(employeeInput);
contract.getInputs().add(buildInput(null, "days", ContractInputType.TEXT, true));
doReturn(contract.getInputs()).when(proposalComputer).getContractInputs(context);
doReturn(contentAssistContext).when(proposalComputer).createContentAssistContext(any(GroovyCompilationUnit.class), anyInt(), any(Document.class));
doReturn(ContractInputCompletionProposalComputerTest.class.getClassLoader()).when(proposalComputer).getProjectClassloader(monitor);
doReturn(contentAssistContext).when(proposalComputer).createContentAssistContext(any(GroovyCompilationUnit.class),
anyInt(), any(Document.class));
doReturn(ContractInputCompletionProposalComputerTest.class.getClassLoader()).when(proposalComputer)
.getProjectClassloader(monitor);
doReturn(methodProposalCreator).when(proposalComputer).createMethodProposalCreator();
doReturn(moduleNode).when(proposalComputer).getModuleNode(contentAssistContext);
when(context.computeIdentifierPrefix()).thenReturn("");
when(contentAssistContext.getPerceivedCompletionNode()).thenReturn(new VariableExpression(""));
when(context.getCompilationUnit()).thenReturn(groovyCompilationUnit);
when(groovyCompilationUnit.getModuleNode()).thenReturn(moduleNode);
}
@Test
public void should_computeCompletionProposals_return_emptyList_if_context_is_not_a_JavaContentAssistInvocationContext() throws Exception {
public void should_computeCompletionProposals_return_emptyList_if_context_is_not_a_JavaContentAssistInvocationContext()
throws Exception {
assertThat(proposalComputer.computeCompletionProposals(null, monitor)).isEmpty();
}
......@@ -148,7 +152,8 @@ public class ContractInputCompletionProposalComputerTest {
public void should_computeCompletionProposals_returns_complex_input_children() throws Exception {
when(contentAssistContext.getPerceivedCompletionNode()).thenReturn(new VariableExpression("employee"));
final List<ICompletionProposal> proposals = proposalComputer.computeCompletionProposals(context, monitor);
assertThat(proposals).extracting("displayString").contains("firstName -- TEXT", "lastName -- TEXT", "skills -- TEXT");
assertThat(proposals).extracting("displayString").contains("firstName -- TEXT", "lastName -- TEXT",
"skills -- TEXT");
}
@Test
......@@ -159,23 +164,30 @@ public class ContractInputCompletionProposalComputerTest {
}
@Test
public void should_computeCompletionProposals_returns_complex_and_multiple_input_children_for_variable_expression() throws Exception {
public void should_computeCompletionProposals_returns_complex_and_multiple_input_children_for_variable_expression()
throws Exception {
final BinaryExpression binaryExpression = new BinaryExpression(new VariableExpression("employee"), null, null);
when(contentAssistContext.getPerceivedCompletionNode()).thenReturn(binaryExpression);
assertThat(proposalComputer.computeCompletionProposals(context, monitor)).extracting("displayString").contains("firstName -- TEXT", "lastName -- TEXT",
assertThat(proposalComputer.computeCompletionProposals(context, monitor)).extracting("displayString").contains(
"firstName -- TEXT", "lastName -- TEXT",
"skills -- TEXT");
}
@Test
public void should_computeCompletionProposals_returns_complex_and_multiple_input_children_for_property_expression() throws Exception {
final BinaryExpression binaryExpression = new BinaryExpression(new PropertyExpression(new ConstantExpression("employee"), new ConstantExpression(
"employee")), null, null);
public void should_computeCompletionProposals_returns_complex_and_multiple_input_children_for_property_expression()
throws Exception {
final BinaryExpression binaryExpression = new BinaryExpression(
new PropertyExpression(new ConstantExpression("employee"), new ConstantExpression(
"employee")),
null, null);
when(contentAssistContext.getPerceivedCompletionNode()).thenReturn(binaryExpression);
assertThat(proposalComputer.computeCompletionProposals(context, monitor)).extracting("displayString").contains("firstName -- TEXT", "lastName -- TEXT",
assertThat(proposalComputer.computeCompletionProposals(context, monitor)).extracting("displayString").contains(
"firstName -- TEXT", "lastName -- TEXT",
"skills -- TEXT");
}
private ContractInput buildInput(final ContractInput parent, final String name, final ContractInputType type, final boolean multiple) {
private ContractInput buildInput(final ContractInput parent, final String name, final ContractInputType type,
final boolean multiple) {
final ContractInput input = ProcessFactory.eINSTANCE.createContractInput();
input.setName(name);
input.setType(type);
......
......@@ -58,16 +58,19 @@ public class ContractInputCompletionProposalComputer extends GroovyCompletionPro
.getCompilationUnit() instanceof GroovyCompilationUnit)) {
return Collections.emptyList();
}
final List<ContractInput> inputs = getContractInputs(context);
if (inputs.isEmpty()) {
return java.util.Collections.emptyList();
}
final JavaContentAssistInvocationContext javaContext = (JavaContentAssistInvocationContext) context;
GroovyCompilationUnit compilationUnit = (GroovyCompilationUnit) javaContext.getCompilationUnit();
if (compilationUnit.getModuleNode() == null) {
return Collections.emptyList();
}
final ContentAssistContext contentAssistContext = createContentAssistContext(
compilationUnit,
context.getInvocationOffset(), context.getDocument());
final List<ContractInput> inputs = getContractInputs(context);
if (inputs.isEmpty()) {
return java.util.Collections.emptyList();
}
CharSequence computeIdentifierPrefix = "";
try {
computeIdentifierPrefix = javaContext.computeIdentifierPrefix();
......
/**
* Copyright (C) 2017 Bonitasoft S.A.
* Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.ui.dialog;
import java.util.function.Function;
import org.bonitasoft.engine.api.result.Status;
public class Defaultl10nStatusFunction implements Function<Status, String> {
/*
* (non-Javadoc)
* @see java.util.function.Function#apply(java.lang.Object)
*/
@Override
public String apply(Status status) {
//No l10n, use technical message.
return status.getMessage();
}
}
......@@ -22,9 +22,10 @@ import org.eclipse.core.runtime.Status;
public class EngineStatusMapper implements Function<org.bonitasoft.engine.api.result.Status, Status> {
private static EngineStatusMapper INSTANCE;
private Function<org.bonitasoft.engine.api.result.Status, String> l10nFunction;
private EngineStatusMapper() {
private EngineStatusMapper(Function<org.bonitasoft.engine.api.result.Status, String> l10nFunction) {
this.l10nFunction = l10nFunction;
}
/*
......@@ -37,13 +38,7 @@ public class EngineStatusMapper implements Function<org.bonitasoft.engine.api.re
}
private String l10n(org.bonitasoft.engine.api.result.Status engineStatus) {
switch (engineStatus.getCode()) {
case OK:
default:
break;
}
//No l10n, use technical message.
return engineStatus.getMessage();
return l10nFunction.apply(engineStatus);
}
private int levelToSeverity(org.bonitasoft.engine.api.result.Status engineStatus) {
......@@ -59,11 +54,9 @@ public class EngineStatusMapper implements Function<org.bonitasoft.engine.api.re
}
}
public static Function<org.bonitasoft.engine.api.result.Status, Status> instance() {
if (INSTANCE == null) {
INSTANCE = new EngineStatusMapper();
}
return INSTANCE;
public static Function<org.bonitasoft.engine.api.result.Status, Status> instance(
Function<org.bonitasoft.engine.api.result.Status, String> l10nFunction) {
return new EngineStatusMapper(l10nFunction);
}
}
......@@ -15,6 +15,7 @@
package org.bonitasoft.studio.ui.dialog;
import java.util.Collection;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
......@@ -23,20 +24,50 @@ import org.bonitasoft.studio.common.jface.dialog.TypedLabelProvider;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
public class MultiStatusDialog extends ProblemsDialog<IStatus> {
private MultiStatus status;
private Predicate<IStatus> canFinish;
public MultiStatusDialog(Shell parentShell, String dialogTitle, String dialogMessage, int dialogImageType,
String[] dialogButtonLabels, MultiStatus status) {
public MultiStatusDialog(Shell parentShell, String dialogTitle,
String dialogMessage,
int dialogImageType,
String[] dialogButtonLabels,
MultiStatus status) {
super(parentShell, dialogTitle, dialogMessage, dialogImageType, dialogButtonLabels);
this.status = status;
}
public MultiStatusDialog(Shell parentShell, String dialogTitle,
String dialogMessage,
int dialogImageType,
String[] dialogButtonLabels,
MultiStatus status,
Predicate<IStatus> canFinish) {
super(parentShell, dialogTitle, dialogMessage, dialogImageType, dialogButtonLabels);
this.status = status;
this.canFinish = canFinish;
}
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.MessageDialog#createButton(org.eclipse.swt.widgets.Composite, int, java.lang.String, boolean)
*/
@Override
protected Button createButton(Composite parent, int id, String label, boolean defaultButton) {
Button button = super.createButton(parent, id, label, defaultButton);
if(IDialogConstants.OK_ID == id && canFinish != null) {
button.setEnabled(canFinish.test(status));
}
return button;
}
public MultiStatusDialog(Shell shell, String dialogTitle, String deployStatusMessage, String[] dialogButtonLabels,
MultiStatus status) {
......@@ -54,7 +85,7 @@ public class MultiStatusDialog extends ProblemsDialog<IStatus> {
return MessageDialog.INFORMATION;
}
}
/*
* (non-Javadoc)
* @see org.bonitasoft.studio.common.jface.dialog.ProblemsDialog#getTypedLabelProvider()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment