Skip to content

Commit

Permalink
TEIIDDES-505
Browse files Browse the repository at this point in the history
Added UUID property to Model Element in VDB
Added missing UUID validation check and marker
Added missing model validation check
Changed Quick Fix to synchronize on missing uuid, renamed model, and moved model
  • Loading branch information
blafond committed Mar 4, 2013
1 parent a12e5c5 commit c80169e
Show file tree
Hide file tree
Showing 11 changed files with 249 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.teiid.designer.core.container.ResourceFinder;
import org.teiid.designer.core.extension.EmfModelObjectExtensionAssistant;
import org.teiid.designer.core.index.IndexUtil;
import org.teiid.designer.core.metamodel.MetamodelDescriptor;
import org.teiid.designer.core.resource.EmfResource;
import org.teiid.designer.core.resource.MMXmiResource;
import org.teiid.designer.core.xmi.XMIHeader;
Expand Down Expand Up @@ -1028,6 +1029,33 @@ public static boolean isXsdFile( final File file ) {
}
return false;
}

/**
* @param obj the target object
* @return the uuid string
* @throws ModelWorkspaceException if issues finding <code>ModelResource</code>
*/
public static String getUuidString(Object obj) {
ModelResource mr = null;
String uuid = null;
try {
if (obj instanceof ModelResource) {
mr = (ModelResource)obj;
} else if (obj instanceof IFile) {
mr = ModelUtil.getModelResource((IFile)obj, false);
} else if (obj instanceof Resource) {
mr = ModelerCore.getModelEditor().findModelResource((Resource)obj);
}

if( mr != null ) {
uuid = mr.getUuid();
}
} catch (ModelWorkspaceException ex) {
ModelerCore.Util.log(IStatus.ERROR, ex, ex.getMessage());
}

return uuid;
}

/**
* @since 4.0
Expand Down
8 changes: 7 additions & 1 deletion plugins/org.teiid.designer.vdb.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,13 @@
<attribute name="outOfSync" value="true"/>
</markerResolutionGenerator>
</extension>

<extension point="org.eclipse.ui.ide.markerResolution">
<markerResolutionGenerator
class="org.teiid.designer.vdb.ui.build.VdbMissingUuidMarkerResolutionGenerator"
markerType="org.teiid.designer.vdb.ui.vdbMarker">
<attribute name="missingUuid" value="true"/>
</markerResolutionGenerator>
</extension>
<extension
point="org.teiid.designer.core.refactorModelHandler">
<refactorHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,37 @@ public class VdbBuilder extends IncrementalProjectBuilder {
public static final String WRONG_PATH = "wrongPath"; //$NON-NLS-1$
@SuppressWarnings("javadoc")
public static final String OUT_OF_SYNC = "outOfSync"; //$NON-NLS-1$
@SuppressWarnings("javadoc")
public static final String NAME_CHANGED = "nameChanged"; //$NON-NLS-1$
@SuppressWarnings("javadoc")
public static final String MISSING_UUID = "missingUuid"; //$NON-NLS-1$
@SuppressWarnings("javadoc")
public static final String MISSING_MODEL = "missingModel"; //$NON-NLS-1$

private enum MarkerType {
DEFAULT,
WRONG_PATH,
OUT_OF_SYNC,
NAME_CHANGED,
MISSING_UUID,
MISSING_MODEL;

}

/**
public enum Currency {
PENNY(1), NICKLE(5), DIME(10), QUARTER(25);
private int value;
private Currency(int value) {
this.value = value;
}
};
Read more: http://javarevisited.blogspot.com/2011/08/enum-in-java-example-tutorial.html#ixzz2MJdMYTAM
*/

