/**
  * Methode permettant de mettre l'application dans un état particulier pour se prémunir d'éventuel
  * problème de concurrence au niveau métier
  */
 @Override
 @Transactional
 public void setStatus(Application application, Status status) throws ServiceException {
   try {
     Application _application = applicationDAO.findOne(application.getId());
     _application.setStatus(status);
     application.setStatus(status);
     applicationDAO.saveAndFlush(_application);
   } catch (PersistenceException e) {
     throw new ServiceException(e.getLocalizedMessage(), e);
   }
 }
Example #2
0
 @RequestMapping(value = "/jobs/{jobId}/delete")
 public String deleteJob(@PathVariable String jobId, HttpServletRequest request, ModelMap model) {
   User user = (User) request.getSession().getAttribute("user");
   if (user == null) {
     model.addAttribute("errorMsg", "User has no permission");
     return "login";
   }
   try {
     // Archive applications as well
     List<Application> applications =
         ApplicationsDao.instance.getByJob(ORSKEY, user.getShortKey(), jobId);
     if (request.getParameter("selectedCandidate") != null) {
       for (Application a : applications) {
         a.setStatus(ApplicationStatus.ARCHIVED);
         ApplicationsDao.instance.update(a);
       }
     }
     JobsDao.instance.delete(ORSKEY, user.getShortKey(), jobId);
     return "redirect:/jobs";
   } catch (Exception e) {
     e.printStackTrace();
     model.addAttribute("errorMsg", e.getMessage());
     return "error";
   }
 }
Example #3
0
 @RequestMapping(
     value = "/jobs/{jobId}/shortlist",
     method = {RequestMethod.POST})
 public String submitShortlist(
     @PathVariable String jobId, HttpServletRequest request, ModelMap model) {
   User user = (User) request.getSession().getAttribute("user");
   if (user == null || !user.getRole().equals("manager")) {
     model.addAttribute("errorMsg", "User has no permission");
     return "login";
   }
   try {
     Job j = JobsDao.instance.getById(jobId);
     List<Application> applications =
         ApplicationsDao.instance.getByJob(ORSKEY, user.getShortKey(), jobId);
     DetailedJob dj = new DetailedJob(j);
     dj.setApplications(ORSKEY, user.getShortKey(), (ArrayList<Application>) applications);
     if (!dj.getStatus().equals(RecruitmentStatus.IN_REVIEW) && dj.allApplicationsReviewed()) {
       return "redirect:/jobs";
     }
     for (Application a : applications) {
       if (request.getParameter(a.get_appId()) != null) {
         a.setStatus(ApplicationStatus.SHORTLISTED);
         // TODO send invitations
       } else {
         a.setStatus(ApplicationStatus.FINALISED);
         // TODO send notifications
       }
       ApplicationsDao.instance.update(a);
     }
     j.setStatus(RecruitmentStatus.SENT_INVITATIONS);
     JobsDao.instance.update(ORSKEY, user.getShortKey(), j);
     return "redirect:/jobs";
   } catch (Exception e) {
     e.printStackTrace();
     model.addAttribute("errorMsg", e.getMessage());
     return "error";
   }
 }
Example #4
0
 @RequestMapping(value = "/jobs/{jobId}/startAutoChecks")
 public String doAutoChecks(
     @PathVariable String jobId,
     HttpServletRequest request,
     RedirectAttributes redirectAttrs,
     ModelMap model) {
   User user = (User) request.getSession().getAttribute("user");
   if (user == null || !user.getRole().equals("manager")) {
     model.addAttribute("errorMsg", "User has no permission");
     return "login";
   }
   try {
     List<Application> applications =
         ApplicationsDao.instance.getByJob(ORSKEY, user.getShortKey(), jobId);
     for (Application a : applications) {
       AutoCheckRequest req = new AutoCheckRequest();
       req.setLicenseNo(a.getLicenseNo());
       req.setFullName(a.getFullName());
       req.setPostcode(a.getPostcode());
       AutoCheckResponse response = autoCheckService.check(req);
       String pdvResult = response.getPdvResult();
       String crvResult = response.getCrvResult();
       // save result to API
       AutoCheckResult newAutoCheckResult = new AutoCheckResult();
       newAutoCheckResult.set_appId(a.get_appId());
       newAutoCheckResult.setPdvResult(pdvResult);
       newAutoCheckResult.setCrvResult(crvResult);
       AutoCheckResultsDao.instance.create(ORSKEY, user.getShortKey(), newAutoCheckResult);
     }
     Job j = JobsDao.instance.getById(jobId);
     if (j.getAssignedTeam() != null) {
       j.setStatus(RecruitmentStatus.IN_REVIEW);
       JobsDao.instance.update(ORSKEY, user.getShortKey(), j);
       // update status for all applications of the job
       for (Application a : applications) {
         a.setStatus(ApplicationStatus.IN_REVIEW);
         ApplicationsDao.instance.update(a);
       }
     }
     redirectAttrs.addFlashAttribute("successMsg", "Auto-checks run successfully");
     return "redirect:/jobs";
   } catch (Exception e) {
     e.printStackTrace();
     model.addAttribute("errorMsg", e.getMessage());
     return "error";
   }
 }
