Java Code Examples for org.alfresco.service.ServiceRegistry

The following are top voted examples for showing how to use org.alfresco.service.ServiceRegistry. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: alfresco-repository   File: ScriptGroup.java   View source code 6 votes vote down vote up
/**
 * Returns an array of ScriptGroup objects representing the given paged results.
 * 
 * @param pagedGroups The paged results
 * @param paging Object representing the paging details
 * @param sortBy field for sorting
 * @param sortAsc sort ascending or not
 * @param serviceRegistry ServiceRegistry
 * @param scope Scriptable
 * @return Array of ScriptGroup objects
 * 
 * @since 4.1.4
 */
public static ScriptGroup[] makeScriptGroups(PagingResults<String> pagedGroups, ScriptPagingDetails paging,
            String sortBy, boolean sortAsc,
            ServiceRegistry serviceRegistry, Scriptable scope)
{
    // set the total on the paging object
    paging.setTotalItems(pagedGroups);
    
    // retrive the page of results and create a ScriptGroup for each one
    List<String> groupNames = pagedGroups.getPage();
    AuthorityComparator authComp = new AuthorityComparator(sortBy, sortAsc);
    List<ScriptGroup> groupList= new ArrayList<ScriptGroup>();
    for (int i=0; i<groupNames.size(); i++)
    {
        groupList.add(new ScriptGroup(groupNames.get(i), serviceRegistry, scope));
    }
    Collections.sort(groupList, authComp);
    ScriptGroup[] groups = new ScriptGroup[groupNames.size()];
    groupList.toArray(groups);
    
    return groups;
}
 
Example 2
Project: alfresco-repository   File: ScriptGroup.java   View source code 6 votes vote down vote up
/**
 * Returns an array of ScriptGroup objects representing the given paged results.
 * 
 * @param pagedGroups sorted paged results (the page of results get sorted again taking I18n into account)
 * @param paging Object representing the paging details
 * @param serviceRegistry ServiceRegistry
 * @param scope Scriptable
 * @return Array of ScriptGroup objects
 * 
 * @since 4.1.4
 */
public static ScriptGroup[] makeScriptGroupsInfo(PagingResults<AuthorityInfo> pagedGroups, ScriptPagingDetails paging,
            String sortBy, boolean sortAsc,
            ServiceRegistry serviceRegistry, Scriptable scope)
{
    // set the total on the paging object
    paging.setTotalItems(pagedGroups);
    
    // retrive the page of results and create a ScriptGroup for each one
    List<AuthorityInfo> groupInfo = pagedGroups.getPage();
    AuthorityComparator authComp = new AuthorityComparator(sortBy, sortAsc);
    List<ScriptGroup> groupList= new ArrayList<ScriptGroup>();
    
    for (int i=0; i<groupInfo.size(); i++)
    {
        AuthorityInfo authorityInfo = groupInfo.get(i);
        groupList.add(new ScriptGroup(authorityInfo.getAuthorityName(), authorityInfo.getAuthorityDisplayName(), serviceRegistry, scope));
    }
    Collections.sort(groupList, authComp);
    ScriptGroup[] groups = new ScriptGroup[groupInfo.size()];
    groupList.toArray(groups);
    
    return groups;
}
 
Example 3
Project: alfresco-repository   File: AuthorityBridgeTableAsynchronouslyRefreshedCacheTest.java   View source code 6 votes vote down vote up
@Override
public void setUp() throws Exception
{
    if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE)
    {
        throw new AlfrescoRuntimeException(
                "A previous tests did not clean up transaction: " +
                AlfrescoTransactionSupport.getTransactionId());
    }
    
    transactionService = (TransactionService) ctx.getBean(ServiceRegistry.TRANSACTION_SERVICE.getLocalName());
    authorityService = (AuthorityService) ctx.getBean(ServiceRegistry.AUTHORITY_SERVICE.getLocalName());
    tenantAdminService = ctx.getBean("tenantAdminService", TenantAdminService.class);
    personService = (PersonService) ctx.getBean(ServiceRegistry.PERSON_SERVICE.getLocalName());
    tenantService = (TenantService) ctx.getBean("tenantService");
    authorityBridgeTableCache = (AuthorityBridgeTableAsynchronouslyRefreshedCache) ctx.getBean("authorityBridgeTableCache");
}
 
Example 4
Project: alfresco-repository   File: TemplateNode.java   View source code 6 votes vote down vote up
/**
 * Constructor
 * 
 * @param nodeRef       The NodeRef this Node wrapper represents
 * @param services      The ServiceRegistry the TemplateNode can use to access services
 * @param resolver      Image resolver to use to retrieve icons
 */
