Example usage for java.util Objects nonNull

List of usage examples for java.util Objects nonNull

Introduction

In this page you can find the example usage for java.util Objects nonNull.

Prototype

public static boolean nonNull(Object obj) 

Source Link

Document

Returns true if the provided reference is non- null otherwise returns false .

Usage

From source file:com.qpark.maven.plugin.flowmapper.AbstractGenerator.java

protected final void getChildrenImports(
        final List<Entry<ComplexTypeChild, List<ComplexTypeChild>>> childrenTree, final Set<String> imports,
        final Set<String> importClasses) {
    childrenTree.stream().filter(child -> !"interfaceName".equals(child.getKey().getChildName()))
            .forEach(child -> {//from w w  w .  ja  v  a  2s .c  om
                addImport(child.getKey().getComplexType().getClassNameFullQualified(), imports, importClasses);
                child.getValue().stream()
                        .filter(grandchild -> !"interfaceName".equals(grandchild.getChildName()))
                        .forEach(grandchild -> {
                            final ComplexContent cc = this.getMapperDefinition(grandchild.getComplexType());
                            if (Objects.nonNull(cc)) {
                                AbstractGenerator.addImport(cc.getFQInterfaceName(), imports, importClasses);
                            }
                            AbstractGenerator.addImport(grandchild.getComplexType().getClassNameFullQualified(),
                                    imports, importClasses);
                        });
            });
}

From source file:org.kitodo.production.plugin.importer.massimport.PicaMassImport.java

@Override
public LegacyMetsModsDigitalDocumentHelper convertData() throws ImportPluginException {

    currentIdentifier = data;//  w  w w .j a v  a 2  s  . co m

    logger.debug("retrieving pica record for {} with server address: {}", this.currentIdentifier,
            getOpacAddress());
    String search = SRUHelper.search(currentIdentifier, this.getOpacAddress());
    logger.trace(search);
    try {
        Node pica = SRUHelper.parseResult(search);
        if (pica == null) {
            String mess = "PICA record for " + currentIdentifier + " does not exist in catalogue.";
            logger.error(mess);
            throw new ImportPluginException(mess);
        }
        pica = addParentDataForVolume(pica);
        LegacyMetsModsDigitalDocumentHelper fileformat = SRUHelper.parsePicaFormat(pica, prefs);
        LegacyMetsModsDigitalDocumentHelper digitalDocument = fileformat.getDigitalDocument();
        boolean multivolue = false;
        LegacyDocStructHelperInterface logicalDS = digitalDocument.getLogicalDocStruct();
        LegacyDocStructHelperInterface child = null;
        if (logicalDS.getDocStructType().getAnchorClass() != null) {
            child = logicalDS.getAllChildren().get(0);
            multivolue = true;
        }

        readCurrentTitle(logicalDS);
        readIdentifier(child, logicalDS);
        readAuthor(logicalDS);
        readVolumeNumber(child);

        // reading ats
        LegacyMetadataTypeHelper atsType = prefs.getMetadataTypeByName("TSL_ATS");
        List<? extends LegacyMetadataHelper> mdList = logicalDS.getAllMetadataByType(atsType);
        if (Objects.nonNull(mdList) && !mdList.isEmpty()) {
            LegacyMetadataHelper atstsl = mdList.get(0);
            ats = atstsl.getValue();
        } else {
            // generating ats
            ats = createAtstsl(currentTitle, author);
            LegacyMetadataHelper atstsl = new LegacyMetadataHelper(atsType);
            atstsl.setStringValue(ats);
            logicalDS.addMetadata(atstsl);
        }

        templateProperties.add(prepareProperty("Titel", currentTitle));

        if (StringUtils.isNotBlank(volumeNumber) && multivolue) {
            templateProperties.add(prepareProperty("Bandnummer", volumeNumber));
        }

        LegacyMetadataTypeHelper identifierAnalogType = prefs.getMetadataTypeByName("CatalogIDSource");
        mdList = logicalDS.getAllMetadataByType(identifierAnalogType);
        if (Objects.nonNull(mdList) && !mdList.isEmpty()) {
            String analog = mdList.get(0).getValue();
            templateProperties.add(prepareProperty("Identifier", analog));
        }

        LegacyMetadataTypeHelper identifierType = prefs.getMetadataTypeByName("CatalogIDDigital");
        if (child != null) {
            mdList = child.getAllMetadataByType(identifierType);
            if (Objects.nonNull(mdList) && !mdList.isEmpty()) {
                LegacyMetadataHelper identifier = mdList.get(0);
                workpieceProperties.add(prepareProperty("Identifier Band", identifier.getValue()));
            }
        }

        workpieceProperties.add(prepareProperty("Artist", author));
        workpieceProperties.add(prepareProperty("ATS", ats));
        workpieceProperties.add(prepareProperty("Identifier", currentIdentifier));

        // pathimagefiles
        LegacyMetadataTypeHelper mdt = prefs.getMetadataTypeByName("pathimagefiles");
        LegacyMetadataHelper newmd = new LegacyMetadataHelper(mdt);
        newmd.setStringValue("/images/");
        digitalDocument.getPhysicalDocStruct().addMetadata(newmd);

        // collections
        if (this.currentCollectionList != null) {
            LegacyMetadataTypeHelper mdTypeCollection = this.prefs.getMetadataTypeByName("singleDigCollection");
            LegacyDocStructHelperInterface topLogicalStruct = digitalDocument.getLogicalDocStruct();
            List<LegacyDocStructHelperInterface> volumes = topLogicalStruct.getAllChildren();
            if (volumes == null) {
                volumes = Collections.emptyList();
            }
            for (String collection : this.currentCollectionList) {
                LegacyMetadataHelper mdCollection = new LegacyMetadataHelper(mdTypeCollection);
                mdCollection.setStringValue(collection);
                topLogicalStruct.addMetadata(mdCollection);
                for (LegacyDocStructHelperInterface volume : volumes) {
                    LegacyMetadataHelper mdCollectionForVolume = new LegacyMetadataHelper(mdTypeCollection);
                    mdCollectionForVolume.setStringValue(collection);
                    volume.addMetadata(mdCollectionForVolume);
                }
            }
        }

        return fileformat;
    } catch (IOException | JDOMException | ParserConfigurationException e) {
        logger.error(this.currentIdentifier + ": " + e.getMessage(), e);
        throw new ImportPluginException(e);
    }
}

