Skip to content

Commit

Permalink
this is a working, but still work-in-progress state of things - needs…
Browse files Browse the repository at this point in the history
… some cleanup and refinements. #10623
  • Loading branch information
landreev committed Aug 17, 2024
1 parent 35ce7ef commit d4b9bac
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 120 deletions.
11 changes: 10 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/DatasetServiceBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -412,12 +412,20 @@ public boolean checkDatasetLock(Long datasetId) {
List<DatasetLock> lock = lockCounter.getResultList();
return lock.size()>0;
}


public List<DatasetLock> getLocksByDatasetId(Long datasetId) {
TypedQuery<DatasetLock> locksQuery = em.createNamedQuery("DatasetLock.getLocksByDatasetId", DatasetLock.class);
locksQuery.setParameter("datasetId", datasetId);
return locksQuery.getResultList();
}

public List<DatasetLock> getDatasetLocksByUser( AuthenticatedUser user) {

return listLocks(null, user);
}

// @todo: we'll be better off getting rid of this method and using the other
// version of addDatasetLock() (that uses datasetId instead of Dataset).
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public DatasetLock addDatasetLock(Dataset dataset, DatasetLock lock) {
lock.setDataset(dataset);
Expand Down Expand Up @@ -467,6 +475,7 @@ public DatasetLock addDatasetLock(Long datasetId, DatasetLock.Reason reason, Lon
* is {@code aReason}.
* @param dataset the dataset whose locks (for {@code aReason}) will be removed.
* @param aReason The reason of the locks that will be removed.
* @todo this should probably take dataset_id, not a dataset
*/
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void removeDatasetLocks(Dataset dataset, DatasetLock.Reason aReason) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/api/Datasets.java
Original file line number Diff line number Diff line change
Expand Up @@ -4035,6 +4035,8 @@ public Response addGlobusFilesToDataset(@Context ContainerRequestContext crc,
return wr.getResponse();
}

// @todo check if the dataset is already locked!

JsonObject jsonObject = null;
try {
jsonObject = JsonUtil.getJsonObject(jsonData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2139,9 +2139,9 @@ public Response addFiles(String jsonData, Dataset dataset, User authUser) {
logger.log(Level.WARNING, "Dataset not locked for EditInProgress ");
} else {
datasetService.removeDatasetLocks(dataset, DatasetLock.Reason.EditInProgress);
logger.log(Level.INFO, "Removed EditInProgress lock ");
logger.log(Level.INFO, "Removed EditInProgress lock "+eipLock.getId());
}

try {
Command<Dataset> cmd = new UpdateDatasetVersionCommand(dataset, dvRequest, clone);
((UpdateDatasetVersionCommand) cmd).setValidateLenient(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import edu.harvard.iq.dataverse.engine.command.RequiredPermissions;
import edu.harvard.iq.dataverse.engine.command.exception.CommandException;
import edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException;
import edu.harvard.iq.dataverse.util.BundleUtil;
import edu.harvard.iq.dataverse.util.DatasetFieldUtil;
import edu.harvard.iq.dataverse.util.FileMetadataUtil;

Expand Down Expand Up @@ -102,7 +103,10 @@ public Dataset execute(CommandContext ctxt) throws CommandException {
}

Dataset theDataset = getDataset();
ctxt.permissions().checkUpdateDatasetVersionLock(theDataset, getRequest(), this);
//ctxt.permissions().checkUpdateDatasetVersionLock(theDataset, getRequest(), this);
// this is an experiment (probably temporary)
checkUpdateDatasetVersionLock(ctxt);

Dataset savedDataset = null;

DatasetVersion persistedVersion = clone;
Expand Down Expand Up @@ -297,5 +301,23 @@ public boolean onSuccess(CommandContext ctxt, Object r) {
ctxt.index().asyncIndexDataset((Dataset) r, true);
return true;
}


private void checkUpdateDatasetVersionLock(CommandContext ctxt) throws IllegalCommandException {
List<DatasetLock> locks = ctxt.datasets().getLocksByDatasetId(getDataset().getId());
//locks.forEach(lock -> {
for (DatasetLock lock : locks) {
// Ingest lock is ok:
if (DatasetLock.Reason.Ingest != lock.getReason()) {
// with Workflow lock *some* users can edit;
// any other kind of lock - nope
if (DatasetLock.Reason.Workflow != lock.getReason()
|| !ctxt.permissions().isMatchingWorkflowLock(getDataset(),
getUser().getIdentifier(),
getRequest().getWFInvocationId())) {
throw new IllegalCommandException(
BundleUtil.getStringFromBundle("dataset.message.locked.editNotAllowed"), this);
}
}
}
}
}
Loading

0 comments on commit d4b9bac

Please sign in to comment.