public TemplateNode(NodeRef nodeRef, ServiceRegistry services, TemplateImageResolver resolver)
{
    if (nodeRef == null)
    {
        throw new IllegalArgumentException("NodeRef must be supplied.");
    }
  
    if (services == null)
    {
        throw new IllegalArgumentException("The ServiceRegistry must be supplied.");
    }
    
    this.nodeRef = nodeRef;
    this.id = nodeRef.getId();
    this.services = services;
    this.imageResolver = resolver;
    
    this.properties = new QNameMap<String, Serializable>(this);
}
 
Example 5
Project: alfresco-remote-api   File: SOLRWebScriptTest.java   View source code 6 votes vote down vote up
@Override
protected void setUp() throws Exception
{
    super.setUp();
    ctx = getServer().getApplicationContext();

    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    transactionService = serviceRegistry.getTransactionService();
    nodeService = serviceRegistry.getNodeService();
    fileFolderService = serviceRegistry.getFileFolderService();
    namespaceService = serviceRegistry.getNamespaceService();
    txnHelper = transactionService.getRetryingTransactionHelper();
    nodeDAO = (NodeDAO)ctx.getBean("nodeDAO");
    solrTrackingComponent = (SOLRTrackingComponent) ctx.getBean("solrTrackingComponent");

    admin = AuthenticationUtil.getAdminUserName();

    AuthenticationUtil.setFullyAuthenticatedUser(admin);
    
    storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, getName() + ".1." + System.currentTimeMillis());
    rootNodeRef = nodeService.getRootNode(storeRef);
}
 
Example 6
Project: alfresco-repository   File: AbstractContentTransformerTest.java   View source code 6 votes vote down vote up
/**
 * Ensures that the temp locations are cleaned out before the tests start
 */
@Override
protected void setUp() throws Exception
{
    // Grab a suitably configured context
    ctx = MiscContextTestSuite.getMinimalContext();

    // Grab other useful beans
    serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    mimetypeService = serviceRegistry.getMimetypeService();
    transformerDebug = (TransformerDebug) ctx.getBean("transformerDebug");
    transformerConfig = (TransformerConfig) ctx.getBean("transformerConfig");

    // perform a little cleaning up
    long now = System.currentTimeMillis();
    TempFileProvider.TempFileCleanerJob.removeFiles(now);
}
 
Example 7
Project: alfresco-repository   File: AbstractMimeMessage.java   View source code 6 votes vote down vote up
protected void buildMessage(FileInfo fileInfo, ServiceRegistry serviceRegistry) throws MessagingException
{
    checkParameter(serviceRegistry, "ServiceRegistry");
    this.content = null;
    this.serviceRegistry = serviceRegistry;
    this.imapService = serviceRegistry.getImapService();
    this.messageFileInfo = fileInfo;
    this.isMessageInSitesLibrary = imapService.getNodeSiteContainer(messageFileInfo.getNodeRef()) != null ? true : false;
    RetryingTransactionHelper txHelper = serviceRegistry.getTransactionService().getRetryingTransactionHelper();
    txHelper.setMaxRetries(MAX_RETRIES);
    txHelper.setReadOnly(false);
    txHelper.doInTransaction(new RetryingTransactionCallback<Object>() {
        public Object execute() throws Throwable
        {
            buildMessageInternal();
            return null;
        }
    }, false);
    
}
 
Example 8
Project: alfresco-repository   File: FixedAclUpdaterTest.java   View source code 6 votes vote down vote up
@Override
public void setUp() throws Exception
{
    ctx = ApplicationContextHelper.getApplicationContext();
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    txnHelper = serviceRegistry.getTransactionService().getRetryingTransactionHelper();
    fileFolderService = serviceRegistry.getFileFolderService();
    repository = (Repository) ctx.getBean("repositoryHelper");
    fixedAclUpdater = (FixedAclUpdater) ctx.getBean("fixedAclUpdater");
    permissionsDaoComponent = (PermissionsDaoComponent) ctx.getBean("admPermissionsDaoComponent");
    permissionService = (PermissionService) ctx.getBean("permissionService");
    nodeDAO = (NodeDAO) ctx.getBean("nodeDAO");

    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());

    NodeRef home = repository.getCompanyHome();
    // create a folder hierarchy for which will change permission inheritance
    int[] filesPerLevel = { 5, 5, 10 };
    RetryingTransactionCallback<NodeRef> cb = createFolderHierchyCallback(home, fileFolderService, "ROOT", filesPerLevel);
    folderNodeRef = txnHelper.doInTransaction(cb);

    // change setFixedAclMaxTransactionTime to lower value so setInheritParentPermissions on created folder hierarchy require async call
    setFixedAclMaxTransactionTime(permissionsDaoComponent, home, 50);

}
 
