use of org.structr.web.entity.AbstractFile in project structr by structr.
the class ListFilesCommand method processMessage.
@Override
public void processMessage(final WebSocketMessage webSocketData) {
final SecurityContext securityContext = getWebSocket().getSecurityContext();
final String rawType = (String) webSocketData.getNodeData().get("type");
final Class type = SchemaHelper.getEntityClassForRawType(rawType);
final String sortOrder = webSocketData.getSortOrder();
final String sortKey = webSocketData.getSortKey();
final int pageSize = webSocketData.getPageSize();
final int page = webSocketData.getPage();
final PropertyKey sortProperty = StructrApp.key(type, sortKey);
final Query query = StructrApp.getInstance(securityContext).nodeQuery(type).includeDeletedAndHidden().sort(sortProperty).order("desc".equals(sortOrder));
// for image lists, suppress thumbnails
if (type.equals(Image.class)) {
query.and(StructrApp.key(Image.class, "isThumbnail"), false);
}
try {
// do search
List<NodeInterface> filteredResults = new LinkedList();
List<? extends GraphObject> resultList = query.getAsList();
// add only root folders to the list
for (GraphObject obj : resultList) {
if (obj instanceof AbstractFile) {
AbstractFile node = (AbstractFile) obj;
if (node.getParent() == null) {
filteredResults.add(node);
}
}
}
// save raw result count
int resultCountBeforePaging = filteredResults.size();
// set full result list
webSocketData.setResult(PagingHelper.subList(filteredResults, pageSize, page));
webSocketData.setRawResultCount(resultCountBeforePaging);
// send only over local connection
getWebSocket().send(webSocketData, true);
} catch (FrameworkException fex) {
logger.warn("", fex);
}
}
Aggregations