Search in sources :

Example 26 with Application

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

the class AdminTest method testDeleteApplication.

public void testDeleteApplication() throws Exception {
    ModelManager modelManager = helper.getModelManager();
    Application dbApp = modelManager.getModelService().findApplicationByName(APP_NAME);
    HttpResponse response = helper.postAddModifyApp_delete(dbApp);
    modelManager.getModelService().clearPersistenceContext();
    dbApp = modelManager.getModelService().findApplicationByName(APP_NAME);
    Assert.assertTrue(dbApp == null);
    Assert.assertTrue(!_isVersionArchiveInAdminLocation(VERSION_01_HASH));
    Assert.assertTrue(!_isVersionArchiveInAdminLocation(VERSION_02_HASH));
    Assert.assertTrue(!_isVersionArchiveInDeployedLocation(VERSION_01_HASH));
    Assert.assertTrue(!_isVersionArchiveInDeployedLocation(VERSION_02_HASH));
}
Also used : HttpResponse(com.openmeap.http.HttpResponse) ModelManager(com.openmeap.model.ModelManager) Application(com.openmeap.model.dto.Application)

Example 27 with Application

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

the class AdminTest method testModifyApplication.

public void testModifyApplication() throws Exception {
    Application dbApp = modelManager.getModelService().findApplicationByName(APP_NAME);
    Assert.assertTrue(dbApp != null);
    // make some changes
    String newDesc = "Creating a new description";
    Integer newLen = 2;
    dbApp.setDescription(newDesc);
    dbApp.setDeploymentHistoryLength(newLen);
    Utils.consumeInputStream(helper.postAddModifyApp(dbApp).getResponseBody());
    // validate changes
    modelManager.refresh(dbApp, null);
    Assert.assertTrue(dbApp.getDescription().equals(newDesc));
    Assert.assertTrue(dbApp.getDeploymentHistoryLength().equals(newLen));
// TODO: validate changes are reflected by services-web, from the refresh hit
}
Also used : Application(com.openmeap.model.dto.Application)

Example 28 with Application

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

the class ApplicationManagementServiceImpl method connectionOpen.

public ConnectionOpenResponse connectionOpen(ConnectionOpenRequest request) throws WebServiceException {
    String reqAppArchHashVal = StringUtils.trimToNull(request.getApplication().getHashValue());
    String reqAppVerId = StringUtils.trimToNull(request.getApplication().getVersionId());
    String reqAppName = StringUtils.trimToNull(request.getApplication().getName());
    ConnectionOpenResponse response = new ConnectionOpenResponse();
    GlobalSettings settings = modelManager.getGlobalSettings();
    if (StringUtils.isBlank(settings.getExternalServiceUrlPrefix()) && logger.isWarnEnabled()) {
        logger.warn("The external service url prefix configured in the admin interface is blank.  " + "This will probably cause issues downloading application archives.");
    }
    Application application = getApplication(reqAppName, reqAppVerId);
    // Generate a new auth token for the device to present to the proxy
    String authToken;
    try {
        authToken = AuthTokenProvider.newAuthToken(application.getProxyAuthSalt());
    } catch (DigestException e) {
        throw new GenericRuntimeException(e);
    }
    response.setAuthToken(authToken);
    // If there is a deployment, 
    // and the version of that deployment differs in hash value or identifier
    // then return an update in the response
    Deployment lastDeployment = modelManager.getModelService().getLastDeployment(application);
    Boolean reqAppVerDiffers = lastDeployment != null && !lastDeployment.getVersionIdentifier().equals(reqAppVerId);
    Boolean reqAppArchHashValDiffers = lastDeployment != null && reqAppArchHashVal != null && !lastDeployment.getApplicationArchive().getHash().equals(reqAppArchHashVal);
    //   the app hash value is different than reported
    if (reqAppVerDiffers || reqAppArchHashValDiffers) {
        // TODO: I'm not happy with the discrepancies between the model and schema
        // ...besides, this update header should be encapsulated somewhere else
        ApplicationArchive currentVersionArchive = lastDeployment.getApplicationArchive();
        UpdateHeader uh = new UpdateHeader();
        uh.setVersionIdentifier(lastDeployment.getVersionIdentifier());
        uh.setInstallNeeds(Long.valueOf(currentVersionArchive.getBytesLength() + currentVersionArchive.getBytesLengthUncompressed()));
        uh.setStorageNeeds(Long.valueOf(currentVersionArchive.getBytesLengthUncompressed()));
        uh.setType(UpdateType.fromValue(lastDeployment.getType().toString()));
        uh.setUpdateUrl(currentVersionArchive.getDownloadUrl(settings));
        uh.setHash(new Hash());
        uh.getHash().setAlgorithm(HashAlgorithm.fromValue(currentVersionArchive.getHashAlgorithm()));
        uh.getHash().setValue(currentVersionArchive.getHash());
        response.setUpdate(uh);
    }
    return response;
}
Also used : DigestException(com.openmeap.digest.DigestException) Deployment(com.openmeap.model.dto.Deployment) UpdateHeader(com.openmeap.protocol.dto.UpdateHeader) GlobalSettings(com.openmeap.model.dto.GlobalSettings) ConnectionOpenResponse(com.openmeap.protocol.dto.ConnectionOpenResponse) GenericRuntimeException(com.openmeap.util.GenericRuntimeException) Hash(com.openmeap.protocol.dto.Hash) Application(com.openmeap.model.dto.Application) ApplicationArchive(com.openmeap.model.dto.ApplicationArchive)