Example #5
0
 @RequestMapping(
     value = "/jobs/{jobId}/finalList",
     method = {RequestMethod.POST})
 public String submitfinalList(
     @PathVariable String jobId, HttpServletRequest request, ModelMap model) {
   User user = (User) request.getSession().getAttribute("user");
   if (user == null || !user.getRole().equals("manager")) {
     model.addAttribute("errorMsg", "User has no permission");
     return "login";
   }
   try {
     Job j = JobsDao.instance.getById(jobId);
     if (!j.getStatus().equals(RecruitmentStatus.SENT_INVITATIONS)) {
       return "redirect:/jobs";
     }
     List<Application> applications =
         ApplicationsDao.instance.getByJob(ORSKEY, user.getShortKey(), jobId);
     if (request.getParameter("selectedCandidate") != null) {
       for (Application a : applications) {
         if (a.getStatus().equals(ApplicationStatus.ARCHIVED)) {
           continue;
         }
         if (request.getParameter("selectedCandidate").equals(a.get_appId())) {
           // TODO send notifications
         } else {
           // TODO send notifications
         }
         a.setStatus(ApplicationStatus.FINALISED);
         ApplicationsDao.instance.update(a);
       }
       j.setStatus(RecruitmentStatus.FINALISED);
       JobsDao.instance.update(ORSKEY, user.getShortKey(), j);
     }
     return "redirect:/jobs";
   } catch (Exception e) {
     e.printStackTrace();
     model.addAttribute("errorMsg", e.getMessage());
     return "error";
   }
 }