/**
* {@inheritDoc}
*
Expand Down Expand Up @@ -115,12 +146,24 @@ void refreshVdbFileMarkers( IFile vdbFile ) throws Exception {
for( IStatus iStatus : status.getChildren() ) {
switch( iStatus.getSeverity() ) {
case IStatus.WARNING: {
boolean hasWrongPath = iStatus.getMessage().indexOf("exists in your project") > 0; //$NON-NLS-1$
boolean outOfSync = iStatus.getMessage().indexOf("is not synchronized") > 0; //$NON-NLS-1$
createMarker(vdbFile, IMarker.SEVERITY_WARNING, iStatus.getMessage(), VdbUiConstants.VdbIds.PROBLEM_MARKER, hasWrongPath, outOfSync);
if( iStatus.getMessage().indexOf("exists in your project") > 0 ) { //$NON-NLS-1$
createMarker(vdbFile, IMarker.SEVERITY_WARNING, iStatus.getMessage(), VdbUiConstants.VdbIds.PROBLEM_MARKER, MarkerType.WRONG_PATH);
}
if( iStatus.getMessage().indexOf("is not synchronized") > 0 ) { //$NON-NLS-1$
createMarker(vdbFile, IMarker.SEVERITY_WARNING, iStatus.getMessage(), VdbUiConstants.VdbIds.PROBLEM_MARKER, MarkerType.OUT_OF_SYNC);
}
if( iStatus.getMessage().indexOf("has different name than model") > 0 ) { //$NON-NLS-1$
createMarker(vdbFile, IMarker.SEVERITY_WARNING, iStatus.getMessage(), VdbUiConstants.VdbIds.PROBLEM_MARKER, MarkerType.NAME_CHANGED);
}
if( iStatus.getMessage().indexOf("is missing its ID") > 0 ) { //$NON-NLS-1$
createMarker(vdbFile, IMarker.SEVERITY_WARNING, iStatus.getMessage(), VdbUiConstants.VdbIds.PROBLEM_MARKER, MarkerType.MISSING_UUID);
}
if( iStatus.getMessage().indexOf("does not exist") > 0 ) { //$NON-NLS-1$
createMarker(vdbFile, IMarker.SEVERITY_WARNING, iStatus.getMessage(), VdbUiConstants.VdbIds.PROBLEM_MARKER, MarkerType.MISSING_MODEL);
}
} break;
case IStatus.ERROR: {
createMarker(vdbFile, IMarker.SEVERITY_ERROR, iStatus.getMessage(), VdbUiConstants.VdbIds.PROBLEM_MARKER, false, false);
createMarker(vdbFile, IMarker.SEVERITY_ERROR, iStatus.getMessage(), VdbUiConstants.VdbIds.PROBLEM_MARKER, MarkerType.DEFAULT);
} break;
}
}
Expand All @@ -138,15 +181,13 @@ void refreshVdbFileMarkers( IFile vdbFile ) throws Exception {
* @param severity the marker severity
* @param message the marker message (precondition: not <code>null</code> or empty)
* @param markerId the Id for the marker
* @param hasWrongPath wrong path indicator
* @param outOfSync out of sync indicator
* @param markerType
*/
private void createMarker( IFile file,
int severity,
String message,
String markerId,
boolean hasWrongPath,
boolean outOfSync) {
MarkerType markerType) {
// parameters
assert (file != null) : "file is null"; //$NON-NLS-1$
assert ((message != null) && !message.isEmpty()) : "message is empty"; //$NON-NLS-1$
Expand All @@ -156,11 +197,16 @@ private void createMarker( IFile file,
attributes.put(IMarker.SEVERITY, severity);
attributes.put(IMarker.MESSAGE, message);

// Add attribute if wrong path so Quick Fix can find it
if( hasWrongPath ) attributes.put(WRONG_PATH, true);
// Add attribute if out of sync so Quick Fix can find it
if( outOfSync ) attributes.put(OUT_OF_SYNC, true);

if (markerType == MarkerType.WRONG_PATH) {
attributes.put(WRONG_PATH, true);
} else if (markerType == MarkerType.OUT_OF_SYNC) {
attributes.put(OUT_OF_SYNC, true);
} else if (markerType == MarkerType.NAME_CHANGED) {
attributes.put(NAME_CHANGED, true);
} else if (markerType == MarkerType.MISSING_UUID) {
attributes.put(MISSING_UUID, true);
}

try {
MarkerUtilities.createMarker(file, attributes, markerId);
} catch (CoreException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public class VdbMarkerResolutionGenerator implements IMarkerResolutionGenerator
@Override
public IMarkerResolution[] getResolutions(IMarker marker) {
Collection<IMarkerResolution> resolutions = new ArrayList<IMarkerResolution>();
if( marker.getAttribute(VdbBuilder.WRONG_PATH, false) || marker.getAttribute(VdbBuilder.OUT_OF_SYNC, false)) {
if( marker.getAttribute(VdbBuilder.WRONG_PATH, false) ||
marker.getAttribute(VdbBuilder.OUT_OF_SYNC, false) ||
marker.getAttribute(VdbBuilder.MISSING_UUID, false)) {
resolutions.add(new VdbModelPathResolution());
}
return resolutions.toArray(new IMarkerResolution[resolutions.size()]);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 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.vdb.ui.build;

import org.teiid.designer.vdb.ui.build.VdbMarkerResolutionGenerator;

/**
*
*/
public class VdbMissingUuidMarkerResolutionGenerator extends VdbMarkerResolutionGenerator {

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
/**
*
*/
public class VdbOutOfSyncMarkerResolutionGenerator extends
VdbMarkerResolutionGenerator {
public class VdbOutOfSyncMarkerResolutionGenerator extends VdbMarkerResolutionGenerator {

}
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,8 @@ public boolean preProcess(int refactorType, IResource refactoredResource, IProgr
closeVdbEditor(editor);
}
}



return true;

return result;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public static String createDefaultJndiName(IPath path) {
}

private final String indexName;
private String modelUuid;
private final Set<Problem> problems = new HashSet<Problem>();
private final AtomicBoolean visible = new AtomicBoolean(true);
private final CopyOnWriteArraySet<VdbModelEntry> imports = new CopyOnWriteArraySet<VdbModelEntry>();
Expand Down Expand Up @@ -119,8 +120,10 @@ public static String createDefaultJndiName(IPath path) {
builtIn = getFinder().isBuiltInResource(model);
modelClass = findModelClass(model);
if (ModelUtil.isXmiFile(model)) {
final ModelResource mr = ModelerCore.getModelEditor().findModelResource(model);
final EmfResource emfModel = (EmfResource)model;
type = emfModel.getModelType().getName();
modelUuid = ModelUtil.getUuidString(mr);

// TODO: Backing out the auto-set visibility to FALSE for physical models (Preview won't work)
// visible.set(false);
Expand All @@ -134,7 +137,6 @@ public static String createDefaultJndiName(IPath path) {
if (ModelUtil.isPhysical(model)) {
final String defaultName = createDefaultJndiName(name);
source.set(defaultName);
final ModelResource mr = ModelerCore.getModelEditor().findModelResource(model);
final ConnectionInfoHelper helper = new ConnectionInfoHelper();
final String translator = helper.getTranslatorName(mr);
this.translator.set(translator == null ? EMPTY_STR : translator);
Expand Down Expand Up @@ -262,6 +264,7 @@ public static String getUdfJarPath(final Procedure proc) {
if (ModelElement.BUILT_IN.equals(name)) builtIn = Boolean.parseBoolean(property.getValue());
else if (ModelElement.INDEX_NAME.equals(name)) indexName = property.getValue();
else if (ModelElement.MODEL_CLASS.equals(name)) modelClass = property.getValue();
else if (ModelElement.MODEL_UUID.equals(name)) modelUuid = property.getValue();
else if (ModelElement.IMPORT_VDB_REFERENCE.equals(name)) {
importVdbNames.add(property.getValue());
}
Expand Down Expand Up @@ -469,7 +472,14 @@ void initializeImports() {
}

/**
* @return <code>true</code> if the associated model is a hidden built-in model.
* @return model uuid
*/
public final String getModelUuid() {
return modelUuid;
}

/**
* @return model class
*/
public final String getModelClass() {
return modelClass;
Expand Down

0 comments on commit c80169e

Please sign in to comment.