From source file:org.jboss.aerogear.unifiedpush.service.impl.AliasServiceImpl.java

@Override
@Async/*from   w w w.  ja va 2  s.c om*/
public void removeAll(PushApplication pushApplication, boolean destructive, PostDelete action) {
    UUID pushApplicationId = UUID.fromString(pushApplication.getPushApplicationID());

    aliasDao.findUserIds(pushApplicationId).map(row -> aliasDao.findOne(pushApplicationId, row.getUUID(0)))
            .filter(alias -> Objects.nonNull(alias)).forEach(alias -> {

                // If not destructive, only aliases are deleted.
                if (destructive) {
                    // KC users are registered by email
                    if (StringUtils.isNotEmpty(alias.getEmail()))
                        keycloakService.delete(alias.getEmail());

                    documentService.delete(pushApplicationId, alias);
                }

                aliasDao.remove(pushApplicationId, alias.getId());
            });

    if (destructive) {
        keycloakService.removeClient(pushApplication);
    }

    action.after();
}

From source file:com.caricah.iotracah.datastore.ignitecache.internal.AbstractHandler.java

public Observable<T> getBySet(Set<K> keys) {

    return Observable.create(observer -> {

        try {//  w w  w  .  j a  v a2 s .  c  o m

            keys.forEach(

                    key -> {

                        T item = getDatastoreCache().get(key);

                        if (Objects.nonNull(item))
                            observer.onNext(item);

                    });

            observer.onCompleted();

        } catch (Exception e) {
            observer.onError(e);
        }

    });

}

From source file:org.kitodo.production.exporter.ExportXmlLog.java

