Example usage for java.util Comparator comparing

List of usage examples for java.util Comparator comparing

Introduction

In this page you can find the example usage for java.util Comparator comparing.

Prototype

public static <T, U extends Comparable<? super U>> Comparator<T> comparing(
        Function<? super T, ? extends U> keyExtractor) 

Source Link

Document

Accepts a function that extracts a java.lang.Comparable Comparable sort key from a type T , and returns a Comparator that compares by that sort key.

Usage

From source file:org.cgiar.ccafs.marlo.action.annualReport.CrossCgiarPartnershipAction.java

@Override
public void prepare() throws Exception {
    // Get current CRP
    loggedCrp = (GlobalUnit) this.getSession().get(APConstants.SESSION_CRP);
    loggedCrp = crpManager.getGlobalUnitById(loggedCrp.getId());
    Phase phase = this.getActualPhase();

    // If there is a history version being loaded
    if (this.getRequest().getParameter(APConstants.TRANSACTION_ID) != null) {
        transaction = StringUtils.trim(this.getRequest().getParameter(APConstants.TRANSACTION_ID));
        ReportSynthesis history = (ReportSynthesis) auditLogManager.getHistory(transaction);
        if (history != null) {
            reportSynthesis = history;/*from  www .j a  v a2 s.  c  o m*/
            synthesisID = reportSynthesis.getId();
        } else {
            this.transaction = null;
            this.setTransaction("-1");
        }
    } else {
        // Get Liaison institution ID Parameter
        try {
            liaisonInstitutionID = Long.parseLong(StringUtils
                    .trim(this.getRequest().getParameter(APConstants.LIAISON_INSTITUTION_REQUEST_ID)));
        } catch (NumberFormatException e) {
            User user = userManager.getUser(this.getCurrentUser().getId());
            if (user.getLiasonsUsers() != null || !user.getLiasonsUsers().isEmpty()) {
                List<LiaisonUser> liaisonUsers = new ArrayList<>(user.getLiasonsUsers().stream()
                        .filter(lu -> lu.isActive() && lu.getLiaisonInstitution().isActive()
                                && lu.getLiaisonInstitution().getCrp().getId() == loggedCrp.getId()
                                && lu.getLiaisonInstitution().getInstitution() == null)
                        .collect(Collectors.toList()));
                if (!liaisonUsers.isEmpty()) {
                    boolean isLeader = false;
                    for (LiaisonUser liaisonUser : liaisonUsers) {
                        LiaisonInstitution institution = liaisonUser.getLiaisonInstitution();
                        if (institution.isActive()) {
                            if (institution.getCrpProgram() != null) {
                                if (institution.getCrpProgram()
                                        .getProgramType() == ProgramType.FLAGSHIP_PROGRAM_TYPE.getValue()) {
                                    liaisonInstitutionID = institution.getId();
                                    isLeader = true;
                                    break;
                                }
                            } else {
                                if (institution.getAcronym().equals("PMU")) {
                                    liaisonInstitutionID = institution.getId();
                                    isLeader = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (!isLeader) {
                        liaisonInstitutionID = this.firstFlagship();
                    }
                } else {
                    liaisonInstitutionID = this.firstFlagship();
                }
            } else {
                liaisonInstitutionID = this.firstFlagship();
            }
        }

        try {
            synthesisID = Long.parseLong(
                    StringUtils.trim(this.getRequest().getParameter(APConstants.REPORT_SYNTHESIS_ID)));
            reportSynthesis = reportSynthesisManager.getReportSynthesisById(synthesisID);

            if (!reportSynthesis.getPhase().equals(phase)) {
                reportSynthesis = reportSynthesisManager.findSynthesis(phase.getId(), liaisonInstitutionID);
                if (reportSynthesis == null) {
                    reportSynthesis = this.createReportSynthesis(phase.getId(), liaisonInstitutionID);
                }
                synthesisID = reportSynthesis.getId();
            }
        } catch (Exception e) {
            reportSynthesis = reportSynthesisManager.findSynthesis(phase.getId(), liaisonInstitutionID);
            if (reportSynthesis == null) {
                reportSynthesis = this.createReportSynthesis(phase.getId(), liaisonInstitutionID);
            }
            synthesisID = reportSynthesis.getId();

        }
    }

    if (reportSynthesis != null) {

        ReportSynthesis reportSynthesisDB = reportSynthesisManager
                .getReportSynthesisById(reportSynthesis.getId());
        synthesisID = reportSynthesisDB.getId();
        liaisonInstitutionID = reportSynthesisDB.getLiaisonInstitution().getId();
        liaisonInstitution = liaisonInstitutionManager.getLiaisonInstitutionById(liaisonInstitutionID);

        Path path = this.getAutoSaveFilePath();
        // Verify if there is a Draft file
        if (path.toFile().exists() && this.getCurrentUser().isAutoSave()) {
            BufferedReader reader;
            reader = new BufferedReader(new FileReader(path.toFile()));
            Gson gson = new GsonBuilder().create();
            JsonObject jReader = gson.fromJson(reader, JsonObject.class);
            reader.close();
            AutoSaveReader autoSaveReader = new AutoSaveReader();
            reportSynthesis = (ReportSynthesis) autoSaveReader.readFromJson(jReader);
            synthesisID = reportSynthesis.getId();
            this.setDraft(true);
        } else {

            this.setDraft(false);
            // Check if relation is null -create it
            if (reportSynthesis.getReportSynthesisCrossCgiar() == null) {
                ReportSynthesisCrossCgiar crossCgiar = new ReportSynthesisCrossCgiar();
                // create one to one relation
                reportSynthesis.setReportSynthesisCrossCgiar(crossCgiar);
                crossCgiar.setReportSynthesis(reportSynthesis);
                // save the changes
                reportSynthesis = reportSynthesisManager.saveReportSynthesis(reportSynthesis);
            }

            if (this.isFlagship()) {
                // CGIAR collaborations Information
                if (reportSynthesis.getReportSynthesisCrossCgiar()
                        .getReportSynthesisCrossCgiarCollaborations() != null) {
                    reportSynthesis.getReportSynthesisCrossCgiar()
                            .setCollaborations(new ArrayList<>(reportSynthesis.getReportSynthesisCrossCgiar()
                                    .getReportSynthesisCrossCgiarCollaborations().stream()
                                    .filter(st -> st.isActive()).collect(Collectors.toList())));
                }

                LiaisonInstitution pmuInstitution = loggedCrp.getLiaisonInstitutions().stream()
                        .filter(c -> c.getCrpProgram() == null && c.getAcronym().equals("PMU"))
                        .collect(Collectors.toList()).get(0);
                ReportSynthesis reportSynthesisPMU = reportSynthesisManager.findSynthesis(phase.getId(),
                        pmuInstitution.getId());
                if (reportSynthesisPMU != null) {
                    if (reportSynthesisPMU.getReportSynthesisCrossCgiar() != null) {
                        pmuText = reportSynthesisPMU.getReportSynthesisCrossCgiar().getHighlights();

                    }
                }
            }
        }
    }

    // Getting The list
    statuses = new HashMap<>();
    List<ProjectStatusEnum> listStatus = Arrays.asList(ProjectStatusEnum.values());
    for (ProjectStatusEnum globalStatusEnum : listStatus) {
        statuses.put(Integer.parseInt(globalStatusEnum.getStatusId()), globalStatusEnum.getStatus());
    }
    collaborationList = new ArrayList<>(
            repIndCollaborationTypeManager.findAll().stream().collect(Collectors.toList()));
    globalUnitList = crpManager.findAll().stream().filter(
            gu -> gu.isActive() && (gu.getGlobalUnitType().getId() == 1 || gu.getGlobalUnitType().getId() == 3))
            .collect(Collectors.toList());

    // Get the list of liaison institutions Flagships and PMU.
    liaisonInstitutions = loggedCrp.getLiaisonInstitutions().stream()
            .filter(c -> c.getCrpProgram() != null && c.isActive()
                    && c.getCrpProgram().getProgramType() == ProgramType.FLAGSHIP_PROGRAM_TYPE.getValue())
            .collect(Collectors.toList());
    liaisonInstitutions.sort(Comparator.comparing(LiaisonInstitution::getAcronym));

    if (this.isPMU()) {
        flagshipCollaborations = reportSynthesisCrossCgiarCollaborationManager
                .getFlagshipCollaborations(liaisonInstitutions, phase.getId());
    }

    // ADD PMU as liasion Institution too
    liaisonInstitutions.addAll(loggedCrp.getLiaisonInstitutions().stream()
            .filter(c -> c.getCrpProgram() == null && c.isActive() && c.getAcronym().equals("PMU"))
            .collect(Collectors.toList()));

    // Base Permission
    String params[] = { loggedCrp.getAcronym(), reportSynthesis.getId() + "" };
    this.setBasePermission(this.getText(Permission.REPORT_SYNTHESIS_CROSS_CGIAR_BASE_PERMISSION, params));

    if (this.isHttpPost()) {
        if (reportSynthesis.getReportSynthesisCrossCgiar().getCollaborations() != null) {
            reportSynthesis.getReportSynthesisCrossCgiar().getCollaborations().clear();
        }
    }
}

From source file:org.eclipse.packagedrone.repo.channel.web.channel.ChannelController.java

@Secured(false)
@RequestMapping(value = "/channel/{channelId}/viewPlain", method = RequestMethod.GET)
@HttpConstraint(PERMIT)/*from   ww w .  j  ava2s.co m*/
public ModelAndView viewPlain(@PathVariable("channelId") final String channelId) {
    try {
        return this.channelService.accessCall(By.id(channelId), ReadableChannel.class, (channel) -> {

            final Map<String, Object> model = new HashMap<>();

            model.put("channel", channel.getInformation());

            final Collection<ArtifactInformation> artifacts = channel.getContext().getArtifacts().values();

            if (artifacts.size() > maxWebListSize()) {
                return viewTooMany(channel);
            }

            // sort artifacts

            final List<ArtifactInformation> sortedArtifacts = new ArrayList<>(artifacts);
            sortedArtifacts.sort(Comparator.comparing(ArtifactInformation::getName));
            model.put("sortedArtifacts", sortedArtifacts);

            return new ModelAndView("channel/view", model);
        });
    } catch (final ChannelNotFoundException e) {
        return CommonController.createNotFound("channel", channelId);
    }
}

From source file:org.openbase.bco.ontology.lib.manager.aggregation.DataAggregation.java

/**
 * Method is used to check and prepare the input information, which should be aggregated.
 *
 * @param unitConnectionTime is the time, which describes the connection time in milliseconds between unit and bco. Inconspicuous connection states should
 *                           have connection times equal the time frame of aggregation.
 * @param stateChanges are the state changes, which should be sorted ascending by including timestamp.
 * @return the sorted list of state changes.
 * @throws MultiException is thrown in case the verification of input information, which should be aggregated, is invalid.
 *//*www .  java 2  s  .  c  o m*/
private List<OntStateChangeBuf> preparingStateChanges(final long unitConnectionTime,
        final List<OntStateChangeBuf> stateChanges) throws MultiException {
    MultiException.ExceptionStack exceptionStack = null;

    try {
        if (unitConnectionTime > timeFrameMilliS) {
            throw new VerificationFailedException(
                    "The unitConnectionTime is bigger than the time frame of aggregation!");
        }
    } catch (VerificationFailedException e) {
        exceptionStack = MultiException.push(this, e, null);
    }
    try {
        if (stateChanges.isEmpty()) {
            throw new VerificationFailedException("The list of state changes is empty!");
        }
    } catch (VerificationFailedException e) {
        exceptionStack = MultiException.push(this, e, exceptionStack);
    }
    try {
        if (OffsetDateTime.parse(stateChanges.get(0).getTimestamp()).isAfter(dateTimeFrom)) {
            throw new VerificationFailedException(
                    "First state change is after the beginning aggregation time frame! No information about the state in "
                            + "the beginning time frame! First state change entry should be, chronological, before/equal the beginning time frame.");
        }
    } catch (VerificationFailedException e) {
        exceptionStack = MultiException.push(this, e, exceptionStack);
    }

    MultiException.checkAndThrow("Could not perform aggregation!", exceptionStack);

    // sort ascending (old to young)
    stateChanges.sort(Comparator.comparing(OntStateChangeBuf::getTimestamp));

    return stateChanges;
}

From source file:org.cgiar.ccafs.marlo.action.annualReport.FundingUseAction.java

@Override
public void prepare() throws Exception {
    // Get current CRP
    loggedCrp = (GlobalUnit) this.getSession().get(APConstants.SESSION_CRP);
    loggedCrp = crpManager.getGlobalUnitById(loggedCrp.getId());
    Phase phase = this.getActualPhase();

    // If there is a history version being loaded
    if (this.getRequest().getParameter(APConstants.TRANSACTION_ID) != null) {
        transaction = StringUtils.trim(this.getRequest().getParameter(APConstants.TRANSACTION_ID));
        ReportSynthesis history = (ReportSynthesis) auditLogManager.getHistory(transaction);
        if (history != null) {
            reportSynthesis = history;/*from  w  ww. j  a  v a 2s .  c om*/
            synthesisID = reportSynthesis.getId();
        } else {
            this.transaction = null;
            this.setTransaction("-1");
        }
    } else {
        // Get Liaison institution ID Parameter
        try {
            liaisonInstitutionID = Long.parseLong(StringUtils
                    .trim(this.getRequest().getParameter(APConstants.LIAISON_INSTITUTION_REQUEST_ID)));
        } catch (NumberFormatException e) {
            User user = userManager.getUser(this.getCurrentUser().getId());
            if (user.getLiasonsUsers() != null || !user.getLiasonsUsers().isEmpty()) {
                List<LiaisonUser> liaisonUsers = new ArrayList<>(user.getLiasonsUsers().stream()
                        .filter(lu -> lu.isActive() && lu.getLiaisonInstitution().isActive()
                                && lu.getLiaisonInstitution().getCrp().getId() == loggedCrp.getId()
                                && lu.getLiaisonInstitution().getInstitution() == null)
                        .collect(Collectors.toList()));
                if (!liaisonUsers.isEmpty()) {
                    boolean isLeader = false;
                    for (LiaisonUser liaisonUser : liaisonUsers) {
                        LiaisonInstitution institution = liaisonUser.getLiaisonInstitution();
                        if (institution.isActive()) {
                            if (institution.getCrpProgram() != null) {
                                if (institution.getCrpProgram()
                                        .getProgramType() == ProgramType.FLAGSHIP_PROGRAM_TYPE.getValue()) {
                                    liaisonInstitutionID = institution.getId();
                                    isLeader = true;
                                    break;
                                }
                            } else {
                                if (institution.getAcronym().equals("PMU")) {
                                    liaisonInstitutionID = institution.getId();
                                    isLeader = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (!isLeader) {
                        liaisonInstitutionID = this.firstFlagship();
                    }
                } else {
                    liaisonInstitutionID = this.firstFlagship();
                }
            } else {
                liaisonInstitutionID = this.firstFlagship();
            }
        }

        try {
            synthesisID = Long.parseLong(
                    StringUtils.trim(this.getRequest().getParameter(APConstants.REPORT_SYNTHESIS_ID)));
            reportSynthesis = reportSynthesisManager.getReportSynthesisById(synthesisID);

            if (!reportSynthesis.getPhase().equals(phase)) {
                reportSynthesis = reportSynthesisManager.findSynthesis(phase.getId(), liaisonInstitutionID);
                if (reportSynthesis == null) {
                    reportSynthesis = this.createReportSynthesis(phase.getId(), liaisonInstitutionID);
                }
                synthesisID = reportSynthesis.getId();
            }
        } catch (Exception e) {
            reportSynthesis = reportSynthesisManager.findSynthesis(phase.getId(), liaisonInstitutionID);
            if (reportSynthesis == null) {
                reportSynthesis = this.createReportSynthesis(phase.getId(), liaisonInstitutionID);
            }
            synthesisID = reportSynthesis.getId();
        }
    }

    if (reportSynthesis != null) {
        // reportSynthesisPMU: Used to calculate FLagships values
        LiaisonInstitution pmuInstitution = loggedCrp.getLiaisonInstitutions().stream()
                .filter(c -> c.getCrpProgram() == null && c.getAcronym().equals("PMU"))
                .collect(Collectors.toList()).get(0);
        reportSynthesisPMU = reportSynthesisManager.findSynthesis(phase.getId(), pmuInstitution.getId());

        ReportSynthesis reportSynthesisDB = reportSynthesisManager
                .getReportSynthesisById(reportSynthesis.getId());
        synthesisID = reportSynthesisDB.getId();
        liaisonInstitutionID = reportSynthesisDB.getLiaisonInstitution().getId();
        liaisonInstitution = liaisonInstitutionManager.getLiaisonInstitutionById(liaisonInstitutionID);

        Path path = this.getAutoSaveFilePath();
        // Verify if there is a Draft file
        if (path.toFile().exists() && this.getCurrentUser().isAutoSave()) {
            BufferedReader reader;
            reader = new BufferedReader(new FileReader(path.toFile()));
            Gson gson = new GsonBuilder().create();
            JsonObject jReader = gson.fromJson(reader, JsonObject.class);
            reader.close();
            AutoSaveReader autoSaveReader = new AutoSaveReader();
            reportSynthesis = (ReportSynthesis) autoSaveReader.readFromJson(jReader);
            synthesisID = reportSynthesis.getId();
            this.setDraft(true);
        } else {

            this.setDraft(false);
            // Check if relation is null -create it
            if (reportSynthesis.getReportSynthesisFundingUseSummary() == null) {
                ReportSynthesisFundingUseSummary fundingUseSummary = new ReportSynthesisFundingUseSummary();
                // create one to one relation
                reportSynthesis.setReportSynthesisFundingUseSummary(fundingUseSummary);
                fundingUseSummary.setReportSynthesis(reportSynthesis);
                // save the changes
                reportSynthesis = reportSynthesisManager.saveReportSynthesis(reportSynthesis);
            }
            if (this.isPMU()) {

                // Flagships Funding Expenditure Areas
                if (reportSynthesis.getReportSynthesisFundingUseSummary()
                        .getReportSynthesisFundingUseExpendituryAreas() != null
                        && !reportSynthesis.getReportSynthesisFundingUseSummary()
                                .getReportSynthesisFundingUseExpendituryAreas().isEmpty()) {
                    reportSynthesis.getReportSynthesisFundingUseSummary().setExpenditureAreas(
                            new ArrayList<>(reportSynthesis.getReportSynthesisFundingUseSummary()
                                    .getReportSynthesisFundingUseExpendituryAreas().stream()
                                    .filter(t -> t.isActive())
                                    .sorted((f1, f2) -> f1.getId().compareTo(f2.getId()))
                                    .collect(Collectors.toList())));
                } else {
                    reportSynthesis.getReportSynthesisFundingUseSummary()
                            .setExpenditureAreas(new ArrayList<>());
                    List<PowbExpenditureAreas> expAreas = new ArrayList<>(powbExpenditureAreasManager.findAll()
                            .stream().filter(x -> x.isActive() && x.getIsExpenditure())
                            .sorted((f1, f2) -> f1.getId().compareTo(f2.getId())).collect(Collectors.toList()));
                    for (PowbExpenditureAreas powbExpenditureAreas : expAreas) {
                        ReportSynthesisFundingUseExpendituryArea fundingUseExpenditureArea = new ReportSynthesisFundingUseExpendituryArea();
                        fundingUseExpenditureArea.setExpenditureArea(powbExpenditureAreas);
                        reportSynthesis.getReportSynthesisFundingUseSummary().getExpenditureAreas()
                                .add(fundingUseExpenditureArea);
                    }
                }
            }
        }
    }

    // Get the list of liaison institutions Flagships and PMU.
    liaisonInstitutions = loggedCrp.getLiaisonInstitutions().stream()
            .filter(c -> c.getCrpProgram() != null && c.isActive()
                    && c.getCrpProgram().getProgramType() == ProgramType.FLAGSHIP_PROGRAM_TYPE.getValue())
            .collect(Collectors.toList());
    liaisonInstitutions.sort(Comparator.comparing(LiaisonInstitution::getAcronym));

    // ADD PMU as liasion Institution too
    liaisonInstitutions.addAll(loggedCrp.getLiaisonInstitutions().stream()
            .filter(c -> c.getCrpProgram() == null && c.isActive() && c.getAcronym().equals("PMU"))
            .collect(Collectors.toList()));

    // Informative table to Flagships
    if (this.isFlagship()) {
        if (reportSynthesisPMU != null && reportSynthesisPMU.getReportSynthesisFundingUseSummary() != null
                && reportSynthesisPMU.getReportSynthesisFundingUseSummary()
                        .getReportSynthesisFundingUseExpendituryAreas() != null
                && !reportSynthesisPMU.getReportSynthesisFundingUseSummary()
                        .getReportSynthesisFundingUseExpendituryAreas().isEmpty()) {
            pmuText = reportSynthesisPMU.getReportSynthesisFundingUseSummary().getMainArea();
            reportSynthesis.getReportSynthesisFundingUseSummary()
                    .setExpenditureAreas(new ArrayList<>(reportSynthesisPMU
                            .getReportSynthesisFundingUseSummary()
                            .getReportSynthesisFundingUseExpendituryAreas().stream().filter(t -> t.isActive())
                            .sorted((f1, f2) -> f1.getId().compareTo(f2.getId()))
                            .collect(Collectors.toList())));
        } else {
            reportSynthesis.getReportSynthesisFundingUseSummary().setExpenditureAreas(new ArrayList<>());
            List<PowbExpenditureAreas> expAreas = new ArrayList<>(powbExpenditureAreasManager.findAll().stream()
                    .filter(x -> x.isActive() && x.getIsExpenditure())
                    .sorted((f1, f2) -> f1.getId().compareTo(f2.getId())).collect(Collectors.toList()));
            for (PowbExpenditureAreas powbExpenditureAreas : expAreas) {
                ReportSynthesisFundingUseExpendituryArea fundingUseExpenditureArea = new ReportSynthesisFundingUseExpendituryArea();
                fundingUseExpenditureArea.setExpenditureArea(powbExpenditureAreas);
                reportSynthesis.getReportSynthesisFundingUseSummary().getExpenditureAreas()
                        .add(fundingUseExpenditureArea);
            }
        }
    }

    // Base Permission
    String params[] = { loggedCrp.getAcronym(), reportSynthesis.getId() + "" };
    this.setBasePermission(this.getText(Permission.REPORT_SYNTHESIS_FUNDING_USE_BASE_PERMISSION, params));

    if (this.isHttpPost()) {
        if (reportSynthesis.getReportSynthesisFundingUseSummary().getExpenditureAreas() != null) {
            reportSynthesis.getReportSynthesisFundingUseSummary().getExpenditureAreas().clear();
        }
    }
}

From source file:org.apache.zeppelin.notebook.Notebook.java

public List<Note> getAllNotes() {
    List<Note> noteList = noteManager.getAllNotes();
    Collections.sort(noteList, Comparator.comparing(Note::getPath));
    return noteList;
}

From source file:org.cgiar.ccafs.marlo.action.annualReport.MeliaAction.java

@Override
public void prepare() throws Exception {
    // Get current CRP
    loggedCrp = (GlobalUnit) this.getSession().get(APConstants.SESSION_CRP);
    loggedCrp = crpManager.getGlobalUnitById(loggedCrp.getId());
    Phase phase = this.getActualPhase();

    // If there is a history version being loaded
    if (this.getRequest().getParameter(APConstants.TRANSACTION_ID) != null) {
        transaction = StringUtils.trim(this.getRequest().getParameter(APConstants.TRANSACTION_ID));
        ReportSynthesis history = (ReportSynthesis) auditLogManager.getHistory(transaction);
        if (history != null) {
            reportSynthesis = history;/* w w  w. j  a va2s .  co m*/
            synthesisID = reportSynthesis.getId();
        } else {
            this.transaction = null;
            this.setTransaction("-1");
        }
    } else {
        // Get Liaison institution ID Parameter
        try {
            liaisonInstitutionID = Long.parseLong(StringUtils
                    .trim(this.getRequest().getParameter(APConstants.LIAISON_INSTITUTION_REQUEST_ID)));
        } catch (NumberFormatException e) {
            User user = userManager.getUser(this.getCurrentUser().getId());
            if (user.getLiasonsUsers() != null || !user.getLiasonsUsers().isEmpty()) {
                List<LiaisonUser> liaisonUsers = new ArrayList<>(user.getLiasonsUsers().stream()
                        .filter(lu -> lu.isActive() && lu.getLiaisonInstitution().isActive()
                                && lu.getLiaisonInstitution().getCrp().getId() == loggedCrp.getId()
                                && lu.getLiaisonInstitution().getInstitution() == null)
                        .collect(Collectors.toList()));
                if (!liaisonUsers.isEmpty()) {
                    boolean isLeader = false;
                    for (LiaisonUser liaisonUser : liaisonUsers) {
                        LiaisonInstitution institution = liaisonUser.getLiaisonInstitution();
                        if (institution.isActive()) {
                            if (institution.getCrpProgram() != null) {
                                if (institution.getCrpProgram()
                                        .getProgramType() == ProgramType.FLAGSHIP_PROGRAM_TYPE.getValue()) {
                                    liaisonInstitutionID = institution.getId();
                                    isLeader = true;
                                    break;
                                }
                            } else {
                                if (institution.getAcronym().equals("PMU")) {
                                    liaisonInstitutionID = institution.getId();
                                    isLeader = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (!isLeader) {
                        liaisonInstitutionID = this.firstFlagship();
                    }
                } else {
                    liaisonInstitutionID = this.firstFlagship();
                }
            } else {
                liaisonInstitutionID = this.firstFlagship();
            }
        }

        try {
            synthesisID = Long.parseLong(
                    StringUtils.trim(this.getRequest().getParameter(APConstants.REPORT_SYNTHESIS_ID)));
            reportSynthesis = reportSynthesisManager.getReportSynthesisById(synthesisID);

            if (!reportSynthesis.getPhase().equals(phase)) {
                reportSynthesis = reportSynthesisManager.findSynthesis(phase.getId(), liaisonInstitutionID);
                if (reportSynthesis == null) {
                    reportSynthesis = this.createReportSynthesis(phase.getId(), liaisonInstitutionID);
                }
                synthesisID = reportSynthesis.getId();
            }
        } catch (Exception e) {
            reportSynthesis = reportSynthesisManager.findSynthesis(phase.getId(), liaisonInstitutionID);
            if (reportSynthesis == null) {
                reportSynthesis = this.createReportSynthesis(phase.getId(), liaisonInstitutionID);
            }
            synthesisID = reportSynthesis.getId();

        }
    }

    if (reportSynthesis != null) {

        ReportSynthesis reportSynthesisDB = reportSynthesisManager
                .getReportSynthesisById(reportSynthesis.getId());
        synthesisID = reportSynthesisDB.getId();
        liaisonInstitutionID = reportSynthesisDB.getLiaisonInstitution().getId();
        liaisonInstitution = liaisonInstitutionManager.getLiaisonInstitutionById(liaisonInstitutionID);

        // Fill Flagship Expected Studies
        if (this.isFlagship()) {
            this.studiesList(phase.getId(), liaisonInstitution);
        }

        Path path = this.getAutoSaveFilePath();
        // Verify if there is a Draft file
        if (path.toFile().exists() && this.getCurrentUser().isAutoSave()) {
            BufferedReader reader;
            reader = new BufferedReader(new FileReader(path.toFile()));
            Gson gson = new GsonBuilder().create();
            JsonObject jReader = gson.fromJson(reader, JsonObject.class);
            reader.close();
            AutoSaveReader autoSaveReader = new AutoSaveReader();
            reportSynthesis = (ReportSynthesis) autoSaveReader.readFromJson(jReader);
            synthesisID = reportSynthesis.getId();
            this.setDraft(true);
        } else {

            this.setDraft(false);
            // Check if relation is null -create it
            if (reportSynthesis.getReportSynthesisMelia() == null) {
                ReportSynthesisMelia melia = new ReportSynthesisMelia();
                // create one to one relation
                reportSynthesis.setReportSynthesisMelia(melia);
                ;
                melia.setReportSynthesis(reportSynthesis);
                // save the changes
                reportSynthesis = reportSynthesisManager.saveReportSynthesis(reportSynthesis);
            }

            if (this.isFlagship()) {
                // Crp Progress Studies
                reportSynthesis.getReportSynthesisMelia().setExpectedStudies(new ArrayList<>());
                if (reportSynthesis.getReportSynthesisMelia().getReportSynthesisMeliaStudies() != null
                        && !reportSynthesis.getReportSynthesisMelia().getReportSynthesisMeliaStudies()
                                .isEmpty()) {
                    for (ReportSynthesisMeliaStudy plannedStudy : reportSynthesis.getReportSynthesisMelia()
                            .getReportSynthesisMeliaStudies().stream().filter(ro -> ro.isActive())
                            .collect(Collectors.toList())) {
                        reportSynthesis.getReportSynthesisMelia().getExpectedStudies()
                                .add(plannedStudy.getProjectExpectedStudy());
                    }
                }

            } else {
                if (reportSynthesis.getReportSynthesisMelia().getReportSynthesisMeliaEvaluations() != null
                        && !reportSynthesis.getReportSynthesisMelia().getReportSynthesisMeliaEvaluations()
                                .isEmpty()) {
                    reportSynthesis.getReportSynthesisMelia()
                            .setEvaluations(new ArrayList<>(reportSynthesis.getReportSynthesisMelia()
                                    .getReportSynthesisMeliaEvaluations().stream().filter(e -> e.isActive())
                                    .collect(Collectors.toList())));
                }
            }
        }
    }

    // Getting The list
    statuses = new HashMap<>();
    List<ProjectStatusEnum> listStatus = Arrays.asList(ProjectStatusEnum.values());
    for (ProjectStatusEnum globalStatusEnum : listStatus) {
        statuses.put(Integer.parseInt(globalStatusEnum.getStatusId()), globalStatusEnum.getStatus());
    }

    // Get the list of liaison institutions Flagships and PMU.
    liaisonInstitutions = loggedCrp.getLiaisonInstitutions().stream()
            .filter(c -> c.getCrpProgram() != null && c.isActive()
                    && c.getCrpProgram().getProgramType() == ProgramType.FLAGSHIP_PROGRAM_TYPE.getValue())
            .collect(Collectors.toList());
    liaisonInstitutions.sort(Comparator.comparing(LiaisonInstitution::getAcronym));

    if (this.isPMU()) {
        // Table I-1 PMU Information
        flagshipPlannedList = reportSynthesisMeliaManager.getMeliaPlannedList(liaisonInstitutions,
                phase.getId(), loggedCrp, this.liaisonInstitution);

        // Table I-2 Evaluations
        fpSynthesisTable = reportSynthesisMeliaManager.flagshipSynthesisEvaluation(liaisonInstitutions,
                phase.getId());

        // Flagships Synthesis Progress
        flagshipMeliaProgress = reportSynthesisMeliaManager.getFlagshipMelia(liaisonInstitutions,
                phase.getId());
    }

    // ADD PMU as liasion Institution too
    liaisonInstitutions.addAll(loggedCrp.getLiaisonInstitutions().stream()
            .filter(c -> c.getCrpProgram() == null && c.isActive() && c.getAcronym().equals("PMU"))
            .collect(Collectors.toList()));

    // Base Permission
    String params[] = { loggedCrp.getAcronym(), reportSynthesis.getId() + "" };
    this.setBasePermission(this.getText(Permission.REPORT_SYNTHESIS_MELIA_BASE_PERMISSION, params));

    if (this.isHttpPost()) {
        if (reportSynthesis.getReportSynthesisMelia().getEvaluations() != null) {
            reportSynthesis.getReportSynthesisMelia().getEvaluations().clear();
        }

        if (reportSynthesis.getReportSynthesisMelia().getPlannedStudies() != null) {
            reportSynthesis.getReportSynthesisMelia().getPlannedStudies().clear();
        }

    }
}

From source file:de.metas.ui.web.window.descriptor.factory.standard.LayoutFactory.java

/** @return included entity grid layout */
public DocumentLayoutDetailDescriptor.Builder layoutDetail() {
    final DocumentEntityDescriptor.Builder entityDescriptor = documentEntity();
    logger.trace("Generating layout detail for {}", entityDescriptor);

    // If the detail is never displayed then don't add it to layout
    final ILogicExpression tabDisplayLogic = descriptorsFactory.getTabDisplayLogic();
    if (tabDisplayLogic.isConstantFalse()) {
        logger.trace("Skip adding detail tab to layout because it's never displayed: {}, tabDisplayLogic={}",
                entityDescriptor, tabDisplayLogic);
        return null;
    }/* w w w.java2  s  .  c om*/

    final DocumentLayoutDetailDescriptor.Builder layoutDetail = DocumentLayoutDetailDescriptor.builder()
            .setDetailId(entityDescriptor.getDetailId()).setCaption(entityDescriptor.getCaption())
            .setDescription(entityDescriptor.getDescription())
            .setEmptyResultText(HARDCODED_TAB_EMPTY_RESULT_TEXT)
            .setEmptyResultHint(HARDCODED_TAB_EMPTY_RESULT_HINT);

    //
    // Create UI elements from AD_UI_Elements which were marked as DisplayedGrid
    {
        streamAD_UI_Elements().filter(adUIElement -> adUIElement.isDisplayedGrid())
                .sorted(Comparator.comparing(I_AD_UI_Element::getSeqNoGrid))
                .map(adUIElement -> layoutElement(adUIElement)).filter(uiElement -> uiElement != null)
                .peek(uiElement -> uiElement.setGridElement()).forEach(layoutDetail::addElement);
    }

    //
    // Fallback: when no elements were found: creating the view using the single row layout
    if (!layoutDetail.hasElements()) {
        logger.warn("No grid layout was found for {}. Trying to create one based on single row layout elements",
                entityDescriptor);
        streamAD_UI_Elements()
                .filter(adUIElement -> adUIElement.isDisplayed() && !adUIElement.isAdvancedField())
                .map(adUIElement -> layoutElement(adUIElement)).filter(uiElement -> uiElement != null)
                .peek(uiElement -> uiElement.setGridElement()).forEach(layoutDetail::addElement);
    }

    //
    // Fallback:
    if (!layoutDetail.hasElements()) {
        logger.warn("No grid layout found for {}. Continuing", entityDescriptor);
    }

    //
    // Make sure all added elements have the GridViewField characteristic
    descriptorsFactory.addFieldsCharacteristic(layoutDetail.getFieldNames(), Characteristic.GridViewField);

    //
    // Quick input
    {
        final QuickInputDescriptor quickInputDescriptor = quickInputDescriptors.getQuickInputEntityDescriptor( //
                entityDescriptor.getDocumentType() //
                , entityDescriptor.getDocumentTypeId() //
                , entityDescriptor.getTableNameOrNull() //
                , entityDescriptor.getDetailId() //
        );
        layoutDetail.setQuickInput(quickInputDescriptor == null ? null : quickInputDescriptor.getLayout());
    }

    return layoutDetail;
}

From source file:org.cgiar.ccafs.marlo.action.projects.ProjectOutcomeAction.java

@Override
public void prepare() throws Exception {

    // Get current CRP
    loggedCrp = (GlobalUnit) this.getSession().get(APConstants.SESSION_CRP);
    loggedCrp = crpManager.getGlobalUnitById(loggedCrp.getId());

    try {//  w ww.ja va 2s . c om
        projectOutcomeID = Long.parseLong(
                StringUtils.trim(this.getRequest().getParameter(APConstants.PROJECT_OUTCOME_REQUEST_ID)));

        ProjectOutcome outcome = projectOutcomeManager.getProjectOutcomeById(projectOutcomeID);
        if (!outcome.getPhase().equals(this.getActualPhase())) {
            List<ProjectOutcome> projectOutcomes = outcome.getProject().getProjectOutcomes().stream()
                    .filter(c -> c.isActive()
                            && c.getCrpProgramOutcome().getComposeID()
                                    .equals(outcome.getCrpProgramOutcome().getComposeID())
                            && c.getPhase().equals(this.getActualPhase()))
                    .collect(Collectors.toList());
            if (!projectOutcomes.isEmpty()) {
                projectOutcomeID = projectOutcomes.get(0).getId();
            }
        }
    } catch (Exception e) {
        LOG.error("unable to parse projectOutcomeID", e);
        /**
         * Original code swallows the exception and didn't even log it. Now we at least log it,
         * but we need to revisit to see if we should continue processing or re-throw the exception.
         */
    }

    if (this.getRequest().getParameter(APConstants.TRANSACTION_ID) != null) {

        transaction = StringUtils.trim(this.getRequest().getParameter(APConstants.TRANSACTION_ID));
        ProjectOutcome history = (ProjectOutcome) auditLogManager.getHistory(transaction);
        if (history != null) {
            projectOutcome = history;
        } else {
            this.transaction = null;

            this.setTransaction("-1");
        }
    } else {
        projectOutcome = projectOutcomeManager.getProjectOutcomeById(projectOutcomeID);
    }

    if (projectOutcome != null) {

        Path path = this.getAutoSaveFilePath();

        if (path.toFile().exists() && this.getCurrentUser().isAutoSave()) {

            BufferedReader reader = null;

            reader = new BufferedReader(new FileReader(path.toFile()));

            Gson gson = new GsonBuilder().create();

            JsonObject jReader = gson.fromJson(reader, JsonObject.class);
            reader.close();

            AutoSaveReader autoSaveReader = new AutoSaveReader();

            projectOutcome = (ProjectOutcome) autoSaveReader.readFromJson(jReader);

            this.setDraft(true);
            project = projectManager.getProjectById(projectOutcome.getProject().getId());
            projectID = project.getId();
            Project projectDb = projectManager.getProjectById(project.getId());
            project.setProjectInfo(projectDb.getProjecInfoPhase(this.getActualPhase()));
            List<ProjectMilestone> milestones = new ArrayList<>();
            if (projectOutcome.getMilestones() != null) {
                for (ProjectMilestone crpMilestone : projectOutcome.getMilestones()) {
                    if (crpMilestone.getCrpMilestone() != null) {
                        crpMilestone.setCrpMilestone(crpMilestoneManager
                                .getCrpMilestoneById(crpMilestone.getCrpMilestone().getId()));
                        milestones.add(crpMilestone);
                    }

                }
            }
            projectOutcome.setMilestones(milestones);

        } else {
            this.setDraft(false);
            project = projectManager.getProjectById(projectOutcome.getProject().getId());
            projectID = project.getId();
            project.setProjectInfo(project.getProjecInfoPhase(this.getActualPhase()));

            projectOutcome.setMilestones(projectOutcome.getProjectMilestones().stream()
                    .filter(c -> c.isActive()).collect(Collectors.toList()));
            if (this.hasSpecificities(APConstants.CRP_SHOW_PROJECT_OUTCOME_COMMUNICATIONS)) {
                projectOutcome.setCommunications(projectOutcome.getProjectCommunications().stream()
                        .filter(c -> c.isActive()).collect(Collectors.toList()));
            }
            projectOutcome.setNextUsers(projectOutcome.getProjectNextusers().stream().filter(c -> c.isActive())
                    .collect(Collectors.toList()));

            projectOutcome.setIndicators(projectOutcome.getProjectOutcomeIndicators().stream()
                    .filter(c -> c.isActive()).collect(Collectors.toList()));
            if (this.isLessonsActive()) {
                this.loadLessonsOutcome(loggedCrp, projectOutcome);
            }

        }

    }

    Set<CrpMilestone> crpMilestones = new HashSet<>();
    if (projectOutcome.getMilestones() != null)

    {
        for (ProjectMilestone crpMilestone : projectOutcome.getMilestones()) {
            CrpMilestone milestone = crpMilestoneManager
                    .getCrpMilestoneById(crpMilestone.getCrpMilestone().getId());

            milestone.setIndex(crpMilestone.getId());
            crpMilestones.add(milestone);

        }

    }
    milestonesProject = new ArrayList<>();
    milestonesProject.addAll(crpMilestones);
    milestonesProject.sort(Comparator.comparing(CrpMilestone::getYear));
    // Collections.sort(milestonesProject, (m1, m2) -> m1.getIndex().compareTo(m2.getIndex()));
    if (projectOutcome != null)

    {
        crpProgramOutcome = crpProgramOutcomeManager
                .getCrpProgramOutcomeById(projectOutcome.getCrpProgramOutcome().getId());

        projectOutcome.setCrpProgramOutcome(crpProgramOutcome);

        milestones = projectOutcome.getCrpProgramOutcome().getCrpMilestones().stream().filter(c -> c.isActive())
                .collect(Collectors.toList());
        milestones.sort(Comparator.comparing(CrpMilestone::getYear));
    }
    /*
     * Loading basic List
     */
    targetUnits = srfTargetUnitManager.findAll().stream().filter(c -> c.isActive())
            .collect(Collectors.toList());
    projectOutcome.setCrpProgramOutcome(
            crpProgramOutcomeManager.getCrpProgramOutcomeById(projectOutcome.getCrpProgramOutcome().getId()));
    projectOutcome.getCrpProgramOutcome().setIndicators(projectOutcome.getCrpProgramOutcome()
            .getCrpProgramOutcomeIndicators().stream().filter(c -> c.isActive()).collect(Collectors.toList()));
    ;
    String params[] = { loggedCrp.getAcronym(), project.getId() + "" };

    projectOutcomeDB = projectOutcomeManager.getProjectOutcomeById(projectOutcomeID);

    this.setBasePermission(this.getText(Permission.PROJECT_CONTRIBRUTIONCRP_BASE_PERMISSION, params));
    if (this.isHttpPost())

    {
        /**
         * This might seem very strange what is going on here, but this is due to issue #1124. The Struts2 Prepare
         * interceptor will set the values on the projectOutcome entity during save, but if we leave the values here and
         * they ids change then Hibernate will be unhappy.
         */
        if (projectOutcome.getMilestones() != null) {
            projectOutcome.getMilestones().clear();
        }
        if (projectOutcome.getCommunications() != null) {
            projectOutcome.getCommunications().clear();
        }

        if (projectOutcome.getNextUsers() != null) {
            projectOutcome.getNextUsers().clear();
        }
        if (projectOutcome.getIndicators() != null) {
            projectOutcome.getIndicators().clear();
        }
        /**
         * Hack to fix ManyToOne issue as a result of issue #1124
         */
        projectOutcome.setAchievedUnit(null);
        projectOutcome.setExpectedUnit(null);
    }

}

From source file:org.cgiar.ccafs.marlo.action.powb.MonitoringEvaluationLearningAction.java

@Override
public void prepare() throws Exception {
    // Get current CRP
    loggedCrp = (GlobalUnit) this.getSession().get(APConstants.SESSION_CRP);
    loggedCrp = crpManager.getGlobalUnitById(loggedCrp.getId());
    Phase phase = this.getActualPhase();

    // If there is a history version being loaded
    if (this.getRequest().getParameter(APConstants.TRANSACTION_ID) != null) {
        transaction = StringUtils.trim(this.getRequest().getParameter(APConstants.TRANSACTION_ID));
        PowbSynthesis history = (PowbSynthesis) auditLogManager.getHistory(transaction);
        if (history != null) {
            powbSynthesis = history;/* w  ww  .j a  va2 s  .com*/
            powbSynthesisID = powbSynthesis.getId();
        } else {
            this.transaction = null;
            this.setTransaction("-1");
        }
    } else {
        // Get Liaison institution ID Parameter
        try {
            liaisonInstitutionID = Long.parseLong(StringUtils
                    .trim(this.getRequest().getParameter(APConstants.LIAISON_INSTITUTION_REQUEST_ID)));
        } catch (NumberFormatException e) {
            User user = userManager.getUser(this.getCurrentUser().getId());
            if (user.getLiasonsUsers() != null || !user.getLiasonsUsers().isEmpty()) {
                List<LiaisonUser> liaisonUsers = new ArrayList<>(user.getLiasonsUsers().stream()
                        .filter(lu -> lu.isActive() && lu.getLiaisonInstitution().isActive()
                                && lu.getLiaisonInstitution().getCrp().getId() == loggedCrp.getId()
                                && lu.getLiaisonInstitution().getInstitution() == null)
                        .collect(Collectors.toList()));
                if (!liaisonUsers.isEmpty()) {
                    boolean isLeader = false;
                    for (LiaisonUser liaisonUser : liaisonUsers) {
                        LiaisonInstitution institution = liaisonUser.getLiaisonInstitution();
                        if (institution.isActive()) {
                            if (institution.getCrpProgram() != null) {
                                if (institution.getCrpProgram()
                                        .getProgramType() == ProgramType.FLAGSHIP_PROGRAM_TYPE.getValue()) {
                                    liaisonInstitutionID = institution.getId();
                                    isLeader = true;
                                    break;
                                }
                            } else {
                                if (institution.getAcronym().equals("PMU")) {
                                    liaisonInstitutionID = institution.getId();
                                    isLeader = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (!isLeader) {
                        liaisonInstitutionID = this.firstFlagship();
                    }
                } else {
                    liaisonInstitutionID = this.firstFlagship();
                }
            } else {
                liaisonInstitutionID = this.firstFlagship();
            }
        }

        try {
            powbSynthesisID = Long
                    .parseLong(StringUtils.trim(this.getRequest().getParameter(APConstants.POWB_SYNTHESIS_ID)));
            powbSynthesis = powbSynthesisManager.getPowbSynthesisById(powbSynthesisID);

            if (!powbSynthesis.getPhase().equals(phase)) {
                powbSynthesis = powbSynthesisManager.findSynthesis(phase.getId(), liaisonInstitutionID);
                if (powbSynthesis == null) {
                    powbSynthesis = this.createPowbSynthesis(phase.getId(), liaisonInstitutionID);
                }
                powbSynthesisID = powbSynthesis.getId();
            }
        } catch (Exception e) {

            powbSynthesis = powbSynthesisManager.findSynthesis(phase.getId(), liaisonInstitutionID);
            if (powbSynthesis == null) {
                powbSynthesis = this.createPowbSynthesis(phase.getId(), liaisonInstitutionID);
            }
            powbSynthesisID = powbSynthesis.getId();

        }
    }

    if (powbSynthesis != null) {

        PowbSynthesis powbSynthesisDB = powbSynthesisManager.getPowbSynthesisById(powbSynthesisID);
        powbSynthesisID = powbSynthesisDB.getId();
        liaisonInstitutionID = powbSynthesisDB.getLiaisonInstitution().getId();
        liaisonInstitution = liaisonInstitutionManager.getLiaisonInstitutionById(liaisonInstitutionID);

        Path path = this.getAutoSaveFilePath();
        // Verify if there is a Draft file
        if (path.toFile().exists() && this.getCurrentUser().isAutoSave()) {
            BufferedReader reader;
            reader = new BufferedReader(new FileReader(path.toFile()));
            Gson gson = new GsonBuilder().create();
            JsonObject jReader = gson.fromJson(reader, JsonObject.class);
            AutoSaveReader autoSaveReader = new AutoSaveReader();
            powbSynthesis = (PowbSynthesis) autoSaveReader.readFromJson(jReader);
            powbSynthesisID = powbSynthesis.getId();
            this.setDraft(true);
            reader.close();
        } else {
            this.setDraft(false);
            // Check if ToC relation is null -create it
            if (powbSynthesis.getPowbMonitoringEvaluationLearning() == null) {
                PowbMonitoringEvaluationLearning monitoringEvaluationLearning = new PowbMonitoringEvaluationLearning();
                // create one to one relation
                powbSynthesis.setPowbMonitoringEvaluationLearning(monitoringEvaluationLearning);
                monitoringEvaluationLearning.setPowbSynthesis(powbSynthesis);
                // save the changes
                powbSynthesis = powbSynthesisManager.savePowbSynthesis(powbSynthesis);
            }

            if (this.isFlagship()) {
                if (powbSynthesis.getPowbMonitoringEvaluationLearning()
                        .getPowbMonitoringEvaluationLearningExercises() != null) {
                    powbSynthesis.getPowbMonitoringEvaluationLearning()
                            .setExercises(new ArrayList<>(powbSynthesis.getPowbMonitoringEvaluationLearning()
                                    .getPowbMonitoringEvaluationLearningExercises().stream()
                                    .filter(ps -> ps.isActive()).collect(Collectors.toList())));
                }
            }
        }
    }

    // Get the list of liaison institutions Flagships and PMU.
    liaisonInstitutions = loggedCrp.getLiaisonInstitutions().stream()
            .filter(c -> c.getCrpProgram() != null && c.isActive()
                    && c.getCrpProgram().getProgramType() == ProgramType.FLAGSHIP_PROGRAM_TYPE.getValue())
            .collect(Collectors.toList());
    liaisonInstitutions.sort(Comparator.comparing(LiaisonInstitution::getAcronym));

    if (this.isPMU()) {
        this.getfpExercises(liaisonInstitutions, phase.getId());
    }

    liaisonInstitutions.addAll(loggedCrp.getLiaisonInstitutions().stream()
            .filter(c -> c.getCrpProgram() == null && c.isActive() && c.getAcronym().equals("PMU"))
            .collect(Collectors.toList()));

    // Base Permission
    String params[] = { loggedCrp.getAcronym(), powbSynthesis.getId() + "" };
    this.setBasePermission(this.getText(Permission.POWB_SYNTHESIS_MEL_BASE_PERMISSION, params));

    if (this.isHttpPost()) {
        if (powbSynthesis.getPowbMonitoringEvaluationLearning().getExercises() != null) {
            powbSynthesis.getPowbMonitoringEvaluationLearning().getExercises().clear();
        }
    }
}