Search in sources :

Example 21 with ApplicationVersion

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;
    }
}
Also used : ApplicationVersion(com.openmeap.model.dto.ApplicationVersion) Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException)

Example 22 with ApplicationVersion

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);
    }
}
Also used : ApplicationVersion(com.openmeap.model.dto.ApplicationVersion) ModelEntityEvent(com.openmeap.model.event.ModelEntityEvent) HashMap(java.util.HashMap) ClusterNotificationException(com.openmeap.cluster.ClusterNotificationException) Deployment(com.openmeap.model.dto.Deployment) GlobalSettings(com.openmeap.model.dto.GlobalSettings) MapPayloadEvent(com.openmeap.model.event.MapPayloadEvent) ApplicationArchive(com.openmeap.model.dto.ApplicationArchive) EventHandlingException(com.openmeap.event.EventHandlingException)

Example 23 with ApplicationVersion

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);
}
Also used : ApplicationVersion(com.openmeap.model.dto.ApplicationVersion)

Example 24 with ApplicationVersion

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);
    }
}
Also used : ApplicationVersion(com.openmeap.model.dto.ApplicationVersion) Application(com.openmeap.model.dto.Application) EventNotificationException(com.openmeap.event.EventNotificationException)

Example 25 with ApplicationVersion

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();
}
Also used : ApplicationVersion(com.openmeap.model.dto.ApplicationVersion) ApplicationArchive(com.openmeap.model.dto.ApplicationArchive) Application(com.openmeap.model.dto.Application)

Aggregations

ApplicationVersion (com.openmeap.model.dto.ApplicationVersion)26 Application (com.openmeap.model.dto.Application)12 ProcessingEvent (com.openmeap.event.ProcessingEvent)7 GlobalSettings (com.openmeap.model.dto.GlobalSettings)6 ApplicationArchive (com.openmeap.model.dto.ApplicationArchive)5 Anchor (com.openmeap.web.html.Anchor)5 HashMap (java.util.HashMap)5 AddSubNavAnchorEvent (com.openmeap.admin.web.events.AddSubNavAnchorEvent)4 MessagesEvent (com.openmeap.event.MessagesEvent)4 File (java.io.File)4 ArrayList (java.util.ArrayList)4 PersistenceException (javax.persistence.PersistenceException)4 InvalidPropertiesException (com.openmeap.model.InvalidPropertiesException)3 Deployment (com.openmeap.model.dto.Deployment)3 Result (com.openmeap.protocol.dto.Result)3 AddModifyApplicationVersionBacking (com.openmeap.admin.web.backing.AddModifyApplicationVersionBacking)2 ClusterNotificationException (com.openmeap.cluster.ClusterNotificationException)2 EventNotificationException (com.openmeap.event.EventNotificationException)2 GenericProcessingEvent (com.openmeap.web.GenericProcessingEvent)2 IOException (java.io.IOException)2