private List<Element> getProcessInformation(Namespace xmlns, Process process) {
    List<Element> processElements = new ArrayList<>();

    Element processTitle = new Element("title", xmlns);
    processTitle.setText(process.getTitle());
    processElements.add(processTitle);//  w w  w .  j  a  v  a  2  s.c o m

    Element project = new Element("project", xmlns);
    project.setText(process.getProject().getTitle());
    processElements.add(project);

    Element date = new Element("time", xmlns);
    date.setAttribute("type", "creation date");
    date.setText(String.valueOf(process.getCreationDate()));
    processElements.add(date);

    Element ruleset = new Element("ruleset", xmlns);
    ruleset.setText(process.getRuleset().getFile());
    processElements.add(ruleset);

    Element comment = new Element("comment", xmlns);
    comment.setText(process.getWikiField());
    processElements.add(comment);

    StringBuilder batches = new StringBuilder();
    for (Batch batch : process.getBatches()) {
        if (Objects.nonNull(batch.getType())) {
            batches.append(ServiceManager.getBatchService().getTypeTranslated(batch));
            batches.append(": ");
        }
        if (batches.length() != 0) {
            batches.append(", ");
        }
        batches.append(ServiceManager.getBatchService().getLabel(batch));
    }
    if (batches.length() != 0) {
        Element batch = new Element("batch", xmlns);
        batch.setText(batches.toString());
        processElements.add(batch);
    }

    List<Element> processProperties = prepareProperties(process.getProperties(), xmlns);

    if (!processProperties.isEmpty()) {
        Element properties = new Element(PROPERTIES, xmlns);
        properties.addContent(processProperties);
        processElements.add(properties);
    }

    // task information
    Element tasks = getTasksElement(process.getTasks(), xmlns);
    processElements.add(tasks);

    // template information
    Element templates = new Element("originals", xmlns);
    List<Element> templateElements = new ArrayList<>();

    Element template = getTemplateElement(process, xmlns);
    templateElements.add(template);
    templates.addContent(templateElements);
    processElements.add(templates);

    // digital document information
    List<Element> docElements = new ArrayList<>();

    Element dd = new Element("digitalDocument", xmlns);
    dd.setAttribute("digitalDocumentID", String.valueOf(process.getId()));

    List<Element> docProperties = prepareProperties(process.getWorkpieces(), xmlns);

    if (!docProperties.isEmpty()) {
        Element properties = new Element(PROPERTIES, xmlns);
        properties.addContent(docProperties);
        dd.addContent(properties);
    }
    docElements.add(dd);

    Element digdoc = new Element("digitalDocuments", xmlns);
    digdoc.addContent(docElements);
    processElements.add(digdoc);

    // METS information
    Element metsElement = new Element("metsInformation", xmlns);
    List<Element> metadataElements = getMetadataElements(xmlns, process);
    metsElement.addContent(metadataElements);
    processElements.add(metsElement);

    return processElements;
}

From source file:org.kitodo.production.forms.WorkflowForm.java

/**
 * Save content of the diagram files.//from ww  w . j  a v  a  2s.  c  o m
 *
 * @return true if save, false if not
 */
private boolean saveFiles() throws IOException, WorkflowException {
    Map<String, String> requestParameterMap = FacesContext.getCurrentInstance().getExternalContext()
            .getRequestParameterMap();

    Map<String, URI> diagramsUris = getDiagramUris();

    URI svgDiagramURI = diagramsUris.get(SVG_DIAGRAM_URI);
    URI xmlDiagramURI = diagramsUris.get(XML_DIAGRAM_URI);

    xmlDiagram = requestParameterMap.get("editForm:workflowTabView:xmlDiagram");
    if (Objects.nonNull(xmlDiagram)) {
        svgDiagram = StringUtils.substringAfter(xmlDiagram, "kitodo-diagram-separator");
        xmlDiagram = StringUtils.substringBefore(xmlDiagram, "kitodo-diagram-separator");

        Reader reader = new Reader(new ByteArrayInputStream(xmlDiagram.getBytes(StandardCharsets.UTF_8)));
        reader.validateWorkflowTasks();

        Converter converter = new Converter(
                new ByteArrayInputStream(xmlDiagram.getBytes(StandardCharsets.UTF_8)));
        converter.validateWorkflowTaskList();

        saveFile(svgDiagramURI, svgDiagram);
        saveFile(xmlDiagramURI, xmlDiagram);
    }

    return fileService.fileExist(xmlDiagramURI) && fileService.fileExist(svgDiagramURI);
}

From source file:de.speexx.csv.table.app.Application.java

void exportResult(final Configuration conf, final RowReader rows) throws Exception {
    assert Objects.nonNull(rows) : "Rows are null";
    assert Objects.nonNull(conf) : "configuration is null";

    final CSVPrinter printer = createCsvPrinter(rows, conf);

    for (final Row row : rows) {
        final List<String> recordEntries = new ArrayList<>();
        for (final Entry entry : row) {
            final EntryDescriptor.Type type = entry.getDescriptor().getType();
            final TypeTransformer transformer = TypeTransformer.of(type, EntryDescriptor.Type.STRING);
            final Optional<String> opt = transformer.transform(entry.getValue());
            recordEntries.add(opt.orElseGet(() -> ""));
        }//from   w w w  .  j a v  a 2 s. c om
        printer.printRecord(recordEntries);
    }
}

From source file:org.openecomp.sdc.translator.services.heattotosca.impl.ResourceTranslationNovaServerImpl.java

