|
|
|
@ -13,7 +13,9 @@ import java.util.zip.ZipEntry;
|
|
|
|
|
import java.util.zip.ZipInputStream; |
|
|
|
|
|
|
|
|
|
import javax.activation.MimetypesFileTypeMap; |
|
|
|
|
import javax.jcr.ValueFactory; |
|
|
|
|
import javax.jcr.Node; |
|
|
|
|
import javax.jcr.RepositoryException; |
|
|
|
|
import javax.jcr.Session; |
|
|
|
|
|
|
|
|
|
import org.apache.sling.api.resource.Resource; |
|
|
|
|
import org.apache.sling.api.resource.ResourceResolver; |
|
|
|
@ -41,7 +43,7 @@ public class ScormExtractor implements WorkflowProcess {
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(ScormExtractor.class); |
|
|
|
|
|
|
|
|
|
ResourceResolver resourceResolver; |
|
|
|
|
ValueFactory valueFactory; |
|
|
|
|
Session session; |
|
|
|
|
|
|
|
|
|
@Reference |
|
|
|
|
QueryBuilder queryBuilder; |
|
|
|
@ -49,6 +51,7 @@ public class ScormExtractor implements WorkflowProcess {
|
|
|
|
|
@Override |
|
|
|
|
public void execute(WorkItem wi, WorkflowSession ws, MetaDataMap mdm) throws WorkflowException { |
|
|
|
|
resourceResolver = ws.adaptTo(ResourceResolver.class); |
|
|
|
|
session = ws.adaptTo(Session.class); |
|
|
|
|
|
|
|
|
|
/* Created for manually triggered workflows */ |
|
|
|
|
String payloadPath = wi.getContentPath().replace("/jcr:content/renditions/original",""); |
|
|
|
@ -80,7 +83,7 @@ public class ScormExtractor implements WorkflowProcess {
|
|
|
|
|
String fileExtension = fileName.length >= 2 ? fileName[fileName.length-1]:"none"; // file extension
|
|
|
|
|
boolean extensionIsValid = Arrays.stream(validFileExtensions).anyMatch(fileExtension::equals); // file extension check
|
|
|
|
|
|
|
|
|
|
// Extract file
|
|
|
|
|
// Extract files
|
|
|
|
|
if (!entry.isDirectory() && extensionIsValid) { |
|
|
|
|
File f = new File(extractedFilename); //create temporary file
|
|
|
|
|
try (FileOutputStream fos = new FileOutputStream(f)) { |
|
|
|
@ -99,6 +102,7 @@ public class ScormExtractor implements WorkflowProcess {
|
|
|
|
|
|
|
|
|
|
am.createAsset(aemFilePath, fis, mimeType, true); // save to AEM DAM
|
|
|
|
|
f.delete(); //delete temporary file once it has been saved to AEM.
|
|
|
|
|
setAssetMetadata(aemFilePath, a); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -113,4 +117,26 @@ public class ScormExtractor implements WorkflowProcess {
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void setAssetMetadata(String filePath, Asset parentAsset) { |
|
|
|
|
Resource r = resourceResolver.getResource(filePath); |
|
|
|
|
Node assetNode = r.adaptTo(Node.class); |
|
|
|
|
|
|
|
|
|
String parentLMSID = parentAsset.getMetadataValue("mcaps:lmsId"); |
|
|
|
|
String skills = parentAsset.getMetadataValue("mcaps:skills"); |
|
|
|
|
String[] parentSkills = skills.replace(", ", ",").split(","); |
|
|
|
|
String parentCategories = parentAsset.getMetadataValue("mcaps:category"); |
|
|
|
|
String parentCourseUrl = parentAsset.getMetadataValue("mcaps:courseUrl"); |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
Node metadataNode = assetNode.getNode("jcr:content/metadata"); |
|
|
|
|
metadataNode.setProperty("mcaps:lmsId", parentLMSID); |
|
|
|
|
metadataNode.setProperty("mcaps:skills", parentSkills); |
|
|
|
|
metadataNode.setProperty("mcaps:categories", parentCategories); |
|
|
|
|
metadataNode.setProperty("mcaps:courseUrl", parentCourseUrl); |
|
|
|
|
session.save(); |
|
|
|
|
} catch (RepositoryException e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |