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:org.kitodo.production.helper.tasks.CreateNewspaperProcessesTask.java

/**
 * Creates a logical structure tree in the process under creation. In the
 * tree, all issues will have been created. Presumption is that never issues
 * for more than one year will be added to the same process.
 *
 * @param newProcess/*w  w  w  .  j ava 2  s .co m*/
 *            process under creation
 * @param issues
 *            issues to add
 * @param publicationRun
 *            verbal description of the course of appearance
 */
private void createLogicalStructure(ProzesskopieForm newProcess, List<IndividualIssue> issues,
        String publicationRun) {

    // initialise
    LegacyPrefsHelper ruleset = ServiceManager.getRulesetService()
            .getPreferences(newProcess.getProzessKopie().getRuleset());
    LegacyMetsModsDigitalDocumentHelper document;
    document = newProcess.getFileformat().getDigitalDocument();
    LegacyDocStructHelperInterface newspaper = document.getLogicalDocStruct();

    // try to add the publication run
    addMetadatum(newspaper, "PublicationRun", publicationRun, false);

    // create the year level
    LegacyDocStructHelperInterface year = createFirstChild(newspaper, document, ruleset);
    String theYear = Integer.toString(issues.get(0).getDate().getYear());
    addMetadatum(year, LegacyMetsModsDigitalDocumentHelper.CREATE_LABEL_ATTRIBUTE_TYPE, theYear, true);

    // create the month level
    Map<Integer, LegacyDocStructHelperInterface> months = new HashMap<>();
    Map<LocalDate, LegacyDocStructHelperInterface> days = new HashMap<>(488);
    for (IndividualIssue individualIssue : issues) {
        LocalDate date = individualIssue.getDate();
        Integer monthNo = date.getMonthOfYear();
        if (!months.containsKey(monthNo)) {
            LegacyDocStructHelperInterface newMonth = createFirstChild(year, document, ruleset);
            addMetadatum(newMonth, LegacyMetsModsDigitalDocumentHelper.CREATE_ORDERLABEL_ATTRIBUTE_TYPE,
                    monthNo.toString(), true);
            addMetadatum(newMonth, year.getDocStructType().getName(), theYear, false);
            addMetadatum(newMonth, LegacyMetsModsDigitalDocumentHelper.CREATE_LABEL_ATTRIBUTE_TYPE,
                    monthNo.toString(), false);
            months.put(monthNo, newMonth);
        }
        LegacyDocStructHelperInterface month = months.get(monthNo);

        // create the day level
        if (!days.containsKey(date)) {
            LegacyDocStructHelperInterface newDay = createFirstChild(month, document, ruleset);
            addMetadatum(newDay, LegacyMetsModsDigitalDocumentHelper.CREATE_ORDERLABEL_ATTRIBUTE_TYPE,
                    Integer.toString(date.getDayOfMonth()), true);
            addMetadatum(newDay, year.getDocStructType().getName(), theYear, false);
            addMetadatum(newDay, month.getDocStructType().getName(), Integer.toString(date.getMonthOfYear()),
                    false);
            addMetadatum(newDay, LegacyMetsModsDigitalDocumentHelper.CREATE_LABEL_ATTRIBUTE_TYPE,
                    Integer.toString(date.getDayOfMonth()), false);
            days.put(date, newDay);
        }
        LegacyDocStructHelperInterface day = days.get(date);

        // create the issue
        LegacyDocStructHelperInterface issue = createFirstChild(day, document, ruleset);
        String heading = individualIssue.getHeading();
        if (Objects.nonNull(heading) && !heading.trim().isEmpty()) {
            addMetadatum(issue, issue.getDocStructType().getName(), heading, true);
        }
        addMetadatum(issue, year.getDocStructType().getName(), theYear, false);
        addMetadatum(issue, month.getDocStructType().getName(), Integer.toString(date.getMonthOfYear()), false);
        addMetadatum(issue, day.getDocStructType().getName(), Integer.toString(date.getDayOfMonth()), false);
        addMetadatum(issue, LegacyMetsModsDigitalDocumentHelper.CREATE_LABEL_ATTRIBUTE_TYPE, heading, false);
    }
}

From source file:org.kitodo.production.forms.dataeditor.StructurePanel.java

void updateLogicalNodeSelection(GalleryMediaContent galleryMediaContent) {
    if (Objects.nonNull(previouslySelectedLogicalNode)) {
        previouslySelectedLogicalNode.setSelected(false);
    }/*w w w  .  j a  v  a  2 s  . c  o m*/
    if (Objects.nonNull(selectedLogicalNode)) {
        selectedLogicalNode.setSelected(false);
    }
    if (Objects.nonNull(logicalTree)) {
        GalleryStripe matchingGalleryStripe = this.dataEditor.getGalleryPanel()
                .getLogicalStructureOfMedia(galleryMediaContent);
        if (Objects.nonNull(matchingGalleryStripe) && Objects.nonNull(matchingGalleryStripe.getStructure())) {
            if (this.separateMedia) {
                TreeNode selectedLogicalTreeNode = updateLogicalNodeSelectionRecursive(
                        matchingGalleryStripe.getStructure(), logicalTree);
                if (Objects.nonNull(selectedLogicalTreeNode)) {
                    setSelectedLogicalNode(selectedLogicalTreeNode);
                } else {
                    Helper.setErrorMessage("Unable to update node selection in logical structure!");
                }
            } else {
                TreeNode selectedTreeNode = updateNodeSelectionRecursive(galleryMediaContent, logicalTree);
                if (Objects.nonNull(selectedTreeNode)) {
                    setSelectedLogicalNode(selectedTreeNode);
                } else {
                    Helper.setErrorMessage("Unable to update node selection in logical structure!");
                }
            }
        }
    }
}

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

/**
 * die Eingabefelder fr die Eigenschaften mit Inhalten aus der RDF-Datei
 * fllen./*ww  w  . j a  va  2  s .c  om*/
 */
private void fillFieldsFromMetadataFile() {
    if (Objects.nonNull(this.rdf)) {
        for (AdditionalField field : this.additionalFields) {
            if (field.isUghBinding() && field.showDependingOnDoctype()) {
                proceedField(field);
                String value = field.getValue();
                if (Objects.nonNull(value) && !value.isEmpty()) {
                    field.setValue(value.replace("&amp;", "&"));
                }
            }
        }
    }
}

From source file:org.kitodo.production.services.data.TaskService.java

/**
 * Get title with user./* w w  w .j  a va 2s  . co m*/
 *
 * @return des Schritttitels sowie (sofern vorhanden) den Benutzer mit
 *         vollstndigem Namen
 */
public String getTitleWithUserName(Task task) {
    String result = task.getTitle();
    User user = task.getProcessingUser();
    if (Objects.nonNull(user) && Objects.nonNull(user.getId())) {
        result += " (" + ServiceManager.getUserService().getFullName(user) + ")";
    }
    return result;
}

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

private List<Element> getMetadataElements(Namespace xmlns, Process process) {
    List<Element> metadataElements = new ArrayList<>();
    try {/*from  w  w  w  .java  2s .co m*/
        URI metadataFilePath = ServiceManager.getFileService().getMetadataFilePath(process);
        Document metsDoc = new SAXBuilder()
                .build(ServiceManager.getFileService().getFile(metadataFilePath).toString());
        Document anchorDoc = null;
        URI anchorFileName = URI.create(ServiceManager.getFileService().getMetadataFilePath(process).toString()
                .replace("meta.xml", "meta_anchor.xml"));
        if (ServiceManager.getFileService().fileExist(anchorFileName)
                && ServiceManager.getFileService().canRead(anchorFileName)) {
            anchorDoc = new SAXBuilder()
                    .build(ServiceManager.getFileService().getFile(metadataFilePath).toString());
        }
        HashMap<String, Namespace> namespaces = new HashMap<>();

        HashMap<String, String> names = getNamespacesFromConfig();
        for (Map.Entry<String, String> entry : names.entrySet()) {
            String key = entry.getKey();
            namespaces.put(key, Namespace.getNamespace(key, entry.getValue()));
        }

        HashMap<String, String> fields = getMetsFieldsFromConfig(false);
        prepareMetadataElements(metadataElements, fields, metsDoc, namespaces, xmlns);

        if (Objects.nonNull(anchorDoc)) {
            fields = getMetsFieldsFromConfig(true);
            prepareMetadataElements(metadataElements, fields, anchorDoc, namespaces, xmlns);
        }
    } catch (IOException | JDOMException | JaxenException e) {
        logger.error(e.getMessage(), e);
    }
    return metadataElements;
}

