|
1 | 1 | package org.ecocean.media; |
2 | 2 |
|
| 3 | +import com.fasterxml.jackson.core.JsonGenerator; |
| 4 | +import com.fasterxml.jackson.core.JsonProcessingException; |
3 | 5 | import java.io.File; |
4 | 6 | import java.io.FileOutputStream; |
5 | 7 | import java.io.IOException; |
|
21 | 23 | import org.apache.commons.lang3.builder.ToStringBuilder; |
22 | 24 | import org.ecocean.AccessControl; |
23 | 25 | import org.ecocean.Annotation; |
| 26 | +import org.ecocean.Base; |
24 | 27 | import org.ecocean.CommonConfiguration; |
25 | 28 | import org.ecocean.Encounter; |
26 | 29 | import org.ecocean.ia.Task; |
|
42 | 45 | /** |
43 | 46 | * MediaAsset describes a photo or video that can be displayed or used for processing and analysis. |
44 | 47 | */ |
45 | | -public class MediaAsset implements java.io.Serializable { |
| 48 | +public class MediaAsset extends Base implements java.io.Serializable { |
46 | 49 | static final long serialVersionUID = 8844223450447974780L; |
| 50 | + @Override public String opensearchIndexName() { return "media_asset"; } |
47 | 51 | protected int id = MediaAssetFactory.NOT_SAVED; |
48 | 52 |
|
49 | 53 | protected String uuid = null; |
@@ -93,6 +97,10 @@ public class MediaAsset implements java.io.Serializable { |
93 | 97 | * To be called by AssetStore factory method. |
94 | 98 | */ |
95 | 99 |
|
| 100 | + public MediaAsset() { |
| 101 | + this(MediaAssetFactory.NOT_SAVED, null, null); |
| 102 | + } |
| 103 | + |
96 | 104 | public MediaAsset(final AssetStore store, final JSONObject params) { |
97 | 105 | // this(store, params, null); |
98 | 106 | this(MediaAssetFactory.NOT_SAVED, store, params); |
@@ -146,10 +154,18 @@ private String getUrlString(final URL url) { |
146 | 154 | return url.toExternalForm(); |
147 | 155 | } |
148 | 156 |
|
149 | | - public int getId() { |
| 157 | + public int getIdInt() { |
150 | 158 | return id; |
151 | 159 | } |
152 | 160 |
|
| 161 | + public String getId() { |
| 162 | + return String.valueOf(id); |
| 163 | + } |
| 164 | + |
| 165 | + public void setId(String s) { |
| 166 | + id = Integer.parseInt(s); |
| 167 | + } |
| 168 | + |
153 | 169 | public void setId(int i) { |
154 | 170 | id = i; |
155 | 171 | } |
@@ -346,6 +362,10 @@ public void setDerivationMethodAsString(String d) { |
346 | 362 | } |
347 | 363 | } |
348 | 364 |
|
| 365 | + public long getVersion() { |
| 366 | + return this.revision; |
| 367 | + } |
| 368 | + |
349 | 369 | public long setRevision() { |
350 | 370 | this.revision = System.currentTimeMillis(); |
351 | 371 | return this.revision; |
@@ -1143,7 +1163,7 @@ public static void updateStandardChildrenBackground(final String context, int id |
1143 | 1163 | } |
1144 | 1164 |
|
1145 | 1165 | public void updateStandardChildrenBackground(String context) { // convenience |
1146 | | - updateStandardChildrenBackground(context, this.getId()); |
| 1166 | + updateStandardChildrenBackground(context, this.getIdInt()); |
1147 | 1167 | } |
1148 | 1168 |
|
1149 | 1169 | public void setKeywords(ArrayList<Keyword> kws) { |
@@ -1363,7 +1383,7 @@ public MediaAssetMetadata setMinimalMetadata(int width, int height, String conte |
1363 | 1383 | } |
1364 | 1384 |
|
1365 | 1385 | public void refreshIAStatus(Shepherd myShepherd) { |
1366 | | - String s = IBEISIA.parseDetectionStatus(Integer.toString(this.getId()), myShepherd); |
| 1386 | + String s = IBEISIA.parseDetectionStatus(Integer.toString(this.getIdInt()), myShepherd); |
1367 | 1387 |
|
1368 | 1388 | if (s != null) this.setDetectionStatus(s); |
1369 | 1389 | String cumulative = null; |
@@ -1614,4 +1634,69 @@ public int hashCode() { |
1614 | 1634 | public void setIsValidImageForIA(Boolean value) { |
1615 | 1635 | if (value == null) { validImageForIA = null; } else { validImageForIA = value; } |
1616 | 1636 | } |
| 1637 | + |
| 1638 | + public JSONObject opensearchMapping() { |
| 1639 | + JSONObject map = super.opensearchMapping(); |
| 1640 | + JSONObject keywordType = new JSONObject("{\"type\": \"keyword\"}"); |
| 1641 | + |
| 1642 | + // "id" is done in Base |
| 1643 | + map.put("acmId", keywordType); |
| 1644 | + map.put("uuid", keywordType); |
| 1645 | + map.put("detectionStatus", keywordType); |
| 1646 | + |
| 1647 | + map.put("encounters", new org.json.JSONObject("{\"type\": \"nested\"}")); |
| 1648 | + map.put("annotations", new org.json.JSONObject("{\"type\": \"nested\"}")); |
| 1649 | + |
| 1650 | + return map; |
| 1651 | + } |
| 1652 | + |
| 1653 | + public void opensearchDocumentSerializer(JsonGenerator jgen, Shepherd myShepherd) |
| 1654 | + throws IOException, JsonProcessingException { |
| 1655 | + super.opensearchDocumentSerializer(jgen, myShepherd); |
| 1656 | + |
| 1657 | + jgen.writeStringField("acmId", this.getAcmId()); |
| 1658 | + jgen.writeStringField("uuid", this.getUUID()); |
| 1659 | + jgen.writeStringField("filename", this.getFilename()); |
| 1660 | + jgen.writeStringField("userFilename", this.getUserFilename()); |
| 1661 | + jgen.writeStringField("detectionStatus", this.getDetectionStatus()); |
| 1662 | + URL url = this.safeURL(); |
| 1663 | + jgen.writeStringField("url", (url == null) ? null : url.toString()); |
| 1664 | + jgen.writeArrayFieldStart("encounters"); |
| 1665 | + for (Encounter enc : Encounter.findAllByMediaAsset(this, myShepherd)) { |
| 1666 | + jgen.writeStartObject(); |
| 1667 | + jgen.writeStringField("id", enc.getId()); |
| 1668 | + jgen.writeStringField("taxonomy", enc.getTaxonomyString()); |
| 1669 | + jgen.writeEndObject(); |
| 1670 | + } |
| 1671 | + jgen.writeEndArray(); |
| 1672 | + jgen.writeArrayFieldStart("annotations"); |
| 1673 | + for (Annotation ann : this.getAnnotations()) { |
| 1674 | + jgen.writeStartObject(); |
| 1675 | + jgen.writeStringField("id", ann.getId()); |
| 1676 | + jgen.writeStringField("acmId", ann.getAcmId()); |
| 1677 | + jgen.writeStringField("iaClass", ann.getIAClass()); |
| 1678 | + jgen.writeStringField("viewpoint", ann.getViewpoint()); |
| 1679 | + jgen.writeEndObject(); |
| 1680 | + } |
| 1681 | + jgen.writeEndArray(); |
| 1682 | + } |
| 1683 | + |
| 1684 | + @Override public String getAllVersionsSql() { |
| 1685 | + return "SELECT CAST(\"ID\" AS text), \"REVISION\" AS version FROM \"MEDIAASSET\" WHERE \"PARENTID\" IS NULL ORDER BY version"; |
| 1686 | + } |
| 1687 | + |
| 1688 | + @Override public Base getById(Shepherd myShepherd, String id) { |
| 1689 | + return myShepherd.getMediaAsset(id); |
| 1690 | + } |
| 1691 | + |
| 1692 | + // comment cruft only needed for Base class |
| 1693 | + @Override public String getComments() { |
| 1694 | + return null; |
| 1695 | + } |
| 1696 | + |
| 1697 | + @Override public void setComments(final String comments) { |
| 1698 | + } |
| 1699 | + |
| 1700 | + @Override public void addComments(final String newComments) { |
| 1701 | + } |
1617 | 1702 | } |
0 commit comments