Skip to content

Commit

Permalink
Merge pull request #37 from gessi-chatbots/end-to-end
Browse files Browse the repository at this point in the history
End to end
  • Loading branch information
mtiessler authored Feb 3, 2025
2 parents 3806e18 + d2867b0 commit 99da5b1
Show file tree
Hide file tree
Showing 43 changed files with 1,674 additions and 205 deletions.
4 changes: 0 additions & 4 deletions src/main/java/upc/edu/gessi/repo/AppGraphRepoApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@SpringBootApplication
@EnableSwagger2
public class AppGraphRepoApplication {

private Logger logger = LoggerFactory.getLogger(AppGraphRepoApplication.class);

public static void main(String[] args) {
SpringApplication.run(AppGraphRepoApplication.class, args);
}
Expand Down
44 changes: 33 additions & 11 deletions src/main/java/upc/edu/gessi/repo/controller/AnalysisAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import upc.edu.gessi.repo.dto.Analysis.ApplicationDayStatisticsDTO;
import upc.edu.gessi.repo.dto.Analysis.TopDescriptorsDTO;
import upc.edu.gessi.repo.dto.Analysis.TopFeaturesDTO;
import upc.edu.gessi.repo.dto.Analysis.TopSentimentsDTO;
import upc.edu.gessi.repo.dto.Analysis.TopEmotionsDTO;
import upc.edu.gessi.repo.exception.MissingBodyException;

import java.io.IOException;
Expand All @@ -21,22 +22,43 @@
public interface AnalysisAPI extends BaseAPI {

@ApiOperation(value = "Get application statistics")
@GetMapping(value = "/{appName}/statistics", produces = "application/json")
@GetMapping(value = "/{appPackage}/statistics", produces = "application/json")
@ResponseBody
List<ApplicationDayStatisticsDTO> getApplicationStatistics(
@ApiParam(value = "Name of the application") @PathVariable String appName,
@ApiParam(value = "Start date") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) @RequestParam(name = "startDate", defaultValue = "2020-01-01") Date startDate,
@ApiParam(value = "End date") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) @RequestParam(name = "endDate", required = false) Date endDate);
@ApiParam(value = "Package of the application")
@PathVariable String appPackage,

@ApiOperation(value = "Get top sentiments by application names")
@PostMapping(value = "/top-sentiments", produces = "application/json")
@ApiParam(value = "Start date")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
@RequestParam(name = "startDate", defaultValue = "2020-01-01") Date startDate,

@ApiParam(value = "End date")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
@RequestParam(name = "endDate", required = false) Date endDate,

@ApiParam(value = "Descriptor")
@RequestParam(name = "descriptor", required = false) String descriptor);

@ApiOperation(value = "Get top sentiments by application packages")
@PostMapping(value = "/top-emotions", produces = "application/json")
@ResponseBody
TopEmotionsDTO getTopEmotionsByAppPackages(@RequestBody List<String> appPackages) throws MissingBodyException;

@ApiOperation(value = "Get top descriptors")
@GetMapping(value = "/top-descriptors", produces = "application/json")
@ResponseBody
TopDescriptorsDTO getTopDescriptors();

@ApiOperation(value = "Get top features")
@GetMapping (value = "/top-features", produces = "application/json")
@ResponseBody
TopSentimentsDTO getTopSentimentsByAppNames(@RequestBody List<String> appNames) throws MissingBodyException;
TopFeaturesDTO getTopFeatures();


@ApiOperation(value = "Get top features by application names")
@PostMapping(value = "/top-features", produces = "application/json")
@ApiOperation(value = "Get top features by application packages")
@PostMapping(value = "/top-features-by-packages", produces = "application/json")
@ResponseBody
TopFeaturesDTO getTopFeaturesByAppNames(@RequestBody List<String> appNames) throws MissingBodyException;
TopFeaturesDTO getTopFeaturesByAppPackages(@RequestBody List<String> appPackages) throws MissingBodyException;

@GetMapping("/excel")
ResponseEntity<byte[]> generateAnalyticalExcel() throws IOException;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/upc/edu/gessi/repo/controller/CrudAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.web.bind.annotation.*;
import upc.edu.gessi.repo.exception.NoObjectFoundException;
import upc.edu.gessi.repo.exception.ObjectNotFoundException;
import upc.edu.gessi.repo.exception.Reviews.NoReviewsFoundException;

