Package org.fao.geonet.kernel.setting

Examples of org.fao.geonet.kernel.setting.SettingManager


     * @return
     * @throws Exception
     */
    public Element exec(Element params, ServiceContext context) throws Exception {
        GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
        SettingManager sm = gc.getBean(SettingManager.class);

        Map<String, String> values = new HashMap<String, String>();
        for (Object obj : params.getChildren()) {
            if (obj instanceof Element) {
                Element param = (Element) obj;
                values.put(param.getName().replace('.', '/'), param.getValue());
            }
        }

        String currentUuid = sm.getSiteId();

        if (!sm.setValues(values))
            throw new OperationAbortedEx("Cannot set all values");

        // And reload services
        String newUuid = values.get(SettingManager.SYSTEM_SITE_SITE_ID_PATH);

View Full Code Here


    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);
View Full Code Here

  //--------------------------------------------------------------------------

  public Element exec(Element params, final ServiceContext context) throws Exception
  {
    GeonetContext  gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
    SettingManager sm = gc.getBean(SettingManager.class);

    String name     = Util.getParam(params, Params.NAME);
    String org      = Util.getParam(params, Params.ORG);
    String email    = Util.getParam(params, Params.EMAIL);
    String comments = Util.getParam(params, Params.COMMENTS);
    String subject  = Util.getParam(params, Params.SUBJECT, "New feedback")// TODO : i18n

    String host = sm.getValue("system/feedback/mailServer/host");
    String to   = sm.getValue("system/feedback/email");

    MailSender sender = new MailSender(context);
    sender.send(host,
            sm.getValueAsInt("system/feedback/mailServer/port"),
            sm.getValue("system/feedback/mailServer/username"),
            sm.getValue("system/feedback/mailServer/password"),
            sm.getValueAsBool("system/feedback/mailServer/ssl"),
            email, name +" ("+org+")", to, null, subject, comments);

    return new Element("response").addContent(params.cloneContent());
  }
