Пример #1
0
  public <E> List<E> retireveProjectsForUser(String UserID) {
    List<ProjectBean> projectList = new ArrayList<ProjectBean>();
    try {

      List<UserProjectMapping> users = userProjectMappingDao.queryForAll();
      userProjectsQuery.setArgumentHolderValue(
          0, UserDAOManager.getInstance().userDetailDao.queryForId(Integer.parseInt(UserID)));
      projectList = projectDao.query(userProjectsQuery);

    } catch (NumberFormatException e) {
      logger.error("Error parsing user ID : " + e.getMessage());
    } catch (SQLException e) {
      logger.error("Error fetching projects for user " + UserID + " : " + e.getMessage());
    }
    return (List<E>) projectList;
  }
Пример #2
0
  @Override
  public StatusBean create(JsonNode newData) {
    ProjectBean projectBean = new ProjectBean();
    Gson projectData = new GsonBuilder().setDateFormat("yyyy'-'MM'-'dd HH':'mm':'ss").create();
    projectBean = projectData.fromJson(newData.toString(), ProjectBean.class);

    StatusBean statusBean = new StatusBean();

    try {

      int rowsUpdated = projectDao.create(projectBean);

      // if(rowsUpdated == 1)
      // Utilities.getInstance().changeActiveDirectory(projectBean.getProjectId());
      UserDAOManager.getInstance()
          .populateMappingBean(projectBean, newData.get("owner").getValueAsText());
      statusBean.setStatusCode(0);
      statusBean.setData(projectBean);
      Utilities.getInstance().initializeDirectory(projectBean.getProjectID());
      String scriptDir =
          Utilities.getInstance().constructProjectDirectory(projectBean.getProjectID())
              + OSProperties.getInstance().getOSFileSeparator()
              + OSProperties.getInstance().getScriptsDirName()
              + OSProperties.getInstance().getOSFileSeparator();
      Utilities.getInstance().checkIfDirExists(new File(scriptDir));
      //			File puppetScriptFile = new File(getClass().getResource("/puppet.sh").toURI());
      InputStream puppetScriptStream = getClass().getResourceAsStream("/puppet.sh");
      File puppetFile = new File("puppet.sh");
      OutputStream outputStream = new FileOutputStream(puppetFile);
      IOUtils.copy(puppetScriptStream, outputStream);

      Utilities.getInstance().copyFile(puppetFile, new File(scriptDir + "puppet.sh"));

      String nodeFileLoc =
          Utilities.getInstance().constructProjectDirectory(projectBean.getProjectID())
              + OSProperties.getInstance().getOSFileSeparator()
              + OSProperties.getInstance().getManifestsDirName()
              + OSProperties.getInstance().getOSFileSeparator()
              + "site.pp";
      boolean nodeFile = new File(nodeFileLoc).createNewFile();

      Integer providerID =
          ProviderDAOManager.getInstance()
              .providerDao
              .queryForId(projectBean.getProviderType())
              .getProviderID();
      ProjectProviderMappingBean projectProvider =
          new ProjectProviderMappingBean(projectBean.getProjectID(), providerID);
      projectProviderMappingDao.create(projectProvider);
      String providerName =
          ProviderDAOManager.getInstance()
              .providerDao
              .queryForId(projectBean.getProviderType())
              .getName();
      if (providerName.equalsIgnoreCase(CommonProperties.getInstance().getDockerProvider())) {
        Utilities.getInstance().initializeDockerVagrantFile(projectBean.getProjectID());
      } else if (providerName.equalsIgnoreCase(AwsProjectDAOManager.PROVIDER_NAME)) {
        AwsProjectDAOManager.getInstance().create(newData, projectBean);
      }
    } catch (SQLException e) {
      logger.error("Error creating a new project : " + e.getMessage());
      statusBean.setStatusCode(1);
      statusBean.setStatusMessage("Error creating project : " + e.getMessage());

    } catch (IOException e) {
      e.printStackTrace();
    }
    return statusBean;
  }