Example 9
Project: alfresco-remote-api   File: Node.java   View source code 6 votes vote down vote up
protected void mapMinimalInfo(Map<QName, Serializable> nodeProps,  Map<String, UserInfo> mapUserInfo, ServiceRegistry sr)
{
    PersonService personService = sr.getPersonService();

    this.name = (String)nodeProps.get(ContentModel.PROP_NAME);

    if (mapUserInfo == null) {
        // minor: save one lookup if creator & modifier are the same
        mapUserInfo = new HashMap<>(2);
    }

    this.createdAt = (Date)nodeProps.get(ContentModel.PROP_CREATED);
    this.createdByUser = lookupUserInfo((String)nodeProps.get(ContentModel.PROP_CREATOR), mapUserInfo, personService);

    this.modifiedAt = (Date)nodeProps.get(ContentModel.PROP_MODIFIED);
    this.modifiedByUser = lookupUserInfo((String)nodeProps.get(ContentModel.PROP_MODIFIER), mapUserInfo, personService);
}
 
Example 10
Project: alfresco-repository   File: DBQueryTest.java   View source code 6 votes vote down vote up
@Before
public void setup() throws Exception
{
    nodeService = (NodeService) ctx.getBean("dbNodeService");
    dictionaryService = (DictionaryService) ctx.getBean("dictionaryService");
    dictionaryDAO = (DictionaryDAO) ctx.getBean("dictionaryDAO");
    namespacePrefixResolver = (DictionaryNamespaceComponent) ctx.getBean("namespaceService");
    transactionService = (TransactionService) ctx.getBean("transactionComponent");
    retryingTransactionHelper = (RetryingTransactionHelper) ctx.getBean("retryingTransactionHelper");
    tenantService = (TenantService) ctx.getBean("tenantService");
    serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    namespaceDao = (NamespaceDAO) ctx.getBean("namespaceDAO");
    authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    contentService = (ContentService) ctx.getBean("contentService");

    loadTestModel();
    createTestData();
}
 
Example 11
Project: alfresco-repository   File: CronScheduledQueryBasedTemplateActionDefinitionTest.java   View source code 6 votes vote down vote up
@Before
@Override
public void setUp() throws Exception
{
    applicationContext = ApplicationContextHelper.getApplicationContext();
    this.registry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);

    initializeScheduler();

    AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();

    transaction = registry.getTransactionService().getUserTransaction(false);
    transaction.begin();

    createTestContent();
}
 
Example 12
Project: alfresco-repository   File: FileFolderDuplicateChildTest.java   View source code 5 votes vote down vote up
@Override
public void setUp() throws Exception
{
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
    transactionService = serviceRegistry.getTransactionService();
    retryingTransactionHelper = transactionService.getRetryingTransactionHelper();
    nodeService = serviceRegistry.getNodeService();
    fileFolderService = serviceRegistry.getFileFolderService();
    authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");

    RetryingTransactionCallback<NodeRef> callback = new RetryingTransactionCallback<NodeRef>()
    {
        public NodeRef execute() throws Throwable
        {
            // authenticate
            authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
            
            // create a test store
            StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, getName() + System.currentTimeMillis());
            rootNodeRef = nodeService.getRootNode(storeRef);
            
            // create a folder to import into
            NodeRef nodeRef = nodeService.createNode(
                    rootNodeRef,
                    ContentModel.ASSOC_CHILDREN,
                    QName.createQName(NamespaceService.ALFRESCO_URI, "working root"),
                    ContentModel.TYPE_FOLDER).getChildRef();
            // Done
            return nodeRef;
        }
    };
    workingRootNodeRef = retryingTransactionHelper.doInTransaction(callback, false, true);
}
 
Example 13
Project: alfresco-repository   File: AbstractMapBasedMetadataLoader.java   View source code 5 votes vote down vote up
protected AbstractMapBasedMetadataLoader(final ServiceRegistry serviceRegistry, final String multiValuedSeparator, final String fileExtension)
{
    // PRECONDITIONS
    assert serviceRegistry      != null : "serviceRegistry must not be null";
    assert multiValuedSeparator != null : "multiValuedSeparator must not be null";
    
    // Body
    this.namespaceService      = serviceRegistry.getNamespaceService();
    this.dictionaryService     = serviceRegistry.getDictionaryService();
    this.multiValuedSeparator  = multiValuedSeparator;
    this.metadataFileExtension = fileExtension;
}
 
Example 14
Project: alfresco-repository   File: LanguagesTest.java   View source code 5 votes vote down vote up
@Override
public void setUp() throws Exception
{
    serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
    transactionService = serviceRegistry.getTransactionService();
    nodeService = serviceRegistry.getNodeService();
    fileFolderService = serviceRegistry.getFileFolderService();
    
    // start the transaction
    txn = transactionService.getUserTransaction();
    txn.begin();

    // downgrade integrity
    IntegrityChecker.setWarnInTransaction();

    // authenticate
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());

    // create a test store
    StoreRef storeRef = nodeService
            .createStore(StoreRef.PROTOCOL_WORKSPACE, getName() + System.currentTimeMillis());
    rootNodeRef = nodeService.getRootNode(storeRef);

    // create a folder to import into
    workingRootNodeRef = nodeService.createNode(
            rootNodeRef,
            ContentModel.ASSOC_CHILDREN,
            QName.createQName(NamespaceService.ALFRESCO_URI, "working root"),
            ContentModel.TYPE_FOLDER).getChildRef();
}
 
