Skip to content

Commit

Permalink
Fixing syncing issue with multiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
dcolvin committed Oct 3, 2024
1 parent 748bc76 commit cdf5d26
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 44 deletions.
2 changes: 1 addition & 1 deletion current/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<parent>
<groupId>com.coresecure.brightcove.cq5</groupId>
<artifactId>brightcove_connector</artifactId>
<version>6.0.6</version>
<version>6.0.7</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>brightcove-services</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class BrightcoveDeleteAssetWorkflowStep implements WorkflowProcess{
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap processArguments) throws WorkflowException {
// TODO Auto-generated method stub
String payloadPath = workItem.getWorkflowData().getPayload().toString();
LOG.error("********************* payloadpath:" + payloadPath);
LOG.info("********************* payloadpath:" + payloadPath);

ResourceResolver rr = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,26 @@
@Service
@Component(immediate = true, metatype = true)
@Properties({
@Property(name = org.osgi.framework.Constants.SERVICE_DESCRIPTION, value = "Brightcove: Sync Asset to Brightcove"),
@Property(name = org.osgi.framework.Constants.SERVICE_VENDOR, value = "Brightcove"),
@Property(name = "process.label", value = "Brightcove: Sync Asset to Brightcove") })
public class BrightcoveSyncAssetWorkflowStep implements WorkflowProcess{

@Reference
private ResourceResolverFactory resourceResolverFactory;
@Property(name = org.osgi.framework.Constants.SERVICE_DESCRIPTION, value = "Brightcove: Sync Asset to Brightcove"),
@Property(name = org.osgi.framework.Constants.SERVICE_VENDOR, value = "Brightcove"),
@Property(name = "process.label", value = "Brightcove: Sync Asset to Brightcove")})
public class BrightcoveSyncAssetWorkflowStep implements WorkflowProcess {

private static final Logger LOG = LoggerFactory.getLogger(BrightcoveSyncAssetWorkflowStep.class);
private static final String SERVICE_ACCOUNT_IDENTIFIER = "brightcoveWrite";
private String brightcoveAssetId;
@Reference
private ResourceResolverFactory resourceResolverFactory;
// private String brightcoveAssetId;
private Map<String, String> paths = null;

@Override
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap processArguments) throws WorkflowException {

String payloadPath = workItem.getWorkflowData().getPayload().toString();
LOG.error("********************* payloadpath:" + payloadPath);
LOG.info("********************* payloadpath:" + payloadPath);

ResourceResolver rr = null;
String brightcoveAssetId = null;

try {

Expand Down Expand Up @@ -115,13 +115,13 @@ public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaData
Asset _asset = assetResource.adaptTo(Asset.class);
ServiceUtil serviceUtil = new ServiceUtil(brightcoveAccountId);
// upload or modify the asset
activateAsset(rr, _asset, serviceUtil);
brightcoveAssetId = activateAsset(rr, _asset, serviceUtil);
TimeUnit.SECONDS.sleep(15);
if (brightcoveAssetId != null && !brightcoveAssetId.isEmpty()) {
syncBrightcoveData(serviceUtil, _asset, rr, brightcoveAccountId);
syncBrightcoveData(brightcoveAssetId, serviceUtil, _asset, rr, brightcoveAccountId);
}
rr.commit();


}

Expand All @@ -144,23 +144,25 @@ public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaData
}
}
}
private void syncBrightcoveData(ServiceUtil serviceUtil, Asset _asset, ResourceResolver rr, String brightcoveAccountId) {

private void syncBrightcoveData(String brightcoveAssetId, ServiceUtil serviceUtil, Asset _asset, ResourceResolver rr, String brightcoveAccountId) {

try {
JSONObject result = serviceUtil.getSelectedVideo(brightcoveAssetId);


serviceUtil.updateAsset(_asset, result, rr, brightcoveAccountId);
} catch (PersistenceException | JSONException | RepositoryException e) {
LOG.error("Error when updating Brightcove metadata and renditions: {}", e.getMessage());
}
}

private void activateNew(Asset _asset, ServiceUtil serviceUtil, Video video, ModifiableValueMap brc_lastsync_map) {
private String activateNew(Asset _asset, ServiceUtil serviceUtil, Video video, ModifiableValueMap brc_lastsync_map) {

LOG.trace("brc_lastsync was null or zero : asset should be initialized");
LOG.info("activate new asset");
String brightcoveAssetId = null;

try {

// get the binary
Expand Down Expand Up @@ -199,13 +201,16 @@ private void activateNew(Asset _asset, ServiceUtil serviceUtil, Video video, Mod
LOG.error("Error: {}", e.getMessage());

}

return brightcoveAssetId;

}

private void activateModified(Asset _asset, ServiceUtil serviceUtil, Video video,
ModifiableValueMap brc_lastsync_map) {
private String activateModified(Asset _asset, ServiceUtil serviceUtil, Video video,
ModifiableValueMap brc_lastsync_map) {

LOG.info("Entering activateModified()");
String brightcoveAssetId = null;

try {

Expand All @@ -216,7 +221,7 @@ private void activateModified(Asset _asset, ServiceUtil serviceUtil, Video video

boolean sent = api_resp.getBoolean(Constants.SENT);
if (sent) {

brightcoveAssetId = api_resp.getString(Constants.VIDEOID);
LOG.info("Brightcove video updated successfully: {}", _asset.getPath());
serviceUtil.updateRenditions(_asset, video);
LOG.info("Updated renditions for Brightcove video: {}", _asset.getPath());
Expand All @@ -240,28 +245,44 @@ private void activateModified(Asset _asset, ServiceUtil serviceUtil, Video video
LOG.error("General Error: {}", _asset.getName());

}

return brightcoveAssetId;

}

private void syncFolder(ServiceUtil serviceUtil, JSONObject api_resp, Node assetNode) {
private void syncFolder(ServiceUtil serviceUtil, JSONObject api_resp, Node assetNode) {
try {
LOG.trace("CHECKING PARENT FOR BRC_FOLDER_ID: " + assetNode.getParent().getPath());
Node parentNode = assetNode.getParent();
String videoId = api_resp.getString(Constants.VIDEOID);

if (!parentNode.hasProperty("brc_folder_id")) {
String folderId = serviceUtil.createFolder(assetNode.getParent().getName());
if (folderId != null && !folderId.isEmpty()) {
parentNode.getSession().move(parentNode.getPath(), parentNode.getParent().getPath() + "/" + folderId);
parentNode.getSession().save();
parentNode.setProperty("brc_folder_id", folderId);

LOG.trace("SUBFOLDER FOUND - SETTING THE FOLDER ID to '" + folderId + "'");
serviceUtil.moveVideoToFolder(folderId, api_resp.getString(Constants.VIDEOID));
setFolderIdMoveAssetInBC(serviceUtil, parentNode, videoId, folderId);
} else {
LOG.error("*************************** No folder created ***************************");
TimeUnit.SECONDS.sleep(15);
parentNode.refresh(false);
if (!parentNode.hasProperty("brc_folder_id")) {
folderId = serviceUtil.createFolder(assetNode.getParent().getName());
if (folderId != null && !folderId.isEmpty()) {
setFolderIdMoveAssetInBC(serviceUtil, parentNode, videoId, folderId);
} else {
LOG.error("*************************** No folder created attempt 2 ***************************");
}
} else {
// this is in a subfolder so we need to formally move the asset to this folder
String brc_folder_id = parentNode.getProperty("brc_folder_id").getString();
LOG.trace("SUBFOLDER FOUND - SETTING THE FOLDER ID to '" + brc_folder_id + "'");
serviceUtil.moveVideoToFolder(brc_folder_id, videoId);
}
}
} else {
// this is in a subfolder so we need to formally move the asset to this folder
String brc_folder_id = assetNode.getParent().getProperty("brc_folder_id").getString();
String brc_folder_id = parentNode.getProperty("brc_folder_id").getString();
LOG.trace("SUBFOLDER FOUND - SETTING THE FOLDER ID to '" + brc_folder_id + "'");
serviceUtil.moveVideoToFolder(brc_folder_id, api_resp.getString(Constants.VIDEOID));
serviceUtil.moveVideoToFolder(brc_folder_id, videoId);
}


Expand All @@ -273,27 +294,36 @@ private void syncFolder(ServiceUtil serviceUtil, JSONObject api_resp, Node asset
}
}

private void activateAsset(ResourceResolver rr, Asset _asset, ServiceUtil serviceUtil) {
private void setFolderIdMoveAssetInBC(ServiceUtil serviceUtil, Node parentNode, String videoId, String folderId) throws Exception {
parentNode.setProperty("brc_folder_id", folderId);
parentNode.getSession().save();

LOG.trace("SUBFOLDER FOUND - SETTING THE FOLDER ID to '" + folderId + "'");
serviceUtil.moveVideoToFolder(folderId, videoId);
}

private String activateAsset(ResourceResolver rr, Asset _asset, ServiceUtil serviceUtil) {

// need to either activate a new asset or an updated existing
// ServiceUtil serviceUtil = new ServiceUtil(accountId);
String path = _asset.getPath();

String brightcoveAssetId = null;

Video video = serviceUtil.createVideo(path, _asset, "ACTIVE");
Resource assetRes = _asset.adaptTo(Resource.class);

if (assetRes == null) {
return;
return "";
}

Resource metadataRes = assetRes.getChild(Constants.ASSET_METADATA_PATH);
if (metadataRes == null) {
return;
return "";
}

ModifiableValueMap brc_lastsync_map = metadataRes.adaptTo(ModifiableValueMap.class);
if (brc_lastsync_map == null) {
return;
return "";
}

Long jcr_lastmod = _asset.getLastModified();
Expand All @@ -305,13 +335,15 @@ private void activateAsset(ResourceResolver rr, Asset _asset, ServiceUtil servic

// we need to activate a new asset here
LOG.info("Activating New Brightcove Asset: {}", _asset.getPath());
activateNew(_asset, serviceUtil, video, brc_lastsync_map);
brightcoveAssetId = activateNew(_asset, serviceUtil, video, brc_lastsync_map);

} else {
// we need to modify an existing asset here
// we need to modify an existing asset here
LOG.info("Activating Modified Brightcove Asset: {}", _asset.getPath());
activateModified(_asset, serviceUtil, video, brc_lastsync_map);
brightcoveAssetId = activateModified(_asset, serviceUtil, video, brc_lastsync_map);
}

return brightcoveAssetId;

}
}
}
2 changes: 1 addition & 1 deletion current/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Copyright (C) 2019 3|SHARE Inc.
<groupId>com.coresecure.brightcove.cq5</groupId>
<artifactId>brightcove_connector</artifactId>
<packaging>pom</packaging>
<version>6.0.6</version>
<version>6.0.7</version>
<description>
Parent Maven POM for the 'Adobe CQ5 Brightcove Connector API' project.
</description>
Expand Down
4 changes: 2 additions & 2 deletions current/ui.apps/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<parent>
<groupId>com.coresecure.brightcove.cq5</groupId>
<artifactId>brightcove_connector</artifactId>
<version>6.0.6</version>
<version>6.0.7</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -227,7 +227,7 @@
<dependency>
<groupId>com.coresecure.brightcove.cq5</groupId>
<artifactId>brightcove-services</artifactId>
<version>6.0.6</version>
<version>6.0.7</version>
</dependency>

<dependency>
Expand Down

0 comments on commit cdf5d26

Please sign in to comment.