Commit df206c5c authored by Romain Bioteau's avatar Romain Bioteau
Browse files

BS-9737

parent 7b73cdcf
......@@ -80,3 +80,5 @@ defaultGroovyMethodImportMissing=You may add \"import static org.codehaus.groovy
invalidDependencyAssignement=\"{0}\" dependency cannot be initialized or updated inside a groovy script expression. You have to use an Operation.
validation_OperatorConsistency=The operator \"{0}\" is not compatible with the \"{1}\" left operand.
DuplicatedFileWidgetMultipleDocumentConsistencyError=The widget cannot handle a document of type "list." Specify a single document as "initial value"..
cmisConnectorWebserviceConfigMissingUrl=Invalid CMIS connector configuration. No webservice URL found in configuration for connector {0}.
cmisConnectorAtomPubConfigMissingUrl=Invalid CMIS connector configuration. No atompub URL found in configuration for connector {0}.
\ No newline at end of file
......@@ -885,7 +885,7 @@
</target>
</constraint>
<constraint
class="org.bonitasoft.studio.validation.constraints.process.ConnectorExistenceConstraint"
class="org.bonitasoft.studio.validation.constraints.connector.ConnectorExistenceConstraint"
id="org.bonitasoft.studio.validation.constraints.connectorexistence"
isEnabledByDefault="true"
lang="Java"
......@@ -916,7 +916,7 @@
</target>
</constraint>
<constraint
class="org.bonitasoft.studio.validation.constraints.process.ConnectorDefinitionAndConfigurationInputConsistencyConstraint"
class="org.bonitasoft.studio.validation.constraints.connector.ConnectorDefinitionAndConfigurationInputConsistencyConstraint"
id="org.bonitasoft.studio.validation.constraints.connectorDefAndConfigInputConsistency"
isEnabledByDefault="true"
lang="Java"
......@@ -932,7 +932,7 @@
</target>
</constraint>
<constraint
class="org.bonitasoft.studio.validation.constraints.process.ConnectorDefinitionAndConfigurationOutputConsistencyConstraint"
class="org.bonitasoft.studio.validation.constraints.connector.ConnectorDefinitionAndConfigurationOutputConsistencyConstraint"
id="org.bonitasoft.studio.validation.constraints.connectorDefAndConfigOutputConsistency"
isEnabledByDefault="true"
lang="Java"
......@@ -995,6 +995,22 @@
class="Operation">
</target>
</constraint>
<constraint
class="org.bonitasoft.studio.validation.constraints.connector.CMISConnectorDefinitionConstraint"
id="org.bonitasoft.studio.validation.constraints.cmisConnectorConfigurationConstraint"
isEnabledByDefault="true"
lang="Java"
mode="Batch"
name="Connector definition and configuration output consistency"
severity="ERROR"
statusCode="1">
<message>
{0}
</message>
<target
class="Connector">
</target>
</constraint>
</constraints>
<package
namespaceUri="http://www.bonitasoft.org/ns/studio/process">
......
/**
* Copyright (C) 2014 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.validation.constraints.connector;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.verifyZeroInteractions;
import org.bonitasoft.studio.model.process.Connector;
import org.eclipse.emf.validation.IValidationContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
/**
* @author Romain Bioteau
*
*/
@RunWith(MockitoJUnitRunner.class)
public class CMISConnectorDefinitionConstraintTest {
private CMISConnectorDefinitionConstraint cmisConnectorDefinitionConstraint;
@Mock
private IValidationContext context;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
cmisConnectorDefinitionConstraint = new CMISConnectorDefinitionConstraint();
}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
}
@Test
public void should_performLiveValidation_return_null() throws Exception {
assertThat(cmisConnectorDefinitionConstraint.performLiveValidation(context)).isNull();
verifyZeroInteractions(context);
}
@Test
public void should_performBatchValidation() throws Exception {
}
private Connector aValidAtompubConfig() {
// final ConnectorBuilder
return null;
}
private Connector aValidWerbserviceConfig() {
return null;
}
private Connector anInvalidAtompubConfig() {
return null;
}
private Connector anInvalidWebserviceConfig() {
return null;
}
}
......@@ -14,7 +14,7 @@
* 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.validation.constraints.process;
package org.bonitasoft.studio.validation.constraints.connector;
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Matchers.any;
......@@ -44,6 +44,7 @@ import org.bonitasoft.studio.model.expression.ExpressionFactory;
import org.bonitasoft.studio.model.expression.Operation;
import org.bonitasoft.studio.model.process.Connector;
import org.bonitasoft.studio.model.process.ProcessFactory;
import org.bonitasoft.studio.validation.constraints.connector.ConnectorDefinitionAndConfigurationInputConsistencyConstraint;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.validation.IValidationContext;
......
......@@ -14,7 +14,7 @@
* 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.validation.constraints.process;
package org.bonitasoft.studio.validation.constraints.connector;
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Matchers.anyObject;
......@@ -37,6 +37,7 @@ import org.bonitasoft.studio.model.expression.ExpressionFactory;
import org.bonitasoft.studio.model.expression.Operation;
import org.bonitasoft.studio.model.process.Connector;
import org.bonitasoft.studio.model.process.ProcessFactory;
import org.bonitasoft.studio.validation.constraints.connector.ConnectorDefinitionAndConfigurationOutputConsistencyConstraint;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.validation.IValidationContext;
......
package org.bonitasoft.studio.validation.constraints.connector;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.bonitasoft.studio.model.connectorconfiguration.ConnectorConfiguration;
import org.bonitasoft.studio.model.connectorconfiguration.ConnectorParameter;
import org.bonitasoft.studio.model.expression.AbstractExpression;
import org.bonitasoft.studio.model.expression.Expression;
import org.bonitasoft.studio.model.process.Connector;
import org.bonitasoft.studio.model.process.Element;
import org.bonitasoft.studio.validation.constraints.AbstractLiveValidationMarkerConstraint;
import org.bonitasoft.studio.validation.i18n.Messages;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.validation.IValidationContext;
public class CMISConnectorDefinitionConstraint extends AbstractLiveValidationMarkerConstraint {
public static final String ID = "org.bonitasoft.studio.validation.constraints.cmisConnectorConfigurationConstraint";
private static final String ATOM_PUB = "atompub";
private static final String WEB_SERVICES = "webservices";
private static Set<String> CMIS_DEF_IDS;
static {
CMIS_DEF_IDS = new HashSet<String>();
CMIS_DEF_IDS.add("cmis-createfolder");
CMIS_DEF_IDS.add("cmis-deletefolder");
CMIS_DEF_IDS.add("cmis-deletedocument");
CMIS_DEF_IDS.add("cmis-deleteversionofdocument");
CMIS_DEF_IDS.add("cmis-downloaddocument");
CMIS_DEF_IDS.add("cmis-uploadnewdocument");
CMIS_DEF_IDS.add("cmis-uploadnewversionofdocument");
}
@Override
protected IStatus performLiveValidation(final IValidationContext context) {
return null;
}
@Override
protected IStatus performBatchValidation(final IValidationContext context) {
final Connector connector = (Connector)context.getTarget();
final ConnectorConfiguration configuration = connector.getConfiguration();
if (isCMISConnectorDefinition(connector)) {
final ConnectorParameter bindingTypeParam = getParameter("binding_type", configuration);
if (bindingTypeParam != null) {
final String type = getBindingType(bindingTypeParam);
if (ATOM_PUB.equals(type)) {
return validateAtomPubConfiguration(configuration, context);
} else if (WEB_SERVICES.equals(type)) {
return validateWebserviceConfiguration(configuration, context);
}
}
}
return context.createSuccessStatus();
}
private IStatus validateWebserviceConfiguration(final ConnectorConfiguration configuration, final IValidationContext context) {
final List<ConnectorParameter> serviceUrlParams = getAllParametersContaining("ServiceUrl", configuration);
final List<ConnectorParameter> serviceEdpointUrlParams = getAllParametersContaining("ServiceEndpointUrl", configuration);
if (serviceUrlParams.isEmpty() && serviceEdpointUrlParams.isEmpty()) {
return context.createFailureStatus(Messages.bind(Messages.cmisConnectorWebserviceConfigMissingUrl, ((Element) context.getTarget()).getName()));
}
return context.createSuccessStatus();
}
private IStatus validateAtomPubConfiguration(final ConnectorConfiguration configuration, final IValidationContext context) {
final ConnectorParameter wsObjectServiceUrlParam = getParameter("url", configuration);
if (wsObjectServiceUrlParam == null
|| wsObjectServiceUrlParam.getExpression() == null
|| ((Expression) wsObjectServiceUrlParam.getExpression()).getContent() == null
|| ((Expression) wsObjectServiceUrlParam.getExpression()).getContent().isEmpty()) {
return context.createFailureStatus(Messages.bind(Messages.cmisConnectorAtomPubConfigMissingUrl, ((Element) context.getTarget()).getName()));
}
return context.createSuccessStatus();
}
protected String getBindingType(final ConnectorParameter bindingTypeParam) {
final AbstractExpression expression = bindingTypeParam.getExpression();
if (expression instanceof Expression) {
return ((Expression) expression).getContent();
}
return null;
}
private ConnectorParameter getParameter(final String key, final ConnectorConfiguration configuration) {
for (final ConnectorParameter param : configuration.getParameters()) {
if (key.equals(param.getKey())) {
return param;
}
}
return null;
}
private List<ConnectorParameter> getAllParametersContaining(final String containing, final ConnectorConfiguration configuration) {
final List<ConnectorParameter> result = new ArrayList<ConnectorParameter>();
for (final ConnectorParameter param : configuration.getParameters()) {
if (param.getKey().contains(containing)) {
result.add(param);
}
}
return result;
}
private boolean isCMISConnectorDefinition(final Connector connector) {
final String definitionId = connector.getDefinitionId();
return CMIS_DEF_IDS.contains(definitionId);
}
@Override
protected String getConstraintId() {
return ID;
}
}
package org.bonitasoft.studio.validation.constraints.process;
package org.bonitasoft.studio.validation.constraints.connector;
import org.bonitasoft.studio.actors.repository.ActorFilterDefRepositoryStore;
import org.bonitasoft.studio.common.repository.RepositoryManager;
......
......@@ -183,6 +183,10 @@ public class Messages extends NLS {
public static String invalidDependencyAssignement;
public static String validation_OperatorConsistency;
public static String cmisConnectorAtomPubConfigMissingUrl;
public static String cmisConnectorWebserviceConfigMissingUrl;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
......
Supports Markdown
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