mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Merged HEAD-BUG-FIX (4.3/Cloud) to HEAD (4.3/Cloud)
70596: Merged WAT1 (4.3/Cloud) to HEAD-BUG-FIX (4.3/Cloud) 67363: ACE-1264, ACE-1270: added support for the facet value results, to include display-name for userID and mimetype. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@70828 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
71
source/java/org/alfresco/repo/jscript/ScriptFacetResult.java
Normal file
71
source/java/org/alfresco/repo/jscript/ScriptFacetResult.java
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2014 Alfresco Software Limited.
|
||||||
|
*
|
||||||
|
* This file is part of Alfresco
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.alfresco.repo.jscript;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scriptable facet. Specific for use by Search script as part of the object model.
|
||||||
|
*
|
||||||
|
* @author Jamal Kaabi-Mofrad
|
||||||
|
*/
|
||||||
|
public class ScriptFacetResult implements Serializable
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = -6948514033689491531L;
|
||||||
|
|
||||||
|
private final String facetValue;
|
||||||
|
private final String facetLabel;
|
||||||
|
private final int hits;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param facetValue the facet value. e.g. the content creator's userID
|
||||||
|
* @param facetLabel the display name of the {@code facetValue}. e.g. jdoe => John Doe
|
||||||
|
* @param hits the number of hits
|
||||||
|
*/
|
||||||
|
public ScriptFacetResult(String facetValue, String facetLabel, int hits)
|
||||||
|
{
|
||||||
|
this.facetValue = facetValue;
|
||||||
|
this.facetLabel = facetLabel;
|
||||||
|
this.hits = hits;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the facetValue
|
||||||
|
*/
|
||||||
|
public String getFacetValue()
|
||||||
|
{
|
||||||
|
return this.facetValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the facetLabel
|
||||||
|
*/
|
||||||
|
public String getFacetLabel()
|
||||||
|
{
|
||||||
|
return this.facetLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the hits
|
||||||
|
*/
|
||||||
|
public int getHits()
|
||||||
|
{
|
||||||
|
return this.hits;
|
||||||
|
}
|
||||||
|
}
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
* Copyright (C) 2005-2014 Alfresco Software Limited.
|
||||||
*
|
*
|
||||||
* This file is part of Alfresco
|
* This file is part of Alfresco
|
||||||
*
|
*
|
||||||
@@ -20,6 +20,7 @@ package org.alfresco.repo.jscript;
|
|||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
@@ -32,6 +33,7 @@ import org.alfresco.repo.management.subsystems.SwitchableApplicationContextFacto
|
|||||||
import org.alfresco.repo.model.Repository;
|
import org.alfresco.repo.model.Repository;
|
||||||
import org.alfresco.service.ServiceRegistry;
|
import org.alfresco.service.ServiceRegistry;
|
||||||
import org.alfresco.service.cmr.repository.ContentReader;
|
import org.alfresco.service.cmr.repository.ContentReader;
|
||||||
|
import org.alfresco.service.cmr.repository.MimetypeService;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeService;
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
import org.alfresco.service.cmr.repository.StoreRef;
|
import org.alfresco.service.cmr.repository.StoreRef;
|
||||||
@@ -891,15 +893,22 @@ public class Search extends BaseScopableProcessorExtension
|
|||||||
meta.put("numberFound", results.getNumberFound());
|
meta.put("numberFound", results.getNumberFound());
|
||||||
meta.put("hasMore", results.hasMore());
|
meta.put("hasMore", results.hasMore());
|
||||||
// results facets
|
// results facets
|
||||||
Map<String, Map<String, Integer>> facetMeta = new HashMap<>();
|
Map<String, List<ScriptFacetResult>> facetMeta = new HashMap<>();
|
||||||
for (FieldFacet ff: sp.getFieldFacets())
|
for (FieldFacet ff: sp.getFieldFacets())
|
||||||
{
|
{
|
||||||
// for each field facet, get the facet results
|
// for each field facet, get the facet results
|
||||||
List<Pair<String, Integer>> fs = results.getFieldFacet(ff.getField());
|
List<Pair<String, Integer>> fs = results.getFieldFacet(ff.getField());
|
||||||
HashMap<String, Integer> facets = new HashMap<>();
|
List<ScriptFacetResult> facets = new ArrayList<>();
|
||||||
for (Pair<String, Integer> f: fs)
|
for (Pair<String, Integer> f : fs)
|
||||||
{
|
{
|
||||||
facets.put(f.getFirst(), f.getSecond());
|
// ignore zero hit fields
|
||||||
|
if (f.getSecond() > 0)
|
||||||
|
{
|
||||||
|
String facetValue = f.getFirst();
|
||||||
|
Field field = getFieldType(ff.getField());
|
||||||
|
String label = (field == null) ? facetValue : field.getLabel(services, facetValue);
|
||||||
|
facets.add(new ScriptFacetResult(facetValue, label, f.getSecond()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// store facet results per field
|
// store facet results per field
|
||||||
facetMeta.put(ff.getField(), facets);
|
facetMeta.put(ff.getField(), facets);
|
||||||
@@ -952,4 +961,83 @@ public class Search extends BaseScopableProcessorExtension
|
|||||||
public String column;
|
public String column;
|
||||||
public boolean asc;
|
public boolean asc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Jamal Kaabi-Mofrad
|
||||||
|
*/
|
||||||
|
private enum Field
|
||||||
|
{
|
||||||
|
CREATOR("creator.__"), MODIFIER("modifier.__"), MIMETYPE("content.mimetype")
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
/*Package access level*/
|
||||||
|
String getLabel(ServiceRegistry services, String facetValue)
|
||||||
|
{
|
||||||
|
MimetypeService mimetypeService = services.getMimetypeService();
|
||||||
|
Map<String, String> mimetypes = mimetypeService.getDisplaysByMimetype();
|
||||||
|
String displayName = mimetypes.get(facetValue);
|
||||||
|
return displayName == null ? facetValue : displayName.trim();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private Field(String facetField)
|
||||||
|
{
|
||||||
|
this.facetField = facetField;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String facetField;
|
||||||
|
|
||||||
|
private String getFacetField()
|
||||||
|
{
|
||||||
|
return facetField;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default implementation which will return the full user name from
|
||||||
|
* the facetValue, if the facetValue represent a userID
|
||||||
|
*
|
||||||
|
* @param services the ServiceRegistry
|
||||||
|
* @param facetValue the facet value
|
||||||
|
* @return the full user name. If the user doesn't exist then, the
|
||||||
|
* {@code facetValue} will be returned.
|
||||||
|
*/
|
||||||
|
/*Package access level*/
|
||||||
|
String getLabel(ServiceRegistry services, String facetValue)
|
||||||
|
{
|
||||||
|
String name = null;
|
||||||
|
|
||||||
|
final NodeRef personRef = services.getPersonService().getPersonOrNull(facetValue);
|
||||||
|
if (personRef != null)
|
||||||
|
{
|
||||||
|
final NodeService nodeService = services.getNodeService();
|
||||||
|
final String firstName = (String) nodeService.getProperty(personRef, ContentModel.PROP_FIRSTNAME);
|
||||||
|
final String lastName = (String) nodeService.getProperty(personRef, ContentModel.PROP_LASTNAME);
|
||||||
|
name = (firstName != null ? firstName + " " : "") + (lastName != null ? lastName : "");
|
||||||
|
}
|
||||||
|
return name == null ? facetValue : name.trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the facet field.
|
||||||
|
*
|
||||||
|
* @param facetField the facet field value
|
||||||
|
* @return the Field type
|
||||||
|
*/
|
||||||
|
private Field getFieldType(String facetField)
|
||||||
|
{
|
||||||
|
if (facetField == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Field val : Field.values())
|
||||||
|
{
|
||||||
|
if (facetField.endsWith(val.getFacetField()))
|
||||||
|
{
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user