* @param size
* @return
*/
@SuppressWarnings("unchecked")
public JSONObject getJSONCompositeItem(MetsObject obj, String cid) {
CompositeItem item = obj.getCompositeItemMap().get(cid);
DescriptiveMetadata dmd = obj.getDmdMap().get(item.getDmdID());
JSONObject citem = null;
// Gets the descriptive metadata to be shown
if (dmd == null) {
if (StringUtils.isBlank(item.getLabel())) {
return null;
} else {
citem = new JSONObject();
citem.put("id", item.getId());
citem.put("title", item.getLabel());
}
} else {
DescriptiveMetadataHandler handler = new XSLTDescriptiveMetadataHandler(); //TODO: generalize, dynamic loading
citem = (JSONObject)JSONSerializer.toJSON(handler.getMetadata(dmd.getDmd(), "simple"));
citem.put("hasDmd", true);
}
citem.put("firstPage", item.getFirst().getSequentialOrder());
citem.put("lastPage", item.getLast().getSequentialOrder());
citem.put("label", item.getLabel());
if (!StringUtils.isBlank(item.getContentId())) {
citem.put("contentId", item.getContentId());
}
JSONObject dataStream = new JSONObject();
Map<String, Map<String, String>> map = item.getDataStreamsMap();
for (Map.Entry<String, Map<String, String>> stream: map.entrySet()) {
JSONObject streamJson = new JSONObject();
String streamKey = stream.getKey();
Map<String, String> streamMap = stream.getValue();
for (Map.Entry<String, String> entry : streamMap.entrySet()) {
streamJson.put(entry.getKey(), entry.getValue());
}
if (streamJson.entrySet().size() > 0) {
dataStream.put(streamKey, streamJson);
}
}
if (dataStream.entrySet().size() > 0) {
citem.put("dataStream", dataStream);
}
// Now add its childrens
JSONArray childrenJSON = new JSONArray();
List<AbstractItem> children = item.getChildren();
for (AbstractItem abstractItem : children) {
if (abstractItem instanceof CompositeItem) {
CompositeItem child = (CompositeItem) abstractItem;
JSONObject childJson = getJSONCompositeItem(obj, child.getId());
if (childJson != null) {
childrenJSON.add(childJson);
}
}
}