下面列出了org.springframework.context.support.AbstractRefreshableApplicationContext#org.alfresco.service.cmr.repository.NodeService 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* * This method gets all nodes from the archive which were originally
* contained within the specified StoreRef.
*
* @param storeRef mandatory store ref
* @param paging mandatory paging
* @param filter optional filter
*/
protected PagingResults<NodeRef> getArchivedNodesFrom(StoreRef storeRef, ScriptPagingDetails paging, String filter)
{
NodeService nodeService = serviceRegistry.getNodeService();
NodeRef archiveStoreRootNodeRef = nodeService.getStoreArchiveNode(storeRef);
// Create canned query
ArchivedNodesCannedQueryBuilder queryBuilder = new ArchivedNodesCannedQueryBuilder.Builder(
archiveStoreRootNodeRef, paging).filter(filter)
.sortOrderAscending(false).build();
// Query the DB
PagingResults<NodeRef> result = nodeArchiveService.listArchivedNodes(queryBuilder);
return result;
}
@BeforeClass public static void initTestsContext() throws Exception
{
AUTHENTICATION_SERVICE = (MutableAuthenticationService)testContext.getBean("authenticationService");
BEHAVIOUR_FILTER = (BehaviourFilter)testContext.getBean("policyBehaviourFilter");
LINKS_SERVICE = (LinksService)testContext.getBean("LinksService");
NODE_SERVICE = (NodeService)testContext.getBean("nodeService");
PUBLIC_NODE_SERVICE = (NodeService)testContext.getBean("NodeService");
PERSON_SERVICE = (PersonService)testContext.getBean("personService");
TRANSACTION_HELPER = (RetryingTransactionHelper)testContext.getBean("retryingTransactionHelper");
PERMISSION_SERVICE = (PermissionService)testContext.getBean("permissionService");
SITE_SERVICE = (SiteService)testContext.getBean("siteService");
CONTENT_SERVICE = (ContentService)testContext.getBean("ContentService");
// Do the setup as admin
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
createUser(TEST_USER);
// We need to create the test site as the test user so that they can contribute content to it in tests below.
AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER);
createTestSites();
}
/**
* Dumps the contents of a store to a string.
*
* @param nodeService the node service
* @param storeRef the store reference
* @return string containing textual representation of the contents of the store
*/
public static String dumpNodeStore(NodeService nodeService, StoreRef storeRef)
{
StringBuilder builder = new StringBuilder();
if (nodeService.exists(storeRef) == true)
{
NodeRef rootNode = nodeService.getRootNode(storeRef);
builder.append(outputNode(0, nodeService, rootNode));
}
else
{
builder.
append("The store ").
append(storeRef.toString()).
append(" does not exist.");
}
return builder.toString();
}
/**
* @param thisNode NodeRef
* @return Set<NodeRef>
*/
private Set<NodeRef> processExcludedSet(NodeRef thisNode)
{
Set<NodeRef> results = new HashSet<NodeRef>(89);
NodeService nodeService = serviceRegistry.getNodeService();
// Find all the child nodes (filtering as necessary).
List<ChildAssociationRef> children = nodeService.getChildAssocs(thisNode);
boolean filterChildren = !childAssociationTypes.isEmpty();
for (ChildAssociationRef child : children)
{
if (!filterChildren || !childAssociationTypes.contains(child.getTypeQName()))
{
results.add(child.getChildRef());
}
}
return results;
}
@Override
protected void updateAssociations(NodeService nodeService)
{
List<AssociationRef> existingAssocs = nodeService.getTargetAssocs(sourceNodeRef, assocQName);
for (AssociationRef assoc : existingAssocs)
{
if (assoc.getTargetRef().equals(targetNodeRef))
{
if (logger.isWarnEnabled())
{
logger.warn("Attempt to add existing association prevented. " + assoc);
}
return;
}
}
nodeService.createAssociation(sourceNodeRef, targetNodeRef, assocQName);
}
@Before
public void setUp() throws Exception
{
namespaceService = mock(NamespaceService.class);
Collection<String> cmAlways = new ArrayList<String>();
cmAlways.add("cm");
when(namespaceService.getPrefixes(anyString())).thenReturn(cmAlways);
when(namespaceService.getNamespaceURI(anyString())).thenReturn("cm");
nodeService = mock(NodeService.class);
Path rootPath = newPath(null, "/");
Path homeFolderPath = newPath(rootPath, "cm:homeFolder");
folderPath1 = newPath(homeFolderPath, "cm:folder1");
folderPath2 = newPath(homeFolderPath, "cm:folder2");
folder1 = newFolder(folderPath1);
folder2 = newFolder(folderPath2);
content1 = newContent(folderPath1, "cm:content1");
nodeInfoFactory = new NodeInfoFactory(nodeService, namespaceService);
nodeChange = new NodeChange(nodeInfoFactory, namespaceService, content1);
}
@Before
public void before() throws Exception
{
mlAwareNodeService = (NodeService) applicationContext.getBean("mlAwareNodeService");
nodeService = (NodeService) applicationContext.getBean("nodeService");
dictionaryDAO = (DictionaryDAO) applicationContext.getBean("dictionaryDAO");
authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent");
authenticationComponent.setSystemUserAsCurrentUser();
ClassLoader cl = BaseNodeServiceTest.class.getClassLoader();
InputStream modelStream = cl.getResourceAsStream("org/alfresco/repo/node/NodeRefTestModel.xml");
assertNotNull(modelStream);
M2Model model = M2Model.createModel(modelStream);
dictionaryDAO.putModel(model);
StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
rootNodeRef = nodeService.getRootNode(storeRef);
}
@Before
public void before() throws Exception
{
this.nodeService = (NodeService)applicationContext.getBean(ServiceRegistry.NODE_SERVICE.getLocalName());
this.fileFolderService = (FileFolderService)applicationContext.getBean(ServiceRegistry.FILE_FOLDER_SERVICE.getLocalName());
this.repositoryService = (RepositoryExporterService)applicationContext.getBean("repositoryExporterComponent");
this.authenticationComponent = (AuthenticationComponent)this.applicationContext.getBean("authenticationComponent");
this.authenticationComponent.setSystemUserAsCurrentUser();
}
/**
* Called during the transaction setup
*/
@Before
public void before() throws Exception
{
super.before();
// Get the required services
this.transferService = (TransferService)this.applicationContext.getBean("TransferService");
this.contentService = (ContentService)this.applicationContext.getBean("ContentService");
this.transferServiceImpl = (TransferServiceImpl2)this.applicationContext.getBean("transferService2");
this.searchService = (SearchService)this.applicationContext.getBean("SearchService");
this.transactionService = (TransactionService)this.applicationContext.getBean("TransactionService");
this.nodeService = (NodeService) this.applicationContext.getBean("nodeService");
this.contentService = (ContentService) this.applicationContext.getBean("contentService");
this.authenticationService = (MutableAuthenticationService) this.applicationContext.getBean("authenticationService");
this.actionService = (ActionService)this.applicationContext.getBean("actionService");
this.permissionService = (PermissionService)this.applicationContext.getBean("permissionService");
this.receiver = (TransferReceiver)this.applicationContext.getBean("transferReceiver");
this.transferManifestNodeFactory = (TransferManifestNodeFactory)this.applicationContext.getBean("transferManifestNodeFactory");
this.authenticationComponent = (AuthenticationComponent) this.applicationContext.getBean("authenticationComponent");
this.lockService = (LockService) this.applicationContext.getBean("lockService");
this.personService = (PersonService)this.applicationContext.getBean("PersonService");
this.descriptorService = (DescriptorService)this.applicationContext.getBean("DescriptorService");
this.copyService = (CopyService)this.applicationContext.getBean("CopyService");
this.taggingService = ((TaggingService)this.applicationContext.getBean("TaggingService"));
this.categoryService = (CategoryService)this.applicationContext.getBean("CategoryService");
this.repositoryHelper = (Repository) this.applicationContext.getBean("repositoryHelper");
this.serverDescriptor = descriptorService.getServerDescriptor();
REPO_ID_B = descriptorService.getCurrentRepositoryDescriptor().getId();
authenticationComponent.setSystemUserAsCurrentUser();
assertNotNull("receiver is null", this.receiver);
TestTransaction.flagForCommit();
TestTransaction.end();
}
@BeforeClass public static void initStaticData() throws Exception
{
AUTHORITY_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("AuthorityService", AuthorityService.class);
NAMESPACE_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("namespaceService", NamespaceService.class);
NODE_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("NodeService", NodeService.class);
NODE_ARCHIVE_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("nodeArchiveService", NodeArchiveService.class);
SITE_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("siteService", SiteService.class);
COCI_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("checkOutCheckInService", CheckOutCheckInService.class);
TRANSACTION_HELPER = APP_CONTEXT_INIT.getApplicationContext().getBean("retryingTransactionHelper", RetryingTransactionHelper.class);
PERMISSION_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("permissionServiceImpl", PermissionService.class);
AUTHENTICATION_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("authenticationService", MutableAuthenticationService.class);
PERSON_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("PersonService", PersonService.class);
FILE_FOLDER_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("FileFolderService",FileFolderService.class);
AUTHENTICATION_COMPONENT = APP_CONTEXT_INIT.getApplicationContext().getBean("authenticationComponent",AuthenticationComponent.class);
LOCK_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("lockService",LockService.class);
// We'll create this test content as admin.
final String admin = AuthenticationUtil.getAdminUserName();
TEST_SITE_NAME = GUID.generate();
TEST_SUB_SITE_NAME = GUID.generate();
final QName subSiteType = QName.createQName("testsite", "testSubsite", NAMESPACE_SERVICE);
STATIC_TEST_SITES.createSite("sitePreset", TEST_SITE_NAME, "siteTitle", "siteDescription", SiteVisibility.PUBLIC, admin);
STATIC_TEST_SITES.createSite("sitePreset", TEST_SUB_SITE_NAME, "siteTitle", "siteDescription", SiteVisibility.PUBLIC, subSiteType, admin);
TEST_SITE_WITH_MEMBERS = STATIC_TEST_SITES.createTestSiteWithUserPerRole(SiteServiceImplMoreTest.class.getSimpleName(), "sitePreset", SiteVisibility.PUBLIC, admin);
}
public static Filter<NodeRef> exists(final NodeService nodeService)
{
return new Filter<NodeRef>()
{
public Boolean apply(NodeRef value)
{
return nodeService.exists(value);
}
};
}
@Override
protected void updateAssociations(NodeService nodeService)
{
List<AssociationRef> existingAssocs = nodeService.getTargetAssocs(sourceNodeRef, assocQName);
boolean assocDoesNotExist = true;
for (AssociationRef assoc : existingAssocs)
{
if (assoc.getTargetRef().equals(targetNodeRef))
{
assocDoesNotExist = false;
break;
}
}
if (assocDoesNotExist)
{
if (logger.isWarnEnabled())
{
StringBuilder msg = new StringBuilder();
msg.append("Attempt to remove non-existent association prevented. ").append(sourceNodeRef).append("|")
.append(targetNodeRef).append(assocQName);
logger.warn(msg.toString());
}
return;
}
nodeService.removeAssociation(sourceNodeRef, targetNodeRef, assocQName);
}
private static List<ChildAssociationRef> getChildAssociationRefs(final QName childName, final NodeService nodeService,
final Repository repositoryHelper)
{
final NodeRef system = getSystemContainer(nodeService, repositoryHelper);
List<ChildAssociationRef> containerRefs = AuthenticationUtil.runAsSystem(new RunAsWork<List<ChildAssociationRef>>()
{
@Override
public List<ChildAssociationRef> doWork() throws Exception
{
return nodeService.getChildAssocs(system, ContentModel.ASSOC_CHILDREN, childName);
}
});
return containerRefs;
}
SOLRTest4(
RetryingTransactionHelper txnHelper, FileFolderService fileFolderService,
NodeDAO nodeDAO, QNameDAO qnameDAO, NodeService nodeService, DictionaryService dictionaryService,
NodeRef rootNodeRef, String containerName, boolean doNodeChecks, boolean doMetaDataChecks)
{
super(txnHelper, fileFolderService, nodeDAO, qnameDAO, nodeService, dictionaryService, rootNodeRef, containerName, doNodeChecks, doMetaDataChecks);
}
/**
* Returns the NodeRef of a given Child Container within the current Tenant's
* System Container, if found
*/
public static NodeRef getSystemChildContainer(final QName childName, final NodeService nodeService, final Repository repositoryHelper)
{
List<ChildAssociationRef> containerRefs = getChildAssociationRefs(childName, nodeService, repositoryHelper);
NodeRef container = null;
if (containerRefs.size() > 0)
{
container = containerRefs.get(0).getChildRef();
warnIfDuplicates(containerRefs);
}
return container;
}
public void setUp() throws Exception
{
if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE)
{
throw new AlfrescoRuntimeException(
"A previous tests did not clean up transaction: " +
AlfrescoTransactionSupport.getTransactionId());
}
nodeService = (NodeService) ctx.getBean("nodeService");
authenticationService = (MutableAuthenticationService) ctx.getBean("authenticationService");
authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
ownableService = (OwnableService) ctx.getBean("ownableService");
permissionService = (PermissionService) ctx.getBean("permissionService");
authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
authenticationDAO = (MutableAuthenticationDao) ctx.getBean("authenticationDao");
TransactionService transactionService = (TransactionService) ctx.getBean(ServiceRegistry.TRANSACTION_SERVICE.getLocalName());
txn = transactionService.getUserTransaction();
txn.begin();
StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
rootNodeRef = nodeService.getRootNode(storeRef);
permissionService.setPermission(rootNodeRef, PermissionService.ALL_AUTHORITIES, PermissionService.ADD_CHILDREN, true);
if(authenticationDAO.userExists("andy"))
{
authenticationService.deleteAuthentication("andy");
}
authenticationService.createAuthentication("andy", "andy".toCharArray());
dynamicAuthority = new OwnerDynamicAuthority();
dynamicAuthority.setOwnableService(ownableService);
authenticationComponent.clearCurrentSecurityContext();
}
public TestIntegrityEvent(
NodeService nodeService,
DictionaryService dictionaryService,
NodeRef nodeRef,
QName typeQName,
QName qname)
{
super(nodeService, dictionaryService, nodeRef, typeQName, qname);
}
private void dumpNodeStore(Locale locale)
{
System.out.println(locale.getDisplayLanguage() + " LOCALE: ");
I18NUtil.setLocale(locale);
System.out.println(NodeStoreInspector.dumpNodeStore((NodeService) applicationContext.getBean("NodeService"), storeRef));
}
public static String makeAvatar(final NodeService nodeService, final NodeRef person)
{
nodeService.addAspect(person, ContentModel.ASPECT_PREFERENCES, null);
ChildAssociationRef assoc = nodeService.createNode(person, ContentModel.ASSOC_PREFERENCE_IMAGE, avatarQName,
ContentModel.TYPE_CONTENT);
NodeRef avatar = assoc.getChildRef();
nodeService.createAssociation(person, avatar, ContentModel.ASSOC_AVATAR);
return "api/node/" + avatar + "/content/thumbnails/avatar";
}
/**
* Constructs the rule with a reference to a {@link ApplicationContextInit rule} which can be used to retrieve the ApplicationContext.
*
* @param appContextRule a rule which can be used to retrieve the spring app context.
*/
public WellKnownNodes(ApplicationContextInit appContextRule)
{
this.appContextRule = appContextRule;
this.repositoryHelper = (Repository)appContextRule.getApplicationContext().getBean("repositoryHelper");
this.nodeService = (NodeService)appContextRule.getApplicationContext().getBean("NodeService");
}
@BeforeClass public static void initStaticData() throws Exception
{
NAMESPACE_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("namespaceService", NamespaceService.class);
NODE_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("nodeService", NodeService.class);
SITE_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("siteService", SiteService.class);
TRANSACTION_HELPER = APP_CONTEXT_INIT.getApplicationContext().getBean("retryingTransactionHelper", RetryingTransactionHelper.class);
}
/**
* Called during the transaction setup
*/
@SuppressWarnings("deprecation")
@Before
public void before() throws Exception
{
super.before();
// Get the required services
this.nodeService = (NodeService) applicationContext.getBean("NodeService");
this.serviceRegistry = (ServiceRegistry) applicationContext.getBean("ServiceRegistry");
this.nodeCrawlerFactory = (NodeCrawlerFactory) applicationContext.getBean("NodeCrawlerFactory");
Repository repositoryHelper = (Repository) applicationContext.getBean("repositoryHelper");
this.companyHome = repositoryHelper.getCompanyHome();
}
public TestPersonManager(MutableAuthenticationService authenticationService,
PersonService personService,
NodeService nodeService)
{
this.authenticationService = authenticationService;
this.personService = personService;
this.nodeService = nodeService;
}
private NodeService makeNodeService()
{
NodeService service = mock(NodeService.class);
when(service.hasAspect(PCKG_NODE, ASPECT_WORKFLOW_PACKAGE))
.thenReturn(true);
Map<QName, Serializable> props = new HashMap<QName, Serializable>(2);
props.put(ContentModel.PROP_FIRSTNAME, "System");
props.put(ContentModel.PROP_LASTNAME, "Administrator");
when(service.getProperties(USER_NODE)).thenReturn(props);
return service;
}
public NodeSearcher(NodeService nodeService, DictionaryService dictionaryService, SearchService searchService)
{
this.nodeService = nodeService;
this.dictionaryService = dictionaryService;
this.searchService = searchService;
}
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* Set the node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
private List<NodeRef> getSortedPeopleObjects(List<NodeRef> peopleRefs, final String sortBy, Boolean sortAsc)
{
if (sortBy == null)
{
return peopleRefs;
}
//make copy of peopleRefs because it can be unmodifiable list.
List<NodeRef> sortedPeopleRefs = new ArrayList<NodeRef>(peopleRefs);
final Collator col = Collator.getInstance(I18NUtil.getLocale());
final NodeService nodeService = services.getNodeService();
final int orderMultiplicator = ((sortAsc == null) || sortAsc) ? 1 : -1;
Collections.sort(sortedPeopleRefs, new Comparator<NodeRef>()
{
@Override
public int compare(NodeRef n1, NodeRef n2)
{
Serializable p1 = getProperty(n1);
Serializable p2 = getProperty(n2);
if ((p1 instanceof Long) && (p2 instanceof Long))
{
return Long.compare((Long)p1, (Long)p2) * orderMultiplicator;
}
return col.compare(p1.toString(), p2) * orderMultiplicator;
}
public Serializable getProperty(NodeRef nodeRef)
{
Serializable result;
if ("fullName".equalsIgnoreCase(sortBy))
{
String firstName = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_FIRSTNAME);
String lastName = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_LASTNAME);
String fullName = firstName;
if (lastName != null && lastName.length() > 0)
{
fullName = fullName + " " + lastName;
}
result = fullName;
}
else if ("jobtitle".equalsIgnoreCase(sortBy))
{
result = nodeService.getProperty(nodeRef, ContentModel.PROP_JOBTITLE);
}
else if ("email".equalsIgnoreCase(sortBy))
{
result = nodeService.getProperty(nodeRef, ContentModel.PROP_EMAIL);
}
else if ("usage".equalsIgnoreCase(sortBy))
{
result = nodeService.getProperty(nodeRef, ContentModel.PROP_SIZE_CURRENT);
}
else if ("quota".equalsIgnoreCase(sortBy))
{
result = nodeService.getProperty(nodeRef, ContentModel.PROP_SIZE_QUOTA);
}
else
{
// Default
result = nodeService.getProperty(nodeRef, ContentModel.PROP_USERNAME);
}
if (result == null)
{
result = "";
}
return result;
}
});
return sortedPeopleRefs;
}