-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add data model (AnalyticsJob and Point); Add API
- Loading branch information
Showing
28 changed files
with
481 additions
and
724 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
persistence/src/main/java/de/starwit/persistence/entity/AnalyticsJobEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package de.starwit.persistence.entity; | ||
|
||
import java.util.List; | ||
|
||
import de.starwit.persistence.enumeration.JobType; | ||
import jakarta.persistence.CascadeType; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.OneToMany; | ||
import jakarta.persistence.Table; | ||
|
||
@Entity | ||
@Table(name = "analytics_job") | ||
public class AnalyticsJobEntity extends AbstractEntity<Long> { | ||
|
||
@Column(name = "name") | ||
private String name; | ||
|
||
@Column(name = "parkingareaid") | ||
private String parkingAreaId; | ||
|
||
@Column(name = "type") | ||
private JobType type; | ||
|
||
@Column(name = "enabled") | ||
private Boolean enabled; | ||
|
||
@OneToMany(mappedBy = "analyticsJob", cascade = CascadeType.ALL, fetch = FetchType.EAGER) | ||
private List<PointEntity> geometryPoints; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getParkingAreaId() { | ||
return parkingAreaId; | ||
} | ||
|
||
public void setParkingAreaId(String parkingAreaId) { | ||
this.parkingAreaId = parkingAreaId; | ||
} | ||
|
||
public JobType getType() { | ||
return type; | ||
} | ||
|
||
public void setType(JobType type) { | ||
this.type = type; | ||
} | ||
|
||
public Boolean getEnabled() { | ||
return enabled; | ||
} | ||
|
||
public void setEnabled(Boolean enabled) { | ||
this.enabled = enabled; | ||
} | ||
|
||
public List<PointEntity> getGeometryPoints() { | ||
return geometryPoints; | ||
} | ||
|
||
public void setGeometryPoints(List<PointEntity> geometryPoints) { | ||
this.geometryPoints = geometryPoints; | ||
} | ||
|
||
} |
5 changes: 0 additions & 5 deletions
5
persistence/src/main/java/de/starwit/persistence/entity/Direction.java
This file was deleted.
Oops, something went wrong.
18 changes: 8 additions & 10 deletions
18
persistence/src/main/java/de/starwit/persistence/entity/FlowEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
persistence/src/main/java/de/starwit/persistence/entity/PointEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package de.starwit.persistence.entity; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.Table; | ||
|
||
@Entity | ||
@Table(name = "point") | ||
public class PointEntity extends AbstractEntity<Long> { | ||
|
||
@Column(name = "x") | ||
private Double x; | ||
|
||
@Column(name = "y") | ||
private Double y; | ||
|
||
@Column(name = "order_idx") | ||
private int orderIdx; | ||
|
||
@ManyToOne | ||
@JsonIgnore | ||
private AnalyticsJobEntity analyticsJob; | ||
|
||
public Double getX() { | ||
return x; | ||
} | ||
|
||
public void setX(Double x) { | ||
this.x = x; | ||
} | ||
|
||
public Double getY() { | ||
return y; | ||
} | ||
|
||
public void setY(Double y) { | ||
this.y = y; | ||
} | ||
|
||
public int getOrderIdx() { | ||
return orderIdx; | ||
} | ||
|
||
public void setOrderIdx(int orderIdx) { | ||
this.orderIdx = orderIdx; | ||
} | ||
|
||
public AnalyticsJobEntity getAnalyticsJob() { | ||
return analyticsJob; | ||
} | ||
|
||
public void setAnalyticsJob(AnalyticsJobEntity analyticsJob) { | ||
this.analyticsJob = analyticsJob; | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
persistence/src/main/java/de/starwit/persistence/enumeration/Direction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package de.starwit.persistence.enumeration; | ||
|
||
public enum Direction { | ||
in,out; | ||
} |
7 changes: 7 additions & 0 deletions
7
persistence/src/main/java/de/starwit/persistence/enumeration/JobType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package de.starwit.persistence.enumeration; | ||
|
||
public enum JobType { | ||
NOOP, | ||
LINE_CROSSING, | ||
AREA_OCCUPANCY; | ||
} |
18 changes: 18 additions & 0 deletions
18
persistence/src/main/java/de/starwit/persistence/repository/AnalyticsJobRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package de.starwit.persistence.repository; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import de.starwit.persistence.entity.AnalyticsJobEntity; | ||
|
||
/** | ||
* ObjectClass Repository class | ||
*/ | ||
@Repository | ||
public interface AnalyticsJobRepository extends JpaRepository<AnalyticsJobEntity, Long> { | ||
|
||
List<AnalyticsJobEntity> findByEnabledTrue(); | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
persistence/src/main/java/de/starwit/persistence/repository/PointRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package de.starwit.persistence.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import de.starwit.persistence.entity.PointEntity; | ||
|
||
/** | ||
* ObjectClass Repository class | ||
*/ | ||
@Repository | ||
public interface PointRepository extends JpaRepository<PointEntity, Long> { | ||
|
||
} |
Empty file.
28 changes: 0 additions & 28 deletions
28
persistence/src/main/resources/db/migration/V1_0__init.sql
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
persistence/src/main/resources/db/migration/V1_1__init.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
create table ANALYTICS_JOB ( | ||
ID bigserial not null, | ||
ENABLED boolean, | ||
TYPE smallint check (TYPE between 0 and 2), | ||
NAME varchar(255), | ||
PARKINGAREAID varchar(255), | ||
primary key (ID) | ||
); | ||
|
||
create table POINT ( | ||
ID bigserial not null, | ||
X float(53), | ||
Y float(53), | ||
ORDER_IDX integer, | ||
ANALYTICS_JOB_ID bigint, | ||
primary key (ID) | ||
); | ||
|
||
alter table if exists POINT | ||
add constraint "fk_point_analytics_job" | ||
foreign key (ANALYTICS_JOB_ID) | ||
references ANALYTICS_JOB; | ||
|
||
create table FLOW ( | ||
FLOWTIME timestamp(6) with time zone, | ||
ID bigserial not null, | ||
OBJECTCLASS_ID bigint, | ||
PARKINGAREAID bigint not null, | ||
DIRECTION varchar(255) check (DIRECTION in ('in','out')), | ||
OBJECTID varchar(255), | ||
primary key (ID) | ||
); | ||
|
||
create table OBJECTCLASS ( | ||
CLASSID integer, | ||
ID bigserial not null, | ||
NAME varchar(255), | ||
primary key (ID) | ||
); | ||
|
||
alter table if exists FLOW | ||
add constraint "fk_flow_objectclass" | ||
foreign key (OBJECTCLASS_ID) | ||
references OBJECTCLASS; | ||
|
69 changes: 69 additions & 0 deletions
69
rest/src/main/java/de/starwit/rest/controller/AnalyticsJobController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package de.starwit.rest.controller; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.server.ResponseStatusException; | ||
|
||
import de.starwit.persistence.entity.AnalyticsJobEntity; | ||
import de.starwit.service.impl.AnalyticsJobService; | ||
|
||
@RestController | ||
@RequestMapping("${rest.base-path}/analytics-job") | ||
public class AnalyticsJobController { | ||
|
||
@Autowired | ||
private AnalyticsJobService analyticsJobService; | ||
|
||
@GetMapping("/all") | ||
public ResponseEntity<List<AnalyticsJobEntity>> getAllJobs() { | ||
return new ResponseEntity<>(analyticsJobService.findAll(), HttpStatus.OK); | ||
} | ||
|
||
@GetMapping("/{id}") | ||
public ResponseEntity<AnalyticsJobEntity> getJob(@PathVariable long id) { | ||
AnalyticsJobEntity jobEntity = analyticsJobService.findById(id); | ||
if (jobEntity == null) { | ||
throw new ResponseStatusException(HttpStatus.NOT_FOUND); | ||
} | ||
return new ResponseEntity<>(jobEntity, HttpStatus.OK); | ||
} | ||
|
||
@PostMapping | ||
public ResponseEntity<AnalyticsJobEntity> postJob(@RequestBody AnalyticsJobEntity job) { | ||
if (job.getId() != null) { | ||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Field 'id' must not be set."); | ||
} | ||
AnalyticsJobEntity newEntity = analyticsJobService.saveNew(job); | ||
return new ResponseEntity<>(newEntity, HttpStatus.CREATED); | ||
} | ||
|
||
@PutMapping("/{id}") | ||
public ResponseEntity<AnalyticsJobEntity> updateJob(@PathVariable Long id, @RequestBody AnalyticsJobEntity job) { | ||
if (analyticsJobService.findById(id) == null) { | ||
throw new ResponseStatusException(HttpStatus.NOT_FOUND); | ||
} | ||
|
||
AnalyticsJobEntity updatedEntity = analyticsJobService.update(id, job); | ||
return new ResponseEntity<>(updatedEntity, HttpStatus.OK); | ||
} | ||
|
||
@DeleteMapping("/{id}") | ||
public ResponseEntity<String> deleteJob(@PathVariable Long id) { | ||
if (analyticsJobService.findById(id) == null) { | ||
throw new ResponseStatusException(HttpStatus.NOT_FOUND); | ||
} | ||
analyticsJobService.deleteById(id); | ||
return new ResponseEntity<>(HttpStatus.NO_CONTENT); | ||
} | ||
} |
Oops, something went wrong.