List of usage examples for java.util Comparator comparing
public static <T, U extends Comparable<? super U>> Comparator<T> comparing( Function<? super T, ? extends U> keyExtractor)
From source file:org.sleuthkit.autopsy.timeline.ui.listvew.ListTimeline.java
/** * Set the combined events that are selected in this view. * * @param selectedEvents The events that should be selected. *///w ww . j a va 2s. co m void selectEvents(Collection<CombinedEvent> selectedEvents) { CombinedEvent firstSelected = selectedEvents.stream() .min(Comparator.comparing(CombinedEvent::getStartMillis)).orElse(null); table.getSelectionModel().clearSelection(); table.scrollTo(firstSelected); selectedEvents.forEach(table.getSelectionModel()::select); table.requestFocus(); }
From source file:de.dentrassi.pm.storage.web.channel.ChannelController.java
@Secured(false) @RequestMapping(value = "/channel/{channelId}/viewPlain", method = RequestMethod.GET) @HttpConstraint(PERMIT)/*from ww w .j a v a 2s . c om*/ public ModelAndView viewPlain(@PathVariable("channelId") final String channelId) { final ModelAndView result = new ModelAndView("channel/view"); try { this.channelService.access(By.id(channelId), ReadableChannel.class, (channel) -> { final List<ArtifactInformation> sortedArtifacts = new ArrayList<>( channel.getContext().getArtifacts()); sortedArtifacts.sort(Comparator.comparing(ArtifactInformation::getId)); // FIXME: change to name result.put("channel", channel.getInformation()); result.put("sortedArtifacts", sortedArtifacts); }); } catch (final ChannelNotFoundException e) { return CommonController.createNotFound("channel", channelId); } return result; }
From source file:com.github.horrorho.liquiddonkey.cloud.Looter.java
List<ICloud.MBSFile> sorted(Snapshot snapshot) { List<ICloud.MBSFile> files = new ArrayList<>(snapshot.files()); Collections.sort(files, Comparator.comparing(file -> file.getDomain() + file.getRelativePath())); return files; }
From source file:org.keycloak.models.jpa.JpaRealmProvider.java
@Override public List<GroupModel> getGroups(RealmModel realm) { RealmEntity ref = em.getReference(RealmEntity.class, realm.getId()); return ref.getGroups().stream().map(g -> session.realms().getGroupById(g.getId(), realm)) .sorted(Comparator.comparing(GroupModel::getName)) .collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList)); }
From source file:org.phoenicis.repository.types.ClasspathRepository.java
private List<ScriptDTO> buildScripts(String typeId, String categoryId, String applicationId, String typeFileName, String categoryFileName, String applicationFileName) throws RepositoryException { try {/* ww w . j a va2 s .c o m*/ final String applicationScanClassPath = packagePath + "/" + typeFileName + "/" + categoryFileName + "/" + applicationFileName; Resource[] resources = resourceResolver.getResources(applicationScanClassPath + "/*"); final List<ScriptDTO> scriptDTOs = new ArrayList<>(); for (Resource resource : resources) { final String fileName = resource.getFilename(); if (!"resources".equals(fileName) && !"miniatures".equals(fileName) && !"application.json".equals(fileName)) { final ScriptDTO script = buildScript(typeId, categoryId, applicationId, typeFileName, categoryFileName, applicationFileName, fileName); scriptDTOs.add(script); } } scriptDTOs.sort(Comparator.comparing(ScriptDTO::getScriptName)); return scriptDTOs; } catch (IOException e) { throw new RepositoryException("Could not build scripts", e); } }
From source file:org.silverpeas.web.jobstartpage.control.JobStartPagePeasSessionController.java
/** * @param isNew/*from ww w . ja v a 2s.com*/ * @return */ public SpaceInst[] getBrotherSpaces(boolean isNew) { String[] sids; SpaceInst spaceint1 = getSpaceInstById(); String fatherId; String currentSpaceId; int j; if (isNew) { if (spaceint1 == null) { fatherId = null; } else { fatherId = "WA" + getManagedSpaceId(); } currentSpaceId = ""; } else { fatherId = spaceint1.getDomainFatherId(); currentSpaceId = "WA" + getManagedSpaceId(); } if (fatherId != null && !fatherId.equals("0")) { sids = adminController.getAllSubSpaceIds(fatherId); } else { sids = adminController.getAllRootSpaceIds(); } if (sids == null || sids.length <= 0) { return new SpaceInst[0]; } if (isNew) { m_BrothersSpaces = new SpaceInst[sids.length]; } else { m_BrothersSpaces = new SpaceInst[sids.length - 1]; } j = 0; for (String sid : sids) { if (isNew || !sid.equals(currentSpaceId)) { m_BrothersSpaces[j++] = adminController.getSpaceInstById(sid); } } Arrays.sort(m_BrothersSpaces, Comparator.comparing(SpaceInst::getOrderNum)); return m_BrothersSpaces; }
From source file:org.egov.pgr.service.ComplaintService.java
@ReadOnly public List<Complaint> getActedUponComplaintCount() { User user = securityUtils.getCurrentUser(); List<Complaint> complaintList = new ArrayList<>(); List<Complaint> openComplaints = complaintRepository.findByStatusNameIn(Arrays.asList(PENDING_STATUS)); List<Position> positions = positionMasterService.getPositionsForEmployee(user.getId()); openComplaints.forEach(openComplaint -> { if (!openComplaint.getStateHistory().isEmpty()) { openComplaint.getStateHistory().stream() .sorted(Comparator.comparing(StateHistory::getLastModifiedDate)).findFirst() .ifPresent(stateHistory -> { if (positions.contains(stateHistory.getOwnerPosition())) complaintList.add(openComplaint); });/*from w w w. j av a 2 s.co m*/ } }); return complaintList; }
From source file:org.cgiar.ccafs.marlo.action.annualReport.RisksAction.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 w w.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(synthesisID); 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 ToC relation is null -create it if (reportSynthesis.getReportSynthesisRisk() == null) { ReportSynthesisRisk managementRisk = new ReportSynthesisRisk(); // create one to one relation reportSynthesis.setReportSynthesisRisk(managementRisk); managementRisk.setReportSynthesis(reportSynthesis); // save the changes reportSynthesis = reportSynthesisManager.saveReportSynthesis(reportSynthesis); } } } // 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 liaison Institution too liaisonInstitutions.addAll(loggedCrp.getLiaisonInstitutions().stream() .filter(c -> c.getCrpProgram() == null && c.isActive() && c.getAcronym().equals("PMU")) .collect(Collectors.toList())); if (this.isFlagship()) { LiaisonInstitution pmuInstitution = loggedCrp.getLiaisonInstitutions().stream() .filter(c -> c.getCrpProgram() == null && c.getAcronym().equals("PMU")) .collect(Collectors.toList()).get(0); ReportSynthesis reportSynthesisDB = reportSynthesisManager.findSynthesis(phase.getId(), pmuInstitution.getId()); if (reportSynthesisDB != null) { if (reportSynthesisDB.getReportSynthesisRisk() != null) { pmuText = reportSynthesisDB.getReportSynthesisRisk().getBriefSummary(); } } } // Base Permission String params[] = { loggedCrp.getAcronym(), reportSynthesis.getId() + "" }; this.setBasePermission(this.getText(Permission.REPORT_SYNTHESIS_MANAGEMENT_RISK_BASE_PERMISSION, params)); }
From source file:org.cgiar.ccafs.marlo.action.annualReport.EfficiencyAction.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 w w. j a v a 2 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(synthesisID); 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 Efficiency relation is null -create it if (reportSynthesis.getReportSynthesisEfficiency() == null) { ReportSynthesisEfficiency efficiency = new ReportSynthesisEfficiency(); // create one to one relation reportSynthesis.setReportSynthesisEfficiency(efficiency); efficiency.setReportSynthesis(reportSynthesis); // save the changes reportSynthesis = reportSynthesisManager.saveReportSynthesis(reportSynthesis); } } } // 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 liaison Institution too liaisonInstitutions.addAll(loggedCrp.getLiaisonInstitutions().stream() .filter(c -> c.getCrpProgram() == null && c.isActive() && c.getAcronym().equals("PMU")) .collect(Collectors.toList())); if (this.isFlagship()) { LiaisonInstitution pmuInstitution = loggedCrp.getLiaisonInstitutions().stream() .filter(c -> c.getCrpProgram() == null && c.getAcronym().equals("PMU")) .collect(Collectors.toList()).get(0); ReportSynthesis reportSynthesisDB = reportSynthesisManager.findSynthesis(phase.getId(), pmuInstitution.getId()); if (reportSynthesisDB != null) { if (reportSynthesisDB.getReportSynthesisEfficiency() != null) { pmuText = reportSynthesisDB.getReportSynthesisEfficiency().getDescription(); } } } // Base Permission String params[] = { loggedCrp.getAcronym(), reportSynthesis.getId() + "" }; this.setBasePermission(this.getText(Permission.REPORT_SYNTHESIS_EFFICIENCY_BASE_PERMISSION, params)); }
From source file:org.cgiar.ccafs.marlo.action.annualReport.ManagementGovernanceAction.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 av 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) { ReportSynthesis reportSynthesisDB = reportSynthesisManager.getReportSynthesisById(synthesisID); 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 ToC relation is null -create it if (reportSynthesis.getReportSynthesisGovernance() == null) { ReportSynthesisGovernance managementGovernance = new ReportSynthesisGovernance(); // create one to one relation reportSynthesis.setReportSynthesisGovernance(managementGovernance); managementGovernance.setReportSynthesis(reportSynthesis); // save the changes reportSynthesis = reportSynthesisManager.saveReportSynthesis(reportSynthesis); } } } // 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 liaison Institution too liaisonInstitutions.addAll(loggedCrp.getLiaisonInstitutions().stream() .filter(c -> c.getCrpProgram() == null && c.isActive() && c.getAcronym().equals("PMU")) .collect(Collectors.toList())); if (this.isFlagship()) { LiaisonInstitution pmuInstitution = loggedCrp.getLiaisonInstitutions().stream() .filter(c -> c.getCrpProgram() == null && c.getAcronym().equals("PMU")) .collect(Collectors.toList()).get(0); ReportSynthesis reportSynthesisDB = reportSynthesisManager.findSynthesis(phase.getId(), pmuInstitution.getId()); if (reportSynthesisDB != null) { if (reportSynthesisDB.getReportSynthesisGovernance() != null) { pmuText = reportSynthesisDB.getReportSynthesisGovernance().getDescription(); } } } // Base Permission String params[] = { loggedCrp.getAcronym(), reportSynthesis.getId() + "" }; this.setBasePermission( this.getText(Permission.REPORT_SYNTHESIS_MANAGEMENT_GOVERNANCE_BASE_PERMISSION, params)); }