From source file:org.kitodo.production.services.data.ProcessService.java

/**
 * Add process to project, if project is assigned to process.
 *
 * @param process/*from w w w.  j a v a 2 s  .  c  om*/
 *            object
 */
private void manageProjectDependenciesForIndex(Process process)
        throws CustomResponseException, DataException, IOException {
    if (Objects.nonNull(process.getProject())) {
        ServiceManager.getProjectService().saveToIndex(process.getProject(), false);
    }
}

From source file:org.kitodo.production.services.data.TaskService.java

/**
 * Get script path.//  ww  w. j  ava2s  .c  om
 *
 * @param task
 *            object
 * @return script path as String
 */
public String getScriptPath(Task task) {
    if (Objects.nonNull(task.getScriptPath()) && !task.getScriptPath().isEmpty()) {
        return task.getScriptPath();
    }
    return "";
}

From source file:com.mac.holdempoker.app.impl.util.HandMatrix.java

private Rank getNextHighestRank(Rank rank) {
    Rank nextHighestRank = null;/*from w w  w . j av a2s  .  c  o m*/
    Set<Rank> keys = rankHistogram.keySet();
    Rank[] ranks = keys.toArray(new Rank[keys.size()]);
    ArrayUtils.reverse(ranks);

    for (Rank r : ranks) {
        Integer val = rankHistogram.get(r);
        if (Objects.nonNull(val)) {
            if (val >= 1) {
                if (Objects.isNull(nextHighestRank)) {
                    nextHighestRank = r;
                } else {
                    if (r.value() < rank.value()) {
                        return r;
                    }
                }
            }
        }
    }
    return nextHighestRank;
}

From source file:org.kitodo.production.forms.dataeditor.FieldedMetadataTableRow.java

/**
 * Reads the contents of the meta-data panel and stores the values in the
 * appropriate place. If the line is used to edit a field of the METS
 * structure, this field is set, otherwise the meta-data will be stored in
 * the list. The hidden meta-data is also written back there again.
 *
 * @throws InvalidMetadataValueException
 *             if the content of a meta-data input field is syntactically
 *             wrong/*w  w w. j  a  va 2s . c  o  m*/
 * @throws NoSuchMetadataFieldException
 *             if an input shall be saved to a field of the structure, but
 *             there is no setter corresponding to the name configured in
 *             the rule set
 */
void preserve() throws InvalidMetadataValueException, NoSuchMetadataFieldException {
    try {
        metadata.clear();
        for (MetadataTableRow row : rows) {
            Pair<Method, Object> metsFieldValue = row.getStructureFieldValue();
            if (Objects.nonNull(metsFieldValue)) {
                try {
                    metsFieldValue.getKey().invoke(structure, metsFieldValue.getValue());
                } catch (IllegalAccessException | InvocationTargetException e) {
                    throw new IllegalStateException(e);
                }
            } else {
                metadata.addAll(row.getMetadata());
            }
        }
        metadata.addAll(hiddenMetadata);
    } catch (InvalidMetadataValueException invalidValueException) {
        if (Objects.isNull(structure)) {
            invalidValueException.addParent(metadataView.getId());
        }
        throw invalidValueException;
    }
}

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

private void proceedField(AdditionalField field) {
    LegacyDocStructHelperInterface docStruct = getDocStruct(field);
    try {//from w  w  w . jav a 2 s .c om
        if (field.getMetadata().equals(LIST_OF_CREATORS)) {
            throw new UnsupportedOperationException("Dead code pending removal");
        } else {
            // evaluate the content in normal fields
            LegacyMetadataTypeHelper mdt = LegacyPrefsHelper.getMetadataType(
                    ServiceManager.getRulesetService().getPreferences(this.prozessKopie.getRuleset()),
                    field.getMetadata());
            LegacyMetadataHelper md = LegacyLogicalDocStructHelper.getMetadata(docStruct, mdt);
            if (Objects.nonNull(md)) {
                field.setValue(md.getValue());
                md.setStringValue(field.getValue().replace("&amp;", "&"));
            }
        }
    } catch (IllegalArgumentException e) {
        Helper.setErrorMessage(e.getLocalizedMessage(), logger, e);
    }
}