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:nl.knaw.huygens.alexandria.lmnl.importer.LMNLImporterInMemoryTest.java
private void assertActualMatchesExpected(Document actual, Document expected) { Limen actualLimen = actual.value();/*from w ww . j ava2s. c o m*/ List<Markup> actualMarkupList = actualLimen.markupList; List<TextNode> actualTextNodeList = actualLimen.textNodeList; Limen expectedLimen = expected.value(); List<Markup> expectedMarkupList = expectedLimen.markupList; List<TextNode> expectedTextNodeList = expectedLimen.textNodeList; assertThat(actualTextNodeList).hasSize(expectedTextNodeList.size()); for (int i = 0; i < expectedTextNodeList.size(); i++) { TextNode actualTextNode = actualTextNodeList.get(i); TextNode expectedTextNode = expectedTextNodeList.get(i); assertThat(actualTextNode).isEqualToComparingFieldByFieldRecursively(expectedTextNode); } assertThat(actualMarkupList).hasSize(expectedMarkupList.size()); for (int i = 0; i < expectedMarkupList.size(); i++) { Markup actualMarkup = actualMarkupList.get(i); Markup expectedMarkup = expectedMarkupList.get(i); assertThat(actualMarkup.getTag()).isEqualTo(expectedMarkup.getTag()); Comparator<Markup> markupComparator = Comparator.comparing(Markup::getTag); assertThat(actualMarkup).usingComparator(markupComparator).isEqualTo(expectedMarkup); } String actualLMNL = lmnlExporterInMemory.toLMNL(actual); String expectedLMNL = lmnlExporterInMemory.toLMNL(expected); LOG.info("LMNL={}", actualLMNL); assertThat(actualLMNL).isEqualTo(expectedLMNL); // assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected); }
From source file:org.cgiar.ccafs.marlo.action.powb.FinancialPlanAction.java
@Override public void prepare() throws Exception { // Get current CRP loggedCrp = (GlobalUnit) this.getSession().get(APConstants.SESSION_CRP); loggedCrp = crpManager.getGlobalUnitById(loggedCrp.getId()); // Check history version if (this.getRequest().getParameter(APConstants.TRANSACTION_ID) != null) { this.setPowbSynthesisIdHistory(); } else {/*from w ww . j a va2 s . co m*/ this.setPowbSynthesisParameters(); } // Validate draft version if (powbSynthesis != null) { Path path = this.getAutoSaveFilePath(); if (path.toFile().exists() && this.getCurrentUser().isAutoSave()) { this.readJsonAndLoadPowbSynthesis(path); } else { this.setDraft(false); this.createEmptyFinancialPlan(); powbSynthesis.setPowbFinancialPlannedBudgetList(powbSynthesis.getPowbFinancialPlannedBudget() .stream().filter(fp -> fp.isActive()).collect(Collectors.toList())); powbSynthesis.setPowbFinancialExpendituresList(powbSynthesis.getPowbFinancialExpenditures().stream() .filter(fe -> fe.isActive()).collect(Collectors.toList())); } } // Get the list of liaison institutions Flagships and PMU. liaisonInstitutions = this.getFlagships(); liaisonInstitutions.addAll(loggedCrp.getLiaisonInstitutions().stream() .filter(c -> c.getCrpProgram() == null && c.getAcronym().equals("PMU") && c.isActive()) .collect(Collectors.toList())); liaisonInstitutions.sort(Comparator.comparing(LiaisonInstitution::getAcronym)); powbExpenditureAreas = new ArrayList<>(); powbExpenditureAreas = powbExpenditureAreasManager.findAll().stream().filter(c -> c.isActive()) .collect(Collectors.toList()); if (this.isFlagship()) { PowbSynthesis powbSynthesisDB = powbSynthesisManager.findSynthesis(this.getActualPhase().getId(), liaisonInstitution.getId()); powbSynthesisID = powbSynthesisDB.getId(); } // Base Permission String params[] = { loggedCrp.getAcronym(), powbSynthesis.getId() + "" }; this.setBasePermission(this.getText(Permission.POWB_SYNTHESIS_FINANCIAL_PLAN_BASE_PERMISSION, params)); if (this.isHttpPost()) { if (powbSynthesis.getPowbFinancialPlannedBudgetList() != null) { powbSynthesis.getPowbFinancialPlannedBudgetList().clear(); } if (powbSynthesis.getPowbFinancialExpendituresList() != null) { powbSynthesis.getPowbFinancialExpendituresList().clear(); } } }
From source file:org.apache.druid.indexing.overlord.RemoteTaskRunner.java
@VisibleForTesting static void sortByInsertionTime(List<RemoteTaskRunnerWorkItem> tasks) { Collections.sort(tasks, Comparator.comparing(RemoteTaskRunnerWorkItem::getQueueInsertionTime)); }
From source file:com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient.java
/** * The role parameter is ignored for Bitbucket Server. *//* w w w . j a va 2 s . c om*/ @NonNull @Override public List<BitbucketServerRepository> getRepositories(@CheckForNull UserRoleInRepository role) throws IOException, InterruptedException { UriTemplate template = UriTemplate.fromTemplate(API_REPOSITORIES_PATH).set("owner", getUserCentricOwner()); List<BitbucketServerRepository> repositories; try { repositories = getResources(template, BitbucketServerRepositories.class); } catch (FileNotFoundException e) { return new ArrayList<>(); } repositories.sort(Comparator.comparing(BitbucketServerRepository::getRepositoryName)); return repositories; }
From source file:org.cgiar.ccafs.marlo.action.annualReport.FlagshipProgressAction.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. ja v a 2s.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.getReportSynthesisFlagshipProgress() == null) { ReportSynthesisFlagshipProgress flagshipProgress = new ReportSynthesisFlagshipProgress(); // create one to one relation reportSynthesis.setReportSynthesisFlagshipProgress(flagshipProgress); flagshipProgress.setReportSynthesis(reportSynthesis); // save the changes reportSynthesis = reportSynthesisManager.saveReportSynthesis(reportSynthesis); } if (this.isFlagship()) { // Setu up Milestones Flagship Table if (reportSynthesis.getReportSynthesisFlagshipProgress() != null) { reportSynthesis.getReportSynthesisFlagshipProgress() .setMilestones(reportSynthesis.getReportSynthesisFlagshipProgress() .getReportSynthesisFlagshipProgressMilestones().stream() .filter(c -> c.isActive() && c.getCrpMilestone() != null) .collect(Collectors.toList())); reportSynthesis.getReportSynthesisFlagshipProgress().getMilestones().sort( (p1, p2) -> p1.getCrpMilestone().getId().compareTo(p2.getCrpMilestone().getId())); } } else { reportSynthesis.getReportSynthesisFlagshipProgress() .setMilestones(reportSynthesis.getReportSynthesisFlagshipProgress() .getReportSynthesisFlagshipProgressMilestones().stream() .filter(c -> c.isActive()).collect(Collectors.toList())); } } } // Get the Outcome milestones outcomes = new ArrayList<>(); List<CrpProgramOutcome> outcomesList = new ArrayList<>(); Set<CrpProgramOutcome> outcomesSet = new HashSet<>(); for (CrpProgram crpProgram : loggedCrp.getCrpPrograms().stream().filter(c -> c.isActive()) .collect(Collectors.toList())) { outcomesList.addAll(crpProgram.getCrpProgramOutcomes().stream() .filter(c -> c.isActive() && c.getPhase().equals(this.getActualPhase()) && liaisonInstitution.getCrpProgram() != null && liaisonInstitution.getCrpProgram().getId().equals(c.getCrpProgram().getId())) .collect(Collectors.toList())); } for (CrpProgramOutcome outcome : outcomesList) { outcome.setMilestones(outcome.getCrpMilestones().stream() .filter(c -> c.isActive() && c.getYear().intValue() == this.getActualPhase().getYear()) .collect(Collectors.toList())); if (!outcome.getMilestones().isEmpty()) { outcomesSet.add(outcome); } } outcomes.addAll(outcomesSet); outcomes.sort((p1, p2) -> p1.getId().compareTo(p2.getId())); // 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.loadTablePMU(); } // 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_FLAGSHIP_PROGRESS_BASE_PERMISSION, params)); if (this.isHttpPost()) { if (reportSynthesis.getReportSynthesisFlagshipProgress().getMilestones() != null) { reportSynthesis.getReportSynthesisFlagshipProgress().getMilestones().clear(); } } }
From source file:org.apache.sysml.hops.codegen.template.PlanSelectionFuseCostBased.java
private void rSelectPlansFuseAll(CPlanMemoTable memo, Hop current, TemplateType currentType, HashSet<Long> partition) { if (isVisited(current.getHopID(), currentType) || !partition.contains(current.getHopID())) return;//w w w . j av a 2 s .co m //step 1: prune subsumed plans of same type if (memo.contains(current.getHopID())) { HashSet<MemoTableEntry> rmSet = new HashSet<MemoTableEntry>(); List<MemoTableEntry> hopP = memo.get(current.getHopID()); for (MemoTableEntry e1 : hopP) for (MemoTableEntry e2 : hopP) if (e1 != e2 && e1.subsumes(e2)) rmSet.add(e2); memo.remove(current, rmSet); } //step 2: select plan for current path MemoTableEntry best = null; if (memo.contains(current.getHopID())) { if (currentType == null) { best = memo.get(current.getHopID()).stream().filter(p -> isValid(p, current)) .min(new BasicPlanComparator()).orElse(null); } else { best = memo.get(current.getHopID()).stream() .filter(p -> p.type == currentType || p.type == TemplateType.CellTpl) .min(Comparator.comparing(p -> 7 - ((p.type == currentType) ? 4 : 0) - p.countPlanRefs())) .orElse(null); } addBestPlan(current.getHopID(), best); } //step 3: recursively process children for (int i = 0; i < current.getInput().size(); i++) { TemplateType pref = (best != null && best.isPlanRef(i)) ? best.type : null; rSelectPlansFuseAll(memo, current.getInput().get(i), pref, partition); } setVisited(current.getHopID(), currentType); }
From source file:org.cgiar.ccafs.marlo.action.powb.ExpectedCRPProgressAction.java
@Override public void prepare() throws Exception { // Get current CRP loggedCrp = (GlobalUnit) this.getSession().get(APConstants.SESSION_CRP); loggedCrp = crpManager.getGlobalUnitById(loggedCrp.getId()); try {// ww w . j a va 2s .c om 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(); } } liaisonInstitution = liaisonInstitutionManager.getLiaisonInstitutionById(liaisonInstitutionID); // 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; powbSynthesisID = powbSynthesis.getId(); } else { this.transaction = null; this.setTransaction("-1"); } } else { // Get Liaison institution ID Parameter try { powbSynthesisID = Long .parseLong(StringUtils.trim(this.getRequest().getParameter(APConstants.POWB_SYNTHESIS_ID))); powbSynthesis = powbSynthesisManager.getPowbSynthesisById(powbSynthesisID); if (!powbSynthesis.getPhase().equals(this.getActualPhase())) { powbSynthesis = powbSynthesisManager.findSynthesis(this.getActualPhase().getId(), liaisonInstitutionID); if (powbSynthesis == null) { powbSynthesis = this.createPowbSynthesis(this.getActualPhase().getId(), liaisonInstitutionID); } powbSynthesisID = powbSynthesis.getId(); } } catch (Exception e) { Phase phase = this.getActualPhase(); 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(); 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); powbSynthesis.setLiaisonInstitution(liaisonInstitution); powbSynthesisID = powbSynthesis.getId(); this.setDraft(true); reader.close(); } else { this.setDraft(false); if (this.isFlagship()) { powbSynthesis.setExpectedCrpProgresses(powbSynthesis.getPowbExpectedCrpProgresses().stream() .filter(c -> c.isActive() && c.getCrpMilestone() != null).collect(Collectors.toList())); powbSynthesis.getExpectedCrpProgresses() .sort((p1, p2) -> p1.getCrpMilestone().getId().compareTo(p2.getCrpMilestone().getId())); } else { powbSynthesis.setExpectedCrpProgresses(powbSynthesis.getPowbExpectedCrpProgresses().stream() .filter(c -> c.isActive()).collect(Collectors.toList())); } } } outcomes = new ArrayList<>(); List<CrpProgramOutcome> outcomesList = new ArrayList<>(); Set<CrpProgramOutcome> outcomesSet = new HashSet<>(); for (CrpProgram crpProgram : loggedCrp.getCrpPrograms().stream().filter(c -> c.isActive()) .collect(Collectors.toList())) { outcomesList.addAll(crpProgram.getCrpProgramOutcomes().stream() .filter(c -> c.isActive() && c.getPhase().equals(this.getActualPhase()) && liaisonInstitution.getCrpProgram() != null && liaisonInstitution.getCrpProgram().getId().equals(c.getCrpProgram().getId())) .collect(Collectors.toList())); } for (CrpProgramOutcome outcome : outcomesList) { outcome.setMilestones(outcome.getCrpMilestones().stream() .filter(c -> c.isActive() && c.getYear().intValue() == this.getActualPhase().getYear()) .collect(Collectors.toList())); if (!outcome.getMilestones().isEmpty()) { outcomesSet.add(outcome); } } outcomes.addAll(outcomesSet); outcomes.sort((p1, p2) -> p1.getId().compareTo(p2.getId())); // 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.addAll(loggedCrp.getLiaisonInstitutions().stream() .filter(c -> c.getCrpProgram() == null && c.getAcronym().equals("PMU") & c.isActive()) .collect(Collectors.toList())); liaisonInstitutions.sort(Comparator.comparing(LiaisonInstitution::getAcronym)); if (this.isPMU()) { this.loadTablePMU(); } // Base Permission String params[] = { loggedCrp.getAcronym(), powbSynthesis.getId() + "" }; this.setBasePermission(this.getText(Permission.POWB_SYNTHESIS_EXPECTED_BASE_PERMISSION, params)); if (this.isHttpPost()) { if (powbSynthesis.getExpectedCrpProgresses() != null) { powbSynthesis.setExpectedCrpProgresses(null); } } }
From source file:org.cgiar.ccafs.marlo.action.powb.EvidencesAction.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;//from www .j a v a 2s . co m 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); if (this.isFlagship()) { this.popUpProject(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); AutoSaveReader autoSaveReader = new AutoSaveReader(); powbSynthesis = (PowbSynthesis) autoSaveReader.readFromJson(jReader); powbSynthesisID = powbSynthesis.getId(); if (this.isFlagship()) { if (powbSynthesis.getPowbEvidence().getPlannedStudiesValue() != null) { String[] studyValues = powbSynthesis.getPowbEvidence().getPlannedStudiesValue().split(","); powbSynthesis.getPowbEvidence().setExpectedStudies(new ArrayList<>()); for (int i = 0; i < studyValues.length; i++) { ProjectExpectedStudy study = projectExpectedStudyManager .getProjectExpectedStudyById(Long.parseLong(studyValues[i])); powbSynthesis.getPowbEvidence().getExpectedStudies().add(study); } } } this.setDraft(true); reader.close(); } else { this.setDraft(false); // Check if ToC relation is null -create it if (powbSynthesis.getPowbEvidence() == null) { PowbEvidence evidence = new PowbEvidence(); // create one to one relation powbSynthesis.setPowbEvidence(evidence); evidence.setPowbSynthesis(powbSynthesis); // save the changes powbSynthesis = powbSynthesisManager.savePowbSynthesis(powbSynthesis); } if (this.isFlagship()) { powbSynthesis.getPowbEvidence().setExpectedStudies(new ArrayList<>()); if (powbSynthesis.getPowbEvidence().getPowbEvidencePlannedStudies() != null && !powbSynthesis.getPowbEvidence().getPowbEvidencePlannedStudies().isEmpty()) { for (PowbEvidencePlannedStudy plannedStudy : powbSynthesis.getPowbEvidence() .getPowbEvidencePlannedStudies().stream().filter(ro -> ro.isActive()) .collect(Collectors.toList())) { powbSynthesis.getPowbEvidence().getExpectedStudies() .add(plannedStudy.getProjectExpectedStudy()); } } } } } // 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.getFpPlannedList(liaisonInstitutions, phase.getId()); } liaisonInstitutions.addAll(loggedCrp.getLiaisonInstitutions().stream() .filter(c -> c.getCrpProgram() == null && c.isActive() && c.getAcronym().equals("PMU")) .collect(Collectors.toList())); // Setup Geo Scope List scopes = new HashMap<>(); List<GlobalScopeEnum> listScope = Arrays.asList(GlobalScopeEnum.values()); for (GlobalScopeEnum globalScopeEnum : listScope) { scopes.put(globalScopeEnum.getId(), globalScopeEnum.getType()); } // Setup Sub IDOS list subIdos = new HashMap<>(); for (SrfSubIdo srfSubIdo : srfSubIdoManager.findAll()) { subIdos.put(srfSubIdo.getId(), srfSubIdo.getDescription()); } // Setup SLO Indicators List targets = new HashMap<>(); for (SrfSloIndicator srfSloIndicator : srfSloIndicatorManager.findAll()) { targets.put(srfSloIndicator.getId(), srfSloIndicator.getTitle()); } // Base Permission String params[] = { loggedCrp.getAcronym(), powbSynthesis.getId() + "" }; this.setBasePermission(this.getText(Permission.POWB_SYNTHESIS_EVIDENCES_BASE_PERMISSION, params)); if (this.isHttpPost()) { if (powbSynthesis.getPowbEvidence().getPlannedStudies() != null) { powbSynthesis.getPowbEvidence().getPlannedStudies().clear(); } } }
From source file:org.silverpeas.web.jobstartpage.control.JobStartPagePeasSessionController.java
/** * ********************* Gestion des composants **************************************** *///from www.j av a2s . c o m public ComponentInst[] getBrotherComponents(boolean isNew) { ArrayList<ComponentInst> arc = getSpaceInstById().getAllComponentsInst(); if (arc == null || arc.isEmpty()) { return new ComponentInst[0]; } if (isNew) { m_BrothersComponents = new ComponentInst[arc.size()]; } else { m_BrothersComponents = new ComponentInst[arc.size() - 1]; } int j = 0; for (ComponentInst theComponent : arc) { if (isNew || !theComponent.getId().equals(getManagedInstanceId())) { m_BrothersComponents[j++] = theComponent; } } Arrays.sort(m_BrothersComponents, Comparator.comparing(ComponentInst::getOrderNum)); return m_BrothersComponents; }
From source file:org.apache.sysml.hops.codegen.template.PlanSelectionFuseCostBased.java
private static double rGetPlanCosts(CPlanMemoTable memo, Hop current, HashSet<Pair<Long, Long>> visited, HashSet<Long> partition, ArrayList<Long> M, boolean[] plan, HashMap<Long, Double> computeCosts, CostVector costsCurrent, TemplateType currentType) { //memoization per hop id and cost vector to account for redundant //computation without double counting materialized results or compute //costs of complex operation DAGs within a single fused operator Pair<Long, Long> tag = Pair.of(current.getHopID(), (costsCurrent == null) ? 0 : costsCurrent.ID); if (visited.contains(tag)) return 0; visited.add(tag);//w w w . j a v a 2 s .c om //open template if necessary, including memoization //under awareness of current plan choice MemoTableEntry best = null; boolean opened = false; if (memo.contains(current.getHopID())) { if (currentType == null) { best = memo.get(current.getHopID()).stream().filter(p -> isValid(p, current)) .filter(p -> hasNoRefToMaterialization(p, M, plan)).min(new BasicPlanComparator()) .orElse(null); opened = true; } else { best = memo.get(current.getHopID()).stream() .filter(p -> p.type == currentType || p.type == TemplateType.CellTpl) .filter(p -> hasNoRefToMaterialization(p, M, plan)) .min(Comparator.comparing(p -> 7 - ((p.type == currentType) ? 4 : 0) - p.countPlanRefs())) .orElse(null); } } //create new cost vector if opened, initialized with write costs CostVector costVect = !opened ? costsCurrent : new CostVector(Math.max(current.getDim1(), 1) * Math.max(current.getDim2(), 1)); //add compute costs of current operator to costs vector if (partition.contains(current.getHopID())) costVect.computeCosts += computeCosts.get(current.getHopID()); //process children recursively double costs = 0; for (int i = 0; i < current.getInput().size(); i++) { Hop c = current.getInput().get(i); if (best != null && best.isPlanRef(i)) costs += rGetPlanCosts(memo, c, visited, partition, M, plan, computeCosts, costVect, best.type); else if (best != null && isImplicitlyFused(current, i, best.type)) costVect.addInputSize(c.getInput().get(0).getHopID(), Math.max(c.getDim1(), 1) * Math.max(c.getDim2(), 1)); else { //include children and I/O costs costs += rGetPlanCosts(memo, c, visited, partition, M, plan, computeCosts, null, null); if (costVect != null && c.getDataType().isMatrix()) costVect.addInputSize(c.getHopID(), Math.max(c.getDim1(), 1) * Math.max(c.getDim2(), 1)); } } //add costs for opened fused operator if (partition.contains(current.getHopID())) { if (opened) { if (LOG.isTraceEnabled()) LOG.trace("Cost vector for fused operator (hop " + current.getHopID() + "): " + costVect); costs += costVect.outSize * 8 / WRITE_BANDWIDTH; //time for output write costs += Math.max(costVect.computeCosts * costVect.getMaxInputSize() / COMPUTE_BANDWIDTH, costVect.getSumInputSizes() * 8 / READ_BANDWIDTH); } //add costs for non-partition read in the middle of fused operator else if (hasNonPartitionConsumer(current, partition)) { costs += rGetPlanCosts(memo, current, visited, partition, M, plan, computeCosts, null, null); } } //sanity check non-negative costs if (costs < 0 || Double.isNaN(costs) || Double.isInfinite(costs)) throw new RuntimeException("Wrong cost estimate: " + costs); return costs; }