Commit 6798be39 authored by Adrien's avatar Adrien Committed by Romain Bioteau

Feat/bs 18181 translate bdm errors (#1100)


closes [BS-18181](https://bonitasoft.atlassian.net/browse/BS-18181)
parent 20625ecd
......@@ -69,6 +69,7 @@ Require-Bundle: org.bonitasoft.studio.engine;bundle-version="1.0.0",
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Import-Package: org.bonitasoft.engine.api,
org.bonitasoft.engine.api.result,
org.bonitasoft.engine.bdm,
org.bonitasoft.engine.bdm.dao,
org.bonitasoft.engine.bdm.model,
......
......@@ -168,4 +168,32 @@ dateTimeInTimezoneDetails=%s is used to hold a date-time that will take the user
fieldNameShouldStartsWithLowercase=Attribute name should starts with a lower case, else it might leads to some errors.
generatingJarFromBDMModel=Generating jar from Business Data Model...
deployBDMJobName=Deploy Business Data Model
continueDeploy=Continue
\ No newline at end of file
continueDeploy=Continue
duplicateConstraintOrIndexName=There are at least two %s with the same name : %s"
emptyBdm=Business object model must have at least one business object declared
duplicateQueryName=The query '%s' already exists for the business object '%s'
businessObjectWithoutName=A Business Object must have a qualified name
reservedPackageName=Package %s is reserved. Please choose another package name
invalidJavaIdentifier=%s is not a valid Java qualified name
invalidCharacterInBusinessObjectName=%s is a forbidden character in business object's name
businessObjectWithoutField=The business object '%s' must have at least one field declared
duplicateConstraintName=The constraint '%s' already exists for the business object '%s'
unknownFieldInConstraint=The field '%s' does not exist in the business object '%s'
invalidFieldIdentifier='%s' is not a valid field identifier
indexWithoutName=An index must have name
invalidSqlIdentifier='%s' is not a valid SQL identifier
indexWithoutField=The index '%s' must have at least one field declared
queryParameterWithoutName=A query parameter must have name
forbiddenQueryParameterName=%s is a reserved parameter name. Use a name different from: %s
queryParameterWithoutClassName=%s query parameter must have a classname
queryWithoutName=A query must have name
queryNameLengthToHigh='%s' length must be lower than 150 characters
queryWithoutContent=The query '%s' must have a content defined
queryWithoutReturntype=The query '%s' must have a return type defined
fieldWithoutName=The field '%s' must have a type declared
constraintWithoutName=A unique constraint must have name
constraintWithoutField=The unique constraint '%s' must have at least one field declared
boUsedInCompositionAndAggregation=The object '%s' is referenced both in composition and in aggregation. This may lead to runtime errors and may lead to unpredictable behavior of the AccessControl configuration
circularCompositionReference=The business object '%s' has a circular composition reference to itself or is referenced several times in the object '%s'
severalCompositionReferenceForABusinessObject=The business object '%s' is referenced by composition in two business objects, or is referenced several times in a single business object
multipleAggregationToItself=The object '%s' is referencing itself in a multiple aggregation relation
\ No newline at end of file
/**
* Copyright (C) 2018 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.businessobject.core.status;
import java.util.Arrays;
import java.util.List;
import org.bonitasoft.engine.api.result.Status;
import org.bonitasoft.engine.api.result.StatusContext;
import org.bonitasoft.engine.bdm.BDMQueryUtil;
import org.bonitasoft.studio.businessobject.i18n.Messages;
import org.bonitasoft.studio.ui.dialog.EngineStatusMapper;
public class BusinessDataModelStatusMapper extends EngineStatusMapper {
private static BusinessDataModelStatusMapper INSTANCE;
private static final List<String> FORBIDDEN_PARAMETER_NAMES = Arrays.asList(BDMQueryUtil.START_INDEX_PARAM_NAME,
BDMQueryUtil.MAX_RESULTS_PARAM_NAME);
public static BusinessDataModelStatusMapper instance() {
if (INSTANCE == null) {
INSTANCE = new BusinessDataModelStatusMapper();
}
return INSTANCE;
}
@Override
public String localizedMessage(Status status) {
StatusContext context = status.getContext();
switch (status.getCode()) {
case DUPLICATE_CONSTRAINT_OR_INDEX_NAME:
return String.format(Messages.duplicateConstraintOrIndexName,
context.get(StatusContext.BDM_ARTIFACT_KEY),
context.get(StatusContext.BDM_ARTIFACT_NAME_KEY));
case UNIQUE_CONSTRAINT_WITHOUT_NAME:
return Messages.constraintWithoutName;
case INVALID_SQL_IDENTIFIER_NAME:
String sqlInvalidName = (String) context.get(StatusContext.BDM_ARTIFACT_NAME_KEY);
if (sqlInvalidName == null) {
sqlInvalidName = (String) context.get(StatusContext.INVALID_NAME_KEY);
}
return String.format(Messages.invalidSqlIdentifier, sqlInvalidName);
case UNIQUE_CONSTRAINT_WITHOUT_FIELD:
return String.format(Messages.constraintWithoutField, context.get(StatusContext.BDM_ARTIFACT_NAME_KEY));
case FIELD_WITHOUT_NAME:
return String.format(Messages.fieldWithoutName, context.get(StatusContext.BDM_ARTIFACT_NAME_KEY));
case QUERY_WITHOUT_NAME:
return Messages.queryWithoutName;
case INVALID_JAVA_IDENTIFIER_NAME:
String javaInvalidname = (String) context.get(StatusContext.BUSINESS_OBJECT_NAME_KEY);
if (javaInvalidname == null) {
javaInvalidname = (String) context.get(StatusContext.BDM_ARTIFACT_NAME_KEY);
}
return String.format(Messages.invalidJavaIdentifier, javaInvalidname);
case QUERY_NAME_LENGTH_TO_HIGH:
return String.format(Messages.queryNameLengthToHigh, context.get(StatusContext.BDM_ARTIFACT_NAME_KEY));
case QUERY_WITHOUT_CONTENT:
return String.format(Messages.queryWithoutContent, context.get(StatusContext.BDM_ARTIFACT_NAME_KEY));
case QUERY_WITHOUT_RETURN_TYPE:
return String.format(Messages.queryWithoutReturntype, context.get(StatusContext.BDM_ARTIFACT_NAME_KEY));
case QUERY_PARAMETER_WITHOUT_NAME:
return Messages.queryParameterWithoutName;
case FORBIDDEN_QUERY_PARAMETER_NAME:
return String.format(Messages.forbiddenQueryParameterName, context.get(StatusContext.BDM_ARTIFACT_NAME_KEY),
FORBIDDEN_PARAMETER_NAMES);
case QUERY_PARAMETER_WITHOUT_CLASS_NAME:
return String.format(Messages.queryParameterWithoutClassName,
context.get(StatusContext.BDM_ARTIFACT_NAME_KEY));
case INDEX_WITHOUT_NAME:
return Messages.indexWithoutName;
case INDEX_WITHOUT_FIELD:
return String.format(Messages.indexWithoutField, context.get(StatusContext.BDM_ARTIFACT_NAME_KEY));
case INVALID_FIELD_IDENTIFIER:
return String.format(Messages.invalidFieldIdentifier, context.get(StatusContext.BDM_ARTIFACT_NAME_KEY));
case BUSINESS_OBJECT_WITHOUT_NAME:
return Messages.businessObjectWithoutName;
case RESERVED_PACKAGE_NAME:
return String.format(Messages.reservedPackageName, context.get(StatusContext.BDM_ARTIFACT_NAME_KEY));
case INVALID_CHARACTER_IN_BUSINESS_OBJECT_NAME:
return String.format(Messages.invalidCharacterInBusinessObjectName, "_");
case BUSINESS_OBJECT_WITHOUT_FIELD:
return String.format(Messages.businessObjectWithoutField,
context.get(StatusContext.BUSINESS_OBJECT_NAME_KEY));
case DUPLICATE_QUERY_NAME:
return String.format(Messages.duplicateQueryName,
context.get(StatusContext.BDM_ARTIFACT_NAME_KEY),
context.get(StatusContext.BUSINESS_OBJECT_NAME_KEY));
case DUPLICATE_CONSTRAINT_NAME:
return String.format(Messages.duplicateConstraintName,
context.get(StatusContext.BDM_ARTIFACT_NAME_KEY),
context.get(StatusContext.BUSINESS_OBJECT_NAME_KEY));
case UNKNOWN_FIELD_IN_CONSTRAINT:
return String.format(Messages.unknownFieldInConstraint,
context.get(StatusContext.BDM_ARTIFACT_NAME_KEY),
context.get(StatusContext.BUSINESS_OBJECT_NAME_KEY));
case EMPTY_BDM:
return Messages.emptyBdm;
case SEVERAL_COMPOSITION_REFERENCE_FOR_A_BUSINESS_OBJECT:
return String.format(Messages.severalCompositionReferenceForABusinessObject,
context.get(StatusContext.BUSINESS_OBJECT_NAME_KEY));
case CIRCULAR_COMPOSITION_REFERENCE:
return String.format(Messages.circularCompositionReference,
context.get(StatusContext.BUSINESS_OBJECT_NAME_KEY),
context.get(StatusContext.BDM_ARTIFACT_NAME_KEY));
case BUSINESS_OBJECT_USED_IN_COMPOSITION_AND_AGGREGATION:
return String.format(Messages.boUsedInCompositionAndAggregation,
context.get(StatusContext.BUSINESS_OBJECT_NAME_KEY));
case MULTIPLE_AGGREGATION_RELATION_TO_ITSELF:
return String.format(Messages.multipleAggregationToItself,
context.get(StatusContext.BUSINESS_OBJECT_NAME_KEY));
default:
return super.localizedMessage(status);
}
}
}
......@@ -345,6 +345,35 @@ public class Messages extends NLS {
public static String continueDeploy;
public static String duplicateConstraintOrIndexName;
public static String emptyBdm;
public static String duplicateQueryName;
public static String businessObjectWithoutName;
public static String reservedPackageName;
public static String invalidJavaIdentifier;
public static String invalidCharacterInBusinessObjectName;
public static String businessObjectWithoutField;
public static String duplicateConstraintName;
public static String unknownFieldInConstraint;
public static String invalidFieldIdentifier;
public static String indexWithoutName;
public static String invalidSqlIdentifier;
public static String indexWithoutField;
public static String queryParameterWithoutName;
public static String forbiddenQueryParameterName;
public static String queryParameterWithoutClassName;
public static String queryWithoutName;
public static String queryNameLengthToHigh;
public static String queryWithoutContent;
public static String queryWithoutReturntype;
public static String fieldWithoutName;
public static String constraintWithoutName;
public static String constraintWithoutField;
public static String boUsedInCompositionAndAggregation;
public static String circularCompositionReference;
public static String severalCompositionReferenceForABusinessObject;
public static String multipleAggregationToItself;
private Messages() {
}
......
......@@ -16,6 +16,7 @@ package org.bonitasoft.studio.businessobject.ui.wizard;
import java.lang.reflect.InvocationTargetException;
import org.bonitasoft.engine.api.result.Status;
import org.bonitasoft.engine.bdm.model.BusinessObject;
import org.bonitasoft.engine.bdm.model.BusinessObjectModel;
import org.bonitasoft.engine.bdm.model.Index;
......@@ -29,6 +30,7 @@ import org.bonitasoft.studio.businessobject.core.operation.DeployBDMOperation;
import org.bonitasoft.studio.businessobject.core.operation.DeployBDMStackTraceResolver;
import org.bonitasoft.studio.businessobject.core.operation.GenerateBDMOperation;
import org.bonitasoft.studio.businessobject.core.repository.BusinessObjectModelFileStore;
import org.bonitasoft.studio.businessobject.core.status.BusinessDataModelStatusMapper;
import org.bonitasoft.studio.businessobject.i18n.Messages;
import org.bonitasoft.studio.common.jface.BonitaErrorDialog;
import org.bonitasoft.studio.common.jface.MessageDialogWithPrompt;
......@@ -130,16 +132,20 @@ public class ManageBusinessDataModelWizard extends Wizard {
} else {
monitor.beginTask(Messages.validatingBDM, IProgressMonitor.UNKNOWN);
ValidationStatus validate = new BusinessObjectModelValidator().validate(businessObjectModel);
if (!(validate.getErrors().isEmpty() && validate.getWarnings().isEmpty())) {
validate.getStatuses().stream().map(Status::getMessage).forEach(System.out::println);
if (!validate.getStatuses().isEmpty()) {
MultiStatus status = new MultiStatus(BusinessObjectPlugin.PLUGIN_ID, 0, "", null);
validate.getErrors().stream()
.distinct()
.map(org.eclipse.core.databinding.validation.ValidationStatus::error)
.forEach(status::add);
validate.getWarnings().stream()
.distinct()
.map(org.eclipse.core.databinding.validation.ValidationStatus::warning)
.forEach(status::add);
for (Status engineStatus : validate.getStatuses()) {
String translatedMessage = BusinessDataModelStatusMapper.instance()
.localizedMessage(engineStatus);
if (engineStatus.getLevel().equals(Status.Level.ERROR)) {
status.add(org.eclipse.core.databinding.validation.ValidationStatus
.error(translatedMessage));
} else {
status.add(org.eclipse.core.databinding.validation.ValidationStatus
.warning(translatedMessage));
}
}
if (!manageErrors(status, getShell())) {
throw new InterruptedException();
}
......
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