From bde7ffd1092aabc6527e2d4da22f1a2fed0ae162 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1s=C3=A1ry=20D=C3=A1niel?= Date: Mon, 20 Nov 2017 16:36:28 +0000 Subject: [PATCH] git-tfs-id: [http://tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube;C30750 --- .../Configuration/configuration-nle.json | 6 + .../configuration-playout-ingest.json | 2 +- .../Configuration/configuration-studio.json | 2 +- client/Maestro/MaestroForm.Designer.cs | 3 +- client/Maestro/MaestroForm.Metadata.cs | 13 +- client/Maestro/MaestroForm.Target.cs | 3 - client/Maestro/MaestroForm.cs | 4 + client/Maestro/MaestroForm.resx | 14 +-- .../Configuration/ConfigurationInfo.cs | 1 + .../OctopusIDSelector.Designer.cs | 1 + client/OctopusClient/OctopusIDSelector.cs | 16 ++- client/PlanAIRClient/TrafficIDSelector.cs | 13 ++ .../run-mediacube-server-bsh.launch | 2 +- server/-configuration/scheduledjobs.json | 2 +- .../src/user/commons/nosql/NoSQLUtils.java | 42 +++++-- .../src/user/commons/octopus/OctopusAPI.java | 118 ++++++++++-------- .../commons/octopus/OctopusDataMiner.java | 70 +++++------ 17 files changed, 195 insertions(+), 117 deletions(-) diff --git a/client/Maestro/Configuration/configuration-nle.json b/client/Maestro/Configuration/configuration-nle.json index 78e56c0c..aa4440e8 100644 --- a/client/Maestro/Configuration/configuration-nle.json +++ b/client/Maestro/Configuration/configuration-nle.json @@ -31,6 +31,12 @@ "userName": "MAM", "password": "7RKZYBzumKjL40SJwuwiFCvX57xuCN8zay6OttUm2wbrgImyYZBHyZTUUYrXX31Ge2Uwew07HYsqh2uzdJeDBDwcVntxaHg3nIpv9Dyq/odVoiC4tUF/K+lgvKWANcrZ", "timeout": 1000 + }, + "local": { + "address": "file://10.10.1.100/OCTOPUS", + "userName": "mediacube", + "password": "Dn8t4gfHcK98o8hyPgLDhr5SgSji4JCxsfpMJsODikUp3nXgrM0UNCi45lLAK8ZOnmEneO44P9qpJ4QDqhctN6MxZodjJgdZTyoZKmSa+ECzEzLr/wPYNgxVaXrVotEy", + "timeout": 1000 } }, { diff --git a/client/Maestro/Configuration/configuration-playout-ingest.json b/client/Maestro/Configuration/configuration-playout-ingest.json index aa818ef7..ddd13040 100644 --- a/client/Maestro/Configuration/configuration-playout-ingest.json +++ b/client/Maestro/Configuration/configuration-playout-ingest.json @@ -1,6 +1,6 @@ { "title": "Lebony betöltő", - "active": true, + "active": false, "startInTray": false, "enableCustomMetadataId": true, "player": { diff --git a/client/Maestro/Configuration/configuration-studio.json b/client/Maestro/Configuration/configuration-studio.json index a159bf7b..a3db7e94 100644 --- a/client/Maestro/Configuration/configuration-studio.json +++ b/client/Maestro/Configuration/configuration-studio.json @@ -1,6 +1,6 @@ { "title": "Stúdió", - "active": true, + "active": false, "startInTray": false, "enableCustomMetadataId": true, "filter": "avi", diff --git a/client/Maestro/MaestroForm.Designer.cs b/client/Maestro/MaestroForm.Designer.cs index 69214110..b4b037ee 100644 --- a/client/Maestro/MaestroForm.Designer.cs +++ b/client/Maestro/MaestroForm.Designer.cs @@ -213,12 +213,13 @@ namespace Maestro { this.treeFolders.Visible = false; this.treeFolders.BeforeExpand += new System.Windows.Forms.TreeViewCancelEventHandler(this.OnBeforeExpandFolder); this.treeFolders.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.OnAfterSelectFolder); + this.treeFolders.MouseDown += new System.Windows.Forms.MouseEventHandler(this.OnFolderMouseDown); // // ilFolders // this.ilFolders.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("ilFolders.ImageStream"))); this.ilFolders.TransparentColor = System.Drawing.Color.Transparent; - this.ilFolders.Images.SetKeyName(0, "ic_folder_open_black_24dp_1x.png"); + this.ilFolders.Images.SetKeyName(0, "ic_folder_open_black_24dp_1x.jpg"); // // pSourceFilter // diff --git a/client/Maestro/MaestroForm.Metadata.cs b/client/Maestro/MaestroForm.Metadata.cs index b1a442a6..c5b5546c 100644 --- a/client/Maestro/MaestroForm.Metadata.cs +++ b/client/Maestro/MaestroForm.Metadata.cs @@ -429,12 +429,23 @@ namespace Maestro { MetadataProvider config = null; MetadataType metadataType = GuessMetadataType(id); switch (metadataType) { - case MetadataType.TrafficAD: case MetadataType.TrafficMaterial: + config = Configuration.GetMetadataProvider(); + if (config == null) + return; + trafficIDSelector.LookupByMaterialID(id); + break; case MetadataType.TrafficPromo: config = Configuration.GetMetadataProvider(); if (config == null) return; + trafficIDSelector.LookupByPromoID(id); + break; + case MetadataType.TrafficAD: + config = Configuration.GetMetadataProvider(); + if (config == null) + return; + trafficIDSelector.LookupByADID(id); break; case MetadataType.OctopusPlaceHolder: config = Configuration.GetMetadataProvider(); diff --git a/client/Maestro/MaestroForm.Target.cs b/client/Maestro/MaestroForm.Target.cs index 8d1a646f..c78a12e3 100644 --- a/client/Maestro/MaestroForm.Target.cs +++ b/client/Maestro/MaestroForm.Target.cs @@ -77,7 +77,6 @@ namespace Maestro { private List CreateProcessors(Target target, CheckBox checkBox) { List result = null; foreach (ISourceItem sourceItem in selectedSourceItems) { - //ISourceItem sourceItem = actualRow.DataBoundItem as ISourceItem; if (sourceItem == null) continue; if (!EnsureSegments(target)) { @@ -96,9 +95,7 @@ namespace Maestro { result = new List(); result.Add(processor); - //var beforeProcessors = new Dictionary>(currentProcessors); HandleCheckBoxReferences(target.Reference, true); - //var diff = beforeProcessors.Except(currentProcessors).Concat(currentProcessors.Except(beforeProcessors)); } return result; } diff --git a/client/Maestro/MaestroForm.cs b/client/Maestro/MaestroForm.cs index 860ec07c..ad9d46af 100644 --- a/client/Maestro/MaestroForm.cs +++ b/client/Maestro/MaestroForm.cs @@ -246,5 +246,9 @@ namespace Maestro { } } + private void OnFolderMouseDown(object sender, MouseEventArgs e) { + if (e.Button == MouseButtons.Right) + treeFolders.SelectedNode = treeFolders.GetNodeAt(e.X, e.Y); + } } } diff --git a/client/Maestro/MaestroForm.resx b/client/Maestro/MaestroForm.resx index cd7a5716..f09802db 100644 --- a/client/Maestro/MaestroForm.resx +++ b/client/Maestro/MaestroForm.resx @@ -127,8 +127,8 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 - ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAACc - BwAAAk1TRnQBSQFMAwEBAAFAAQABQAEAARABAAEQAQAE/wEJAQAI/wFCAU0BNgEEBgABNgEEAgABKAMA + ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAACU + BwAAAk1TRnQBSQFMAwEBAAFYAQABWAEAARABAAEQAQAE/wEJAQAI/wFCAU0BNgEEBgABNgEEAgABKAMA AUADAAEQAwABAQEAAQgGAAEEGAABgAIAAYADAAKAAQABgAMAAYABAAGAAQACgAIAA8ABAAHAAdwBwAEA AfABygGmAQABMwUAATMBAAEzAQABMwEAAjMCAAMWAQADHAEAAyIBAAMpAQADVQEAA00BAANCAQADOQEA AYABfAH/AQACUAH/AQABkwEAAdYBAAH/AewBzAEAAcYB1gHvAQAB1gLnAQABkAGpAa0CAAH/ATMDAAFm @@ -156,11 +156,11 @@ AQAB/wGZAf8BAAH/AcwCAAH/AcwBMwEAAf8BzAFmAQAB/wHMAZkBAAH/AswBAAH/AcwB/wEAAv8BMwEA AcwB/wFmAQAC/wGZAQAC/wHMAQACZgH/AQABZgH/AWYBAAFmAv8BAAH/AmYBAAH/AWYB/wEAAv8BZgEA ASEBAAGlAQADXwEAA3cBAAOGAQADlgEAA8sBAAOyAQAD1wEAA90BAAPjAQAD6gEAA/EBAAP4AQAB8AH7 - Af8BAAGkAqABAAOAAwAB/wIAAf8DAAL/AQAB/wMAAf8BAAH/AQAC/wIAA/+CAAH/AQcK7wEHAfQyAAEH - DAABETIAAe8LAAHvMwAB7wsAAe8zAAHvCwAB7zMAAe8LAAHvMwAB7wsAAe8zAAHvCwAB7zMAAe8BAArv - AW0BDjIAAe8LAAEOAfEyAAHxAQ4EAAHv+AABQgFNAT4HAAE+AwABKAMAAUADAAEQAwABAQEAAQEFAAGA - FwAD/wEAAv8GAAL/BgABgAEBBgABgAEBBgABnwH5BgABnwH5BgABnwH5BgABnwH5BgABnwH5BgABnwH5 - BgABgAEBBgABgAEBBgABgAH/BgAC/wYAAv8GAAL/BgAL + Af8BAAGkAqABAAOAAwAB/wIAAf8DAAL/AQAB/wMAAf8BAAH/AQAC/wIAA/8BABD/MAAQ/zAAAf8B8wzv + AfMB/zAAAf8B7AwAAewB/zAAAf8B6gEPChIBDwHqAf8wAAH/AhIK/wISAf8wAAH/AhIK/wISAf8wAAH/ + AhIK/wISAf8wAAH/AhIK/wISAf8wAAH/AhIK/wISAf8wAAH/AhIK/wISAf8wAAH/ARIBDwoSAQ8B6gH/ + MAAB/wHqBQABDwUSAeoB8QH/MAAB/wH3AQ4DAAEPAe8I/zAAEP8wABD/MAABQgFNAT4HAAE+AwABKAMA + AUADAAEQAwABAQEAAQEFAAGAFwAD/4EACw== diff --git a/client/MaestroShared/Configuration/ConfigurationInfo.cs b/client/MaestroShared/Configuration/ConfigurationInfo.cs index 5f3cf2b0..978f87b8 100644 --- a/client/MaestroShared/Configuration/ConfigurationInfo.cs +++ b/client/MaestroShared/Configuration/ConfigurationInfo.cs @@ -109,6 +109,7 @@ namespace MaestroShared.Configuration { public class OctopusMetadata : MetadataProvider { public bool DisablePlaceHolderCheck { get; set; } public bool DisableStoryCheck { get; set; } + public Connection Local { get; set; } } public class TrafficMetadata : MetadataProvider { diff --git a/client/OctopusClient/OctopusIDSelector.Designer.cs b/client/OctopusClient/OctopusIDSelector.Designer.cs index 3d92bff0..af3b5c4b 100644 --- a/client/OctopusClient/OctopusIDSelector.Designer.cs +++ b/client/OctopusClient/OctopusIDSelector.Designer.cs @@ -48,6 +48,7 @@ this.treeOctopus.Size = new System.Drawing.Size(300, 322); this.treeOctopus.TabIndex = 5; this.treeOctopus.KeyDown += new System.Windows.Forms.KeyEventHandler(this.treeContent_KeyDown); + this.treeOctopus.MouseDown += new System.Windows.Forms.MouseEventHandler(this.treeOctopus_MouseDown); // // pSearch // diff --git a/client/OctopusClient/OctopusIDSelector.cs b/client/OctopusClient/OctopusIDSelector.cs index cc6de4d9..8d046f1d 100644 --- a/client/OctopusClient/OctopusIDSelector.cs +++ b/client/OctopusClient/OctopusIDSelector.cs @@ -148,6 +148,7 @@ namespace OctopusClient { if (lookupPlaceHolderId != null && lookupPlaceHolderId.Equals(mosObject.ObjID)) { placeHolderNode.Checked = true; storyNode.Expand(); + placeHolderNode.EnsureVisible(); } } } @@ -203,9 +204,9 @@ namespace OctopusClient { SendMessage(tvw.Handle, TVM_SETITEM, IntPtr.Zero, ref tvi); } - public bool LookupByStory(string storyId) { + public void LookupByStory(string storyId) { if (String.IsNullOrEmpty(storyId)) - return false; + return; var rundown = client.GetRundownsByStoryID(storyId)?.FirstOrDefault(); if (rundown == null) { var storyFolder = client.GetStoryFoldersByStoryID(storyId)?.FirstOrDefault(); @@ -238,12 +239,11 @@ namespace OctopusClient { lookupStoryId = null; if (selectedNode == null) MessageBox.Show("Nincs találat."); - return selectedNode != null; } - public bool LookupByPlaceHolder(string placeHolderId) { + public void LookupByPlaceHolder(string placeHolderId) { if (String.IsNullOrEmpty(placeHolderId)) - return false; + return; var rundown = client.GetRundownsByPlaceHolderId(placeHolderId)?.FirstOrDefault(); if (rundown == null) { var storyFolder = client.GetStoryFoldersByPlaceHolderId(placeHolderId)?.FirstOrDefault(); @@ -278,7 +278,6 @@ namespace OctopusClient { lookupPlaceHolderId = null; if (selectedNode == null) MessageBox.Show("Nincs találat."); - return selectedNode != null; } private void OnTypeCheckChanged(object sender, EventArgs e) { @@ -356,6 +355,11 @@ namespace OctopusClient { else LookupByStory(txtFilter.Text); } + + private void treeOctopus_MouseDown(object sender, MouseEventArgs e) { + if (e.Button == MouseButtons.Right) + treeOctopus.SelectedNode = treeOctopus.GetNodeAt(e.X, e.Y); + } } public class OctopusAPIMessage : IMessage { diff --git a/client/PlanAIRClient/TrafficIDSelector.cs b/client/PlanAIRClient/TrafficIDSelector.cs index 2b1d005d..81dc0c07 100644 --- a/client/PlanAIRClient/TrafficIDSelector.cs +++ b/client/PlanAIRClient/TrafficIDSelector.cs @@ -139,6 +139,19 @@ namespace TrafficClient { private void tableLayoutPanelSearch_Paint(object sender, PaintEventArgs e) { ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, Color.LightGray, ButtonBorderStyle.Solid); // dotted border } + + public bool LookupByMaterialID(string id) { + //TrafficItem result = trafficAPI.GetMaterials(id, false); + return false; + } + + public bool LookupByPromoID(string id) { + return false; + } + + public bool LookupByADID(string id) { + return false; + } } public class TrafficItem { diff --git a/server/-configuration/run-mediacube-server-bsh.launch b/server/-configuration/run-mediacube-server-bsh.launch index d0240306..f957593d 100644 --- a/server/-configuration/run-mediacube-server-bsh.launch +++ b/server/-configuration/run-mediacube-server-bsh.launch @@ -19,7 +19,7 @@ - + diff --git a/server/-configuration/scheduledjobs.json b/server/-configuration/scheduledjobs.json index 3b28b6bc..452149c3 100644 --- a/server/-configuration/scheduledjobs.json +++ b/server/-configuration/scheduledjobs.json @@ -66,7 +66,7 @@ ] }, { - "active": true, + "active": false, "name" : "OCTOPUS adatok szinkronizálása", "template": "sync-octopus.xml", "executeimmediate": true, diff --git a/server/user.jobengine.osgi.commons/src/user/commons/nosql/NoSQLUtils.java b/server/user.jobengine.osgi.commons/src/user/commons/nosql/NoSQLUtils.java index 74b22230..3852a610 100644 --- a/server/user.jobengine.osgi.commons/src/user/commons/nosql/NoSQLUtils.java +++ b/server/user.jobengine.osgi.commons/src/user/commons/nosql/NoSQLUtils.java @@ -22,17 +22,17 @@ public class NoSQLUtils { Pass = System.getProperty("jobengine.nosql.db.password"); } - public static DB getNoSQLDB(String url, String user, String pass) { - return NoSQLClient.getDB(Url, User, Pass); + public static BasicDBList asDBList(BasicDBObject obj, String name) { + BasicDBList result = null; + if (obj.containsKey(name) && (obj.get(name) instanceof BasicDBList)) + result = (BasicDBList) obj.get(name); + return result; } - public static DB getDB() { - DB result = null; - try { - result = NoSQLClient.getDB(NoSQLUtils.Url, NoSQLUtils.User, NoSQLUtils.Pass); - } catch (Exception e) { - logger.error(e); - } + public static BasicDBObject asDBObject(BasicDBObject obj, String name) { + BasicDBObject result = null; + if (obj.containsKey(name) && (obj.get(name) instanceof BasicDBObject)) + result = (BasicDBObject) obj.get(name); return result; } @@ -46,4 +46,28 @@ public class NoSQLUtils { return result; } + public static List asList(BasicDBObject obj, String name) { + List result = null; + if (obj != null) { + BasicDBList dbList = asDBList(obj, name); + if (dbList != null) + result = Arrays.asList(dbList.toArray(new BasicDBObject[obj.size()])); + } + return result; + } + + public static DB getDB() { + DB result = null; + try { + result = NoSQLClient.getDB(NoSQLUtils.Url, NoSQLUtils.User, NoSQLUtils.Pass); + } catch (Exception e) { + logger.error(e); + } + return result; + } + + public static DB getNoSQLDB(String url, String user, String pass) { + return NoSQLClient.getDB(Url, User, Pass); + } + } diff --git a/server/user.jobengine.osgi.commons/src/user/commons/octopus/OctopusAPI.java b/server/user.jobengine.osgi.commons/src/user/commons/octopus/OctopusAPI.java index a6824a92..36d4e792 100644 --- a/server/user.jobengine.osgi.commons/src/user/commons/octopus/OctopusAPI.java +++ b/server/user.jobengine.osgi.commons/src/user/commons/octopus/OctopusAPI.java @@ -6,9 +6,6 @@ import java.util.Calendar; import java.util.Date; import java.util.List; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - import com.ibm.nosql.json.api.BasicDBList; import com.ibm.nosql.json.api.BasicDBObject; import com.ibm.nosql.json.api.DB; @@ -21,10 +18,17 @@ import user.commons.CalendarUtils; import user.commons.nosql.NoSQLUtils; public class OctopusAPI implements IOctopusAPI { - private static final Logger logger = LogManager.getLogger(); + private static final String _ID = "_id"; + private static final String OBJID = "objId"; + private static final String $DATE = "$date"; + private static final String SCHEDULEDSTART = "scheduledStart"; + private static final String STORYID = "storyId"; + private static final String $ELEMMATCH = "$elemMatch"; + //private static final Logger logger = LogManager.getLogger(); + private static final String SLUGS = "slugs"; private static final String ID = "id"; private static final String STORY_FOLDER = "story_folder"; - private static final String MOS_OBJECTS = "mosObjects"; + private static final String MOSOBJECTS = "mosObjects"; private static final String RUNDOWN = "rundown"; public static final String RUNDOWN_COLLECTION_NAME = "rundowns"; public static final String STORY_COLLECTION_NAME = "stories"; @@ -54,7 +58,7 @@ public class OctopusAPI implements IOctopusAPI { List mosObjectsResult = new ArrayList<>(); DBCollection collection = db.getCollection(STORY_COLLECTION_NAME); DBCursor find = collection - .find(new BasicDBObject(MOS_OBJECTS, new BasicDBObject("$elemMatch", new BasicDBObject(ID, id))), + .find(new BasicDBObject(MOSOBJECTS, new BasicDBObject($ELEMMATCH, new BasicDBObject(ID, id))), new BasicDBObject(ID, 1).append("name", 1).append("modified", 1).append(STORY_FOLDER, 1).append("type", 1).append("mosObjects", 1)) .sort(new BasicDBObject("name", 1)); if (find.hasNext()) @@ -74,28 +78,48 @@ public class OctopusAPI implements IOctopusAPI { return mosObjectsResult; } - private List getParentsByReferences(DBCursor find, DBCollection collection, List referenceObjects, String referenceName) { + private List getParentsByReferences(List references, DBCollection collection, String referenceName) { List result = null; + List rundownIDs = getIDsFromReferences(references, referenceName); + BasicDBObject query = (BasicDBObject) QueryBuilder.start().put(ID).in(rundownIDs).get(); + DBCursor find = collection.find(query); if (find.hasNext()) - referenceObjects = find.toArray(); - if (referenceObjects != null) { - List rundownIDs = getIDsFromReferences(referenceObjects, referenceName); - BasicDBObject query = (BasicDBObject) QueryBuilder.start().put("id").in(rundownIDs).get(); - find = collection.find(query); - if (find.hasNext()) - result = find.toArray(); + result = find.toArray(); + return result; + } + + private List getReferencedObjects(List stories, String referenceCollectionName, String referenceField) { + List ids = null; + for (DBObject story : stories) { + List references = NoSQLUtils.asList((BasicDBObject) story, referenceField); + if (references == null) + continue; + for (BasicDBObject reference : references) { + if (reference == null || !reference.containsKey(ID)) + continue; + long id = reference.getLong(ID); + if (ids == null) + ids = new ArrayList<>(); + ids.add(id); + } } + + List result = null; + DBCollection rundownCollection = db.getCollection(referenceCollectionName); + BasicDBObject query = (BasicDBObject) QueryBuilder.start().put(ID).in(ids).get(); + DBCursor findParents = rundownCollection.find(query); + if (findParents.hasNext()) + result = findParents.toArray(); return result; } @Override public List getRundownByStoryID(long storyID) { List result = null; - List queryedRundownsFromStoryCollection = null; - DBCollection storyCollection = db.getCollection(STORY_COLLECTION_NAME); DBCollection rundownCollection = db.getCollection(RUNDOWN_COLLECTION_NAME); - DBCursor find = storyCollection.find(new BasicDBObject("id", storyID), new BasicDBObject(RUNDOWN, 1).append("_id", 0)); - result = getParentsByReferences(find, rundownCollection, queryedRundownsFromStoryCollection, RUNDOWN); + DBCursor find = rundownCollection.find(new BasicDBObject(SLUGS, new BasicDBObject($ELEMMATCH, new BasicDBObject(STORYID, storyID)))); + if (find.hasNext()) + result = find.toArray(); return result; } @@ -112,12 +136,12 @@ public class OctopusAPI implements IOctopusAPI { if (scheduledDate == null) { query = builder.get(); } else { - query = builder.and(QueryBuilder.start("scheduledStart").greaterThanEquals(calStart.getTime()).get(), - QueryBuilder.start("scheduledStart").lessThan(calStop.getTime()).get()).get(); + query = builder.and(QueryBuilder.start(SCHEDULEDSTART).greaterThanEquals(calStart.getTime()).get(), + QueryBuilder.start(SCHEDULEDSTART).lessThan(calStop.getTime()).get()).get(); } //logger.info(query); - DBCursor find = collection.find(query).sort(new BasicDBObject("scheduledStart", new BasicDBList(1, "$date"))); + DBCursor find = collection.find(query).sort(new BasicDBObject(SCHEDULEDSTART, new BasicDBList(1, $DATE))); if (find.hasNext()) result = find.toArray(); return result; @@ -125,17 +149,14 @@ public class OctopusAPI implements IOctopusAPI { @Override public List getRundownsByPlaceHolderId(String placeHolderID) { - List result = null; DBCollection storyCollection = db.getCollection(STORY_COLLECTION_NAME); - DBCollection rundownCollection = db.getCollection(RUNDOWN_COLLECTION_NAME); - List queryedRundownsFromStoryCollection = null; - BasicDBObject id = new BasicDBObject("objId", placeHolderID); - BasicDBObject elemmatch = new BasicDBObject("$elemMatch", id); - BasicDBObject mosObjects = new BasicDBObject(MOS_OBJECTS, elemmatch); //db.testStoryCollection.find({"mosObjects": {$elemMatch: {"globalId": "OCTOPUS-ECHOTV-2429902"}}}) - DBCursor find = storyCollection.find(mosObjects); - result = getParentsByReferences(find, rundownCollection, queryedRundownsFromStoryCollection, RUNDOWN); - return result; + BasicDBObject criteria = new BasicDBObject(MOSOBJECTS, new BasicDBObject($ELEMMATCH, new BasicDBObject(OBJID, placeHolderID))); + BasicDBObject filter = new BasicDBObject(RUNDOWN, 1).append(_ID, 0); + DBCursor find = storyCollection.find(criteria, filter); + if (!find.hasNext()) + return null; + return getReferencedObjects(find.toArray(), RUNDOWN_COLLECTION_NAME, RUNDOWN); } @Override @@ -156,7 +177,7 @@ public class OctopusAPI implements IOctopusAPI { // { rundown: { $elemMatch: { id: 44622396 } }} DBCursor find = collection - .find(new BasicDBObject(RUNDOWN, new BasicDBObject("$elemMatch", new BasicDBObject(ID, rundownID))), new BasicDBObject(ID, 1) + .find(new BasicDBObject(RUNDOWN, new BasicDBObject($ELEMMATCH, new BasicDBObject(ID, rundownID))), new BasicDBObject(ID, 1) .append("parentStoryId", 1).append("name", 1).append("modified", 1).append(RUNDOWN, 1).append("format", 1).append("mosObjects", 1)) .sort(new BasicDBObject("name", 1)); if (find.hasNext()) @@ -192,9 +213,9 @@ public class OctopusAPI implements IOctopusAPI { public List getStoriesByPlaceHolderId(String placeHolderID) { List result = new ArrayList<>(); DBCollection storyCollection = db.getCollection(STORY_COLLECTION_NAME); - BasicDBObject globalId = new BasicDBObject("objId", placeHolderID); - BasicDBObject elemmatch = new BasicDBObject("$elemMatch", globalId); - BasicDBObject mosObjects = new BasicDBObject(MOS_OBJECTS, elemmatch); + BasicDBObject globalId = new BasicDBObject(OBJID, placeHolderID); + BasicDBObject elemmatch = new BasicDBObject($ELEMMATCH, globalId); + BasicDBObject mosObjects = new BasicDBObject(MOSOBJECTS, elemmatch); DBCursor find = storyCollection.find(mosObjects); if (find.hasNext()) result.add(find.next()); @@ -206,7 +227,7 @@ public class OctopusAPI implements IOctopusAPI { List result = null; DBCollection collection = db.getCollection(STORY_COLLECTION_NAME); DBCursor find = collection - .find(new BasicDBObject(STORY_FOLDER, new BasicDBObject("$elemMatch", new BasicDBObject(ID, storyFolderId))), new BasicDBObject(ID, 1) + .find(new BasicDBObject(STORY_FOLDER, new BasicDBObject($ELEMMATCH, new BasicDBObject(ID, storyFolderId))), new BasicDBObject(ID, 1) .append("parentStoryId", 1).append("name", 1).append("modified", 1).append(STORY_FOLDER, 1).append("format", 1).append("mosObjects", 1)) .sort(new BasicDBObject("name", 1)); if (find.hasNext()) @@ -226,26 +247,23 @@ public class OctopusAPI implements IOctopusAPI { @Override public List getStoryFolders(long storyID) { - List result = null; - List queryedStory_FoldersFromStoryCollection = null; DBCollection storyCollection = db.getCollection(STORY_COLLECTION_NAME); - DBCollection storyFolderCollection = db.getCollection(STORY_FOLDER_COLLECTION_NAME); - DBCursor find = storyCollection.find(new BasicDBObject("id", storyID), new BasicDBObject(STORY_FOLDER, 1).append("_id", 0)); - result = getParentsByReferences(find, storyFolderCollection, queryedStory_FoldersFromStoryCollection, STORY_FOLDER); - return result; + BasicDBObject criteria = new BasicDBObject(ID, storyID); + BasicDBObject filter = new BasicDBObject(STORY_FOLDER, 1).append(_ID, 0); + DBCursor find = storyCollection.find(criteria, filter); + if (!find.hasNext()) + return null; + return getReferencedObjects(find.toArray(), STORY_FOLDER_COLLECTION_NAME, STORY_FOLDER); } @Override public List getStoryFoldersByPlaceHolderId(String placeHolderID) { - List result = null; DBCollection storyCollection = db.getCollection(STORY_COLLECTION_NAME); - DBCollection rundownCollection = db.getCollection(STORY_FOLDER_COLLECTION_NAME); - List queryedRundownsFromStoryCollection = null; - BasicDBObject globalId = new BasicDBObject("objId", placeHolderID); - BasicDBObject elemmatch = new BasicDBObject("$elemMatch", globalId); - BasicDBObject mosObjects = new BasicDBObject("mosObjects", elemmatch); - DBCursor find = storyCollection.find(mosObjects, new BasicDBObject(STORY_FOLDER, 1).append("_id", 0)); - result = getParentsByReferences(find, rundownCollection, queryedRundownsFromStoryCollection, STORY_FOLDER); - return result; + BasicDBObject criteria = new BasicDBObject(MOSOBJECTS, new BasicDBObject($ELEMMATCH, new BasicDBObject(OBJID, placeHolderID))); + BasicDBObject filter = new BasicDBObject(STORY_FOLDER, 1).append(_ID, 0); + DBCursor find = storyCollection.find(criteria, filter); + if (!find.hasNext()) + return null; + return getReferencedObjects(find.toArray(), STORY_FOLDER_COLLECTION_NAME, STORY_FOLDER); } } diff --git a/server/user.jobengine.osgi.commons/src/user/commons/octopus/OctopusDataMiner.java b/server/user.jobengine.osgi.commons/src/user/commons/octopus/OctopusDataMiner.java index 09ab483c..d402724c 100644 --- a/server/user.jobengine.osgi.commons/src/user/commons/octopus/OctopusDataMiner.java +++ b/server/user.jobengine.osgi.commons/src/user/commons/octopus/OctopusDataMiner.java @@ -123,26 +123,14 @@ public class OctopusDataMiner implements Runnable { progressListenerList.add(IProgressEventListener.class, listener); } - private BasicDBList asDBList(BasicDBObject obj, String name) { - BasicDBList result = null; - if (obj.containsKey(name) && (obj.get(name) instanceof BasicDBList)) - result = (BasicDBList) obj.get(name); - return result; - } - - private BasicDBObject asDBObject(BasicDBObject obj, String name) { - BasicDBObject result = null; - if (obj.containsKey(name) && (obj.get(name) instanceof BasicDBObject)) - result = (BasicDBObject) obj.get(name); - return result; - } - private Map buildRundownReferences(BasicDBList rundowns) { Map result = new HashMap<>(); List rundownsList = NoSQLUtils.asList(rundowns); for (BasicDBObject rundown : rundownsList) { long rundownId = rundown.getLong(ID); - List slugs = NoSQLUtils.asList(asDBList(rundown, SLUGS)); + List slugs = NoSQLUtils.asList(rundown, SLUGS); + if (slugs == null) + continue; for (BasicDBObject slug : slugs) { if (!slug.containsKey(STORYID)) continue; @@ -168,20 +156,20 @@ public class OctopusDataMiner implements Runnable { while (cursor.hasNext()) { BasicDBObject story = (BasicDBObject) cursor.next(); long storyId = story.getLong(ID); - BasicDBList rundownRef = asDBList(story, REF_RUNDOWN); + BasicDBList rundownRef = NoSQLUtils.asDBList(story, REF_RUNDOWN); if (rundownRef != null) { if (storedStoryRundowns == null) storedStoryRundowns = new HashMap<>(); storedStoryRundowns.put(storyId, rundownRef); } - BasicDBList storyFolderRef = asDBList(story, REF_STORYFOLDER); + BasicDBList storyFolderRef = NoSQLUtils.asDBList(story, REF_STORYFOLDER); if (storyFolderRef != null) { if (storedStoryStoryFolders == null) storedStoryStoryFolders = new HashMap<>(); storedStoryStoryFolders.put(storyId, storyFolderRef); } - BasicDBList storyMosObjects = asDBList(story, MOS_OBJECTS); + BasicDBList storyMosObjects = NoSQLUtils.asDBList(story, MOS_OBJECTS); if (storyMosObjects != null) { if (storedStoryMosObjects == null) storedStoryMosObjects = new HashMap<>(); @@ -201,7 +189,9 @@ public class OctopusDataMiner implements Runnable { List storyFolderList = NoSQLUtils.asList(storyFolders); for (BasicDBObject storyFolder : storyFolderList) { long storyFolderId = storyFolder.getLong(ID); - List stories = NoSQLUtils.asList(asDBList(storyFolder, STORIES)); + List stories = NoSQLUtils.asList(storyFolder, STORIES); + if (stories == null) + continue; long position = 1; for (BasicDBObject story : stories) { long storyId = story.getLong(ID); @@ -290,7 +280,7 @@ public class OctopusDataMiner implements Runnable { break; } case MOS: { - BasicDBObject mosObject = asDBObject(content, OBJECT); + BasicDBObject mosObject = NoSQLUtils.asDBObject(content, OBJECT); if (mosObject != null && !mosObject.isEmpty()) { if (mosObject.containsKey(OBJ_ID)) { String objID = mosObject.getString(OBJ_ID); @@ -301,10 +291,12 @@ public class OctopusDataMiner implements Runnable { } default: { if (content.containsKey(CONTENT)) { - List innerContents = NoSQLUtils.asList(asDBList(content, CONTENT)); - for (BasicDBObject actualInnerContent : innerContents) { - if (actualInnerContent != null && actualInnerContent.isEmpty()) - scriptContent += GetContent(actualInnerContent); + List innerContents = NoSQLUtils.asList(content, CONTENT); + if (innerContents != null) { + for (BasicDBObject actualInnerContent : innerContents) { + if (actualInnerContent != null && actualInnerContent.isEmpty()) + scriptContent += GetContent(actualInnerContent); + } } } break; @@ -322,8 +314,10 @@ public class OctopusDataMiner implements Runnable { // } private String GetCustomColumnValue(String columnName, BasicDBObject story) { + List customColumns = NoSQLUtils.asList(story, CUSTOM_COLUMNS); + if (customColumns == null) + return null; String result = null; - List customColumns = NoSQLUtils.asList(asDBList(story, CUSTOM_COLUMNS)); for (BasicDBObject customColumn : customColumns) { if (!customColumn.containsKey(LABEL)) continue; @@ -350,8 +344,10 @@ public class OctopusDataMiner implements Runnable { } private BasicDBList GetRelevantMOSObjects(BasicDBObject story) { + List mosObjects = NoSQLUtils.asList(story, MOS_OBJECTS); + if (mosObjects == null) + return null; BasicDBList result = null; - List mosObjects = NoSQLUtils.asList(asDBList(story, MOS_OBJECTS)); for (BasicDBObject mosObject : mosObjects) { if (!mosObject.containsKey(MOS_ID)) continue; @@ -366,12 +362,12 @@ public class OctopusDataMiner implements Runnable { } private String GetScriptContent(BasicDBObject story) { - BasicDBObject script = asDBObject(story, SCRIPT); + BasicDBObject script = NoSQLUtils.asDBObject(story, SCRIPT); if (script == null || script.isEmpty()) return null; - List body = NoSQLUtils.asList(asDBList(script, BODY)); - if (body.size() == 0) + List body = NoSQLUtils.asList(script, BODY); + if (body == null || body.size() == 0) return null; StringBuilder sb = new StringBuilder(); @@ -381,7 +377,9 @@ public class OctopusDataMiner implements Runnable { sb.append(bodyItem.getString(LABEL)); sb.append(LINEFEED); } - List contents = NoSQLUtils.asList(asDBList(bodyItem, CONTENT)); + List contents = NoSQLUtils.asList(bodyItem, CONTENT); + if (contents == null) + continue; for (BasicDBObject content : contents) { sb.append(GetContent(content)); } @@ -411,7 +409,7 @@ public class OctopusDataMiner implements Runnable { String json = response.readEntity(String.class); BasicDBObject resultObject = (BasicDBObject) JSONUtil.jsonToDbObject(json); if (resultObject != null) - result = asDBObject(resultObject, RESULT); + result = NoSQLUtils.asDBObject(resultObject, RESULT); logger.trace(EXIT); return result; } @@ -423,7 +421,7 @@ public class OctopusDataMiner implements Runnable { String json = response.readEntity(String.class); BasicDBObject resultObject = (BasicDBObject) JSONUtil.jsonToDbObject(json); if (resultObject != null) - result = asDBList(resultObject, RESULT); + result = NoSQLUtils.asDBList(resultObject, RESULT); logger.trace(EXIT); return result; } @@ -436,7 +434,7 @@ public class OctopusDataMiner implements Runnable { String json = response.readEntity(String.class); BasicDBObject resultObject = (BasicDBObject) JSONUtil.jsonToDbObject(json); if (resultObject != null) - result = asDBObject(resultObject, RESULT); + result = NoSQLUtils.asDBObject(resultObject, RESULT); logger.trace(EXIT); return result; } @@ -448,7 +446,7 @@ public class OctopusDataMiner implements Runnable { String json = response.readEntity(String.class); BasicDBObject resultObject = (BasicDBObject) JSONUtil.jsonToDbObject(json); if (resultObject != null) - result = asDBList(resultObject, RESULT); + result = NoSQLUtils.asDBList(resultObject, RESULT); /* teszt */ List list = NoSQLUtils.asList(result); @@ -543,7 +541,7 @@ public class OctopusDataMiner implements Runnable { String name = rundown.containsKey(NAME) ? rundown.getString(NAME) : null; logger.info("Checking rundown {} {}", name, rundown.get(SCHEDULED_START)); BasicDBObject rundownWithStories = queryRundown(rundownID); - BasicDBList stories = asDBList(rundownWithStories, SLUGS); + BasicDBList stories = NoSQLUtils.asDBList(rundownWithStories, SLUGS); if (stories != null) storeRundownStories(stories, lastUpdateTime); rundown.put(SCHEDULED_START, toDate(rundown, SCHEDULED_START)); @@ -654,7 +652,7 @@ public class OctopusDataMiner implements Runnable { long storyFolderID = storyFolder.getLong(ID); BasicDBObject storyFoldersWithStories = queryStoryFolder(storyFolderID); - BasicDBList stories = asDBList(storyFoldersWithStories, STORIES); + BasicDBList stories = NoSQLUtils.asDBList(storyFoldersWithStories, STORIES); if (stories != null) storeStoryFolderStories(stories, lastUpdateTime); storyFolder.put(MODIFIED, toDate(storyFolder, MODIFIED)); -- 2.54.0