Element result = new Element(Jeeves.Elem.RESPONSE);
GeonetContext gc = (GeonetContext) context
.getHandlerContext(Geonet.CONTEXT_NAME);
DataManager dataMan = gc.getBean(DataManager.class);
SchemaManager schemaMan = gc.getBean(SchemaManager.class);
String siteId = gc.getBean(SettingManager.class).getSiteId();
int owner = context.getUserSession().getUserIdAsInt();
Log.info(Geonet.DATA_MANAGER, "Loading templates for schemas "
+ schemaList);
String schemas[] = schemaList.split(",");
for (String schemaName : schemas) {
Element schema = new Element(schemaName);
String schemaDir = schemaMan.getSchemaTemplatesDir(schemaName);
if (schemaDir == null) {
Log.error(Geonet.DATA_MANAGER, "Skipping - No templates?");
continue;
}
File templateFiles[] = new File(schemaDir).listFiles();
List<File> templateFilesList = new ArrayList<File>();
if (templateFiles != null) {
for (File file : templateFiles)
if (file.getName().endsWith(".xml"))
templateFilesList.add(file);
}
final String prefix = "sub-";
final int prefixLength = prefix.length();
for (File temp : templateFilesList) {
String status = "failed";
String templateName = temp.getName();
Element template = new Element("template");
template.setAttribute("name", templateName);
if (Log.isDebugEnabled(Geonet.DATA_MANAGER)) {
Log.debug(Geonet.DATA_MANAGER,
" - Adding template file (for schema " + schemaName + "): " + templateName);
}
try {
Element xml = Xml.loadFile(temp);
String uuid = UUID.randomUUID().toString();
String isTemplate = "y";
String title = null;
if (templateName.startsWith(prefix)) {
isTemplate = "s";
title = templateName.substring(prefixLength,
templateName.length() - prefixLength);
}
//
// insert metadata
//
String groupOwner = "1";
String docType = null, category = null, createDate = null, changeDate = null;
boolean ufo = true, indexImmediate = true;
dataMan.insertMetadata(context, schemaName, xml, uuid, owner, groupOwner, siteId,
isTemplate, docType, category, createDate, changeDate, ufo, indexImmediate);
status = "loaded";
} catch (Exception e) {
serviceStatus = "false";