Ejemplo n.º 1
0
  @Transactional
  public DayGrid updateDayGid(DayGrid dayGrid, String profile) throws ParseException {

    Set<EmplacementDTO> blocs = dayGrid.getBlocs();
    if (blocs != null) {
      for (Iterator<EmplacementDTO> iterator = blocs.iterator(); iterator.hasNext(); ) {
        EmplacementDTO emplacementDTO = iterator.next();
        Set<RubriqueDTO> rubriqueDTOSet = emplacementDTO.getRubrique();
        if (rubriqueDTOSet != null) {
          for (Iterator<RubriqueDTO> rubriqueDTOIterator = rubriqueDTOSet.iterator();
              rubriqueDTOIterator.hasNext(); ) {
            RubriqueDTO rubriqueDTO = rubriqueDTOIterator.next();
            rubriqueLoggingService.updateEmplacementRubriqueForDay(
                emplacementDTO.getId(),
                emplacementDTO.getName(),
                emplacementDTO.getPosition(),
                rubriqueDTO.getId(),
                profile,
                dayGrid.getId());

            LinkedHashSet<CommunicationGroupDTO> communicationGroups =
                rubriqueDTO.getCommunicationGroups();
            for (Iterator<CommunicationGroupDTO> communicationGroupDTOIterator =
                    communicationGroups.iterator();
                communicationGroupDTOIterator.hasNext(); ) {
              CommunicationGroupDTO communicationGroupDTO = communicationGroupDTOIterator.next();
              LinkedHashSet<CommunicationDTO> communicationDTOs =
                  communicationGroupDTO.getCommunications();
              if (communicationDTOs != null && communicationDTOs.size() > 0) {
                List<String> communicationIdsToDeactivate = Lists.newArrayList();
                List<String> communicationIdsToActivate = Lists.newArrayList();
                for (Iterator<CommunicationDTO> communicationDTOIterator =
                        communicationDTOs.iterator();
                    communicationDTOIterator.hasNext(); ) {
                  CommunicationDTO communicationDTO = communicationDTOIterator.next();
                  if (isToday(dayGrid.getDate())) {
                    if (communicationDTO.isDeactivated()
                        && !communicationLoggingService.isDeactivatedCommunicationLogging(
                            communicationDTO.getCommunicationLoggingId())) {
                      communicationIdsToDeactivate.add(communicationDTO.getIdArrowCommunication());
                    }
                    if (!communicationDTO.isDeactivated()
                        && communicationLoggingService.isDeactivatedCommunicationLogging(
                            communicationDTO.getCommunicationLoggingId())) {
                      communicationIdsToActivate.add(communicationDTO.getIdArrowCommunication());
                    }
                  }
                  // update communicationLogging
                  communicationLoggingService.updateCommunicationLoggingForCommunicationAndDay(
                      communicationDTO.getIdCommunication(),
                      dayGrid.getId(),
                      communicationDTO.getPriority(),
                      communicationGroupDTO.getId(),
                      communicationGroupDTO.getLabel(),
                      communicationDTO.getNbAffichageMax(),
                      communicationDTO.getNbJourAffichageMax(),
                      communicationDTO.getNbClicMax(),
                      communicationDTO.getNbJourClicMax(),
                      communicationDTO.isDeactivated());
                }
                if (isToday(dayGrid.getDate())) {
                  if (CollectionUtils.isNotEmpty(communicationIdsToDeactivate)) {
                    deactivateCommunicationsInstantaneously(
                        dayGrid.getDate(), communicationIdsToDeactivate);
                  }
                  if (CollectionUtils.isNotEmpty(communicationIdsToActivate)) {
                    activateCommunicationsInstantaneously(
                        dayGrid.getDate(), communicationIdsToActivate);
                  }
                }
              }
            }
          }
        }
      }
    }

    return dayGrid;
  }
