Fixed business logic issue, when edited script had run and dry run info from previous version.
*/
package com.cognifide.cq.cqsm.core.scripts;
-import com.google.common.collect.Lists;
-
import com.cognifide.cq.cqsm.api.executors.Mode;
import com.cognifide.cq.cqsm.api.scripts.Event;
import com.cognifide.cq.cqsm.api.scripts.Script;
@@ -29,7 +27,18 @@ import com.cognifide.cq.cqsm.api.scripts.ScriptManager;
import com.cognifide.cq.cqsm.api.scripts.ScriptStorage;
import com.cognifide.cq.cqsm.core.Cqsm;
import com.day.cq.commons.jcr.JcrConstants;
-
+import com.google.common.collect.Lists;
+import java.io.InputStream;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.util.Calendar;
+import java.util.List;
+import java.util.Map;
+import javax.jcr.Binary;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.ValueFactory;
import org.apache.commons.io.FilenameUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
@@ -45,19 +54,6 @@ import org.osgi.framework.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.InputStream;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
-import java.util.Calendar;
-import java.util.List;
-import java.util.Map;
-
-import javax.jcr.Binary;
-import javax.jcr.Node;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.ValueFactory;
-
@Component
@Service
@Properties({@Property(name = Constants.SERVICE_DESCRIPTION, value = "Storage accessor for scripts"),
@@ -137,6 +133,9 @@ public class ScriptStorageImpl implements ScriptStorage {
contentNode.setProperty(JcrConstants.JCR_DATA, binary);
contentNode.setProperty(JcrConstants.JCR_ENCODING, SCRIPT_ENCODING.name());
+ removeProp(contentNode, ScriptContent.CQSM_DRY_RUN_LAST);
+ removeProp(contentNode, ScriptContent.CQSM_DRY_RUN_SUCCESSFUL);
+ removeProp(contentNode, ScriptContent.CQSM_EXECUTION_LAST);
JcrUtils.setLastModified(contentNode, Calendar.getInstance());
session.save();
result = scriptFinder.find(fileNode.getPath(), resolver);
@@ -146,6 +145,12 @@ public class ScriptStorageImpl implements ScriptStorage {
return result;
}
+ private void removeProp(Node contentNode, String propName) throws RepositoryException {
+ if (contentNode.hasProperty(propName)) {
+ contentNode.getProperty(propName).remove();
+ }
+ }
+
private String generateFileName(String fileName, Node saveNode) throws RepositoryException {
String baseName = FilenameUtils.getBaseName(fileName);
int num = 1;
