Ejemplo n.º 1
0
  private String newScope(GameModel gameModel, VariableDescriptor vd) {
    StringBuilder sb = new StringBuilder();
    try {
      descriptorFacade.detach(vd);
      String name = vd.getName();
      String parentName = vd.getParentList().getName();

      GameModelScope scope = new GameModelScope();
      scope.setBroadcastScope("GameScope");
      vd.setScope(scope);
      String json = vd.toJson(Views.Export.class);
      logger.error("JSON for " + parentName + "/" + name + " variable: " + json);

      descriptorFacade.remove(vd.getId());
      descriptorFacade.flush();

      logger.error("REMOVED");

      sb.append("NAME: ")
          .append(name)
          .append(" -> ")
          .append(this.addVariable(gameModel, json, name, parentName));

    } catch (IOException ex) {
      java.util.logging.Logger.getLogger(UpdateController.class.getName())
          .log(Level.SEVERE, null, ex);
    }
    return sb.toString();
  }
Ejemplo n.º 2
0
  private String rtsUpdateScope(GameModel gameModel) {
    List<VariableDescriptor> variableDescriptors = gameModel.getVariableDescriptors();
    StringBuilder sb = new StringBuilder();
    sb.append("[");

    for (VariableDescriptor vd : variableDescriptors) {

      if ("question".equals(vd.getLabel().toLowerCase())) {
        this.updateScope(vd);
      } else if ("toolbar".equals(vd.getLabel().toLowerCase())
          || "moves".equals(vd.getLabel().toLowerCase())
          || "dialogues".equals(vd.getLabel().toLowerCase())) {
        if (vd instanceof ListDescriptor) {
          ListDescriptor list = (ListDescriptor) vd;
          for (VariableDescriptor child : list.getItems()) {
            if (child instanceof StringDescriptor) {
              this.updateScope(child);
            }
          }
        }
      }
    }
    sb.append("]");

    return sb.toString();
  }
Ejemplo n.º 3
0
  @GET
  @Path("CleanOccupations")
  public String cleanOccupations() {
    String sqlRD = "SELECT rd FROM ResourceDescriptor rd";
    TypedQuery<ResourceDescriptor> allRd =
        this.getEntityManager().createQuery(sqlRD, ResourceDescriptor.class);
    StringBuilder output = new StringBuilder();

    for (ResourceDescriptor rd : allRd.getResultList()) {
      ResourceInstance defaultInstance = rd.getDefaultInstance();
      List<Occupation> occupations = defaultInstance.getOccupations();

      HashMap<Long, List<Occupation>> map = new HashMap<>();
      List<Occupation> cleanList = new ArrayList<>();

      for (Occupation occ : occupations) {
        Long key = ((Double) occ.getTime()).longValue();
        if (!map.containsKey(key)) {
          map.put(key, new ArrayList<>());
          cleanList.add(occ);
        }

        map.get(key).add(occ);
      }

      Long created = 0L;

      /** make sure each occupation exists for each resources */
      Collection<ResourceInstance> resourceInstances = rd.getScope().getPrivateInstances().values();
      for (ResourceInstance resourceInstance : resourceInstances) {
        for (Entry<Long, List<Occupation>> entry : map.entrySet()) {
          if (!hasOccupation(resourceInstance, entry.getKey().doubleValue())) {
            resourceFacade.addOccupation(resourceInstance.getId(), false, entry.getKey());
            created++;
          }
        }
      }

      if (cleanList.size() != occupations.size()) {
        output
            .append("CLEAN OCCUPATIONS FOR ")
            .append(rd.getLabel())
            .append(" (from ")
            .append(occupations.size())
            .append(" to ")
            .append(cleanList.size())
            .append("; ")
            .append(created)
            .append(" propagated)")
            .append("<br />");
        defaultInstance.setOccupations(cleanList);
      }
    }

    return output.toString();
  }
Ejemplo n.º 4
0
  private String listDescriptorScope(GameModel gameModel) {
    List<VariableDescriptor> variableDescriptors = gameModel.getVariableDescriptors();
    StringBuilder sb = new StringBuilder();
    sb.append("[");

    for (VariableDescriptor vd : variableDescriptors) {
      if (vd instanceof ListDescriptor) {
        this.updateScope(vd);
      }
    }
    sb.append("]");

    return sb.toString();
  }
Ejemplo n.º 5
0
  private String lawUpdateScope(GameModel gameModel) {
    this.updateListDescriptorScope(gameModel);
    StringBuilder sb = new StringBuilder();
    try {
      sb.append("[");

      ListDescriptor etapes =
          (ListDescriptor) VariableDescriptorFacade.lookup().find(gameModel, "etapes");
      for (VariableDescriptor item : etapes.getItems()) {
        this.updateScope(item);
      }

      sb.append("]");

    } catch (WegasNoResultException ex) {
      java.util.logging.Logger.getLogger(UpdateController.class.getName())
          .log(Level.SEVERE, null, ex);
    }
    return sb.toString();
  }
