use of org.alfresco.rest.api.model.UserInfo in project alfresco-remote-api by Alfresco.
the class AbstractNodeRelation method listNodeChildAssocs.
protected CollectionWithPagingInfo<Node> listNodeChildAssocs(List<ChildAssociationRef> childAssocRefs, Parameters parameters, Boolean isPrimary, boolean returnChild) {
Map<QName, String> qnameMap = new HashMap<>(3);
Map<String, UserInfo> mapUserInfo = new HashMap<>(10);
List<String> includeParam = parameters.getInclude();
List<Node> collection = new ArrayList<Node>(childAssocRefs.size());
for (ChildAssociationRef childAssocRef : childAssocRefs) {
if (isPrimary == null || (isPrimary == childAssocRef.isPrimary())) {
// minimal info by default (unless "include"d otherwise)
NodeRef nodeRef = (returnChild ? childAssocRef.getChildRef() : childAssocRef.getParentRef());
Node node = nodes.getFolderOrDocument(nodeRef, null, null, includeParam, mapUserInfo);
QName assocTypeQName = childAssocRef.getTypeQName();
if (!EXCLUDED_NS.contains(assocTypeQName.getNamespaceURI())) {
String assocType = qnameMap.get(assocTypeQName);
if (assocType == null) {
assocType = assocTypeQName.toPrefixString(namespaceService);
qnameMap.put(assocTypeQName, assocType);
}
node.setAssociation(new AssocChild(assocType, childAssocRef.isPrimary()));
collection.add(node);
}
}
}
return listPage(collection, parameters.getPaging());
}
use of org.alfresco.rest.api.model.UserInfo in project alfresco-remote-api by Alfresco.
the class AbstractNodeRelation method listNodePeerAssocs.
protected CollectionWithPagingInfo<Node> listNodePeerAssocs(List<AssociationRef> assocRefs, Parameters parameters, boolean returnTarget) {
Map<QName, String> qnameMap = new HashMap<>(3);
Map<String, UserInfo> mapUserInfo = new HashMap<>(10);
List<String> includeParam = parameters.getInclude();
List<Node> collection = new ArrayList<Node>(assocRefs.size());
for (AssociationRef assocRef : assocRefs) {
// minimal info by default (unless "include"d otherwise)
NodeRef nodeRef = (returnTarget ? assocRef.getTargetRef() : assocRef.getSourceRef());
Node node = nodes.getFolderOrDocument(nodeRef, null, null, includeParam, mapUserInfo);
QName assocTypeQName = assocRef.getTypeQName();
if (!EXCLUDED_NS.contains(assocTypeQName.getNamespaceURI())) {
String assocType = qnameMap.get(assocTypeQName);
if (assocType == null) {
assocType = assocTypeQName.toPrefixString(namespaceService);
qnameMap.put(assocTypeQName, assocType);
}
node.setAssociation(new Assoc(assocType));
collection.add(node);
}
}
return listPage(collection, parameters.getPaging());
}
use of org.alfresco.rest.api.model.UserInfo in project alfresco-remote-api by Alfresco.
the class AuditImpl method getQueryResultAuditEntries.
/**
* @param auditAppId
* @param propertyWalker
* @param includeParams
* @param maxItem
* @param forward
* @return
*/
public List<AuditEntry> getQueryResultAuditEntries(AuditService.AuditApplication auditApplication, AuditEntryQueryWalker propertyWalker, List<String> includeParam, int maxItem, Boolean forward) {
final List<AuditEntry> results = new ArrayList<>();
final String auditAppId = auditApplication.getKey().substring(1);
String auditApplicationName = auditApplication.getName();
// Execute the query
AuditQueryParameters params = new AuditQueryParameters();
// used to orderBY by field createdAt
params.setForward(forward);
params.setApplicationName(auditApplicationName);
params.setUser(propertyWalker.getCreatedByUser());
Long fromId = propertyWalker.getFromId();
Long toId = propertyWalker.getToId();
validateWhereBetween(auditAppId, fromId, toId);
Long fromTime = propertyWalker.getFromTime();
Long toTime = propertyWalker.getToTime();
validateWhereBetween(auditAppId, fromTime, toTime);
params.setFromTime(fromTime);
params.setToTime(toTime);
params.setFromId(fromId);
params.setToId(toId);
if (propertyWalker.getValuesKey() != null && propertyWalker.getValuesValue() != null) {
params.addSearchKey(propertyWalker.getValuesKey(), propertyWalker.getValuesValue());
}
final Map<String, UserInfo> mapUserInfo = new HashMap<>(10);
// 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, mapUserInfo, personService);
AuditEntry auditEntry = new AuditEntry(entryId, auditAppId, userInfo, new Date(time), values);
results.add(auditEntry);
return true;
}
};
auditService.auditQuery(callback, params, maxItem);
return results;
}
use of org.alfresco.rest.api.model.UserInfo in project alfresco-remote-api by Alfresco.
the class AuditImpl method getQueryResultAuditEntriesByNodeRef.
private List<AuditEntry> getQueryResultAuditEntriesByNodeRef(NodeRef nodeRef, AuditEntriesByNodeIdQueryWalker propertyWalker, List<String> includeParam, boolean forward, int limit) {
final List<AuditEntry> results = new ArrayList<>();
String auditAppId = "alfresco-access";
String auditApplicationName = AuthenticationUtil.runAs(new RunAsWork<String>() {
public String doWork() throws Exception {
return findAuditAppByIdOr404(auditAppId).getName();
}
}, AuthenticationUtil.getSystemUserName());
// 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;
}
};
// resolve the path of the node - note: this will also check read permission for current user
final String nodePath = ISO9075.decode(nodeService.getPath(nodeRef).toPrefixString(namespaceService));
Long fromTime = propertyWalker.getFromTime();
Long toTime = propertyWalker.getToTime();
validateWhereBetween(nodeRef.getId(), fromTime, toTime);
AuthenticationUtil.runAs(new RunAsWork<Object>() {
public Object doWork() throws Exception {
// QueryParameters
AuditQueryParameters pathParams = new AuditQueryParameters();
// used to orderBY by field createdAt
pathParams.setForward(forward);
pathParams.setUser(propertyWalker.getCreatedByUser());
pathParams.setFromTime(fromTime);
pathParams.setToTime(toTime);
pathParams.setApplicationName(auditApplicationName);
pathParams.addSearchKey("/" + auditAppId + "/transaction/path", nodePath);
auditService.auditQuery(callback, pathParams, limit);
AuditQueryParameters copyFromPathParams = new AuditQueryParameters();
// used to orderBY by field createdAt
copyFromPathParams.setForward(forward);
copyFromPathParams.setUser(propertyWalker.getCreatedByUser());
copyFromPathParams.setFromTime(fromTime);
copyFromPathParams.setToTime(toTime);
copyFromPathParams.setApplicationName(auditApplicationName);
copyFromPathParams.addSearchKey("/" + auditAppId + "/transaction/copy/from/path", nodePath);
auditService.auditQuery(callback, copyFromPathParams, limit);
AuditQueryParameters moveFromPathParams = new AuditQueryParameters();
// used to orderBY by field createdAt
moveFromPathParams.setForward(forward);
moveFromPathParams.setUser(propertyWalker.getCreatedByUser());
moveFromPathParams.setFromTime(fromTime);
moveFromPathParams.setToTime(toTime);
moveFromPathParams.setApplicationName(auditApplicationName);
moveFromPathParams.addSearchKey("/" + auditAppId + "/transaction/move/from/path", nodePath);
auditService.auditQuery(callback, moveFromPathParams, limit);
return null;
}
}, AuthenticationUtil.getSystemUserName());
return results;
}
use of org.alfresco.rest.api.model.UserInfo in project alfresco-remote-api by Alfresco.
the class ResultMapperTests method setupTests.
@BeforeClass
public static void setupTests() throws Exception {
Map<String, UserInfo> mapUserInfo = new HashMap<>();
mapUserInfo.put(AuthenticationUtil.getSystemUserName(), new UserInfo(AuthenticationUtil.getSystemUserName(), "sys", "sys"));
Map<QName, Serializable> nodeProps = new HashMap<>();
NodesImpl nodes = mock(NodesImpl.class);
ServiceRegistry sr = mock(ServiceRegistry.class);
DeletedNodes deletedNodes = mock(DeletedNodes.class);
nodes.setServiceRegistry(sr);
VersionService versionService = mock(VersionService.class);
VersionHistory versionHistory = mock(VersionHistory.class);
Map<String, Serializable> versionProperties = new HashMap<>();
versionProperties.put(Version.PROP_DESCRIPTION, "ver desc");
versionProperties.put(Version2Model.PROP_VERSION_TYPE, "v type");
when(versionHistory.getVersion(anyString())).thenAnswer(invocation -> {
return new VersionImpl(versionProperties, new NodeRef(StoreMapper.STORE_REF_VERSION2_SPACESSTORE, GUID.generate()));
});
NodeService nodeService = mock(NodeService.class);
when(versionService.getVersionHistory(any(NodeRef.class))).thenAnswer(invocation -> {
Object[] args = invocation.getArguments();
NodeRef aNode = (NodeRef) args[0];
return versionHistory;
});
when(nodeService.getProperties(any(NodeRef.class))).thenAnswer(invocation -> {
Object[] args = invocation.getArguments();
NodeRef aNode = (NodeRef) args[0];
if (StoreMapper.STORE_REF_VERSION2_SPACESSTORE.equals(aNode.getStoreRef())) {
nodeProps.put(Version2Model.PROP_QNAME_FROZEN_NODE_REF, new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, FROZEN_ID + aNode.getId()));
nodeProps.put(Version2Model.PROP_QNAME_VERSION_LABEL, FROZEN_VER);
}
return nodeProps;
});
when(sr.getVersionService()).thenReturn(versionService);
when(sr.getNodeService()).thenReturn(nodeService);
when(nodes.validateOrLookupNode(nullable(String.class), nullable(String.class))).thenAnswer(invocation -> {
Object[] args = invocation.getArguments();
String aNode = (String) args[0];
if (aNode.endsWith("" + VERSIONED_ID)) {
throw new EntityNotFoundException("" + VERSIONED_ID);
} else {
return new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, aNode);
}
});
// // NodeRef nodeRef = nodes.validateOrLookupNode(nodeId, null);
when(nodes.getFolderOrDocument(any(NodeRef.class), nullable(NodeRef.class), nullable(QName.class), nullable(List.class), nullable(Map.class))).thenAnswer(new Answer<Node>() {
@Override
public Node answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
NodeRef aNode = (NodeRef) args[0];
if (StoreRef.STORE_REF_ARCHIVE_SPACESSTORE.equals(aNode.getStoreRef())) {
// Return NULL if its from the archive store.
return null;
}
return new Node(aNode, (NodeRef) args[1], nodeProps, mapUserInfo, sr);
}
});
when(deletedNodes.getDeletedNode(nullable(String.class), nullable(Parameters.class), anyBoolean(), nullable(Map.class))).thenAnswer(new Answer<Node>() {
@Override
public Node answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
String nodeId = (String) args[0];
if (FROZEN_ID.equals(nodeId))
throw new EntityNotFoundException(nodeId);
NodeRef aNode = new NodeRef(StoreRef.STORE_REF_ARCHIVE_SPACESSTORE, nodeId);
return new Node(aNode, new NodeRef(StoreRef.STORE_REF_ARCHIVE_SPACESSTORE, "unknown"), nodeProps, mapUserInfo, sr);
}
});
PersonPropertyLookup propertyLookups = mock(PersonPropertyLookup.class);
when(propertyLookups.supports()).thenReturn(Stream.of("creator", "modifier").collect(Collectors.toSet()));
when(propertyLookups.lookup(notNull(String.class))).thenAnswer(invocation -> {
Object[] args = invocation.getArguments();
String value = (String) args[0];
if ("mjackson".equals(value))
return "Michael Jackson";
return null;
});
PropertyLookupRegistry propertyLookupRegistry = new PropertyLookupRegistry();
propertyLookupRegistry.setLookups(Arrays.asList(propertyLookups));
mapper = new ResultMapper();
mapper.setNodes(nodes);
mapper.setStoreMapper(new StoreMapper());
mapper.setPropertyLookup(propertyLookupRegistry);
mapper.setDeletedNodes(deletedNodes);
mapper.setServiceRegistry(sr);
NodeVersionsRelation nodeVersionsRelation = new NodeVersionsRelation();
nodeVersionsRelation.setNodes(nodes);
nodeVersionsRelation.setServiceRegistry(sr);
nodeVersionsRelation.afterPropertiesSet();
mapper.setNodeVersions(nodeVersionsRelation);
helper = new SerializerTestHelper();
searchMapper.setStoreMapper(new StoreMapper());
}
Aggregations