package nl.idgis.publisher.harvester.sources;

import nl.idgis.publisher.provider.protocol.metadata.MetadataItem;

public class ProviderUtils {

	public static String getTableName(MetadataItem metadataItem) {
		String alternateTitle = metadataItem.getAlternateTitle();
		
		if(alternateTitle != null 
			&& !alternateTitle.trim().isEmpty()) {			 
		
			if(alternateTitle.contains(" ")) {
				return alternateTitle.substring(0, alternateTitle.indexOf(" ")).trim();
			} else {
				return alternateTitle.trim();
			}
		}
		
		return null;
	}
	
	public static String getCategoryId(MetadataItem metadataItem) {
		String tableName = getTableName(metadataItem);
		
		if(tableName != null) {
			int separator = tableName.indexOf(".");
			if(separator != -1) {
				String schemaName = tableName.substring(0, separator);
				return schemaName;
			}
		}
		
		return null;
	}
}

@@ -355,16 +355,44 @@
 %09 %0D%0A%09%09%0D%0A
+%09%09%09final String tableName;%0D%0A
 %09%09%09if(al
@@ -418,38 +418,43 @@
 ns(%22 %22)) %7B%0D%0A%09%09%09%09
-return
+tableName =
  alternateTitle.
@@ -521,22 +521,27 @@
  %7B%0D%0A%09%09%09%09
-return
+tableName =
  alterna
@@ -555,32 +555,73 @@
 .trim();%0D%0A%09%09%09%7D%0D%0A
+%09%09%09%0D%0A%09%09%09return tableName.toUpperCase();%0D%0A
 %09%09%7D%0D%0A%09%09%0D%0A%09%09retur

table name converted to uppercase