Exemplo n.º 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;
  }
Exemplo n.º 2
0
  /**
   * @param application
   * @param propertyName
   * @return
   * @throws ValidationException
   */
  @Override
  public Property addProperty(Application application, String propertyName)
      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 (Property p : app.getPropertyList()) {
      if (p.getName().equals(propertyName)) {
        String[] inserts = new String[] {propertyName, app.getName()};
        throw validationException(DUPLICATE_PROPERTY_MESSAGE, inserts);
      }
    }

    Property p = new Property();
    p.setName(propertyName);
    app.addProperty(p);
    p = propertyDAO.create(p);

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

    return p;
  }
Exemplo n.º 3
0
  /**
   * @param applicationName
   * @return
   * @throws ValidationException
   */
  @Override
  public Application addApplication(String applicationName) throws ValidationException {
    Query q = em.createQuery("select a from Application a where a.name=:name");
    q.setParameter("name", applicationName);
    List<Application> applicationList = q.getResultList();

    if (applicationList.size() > 0) {
      String[] inserts = new String[] {applicationName};
      throw validationException(DUPLICATE_APPLICATION_MESSAGE, inserts);
    }

    Application application = new Application();
    application.setName(applicationName);

    return applicationDAO.create(application);
  }