modularization
This commit is contained in:
@ -95,34 +95,6 @@ public class DoneController {
|
||||
return toItem(bean, model);
|
||||
}
|
||||
|
||||
@RolesAllowed("timetrack_user")
|
||||
@GetMapping("/done/edit/project/{id}")
|
||||
public String toProject(@PathVariable Integer id, Model model) {
|
||||
TProjectRecord project = doneService.getProject(id);
|
||||
model.addAttribute("projectBean", project);
|
||||
return "done/project";
|
||||
}
|
||||
|
||||
@RolesAllowed("timetrack_user")
|
||||
@RequestMapping(value = "/done/upsert/project", method = RequestMethod.POST)
|
||||
public String doUpsert(Model model, @ModelAttribute TProjectRecord bean) {
|
||||
Integer amount = doneService.doUpsertProject(bean);
|
||||
return amount.equals(1) ? getList(new DoneModel(), model) : toProject(bean.getPk(), model);
|
||||
}
|
||||
|
||||
@RolesAllowed("timetrack_user")
|
||||
@RequestMapping(value = "/done/add/project", method = RequestMethod.GET)
|
||||
public String toAddProject(Model model) {
|
||||
return toProject(null, model);
|
||||
}
|
||||
|
||||
@RolesAllowed("timetrack_user")
|
||||
@GetMapping(value = "/done/delete/project/{id}")
|
||||
public String doDeleteProject(@PathVariable Integer id, Model model) {
|
||||
Integer amount = doneService.doDeleteProject(id);
|
||||
return amount.equals(1) ? getList(new DoneModel(), model) : toProject(id, model);
|
||||
}
|
||||
|
||||
@RolesAllowed("timetrack_user")
|
||||
@RequestMapping(value = "/done/upsert", method = RequestMethod.POST)
|
||||
public String doUpsert(Model model, @ModelAttribute DoneBean bean) {
|
||||
|
@ -34,10 +34,4 @@ public interface IDoneService {
|
||||
public Integer doUpsert(DoneBean bean, String username);
|
||||
|
||||
public Integer doDelete(Integer id);
|
||||
|
||||
public TProjectRecord getProject(Integer id);
|
||||
|
||||
public Integer doUpsertProject(TProjectRecord bean);
|
||||
|
||||
public Integer doDeleteProject(Integer id);
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package de.jottyfan.timetrack.spring.done.impl;
|
||||
|
||||
import static de.jottyfan.timetrack.db.done.Tables.T_DONE;
|
||||
import static de.jottyfan.timetrack.db.done.Tables.T_PROJECT;
|
||||
import static de.jottyfan.timetrack.db.done.Tables.V_BILLING;
|
||||
import static de.jottyfan.timetrack.db.done.Tables.V_JOB;
|
||||
import static de.jottyfan.timetrack.db.done.Tables.V_MODULE;
|
||||
@ -20,7 +19,6 @@ import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jooq.DSLContext;
|
||||
import org.jooq.DeleteConditionStep;
|
||||
import org.jooq.InsertReturningStep;
|
||||
import org.jooq.InsertValuesStep7;
|
||||
import org.jooq.Record7;
|
||||
import org.jooq.Result;
|
||||
@ -31,7 +29,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import de.jottyfan.timetrack.db.done.tables.records.TDoneRecord;
|
||||
import de.jottyfan.timetrack.db.done.tables.records.TProjectRecord;
|
||||
import de.jottyfan.timetrack.db.done.tables.records.VBillingRecord;
|
||||
import de.jottyfan.timetrack.db.done.tables.records.VJobRecord;
|
||||
import de.jottyfan.timetrack.db.done.tables.records.VModuleRecord;
|
||||
@ -277,7 +274,7 @@ public class DoneGateway {
|
||||
* @throws ClassNotFoundException
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
public Integer delete(Integer pk) throws DataAccessException, ClassNotFoundException, SQLException {
|
||||
public Integer delete(Integer pk) {
|
||||
DeleteConditionStep<TDoneRecord> sql = getJooq()
|
||||
// @formatter:off
|
||||
.deleteFrom(T_DONE)
|
||||
@ -365,48 +362,4 @@ public class DoneGateway {
|
||||
LOGGER.debug(sql.toString());
|
||||
return sql.execute();
|
||||
}
|
||||
|
||||
public TProjectRecord getProject(Integer id) {
|
||||
SelectConditionStep<TProjectRecord> sql = getJooq().selectFrom(T_PROJECT).where(T_PROJECT.PK.eq(id));
|
||||
LOGGER.debug(sql.toString());
|
||||
return sql.fetchOne();
|
||||
}
|
||||
|
||||
public Integer upsertProject(TProjectRecord bean) {
|
||||
return bean.getPk() != null ? updateProject(bean) : insertProject(bean);
|
||||
}
|
||||
|
||||
private Integer insertProject(TProjectRecord bean) {
|
||||
InsertReturningStep<TProjectRecord> sql = getJooq()
|
||||
// @formatter:off
|
||||
.insertInto(T_PROJECT,
|
||||
T_PROJECT.NAME)
|
||||
.values(bean.getName())
|
||||
.onConflict(T_PROJECT.NAME)
|
||||
.doNothing();
|
||||
// @formatter:on
|
||||
LOGGER.debug(sql.toString());
|
||||
return sql.execute();
|
||||
}
|
||||
|
||||
private Integer updateProject(TProjectRecord bean) {
|
||||
UpdateConditionStep<TProjectRecord> sql = getJooq()
|
||||
// @formatter:off
|
||||
.update(T_PROJECT)
|
||||
.set(T_PROJECT.NAME, bean.getName())
|
||||
.where(T_PROJECT.PK.eq(bean.getPk()));
|
||||
// @formatter:on
|
||||
LOGGER.debug(sql.toString());
|
||||
return sql.execute();
|
||||
}
|
||||
|
||||
public Integer deleteProject(Integer id) {
|
||||
DeleteConditionStep<TProjectRecord> sql = getJooq()
|
||||
// @formatter:off
|
||||
.deleteFrom(T_PROJECT)
|
||||
.where(T_PROJECT.PK.eq(id));
|
||||
// @formatter:on
|
||||
LOGGER.debug("{}", sql.toString());
|
||||
return sql.execute();
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import de.jottyfan.timetrack.db.done.tables.records.TProjectRecord;
|
||||
import de.jottyfan.timetrack.db.done.tables.records.VBillingRecord;
|
||||
import de.jottyfan.timetrack.db.done.tables.records.VJobRecord;
|
||||
import de.jottyfan.timetrack.db.done.tables.records.VModuleRecord;
|
||||
@ -120,7 +119,6 @@ public class DoneService implements IDoneService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer doDelete(Integer id) {
|
||||
try {
|
||||
return new DoneGateway(dsl).delete(id);
|
||||
@ -129,34 +127,4 @@ public class DoneService implements IDoneService {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TProjectRecord getProject(Integer id) {
|
||||
try {
|
||||
return id == null ? new TProjectRecord() : new DoneGateway(dsl).getProject(id);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer doUpsertProject(TProjectRecord bean) {
|
||||
try {
|
||||
return new DoneGateway(dsl).upsertProject(bean);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer doDeleteProject(Integer id) {
|
||||
try {
|
||||
return new DoneGateway(dsl).deleteProject(id);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,14 @@
|
||||
package de.jottyfan.timetrack.spring.done.project;
|
||||
|
||||
import de.jottyfan.timetrack.db.done.tables.records.TProjectRecord;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author henkej
|
||||
*
|
||||
*/
|
||||
public interface IProjectService {
|
||||
public TProjectRecord getProject(Integer id);
|
||||
public Integer doUpsertProject(TProjectRecord bean);
|
||||
public Integer doDeleteProject(Integer id);
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package de.jottyfan.timetrack.spring.done.project;
|
||||
|
||||
import javax.annotation.security.RolesAllowed;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import de.jottyfan.timetrack.db.done.tables.records.TProjectRecord;
|
||||
import de.jottyfan.timetrack.spring.done.DoneController;
|
||||
import de.jottyfan.timetrack.spring.done.DoneModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author henkej
|
||||
*
|
||||
*/
|
||||
@Controller
|
||||
public class ProjectController {
|
||||
private static final Logger LOGGER = LogManager.getLogger(ProjectController.class);
|
||||
|
||||
@Autowired
|
||||
private IProjectService projectService;
|
||||
|
||||
@Autowired
|
||||
private DoneController doneController;
|
||||
|
||||
@RolesAllowed("timetrack_user")
|
||||
@GetMapping("/done/edit/project/{id}")
|
||||
public String toProject(@PathVariable Integer id, Model model) {
|
||||
TProjectRecord project = projectService.getProject(id);
|
||||
model.addAttribute("projectBean", project);
|
||||
return "done/project";
|
||||
}
|
||||
|
||||
@RolesAllowed("timetrack_user")
|
||||
@RequestMapping(value = "/done/upsert/project", method = RequestMethod.POST)
|
||||
public String doUpsert(Model model, @ModelAttribute TProjectRecord bean) {
|
||||
Integer amount = projectService.doUpsertProject(bean);
|
||||
return amount.equals(1) ? doneController.getList(new DoneModel(), model) : toProject(bean.getPk(), model);
|
||||
}
|
||||
|
||||
@RolesAllowed("timetrack_user")
|
||||
@RequestMapping(value = "/done/add/project", method = RequestMethod.GET)
|
||||
public String toAddProject(Model model) {
|
||||
return toProject(null, model);
|
||||
}
|
||||
|
||||
@RolesAllowed("timetrack_user")
|
||||
@GetMapping(value = "/done/delete/project/{id}")
|
||||
public String doDeleteProject(@PathVariable Integer id, Model model) {
|
||||
Integer amount = projectService.doDeleteProject(id);
|
||||
return amount.equals(1) ? doneController.getList(new DoneModel(), model) : toProject(id, model);
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
package de.jottyfan.timetrack.spring.done.project.impl;
|
||||
|
||||
import static de.jottyfan.timetrack.db.done.Tables.T_PROJECT;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jooq.DSLContext;
|
||||
import org.jooq.DeleteConditionStep;
|
||||
import org.jooq.InsertReturningStep;
|
||||
import org.jooq.SelectConditionStep;
|
||||
import org.jooq.UpdateConditionStep;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import de.jottyfan.timetrack.db.done.tables.records.TProjectRecord;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
@Repository
|
||||
public class ProjectGateway {
|
||||
private static final Logger LOGGER = LogManager.getLogger(ProjectGateway.class);
|
||||
private final DSLContext jooq;
|
||||
|
||||
public ProjectGateway(@Autowired DSLContext jooq) throws Exception {
|
||||
this.jooq = jooq;
|
||||
}
|
||||
|
||||
public DSLContext getJooq() {
|
||||
return this.jooq;
|
||||
}
|
||||
|
||||
public TProjectRecord getProject(Integer id) {
|
||||
SelectConditionStep<TProjectRecord> sql = getJooq().selectFrom(T_PROJECT).where(T_PROJECT.PK.eq(id));
|
||||
LOGGER.debug(sql.toString());
|
||||
return sql.fetchOne();
|
||||
}
|
||||
|
||||
public Integer upsert(TProjectRecord bean) {
|
||||
return bean.getPk() != null ? update(bean) : insert(bean);
|
||||
}
|
||||
|
||||
private Integer insert(TProjectRecord bean) {
|
||||
InsertReturningStep<TProjectRecord> sql = getJooq()
|
||||
// @formatter:off
|
||||
.insertInto(T_PROJECT,
|
||||
T_PROJECT.NAME)
|
||||
.values(bean.getName())
|
||||
.onConflict(T_PROJECT.NAME)
|
||||
.doNothing();
|
||||
// @formatter:on
|
||||
LOGGER.debug(sql.toString());
|
||||
return sql.execute();
|
||||
}
|
||||
|
||||
private Integer update(TProjectRecord bean) {
|
||||
UpdateConditionStep<TProjectRecord> sql = getJooq()
|
||||
// @formatter:off
|
||||
.update(T_PROJECT)
|
||||
.set(T_PROJECT.NAME, bean.getName())
|
||||
.where(T_PROJECT.PK.eq(bean.getPk()));
|
||||
// @formatter:on
|
||||
LOGGER.debug(sql.toString());
|
||||
return sql.execute();
|
||||
}
|
||||
|
||||
public Integer delete(Integer id) {
|
||||
DeleteConditionStep<TProjectRecord> sql = getJooq()
|
||||
// @formatter:off
|
||||
.deleteFrom(T_PROJECT)
|
||||
.where(T_PROJECT.PK.eq(id));
|
||||
// @formatter:on
|
||||
LOGGER.debug(sql.toString());
|
||||
return sql.execute();
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package de.jottyfan.timetrack.spring.done.project.impl;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jooq.DSLContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import de.jottyfan.timetrack.db.done.tables.records.TProjectRecord;
|
||||
import de.jottyfan.timetrack.spring.done.project.IProjectService;
|
||||
|
||||
@Service
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public class ProjectService implements IProjectService {
|
||||
private static final Logger LOGGER = LogManager.getLogger(ProjectService.class);
|
||||
|
||||
@Autowired
|
||||
private DSLContext dsl;
|
||||
|
||||
|
||||
@Override
|
||||
public TProjectRecord getProject(Integer id) {
|
||||
try {
|
||||
return id == null ? new TProjectRecord() : new ProjectGateway(dsl).getProject(id);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer doUpsertProject(TProjectRecord bean) {
|
||||
try {
|
||||
return new ProjectGateway(dsl).upsert(bean);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer doDeleteProject(Integer id) {
|
||||
try {
|
||||
return new ProjectGateway(dsl).delete(id);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user