Skip to content

Commit

Permalink
TEIIDDES-1473 - added QuickFix feature for handling of MEDs with lega…
Browse files Browse the repository at this point in the history
…cy classnames
  • Loading branch information
mdrillin committed Nov 13, 2012
1 parent 2367219 commit f788717
Show file tree
Hide file tree
Showing 9 changed files with 435 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public abstract class ResourceNameUtil {
public static final String VDB_FILE_EXTENSION = "vdb"; //$NON-NLS-1$
public static final String XSD_FILE_EXTENSION = "xsd"; //$NON-NLS-1$
public static final String WSDL_FILE_EXTENSION = "wsdl"; //$NON-NLS-1$
public static final String MED_FILE_EXTENSION = "mxd"; //$NON-NLS-1$

public static final String DOT_XMI_FILE_EXTENSION = ".xmi"; //$NON-NLS-1$
public static final String DOT_VDB_FILE_EXTENSION = ".vdb"; //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
package org.teiid.designer.core.extension;

import static org.teiid.designer.core.ModelerCore.Util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.common.util.EMap;
import org.eclipse.emf.ecore.EObject;
Expand Down Expand Up @@ -799,8 +799,12 @@ public static void updateModelExtensionDefinition( ModelResource modelResource,
}
}

// Remove metaclass annotations from model if they are not in the MED
String[] medExtendedMetaclasses = definition.getExtendedMetaclasses();
removeUnsupportedMetaclassAnnotations(modelResource, definitionTags, medExtendedMetaclasses);

