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;
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations