Commit 41eed0b8 authored by Sebastian's avatar Sebastian

erster wurf zur app-struktur / team culture.

parent 19a17dc7
package de.transformationsstadt.geoportal.DAO;
import de.transformationsstadt.geoportal.entities.App;
public interface AppDAO extends DaoInterface<App> {
}
\ No newline at end of file
package de.transformationsstadt.geoportal.DAO;
import org.springframework.stereotype.Repository;
import de.transformationsstadt.geoportal.entities.App;
@Repository
public class AppDAOImpl extends GenericDao<App> implements AppDAO {
}
package de.transformationsstadt.geoportal.DAO;
import org.springframework.stereotype.Repository;
import de.transformationsstadt.geoportal.entities.BliDimension;
......
......@@ -36,7 +36,7 @@ public class HibernateConfig {
*
*/
Boolean dev = true;
@Bean
public LocalSessionFactoryBean sessionFactory(){
......@@ -52,11 +52,15 @@ public class HibernateConfig {
@Bean
public DataSource dataSource() {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName("org.postgresql.Driver");
dataSource.setUrl("jdbc:postgresql://127.0.0.1:5432/dev");
dataSource.setUsername("dev");
dataSource.setPassword("dev");
String db = this.dev?"dev":"geoportal";
String user = this.dev?"dev":"geoportal";
String password = this.dev?"dev":"geoportal";
String host = this.dev?"postgres-dev-server":"postgres-server";
dataSource.setDriverClassName("org.postgresql.Driver");
dataSource.setUrl("jdbc:postgresql://"+host+":5432/"+db);
dataSource.setUsername(user);
dataSource.setPassword(password);
return dataSource;
}
......@@ -71,7 +75,11 @@ public class HibernateConfig {
Properties hibernateProperties = new Properties();
hibernateProperties.setProperty("hibernate.dialect","org.hibernate.dialect.PostgreSQL94Dialect");
hibernateProperties.setProperty("hibernate.connection.driver_class","org.postgresql.Driver");
hibernateProperties.setProperty("hibernate.hbm2ddl.auto","create");
if(this.dev) {
hibernateProperties.setProperty("hibernate.hbm2ddl.auto","create");
}else {
hibernateProperties.setProperty("hibernate.hbm2ddl.auto","validate");
}
hibernateProperties.setProperty("hibernate.show_sql","false");
hibernateProperties.setProperty("hibernate.connection.characterEncoding","utf8");
hibernateProperties.setProperty("hibernate.connection.useUnicode","true");
......
package de.transformationsstadt.geoportal.api;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.config.RepositoryNameSpaceHandler;
import de.transformationsstadt.geoportal.apiparameters.LongParameter;
import de.transformationsstadt.geoportal.apiparameters.OsmReferenceParameter;
import de.transformationsstadt.geoportal.entities.OsmReference;
import de.transformationsstadt.geoportal.services.AppService;
import de.transformationsstadt.geoportal.services.OsmReferenceService;
@Path("/apps/")
public class App {
@Autowired
AppService appService;
@Autowired
OsmReferenceService osmRefService;
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response list() {
return Response.status(Status.OK).entity(appService.getAll()).build();
}
@GET
@Path("/{appname:[A-Za-z0-9\\-\\_]+}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response getApp(@PathParam("appname") String appname) {
de.transformationsstadt.geoportal.entities.App app = appService.getByName(appname);
if(app == null) {
return Response.status(Status.NOT_FOUND).entity("{\"error\":\"did not find specified resource\"}").build();
}
return Response.status(Status.OK).entity(app).build();
}
@GET
@Path("/{appname:[A-Za-z0-9\\-\\_]+}/elements/")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response getAppElements(@PathParam("appname") String appname) {
de.transformationsstadt.geoportal.entities.App app = appService.getByName(appname);
if(app == null) {
return Response.status(Status.NOT_FOUND).entity("{\"error\":\"did not find specified resource\"}").build();
}
return Response.status(Status.OK).entity(app.getElements()).build();
}
@POST
@Path("/{appname:[A-Za-z0-9\\-\\_]+}/elements/")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response addAppElement(@PathParam("appname") String appname,LongParameter el) {
de.transformationsstadt.geoportal.entities.App app = appService.getByName(appname);
OsmReference ref = osmRefService.get(el.getId());
if(ref == null) {
return Response.status(Status.BAD_REQUEST).entity("{\"error\":\"referenced element not found\"}").build();
}
if(appname == null) {
return Response.status(Status.BAD_REQUEST).entity("{\"error\":\"appName expected\"}").build();
}
if(app == null) {
return Response.status(Status.NOT_FOUND).entity("{\"error\":\"did not find specified app\"}").build();
}
app.getElements().add(ref);
appService.merge(app);
return Response.status(Status.OK).entity(app.getElements()).build();
}
/**
*
* ToDo: API-Pfad um eine App zu anzulegen
*
* - App-anlegen-pfad (POST)
* - Rolle "appname-admin" anlegen und dem Benutzer zuweisen
* -
*/
}
......@@ -152,7 +152,48 @@ public class GeoElements {
return Response.status(Status.OK).entity(element).build();
}
}
@POST
@Path("/{id: [0-9]+}/tags")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response getElementById(@PathParam("id") Long id, KeyValuePairParameter kvpp) {
OsmReference element = osmRefService.get(id);
if(element == null) {
HashMap<String,String> map = new HashMap<String,String>();
map.put("error", "geoelement not found");
return Response.status(Status.NOT_FOUND).entity(map).build();
}else {
if(kvpp == null) {
HashMap<String,String> map = new HashMap<String,String>();
map.put("error", "parameter expected");
return Response.status(Status.BAD_REQUEST).entity(map).build();
}
if(kvpp.key == null || kvpp.key.isEmpty() || kvpp.value == null ||kvpp.value.isEmpty()) {
HashMap<String,String> map = new HashMap<String,String>();
map.put("error", "key and value may not be empty or null");
return Response.status(Status.BAD_REQUEST).entity(map).build();
}
for(KeyValuePair p : element.getTags()) {
if(p.getKey() == kvpp.key) {
HashMap<String,String> map = new HashMap<String,String>();
map.put("error", "tag exists. use PATCH to update.");
return Response.status(Status.CONFLICT).entity(map).build();
}
}
// parameter is valid and not attached already.
KeyValuePair kvp = new KeyValuePair();
kvp.setKey(kvpp.key);
kvp.setValue(kvpp.value);
kvp.setSource(kvpp.source);
kvp.setDisplayName(kvpp.displayName);
kvpService.create(kvp);
element.addTag(kvp);
osmRefService.merge(element);
return Response.status(Status.OK).entity(element).build();
}
}
/**
* Gibt alle Elemente zurück, die im Rechteck (minX,maxX) x (minY,maxY) liegen.
*
......
......@@ -20,6 +20,7 @@ import javax.ws.rs.core.Response.Status;
import org.hibernate.TransientObjectException;
import org.springframework.beans.factory.annotation.Autowired;
import de.transformationsstadt.geoportal.entities.App;
import de.transformationsstadt.geoportal.entities.BliDimension;
import de.transformationsstadt.geoportal.entities.Category;
import de.transformationsstadt.geoportal.entities.DataGroup;
......@@ -27,6 +28,7 @@ import de.transformationsstadt.geoportal.entities.KeyValuePair;
import de.transformationsstadt.geoportal.entities.Permission;
import de.transformationsstadt.geoportal.entities.Role;
import de.transformationsstadt.geoportal.entities.User;
import de.transformationsstadt.geoportal.services.AppService;
import de.transformationsstadt.geoportal.services.BliDimensionService;
import de.transformationsstadt.geoportal.services.CategoryService;
import de.transformationsstadt.geoportal.services.DataGroupService;
......@@ -69,6 +71,8 @@ public class Setup {
@Autowired
KeyValuePairService kvpService;
@Autowired
AppService appService;
@GET
@Consumes(MediaType.APPLICATION_JSON)
......@@ -564,8 +568,20 @@ public class Setup {
map.put("error","persistence-error. "+cve.getMessage());
throw cve;
}
User cultureUser = new User();
cultureUser.setUsername("culture");
cultureUser.setPassword("culture");
cultureUser.setEmail("teamculture@geoportal.transformationsstadt.de");
cultureUser.setActive(true);
cultureUser.setValidated(true);
cultureUser.addRole(userRole);
App CultureApp = new App();
CultureApp.setAdmin(cultureUser);
CultureApp.setName("culture");
userService.create(cultureUser);
appService.create(CultureApp);
return Response.status(Status.OK).entity(categoryService.getAll()).build();
}
......
......@@ -12,4 +12,6 @@ public class KeyValuePairParameter {
public Long id;
public String key;
public String value;
public String displayName;
public String source;
}
package de.transformationsstadt.geoportal.apiparameters;
import java.io.Serializable;
public class LongParameter implements Serializable{
/**
*
*/
private static final long serialVersionUID = -5695457909688475966L;
Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
package de.transformationsstadt.geoportal.entities;
import java.io.Serializable;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.sun.istack.NotNull;
@Entity
@Table(name="app_data")
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
public class App implements Serializable{
/**
*
*/
private static final long serialVersionUID = 5076194323483150225L;
@Id
@GeneratedValue
Long id;
@Column(columnDefinition="text")
String description;
private User admin;
@ManyToMany(fetch=FetchType.EAGER)
@JoinTable(
name="app_dimensions",
joinColumns = { @JoinColumn(name = "app_id") },
inverseJoinColumns = { @JoinColumn( name = "dim_id") }
)
private Set<BliDimension> dimensions;
@ManyToMany(fetch=FetchType.EAGER)
@JoinTable(
name="app_elements",
joinColumns = { @JoinColumn(name = "app_id") },
inverseJoinColumns = { @JoinColumn( name = "element_id") }
)
private Set<OsmReference> elements;
@NotNull
@Column(unique=true)
private String name;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@JsonIgnoreProperties({ "accountCreated","account_created", "active","description","email","eulaVersion","firstname","lastLogin","last_login","login_count","eula_version","lastname","locked","loginCount","password_hash","roles","salt","tags","updating","validated"})
public User getAdmin() {
return admin;
}
public void setAdmin(User admin) {
this.admin = admin;
}
public Set<BliDimension> getDimensions() {
return dimensions;
}
public void setDimensions(Set<BliDimension> dimensions) {
this.dimensions = dimensions;
}
public Set<OsmReference> getElements() {
return elements;
}
public void setElements(Set<OsmReference> elements) {
this.elements = elements;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
}
......@@ -143,7 +143,7 @@ public class OsmReference implements Serializable{
@JsonIgnoreProperties({"peers"})
private Set<OsmReference> peers = new HashSet<OsmReference>();
@ManyToMany(fetch=FetchType.EAGER)
@JoinTable(
......
package de.transformationsstadt.geoportal.services;
import java.util.List;
import de.transformationsstadt.geoportal.entities.App;
import de.transformationsstadt.geoportal.entities.BliDimension;
public interface AppService extends ServiceInterface<App>{
public App get(Long id);
public App create(App app);
public List<App> getAll();
public App getByName(String name);
public App merge(App app);
}
package de.transformationsstadt.geoportal.services;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import de.transformationsstadt.geoportal.DAO.AppDAO;
import de.transformationsstadt.geoportal.entities.App;
@Service
@Transactional
public class AppServiceImpl extends GenericService<App> implements AppService{
@Autowired
AppDAO dao;
public App get(Long id) {
return dao.get(id);
}
public App create(App app) {
long id = (long) dao.create(app);
app.setId(id);
return app;
}
public List<App> getAll() {
return dao.getAll();
}
public App getByName(String name) {
return dao.getSingleResultByField("name", name);
}
public App merge(App app) {
dao.merge(app);
return app;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment