Skip to content

Commit 1a834de

Browse files
committed
get rid of unneeded null checks #10517
These days the field is non-null able and we prevent deletion of the default dataset type.
1 parent eb20155 commit 1a834de

File tree

7 files changed

+7
-19
lines changed

7 files changed

+7
-19
lines changed

src/main/java/edu/harvard/iq/dataverse/engine/command/impl/AbstractCreateDatasetCommand.java

-3
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,6 @@ public Dataset execute(CommandContext ctxt) throws CommandException {
122122
handlePid(theDataset, ctxt);
123123

124124
DatasetType defaultDatasetType = ctxt.datasetTypes().getByName(DatasetType.DEFAULT_DATASET_TYPE);
125-
if (defaultDatasetType == null) {
126-
throw new CommandException("Couldn't find default dataset type: " + DatasetType.DEFAULT_DATASET_TYPE, this);
127-
}
128125
DatasetType existingDatasetType = theDataset.getDatasetType();
129126
logger.fine("existing dataset type: " + existingDatasetType);
130127
if (existingDatasetType != null) {

src/main/java/edu/harvard/iq/dataverse/search/IndexServiceBean.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -1004,9 +1004,7 @@ public SolrInputDocuments toSolrDocs(IndexableDataset indexableDataset, Set<Long
10041004
}
10051005

10061006
DatasetType datasetType = dataset.getDatasetType();
1007-
if (datasetType != null) {
1008-
solrInputDocument.addField(SearchFields.DATASET_TYPE, datasetType.getName());
1009-
}
1007+
solrInputDocument.addField(SearchFields.DATASET_TYPE, datasetType.getName());
10101008

10111009
DatasetVersion datasetVersion = indexableDataset.getDatasetVersion();
10121010
String parentDatasetTitle = "TBD";

src/main/java/edu/harvard/iq/dataverse/search/SearchServiceBean.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -643,9 +643,7 @@ public SolrQueryResponse search(
643643
if (authors != null) {
644644
solrSearchResult.setDatasetAuthors(authors);
645645
}
646-
if (datasetType != null) {
647-
solrSearchResult.setDatasetType(datasetType);
648-
}
646+
solrSearchResult.setDatasetType(datasetType);
649647
} else if (type.equals("files")) {
650648
String parentGlobalId = null;
651649
Object parentGlobalIdObject = solrDocument.getFieldValue(SearchFields.PARENT_IDENTIFIER);

src/main/java/edu/harvard/iq/dataverse/util/json/JSONLDUtil.java

-3
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,6 @@ public static Dataset updateDatasetMDFromJsonLD(Dataset ds, String jsonLDBody,
104104
String datasetTypeIn = jsonObject.getString("datasetType", null);
105105
logger.fine("datasetTypeIn: " + datasetTypeIn);
106106
DatasetType defaultDatasetType = datasetTypeSvc.getByName(DatasetType.DEFAULT_DATASET_TYPE);
107-
if (defaultDatasetType == null) {
108-
throw new RuntimeException("Couldn't find default dataset type: " + DatasetType.DEFAULT_DATASET_TYPE);
109-
}
110107
if (datasetTypeIn == null) {
111108
ds.setDatasetType(defaultDatasetType);
112109
} else {

src/main/java/edu/harvard/iq/dataverse/util/json/JsonParser.java

-3
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,6 @@ public Dataset parseDataset(JsonObject obj) throws JsonParseException {
333333
throw new JsonParseException("Specified metadatalanguage not allowed.");
334334
}
335335
DatasetType defaultDatasetType = datasetTypeService.getByName(DatasetType.DEFAULT_DATASET_TYPE);
336-
if (defaultDatasetType == null) {
337-
throw new JsonParseException("Couldn't find default dataset type: " + DatasetType.DEFAULT_DATASET_TYPE);
338-
}
339336
String datasetTypeIn = obj.getString("datasetType", null);
340337
logger.fine("datasetTypeIn: " + datasetTypeIn);
341338
if (datasetTypeIn == null) {

src/main/java/edu/harvard/iq/dataverse/util/json/JsonPrinter.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -406,10 +406,7 @@ public static JsonObjectBuilder json(Dataset ds, Boolean returnOwners) {
406406
if (returnOwners){
407407
bld.add("isPartOf", getOwnersFromDvObject(ds));
408408
}
409-
DatasetType datasetType = ds.getDatasetType();
410-
if (datasetType != null) {
411-
bld.add("datasetType", datasetType.getName());
412-
}
409+
bld.add("datasetType", ds.getDatasetType().getName());
413410
return bld;
414411
}
415412

src/test/java/edu/harvard/iq/dataverse/search/IndexServiceBeanTest.java

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import edu.harvard.iq.dataverse.*;
44
import edu.harvard.iq.dataverse.Dataverse.DataverseType;
55
import edu.harvard.iq.dataverse.branding.BrandingUtil;
6+
import edu.harvard.iq.dataverse.dataset.DatasetType;
67
import edu.harvard.iq.dataverse.mocks.MocksFactory;
78
import edu.harvard.iq.dataverse.pidproviders.doi.AbstractDOIProvider;
89
import edu.harvard.iq.dataverse.settings.JvmSettings;
@@ -142,6 +143,9 @@ private IndexableDataset createIndexableDataset() {
142143
datasetVersion.getDatasetFields().add(field);
143144
final IndexableDataset indexableDataset = new IndexableDataset(datasetVersion);
144145
indexableDataset.getDatasetVersion().getDataset().setOwner(dataverse);
146+
DatasetType datasetType = new DatasetType();
147+
datasetType.setName(DatasetType.DEFAULT_DATASET_TYPE);
148+
indexableDataset.getDatasetVersion().getDataset().setDatasetType(datasetType);
145149
return indexableDataset;
146150
}
147151

0 commit comments

Comments
 (0)