Search in sources :

Example 6 with ApplicationVersion

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

the class AddModifyApplicationVersionBacking method obtainExistingApplicationVersionFromParameters.

/**
	 * @param app
	 * @param appId
	 * @param events
	 * @param parameterMap
	 * @return The application version indicated by the parameterMap, or null
	 */
private ApplicationVersion obtainExistingApplicationVersionFromParameters(Application app, Long appId, List<ProcessingEvent> events, Map<Object, Object> parameterMap) {
    // if we're not processing and there is a versionId or an identifier in the request
    // then we're pre-populating the form with information from the version
    ApplicationVersion version = null;
    String versionId = firstValue("versionId", parameterMap);
    String identifier = firstValue("identifier", parameterMap);
    if (StringUtils.isNotBlank(versionId) || StringUtils.isNotBlank(identifier)) {
        if (StringUtils.isNotBlank(versionId)) {
            version = modelManager.getModelService().findByPrimaryKey(ApplicationVersion.class, Long.valueOf(versionId));
        }
        if (version == null && StringUtils.isNotBlank(identifier)) {
            version = modelManager.getModelService().findAppVersionByNameAndId(app.getName(), identifier);
        }
        if (version == null) {
            events.add(new GenericProcessingEvent(ProcessingTargets.MESSAGES, "An Application Version matching input could not be found.  Creating a new version."));
        } else if (version.getApplication() != null && version.getApplication().getId().compareTo(appId) != 0) {
            version = null;
            events.add(new GenericProcessingEvent(ProcessingTargets.MESSAGES, "The Application Version with id " + versionId + " is not a version of the Application with id " + appId));
        }
    }
    return version;
}
Also used : ApplicationVersion(com.openmeap.model.dto.ApplicationVersion) GenericProcessingEvent(com.openmeap.web.GenericProcessingEvent)

Example 7 with ApplicationVersion

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

the class ModelServiceRefreshNotifier method makeRequest.

/**
	 * This MUST remain state-less
	 * 
	 * @param <T>
	 * @param thisUrl
	 * @param obj
	 */
@Override
protected void makeRequest(final URL url, final Event<ModelEntity> mesg) throws ClusterNotificationException {
    com.openmeap.http.HttpResponse httpResponse = null;
    String simpleName = null;
    String thisUrl = url.toString() + "/" + ServletNameConstants.SERVICE_MANAGEMENT + "/";
    ModelEntity obj = mesg.getPayload();
    // I am not using obj.getClass().getSimpleName() because of Hibernate Proxy object wrapping
    if (obj instanceof Application)
        simpleName = "Application";
    else if (obj instanceof ApplicationVersion)
        simpleName = "ApplicationVersion";
    else if (obj instanceof ApplicationArchive)
        simpleName = "ApplicationArchive";
    else if (obj instanceof ApplicationInstallation)
        simpleName = "ApplicationInstallation";
    else if (obj instanceof GlobalSettings)
        simpleName = "GlobalSettings";
    else
        return;
    Hashtable<String, Object> parms = new Hashtable<String, Object>();
    parms.put(UrlParamConstants.ACTION, ModelEntityEventAction.MODEL_REFRESH.getActionName());
    parms.put(UrlParamConstants.AUTH_TOKEN, newAuthToken());
    parms.put(UrlParamConstants.REFRESH_TYPE, simpleName);
    parms.put(UrlParamConstants.REFRESH_OBJ_PKID, obj.getPk());
    try {
        logger.debug("Refresh post to {} for {} with id {}", new Object[] { thisUrl, simpleName, obj.getPk() });
        httpResponse = getHttpRequestExecuter().postData(thisUrl, parms);
        Utils.consumeInputStream(httpResponse.getResponseBody());
        int statusCode = httpResponse.getStatusCode();
        if (statusCode != 200) {
            String exMesg = "HTTP " + statusCode + " returned for refresh post to " + thisUrl + " for " + simpleName + " with id " + obj.getPk();
            logger.error(exMesg);
            throw new ClusterNotificationException(url, exMesg);
        }
    } catch (Exception e) {
        String exMesg = "Refresh post to " + thisUrl + " for " + simpleName + " with id " + obj.getPk() + " threw an exception";
        logger.error(exMesg, e);
        throw new ClusterNotificationException(url, exMesg, e);
    }
}
Also used : ApplicationVersion(com.openmeap.model.dto.ApplicationVersion) Hashtable(java.util.Hashtable) ClusterNotificationException(com.openmeap.cluster.ClusterNotificationException) GlobalSettings(com.openmeap.model.dto.GlobalSettings) ApplicationArchive(com.openmeap.model.dto.ApplicationArchive) ClusterNotificationException(com.openmeap.cluster.ClusterNotificationException) ApplicationInstallation(com.openmeap.model.dto.ApplicationInstallation) ModelEntity(com.openmeap.model.ModelEntity) Application(com.openmeap.model.dto.Application)

Example 8 with ApplicationVersion

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

