mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
First cut of Facebook integration:
1) Web Script framework extensions for supporting the development of Alfresco based Facebook applications 2) Sample Document Library Facebook application 3) FormData enhancements for supporting request args retrieval for multipart/form-data encoding 4) Sort order added to Search Javascript API Note: Stuff needs commenting, tidy up, but at least it's in SVN. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@7259 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -79,6 +79,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
import org.mozilla.javascript.ScriptableObject;
|
||||
import org.mozilla.javascript.UniqueTag;
|
||||
import org.mozilla.javascript.Wrapper;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -1884,13 +1885,17 @@ public class ScriptNode implements Serializable, Scopeable
|
||||
|
||||
private String processTemplate(String template, NodeRef templateRef, ScriptableObject args)
|
||||
{
|
||||
Object person = (Object)scope.get("person", scope);
|
||||
Object companyhome = (Object)scope.get("companyhome", scope);
|
||||
Object userhome = (Object)scope.get("userhome", scope);
|
||||
|
||||
// build default model for the template processing
|
||||
Map<String, Object> model = this.services.getTemplateService().buildDefaultModel(
|
||||
((ScriptNode)((Wrapper)scope.get("person", scope)).unwrap()).getNodeRef(),
|
||||
((ScriptNode)((Wrapper)scope.get("companyhome", scope)).unwrap()).getNodeRef(),
|
||||
((ScriptNode)((Wrapper)scope.get("userhome", scope)).unwrap()).getNodeRef(),
|
||||
templateRef,
|
||||
null);
|
||||
(person.equals(UniqueTag.NOT_FOUND)) ? null : ((ScriptNode)((Wrapper)person).unwrap()).getNodeRef(),
|
||||
(companyhome.equals(UniqueTag.NOT_FOUND)) ? null : ((ScriptNode)((Wrapper)companyhome).unwrap()).getNodeRef(),
|
||||
(userhome.equals(UniqueTag.NOT_FOUND)) ? null : ((ScriptNode)((Wrapper)userhome).unwrap()).getNodeRef(),
|
||||
templateRef,
|
||||
null);
|
||||
|
||||
// add the current node as either the document/space as appropriate
|
||||
if (this.getIsDocument())
|
||||
|
@@ -36,6 +36,7 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.search.ResultSet;
|
||||
import org.alfresco.service.cmr.search.ResultSetRow;
|
||||
import org.alfresco.service.cmr.search.SearchParameters;
|
||||
import org.alfresco.service.cmr.search.SearchService;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.Element;
|
||||
@@ -157,6 +158,32 @@ public final class Search extends BaseScopableProcessorExtension
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a Lucene search (sorted)
|
||||
*
|
||||
* @param search Lucene search string to execute
|
||||
* @param sortKey property name to sort on
|
||||
* @param asc true => ascending sort
|
||||
*
|
||||
* @return JavaScript array of Node results from the search - can be empty but not null
|
||||
*/
|
||||
public Scriptable luceneSearch(String search, String sortColumn, boolean asc)
|
||||
{
|
||||
if (search == null || search.length() == 0)
|
||||
{
|
||||
return Context.getCurrentContext().newArray(getScope(), 0);
|
||||
}
|
||||
if (sortColumn == null || sortColumn.length() == 0)
|
||||
{
|
||||
return luceneSearch(search);
|
||||
}
|
||||
|
||||
SortColumn[] sort = new SortColumn[1];
|
||||
sort[0] = new SortColumn(sortColumn, asc);
|
||||
Object[] results = query(search, sort, SearchService.LANGUAGE_LUCENE);
|
||||
return Context.getCurrentContext().newArray(getScope(), results);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a saved Lucene search
|
||||
*
|
||||
@@ -271,4 +298,82 @@ public final class Search extends BaseScopableProcessorExtension
|
||||
|
||||
return set.toArray(new Object[(set.size())]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the query
|
||||
*
|
||||
* Removes any duplicates that may be present (ID search can cause duplicates - it is better to remove them here)
|
||||
*
|
||||
* @param search Lucene search to execute
|
||||
* @param language Search language to use e.g. SearchService.LANGUAGE_LUCENE
|
||||
*
|
||||
* @return Array of Node objects
|
||||
*/
|
||||
private Object[] query(String search, SortColumn[] sort, String language)
|
||||
{
|
||||
LinkedHashSet<ScriptNode> set = new LinkedHashSet<ScriptNode>();
|
||||
|
||||
// perform the search against the repo
|
||||
ResultSet results = null;
|
||||
try
|
||||
{
|
||||
SearchParameters sp = new SearchParameters();
|
||||
sp.addStore(this.storeRef);
|
||||
sp.setLanguage(language);
|
||||
sp.setQuery(search);
|
||||
if (sort != null)
|
||||
{
|
||||
for (SortColumn sd : sort)
|
||||
{
|
||||
sp.addSort(sd.column, sd.asc);
|
||||
}
|
||||
}
|
||||
|
||||
results = this.services.getSearchService().query(sp);
|
||||
|
||||
if (results.length() != 0)
|
||||
{
|
||||
for (ResultSetRow row: results)
|
||||
{
|
||||
NodeRef nodeRef = row.getNodeRef();
|
||||
set.add(new ScriptNode(nodeRef, this.services, getScope()));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable err)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Failed to execute search: " + search, err);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (results != null)
|
||||
{
|
||||
results.close();
|
||||
}
|
||||
}
|
||||
|
||||
return set.toArray(new Object[(set.size())]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search sort column
|
||||
*/
|
||||
private class SortColumn
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param column column to sort on
|
||||
* @param asc sort direction
|
||||
*/
|
||||
SortColumn(String column, boolean asc)
|
||||
{
|
||||
this.column = column;
|
||||
this.asc = asc;
|
||||
}
|
||||
|
||||
public String column;
|
||||
public boolean asc;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -248,9 +248,18 @@ public class TemplateServiceImpl implements TemplateService
|
||||
}
|
||||
|
||||
// Put the common node reference into the model
|
||||
model.put(KEY_COMPANY_HOME, companyHome);
|
||||
model.put(KEY_USER_HOME, userHome);
|
||||
model.put(KEY_PERSON, person);
|
||||
if (companyHome != null)
|
||||
{
|
||||
model.put(KEY_COMPANY_HOME, companyHome);
|
||||
}
|
||||
if (userHome != null)
|
||||
{
|
||||
model.put(KEY_USER_HOME, userHome);
|
||||
}
|
||||
if (person != null)
|
||||
{
|
||||
model.put(KEY_PERSON, person);
|
||||
}
|
||||
|
||||
// add the template itself as "template" if it comes from content on a node
|
||||
if (template != null)
|
||||
|
Reference in New Issue
Block a user