Commit c0b7e570 authored by Bonita CI's avatar Bonita CI
Browse files

Merge branch 'R2D2-7.2' into 'master'

parents 4ee98f66 4214020b
......@@ -89,7 +89,7 @@ numeric=Numeric (java.util.Long)
queryLink=JPQL Query * <a>?</a>
jpqlParametersHint=Define parameters used in the above query
emptyQueryError=JPQL Query cannot be empty
queryNameReserved={0} is a reserved query name (query generated from unique constraint)
queryNameReserved={0} is a reserved query name (query generated in default queries)
queryExpressionLabel=Query
queryContent=Query content
value=Value
......@@ -105,7 +105,7 @@ installFailedTitle=Deploy failed
installFailedMessage=An error occurred while deploying the Business Data Model in engine
defaultQueriesOption=Default
customQueriesOption=Custom
defaultQueriesHint=3 default types of queries to select Business Objects: based on unique constraints, which returns\nsingle results, based on simple attributes (with equals criterion) which returns multiple\nresults, and a Select All, which returns all Business Data on the Business Object.
defaultQueriesHint=4 default types of queries to select Business Objects: based on unique constraints, which returns\nsingle results, based on simple attributes (with equals criterion) which returns multiple and their associated countFor queries\nresults, and a Select All, which returns all Business Data on the Business Object.
providedQuery=Provided query
providedQueryDescription=Display the content of this provided query
queryParameterNameReservedForPagination={0} is a reserved keyword for pagination
......
......@@ -16,6 +16,9 @@
*/
package org.bonitasoft.studio.businessobject.ui.wizard.validator;
import org.bonitasoft.engine.bdm.BDMQueryUtil;
import org.bonitasoft.engine.bdm.model.BusinessObject;
import org.bonitasoft.engine.bdm.model.Query;
import org.bonitasoft.studio.businessobject.i18n.Messages;
import org.bonitasoft.studio.common.jface.databinding.validator.InputLengthValidator;
import org.eclipse.core.databinding.validation.IValidator;
......@@ -25,10 +28,6 @@ import org.eclipse.jdt.core.JavaConventions;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jface.viewers.ICellEditorValidator;
import org.bonitasoft.engine.bdm.BDMQueryUtil;
import org.bonitasoft.engine.bdm.model.BusinessObject;
import org.bonitasoft.engine.bdm.model.Query;
/**
* @author Romain Bioteau
*
......@@ -37,9 +36,9 @@ public class QueryNameCellEditorValidator implements ICellEditorValidator, IVali
public static final int MAX_QUERY_NAME_LENGTH = 150;
private BusinessObject bo;
private final BusinessObject bo;
private Query query;
private final Query query;
public QueryNameCellEditorValidator(BusinessObject bo, Query query) {
this.bo = bo;
......@@ -52,7 +51,7 @@ public class QueryNameCellEditorValidator implements ICellEditorValidator, IVali
*/
@Override
public String isValid(Object value) {
IStatus status = doValidate(value);
final IStatus status = doValidate(value);
if (!status.isOK()) {
return status.getMessage();
}
......@@ -73,12 +72,12 @@ public class QueryNameCellEditorValidator implements ICellEditorValidator, IVali
if (!status.isOK()) {
return status;
}
for (String queryName : BDMQueryUtil.getAllProvidedQueriesNameForBusinessObject(bo)) {
for (final String queryName : BDMQueryUtil.getAllProvidedQueriesNameForBusinessObject(bo)) {
if (name.equalsIgnoreCase(queryName)) {
return ValidationStatus.error(Messages.bind(Messages.queryNameReserved, name));
}
}
for (Query query : bo.getQueries()) {
for (final Query query : bo.getQueries()) {
if (query.getName().equalsIgnoreCase(name) && !this.query.equals(query)) {
return ValidationStatus.error(Messages.queryNameAlreadyExists);
}
......
......@@ -119,3 +119,4 @@ nameUnicityConstraintParameter=parameter
nameUnicityConstraintContractInput=contract input
nameUnicityConstraintVariable=variable
formMappingAtDiagramLevel_ModelInconsistency=A form mapping exists at diagram level where there should not be one. Please report a bug explaining the actions you took when modeling the diagram to reach this inconsistent state.
conflictingQueryNamesInBusinessObject={1} query name in {0} of the Business Object Model is conflicting with a default query.
\ No newline at end of file
......@@ -1125,6 +1125,22 @@
class="Activity:http://www.bonitasoft.org/ns/studio/process">
</target>
</constraint>
<constraint
class="org.bonitasoft.studio.validation.constraints.process.QueryNameValidationConstraint"
id="org.bonitasoft.studio.validation.constraint.businessobject.checkQueryName"
isEnabledByDefault="true"
lang="Java"
mode="Batch"
name="BDM Query name conflict"
severity="ERROR"
statusCode="1">
<message>
{0}
</message>
<target
class="MainProcess:http://www.bonitasoft.org/ns/studio/process">
</target>
</constraint>
</constraints>
<package
namespaceUri="http://www.bonitasoft.org/ns/studio/process">
......
/**
* Copyright (C) 2015 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.process;
import static com.google.common.collect.Lists.newArrayList;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.List;
import org.bonitasoft.engine.bdm.model.BusinessObject;
import org.bonitasoft.engine.bdm.model.Query;
import org.bonitasoft.studio.assertions.StatusAssert;
import org.bonitasoft.studio.businessobject.core.repository.BusinessObjectModelFileStore;
import org.bonitasoft.studio.model.businessObject.BusinessObjectBuilder;
import org.bonitasoft.studio.model.businessObject.FieldBuilder;
import org.bonitasoft.studio.validation.i18n.Messages;
import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.validation.IValidationContext;
import org.eclipse.osgi.util.NLS;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.runners.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class QueryNameValidationConstraintTest {
@Spy
private QueryNameValidationConstraint constraint;
@Mock
private IValidationContext context;
@Before
public void setUp() throws Exception {
when(context.createSuccessStatus()).thenReturn(ValidationStatus.ok());
when(context.createFailureStatus(any())).thenReturn(ValidationStatus.error("error"));
}
@Test
public void should_fail_if_query_name_is_conflicting() throws Exception {
doReturn(aBusinessObjectModelFileStoreWithBo(aBoWithConflictingQueryNames())).when(constraint).getCurrentBDM();
final IStatus status = constraint.performBatchValidation(context);
verify(context).createFailureStatus(NLS.bind(Messages.conflictingQueryNamesInBusinessObject, "Employee", "findByName"));
StatusAssert.assertThat(status).isNotOK();
}
@Test
public void should_not_fail_if_no_query_name_is_conflicting() throws Exception {
doReturn(aBusinessObjectModelFileStoreWithBo(aBoWithoutConflictingQueryNames())).when(constraint).getCurrentBDM();
final IStatus status = constraint.performBatchValidation(context);
verify(context, never()).createFailureStatus(any());
StatusAssert.assertThat(status).isOK();
}
private BusinessObject aBoWithConflictingQueryNames() {
return new BusinessObjectBuilder("Employee")
.withField(FieldBuilder.aStringField("name").build())
.withQuery(new Query("findByName", "", List.class.getName()))
.build();
}
private BusinessObject aBoWithoutConflictingQueryNames() {
return new BusinessObjectBuilder("Employee")
.withField(FieldBuilder.aStringField("name").build())
.withQuery(new Query("myFindByName", "", List.class.getName()))
.build();
}
private BusinessObjectModelFileStore aBusinessObjectModelFileStoreWithBo(BusinessObject... businessObjects) {
final BusinessObjectModelFileStore fStore = mock(BusinessObjectModelFileStore.class);
when(fStore.getBusinessObjects()).thenReturn(newArrayList(businessObjects));
return fStore;
}
}
/**
* Copyright (C) 2015 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.process;
import org.bonitasoft.engine.bdm.BDMQueryUtil;
import org.bonitasoft.engine.bdm.model.BusinessObject;
import org.bonitasoft.engine.bdm.model.Query;
import org.bonitasoft.studio.businessobject.core.repository.BusinessObjectModelFileStore;
import org.bonitasoft.studio.businessobject.core.repository.BusinessObjectModelRepositoryStore;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.validation.ValidationPlugin;
import org.bonitasoft.studio.validation.constraints.AbstractLiveValidationMarkerConstraint;
import org.bonitasoft.studio.validation.i18n.Messages;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.emf.validation.IValidationContext;
import org.eclipse.osgi.util.NLS;
import com.google.common.base.Objects;
public class QueryNameValidationConstraint extends AbstractLiveValidationMarkerConstraint {
public static final String ID = "org.bonitasoft.studio.validation.constraint.businessobject.checkQueryName";
@Override
protected IStatus performBatchValidation(final IValidationContext context) {
final BusinessObjectModelFileStore modelFileStore = getCurrentBDM();
final MultiStatus multiStatus = new MultiStatus(ValidationPlugin.PLUGIN_ID, 0, null, null);
if (modelFileStore != null) {
for (final BusinessObject bo : modelFileStore.getBusinessObjects()) {
for (final Query q : BDMQueryUtil.createProvidedQueriesForBusinessObject(bo)) {
for (final Query customQuery : bo.getQueries()) {
if (Objects.equal(customQuery.getName().toLowerCase(), q.getName().toLowerCase())) {
multiStatus.add(
context.createFailureStatus(NLS.bind(Messages.conflictingQueryNamesInBusinessObject, bo.getSimpleName(), q.getName())));
}
}
}
}
return multiStatus;
}
return context.createSuccessStatus();
}
protected BusinessObjectModelFileStore getCurrentBDM() {
final BusinessObjectModelRepositoryStore businessObjectModelRepositoryStore = getBusinessObjectDefinitionStore();
return businessObjectModelRepositoryStore.getChild(BusinessObjectModelFileStore.DEFAULT_BDM_FILENAME);
}
protected BusinessObjectModelRepositoryStore getBusinessObjectDefinitionStore() {
return RepositoryManager.getInstance().getRepositoryStore(BusinessObjectModelRepositoryStore.class);
}
@Override
protected String getConstraintId() {
return ID;
}
}
......@@ -232,6 +232,7 @@ public class Messages extends NLS {
public static String nameUnicityConstraintVariable;
public static String formMappingAtDiagramLevel_ModelInconsistency;
public static String instantiationFormMapping;
public static String conflictingQueryNamesInBusinessObject;
static {
// initialize resource bundle
......
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