Ejemplo n.º 6
0
  private String rtsNewScope(GameModel gameModel) {
    List<VariableDescriptor> variableDescriptors = gameModel.getVariableDescriptors();
    StringBuilder sb = new StringBuilder();
    sb.append("[");

    for (Iterator<VariableDescriptor> it = variableDescriptors.iterator(); it.hasNext(); ) {
      VariableDescriptor vd = it.next();
      if ("question".equals(vd.getLabel().toLowerCase())) {
        if (!(vd.getScope() instanceof GameModelScope)) {
          sb.append(this.newScope(gameModel, vd));
        }
      } else if ("toolbar".equals(vd.getLabel().toLowerCase())
          || "moves".equals(vd.getLabel().toLowerCase())
          || "dialogues".equals(vd.getLabel().toLowerCase())) {
        if (vd instanceof ListDescriptor) {
          ListDescriptor list = (ListDescriptor) vd;
          for (VariableDescriptor child : list.getItems()) {
            if (child instanceof StringDescriptor) {
              sb.append(this.newScope(gameModel, child));
            }
          }
        }
      }
    }
    sb.append("]");

    return sb.toString();
  }
Ejemplo n.º 7
0
  private String deleteDuplicata() {

    StringBuilder sb = new StringBuilder();

    String sql =
        "SELECT vi.gameScope, vi.game FROM VariableInstance vi WHERE vi.gameScope IS NOT NULL GROUP BY vi.gameScope.id, vi.game.id HAVING count(vi) > 1";
    Query createQuery = this.getEntityManager().createQuery(sql);

    List resultList = createQuery.getResultList();
    int i = 0;
    for (Object o : resultList) {
      Object[] array = (Object[]) o;
      GameScope scope = (GameScope) array[0];
      Game game = (Game) array[1];
      // VariableInstance variableInstance = scope.getVariableInstance(game);
      // System.out.println("DELETE: " + variableInstance);

      sb.append("DELETE: ");
      sb.append(i++);
      sb.append(". ");

      String sql2 =
          "SELECT vi from VariableInstance vi WHERE vi.gameScope.id = :scopeId and vi.game.id = :gameId";

      TypedQuery<VariableInstance> query2 =
          this.getEntityManager().createQuery(sql2, VariableInstance.class);
      query2.setHint(QueryHints.CACHE_USAGE, CacheUsage.DoNotCheckCache);
      // @QueryHint(name = QueryHints.CACHE_USAGE, value = CacheUsage.CheckCacheThenDatabase)

      query2.setParameter("scopeId", scope.getId());
      query2.setParameter("gameId", game.getId());

      List<VariableInstance> list = query2.getResultList();

      sb.append(list.get(0));
      sb.append(" SCOPE - TEAM " + scope.getId() + "   " + game.getId());

      sb.append(("<br />"));

      if (list.size() != 2) {
        sb.append("   -> NOT 2 but " + list.size());
      } else {

        VariableInstance get = list.get(0);
        VariableInstance get2 = list.get(1);
        if (get instanceof BooleanInstance) {
          if (((BooleanInstance) get).getValue() != ((BooleanInstance) get2).getValue()) {
            sb.append(("   -> NOT EQUALS"));
          } else {
            this.getEntityManager().remove(get2);
          }
        } else if (get instanceof NumberInstance) {
          if (((NumberInstance) get).getValue() != ((NumberInstance) get2).getValue()) {
            sb.append(("   -> NOT EQUALS"));
          } else {
            this.getEntityManager().remove(get2);
          }
        } else if (get instanceof StringInstance) {
          if (!((StringInstance) get).getValue().equals(((StringInstance) get2).getValue())) {
            sb.append(("   -> NOT EQUALS"));
          } else {
            this.getEntityManager().remove(get2);
          }
        }
      }
      sb.append(("<br />"));
    }
    return sb.toString();
  }
Ejemplo n.º 8
0
  @GET
  @Path("PMG_UPGRADE")
  public String pmg_upgrade() {
    List<GameModel> PMGs = this.findPMGs(false);
    StringBuilder ret = new StringBuilder();
    String status;

    ret.append("<ul>");

    for (GameModel pmg : PMGs) {
      ret.append("<li>");
      ret.append(pmg.getName());
      ret.append("/");
      ret.append(pmg.getId());
      status =
          addVariable(
              pmg,
              "{\"@class\":\"BooleanDescriptor\",\"comments\":\"\",\"defaultInstance\":{\"@class\":\"BooleanInstance\",\"value\":false},\"label\":\"burndownEnabled\",\"scope\":{\"@class\":\"GameScope\",\"broadcastScope\":\"TeamScope\"},\"title\":null,\"name\":\"burndownEnabled\"}",
              "burndownEnabled",
              "properties");
      ret.append(" burndownEnabled: ");
      ret.append(status);

      ret.append("</li>");

      ret.append("<li>");
      ret.append(pmg.getName());
      ret.append("/");
      ret.append(pmg.getId());
      status =
          addVariable(
              pmg,
              "{\"@class\":\"BurndownDescriptor\",\"comments\":\"\",\"defaultInstance\":{\"@class\":\"BurndownInstance\",\"iterations\":[]},\"label\":\"burndown\",\"scope\":{\"@class\":\"TeamScope\",\"broadcastScope\":\"TeamScope\"},\"title\":\"\",\"name\":\"burndown\",\"description\":\"\"}",
              "burndown",
              "pageUtilities");
      ret.append(" burndown: ");
      ret.append(status);

      ret.append("</li>");
    }
    ret.append("</ul>");
    return ret.toString();
  }