sensor.modify

This commit is contained in:
insanity 2018-07-02 17:15:11 +09:00
parent 8a188b3873
commit a6b9b609d1
3 changed files with 14 additions and 9 deletions

View File

@ -50,7 +50,7 @@
<dependency>
<groupId>com.loafle.overflow</groupId>
<artifactId>commons-java</artifactId>
<version>1.0.116-SNAPSHOT</version>
<version>1.0.117-SNAPSHOT</version>
</dependency>
<dependency>

View File

@ -1,13 +1,9 @@
package com.loafle.overflow.central.module.sensor.service;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import javax.crypto.Cipher;
@ -53,7 +49,7 @@ public class CentralSensorConfigService {
private MessagePublisher messagePublisher;
@Transactional
public SensorConfig regist(Sensor sensor) throws OverflowException {
public SensorConfig regist(Sensor sensor, boolean update) throws OverflowException {
if (null == sensor.getId()) {
throw new OverflowException(String.format("ID[%s] of Sensor is not valid", sensor.getId()));
}
@ -66,7 +62,8 @@ public class CentralSensorConfigService {
Probe probe = sensor.getTarget().getInfra().getProbe();
String encryptedSensorConfigBase64 = this.toEncryptString(sensorConfig, probe.getEncryptionKey());
this.messagePublisher.publishToProbe(probe.getProbeKey(), "SensorService.AddSensor", encryptedSensorConfigBase64);
String method = update ? "SensorService.UpdateSensor" : "SensorService.AddSensor";
this.messagePublisher.publishToProbe(probe.getProbeKey(), method, encryptedSensorConfigBase64);
return sensorConfig;
}

View File

@ -59,6 +59,11 @@ public class CentralSensorService implements SensorService {
}
}
@Override
public Sensor modify(Sensor sensor) throws OverflowException {
return this.sensorDAO.save(sensor);
}
@Transactional
@Override
public Sensor regist(Sensor sensor, List<MetaDisplayItemMapping> metaDisplayItemMappings) throws OverflowException {
@ -82,14 +87,15 @@ public class CentralSensorService implements SensorService {
}
// FiXME : process asynchronously
this.sensorConfigService.regist(retSensor);
this.sensorConfigService.regist(retSensor, false);
return retSensor;
}
@Transactional
@Override
public Sensor modify(Long sensorID, List<MetaDisplayItemMapping> metaDisplayItemMappings) throws OverflowException {
public Sensor modifyItems(Long sensorID, List<MetaDisplayItemMapping> metaDisplayItemMappings)
throws OverflowException {
Sensor sensor = this.read(sensorID);
if (null == sensor) {
throw new OverflowException(String.format("ID[%d] of Sensor is not valid", sensorID));
@ -98,6 +104,8 @@ public class CentralSensorService implements SensorService {
for (MetaDisplayItemMapping metaDisplayItemMapping : metaDisplayItemMappings) {
this.sensorItemService.regist(sensor, metaDisplayItemMapping);
}
this.sensorConfigService.regist(sensor, true);
return sensor;
}