Java Code Examples for org.alfresco.service.cmr.site.SiteService

The following are top voted examples for showing how to use org.alfresco.service.cmr.site.SiteService. 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: QuickShareServiceIntegrationTest.java   View source code 7 votes vote down vote up
private static void findServices()
{
    ApplicationContext ctx = testContext.getApplicationContext();
    
    copyService = ctx.getBean("CopyService", CopyService.class);
    nodeService = ctx.getBean("NodeService", NodeService.class);
    directQuickShareService = ctx.getBean("quickShareService", QuickShareService.class);
    quickShareService = ctx.getBean("QuickShareService", QuickShareService.class);
    repository = ctx.getBean("repositoryHelper", Repository.class);
    attributeService = ctx.getBean("AttributeService", AttributeService.class);
    permissionService = ctx.getBean("PermissionService", PermissionService.class);
    nodeArchiveService = ctx.getBean("nodeArchiveService", NodeArchiveService.class);
    scheduledPersistedActionService = ctx.getBean("scheduledPersistedActionService", ScheduledPersistedActionService.class);
    quickShareLinkExpiryActionPersister = ctx.getBean("quickShareLinkExpiryActionPersister", QuickShareLinkExpiryActionPersister.class);
    transactionHelper = ctx.getBean("retryingTransactionHelper", RetryingTransactionHelper.class);
    globalProperties = ctx.getBean("global-properties", Properties.class);
    siteService = (SiteService) ctx.getBean("SiteService");
}
 
Example 2
Project: alfresco-repository   File: DocLibNodeLocator.java   View source code 6 votes vote down vote up
/**
 * Finds the site in which the source {@link NodeRef} resides and returns the Document Library container for that site.
 * If no site can be found or the site does not have a Document Library then the Company Home is returned.
 * 
 * @param source the starting point for locating the site Document Library.
 * @param params Not used.
 * @return the Document Library or the Company Home.
 */
@Override
public NodeRef getNode(NodeRef source, Map<String, Serializable> params)
{
    NodeRef docLib = null;
    if (source != null)
    {
        String siteName = siteService.getSiteShortName(source);
        if (siteName != null)
        {
            String containerId = SiteService.DOCUMENT_LIBRARY;
            docLib = siteService.getContainer(siteName, containerId);
        }
    }
    if (docLib == null)
    {
        docLib = repositoryHelper.getCompanyHome();
    }
    return docLib;
}
 
Example 3
Project: alfresco-repository   File: SiteServiceImpl.java   View source code 6 votes vote down vote up
public PagingResults<SiteMembership> listMembersPaged(String shortName, boolean collapseGroups, List<Pair<SiteService.SortFields, Boolean>> sortProps, PagingRequest pagingRequest)
  {
      CannedQueryPageDetails pageDetails = new CannedQueryPageDetails(pagingRequest.getSkipCount(), pagingRequest.getMaxItems());

      // sort details
      CannedQuerySortDetails sortDetails = null;
      if(sortProps != null)
      {
          List<Pair<? extends Object, SortOrder>> sortPairs = new ArrayList<Pair<? extends Object, SortOrder>>(sortProps.size());
          for (Pair<SiteService.SortFields, Boolean> sortProp : sortProps)
          {
              sortPairs.add(new Pair<SiteService.SortFields, SortOrder>(sortProp.getFirst(), (sortProp.getSecond() ? SortOrder.ASCENDING : SortOrder.DESCENDING)));
          }
          
          sortDetails = new CannedQuerySortDetails(sortPairs);
      }

      SiteMembersCannedQueryParams parameterBean = new SiteMembersCannedQueryParams(shortName, collapseGroups);
      CannedQueryParameters params = new CannedQueryParameters(parameterBean, pageDetails, sortDetails, pagingRequest.getRequestTotalCountMax(), pagingRequest.getQueryExecutionId());

CannedQuery<SiteMembership> query = new SiteMembersCannedQuery(this, personService, nodeService, params);

      CannedQueryResults<SiteMembership> results = query.execute();

      return getPagingResults(pagingRequest, results);
  }
 
Example 4
Project: alfresco-remote-api   File: SiteServiceTest.java   View source code 6 votes vote down vote up
@Override
protected void setUp() throws Exception
{
    super.setUp();
    
    this.siteService = (SiteService)getServer().getApplicationContext().getBean("SiteService");
    this.nodeService = (NodeService)getServer().getApplicationContext().getBean("NodeService");
    this.permissionService = (PermissionService)getServer().getApplicationContext().getBean("PermissionService");
    this.authorityService = (AuthorityService)getServer().getApplicationContext().getBean("AuthorityService");
    this.fileFolderService = (FileFolderService)getServer().getApplicationContext().getBean("FileFolderService");

    
    // Create users
    createUser(USER_ONE);
    createUser(USER_TWO);
    createUser(USER_THREE);
    createUser(USER_NUMERIC);
    createUser(USER_FOUR_AS_SITE_ADMIN);
    
    // Add user four as a member of the site admins group
    authorityService.addAuthority("GROUP_SITE_ADMINISTRATORS", USER_FOUR_AS_SITE_ADMIN);
    
    // Do tests as user one
    this.authenticationComponent.setCurrentUser(USER_ONE);
}
 
Example 5
Project: alfresco-repository   File: SiteTitleDisplayHandler.java   View source code 6 votes vote down vote up
@Override
public FacetLabel getDisplayLabel(String value)
{
    // Solr returns the site short name encoded
    value = ISO9075.decode(value);
    String title = null;

    if (nonSiteLocationsLabels.containsKey(value))
    {
        title = nonSiteLocationsLabels.get(value);
    }
    else
    {
        SiteService siteService = serviceRegistry.getSiteService();
        SiteInfo siteInfo = siteService.getSite(value);
        title = siteInfo != null ? siteInfo.getTitle() : value;
    }

    return new FacetLabel(value, title, -1);
}
 
