Skip to content

Commit

Permalink
TEIIDDES-2775 Added Convert Functions action and dialog
Browse files Browse the repository at this point in the history
 * Verified functions exist in selected legacy function model
 * insures that one or more functions are selected for conversion
 * Allows exporting to existing or new virtual model
  • Loading branch information
blafond committed Feb 9, 2016
1 parent a444e32 commit b975dce
Show file tree
Hide file tree
Showing 9 changed files with 814 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,14 @@ public class RelationalModelFactory implements RelationalConstants {

private Map<String, Collection<ModelObjectExtensionAssistant>> classNameToMedAssistantsMap = new HashMap<String,Collection<ModelObjectExtensionAssistant>>();

private boolean allowsZeroStringLength;
/**
*
*/
public RelationalModelFactory() {
super();
this.datatypeProcessor = new DatatypeProcessor();
allowsZeroStringLength = false;
}

protected RelationalModelExtensionAssistant getExtensionAssistant() {
Expand Down Expand Up @@ -501,7 +503,7 @@ public EObject createColumn( RelationalReference ref, ProcedureResult procedureR
String dTypeName = ModelerCore.getModelEditor().getName(datatype);

int datatypeLength = columnRef.getLength();
if( datatypeLength == 0 && DatatypeProcessor.DEFAULT_DATATYPE.equalsIgnoreCase(dTypeName) ) {
if( !allowsZeroStringLength && datatypeLength == 0 && DatatypeProcessor.DEFAULT_DATATYPE.equalsIgnoreCase(dTypeName) ) {
columnRef.setLength(DatatypeProcessor.DEFAULT_DATATYPE_LENGTH);
} else {
columnRef.setLength(datatypeLength);
Expand Down Expand Up @@ -750,6 +752,7 @@ public EObject createParameter( RelationalReference ref, Procedure procedure, Mo
parameter.setNameInSource(parameterRef.getNameInSource());
parameter.setDefaultValue(parameterRef.getDefaultValue());
parameter.setDirection(getDirectionKind(parameterRef.getDirection()));
parameter.setLength(parameterRef.getLength());
parameter.setNativeType(parameterRef.getNativeType());
parameter.setNullable(getNullableType(parameterRef.getNullable()));
parameter.setPrecision(parameterRef.getPrecision());
Expand All @@ -767,12 +770,16 @@ public EObject createParameter( RelationalReference ref, Procedure procedure, Mo
String dTypeName = ModelerCore.getModelEditor().getName(datatype);

int datatypeLength = parameterRef.getLength();
if( datatypeLength == 0 && DatatypeProcessor.DEFAULT_DATATYPE.equalsIgnoreCase(dTypeName) ) {
if( !allowsZeroStringLength && datatypeLength == 0 && DatatypeProcessor.DEFAULT_DATATYPE.equalsIgnoreCase(dTypeName) ) {
parameter.setLength(DatatypeProcessor.DEFAULT_DATATYPE_LENGTH);
} else {
parameter.setLength(datatypeLength);
}
}

if( parameterRef.getDescription() != null) {
createAnnotation(parameter, parameterRef.getDescription(), modelResource);
}

// Apply Extension Properties
processExtensionProperties(modelResource,parameterRef,parameter);
Expand Down Expand Up @@ -1221,5 +1228,15 @@ private boolean hasMatchingPropertyName(ModelExtensionDefinition med, String met
ModelExtensionPropertyDefinition propDefn = med.getPropertyDefinition(metaclassName, propId);
return propDefn!=null ? true : false;
}

public boolean allowsZeroStringLength() {
return allowsZeroStringLength;
}

public void setAllowsZeroStringLength(boolean allowsZeroStringLength) {
this.allowsZeroStringLength = allowsZeroStringLength;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,8 @@ newChildViewTableAction=Table...
newSiblingViewTableAction=Table...

exportTeiidDdlWizard.name=Teiid DDL
exportTeiidDdlWizard.description=Convert relational source or view model to Teiid DDL and save to workspace or file system
exportTeiidDdlWizard.description=Convert relational source or view model to Teiid DDL and save to workspace or file system

convertFunctionsAction.label=Convert Legacy Functions to Virtual Procedures
convertFunctionsAction.name=Convert Legacy Functions to Virtual Procedures
convertFunctionsAction.tooltip=Convert Legacy Functions to Virtual Procedures
9 changes: 9 additions & 0 deletions plugins/org.teiid.designer.transformation.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,15 @@
label="%editTransformationAction.label">
</resourceAction>
</extension>
<extension
id="ConvertFunctionsAction"
name="%convertFunctionsAction.name"
point="org.teiid.designer.ui.modelResourceAction">
<resourceAction
name="org.teiid.designer.transformation.ui.actions.ConvertFunctionsToVirtualProceduresAction"
label="%convertFunctionsAction.label">
</resourceAction>
</extension>

<!-- Action contributed to generate materialized views -->
<extension
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* JBoss, Home of Professional Open Source.
*
* See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing.
*
* See the AUTHORS.txt file distributed with this work for a full listing of individual contributors.
*/
package org.teiid.designer.transformation.ui.actions;

import java.util.Iterator;
import java.util.List;

import org.eclipse.core.resources.IFile;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.widgets.Display;
import org.teiid.designer.core.workspace.ModelResource;
import org.teiid.designer.core.workspace.ModelUtil;
import org.teiid.designer.core.workspace.ModelWorkspaceException;
import org.teiid.designer.transformation.ui.UiConstants;
import org.teiid.designer.transformation.ui.UiPlugin;
import org.teiid.designer.transformation.ui.wizards.functions.ConvertFunctionModelDialog;
import org.teiid.designer.transformation.ui.wizards.functions.ConvertFunctionModelHelper;
import org.teiid.designer.ui.actions.SortableSelectionAction;
import org.teiid.designer.ui.common.eventsupport.SelectionUtilities;
import org.teiid.designer.ui.common.widget.Dialog;
import org.teiid.designer.ui.viewsupport.ModelIdentifier;

public class ConvertFunctionsToVirtualProceduresAction extends SortableSelectionAction {

public static final String OPEN_EDITOR_TITLE = UiConstants.Util.getString("ConvertFunctionsToVirtualProceduresAction.openModelEditorTitle"); //$NON-NLS-1$
public static final String OPEN_EDITOR_MESSAGE = UiConstants.Util.getString("ConvertFunctionsToVirtualProceduresAction.openModelEditorMessage"); //$NON-NLS-1$
public static final String ALWAY_FORCE_OPEN_MESSAGE = UiConstants.Util.getString("ConvertFunctionsToVirtualProceduresAction.alwaysForceOpenMessage"); //$NON-NLS-1$

public ConvertFunctionsToVirtualProceduresAction() {
super();
setImageDescriptor(UiPlugin.getDefault().getImageDescriptor(
org.teiid.designer.transformation.ui.PluginConstants.Images.CREATE_MATERIALIZED_VIEWS_ICON));
}

@Override
public boolean isValidSelection(ISelection selection) {
// Enable for single/multiple Virtual Tables
return functionModelSelected(selection);
}

@Override
public void run() {
ISelection cachedSelection = getSelection();
if( cachedSelection != null && !cachedSelection.isEmpty() ) {
Object selectedObj = SelectionUtilities.getSelectedObject(cachedSelection);
if( selectedObj != null && selectedObj instanceof IFile) {
ModelResource functionModel = null;
try {
functionModel = ModelUtil.getModelResource(((IFile) selectedObj), false);
if( functionModel != null ) {
// FUNCTION MODEL IS SELECTED SO LET's PROCESS

ConvertFunctionModelHelper helper = new ConvertFunctionModelHelper(functionModel);

System.out.println("ConvertFunctionsToVirtualProceduresAction.run() called. Model = " + functionModel.getItemName());

ConvertFunctionModelDialog dialog = new ConvertFunctionModelDialog(Display.getCurrent().getActiveShell(), helper);

if( dialog.open() == Dialog.OK ) {
helper.generateProcedures();
}
}
} catch (ModelWorkspaceException e) {
UiConstants.Util.log(e);
}
}

}
selectionChanged(null, new StructuredSelection());
}

@Override
public boolean isApplicable(ISelection selection) {
return functionModelSelected(selection);
}

private boolean functionModelSelected(ISelection theSelection) {
boolean result = false;
List allObjs = SelectionUtilities.getSelectedObjects(theSelection);
if( !allObjs.isEmpty() && allObjs.size() == 1 ) {
Iterator iter = allObjs.iterator();
result = true;
Object nextObj = null;
while( iter.hasNext() && result ) {
nextObj = iter.next();

if( nextObj instanceof IFile ) {
result = ModelIdentifier.isFunctionModel((IFile)nextObj);
} else {
result = false;
}
}
}

return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1138,8 +1138,6 @@ DefineViewProcedureDialog.restOptions=REST Options
DefineViewProcedureDialog.restMethod=REST Method
DefineViewProcedureDialog.uri=URI
DefineViewProcedureDialog.restUriTooltip=Rest URI (i.e. xxxxx/{yyyy})
<<<<<<< HEAD
=======

#=================================================================================================================================
# ExportTeiidDdlWizard
Expand Down Expand Up @@ -1199,4 +1197,27 @@ ExportTeiidDdlWizard_fileLabel = File:
ExportTeiidDdlWizard_clipboardChoiceLabel = Clipboard
ExportTeiidDdlWizard_fileChoiceLabel = File
ExportTeiidDdlWizard_clipboardTooltip = Facility for short-term storage of data. The DDL text is held in this clipboard and can be added to other applications and files using their paste functions
>>>>>>> origin/dynamic_vdbs

ConvertFunctionsToVirtualProceduresAction.openModelEditorTitle=Open Model Editor
ConvertFunctionsToVirtualProceduresAction.openModelEditorMessage=You must open this model in an editor tab before you can \
continue. Do you want to open the editor?
ConvertFunctionsToVirtualProceduresAction.alwaysForceOpenMessage=Always open editor without prompting

ConvertFunctionModelDialog.title=Convert Legacy Functions
ConvertFunctionModelDialog.titleMessage=Convert legacy functions to UDF view procedures
ConvertFunctionModelDialog.selectFunctions=Select functions to convert
ConvertFunctionModelDialog.targetModelGroupName=Target Model
ConvertFunctionModelDialog.name=Name
ConvertFunctionModelDialog.modelNameDialogTitle=Model Name
ConvertFunctionModelDialog.modelNameDialogNewName=New Model Name
ConvertFunctionModelDialog.modelNameDialogMessage=Select or create View model
ConvertFunctionModelDialog.modelNameDialogNoModelSelected=No view model selected
ConvertFunctionModelDialog.modelNameDialogMultipleSelection=Must select single view model

ConvertFunctionModelHelper.buildErrorTitle=Problem creating virtual procedures
ConvertFunctionModelHelper.buildErrorMessage=Error creating virtual procedures from modeled functions
ConvertFunctionModelHelper.noFunctionsMessage=Function model contains no functions
ConvertFunctionModelHelper.targetModelUndefined=Virtual model not defined
ConvertFunctionModelHelper.noFunctionsSelected=No functions selected to convert
ConvertFunctionModelHelper.okToFinishMessage=Click OK to generate your UDF virtual procedures

Loading

0 comments on commit b975dce

Please sign in to comment.