Skip to content

Commit

Permalink
Updated broken rollback with classification (#20)
Browse files Browse the repository at this point in the history
* Updated broken rollback with classification

* Validated fix

* Fixing null pointer when enforcement is not set
  • Loading branch information
mirzakaracic authored May 1, 2024
1 parent 3311575 commit 4f96b6f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import com.arcadedb.utility.LockException;
import com.arcadedb.utility.MultiIterator;
import com.arcadedb.utility.RWLockContext;
import lombok.extern.slf4j.Slf4j;

import java.io.*;
import java.nio.channels.*;
Expand Down Expand Up @@ -855,8 +856,12 @@ public void updateRecord(final Record record) {
if (mode == PaginatedFile.MODE.READ_ONLY)
throw new DatabaseIsReadOnlyException("Cannot update a record");

if (record instanceof MutableDocument)
((MutableDocument) record).validateAndAccmCheck(getContext().getCurrentUser());
if (record instanceof MutableDocument) {
var rec = (MutableDocument) record;
var context = DatabaseContext.INSTANCE.getContext(rec.database.getDatabasePath());
if (context.getCurrentUser() != null)
rec.validateAndAccmCheck(context.getCurrentUser());
}

// INVOKE EVENT CALLBACKS
if (!events.onBeforeUpdate(record))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Deque;
import java.util.Map;

import com.arcadedb.database.MutableDocument;
import com.arcadedb.database.RID;
import com.arcadedb.database.*;
import com.arcadedb.database.Record;
import com.arcadedb.database.Utils;
import com.arcadedb.serializer.json.JSONObject;
import com.arcadedb.server.ArcadeDBServer;
import com.arcadedb.server.DataFabricRestClient;
Expand Down Expand Up @@ -100,13 +99,22 @@ protected ExecutionResponse execute(HttpServerExchange exchange, ServerSecurityU

var payload = new JSONObject(value).getJSONObject("history").getString("entity");
var content = new JSONObject(payload);

final ArcadeDBServer server = httpServer.getServer();
var activeDatabase = server.getDatabase(database);
Record record = server.getDatabase(database).lookupByRID(new RID(activeDatabase, rid), true);
Map<String, Object> classification = null;
if (activeDatabase.getSchema().getEmbedded().isClassificationValidationEnabled()) {
var classificationObj = (JSONObject)content.remove(MutableDocument.CLASSIFICATION_PROPERTY);
classification = classificationObj.toMap();
}

MutableDocument mutable = record.asDocument().modify();
mutable.fromJSON(content);
mutable.set(MutableDocument.CLASSIFICATION_PROPERTY, classification);

if (activeDatabase.getSchema().getEmbedded().isClassificationValidationEnabled()) {
mutable.set(MutableDocument.CLASSIFICATION_PROPERTY, classification);
}

LocalDateTime createdDate = null;
if (record.asDocument().get(Utils.CREATED_DATE) instanceof Long) {
Expand All @@ -131,7 +139,8 @@ protected ExecutionResponse execute(HttpServerExchange exchange, ServerSecurityU

return new ExecutionResponse(200, "{ \"result\" : \"Success\"}");
} catch (Exception e) {
log.error("Error handling history rollback request.", e.getMessage());
e.printStackTrace();
log.error("Error handling history rollback request. Error {}", e.getMessage());
log.debug("Exception", e);
}
return new ExecutionResponse(400, "{ \"error\" : \"Request failed\"}");
Expand Down

0 comments on commit 4f96b6f

Please sign in to comment.