Skip to content

Commit

Permalink
Crud operation consistency
Browse files Browse the repository at this point in the history
* Fixes #609 crud operations on basic object are now made more consistent.
  This allows there to be a simple interace ObjectCrud for these.
* Fixes #513 rather than use suppress, which I now understand, I fixed the
  problems that were being reported.
  • Loading branch information
dickschoeller committed Apr 14, 2019
1 parent 5b5ebf5 commit fff440c
Show file tree
Hide file tree
Showing 34 changed files with 340 additions and 189 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ public ResponseEntity<?> changePassword(
}

/**
* This will probably eventually be private or public, not default.
*
* @author Dick Schoeller
*/
static final class PasswordChanger {
/* default */ static final class PasswordChanger {
/** */
private String oldPassword;
/** */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private Claims getClaimsFromToken(final String token) {
* @param claims the claims
* @return the token
*/
String generateToken(final Map<String, Object> claims) {
private String generateToken(final Map<String, Object> claims) {
return Jwts.builder()
.setClaims(claims)
.setExpiration(generateExpirationDate())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public class Application {
* @throws InterruptedException if thread sleep fails at end
*/
public static void main(final String[] args) throws InterruptedException {
SpringApplication.run(
org.schoellerfamily.gedbrowser.Application.class, args);
SpringApplication.run(Application.class, args);
Thread.sleep(TWENTY_SECONDS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import java.util.List;

import org.schoellerfamily.gedbrowser.api.crud.FamilyCrud;
import org.schoellerfamily.gedbrowser.api.crud.ObjectCrud;
import org.schoellerfamily.gedbrowser.api.datamodel.ApiFamily;
import org.schoellerfamily.gedbrowser.api.datamodel.ApiObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
Expand All @@ -25,7 +25,7 @@ public final class FamiliesController extends CrudInvoker {
/**
* @return the CRUD object for manipulating families
*/
private FamilyCrud familyCrud() {
private ObjectCrud<ApiFamily> crud() {
return new FamilyCrud(getLoader(), getConverter(), getManager());
}

Expand All @@ -36,9 +36,10 @@ private FamilyCrud familyCrud() {
*/
@PostMapping(value = "/v1/dbs/{db}/families")
@ResponseBody
public ApiObject createFamily(@PathVariable final String db,
public ApiFamily create(
@PathVariable final String db,
@RequestBody final ApiFamily family) {
return familyCrud().createFamily(db, family);
return crud().createOne(db, family);
}

/**
Expand All @@ -47,9 +48,9 @@ public ApiObject createFamily(@PathVariable final String db,
*/
@GetMapping(value = "/v1/dbs/{db}/families")
@ResponseBody
public List<ApiFamily> readFamilies(
public List<ApiFamily> read(
@PathVariable final String db) {
return familyCrud().readAll(db);
return crud().readAll(db);
}

/**
Expand All @@ -59,10 +60,10 @@ public List<ApiFamily> readFamilies(
*/
@GetMapping(value = "/v1/dbs/{db}/families/{id}")
@ResponseBody
public ApiFamily readFamily(
public ApiFamily read(
@PathVariable final String db,
@PathVariable final String id) {
return familyCrud().readFamily(db, id);
return crud().readOne(db, id);
}

/**
Expand All @@ -73,10 +74,11 @@ public ApiFamily readFamily(
*/
@PutMapping(value = "/v1/dbs/{db}/families/{id}")
@ResponseBody
public ApiObject updateFamily(@PathVariable final String db,
public ApiFamily update(
@PathVariable final String db,
@PathVariable final String id,
@RequestBody final ApiFamily family) {
return familyCrud().updateOne(db, id, family);
return crud().updateOne(db, id, family);
}

/**
Expand All @@ -86,9 +88,9 @@ public ApiObject updateFamily(@PathVariable final String db,
*/
@DeleteMapping(value = "/v1/dbs/{db}/families/{id}")
@ResponseBody
public ApiFamily deleteFamily(
public ApiFamily delete(
@PathVariable final String db,
@PathVariable final String id) {
return familyCrud().deleteFamily(db, id);
return crud().deleteOne(db, id);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.schoellerfamily.gedbrowser.api.controller;

import org.schoellerfamily.gedbrowser.api.crud.HeadCrud;
import org.schoellerfamily.gedbrowser.api.crud.ObjectCrud;
import org.schoellerfamily.gedbrowser.api.datamodel.ApiHead;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
Expand All @@ -18,7 +19,7 @@ public class HeadController extends CrudInvoker {
/**
* @return the CRUD object for manipulating the DB header
*/
private HeadCrud headCrud() {
private ObjectCrud<ApiHead> crud() {
return new HeadCrud(getLoader(), getConverter(), getManager());
}

Expand All @@ -28,7 +29,7 @@ private HeadCrud headCrud() {
*/
@GetMapping(value = "/v1/dbs/{db}")
@ResponseBody
public ApiHead readHead(@PathVariable final String db) {
return headCrud().readHead(db);
public ApiHead read(@PathVariable final String db) {
return crud().readOne(db, "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import java.util.List;

import org.schoellerfamily.gedbrowser.api.crud.NoteCrud;
import org.schoellerfamily.gedbrowser.api.crud.ObjectCrud;
import org.schoellerfamily.gedbrowser.api.datamodel.ApiNote;
import org.schoellerfamily.gedbrowser.api.datamodel.ApiObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
Expand All @@ -25,7 +25,7 @@ public class NotesController extends CrudInvoker {
/**
* @return the CRUD object for manipulating notes
*/
private NoteCrud noteCrud() {
private ObjectCrud<ApiNote> crud() {
return new NoteCrud(getLoader(), getConverter(), getManager());
}

Expand All @@ -36,9 +36,10 @@ private NoteCrud noteCrud() {
*/
@PostMapping(value = "/v1/dbs/{db}/notes")
@ResponseBody
public ApiObject createNote(@PathVariable final String db,
public ApiNote create(
@PathVariable final String db,
@RequestBody final ApiNote note) {
return noteCrud().createNote(db, note);
return crud().createOne(db, note);
}

/**
Expand All @@ -47,9 +48,9 @@ public ApiObject createNote(@PathVariable final String db,
*/
@GetMapping(value = "/v1/dbs/{db}/notes")
@ResponseBody
public List<ApiNote> readNotes(
public List<ApiNote> read(
@PathVariable final String db) {
return noteCrud().readAll(db);
return crud().readAll(db);
}

/**
Expand All @@ -59,10 +60,10 @@ public List<ApiNote> readNotes(
*/
@GetMapping(value = "/v1/dbs/{db}/notes/{id}")
@ResponseBody
public ApiNote readNote(
public ApiNote read(
@PathVariable final String db,
@PathVariable final String id) {
return noteCrud().readNote(db, id);
return crud().readOne(db, id);
}

/**
Expand All @@ -73,10 +74,11 @@ public ApiNote readNote(
*/
@PutMapping(value = "/v1/dbs/{db}/notes/{id}")
@ResponseBody
public ApiObject updateNote(@PathVariable final String db,
public ApiNote update(
@PathVariable final String db,
@PathVariable final String id,
@RequestBody final ApiNote note) {
return noteCrud().updateOne(db, id, note);
return crud().updateOne(db, id, note);
}

/**
Expand All @@ -86,9 +88,9 @@ public ApiObject updateNote(@PathVariable final String db,
*/
@DeleteMapping(value = "/v1/dbs/{db}/notes/{id}")
@ResponseBody
public ApiNote deleteNote(
public ApiNote delete(
@PathVariable final String db,
@PathVariable final String id) {
return noteCrud().deleteNote(db, id);
return crud().deleteOne(db, id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.schoellerfamily.gedbrowser.api.crud.ObjectCrud;
import org.schoellerfamily.gedbrowser.api.crud.PersonCrud;
import org.schoellerfamily.gedbrowser.api.datamodel.ApiObject;
import org.schoellerfamily.gedbrowser.api.datamodel.ApiPerson;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
Expand All @@ -30,7 +30,7 @@ public class PersonsController extends CrudInvoker {
/**
* @return the CRUD object for manipulating persons
*/
private PersonCrud personCrud() {
private ObjectCrud<ApiPerson> crud() {
return new PersonCrud(getLoader(), getConverter(), getManager());
}

Expand All @@ -41,9 +41,9 @@ private PersonCrud personCrud() {
*/
@PostMapping(value = "/v1/dbs/{db}/persons")
@ResponseBody
public ApiObject createPerson(@PathVariable final String db,
public ApiPerson create(@PathVariable final String db,
@RequestBody final ApiPerson person) {
return personCrud().createPerson(db, person);
return crud().createOne(db, person);
}

/**
Expand All @@ -52,9 +52,9 @@ public ApiObject createPerson(@PathVariable final String db,
*/
@GetMapping(value = "/v1/dbs/{db}/persons")
@ResponseBody
public List<ApiPerson> readPersons(
public List<ApiPerson> read(
@PathVariable final String db) {
return personCrud().readAll(db);
return crud().readAll(db);
}

/**
Expand All @@ -64,11 +64,11 @@ public List<ApiPerson> readPersons(
*/
@GetMapping(value = "/v1/dbs/{db}/persons/{id}")
@ResponseBody
public ApiPerson readPerson(
public ApiPerson read(
@PathVariable final String db,
@PathVariable final String id) {
logger.info("entering read person: " + id);
return personCrud().readPerson(db, id);
return crud().readOne(db, id);
}

/**
Expand All @@ -79,11 +79,11 @@ public ApiPerson readPerson(
*/
@PutMapping(value = "/v1/dbs/{db}/persons/{id}")
@ResponseBody
public ApiObject updatePerson(@PathVariable final String db,
public ApiPerson update(@PathVariable final String db,
@PathVariable final String id,
@RequestBody final ApiPerson person) {
logger.info("entering update person: " + id);
return personCrud().updateOne(db, id, person);
return crud().updateOne(db, id, person);
}

/**
Expand All @@ -93,10 +93,10 @@ public ApiObject updatePerson(@PathVariable final String db,
*/
@DeleteMapping(value = "/v1/dbs/{db}/persons/{id}")
@ResponseBody
public ApiPerson deletePerson(
public ApiPerson delete(
@PathVariable final String db,
@PathVariable final String id) {
logger.info("entering delete person: " + id);
return personCrud().deletePerson(db, id);
return crud().deleteOne(db, id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import java.util.List;

import org.schoellerfamily.gedbrowser.api.crud.ObjectCrud;
import org.schoellerfamily.gedbrowser.api.crud.SourceCrud;
import org.schoellerfamily.gedbrowser.api.datamodel.ApiObject;
import org.schoellerfamily.gedbrowser.api.datamodel.ApiSource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
Expand All @@ -25,7 +25,7 @@ public class SourcesController extends CrudInvoker {
/**
* @return the CRUD object for manipulating persons
*/
private SourceCrud sourceCrud() {
private ObjectCrud<ApiSource> crud() {
return new SourceCrud(getLoader(), getConverter(), getManager());
}

Expand All @@ -36,9 +36,10 @@ private SourceCrud sourceCrud() {
*/
@PostMapping(value = "/v1/dbs/{db}/sources")
@ResponseBody
public ApiObject createSource(@PathVariable final String db,
public ApiSource create(
@PathVariable final String db,
@RequestBody final ApiSource source) {
return sourceCrud().createSource(db, source);
return crud().createOne(db, source);
}

/**
Expand All @@ -47,9 +48,9 @@ public ApiObject createSource(@PathVariable final String db,
*/
@GetMapping(value = "/v1/dbs/{db}/sources")
@ResponseBody
public List<ApiSource> readSources(
public List<ApiSource> read(
@PathVariable final String db) {
return sourceCrud().readAll(db);
return crud().readAll(db);
}

/**
Expand All @@ -59,10 +60,10 @@ public List<ApiSource> readSources(
*/
@GetMapping(value = "/v1/dbs/{db}/sources/{id}")
@ResponseBody
public ApiSource readSource(
public ApiSource read(
@PathVariable final String db,
@PathVariable final String id) {
return sourceCrud().readSource(db, id);
return crud().readOne(db, id);
}

/**
Expand All @@ -73,10 +74,11 @@ public ApiSource readSource(
*/
@PutMapping(value = "/v1/dbs/{db}/sources/{id}")
@ResponseBody
public ApiObject updateSource(@PathVariable final String db,
public ApiSource update(
@PathVariable final String db,
@PathVariable final String id,
@RequestBody final ApiSource source) {
return sourceCrud().updateOne(db, id, source);
return crud().updateOne(db, id, source);
}

/**
Expand All @@ -86,9 +88,9 @@ public ApiObject updateSource(@PathVariable final String db,
*/
@DeleteMapping(value = "/v1/dbs/{db}/sources/{id}")
@ResponseBody
public ApiSource deleteSource(
public ApiSource delete(
@PathVariable final String db,
@PathVariable final String id) {
return sourceCrud().deleteSource(db, id);
return crud().deleteOne(db, id);
}
}
Loading

0 comments on commit fff440c

Please sign in to comment.