List<SharePojo> results = _driver.searchShares("community", communityIdStrList.toString(), "kibana-int-" + mode, responseObj);
if (null == results) {
results = new ArrayList<SharePojo>(0);
}
if (_deleteMode) { // This one is very straightforward ... find the share and delete it...
DashboardProxyResultPojo deleteResult = new DashboardProxyResultPojo();
deleteResult._id = command;
for (SharePojo result: results) {
if (command.equals(result.getTitle())) {
_driver.removeShare(result.get_id().toString(), responseObj);
deleteResult.found = responseObj.isSuccess();
return new StringRepresentation(deleteResult.toApi(), MediaType.APPLICATION_JSON);
}
}//TESTED (7)
deleteResult.found = false;
return new StringRepresentation(deleteResult.toApi(), MediaType.APPLICATION_JSON);
}//TESTED (7)
else if (command.equalsIgnoreCase("_search")) { // Search
//Filter: (really need to start indexing)
String titleFilter = null;
if (null != _postData) { // pull out filter
Matcher m = extractFilter.matcher(_postData);
if (m.find()) {
titleFilter = m.group(1).toLowerCase();
if (titleFilter.isEmpty()) {
titleFilter = null;
}
}
}//TESTED (3)
// Perform search
DashboardProxySearchResultPojo reply = new DashboardProxySearchResultPojo();
reply.hits = new DashboardProxySearchResultPojo.Hits();
reply.hits.hits = new LinkedList<DashboardProxySearchResultPojo.Hits.HitElement>();
int hits = 0;
for (SharePojo result: results) {
if ((null == titleFilter) || ((null != result.getTitle()) && (result.getTitle().toLowerCase().contains(titleFilter)))) {
DashboardProxySearchResultPojo.Hits.HitElement hitEl = new DashboardProxySearchResultPojo.Hits.HitElement();
hitEl._id = result.getTitle();
hitEl._source.title = result.getTitle();
hitEl._source.dashboard= result.getShare();
reply.hits.hits.add(hitEl);
hits++;
}
}//TESTED (2, 3)
reply.hits.total = hits;
return new StringRepresentation(reply.toApi(), MediaType.APPLICATION_JSON);
}//TESTED (2, 3)
else if (null == _postData) { // GET
DashboardProxyResultPojo getResult = new DashboardProxyResultPojo();
getResult._id = command;
for (SharePojo result: results) {
if (command.equals(result.getTitle())) {
getResult.found = true;
getResult._source = new DashboardPojo("guest", "guest");
getResult._source.title = command;
getResult._source.dashboard = result.getShare();
return new StringRepresentation(getResult.toApi(), MediaType.APPLICATION_JSON);
}
}
getResult.found = false;
return new StringRepresentation(getResult.toApi(), MediaType.APPLICATION_JSON);
}//TESTED (6)
else { // We're overwriting the existing share with a new JSON file...
DashboardProxyResultPojo putResult = new DashboardProxyResultPojo();
putResult._id = command;
// Extract dashboard from JSON:
DashboardPojo dash = DashboardPojo.fromApi(_postData, DashboardPojo.class);
SharePojo shareToUpdate = null;
for (SharePojo result: results) {
if (command.equals(result.getTitle())) {
shareToUpdate = result;
break;
}
}//TESTED (4, 5)
if (null == shareToUpdate) { //create a new share...
putResult.found = false;
SharePojo addedShare = _driver.addShareJSON(command, "Added by infinit.e.records.server", "kibana-int-" + mode, dash.dashboard, responseObj);
if (null != addedShare) {
for (String commIdStr: communityIds) {
_driver.addShareToCommunity(addedShare.get_id().toString(), "Added by infinit.e.records.server", commIdStr, responseObj);
}
}
}//TESTED (4, 5)
else { // update an existing share
putResult.found = true;
// Update communities:
for (SharePojo.ShareCommunityPojo shareShare: shareToUpdate.getCommunities()) {
String shareShareIdStr = shareShare.get_id().toString();
if (communityIds.contains(shareShareIdStr)) {
communityIds.remove(shareShareIdStr);
}
else {
_driver.removeShareFromCommunity(shareToUpdate.get_id().toString(), shareShareIdStr, responseObj);
}
}//TESTED (5)
for (String commIdStr: communityIds) {
_driver.addShareToCommunity(shareToUpdate.get_id().toString(), "Added by infinit.e.records.server", commIdStr, responseObj);
}//TESTED (5)
// Update content:
_driver.updateShareJSON(shareToUpdate.get_id().toString(), shareToUpdate.getTitle(), shareToUpdate.getDescription(),
shareToUpdate.getType(), dash.dashboard, responseObj);
}//TESTED (4,5)
return new StringRepresentation(putResult.toApi(), MediaType.APPLICATION_JSON);
}
}//TESTED (See below)