package net.explorviz.settings.server.main;

import java.util.Arrays;
import java.util.List;
import javax.inject.Inject;
import javax.servlet.annotation.WebListener;
import net.explorviz.shared.security.model.User;
import net.explorviz.shared.security.model.roles.Role;
import net.explorviz.shared.security.model.settings.UserSettings;
import org.glassfish.jersey.server.monitoring.ApplicationEvent;
import org.glassfish.jersey.server.monitoring.ApplicationEventListener;
import org.glassfish.jersey.server.monitoring.RequestEvent;
import org.glassfish.jersey.server.monitoring.RequestEventListener;
import org.glassfish.jersey.server.monitoring.ApplicationEvent.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import xyz.morphia.Datastore;

/**
 * Primary starting class - executed, when the servlet context is started.
 */
@WebListener
public class SetupApplicationListener implements ApplicationEventListener {

  private static final Logger LOGGER = LoggerFactory.getLogger(SetupApplicationListener.class);

  private static final String ADMIN_NAME = "admin";

  @Inject
  private Datastore datastore;


  @Override
  public void onEvent(final ApplicationEvent event) {

    // After this type, CDI (e.g. injected LandscapeExchangeService) has been
    // fullfilled
    final Type t = Type.INITIALIZATION_FINISHED;


    if (event.getType().equals(t)) {
      
    }

  }

  @Override
  public RequestEventListener onRequest(final RequestEvent requestEvent) {
    return null;
  }




}
@@ -38,16 +38,44 @@
 .main;%0A%0A
+import java.util.ArrayList;%0A
 import j
@@ -91,16 +91,16 @@
 Arrays;%0A
-
 import j
@@ -213,132 +213,165 @@
 iz.s
-hared.security.model.User;%0Aimport net.explorviz.shared.security.model.roles.Role;%0Aimport net.explorviz.shared.security.model
+ettings.services.MongoRepository;%0Aimport net.explorviz.settings.model.BooleanSetting;%0Aimport net.explorviz.settings.model.DoubleSetting;%0Aimport net.explorviz
 .set
@@ -380,20 +380,21 @@
 ngs.
-User
+model.
 Setting
-s
 ;%0Aim
@@ -1177,16 +1177,82 @@
 store;%0A%0A
+  @Inject%0A  private MongoRepository%3CSetting, String%3E settingRepo;%0A
 %0A  @Over
@@ -1501,16 +1501,37 @@
 %7B%0A      
+addDefaultSettings();
 %0A    %7D%0A%0A
@@ -1645,11 +1645,1244 @@
 ;%0A  %7D%0A%0A%0A
+%0A  private void addDefaultSettings() %7B%0A    List%3CSetting%3C?%3E%3E defaults = new ArrayList%3CSetting%3C?%3E%3E(Arrays.asList(%0A        new BooleanSetting(%22showFpsCounter%22, %22Show FPS Counter%22, %22%5C'Frames Per Second%5C' metrics in visualizations%22, false),%0A        new BooleanSetting(%22appVizTransparency%22, %22App Viz Transparency%22, %22Transparency effect for selection (left click) in application visualization%22, true),%0A        new BooleanSetting(%22enableHoverEffects%22, %22Enable Hover Effects%22, %22Hover effect (flashing entities) for mouse cursor%22, true),%0A        new BooleanSetting(%22keepHighlightingOnOpenOrClose%22, %22Keep Highlighting On Open Or Close%22, %22Toggle if highlighting should be resetted on double click in application visualization%22, true),%0A        new DoubleSetting(%22appVizCommArrowSize%22, %22Arrow Size in Application Visualization%22, %22Arrow Size for selected communications in application visualization%22, 1.0),%0A        new DoubleSetting(%22appVizTransparencyIntensity%22, %22Transparency Intensity in Application Visualization%22, %22Transparency effect intensity (%5C'App Viz Transparency%5C' must be enabled)%22, 0.1, 0.5, 0.1)%0A      ));%0A    %0A    defaults.stream()  %0A      .filter(d -%3E !settingRepo.find(d.getId()).isPresent()).forEach(settingRepo::create);%0A    %0A  %7D
 %0A%0A%7D

Add default settings on application startu