...
 
Commits (2)
......@@ -24,10 +24,12 @@
<timestamp>${maven.build.timestamp}</timestamp>
<maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format>
<commons-lang3.version>3.9</commons-lang3.version>
<commons-lang3.version>3.10</commons-lang3.version>
<commons-collections4.version>4.4</commons-collections4.version>
<jacoco-maven-plugin.version>0.8.4</jacoco-maven-plugin.version>
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<pitest-maven.version>1.5.2</pitest-maven.version>
<pitest-junit5-plugin.version>0.12</pitest-junit5-plugin.version>
</properties>
<dependencies>
......@@ -47,16 +49,7 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hateoas</artifactId>
</dependency>
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>-->
<!--
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
......@@ -101,7 +94,7 @@
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>1.5.2</version>
<version>${pitest-maven.version}</version>
<executions>
<execution>
<id>mutation</id>
......@@ -115,7 +108,7 @@
<dependency>
<groupId>org.pitest</groupId>
<artifactId>pitest-junit5-plugin</artifactId>
<version>0.12</version>
<version>${pitest-junit5-plugin.version}</version>
</dependency>
</dependencies>
<configuration>
......@@ -174,7 +167,6 @@
<version>${project.parent.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</profile>
</profiles>
......
......@@ -17,6 +17,7 @@ public class RelveoApplication {
public static void main(String[] args) {
SpringApplication.run(RelveoApplication.class, args);
System.setProperty("tomcat.util.http.parser.HttpParser.requestTargetAllow","|{}");
}
public static void Browse(String url) {
......
......@@ -14,7 +14,7 @@ import java.util.Date;
* Created by andy on 24/03/17.
*/
@Entity
@Table(indexes = {@Index(columnList = "userId", name = "electricity_userid_idx")})
@Table(indexes = {@Index(columnList = "userId", unique = true, name = "electricity_userid_idx")})
@Data
@NoArgsConstructor
@AllArgsConstructor
......
......@@ -2,32 +2,51 @@ package com.andycostanza.relveo.electricity;
import com.andycostanza.relveo.chart.service.ChartService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.hateoas.server.ExposesResourceFor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/electricityIndexStatements")
@ExposesResourceFor(ElectricityIndexStatement.class)
@Slf4j
public class ElectricityIndexStatementController {
private final ElectricityIndexStatementRepository repository;
private final ChartService chartService;
public String decode(String encoded) {
byte[] base64decodedBytes = Base64.getDecoder()
.decode(encoded);
return new String(base64decodedBytes,
StandardCharsets.UTF_8);
}
@GetMapping
public ResponseEntity findAllPaginate(@RequestParam("page") int page, @RequestParam("size") int size) {
return ResponseEntity.ok(repository.findAll(PageRequest.of(page,
size,
Sort.by(Sort.Direction.DESC, "statementDate"))));
public ResponseEntity findAllPaginate(@RequestParam("userId") String userId, @RequestParam(name = "page", required = false) int page,
@RequestParam(name = "size", required = false) int size) {
log.info("userId {}",
userId);
return ResponseEntity.ok(repository.findByUserId(decode(userId), PageRequest.of(page,
size,
Sort.by(Sort.Direction.DESC,
"statementDate"))));
}
@GetMapping("/chart")
public ResponseEntity buildChart() {
public ResponseEntity buildChart(@RequestParam("userId") String userId) {
log.info("userId {}",
userId);
return ResponseEntity.ok(chartService.electricityConsumptionCalculator(
repository.findTop53ByOrderByStatementDateDesc()));
repository.findTop53ByUserIdOrderByStatementDateDesc(decode(userId))));
}
@GetMapping("/{id}")
......@@ -53,7 +72,8 @@ public class ElectricityIndexStatementController {
@DeleteMapping("/{id}")
public ResponseEntity delete(@PathVariable("id") Long id) {
repository.deleteById(id);
return ResponseEntity.noContent().build();
return ResponseEntity.noContent()
.build();
}
}
package com.andycostanza.relveo.electricity;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
......@@ -10,5 +11,6 @@ import java.util.List;
*/
@Repository
public interface ElectricityIndexStatementRepository extends JpaRepository<ElectricityIndexStatement, Long> {
List<ElectricityIndexStatement> findTop53ByOrderByStatementDateDesc();
List<ElectricityIndexStatement> findTop53ByUserIdOrderByStatementDateDesc(String userId);
List<ElectricityIndexStatement> findByUserId(String userId, Pageable page);
}
......@@ -14,7 +14,7 @@ import java.util.Date;
* Created by andy on 24/03/17.
*/
@Entity
@Table(indexes = {@Index(columnList = "userId", name = "heating_userid_idx")})
@Table(indexes = {@Index(columnList = "userId", unique = true, name = "heating_userid_idx")})
@Data
@NoArgsConstructor
@AllArgsConstructor
......
......@@ -14,7 +14,7 @@ import java.util.Date;
* Created by andy on 24/03/17.
*/
@Entity
@Table(indexes = {@Index(columnList = "userId", name = "water_userid_idx")})
@Table(indexes = {@Index(columnList = "userId", unique = true, name = "water_userid_idx")})
@Data
@NoArgsConstructor
@AllArgsConstructor
......
......@@ -41,7 +41,7 @@ class ElectricityIndexStatementControllerTest {
.id(1L)
.build())));
//when
ResponseEntity result = controller.findAllPaginate(1,
ResponseEntity result = controller.findAllPaginate("userId",1,
1);
//then
Mockito.verify(repository,
......@@ -59,7 +59,7 @@ class ElectricityIndexStatementControllerTest {
@DisplayName("should buildChart method retrieve data in repository and return a body with HTTP 200")
void buildChartTest10() {
//given
Mockito.when(repository.findTop53ByOrderByStatementDateDesc())
Mockito.when(repository.findTop53ByUserIdOrderByStatementDateDesc("userId"))
.thenReturn(Collections.singletonList(ElectricityIndexStatement.builder()
.id(1L)
.build()));
......@@ -69,12 +69,12 @@ class ElectricityIndexStatementControllerTest {
.build()));
//when
ResponseEntity result = controller.buildChart();
ResponseEntity result = controller.buildChart("userId");
//then
Mockito.verify(repository,
Mockito.times(1))
.findTop53ByOrderByStatementDateDesc();
.findTop53ByUserIdOrderByStatementDateDesc("userId");
Mockito.verify(chartService,
Mockito.times(1))
.electricityConsumptionCalculator(Mockito.anyList());
......
......@@ -5,7 +5,7 @@
<artifactId>relveo-frontend</artifactId>
<description>The relveo frontend project</description>
<properties>
<frontend-maven-plugin.version>1.8.0</frontend-maven-plugin.version>
<frontend-maven-plugin.version>1.10.0</frontend-maven-plugin.version>
</properties>
<parent>
......@@ -27,8 +27,8 @@
<artifactId>frontend-maven-plugin</artifactId>
<version>${frontend-maven-plugin.version}</version>
<configuration>
<nodeVersion>v12.13.0</nodeVersion>
<npmVersion>6.12.0</npmVersion>
<nodeVersion>v12.18.1</nodeVersion>
<npmVersion>6.14.5</npmVersion>
<workingDirectory>src/main/frontend</workingDirectory>
</configuration>
<executions>
......
......@@ -25,7 +25,7 @@
"@angular/router": "9.1.11",
"@auth0/auth0-spa-js": "^1.10.0",
"@ng-bootstrap/ng-bootstrap": "^6.1.0",
"@swimlane/ngx-charts": "^12.1.0",
"@swimlane/ngx-charts": "^14.0.0",
"core-js": "^2.4.1",
"d3": "^5.16.0",
"rxjs": "^6.5.3",
......
import {Component, Input, OnInit} from '@angular/core';
import {ElectricityService} from "../service/electricity.service";
import {AuthService} from '../auth.service';
@Component({
selector: 'app-electricity-chart',
......@@ -26,7 +27,7 @@ export class ElectricityChartComponent implements OnInit {
// line, area
autoScale = true;
constructor(private electricityService: ElectricityService) {
constructor(private electricityService: ElectricityService, public auth: AuthService) {
}
......@@ -38,7 +39,7 @@ export class ElectricityChartComponent implements OnInit {
}
initElectricityChart() {
this.electricityService.getChart()
this.electricityService.getChart(btoa(this.auth.getUserId()))
.subscribe(list => this.multi = list);
}
......
......@@ -46,7 +46,7 @@ export class ElectricityComponent implements OnInit {
}
refreshElectricityChart() {
this.electricityService.getChart()
this.electricityService.getChart(btoa(this.auth.getUserId()))
.subscribe(list => this.multi = list);
}
......@@ -58,7 +58,7 @@ export class ElectricityComponent implements OnInit {
}
loadData() {
this.electricityService.getAllPaginate(
this.electricityService.getAllPaginate(btoa(this.auth.getUserId()),
this.page - 1,
this.itemsPerPage,
).subscribe(
......
import {Component, Input, OnInit} from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Location } from '@angular/common';
import {ActivatedRoute} from '@angular/router';
import {Location} from '@angular/common';
import {Heating} from '../model/heating';
import {HeatingService} from '../service/heating.service';
import {AuthService} from '../auth.service';
@Component({
selector: 'app-heating-detail',
......@@ -13,7 +14,8 @@ export class HeatingDetailComponent implements OnInit {
@Input() heating: Heating;
constructor(private route: ActivatedRoute,
private heatingService: HeatingService,
private location: Location) { }
private location: Location,
public auth: AuthService) { }
ngOnInit() {
this.heating=new Heating();
......@@ -29,6 +31,7 @@ export class HeatingDetailComponent implements OnInit {
this.location.back();
}
onSubmit(): void {
this.heating.userId = this.auth.getUserId();
console.log("PUT to backend : " + JSON.stringify(this.heating));
this.heatingService.update(this.heating)
.subscribe(() => this.goBack());
......
......@@ -16,15 +16,15 @@ export class ElectricityService {
constructor(private http: HttpClient) {
}
getChart() : Observable<any>{
return this.http.get<any>(this.url+'/chart')
getChart(userId: string) : Observable<any>{
return this.http.get<any>(this.url+'/chart?userId='+userId)
.pipe(
catchError(this.handleError('getChart', []))
)
;
}
getAllPaginate(page: number, size:number): Observable<Page> {
return this.http.get<Page>(this.url+'?size='+size+'&page='+page)
getAllPaginate(userId: string, page: number, size:number): Observable<Page> {
return this.http.get<Page>(this.url+'?userId='+userId+'&size='+size+'&page='+page)
.pipe(
catchError(this.handleError<Page>('getAllPaginate'))
)
......
import {Component, Input, OnInit} from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Location } from '@angular/common';
import {ActivatedRoute} from '@angular/router';
import {Location} from '@angular/common';
import {Water} from '../model/water';
import {WaterService} from '../service/water.service';
import {AuthService} from '../auth.service';
@Component({
selector: 'app-water-detail',
......@@ -13,7 +14,8 @@ export class WaterDetailComponent implements OnInit {
@Input() water: Water;
constructor(private route: ActivatedRoute,
private waterService: WaterService,
private location: Location) { }
private location: Location,
public auth: AuthService) { }
ngOnInit() {
this.water=new Water();
......@@ -29,6 +31,7 @@ export class WaterDetailComponent implements OnInit {
this.location.back();
}
onSubmit(): void {
this.water.userId = this.auth.getUserId();
console.log("PUT to backend : " + JSON.stringify(this.water));
this.waterService.update(this.water)
.subscribe(() => this.goBack());
......