Search in sources :

Example 56 with SiteInfo

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

the class ReadOnlyTransactionInGetRestApiTest method tearDown.

/* (non-Javadoc)
     * @see junit.framework.TestCase#tearDown()
     */
@Override
protected void tearDown() throws Exception {
    super.tearDown();
    SiteInfo site = siteService.getSite(TEST_SITE_NAME);
    // use retrying transaction to delete the site
    this.transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            // delete the test site
            siteService.deleteSite(TEST_SITE_NAME);
            return null;
        }
    });
    nodeArchiveService.purgeArchivedNode(nodeArchiveService.getArchivedNode(site.getNodeRef()));
    AuthenticationUtil.clearCurrentSecurityContext();
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo)

Example 57 with SiteInfo

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

the class RenameSiteAuthorityDisplayName method renameDispayNames.

/**
 * Rename display names of authorities of sites.
 *
 * @param siteInfos
 *            list of sites
 */
private void renameDispayNames(final List<SiteInfo> siteInfos) {
    final String tenantDomain = tenantAdminService.getCurrentUserDomain();
    final Iterator<SiteInfo> pathItr = siteInfos.listIterator();
    BatchProcessWorkProvider<SiteInfo> siteWorkProvider = new BatchProcessWorkProvider<SiteInfo>() {

        @Override
        public int getTotalEstimatedWorkSize() {
            return siteInfos.size();
        }

        @Override
        public Collection<SiteInfo> getNextWork() {
            int batchCount = 0;
            List<SiteInfo> nodes = new ArrayList<SiteInfo>(BATCH_SIZE);
            while (pathItr.hasNext() && batchCount++ != BATCH_SIZE) {
                nodes.add(pathItr.next());
            }
            return nodes;
        }
    };
    // prepare the batch processor and worker object
    BatchProcessor<SiteInfo> siteBatchProcessor = new BatchProcessor<SiteInfo>("RenameSiteAuthorityDisplayName", this.transactionHelper, siteWorkProvider, BATCH_THREADS, BATCH_SIZE, this.applicationEventPublisher, progress_logger, BATCH_SIZE * 10);
    BatchProcessWorker<SiteInfo> worker = new BatchProcessWorker<SiteInfo>() {

        @Override
        public String getIdentifier(SiteInfo entry) {
            return entry.getShortName();
        }

        @Override
        public void beforeProcess() throws Throwable {
            // Disable rules
            ruleService.disableRules();
            // Authentication
            String systemUser = AuthenticationUtil.getSystemUserName();
            systemUser = tenantAdminService.getDomainUser(systemUser, tenantDomain);
            AuthenticationUtil.setRunAsUser(systemUser);
        }

        @Override
        public void afterProcess() throws Throwable {
            // Enable rules
            ruleService.enableRules();
            // Clear authentication
            AuthenticationUtil.clearCurrentSecurityContext();
        }

        @Override
        public void process(SiteInfo siteInfo) throws Throwable {
            // Set all the permissions of site
            Set<AccessPermission> sitePermissions = permissionService.getAllSetPermissions(siteInfo.getNodeRef());
            for (AccessPermission sitePermission : sitePermissions) {
                // Use only GROUP authority
                if (sitePermission.getAuthorityType() == AuthorityType.GROUP) {
                    String authorityName = sitePermission.getAuthority();
                    String currDisplayName = authorityService.getAuthorityDisplayName(authorityName);
                    String necessaryName = ((SiteServiceImpl) siteService).getSiteRoleGroup(siteInfo.getShortName(), sitePermission.getPermission(), false);
                    String alternativeName = ((SiteServiceImpl) siteService).getSiteRoleGroup(siteInfo.getShortName(), sitePermission.getPermission(), true);
                    // check for correct displayName
                    if ((!necessaryName.equalsIgnoreCase(currDisplayName)) || (!alternativeName.equalsIgnoreCase(currDisplayName))) {
                        // fix incorrect display name
                        authorityService.setAuthorityDisplayName(authorityName, necessaryName);
                    }
                }
            }
        }
    };
    siteBatchProcessor.process(worker, true);
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) ArrayList(java.util.ArrayList) AccessPermission(org.alfresco.service.cmr.security.AccessPermission) SiteServiceImpl(org.alfresco.repo.site.SiteServiceImpl) BatchProcessWorkProvider(org.alfresco.repo.batch.BatchProcessWorkProvider) BatchProcessWorker(org.alfresco.repo.batch.BatchProcessor.BatchProcessWorker) BatchProcessor(org.alfresco.repo.batch.BatchProcessor)

Example 58 with SiteInfo

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

the class CalendarAllDayEventDatesCorrectingPatch method applyInternal.

