예제 #1
0
  /**
   * Add a new environment and one EnvironmentProperty for each defined property
   *
   * @param application
   * @param environmentName
   * @return
   * @throws ValidationException
   */
  @Override
  public Environment addEnvironment(Application application, String environmentName)
      throws ValidationException {
    Application app = applicationDAO.findById(application.getId());

    if (app == null) {
      String[] inserts = new String[] {application.getId().toString()};
      throw validationException(INVALID_APPLICATION_MESSAGE, inserts);
    }

    for (Environment e : app.getEnvironmentList()) {
      if (e.getName().equals(environmentName)) {
        String[] inserts = new String[] {environmentName, app.getName()};
        throw validationException(DUPLICATE_ENVIRONMENT_MESSAGE, inserts);
      }
    }

    Environment e = new Environment();
    e.setName(environmentName);
    app.addEnvironment(e);
    e = environmentDAO.create(e);

    for (Property p : app.getPropertyList()) {
      EnvironmentProperty ep = new EnvironmentProperty();
      ep.setEnvironment(e);
      ep.setProperty(p);
      environmentPropertyDAO.create(ep);
    }

    return e;
  }
예제 #2
0
  /**
   * @param environment
   * @param property
   * @param propertyValue
   * @throws ValidationException
   */
  @Override
  public EnvironmentProperty setEnvironmentPropertyValue(
      Environment environment, Property property, String propertyValue) throws ValidationException {

    Query q =
        em.createQuery(
            "select ep from EnvironmentProperty ep where ep.property.id=:propertyId and ep.environment.id=:envId");
    q.setParameter("propertyId", property.getId());
    q.setParameter("envId", environment.getId());
    List<EnvironmentProperty> environmentPropertyList = q.getResultList();

    if (environmentPropertyList.size() == 1) {
      EnvironmentProperty environmentProperty = environmentPropertyList.get(0);
      environmentProperty.setValue(propertyValue);
      return environmentPropertyDAO.update(environmentProperty);
    } else {
      String[] inserts =
          new String[] {
            property.getName(), property.getApplication().getName(), environment.getName()
          };
      throw validationException(UNDEFINED_PROPERTY_MESSAGE, inserts);
    }
  }