Skip to content

Commit

Permalink
Merge pull request brightcove#57 from brightcove/release/6.0.2
Browse files Browse the repository at this point in the history
Release/6.0.2
  • Loading branch information
hngrylobster authored Apr 4, 2023
2 parents 0515fbe + 9cc8b91 commit 035c9d8
Show file tree
Hide file tree
Showing 23 changed files with 684 additions and 131 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.0</version>
<version>6.0.2</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>brightcove-services</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,34 @@ public JSONObject updatePlaylist(String playlistId, String[] videos) {
return json;
}

public JSONObject updateLabels(String videoId, String[] labels) {
JSONObject json = new JSONObject();
TokenObj authToken = account.getLoginToken();
if (authToken != null) {
Map<String, String> headers = new HashMap<String, String>();
headers.put(Constants.AUTHENTICATION_HEADER, authToken.getTokenType() + " " + authToken.getToken());
String targetURL = Constants.ACCOUNTS_API_PATH + account.getAccount_ID() + "/videos"
+ "/" + videoId;
try {
LOGGER.debug("targetURL: {}", targetURL);
JSONObject request = new JSONObject();
ArrayList<String> labelArray = new ArrayList<String>();
for (String item : labels) {
labelArray.add(item);
}
request.put("labels", new JSONArray(labelArray));
LOGGER.info("updateVideoParams: {}", request.toString(1));
String response = account.platform.patchAPI(targetURL, request.toString(1), headers);
if (response != null && !response.isEmpty()) json = JsonReader.readJsonFromString(response);
} catch (IOException e) {
LOGGER.error(e.getClass().getName(), e);
} catch (JSONException e) {
LOGGER.error(e.getClass().getName(), e);
}
}
return json;
}

