コード例 #1
0
  /**
   * Settings conversion from jaxb model to entity object.
   *
   * @param model jaxb model of Settings
   * @return Settings entity object
   */
  public static org.kaleta.scheduler.backend.entity.Settings transformSettingsToData(
      Settings model) {
    org.kaleta.scheduler.backend.entity.Settings data =
        new org.kaleta.scheduler.backend.entity.Settings();

    data.setFirstUse(Boolean.valueOf(model.getAppSettings().getFirstUse().getValue()));
    data.setUserName(model.getUserSettings().getUserName().getValue());
    data.setLastMonthSelectedId(
        Integer.valueOf(model.getUserSettings().getLastSelected().getMonth_id()));
    data.setLastDaySelected(Integer.valueOf(model.getUserSettings().getLastSelected().getDay()));
    data.setUiSchemeSelected(model.getUserSettings().getUiScheme().getValue());
    data.setLanguage(model.getUserSettings().getLanguage().getValue());
    data.setCurrency(model.getUserSettings().getCurrency().getValue());
    for (Settings.TypesSettings.Type type :
        model.getTypesSettings().getItemTypes().getItemTypes()) {
      UserType itemType = new UserType();
      itemType.setName(type.getName());
      itemType.setColor(new Color(Integer.valueOf(type.getColor())));
      itemType.setSign(type.getSign().equals("+")); // diff -/+
      for (Settings.TypesSettings.Description description : type.getDescriptions()) {
        itemType.getPreparedDescriptions().add(description.getValue());
      }
      data.getItemTypes().add(itemType);
    }
    for (Settings.TypesSettings.Type type :
        model.getTypesSettings().getTaskTypes().getTaskTypes()) {
      UserType taskType = new UserType();
      taskType.setName(type.getName());
      taskType.setColor(new Color(Integer.valueOf(type.getColor())));
      taskType.setSign(false); // not supported
      for (Settings.TypesSettings.Description description : type.getDescriptions()) {
        taskType.getPreparedDescriptions().add(description.getValue());
      }
      data.getTaskTypes().add(taskType);
    }
    for (Settings.TypesSettings.Type type :
        model.getTypesSettings().getGlobalTaskTypes().getGlobalTaskTypes()) {
      UserType globalTaskType = new UserType();
      globalTaskType.setName(type.getName());
      globalTaskType.setColor(new Color(Integer.valueOf(type.getColor())));
      globalTaskType.setSign(false); // not supported
      for (Settings.TypesSettings.Description description : type.getDescriptions()) {
        globalTaskType.getPreparedDescriptions().add(description.getValue());
      }
      data.getGlobalTaskTypes().add(globalTaskType);
    }

    return data;
  }
コード例 #2
0
  /**
   * Settings conversion from entity object to jaxb model.
   *
   * @param data Settings entity object
   * @return jaxb model of Settings
   */
  public static Settings transformSettingsToModel(
      org.kaleta.scheduler.backend.entity.Settings data) {
    Settings model = new Settings();

    Settings.AppSettings appSettings = new Settings.AppSettings();
    Settings.AppSettings.FirstUse firstUse = new Settings.AppSettings.FirstUse();
    firstUse.setValue(String.valueOf(data.getFirstUse()));
    appSettings.setFirstUse(firstUse);
    model.setAppSettings(appSettings);

    Settings.UserSettings userSettings = new Settings.UserSettings();
    Settings.UserSettings.Value userName = new Settings.UserSettings.Value();
    userName.setValue(data.getUserName());
    userSettings.setUserName(userName);
    Settings.UserSettings.LastSelected lastSelected = new Settings.UserSettings.LastSelected();
    lastSelected.setMonth_id(String.valueOf(data.getLastMonthSelectedId()));
    lastSelected.setDay(String.valueOf(data.getLastDaySelected()));
    userSettings.setLastSelected(lastSelected);
    Settings.UserSettings.Value uiScheme = new Settings.UserSettings.Value();
    uiScheme.setValue(data.getUiSchemeSelected());
    userSettings.setUiScheme(uiScheme);
    Settings.UserSettings.Value language = new Settings.UserSettings.Value();
    language.setValue(data.getLanguage());
    userSettings.setLanguage(language);
    Settings.UserSettings.Value currency = new Settings.UserSettings.Value();
    currency.setValue(data.getCurrency());
    userSettings.setCurrency(currency);
    model.setUserSettings(userSettings);

    Settings.TypesSettings typesSettings = new Settings.TypesSettings();
    Settings.TypesSettings.ItemTypes itemTypes = new Settings.TypesSettings.ItemTypes();
    for (UserType type : data.getItemTypes()) {
      Settings.TypesSettings.Type itemType = new Settings.TypesSettings.Type();
      itemType.setName(type.getName());
      itemType.setColor(String.valueOf(type.getColor().getRGB()));
      itemType.setSign((type.getSign()) ? "+" : "-"); // diff -/+
      for (String desc : type.getPreparedDescriptions()) {
        Settings.TypesSettings.Description description = new Settings.TypesSettings.Description();
        description.setValue(desc);
        itemType.getDescriptions().add(description);
      }
      itemTypes.getItemTypes().add(itemType);
    }
    typesSettings.setItemTypes(itemTypes);
    Settings.TypesSettings.TaskTypes taskTypes = new Settings.TypesSettings.TaskTypes();
    for (UserType type : data.getTaskTypes()) {
      Settings.TypesSettings.Type taskType = new Settings.TypesSettings.Type();
      taskType.setName(type.getName());
      taskType.setColor(String.valueOf(type.getColor().getRGB()));
      taskType.setSign("?"); // not supported
      for (String desc : type.getPreparedDescriptions()) {
        Settings.TypesSettings.Description description = new Settings.TypesSettings.Description();
        description.setValue(desc);
        taskType.getDescriptions().add(description);
      }
      taskTypes.getTaskTypes().add(taskType);
    }
    typesSettings.setTaskTypes(taskTypes);
    Settings.TypesSettings.GlobalTaskTypes globalTaskTypes =
        new Settings.TypesSettings.GlobalTaskTypes();
    for (UserType type : data.getGlobalTaskTypes()) {
      Settings.TypesSettings.Type globalTaskType = new Settings.TypesSettings.Type();
      globalTaskType.setName(type.getName());
      globalTaskType.setColor(String.valueOf(type.getColor().getRGB()));
      globalTaskType.setSign("?"); // not supported
      for (String desc : type.getPreparedDescriptions()) {
        Settings.TypesSettings.Description description = new Settings.TypesSettings.Description();
        description.setValue(desc);
        globalTaskType.getDescriptions().add(description);
      }
      globalTaskTypes.getGlobalTaskTypes().add(globalTaskType);
    }
    typesSettings.setGlobalTaskTypes(globalTaskTypes);
    model.setTypesSettings(typesSettings);

    return model;
  }