List of usage examples for java.lang Long compare
public static int compare(long x, long y)
From source file:org.cgiar.ccafs.marlo.action.summaries.ReportingSummaryAction.java
private TypedTableModel getProjectHighlightReportingTableModel() { TypedTableModel model = new TypedTableModel( new String[] { "id", "title", "author", "subject", "publisher", "year_reported", "highlights_types", "highlights_is_global", "start_date", "end_date", "keywords", "countries", "image", "highlight_desc", "introduction", "results", "partners", "links", "width", "heigth", "isGlobal", "imageurl" }, new Class[] { Long.class, String.class, String.class, String.class, String.class, Long.class, String.class, String.class, String.class, String.class, String.class, String.class, String.class, String.class, String.class, String.class, String.class, String.class, Integer.class, Integer.class, Boolean.class, String.class }, 0);/*from ww w .ja va 2s . c om*/ SimpleDateFormat formatter = new SimpleDateFormat("MMM yyyy"); for (ProjectHighlight projectHighlight : project.getProjectHighligths().stream() .sorted((h1, h2) -> Long.compare(h1.getId(), h2.getId())) .filter(ph -> ph.getProjectHighlightInfo(this.getSelectedPhase()) != null && ph.isActive() && ph.getProjectHighlightInfo().getYear() != null && ph.getProjectHighlightInfo().getYear() == this.getSelectedYear()) .collect(Collectors.toList())) { String title = null, author = null, subject = null, publisher = null, highlightsTypes = "", highlightsIsGlobal = null, startDate = null, endDate = null, keywords = null, countries = "", image = "", highlightDesc = null, introduction = null, results = null, partners = null, links = null, imageurl = null; Long yearReported = null; Boolean isGlobal = false; int width = 0; int heigth = 0; if (projectHighlight.getProjectHighlightInfo().getTitle() != null && !projectHighlight.getProjectHighlightInfo().getTitle().isEmpty()) { title = projectHighlight.getProjectHighlightInfo().getTitle(); } if (projectHighlight.getProjectHighlightInfo().getAuthor() != null && !projectHighlight.getProjectHighlightInfo().getAuthor().isEmpty()) { author = projectHighlight.getProjectHighlightInfo().getAuthor(); } if (projectHighlight.getProjectHighlightInfo().getSubject() != null && !projectHighlight.getProjectHighlightInfo().getSubject().isEmpty()) { subject = projectHighlight.getProjectHighlightInfo().getSubject(); } if (projectHighlight.getProjectHighlightInfo().getPublisher() != null && !projectHighlight.getProjectHighlightInfo().getPublisher().isEmpty()) { publisher = projectHighlight.getProjectHighlightInfo().getPublisher(); } if (projectHighlight.getProjectHighlightInfo().getYear() != null) { yearReported = projectHighlight.getProjectHighlightInfo().getYear(); } for (ProjectHighlightType projectHighlightType : projectHighlight.getProjectHighligthsTypes().stream() .filter(pht -> pht.isActive()).collect(Collectors.toList())) { if (ProjectHighligthsTypeEnum.getEnum(projectHighlightType.getIdType() + "") != null) { highlightsTypes += "<br>? " + ProjectHighligthsTypeEnum .getEnum(projectHighlightType.getIdType() + "").getDescription(); } } if (highlightsTypes.isEmpty()) { highlightsTypes = null; } if (projectHighlight.getProjectHighlightInfo().isGlobal() == true) { isGlobal = true; highlightsIsGlobal = "Yes"; } else { highlightsIsGlobal = "No"; } if (projectHighlight.getProjectHighlightInfo().getStartDate() != null) { startDate = formatter.format(projectHighlight.getProjectHighlightInfo().getStartDate()); } if (projectHighlight.getProjectHighlightInfo().getEndDate() != null) { endDate = formatter.format(projectHighlight.getProjectHighlightInfo().getEndDate()); } if (projectHighlight.getProjectHighlightInfo().getKeywords() != null && !projectHighlight.getProjectHighlightInfo().getKeywords().isEmpty()) { keywords = projectHighlight.getProjectHighlightInfo().getKeywords(); } int countriesFlag = 0; for (ProjectHighlightCountry projectHighlightCountry : projectHighlight.getProjectHighlightCountries() .stream().filter(phc -> phc.isActive()).collect(Collectors.toList())) { if (projectHighlightCountry.getLocElement() != null) { if (countriesFlag == 0) { countries += projectHighlightCountry.getLocElement().getName(); countriesFlag++; } else { countries += ", " + projectHighlightCountry.getLocElement().getName(); countriesFlag++; } } } if (countries.isEmpty()) { countries = null; } if (projectHighlight.getProjectHighlightInfo().getFile() != null) { double pageWidth = 612 * 0.4; double pageHeigth = 792 * 0.4; double imageWidth = 0; double imageHeigth = 0; image = this.getHightlightImagePath(projectHighlight.getProject().getId()) + projectHighlight.getProjectHighlightInfo().getFile().getFileName(); imageurl = this.getHighlightsImagesUrl(projectHighlight.getProject().getId().toString()) + projectHighlight.getProjectHighlightInfo().getFile().getFileName(); Image imageFile = null; LOG.info("Image name: " + image); File url; try { url = new File(image); } catch (Exception e) { LOG.warn("Failed to get image File. Url was set to null. Exception: " + e.getMessage()); url = null; image = ""; imageurl = null; } if (url != null && url.exists()) { // System.out.println("Project: " + projectHighlight.getProject().getId() + " PH: " + // projectHighlight.getId()); try { imageFile = Image.getInstance(FileManager.readURL(url)); // System.out.println("W: " + imageFile.getWidth() + " \nH: " + imageFile.getHeight()); if (imageFile.getWidth() >= imageFile.getHeight()) { imageWidth = pageWidth; imageHeigth = imageFile.getHeight() * (((pageWidth * 100) / imageFile.getWidth()) / 100); } else { imageHeigth = pageHeigth; imageWidth = imageFile.getWidth() * (((pageHeigth * 100) / imageFile.getHeight()) / 100); } // System.out.println("New W: " + imageWidth + " \nH: " + imageHeigth); width = (int) imageWidth; heigth = (int) imageHeigth; // If successful, process the message } catch (BadElementException e) { LOG.warn("BadElementException getting image: " + e.getMessage()); image = ""; } catch (MalformedURLException e) { LOG.warn("MalformedURLException getting image: " + e.getMessage()); image = ""; imageurl = null; } catch (IOException e) { LOG.warn("IOException getting image: " + e.getMessage()); image = ""; imageurl = null; } } else { image = ""; imageurl = null; } } if (projectHighlight.getProjectHighlightInfo().getDescription() != null && !projectHighlight.getProjectHighlightInfo().getDescription().isEmpty()) { highlightDesc = projectHighlight.getProjectHighlightInfo().getDescription(); } if (projectHighlight.getProjectHighlightInfo().getObjectives() != null && !projectHighlight.getProjectHighlightInfo().getObjectives().isEmpty()) { introduction = projectHighlight.getProjectHighlightInfo().getObjectives(); } if (projectHighlight.getProjectHighlightInfo().getResults() != null && !projectHighlight.getProjectHighlightInfo().getResults().isEmpty()) { results = projectHighlight.getProjectHighlightInfo().getResults(); } if (projectHighlight.getProjectHighlightInfo().getPartners() != null && !projectHighlight.getProjectHighlightInfo().getPartners().isEmpty()) { partners = projectHighlight.getProjectHighlightInfo().getPartners(); } if (projectHighlight.getProjectHighlightInfo().getLinks() != null && !projectHighlight.getProjectHighlightInfo().getLinks().isEmpty()) { links = projectHighlight.getProjectHighlightInfo().getLinks(); } model.addRow(new Object[] { projectHighlight.getId(), title, author, subject, publisher, yearReported, highlightsTypes, highlightsIsGlobal, startDate, endDate, keywords, countries, image, highlightDesc, introduction, results, partners, links, width, heigth, isGlobal, imageurl }); } return model; }
From source file:org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.java
private String getLatestParentArtifactDataIdByArtifactUUID(String artifactUUID, Wrapper<ResponseFormat> errorWrapper, String parentId, ComponentTypeEnum componentType) { String artifactId = null;/*from w w w . j ava 2s .c om*/ ActionStatus actionStatus = ActionStatus.ARTIFACT_NOT_FOUND; StorageOperationStatus storageStatus; ArtifactDefinition latestArtifact = null; List<ArtifactDefinition> artifacts = null; NodeTypeEnum parentType; if (componentType.equals(ComponentTypeEnum.RESOURCE)) { parentType = NodeTypeEnum.Resource; } else { parentType = NodeTypeEnum.Service; } Either<Map<String, ArtifactDefinition>, StorageOperationStatus> getArtifactsRes = artifactOperation .getArtifacts(parentId, parentType, false); if (getArtifactsRes.isRight()) { storageStatus = getArtifactsRes.right().value(); log.debug("Couldn't fetch artifacts data for parent component {} with uid {}, error: {}", componentType.name(), parentId, storageStatus); if (!storageStatus.equals(StorageOperationStatus.NOT_FOUND)) { actionStatus = componentsUtils.convertFromStorageResponse(storageStatus); } errorWrapper.setInnerElement(componentsUtils.getResponseFormat(actionStatus, artifactUUID)); } if (errorWrapper.isEmpty()) { artifacts = getArtifactsRes.left().value().values().stream() .filter(a -> a.getArtifactUUID() != null && a.getArtifactUUID().equals(artifactUUID)) .collect(Collectors.toList()); if (artifacts == null || artifacts.isEmpty()) { log.debug( "Couldn't fetch artifact with UUID {} data for parent component {} with uid {}, error: {}", artifactUUID, componentType.name(), parentId, actionStatus); errorWrapper.setInnerElement(componentsUtils.getResponseFormat(actionStatus, artifactUUID)); } } if (errorWrapper.isEmpty()) { latestArtifact = artifacts.stream().max((a1, a2) -> { int compareRes = Double.compare(Double.parseDouble(a1.getArtifactVersion()), Double.parseDouble(a2.getArtifactVersion())); if (compareRes == 0) { compareRes = Long.compare(a1.getLastUpdateDate() == null ? 0 : a1.getLastUpdateDate(), a2.getLastUpdateDate() == null ? 0 : a2.getLastUpdateDate()); } return compareRes; }).get(); if (latestArtifact == null) { log.debug( "Couldn't fetch latest artifact with UUID {} data for parent component {} with uid {}, error: {}", artifactUUID, componentType.name(), parentId, actionStatus); errorWrapper.setInnerElement(componentsUtils.getResponseFormat(actionStatus, artifactUUID)); } } if (errorWrapper.isEmpty()) { artifactId = latestArtifact.getUniqueId(); } return artifactId; }