boolean isModified = false;
//Load Module header and globals and imports
String moduleUUID = item.getModule().getUUID();
Module module = repositoryModuleService.loadModule( moduleUUID );
ModuleHeader mh = ModuleHeaderHelper.parseHeader( module.header );
//Make collections of existing items so we don't duplicate them when adding the new
Map<String, String> existingGlobals = new HashMap<String, String>();
for ( ModuleHeader.Global g : mh.getGlobals() ) {
existingGlobals.put( g.getName(),
g.getType() );
}
List<String> existingImports = new ArrayList<String>();
for ( ModuleHeader.Import i : mh.getImports() ) {
existingImports.add( i.getType() );
}
//Add globals
if ( globals != null ) {
for ( Global g : globals ) {
if ( !existingGlobals.containsKey( g.getIdentifier() ) ) {
isModified = true;
result.addMessage( "Created Global '" + g.getIdentifier() + "' of type '" + g.getClassName() + "'.",
ConversionMessageType.INFO );
mh.getGlobals().add( new ModuleHeader.Global( g.getClassName(),
g.getIdentifier() ) );
} else {
if ( !existingGlobals.get( g.getIdentifier() ).equals( g.getClassName() ) ) {
result.addMessage( "Global '" + g.getIdentifier() + "' is already declared. Type '" + existingGlobals.get( g.getIdentifier() ) + "'. Cannot create from Worksheet.",
ConversionMessageType.WARNING );
}
}
}
}
//Add imports
if ( imports != null ) {
for ( Import i : imports ) {
if ( !existingImports.contains( i.getClassName() ) ) {
isModified = true;
result.addMessage( "Created Import for '" + i.getClassName() + "'.",
ConversionMessageType.INFO );
mh.getImports().add( new ModuleHeader.Import( i.getClassName() ) );
}
}
}
//Save update