Skip to content
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
2 changes: 2 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

310 changes: 310 additions & 0 deletions .idea/IntelliLang.xml

Large diffs are not rendered by default.

30 changes: 29 additions & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/diff-generator.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions CamServer-springboot.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="FacetManager">
<facet type="jpa" name="JPA">
<configuration>
<setting name="validation-enabled" value="true" />
<setting name="provider-name" value="Hibernate" />
<datasource-mapping>
<factory-entry name="entityManagerFactory" value="ef732095-9390-4ad0-ba93-259ca10dea94" />
</datasource-mapping>
<naming-strategy-map>
<unit-entry name="entityManagerFactory" />
</naming-strategy-map>
</configuration>
</facet>
</component>
</module>
40 changes: 40 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>


<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>${querydsl.version}</version>
<classifier>jakarta</classifier>
</dependency>

</dependencies>

<build>
Expand All @@ -63,6 +71,38 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>5.1.0</version>
<classifier>jakarta</classifier>
</path>
<path>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<version>3.1.0</version>
</path>

<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.44</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-Aquerydsl.entityAccessors=true</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>


</project>
25 changes: 25 additions & 0 deletions src/main/java/edu/camserver/app/config/ImagePaths.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package edu.camserver.app.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.File;
import java.nio.file.Path;

@Component
public class ImagePaths {

private final Path baseDir;

public ImagePaths(@Value("${app.images.base-dir}") String baseDir) {
this.baseDir = Path.of(baseDir);
}

public File fileFor(String fileName) {
return baseDir.resolve(fileName).normalize().toFile();
}

public Path resolve(String fileName) {
return baseDir.resolve(fileName); // Should
}
}
30 changes: 30 additions & 0 deletions src/main/java/edu/camserver/app/controller/FeatController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package edu.camserver.app.controller;

import edu.camserver.app.model.Image;
import edu.camserver.app.service.ImageService;
import jakarta.persistence.NoResultException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
public class FeatController {
final private ImageService imageService;

public FeatController(ImageService imageService) {
this.imageService = imageService;
}

@RequestMapping("/feat")
public ResponseEntity<?> setFeatured(@RequestParam long imgId, @RequestParam Boolean feat) {
try {
Image image = imageService.setFeatured(imgId, feat);
return ResponseEntity.ok(image.toString());
} catch (NoResultException e) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package edu.camserver.app.controller;

import edu.camserver.app.model.platesolve.PlateSolveResult;
import edu.camserver.app.service.PlateSolveService;
import org.springframework.web.bind.annotation.CrossOrigin;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin(origins = "http://localhost:3000")
@RestController
@RequestMapping("/api/plate-solve")
public class PlateSolveController {
private final PlateSolveService plateSolveService;

public PlateSolveController(PlateSolveService plateSolveService) {
this.plateSolveService = plateSolveService;
}

@GetMapping("/{imgId}")
public PlateSolveResult status(@PathVariable long imgId) {
return plateSolveService.getStatus(imgId);
}

@PostMapping("/{imgId}")
public PlateSolveResult start(
@PathVariable long imgId,
@RequestParam(defaultValue = "false") boolean force,
@RequestParam(defaultValue = "false") boolean wait) {
return plateSolveService.start(imgId, force, wait);
}
}
65 changes: 46 additions & 19 deletions src/main/java/edu/camserver/app/controller/QueryController.java
Original file line number Diff line number Diff line change
@@ -1,46 +1,74 @@
package edu.camserver.app.controller;

import edu.camserver.app.service.DatabaseService;
import org.springframework.beans.factory.annotation.Autowired;
import edu.camserver.app.model.Camera;
import edu.camserver.app.model.Image;
import edu.camserver.app.config.ImagePaths;
import edu.camserver.app.model.ImageFilter;
import edu.camserver.app.service.CameraService;
import edu.camserver.app.service.ImageService;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import java.net.MalformedURLException;
import java.nio.file.*;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;



@CrossOrigin(origins = "http://128.111.23.114")
@CrossOrigin(origins = "http://localhost:3000")
@RestController
@RequestMapping("/api")
public class QueryController {

@Autowired
private DatabaseService db;
public QueryController(ImagePaths imagePaths, ImageService imageService, CameraService cameraService) {
this.imagePaths = imagePaths;
this.imageService = imageService;
this.cameraService = cameraService;
}

// Constructor injection
ImageService imageService;
CameraService cameraService;
private final ImagePaths imagePaths;

@GetMapping("/query")
public List<Map<String,Object>> query(
public List<Image> query(
@RequestParam(defaultValue="20") int pagesize,
@RequestParam(required=false) String conditions,
@RequestParam(defaultValue="DESC") String order,
@RequestParam(required=false) String lastUID) {
@RequestParam(required = false) String lastUID,
@RequestParam(required = false) Boolean featured,
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
@RequestParam(required = false) LocalDateTime startDate,
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
@RequestParam(required = false) LocalDateTime endDate,
@RequestParam(required = false) String siteName,
@RequestParam(required = false) String search,
@RequestParam(required = false) String period) {

return db.queryImages(pagesize, conditions, order, lastUID);
ImageFilter filter = new ImageFilter(featured, startDate, endDate, siteName, search, period);
return imageService.findAll(pagesize, lastUID, filter);
}

private final Path fileStorageLocation = Paths.get("/mnt/CamData/images/").toAbsolutePath().normalize();
@GetMapping("/query/{imgId}")
public ResponseEntity<Image> image(@PathVariable long imgId) {
try {
return ResponseEntity.ok(imageService.findById(imgId));
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
}
}

// private final Path fileStorageLocation = Paths.get("/mnt/CamData/images/").toAbsolutePath().normalize();

@GetMapping("/images/{fileName:.+}")
public ResponseEntity<Resource> getFile(@PathVariable String fileName) {
System.out.println(fileName);
try {
// Resolve file path safely
Path filePath = fileStorageLocation.resolve(fileName).normalize();
Path filePath = imagePaths.resolve(fileName);
Resource resource = new UrlResource(filePath.toUri());

if (!resource.exists()) {
Expand Down Expand Up @@ -68,7 +96,6 @@ public ResponseEntity<Resource> getFile(@PathVariable String fileName) {
}

@GetMapping("/sites")
public List<Map<String,Object>> sites() {
return db.querySites();
}
}
public List<Camera> sites() { return cameraService.getSites(); }

}
Loading