Skip to content

Commit

Permalink
Merge branch 'master' into add-data-source-support
Browse files Browse the repository at this point in the history
  • Loading branch information
dprzybyl committed Nov 2, 2023
2 parents d54fb11 + 51b10d1 commit 3596774
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.cognifide.apm.core.grammar.ScriptExecutionException;
import com.cognifide.apm.core.grammar.datasource.DataSourceInvoker;
import com.cognifide.apm.core.scripts.MutableScriptWrapper;
import com.cognifide.apm.core.scripts.ScriptNode;
import com.day.cq.commons.jcr.JcrUtil;
import com.day.crx.JcrConstants;
import java.util.List;
Expand Down Expand Up @@ -116,15 +115,14 @@ private void createVersion(ResourceResolver resolver, Script script) {
Node versionNode = createVersionNode(scriptNode, script, session);
copyScriptContent(versionNode, script, session);
session.save();
resolver.commit();
} catch (Exception e) {
LOGGER.error("Issues with saving to repository while logging script execution", e);
}
}

private Node createScriptNode(Script script, Session session) throws RepositoryException {
String path = getScriptVersionPath(script);
Node scriptHistory = JcrUtils.getOrCreateByPath(path, "sling:OrderedFolder", JcrConstants.NT_UNSTRUCTURED, session, true);
Node scriptHistory = JcrUtils.getOrCreateByPath(path, "sling:OrderedFolder", JcrConstants.NT_UNSTRUCTURED, session, false);
scriptHistory.setProperty("scriptPath", script.getPath());
scriptHistory.setProperty("lastChecksum", script.getChecksum());
return scriptHistory;
Expand All @@ -136,14 +134,13 @@ private String getScriptVersionPath(Script script) {

private Node createVersionNode(Node parent, Script script, Session session) throws RepositoryException {
String path = parent.getPath() + "/" + script.getChecksum();
return JcrUtils.getOrCreateByPath(path, "sling:OrderedFolder", "sling:OrderedFolder", session, true);
return JcrUtils.getOrCreateByPath(path, "sling:OrderedFolder", "sling:OrderedFolder", session, false);
}

private void copyScriptContent(Node parent, Script script, Session session) throws RepositoryException {
if (!parent.hasNode(SCRIPT_NODE_NAME)) {
Node source = session.getNode(script.getPath());
Node file = JcrUtil.copy(source, parent, SCRIPT_NODE_NAME);
file.addMixin(ScriptNode.APM_SCRIPT);
JcrUtil.copy(source, parent, SCRIPT_NODE_NAME);
}
}

Expand Down

0 comments on commit 3596774

Please sign in to comment.