Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analysis summary projection #73

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.jboss.xavier.integrations.jpa.projection;

import java.util.Date;

public interface AnalysisSummary
{
Long getId();
String getReportName();
String getReportDescription();
String getPayloadName();
Date getInserted();
Date getLastUpdate();
String getStatus();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.jboss.xavier.analytics.pojo.AdministrationMetricsProjection;
import org.jboss.xavier.analytics.pojo.output.AnalysisModel;
import org.jboss.xavier.integrations.jpa.projection.AnalysisSummary;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
Expand All @@ -18,10 +19,16 @@ public interface AnalysisRepository extends JpaRepository<AnalysisModel, Long>

Page<AnalysisModel> findByOwnerAndReportNameIgnoreCaseContaining(String owner, String filterText, Pageable pageable);

Page<AnalysisSummary> findAnalysisSummaryByOwnerAndReportNameIgnoreCaseContaining(String owner, String filterText, Pageable pageable);

Page<AnalysisModel> findAllByOwner(String owner, Pageable pageable);

Page<AnalysisSummary> findAllAnalysisSummaryByOwner(String owner, Pageable pageable);

AnalysisModel findByOwnerAndId(String owner, Long id);

AnalysisSummary findAnalysisSummaryByOwnerAndId(String owner, Long id);

Integer countByOwner(String owner);

AnalysisModel findByIdAndStatusIgnoreCaseNot(Long id, String status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.jboss.xavier.analytics.pojo.output.InitialSavingsEstimationReportModel;
import org.jboss.xavier.analytics.pojo.output.workload.inventory.WorkloadInventoryReportModel;
import org.jboss.xavier.analytics.pojo.output.workload.summary.WorkloadSummaryReportModel;
import org.jboss.xavier.integrations.jpa.projection.AnalysisSummary;
import org.jboss.xavier.integrations.jpa.repository.AnalysisRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
Expand Down Expand Up @@ -42,6 +43,11 @@ public AnalysisModel findByOwnerAndId(String owner, Long id)
return analysisRepository.findByOwnerAndId(owner, id);
}

public AnalysisSummary findAnalysisSummaryByOwnerAndId(String owner, Long id)
{
return analysisRepository.findAnalysisSummaryByOwnerAndId(owner, id);
}

public void deleteById(Long id)
{
analysisRepository.delete(id);
Expand Down Expand Up @@ -103,6 +109,12 @@ public Page<AnalysisModel> findAllByOwner(String owner, int page, int size)
return analysisRepository.findAllByOwner(owner, pageable);
}

public Page<AnalysisSummary> findAllAnalysisSummaryByOwner(String owner, int page, int size)
{
Pageable pageable = new PageRequest(page, size, new Sort(Sort.Direction.DESC, "id"));
return analysisRepository.findAllAnalysisSummaryByOwner(owner, pageable);
}

public Integer countByOwner(String owner)
{
return analysisRepository.countByOwner(owner);
Expand All @@ -114,6 +126,12 @@ public Page<AnalysisModel> findByOwnerAndReportName(String owner, String filterT
return analysisRepository.findByOwnerAndReportNameIgnoreCaseContaining(owner, filterText.trim(), pageable);
}

public Page<AnalysisSummary> findAnalysisSummaryByOwnerAndReportName(String owner, String filterText, int page, int size)
{
Pageable pageable = new PageRequest(page, size, new Sort(Sort.Direction.DESC, "id"));
return analysisRepository.findAnalysisSummaryByOwnerAndReportNameIgnoreCaseContaining(owner, filterText.trim(), pageable);
}

public void updateStatus(String status, Long id) {
AnalysisModel analysisModel = findById(id);
analysisModel.setStatus(status);
Expand Down
12 changes: 6 additions & 6 deletions src/main/resources/spring/camel-context.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,25 +128,25 @@
<route id="reports-get-all">
<choice>
<when>
<simple>${header.filterText} == null</simple>
<bean ref="analysisService" method="findAllByOwner(${header.${type:org.jboss.xavier.integrations.route.RouteBuilderExceptionHandler.USERNAME}}, ${header.page}, ${header.size})" />
<simple>${header.filterText} == null || ${header.filterText} == ''</simple>
<bean ref="analysisService" method="findAllAnalysisSummaryByOwner(${header.${type:org.jboss.xavier.integrations.route.RouteBuilderExceptionHandler.USERNAME}}, ${header.page}, ${header.size})" />
</when>
<otherwise>
<bean ref="analysisService" method="findByOwnerAndReportName(${header.${type:org.jboss.xavier.integrations.route.RouteBuilderExceptionHandler.USERNAME}}, ${header.filterText}, ${header.page}, ${header.size})" />
<bean ref="analysisService" method="findAnalysisSummaryByOwnerAndReportName(${header.${type:org.jboss.xavier.integrations.route.RouteBuilderExceptionHandler.USERNAME}}, ${header.filterText}, ${header.page}, ${header.size})" />
</otherwise>
</choice>
</route>
</get>
<get uri="/{id}">
<description>Get the details of a report</description>
<route id="report-get-details">
<bean ref="analysisService" method="findByOwnerAndId(${header.${type:org.jboss.xavier.integrations.route.RouteBuilderExceptionHandler.USERNAME}}, ${header.id})" />
<bean ref="analysisService" method="findAnalysisSummaryByOwnerAndId(${header.${type:org.jboss.xavier.integrations.route.RouteBuilderExceptionHandler.USERNAME}}, ${header.id})" />
</route>
</get>
<delete uri="/{id}">
<description>Delete a report</description>
<route id="report-delete">
<bean ref="analysisService" method="findByOwnerAndId(${header.${type:org.jboss.xavier.integrations.route.RouteBuilderExceptionHandler.USERNAME}}, ${header.id})"/>
<bean ref="analysisService" method="findAnalysisSummaryByOwnerAndId(${header.${type:org.jboss.xavier.integrations.route.RouteBuilderExceptionHandler.USERNAME}}, ${header.id})"/>
<choice>
<when>
<simple>${body} != null</simple>
Expand Down Expand Up @@ -208,7 +208,7 @@
<description>Get available filters</description>
<route id="workload-inventory-report-available-filters">
<!-- if the user is the owner of the analysis then it's fine to get the filters -->
<bean ref="analysisService" method="findByOwnerAndId(${header.${type:org.jboss.xavier.integrations.route.RouteBuilderExceptionHandler.USERNAME}}, ${header.id})"/>
<bean ref="analysisService" method="findAnalysisSummaryByOwnerAndId(${header.${type:org.jboss.xavier.integrations.route.RouteBuilderExceptionHandler.USERNAME}}, ${header.id})"/>
<choice>
<when>
<simple>${body} != null</simple>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.apache.commons.io.IOUtils;
import org.jboss.xavier.Application;
import org.jboss.xavier.analytics.pojo.output.AnalysisModel;
import org.jboss.xavier.integrations.jpa.projection.AnalysisSummary;
import org.jboss.xavier.integrations.jpa.service.AnalysisService;
import org.jboss.xavier.integrations.jpa.service.FlagService;
import org.jboss.xavier.integrations.jpa.service.InitialSavingsEstimationReportService;
Expand Down Expand Up @@ -34,6 +35,7 @@
import javax.servlet.http.HttpServletResponse;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand Down Expand Up @@ -89,7 +91,7 @@ public void xmlRouteBuilder_RestReport_NoParamGiven_ShouldCallFindReports() thro
ResponseEntity<String> response = restTemplate.exchange(camel_context + "report/", HttpMethod.GET, entity, String.class);

//Then
verify(analysisService).findAllByOwner("[email protected]", 0, 10);
verify(analysisService).findAllAnalysisSummaryByOwner("[email protected]", 0, 10);
assertThat(response).isNotNull();
assertThat(response.getBody()).contains("\"content\":[]");
assertThat(response.getBody()).contains("\"size\":10");
Expand Down Expand Up @@ -136,7 +138,7 @@ public void xmlRouteBuilder_RestReport_PageAndSizeParamGiven_ShouldCallFindRepor
ResponseEntity<String> response = restTemplate.exchange(camel_context + "report?page={page}&size={size}", HttpMethod.GET, entity, String.class, variables);

//Then
verify(analysisService).findAllByOwner("[email protected]", page, size);
verify(analysisService).findAllAnalysisSummaryByOwner("[email protected]", page, size);
assertThat(response).isNotNull();
assertThat(response.getBody()).contains("\"content\":[]");
assertThat(response.getBody()).contains("\"size\":3");
Expand Down Expand Up @@ -167,7 +169,36 @@ public void xmlRouteBuilder_RestReport_FilterTextPageAndSizeParamGiven_ShouldCal
ResponseEntity<String> response = restTemplate.exchange(camel_context + "report?page={page}&size={size}&filterText={filterText}", HttpMethod.GET, entity, String.class, variables);

//Then
verify(analysisService).findByOwnerAndReportName("[email protected]", filterText, page, size);
verify(analysisService).findAnalysisSummaryByOwnerAndReportName("[email protected]", filterText, page, size);
assertThat(response).isNotNull();
assertThat(response.getBody()).contains("\"content\":[]");
assertThat(response.getBody()).contains("\"size\":3");
camelContext.stop();
}

@Test
public void xmlRouteBuilder_RestReport_FilterTextEmptyPageAndSizeParamGiven_ShouldCallFindReports() throws Exception {
//Given
//When
camelContext.start();
TestUtil.startUsernameRoutes(camelContext);
camelContext.startRoute("reports-get-all");
Map<String, Object> variables = new HashMap<>();
int page = 2;
variables.put("page", page);
int size = 3;
variables.put("size", size);
String filterText = "";
variables.put("filterText", filterText);

HttpHeaders headers = new HttpHeaders();
headers.set(TestUtil.HEADER_RH_IDENTITY, TestUtil.getBase64RHIdentity());
HttpEntity<String> entity = new HttpEntity<>(null, headers);

ResponseEntity<String> response = restTemplate.exchange(camel_context + "report?page={page}&size={size}&filterText={filterText}", HttpMethod.GET, entity, String.class, variables);

//Then
verify(analysisService).findAllAnalysisSummaryByOwner("[email protected]", page, size);
assertThat(response).isNotNull();
assertThat(response.getBody()).contains("\"content\":[]");
assertThat(response.getBody()).contains("\"size\":3");
Expand Down Expand Up @@ -195,7 +226,7 @@ public void xmlRouteBuilder_RestReportId_IdParamGiven_ShouldCallFindById() throw
ResponseEntity<String> response = restTemplate.exchange(camel_context + "report/{id}", HttpMethod.GET, entity, String.class, variables);

//Then
verify(analysisService).findByOwnerAndId("[email protected]", one);
verify(analysisService).findAnalysisSummaryByOwnerAndId("[email protected]", one);
assertThat(response).isNotNull();
camelContext.stop();
}
Expand Down Expand Up @@ -437,7 +468,7 @@ public void xmlRouteBuilder_RestReportId_IdParamGiven_AndIdNotExists_ShouldRetur
//Given

Long one = 1L;
when(analysisService.findByOwnerAndId("[email protected]", one)).thenReturn(null);
when(analysisService.findAnalysisSummaryByOwnerAndId("[email protected]", one)).thenReturn(null);

//When
camelContext.start();
Expand All @@ -454,7 +485,7 @@ public void xmlRouteBuilder_RestReportId_IdParamGiven_AndIdNotExists_ShouldRetur

//Then
Assert.assertEquals(response.getStatusCodeValue(), HttpServletResponse.SC_NOT_FOUND);
verify(analysisService).findByOwnerAndId("[email protected]", one);
verify(analysisService).findAnalysisSummaryByOwnerAndId("[email protected]", one);
verify(analysisService, never()).deleteById(one);
assertThat(response).isNotNull();
assertThat(response.getBody()).contains("Analysis not found");
Expand All @@ -466,7 +497,42 @@ public void xmlRouteBuilder_RestReportId_IdParamGiven_AndIdExists_ShouldCallDele
//Given

Long one = 1L;
when(analysisService.findByOwnerAndId("[email protected]",one)).thenReturn(new AnalysisModel());
when(analysisService.findAnalysisSummaryByOwnerAndId("[email protected]",one)).thenReturn(new AnalysisSummary() {
@Override
public Long getId() {
return null;
}

@Override
public String getReportName() {
return null;
}

@Override
public String getReportDescription() {
return null;
}

@Override
public String getPayloadName() {
return null;
}

@Override
public Date getInserted() {
return null;
}

@Override
public Date getLastUpdate() {
return null;
}

@Override
public String getStatus() {
return null;
}
});
doNothing().when(analysisService).deleteById(one);

//When
Expand All @@ -485,7 +551,7 @@ public void xmlRouteBuilder_RestReportId_IdParamGiven_AndIdExists_ShouldCallDele
//Then
Assert.assertEquals(response.getStatusCodeValue(), HttpServletResponse.SC_NO_CONTENT);
Assert.assertNull(response.getBody());
verify(analysisService).findByOwnerAndId("[email protected]",one);
verify(analysisService).findAnalysisSummaryByOwnerAndId("[email protected]",one);
verify(analysisService).deleteById(one);
assertThat(response).isNotNull();
assertThat(response.getBody()).isNull();
Expand Down Expand Up @@ -524,7 +590,42 @@ public void xmlRouteBuilder_RestReportIdWorkloadInventory_IdParamGiven_ShouldCal
public void xmlRouteBuilder_RestReportIdWorkloadInventory_IdParamGiven_ShouldCallFindByAnalysisIdAndReturnAvailableFilters() throws Exception {
//Given
Long one = 1L;
when(analysisService.findByOwnerAndId("[email protected]", one)).thenReturn(new AnalysisModel());
when(analysisService.findAnalysisSummaryByOwnerAndId("[email protected]", one)).thenReturn(new AnalysisSummary() {
@Override
public Long getId() {
return null;
}

@Override
public String getReportName() {
return null;
}

@Override
public String getReportDescription() {
return null;
}

@Override
public String getPayloadName() {
return null;
}

@Override
public Date getInserted() {
return null;
}

@Override
public Date getLastUpdate() {
return null;
}

@Override
public String getStatus() {
return null;
}
});

//When
camelContext.start();
Expand All @@ -539,7 +640,7 @@ public void xmlRouteBuilder_RestReportIdWorkloadInventory_IdParamGiven_ShouldCal
ResponseEntity<String> response = restTemplate.exchange(camel_context + "report/{id}/workload-inventory/available-filters" , HttpMethod.GET, entity, String.class, variables);

//Then
verify(analysisService).findByOwnerAndId("[email protected]", one);
verify(analysisService).findAnalysisSummaryByOwnerAndId("[email protected]", one);
verify(workloadInventoryReportService).findAvailableFiltersByAnalysisId(one);
assertThat(response).isNotNull();
camelContext.stop();
Expand Down