Search in sources :

Example 11 with SiteInfo

use of org.alfresco.service.cmr.site.SiteInfo in project alfresco-remote-api by Alfresco.

the class BlogServiceTest method setUp.

// General methods
@Override
protected void setUp() throws Exception {
    super.setUp();
    this.authenticationService = (MutableAuthenticationService) getServer().getApplicationContext().getBean("AuthenticationService");
    this.authenticationComponent = (AuthenticationComponent) getServer().getApplicationContext().getBean("authenticationComponent");
    this.personService = (PersonService) getServer().getApplicationContext().getBean("PersonService");
    this.siteService = (SiteService) getServer().getApplicationContext().getBean("SiteService");
    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_BLOG);
    if (siteInfo == null) {
        this.siteService.createSite("BlogSitePreset", SITE_SHORT_NAME_BLOG, "BlogSiteTitle", "BlogSiteDescription", SiteVisibility.PUBLIC);
    }
    // Create users
    createUser(USER_ONE, SiteModel.SITE_COLLABORATOR, SITE_SHORT_NAME_BLOG);
    createUser(USER_TWO, SiteModel.SITE_COLLABORATOR, SITE_SHORT_NAME_BLOG);
    // Blank our lists used to track things the test creates
    posts = new ArrayList<String>(5);
    drafts = new ArrayList<String>(5);
    // Do tests as inviter user
    this.authenticationComponent.setCurrentUser(USER_ONE);
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) ApplicationContext(org.springframework.context.ApplicationContext) ChildApplicationContextFactory(org.alfresco.repo.management.subsystems.ChildApplicationContextFactory)

Example 12 with SiteInfo

use of org.alfresco.service.cmr.site.SiteInfo in project alfresco-remote-api by Alfresco.

the class CalendarRestApiTest method tearDown.

@Override
protected void tearDown() throws Exception {
    super.tearDown();
    // admin user required to delete user
    this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
    SiteInfo siteInfo = this.siteService.getSite(SITE_SHORT_NAME_CALENDAR);
    if (siteInfo != null) {
        // delete invite site
        siteService.deleteSite(SITE_SHORT_NAME_CALENDAR);
        nodeArchiveService.purgeArchivedNode(nodeArchiveService.getArchivedNode(siteInfo.getNodeRef()));
    }
    // delete the users
    deleteUser(USER_ONE);
    deleteUser(USER_TWO);
    deleteUser(USER_THREE);
    deleteUser(USER_FOUR);
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo)

Example 13 with SiteInfo

use of org.alfresco.service.cmr.site.SiteInfo in project alfresco-remote-api by Alfresco.