View Full Code Here

  //----------------------------------------------------------------------------
 
  private void notifyAndLog(boolean doNotify, String id, String uuid, String access, String username, String theFile, ServiceContext context) throws Exception {

    GeonetContext  gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
    SettingManager sm = gc.getBean(SettingManager.class);
    DataManager    dm = gc.getBean(DataManager.class);

    //--- increase metadata popularity
    if (access.equals(Params.Access.PRIVATE)) {
            dm.increasePopularity(context, id);
        }

    //--- send email notification
    if (doNotify) {
     
      String site = sm.getSiteId();
      String host = sm.getValue("system/feedback/mailServer/host");
      String port = sm.getValue("system/feedback/mailServer/port");
      String from = sm.getValue("system/feedback/email");

      String fromDescr = "GeoNetwork administrator";

      String dateTime = now();
            context.info("DOWNLOADED:" + theFile + "," + id + "," + uuid + "," + context.getIpAddress() + "," + username);

      if (host.trim().length() == 0 || from.trim().length() == 0) {
                if(context.isDebugEnabled()) {
                    context.debug("Skipping email notification");
                }
      } else {
                if(context.isDebugEnabled()) {
                    context.debug("Sending email notification for file : " + theFile);
                }

                OperationAllowedRepository opAllowedRepo = context.getBean(OperationAllowedRepository.class);
                List<OperationAllowed> opsAllowed = opAllowedRepo.findByMetadataId(id);

                final GroupRepository groupRepository = context.getBean(GroupRepository.class);

                for (OperationAllowed opAllowed : opsAllowed) {
                    Group group = groupRepository.findOne(opAllowed.getId().getGroupId());
                    String  name  = group.getName();
          String  email = group.getEmail();

          if (email.trim().length() != 0) {
            String subject = "File " + theFile + " has been downloaded at "+dateTime;
            String message = "GeoNetwork (site: "+site+") notifies you, as supervisor of group "+ name
              + " that data file "+ theFile
              + " attached to metadata record with id number "+ id
              + " (uuid: "+uuid+")"
              + " has been downloaded from address " + context.getIpAddress()
              + " by user " + username
              + ".";

            try {
              MailSender sender = new MailSender(context);
              sender.send(host, Integer.parseInt(port),
                      sm.getValue("system/feedback/mailServer/username"),
                      sm.getValue("system/feedback/mailServer/password"),
                      sm.getValueAsBool("system/feedback/mailServer/ssl"),
                      from, fromDescr, email, null, subject, message);
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
View Full Code Here

      throw new IllegalArgumentException("Only users with profile RegisteredUser can change their password using this option");
        }

    // get mail settings   
    GeonetContext  gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
    SettingManager sm = gc.getBean(SettingManager.class);

    String adminEmail = sm.getValue("system/feedback/email");
    String thisSite = sm.getSiteName();

    SettingInfo si = context.getBean(SettingInfo.class);
    String siteURL = si.getSiteUrl() + context.getBaseUrl();

    // construct change key - only valid today
View Full Code Here

    String username = email;
    String password = getInitPassword();

    GeonetContext  gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
    SettingManager sm = gc.getBean(SettingManager.class);
   
    String catalogAdminEmail = sm.getValue("system/feedback/email");
    String thisSite = sm.getSiteName();


        Element element = new Element(Jeeves.Elem.RESPONSE);
        element.setAttribute(Params.SURNAME, surname);
        element.setAttribute(Params.NAME, name);
View Full Code Here

    //check change key
    if (!passwordMatches)
      throw new BadParameterEx("Change key invalid or expired", changeKey);
   
    // get mail details
    SettingManager sm = context.getBean(SettingManager.class);

    String adminEmail = sm.getValue("system/feedback/email");
    String thisSite = sm.getSiteName();

    // get site URL
    SettingInfo si = context.getBean(SettingInfo.class);
    String siteURL = si.getSiteUrl() + context.getBaseUrl();
View Full Code Here

    if (!file.exists())
      throw new ResourceNotFoundEx(fname);

    GeonetContext  gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
    SettingManager sm = gc.getBean(SettingManager.class);
    DataManager    dm = gc.getBean(DataManager.class);

    //--- increase metadata popularity
    if (access.equals(Params.Access.PRIVATE))
      dm.increasePopularity(context, id);

    //--- send email notification

    if (doNotify)
    {
      String host = sm.getValue("system/feedback/mailServer/host");
      String port = sm.getValue("system/feedback/mailServer/port");
      String from = sm.getValue("system/feedback/email");

      String fromDescr = "GeoNetwork administrator";

      if (host.trim().length() == 0 || from.trim().length() == 0)
                if(context.isDebugEnabled())
                    context.debug("Skipping email notification");
      else
      {
                if(context.isDebugEnabled()) {
                    context.debug("Sending email notification for file : "+ file);
                }

        // send emails about downloaded file to groups with notify privilege

                OperationAllowedRepository opAllowedRepo = context.getBean(OperationAllowedRepository.class);
                final GroupRepository groupRepository = context.getBean(GroupRepository.class);

                List<OperationAllowed> opsAllowed = opAllowedRepo.findByMetadataId(id);
               
        for (OperationAllowed opAllowed : opsAllowed) {
                    Group group = groupRepository.findOne(opAllowed.getId().getGroupId());
          String  name  = group.getName();
          String  email = group.getEmail();

          if (email.trim().length() != 0)
          {
              // TODO i18n
            String subject = "File " + fname + " has been downloaded";
            String message = "GeoNetwork notifies you, as contact person of group "+ name
              + " that data file "+ fname
              + " belonging metadata "+ id
              + " has beed downloaded from address " + context.getIpAddress() + ".";

            try
            {
              MailSender sender = new MailSender(context);
              sender.send(host, Integer.parseInt(port),
                      sm.getValue("system/feedback/mailServer/username"),
                      sm.getValue("system/feedback/mailServer/password"),
                      sm.getValueAsBool("system/feedback/mailServer/ssl"),
                      from, fromDescr, email, null, subject, message);
            }
            catch (Exception e)
            {
              e.printStackTrace();
View Full Code Here

      throw new BadParameterEx(Params.RATING, rat);

    String harvUuid = getHarvestingUuid(context, id);

    // look up value of localrating/enable
    SettingManager settingManager = gc.getBean(SettingManager.class);
    boolean localRating = settingManager.getValueAsBool("system/localrating/enable", false);
   
    if (localRating || harvUuid == null)
      //--- metadata is local, just rate it
      rating = dm.rateMetadata(Integer.valueOf(id), ip, rating);
    else
View Full Code Here

  public void search(ServiceContext context, Element request,
               ServiceConfig config) throws Exception
  {
    GeonetContext  gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
    SettingManager sm = gc.getBean(SettingManager.class);

    String siteId = sm.getSiteId();

    alResult = new ArrayList<String>();

    //--- get maximun delta in minutes
View Full Code Here

TOP

Related Classes of org.fao.geonet.kernel.setting.SettingManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.