Skip to content

Commit

Permalink
get rid of unneeded null checks #10517
Browse files Browse the repository at this point in the history
These days the field is non-null able and we prevent deletion
of the default dataset type.
  • Loading branch information
pdurbin committed Aug 13, 2024
1 parent eb20155 commit 1a834de
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,6 @@ public Dataset execute(CommandContext ctxt) throws CommandException {
handlePid(theDataset, ctxt);

DatasetType defaultDatasetType = ctxt.datasetTypes().getByName(DatasetType.DEFAULT_DATASET_TYPE);
if (defaultDatasetType == null) {
throw new CommandException("Couldn't find default dataset type: " + DatasetType.DEFAULT_DATASET_TYPE, this);
}
DatasetType existingDatasetType = theDataset.getDatasetType();
logger.fine("existing dataset type: " + existingDatasetType);
if (existingDatasetType != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1004,9 +1004,7 @@ public SolrInputDocuments toSolrDocs(IndexableDataset indexableDataset, Set<Long
}

DatasetType datasetType = dataset.getDatasetType();
if (datasetType != null) {
solrInputDocument.addField(SearchFields.DATASET_TYPE, datasetType.getName());
}
solrInputDocument.addField(SearchFields.DATASET_TYPE, datasetType.getName());

DatasetVersion datasetVersion = indexableDataset.getDatasetVersion();
String parentDatasetTitle = "TBD";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,9 +643,7 @@ public SolrQueryResponse search(
if (authors != null) {
solrSearchResult.setDatasetAuthors(authors);
}
if (datasetType != null) {
solrSearchResult.setDatasetType(datasetType);
}
solrSearchResult.setDatasetType(datasetType);
} else if (type.equals("files")) {
String parentGlobalId = null;
Object parentGlobalIdObject = solrDocument.getFieldValue(SearchFields.PARENT_IDENTIFIER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ public static Dataset updateDatasetMDFromJsonLD(Dataset ds, String jsonLDBody,
String datasetTypeIn = jsonObject.getString("datasetType", null);
logger.fine("datasetTypeIn: " + datasetTypeIn);
DatasetType defaultDatasetType = datasetTypeSvc.getByName(DatasetType.DEFAULT_DATASET_TYPE);
if (defaultDatasetType == null) {
throw new RuntimeException("Couldn't find default dataset type: " + DatasetType.DEFAULT_DATASET_TYPE);
}
if (datasetTypeIn == null) {
ds.setDatasetType(defaultDatasetType);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,6 @@ public Dataset parseDataset(JsonObject obj) throws JsonParseException {
throw new JsonParseException("Specified metadatalanguage not allowed.");
}
DatasetType defaultDatasetType = datasetTypeService.getByName(DatasetType.DEFAULT_DATASET_TYPE);
if (defaultDatasetType == null) {
throw new JsonParseException("Couldn't find default dataset type: " + DatasetType.DEFAULT_DATASET_TYPE);
}
String datasetTypeIn = obj.getString("datasetType", null);
logger.fine("datasetTypeIn: " + datasetTypeIn);
if (datasetTypeIn == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,7 @@ public static JsonObjectBuilder json(Dataset ds, Boolean returnOwners) {
if (returnOwners){
bld.add("isPartOf", getOwnersFromDvObject(ds));
}
DatasetType datasetType = ds.getDatasetType();
if (datasetType != null) {
bld.add("datasetType", datasetType.getName());
}
bld.add("datasetType", ds.getDatasetType().getName());
return bld;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import edu.harvard.iq.dataverse.*;
import edu.harvard.iq.dataverse.Dataverse.DataverseType;
import edu.harvard.iq.dataverse.branding.BrandingUtil;
import edu.harvard.iq.dataverse.dataset.DatasetType;
import edu.harvard.iq.dataverse.mocks.MocksFactory;
import edu.harvard.iq.dataverse.pidproviders.doi.AbstractDOIProvider;
import edu.harvard.iq.dataverse.settings.JvmSettings;
Expand Down Expand Up @@ -142,6 +143,9 @@ private IndexableDataset createIndexableDataset() {
datasetVersion.getDatasetFields().add(field);
final IndexableDataset indexableDataset = new IndexableDataset(datasetVersion);
indexableDataset.getDatasetVersion().getDataset().setOwner(dataverse);
DatasetType datasetType = new DatasetType();
datasetType.setName(DatasetType.DEFAULT_DATASET_TYPE);
indexableDataset.getDatasetVersion().getDataset().setDatasetType(datasetType);
return indexableDataset;
}

Expand Down

0 comments on commit 1a834de

Please sign in to comment.