Example 15
Project: alfresco-repository   File: XmlMetadataExtracterTest.java   View source code 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void setUp() throws Exception
{
    serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    alfrescoModelMetadataExtracter = (XPathMetadataExtracter) ctx.getBean("extracter.xml.AlfrescoModelMetadataExtracter");
    eclipseProjectMetadataExtracter = (XPathMetadataExtracter) ctx.getBean("extracter.xml.EclipseProjectMetadataExtracter");
    ditaConceptMetadataExtracter = (XPathMetadataExtracter) ctx.getBean("extracter.xml.DITAConceptMetadataExtracter");
    rootElementNameMetadataExtracterSelector = (RootElementNameContentWorkerSelector<MetadataExtracter>) ctx.getBean("extracter.xml.selector.RootElementSelector");
    xpathMetadataExtracterSelector = (XPathContentWorkerSelector<MetadataExtracter>) ctx.getBean("extracter.xml.selector.XPathSelector");
    xmlMetadataExtracter = (XmlMetadataExtracter) ctx.getBean("extracter.xml.XMLMetadataExtracter");
    
    authenticationComponent.setSystemUserAsCurrentUser();
}
 
Example 16
Project: alfresco-repository   File: AclCrudDAOTest.java   View source code 5 votes vote down vote up
@Override
public void setUp() throws Exception
{
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    transactionService = serviceRegistry.getTransactionService();
    txnHelper = transactionService.getRetryingTransactionHelper();
    
    aclCrudDAO = (AclCrudDAO)ctx.getBean("aclCrudDAO");
}
 
Example 17
Project: alfresco-repository   File: ScriptBehaviour.java   View source code 5 votes vote down vote up
public ScriptBehaviour(ServiceRegistry serviceRegistry, ScriptLocation location, NotificationFrequency frequency)
{
	super(frequency);
    ParameterCheck.mandatory("Location", location);
    ParameterCheck.mandatory("ServiceRegistry", serviceRegistry);
    this.location = location;
    this.serviceRegistry = serviceRegistry;
}
 
Example 18
Project: alfresco-repository   File: Association.java   View source code 5 votes vote down vote up
public Association(ServiceRegistry services, AssociationRef assocRef, Scriptable scope)
{
	ParameterCheck.mandatory("Service registry", services);
	ParameterCheck.mandatory("Association reference", assocRef);		
	this.services = services;
	this.assocRef = assocRef;
	if (scope != null)
	{
		this.scope = scope;
	}
}
 
Example 19
Project: alfresco-repository   File: Site.java   View source code 5 votes vote down vote up
/**
 * Constructor 
 * 
 * @param siteInfo      site information
 */
/*package*/ Site(SiteInfo siteInfo, ServiceRegistry serviceRegistry, SiteService siteService, Scriptable scope)
{
	this.serviceRegistry = serviceRegistry;
    this.siteService = siteService;
    this.siteInfo = siteInfo;
    this.scope = scope;
    this.invitationService = serviceRegistry.getInvitationService();
    NodeService nodeService = serviceRegistry.getNodeService();
    PersonService personService = serviceRegistry.getPersonService();
    this.scriptInvitationFactory = new ScriptInvitationFactory(invitationService, nodeService, personService);
}
 
Example 20
Project: alfresco-repository   File: ReplicationServiceIntegrationTest.java   View source code 5 votes vote down vote up
public void testJavascriptAPI() throws Exception
{
   ServiceRegistry serviceRegistry = (ServiceRegistry)ctx.getBean("ServiceRegistry");
   
   // Setup some replication tasks
   ReplicationDefinition empty = replicationService.createReplicationDefinition(ACTION_NAME, "Empty");
   
   ReplicationDefinition persisted = replicationService.createReplicationDefinition(ACTION_NAME2, "Persisted");
   persisted.setTargetName(TRANSFER_TARGET);
   persisted.getPayload().add(
         new NodeRef("workspace://SpacesStore/Testing")
   );
   persisted.getPayload().add(
         new NodeRef("workspace://SpacesStore/Testing2")
   );
   replicationService.saveReplicationDefinition(persisted);
   
   ReplicationDefinition persisted2 = replicationService.createReplicationDefinition(ACTION_NAME3, "Persisted2");
   persisted2.setTargetName("AnotherTarget");
   replicationService.saveReplicationDefinition(persisted2);
   
   // Call the test 
   Map<String, Object> model = new HashMap<String, Object>();
   model.put("Empty", new ScriptReplicationDefinition(serviceRegistry, replicationService, null, empty));
   model.put("EmptyName", ACTION_NAME);
   model.put("Persisted", new ScriptReplicationDefinition(serviceRegistry, replicationService, null, persisted));
   model.put("PersistedName", ACTION_NAME2);
   model.put("PersistedNodeRef", persisted.getNodeRef().toString());
   model.put("PersistedTarget", persisted.getTargetName());
   model.put("Persisted2", new ScriptReplicationDefinition(serviceRegistry, replicationService, null, persisted2));
   model.put("Persisted2Name", ACTION_NAME3);
   model.put("Persisted2NodeRef", persisted2.getNodeRef().toString());
   model.put("Persisted2Target", persisted2.getTargetName());
   
   ScriptLocation location = new ClasspathScriptLocation("org/alfresco/repo/replication/script/test_replicationService.js");
   this.scriptService.executeScript(location, model);
}
 
