Skip to content

Commit

Permalink
TEIIDDES-2034 Added character validation to ModelNameChecker.validate…
Browse files Browse the repository at this point in the history
…() method

* Added additional messaging in UI panels/pages to insert name context in message like "Invalid view model name", etc...
  • Loading branch information
blafond committed Jan 29, 2014
1 parent fafaf54 commit 8364545
Show file tree
Hide file tree
Showing 24 changed files with 70 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ private void validatePage(boolean firstTime) {
ModelNameUtil.IGNORE_CASE | ModelNameUtil.NO_DUPLICATE_MODEL_NAMES);

if( !updating && status.getSeverity() == IStatus.ERROR ) {
WizardUtil.setPageComplete(this, status.getMessage(), ERROR);
WizardUtil.setPageComplete(this, ModelNameUtil.MESSAGES.INVALID_MODEL_NAME + status.getMessage(), ERROR);
folder = null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.eclipse.ui.help.IWorkbenchHelpSystem;
import org.teiid.core.designer.event.IChangeListener;
import org.teiid.core.designer.event.IChangeNotifier;
import org.teiid.designer.core.ModelerCore;
import org.teiid.designer.datatools.profiles.ldap.ILdapProfileConstants;
import org.teiid.designer.datatools.ui.dialogs.ConnectionProfileWorker;
import org.teiid.designer.datatools.ui.dialogs.IProfileChangedListener;
Expand All @@ -49,6 +50,7 @@
import org.teiid.designer.ui.common.util.WidgetFactory;
import org.teiid.designer.ui.common.util.WidgetUtil;
import org.teiid.designer.ui.common.util.WizardUtil;
import org.teiid.designer.ui.viewsupport.ModelNameUtil;

/**
* Wizard page for specifying the connection parameters
Expand Down Expand Up @@ -431,6 +433,13 @@ protected IStatus run(IProgressMonitor monitor) {
if (this.importManager.getSourceModelName() == null || this.importManager.getSourceModelName().length() == 0) {
WizardUtil.setPageComplete(this, getString("statusSourceModelNameCannotBeNullOrEmpty"), IMessageProvider.ERROR); //$NON-NLS-1$
return;
} else {
IStatus status = ModelNameUtil.validate(this.importManager.getSourceModelName(), ModelerCore.MODEL_FILE_EXTENSION, null,
ModelNameUtil.IGNORE_CASE );
if( status.getSeverity() == IStatus.ERROR ) {
WizardUtil.setPageComplete(this, ModelNameUtil.MESSAGES.INVALID_MODEL_NAME + status.getMessage(), ERROR);
return ;
}
}

if (sourceModelPanel.sourceModelExists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ private IContainer validateFileAndFolder( final Text fileText,
IStatus status = ModelNameUtil.validate(fileName, ModelerCore.MODEL_FILE_EXTENSION, targetModelLocation,
ModelNameUtil.IGNORE_CASE | ModelNameUtil.NO_DUPLICATE_MODEL_NAMES);
if( status.getSeverity() == IStatus.ERROR ) {
WizardUtil.setPageComplete(this, status.getMessage(), ERROR);
WizardUtil.setPageComplete(this, ModelNameUtil.MESSAGES.INVALID_MODEL_NAME + status.getMessage(), ERROR);
targetModelLocation = null;
} else {
final String folderName = folderText.getText();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.List;
import java.util.Map;
import java.util.Properties;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.MultiStatus;
Expand All @@ -25,9 +26,9 @@
import org.teiid.designer.modelgenerator.wsdl.model.Model;
import org.teiid.designer.modelgenerator.wsdl.model.ModelGenerationException;
import org.teiid.designer.modelgenerator.wsdl.model.Operation;
import org.teiid.designer.modelgenerator.wsdl.model.Port;
import org.teiid.designer.modelgenerator.wsdl.ui.wizards.soap.ImportManagerValidator;
import org.teiid.designer.modelgenerator.wsdl.ui.wizards.soap.ProcedureGenerator;
import org.teiid.designer.query.proc.wsdl.model.IPort;
import org.teiid.designer.ui.common.ICredentialsCommon;
import org.teiid.designer.ui.common.ICredentialsCommon.SecurityType;
import org.teiid.designer.ui.viewsupport.ModelUtilities;
Expand Down Expand Up @@ -77,7 +78,7 @@ public class WSDLImportWizardManager implements IChangeNotifier {

private Model wsdlModel;

private String translatorDefaultBinding = Port.SOAP11;
private String translatorDefaultBinding = IPort.SOAP11;
private String translatorDefaultServiceMode = PAYLOAD;

private Properties designerProperties;
Expand Down Expand Up @@ -275,7 +276,7 @@ public void setConnectionProfile(IConnectionProfile connectionProfile) {
if (binding != null) {
setTranslatorDefaultBinding(binding);
} else {
setTranslatorDefaultBinding(Port.SOAP11);
setTranslatorDefaultBinding(IPort.SOAP11);
}
}
setChanged(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class ImportManagerValidator {

public static final DatatypeManager datatypeManager = ModelerCore.getWorkspaceDatatypeManager();

String PLUGIN_ID = ModelGeneratorWsdlUiConstants.PLUGIN_ID;

WSDLImportWizardManager manager;
IStatus connectionProfileStatus;
IStatus operationsStatus;
Expand Down Expand Up @@ -109,7 +111,7 @@ public IStatus getProcedureStatus(ProcedureGenerator generator) {
}

public IStatus getWorstProcedureStatus() {
MultiStatus status = new MultiStatus(ProcedureGenerator.PLUGIN_ID, 0, null, null);
MultiStatus status = new MultiStatus(PLUGIN_ID, 0, null, null);

for(ProcedureGenerator generator : this.manager.getProcedureGenerators() ) {
IStatus theStatus = this.proceduresStatusMap.get(generator);
Expand All @@ -122,7 +124,7 @@ public IStatus getWorstProcedureStatus() {
}

private IStatus validateConnectionProfile() {
MultiStatus status = new MultiStatus(ProcedureGenerator.PLUGIN_ID, 0, null, null);
MultiStatus status = new MultiStatus(PLUGIN_ID, 0, null, null);

IConnectionProfile connectionProfile = manager.getConnectionProfile();
if (connectionProfile == null) {
Expand All @@ -149,7 +151,7 @@ private IStatus validateConnectionProfile() {
}

private IStatus validateResourceInfo() {
MultiStatus status = new MultiStatus(ProcedureGenerator.PLUGIN_ID, 0, null, null);
MultiStatus status = new MultiStatus(PLUGIN_ID, 0, null, null);

// Validate Source location & model name
if (this.manager.getSourceModelLocation() == null ) {
Expand All @@ -162,7 +164,9 @@ private IStatus validateResourceInfo() {
} else {
nameStatus = ModelNameUtil.validate(this.manager.getSourceModelName(), ModelerCore.MODEL_FILE_EXTENSION, ModelNameUtil.IGNORE_CASE );
if (nameStatus.getSeverity() == IStatus.ERROR) {
status.add(nameStatus);
Status newStatus = new Status(nameStatus.getSeverity(), nameStatus.getPlugin(),
ModelNameUtil.MESSAGES.INVALID_SOURCE_MODEL_NAME + nameStatus.getMessage());
status.add(newStatus);
}
}

Expand All @@ -177,7 +181,9 @@ private IStatus validateResourceInfo() {
else {
nameStatus = ModelNameUtil.validate(this.manager.getViewModelName(), ModelerCore.MODEL_FILE_EXTENSION, ModelNameUtil.IGNORE_CASE );
if (nameStatus.getSeverity() == IStatus.ERROR) {
status.add(nameStatus);
Status newStatus = new Status(nameStatus.getSeverity(), nameStatus.getPlugin(),
ModelNameUtil.MESSAGES.INVALID_VIEW_MODEL_NAME + nameStatus.getMessage());
status.add(newStatus);
}
}

Expand All @@ -199,7 +205,7 @@ private IStatus validateProcedures() {
return createStatus(IStatus.WARNING, Messages.Error_NoOperationsSelected);
}

MultiStatus status = new MultiStatus(ProcedureGenerator.PLUGIN_ID, 0, null, null);
MultiStatus status = new MultiStatus(PLUGIN_ID, 0, null, null);
for(ProcedureGenerator generator : this.manager.getProcedureGenerators() ) {
IStatus theStatus = generator.validate();
this.proceduresStatusMap.put(generator, theStatus);
Expand All @@ -212,7 +218,7 @@ private IStatus validateProcedures() {
}

private IStatus createStatus(int severity, String message) {
return new Status(severity, ProcedureGenerator.PLUGIN_ID, message);
return new Status(severity, PLUGIN_ID, message);
}

public static boolean isValidDatatype(String type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ private void validatePage() {
IStatus status = ModelNameUtil.validate(name, ModelerCore.MODEL_FILE_EXTENSION, folder,
ModelNameUtil.IGNORE_CASE | ModelNameUtil.NO_DUPLICATE_MODEL_NAMES);
if( status.getSeverity() == IStatus.ERROR ) {
WizardUtil.setPageComplete(this, status.getMessage(), ERROR);
WizardUtil.setPageComplete(this, ModelNameUtil.MESSAGES.INVALID_MODEL_NAME + status.getMessage(), ERROR);
folder = null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ private String getModelNameStatus( String sModelName ) {
IStatus status = ModelNameUtil.validate(sModelName, ModelerCore.MODEL_FILE_EXTENSION, newModelParent,
ModelNameUtil.IGNORE_CASE | ModelNameUtil.NO_DUPLICATE_MODEL_NAMES);
if( status.getSeverity() == IStatus.ERROR ) {
return status.getMessage();
return ModelNameUtil.MESSAGES.INVALID_MODEL_NAME + status.getMessage();
}

// success
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ private boolean validateTargetModelSelection() {
IStatus status = ModelNameUtil.validate(fileText, ModelerCore.MODEL_FILE_EXTENSION, null,
ModelNameUtil.IGNORE_CASE );
if( status.getSeverity() == IStatus.ERROR ) {
setThisPageComplete(status.getMessage(), ERROR);
setThisPageComplete(ModelNameUtil.MESSAGES.INVALID_MODEL_NAME + status.getMessage(), ERROR);
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ private String getVirtualModelNameStatus( String sModelName ) {
IStatus status = ModelNameUtil.validate(sModelName, ModelerCore.MODEL_FILE_EXTENSION, newModelParent,
ModelNameUtil.IGNORE_CASE | ModelNameUtil.NO_DUPLICATE_MODEL_NAMES_OTHER_THAN_LOCATION | ModelNameUtil.NO_DUPLICATE_MODEL_NAMES);
if( status.getSeverity() == IStatus.ERROR ) {
return status.getMessage();
return ModelNameUtil.MESSAGES.INVALID_MODEL_NAME + status.getMessage();
}

// success
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public class RelationalModelSelectorDialog extends ModelWorkspaceDialog implemen
private Label lblRelationalModelName;
private Text txtRelationalModelName;
private IContainer newModelParent;
private IPath targetRelationalFilePath;
private ModelResource mrRelationalModel;
private EObject selectedEObject;
private SelectionAdapter saCreateCbxAdapter;
Expand Down Expand Up @@ -370,7 +369,7 @@ private String getModelNameStatus( String sModelName ) {
IStatus status = ModelNameUtil.validate(sModelName, ModelerCore.MODEL_FILE_EXTENSION, newModelParent,
ModelNameUtil.IGNORE_CASE | ModelNameUtil.NO_DUPLICATE_MODEL_NAMES_OTHER_THAN_LOCATION | ModelNameUtil.NO_DUPLICATE_MODEL_NAMES);
if( status.getSeverity() == IStatus.ERROR ) {
return status.getMessage();
return ModelNameUtil.MESSAGES.INVALID_MODEL_NAME + status.getMessage();
}

// success
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,7 @@ private boolean validatePage() {
IStatus status = ModelNameUtil.validate(fileText, ModelerCore.MODEL_FILE_EXTENSION, null,
ModelNameUtil.IGNORE_CASE );
if( status.getSeverity() == IStatus.ERROR ) {
setThisPageComplete(status.getMessage(), ERROR);
setThisPageComplete(ModelNameUtil.MESSAGES.INVALID_SOURCE_MODEL_NAME + status.getMessage(), ERROR);
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ private boolean validatePage() {
IStatus status = ModelNameUtil.validate(fileText, ModelerCore.MODEL_FILE_EXTENSION, null,
ModelNameUtil.IGNORE_CASE | ModelNameUtil.NO_DUPLICATE_MODEL_NAMES);
if( status.getSeverity() == IStatus.ERROR ) {
setThisPageComplete(status.getMessage(), ERROR);
setThisPageComplete(ModelNameUtil.MESSAGES.INVALID_VIEW_MODEL_NAME + status.getMessage(), ERROR);
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ private boolean validatePage() {
IStatus status = ModelNameUtil.validate(fileText, ModelerCore.MODEL_FILE_EXTENSION, null,
ModelNameUtil.IGNORE_CASE | ModelNameUtil.NO_DUPLICATE_MODEL_NAMES);
if( status.getSeverity() == IStatus.ERROR ) {
setThisPageComplete(status.getMessage(), ERROR);
setThisPageComplete(ModelNameUtil.MESSAGES.INVALID_SOURCE_MODEL_NAME + status.getMessage(), ERROR);
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ class TableOrProcedureFinder implements ModelVisitor {

boolean hasTableOrProcedure = false;

@SuppressWarnings("unused")
@Override
public boolean visit(EObject object) throws ModelerCoreException {
// Tables are contained by Catalogs, Schemas and Resources
Expand All @@ -388,6 +389,7 @@ public boolean visit(EObject object) throws ModelerCoreException {
return false;
}

@SuppressWarnings("unused")
@Override
public boolean visit(Resource resource) throws ModelerCoreException {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1544,6 +1544,12 @@ ModelNameChecker.exception.sameNameModelExistsInProjectMessage=Error trying to d
ModelNameChecker.zeroLengthFileMessage=Model name cannot be empty. It must include one or more valid characters.
ModelNameChecker.illegalExtensionMessage=Model files must end with the extension {0}

ModelNameUtil.invalidModelName=Invalid model name.
ModelNameUtil.invalidSourceModelName=Invalid source model name.
ModelNameUtil.invalidViewModelName=Invalid view model name.
ModelNameUtil.invalidSchemaFileName=Invalid schema file name.


##### DefaultTeiidServerPreferenceContributor #####
DefaultTeiidServerPreferenceContributor.name=defaultTeiidInstanceVersion
DefaultTeiidServerPreferenceContributor.title=Default Teiid Instance Version (applicable if no teiid instance defined)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.eclipse.core.runtime.Status;
import org.teiid.core.designer.util.CoreArgCheck;
import org.teiid.core.designer.util.I18nUtil;
import org.teiid.designer.core.validation.rules.StringNameValidator;
import org.teiid.designer.ui.PluginConstants;
import org.teiid.designer.ui.UiConstants;

Expand Down Expand Up @@ -149,6 +150,14 @@ private void checkNameAndExtension() {
createErrorStatus(getString("illegalExtensionMessage", finalFileExtension)); //$NON-NLS-1$
return;
}
} else {
// Check name first

StringNameValidator nameValidator = new StringNameValidator();
String result = nameValidator.checkValidName(finalProposedName);
if( result != null ) {
createErrorStatus(result);
}
}

originalNameWithoutExtension = finalProposedName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.runtime.IStatus;
import org.teiid.designer.core.util.StringUtilities;
import org.teiid.designer.ui.UiConstants;

/**
* Utility class providing model name analysis and validation methods
Expand All @@ -35,7 +37,14 @@ public abstract class ModelNameUtil {
* target project or folder
*/
static public final int NO_DUPLICATE_MODEL_NAMES_OTHER_THAN_LOCATION = 8; // 00001000

public interface MESSAGES {
String INVALID_MODEL_NAME = UiConstants.Util.getString("ModelNameUtil.invalidModelName") + StringUtilities.SPACE; //$NON-NLS-1$
String INVALID_SOURCE_MODEL_NAME = UiConstants.Util.getString("ModelNameUtil.invalidSourceModelName") + StringUtilities.SPACE; //$NON-NLS-1$
String INVALID_VIEW_MODEL_NAME = UiConstants.Util.getString("ModelNameUtil.invalidViewModelName") + StringUtilities.SPACE; //$NON-NLS-1$
String INVALID_SCHEMA_FILE_NAME = UiConstants.Util.getString("ModelNameUtil.invalidSchemaFileName") + StringUtilities.SPACE; //$NON-NLS-1$

}

/**
* Determine if the proposed model name is valid, and return an error message if it is not.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.teiid.designer.core.workspace.ModelWorkspaceException;
import org.teiid.designer.ui.UiConstants;
import org.teiid.designer.ui.common.util.WidgetFactory;
import org.teiid.designer.ui.common.util.WizardUtil;
import org.teiid.designer.ui.common.viewsupport.StatusInfo;
import org.teiid.designer.ui.explorer.ModelExplorerContentProvider;
import org.teiid.designer.ui.explorer.ModelExplorerLabelProvider;
Expand All @@ -68,8 +67,6 @@ public class ModelSelectorDialog extends ModelWorkspaceDialog implements UiConst
private final static int MODEL_NAME_TEXT_WIDTH = (int)(Display.getCurrent().getBounds().width * .25);

private final static String MODEL_CREATE_ERROR_NO_NAME = getString("noName.message"); //$NON-NLS-1$
private final static String MODEL_CREATE_ERROR_ALREADY_EXISTS = getString("alreadyExists.message"); //$NON-NLS-1$
private final static String MODEL_CREATE_ERROR_SAME_NAME_AS = getString("sameNameAs.message"); //$NON-NLS-1$
private final static String MODEL_CREATE_ERROR_IS_VALID = getString("isValid.message"); //$NON-NLS-1$
private final static String MODEL_NAME_LABEL = getString("newModelName.text"); //$NON-NLS-1$

Expand Down Expand Up @@ -395,7 +392,7 @@ private String getModelNameStatus( String sModelName ) {
IStatus status = ModelNameUtil.validate(sModelName, ModelerCore.MODEL_FILE_EXTENSION, newModelParent,
ModelNameUtil.IGNORE_CASE | ModelNameUtil.NO_DUPLICATE_MODEL_NAMES | ModelNameUtil.NO_EXISTING_MODEL_AT_LOCATION);
if( status.getSeverity() == IStatus.ERROR ) {
return status.getMessage();
return ModelNameUtil.MESSAGES.INVALID_MODEL_NAME + status.getMessage();
}

// success
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchWizard;
import org.eclipse.ui.actions.WorkspaceModifyOperation;
import org.eclipse.xsd.XSDElementDeclaration;
import org.teiid.core.designer.PluginUtil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.jface.dialogs.IDialogPage;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
Expand Down Expand Up @@ -614,7 +613,7 @@ void checkStatus() {
IStatus status = ModelNameUtil.validate(modelName, ModelerCore.MODEL_FILE_EXTENSION, folder,
ModelNameUtil.IGNORE_CASE | ModelNameUtil.NO_DUPLICATE_MODEL_NAMES | ModelNameUtil.NO_EXISTING_MODEL_AT_LOCATION);
if (status.getSeverity() == IStatus.ERROR) {
setErrorMessage(status.getMessage());
setErrorMessage(ModelNameUtil.MESSAGES.INVALID_SCHEMA_FILE_NAME + status.getMessage());
setPageComplete(false);
return;
}
Expand All @@ -634,7 +633,7 @@ void checkStatus() {
ModelNameUtil.IGNORE_CASE | ModelNameUtil.NO_DUPLICATE_MODEL_NAMES | ModelNameUtil.NO_EXISTING_MODEL_AT_LOCATION);

if (status.getSeverity() == IStatus.ERROR) {
setErrorMessage(status.getMessage());
setErrorMessage(ModelNameUtil.MESSAGES.INVALID_SCHEMA_FILE_NAME + status.getMessage());
setPageComplete(false);
return;
}
Expand All @@ -653,7 +652,7 @@ void checkStatus() {
status = ModelNameUtil.validate(wsName, XMI_EXT, folder,
ModelNameUtil.IGNORE_CASE | ModelNameUtil.NO_DUPLICATE_MODEL_NAMES | ModelNameUtil.NO_EXISTING_MODEL_AT_LOCATION);
if (status.getSeverity() == IStatus.ERROR) {
setErrorMessage(status.getMessage());
setErrorMessage(ModelNameUtil.MESSAGES.INVALID_VIEW_MODEL_NAME + status.getMessage());
setPageComplete(false);
return;
}
Expand Down

0 comments on commit 8364545

Please sign in to comment.