Example 6
Project: alfresco-repository   File: SiteServiceImplMoreTest.java   View source code 6 votes vote down vote up
@Test public void testSiteMembersPaged()
{
    // Choose a site name that will link back to this test case...
    final String siteShortName = testName.getMethodName();
    log.debug("Creating test site called: " + siteShortName);

    TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<Void>()
    {
        public Void execute() throws Throwable
        {
            // ...and create the site
            final TestSiteAndMemberInfo testSiteAndMemberInfo = perMethodTestSites.createTestSiteWithUserPerRole(siteShortName, "sitePreset", SiteVisibility.PUBLIC, AuthenticationUtil.getAdminUserName());

            List<Pair<SiteService.SortFields, Boolean>> sortProps = new ArrayList<Pair<SiteService.SortFields, Boolean>>(1);
            sortProps.add(new Pair<SiteService.SortFields, Boolean>(SiteService.SortFields.FirstName, true));
            PagingResults<SiteMembership> pagedMembers = SITE_SERVICE.listMembersPaged(siteShortName, true, sortProps, new PagingRequest(100));
            assertNotNull(pagedMembers);
            assertNotNull(pagedMembers.getPage());
            assertNotNull(pagedMembers.getQueryExecutionId());
            assertFalse(pagedMembers.hasMoreItems());
            log.debug("About to delete site completely.");
            SITE_SERVICE.deleteSite(siteShortName);
            return null;
        }
    });
}
 
Example 7
Project: alfresco-repository   File: CustomRoleTest.java   View source code 6 votes vote down vote up
@SuppressWarnings("deprecation")
protected void onSetUpInTransaction() throws Exception
{
    super.onSetUpInTransaction();

    // Get the required services
    this.authenticationComponent = (AuthenticationComponent) this.applicationContext.getBean("authenticationComponent");
    this.siteService = (SiteService) this.applicationContext.getBean("SiteService");
    this.personService = (PersonService) this.applicationContext.getBean("PersonService");

    // Create the test users
    createUser(USER_ONE, "UserOne");
    createUser(USER_TWO, "UserTwo");

    // Set the current authentication
    this.authenticationComponent.setCurrentUser(USER_ONE);
}
 
Example 8
Project: alfresco-repository   File: CustomRoleTest.java   View source code 6 votes vote down vote up
public void testCustomRole()
{
    try
    {
        // Create a site
        siteService.createSite("customrolessite", "customrolessite", "Test custom role", "Test custom role", SiteVisibility.PUBLIC);

        this.siteService.setMembership("customrolessite", USER_TWO, "SiteCoordinator");

        // Get the members of the site
        final List<Pair<SiteService.SortFields, Boolean>> sort = new ArrayList<Pair<SiteService.SortFields, Boolean>>();
        sort.add(new Pair<SiteService.SortFields, Boolean>(SiteService.SortFields.SiteTitle, Boolean.TRUE));
        sort.add(new Pair<SiteService.SortFields, Boolean>(SiteService.SortFields.Role, Boolean.TRUE));

        PagingResults<SiteMembership> sites = siteService.listSitesPaged(USER_TWO, sort, new PagingRequest(0, 100));
        assertNotNull(sites);
        assertEquals(sites.getPage().size(), 1);
    }
    catch (Exception ex)
    {
        fail("Custom role breaks sites API. Take a look on MNT-12873\n" + ex.getMessage());
    }
}
 
Example 9
Project: alfresco-repository   File: CommentsTest.java   View source code 6 votes vote down vote up
@BeforeClass public static void initBasicServices() throws Exception
{
    behaviourFilter = (BehaviourFilter)APP_CONTEXT_INIT.getApplicationContext().getBean("policyBehaviourFilter");
    contentService = (ContentService)APP_CONTEXT_INIT.getApplicationContext().getBean("ContentService");
    nodeService = (NodeService)APP_CONTEXT_INIT.getApplicationContext().getBean("NodeService");
    repositoryHelper = (Repository)APP_CONTEXT_INIT.getApplicationContext().getBean("repositoryHelper");
    siteService = (SiteService)APP_CONTEXT_INIT.getApplicationContext().getBean("SiteService");
    transactionHelper = (RetryingTransactionHelper)APP_CONTEXT_INIT.getApplicationContext().getBean("retryingTransactionHelper");

    authenticationComponent = (AuthenticationComponent)APP_CONTEXT_INIT.getApplicationContext().getBean("authenticationComponent");
    commentService = (CommentService)APP_CONTEXT_INIT.getApplicationContext().getBean("commentService");
    authenticationService = (MutableAuthenticationService)APP_CONTEXT_INIT.getApplicationContext().getBean("AuthenticationService");
    personService = (PersonService)APP_CONTEXT_INIT.getApplicationContext().getBean("PersonService");
    postDAO = (ActivityPostDAO)APP_CONTEXT_INIT.getApplicationContext().getBean("postDAO");
    permissionServiceImpl = (PermissionServiceImpl)APP_CONTEXT_INIT.getApplicationContext().getBean("permissionServiceImpl");
    permissionModelDAO = (ModelDAO)APP_CONTEXT_INIT.getApplicationContext().getBean("permissionsModelDAO");
    lockService = (LockService)APP_CONTEXT_INIT.getApplicationContext().getBean("lockService");

    COMPANY_HOME = repositoryHelper.getCompanyHome();
}
 
Example 10
Project: alfresco-repository   File: BlogServiceImplTest.java   View source code 6 votes vote down vote up
@BeforeClass public static void initTestsContext() throws Exception
{
    AUTHENTICATION_SERVICE = (MutableAuthenticationService)testContext.getBean("authenticationService");
    BEHAVIOUR_FILTER       = (BehaviourFilter)testContext.getBean("policyBehaviourFilter");
    BLOG_SERVICE           = (BlogService)testContext.getBean("blogService");
    DICTIONARY_SERVICE     = (DictionaryService)testContext.getBean("dictionaryService");
    NODE_SERVICE           = (NodeService)testContext.getBean("nodeService");
    PERSON_SERVICE         = (PersonService)testContext.getBean("personService");
    TRANSACTION_HELPER     = (RetryingTransactionHelper)testContext.getBean("retryingTransactionHelper");
    SITE_SERVICE           = (SiteService)testContext.getBean("siteService");
    TAGGING_SERVICE        = (TaggingService)testContext.getBean("TaggingService");
    
    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);
    createTestSiteWithBlogContainer();
}
 