the class ModelServiceImpl method findVersionsByApplicationArchive.

@Override
public List<ApplicationVersion> findVersionsByApplicationArchive(ApplicationArchive archive) {
    Query q = entityManager.createQuery("select distinct av " + "from ApplicationVersion av " + "inner join fetch av.archive aa " + "where aa.id=:id ");
    q.setParameter("id", archive.getId());
    try {
        @SuppressWarnings(value = { "unchecked" }) List<ApplicationVersion> versions = (List<ApplicationVersion>) q.getResultList();
        return versions;
    } catch (NoResultException nre) {
        return null;
    }
}
Also used : ApplicationVersion(com.openmeap.model.dto.ApplicationVersion) Query(javax.persistence.Query) List(java.util.List) NoResultException(javax.persistence.NoResultException)

Example 9 with ApplicationVersion

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

the class ModelManagerImplTest method testAddModifyApplicationVersion.

@Test
public void testAddModifyApplicationVersion() throws Exception {
    Boolean thrown = false;
    Application app = modelManager.getModelService().findByPrimaryKey(Application.class, 1L);
    InvalidPropertiesException e = null;
    ////////////////////////////
    // Verify creating a new application version
    ApplicationVersion version = newValidAppVersion(app);
    modelManager.begin();
    version.setArchive(modelManager.addModify(version.getArchive(), null));
    version = modelManager.addModify(version, null);
    try {
        modelManager.getModelService().delete(version);
        modelManager.commit();
    } catch (Exception e1) {
        modelManager.rollback();
        throw new Exception(e1);
    }
    ////////////////////////////
    // Verify that attempting to create an application version 
    // with no content length specified throws an exception
    version = newValidAppVersion(app);
    version.getArchive().setBytesLength(null);
    try {
        version = modelManager.begin().addModify(version, null);
        modelManager.commit();
    } catch (InvalidPropertiesException ipe) {
        modelManager.rollback();
        e = ipe;
        thrown = true;
    }
    Assert.assertTrue("When bytes length is null, an exception should be thrown", thrown);
    Assert.assertTrue(e.getMethodMap().get(ApplicationArchive.class.getMethod("getBytesLength")) != null);
    ////////////////////////////
    // Verify that attempting to create an application version 
    // with no content length specified throws an exception
    version.getArchive().setBytesLength(0);
    try {
        version = modelManager.begin().addModify(version, null);
        modelManager.commit();
    } catch (InvalidPropertiesException ipe) {
        modelManager.rollback();
        e = ipe;
        thrown = true;
    }
    Assert.assertTrue("When bytes length is 0, an exception should be thrown", thrown);
    Assert.assertTrue(e.getMethodMap().get(ApplicationArchive.class.getMethod("getBytesLength")) != null);
    ////////////
    // Verify that trying to add a version with an invalid hash throws an exception
    version.getArchive().setHashAlgorithm("NOT_SUCH_ALGORITHM");
    try {
        version = modelManager.begin().addModify(version, null);
        modelManager.commit();
    } catch (InvalidPropertiesException ipe) {
        modelManager.rollback();
        e = ipe;
    }
    Assert.assertTrue(e != null);
    Assert.assertTrue(e.getMethodMap().size() == 2);
    Assert.assertTrue(e.getMethodMap().get(ApplicationArchive.class.getMethod("getHashAlgorithm")) != null);
    Assert.assertTrue(e.getMethodMap().get(ApplicationArchive.class.getMethod("getBytesLength")) != null);
}
Also used : ApplicationVersion(com.openmeap.model.dto.ApplicationVersion) Application(com.openmeap.model.dto.Application) ApplicationArchive(com.openmeap.model.dto.ApplicationArchive) PersistenceException(javax.persistence.PersistenceException) EventNotificationException(com.openmeap.event.EventNotificationException) Test(org.junit.Test)

Example 10 with ApplicationVersion

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

the class ModelManagerImplTest method newValidAppVersion.

/**
	 * Encapsulated so I can make a bunch of minor variations on a valid app version
	 * to test the model manager rigorously
	 * @param app
	 * @return
	 */
ApplicationVersion newValidAppVersion(Application app) {
    ApplicationVersion version = new ApplicationVersion();
    version.setIdentifier(UUID.randomUUID().toString());
    version.setArchive(new ApplicationArchive());
    version.getArchive().setApplication(app);
    version.getArchive().setUrl("ApplicationArchive.url.3");
    version.getArchive().setHashAlgorithm("SHA1");
    version.getArchive().setHash("ApplicationArchive.hash.3");
    version.getArchive().setBytesLength(1000);
    version.getArchive().setBytesLengthUncompressed(1000);
    version.setCreateDate(null);
    version.setNotes(null);
    version.setApplication(app);
    return version;
}
Also used : ApplicationVersion(com.openmeap.model.dto.ApplicationVersion) ApplicationArchive(com.openmeap.model.dto.ApplicationArchive)

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