use of org.alfresco.service.cmr.repository.NodeService in project alfresco-remote-api by Alfresco.
the class AdminWebScriptTest method testResidualProperties.
@Test
public // ALF-21950 We check now if the property belongs to the type of the node
void testResidualProperties() throws Exception {
NodeBrowserPost nodeBrowserPost = new NodeBrowserPost();
DictionaryService dictionaryService = mock(DictionaryService.class);
NodeService nodeService = mock(NodeService.class);
nodeBrowserPost.setDictionaryService(dictionaryService);
nodeBrowserPost.setNodeService(nodeService);
// make own class definition from origin type
ClassDefinition classDefinition = mock(ClassDefinition.class);
when(dictionaryService.getClass(any())).thenReturn(classDefinition);
QName qnameResidualFalse1 = QName.createQName("testResidualProperties", "residualFalse1");
QName qnameResidualFalse2 = QName.createQName("testResidualProperties", "residualFalse2");
QName qnameResidualTrue1 = QName.createQName("testResidualProperties", "residualTrue1");
QName qnameResidualTrue2 = QName.createQName("testResidualProperties", "residualTrue2");
// Define residual False properties inside of class definition
// That simulates the belonging of the properties to a given type of a node
Map<QName, PropertyDefinition> properties = new HashMap<>();
properties.put(qnameResidualFalse1, new SimplePropertyDefinition(false));
properties.put(qnameResidualFalse2, new SimplePropertyDefinition(true));
when(classDefinition.getProperties()).thenReturn(properties);
when(dictionaryService.getProperty(eq(qnameResidualFalse1))).thenReturn(new SimplePropertyDefinition(false));
when(dictionaryService.getProperty(eq(qnameResidualFalse2))).thenReturn(new SimplePropertyDefinition(true));
when(dictionaryService.getProperty(eq(qnameResidualTrue1))).thenReturn(new SimplePropertyDefinition(true));
when(dictionaryService.getProperty(eq(qnameResidualTrue2))).thenReturn(new SimplePropertyDefinition(false));
// property found in definition so it is not residual
String value = "abc";
NodeBrowserPost.Property property = nodeBrowserPost.new Property(qnameResidualFalse1, value, null);
assertFalse(property.getResidual());
// property belongs to an aspect so it is not residual
property = nodeBrowserPost.new Property(qnameResidualFalse2, value, null);
assertFalse(property.getResidual());
// property not found in definition but it is an aspect so it is not residual
property = nodeBrowserPost.new Property(qnameResidualTrue1, value, null);
assertFalse(property.getResidual());
// property not found in definition so it is residual
property = nodeBrowserPost.new Property(qnameResidualTrue2, value, null);
assertTrue(property.getResidual());
}
use of org.alfresco.service.cmr.repository.NodeService in project alfresco-remote-api by Alfresco.
the class PutMethodTest method setUp.
@Before
public void setUp() throws Exception {
searchService = ctx.getBean("SearchService", SearchService.class);
fileFolderService = ctx.getBean("FileFolderService", FileFolderService.class);
nodeService = ctx.getBean("NodeService", NodeService.class);
transactionService = ctx.getBean("transactionService", TransactionService.class);
webDAVHelper = ctx.getBean("webDAVHelper", WebDAVHelper.class);
authenticationService = ctx.getBean("authenticationService", MutableAuthenticationService.class);
personService = ctx.getBean("PersonService", PersonService.class);
lockService = ctx.getBean("LockService", LockService.class);
contentService = ctx.getBean("contentService", ContentService.class);
checkOutCheckInService = ctx.getBean("CheckOutCheckInService", CheckOutCheckInService.class);
permissionService = ctx.getBean("PermissionService", PermissionService.class);
namespaceService = ctx.getBean("namespaceService", NamespaceService.class);
actionService = ctx.getBean("ActionService", ActionService.class);
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
repositoryHelper = (Repository) ctx.getBean("repositoryHelper");
companyHomeNodeRef = repositoryHelper.getCompanyHome();
txn = transactionService.getUserTransaction();
txn.begin();
createUser(USER1_NAME);
createUser(USER2_NAME);
InputStream testDataIS = getClass().getClassLoader().getResourceAsStream(TEST_DATA_FILE_NAME);
InputStream davLockInfoAdminIS = getClass().getClassLoader().getResourceAsStream(DAV_LOCK_INFO_ADMIN);
InputStream davLockInfoUser2IS = getClass().getClassLoader().getResourceAsStream(DAV_LOCK_INFO_USER2);
testDataFile = IOUtils.toByteArray(testDataIS);
davLockInfoAdminFile = IOUtils.toByteArray(davLockInfoAdminIS);
davLockInfoUser2File = IOUtils.toByteArray(davLockInfoUser2IS);
testDataIS.close();
davLockInfoAdminIS.close();
davLockInfoUser2IS.close();
// Create a test file with versionable aspect and content
Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
versionableDocName = "doc-" + GUID.generate();
properties.put(ContentModel.PROP_NAME, versionableDocName);
versionableDoc = nodeService.createNode(companyHomeNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(ContentModel.USER_MODEL_URI, versionableDocName), ContentModel.TYPE_CONTENT, properties).getChildRef();
contentService.getWriter(versionableDoc, ContentModel.PROP_CONTENT, true).putContent("WebDAVTestContent");
nodeService.addAspect(versionableDoc, ContentModel.ASPECT_VERSIONABLE, null);
txn.commit();
txn = transactionService.getUserTransaction();
txn.begin();
}
use of org.alfresco.service.cmr.repository.NodeService in project alfresco-remote-api by Alfresco.
the class ResultMapperTests method mockResultset.
private ResultSet mockResultset(String json) throws Exception {
NodeService nodeService = mock(NodeService.class);
JSONObject jsonObj = new JSONObject(new JSONTokener(json));
SearchParameters sp = new SearchParameters();
sp.setBulkFetchEnabled(false);
ResultSet results = new SolrJSONResultSet(jsonObj, sp, nodeService, null, LimitBy.FINAL_SIZE, 10);
return results;
}
use of org.alfresco.service.cmr.repository.NodeService in project alfresco-remote-api by Alfresco.
the class ResultMapperTests method mockResultset.
private ResultSet mockResultset(List<Long> archivedNodes, List<Long> versionNodes) throws JSONException {
NodeService nodeService = mock(NodeService.class);
when(nodeService.getNodeRef(any())).thenAnswer(new Answer<NodeRef>() {
@Override
public NodeRef answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
// If the DBID is in the list archivedNodes, instead of returning a noderef return achivestore noderef
if (archivedNodes.contains(args[0]))
return new NodeRef(StoreRef.STORE_REF_ARCHIVE_SPACESSTORE, GUID.generate());
if (versionNodes.contains(args[0]))
return new NodeRef(StoreMapper.STORE_REF_VERSION2_SPACESSTORE, GUID.generate() + args[0]);
return new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, GUID.generate());
}
});
SearchParameters sp = new SearchParameters();
sp.setBulkFetchEnabled(false);
JSONObject json = new JSONObject(new JSONTokener(JSON_REPONSE));
ResultSet results = new SolrJSONResultSet(json, sp, nodeService, null, LimitBy.FINAL_SIZE, 10);
return results;
}
use of org.alfresco.service.cmr.repository.NodeService 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(notNull(NodeRef.class))).thenAnswer(invocation -> {
Object[] args = invocation.getArguments();
NodeRef aNode = (NodeRef) args[0];
return versionHistory;
});
when(nodeService.getProperties(notNull(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(notNull(String.class), anyString())).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(notNull(NodeRef.class), any(), any(), any(), any())).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(notNull(String.class), any(), anyBoolean(), any())).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