private List<Long[]> getDtoProdAndVersionList(List<Product> products, Region region) {
   ArrayList<Long[]> list = new ArrayList<>();
   for (Product product : products) {
     ProductVersion version = pickOne(product.getProductVersions(), region, true);
     if (version == null) {
       continue;
     }
     list.add(new Long[] {product.getId(), version.getId()});
   }
   return list;
 }
 private ProductVersion pickOne(
     List<ProductVersion> productVersions, Region region, boolean iCareAboutAmis) {
   for (ProductVersion version : productVersions) {
     if ((trialEnvironmentDao.countByProductVersionAndRegionAndAvailable(version, region, true)
         > 0)) {
       if (iCareAboutAmis && version.getAmiDescriptors().size() < 1) {
         continue;
       }
       return version;
     }
   }
   return null;
 }
  private DeployRequestDto getTrialRequestFor(
      User user, ProductVersion productVersion, Region region, Date createdAt) {
    DeployRequestDto dto = new DeployRequestDto();
    dto.setUserId(user.getId());
    dto.setDeploymentName(user.getUsername() + ":" + productVersion.getProduct().getShortName());
    dto.setDeploymentType(DeploymentType.INFOR24);
    dto.setRegionId(region.getId());
    dto.setCreatedAt(createdAt);
    ArrayList<Long[]> productIds = new ArrayList<>();
    productIds.add(new Long[] {productVersion.getProduct().getId(), productVersion.getId()});
    dto.setProductIds(productIds);

    return dto;
  }
예제 #4
0
  @Test
  public void testAddTrialEnvironment() throws Exception {
    loginTestUser();
    List<TrialEnvironment> environments = trialService.getEnvironments(1L);
    int enviroSize = environments.size();

    User user = new User();
    user.setUsername("*****@*****.**");
    user.setFirstName("Test");
    user.setLastName("Test");
    user.setCreatedAt(new Date());
    user.getRoles().add(Role.ROLE_EXTERNAL);
    user.setPassword(securityService.encodePassword("test", user.getCreatedAt()));
    userDao.save(user);

    Product product = new Product();
    product.setShortName("Test");
    product.setName("Test Long");

    productService.addProduct(product);

    ProductVersion productVersion = new ProductVersion();
    productVersion.setName("Test-version");
    productVersion.setCreatedAt(new Date());
    productVersion.setProduct(product);
    productVersion.setIeOnly(true);
    productVersionDao.save(productVersion);
    product.getProductVersions().add(productVersion);
    productDao.save(product);

    emService.flush();

    TrialDto trial = new TrialDto();
    trial.setProductId(product.getId());
    trial.setProductVersionId(productVersion.getId());
    trial.setUserId(user.getId());
    trial.setUrl("http://test/hahahaha");
    trial.setUsername("test");
    trial.setPassword("haha");
    trialService.createTrialEnvironment(trial);
    emService.flush();

    environments = trialService.getEnvironments(product.getId());
    assertEquals(enviroSize + 1, environments.size());
  }