Search in sources :

Example 11 with Application

use of com.openmeap.model.dto.Application in project OpenMEAP by OpenMEAP.

the class ModelServiceImpl method findApplicationByName.

@Override
public Application findApplicationByName(String name) {
    Query q = entityManager.createQuery("select distinct a " + "from Application a " + "where a.name=:name");
    q.setParameter("name", name);
    try {
        return (Application) q.getSingleResult();
    } catch (NoResultException nre) {
        return null;
    }
}
Also used : Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException) Application(com.openmeap.model.dto.Application)

Example 12 with Application

use of com.openmeap.model.dto.Application in project OpenMEAP by OpenMEAP.

the class ApplicationDeleteNotifier method onBeforeOperation.

@Override
public <E extends Event<Application>> void onBeforeOperation(E event, List<ProcessingEvent> events) throws EventNotificationException {
    Application app = (Application) event.getPayload();
    modelManager.refresh(app, events);
    deleteApplicationVersions(app, events);
    deleteDeployments(app, events);
}
Also used : Application(com.openmeap.model.dto.Application)

Example 13 with Application

use of com.openmeap.model.dto.Application in project OpenMEAP by OpenMEAP.

the class EntityRelationshipsTest method makeModifications.

public void makeModifications(EntityManager em) {
    Application app = em.find(Application.class, 1L);
    app.setDescription("BUNKER");
    em.persist(app);
}
Also used : Application(com.openmeap.model.dto.Application)

Example 14 with Application

use of com.openmeap.model.dto.Application in project OpenMEAP by OpenMEAP.

the class EntityRelationshipsTest method assertInserts.

public void assertInserts(EntityManager em) {
    // TODO: flush this whole test out much more
    Query q = em.createQuery("select distinct a from Application a");
    @SuppressWarnings("unchecked") List<Application> result = (List<Application>) q.getResultList();
    Assert.assertTrue(result.size() == 1);
    Application a = result.get(0);
    // Application simple types
    //Assert.assertTrue(a.getCurrentVersion()!=null);
    Assert.assertTrue(a.getName().compareTo("Application.name") == 0);
    Assert.assertTrue(a.getDescription().compareTo("Application.description") == 0);
    // Versions and CurrentVersion
    Assert.assertTrue(a.getVersions() != null && a.getVersions().entrySet().size() == 2);
    Assert.assertTrue(a.getDeployments().size() == 3);
}
Also used : Application(com.openmeap.model.dto.Application)

Example 15 with Application

use of com.openmeap.model.dto.Application in project OpenMEAP by OpenMEAP.

the class ModelManagerImplTest method testAddModifyApplication.

@Test
public void testAddModifyApplication() throws Exception {
    InvalidPropertiesException e = null;
    Application app = null;
    // to modify a completely invalid Application
    try {
        app = new Application();
        modelManager.begin().addModify(app, null);
        modelManager.commit();
    } catch (InvalidPropertiesException ipe) {
        modelManager.rollback();
        e = ipe;
    }
    Assert.assertTrue(e != null && e.getMethodMap().size() == 1);
    Assert.assertTrue(e.getMethodMap().containsKey(Application.class.getMethod("getName")));
    //////////////////////////////////
    // make sure that adding name changes the exception
    e = null;
    app = new Application();
    app.setName("Application.2.name");
    try {
        app = modelManager.begin().addModify(app, null);
        modelManager.commit();
    } catch (InvalidPropertiesException ipe) {
        modelManager.rollback();
        e = ipe;
    }
    Assert.assertTrue(e == null);
    Assert.assertTrue(app.getId() != null && app.getName().compareTo("Application.2.name") == 0);
    //////////////////////////////////
    // now modify the application returned by addModifyApplication
    Long id = app.getId();
    app.setName("Application.2.name_modified");
    try {
        app = modelManager.begin().addModify(app, null);
        modelManager.commit();
    } catch (Exception e1) {
        modelManager.rollback();
        throw new Exception(e1);
    }
    Application appFound = modelManager.getModelService().findByPrimaryKey(Application.class, id);
    Assert.assertTrue(appFound.getName().compareTo("Application.2.name_modified") == 0);
}
Also used : Application(com.openmeap.model.dto.Application) PersistenceException(javax.persistence.PersistenceException) EventNotificationException(com.openmeap.event.EventNotificationException) Test(org.junit.Test)

Aggregations

Application (com.openmeap.model.dto.Application)34 ApplicationVersion (com.openmeap.model.dto.ApplicationVersion)12 Test (org.junit.Test)9 ProcessingEvent (com.openmeap.event.ProcessingEvent)7 Deployment (com.openmeap.model.dto.Deployment)7 ModelManager (com.openmeap.model.ModelManager)6 ApplicationArchive (com.openmeap.model.dto.ApplicationArchive)6 GlobalSettings (com.openmeap.model.dto.GlobalSettings)6 PersistenceException (javax.persistence.PersistenceException)6 MessagesEvent (com.openmeap.event.MessagesEvent)5 Anchor (com.openmeap.web.html.Anchor)5 ArrayList (java.util.ArrayList)5 AddSubNavAnchorEvent (com.openmeap.admin.web.events.AddSubNavAnchorEvent)4 EventNotificationException (com.openmeap.event.EventNotificationException)4 HashMap (java.util.HashMap)4 InvalidPropertiesException (com.openmeap.model.InvalidPropertiesException)3 DigestException (com.openmeap.digest.DigestException)2 HttpResponse (com.openmeap.http.HttpResponse)2 WebServiceException (com.openmeap.protocol.WebServiceException)2 UpdateHeader (com.openmeap.protocol.dto.UpdateHeader)2