Ejemplo n.º 2
0
  @Transactional
  public DayGrid getDayGridForDay(
      Date date, Long siteId, Long pageId, String profile, User user, boolean future)
      throws ExecutionException { // , Map<Long,Set<AnimationDTO>> validAnimationsByRubriques) {
    logger.debug(
        "getDayGridForDay for date {}, site {}, page {} and profile {}",
        date,
        siteId,
        pageId,
        profile);
    Day day = periodService.getDay(date);

    List<CommunicationGroup> communicationGroups = arrowService.getCommunicationGroups();

    // recuperer liste des emplacements avec rubriques attaches pour le profile
    // commencer par chercher la liste des rubriques, et voir si y a des rubriqueLogging pour ce
    // jour et ce profil
    // si la liste est vide créer les rubriqueLogging avec les emplaceemnts par défaut (le test pour
    // création est fait dans le service)
    LinkedHashSet<RubriqueLogging> emplacementsRubriqueForThisDay =
        rubriqueLoggingService.getRubriqueLoggingForSiteProfileAndDay(
            siteId, pageId, profile, day.getId());

    LinkedHashSet<EmplacementDTO> blocs = new LinkedHashSet<>();
    for (Iterator<RubriqueLogging> iterator = emplacementsRubriqueForThisDay.iterator();
        iterator.hasNext(); ) {
      EmplacementDTO emplacementDTO = new EmplacementDTO();

      RubriqueLogging rubriqueLogging = iterator.next();
      emplacementDTO.setId(rubriqueLogging.getIdEmplacement());
      emplacementDTO.setName(rubriqueLogging.getEmplacement());
      emplacementDTO.setPosition(rubriqueLogging.getPosition());
      LinkedHashSet<RubriqueDTO> rubriquesDTO = new LinkedHashSet<>();
      Rubrique rubrique = neo4jOperations.fetch(rubriqueLogging.getRubrique());

      // NEW CODE
      LinkedHashSet<CommunicationQueryResult> communications =
          dayRepository.findCommunicationForGridDayAndRubrique(
              rubrique.getId(), day.getId(), profile, !future);
      LinkedHashMap<String, LinkedHashSet<CommunicationDTO>> tempCommunicationGroup =
          new LinkedHashMap<>();
      for (Iterator<CommunicationQueryResult> communicationQueryResultIterator =
              communications.iterator();
          communicationQueryResultIterator.hasNext(); ) {
        CommunicationQueryResult communicationQueryResult = communicationQueryResultIterator.next();
        CommunicationDTO communicationDTO = communicationDTOAdapter.adapt(communicationQueryResult);
        LinkedHashSet<CommunicationDTO> communicationDTOListForThisGroup =
            tempCommunicationGroup.get(communicationDTO.getCommunicationGroupId());
        if (communicationDTOListForThisGroup == null) {
          communicationDTOListForThisGroup = new LinkedHashSet<>();
        }
        communicationDTOListForThisGroup.add(communicationDTO);
        tempCommunicationGroup.put(
            communicationDTO.getCommunicationGroupId(), communicationDTOListForThisGroup);
      }

      LinkedHashSet<CommunicationGroupDTO> communicationGroupDTOs = new LinkedHashSet<>();

      for (Iterator<CommunicationGroup> communicationGroupsIterator =
              communicationGroups.iterator();
          communicationGroupsIterator.hasNext(); ) {
        CommunicationGroup communicationGroup = communicationGroupsIterator.next();
        LinkedHashSet<CommunicationDTO> communicationDTOListForThisGroup =
            tempCommunicationGroup.get(communicationGroup.getId());
        if (communicationDTOListForThisGroup == null) {
          communicationDTOListForThisGroup = new LinkedHashSet<>();
        }
        communicationGroupDTOs.add(
            new CommunicationGroupDTO(
                communicationGroup.getId(),
                communicationGroup.getLabel(),
                communicationDTOListForThisGroup));
      }

      // END NEW CODE

      /*Set<AnimationDTO> animations = validAnimationsByRubriques.get(rubrique.getId());
      // rubrique.getAnimations();
      Set<AnimationDTO> animationsDTO = new LinkedHashSet<>();
      for (Iterator<AnimationDTO> animationIterator = animations.iterator(); animationIterator.hasNext(); ) {
          AnimationDTO animation = animationIterator.next();
          //vérifier si l'animation est valide ce jour là
          Calendar endDateCalendar = GregorianCalendar.getInstance();
          endDateCalendar.setTime( animation.getDateFin());
          endDateCalendar.add(GregorianCalendar.DAY_OF_YEAR, 1);

          Interval interval = new Interval( animation.getDateDebut().getTime(), endDateCalendar.getTime().getTime() );
          boolean intervalContainsThisDay = interval.contains( date.getTime() );
          if(intervalContainsThisDay){
              //mettre à jour les créas pour ce jour là
              animationsDTO.add(animation);
          }
      }*/
      RubriqueDTO rubriqueDTO =
          new RubriqueDTO(
              rubrique.getId(),
              rubrique.getNom(),
              rubrique.getManagedByCooper(),
              communicationGroupDTOs);
      rubriquesDTO.add(rubriqueDTO);
      emplacementDTO.setRubrique(rubriquesDTO);
      blocs.add(emplacementDTO);
    }
    DayGrid dayGrid = new DayGrid(day.getId(), day.getName(), blocs);

    String formattedDate = new SimpleDateFormat(Day.dateFormat).format(date);

    DayGridLock lockForDayAndProfile =
        gridLockManager.getLockStatusForDayAndProfile(siteId, pageId, formattedDate, profile, user);
    dayGrid.setDayGridLockDTO(new DayGridLockDTO(lockForDayAndProfile, user));

    return dayGrid;
  }