Example 21
Project: alfresco-repository   File: TransactionCleanupTest.java   View source code 5 votes vote down vote up
@SuppressWarnings("unchecked")
  @Before
  public void before()
  {
  	ServiceRegistry serviceRegistry = (ServiceRegistry)ctx.getBean("ServiceRegistry");
      NamespaceService namespaceService = serviceRegistry.getNamespaceService();
this.transactionService = serviceRegistry.getTransactionService();
this.authenticationService = (MutableAuthenticationService)ctx.getBean("authenticationService");
this.nodeService = serviceRegistry.getNodeService();
this.searchService = serviceRegistry.getSearchService();
this.nodeDAO = (NodeDAO)ctx.getBean("nodeDAO");
this.nodesCache = (SimpleCache<Serializable, Serializable>) ctx.getBean("node.nodesSharedCache");
      this.worker = (DeletedNodeCleanupWorker)ctx.getBean("nodeCleanup.deletedNodeCleanup");
      this.worker.setMinPurgeAgeDays(0);

  	this.helper = transactionService.getRetryingTransactionHelper();
      authenticationService.authenticate("admin", "admin".toCharArray());
      
StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
NodeRef storeRoot = nodeService.getRootNode(storeRef);
List<NodeRef> nodeRefs = searchService.selectNodes(
        storeRoot, "/app:company_home", null, namespaceService, false);
final NodeRef companyHome = nodeRefs.get(0);

  	RetryingTransactionHelper.RetryingTransactionCallback<NodeRef> createNode = new RetryingTransactionHelper.RetryingTransactionCallback<NodeRef>()
  	{
	@Override
	public NodeRef execute() throws Throwable
	{
		return nodeService.createNode(companyHome, ContentModel.ASSOC_CONTAINS, QName.createQName("test", GUID.generate()), ContentModel.TYPE_CONTENT).getChildRef();
	}
  	};
  	this.nodeRef1 = helper.doInTransaction(createNode, false, true);
  	this.nodeRef2 = helper.doInTransaction(createNode, false, true);
  	this.nodeRef3 = helper.doInTransaction(createNode, false, true);
  	this.nodeRef4 = helper.doInTransaction(createNode, false, true);
  	this.nodeRef5 = helper.doInTransaction(createNode, false, true);
  }
 
Example 22
Project: alfresco-repository   File: SearcherComponentTest.java   View source code 5 votes vote down vote up
public void setUp() throws Exception
{
    dialect = (Dialect) ctx.getBean("dialect");
    if (dialect instanceof PostgreSQLDialect)
    {
        // Note: PostgreSQL does not support \u0000 char embedded in a string
        // http://archives.postgresql.org/pgsql-jdbc/2007-02/msg00115.php
        COMPLEX_LOCAL_NAME = COMPLEX_LOCAL_NAME_NO_U0000;
    }
    
    serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    transactionService = serviceRegistry.getTransactionService();
    dictionaryService = BaseNodeServiceTest.loadModel(ctx);
    nodeService = serviceRegistry.getNodeService();

    this.authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    this.authenticationComponent.setSystemUserAsCurrentUser();

    // get the indexer and searcher factory
    IndexerAndSearcher indexerAndSearcher = (IndexerAndSearcher) ctx.getBean("indexerAndSearcherFactory");
    searcher = new SearcherComponent();
    searcher.setIndexerAndSearcherFactory(indexerAndSearcher);
    // create a test workspace
    StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, getName()
            + "_" + System.currentTimeMillis());
    rootNodeRef = nodeService.getRootNode(storeRef);
    // begin a transaction
    txn = transactionService.getUserTransaction();
    txn.begin();
}
 
Example 23
Project: alfresco-repository   File: RepositoryStartupTest.java   View source code 5 votes vote down vote up
public void setUp() throws Exception
{
    ctx = ApplicationContextHelper.getApplicationContext();
    serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    transactionService = serviceRegistry.getTransactionService();
    AuthenticationUtil.setRunAsUserSystem();
}
 
Example 24
Project: alfresco-repository   File: ScriptAction.java   View source code 5 votes vote down vote up
/**
 * Construct
 * 
 * @param action
 *            Alfresco action
 */