Example 11
Project: alfresco-repository   File: SubscriptionServiceActivitiesTest.java   View source code 6 votes vote down vote up
@BeforeClass public static void setUp() throws Exception
{
    final ApplicationContext ctx = APP_CONTEXT_INIT.getApplicationContext();
    
    // Let's shut down the scheduler so that we aren't competing with the
    // scheduled versions of the post lookup and
    // feed generator jobs
    // Note that to ensure this test class can be run within a suite, that we do not want to actually 'shutdown' the scheduler.
    // It may be needed by other test classes and must be restored to life after this class has run.
    QUARTZ_SCHEDULER = ctx.getBean("schedulerFactory", Scheduler.class);
    QUARTZ_SCHEDULER.standby();
    
    // Get the required services
    subscriptionService = (SubscriptionService) ctx.getBean("SubscriptionService");
    personService = (PersonService) ctx.getBean("PersonService");
    siteService = (SiteService) ctx.getBean("SiteService");
    activityService = (ActivityService) ctx.getBean("activityService");
    nodeService = (NodeService) ctx.getBean("NodeService");
    contentService = (ContentService) ctx.getBean("ContentService");
    nodeArchiveService = (NodeArchiveService)ctx.getBean("nodeArchiveService");
    transactionHelper = (RetryingTransactionHelper) ctx.getBean("retryingTransactionHelper");
    
    ChildApplicationContextFactory activitiesFeed = (ChildApplicationContextFactory) ctx.getBean("ActivitiesFeed");
    ApplicationContext activitiesFeedCtx = activitiesFeed.getApplicationContext();
    postLookup = (PostLookup) activitiesFeedCtx.getBean("postLookup");
    feedGenerator = (FeedGenerator) activitiesFeedCtx.getBean("feedGenerator");
    
    LocalFeedTaskProcessor feedProcessor = (LocalFeedTaskProcessor) activitiesFeedCtx.getBean("feedTaskProcessor");
    
    List<String> templateSearchPaths = new ArrayList<String>(1);
    templateSearchPaths.add(TEST_TEMPLATES_LOCATION);
    feedProcessor.setTemplateSearchPaths(templateSearchPaths);
    feedProcessor.setUseRemoteCallbacks(false);
}
 
Example 12
Project: alfresco-repository   File: LinksServiceImplTest.java   View source code 6 votes vote down vote up
@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();
}
 
Example 13
Project: alfresco-repository   File: InviteModeratedSenderTest.java   View source code 6 votes vote down vote up
/**
 * @return ServiceRegistry
 */
private ServiceRegistry mockServices()
{
    ActionService mockActionService = mockActionService();
    NodeService mockNodeService = mockNodeService();
    PersonService mockPersonService = mockPersonService();
    SearchService mockSearchService = mockSearchService();
    SiteService mockSiteService = mockSiteService();
    FileFolderService mockFileFolderService = mockFileFolderService();

    ServiceRegistry services = mock(ServiceRegistry.class);
    when(services.getActionService()).thenReturn(mockActionService);
    when(services.getNodeService()).thenReturn(mockNodeService);
    when(services.getPersonService()).thenReturn(mockPersonService);
    when(services.getSearchService()).thenReturn(mockSearchService);
    when(services.getSiteService()).thenReturn(mockSiteService);
    when(services.getFileFolderService()).thenReturn(mockFileFolderService);
    return services;
}
 
Example 14
Project: alfresco-remote-api   File: QuickShareRestApiTest.java   View source code 6 votes vote down vote up
private SiteInfo createSite(final String shortName)
{
    return transactionHelper.doInTransaction(new RetryingTransactionCallback<SiteInfo>()
       {
          @Override
          public SiteInfo execute() throws Throwable
          {
              SiteInfo siteInfo = siteService.getSite(shortName);
              if (siteInfo != null)
              {
                  // Tidy up after failed earlier run
                  siteService.deleteSite(shortName);
              }
              
              // Do the create
              SiteInfo site = siteService.createSite("Testing", shortName, shortName, "myDescription", SiteVisibility.PUBLIC);
              
              // Ensure we have a doclib
              siteService.createContainer(shortName, SiteService.DOCUMENT_LIBRARY, ContentModel.TYPE_FOLDER, null);
              
              // All done
              return site;
          }
       }, false, true
    ); 
}
 
Example 15
Project: alfresco-remote-api   File: WebDAVHelper.java   View source code 6 votes vote down vote up
public String determineSiteId(NodeRef rootNodeRef, String path)
{
    SiteService siteService = getServiceRegistry().getSiteService();
    String siteId;
    try
    {
        FileInfo fileInfo = getNodeForPath(rootNodeRef, path);
        siteId = siteService.getSiteShortName(fileInfo.getNodeRef());
        if (siteId == null)
        {
            throw new RuntimeException("Node is not contained by a site: " + path);
        }
    }
    catch (Exception error)
    {
        siteId = EMPTY_SITE_ID;
    }
    return siteId;
}
 
Example 16
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 17
Project: alfresco-remote-api   File: LinksRestApiTest.java   View source code 5 votes vote down vote up
@Override
protected void setUp() throws Exception
{
    super.setUp();
    
    this.authenticationService = (MutableAuthenticationService)getServer().getApplicationContext().getBean("AuthenticationService");
    this.authenticationComponent = (AuthenticationComponent)getServer().getApplicationContext().getBean("authenticationComponent");
    this.policyBehaviourFilter = (BehaviourFilter)getServer().getApplicationContext().getBean("policyBehaviourFilter");
    this.transactionService = (TransactionService)getServer().getApplicationContext().getBean("transactionService");
    this.personService = (PersonService)getServer().getApplicationContext().getBean("PersonService");
    this.nodeService = (NodeService)getServer().getApplicationContext().getBean("NodeService");
    this.siteService = (SiteService)getServer().getApplicationContext().getBean("SiteService");
    this.internalNodeService = (NodeService)getServer().getApplicationContext().getBean("nodeService");
    this.nodeArchiveService = (NodeArchiveService)getServer().getApplicationContext().getBean("nodeArchiveService");
    this.activityService = (ActivityService)getServer().getApplicationContext().getBean("activityService");
    ChildApplicationContextFactory activitiesFeed = (ChildApplicationContextFactory)getServer().getApplicationContext().getBean("ActivitiesFeed");
    ApplicationContext activitiesFeedCtx = activitiesFeed.getApplicationContext();
    this.feedGenerator = (FeedGenerator)activitiesFeedCtx.getBean("feedGenerator");
    this.postLookup = (PostLookup)activitiesFeedCtx.getBean("postLookup");


    // Authenticate as user
    this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
    
    // Create test site
    // - only create the site if it doesn't already exist
    SiteInfo siteInfo = this.siteService.getSite(SITE_SHORT_NAME_LINKS);
    if (siteInfo == null)
    {
        this.siteService.createSite("CalendarSitePreset", SITE_SHORT_NAME_LINKS, "LinksSiteTitle", "TestDescription", SiteVisibility.PUBLIC);
    }
    
    // Ensure the links container is there
    if (!siteService.hasContainer(SITE_SHORT_NAME_LINKS, "links"))
    {
        siteService.createContainer(SITE_SHORT_NAME_LINKS, "links", null, null);
    }
    
    // Create users
    createUser(USER_ONE, SiteModel.SITE_COLLABORATOR, SITE_SHORT_NAME_LINKS);
    createUser(USER_TWO, SiteModel.SITE_COLLABORATOR, SITE_SHORT_NAME_LINKS);

    // Do tests as inviter user
    this.authenticationComponent.setCurrentUser(USER_ONE);
}
 