private void addServerGroupHintsToPoliciesProups(TranslateTo translateTo, TranslationContext context,
        String heatFileName, ServiceTemplate serviceTemplate,
        HeatOrchestrationTemplate heatOrchestrationTemplate, Map<String, Object> schedulerHints) {
    for (Object hint : schedulerHints.values()) {
        Optional<AttachedResourceId> attachedResourceId = HeatToToscaUtil
                .extractAttachedResourceId(heatFileName, heatOrchestrationTemplate, context, hint);
        if (attachedResourceId.isPresent()) {
            AttachedResourceId serverGroupResourceId = attachedResourceId.get();
            Object serverGroupResourceToTranslate = serverGroupResourceId.getEntityId();
            if (serverGroupResourceId.isGetResource()) {
                boolean isHintOfTypeNovaServerGroup = isHintOfTypeNovaServerGroup(heatOrchestrationTemplate,
                        serverGroupResourceToTranslate);
                if (isHintOfTypeNovaServerGroup) {
                    addNovaServerToPolicyGroup(translateTo, context, heatFileName, serviceTemplate,
                            heatOrchestrationTemplate, (String) serverGroupResourceToTranslate);
                }// w ww. j  a  va 2  s. co  m
            } else if (serverGroupResourceId.isGetParam()) {
                TranslatedHeatResource translatedServerGroupResource = context.getHeatSharedResourcesByParam()
                        .get(serverGroupResourceToTranslate);
                if (Objects.nonNull(translatedServerGroupResource)
                        && !HeatToToscaUtil.isHeatFileNested(translateTo, translateTo.getHeatFileName())) {
                    serviceTemplate.getTopology_template().getGroups()
                            .get(translatedServerGroupResource.getTranslatedId()).getMembers()
                            .add(translateTo.getTranslatedId());
                }
            }
        }
    }
}

From source file:uk.co.flax.biosolr.ontology.core.ols.OLSOntologyHelper.java

@Override
public Collection<String> findLabelsForIRIs(Collection<String> iris) throws OntologyHelperException {
    Collection<String> labels;

    if (iris == null) {
        labels = Collections.emptyList();
    } else {//w  w  w.j a v  a  2 s  . c  o  m
        // Check if we have labels in the graph cache
        labels = iris.stream().filter(graphLabels::containsKey).map(graphLabels::get)
                .collect(Collectors.toList());

        if (labels.size() != iris.size()) {
            // Not everything in graph cache - do further lookups
            Collection<String> lookups = iris.stream().filter(i -> !graphLabels.containsKey(i))
                    .collect(Collectors.toList());
            checkTerms(lookups);

            labels.addAll(lookups.stream().filter(i -> Objects.nonNull(terms.get(i)))
                    .map(i -> terms.get(i).getLabel()).collect(Collectors.toList()));
        }
    }

    return labels;
}

From source file:org.kitodo.production.forms.MassImportForm.java

/**
 * Convert data.//w w w  .  j  a va  2 s  .  c  o m
 *
 * @return String
 */
public String convertData() throws IOException {
    this.processList = new ArrayList<>();
    if (StringUtils.isEmpty(currentPlugin)) {
        Helper.setErrorMessage("missingPlugin");
        return this.stayOnCurrentPage;
    }
    if (testForData()) {
        List<ImportObject> answer = new ArrayList<>();

        // found list with ids
        LegacyPrefsHelper prefs = ServiceManager.getRulesetService().getPreferences(this.template.getRuleset());
        String tempFolder = ConfigCore.getParameter(ParameterCore.DIR_TEMP);
        this.plugin.setImportFolder(tempFolder);
        this.plugin.setPrefs(prefs);
        this.plugin.setOpacCatalogue(this.getOpacCatalogue());
        this.plugin.setKitodoConfigDirectory(ConfigCore.getKitodoConfigDirectory());

        if (StringUtils.isNotEmpty(this.idList)) {
            answer = this.plugin.generateFiles(generateRecordList());
        } else if (Objects.nonNull(this.importFile)) {
            this.plugin.setFile(this.importFile);
            answer = getAnswer(this.plugin.generateRecordsFromFile());
        } else if (StringUtils.isNotEmpty(this.records)) {
            answer = getAnswer(this.plugin.splitRecords(this.records));
        } else if (!this.selectedFilenames.isEmpty()) {
            answer = getAnswer(this.plugin.generateRecordsFromFilenames(this.selectedFilenames));
        }

        iterateOverAnswer(answer);

        if (answer.size() != this.processList.size()) {
            // some error on process generation, don't go to next page
            return this.stayOnCurrentPage;
        }
    } else {
        Helper.setErrorMessage("missingData");
        return this.stayOnCurrentPage;
    }

    removeFiles();

    this.idList = null;
    this.records = "";
    return massImportThreePath;
}