Search in sources :

Example 1 with ApplicationInstalledJson

use of com.enonic.xp.impl.server.rest.model.ApplicationInstalledJson in project xp by enonic.

the class ApplicationResource method installApplication.

private ApplicationInstallResultJson installApplication(final URL url, byte[] sha512) {
    final ApplicationInstallResultJson result = new ApplicationInstallResultJson();
    try {
        final Application application = this.applicationService.installGlobalApplication(url, sha512);
        result.setApplicationInstalledJson(new ApplicationInstalledJson(application, false));
    } catch (Exception e) {
        final String failure = "Failed to process application from " + url;
        LOG.error(failure, e);
        result.setFailure(failure);
    }
    return result;
}
Also used : ApplicationInstallResultJson(com.enonic.xp.impl.server.rest.model.ApplicationInstallResultJson) ApplicationInstalledJson(com.enonic.xp.impl.server.rest.model.ApplicationInstalledJson) Application(com.enonic.xp.app.Application) IOException(java.io.IOException)

Example 2 with ApplicationInstalledJson

use of com.enonic.xp.impl.server.rest.model.ApplicationInstalledJson in project xp by enonic.

the class ApplicationResource method installApplication.

private ApplicationInstallResultJson installApplication(final ByteSource byteSource, final String applicationName) {
    final ApplicationInstallResultJson result = new ApplicationInstallResultJson();
    try {
        final Application application = this.applicationService.installGlobalApplication(byteSource, applicationName);
        result.setApplicationInstalledJson(new ApplicationInstalledJson(application, false));
    } catch (Exception e) {
        final String failure = "Failed to process application " + applicationName;
        LOG.error(failure, e);
        result.setFailure(failure);
    }
    return result;
}
Also used : ApplicationInstallResultJson(com.enonic.xp.impl.server.rest.model.ApplicationInstallResultJson) ApplicationInstalledJson(com.enonic.xp.impl.server.rest.model.ApplicationInstalledJson) Application(com.enonic.xp.app.Application) IOException(java.io.IOException)

Example 3 with ApplicationInstalledJson

use of com.enonic.xp.impl.server.rest.model.ApplicationInstalledJson in project xp by enonic.

the class ApplicationResourceTest method install.

@Test
public void install() throws Exception {
    ApplicationResource resource = getResourceInstance();
    ByteSource byteSource = ByteSource.wrap("bytes".getBytes());
    Application application = createApplication();
    MultipartItem multipartItem = Mockito.mock(MultipartItem.class);
    Mockito.when(multipartItem.getBytes()).thenReturn(byteSource);
    String fileName = application.getDisplayName();
    Mockito.when(multipartItem.getFileName()).thenReturn(fileName);
    MultipartForm multipartForm = Mockito.mock(MultipartForm.class);
    Mockito.when(this.applicationService.installGlobalApplication(Mockito.isA(ByteSource.class), eq(fileName))).thenReturn(application);
    Mockito.when(multipartForm.get("file")).thenReturn(multipartItem);
    ApplicationInstallResultJson result = resource.install(multipartForm);
    assertEquals(new ApplicationInstalledJson(application, false), result.getApplicationInstalledJson());
}
Also used : MultipartItem(com.enonic.xp.web.multipart.MultipartItem) ApplicationInstallResultJson(com.enonic.xp.impl.server.rest.model.ApplicationInstallResultJson) ApplicationInstalledJson(com.enonic.xp.impl.server.rest.model.ApplicationInstalledJson) ByteSource(com.google.common.io.ByteSource) MultipartForm(com.enonic.xp.web.multipart.MultipartForm) Application(com.enonic.xp.app.Application) Test(org.junit.jupiter.api.Test)

Aggregations

Application (com.enonic.xp.app.Application)3 ApplicationInstallResultJson (com.enonic.xp.impl.server.rest.model.ApplicationInstallResultJson)3 ApplicationInstalledJson (com.enonic.xp.impl.server.rest.model.ApplicationInstalledJson)3 IOException (java.io.IOException)2 MultipartForm (com.enonic.xp.web.multipart.MultipartForm)1 MultipartItem (com.enonic.xp.web.multipart.MultipartItem)1 ByteSource (com.google.common.io.ByteSource)1 Test (org.junit.jupiter.api.Test)1