Example #1
0
  public SettingValue<?> get(final Context c, final Scope s, final String key) {
    Object got =
        new SynchronizationTask<Object>() {
          @Override
          protected Object execute(SessionContext ctx) {

            ScopeEntity scope = getScope(c, s);
            if (scope == null) {
              return null; // Property doesn't exist
            } else {
              return scope.getValue(key);
            }
          }
        }.executeWith(chromatticLifeCycle);

    if (got instanceof Long) {
      return SettingValue.create((Long) got);
    } else if (got instanceof String) {
      return SettingValue.create((String) got);
    } else if (got instanceof Double) {
      return SettingValue.create((Double) got);
    } else if (got instanceof Boolean) {
      return SettingValue.create((Boolean) got);
    }
    return null;
  }
 private int getSkippedNumber() {
   SettingValue settingValue =
       settingService.get(Context.GLOBAL, Scope.GLOBAL, SOFTWARE_REGISTRATION_SKIPPED);
   if (settingValue != null) {
     return Integer.parseInt(settingValue.getValue().toString());
   }
   settingService.set(
       Context.GLOBAL, Scope.GLOBAL, SOFTWARE_REGISTRATION_SKIPPED, new SettingValue<Object>("0"));
   return 0;
 }
  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    SettingService settingService =
        PortalContainer.getInstance().getComponentInstanceOfType(SettingService.class);
    SoftwareRegistrationService softwareRegistrationService =
        PortalContainer.getInstance().getComponentInstanceOfType(SoftwareRegistrationService.class);

    if (softwareRegistrationService.isSoftwareRegistered()) {
      response.sendRedirect("/");
      return;
    }
    String code = request.getParameter("code");
    if (StringUtils.isEmpty(code)) {
      try {
        getServletContext().getRequestDispatcher(SR_JSP_RESOURCE).forward(request, response);
      } catch (Exception se) {
        if (LOG.isErrorEnabled()) {
          LOG.error(se);
        }
        response.sendRedirect("/");
      }
      return;
    }

    SoftwareRegistration softwareRegistration =
        softwareRegistrationService.registrationPLF(code, getRegistrationURL(request));
    if (softwareRegistration.isPushInfo()) {
      settingService.set(
          Context.GLOBAL,
          Scope.GLOBAL,
          SoftwareRegistrationService.SOFTWARE_REGISTRATION_NODE,
          SettingValue.create("Software registered:" + "true"));
      softwareRegistrationService.checkSoftwareRegistration();
      getServletContext().setAttribute("status", "success");
    } else if (softwareRegistration.isNotReachable()) {
      request.getSession().setAttribute("notReachable", "true");
      getServletContext().getRequestDispatcher(SR_JSP_RESOURCE).forward(request, response);
      return;
    } else {
      getServletContext().setAttribute("status", "failed");
      request.getSession().setAttribute("notReachable", "true");
      response.sendRedirect("/");
      return;
    }
    getServletContext().getRequestDispatcher(SR_JSP_RESOURCE_SUCCESS).forward(request, response);
    return;
  }