public ScriptAction(ServiceRegistry services, Action action, ActionDefinition actionDef)
{
    this.services = services;
    this.actionService = services.getActionService();
    this.namespaceService = services.getNamespaceService();
    this.transactionService = services.getTransactionService();
    
    this.action = action;
    this.actionDef = actionDef;
    this.converter = new ActionValueConverter();
}
 
Example 25
Project: alfresco-repository   File: AppliedPatchDAOTest.java   View source code 5 votes vote down vote up
@Override
public void setUp() throws Exception
{
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    transactionService = serviceRegistry.getTransactionService();
    txnHelper = transactionService.getRetryingTransactionHelper();
    
    appliedPatchDAO = (AppliedPatchDAO) ctx.getBean("appliedPatchDAO");
}
 
Example 26
Project: alfresco-repository   File: UpdateTagScopesActionExecuterTest.java   View source code 5 votes vote down vote up
/**
 * Creates simple hierarchy with documents tagged on the first layer only
 * 
 * @param registry - {@link ServiceRegistry} instance
 * @param createdTagScopes - {@link List}&lt;{@link NodeRef}&gt; instance which contains all tag scope folders
 */
private void createTestContent(ServiceRegistry registry, List<NodeRef> createdTagScopes)
{
    NodeRef rootNode = registry.getNodeLocatorService().getNode(CompanyHomeNodeLocator.NAME, null, null);

    NodeRef currentParent = rootNode;
    for (int i = 0; i < TAGSCOPE_LAYERS; i++)
    {
        FileInfo newFolder = fileFolderService.create(currentParent, String.format(TEST_FOLDER_NAME_PATTERN, i), ContentModel.TYPE_FOLDER);
        currentParent = newFolder.getNodeRef();

        if (null != createdTagScopes)
        {
            createdTagScopes.add(currentParent);
        }

        nodeService.addAspect(currentParent, ContentModel.ASPECT_TAGSCOPE, null);

        for (int j = 0; j < TEST_DOCUMENTS_AMOUNT; j++)
        {
            FileInfo newDocument = fileFolderService.create(currentParent, String.format(TEST_DOCUMENT_NAME_PATTERN, i, j), ContentModel.TYPE_CONTENT);
            nodeService.addAspect(newDocument.getNodeRef(), ContentModel.ASPECT_TAGGABLE, null);

            if (0 == i)
            {
                for (int k = 0; k < TEST_TAGS_AMOUNT; k++)
                {
                    String tagName = String.format(TEST_TAG_NAME_PATTERN, k, j, i);
                    testTags.add(tagName);
                    taggingService.addTag(newDocument.getNodeRef(), tagName);
                }
            }
        }
    }
}
 
Example 27
Project: alfresco-remote-api   File: HTTPRequestAuthenticationFilter.java   View source code 5 votes vote down vote up
/**
 * Initialize the filter
 * 
 * @param config
 *            FitlerConfig
 * @exception ServletException
 */
public void init(FilterConfig config) throws ServletException
{
    // Save the context

    m_context = config.getServletContext();

    // Setup the authentication context

    WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(m_context);

    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    setNodeService(serviceRegistry.getNodeService());
    setAuthenticationService(serviceRegistry.getAuthenticationService());
    setTransactionService(serviceRegistry.getTransactionService());
    setPersonService((PersonService) ctx.getBean("PersonService")); // transactional and permission-checked
    m_authComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    
    httpServletRequestAuthHeaderName = config.getInitParameter("httpServletRequestAuthHeaderName");
    if(httpServletRequestAuthHeaderName == null)
    {
        httpServletRequestAuthHeaderName = "x-user";
    }
    this.m_authPatternString = config.getInitParameter("authPatternString");
    if (this.m_authPatternString != null)
    {
        try
        {
            m_authPattern = Pattern.compile(this.m_authPatternString);
        }
        catch (PatternSyntaxException e)
        {
            logger.warn("Invalid pattern: " + this.m_authPatternString, e);
            m_authPattern = null;
        }
    }
    
}
 
Example 28
Project: alfresco-repository   File: TemplateNode.java   View source code 5 votes vote down vote up
@Override
public Serializable convertProperty(
        Serializable value, QName name, ServiceRegistry services, TemplateImageResolver resolver)
{
    if (value instanceof ContentData)
    {
        // ContentData object properties are converted to TemplateContentData objects
        // so the content and other properties of those objects can be accessed
        return new TemplateContentData((ContentData)value, name);
    }
    else
    {
        return super.convertProperty(value, name, services, resolver);
    }
}
 
Example 29
Project: alfresco-repository   File: ContentDataDAOTest.java   View source code 5 votes vote down vote up
@Override
public void setUp() throws Exception
{
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    transactionService = serviceRegistry.getTransactionService();
    txnHelper = transactionService.getRetryingTransactionHelper();
    
    contentDataDAO = (ContentDataDAO) ctx.getBean("contentDataDAO");
    contentStore = new FileContentStore(ctx, TempFileProvider.getTempDir());
}
 
