Merge remote-tracking branch 'origin/master'

This commit is contained in:
geek 2018-06-29 15:04:29 +09:00
commit 024f49fd10
8 changed files with 74 additions and 18 deletions

View File

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

View File

@ -16,4 +16,6 @@ public interface MetaDisplayItemMappingDAO extends JpaRepository<MetaDisplayItem
List<MetaDisplayItemMapping> findAllByMetaCrawlerMappingId(Long metaCrawlerMappingID);
List<MetaDisplayItemMapping> findAllByMetaDisplayItemId(Long metaDisplayItemID);
List<MetaDisplayItemMapping> findAllByMetaCrawlerMappingIdAndIsDefaultTrueAndIsRequiredTrue(Long metaDisplayItemID);
}

View File

@ -15,8 +15,8 @@ import java.util.List;
*/
@Service("MetaDisplayItemMappingService")
public class CentralMetaDisplayItemMappingService implements MetaDisplayItemMappingService {
@Autowired
private MetaDisplayItemMappingDAO metaDisplayItemMappingDAO;
@Autowired
private MetaDisplayItemMappingDAO metaDisplayItemMappingDAO;
@Override
public MetaDisplayItemMapping regist(MetaDisplayItemMapping metaDisplayItemMapping) throws OverflowException {
@ -29,7 +29,8 @@ public class CentralMetaDisplayItemMappingService implements MetaDisplayItemMapp
}
@Override
public List<MetaDisplayItemMapping> readAllByMetaCrawlerMappingID(Long metaCrawlerMappingID) throws OverflowException {
public List<MetaDisplayItemMapping> readAllByMetaCrawlerMappingID(Long metaCrawlerMappingID)
throws OverflowException {
return this.metaDisplayItemMappingDAO.findAllByMetaCrawlerMappingId(metaCrawlerMappingID);
}
@ -37,4 +38,9 @@ public class CentralMetaDisplayItemMappingService implements MetaDisplayItemMapp
public List<MetaDisplayItemMapping> readAll() throws OverflowException {
return this.metaDisplayItemMappingDAO.findAll();
}
public List<MetaDisplayItemMapping> readAllDefault(Long metaCrawlerMappingID) throws OverflowException {
return this.metaDisplayItemMappingDAO
.findAllByMetaCrawlerMappingIdAndIsDefaultTrueAndIsRequiredTrue(metaCrawlerMappingID);
}
}

View File

@ -0,0 +1,13 @@
package com.loafle.overflow.central.module.sensor.service;
import com.loafle.overflow.model.sensor.Sensor;
import org.springframework.stereotype.Service;
@Service("SensorConfigService")
public class CentralSensorConfigService {
public void regist(Sensor sensor) {
}
}

View File

@ -1,13 +1,16 @@
package com.loafle.overflow.central.module.sensor.service;
import com.loafle.overflow.central.module.meta.service.CentralMetaCrawlerMappingService;
import com.loafle.overflow.central.module.meta.service.CentralMetaDisplayItemMappingService;
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.model.meta.MetaCrawlerMapping;
import com.loafle.overflow.model.meta.MetaDisplayItemMapping;
import com.loafle.overflow.model.meta.MetaSensorStatus;
import com.loafle.overflow.model.sensor.Sensor;
import com.loafle.overflow.model.target.Target;
import com.loafle.overflow.service.central.sensor.SensorService;
import com.loafle.overflow.service.central.target.TargetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -23,12 +26,37 @@ public class CentralSensorService implements SensorService {
@Autowired
private SensorDAO sensorDAO;
@Autowired
private CentralSensorItemService sensorItemService;
@Autowired
private TargetService targetService;
private CentralTargetService targetService;
@Autowired
private CentralMetaCrawlerMappingService metaCrawlerMappingService;
@Autowired
private CentralMetaDisplayItemMappingService metaDisplayItemMappingService;
@Autowired
private CentralSensorConfigService sensorConfigService;
public void registDefaults(List<Target> targets) throws OverflowException {
for (Target target : targets) {
this.registDefault(target);
}
}
private void registDefault(Target target) throws OverflowException {
List<MetaCrawlerMapping> metaCrawlerMappings = this.metaCrawlerMappingService
.readAllByMetaTargetTypeKey(target.getMetaTargetType().getKey());
for (MetaCrawlerMapping metaCrawlerMapping : metaCrawlerMappings) {
if (metaCrawlerMapping.getDefault()) {
Sensor sensor = new Sensor();
sensor.setMetaCrawlerMapping(metaCrawlerMapping);
sensor.setInterval(metaCrawlerMapping.getDefaultInterval());
sensor.setTarget(target);
this.regist(sensor, this.metaDisplayItemMappingService.readAllDefault(metaCrawlerMapping.getId()));
}
}
}
@Transactional
@Override
@ -44,14 +72,17 @@ public class CentralSensorService implements SensorService {
sensor.setName(targetTypeName + " Sensor via " + crawlerName);
}
sensor.setMetaSensorStatus(MetaSensorStatus.Enum.RUNNING.to());
Sensor s = this.sensorDAO.save(sensor);
s.setItemCount(0);
Sensor retSensor = this.sensorDAO.save(sensor);
retSensor.setItemCount(0);
this.targetService.increaseSensorCount(targetID);
for (MetaDisplayItemMapping metaDisplayItemMapping : metaDisplayItemMappings) {
this.sensorItemService.regist(s, metaDisplayItemMapping);
this.sensorItemService.regist(retSensor, metaDisplayItemMapping);
}
return s;
this.sensorConfigService.regist(retSensor);
return retSensor;
}
@Transactional
@ -61,7 +92,7 @@ public class CentralSensorService implements SensorService {
if (null == sensor) {
throw new OverflowException(String.format("ID[%d] of Sensor is not valid", sensorID));
}
this.sensorItemService.readAllBySensorID(sensorID);
this.sensorItemService.removeAllBySensorID(sensorID);
for (MetaDisplayItemMapping metaDisplayItemMapping : metaDisplayItemMappings) {
this.sensorItemService.regist(sensor, metaDisplayItemMapping);
}

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List;
import com.loafle.overflow.central.module.probe.service.CentralProbeService;
import com.loafle.overflow.central.module.sensor.service.CentralSensorService;
import com.loafle.overflow.central.module.target.dao.TargetDAO;
import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.model.infra.Infra;
@ -30,6 +31,8 @@ public class CentralTargetService implements TargetService {
private InfraService infraService;
@Autowired
private CentralProbeService probeService;
@Autowired
private CentralSensorService sensorService;
@Transactional
public Target regist(Target target, Long probeID) throws OverflowException {
@ -105,6 +108,9 @@ public class CentralTargetService implements TargetService {
probe.setTargetCount(targetCount);
this.probeService.modify(probe);
// FIXME : process asynchronously
this.sensorService.registDefaults(registered);
return registered;
}

View File

@ -1212,11 +1212,7 @@ VALUES
( 1 , 'service.health.response_time' , 'Service Response Time' );
INSERT INTO public.meta_display_item_mapping
( id , meta_crawler_mapping_id , meta_display_item_id , is_default , priority )
VALUES
( 1 , 252 , 1 , 'true' , 1 );
INSERT INTO public.meta_display_item_mapping ( id , meta_crawler_mapping_id , meta_display_item_id , is_default , priority , is_required , meta_display_item_category_id ) VALUES ( 1 , 252 , 1 , 'true' , 1 , 'true' , 1 );
INSERT INTO public.meta_collection_item
( id , key , item , item_class )

View File

@ -49,6 +49,8 @@ public class SensorServiceTest {
List<MetaCrawlerMapping> metaCrawlerMappings = this.metaCrawlerMappingDAO.findAll();
sensor.setMetaCrawlerMapping(metaCrawlerMappings.get(0));
sensor.setInterval(metaCrawlerMappings.get(0).getDefaultInterval());
Sensor result = this.sensorService.regist(sensor, this.metaDisplayItemMappingService.findAll());
Assert.assertNotNull(result);
}