@Override
protected String applyInternal() throws Exception {
    int updatedEventsAmount = 0;
    NodeRef siteRoot = siteService.getSiteRoot();
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Site root: " + siteRoot);
    }
    List<ChildAssociationRef> allSites = (null != siteRoot) ? (nodeService.getChildAssocs(siteRoot)) : (null);
    if ((null != allSites) && !allSites.isEmpty()) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Starting processing of " + allSites.size() + " sites...");
        }
        PagingResults<CalendarEntry> entries = null;
        String queryId = null;
        int maxItems = (batchEnabled) ? (batchSize) : (Integer.MAX_VALUE);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Batching info:\n\t- batching enabled: " + batchEnabled + ";\n\t-batch size: " + batchSize);
        }
        for (ChildAssociationRef siteAssoc : allSites) {
            SiteInfo site = siteService.getSite(siteAssoc.getChildRef());
            if (null != site) {
                int skipCount = 0;
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Processing a site: [short name: " + site.getShortName() + ", title: " + site.getTitle() + ", visibility: " + site.getVisibility() + "]");
                }
                do {
                    PagingRequest paging = new PagingRequest(skipCount, maxItems, queryId);
                    entries = calendarService.listCalendarEntries(site.getShortName(), paging);
                    List<CalendarEntry> page = (null != entries) ? (entries.getPage()) : (null);
                    if (null != page) {
                        if (LOGGER.isDebugEnabled()) {
                            LOGGER.debug("Processing " + page.size() + " Calendar Events...");
                        }
                        queryId = entries.getQueryExecutionId();
                        for (CalendarEntry entry : page) {
                            if (isAllDay(entry)) {
                                updatedEventsAmount++;
                                if (LOGGER.isDebugEnabled()) {
                                    LOGGER.debug("'All Day' Calendar event has been detected: [title: " + entry.getTitle() + ", start: " + entry.getStart() + ", end: " + entry.getEnd() + ", isOutlook: " + entry.isOutlook() + "]");
                                }
                                nodeService.setProperty(entry.getNodeRef(), CalendarModel.PROP_TO_DATE, adjustOldDate(entry.getEnd()));
                                nodeService.setProperty(entry.getNodeRef(), CalendarModel.PROP_FROM_DATE, adjustOldDate(entry.getStart()));
                            }
                        }
                        skipCount += maxItems;
                    }
                } while (batchEnabled && entries.hasMoreItems());
            } else {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Not site object has been detected. Skipping...");
                }
            }
        }
    } else {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("No one site has been found! Skipping patch execution...");
        }
    }
    return I18NUtil.getMessage(MSG_SUCCESS, updatedEventsAmount);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) CalendarEntry(org.alfresco.service.cmr.calendar.CalendarEntry) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) PagingRequest(org.alfresco.query.PagingRequest)

Example 59 with SiteInfo

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

the class SWSDPPatch method applyInternal.

@Override
protected String applyInternal() throws Exception {
    SiteInfo siteInfo = siteService.getSite("swsdp");
    if (siteInfo != null) {
        NodeRef nodeRef = siteInfo.getNodeRef();
        NodeRef surfConfigNodeRef = nodeService.getChildByName(nodeRef, ContentModel.ASSOC_CONTAINS, "surf-config");
        if (surfConfigNodeRef == null) {
            return I18NUtil.getMessage(MSG_MISSING_SURFCONFIG);
        } else {
            for (ChildAssociationRef childRef : nodeService.getChildAssocs(surfConfigNodeRef, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL)) {
                hiddenAspect.showNode(childRef.getChildRef(), true);
            }
        }
        return I18NUtil.getMessage(MSG_SITE_PATCHED);
    } else {
        return I18NUtil.getMessage(MSG_SKIPPED);
    }
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 60 with SiteInfo

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

the class FavouritesServiceImpl method removeFavouriteSite.

private boolean removeFavouriteSite(String userName, NodeRef nodeRef) {
    PrefKeys prefKeys = getPrefKeys(Type.SITE);
    boolean exists = false;
    SiteInfo siteInfo = siteService.getSite(nodeRef);
    if (siteInfo != null) {
        StringBuilder sitePrefKeyBuilder = new StringBuilder(prefKeys.getSharePrefKey());
        sitePrefKeyBuilder.append(siteInfo.getShortName());
        String sitePrefKey = sitePrefKeyBuilder.toString();
        String siteFavouritedKey = siteFavouritedKey(siteInfo);
        exists = preferenceService.getPreference(userName, siteFavouritedKey) != null;
        preferenceService.clearPreferences(userName, sitePrefKey);
    } else {
        throw new IllegalArgumentException("NodeRef " + nodeRef + " is not a site");
    }
    return exists;
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo)

Aggregations

SiteInfo (org.alfresco.service.cmr.site.SiteInfo)190 NodeRef (org.alfresco.service.cmr.repository.NodeRef)83 Test (org.junit.Test)48 FilterPropString (org.alfresco.repo.node.getchildren.FilterPropString)45 ArrayList (java.util.ArrayList)32 QName (org.alfresco.service.namespace.QName)29 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)27 BaseAlfrescoSpringTest (org.alfresco.util.BaseAlfrescoSpringTest)26 HashMap (java.util.HashMap)22 Serializable (java.io.Serializable)20 RelationshipResourceNotFoundException (org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException)18 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)17 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)17 BaseUnitTest (org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest)15 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)15 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)14 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)14 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)12 Date (java.util.Date)9 PagingRequest (org.alfresco.query.PagingRequest)9