// properties
for (String extendedMetaclassName : definition.getExtendedMetaclasses()) {
for (String extendedMetaclassName : medExtendedMetaclasses) {
String metaclassKey = constructKey(EXTENDED_METACLASS_PREFIX, extendedMetaclassName);
Annotation metaclassAnnotation = getAnnotation(modelResource, definitionAnnotation, metaclassKey,
extendedMetaclassName, true);
Expand Down Expand Up @@ -940,6 +944,45 @@ public static void updateModelExtensionDefinition( ModelResource modelResource,
}
}

/*
* Remove metaclass annotations from the model that are not included in the supplied MED
* @param modelResc the ModelResource
* @param defnTags the models definition annotation tags
* @param medMetaclasses the array of extended metaclasses in the MED
*/
private static void removeUnsupportedMetaclassAnnotations(ModelResource modelResc, EMap<String, String> defnTags, String[] medMetaclasses) throws Exception {
// Track definition keys for later removal.
List<String> keysToRemove = new ArrayList<String>();

List<String> medMetaclassList = Arrays.asList(medMetaclasses);

// Iterate model's extended metaclass annotations, removing those not in the med.
for (Object object : defnTags.entrySet()) {
if (!(object instanceof EStringToStringMapEntryImpl)) {
throw new Exception(Util.getString(I18N_PREFIX + "modelExtensionDefinitionTagUnexpectedClass", //$NON-NLS-1$
object.getClass()));
}

EStringToStringMapEntryImpl entry = (EStringToStringMapEntryImpl)object;
if (entry.getKey().startsWith(EXTENDED_METACLASS_PREFIX)) {
// Model Extended Metaclass name
String metaclassName = getKeyId(EXTENDED_METACLASS_PREFIX, entry.getKey());

// If Model Extended Metaclass is not in the MED, remove it.
if(!medMetaclassList.contains(metaclassName)) {
removeMetaclassAnnotation(modelResc,entry);
// Track those entries removed
keysToRemove.add(entry.getKey());
}
}
}

// Remove Definition Tag for any removed metaclass annotations
for(String remKey: keysToRemove) {
defnTags.remove(remKey);
}
}

/**
* Don't allow construction.
*/
Expand Down
10 changes: 10 additions & 0 deletions plugins/org.teiid.designer.extension.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,14 @@
</run>
</builder>
</extension>

<!-- QuickFix extension to resolve Med Problem Markers -->
<extension point="org.eclipse.ui.ide.markerResolution">
<markerResolutionGenerator
class="org.teiid.designer.extension.ui.actions.MedMarkerResolutionGenerator"
markerType="org.teiid.designer.extension.ui.medMarker">
<attribute name="hasLegacyNames" value="true"/>
</markerResolutionGenerator>
</extension>

</plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,19 @@ public class Messages extends NLS {
public static String modelMedDifferentVersionThanOneFoundInRegistry;
public static String medChangedOnFileSystemDialogTitle;
public static String medChangedOnFileSystemDialogMsg;

public static String medFileHasLegacyClassnames;
public static String modelMedHasLegacyClassnames;
public static String getSupportedPrefixesErrorMsg;
public static String getModelMedErrorMsg;
public static String saveModelMedErrorMsg;
public static String saveModelErrorMsg;
public static String fixMedFileClassnamesFailedMsg;
public static String legacyClassnameResolutionLabel;
public static String quickFixMedFileDirtyTitle;
public static String quickFixMedFileDirtyMsg;
public static String quickFixModelDirtyTitle;
public static String quickFixModelDirtyMsg;

public static String registerMedActionInvalidMedTitle;
public static String registerMedActionInvalidMedMsg;
public static String registerMedActionNamespacePrefixRegisteredTitle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
Expand All @@ -37,6 +38,7 @@
import org.teiid.designer.extension.definition.ModelExtensionDefinition;
import org.teiid.designer.extension.definition.ModelExtensionDefinitionParser;
import org.teiid.designer.extension.definition.ModelObjectExtensionAssistant;
import org.teiid.designer.extension.properties.ModelExtensionPropertyDefinition;
import org.teiid.designer.extension.registry.ModelExtensionRegistry;
import org.teiid.designer.extension.ui.UiConstants.ExtensionIds;

Expand All @@ -50,6 +52,8 @@ public final class ModelExtensionDefinitionBuilder extends IncrementalProjectBui
private static final String SAX_ERR_PREFIX = "cvc-"; //$NON-NLS-1$
private static final String MED_VALIDATION_MSG = "MED Validation: "; //$NON-NLS-1$
private static final String SEE_DETAILS_MSG = " (See log for details)"; //$NON-NLS-1$
private static final String LEGACY_CLASSNAME_PREFIX = "com.metamatrix"; //$NON-NLS-1$
public static final String HAS_LEGACY_NAMES = "hasLegacyNames"; //$NON-NLS-1$

private ModelExtensionAssistantAggregator aggregator = ExtensionPlugin.getInstance().getModelExtensionAssistantAggregator();
private ModelExtensionRegistry registry = ExtensionPlugin.getInstance().getRegistry();
Expand Down Expand Up @@ -106,10 +110,10 @@ protected IProject[] build( int kind,
medFile.deleteMarkers(null, true, IResource.DEPTH_INFINITE);

// parse to get parse problems
parser.parse(medFile.getContents(), ExtensionPlugin.getInstance().createDefaultModelObjectExtensionAssistant());
ModelExtensionDefinition med = parser.parse(medFile.getContents(), ExtensionPlugin.getInstance().createDefaultModelObjectExtensionAssistant());

// create new problem markers
createMarkers(medFile, parser.getErrors(), parser.getWarnings(), parser.getInfos());
createMarkers(medFile, med, parser.getErrors(), parser.getWarnings(), parser.getInfos());
} catch (Exception e) {
IStatus parseStatus = new Status(IStatus.ERROR, PLUGIN_ID, NLS.bind(Messages.medFileParseErrorMsg,
medFile.getName()), e);
Expand Down Expand Up @@ -177,7 +181,7 @@ protected void clean( IProgressMonitor monitor ) throws CoreException {
monitor.beginTask(Messages.medCleanTaskName, (medFilesToClean.size() + modelFilesToClean.size()));

// clean all MED problem markers
for (IFile medFile : visitor.getMedFiles()) {
for (IFile medFile : medFilesToClean) {
try {
monitor.subTask(NLS.bind(Messages.medCleanSubTaskName, medFile.getName()));
medFile.deleteMarkers(null, true, IResource.DEPTH_INFINITE);
Expand All @@ -191,7 +195,7 @@ protected void clean( IProgressMonitor monitor ) throws CoreException {
}

// clean MED-related problem markers in Teiid Designer models
for (IFile modelFile : medFilesToClean) {
for (IFile modelFile : modelFilesToClean) {
try {
monitor.subTask(NLS.bind(Messages.medCleanSubTaskName, modelFile.getName()));
modelFile.deleteMarkers(ExtensionIds.PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
Expand All @@ -212,10 +216,14 @@ protected void clean( IProgressMonitor monitor ) throws CoreException {
* @param file the MED or model file who will create the problem marker (precondition: not <code>null</code>)
* @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 hasLegacyNames when 'true' adds "hasLegacyNames" attribute to the marker
*/
private void createMarker( IFile file,
int severity,
String message ) {
String message,
String markerId,
boolean hasLegacyNames) {
// parameters
assert (file != null) : "file is null"; //$NON-NLS-1$
assert ((message != null) && !message.isEmpty()) : "message is empty"; //$NON-NLS-1$
Expand All @@ -238,9 +246,10 @@ private void createMarker( IFile file,
Map attributes = new HashMap();
attributes.put(IMarker.SEVERITY, severity);
attributes.put(IMarker.MESSAGE, message);
if(hasLegacyNames) attributes.put(HAS_LEGACY_NAMES, true);

try {
MarkerUtilities.createMarker(file, attributes, ExtensionIds.PROBLEM_MARKER);
MarkerUtilities.createMarker(file, attributes, markerId);
} catch (CoreException e) {
UTIL.log(e);
}
Expand All @@ -254,6 +263,7 @@ private void createMarker( IFile file,
* @throws Exception if there is a problem writing the markers to the resource
*/
private void createMarkers( IFile medFile,
ModelExtensionDefinition med,
Collection<String> errors,
Collection<String> warnings,
Collection<String> infos ) throws Exception {
Expand All @@ -264,24 +274,47 @@ private void createMarkers( IFile medFile,

// create errors
for (String message : errors) {
createMarker(medFile, IMarker.SEVERITY_ERROR, message);
createMarker(medFile, IMarker.SEVERITY_ERROR, message, ExtensionIds.PROBLEM_MARKER, false);
}

// create warnings
for (String message : warnings) {
createMarker(medFile, IMarker.SEVERITY_WARNING, message);
createMarker(medFile, IMarker.SEVERITY_WARNING, message ,ExtensionIds.PROBLEM_MARKER, false);
}

// create infos
for (String message : infos) {
createMarker(medFile, IMarker.SEVERITY_INFO, message);
createMarker(medFile, IMarker.SEVERITY_INFO, message, ExtensionIds.PROBLEM_MARKER, false);
}

// Check for Legacy 'com.metamatrix' classnames
if(medHasLegacyClassnames(med)) {
createMarker(medFile, IMarker.SEVERITY_ERROR, Messages.medFileHasLegacyClassnames, ExtensionIds.PROBLEM_MARKER, true);
}
}

private boolean medsAreEqual( ModelExtensionDefinition thisMed,
ModelExtensionDefinition thatMed ) {
return thisMed.equals(thatMed);
}

/*
* Determine if the supplied MED contains property references to the legacy 'com.metamatrix' class names
* @param theMed the supplied MED
* @return 'true' if the MED contains properties that reference 'com.metamatrix' class names, 'false' if not.
*/
private boolean medHasLegacyClassnames( ModelExtensionDefinition theMed ) {
boolean hasLegacyClassnames = false;
Map<String, Collection<ModelExtensionPropertyDefinition>> propMap = theMed.getPropertyDefinitions();
Set<String> mapKeys = propMap.keySet();
for(String mapKey : mapKeys) {
if(mapKey.startsWith(LEGACY_CLASSNAME_PREFIX)) {
hasLegacyClassnames = true;
break;
}
}
return hasLegacyClassnames;
}

/**
* @param modelFile the model file whose MED-related problem markers are being refreshed (cannot be <code>null</code>)
Expand All @@ -293,18 +326,25 @@ void refreshModelFileMarkers( IFile modelFile ) throws Exception {

// if there is no assistant than the MED is not registered
if ((temp == null) || (!(temp instanceof ModelObjectExtensionAssistant))) {
createMarker(modelFile, IMarker.SEVERITY_WARNING, NLS.bind(Messages.modelMedNotFoundInRegistry, namespacePrefix));
createMarker(modelFile, IMarker.SEVERITY_WARNING, NLS.bind(Messages.modelMedNotFoundInRegistry, namespacePrefix), ExtensionIds.PROBLEM_MARKER, false);
} else {
ModelObjectExtensionAssistant registryAssistant = (ModelObjectExtensionAssistant)temp;
ModelExtensionDefinition registryMed = registryAssistant.getModelExtensionDefinition();
ModelObjectExtensionAssistant modelAssistant = ExtensionPlugin.getInstance()
.createDefaultModelObjectExtensionAssistant(namespacePrefix);
ModelExtensionDefinition modelMed = modelAssistant.getModelExtensionDefinition(modelFile);

// Add marker if Model has properties with the legacy Class names ("com.metamatrix")
// No further analysis is done until legacy names are corrected.
if (medHasLegacyClassnames(modelMed)) {
createMarker(modelFile, IMarker.SEVERITY_ERROR, Messages.modelMedHasLegacyClassnames, ExtensionIds.PROBLEM_MARKER, true);
return;
}

if (!medsAreEqual(registryMed, modelMed)) {
// make sure MED is same version as the registered one
createMarker(modelFile, IMarker.SEVERITY_WARNING,
NLS.bind(Messages.modelMedDifferentVersionThanOneFoundInRegistry, namespacePrefix));
NLS.bind(Messages.modelMedDifferentVersionThanOneFoundInRegistry, namespacePrefix), ExtensionIds.PROBLEM_MARKER, false);
}
}
}
Expand Down

0 comments on commit f788717

Please sign in to comment.