Example 30
Project: alfresco-remote-api   File: Node.java   View source code 5 votes vote down vote up
public Node(NodeRef nodeRef, NodeRef parentNodeRef, Map<QName, Serializable> nodeProps, Map<String, UserInfo> mapUserInfo, ServiceRegistry sr)
{
    if(nodeRef == null)
    {
        throw new IllegalArgumentException();
    }

    this.nodeRef = nodeRef;
    this.parentNodeRef = parentNodeRef;

    mapMinimalInfo(nodeProps, mapUserInfo, sr);
}
 
Example 31
Project: alfresco-repository   File: ScriptTaskListener.java   View source code 5 votes vote down vote up
protected Map<String, Object> getInputMap(DelegateTask delegateTask, String runAsUser) 
{
    HashMap<String, Object> scriptModel = new HashMap<String, Object>(1);
    
    // Add current logged-in user and it's user home
    ActivitiScriptNode personNode = getPersonNode(runAsUser);
    if (personNode != null)
    {
        ServiceRegistry registry = getServiceRegistry();
        scriptModel.put(PERSON_BINDING_NAME, personNode);
        NodeRef userHomeNode = (NodeRef) registry.getNodeService().getProperty(personNode.getNodeRef(), ContentModel.PROP_HOMEFOLDER);
        if (userHomeNode != null)
        {
            scriptModel.put(USERHOME_BINDING_NAME, new ActivitiScriptNode(userHomeNode, registry));
        }
    }
    
    // Add activiti-specific objects
    scriptModel.put(TASK_BINDING_NAME, delegateTask);
    scriptModel.put(EXECUTION_BINDING_NAME, delegateTask.getExecution());
    
    // Add all workflow variables to model
    Map<String, Object> variables = delegateTask.getExecution().getVariables();
    
    for (Entry<String, Object> varEntry : variables.entrySet())
    {
        scriptModel.put(varEntry.getKey(), varEntry.getValue());
    }
    return scriptModel;
}
 
Example 32
Project: alfresco-repository   File: UpgradePasswordHashTest.java   View source code 5 votes vote down vote up
public void setUp() throws Exception
{
    if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE)
    {
        throw new AlfrescoRuntimeException(
                "A previous tests did not clean up transaction: " +
                AlfrescoTransactionSupport.getTransactionId());
    }
    
    serviceRegistry = (ServiceRegistry)ctx.getBean("ServiceRegistry");

    SimpleCache<String, RepositoryAuthenticationDao.CacheEntry> authenticationCache = (SimpleCache<String, RepositoryAuthenticationDao.CacheEntry>) ctx.getBean("authenticationCache");
    SimpleCache<String, NodeRef> immutableSingletonCache = (SimpleCache<String, NodeRef>) ctx.getBean("immutableSingletonCache");
    TenantService tenantService = (TenantService) ctx.getBean("tenantService");
    compositePasswordEncoder = (CompositePasswordEncoder) ctx.getBean("compositePasswordEncoder");
    PolicyComponent policyComponent = (PolicyComponent) ctx.getBean("policyComponent");

    repositoryAuthenticationDao = new RepositoryAuthenticationDao();
    repositoryAuthenticationDao.setTransactionService(serviceRegistry.getTransactionService());
    repositoryAuthenticationDao.setAuthorityService(serviceRegistry.getAuthorityService());
    repositoryAuthenticationDao.setTenantService(tenantService);
    repositoryAuthenticationDao.setNodeService(serviceRegistry.getNodeService());
    repositoryAuthenticationDao.setNamespaceService(serviceRegistry.getNamespaceService());
    repositoryAuthenticationDao.setCompositePasswordEncoder(compositePasswordEncoder);
    repositoryAuthenticationDao.setPolicyComponent(policyComponent);
    repositoryAuthenticationDao.setAuthenticationCache(authenticationCache);
    repositoryAuthenticationDao.setSingletonCache(immutableSingletonCache);

    upgradePasswordHashWorker = (UpgradePasswordHashWorker)ctx.getBean("upgradePasswordHashWorker");
    nodeService = serviceRegistry.getNodeService();

    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
}
 
Example 33
Project: alfresco-repository   File: JscriptWorkflowDefinition.java   View source code 5 votes vote down vote up
/**
 * Create a new instance of <code>WorkflowDefinition</code> from a
 * CMR workflow object model WorkflowDefinition instance
 * 
 * @param cmrWorkflowDefinition an instance of WorkflowDefinition from the CMR workflow object model
 * @param serviceRegistry reference to the Service Registry
 * @param scope the root scripting scope for this object 
 */
