Skip to content

Commit

Permalink
Select apps in group edit analysis page T517
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraZizka committed Mar 3, 2017
1 parent dd48e30 commit c840aad
Show file tree
Hide file tree
Showing 14 changed files with 426 additions and 85 deletions.
Expand Up @@ -22,6 +22,8 @@
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import javax.persistence.Access;
import javax.persistence.AccessType;

/**
* Contains an application that has been registered into Windup.
Expand All @@ -40,6 +42,7 @@ public enum RegistrationType {
public static final String REGISTERED_APPLICATION_ID = "registered_application_id";

@Id
@Access(AccessType.PROPERTY) // Allow accessing ID without Lazy-loading the entity.
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = REGISTERED_APPLICATION_ID, updatable = false, nullable = false)
private Long id;
Expand Down
Expand Up @@ -21,11 +21,13 @@
*
* @author <a href="http://ondra.zizka.cz/">Ondrej Zizka, zizka@seznam.cz</a>
*/
@Path("migrationProjects")
@Path(MigrationProjectEndpoint.MIGRATION_PROJECTS_SUBPATH)
@Consumes("application/json")
@Produces("application/json")
public interface MigrationProjectEndpoint
{
static final String MIGRATION_PROJECTS_SUBPATH = "migrationProjects";

/**
* List all {@link MigrationProject}s.
*/
Expand Down
Expand Up @@ -21,7 +21,7 @@ public interface RegisteredApplicationEndpoint
String REGISTERED_APPLICATIONS = "/registeredApplications";

@GET
Collection<RegisteredApplication> getAllApplications();
Collection<RegisteredApplication> getAllApplications(@QueryParam("projectId") Long projectId);

@Path("{id}")
@GET
Expand Down
Expand Up @@ -20,9 +20,12 @@ public class RegisteredApplicationEndpointImpl implements RegisteredApplicationE
private RegisteredApplicationService registeredApplicationService;

@Override
public Collection<RegisteredApplication> getAllApplications()
public Collection<RegisteredApplication> getAllApplications(Long projectId)
{
return this.registeredApplicationService.getAllApplications();
if (projectId == null)
return this.registeredApplicationService.getAllApplications();
else
return this.registeredApplicationService.getApplicationsFromProject((long)projectId);
}

@Override
Expand Down
Expand Up @@ -11,6 +11,7 @@
import javax.transaction.Transactional;

import org.jboss.forge.furnace.Furnace;
import org.jboss.windup.util.exception.WindupException;
import org.jboss.windup.web.addons.websupport.services.PackageDiscoveryService;
import org.jboss.windup.web.furnaceserviceprovider.FromFurnace;
import org.jboss.windup.web.furnaceserviceprovider.WebProperties;
Expand Down Expand Up @@ -61,6 +62,9 @@ public Collection<Package> discoverPackages(RegisteredApplication application)
if (applicationId != null)
application = this.entityManager.find(RegisteredApplication.class, applicationId);

if (application == null)
throw new WindupException("Non-existent app ID: " + applicationId);

PackageMetadata appPackageMetadata = application.getPackageMetadata();
appPackageMetadata.setScanStatus(PackageMetadata.ScanStatus.IN_PROGRESS);
this.entityManager.merge(appPackageMetadata);
Expand Down
Expand Up @@ -69,6 +69,12 @@ public Collection<RegisteredApplication> getAllApplications()
.getResultList();
}

public Collection<RegisteredApplication> getApplicationsFromProject(long projectId)
{
String jql = "SELECT app FROM " + RegisteredApplication.class.getSimpleName() + " app WHERE app.migrationProject.id = " + projectId;
return entityManager.createQuery(jql, RegisteredApplication.class).getResultList();
}

public RegisteredApplication getApplication(long id)
{
RegisteredApplication application = this.entityManager.find(RegisteredApplication.class, id);
Expand Down
Expand Up @@ -56,15 +56,32 @@ public void setUp()

this.migrationProjectRegisteredApplicationsEndpoint = target.proxy(MigrationProjectRegisteredApplicationsEndpoint.class);
this.registeredApplicationEndpoint = target.proxy(RegisteredApplicationEndpoint.class);

this.dummyProject = this.dataProvider.getMigrationProject();
}

@Test
@RunAsClient
public void testRegisteredAppByProjectId() throws Exception
{
try {
final MigrationProject project = this.dataProvider.getMigrationProject();
RegisteredApplication dummyApp = this.dataProvider.getApplication(project);
Collection<RegisteredApplication> existingApps = registeredApplicationEndpoint.getAllApplications(project.getId());
Assert.assertNotEquals(0, existingApps.size());
}
finally
{
for (RegisteredApplication application : registeredApplicationEndpoint.getAllApplications(null))
registeredApplicationEndpoint.deleteApplication(application.getId());
}
}

