Merge remote-tracking branch 'origin/master'

This commit is contained in:
snoop 2017-08-23 11:06:04 +09:00
commit c490167a79
3 changed files with 17 additions and 7 deletions

View File

@ -9,9 +9,12 @@ import com.loafle.overflow.module.noauthprobe.model.NoAuthProbe;
import com.loafle.overflow.module.probe.model.Probe; import com.loafle.overflow.module.probe.model.Probe;
import com.loafle.overflow.module.probe.service.ProbeService; import com.loafle.overflow.module.probe.service.ProbeService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID;
/** /**
* Created by snoop on 17. 6. 28. * Created by snoop on 17. 6. 28.
@ -30,6 +33,7 @@ public class NoAuthProbeService {
return this.noAuthProbeDAO.save(noAuthProbe); return this.noAuthProbeDAO.save(noAuthProbe);
} }
public List<NoAuthProbe> readAllByDomain(Domain domain) { public List<NoAuthProbe> readAllByDomain(Domain domain) {
return this.noAuthProbeDAO.findAllByDomain(domain); return this.noAuthProbeDAO.findAllByDomain(domain);
@ -41,13 +45,15 @@ public class NoAuthProbeService {
public List<NoAuthProbe> acceptNoAuthProbes(List<NoAuthProbe> noAuthProbes) { public List<NoAuthProbe> acceptNoAuthProbes(List<NoAuthProbe> noAuthProbes) {
// Todo encryption key generation & probe key generation
// Todo domain injection & member injection // Todo domain injection & member injection
// List<Probe> resProbe = new ArrayList<>(); List<Probe> probes = new ArrayList<>();
Probe probe = null; Probe probe = null;
for (NoAuthProbe noAuth : noAuthProbes) { for (NoAuthProbe noAuth : noAuthProbes) {
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
String key = passwordEncoder.encode(UUID.randomUUID().toString());
probe = new Probe(); probe = new Probe();
probe.setEncryptionKey(key);
probe.setProbeKey(noAuth.getApiKey()); probe.setProbeKey(noAuth.getApiKey());
probe.setDomain(new Domain(1)); probe.setDomain(new Domain(1));
probe.setAuthorizeMember(new Member(1)); probe.setAuthorizeMember(new Member(1));
@ -57,11 +63,12 @@ public class NoAuthProbeService {
probe.setEncryptionKey("111"); probe.setEncryptionKey("111");
probe.setDisplayName(noAuth.getHostName()+"'s probe"); probe.setDisplayName(noAuth.getHostName()+"'s probe");
// resprobe.add(probe); probes.add(probe);
this.probeService.regist(probe);
noAuth.setStatus(new MetaNoAuthProbeStatus((short) 1)); noAuth.setStatus(new MetaNoAuthProbeStatus((short) 1));
} }
this.probeService.regist(probes);
this.noAuthProbeDAO.save(noAuthProbes); this.noAuthProbeDAO.save(noAuthProbes);
return this.readAllByDomain(noAuthProbes.get(0).getDomain()); return this.readAllByDomain(noAuthProbes.get(0).getDomain());
} }

View File

@ -21,8 +21,11 @@ public class ProbeService {
return this.probeDAO.save(probe); return this.probeDAO.save(probe);
} }
public List<Probe> readAllByDomain(Domain domain) { public List<Probe> regist(List<Probe> probes) {
return this.probeDAO.save(probes);
}
public List<Probe> readAllByDomain(Domain domain) {
return this.probeDAO.findAllByDomainOrderByIdDesc(domain); return this.probeDAO.findAllByDomainOrderByIdDesc(domain);
} }

View File

@ -1,7 +1,6 @@
package com.loafle.overflow.module.sensor.dao; package com.loafle.overflow.module.sensor.dao;
import com.loafle.overflow.module.probe.model.Probe;
import com.loafle.overflow.module.sensor.model.Sensor; import com.loafle.overflow.module.sensor.model.Sensor;
import com.loafle.overflow.module.target.model.Target; import com.loafle.overflow.module.target.model.Target;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
@ -21,4 +20,5 @@ public interface SensorDAO extends JpaRepository<Sensor, Long> {
@Query("SELECT s from Sensor s WHERE s.target in (:targetList)") @Query("SELECT s from Sensor s WHERE s.target in (:targetList)")
List<Sensor> findAllByTarget(@Param("targetList") List<Target> targetList); List<Sensor> findAllByTarget(@Param("targetList") List<Target> targetList);
// List<Sensor> findAllByTargetList(List<Target> targets); // List<Sensor> findAllByTargetList(List<Target> targets);
} }