use of org.alfresco.rest.api.model.UserInfo in project records-management by Alfresco.
the class FilePlanChildrenRelation method readAll.
@Override
@WebApiDescription(title = "Return a paged list of file plan children (record categories) for the container identified by 'filePlanId'")
public CollectionWithPagingInfo<RecordCategory> readAll(String filePlanId, Parameters parameters) {
// validate parameters
checkNotBlank("filePlanId", filePlanId);
mandatory("parameters", parameters);
QName filePlanType = apiUtils.getFilePlanType();
if (// rm site not created
filePlanType == null) {
throw new EntityNotFoundException(filePlanId);
}
NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(filePlanId, filePlanType);
// list record categories
Set<QName> searchTypeQNames = searchTypesFactory.buildSearchTypesForFilePlanEndpoint();
// FIXME this param null
List<FilterProp> filterProps = apiUtils.getListChildrenFilterProps(parameters, null);
final PagingResults<FileInfo> pagingResults = fileFolderService.list(parentNodeRef, null, searchTypeQNames, null, apiUtils.getSortProperties(parameters), filterProps, Util.getPagingRequest(parameters.getPaging()));
final List<FileInfo> page = pagingResults.getPage();
Map<String, UserInfo> mapUserInfo = new HashMap<>();
List<RecordCategory> nodes = new AbstractList<RecordCategory>() {
@Override
public RecordCategory get(int index) {
FileInfo info = page.get(index);
return nodesModelFactory.createRecordCategory(info, parameters, mapUserInfo, true);
}
@Override
public int size() {
return page.size();
}
};
FilePlan sourceEntity = null;
if (parameters.includeSource()) {
FileInfo info = fileFolderService.getFileInfo(parentNodeRef);
sourceEntity = nodesModelFactory.createFilePlan(info, parameters, mapUserInfo, true);
}
return CollectionWithPagingInfo.asPaged(parameters.getPaging(), nodes, pagingResults.hasMoreItems(), pagingResults.getTotalResultCount().getFirst(), sourceEntity);
}
use of org.alfresco.rest.api.model.UserInfo in project records-management by Alfresco.
the class UnfiledContainerChildrenRelation method create.
@Override
@WebApiDescription(title = "Create one (or more) nodes as children of a unfiled container identified by 'unfiledContainerId'")
public List<UnfiledContainerChild> create(String unfiledContainerId, final List<UnfiledContainerChild> nodeInfos, Parameters parameters) {
checkNotBlank("unfiledContainerId", unfiledContainerId);
mandatory("nodeInfos", nodeInfos);
mandatory("parameters", parameters);
final NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(unfiledContainerId, RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER);
// Create the nodes
RetryingTransactionCallback<List<NodeRef>> callback = new RetryingTransactionCallback<List<NodeRef>>() {
public List<NodeRef> execute() {
List<NodeRef> createdNodes = new LinkedList<>();
for (UnfiledContainerChild nodeInfo : nodeInfos) {
NodeRef newNodeRef = apiUtils.createRMNode(parentNodeRef, nodeInfo, parameters);
createdNodes.add(newNodeRef);
}
return createdNodes;
}
};
List<NodeRef> createdNodes = transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
// Get the nodes info
List<UnfiledContainerChild> result = new LinkedList<>();
Map<String, UserInfo> mapUserInfo = new HashMap<>();
for (NodeRef newNodeRef : createdNodes) {
FileInfo info = fileFolderService.getFileInfo(newNodeRef);
apiUtils.postActivity(info, parentNodeRef, ActivityType.FILE_ADDED);
result.add(nodesModelFactory.createUnfiledContainerChild(info, parameters, mapUserInfo, false));
}
return result;
}
use of org.alfresco.rest.api.model.UserInfo in project alfresco-remote-api by Alfresco.
the class AuditImpl method getAuditEntry.
@Override
public AuditEntry getAuditEntry(String auditAppId, long auditEntryId, Parameters parameters) {
checkEnabled();
AuditService.AuditApplication auditApplication = findAuditAppByIdOr404(auditAppId);
// Execute the query
AuditQueryParameters params = new AuditQueryParameters();
params.setApplicationName(auditApplication.getName());
params.setFromId(auditEntryId);
params.setToId(auditEntryId + 1);
List<String> includeParam = new ArrayList<>();
if (parameters != null) {
includeParam.addAll(parameters.getInclude());
}
// Add values for single get
includeParam.add(PARAM_INCLUDE_VALUES);
final List<AuditEntry> results = new ArrayList<>();
// create the callback for auditQuery method
final AuditQueryCallback callback = new AuditQueryCallback() {
public boolean valuesRequired() {
return ((includeParam != null) && (includeParam.contains(PARAM_INCLUDE_VALUES)));
}
public boolean handleAuditEntryError(Long entryId, String errorMsg, Throwable error) {
throw new AlfrescoRuntimeException("Failed to retrieve audit data.", error);
}
public boolean handleAuditEntry(Long entryId, String applicationName, String userName, long time, Map<String, Serializable> values) {
UserInfo userInfo = Node.lookupUserInfo(userName, new HashMap<>(0), personService);
AuditEntry auditEntry = new AuditEntry(entryId, auditAppId, userInfo, new Date(time), values);
results.add(auditEntry);
return true;
}
};
auditService.auditQuery(callback, params, 1);
if (results.size() != 1) {
throw new EntityNotFoundException("" + auditEntryId);
}
return results.get(0);
}
use of org.alfresco.rest.api.model.UserInfo in project alfresco-remote-api by Alfresco.
the class QuickShareLinksImpl method getQuickShareInfo.
private QuickShareLink getQuickShareInfo(NodeRef nodeRef, Map<String, Object> map, boolean noAuth, List<String> includeParam) {
String sharedId = (String) map.get("sharedId");
try {
Map<QName, Serializable> nodeProps = nodeService.getProperties(nodeRef);
ContentData cd = (ContentData) nodeProps.get(ContentModel.PROP_CONTENT);
String mimeType = cd.getMimetype();
String mimeTypeName = mimeTypeService.getDisplaysByMimetype().get(mimeType);
ContentInfo contentInfo = new ContentInfo(mimeType, mimeTypeName, cd.getSize(), cd.getEncoding());
Map<String, UserInfo> mapUserInfo = new HashMap<>(2);
// note: if noAuth mode then don't return userids (to limit disclosure and be consistent with v0 internal)
boolean displayNameOnly = noAuth;
UserInfo modifiedByUser = Node.lookupUserInfo((String) nodeProps.get(ContentModel.PROP_MODIFIER), mapUserInfo, personService, displayNameOnly);
// TODO review - should we return sharedByUser for authenticated users only ?? (not exposed by V0 but needed for "find")
String sharedByUserId = (String) nodeProps.get(QuickShareModel.PROP_QSHARE_SHAREDBY);
UserInfo sharedByUser = Node.lookupUserInfo(sharedByUserId, mapUserInfo, personService, displayNameOnly);
QuickShareLink qs = new QuickShareLink(sharedId, nodeRef.getId());
qs.setName((String) map.get("name"));
qs.setTitle((String) map.get("title"));
qs.setDescription((String) map.get("description"));
qs.setContent(contentInfo);
qs.setModifiedAt((Date) map.get("modified"));
qs.setModifiedByUser(modifiedByUser);
qs.setSharedByUser(sharedByUser);
qs.setExpiresAt((Date) map.get("expiryDate"));
// note: if noAuth mode then do not return allowable operations (eg. but can be optionally returned when finding shared links)
if (!noAuth) {
// Cached document
Node doc = null;
if (includeParam.contains(PARAM_INCLUDE_ALLOWABLEOPERATIONS)) {
if (quickShareService.canDeleteSharedLink(nodeRef, sharedByUserId)) {
// the allowable operations for the shared link
qs.setAllowableOperations(Collections.singletonList(Nodes.OP_DELETE));
}
doc = getNode(nodeRef, includeParam, mapUserInfo);
List<String> allowableOps = doc.getAllowableOperations();
// the allowable operations for the actual file being shared
qs.setAllowableOperationsOnTarget(allowableOps);
}
// in noAuth mode we don't return the path info
if (includeParam.contains(PARAM_INCLUDE_PATH)) {
qs.setPath(nodes.lookupPathInfo(nodeRef, null));
}
if (includeParam.contains(PARAM_INCLUDE_PROPERTIES)) {
if (doc == null) {
doc = getNode(nodeRef, includeParam, mapUserInfo);
}
// Create a map from node properties excluding properties already in this QuickShareLink
Map<String, Object> filteredNodeProperties = filterProps(doc.getProperties(), EXCLUDED_PROPS);
qs.setProperties(filteredNodeProperties);
}
if (includeParam.contains(PARAM_INCLUDE_ISFAVORITE)) {
if (doc == null) {
doc = getNode(nodeRef, includeParam, mapUserInfo);
}
qs.setIsFavorite(doc.getIsFavorite());
}
if (includeParam.contains(PARAM_INCLUDE_ASPECTNAMES)) {
if (doc == null) {
doc = getNode(nodeRef, includeParam, mapUserInfo);
}
qs.setAspectNames(doc.getAspectNames());
}
}
return qs;
} catch (InvalidSharedIdException ex) {
logger.warn("Unable to find: " + sharedId);
throw new EntityNotFoundException(sharedId);
} catch (InvalidNodeRefException inre) {
logger.warn("Unable to find: " + sharedId + " [" + inre.getNodeRef() + "]");
throw new EntityNotFoundException(sharedId);
}
}
use of org.alfresco.rest.api.model.UserInfo 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());
}
Aggregations