Skip to content

Commit

Permalink
versionState should never be null #3584
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed Feb 6, 2017
1 parent eb40c73 commit c65a0df
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
8 changes: 6 additions & 2 deletions src/main/java/edu/harvard/iq/dataverse/Dataset.java
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,14 @@ public DatasetVersion getEditVersion(Template template) {
}
}

public DatasetVersion getCreateVersion() {
/**
* @todo Investigate if this method should be deprecated in favor of
* createNewDatasetVersion.
*/
public DatasetVersion getCreateVersion() {
DatasetVersion dsv = new DatasetVersion();
dsv.setVersionState(DatasetVersion.VersionState.DRAFT);
dsv.setDataset(this);
dsv.setDataset(this);
dsv.initDefaultValues();
this.setVersions(new ArrayList());
getVersions().add(0, dsv);
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/DatasetVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ public void setVersion(Long version) {
@Column(length = VERSION_NOTE_MAX_LENGTH)
private String versionNote;

/**
* @todo versionState should never be null so when we are ready, uncomment
* the `nullable = false` below.
*/
// @Column(nullable = false)
@Enumerated(EnumType.STRING)
private VersionState versionState;

Expand Down Expand Up @@ -444,7 +449,7 @@ public void setVersionState(VersionState versionState) {
}

public boolean isReleased() {
return versionState != null && versionState.equals(VersionState.RELEASED);
return versionState.equals(VersionState.RELEASED);
}

public boolean isDraft() {
Expand Down
11 changes: 3 additions & 8 deletions src/test/java/edu/harvard/iq/dataverse/util/FileUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,11 @@ public void testIsDownloadPopupRequiredNull() {
assertEquals(false, FileUtil.isDownloadPopupRequired(null));
}

@Test
public void testIsDownloadPopupRequiredNoPopup() {
DatasetVersion dsv1 = new DatasetVersion();
assertEquals(false, FileUtil.isDownloadPopupRequired(dsv1));
}

@Test
public void testIsDownloadPopupRequiredDraft() {
DatasetVersion dsv1 = new DatasetVersion();
dsv1.setVersionState(DatasetVersion.VersionState.DRAFT);
Dataset dataset = new Dataset();
DatasetVersion dsv1 = dataset.getEditVersion();
assertEquals(DatasetVersion.VersionState.DRAFT, dsv1.getVersionState());
assertEquals(false, FileUtil.isDownloadPopupRequired(dsv1));
}

Expand Down

0 comments on commit c65a0df

Please sign in to comment.