Skip to content

Commit

Permalink
Merged Jims PR
Browse files Browse the repository at this point in the history
  • Loading branch information
janvanmansum committed Dec 13, 2024
1 parent 4fec5ea commit 07e4d1d
Show file tree
Hide file tree
Showing 24 changed files with 1,113 additions and 579 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*/
@Entity
@Table(indexes = {@Index(columnList="datasetfieldtype_id"), @Index(columnList="displayorder")})
public class ControlledVocabularyValue implements Serializable {
public class ControlledVocabularyValue implements Serializable, Comparable<ControlledVocabularyValue> {

private static final Logger logger = Logger.getLogger(ControlledVocabularyValue.class.getCanonicalName());

Expand Down Expand Up @@ -167,7 +167,13 @@ public boolean equals(Object object) {
}
ControlledVocabularyValue other = (ControlledVocabularyValue) object;
return Objects.equals(getId(), other.getId());
}
}

@Override
public int compareTo(ControlledVocabularyValue o) {
//Display order may be better but the raw return from the db is by id, so for now we use id.
return Long.compare(this.getId(), o.getId());
}

@Override
public String toString() {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/Dataset.java
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ public void setVersions(List<DatasetVersion> versions) {
private DatasetVersion createNewDatasetVersion(Template template, FileMetadata fmVarMet) {

DatasetVersion dsv = new DatasetVersion();
DatasetVersionModifiedDate date = new DatasetVersionModifiedDate();
dsv.setModifiedDate(date);
dsv.setVersionState(DatasetVersion.VersionState.DRAFT);
dsv.setFileMetadatas(new ArrayList<>());
DatasetVersion latestVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,11 @@ public ControlledVocabAlternate save(ControlledVocabAlternate alt) {
* @return - a map of JsonObjects containing configuration information keyed by the DatasetFieldType id (Long)
*/
public Map<Long, JsonObject> getCVocConf(boolean byTermUriField){

return getCVocConf(byTermUriField, settingsService.getValueForKey(SettingsServiceBean.Key.CVocConf));
}

public Map<Long, JsonObject> getCVocConf(boolean byTermUriField, String cvocSetting) {
//ToDo - change to an API call to be able to provide feedback if the json is invalid?
String cvocSetting = settingsService.getValueForKey(SettingsServiceBean.Key.CVocConf);
if (cvocSetting == null || cvocSetting.isEmpty()) {
oldHash=null;
//Release old maps
Expand Down Expand Up @@ -356,11 +358,11 @@ public Set<Long> getCvocFieldSet() {
/**
* Adds information about the external vocabulary term being used in this DatasetField to the ExternalVocabularyValue table if it doesn't already exist.
* @param df - the primitive/parent compound field containing a newly saved value
* @param cvocEntry
*/
public void registerExternalVocabValues(DatasetField df) {
public void registerExternalVocabValues(DatasetField df, JsonObject cvocEntry) {
DatasetFieldType dft = df.getDatasetFieldType();
logger.fine("Registering for field: " + dft.getName());
JsonObject cvocEntry = getCVocConf(true).get(dft.getId());
if (dft.isPrimitive()) {
List<DatasetField> siblingsDatasetFields = new ArrayList<>();
if(dft.getParentDatasetFieldType()!=null) {
Expand Down
61 changes: 41 additions & 20 deletions src/main/java/edu/harvard/iq/dataverse/DatasetPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import edu.harvard.iq.dataverse.engine.command.impl.PublishDatasetCommand;
import edu.harvard.iq.dataverse.engine.command.impl.PublishDataverseCommand;
import edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetVersionCommand;
import edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetVersionMetadataCommand;
import edu.harvard.iq.dataverse.export.ExportService;
import edu.harvard.iq.dataverse.util.cache.CacheFactoryBean;
import io.gdcc.spi.export.ExportException;
Expand Down Expand Up @@ -101,6 +102,7 @@
import jakarta.faces.view.ViewScoped;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import jakarta.persistence.OptimisticLockException;

import org.apache.commons.lang3.StringUtils;
import org.primefaces.event.FileUploadEvent;
Expand Down Expand Up @@ -182,7 +184,7 @@ public class DatasetPage implements java.io.Serializable {

public enum EditMode {

CREATE, INFO, FILE, METADATA, LICENSE
CREATE, INFO, FILE, METADATA, LICENSE, DEFAULT
};

public enum DisplayMode {
Expand Down Expand Up @@ -2887,6 +2889,9 @@ private String releaseDataset(boolean minor) {
// the lock info system.
JsfHelper.addErrorMessage(ex.getLocalizedMessage());
}
if(ex.getCause()!=null && ex.getCause() instanceof OptimisticLockException) {
JsfHelper.addErrorMessage(BundleUtil.getStringFromBundle("dataset.message.parallelPublishError"));
}
logger.severe(ex.getMessage());
}

Expand All @@ -2896,21 +2901,6 @@ private String releaseDataset(boolean minor) {
return returnToDraftVersion();
}

@Deprecated
public String registerDataset() {
try {
UpdateDatasetVersionCommand cmd = new UpdateDatasetVersionCommand(dataset, dvRequestService.getDataverseRequest());
cmd.setValidateLenient(true);
dataset = commandEngine.submit(cmd);
} catch (CommandException ex) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN,BundleUtil.getStringFromBundle( "dataset.registration.failed"), " - " + ex.toString()));
logger.severe(ex.getMessage());
}
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, BundleUtil.getStringFromBundle("dataset.registered"), BundleUtil.getStringFromBundle("dataset.registered.msg"));
FacesContext.getCurrentInstance().addMessage(null, message);
return returnToDatasetOnly();
}

public String updateCurrentVersion() {
/*
* Note: The code here mirrors that in the
Expand Down Expand Up @@ -3918,8 +3908,10 @@ public String save() {
Map<Long, String> deleteStorageLocations = null;

try {
if (editMode == EditMode.CREATE) {
//Lock the metadataLanguage once created
EditMode currentMode = (editMode == null? EditMode.DEFAULT : editMode);
switch (currentMode) {
case CREATE:
//Lock the metadataLanguage once created
dataset.setMetadataLanguage(getEffectiveMetadataLanguage());
//ToDo - could drop use of selectedTemplate and just use the persistent dataset.getTemplate()
if ( selectedTemplate != null ) {
Expand All @@ -3932,8 +3924,9 @@ public String save() {
} else {
cmd = new CreateNewDatasetCommand(dataset, dvRequestService.getDataverseRequest());
}

} else {
break;
case METADATA:
case LICENSE:
//Precheck - also checking db copy of dataset to catch edits in progress that would cause update command transaction to fail
if (dataset.getId() != null) {
Dataset lockTest = datasetService.find(dataset.getId());
Expand All @@ -3944,6 +3937,21 @@ public String save() {
return returnToDraftVersion();
}
}

cmd = new UpdateDatasetVersionMetadataCommand(dataset, dvRequestService.getDataverseRequest(), clone );
((UpdateDatasetVersionMetadataCommand) cmd).setValidateLenient(true);
break;
default:
//Precheck - also checking db copy of dataset to catch edits in progress that would cause update command transaction to fail
if (dataset.getId() != null) {
Dataset lockTest = datasetService.find(dataset.getId());
if (dataset.isLockedFor(DatasetLock.Reason.EditInProgress) || lockTest.isLockedFor(DatasetLock.Reason.EditInProgress)) {
logger.log(Level.INFO, "Couldn''t save dataset: {0}", "It is locked."
+ "");
JH.addMessage(FacesMessage.SEVERITY_FATAL, BundleUtil.getStringFromBundle("dataset.locked.editInProgress.message"),BundleUtil.getStringFromBundle("dataset.locked.editInProgress.message.details", Arrays.asList(BrandingUtil.getSupportTeamName(null))));
return returnToDraftVersion();
}
}
if (!filesToBeDeleted.isEmpty()) {
deleteStorageLocations = datafileService.getPhysicalFilesToDelete(filesToBeDeleted);
}
Expand All @@ -3964,6 +3972,10 @@ public String save() {
Throwable cause = ex;
while (cause.getCause()!= null) {
cause = cause.getCause();
if (cause != null && cause instanceof OptimisticLockException) {
JsfHelper.addErrorMessage(BundleUtil.getStringFromBundle("dataset.message.parallelUpdateError"));
return null;
}
error.append(cause).append(" ");
error.append(cause.getMessage()).append(" ");
}
Expand All @@ -3973,6 +3985,15 @@ public String save() {
} catch (CommandException ex) {
//FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Dataset Save Failed", " - " + ex.toString()));
logger.log(Level.SEVERE, "CommandException, when attempting to update the dataset: " + ex.getMessage(), ex);
Throwable cause = ex;
while (cause.getCause()!= null) {
cause = cause.getCause();
logger.info("Cause is: " + cause.getClass().getName() + ", Message: " + cause.getMessage());
if (cause != null && cause instanceof OptimisticLockException) {
JsfHelper.addErrorMessage(BundleUtil.getStringFromBundle("dataset.message.parallelUpdateError"));
return null;
}
}
populateDatasetUpdateFailureMessage();
return returnToDraftVersion();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@ public DatasetLock addDatasetLock(Long datasetId, DatasetLock.Reason reason, Lon
// (to prevent multiple, duplicate locks on the dataset!)
DatasetLock lock = dataset.getLockFor(reason);
if (lock != null) {
return lock;
//return lock;
return null;
}

// Create new:
Expand Down
48 changes: 24 additions & 24 deletions src/main/java/edu/harvard/iq/dataverse/DatasetVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@
@ValidateVersionNote(versionNote = "versionNote", versionState = "versionState")
public class DatasetVersion implements Serializable {

public DatasetVersion() {
super();
this.modifiedDate = new DatasetVersionModifiedDate();

}

private static final Logger logger = Logger.getLogger(DatasetVersion.class.getCanonicalName());
private static final Validator validator = Validation.buildDefaultValidatorFactory().getValidator();

Expand Down Expand Up @@ -127,8 +133,17 @@ public enum VersionState {

private String UNF;

@Version
private Long version;

@OneToOne(cascade = {CascadeType.REMOVE, CascadeType.MERGE, CascadeType.PERSIST})
private DatasetVersionModifiedDate modifiedDate;

public void setModifiedDate(DatasetVersionModifiedDate modifiedDate) {
this.modifiedDate = modifiedDate;
}

public DatasetVersionModifiedDate getModifiedDate() {
return modifiedDate;
}

private Long versionNumber;
private Long minorVersionNumber;
Expand Down Expand Up @@ -163,10 +178,6 @@ public enum VersionState {
@Column( nullable=false )
private Date createTime;

@Temporal(value = TemporalType.TIMESTAMP)
@Column( nullable=false )
private Date lastUpdateTime;

@Temporal(value = TemporalType.TIMESTAMP)
private Date releaseTime;

Expand Down Expand Up @@ -231,17 +242,6 @@ public void setUNF(String UNF) {
this.UNF = UNF;
}

/**
* This is JPA's optimistic locking mechanism, and has no semantic meaning in the DV object model.
* @return the object db version
*/
public Long getVersion() {
return this.version;
}

public void setVersion(Long version) {
}

public String getDataverseSiteUrl() {
return dataverseSiteUrl;
}
Expand Down Expand Up @@ -429,25 +429,25 @@ public void setCreateTime(Date createTime) {
}

public Date getLastUpdateTime() {
return lastUpdateTime;
return modifiedDate.getLastUpdateTime();
}

public void setLastUpdateTime(Date lastUpdateTime) {
if (createTime == null) {
createTime = lastUpdateTime;
}
this.lastUpdateTime = lastUpdateTime;
modifiedDate.setLastUpdateTime(lastUpdateTime);
}

public String getVersionDate() {
if (this.lastUpdateTime == null){
if (modifiedDate.getLastUpdateTime() == null){
return null;
}
return DateUtil.formatDate(lastUpdateTime);
return DateUtil.formatDate(modifiedDate.getLastUpdateTime());
}

public String getVersionYear() {
return new SimpleDateFormat("yyyy").format(lastUpdateTime);
return new SimpleDateFormat("yyyy").format(modifiedDate.getLastUpdateTime());
}

public Date getReleaseTime() {
Expand Down Expand Up @@ -672,7 +672,7 @@ public void updateDefaultValuesFromTemplate(Template template) {

public DatasetVersion cloneDatasetVersion(){
DatasetVersion dsv = new DatasetVersion();
dsv.setVersionState(this.getPriorVersionState());
dsv.setVersionState(this.getVersionState());
dsv.setFileMetadatas(new ArrayList<>());

if (this.getUNF() != null){
Expand Down Expand Up @@ -2122,7 +2122,7 @@ public String getJsonLd() {
}

public String getLocaleLastUpdateTime() {
return DateUtil.formatDate(new Timestamp(lastUpdateTime.getTime()));
return DateUtil.formatDate(new Timestamp(modifiedDate.getLastUpdateTime().getTime()));
}

public String getExternalStatusLabel() {
Expand Down
Loading

0 comments on commit 07e4d1d

Please sign in to comment.