public Element exec(Element params, ServiceContext context) throws Exception
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
DataManager dm = gc.getBean(DataManager.class);
UserSession session = context.getUserSession();
String id = Utils.getIdentifierFromParameters(params, context);
String access = Util.getParam(params, Params.ACCESS, Params.Access.PUBLIC);
//--- resource required is public (thumbnails)
if (access.equals(Params.Access.PUBLIC)) {
File dir = new File(Lib.resource.getDir(context, access, id));
String fname = Util.getParam(params, Params.FNAME);
if (fname.contains("..")) {
throw new BadParameterEx("Invalid character found in resource name.", fname);
}
File file = new File(dir, fname);
return BinaryFile.encode(200, file.getAbsolutePath(),false);
}
//--- from here on resource required is private datafile(s)
//--- check if disclaimer for this metadata has been displayed
Element elData = (Element) session.getProperty(Geonet.Session.FILE_DISCLAIMER);
if (elData == null) {
return new Element("response");
} else {
String idAllowed = elData.getChildText(Geonet.Elem.ID);
if (idAllowed == null || !idAllowed.equals(id)) {
return new Element("response");
}
}
//--- check whether notify is required
boolean doNotify = false;
Lib.resource.checkPrivilege(context, id, ReservedOperation.download);
doNotify = true;
//--- set username for emails and logs
String username = session.getUsername();
if (username == null) username = "internet";
String userId = session.getUserId();
//--- get feedback/reason for download info passed in & record in 'entered'
// String name = Util.getParam(params, Params.NAME);
// String org = Util.getParam(params, Params.ORG);
// String email = Util.getParam(params, Params.EMAIL);