the class CommentsApiTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    ApplicationContext appContext = getServer().getApplicationContext();
    fileFolderService = (FileFolderService) appContext.getBean("fileFolderService");
    transactionService = (TransactionService) appContext.getBean("transactionService");
    searchService = (SearchService) appContext.getBean("SearchService");
    nodeService = (NodeService) appContext.getBean("nodeService");
    namespaceService = (NamespaceService) appContext.getBean("namespaceService");
    versionService = (VersionService) appContext.getBean("versionService");
    personService = (PersonService) getServer().getApplicationContext().getBean("PersonService");
    authenticationService = (MutableAuthenticationService) getServer().getApplicationContext().getBean("AuthenticationService");
    authenticationComponent = (AuthenticationComponent) getServer().getApplicationContext().getBean("authenticationComponent");
    permissionService = (PermissionServiceSPI) getServer().getApplicationContext().getBean("permissionService");
    permissionModelDAO = (ModelDAO) getServer().getApplicationContext().getBean("permissionsModelDAO");
    siteService = (SiteService) getServer().getApplicationContext().getBean("SiteService");
    personService = (PersonService) getServer().getApplicationContext().getBean("PersonService");
    nodeArchiveService = (NodeArchiveService) getServer().getApplicationContext().getBean("nodeArchiveService");
    activityService = (ActivityService) getServer().getApplicationContext().getBean("activityService");
    ChildApplicationContextFactory activitiesFeed = (ChildApplicationContextFactory) getServer().getApplicationContext().getBean("ActivitiesFeed");
    ApplicationContext activitiesFeedCtx = activitiesFeed.getApplicationContext();
    feedGenerator = (FeedGenerator) activitiesFeedCtx.getBean("feedGenerator");
    postLookup = (PostLookup) activitiesFeedCtx.getBean("postLookup");
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    txn = transactionService.getUserTransaction();
    txn.begin();
    // Get Company Home
    rootNodeRef = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
    List<NodeRef> results = searchService.selectNodes(rootNodeRef, "/app:company_home", null, namespaceService, false);
    if (results.size() == 0) {
        throw new AlfrescoRuntimeException("Can't find /app:company_home");
    }
    companyHomeNodeRef = results.get(0);
    // Get Shared
    results = searchService.selectNodes(rootNodeRef, "/app:company_home/app:shared", null, namespaceService, false);
    if (results.size() == 0) {
        throw new AlfrescoRuntimeException("Can't find /app:company_home/app:shared");
    }
    sharedHomeNodeRef = results.get(0);
    results = searchService.selectNodes(rootNodeRef, "/app:company_home/cm:Commenty", null, namespaceService, false);
    if (results.size() > 0) {
        fileFolderService.delete(results.get(0));
    }
    nodeRef = fileFolderService.create(companyHomeNodeRef, "Commenty", ContentModel.TYPE_CONTENT).getNodeRef();
    versionService.ensureVersioningEnabled(nodeRef, null);
    nodeService.setProperty(nodeRef, ContentModel.PROP_AUTO_VERSION_PROPS, true);
    createUser(USER2);
    createUser(USER_TEST);
    txn.commit();
    AuthenticationUtil.clearCurrentSecurityContext();
    // MNT-12082
    // Authenticate as admin
    AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
    // Create test site
    // - only create the site if it doesn't already exist
    SiteInfo siteInfo = siteService.getSite(SITE_SHORT_NAME);
    if (siteInfo == null) {
        siteInfo = siteService.createSite("SomeTestSite", SITE_SHORT_NAME, "SiteTitle", "SiteDescription", SiteVisibility.PUBLIC);
    }
    NodeRef docLibContainer = siteService.getContainer(SITE_SHORT_NAME, DOCLIB_CONTAINER);
    if (docLibContainer == null) {
        siteService.createContainer(SITE_SHORT_NAME, DOCLIB_CONTAINER, ContentModel.TYPE_FOLDER, null);
    }
    txn = transactionService.getUserTransaction();
    txn.begin();
    // Create users
    createUser(USER_ONE, SiteModel.SITE_CONSUMER);
    createUser(USER_TWO, SiteModel.SITE_CONTRIBUTOR);
    createUser(USER_THREE, SiteModel.SITE_COLLABORATOR);
    createUser(USER_FOUR, SiteModel.SITE_COLLABORATOR);
    // Create site page
    sitePage = nodeService.createNode(siteInfo.getNodeRef(), ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, "test"), ContentModel.TYPE_CONTENT).getChildRef();
    txn.commit();
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) ApplicationContext(org.springframework.context.ApplicationContext) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ChildApplicationContextFactory(org.alfresco.repo.management.subsystems.ChildApplicationContextFactory)

Example 14 with SiteInfo

use of org.alfresco.service.cmr.site.SiteInfo in project alfresco-remote-api by Alfresco.

the class FavouritesImpl method addFavourite.

@Override
public Favourite addFavourite(String personId, Favourite favourite, Parameters parameters) {
    Favourite ret = null;
    personId = people.validatePerson(personId, true);
    Target target = favourite.getTarget();
    if (target == null) {
        throw new InvalidArgumentException("target is missing");
    } else if (target instanceof SiteTarget) {
        SiteTarget siteTarget = (SiteTarget) target;
        String guid = siteTarget.getSite().getGuid();
        SiteInfo siteInfo = sites.validateSite(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, guid));
        NodeRef siteNodeRef = siteInfo.getNodeRef();
        String siteId = siteInfo.getShortName();
        try {
            PersonFavourite personFavourite = favouritesService.addFavourite(personId, siteNodeRef);
            ret = getFavourite(personFavourite, parameters);
        } catch (SiteDoesNotExistException e) {
            throw new RelationshipResourceNotFoundException(personId, siteId);
        }
    } else if (target instanceof DocumentTarget) {
        DocumentTarget documentTarget = (DocumentTarget) target;
        NodeRef nodeRef = documentTarget.getFile().getGuid();
        if (!nodes.nodeMatches(nodeRef, Collections.singleton(ContentModel.TYPE_CONTENT), null)) {
            throw new RelationshipResourceNotFoundException(personId, nodeRef.getId());
        }
        PersonFavourite personFavourite = favouritesService.addFavourite(personId, nodeRef);
        ret = getFavourite(personFavourite, parameters);
    } else if (target instanceof FolderTarget) {
        FolderTarget folderTarget = (FolderTarget) target;
        NodeRef nodeRef = folderTarget.getFolder().getGuid();
        if (!nodes.nodeMatches(nodeRef, Collections.singleton(ContentModel.TYPE_FOLDER), Collections.singleton(SiteModel.TYPE_SITE))) {
            throw new RelationshipResourceNotFoundException(personId, nodeRef.getId());
        }
        PersonFavourite personFavourite = favouritesService.addFavourite(personId, nodeRef);
        ret = getFavourite(personFavourite, parameters);
    }
    return ret;
}
Also used : RelationshipResourceNotFoundException(org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SiteTarget(org.alfresco.rest.api.model.SiteTarget) DocumentTarget(org.alfresco.rest.api.model.DocumentTarget) FolderTarget(org.alfresco.rest.api.model.FolderTarget) Target(org.alfresco.rest.api.model.Target) DocumentTarget(org.alfresco.rest.api.model.DocumentTarget) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) PersonFavourite(org.alfresco.repo.favourites.PersonFavourite) SiteDoesNotExistException(org.alfresco.repo.site.SiteDoesNotExistException) SiteTarget(org.alfresco.rest.api.model.SiteTarget) FolderTarget(org.alfresco.rest.api.model.FolderTarget) PersonFavourite(org.alfresco.repo.favourites.PersonFavourite) Favourite(org.alfresco.rest.api.model.Favourite)

