Skip to content

Commit 59f770c

Browse files
authored
Merge pull request #1 from Toro520/fix-for-issue-9717
Fix for issue 9717
2 parents 847b732 + 28ace53 commit 59f770c

File tree

4 files changed

+77
-22
lines changed

4 files changed

+77
-22
lines changed

build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ dependencies {
147147

148148
implementation 'com.fasterxml:aalto-xml:1.3.2'
149149

150-
implementation group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: '2.7.9'
150+
implementation group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: '3.1.2'
151151

152152
implementation 'org.postgresql:postgresql:42.6.0'
153153

@@ -247,8 +247,8 @@ dependencies {
247247

248248
checkstyle 'com.puppycrawl.tools:checkstyle:10.12.4'
249249
// xjc needs the runtime as well for the ant task, otherwise it fails
250-
xjc group: 'org.glassfish.jaxb', name: 'jaxb-xjc', version: '3.0.2'
251-
xjc group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '3.0.2'
250+
xjc group: 'org.glassfish.jaxb', name: 'jaxb-xjc', version: '4.0.2'
251+
xjc group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '4.0.2'
252252

253253
rewrite(platform("org.openrewrite.recipe:rewrite-recipe-bom:2.4.0"))
254254
rewrite("org.openrewrite.recipe:rewrite-static-analysis")

settings.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ plugins {
1111
id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0"
1212
}
1313

14-
rootProject.name = "JabRef"
14+
rootProject.name = "jabRef"

src/main/java/org/jabref/model/entry/BibEntry.java

+72-17
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@
5252
/**
5353
* Represents a Bib(La)TeX entry, which can be BibTeX or BibLaTeX.
5454
* <p>
55-
* Example:
55+
* Example:
5656
*
57-
* <pre>{@code
57+
* <pre>{@code
5858
* Some commment
5959
* @misc{key,
6060
* fieldName = {fieldValue},
6161
* otherFieldName = {otherVieldValue}
6262
* }
6363
* }</pre>
64-
*
65-
* Then,
64+
* <p>
65+
* Then,
6666
* <ul>
6767
* <li>"Some comment" is the comment before the entry,</li>
6868
* <li>"misc" is the entry type</li>
@@ -157,14 +157,20 @@ public Optional<FieldChange> setMonth(Month parsedMonth) {
157157
return setField(StandardField.MONTH, parsedMonth.getJabRefFormat());
158158
}
159159

160+
/**
161+
* Retrieves the first resolved field or its alias from the provided OrFields object using Stream API.
162+
*
163+
* @param fields The OrFields object containing a list of fields to be resolved.
164+
* @param database The BibDatabase used for resolving the field or its alias.
165+
* @return An Optional containing the first resolved field or alias if present,
166+
* otherwise an empty Optional.
167+
*/
160168
public Optional<String> getResolvedFieldOrAlias(OrFields fields, BibDatabase database) {
161-
for (Field field : fields.getFields()) {
162-
Optional<String> value = getResolvedFieldOrAlias(field, database);
163-
if (value.isPresent()) {
164-
return value;
165-
}
166-
}
167-
return Optional.empty();
169+
return fields.getFields().stream()
170+
.map(field -> getResolvedFieldOrAlias(field, database))
171+
.filter(Optional::isPresent)
172+
.map(Optional::get)
173+
.findFirst();
168174
}
169175

170176
/**
@@ -478,7 +484,7 @@ public boolean hasField(Field field) {
478484

479485
/**
480486
* Internal method used to get the content of a field (or its alias)
481-
*
487+
* <p>
482488
* Used by {@link #getFieldOrAlias(Field)} and {@link #getFieldOrAliasLatexFree(Field)}
483489
*
484490
* @param field the field
@@ -711,7 +717,7 @@ public String toString() {
711717
* Author1, Author2: Title (Year)
712718
*/
713719
public String getAuthorTitleYear(int maxCharacters) {
714-
String[] s = new String[]{getField(StandardField.AUTHOR).orElse("N/A"), getField(StandardField.TITLE).orElse("N/A"),
720+
String[] s = new String[] {getField(StandardField.AUTHOR).orElse("N/A"), getField(StandardField.TITLE).orElse("N/A"),
715721
getField(StandardField.YEAR).orElse("N/A")};
716722

717723
String text = s[0] + ": \"" + s[1] + "\" (" + s[2] + ')';
@@ -907,7 +913,7 @@ public boolean equals(Object o) {
907913

908914
/**
909915
* On purpose, this hashes the "content" of the BibEntry, not the {@link #sharedBibEntryData}.
910-
*
916+
* <p>
911917
* The content is
912918
*
913919
* <ul>
@@ -928,7 +934,8 @@ public void registerListener(Object object) {
928934
public void unregisterListener(Object object) {
929935
try {
930936
this.eventBus.unregister(object);
931-
} catch (IllegalArgumentException e) {
937+
} catch (
938+
IllegalArgumentException e) {
932939
// occurs if the event source has not been registered, should not prevent shutdown
933940
LOGGER.debug("Problem unregistering", e);
934941
}
@@ -1106,7 +1113,7 @@ public Observable[] getObservables() {
11061113
* This method. adds the given path (as file) to the entry and removes the url.
11071114
*
11081115
* @param linkToDownloadedFile the link to the file, which was downloaded
1109-
* @param downloadedFile the path to be added to the entry
1116+
* @param downloadedFile the path to be added to the entry
11101117
*/
11111118
public void replaceDownloadedFile(String linkToDownloadedFile, LinkedFile downloadedFile) {
11121119
List<LinkedFile> linkedFiles = this.getFiles();
@@ -1144,7 +1151,7 @@ public void mergeWith(BibEntry other) {
11441151
* Merge this entry's fields with another BibEntry. Non-intersecting fields will be automatically merged. In cases of
11451152
* intersection, priority is given to THIS entry's field value, UNLESS specified otherwise in the arguments.
11461153
*
1147-
* @param other another BibEntry from which fields are sourced from
1154+
* @param other another BibEntry from which fields are sourced from
11481155
* @param otherPrioritizedFields collection of Fields in which 'other' has a priority into final result
11491156
*/
11501157
public void mergeWith(BibEntry other, Set<Field> otherPrioritizedFields) {
@@ -1174,4 +1181,52 @@ public boolean isEmpty() {
11741181
}
11751182
return StandardField.AUTOMATIC_FIELDS.containsAll(this.getFields());
11761183
}
1184+
1185+
public void addCrossref(BibEntry crossrefEntry) {
1186+
// Adding cross-references
1187+
this.setField(StandardField.CROSSREF, crossrefEntry.getCitationKey().toString());
1188+
// Updating Cells
1189+
updateCell();
1190+
}
1191+
1192+
public void addFileFromCrossref(LinkedFile file) {
1193+
List<LinkedFile> linkedFiles = this.getFiles();
1194+
// If the cross-referenced entry already has documentation from the cross-referenced entry, the documentation is not updated
1195+
if (!linkedFiles.stream().anyMatch(f -> f.getLink().equalsIgnoreCase(file.getLink()))) {
1196+
linkedFiles.add(file);
1197+
// Updated documents
1198+
updateFiles(linkedFiles);
1199+
}
1200+
}
1201+
1202+
public void removeCrossref() {
1203+
// Removing cross-references
1204+
// this.removeCrossrefedEntry(StandardField.ENTRYSET);
1205+
// Updating Cells
1206+
updateCell();
1207+
}
1208+
1209+
public void updateCitationKey(String newCitationKey) {
1210+
// Changing the reference key of a cross-reference entry
1211+
this.setField(InternalField.KEY_FIELD, newCitationKey);
1212+
// Updating Cells
1213+
updateCell();
1214+
}
1215+
1216+
public void removeCrossrefedEntry(BibEntry crossrefedEntry) {
1217+
// Remove cross-referenced entries
1218+
crossrefedEntry.removeCrossref();
1219+
// Updating Cells
1220+
updateCell();
1221+
}
1222+
1223+
private void updateCell() {
1224+
// Logic for updating cells
1225+
// ...
1226+
}
1227+
1228+
private void updateFiles(List<LinkedFile> linkedFiles) {
1229+
// Logic for updating documents
1230+
// ...
1231+
}
11771232
}

src/main/java/org/jabref/model/entry/BibEntryTypeBuilder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
import org.jabref.model.entry.field.OrFields;
1515
import org.jabref.model.entry.types.EntryType;
1616
import org.jabref.model.entry.types.StandardEntryType;
17-
1817
import com.google.common.collect.Streams;
1918

19+
2020
public class BibEntryTypeBuilder {
2121

2222
private EntryType type = StandardEntryType.Misc;

0 commit comments

Comments
 (0)