Skip to content

Commit

Permalink
feat: Add data model (AnalyticsJob and Point); Add API
Browse files Browse the repository at this point in the history
  • Loading branch information
flonix8 committed Nov 9, 2023
1 parent e7bb745 commit 0e2af1c
Show file tree
Hide file tree
Showing 28 changed files with 481 additions and 724 deletions.
7 changes: 6 additions & 1 deletion application/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ spring.datasource.username=databackend
spring.datasource.password=databackend
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.data.rest.detection-strategy=annotated
#spring.jpa.hibernate.ddl-auto=create
# spring.jpa.hibernate.ddl-auto=create-drop
# logging.level.org.hibernate.SQL=DEBUG

# Flyway
# spring.flyway.enabled=false
spring.flyway.user=${spring.datasource.username}
spring.flyway.password=${spring.datasource.password}
spring.flyway.url=${spring.datasource.url}
Expand All @@ -34,5 +36,8 @@ spring.flyway.placeholder-replacement=false
# OpenApi
springdoc.swagger-ui.csrf.enabled=true

# Configuration
analytics.dataRetrievalRate=1000

# logging.level.org.springframework.security=DEBUG
# logging.level.org.springframework.web=DEBUG
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;
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
package de.starwit.persistence.entity;

import java.time.ZonedDateTime;

import com.fasterxml.jackson.annotation.JsonFilter;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import de.starwit.persistence.enumeration.Direction;
import de.starwit.persistence.serializer.ZonedDateTimeDeserializer;
import de.starwit.persistence.serializer.ZonedDateTimeSerializer;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;
import jakarta.validation.constraints.NotNull;
import java.util.Date;

import java.time.ZonedDateTime;
import de.starwit.persistence.serializer.ZonedDateTimeSerializer;
import de.starwit.persistence.serializer.ZonedDateTimeDeserializer;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import jakarta.persistence.CascadeType;

/**
* Flow Entity class
Expand Down
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;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package de.starwit.persistence.enumeration;

public enum Direction {
in,out;
}
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;
}
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();

}
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 persistence/src/main/resources/db/migration/V1_0__init.sql

This file was deleted.

45 changes: 45 additions & 0 deletions persistence/src/main/resources/db/migration/V1_1__init.sql
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;

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);
}
}
Loading

0 comments on commit 0e2af1c

Please sign in to comment.