Example 15 with SiteInfo

use of org.alfresco.service.cmr.site.SiteInfo in project alfresco-remote-api by Alfresco.

the class NodesImpl method getActivityInfo.

// note: see also org.alfresco.opencmis.ActivityPosterImpl
protected ActivityInfo getActivityInfo(NodeRef parentNodeRef, NodeRef nodeRef) {
    // runAs system, eg. user may not have permission see one or more parents (irrespective of whether in a site context of not)
    SiteInfo siteInfo = AuthenticationUtil.runAs(new RunAsWork<SiteInfo>() {

        @Override
        public SiteInfo doWork() throws Exception {
            return siteService.getSite(nodeRef);
        }
    }, AuthenticationUtil.getSystemUserName());
    String siteId = (siteInfo != null ? siteInfo.getShortName() : null);
    if (siteId != null && !siteId.equals("")) {
        FileInfo fileInfo = fileFolderService.getFileInfo(nodeRef);
        if (fileInfo != null) {
            boolean isContent = isSubClass(fileInfo.getType(), ContentModel.TYPE_CONTENT);
            if (fileInfo.isFolder() || isContent) {
                return new ActivityInfo(null, parentNodeRef, siteId, fileInfo);
            }
        }
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("Non-site activity, so ignored " + nodeRef);
        }
    }
    return null;
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) ActivityInfo(org.alfresco.service.cmr.activities.ActivityInfo) FileInfo(org.alfresco.service.cmr.model.FileInfo) FileExistsException(org.alfresco.service.cmr.model.FileExistsException) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) DuplicateChildNodeNameException(org.alfresco.service.cmr.repository.DuplicateChildNodeNameException) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) ConcurrencyFailureException(org.springframework.dao.ConcurrencyFailureException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) ApiException(org.alfresco.rest.framework.core.exceptions.ApiException) IntegrityException(org.alfresco.repo.node.integrity.IntegrityException) IOException(java.io.IOException) RequestEntityTooLargeException(org.alfresco.rest.framework.core.exceptions.RequestEntityTooLargeException) DisabledServiceException(org.alfresco.rest.framework.core.exceptions.DisabledServiceException) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) ContentQuotaException(org.alfresco.service.cmr.usage.ContentQuotaException) UnsupportedMediaTypeException(org.alfresco.rest.framework.core.exceptions.UnsupportedMediaTypeException) AssociationExistsException(org.alfresco.service.cmr.repository.AssociationExistsException) InsufficientStorageException(org.alfresco.rest.framework.core.exceptions.InsufficientStorageException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) NodeLockedException(org.alfresco.service.cmr.lock.NodeLockedException) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException) ContentLimitViolationException(org.alfresco.repo.content.ContentLimitViolationException)

Aggregations

SiteInfo (org.alfresco.service.cmr.site.SiteInfo)103 NodeRef (org.alfresco.service.cmr.repository.NodeRef)42 ArrayList (java.util.ArrayList)22 Test (org.junit.Test)18 BaseUnitTest (org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest)15 FilterPropString (org.alfresco.repo.node.getchildren.FilterPropString)15 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)15 RelationshipResourceNotFoundException (org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException)15 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)13 QName (org.alfresco.service.namespace.QName)13 HashMap (java.util.HashMap)12 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)12 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)12 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)12 IOException (java.io.IOException)8 Serializable (java.io.Serializable)8 JSONObject (org.json.simple.JSONObject)8 RMSite (org.alfresco.rm.rest.api.model.RMSite)7 UnknownAuthorityException (org.alfresco.repo.security.authority.UnknownAuthorityException)5 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)5