use of com.openmeap.model.dto.ApplicationVersion in project OpenMEAP by OpenMEAP.
the class ModelServiceImpl method findAppVersionByNameAndId.
@Override
public ApplicationVersion findAppVersionByNameAndId(String appName, String identifier) {
Query q = entityManager.createQuery("select distinct av " + "from ApplicationVersion av " + "inner join fetch av.application a " + "where av.identifier=:identifier " + "and a.name=:name");
q.setParameter("name", appName);
q.setParameter("identifier", identifier);
try {
ApplicationVersion ver = (ApplicationVersion) q.getSingleResult();
return ver;
} catch (NoResultException nre) {
return null;
}
}
use of com.openmeap.model.dto.ApplicationVersion in project OpenMEAP by OpenMEAP.
the class DeploymentDeleteNotifier method onAfterOperation.
@Override
public <E extends Event<Deployment>> void onAfterOperation(E event, List<ProcessingEvent> events) throws EventNotificationException {
//public <E extends Event<Deployment>> void onInCommitBeforeCommit(E event, List<ProcessingEvent> events) throws EventNotificationException {
Deployment deployment2Delete = (Deployment) event.getPayload();
ApplicationArchive archive = deployment2Delete.getApplicationArchive();
// if there are any other deployments with this hash,
// then we cannot yet delete it's archive yet at all.
List<Deployment> deployments = archiveDeleteHandler.getModelManager().getModelService().findDeploymentsByApplicationArchive(archive);
if (deployments.size() != 0) {
return;
} else {
int deplCount = archiveDeleteHandler.getModelManager().getModelService().countDeploymentsByHashAndHashAlg(archive.getHash(), archive.getHashAlgorithm());
if (deplCount == 0) {
// use the archive delete notifier to cleanup to cluster nodes
archiveDeleteNotifier.notify(new ModelEntityEvent(ModelServiceOperation.DELETE, archive), events);
}
}
// if there are any application versions with this archive,
// then we cannot delete it's archive.
List<ApplicationVersion> versions = archiveDeleteHandler.getModelManager().getModelService().findVersionsByApplicationArchive(archive);
if (versions.size() != 0) {
return;
}
// OK TO DELETE THIS APPLICATION'S COPY OF THE ARCHIVE,
// but possibly not the archive file...as it may be in use by another app
// use the archive delete handler to cleanup localhost
Map<String, Object> map = new HashMap<String, Object>();
map.put("archive", archive);
try {
int archivesWithHashAndAlg = archiveDeleteHandler.getModelManager().getModelService().countApplicationArchivesByHashAndHashAlg(archive.getHash(), archive.getHashAlgorithm());
if (archivesWithHashAndAlg == 1) {
// use the delete handler to cleanup the admin servers copy
GlobalSettings settings = archiveDeleteHandler.getModelManager().getGlobalSettings();
archiveDeleteHandler.setFileSystemStoragePathPrefix(settings.getTemporaryStoragePath());
archiveDeleteHandler.handle(new MapPayloadEvent(map));
}
archiveDeleteHandler.getModelManager().delete(archive, events);
} catch (EventHandlingException e) {
throw new ClusterNotificationException("An event handling exception occured", e);
}
}
use of com.openmeap.model.dto.ApplicationVersion in project OpenMEAP by OpenMEAP.
the class ModelServiceImplTest method testFindAppVersionByNameAndId.
public void testFindAppVersionByNameAndId() {
ApplicationVersion app = modelService.findAppVersionByNameAndId("Application.name", "ApplicationVersion.identifier.2");
Assert.assertTrue(app != null);
}
use of com.openmeap.model.dto.ApplicationVersion in project OpenMEAP by OpenMEAP.
the class ModelServiceImplTest method testSaveOrUpdate.
public void testSaveOrUpdate() {
/////////////////
// Verify that we can create and save an applicaiton
// and that the application returned has the pk assigned by the db/orm
Application app = new Application();
app.setName("This is a unique app name, or my name ain't Jon.");
try {
app = modelService.begin().saveOrUpdate(app);
modelService.commit();
} catch (Exception e) {
modelService.rollback();
throw new RuntimeException(e);
}
Assert.assertTrue(app.getId() != null);
ApplicationVersion appVer = new ApplicationVersion();
appVer.setApplication(app);
appVer.setIdentifier("smacky id");
try {
appVer = modelService.begin().saveOrUpdate(appVer);
modelService.commit();
} catch (Exception e) {
modelService.rollback();
throw new RuntimeException(e);
}
Assert.assertTrue(appVer.getId() != null);
/////////////////
// Verify that we can modify an application
app = modelService.findByPrimaryKey(Application.class, 1L);
String origName = app.getName();
app.setName("picard");
try {
app = modelService.begin().saveOrUpdate(app);
modelService.commit();
} catch (Exception e) {
modelService.rollback();
throw new RuntimeException(e);
}
app = modelService.findByPrimaryKey(Application.class, 1L);
Assert.assertTrue(app.getName() != null && app.getName().compareTo("picard") == 0);
Assert.assertTrue(app.getId() != null);
// put the app back the way we found it
app.setName(origName);
try {
app = modelService.begin().saveOrUpdate(app);
modelService.commit();
} catch (Exception e) {
modelService.rollback();
throw new RuntimeException(e);
}
}
use of com.openmeap.model.dto.ApplicationVersion in project OpenMEAP by OpenMEAP.
the class EntityRelationshipsTest method testModel.
@Test
public void testModel() {
assertInserts(em);
makeModifications(em);
ApplicationArchive aa = null;
ApplicationVersion av = null;
Application app = null;
// Verify that deleting an application version
// deletes only the version and archive
av = em.find(ApplicationVersion.class, 1L);
app = em.find(Application.class, 1L);
em.getTransaction().begin();
app.removeVersion(av);
em.remove(av);
em.getTransaction().commit();
app = em.find(Application.class, 1L);
aa = em.find(ApplicationArchive.class, 1L);
Assert.assertTrue(app != null);
Assert.assertTrue(aa != null);
// Verify that deleting an application deletes all the crap associated to it
app = em.find(Application.class, 1L);
Assert.assertTrue(app != null);
em.getTransaction().begin();
em.remove(app);
em.getTransaction().commit();
av = em.find(ApplicationVersion.class, 2L);
Assert.assertTrue(av != null);
em.clear();
}
Aggregations