Example 29 with Application

use of com.openmeap.model.dto.Application 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 30 with Application

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

the class ModelServiceRefreshNotifierTest method testHandlePostSaveOrUpdate.

@Test
public void testHandlePostSaveOrUpdate() throws Exception {
    try {
        new NonStrictExpectations() {

            {
            }
        };
    } catch (Exception e) {
    }
    ;
    MockHttpRequestExecuter.setResponseCode(200);
    MockHttpRequestExecuter.setResponseText("");
    MockHttpRequestExecuter httpExecuter = new MockHttpRequestExecuter();
    final ModelManager modelManager = new MockModelManager();
    final GlobalSettings globalSettings = new GlobalSettings();
    globalSettings.setServiceManagementAuthSalt(UUID.randomUUID().toString());
    ClusterNode clusterNode = new ClusterNode();
    clusterNode.setServiceWebUrlPrefix("http://www.openmeap.com/openmeap-services-web");
    globalSettings.addClusterNode(clusterNode);
    new NonStrictExpectations(globalSettings, modelManager) {

        {
            modelManager.getGlobalSettings();
            result = globalSettings;
        }
    };
    Application app = new Application();
    app.setName("Happy Name");
    app.setId(1L);
    ModelServiceRefreshNotifier notifier = new ModelServiceRefreshNotifier();
    notifier.setModelManager(modelManager);
    notifier.setHttpRequestExecuter(httpExecuter);
    notifier.notify(new ModelEntityModifyEvent(app), null);
    String lastPostUrl = MockHttpRequestExecuter.getLastPostUrl();
    Map<String, Object> lastPostData = MockHttpRequestExecuter.getLastPostData();
    String uri = lastPostUrl;
    String type = (String) lastPostData.get("type");
    String auth = (String) lastPostData.get("auth");
    String id = (String) lastPostData.get("id").toString();
    Assert.assertTrue(uri.equals("http://www.openmeap.com/openmeap-services-web/service-management/"));
    Assert.assertTrue(id.equals("1"));
    Assert.assertTrue(type.equals("Application"));
    Assert.assertTrue(AuthTokenProvider.validateAuthToken(globalSettings.getServiceManagementAuthSalt(), auth));
}
Also used : ClusterNode(com.openmeap.model.dto.ClusterNode) GlobalSettings(com.openmeap.model.dto.GlobalSettings) ModelManager(com.openmeap.model.ModelManager) MockHttpRequestExecuter(com.openmeap.util.MockHttpRequestExecuter) NonStrictExpectations(mockit.NonStrictExpectations) Application(com.openmeap.model.dto.Application) ModelEntityModifyEvent(com.openmeap.model.event.ModelEntityModifyEvent) 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