Skip to content

Commit

Permalink
#17 convertion of gpsdata to and from string when saving and retrivin…
Browse files Browse the repository at this point in the history
…g from db, for route automatically
  • Loading branch information
mbaniasad committed May 20, 2016
1 parent 327c211 commit 520688a
Show file tree
Hide file tree
Showing 11 changed files with 183 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package gse1.buergerbusserver.general.common.api.datatype;

public class Gps {

private double langitude;

private double lattitude;

public double getLangitude() {

return langitude;
}

public void setLangitude(double langitude) {

this.langitude = langitude;
}

public double getLattitude() {

return lattitude;
}

public void setLattitude(double lattitude) {

this.lattitude = lattitude;
}

public Gps(String stringValue){
this.lattitude = Double.parseDouble(stringValue.substring(0, stringValue.indexOf(',')));
this.langitude = Double.parseDouble(stringValue.substring(stringValue.indexOf(',')+1,stringValue.length()-1));

}
public Gps()
{

}

@Override
public String toString(){

return String.valueOf(this.lattitude) + ',' + String.valueOf(this.langitude);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package gse1.buergerbusserver.general.dataaccess.base;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import gse1.buergerbusserver.general.common.api.datatype.Gps;

import javax.persistence.AttributeConverter;

import org.hibernate.metamodel.domain.BasicType;

public class GpsConverter implements AttributeConverter<List<Gps>, String> {

@Override
public String convertToDatabaseColumn(List<Gps> Gpslist) {

String aggrigated = "";
for(Gps gps:Gpslist)
aggrigated = aggrigated + gps.toString() + ';';

aggrigated = aggrigated.substring(0, aggrigated.length()-1);
return aggrigated;
}

@Override
public List<Gps> convertToEntityAttribute(String gpsCommaSeperated) {

List<String> listOfGpses = Arrays.asList(gpsCommaSeperated.split("\\s*;\\s*"));

List<Gps> GpsList = new ArrayList<Gps>();
for(String gpsString:listOfGpses)
GpsList.add(new Gps(gpsString));

return GpsList;
}
//#todo extends AttributeConverter<String, List<Gps>>
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package gse1.buergerbusserver.linemanagement.common.api;

import java.util.Date;
import java.util.List;

import gse1.buergerbusserver.general.common.api.ApplicationEntity;
import gse1.buergerbusserver.general.common.api.datatype.Gps;

/**
* @author MZEEN
*
*/
public interface Route extends ApplicationEntity {

void setGpsData(String gpsData);
void setGpsData(List<Gps> gpsData);

String getGpsData();
List<Gps> getGpsData();

void setTimeStamp(Date timeStamp);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package gse1.buergerbusserver.linemanagement.dataaccess.api;

import java.util.Date;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import gse1.buergerbusserver.general.common.api.datatype.Gps;
import gse1.buergerbusserver.general.dataaccess.api.ApplicationPersistenceEntity;
import gse1.buergerbusserver.general.dataaccess.base.GpsConverter;
import gse1.buergerbusserver.linemanagement.common.api.Route;

/**
Expand All @@ -18,15 +23,19 @@
@Table(name = "ROUTE")
public class RouteEntity extends ApplicationPersistenceEntity implements Route {

private String gpsdata;

private List<Gps> gpsdata;



private Date timeStamp;

/**
* @return gpsdata
*/
@Override
public String getGpsData() {
@Convert(converter = GpsConverter.class)
public List<Gps> getGpsData() {

return this.gpsdata;
}
Expand All @@ -35,11 +44,13 @@ public String getGpsData() {
* @param GpsData new value of {@link #getgpsdata}.
*/
@Override
public void setGpsData(String gpsData) {
public void setGpsData(List<Gps> gpsData) {

this.gpsdata = gpsData;
}



/**
* @return timeStamp
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import gse1.buergerbusserver.linemanagement.common.api.Line;
import gse1.buergerbusserver.linemanagement.logic.api.to.BusEto;
import gse1.buergerbusserver.linemanagement.logic.api.to.LineWithBusIdsCto;
import gse1.buergerbusserver.linemanagement.logic.api.to.LineEto;
import gse1.buergerbusserver.linemanagement.logic.api.to.RouteEto;

Expand Down Expand Up @@ -34,11 +35,9 @@ public interface Linemanagement {
*/
List<BusEto> getBusesOnLine(Long lineId);

/**
* @return getAllRoutes
*/
@GET
@Path("/routes/")

public List<RouteEto> getAllRoutes();

public List<LineWithBusIdsCto> getAllLinesWithBusIds();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package gse1.buergerbusserver.linemanagement.logic.api.to;


import java.util.ArrayList;
import java.util.List;



public class LineWithBusIdsCto extends LineEto {


private List<BusEto> buses;
public List<Long> getBusids() {

List<Long> returnlist = new ArrayList<Long>();

for(BusEto bus:this.buses)
returnlist.add(bus.getId());
return returnlist;
}



public void setBuses(List<BusEto> buses) {

this.buses = buses;

}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package gse1.buergerbusserver.linemanagement.logic.api.to;

import gse1.buergerbusserver.general.common.api.datatype.Gps;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
* @author MZEEN
Expand All @@ -10,15 +15,15 @@ public class RouteEto {

private Long id;

private String gpsdata;
private List<Gps> gpsdata;

private Date timeStamp;

/**
* @return gpsdata
*/

public String getGpsData() {
public List<Gps> getGpsData() {

return this.gpsdata;
}
Expand All @@ -27,9 +32,9 @@ public String getGpsData() {
* @param gpsdata new value of {@link #getgpsdata}.
*/

public void setGpsData(String gpsData) {

this.gpsdata = gpsData;
public void setGpsData(List<Gps> gpsData) {
this.gpsdata = gpsData;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import gse1.buergerbusserver.linemanagement.dataaccess.api.dao.RouteDao;
import gse1.buergerbusserver.linemanagement.logic.api.Linemanagement;
import gse1.buergerbusserver.linemanagement.logic.api.to.BusEto;
import gse1.buergerbusserver.linemanagement.logic.api.to.LineWithBusIdsCto;
import gse1.buergerbusserver.linemanagement.logic.api.to.LineEto;
import gse1.buergerbusserver.linemanagement.logic.api.to.RouteEto;

Expand Down Expand Up @@ -75,4 +76,16 @@ public List<RouteEto> getAllRoutes() {

return getBeanMapper().mapList(this.routeDao.findAll(), RouteEto.class);
}

@Override
public List<LineWithBusIdsCto> getAllLinesWithBusIds() {

List<LineWithBusIdsCto> lineCtoList = getBeanMapper().mapList(this.lineDao.findAll(), LineWithBusIdsCto.class);

for (LineWithBusIdsCto lineCto : lineCtoList){
List<BusEntity> buses = this.busDao.getBusesOnLine(lineCto.getId());
lineCto.setBuses(getBeanMapper().mapList(buses, BusEto.class));
}
return lineCtoList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import gse1.buergerbusserver.linemanagement.common.api.Line;
import gse1.buergerbusserver.linemanagement.logic.api.to.BusEto;
import gse1.buergerbusserver.linemanagement.logic.api.to.LineWithBusIdsCto;
import gse1.buergerbusserver.linemanagement.logic.api.to.LineEto;
import gse1.buergerbusserver.linemanagement.logic.api.to.RouteEto;

Expand All @@ -27,6 +28,9 @@ public interface LinemanagementRestService {
@Path("/lines/")
public List<LineEto> getAllLines();

@GET
@Path("/linesWithBusids/")
public List<LineWithBusIdsCto> getAllLinesWithBusIds();
/**
* Delegates to {@link Busmanagement#findBusesOnLine(Long)}.
*
Expand All @@ -52,4 +56,6 @@ public interface LinemanagementRestService {
@GET
@Path("/routes/")
public List<RouteEto> getAllRoutes();


}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import gse1.buergerbusserver.linemanagement.logic.api.Linemanagement;
import gse1.buergerbusserver.linemanagement.logic.api.to.BusEto;
import gse1.buergerbusserver.linemanagement.logic.api.to.LineWithBusIdsCto;
import gse1.buergerbusserver.linemanagement.logic.api.to.LineEto;
import gse1.buergerbusserver.linemanagement.logic.api.to.RouteEto;
import gse1.buergerbusserver.linemanagement.service.api.rest.LinemanagementRestService;
Expand Down Expand Up @@ -69,4 +70,11 @@ public List<RouteEto> getAllRoutes() {

return this.linemanagement.getAllRoutes();
}

@Override
public List<LineWithBusIdsCto> getAllLinesWithBusIds() {

return this.linemanagement.getAllLinesWithBusIds();
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
INSERT INTO bus(id, modificationCounter, numberPlate, color, picture, "TIMESTAMP") VALUES
(1, 0, 'bus1numberPlate', 'blue', 'bus1pic.jpg', '2004-10-19 10:23:54'),
(2, 0, 'bus2numberPlate', 'blue', 'bus2pic.jpg', '2004-10-19 10:23:54'),
(3, 0, 'bus3numberPlate', 'blue', 'bus3pic.jpg', '2004-10-19 10:23:54'),
(4, 0, 'bus4numberPlate', 'blue', 'bus4pic.jpg', '2004-10-19 10:23:54'),
(5, 0, 'bus5numberPlate', 'blue', 'bus5pic.jpg', '2004-10-19 10:23:54');
INSERT INTO bus(id, modificationCounter, numberPlate, color, picture,lineId, "TIMESTAMP") VALUES
(1, 0, 'bus1numberPlate', 'blue', 'bus1pic.jpg',1, '2004-10-19 10:23:54'),
(2, 0, 'bus2numberPlate', 'blue', 'bus2pic.jpg',1, '2004-10-19 10:23:54'),
(3, 0, 'bus3numberPlate', 'blue', 'bus3pic.jpg',2, '2004-10-19 10:23:54'),
(4, 0, 'bus4numberPlate', 'blue', 'bus4pic.jpg',2, '2004-10-19 10:23:54'),
(5, 0, 'bus5numberPlate', 'blue', 'bus5pic.jpg',3, '2004-10-19 10:23:54');


INSERT INTO line(id, modificationcounter, name, routeId, "TIMESTAMP")VALUES
Expand All @@ -12,10 +12,10 @@ INSERT INTO line(id, modificationcounter, name, routeId, "TIMESTAMP")VALUES
(3, 0, 'line3name', 3, '2004-10-19 10:23:54');

INSERT INTO ROUTE(id, modificationcounter,GPSData, "TIMESTAMP")
VALUES (1,0,'route1','2004-10-19 10:23:54'),
(2,0,'route2','2004-10-19 10:23:54'),
(3,0,'route3','2004-10-19 10:23:54'),
(4,0,'route4','2004-10-19 10:23:54');
VALUES (1,0,'11.968046,-12.420307;11.968046,-12.420307;11.968046,-12.420307','2004-10-19 10:23:54'),
(2,0,'21.968046,-22.420307;21.968046,-22.420307;21.968046,-22.420307','2004-10-19 10:23:54'),
(3,0,'31.968046,-32.420307;31.968046,-32.420307;31.968046,-32.420307','2004-10-19 10:23:54'),
(4,0,'41.968046,-42.420307;41.968046,-42.420307;41.968046,-42.420307','2004-10-19 10:23:54');

--added by Hafiz
INSERT INTO LASTPOSITION(id,busId, modificationCounter, lat, lon, "TIMESTAMP") VALUES
Expand Down

0 comments on commit 520688a

Please sign in to comment.