Example 18
Project: alfresco-remote-api   File: CalendarRestApiTest.java   View source code 5 votes vote down vote up
@Override
protected void setUp() throws Exception
{
    super.setUp();
    
    this.authenticationService = (MutableAuthenticationService)getServer().getApplicationContext().getBean("AuthenticationService");
    this.authenticationComponent = (AuthenticationComponent)getServer().getApplicationContext().getBean("authenticationComponent");
    this.permissionService = (PermissionService)getServer().getApplicationContext().getBean("PermissionService");
    this.personService = (PersonService)getServer().getApplicationContext().getBean("PersonService");
    this.nodeService = (NodeService)getServer().getApplicationContext().getBean("NodeService");
    this.siteService = (SiteService)getServer().getApplicationContext().getBean("SiteService");
    this.nodeArchiveService = (NodeArchiveService)getServer().getApplicationContext().getBean("nodeArchiveService");
    
    // Authenticate as user
    this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
    
    // Create test site
    // - only create the site if it doesn't already exist
    SiteInfo siteInfo = this.siteService.getSite(SITE_SHORT_NAME_CALENDAR);
    if (siteInfo == null)
    {
        this.siteService.createSite("CalendarSitePreset", SITE_SHORT_NAME_CALENDAR, "CalendarSiteTitle", "BlogSiteDescription", SiteVisibility.PUBLIC);
    }
    
    // Ensure the calendar container is there
    if (!siteService.hasContainer(SITE_SHORT_NAME_CALENDAR, CalendarServiceImpl.CALENDAR_COMPONENT))
    {
        siteService.createContainer(SITE_SHORT_NAME_CALENDAR, CalendarServiceImpl.CALENDAR_COMPONENT, null, null);
    }
    
    // Create users
    createUser(USER_ONE, SiteModel.SITE_COLLABORATOR);
    createUser(USER_TWO, SiteModel.SITE_COLLABORATOR);
    createUser(USER_THREE, SiteModel.SITE_CONTRIBUTOR);
    createUser(USER_FOUR, SiteModel.SITE_CONSUMER);

    // Do tests as inviter user
    this.authenticationComponent.setCurrentUser(USER_ONE);
}
 
Example 19
Project: alfresco-repository   File: ActivityPosterImpl.java   View source code 5 votes vote down vote up
public ActivityInfo getActivityInfo(NodeRef nodeRef)
{
    SiteInfo siteInfo = siteService.getSite(nodeRef);
    String siteId = (siteInfo != null ? siteInfo.getShortName() : null);
    if(siteId != null && !siteId.equals(""))
    {
        NodeRef parentNodeRef = nodeService.getPrimaryParent(nodeRef).getParentRef();
        FileInfo fileInfo = fileFolderService.getFileInfo(nodeRef);
        String name = fileInfo.getName();
        boolean isFolder = fileInfo.isFolder();
            
        NodeRef documentLibrary = siteService.getContainer(siteId, SiteService.DOCUMENT_LIBRARY);
        String parentPath = "/";
        try
        {
            parentPath = getPathFromNode(documentLibrary, parentNodeRef);
        }
        catch (FileNotFoundException error)
        {
            if (logger.isDebugEnabled())
            {
                logger.debug("No " + SiteService.DOCUMENT_LIBRARY + " container found.");
            }
        }
        
        return new ActivityInfo(nodeRef, parentPath, parentNodeRef, siteId, name, isFolder);
    }
    else
    {
        return null;
    }
}
 
Example 20
Project: alfresco-repository   File: SiteServiceImplMoreTest.java   View source code 5 votes vote down vote up
@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);
}
 
Example 21
Project: alfresco-repository   File: CommentsTest.java   View source code 5 votes vote down vote up
@Before public void createSomeContentForCommentingOn() throws Exception
{
    // Create some content which we will comment on.
    testSite = testSites.createSite("sitePreset", "testSite", "test site title", "test site description", SiteVisibility.PUBLIC, USER_ONE_NAME);
    final NodeRef doclib = siteService.getContainer(testSite.getShortName(), SiteService.DOCUMENT_LIBRARY);
    testFolder = testNodes.createFolder(doclib, "testFolder", TEST_USER1.getUsername());
    testDocs = new ArrayList<NodeRef>(3);
    for (int i = 0; i < 3; i++)
    {
        NodeRef testNode = testNodes.createQuickFile(MimetypeMap.MIMETYPE_TEXT_PLAIN, testFolder, "testDocInFolder_" + GUID.generate() + "_" + i, TEST_USER1.getUsername());
        testDocs.add(testNode);
    }
}
 