@Test
@RunAsClient
public void testRegisterAppByPath() throws Exception
{
Collection<RegisteredApplication> existingApps = registeredApplicationEndpoint.getAllApplications();
Collection<RegisteredApplication> existingApps = registeredApplicationEndpoint.getAllApplications(null);
Assert.assertEquals(0, existingApps.size());

File tempFile1 = File.createTempFile(RegisteredApplicationEndpointTest.class.getSimpleName() + ".1", ".ear");
Expand All @@ -75,7 +92,7 @@ public void testRegisterAppByPath() throws Exception

try
{
Collection<RegisteredApplication> apps = registeredApplicationEndpoint.getAllApplications();
Collection<RegisteredApplication> apps = registeredApplicationEndpoint.getAllApplications(null);
Assert.assertEquals(2, apps.size());
boolean foundPath1 = false;
boolean foundPath2 = false;
Expand All @@ -93,7 +110,7 @@ else if (app.getInputPath().equals(tempFile2.getAbsolutePath()))
}
finally
{
for (RegisteredApplication application : registeredApplicationEndpoint.getAllApplications())
for (RegisteredApplication application : registeredApplicationEndpoint.getAllApplications(null))
{
registeredApplicationEndpoint.deleteApplication(application.getId());
}
Expand All @@ -104,7 +121,7 @@ else if (app.getInputPath().equals(tempFile2.getAbsolutePath()))
@RunAsClient
public void testRegisterAppUpload() throws Exception
{
Collection<RegisteredApplication> existingApps = registeredApplicationEndpoint.getAllApplications();
Collection<RegisteredApplication> existingApps = registeredApplicationEndpoint.getAllApplications(null);
Assert.assertEquals(0, existingApps.size());

try (InputStream sampleIS = getClass().getResourceAsStream(DataProvider.TINY_SAMPLE_PATH))
Expand All @@ -123,7 +140,7 @@ public void testRegisterAppUpload() throws Exception
RegisteredApplication application = response.readEntity(RegisteredApplication.class);
response.close();

Collection<RegisteredApplication> apps = registeredApplicationEndpoint.getAllApplications();
Collection<RegisteredApplication> apps = registeredApplicationEndpoint.getAllApplications(null);
Assert.assertEquals(1, apps.size());

Assert.assertEquals(fileName, application.getTitle());
Expand All @@ -140,7 +157,7 @@ public void testRegisterAppUpload() throws Exception
}
finally
{
for (RegisteredApplication application : registeredApplicationEndpoint.getAllApplications())
for (RegisteredApplication application : registeredApplicationEndpoint.getAllApplications(null))
{
registeredApplicationEndpoint.deleteApplication(application.getId());
}
Expand Down
Expand Up @@ -4,13 +4,18 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.StringReader;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.List;
import javax.json.Json;

import javax.ws.rs.client.Entity;
import javax.ws.rs.core.GenericEntity;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.xml.bind.annotation.XmlList;

import org.apache.http.HttpStatus;
import org.jboss.arquillian.container.test.api.RunAsClient;
Expand All @@ -27,6 +32,7 @@
import org.jboss.windup.web.services.model.RegisteredApplication;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;

Expand Down Expand Up @@ -58,6 +64,27 @@ public void setUp()
this.project = this.dataProvider.getMigrationProject();
}


@Test
@RunAsClient
@Ignore
public void testGetAppFromProject() throws Exception
{
RegisteredApplication dummyApp = this.dataProvider.getApplication(this.project);

String uri = this.target.getUri() + RegisteredApplicationEndpoint.REGISTERED_APPLICATIONS;
ResteasyWebTarget target = this.client.target(uri).queryParam("projectId", this.project.getId());
Response response = target.request().get();
response.close();
Assert.assertEquals(HttpStatus.SC_OK, response.getStatus());

//String json = response.readEntity(String.class);
//Json.createParser(new StringReader(json)).;
List<RegisteredApplication> apps = response.readEntity(new GenericType<List<RegisteredApplication>>(){});
Assert.assertEquals("App ID matches", dummyApp.getId(), apps.get(0).getId());
}


@Test
@RunAsClient
public void testReuploadApp() throws Exception
Expand Down Expand Up @@ -92,7 +119,7 @@ public void testReuploadApp() throws Exception
}
finally
{
for (RegisteredApplication application : registeredApplicationEndpoint.getAllApplications())
for (RegisteredApplication application : registeredApplicationEndpoint.getAllApplications(null))
{
registeredApplicationEndpoint.deleteApplication(application.getId());
}
Expand All @@ -118,7 +145,7 @@ private ResteasyWebTarget getResteasyWebTarget(Long appId)
{
return this.getResteasyWebTarget(appId, "");
}

private ResteasyWebTarget getResteasyWebTarget(Long appId, String resource)
{
String registeredAppTargetUri = this.target.getUri() + RegisteredApplicationEndpoint.REGISTERED_APPLICATIONS + "/" + appId;
Expand Down
2 changes: 2 additions & 0 deletions ui/src/main/webapp/src/app/app.module.ts
Expand Up @@ -106,6 +106,7 @@ import {MomentModule} from "angular2-moment";
import {FileUploadModule, FileUploader} from "ng2-file-upload";
import {WizardComponent} from "./components/wizard.component";
import {DurationPipe} from "./components/duration.pipe";
import {CheckboxesComponent} from "./components/reusable/checkboxes.component";
import {TabContainerComponent} from "./components/tabs/tab-container.component";
import {TabComponent} from "./components/tabs/tab.component";
import {LogViewComponent} from "./components/log-view.component";
Expand Down Expand Up @@ -176,6 +177,7 @@ initializeModelMappingData();
RulesModalComponent,
TechnologyComponent,

CheckboxesComponent,
UploadQueueComponent,
UploadProgressbarComponent,
CustomRuleSelectionComponent,
Expand Down
Expand Up @@ -5,6 +5,7 @@ <h1 i18n>
</h1>

<h2 *ngIf="!applicationGroup" i18n>Loading...</h2>

<form *ngIf="applicationGroup" #analysisContextForm="ngForm" (ngSubmit)="onSubmit()" class="form-horizontal">

<div *ngFor="let errorMessage of errorMessages" class="row form-errors alert alert-danger">
Expand All @@ -17,7 +18,7 @@ <h2 *ngIf="!applicationGroup" i18n>Loading...</h2>
<div class="row">
<div class="form-group">
<label class="col-md-2 control-label" for="migrationPath" i18n>Migration Path</label>
<div class="col-md-6">
<div class="col-md-10 col-lg-8">
<select #migrationPath="ngModel" id="migrationPath" name="migrationPath" ngControl="migrationPath"
class="form-control" required
[(ngModel)]="analysisContext.migrationPath.id"
Expand All @@ -30,9 +31,27 @@ <h2 *ngIf="!applicationGroup" i18n>Loading...</h2>
</span>
</div>
</div>

<!-- Apps -->
<div class="form-group">
<label class="col-md-2 control-label" i18n>Applications included</label>
<div class="col-md-10 col-lg-8">
<wu-checkboxes [groupName]="'includedApps'"
[options]="availableApps"
[valueCallback]="appsValueCallback"
[labelCallback]="appsLabelCallback"
[equalsCallback]="equalsCallback"
[(checkedOptions)]="applicationGroup.applications"
(checkedOptionsChange)="onCheckedOptionsChange()"
>
</wu-checkboxes>
</div>
</div>

<!-- Packages -->
<div class="form-group">
<label class="col-md-2 control-label" i18n>Include Packages</label>
<div class="col-md-4">
<div class="col-md-10 col-lg-8">
<wu-js-tree-wrapper
[treeNodes]="packageTree"
[(selectedNodes)]="analysisContext.includePackages"
Expand All @@ -42,7 +61,7 @@ <h2 *ngIf="!applicationGroup" i18n>Loading...</h2>
</div>
<div class="form-group">
<label class="col-md-2 control-label" i18n>Exclude Package</label>
<div class="col-md-3">
<div class="col-md-10 col-lg-8">
<wu-js-tree-wrapper
[treeNodes]="packageTree"
[(selectedNodes)]="analysisContext.excludePackages">
Expand All @@ -61,8 +80,18 @@ <h2 *ngIf="!applicationGroup" i18n>Loading...</h2>
</div>

<div class="form-group">
<label class="col-md-2 control-label" i18n>Advanced Options</label>
<label class="col-md-2 control-label">Custom Ruleset selection</label>
<div class="col-md-6">
<wu-custom-rule-selection
[selectedRulePaths]="analysisContext.rulesPaths"
(selectedRulePathsChanged)="rulesPathsChanged($event)">
</wu-custom-rule-selection>
</div>
</div>

<div class="form-group">
<label class="col-md-2 control-label" i18n>Advanced Options</label>
<div class="col-md-10 col-lg-8">
<wu-analysis-context-advanced-options
[(selectedOptions)]="analysisContext.advancedOptions"
(advancedOptionsChanged)="advancedOptionsChanged($event)"
Expand All @@ -72,10 +101,10 @@ <h2 *ngIf="!applicationGroup" i18n>Loading...</h2>
</div>
</div>
<div class="form-group">
<div class="col-md-10 col-md-offset-2">
<button *ngIf="isInWizard" [disabled]="!analysisContextForm.form.valid" class="btn btn-primary" (click)="saveAndRun()" i18n>Save &amp; Run</button>
<button [disabled]="!analysisContextForm.form.valid" class="btn btn-primary" (click)="save()" i18n>Save Configuration</button>
<button (click)="cancel()" type="button" class="btn btn-default" i18n>Cancel</button>
<div class="col-lg-10 col-lg-offset-2">
<button (click)="saveAndRun()" class="btn btn-primary" [disabled]="!analysisContextForm.form.valid" *ngIf="isInWizard" i18n>Save &amp; Run</button>
<button (click)="save()" class="btn btn-primary" [disabled]="!analysisContextForm.form.valid" i18n>Save Configuration</button>
<button (click)="cancel()" class="btn btn-default" type="button" i18n>Cancel</button>
</div>
</div>
</div>
Expand Down

0 comments on commit c840aad

Please sign in to comment.