List of usage examples for java.util Objects isNull
public static boolean isNull(Object obj)
From source file:org.keycloak.models.jpa.JpaRealmProvider.java
@Override public List<GroupModel> searchForGroupByName(RealmModel realm, String search, Integer first, Integer max) { TypedQuery<String> query = em.createNamedQuery("getGroupIdsByNameContaining", String.class) .setParameter("realm", realm.getId()).setParameter("search", search); if (Objects.nonNull(first) && Objects.nonNull(max)) { query = query.setFirstResult(first).setMaxResults(max); }/*w w w. j a va2 s. c o m*/ List<String> groups = query.getResultList(); if (Objects.isNull(groups)) return Collections.EMPTY_LIST; List<GroupModel> list = new ArrayList<>(); for (String id : groups) { GroupModel groupById = session.realms().getGroupById(id, realm); while (Objects.nonNull(groupById.getParentId())) { groupById = session.realms().getGroupById(groupById.getParentId(), realm); } if (!list.contains(groupById)) { list.add(groupById); } } list.sort(Comparator.comparing(GroupModel::getName)); return Collections.unmodifiableList(list); }
From source file:org.kitodo.production.forms.ProzesskopieForm.java
/** * If there is an RDF configuration (for example, from the OPAC import, or * freshly created), then supplement these. *//* www .j ava 2 s . c o m*/ private void processRdfConfiguration() { // create RDF config if there is none if (Objects.isNull(this.rdf)) { createNewFileformat(); } try { if (Objects.nonNull(this.rdf)) { insertLogicalDocStruct(); for (AdditionalField field : this.additionalFields) { if (field.isUghBinding() && field.showDependingOnDoctype()) { processAdditionalField(field); } } updateMetadata(); insertCollections(); insertImagePath(); } ServiceManager.getProcessService().readMetadataFile(this.prozessKopie); startTaskScriptThreads(); } catch (IOException e) { Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); } }
From source file:com.epam.dlab.backendapi.service.impl.SchedulerJobServiceImpl.java
private SchedulerJobDTO nullableJobDto(SchedulerJobDTO dto) { return (Objects.isNull(dto.getStartDaysRepeat()) || dto.getStartDaysRepeat().isEmpty()) && (Objects.isNull(dto.getStopDaysRepeat()) || dto.getStopDaysRepeat().isEmpty()) ? null : dto; }
From source file:org.kitodo.production.services.file.FileService.java
/** * This method is needed for migration purposes. It maps existing filePaths * to the correct URI. File.separator doesn't work because on Windows it * appends backslash to URI.// w w w .j a va 2 s . co m * * @param process * the process, the uri is needed for. * @return the URI. */ public URI getProcessBaseUriForExistingProcess(Process process) { URI processBaseUri = process.getProcessBaseUri(); if (Objects.isNull(processBaseUri) && Objects.nonNull(process.getId())) { process.setProcessBaseUri(fileManagementModule.createUriForExistingProcess(process.getId().toString())); } return process.getProcessBaseUri(); }
From source file:org.opencb.opencga.storage.core.variant.io.VariantVcfDataWriter.java
public VariantContext convertVariantToVariantContext(Variant variant, List<String> annotations) { //, StudyConfiguration final String noCallAllele = String.valueOf(VCFConstants.NO_CALL_ALLELE); VariantContextBuilder variantContextBuilder = new VariantContextBuilder(); VariantType type = variant.getType(); Pair<Integer, Integer> adjustedRange = adjustedVariantStart(variant); StudyEntry studyEntry = variant.getStudy(this.studyConfiguration.getStudyName()); String[] ori = getOri(studyEntry); List<String> originalAlleles = getOriginalAlleles(ori); List<String> allelesArray; if (originalAlleles != null) { allelesArray = originalAlleles;//w w w . j a v a 2 s . c o m } else { allelesArray = buildAlleles(variant, adjustedRange); } Set<Integer> nocallAlleles = IntStream.range(0, allelesArray.size()).boxed() .filter(i -> noCallAllele.equals(allelesArray.get(i))).collect(Collectors.toSet()); String filter = "PASS"; String prk = "PR"; String crk = "CR"; String oprk = "OPR"; //Attributes for INFO column ObjectMap attributes = new ObjectMap(); ArrayList<Genotype> genotypes = new ArrayList<>(); // Integer originalPosition = null; // List<String> originalAlleles = null; // TODO work out properly how to deal with multi allelic sites. // Integer auxOriginalPosition = getOriginalPosition(ori); // if (originalPosition != null && auxOriginalPosition != null && !originalPosition.equals(auxOriginalPosition)) { // throw new IllegalStateException("Two or more VariantSourceEntries have different origin. Unable to merge"); // } // originalPosition = auxOriginalPosition; // if (originalAlleles == null) { // originalAlleles = allelesArray; // } // //Only print those variants in which the alternate is the first alternate from the multiallelic alternatives if (originalAlleles != null && originalAlleles.size() > 2 && !"0".equals(getOriginalAlleleIndex(ori))) { logger.debug("Skip multi allelic variant! {}", variant); return null; } String sourceFilter = studyEntry.getAttribute("FILTER"); if (sourceFilter != null && !filter.equals(sourceFilter)) { filter = "."; // write PASS iff all sources agree that the filter is "PASS" or assumed if not present, otherwise write "." } if (studyEntry.getFiles() != null && studyEntry.getFiles().size() == 1) { Map<String, String> fileAttributes = studyEntry.getFiles().get(0).getAttributes(); if (fileAttributes.containsKey("PR")) { attributes.putIfNotNull(prk, DECIMAL_FORMAT_7.format(Double.valueOf(fileAttributes.get("PR")))); } if (fileAttributes.containsKey("CR")) { attributes.putIfNotNull(crk, DECIMAL_FORMAT_7.format(Double.valueOf(fileAttributes.get("CR")))); } if (fileAttributes.containsKey("OPR")) { attributes.putIfNotNull(oprk, DECIMAL_FORMAT_7.format(Double.valueOf(fileAttributes.get("OPR")))); } } String refAllele = allelesArray.get(0); for (String sampleName : this.sampleNames) { String gtStr = studyEntry.getSampleData(sampleName, "GT"); String genotypeFilter = studyEntry.getSampleData(sampleName, "FT"); if (Objects.isNull(gtStr)) { gtStr = noCallAllele; genotypeFilter = noCallAllele; } List<String> gtSplit = new ArrayList<>(Arrays.asList(gtStr.split(","))); List<String> ftSplit = new ArrayList<>( Arrays.asList((StringUtils.isBlank(genotypeFilter) ? "" : genotypeFilter).split(","))); while (gtSplit.size() > 1) { int idx = gtSplit.indexOf(noCallAllele); if (idx < 0) { idx = gtSplit.indexOf("0/0"); } if (idx < 0) { break; } gtSplit.remove(idx); ftSplit.remove(idx); } String gt = gtSplit.get(0); String ft = ftSplit.get(0); org.opencb.biodata.models.feature.Genotype genotype = new org.opencb.biodata.models.feature.Genotype(gt, refAllele, allelesArray.subList(1, allelesArray.size())); List<Allele> alleles = new ArrayList<>(); for (int gtIdx : genotype.getAllelesIdx()) { if (gtIdx < allelesArray.size() && gtIdx >= 0 && !nocallAlleles.contains(gtIdx)) { // .. AND NOT a nocall allele alleles.add(Allele.create(allelesArray.get(gtIdx), gtIdx == 0)); // allele is ref. if the alleleIndex is 0 } else { alleles.add(Allele.create(noCallAllele, false)); // genotype of a secondary alternate, or an actual missing } } if (StringUtils.isBlank(ft)) { genotypeFilter = null; } else if (StringUtils.equals("PASS", ft)) { genotypeFilter = "1"; } else { genotypeFilter = "0"; } GenotypeBuilder builder = new GenotypeBuilder().name(this.sampleNameMapping.get(sampleName)); if (studyEntry.getFormatPositions().containsKey("GT")) { builder.alleles(alleles).phased(genotype.isPhased()); } if (genotypeFilter != null) { builder.attribute("PF", genotypeFilter); } for (String id : studyEntry.getFormat()) { if (id.equals("GT") || id.equals("FT")) { continue; } String value = studyEntry.getSampleData(sampleName, id); builder.attribute(id, value); } genotypes.add(builder.make()); } addStats(studyEntry, attributes); variantContextBuilder.start(adjustedRange.getLeft()).stop(adjustedRange.getLeft() + refAllele.length() - 1) //TODO mh719: check what happens for Insertions .chr(variant.getChromosome()).filter(filter); // TODO jmmut: join attributes from different source entries? what to do on a collision? if (genotypes.isEmpty()) { variantContextBuilder.noGenotypes(); } else { variantContextBuilder.genotypes(genotypes); } if (type.equals(VariantType.NO_VARIATION) && allelesArray.get(1).isEmpty()) { variantContextBuilder.alleles(refAllele); } else { variantContextBuilder.alleles( allelesArray.stream().filter(a -> !a.equals(noCallAllele)).collect(Collectors.toList())); } // if asked variant annotations are exported if (annotations != null) { addAnnotations(variant, annotations, attributes); } variantContextBuilder.attributes(attributes); if (StringUtils.isNotEmpty(variant.getId()) && !variant.toString().equals(variant.getId())) { StringBuilder ids = new StringBuilder(); ids.append(variant.getId()); if (variant.getNames() != null) { for (String name : variant.getNames()) { ids.append(VCFConstants.ID_FIELD_SEPARATOR).append(name); } } variantContextBuilder.id(ids.toString()); } else { variantContextBuilder.id(VCFConstants.EMPTY_ID_FIELD); } return variantContextBuilder.make(); }
From source file:org.kitodo.production.services.file.FileService.java
/** * Get the URI for a process sub-location. Possible locations are listed in * ProcessSubType./* w w w . j ava 2 s . c o m*/ * * @param processId * the id of process to get the sublocation for * @param processTitle * the title of process to get the sublocation for * @param processDataDirectory * the base URI of process to get the sublocation for * @param processSubType * The subType. * @param resourceName * the name of the single object (e.g. image) if null, the root * folder of the sublocation is returned * @return The URI of the requested location */ public URI getProcessSubTypeURI(Integer processId, String processTitle, URI processDataDirectory, ProcessSubType processSubType, String resourceName) { if (Objects.isNull(processDataDirectory)) { try { Process process = ServiceManager.getProcessService().getById(processId); processDataDirectory = ServiceManager.getProcessService().getProcessDataDirectory(process); } catch (DAOException e) { processDataDirectory = URI.create(String.valueOf(processId)); } } if (Objects.isNull(resourceName)) { resourceName = ""; } return fileManagementModule.getProcessSubTypeUri(processDataDirectory, processTitle, processSubType, resourceName); }
From source file:org.kitodo.production.forms.ProzesskopieForm.java
/** * There must be at least one non-anchor level doc struct, if missing, * insert logical doc structures until you reach it. *//*from w ww.ja v a 2s .co m*/ private void insertLogicalDocStruct() { LegacyDocStructHelperInterface populizer = null; try { populizer = rdf.getDigitalDocument().getLogicalDocStruct(); if (Objects.nonNull(populizer.getAnchorClass()) && Objects.isNull(populizer.getAllChildren())) { LegacyLogicalDocStructTypeHelper docStructType = populizer.getDocStructType(); while (Objects.nonNull(docStructType.getAnchorClass())) { throw new UnsupportedOperationException("Dead code pending removal"); } } } catch (NullPointerException | IndexOutOfBoundsException e) { String name = Objects.nonNull(populizer) && Objects.nonNull(populizer.getDocStructType()) ? populizer.getDocStructType().getName() : null; Helper.setErrorMessage( "DocStrctType: " + name + " is configured as anchor but has no allowedchildtype.", logger, e); } }
From source file:org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupManager.java
private DrawableGroup popuplateIfAnalyzed(GroupKey<?> groupKey, ReGroupTask<?> task) { if (Objects.nonNull(task) && (task.isCancelled())) { /*//from ww w. j a v a 2 s . c o m * if this method call is part of a ReGroupTask and that task is * cancelled, no-op * * this allows us to stop if a regroup task has been cancelled (e.g. * the user picked a different group by attribute, while the current * task was still running) */ } else { // no task or un-cancelled task if ((groupKey.getAttribute() != DrawableAttribute.PATH) || db.isGroupAnalyzed(groupKey)) { /* * for attributes other than path we can't be sure a group is * fully analyzed because we don't know all the files that will * be a part of that group,. just show them no matter what. */ try { Set<Long> fileIDs = getFileIDsInGroup(groupKey); if (Objects.nonNull(fileIDs)) { DrawableGroup group; final boolean groupSeen = db.isGroupSeen(groupKey); synchronized (groupMap) { if (groupMap.containsKey(groupKey)) { group = groupMap.get(groupKey); group.setFiles(ObjectUtils.defaultIfNull(fileIDs, Collections.emptySet())); } else { group = new DrawableGroup(groupKey, fileIDs, groupSeen); controller.getCategoryManager().registerListener(group); group.seenProperty().addListener((o, oldSeen, newSeen) -> { Platform.runLater(() -> markGroupSeen(group, newSeen)); }); groupMap.put(groupKey, group); } } Platform.runLater(() -> { if (analyzedGroups.contains(group) == false) { analyzedGroups.add(group); if (Objects.isNull(task)) { FXCollections.sort(analyzedGroups, applySortOrder(sortOrder, sortBy)); } } markGroupSeen(group, groupSeen); }); return group; } } catch (TskCoreException ex) { LOGGER.log( Level.SEVERE, "failed to get files for group: " + groupKey.getAttribute().attrName.toString() + " = " + groupKey.getValue(), ex); //NON-NLS } } } return null; }
From source file:org.kitodo.production.services.file.FileService.java
/** * Get's the URI for a Process Sub-location. Possible Locations are listed * in ProcessSubType/*from www . ja v a2 s .com*/ * * @param process * the process to get the sublocation for. * @param processSubType * The subType. * @param resourceName * the name of the single object (e.g. image) if null, the root * folder of the sublocation is returned * @return The URI of the requested location */ public URI getProcessSubTypeURI(Process process, ProcessSubType processSubType, String resourceName) { URI processDataDirectory = ServiceManager.getProcessService().getProcessDataDirectory(process); if (Objects.isNull(resourceName)) { resourceName = ""; } return fileManagementModule.getProcessSubTypeUri(processDataDirectory, Helper.getNormalizedTitle(process.getTitle()), processSubType, resourceName); }