Example 22
Project: alfresco-repository   File: AbstractSiteActivityTest.java   View source code 5 votes vote down vote up
@Before
public void setUp() throws Exception
{
    applicationContext = ApplicationContextHelper.getApplicationContext();
    String testid = ""+System.currentTimeMillis();
    
    // Let's shut down the scheduler so that we aren't competing with the scheduled versions of the post lookup and
    // feed generator jobs
    Scheduler scheduler = (Scheduler) applicationContext.getBean("schedulerFactory");
    scheduler.shutdown();
    
    // Get the required services
    this.activityService = (ActivityService)applicationContext.getBean("activityService");
    this.siteService = (SiteService)applicationContext.getBean("SiteService");
    this.authenticationService = (MutableAuthenticationService)applicationContext.getBean("AuthenticationService");
    this.personService = (PersonService)applicationContext.getBean("PersonService");
    this.nodeArchiveService = (NodeArchiveService)applicationContext.getBean("nodeArchiveService");
    
    LocalFeedTaskProcessor feedProcessor = null;
    
    // alternative: would need to add subsystem context to config location (see above)
    //this.postLookup = (PostLookup)applicationContext.getBean("postLookup");
    //this.feedGenerator = (FeedGenerator)applicationContext.getBean("feedGenerator");
    //feedProcessor = (LocalFeedTaskProcessor)applicationContext.getBean("feedTaskProcessor");
    
    ChildApplicationContextFactory activitiesFeed = (ChildApplicationContextFactory)applicationContext.getBean("ActivitiesFeed");
    ApplicationContext activitiesFeedCtx = activitiesFeed.getApplicationContext();
    this.postLookup = (PostLookup)activitiesFeedCtx.getBean("postLookup");
    this.feedGenerator = (FeedGenerator)activitiesFeedCtx.getBean("feedGenerator");
    feedProcessor = (LocalFeedTaskProcessor)activitiesFeedCtx.getBean("feedTaskProcessor");
    
    
    List<String> templateSearchPaths = new ArrayList<String>(1);
    templateSearchPaths.add(TEST_TEMPLATES_LOCATION);
    feedProcessor.setTemplateSearchPaths(templateSearchPaths);
    feedProcessor.setUseRemoteCallbacks(false);
    
    site1 = "test_site1_" + testid;
    site2 = "test_site2_" + testid;
    site3 = "test_site3_" + testid;
    
    user1 = "Test_User1_" + testid;
    user2 = "Test_User2_" + testid;
    user3 = "Test_User3_" + testid;
    user4 = "Test_User4_" + testid;
    
    
    // create users
    
    login(ADMIN_USER, ADMIN_PW);
    
    createUser(user1, USER_PW);
    createUser(user2, USER_PW);
    createUser(user3, USER_PW);
    createUser(user4, USER_PW);
    
    // create sites
    
    // create public site
    createSite(site1, true);
    
    // create private sites
    createSite(site2, false);
    createSite(site3, false);
}
 
Example 23
Project: alfresco-repository   File: FeedNotifierJobTest.java   View source code 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception
{
    ChildApplicationContextFactory activitiesFeed = (ChildApplicationContextFactory) ctx.getBean("ActivitiesFeed");
    ApplicationContext activitiesFeedCtx = activitiesFeed.getApplicationContext();
    feedNotifier = (FeedNotifierImpl) activitiesFeedCtx.getBean("feedNotifier");
    activityService = (ActivityService) activitiesFeedCtx.getBean("activityService");
    feedGenerator = (FeedGenerator) activitiesFeedCtx.getBean("feedGenerator");
    postLookup = (PostLookup) activitiesFeedCtx.getBean("postLookup");
    ObjectFactory<ActivitiesFeedModelBuilder> feedModelBuilderFactory = (ObjectFactory<ActivitiesFeedModelBuilder>) activitiesFeedCtx.getBean("feedModelBuilderFactory");
    EmailUserNotifier emailUserNotifier = (EmailUserNotifier) activitiesFeedCtx.getBean("emailUserNotifier");
    
    tenantAdminService = (TenantAdminService) ctx.getBean("tenantAdminService");
    transactionService = (TransactionService) ctx.getBean("transactionService");
    personService = (PersonService) ctx.getBean("personService");
    postDAO = (ActivityPostDAO) ctx.getBean("postDAO");
    nodeService = (NodeService) ctx.getBean("nodeService");
    namespaceService = (NamespaceService) ctx.getBean("namespaceService");
    siteService = (SiteService) ctx.getBean("siteService");
    repoAdminService = (RepoAdminService) ctx.getBean("repoAdminService");
    actionService = (ActionService) ctx.getBean("ActionService");
    authenticationContext = (AuthenticationContext) ctx.getBean("authenticationContext");
    EmailHelper emailHelper = (EmailHelper) ctx.getBean("emailHelper");
    
    AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
    // create some users
    transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
    {
        @SuppressWarnings("synthetic-access")
        public Void execute() throws Throwable
        {
            personNodeRef = createUser(userName1);
            failingPersonNodeRef = createUser(userName2);
            return null;
        }
    }, false, true);
    
    // use our own user notifier for testing purposes
    userNotifier = new RegisterErrorUserFeedNotifier();
    userNotifier.setNodeService(nodeService);
    userNotifier.setNamespaceService(namespaceService);
    userNotifier.setSiteService(siteService);
    userNotifier.setActivityService(activityService);
    userNotifier.setRepoAdminService(repoAdminService);
    userNotifier.setActionService(actionService);
    userNotifier.setActivitiesFeedModelBuilderFactory(feedModelBuilderFactory);
    userNotifier.setAuthenticationContext(authenticationContext);
    userNotifier.setExcludedEmailSuffixes(emailUserNotifier.getExcludedEmailSuffixes());
    userNotifier.setEmailHelper(emailHelper);
    feedNotifier.setUserNotifier(userNotifier);
    
    jobDetail = new JobDetail("feedNotifier", FeedNotifierJob.class);
    JobDataMap jobDataMap = jobDetail.getJobDataMap();
    jobDataMap.put("tenantAdminService", tenantAdminService);
    jobDataMap.put("feedNotifier", feedNotifier);
    feedNotifierJob = new FeedNotifierJob();
    
    when(jobCtx.getJobDetail()).thenReturn(jobDetail);
}
 
Example 24
Project: alfresco-repository   File: AbstractFeedCleanerTest.java   View source code 5 votes vote down vote up
@Before
public void setUp() throws Exception
{
    ctx = ApplicationContextHelper.getApplicationContext();
    JobLockService jobLockService = (JobLockService) ctx.getBean("JobLockService");
    PolicyComponent policyComponent = (PolicyComponent) ctx.getBean("policyComponent");
    NodeService nodeService = (NodeService) ctx.getBean("NodeService");

    siteService = (SiteService) ctx.getBean("SiteService");
    personService = (PersonService) ctx.getBean("PersonService");
    feedDAO = (ActivityFeedDAO) ctx.getBean("feedDAO");
    transactionHelper = (RetryingTransactionHelper)ctx.getBean("retryingTransactionHelper");
    nodeArchiveService = (NodeArchiveService)ctx.getBean("nodeArchiveService");
    
    // Let's shut down the scheduler so that we aren't competing with the scheduled versions of jobs (ie. feed cleaner)
    Scheduler scheduler = (Scheduler) ctx.getBean("schedulerFactory");
    scheduler.shutdown();
    
    tearDown();
    
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    for (int i = 1; i <= 7; i++)
    {
        siteService.createSite("myPreset", "testSite"+i, null, null, SiteVisibility.PUBLIC);
    }
    
    AuthenticationUtil.setRunAsUserSystem();
    
    // construct the test cleaner
    cleaner = new FeedCleaner();
    cleaner.setFeedDAO(feedDAO);
    cleaner.setPolicyComponent(policyComponent);
    cleaner.setJobLockService(jobLockService);
    cleaner.setNodeService(nodeService);
}
 
