.getParam(params, "relation", "true");
UserSession session = context.getUserSession();
Log.info(Geonet.MEF, "Create export task for selected metadata(s).");
SelectionManager selectionManger = SelectionManager.getManager(session);
Set<String> uuids = selectionManger
.getSelection(SelectionManager.SELECTION_METADATA);
Set<String> uuidsBeforeExp = Collections
.synchronizedSet(new HashSet<String>(0));
Log.info(Geonet.MEF, "Current record(s) in selection: " + uuids.size());
uuidsBeforeExp.addAll(uuids);
// If provided uuid, export the metadata record only
if (uuid != null) {
SelectionManager.getManager(session).close(SelectionManager.SELECTION_METADATA);
SelectionManager.getManager(session).addSelection(
SelectionManager.SELECTION_METADATA, uuid);
uuids = selectionManger
.getSelection(SelectionManager.SELECTION_METADATA);
}
// If provided uuid, export the metadata record only
if (uuid != null) {
SelectionManager.getManager(session).close(SelectionManager.SELECTION_METADATA);
SelectionManager.getManager(session).addSelection(
SelectionManager.SELECTION_METADATA, uuid);
uuids = selectionManger
.getSelection(SelectionManager.SELECTION_METADATA);
}
// MEF version 1 only support one metadata record by file.
// Uuid parameter MUST be set and add to selection manager before
// export.
if (version == null) {
file = MEFLib.doExport(context, uuid, format, skipUUID, resolveXlink, removeXlinkAttribute);
} else {
// MEF version 2 support multiple metadata record by file.
if (relatedMetadataRecord.equals("true")) {
// Adding children in MEF file
Set<String> tmpUuid = new HashSet<String>();
for (Iterator<String> iter = uuids.iterator(); iter.hasNext();) {
String _uuid = (String) iter.next();
// Creating request for services search
Element childRequest = new Element("request");
childRequest.addContent(new Element("parentUuid")
.setText(_uuid));
childRequest.addContent(new Element("to").setText("1000"));
// Get children to export - It could be better to use GetRelated service TODO
Set<String> childs = getUuidsToExport(_uuid, context,
childRequest);
if (childs.size() != 0) {
tmpUuid.addAll(childs);
}
// Creating request for services search
Element servicesRequest = new Element(Jeeves.Elem.REQUEST);
servicesRequest.addContent(new Element(
org.fao.geonet.constants.Params.OPERATES_ON)
.setText(_uuid));
servicesRequest.addContent(new Element(
org.fao.geonet.constants.Params.TYPE)
.setText("service"));
// Get linked services for export
Set<String> services = getUuidsToExport(_uuid, context,
servicesRequest);
if (services.size() != 0) {
tmpUuid.addAll(services);
}
}
if (selectionManger.addAllSelection(
SelectionManager.SELECTION_METADATA, tmpUuid))
Log.info(Geonet.MEF,
"Child and services added into the selection");
}
uuids = selectionManger
.getSelection(SelectionManager.SELECTION_METADATA);
Log.info(Geonet.MEF, "Building MEF2 file with " + uuids.size()
+ " records.");
file = MEFLib
.doMEF2Export(context, uuids, format, false, stylePath, resolveXlink, removeXlinkAttribute);
}
// -- Reset selection manager
selectionManger.close();
selectionManger.addAllSelection(SelectionManager.SELECTION_METADATA,
uuidsBeforeExp);
String fname = String.valueOf(Calendar.getInstance().getTimeInMillis());
return BinaryFile.encode(200, file, "export-" + format + "-" + fname