Skip to content

Commit d589cb7

Browse files
committed
make mef importer take info.xml isTemplate field into account when present
1 parent f586361 commit d589cb7

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

core/src/main/java/org/fao/geonet/kernel/mef/Importer.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public static List<String> doImport(final Element params, final ServiceContext c
9090
}
9191

9292
public static List<String> doImport(String fileType, final MEFLib.UuidAction uuidAction, final String style, final String source,
93-
final MetadataType isTemplate, final String[] category, final String groupId, final boolean validate, final boolean assign,
93+
final MetadataType isTemplateParam, final String[] category, final String groupId, final boolean validate, final boolean assign,
9494
final ServiceContext context, final Path mefFile) throws Exception {
9595
ApplicationContext applicationContext = ApplicationContextHolder.get();
9696
final IMetadataSchemaUtils metadataSchemaUtils = applicationContext.getBean(IMetadataSchemaUtils.class);
@@ -105,6 +105,8 @@ public static List<String> doImport(String fileType, final MEFLib.UuidAction uui
105105
// Load preferred schema and set to iso19139 by default
106106
String preferredSchema = applicationContext.getBean(ServiceConfig.class).getValue("preferredSchema", "iso19139");
107107

108+
final MetadataType[] isTemplate = {isTemplateParam};
109+
108110
final List<String> metadataIdMap = new ArrayList<>();
109111
final List<Element> md = new ArrayList<>();
110112
final List<Element> fc = new ArrayList<>();
@@ -281,6 +283,20 @@ public void handleInfo(Element info, int index) throws Exception {
281283
if (schema == null)
282284
throw new Exception("Unknown schema");
283285

286+
Element generalElem = info.getChild("general");
287+
if (generalElem != null) {
288+
String isTemplateStr = generalElem.getChildText("isTemplate");
289+
if (isTemplateStr != null && !isTemplateStr.trim().isEmpty()) {
290+
if ("false".equalsIgnoreCase(isTemplateStr.trim())) {
291+
isTemplate[0] = MetadataType.METADATA;
292+
} else if ("true".equalsIgnoreCase(isTemplateStr.trim())) {
293+
isTemplate[0] = MetadataType.TEMPLATE;
294+
} else {
295+
isTemplate[0] = org.fao.geonet.domain.MetadataType.lookup(isTemplateStr.trim());
296+
}
297+
}
298+
}
299+
284300
// Handle non MEF files insertion
285301
if (info.getChildren().isEmpty()) {
286302
if (category != null) {
@@ -298,13 +314,13 @@ public void handleInfo(Element info, int index) throws Exception {
298314
privileges.addContent(new Element("operation").setAttribute("name", "dynamic"));
299315
privileges.addContent(new Element("operation").setAttribute("name", "featured"));
300316

301-
if (isTemplate == MetadataType.METADATA) {
317+
if (isTemplate[0] == MetadataType.METADATA) {
302318
// Get the Metadata uuid if it's not a template.
303319
uuid = metadataUtils.extractUUID(schema, md.get(index));
304-
} else if (isTemplate == MetadataType.SUB_TEMPLATE) {
320+
} else if (isTemplate[0] == MetadataType.SUB_TEMPLATE) {
305321
// Get subtemplate uuid if defined in @uuid at root
306322
uuid = md.get(index).getAttributeValue("uuid");
307-
} else if (isTemplate == MetadataType.TEMPLATE_OF_SUB_TEMPLATE) {
323+
} else if (isTemplate[0] == MetadataType.TEMPLATE_OF_SUB_TEMPLATE) {
308324
// Get subtemplate uuid if defined in @uuid at root
309325
uuid = md.get(index).getAttributeValue("uuid");
310326
}
@@ -360,7 +376,7 @@ public void handleInfo(Element info, int index) throws Exception {
360376

361377
try {
362378
importRecord(uuid, uuidAction, md, schema, index, source, sourceName, sourceTranslations, context, metadataIdMap,
363-
createDate, changeDate, groupId, isTemplate);
379+
createDate, changeDate, groupId, isTemplate[0]);
364380
} catch (Exception e) {
365381
throw new Exception("Failed to import metadata with uuid '" + uuid + "'. " + e.getLocalizedMessage(), e);
366382
}
@@ -381,7 +397,7 @@ public void handleInfo(Element info, int index) throws Exception {
381397
String category = null;
382398
boolean ufo = false;
383399
String fcId = metadataManager
384-
.insertMetadata(context, "iso19110", fc.get(index), uuid, userid, group, source, isTemplate.codeString, docType,
400+
.insertMetadata(context, "iso19110", fc.get(index), uuid, userid, group, source, isTemplate[0].codeString, docType,
385401
category, createDate, changeDate, ufo, IndexingMode.full);
386402

387403
if (Log.isDebugEnabled(Geonet.MEF))
@@ -417,7 +433,7 @@ public void apply(@Nonnull final AbstractMetadata metadata) {
417433
if (finalRating != null) {
418434
dataInfo.setRating(Integer.valueOf(finalRating));
419435
}
420-
dataInfo.setType(isTemplate);
436+
dataInfo.setType(isTemplate[0]);
421437

422438
metadata.getHarvestInfo().setHarvested(false);
423439

0 commit comments

Comments
 (0)