Example 25
Project: alfresco-repository   File: CalendarServiceImplTest.java   View source code 5 votes vote down vote up
@BeforeClass public static void initTestsContext() throws Exception
{
    AUTHENTICATION_SERVICE = (MutableAuthenticationService)testContext.getBean("authenticationService");
    BEHAVIOUR_FILTER       = (BehaviourFilter)testContext.getBean("policyBehaviourFilter");
    CALENDAR_SERVICE       = (CalendarService)testContext.getBean("CalendarService");
    DICTIONARY_SERVICE     = (DictionaryService)testContext.getBean("dictionaryService");
    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");
    // Get the canned query registry, and from that the factory
    @SuppressWarnings("unchecked")
    NamedObjectRegistry<CannedQueryFactory<? extends Object>> calendarCannedQueryRegistry =
       (NamedObjectRegistry<CannedQueryFactory<? extends Object>>)testContext.getBean("calendarCannedQueryRegistry");
    CALENDAR_CQ_FACTORY = (GetCalendarEntriesCannedQueryFactory)
       calendarCannedQueryRegistry.getNamedObject(CalendarServiceImpl.CANNED_QUERY_GET_ENTRIES);
    
    // 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();
}
 
Example 26
Project: alfresco-remote-api   File: QuickShareRestApiTest.java   View source code 5 votes vote down vote up
public void testUnshareContributer() throws UnsupportedEncodingException, IOException, JSONException
{
	final int expectedStatusOK = 200;
    final int expectedStatusForbidden = 403;
    
    authenticationComponent.setCurrentUser("admin");
	
    SiteInfo siteInfo = createSite("site" + RUN_ID);
    siteService.setMembership(siteInfo.getShortName(), USER_ONE, SiteModel.SITE_CONSUMER);
    siteService.setMembership(siteInfo.getShortName(), USER_TWO, SiteModel.SITE_CONTRIBUTOR);
    
    NodeRef siteDocLib = siteService.getContainer(siteInfo.getShortName(), SiteService.DOCUMENT_LIBRARY);
    NodeRef testFile = createTestFile(siteDocLib, "unshare-test" + RUN_ID, quickFile);
    
    String strTestNodeRef = testFile.toString().replace("://", "/");
    
    authenticationComponent.setCurrentUser(USER_ONE);
    
    // share
    Response rsp= sendRequest(new PostRequest(SHARE_URL.replace("{node_ref_3}", strTestNodeRef), "", APPLICATION_JSON), expectedStatusOK, USER_ONE);
    JSONObject jsonRsp = new JSONObject(new JSONTokener(rsp.getContentAsString()));
    String sharedId = jsonRsp.getString("sharedId");
    assertNotNull(sharedId);
    
    // unshare
    authenticationComponent.setCurrentUser(USER_TWO);
    rsp = sendRequest(new DeleteRequest(UNSHARE_URL.replace("{shared_id}", sharedId)), expectedStatusForbidden, USER_TWO);
    authenticationComponent.setCurrentUser(USER_ONE);
    rsp = sendRequest(new DeleteRequest(UNSHARE_URL.replace("{shared_id}", sharedId)), expectedStatusOK, USER_ONE);
    
    authenticationComponent.setCurrentUser("admin");
    deleteSite(siteInfo.getShortName());
}
 
Example 27
Project: alfresco-repository   File: MiscellaneousRulesTest.java   View source code 5 votes vote down vote up
@BeforeClass public static void initSpringBeans() throws Exception
{
    final ApplicationContext appCtxt = APP_CTXT_INIT.getApplicationContext();
    
    ACTION_SERVICE     = appCtxt.getBean("ActionService", ActionService.class);
    COPY_SERVICE       = appCtxt.getBean("CopyService", CopyService.class);
    NODE_SERVICE       = appCtxt.getBean("NodeService", NodeService.class);
    TRANSACTION_HELPER = appCtxt.getBean("retryingTransactionHelper", RetryingTransactionHelper.class);
    RULE_SERVICE       = appCtxt.getBean("RuleService", RuleService.class);
    SITE_SERVICE       = appCtxt.getBean("SiteService", SiteService.class);
}
 
Example 28
Project: alfresco-test-assertions   File: SiteAssertTest.java   View source code 5 votes vote down vote up
private SiteInfo createTestSite() {
    final String siteId = UUID.randomUUID().toString();
    final String siteTitle = siteId;
    final String siteDescription = siteId;
    final SiteInfo siteInfo = siteService.createSite(TEST_SITE_PRESET, siteId, siteTitle, siteDescription, SiteVisibility.PUBLIC);
    siteService.createContainer(siteInfo.getShortName(), SiteService.DOCUMENT_LIBRARY, ContentModel.TYPE_FOLDER, Collections.emptyMap());
    return siteInfo;
}
 
Example 29
Project: alfresco-repository   File: InviteSenderTest.java   View source code 5 votes vote down vote up
/**
 * Mocks up a SiteService that returns appropriate SiteInfo.
 * 
 * @return SiteService
 */
private SiteService mockSiteService()
{
    SiteService siteService = mock(SiteService.class);
    when(siteInfo.getShortName()).thenReturn(siteShortName);
    when(siteService.getSite(siteName)).thenReturn(siteInfo);
    return siteService;
}
 
Example 30
Project: alfresco-repository   File: InviteModeratedSenderTest.java   View source code 5 votes vote down vote up
/**
 * Mocks up a SiteService that returns appropriate SiteInfo.
 * 
 * @return SiteService
 */
