From 7594a03de5c1e29f3fcec26ba144adc659a62268 Mon Sep 17 00:00:00 2001 From: Nadim Ritter Date: Fri, 15 Mar 2024 13:42:04 +0100 Subject: [PATCH] SEBSLI-9 new light init class --- .../servicelayer/light/impl/LightInit.java | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/light/impl/LightInit.java diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/light/impl/LightInit.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/light/impl/LightInit.java new file mode 100644 index 00000000..bf06779f --- /dev/null +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/light/impl/LightInit.java @@ -0,0 +1,85 @@ +package ch.ethz.seb.sebserver.webservice.servicelayer.light.impl; + + +import ch.ethz.seb.sebserver.SEBServerInitEvent; +import ch.ethz.seb.sebserver.gbl.model.sebconfig.SEBClientConfig; +import ch.ethz.seb.sebserver.gbl.util.Result; +import ch.ethz.seb.sebserver.gbl.util.Utils; +import ch.ethz.seb.sebserver.webservice.servicelayer.dao.FilterMap; +import ch.ethz.seb.sebserver.webservice.servicelayer.dao.SEBClientConfigDAO; +import org.joda.time.DateTime; +import org.joda.time.DateTimeZone; +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; +import org.springframework.context.annotation.Lazy; +import org.springframework.context.event.EventListener; +import org.springframework.stereotype.Service; + +import java.util.Collection; +import java.util.stream.Collectors; + +@Lazy +@Service +@ConditionalOnExpression("'${sebserver.webservice.light.setup}'.equals('true')") +public class LightInit { + + private final SEBClientConfigDAO sebClientConfigDAO; + + public LightInit(final SEBClientConfigDAO sebClientConfigDAO){ + this.sebClientConfigDAO = sebClientConfigDAO; + } + + + + @EventListener(SEBServerInitEvent.class) + public void init() { + if(isConnectionConfigAbsent()){ + this.sebClientConfigDAO.createNew(createLightConnectionConfiguration()).getOrThrow(); + } + } + + private boolean isConnectionConfigAbsent() { + Collection connectionConfigs = this.sebClientConfigDAO + .all(null, null) + .getOrThrow(); + + if(connectionConfigs.size() == 0){ + return true; + } + + return false; + } + + private SEBClientConfig createLightConnectionConfiguration(){ + return new SEBClientConfig( + 1L, + 1L, + "light-config", + SEBClientConfig.ConfigPurpose.CONFIGURE_CLIENT, + 1000L, + SEBClientConfig.VDIType.NO, + null, + null, + null, + false, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + false, + true, + null, + null, + null); + } + + + +}