public void init(String appPath, ServiceConfig params) throws Exception {}
public Element exec(Element params, final ServiceContext context) throws Exception {
try {
GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
SettingManager sm = gc.getBean(SettingManager.class);
String NOREPLY = sm.getValue("system/feedback/email");
//
// user-supplied params
//
String phone = Util.getParam(params, Params.PHONE, "");
String sex = Util.getParam(params, Params.SEX, "");
String name = Util.getParam(params, Params.NAME, "");
String remarks = Util.getParam(params, Params.REMARKS, "");
String category = Util.getParam(params, Params.CATEGORY, "");
String function = Util.getParam(params, Params.FUNCTION, "");
String organization = Util.getParam(params, Params.ORGANIZATION, "");
String feedbackFunction = Util.getParam(params, Params.FEEDBACK_FUNCTION, "");
String email = Util.getParam(params, Params.EMAIL, "");
//
// automatic hidden params
//
String metadataOrganization = Util.getParam(params, Params.METADATA_ORGANIZATION, "");
String metadataEmail = Util.getParam(params, Params.METADATA_EMAIL, "");
String uuid = Util.getParam(params, Params.UUID, "");
String date = Util.getParam(params, Params.DATE, "");
String title = Util.getParam(params, Params.TITLE, "");
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd MMMMM yyyy 'at' hh:mm:ss z");
String currentDateTime = sdf.format(cal.getTime());
String body = "Date and time: " + currentDateTime + "\n";
if(StringUtils.isEmpty(uuid)) {
body += "Subject:\tGeneral feedback GeoNetwork catalog\n";
}
else {
body += "Subject:\tMetadata feedback GeoNetwork catalog\n";
body += "Metadata UUID: " + uuid + "\n";
body = "Metadata title: " + title + "\n";
body += "Metadata date: " + date + "\n";
body += "Metadata organization: " + metadataOrganization + "\n";
}
body = "Name:\t" + name + "\n";
body += "Sex:\t" + sex + "\n";
body += "Function:\t" + function + "\n";
body += "Organization:\t" + organization + "\n";
body += "Phone:\t" + phone + "\n" ;
body += "Email:\t" + email + "\n" ;
body += "Feedback function:\t" + feedbackFunction + "\n";
body += "Feedback category:\t" + category + "\n";
body += "Remarks:\n" + remarks;
Log.debug(Geonet.FEEDBACK, "created feedback message:\n" + body);
String subject;
if(StringUtils.isEmpty(uuid)) {
subject = "General feedback GeoNetwork catalog: " + feedbackFunction;
}
else {
subject = "Metadata feedback GeoNetwork catalog: " + feedbackFunction;
}
String host = sm.getValue("system/feedback/mailServer/host");
String port = sm.getValue("system/feedback/mailServer/port");
String to = sm.getValue("system/feedback/email");
Log.debug(Geonet.FEEDBACK, "email settings.. host: " + host + " port: " + port + " email: " + to);
JavaMailer mailer = new JavaMailer(host, port, false, null, null);