|
|
@ -6,17 +6,12 @@ import java.io.FileNotFoundException; |
|
|
|
import java.io.FileOutputStream; |
|
|
|
import java.io.FileOutputStream; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.io.InputStream; |
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
|
|
|
|
import java.util.regex.Matcher; |
|
|
|
|
|
|
|
import java.util.regex.Pattern; |
|
|
|
import java.util.zip.ZipEntry; |
|
|
|
import java.util.zip.ZipEntry; |
|
|
|
import java.util.zip.ZipInputStream; |
|
|
|
import java.util.zip.ZipInputStream; |
|
|
|
|
|
|
|
|
|
|
|
import javax.jcr.AccessDeniedException; |
|
|
|
|
|
|
|
import javax.jcr.Node; |
|
|
|
|
|
|
|
import javax.jcr.RepositoryException; |
|
|
|
|
|
|
|
import javax.jcr.lock.LockException; |
|
|
|
|
|
|
|
import javax.jcr.nodetype.ConstraintViolationException; |
|
|
|
|
|
|
|
import javax.jcr.version.VersionException; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.sling.api.resource.PersistenceException; |
|
|
|
|
|
|
|
import org.apache.sling.api.resource.Resource; |
|
|
|
import org.apache.sling.api.resource.Resource; |
|
|
|
import org.apache.sling.api.resource.ResourceResolver; |
|
|
|
import org.apache.sling.api.resource.ResourceResolver; |
|
|
|
import org.osgi.framework.Constants; |
|
|
|
import org.osgi.framework.Constants; |
|
|
@ -35,9 +30,9 @@ import com.day.cq.dam.api.AssetManager; |
|
|
|
import com.day.cq.search.QueryBuilder; |
|
|
|
import com.day.cq.search.QueryBuilder; |
|
|
|
|
|
|
|
|
|
|
|
@Component(property = { |
|
|
|
@Component(property = { |
|
|
|
Constants.SERVICE_DESCRIPTION + "=Extracts a SCORM content package and puts it somewhere", |
|
|
|
Constants.SERVICE_DESCRIPTION + "=Extracts a SCORM wrapped course package and puts it somewhere", |
|
|
|
Constants.SERVICE_VENDOR + "=Slalom LLC", |
|
|
|
Constants.SERVICE_VENDOR + "=Slalom LLC", |
|
|
|
"process.label" + "=Extracts a SCORM content package" |
|
|
|
"process.label" + "=001 Extract SCORM Course Package" |
|
|
|
}) |
|
|
|
}) |
|
|
|
public class ScormExtractor implements WorkflowProcess { |
|
|
|
public class ScormExtractor implements WorkflowProcess { |
|
|
|
private static final Logger log = LoggerFactory.getLogger(ScormExtractor.class); |
|
|
|
private static final Logger log = LoggerFactory.getLogger(ScormExtractor.class); |
|
|
@ -54,13 +49,21 @@ public class ScormExtractor implements WorkflowProcess { |
|
|
|
|
|
|
|
|
|
|
|
log.warn("SCORM WORKFLOW: MetaDataMap args: " + mdm.get("PROCESS_ARGS", "string").toString()); |
|
|
|
log.warn("SCORM WORKFLOW: MetaDataMap args: " + mdm.get("PROCESS_ARGS", "string").toString()); |
|
|
|
String[] params = mdm.get("PROCESS_ARGS", "string").toString().split(","); |
|
|
|
String[] params = mdm.get("PROCESS_ARGS", "string").toString().split(","); |
|
|
|
//String excludePath = params[0];
|
|
|
|
|
|
|
|
//String saveToLocation = params[1];
|
|
|
|
/* Initially created for Workflow Launcher |
|
|
|
|
|
|
|
String excludePath = params[0]; |
|
|
|
|
|
|
|
String saveToLocation = params[1]; |
|
|
|
String payloadPath = wi.getContentPath().replace("/jcr:content/renditions/original",""); |
|
|
|
String payloadPath = wi.getContentPath().replace("/jcr:content/renditions/original",""); |
|
|
|
//unzipFile(payloadPath, saveToLocation);
|
|
|
|
unzipFile(payloadPath, saveToLocation); |
|
|
|
|
|
|
|
|
|
|
|
String nodePath = wi.getContentPath().replace(".zip/jcr:content/renditions/original",""); |
|
|
|
String nodePath = wi.getContentPath().replace(".zip/jcr:content/renditions/original",""); |
|
|
|
cleanup(nodePath, resourceResolver); |
|
|
|
cleanup(nodePath, resourceResolver); |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Created for manually triggered workflows */ |
|
|
|
|
|
|
|
String payloadPath = wi.getContentPath().replace("/jcr:content/renditions/original",""); |
|
|
|
|
|
|
|
String[] fileExtensions = params; |
|
|
|
|
|
|
|
unzipFile(payloadPath, fileExtensions); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void cleanup(String path, ResourceResolver resourceResolver) { |
|
|
|
private void cleanup(String path, ResourceResolver resourceResolver) { |
|
|
@ -77,9 +80,12 @@ public class ScormExtractor implements WorkflowProcess { |
|
|
|
}*/ |
|
|
|
}*/ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void unzipFile(String filePath, String outputFolder) { |
|
|
|
private void unzipFile(String filePath, String[] validFileExtensions) {//, String outputFolder) {
|
|
|
|
|
|
|
|
String nodePath = filePath.replaceAll("(?:.[^/]+).zip(/jcr:content/renditions/original)?",""); |
|
|
|
|
|
|
|
Pattern p = Pattern.compile("(?:.[^/]+).("+String.join("|", validFileExtensions)+")(/jcr:content/renditions/original)?"); // the pattern to search for
|
|
|
|
|
|
|
|
|
|
|
|
log.warn("SCORM WORKFLOW: inside unzipFile: filePath - " + filePath); |
|
|
|
log.warn("SCORM WORKFLOW: inside unzipFile: filePath - " + filePath); |
|
|
|
log.warn("SCORM WORKFLOW: inside unzipFile: outputFolder - " + outputFolder); |
|
|
|
log.warn("SCORM WORKFLOW: inside unzipFile: nodePath - " + nodePath); |
|
|
|
|
|
|
|
|
|
|
|
Resource zipfile = resourceResolver.getResource(filePath); |
|
|
|
Resource zipfile = resourceResolver.getResource(filePath); |
|
|
|
AssetManager am = resourceResolver.adaptTo(AssetManager.class); |
|
|
|
AssetManager am = resourceResolver.adaptTo(AssetManager.class); |
|
|
@ -91,10 +97,19 @@ public class ScormExtractor implements WorkflowProcess { |
|
|
|
try (ZipInputStream zipIn = new ZipInputStream(is)) { |
|
|
|
try (ZipInputStream zipIn = new ZipInputStream(is)) { |
|
|
|
ZipEntry entry = zipIn.getNextEntry(); |
|
|
|
ZipEntry entry = zipIn.getNextEntry(); |
|
|
|
while (entry != null) { |
|
|
|
while (entry != null) { |
|
|
|
String zipFilePath = outputFolder + File.separator + entry.getName(); |
|
|
|
Matcher m = p.matcher(entry.getName()); |
|
|
|
log.warn("SCORM WORKFLOW: zipFilePath - " + zipFilePath); |
|
|
|
String matchedString = m.find()?m.group(0):"no match"; |
|
|
|
|
|
|
|
log.warn("SCORM WORKFLOW: matcher - " + matchedString); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String[] fileName = entry.getName().split("\\."); |
|
|
|
|
|
|
|
String zipFilePath = nodePath + matchedString; |
|
|
|
|
|
|
|
String zipFileExtension = fileName.length >= 2 ? fileName[fileName.length-1]:"none"; |
|
|
|
|
|
|
|
boolean extensionIsValid = Arrays.stream(validFileExtensions).anyMatch(zipFileExtension::equals); |
|
|
|
|
|
|
|
|
|
|
|
// Extract file
|
|
|
|
// Extract file
|
|
|
|
if (!entry.isDirectory()) { |
|
|
|
if (!entry.isDirectory() && extensionIsValid) { |
|
|
|
|
|
|
|
log.warn("SCORM WORKFLOW: zipFilePath - " + zipFilePath); |
|
|
|
|
|
|
|
log.warn("SCORM WORKFLOW: zipFileExtension - " + zipFileExtension); |
|
|
|
File f = new File(entry.getName()); |
|
|
|
File f = new File(entry.getName()); |
|
|
|
try (FileOutputStream fos = new FileOutputStream(f)) { |
|
|
|
try (FileOutputStream fos = new FileOutputStream(f)) { |
|
|
|
byte[] buffer = new byte[1024]; |
|
|
|
byte[] buffer = new byte[1024]; |
|
|
|