Modified database retrieval of recordings

This commit is contained in:
Paul Trudel 2023-01-19 15:23:54 +00:00
parent f7fe6b9b5d
commit 0ee382c493
5 changed files with 72 additions and 56 deletions

View File

@ -14,7 +14,7 @@ public interface XmlService {
String thumbnailToXml(Thumbnail thumbnail);
String callbackDataToXml(CallbackData callbackData);
String constructResponseFromRecordingsXml(String xml);
String constructPaginatedResponse(Page<?> page, String response);
String constructPaginatedResponse(Page<?> page, int offset, String response);
Recording xmlToRecording(String recordId, String xml);
String noRecordings();
}

View File

@ -74,61 +74,73 @@ public class RecordingServiceDbImpl implements RecordingService {
@Override
public String getRecordings2x(List<String> idList, List<String> states, Map<String, String> metadataFilters, int offset, Pageable pageable) {
// If no IDs or limit were provided return no recordings instead of every recording
if(idList.isEmpty() && pageable == null) return xmlService.noRecordings();
if((idList == null || idList.isEmpty()) && pageable == null) return xmlService.noRecordings();
logger.info("Retrieving all recordings");
Set<Recording> recordings = new HashSet<>();
recordings.addAll(dataStore.findAll(Recording.class));
Set<Recording> recordings = new HashSet<>(dataStore.findAll(Recording.class));
logger.info("{} recordings found", recordings.size());
Set<Recording> recordingsById = new HashSet<>();
for(String id: idList) {
List<Recording> r = dataStore.findRecordingsByMeetingId(id);
if(idList != null && !idList.isEmpty()) {
Set<Recording> recordingsById = new HashSet<>();
if(r == null || r.size() == 0) {
Recording recording = dataStore.findRecordingByRecordId(id);
if(recording != null) {
r = new ArrayList<>();
r.add(recording);
for(String id: idList) {
logger.info("Finding recordings using meeting ID with value {}", id);
List<Recording> recordingsByMeetingId = dataStore.findRecordingsByMeetingId(id);
if(recordingsByMeetingId == null || recordingsByMeetingId.isEmpty()) {
logger.info("Finding recordings using recording ID with value {}", id);
Recording recording = dataStore.findRecordingByRecordId(id);
if(recording != null) {
logger.info("Recording found");
recordingsById.add(recording);
}
} else {
logger.info("{} recordings found", recordingsByMeetingId.size());
recordingsById.addAll(recordingsByMeetingId);
}
}
if(r != null) recordingsById.addAll(r);
}
logger.info("Filtering recordings by meeting ID");
if(recordingsById.size() > 0) {
logger.info("Filtering recordings by ID");
recordings.retainAll(recordingsById);
}
logger.info("{} recordings remaining", recordings.size());
Set<Recording> recordingsByState = new HashSet<>();
for(String state: states) {
List<Recording> r = dataStore.findRecordingsByState(state);
if(r != null) recordingsByState.addAll(r);
logger.info("{} recordings remain", recordings.size());
}
logger.info("Filtering recordings by state");
if(recordingsByState.size() > 0) {
if(states != null && !states.isEmpty()) {
Set<Recording> recordingsByState = new HashSet<>();
for(String state: states) {
logger.info("Finding recordings by state {}", state);
List<Recording> r = dataStore.findRecordingsByState(state);
if(state != null && !state.isEmpty()) {
logger.info("{} recordings found", r.size());
recordingsByState.addAll(r);
}
}
logger.info("Filtering recordings by state");
recordings.retainAll(recordingsByState);
}
logger.info("{} recordings remaining", recordings.size());
List<Metadata> metadata = new ArrayList<>();
for(Map.Entry<String, String> metadataFilter: metadataFilters.entrySet()) {
List<Metadata> m = dataStore.findMetadataByFilter(metadataFilter.getKey(), metadataFilter.getValue());
if(m != null) metadata.addAll(m);
logger.info("{} recordings remain", recordings.size());
}
Set<Recording> recordingsByMetadata = new HashSet<>();
for(Metadata m: metadata) {
recordingsByMetadata.add(m.getRecording());
}
if(metadataFilters != null && !metadataFilters.isEmpty()) {
List<Metadata> metadata = new ArrayList<>();
logger.info("Filtering recordings by metadata");
if(recordingsByMetadata.size() > 0) {
for(Map.Entry<String, String> filter: metadataFilters.entrySet()) {
logger.info("Finding metadata using filter {} {}", filter.getKey(), filter.getValue());
List<Metadata> metadataByFilter = dataStore.findMetadataByFilter(filter.getKey(), filter.getValue());
if(metadataByFilter != null) {
logger.info("{} metadata found", metadataByFilter.size());
metadata.addAll(metadataByFilter);
}
}
Set<Recording> recordingsByMetadata = new HashSet<>();
for(Metadata m: metadata) recordingsByMetadata.add(m.getRecording());
logger.info("Filtering recordings by metadata");
recordings.retainAll(recordingsByMetadata);
logger.info("{} recordings remain", recordings.size());
}
logger.info("{} recordings remaining", recordings.size());
// If no/invalid pagination parameters were given do not paginate the response
if(pageable == null) {
@ -140,7 +152,7 @@ public class RecordingServiceDbImpl implements RecordingService {
String recordingsXml = xmlService.recordingsToXml(recordingsPage.getContent());
String response = xmlService.constructResponseFromRecordingsXml(recordingsXml);
return xmlService.constructPaginatedResponse(recordingsPage, response);
return xmlService.constructPaginatedResponse(recordingsPage, offset, response);
}
@Override

View File

@ -213,7 +213,7 @@ public class RecordingServiceFileImpl implements RecordingService {
Page<RecordingMetadata> recordingsPage = listToPage(recs, offset, pageable);
String response = recordingServiceHelper.getRecordings2x(new ArrayList<RecordingMetadata>(recordingsPage.getContent()));
return xmlService.constructPaginatedResponse(recordingsPage, response);
return xmlService.constructPaginatedResponse(recordingsPage, offset, response);
}
private RecordingMetadata getRecordingMetadata(File dir) {

View File

@ -72,7 +72,7 @@ public class XmlServiceImpl implements XmlService {
@Override
public String recordingToXml(Recording recording) {
logger.info("Converting {} to xml", recording);
// logger.info("Converting {} to xml", recording);
try {
setup();
Document document = builder.newDocument();
@ -125,7 +125,7 @@ public class XmlServiceImpl implements XmlService {
@Override
public String metadataToXml(Metadata metadata) {
logger.info("Converting {} to xml", metadata);
// logger.info("Converting {} to xml", metadata);
try {
setup();
@ -148,7 +148,7 @@ public class XmlServiceImpl implements XmlService {
@Override
public String playbackFormatToXml(PlaybackFormat playbackFormat) {
logger.info("Converting {} to xml", playbackFormat);
// logger.info("Converting {} to xml", playbackFormat);
try {
setup();
@ -187,7 +187,7 @@ public class XmlServiceImpl implements XmlService {
@Override
public String thumbnailToXml(Thumbnail thumbnail) {
logger.info("Converting {} to xml", thumbnail);
// logger.info("Converting {} to xml", thumbnail);
try {
setup();
@ -211,7 +211,7 @@ public class XmlServiceImpl implements XmlService {
@Override
public String callbackDataToXml(CallbackData callbackData) {
logger.info("Converting {} to xml", callbackData);
// logger.info("Converting {} to xml", callbackData);
try {
setup();
@ -296,7 +296,7 @@ public class XmlServiceImpl implements XmlService {
}
@Override
public String constructPaginatedResponse(Page<?> page, String response) {
public String constructPaginatedResponse(Page<?> page, int offset, String response) {
logger.info("Constructing paginated response");
try {
@ -315,7 +315,7 @@ public class XmlServiceImpl implements XmlService {
Document secondDoc;
Node node;
xml = pageableToXml(page.getPageable());
xml = pageableToXml(page.getPageable(), offset);
secondDoc = builder.parse(new ByteArrayInputStream(xml.getBytes()));
node = document.importNode(secondDoc.getDocumentElement(), true);
pagination.appendChild(node);
@ -326,8 +326,8 @@ public class XmlServiceImpl implements XmlService {
// Element last = createElement(document, "last", String.valueOf(page.isLast()));
// pagination.appendChild(last);
Element totalPages = createElement(document, "totalPages", String.valueOf(page.getTotalPages()));
pagination.appendChild(totalPages);
// Element totalPages = createElement(document, "totalPages", String.valueOf(page.getTotalPages()));
// pagination.appendChild(totalPages);
// Element first = createElement(document, "first", String.valueOf(page.isFirst()));
// pagination.appendChild(first);
@ -349,7 +349,7 @@ public class XmlServiceImpl implements XmlService {
return null;
}
private String pageableToXml(Pageable pageable) {
private String pageableToXml(Pageable pageable, int o) {
logger.info("Converting {} to xml", pageable);
try {
@ -373,7 +373,7 @@ public class XmlServiceImpl implements XmlService {
//
// rootElement.appendChild(sortElement);
Element offset = createElement(document, "offset", String.valueOf(pageable.getOffset()));
Element offset = createElement(document, "offset", String.valueOf(o));
rootElement.appendChild(offset);
Element limit = createElement(document, "limit", String.valueOf(pageable.getPageSize()));

View File

@ -1,11 +1,13 @@
#!/bin/bash
while getopts i:r:s:m: flag
while getopts i:r:s:m:o:l: flag
do
case "${flag}" in
i) MEETING_ID=${OPTARG};;
r) RECORD_ID=${OPTARG};;
s) STATE=${OPTARG};;
m) META=${OPTARG};;
o) OFFSET=${OPTARG};;
l) LIMIT=${OPTARG};;
esac
done
@ -17,7 +19,9 @@ QUERY=""
if ! [[ -z ${MEETING_ID+x} ]]; then QUERY+="meetingID=$MEETING_ID&"; fi
if ! [[ -z ${RECORD_ID+x} ]]; then QUERY+="recordID=$RECORD_ID&"; fi
if ! [[ -z ${STATE+x} ]]; then QUERY+="state=$STATE&"; fi
if ! [[ -z ${META+x} ]]; then QUERY+="meta=$META"; fi
if ! [[ -z ${META+x} ]]; then QUERY+="meta=$META&"; fi
if ! [[ -z ${OFFSET+x} ]]; then QUERY+="offset=$OFFSET&"; fi
if ! [[ -z ${LIMIT+x} ]]; then QUERY+="limit=$LIMIT"; fi
echo "query: $QUERY"
@ -26,7 +30,7 @@ if [ "${QUERY:$INDEX:1}" = "&" ]; then QUERY=${QUERY:0:$INDEX}; fi
echo "query: $QUERY"
SALT=
SALT=""
DATA="$ENDPOINT$QUERY$SALT"
echo "data: $DATA"