//deleteAPI
public JSONObject deleteVideo(String videoID) {
JSONObject json = new JSONObject();
Expand Down Expand Up @@ -407,6 +435,29 @@ public JSONObject createPlaylist(Playlist aPlaylist) {
return json;
}

public JSONObject createLabel(String label) {
JSONObject json = new JSONObject();
TokenObj authToken = account.getLoginToken();
if (authToken != null)
{
Map<String, String> headers = new HashMap<String, String>();
headers.put(Constants.AUTHENTICATION_HEADER, authToken.getTokenType() + " " + authToken.getToken());
String targetURL = Constants.ACCOUNTS_API_PATH + account.getAccount_ID() + "/labels";
try {
LOGGER.debug("Label {}", label.toString());
String response = account.platform.postAPI(targetURL, "{ \"path\": \"" + label + "\" }", headers);
if (response != null && !response.isEmpty()) json = JsonReader.readJsonFromString(response);
} catch (IOException e) {
LOGGER.error(e.getClass().getName(), e);
} catch (JSONException e)
{
LOGGER.error(e.getClass().getName(), e);
}
}
LOGGER.trace("createLabel: {} Response: {}", label, json);
return json;
}

public JSONObject getVideosCount(String q) {
return getVideosCount(q, true);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
Adobe AEM Brightcove Connector
Copyright (C) 2018 Coresecure Inc.
Authors: Alessandro Bonfatti
Yan Kisen
Pablo Kropilnicki
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
- Additional permission under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or combining
it with httpclient 4.1.3, httpcore 4.1.4, httpmine 4.1.3, jsoup 1.7.2,
squeakysand-commons and squeakysand-osgi (or a modified version of those
libraries), containing parts covered by the terms of APACHE LICENSE 2.0
or MIT License, the licensors of this Program grant you additional
permission to convey the resulting work.
*/
package com.coresecure.brightcove.wrapper.objects;

import com.coresecure.brightcove.wrapper.enums.GeoFilterCodeEnum;
import com.coresecure.brightcove.wrapper.utils.Constants;
import com.coresecure.brightcove.wrapper.utils.ObjectSerializer;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Collection;

public class Folder {
public final String id;
public final String name;
public final String path;
private static final Logger LOGGER = LoggerFactory.getLogger(Folder.class);

public Folder(String aId, String aName, String aPath) {
id = aId;
name = aName;
path = aPath;
}

public Folder(JSONObject aFolder) throws JSONException {
id = aFolder.getString(Constants.ID);
name = aFolder.getString(Constants.FOLDER_ID);
path = "";
}

public JSONObject toJSON() throws JSONException {
JSONObject json = ObjectSerializer.toJSON(this, new String[]{Constants.ID, Constants.NAME});
return json;
}

public String toString() {
String result = new String();
try {
result = toJSON().toString();
} catch (JSONException e) {
LOGGER.error(e.getClass().getName(),e);
}
return result;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class Video {
public final String reference_id;
public final String description;
public final String long_description;
public final String folderId;
public final String state;
public final Collection<String> tags;
public final Collection<String> labels;
Expand All @@ -65,6 +66,7 @@ public class Video {
public final boolean complete;
public final EconomicsEnum economics;
public final JSONArray text_tracks;
public final JSONArray variants;
public final Images images;


Expand Down Expand Up @@ -94,10 +96,18 @@ public Video(String aId, String aName, String aReference_id, String aDescription
}

public Video(String aId, String aName, String aReference_id, String aDescription, String aLong_description, String aState, Collection<String> aTags, Geo aGeo, Schedule aSchedule, boolean aComplete, RelatedLink aLink, Map<String, Object> aCustom_fields, EconomicsEnum aEconomics, String aProjection, JSONArray aText_tracks, Images aImages) {
this(aId, aName, aReference_id, aDescription, aLong_description, aState, aTags, aGeo, aSchedule, aComplete, aLink, aCustom_fields, aEconomics, aProjection, aText_tracks, aImages, null, null);
this(aId, aName, aReference_id, aDescription, aLong_description, aState, aTags, aGeo, aSchedule, aComplete, aLink, aCustom_fields, aEconomics, aProjection, aText_tracks, aImages, null, null, null, null);
}

private Video(String aId, String aName, String aReference_id, String aDescription, String aLong_description, String aState, Collection<String> aTags, Geo aGeo, Schedule aSchedule, boolean aComplete, RelatedLink aLink, Map<String, Object> aCustom_fields, EconomicsEnum aEconomics, String aProjection, JSONArray aText_tracks, Images aImages, String aAccountId, Collection<String> aLabels) {
public Video(String aId, String aName, String aReference_id, String aDescription, String aLong_description, String aState, Collection<String> aTags, Geo aGeo, Schedule aSchedule, boolean aComplete, RelatedLink aLink, Map<String, Object> aCustom_fields, EconomicsEnum aEconomics, String aProjection, JSONArray aText_tracks, Images aImages, Collection<String> aLabels) {
this(aId, aName, aReference_id, aDescription, aLong_description, aState, aTags, aGeo, aSchedule, aComplete, aLink, aCustom_fields, aEconomics, aProjection, aText_tracks, aImages, null, aLabels, null, null);
}

public Video(String aId, String aName, String aReference_id, String aDescription, String aLong_description, String aState, Collection<String> aTags, Geo aGeo, Schedule aSchedule, boolean aComplete, RelatedLink aLink, Map<String, Object> aCustom_fields, EconomicsEnum aEconomics, String aProjection, JSONArray aText_tracks, Images aImages, Collection<String> aLabels, JSONArray aVariants) {
this(aId, aName, aReference_id, aDescription, aLong_description, aState, aTags, aGeo, aSchedule, aComplete, aLink, aCustom_fields, aEconomics, aProjection, aText_tracks, aImages, null, aLabels, aVariants, null);
}

private Video(String aId, String aName, String aReference_id, String aDescription, String aLong_description, String aState, Collection<String> aTags, Geo aGeo, Schedule aSchedule, boolean aComplete, RelatedLink aLink, Map<String, Object> aCustom_fields, EconomicsEnum aEconomics, String aProjection, JSONArray aText_tracks, Images aImages, String aAccountId, Collection<String> aLabels, JSONArray aVariants, String aFolderId) {
id = aId;
account_id = aAccountId;
name = aName;
Expand All @@ -106,7 +116,6 @@ private Video(String aId, String aName, String aReference_id, String aDescriptio
long_description = aLong_description;
state = aState;
tags = aTags;
labels = aLabels;
geo = aGeo;
schedule = aSchedule;
link = aLink;
Expand All @@ -115,7 +124,10 @@ private Video(String aId, String aName, String aReference_id, String aDescriptio
economics = aEconomics;
projection = new Projection(aProjection);
text_tracks = aText_tracks;
variants = aVariants;
images = aImages;
labels = aLabels;
folderId = aFolderId;
}

private Object getNotNull(JSONObject video, String key) throws JSONException{
Expand All @@ -129,6 +141,7 @@ public Video(JSONObject video) throws JSONException {
Projection localprojection = null;
String localreference_id = null;
String localdescription = null;
String localfolderid = null;
String locallong_description = null;
String localstate = null;
Collection<String> localtags = null;
Expand All @@ -140,20 +153,23 @@ public Video(JSONObject video) throws JSONException {
boolean localcomplete = false;
EconomicsEnum localeconomics = null;
JSONArray localtext_tracks = null;
JSONArray localvariants = null;
Images localimages = null;
try {
localid = (String) getNotNull(video, Constants.ID);
localaccount_id = (String) getNotNull(video, Constants.ACCOUNT_ID);
localname = (String) getNotNull(video, Constants.NAME);
localreference_id = (String) getNotNull(video, Constants.REFERENCE_ID);
localdescription = (String) getNotNull(video, Constants.DESCRIPTION);
localfolderid = (String) getNotNull(video, Constants.FOLDER_ID);
locallong_description = (String) getNotNull(video, Constants.LONG_DESCRIPTION);
localstate = (String) getNotNull(video, Constants.STATE);
localprojection = (Projection) getNotNull(video, Constants.PROJECTION);
localgeo = (Geo) getNotNull(video, Constants.GEO);
localschedule = (Schedule) getNotNull(video, Constants.SCHEDULE);
locallink = (RelatedLink) getNotNull(video, Constants.LINK);
localtext_tracks = (JSONArray) getNotNull(video, Constants.TEXT_TRACKS);
localvariants = (JSONArray) getNotNull(video, Constants.VARIANTS);
localcomplete = (Boolean) getNotNull(video, Constants.COMPLETE);
if (!video.isNull(Constants.TAGS))
{
Expand Down Expand Up @@ -184,6 +200,7 @@ public Video(JSONObject video) throws JSONException {
this.projection = localprojection;
this.reference_id = localreference_id;
this.description = localdescription;
this.folderId = localfolderid;
this.long_description = locallong_description;
this.state = localstate;
this.tags = localtags;
Expand All @@ -195,6 +212,7 @@ public Video(JSONObject video) throws JSONException {
this.complete = localcomplete;
this.economics = localeconomics;
this.text_tracks = localtext_tracks;
this.variants = localvariants;
this.images = localimages;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,22 @@ private Asset createAsset(String localpath, String id, String brightcove_filenam
return newAsset;
}

private String cleanPath(String confPath, String filename){
private String cleanPath(String confPath, String filename) {
return (confPath.endsWith("/") ? confPath : confPath.concat("/")).concat(requestedServiceAccount + "/").concat(filename);
}

private String cleanPath(String confPath, String filename, String folderId) {
String accountFolder = (confPath.endsWith("/") ? confPath : confPath.concat("/")).concat(requestedServiceAccount + "/");
if (folderId == null || folderId.length() == 0)
return accountFolder.concat(filename);
else
return accountFolder.concat(folderId + "/").concat(filename);
}

private String cleanFilename(JSONObject innerObj) throws JSONException{
return innerObj.getString(Constants.ORIGINAL_FILENAME) != null ? innerObj.getString(Constants.ORIGINAL_FILENAME).replaceAll("%20", " ") : null;
}

private Asset getAsset(String oldpath, String localpath ){
Resource resource = resourceResolver.getResource(oldpath);
if(resource != null) {
Expand All @@ -210,6 +220,7 @@ private Asset getAsset(String oldpath, String localpath ){
}
return null;
}

public String call(){
// Get the Service resource resolver
try {
Expand All @@ -229,7 +240,6 @@ public String call(){

LOGGER.trace(">>>>START>>>>> {} >> {}", id ,active);

//TODO: CHECK IF VIDEO COMING INTO DAM (1) IS ACTIVE (2) HAS AN ID + SRC IMAGE??
if (!active) {
LOGGER.warn("VIDEO INITIALIZATION FAILED - NOT ACTIVE / NO ID - skipping: " + innerObj.toString(1));
if (resourceResolver != null) {
Expand All @@ -241,17 +251,18 @@ public String call(){
String name = innerObj.getString(Constants.NAME);
String brightcove_filename = id + ".mp4"; //BRIGHTCOVE FILE NAME IS ID + . MP4 <-
String original_filename = cleanFilename(innerObj);
String brightcove_folder_id = (innerObj.isNull(Constants.FOLDER_ID) ? "" : innerObj.getString(Constants.FOLDER_ID));

LOGGER.trace("SYNCING VIDEO>>[" + name + "\tSTATE:ACTIVE\tTO BE:" + original_filename + "]");
LOGGER.trace("SYNCING VIDEO >> [" + name + "\tSTATE:ACTIVE\tTO BE:" + original_filename + "]");

LOGGER.trace("VIDEO HAS FOLDER ID >> [" + brightcove_folder_id + "]");

//INITIALIZING ASSET SEARCH // INITIALIZATION
Asset newAsset = null;

//TODO: PRINTING DEBUGGER (ENABLE TO DEBUG)

//USNIG THE CONFIGURATION - BUILD THE DIRECTORY TO SEARCH FOR THE LOCAL ASSETS OR BUILD INTO
String localpath = cleanPath(confPath,brightcove_filename);
String oldpath = cleanPath(confPath,original_filename);
String localpath = cleanPath(confPath, brightcove_filename, brightcove_folder_id);
String oldpath = cleanPath(confPath, original_filename, brightcove_folder_id);

LOGGER.trace("SEARCHING FOR LOCAL ASSET");
LOGGER.trace(">>ORIGINAL: " + oldpath);
Expand Down Expand Up @@ -286,10 +297,8 @@ public String call(){

}


}


LOGGER.trace(">>>>>>>>>{" + id + "}>>>>>END>>>>");

//MAIN VIDEO ARRAY TRAVERSAL LOOP
Expand Down
Loading

0 comments on commit 035c9d8

Please sign in to comment.