From 8799462ec278fd9b957c52dbc0849b20f684d2d9 Mon Sep 17 00:00:00 2001 From: insanity Date: Fri, 27 Apr 2018 14:44:08 +0900 Subject: [PATCH] count.. --- .../service/CentralNoAuthProbeService.java | 1 + .../probe/service/CentralProbeService.java | 15 +++++++ .../sensor/service/CentralSensorService.java | 11 ++++- .../target/service/CentralTargetService.java | 40 ++++++++++++++++++- 4 files changed, 64 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/loafle/overflow/central/module/noauthprobe/service/CentralNoAuthProbeService.java b/src/main/java/com/loafle/overflow/central/module/noauthprobe/service/CentralNoAuthProbeService.java index 2b929f5..ec459b4 100644 --- a/src/main/java/com/loafle/overflow/central/module/noauthprobe/service/CentralNoAuthProbeService.java +++ b/src/main/java/com/loafle/overflow/central/module/noauthprobe/service/CentralNoAuthProbeService.java @@ -144,6 +144,7 @@ public class CentralNoAuthProbeService implements NoAuthProbeService { probe.setProbeKey(GenerateKey.getKey()); probe.setDomain(new Domain(apiKey.getDomain().getId())); probe.setAuthorizeMember(new Member(domainMember.getMember().getId())); + probe.setTargetCount(0); probe.setStatus(new MetaProbeStatus((short) 1)); String dispName = hostMap.get("name"); diff --git a/src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeService.java b/src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeService.java index a63f2e8..e65d118 100644 --- a/src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeService.java +++ b/src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeService.java @@ -44,4 +44,19 @@ public class CentralProbeService implements ProbeService { public Probe modify(Probe probe) throws OverflowException { return this.probeDAO.save(probe); } + + public Probe increaseTargetCount(Probe probe) { + Probe p = this.probeDAO.findOne(probe.getId()); + p.setTargetCount(p.getTargetCount() + 1); + return this.probeDAO.save(p); + } + + public Probe decreaseTargetCount(Probe probe) { + Probe p = this.probeDAO.findOne(probe.getId()); + int count = p.getTargetCount(); + if (count > 0) { + p.setTargetCount(count - 1); + } + return this.probeDAO.save(p); + } } diff --git a/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorService.java b/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorService.java index 6267e6c..b3a746a 100644 --- a/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorService.java +++ b/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorService.java @@ -3,6 +3,7 @@ package com.loafle.overflow.central.module.sensor.service; import com.loafle.overflow.central.commons.utils.PageUtil; import com.loafle.overflow.central.module.generator.service.SensorConfigGenerator; import com.loafle.overflow.central.module.sensor.dao.SensorDAO; +import com.loafle.overflow.central.module.target.service.CentralTargetService; import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.core.model.PageParams; import com.loafle.overflow.model.domain.Domain; @@ -45,7 +46,12 @@ public class CentralSensorService implements SensorService { @Autowired private SensorConfigGenerator sensorConfigGenerator; - public Sensor regist(Sensor sensor) { + @Autowired + private CentralTargetService targetService; + + @Transactional + public Sensor regist(Sensor sensor) throws OverflowException { + this.targetService.increaseSensorCount(sensor.getTarget()); return this.sensorDAO.save(sensor); } @@ -84,7 +90,9 @@ public class CentralSensorService implements SensorService { return this.sensorDAO.findOne(Long.valueOf(id)); } + @Transactional public void remove(Sensor sensor) throws OverflowException { + this.targetService.decreaseSensorCount(sensor.getTarget()); this.sensorDAO.delete(sensor); } @@ -103,6 +111,7 @@ public class CentralSensorService implements SensorService { @Transactional public Sensor registSensorConfig(Sensor sensor, List sensorItemList, String etcJson) throws OverflowException { + this.targetService.increaseSensorCount(sensor.getTarget()); this.sensorDAO.save(sensor); for (SensorItem sensorItem : sensorItemList) { diff --git a/src/main/java/com/loafle/overflow/central/module/target/service/CentralTargetService.java b/src/main/java/com/loafle/overflow/central/module/target/service/CentralTargetService.java index 9b8e999..8dc4520 100644 --- a/src/main/java/com/loafle/overflow/central/module/target/service/CentralTargetService.java +++ b/src/main/java/com/loafle/overflow/central/module/target/service/CentralTargetService.java @@ -1,7 +1,11 @@ package com.loafle.overflow.central.module.target.service; +import javax.transaction.Transactional; + +import com.loafle.overflow.central.module.probe.service.CentralProbeService; import com.loafle.overflow.central.module.target.dao.TargetDAO; import com.loafle.overflow.core.exception.OverflowException; +import com.loafle.overflow.model.probe.Probe; import com.loafle.overflow.model.target.Target; import com.loafle.overflow.service.central.target.TargetService; @@ -16,16 +20,48 @@ public class CentralTargetService implements TargetService { @Autowired private TargetDAO targetDAO; + @Autowired + private CentralProbeService probeService; - public Target regist(Target target) throws OverflowException { + + @Transactional + public Target regist(Target target, Probe probe) throws OverflowException { + this.probeService.increaseTargetCount(probe); return this.targetDAO.save(target); } + @Transactional + public void remove(Target target, Probe probe) throws OverflowException { + this.probeService.decreaseTargetCount(probe); + this.targetDAO.delete(target); + } + public Target read(String id) throws OverflowException { return this.targetDAO.findOne(Long.valueOf(id)); } - + + @Deprecated + public Target regist(Target target) throws OverflowException { + return this.targetDAO.save(target); + } + + @Deprecated public void remove(Target target) throws OverflowException { this.targetDAO.delete(target); } + + public Target increaseSensorCount(Target target) throws OverflowException { + Target t = this.targetDAO.findOne(target.getId()); + t.setSensorCount(t.getSensorCount() + 1); + return this.targetDAO.save(t); + } + + public Target decreaseSensorCount(Target target) throws OverflowException { + Target t = this.targetDAO.findOne(target.getId()); + int count = t.getSensorCount(); + if (t.getSensorCount() > 0) { + t.setSensorCount(count - 1); + } + return this.targetDAO.save(t); + } }