Example #1
0
  public Map<String, JitElement> addNode(String userId, Element node, String path) {
    UserSettings userSettings = trackItDAO.getCurrentSettings(userId);

    Settings settings = userSettings.getSettings();

    Hierarchy hierarchy = settings.getHierarchy();
    hierarchy.addChildNode(path, node);

    settings.setHierarchy(hierarchy);
    userSettings.setSettings(settings);

    trackItDAO.save(userSettings);

    userSettings = trackItDAO.getCurrentSettings("backup");

    settings.setHierarchy(hierarchy);
    userSettings.setSettings(settings);

    trackItDAO.save(userSettings);
    return new JitUtil().getJitHierarchy(userSettings);
  }
Example #2
0
  public Map<String, JitElement> addGroup(String userId, Element group) {
    UserSettings userSettings = trackItDAO.getCurrentSettings(userId);

    Settings settings = userSettings.getSettings();

    Hierarchy hierarchy = settings.getHierarchy();
    hierarchy.addGroup(group);

    settings.setHierarchy(hierarchy);
    userSettings.setSettings(settings);

    trackItDAO.save(userSettings);

    userSettings = trackItDAO.getCurrentSettings("backup");

    settings.setHierarchy(hierarchy);
    userSettings.setSettings(settings);

    trackItDAO.save(userSettings);
    return new JitUtil().getJitHierarchy(userSettings);
  }
Example #3
0
  public UserSettings getUserSettings(String id) throws IOException {
    UserSettings userSettings = trackItDAO.getCurrentSettings(id);

    if (userSettings == null) {
      InputStream hierachyStream = getClass().getResourceAsStream("/json/hierarchy.json");
      InputStream unitStream = getClass().getResourceAsStream("/json/units.json");
      InputStream assignmentStream = getClass().getResourceAsStream("/json/assignments.json");
      ObjectMapper mapper = new ObjectMapper();
      Hierarchy hierarchy = mapper.readValue(hierachyStream, Hierarchy.class);
      UnitConfig unitConfig = mapper.readValue(unitStream, UnitConfig.class);
      Assignments assignments = mapper.readValue(assignmentStream, Assignments.class);

      Settings defaultSettings = new Settings(hierarchy, unitConfig, assignments);
      userSettings = new UserSettings(id, defaultSettings);

      trackItDAO.save(userSettings);
      userSettings.setUserId("backup");
      userSettings.setId(new ObjectId());
      trackItDAO.save(userSettings);
    }
    return userSettings;
  }