import java.util.List;

Expand All @@ -14,7 +15,7 @@ public interface CrudAPI<T> extends BaseAPI {
ResponseEntity<List<T>> create(@RequestBody List<T> entity);

@GetMapping("/{id}")
ResponseEntity<T> get(@PathVariable String id) throws ObjectNotFoundException;
ResponseEntity<T> get(@PathVariable String id) throws ObjectNotFoundException, NoReviewsFoundException;

@GetMapping("/list")
ResponseEntity<List<T>> getListed(@RequestBody List<String> ids) throws NoObjectFoundException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ ResponseEntity<List<MobileApplicationBasicDataDTO>> getAllMobileApplicationsBasi
throws NoMobileApplicationsFoundException;


@GetMapping(value = "/{appName}/features", produces = "application/json")
@GetMapping(value = "/{appPackage}/features", produces = "application/json")
@ResponseBody
ResponseEntity<List<String>> getMobileApplicationFeatures(@PathVariable String appName);
ResponseEntity<List<String>> getMobileApplicationFeatures(@PathVariable String appPackage);

@PostMapping("/update-repository")
void updateRepository(@RequestParam(value = "url") String url);
Expand Down
15 changes: 9 additions & 6 deletions src/main/java/upc/edu/gessi/repo/controller/ReviewsAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import upc.edu.gessi.repo.dto.PageResponseDTO;
import upc.edu.gessi.repo.dto.Review.ReviewDTO;
import upc.edu.gessi.repo.dto.Review.ReviewFeatureRequestDTO;
import upc.edu.gessi.repo.dto.Review.ReviewFeatureResponseDTO;
import upc.edu.gessi.repo.dto.Review.ReviewDescriptorRequestDTO;
import upc.edu.gessi.repo.dto.Review.ReviewDescriptorResponseDTO;

import java.util.List;

Expand All @@ -20,8 +21,10 @@ ResponseEntity<byte[]> extractReviews(
@RequestParam(name = "size", defaultValue = "10000", required = false) Integer size,
@RequestParam(name = "market-segment", defaultValue = "Communication", required = false) String marketSegment);

@ApiOperation("Fetch reviews based on features")
@PostMapping(value = "/by-features")
ResponseEntity<List<ReviewFeatureResponseDTO>> getReviewsByFeatures(
@RequestBody ReviewFeatureRequestDTO request);
@ApiOperation("Fetch reviews based on filters (descriptors)")
@PostMapping(value = "/by-descriptors")
ResponseEntity<PageResponseDTO<ReviewDescriptorResponseDTO>> getReviewsByDescriptors(
@RequestBody ReviewDescriptorRequestDTO request,
@RequestParam(value = "page", defaultValue = "0", required = false) final Integer page,
@RequestParam(value = "size", defaultValue = "10", required = false) final Integer size);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
import org.springframework.web.bind.annotation.*;
import upc.edu.gessi.repo.controller.AnalysisAPI;
import upc.edu.gessi.repo.dto.Analysis.ApplicationDayStatisticsDTO;
import upc.edu.gessi.repo.dto.Analysis.TopDescriptorsDTO;
import upc.edu.gessi.repo.dto.Analysis.TopFeaturesDTO;
import upc.edu.gessi.repo.dto.Analysis.TopSentimentsDTO;
import upc.edu.gessi.repo.dto.Analysis.TopEmotionsDTO;
import upc.edu.gessi.repo.exception.MissingBodyException;
import upc.edu.gessi.repo.service.AnalysisService;
import upc.edu.gessi.repo.service.InductiveKnowledgeService;
Expand Down Expand Up @@ -44,15 +45,25 @@ private void validateAppNames(final List<String> appNames) throws MissingBodyExc
}
}
@Override
public TopSentimentsDTO getTopSentimentsByAppNames(final List<String> appNames) throws MissingBodyException {
validateAppNames(appNames);
return useAnalysisService().findTopSentimentsByApps(appNames);
public TopEmotionsDTO getTopEmotionsByAppPackages(final List<String> appPackages) throws MissingBodyException {
validateAppNames(appPackages);
return useAnalysisService().findTopEmotionsByApp(appPackages);
}

@Override
public TopFeaturesDTO getTopFeaturesByAppNames(final List<String> appNames) throws MissingBodyException {
validateAppNames(appNames);
return useAnalysisService().findTopFeaturesByApps(appNames);
public TopDescriptorsDTO getTopDescriptors() {
return useAnalysisService().findTopDescriptors();
}

@Override
public TopFeaturesDTO getTopFeaturesByAppPackages(final List<String> appPackages) throws MissingBodyException {
validateAppNames(appPackages);
return useAnalysisService().findTopFeaturesByApps(appPackages);
}

@Override
public TopFeaturesDTO getTopFeatures(){
return useAnalysisService().findTopFeatures();
}

@Override
Expand All @@ -67,16 +78,21 @@ public ResponseEntity<byte[]> generateAnalyticalExcel() throws IOException {
}

@Override
public List<ApplicationDayStatisticsDTO> getApplicationStatistics(final String appName,
public List<ApplicationDayStatisticsDTO> getApplicationStatistics(final String appPackage,
final Date startDate,
final Date endDate) {
final Date endDate,
final String descriptor) {
Date endDateAux = endDate;
if (endDateAux == null) {
logger.warn("No end date given, using today as end ate");
endDateAux = Calendar.getInstance().getTime();
}

return useAnalysisService().getApplicationStatistics(appName, startDate, endDateAux);
if (descriptor == null || descriptor.isEmpty()) {
return null;
}

return useAnalysisService().getApplicationStatistics(appPackage, descriptor, startDate, endDateAux);
}

private AnalysisService useAnalysisService() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import upc.edu.gessi.repo.dto.MobileApplication.MobileApplicationFullDataDTO;
import upc.edu.gessi.repo.exception.*;
import upc.edu.gessi.repo.exception.MobileApplications.NoMobileApplicationsFoundException;
import upc.edu.gessi.repo.exception.Reviews.NoReviewsFoundException;
import upc.edu.gessi.repo.service.AnalysisService;
import upc.edu.gessi.repo.service.GraphDBService;
import upc.edu.gessi.repo.service.MobileApplicationService;
Expand Down Expand Up @@ -100,7 +101,7 @@ public ResponseEntity<List<MobileApplicationFullDataDTO>> getAll() throws NoObje


@Override
public ResponseEntity<MobileApplicationFullDataDTO> get(final String id) throws ObjectNotFoundException {
public ResponseEntity<MobileApplicationFullDataDTO> get(final String id) throws ObjectNotFoundException, NoReviewsFoundException {
return new ResponseEntity<>(((MobileApplicationService) useService(MobileApplicationService.class)).get(id), HttpStatus.OK);
}

Expand All @@ -116,8 +117,8 @@ public ResponseEntity<List<MobileApplicationBasicDataDTO>> getAllMobileApplicati
}

@Override
public ResponseEntity<List<String>> getMobileApplicationFeatures(@PathVariable final String appName) {
return new ResponseEntity<>(((AnalysisService) useService(AnalysisService.class)).findAppFeatures(appName), HttpStatus.OK);
public ResponseEntity<List<String>> getMobileApplicationFeatures(@PathVariable final String appPackage) {
return new ResponseEntity<>(((AnalysisService) useService(AnalysisService.class)).findAppFeatures(appPackage), HttpStatus.OK);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import upc.edu.gessi.repo.controller.ReviewsAPI;
import upc.edu.gessi.repo.dto.PageResponseDTO;
import upc.edu.gessi.repo.dto.Review.ReviewDTO;
import upc.edu.gessi.repo.dto.Review.ReviewFeatureRequestDTO;
import upc.edu.gessi.repo.dto.Review.ReviewFeatureResponseDTO;
import upc.edu.gessi.repo.dto.Review.ReviewDescriptorRequestDTO;
import upc.edu.gessi.repo.dto.Review.ReviewDescriptorResponseDTO;
import upc.edu.gessi.repo.exception.*;
import upc.edu.gessi.repo.exception.Reviews.NoReviewsFoundException;
import upc.edu.gessi.repo.service.MobileApplicationService;
Expand Down Expand Up @@ -42,7 +43,7 @@ public ResponseEntity<List<ReviewDTO>> create(List<ReviewDTO> reviewDTOList) {
}

@Override
public ResponseEntity<ReviewDTO> get(String id) throws ObjectNotFoundException {
public ResponseEntity<ReviewDTO> get(String id) throws ObjectNotFoundException, NoReviewsFoundException {
return new ResponseEntity<>(((ReviewService) useService(ReviewService.class)).get(id), HttpStatus.OK);
}

Expand Down Expand Up @@ -85,18 +86,38 @@ public ResponseEntity<byte[]> extractReviews(final Integer size, final String ma
}

@Override
public ResponseEntity<List<ReviewFeatureResponseDTO>> getReviewsByFeatures(ReviewFeatureRequestDTO request) {
public ResponseEntity<PageResponseDTO<ReviewDescriptorResponseDTO>> getReviewsByDescriptors(
final ReviewDescriptorRequestDTO request,
final Integer page,
final Integer size) {
try {
return new ResponseEntity<>(((ReviewService) useService(ReviewService.class))
.getByAppIdAndFeatures(request.getAppName(),
request.getFeatureList()),
HttpStatus.OK);
ReviewService reviewService = (ReviewService) useService(ReviewService.class);

long totalElements = reviewService.getReviewCountByDescriptors(request);

List<ReviewDescriptorResponseDTO> reviews = reviewService.getByDescriptors(
request,
page != null ? page : 0,
size != null ? size : 10
);

PageResponseDTO<ReviewDescriptorResponseDTO> response = PageResponseDTO.of(
reviews,
page,
size,
totalElements
);

return ResponseEntity.ok(response);
} catch (NoReviewsFoundException e) {
return new ResponseEntity<>(null, HttpStatus.NO_CONTENT);
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null);
} catch (Exception e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}

}


private Object useService(Class<?> clazz) {
return serviceFactory.createService(clazz);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
@JsonIgnoreProperties(ignoreUnknown = true)
public class ApplicationDayStatisticsDTO {
private Date date;
private List<SentimentOccurrenceDTO> sentimentOccurrences;
private List<EmotionOccurrenceDTO> emotionOccurrences;
private List<FeatureOccurrenceDTO> featureOccurrences;
private List<PolarityOccurrenceDTO> polarityOccurrences;
private List<TypeOccurrenceDTO> typeOccurrences;
private List<TopicOccurrenceDTO> topicOccurrences;

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
@JsonIgnoreProperties(ignoreUnknown = true)
public class SentimentOccurrenceDTO {
private String sentimentName;
public class EmotionOccurrenceDTO {
private String emotion;
private Integer occurrences;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
@EqualsAndHashCode(callSuper = false)
@JsonIgnoreProperties(ignoreUnknown = true)
public class FeatureOccurrenceDTO {
private String featureName;
private String feature;
private Integer occurrences;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package upc.edu.gessi.repo.dto.Analysis;


import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.*;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
@JsonIgnoreProperties(ignoreUnknown = true)
public class PolarityOccurrenceDTO {
private String polarity;
private Integer occurrences;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package upc.edu.gessi.repo.dto.Analysis;


import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.*;

import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
@JsonIgnoreProperties(ignoreUnknown = true)
public class TopDescriptorsDTO {
private TopEmotionsDTO topEmotions;
private TopPolaritiesDTO topPolarities;
private TopTypesDTO topTypes;
private TopTopicsDTO topTopics;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
@JsonIgnoreProperties(ignoreUnknown = true)
public class TopSentimentsDTO {
private List<SentimentOccurrenceDTO> topSentiments;
public class TopEmotionsDTO {
private List<EmotionOccurrenceDTO> topEmotions;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package upc.edu.gessi.repo.dto.Analysis;


import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.*;

import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
@JsonIgnoreProperties(ignoreUnknown = true)
public class TopPolaritiesDTO {
private List<PolarityOccurrenceDTO> topPolarities;
}
Loading

0 comments on commit 99da5b1

Please sign in to comment.