Example #6
0
  @RequestMapping(
      value = "/jobs/{jobId}/update",
      method = {RequestMethod.POST})
  public String updateJob(@PathVariable String jobId, HttpServletRequest request, ModelMap model) {
    User user = (User) request.getSession().getAttribute("user");
    if (user == null) {
      model.addAttribute("errorMsg", "User has no permission");
      return "login";
    }
    String closingDate = request.getParameter("closingDate");
    String salary = request.getParameter("salary");
    String positionType = request.getParameter("positionType");
    String location = request.getParameter("location");
    String description = request.getParameter("description");
    String status = request.getParameter("status");
    String assignedTeam = request.getParameter("assignedTeam");

    Job updatedJob = JobsDao.instance.getById(jobId);
    if (closingDate != null) {
      updatedJob.setClosingDate(closingDate);
    }
    if (salary != null) {
      updatedJob.setSalary(Integer.parseInt(salary));
    }
    if (positionType != null) {
      updatedJob.setPositionType(positionType);
    }
    if (location != null) {
      updatedJob.setLocation(location);
    }
    if (description != null) {
      updatedJob.setDescription(description);
    }
    if (status != null) {
      updatedJob.setStatus(RecruitmentStatus.valueOf(status));
    }
    if (assignedTeam != null) {
      if (assignedTeam.isEmpty()) {
        assignedTeam = null;
      } else { // if hiring team is assigned and auto-check is done, proceed to next recruitment
               // stage
        DetailedJob j = new DetailedJob(JobsDao.instance.getById(jobId));
        j.setApplications(
            ORSKEY,
            user.getShortKey(),
            (ArrayList<Application>)
                ApplicationsDao.instance.getByJob(ORSKEY, user.getShortKey(), jobId));
        if (j.allApplicationsAutoChecked()) {
          updatedJob.setStatus(RecruitmentStatus.IN_REVIEW);
          // update status for all applications of the job
          List<Application> applications =
              ApplicationsDao.instance.getByJob(ORSKEY, user.getShortKey(), jobId);
          for (Application a : applications) {
            a.setStatus(ApplicationStatus.IN_REVIEW);
            ApplicationsDao.instance.update(a);
          }
        }
      }
      updatedJob.setAssignedTeam(assignedTeam);
    }
    if (!validateInput(
        closingDate, salary, positionType, location, description, status, assignedTeam)) {
      model.addAttribute("errorMsg", "Invalid form data");
      model.addAttribute("job", updatedJob);
      return "redirect:/jobs/" + jobId + "/edit";
    }
    try {
      JobsDao.instance.update(ORSKEY, user.getShortKey(), updatedJob);
      return "redirect:/jobs/" + jobId;
    } catch (Exception e) {
      e.printStackTrace();
      model.addAttribute("errorMsg", e.getMessage());
      return "error";
    }
  }
  /**
   * Remove an application
   *
   * @param application
   * @param user
   * @return
   * @throws ServiceException
   */
  @Override
  @Transactional
  public Application remove(Application application, User user)
      throws ServiceException, CheckException {

    try {
      logger.info("Starting removing application " + application.getName());

      // Delete all modules
      List<Module> listModules = application.getModules();
      for (Module module : listModules) {
        try {
          moduleService.remove(application, user, module, false, application.getStatus());
        } catch (ServiceException | CheckException e) {
          application.setStatus(Status.FAIL);
          logger.error(
              "ApplicationService Error : failed to remove module "
                  + module.getName()
                  + " for application "
                  + application.getName()
                  + " : "
                  + e);
          e.printStackTrace();
        }
      }

      // Delete all alias
      List<String> aliases = new ArrayList<>();
      aliases.addAll(application.getAliases());
      for (String alias : aliases) {
        removeAlias(application, alias);
      }

      // Delete all servers
      List<Server> listServers = application.getServers();
      for (Server server : listServers) {
        serverService.remove(server.getName());
        if (listServers.indexOf(server) == listServers.size() - 1) {
          hipacheRedisUtils.removeRedisAppKey(application);
          applicationDAO.delete(server.getApplication());
          portUtils.releaseProxyPorts(application);
        }
      }

      logger.info("ApplicationService : Application successfully removed ");

    } catch (PersistenceException e) {
      setStatus(application, Status.FAIL);
      logger.error(
          "ApplicationService Error : failed to remove " + application.getName() + " : " + e);

      throw new ServiceException(e.getLocalizedMessage(), e);
    } catch (ServiceException e) {
      setStatus(application, Status.FAIL);
      logger.error(
          "ApplicationService Error : failed to remove application "
              + application.getName()
              + " : "
              + e);
    }
    return application;
  }
  @Override
  @Transactional(rollbackFor = ServiceException.class)
  public Application create(String applicationName, String login, String serverName, String tagName)
      throws ServiceException, CheckException {

    // if tagname is null, we prefix with a ":"
    if (tagName != null) {
      tagName = ":" + tagName;
    }
    if (applicationName != null) {
      applicationName = applicationName.toLowerCase();
    }

    logger.info("--CALL CREATE NEW APP--");
    Application application = new Application();

    logger.info("applicationName = " + applicationName + ", serverName = " + serverName);

    User user = authentificationUtils.getAuthentificatedUser();

    // For cloning management
    if (tagName != null) {
      application.setAClone(true);
    }

    application.setName(applicationName);
    application.setUser(user);
    application.setModules(new ArrayList<>());

    // verify if application exists already
    this.checkCreate(application, serverName);

    // todo : use a session flag
    application.setStatus(Status.PENDING);

    application = this.saveInDB(application);
    serverService.checkMaxNumberReach(application);

    String subdomain = System.getenv("CU_SUB_DOMAIN") == null ? "" : System.getenv("CU_SUB_DOMAIN");

    List<Image> imagesEnabled = imageService.findEnabledImages();
    List<String> imageNames = new ArrayList<>();
    for (Image image : imagesEnabled) {
      imageNames.add(image.getName());
    }

    if (!imageNames.contains(serverName)) {
      throw new CheckException(messageSource.getMessage("server.not.found", null, locale));
    }

    try {
      // BLOC APPLICATION
      application.setDomainName(subdomain + suffixCloudUnitIO);
      application = applicationDAO.save(application);
      application.setManagerIp(dockerManagerIp);
      application.setJvmRelease(javaVersionDefault);
      application.setRestHost(restHost);
      logger.info(application.getManagerIp());

      // BLOC SERVER
      Server server = ServerFactory.getServer(serverName);
      // We get image associated to server
      Image image = imageService.findByName(serverName);
      server.setImage(image);
      server.setApplication(application);
      server.setName(serverName);
      server = serverService.create(server, tagName);

      List<Server> servers = new ArrayList<>();
      servers.add(server);
      application.setServers(servers);

      // BLOC MODULE
      Module moduleGit = this.addGitContainer(application, tagName);
      application.getModules().add(moduleGit);
      application.setGitContainerIP(moduleGit.getContainerIP());

      // Persistence for Application model
      application = applicationDAO.save(application);

      // Copy the ssh key from the server to git container to be able to deploy war with gitpush
      // During clone processus, env variables are not updated. We must wait for a restart before
      // to copy the ssh keys for git push
      if (tagName == null) {
        this.sshCopyIDToServer(application, user);
      }

    } catch (DataAccessException e) {
      throw new ServiceException(e.getLocalizedMessage(), e);
    }

    logger.info("" + application);
    logger.info(
        "ApplicationService : Application " + application.getName() + " successfully created.");

    return application;
  }