use of org.alfresco.rest.api.model.Node in project alfresco-remote-api by Alfresco.
the class FavouritesImpl method getFavourite.
private Favourite getFavourite(PersonFavourite personFavourite, Parameters parameters) {
Favourite fav = new Favourite();
fav.setTargetGuid(personFavourite.getNodeRef().getId());
fav.setCreatedAt(personFavourite.getCreatedAt());
Target target = getTarget(personFavourite, parameters);
fav.setTarget(target);
// REPO-1147 allow retrieving additional properties
if (parameters.getInclude().contains(PARAM_INCLUDE_PROPERTIES)) {
List<String> includeProperties = new LinkedList<>();
includeProperties.add(PARAM_INCLUDE_PROPERTIES);
// get node representation with only properties included
Node node = nodes.getFolderOrDocument(personFavourite.getNodeRef(), null, null, includeProperties, null);
// Create a map from node properties excluding properties already in this Favorite
Map<String, Object> filteredNodeProperties = filterProps(node.getProperties(), EXCLUDED_PROPS);
if (filteredNodeProperties.size() > 0) {
fav.setProperties(filteredNodeProperties);
}
}
return fav;
}
use of org.alfresco.rest.api.model.Node in project alfresco-remote-api by Alfresco.
the class PeopleImpl method uploadAvatarContent.
@Override
public Person uploadAvatarContent(String personId, BasicContentInfo contentInfo, InputStream stream, Parameters parameters) {
if (!thumbnailService.getThumbnailsEnabled()) {
throw new DisabledServiceException("Thumbnail generation has been disabled.");
}
personId = validatePerson(personId);
checkCurrentUserOrAdmin(personId);
NodeRef personNode = personService.getPerson(personId);
NodeRef avatarOrigNodeRef = getAvatarOriginal(personNode);
if (avatarOrigNodeRef != null) {
deleteAvatar(avatarOrigNodeRef);
}
QName origAvatarQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "origAvatar");
nodeService.addAspect(personNode, ContentModel.ASPECT_PREFERENCES, null);
ChildAssociationRef assoc = nodeService.createNode(personNode, ContentModel.ASSOC_PREFERENCE_IMAGE, origAvatarQName, ContentModel.TYPE_CONTENT);
NodeRef avatar = assoc.getChildRef();
String avatarOriginalNodeId = avatar.getId();
// TODO do we still need this ? - backward compatible with JSF web-client avatar
nodeService.createAssociation(personNode, avatar, ContentModel.ASSOC_AVATAR);
Node n = nodes.updateContent(avatarOriginalNodeId, contentInfo, stream, parameters);
String mimeType = n.getContent().getMimeType();
if (mimeType.indexOf("image/") != 0) {
throw new InvalidArgumentException("Uploaded content must be an image (content type determined to be '" + mimeType + "')");
}
// create thumbnail synchronously
Rendition avatarR = new Rendition();
avatarR.setId("avatar");
renditions.createRendition(avatar, avatarR, false, parameters);
List<String> include = Arrays.asList(PARAM_INCLUDE_ASPECTNAMES, PARAM_INCLUDE_PROPERTIES);
return getPersonWithProperties(personId, include);
}
use of org.alfresco.rest.api.model.Node in project alfresco-remote-api by Alfresco.
the class NodeVersionsRelation method readAll.
/**
* List version history
*
* @param nodeId String id of (live) node
*/
@Override
@WebApiDescription(title = "Return version history as a paged list of version node infos")
public CollectionWithPagingInfo<Node> readAll(String nodeId, Parameters parameters) {
NodeRef nodeRef = nodes.validateOrLookupNode(nodeId, null);
VersionHistory vh = versionService.getVersionHistory(nodeRef);
Map<String, UserInfo> mapUserInfo = new HashMap<>(10);
List<String> includeParam = parameters.getInclude();
List<Node> collection = null;
if (vh != null) {
collection = new ArrayList<>(vh.getAllVersions().size());
for (Version v : vh.getAllVersions()) {
Node node = nodes.getFolderOrDocument(v.getFrozenStateNodeRef(), null, null, includeParam, mapUserInfo);
mapVersionInfo(v, node);
collection.add(node);
}
}
return listPage(collection, parameters.getPaging());
}
use of org.alfresco.rest.api.model.Node in project alfresco-remote-api by Alfresco.
the class SearchApiWebscript method execute.
@Override
public void execute(WebScriptRequest webScriptRequest, WebScriptResponse webScriptResponse) throws IOException {
try {
// Turn JSON into a Java object respresentation
SearchQuery searchQuery = extractJsonContent(webScriptRequest, assistant.getJsonHelper(), SearchQuery.class);
// Parse the parameters
Params params = getParams(webScriptRequest, searchQuery.getFields(), searchQuery.getInclude(), searchQuery.getPaging());
// Make a copy of the request
SearchRequestContext searchRequestContext = SearchRequestContext.from(searchQuery);
// Turn the SearchQuery json into the Java SearchParameters object
SearchParameters searchParams = searchMapper.toSearchParameters(params, searchQuery, searchRequestContext);
// Call searchService
ResultSet results = searchService.query(searchParams);
// Turn solr results into JSON
CollectionWithPagingInfo<Node> resultJson = resultMapper.toCollectionWithPagingInfo(params, searchRequestContext, searchQuery, results);
// Post-process the request and pass in params, eg. params.getFilter()
Object toRender = helper.processAdditionsToTheResponse(null, null, null, params, resultJson);
// Write response
setResponse(webScriptResponse, DEFAULT_SUCCESS);
renderJsonResponse(webScriptResponse, toRender, assistant.getJsonHelper());
} catch (Exception exception) {
renderException(exception, webScriptResponse, assistant);
}
}
use of org.alfresco.rest.api.model.Node in project alfresco-remote-api by Alfresco.
the class ResultMapper method toCollectionWithPagingInfo.
/**
* Turns the results into a CollectionWithPagingInfo
* @param params
* @param searchQuery
*@param results @return CollectionWithPagingInfo<Node>
*/
public CollectionWithPagingInfo<Node> toCollectionWithPagingInfo(Params params, SearchRequestContext searchRequestContext, SearchQuery searchQuery, ResultSet results) {
SearchContext context = null;
Integer total = null;
List<Node> noderesults = new ArrayList<Node>();
Map<String, UserInfo> mapUserInfo = new HashMap<>(10);
Map<NodeRef, List<Pair<String, List<String>>>> hightLighting = results.getHighlighting();
int notFound = 0;
boolean isHistory = searchRequestContext.getStores().contains(StoreMapper.HISTORY);
for (ResultSetRow row : results) {
Node aNode = getNode(row, params, mapUserInfo, isHistory);
if (aNode != null) {
float f = row.getScore();
List<HighlightEntry> highlightEntries = null;
List<Pair<String, List<String>>> high = hightLighting.get(row.getNodeRef());
if (high != null && !high.isEmpty()) {
highlightEntries = new ArrayList<HighlightEntry>(high.size());
for (Pair<String, List<String>> highlight : high) {
highlightEntries.add(new HighlightEntry(highlight.getFirst(), highlight.getSecond()));
}
}
aNode.setSearch(new SearchEntry(f, highlightEntries));
noderesults.add(aNode);
} else {
logger.debug("Unknown noderef returned from search results " + row.getNodeRef());
notFound++;
}
}
SolrJSONResultSet solrResultSet = findSolrResultSet(results);
if (solrResultSet != null) {
// We used Solr for this query
context = toSearchContext(solrResultSet, searchRequestContext, searchQuery, notFound);
}
total = setTotal(results);
return CollectionWithPagingInfo.asPaged(params.getPaging(), noderesults, results.hasMore(), total, null, context);
}
Aggregations