public JscriptWorkflowDefinition(final WorkflowDefinition cmrWorkflowDefinition,
			final ServiceRegistry serviceRegistry, final Scriptable scope)
{
	this.id = cmrWorkflowDefinition.id;
	this.name = cmrWorkflowDefinition.name;
	this.version = cmrWorkflowDefinition.version;
	this.title = cmrWorkflowDefinition.title;
	this.description = cmrWorkflowDefinition.description;
	this.serviceRegistry = serviceRegistry;
	this.scope = scope;
}
 
Example 34
Project: alfresco-repository   File: JscriptWorkflowDefinition.java   View source code 5 votes vote down vote up
/**
 * Creates a new instance of WorkflowDefinition from scratch
 * 
 * @param id workflow definition ID
 * @param name name of workflow definition
 * @param version version of workflow definition
 * @param title title of workflow definition
 * @param description description of workflow definition
 * @param serviceRegistry reference to the Service Registry
 * @param scope root scripting scope for this object
 */
public JscriptWorkflowDefinition(final String id, final String name, final String version,
		final String title, final String description, ServiceRegistry serviceRegistry,
		final Scriptable scope)
{
	this.id = id;
	this.name = name;
	this.version = version;
	this.title = title;
	this.description = description;
	this.serviceRegistry = serviceRegistry;
	this.scope = scope;
}
 
Example 35
Project: alfresco-repository   File: AuditDAOTest.java   View source code 5 votes vote down vote up
@Override
public void setUp() throws Exception
{
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    transactionService = serviceRegistry.getTransactionService();
    txnHelper = transactionService.getRetryingTransactionHelper();
    
    auditDAO = (AuditDAO) ctx.getBean("auditDAO");
    propertyValueDAO = ctx.getBean(PropertyValueDAO.class);
}
 
Example 36
Project: alfresco-repository   File: SubscriptionDAOTest.java   View source code 5 votes vote down vote up
@Override
public void setUp() throws Exception
{
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    transactionService = serviceRegistry.getTransactionService();
    txnHelper = transactionService.getRetryingTransactionHelper();

    personService = serviceRegistry.getPersonService();

    subscriptionsDAO = (SubscriptionsDAO) ctx.getBean("subscriptionsDAO");
}
 
Example 37
Project: alfresco-repository   File: QNameDAOTest.java   View source code 5 votes vote down vote up
@Override
public void setUp() throws Exception
{
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    transactionService = serviceRegistry.getTransactionService();
    txnHelper = transactionService.getRetryingTransactionHelper();
    
    qnameDAO = (QNameDAO) ctx.getBean("qnameDAO");
}
 
Example 38
Project: alfresco-repository   File: RootFolderEvaluator.java   View source code 5 votes vote down vote up
protected RootFolderEvaluator(ServiceRegistry serviceRegistry, CMISActionEvaluator folderEvaluator,
        boolean rootFolderValue)
{
    super(serviceRegistry, folderEvaluator.getAction());
    this.folderEvaluator = folderEvaluator;
    this.rootFolderValue = rootFolderValue;
}
 
Example 39
Project: alfresco-repository   File: RoutingContentServiceTest.java   View source code 5 votes vote down vote up
@Override
public void setUp() throws Exception
{
    ctx = ApplicationContextHelper.getApplicationContext();
    transactionService = (TransactionService) ctx.getBean("TransactionService");
    nodeService = (NodeService) ctx.getBean("NodeService");
    contentService = (ContentService) ctx.getBean(ServiceRegistry.CONTENT_SERVICE.getLocalName());
    this.policyComponent = (PolicyComponent) ctx.getBean("policyComponent");
    this.authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    
    // authenticate
    this.authenticationComponent.setSystemUserAsCurrentUser();
    
    // start the transaction
    txn = getUserTransaction();
    txn.begin();
    
    // create a store and get the root node
    StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, getName());
    if (!nodeService.exists(storeRef))
    {
        storeRef = nodeService.createStore(storeRef.getProtocol(), storeRef.getIdentifier());
    }
    rootNodeRef = nodeService.getRootNode(storeRef);
    // create a content node
    ContentData contentData = new ContentData(null, "text/plain", 0L, "UTF-16", Locale.CHINESE);
    
    PropertyMap properties = new PropertyMap();
    properties.put(ContentModel.PROP_CONTENT, contentData);
    
    ChildAssociationRef assocRef = nodeService.createNode(
            rootNodeRef,
            ContentModel.ASSOC_CHILDREN,
            QName.createQName(TEST_NAMESPACE, GUID.generate()),
            ContentModel.TYPE_CONTENT,
            properties);
    contentNodeRef = assocRef.getChildRef();
}
 
Example 40
Project: alfresco-repository   File: VersionSeriesIdProperty.java   View source code 4 votes vote down vote up
/**
 * Construct
 */
public VersionSeriesIdProperty(ServiceRegistry serviceRegistry, CMISConnector connector)
{
    super(serviceRegistry, connector, PropertyIds.VERSION_SERIES_ID);
}