private SiteService mockSiteService()
{
    SiteService siteService = mock(SiteService.class);
    when(siteInfo.getTitle()).thenReturn(fullSiteName);
    when(siteService.getSite(shortSiteName)).thenReturn(siteInfo);
    return siteService;
}
 
Example 31
Project: alfresco-repository   File: InvitationCleanupTest.java   View source code 5 votes vote down vote up
@BeforeClass public static void initStaticData() throws Exception
{
    INVITATION_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("InvitationService", InvitationService.class);
    SITE_SERVICE       = APP_CONTEXT_INIT.getApplicationContext().getBean("SiteService", SiteService.class);
    TRANSACTION_HELPER = APP_CONTEXT_INIT.getApplicationContext().getBean("retryingTransactionHelper", RetryingTransactionHelper.class);
    WORKFLOW_SERVICE   = APP_CONTEXT_INIT.getApplicationContext().getBean("WorkflowService", WorkflowService.class);
    NODE_ARCHIVE_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("nodeArchiveService", NodeArchiveService.class);
}
 
Example 32
Project: alfresco-repository   File: MultiTDemoTest.java   View source code 5 votes vote down vote up
private SiteInfo createSite(String siteId)
{
    SiteInfo siteInfo = siteService.createSite(null, siteId, "title - "+siteId, "description - "+siteId, SiteVisibility.PRIVATE);
    
    // ensure that the Document Library folder is pre-created so that test code can start creating content straight away.
    // At the time of writing V4.1 does not create this folder automatically, but Thor does.
    NodeRef result = siteService.getContainer(siteId, SiteService.DOCUMENT_LIBRARY);
    if (result == null)
    {
        result = siteService.createContainer(siteId, SiteService.DOCUMENT_LIBRARY, ContentModel.TYPE_FOLDER, null);
    }
    
    return siteInfo;
}
 
Example 33
Project: alfresco-repository   File: MultiTDemoTest.java   View source code 5 votes vote down vote up
public void test20_ALF_12732()
{
    final String tenantDomain1 = TEST_RUN+".one.alf12732";
    
    createTenant(tenantDomain1);
    
    String tenantAdminName = tenantService.getDomainUser(AuthenticationUtil.getAdminUserName(), tenantDomain1);
    
    try
    {
        AuthenticationUtil.setFullyAuthenticatedUser(tenantAdminName); // note: since SiteServiceImpl.setupSitePermissions currently uses getCurrentUserName (rather than runAs)
        
        TenantUtil.runAsUserTenant(new TenantRunAsWork<Object>()
        {
            public Object doWork() throws Exception
            {
                createSite("site1");
                
                NodeRef docLib1Ref = siteService.getContainer("site1", SiteService.DOCUMENT_LIBRARY);
                NodeRef contentRef = addContent(docLib1Ref, "tqbfjotld.txt", "The quick brown fox jumps over the lazy dog", MimetypeMap.MIMETYPE_TEXT_PLAIN);
                
                createSite("site2");
                
                NodeRef docLib2Ref = siteService.getContainer("site2", SiteService.DOCUMENT_LIBRARY);
                
                nodeService.moveNode(contentRef, docLib2Ref, ContentModel.ASSOC_CONTAINS, QName.createQName("tqbfjotld.txt"));
                
                // for Share, called via "move-to.post.json.js" -> ScriptSiteService.cleanSitePermissions
                siteService.cleanSitePermissions(contentRef, null);
                
                return null;
            }
        }, tenantAdminName, tenantDomain1);
    }
    finally
    {
        AuthenticationUtil.clearCurrentSecurityContext();
    }
}
 
Example 34
Project: alfresco-repository   File: DiscussionServiceImplTest.java   View source code 5 votes vote down vote up
@BeforeClass public static void initTestsContext() throws Exception
{
    testContext = ApplicationContextHelper.getApplicationContext();
    AUTHENTICATION_SERVICE = (MutableAuthenticationService)testContext.getBean("authenticationService");
    BEHAVIOUR_FILTER       = (BehaviourFilter)testContext.getBean("policyBehaviourFilter");
    DISCUSSION_SERVICE     = (DiscussionService)testContext.getBean("DiscussionService");
    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");
    TENANT_ADMIN_SERVICE   = testContext.getBean("tenantAdminService", TenantAdminService.class);

    ADMIN_USER = AuthenticationUtil.getAdminUserName() + "@" + TENANT_DOMAIN;

    createTenant();
    
    // Do the setup as admin
    AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
    TenantContextHolder.setTenantDomain(TENANT_DOMAIN);
    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);
    TenantContextHolder.setTenantDomain(TENANT_DOMAIN);
    createTestSites();
}
 
Example 35
Project: alfresco-repository   File: TemporarySitesTest.java   View source code 5 votes vote down vote up
@Test public void ensureTestSitesWereCreatedOk() throws Exception
{
    TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<Void>()
    {
        public Void execute() throws Throwable
        {
            final SiteInfo recoveredSite1 = SITE_SERVICE.getSite(testSite1.getShortName());
            final SiteInfo recoveredSite2 = SITE_SERVICE.getSite(testSite2.getShortName());
            
            assertNotNull("Test site does not exist", recoveredSite1);
            assertNotNull("Test site does not exist", recoveredSite2);
            
            assertEquals("cm:title was wrong", "t", recoveredSite1.getTitle());
            assertEquals("cm:description was wrong", "d", recoveredSite1.getDescription());
            assertEquals("preset was wrong", "sitePreset", recoveredSite1.getSitePreset());
            
            assertEquals("site visibility was wrong", SiteVisibility.PUBLIC, recoveredSite1.getVisibility());
            
            for (String siteShortName : new String[] { testSite1.getShortName(), testSite2.getShortName() })
            {
                assertNotNull("site had no doclib container node", SITE_SERVICE.getContainer(siteShortName, SiteService.DOCUMENT_LIBRARY));
            }
            
            return null;
        }
    });
}
 
Example 36
Project: alfresco-remote-api   File: SurfConfigTest.java   View source code 5 votes vote down vote up
@Override
protected void setUp() throws Exception
{
    super.setUp();
    this.siteService = (SiteService) getServer().getApplicationContext().getBean("SiteService");
    this.nodeService = (NodeService) getServer().getApplicationContext().getBean("NodeService");
    this.permissionService = (PermissionService) getServer().getApplicationContext().getBean("PermissionService");
    this.fileFolderService = (FileFolderService) getServer().getApplicationContext().getBean("FileFolderService");

    createUser(USER_ONE);
    createUser(USER_TWO);
    createUser(USER_THREE);

    AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE);
}
 
