Skip to content

Commit

Permalink
Added camera group support to dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS94 committed Oct 27, 2018
1 parent 49ef91a commit a4a9987
Show file tree
Hide file tree
Showing 26 changed files with 610 additions and 175 deletions.
5 changes: 4 additions & 1 deletion cramp-api/src/main/java/org/eduze/fyp/api/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ private Constants() { }
/** Width and hight of the standardized camera views */
public static final int CAMERA_VIEW_WIDTH = 500;
public static final int CAMERA_VIEW_HEIGHT = 500;
/** Width and height of map images */
public static final int MAP_IMAGE_WIDTH = 500;
public static final int MAP_IMAGE_HEIGHT = 500;

/** Represents the zone -> world*/
/** Represents the zone -> world */
public static final String ZONE_NAME_WORLD = "World";

public static class Properties {
Expand Down
11 changes: 11 additions & 0 deletions cramp-api/src/main/java/org/eduze/fyp/api/model/CameraConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public class CameraConfig {
@OneToOne(mappedBy = "cameraConfig", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private PointMapping pointMapping = new PointMapping();

@ManyToOne
private CameraGroup cameraGroup;

public byte[] getView() {
return view;
}
Expand Down Expand Up @@ -94,6 +97,14 @@ public void setId(int id) {
this.id = id;
}

public CameraGroup getCameraGroup() {
return cameraGroup;
}

public void setCameraGroup(CameraGroup cameraGroup) {
this.cameraGroup = cameraGroup;
}

public String toString() {
return String.format("{ camera : %s, ipAndPort : %s, pointMappings: %s }", cameraId, ipAndPort, pointMapping);
}
Expand Down
74 changes: 74 additions & 0 deletions cramp-api/src/main/java/org/eduze/fyp/api/model/CameraGroup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* <Paste your header here>
*/
package org.eduze.fyp.api.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.OneToMany;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import java.util.Set;

@XmlRootElement
@Entity
@JsonIgnoreProperties("cameraConfigs")
public class CameraGroup {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;

@Column(unique = true)
private String name;

@Lob
@Column(columnDefinition = "LONGBLOB")
private byte[] map;

@XmlTransient
@OneToMany(mappedBy = "cameraGroup")
private Set<CameraConfig> cameraConfigs;

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public byte[] getMap() {
return map;
}

public void setMap(byte[] map) {
this.map = map;
}

public Set<CameraConfig> getCameraConfigs() {
return cameraConfigs;
}

public void setCameraConfigs(Set<CameraConfig> cameraConfigs) {
this.cameraConfigs = cameraConfigs;
}

public String toString() {
return String.format("%s", name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
package org.eduze.fyp.api.model.helpers;

import org.eduze.fyp.api.resources.Point;
import org.springframework.util.StringUtils;

import javax.persistence.AttributeConverter;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand All @@ -40,6 +42,10 @@ public String convertToDatabaseColumn(List<Point> points) {

@Override
public List<Point> convertToEntityAttribute(String stringPoints) {
if (StringUtils.isEmpty(stringPoints)) {
return Collections.emptyList();
}

return Stream.of(stringPoints.split(";"))
.map(str -> {
String[] parts = str.split(",");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static BufferedImage byteArrayToBufferedImage(byte[] array) throws IOExce

public static BufferedImage resize(BufferedImage img, int newW, int newH) {
Image tmp = img.getScaledInstance(newW, newH, Image.SCALE_SMOOTH);
BufferedImage dimg = new BufferedImage(newW, newH, BufferedImage.TYPE_INT_ARGB);
BufferedImage dimg = new BufferedImage(newW, newH, BufferedImage.TYPE_INT_RGB);

Graphics2D g2d = dimg.createGraphics();
g2d.drawImage(tmp, 0, 0, null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017 Eduze
* Copyright 2018 Eduze
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
Expand All @@ -17,18 +17,9 @@
* IN THE SOFTWARE.
*/

import {inject, TestBed} from '@angular/core/testing';
package org.eduze.fyp.core.db.dao;

import {ConfigService} from './config.service';
public interface AbstractDAO {

describe('ConfigService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [ConfigService]
});
});

it('should be created', inject([ConfigService], (service: ConfigService) => {
expect(service).toBeTruthy();
}));
});
void save(Object object);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* <Paste your header here>
*/
package org.eduze.fyp.core.db.dao;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

public class AbstractDAOImpl implements AbstractDAO {

protected SessionFactory sessionFactory;

@Override
public void save(Object object) {
Session session = this.sessionFactory.openSession();
session.beginTransaction();
session.persist(object);
session.getTransaction().commit();
session.close();
}

public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@
package org.eduze.fyp.core.db.dao;

import org.eduze.fyp.api.model.CameraConfig;
import org.eduze.fyp.api.model.CameraGroup;

import java.util.List;

public interface CameraConfigDAO {
public interface CameraConfigDAO extends AbstractDAO {

List<CameraGroup> cameraGroups();

void addCameraGroup(CameraGroup cameraGroup);

CameraConfig findById(int id);

CameraConfig findByCameraId(int cameraId);

void save(CameraConfig cameraConfig);

void delete(CameraConfig cameraConfig);

List<CameraConfig> list();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,32 @@
package org.eduze.fyp.core.db.dao;

import org.eduze.fyp.api.model.CameraConfig;
import org.eduze.fyp.api.model.CameraGroup;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

public class CameraConfigDAOImpl implements CameraConfigDAO {
public class CameraConfigDAOImpl extends AbstractDAOImpl implements CameraConfigDAO {

private static final Logger logger = LoggerFactory.getLogger(CameraConfigDAO.class);

private SessionFactory sessionFactory;

@Override
public List<CameraGroup> cameraGroups() {
Session session = this.sessionFactory.openSession();
List<CameraGroup> cameraGroups = session.createQuery("from CameraGroup", CameraGroup.class)
.list();
session.close();
return cameraGroups;
}

@Override
public void addCameraGroup(CameraGroup cameraGroup) {
this.save(cameraGroup);
}

@Override
public CameraConfig findById(int id) {
Expand All @@ -62,15 +75,6 @@ public CameraConfig findByCameraId(int cameraId) {
return null;
}

@Override
public void save(CameraConfig cameraConfig) {
Session session = this.sessionFactory.openSession();
session.beginTransaction();
session.persist(cameraConfig);
session.getTransaction().commit();
session.close();
}

@Override
public List<CameraConfig> list() {
Session session = this.sessionFactory.openSession();
Expand All @@ -97,7 +101,7 @@ public void update(CameraConfig cameraConfig) {
}

@Override
public void delete(CameraConfig cameraConfig){
public void delete(CameraConfig cameraConfig) {
Session session = this.sessionFactory.openSession();
session.beginTransaction();
try {
Expand All @@ -111,8 +115,4 @@ public void delete(CameraConfig cameraConfig){
session.close();
}
}

public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
}
1 change: 1 addition & 0 deletions cramp-ui/src/main/resources/etc/spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
<value>org.eduze.fyp.api.model.CaptureStamp</value>
<value>org.eduze.fyp.api.model.PointMapping</value>
<value>org.eduze.fyp.api.model.CameraConfig</value>
<value>org.eduze.fyp.api.model.CameraGroup</value>
</list>
</property>
<property name="hibernateProperties">
Expand Down
20 changes: 10 additions & 10 deletions cramp-web/src/main/java/org/eduze/fyp/web/RestServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,16 @@ private void startRestServer() {
ServletHolder servlet = new ServletHolder(servletContainer);
context.addServlet(servlet, CONTEXT_PATH);

DefaultServlet defaultServlet = new DefaultServlet();
ServletHolder servletHolder = new ServletHolder("default", defaultServlet);
URL path = this.getClass().getClassLoader().getResource("ng");
try {
servletHolder.setInitParameter("resourceBase", path.toURI().toASCIIString());
} catch (URISyntaxException e) {
logger.error("Error occurred", e);
}
servletHolder.setInitParameter("dirAllowed", "true");
context.addServlet(servletHolder, "/");
// DefaultServlet defaultServlet = new DefaultServlet();
// ServletHolder servletHolder = new ServletHolder("default", defaultServlet);
// URL path = this.getClass().getClassLoader().getResource("ng");
// try {
// servletHolder.setInitParameter("resourceBase", path.toURI().toASCIIString());
// } catch (URISyntaxException e) {
// logger.error("Error occurred", e);
// }
// servletHolder.setInitParameter("dirAllowed", "true");
// context.addServlet(servletHolder, "/");

jettyServer.setHandler(context);
logger.debug("Starting REST server");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
*/
package org.eduze.fyp.web.controllers;

import org.eduze.fyp.api.model.CameraConfig;
import org.eduze.fyp.api.model.CameraGroup;
import org.eduze.fyp.api.model.Zone;
import org.eduze.fyp.api.resources.Camera;
import org.eduze.fyp.api.model.CameraConfig;
import org.eduze.fyp.web.resources.MapConfiguration;
import org.eduze.fyp.web.resources.Status;
import org.eduze.fyp.web.services.ConfigService;
Expand Down Expand Up @@ -143,6 +144,29 @@ public Response getMap(@PathParam("cameraId") int cameraId) {
return Response.status(200).entity(mapConfiguration).build();
}

@GET
@Path("/cameraGroups")
public Response getCameraGroups() {
try {
return Response.ok(configService.getCameraGroups()).build();
} catch (Exception e) {
logger.error("Error occurred when obtaining camera configs", e);
return Response.status(500).build();
}
}

@POST
@Path("/cameraGroups")
public Response addCameraGroup(CameraGroup cameraGroup) {
try {
configService.addCameraGroup(cameraGroup);
return Response.ok().build();
} catch (Exception e) {
logger.error("Error occurred when obtaining camera configs", e);
return Response.status(500).build();
}
}

@GET
@Path("/cameraConfigs")
public Response getCameraConfigs() {
Expand Down
Loading

0 comments on commit a4a9987

Please sign in to comment.