Example 37
Project: alfresco-remote-api   File: UploadWebScriptTest.java   View source code 5 votes vote down vote up
@Override
protected void setUp() throws Exception
{
    super.setUp();

    this.authenticationService = (MutableAuthenticationService) getServer().getApplicationContext().getBean("AuthenticationService");
    this.globalProperties = (Properties) getServer().getApplicationContext().getBean("global-properties");
    this.transactionService = (TransactionService) getServer().getApplicationContext().getBean("transactionService");
    this.siteService = (SiteService) getServer().getApplicationContext().getBean("SiteService");
    this.nodeService = (NodeService) getServer().getApplicationContext().getBean("nodeService");
    this.contentService = (ContentService) getServer().getApplicationContext().getBean("contentService");
    this.checkOutCheckInService = (CheckOutCheckInService) getServer().getApplicationContext().getBean("checkOutCheckInService");

    globalProperties.setProperty(AUTO_VERSION_PROPS_KEY, "true");

    transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>()
    {
        @Override
        public Void execute() throws Throwable
        {
            authenticationService.authenticate(ADMIN_CREDENTIAL, ADMIN_CREDENTIAL.toCharArray());
            fileName = "quick-2.pdf";
            file = getResourceFile(fileName);

            // Create a Public site
            SiteInfo siteInfo = createSite("site" + GUID.generate(), "doclib", SiteVisibility.PUBLIC);
            
            //Upload file in a site using webScript
            Response response = uploadFileWs(file, fileName, siteInfo.getShortName(), "doclib");
            assertNotNull("content of file", response.getContentAsString());
            JSONObject jsonRsp = (JSONObject) JSONValue.parse(response.getContentAsString());
            final String ssdNodeRefString = (String) jsonRsp.get("nodeRef");
            assertNotNull("nodeRef", ssdNodeRefString);
            documentSite = new NodeRef(ssdNodeRefString);

            return null;
        }
    });
}
 
Example 38
Project: alfresco-remote-api   File: QuickShareRestApiTest.java   View source code 5 votes vote down vote up
@Override
protected void setUp() throws Exception
{
    super.setUp();
    authenticationService = (MutableAuthenticationService) getServer().getApplicationContext().getBean("AuthenticationService");
    authenticationComponent = (AuthenticationComponent) getServer().getApplicationContext().getBean("AuthenticationComponent");
    nodeService = (NodeService) getServer().getApplicationContext().getBean("NodeService");
    contentService = (ContentService) getServer().getApplicationContext().getBean("ContentService");
    personService = (PersonService) getServer().getApplicationContext().getBean("PersonService");
    permissionService = (PermissionService) getServer().getApplicationContext().getBean("PermissionService");
    siteService = (SiteService) getServer().getApplicationContext().getBean("SiteService"); 
    repositoryHelper = (Repository) getServer().getApplicationContext().getBean("repositoryHelper");
    transactionHelper = (RetryingTransactionHelper)getServer().getApplicationContext().getBean("retryingTransactionHelper");
    fileFolderService = (FileFolderService)getServer().getApplicationContext().getBean("FileFolderService");
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
    
    createUser(USER_ONE);
    createUser(USER_TWO);
    
    AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE);
    
    userOneHome = repositoryHelper.getUserHome(personService.getPerson(USER_ONE));
    // no pun intended
    quickFile = AbstractContentTransformerTest.loadQuickTestFile("jpg");
    TEST_CONTENT = new byte[new Long(quickFile.length()).intValue()];
    new FileInputStream(quickFile).read(TEST_CONTENT);
    testNode = createTestFile(userOneHome, TEST_NAME, quickFile);
    
    AuthenticationUtil.setFullyAuthenticatedUser(USER_TWO);
    
    assertEquals(AccessStatus.DENIED, permissionService.hasPermission(testNode, PermissionService.READ));

    AuthenticationUtil.clearCurrentSecurityContext();
}
 
Example 39
Project: alfresco-remote-api   File: MkcolMethod.java   View source code 5 votes vote down vote up
/**
 * Create a folder added activity post.
 * 
 * @throws WebDAVServerException 
 */
private void postActivity(FileInfo fileInfo) throws WebDAVServerException
{
    WebDavService davService = getDAVHelper().getServiceRegistry().getWebDavService();
    if (!davService.activitiesEnabled())
    {
        // Don't post activities if this behaviour is disabled.
        return;
    }
    
    String siteId = getSiteId();
    String tenantDomain = getTenantDomain();
    
    // Check there is enough information to publish site activity.
    if (!siteId.equals(WebDAVHelper.EMPTY_SITE_ID))
    {
        SiteService siteService = getServiceRegistry().getSiteService();
        NodeRef documentLibrary = siteService.getContainer(siteId, SiteService.DOCUMENT_LIBRARY);
        String path = "/";
        try
        {
            path = getDAVHelper().getPathFromNode(documentLibrary, fileInfo.getNodeRef());
        }
        catch (FileNotFoundException error)
        {
            if (logger.isDebugEnabled())
            {
                logger.debug("No " + SiteService.DOCUMENT_LIBRARY + " container found.");
            }
        }
        
        activityPoster.postFileFolderAdded(siteId, tenantDomain, path, fileInfo);
    }
}
 
Example 40
Project: alfresco-remote-api   File: NodeWebScripTest.java   View source code 5 votes vote down vote up
private SiteInfo createSite(final String shortName)
{
    return retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<SiteInfo>()
       {
          @Override
          public SiteInfo execute() throws Throwable
          {
              SiteInfo siteInfo = siteService.getSite(shortName);
              if (siteInfo != null)
              {
                  // Tidy up after failed earlier run
                  siteService.deleteSite(shortName);
                  nodeArchiveService.purgeArchivedNode(nodeArchiveService.getArchivedNode(siteInfo.getNodeRef()));
              }
              
              // Do the create
              SiteInfo site = siteService.createSite("Testing", shortName, shortName, null, SiteVisibility.PUBLIC);
              
              // Ensure we have a doclib
              siteService.createContainer(shortName, SiteService.DOCUMENT_LIBRARY, ContentModel.TYPE_FOLDER, null);
              
              // All done
              return site;
          }
       }, false, true
    ); 
}