protected Activity getActivity(ThemeDisplay themeDisplay, SocialActivity socialActivity) throws Exception { Activity activity = null; String className = socialActivity.getClassName(); if (className.equals(Activity.class.getName())) { activity = getExternalActivity(socialActivity); } else { activity = new ActivityImpl( String.valueOf(socialActivity.getClassPK()), String.valueOf(socialActivity.getUserId())); HttpServletRequest request = HttpServletRequestThreadLocal.getHttpServletRequest(); request.setAttribute(WebKeys.THEME_DISPLAY, themeDisplay); ServiceContext serviceContext = ServiceContextFactory.getInstance(request); serviceContext.setCompanyId(themeDisplay.getCompanyId()); serviceContext.setUserId(themeDisplay.getUserId()); SocialActivityFeedEntry socialActivityFeedEntry = null; SocialActivityInterpreterLocalServiceUtil.interpret( StringPool.BLANK, socialActivity, serviceContext); activity.setBody(socialActivityFeedEntry.getBody()); activity.setTitle(socialActivityFeedEntry.getTitle()); activity.setUrl(socialActivityFeedEntry.getLink()); } return activity; }
protected AssetCategory getAssetCategory(long userId, long groupId, String name) throws PortalException, SystemException { AssetVocabulary assetVocabulary = assetVocabularyPersistence.fetchByG_N(groupId, _ASSET_VOCABULARY_NAME); ServiceContext serviceContext = new ServiceContext(); serviceContext.setScopeGroupId(groupId); serviceContext.setUserId(userId); if (assetVocabulary == null) { assetVocabulary = assetVocabularyLocalService.addVocabulary(userId, _ASSET_VOCABULARY_NAME, serviceContext); } AssetCategory assetCategory = assetCategoryPersistence.fetchByP_N_V( AssetCategoryConstants.DEFAULT_PARENT_CATEGORY_ID, name, assetVocabulary.getVocabularyId()); if (assetCategory != null) { return assetCategory; } return assetCategoryLocalService.addCategory( userId, name, assetVocabulary.getVocabularyId(), serviceContext); }
@Override public void cascadeFileEntryTypes(long userId, DLFolder dlFolder) throws PortalException { long[] groupIds = PortalUtil.getCurrentAndAncestorSiteGroupIds(dlFolder.getGroupId()); List<DLFileEntryType> dlFileEntryTypes = getFolderFileEntryTypes(groupIds, dlFolder.getFolderId(), true); List<Long> fileEntryTypeIds = getFileEntryTypeIds(dlFileEntryTypes); long defaultFileEntryTypeId = getDefaultFileEntryTypeId(dlFolder.getFolderId()); ServiceContext serviceContext = new ServiceContext(); serviceContext.setCompanyId(dlFolder.getCompanyId()); serviceContext.setScopeGroupId(dlFolder.getGroupId()); serviceContext.setUserId(userId); cascadeFileEntryTypes( userId, dlFolder.getGroupId(), dlFolder.getFolderId(), defaultFileEntryTypeId, fileEntryTypeIds, serviceContext); }
@Override public List<WorkflowTask> getWorkflowTasksByWorkflowInstance( long companyId, Long userId, long workflowInstanceId, Boolean completed, int start, int end, OrderByComparator<WorkflowTask> orderByComparator) throws WorkflowException { try { ServiceContext serviceContext = new ServiceContext(); serviceContext.setCompanyId(companyId); if (userId != null) { serviceContext.setUserId(userId); } List<KaleoTaskInstanceToken> kaleoTaskInstanceTokens = KaleoTaskInstanceTokenLocalServiceUtil.getKaleoTaskInstanceTokens( workflowInstanceId, completed, start, end, KaleoTaskInstanceTokenOrderByComparator.getOrderByComparator(orderByComparator), serviceContext); return toWorkflowTasks(kaleoTaskInstanceTokens); } catch (Exception e) { throw new WorkflowException(e); } }
@Override public List<WorkflowTask> search( long companyId, long userId, String keywords, String[] assetTypes, Boolean completed, Boolean searchByUserRoles, int start, int end, OrderByComparator<WorkflowTask> orderByComparator) throws WorkflowException { try { ServiceContext serviceContext = new ServiceContext(); serviceContext.setCompanyId(companyId); serviceContext.setUserId(userId); List<KaleoTaskInstanceToken> kaleoTaskInstanceTokens = KaleoTaskInstanceTokenLocalServiceUtil.search( keywords, assetTypes, completed, searchByUserRoles, start, end, KaleoTaskInstanceTokenOrderByComparator.getOrderByComparator(orderByComparator), serviceContext); return toWorkflowTasks(kaleoTaskInstanceTokens); } catch (Exception e) { throw new WorkflowException(e); } }
@Override public int searchCount( long companyId, long userId, String taskName, String assetType, Long[] assetPrimaryKey, Date dueDateGT, Date dueDateLT, Boolean completed, Boolean searchByUserRoles, boolean andOperator) throws WorkflowException { try { ServiceContext serviceContext = new ServiceContext(); serviceContext.setCompanyId(companyId); serviceContext.setUserId(userId); return KaleoTaskInstanceTokenLocalServiceUtil.searchCount( taskName, assetType, assetPrimaryKey, dueDateGT, dueDateLT, completed, searchByUserRoles, andOperator, serviceContext); } catch (Exception e) { throw new WorkflowException(e); } }
@Override protected void doImportStagedModel(PortletDataContext portletDataContext, MDRAction action) throws Exception { Map<Long, Long> ruleGroupInstanceIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(MDRRuleGroupInstance.class); long ruleGroupInstanceId = MapUtil.getLong( ruleGroupInstanceIds, action.getRuleGroupInstanceId(), action.getRuleGroupInstanceId()); ServiceContext serviceContext = portletDataContext.createServiceContext(action); serviceContext.setUserId(portletDataContext.getUserId(action.getUserUuid())); Element element = portletDataContext.getImportDataStagedModelElement(action); validateLayout(element, action); MDRAction importedAction = null; if (portletDataContext.isDataStrategyMirror()) { MDRAction existingAction = fetchStagedModelByUuidAndGroupId(action.getUuid(), portletDataContext.getScopeGroupId()); if (existingAction == null) { serviceContext.setUuid(action.getUuid()); importedAction = _mdrActionLocalService.addAction( ruleGroupInstanceId, action.getNameMap(), action.getDescriptionMap(), action.getType(), action.getTypeSettingsProperties(), serviceContext); } else { importedAction = _mdrActionLocalService.updateAction( existingAction.getActionId(), action.getNameMap(), action.getDescriptionMap(), action.getType(), action.getTypeSettingsProperties(), serviceContext); } } else { importedAction = _mdrActionLocalService.addAction( ruleGroupInstanceId, action.getNameMap(), action.getDescriptionMap(), action.getType(), action.getTypeSettingsProperties(), serviceContext); } portletDataContext.importClassedModel(action, importedAction); }
@Override public WorkflowTask updateDueDate( long companyId, long userId, long workflowTaskInstanceId, String comment, Date dueDate) throws WorkflowException { ServiceContext serviceContext = new ServiceContext(); serviceContext.setCompanyId(companyId); serviceContext.setUserId(userId); return _taskManager.updateDueDate(workflowTaskInstanceId, comment, dueDate, serviceContext); }
@Override public int getWorkflowTaskCountByUser(long companyId, long userId, Boolean completed) throws WorkflowException { try { ServiceContext serviceContext = new ServiceContext(); serviceContext.setCompanyId(companyId); serviceContext.setUserId(userId); return KaleoTaskInstanceTokenLocalServiceUtil.getKaleoTaskInstanceTokensCount( User.class.getName(), serviceContext.getUserId(), completed, serviceContext); } catch (Exception e) { throw new WorkflowException(e); } }
@Override public int getWorkflowTaskCountByUserRoles(long companyId, long userId, Boolean completed) throws WorkflowException { try { ServiceContext serviceContext = new ServiceContext(); serviceContext.setCompanyId(companyId); serviceContext.setUserId(userId); return KaleoTaskInstanceTokenLocalServiceUtil.searchCount( null, completed, Boolean.TRUE, serviceContext); } catch (Exception e) { throw new WorkflowException(e); } }
@Override public int searchCount( long companyId, long userId, String keywords, Boolean completed, Boolean searchByUserRoles) throws WorkflowException { try { ServiceContext serviceContext = new ServiceContext(); serviceContext.setCompanyId(companyId); serviceContext.setUserId(userId); return KaleoTaskInstanceTokenLocalServiceUtil.searchCount( keywords, completed, searchByUserRoles, serviceContext); } catch (Exception e) { throw new WorkflowException(e); } }
@Override protected void doImportStagedModel(PortletDataContext portletDataContext, MDRRuleGroup ruleGroup) throws Exception { long userId = portletDataContext.getUserId(ruleGroup.getUserUuid()); ServiceContext serviceContext = portletDataContext.createServiceContext(ruleGroup); serviceContext.setUserId(userId); MDRRuleGroup importedRuleGroup = null; if (portletDataContext.isDataStrategyMirror()) { MDRRuleGroup existingRuleGroup = fetchStagedModelByUuidAndGroupId( ruleGroup.getUuid(), portletDataContext.getScopeGroupId()); if (existingRuleGroup == null) { serviceContext.setUuid(ruleGroup.getUuid()); importedRuleGroup = MDRRuleGroupLocalServiceUtil.addRuleGroup( portletDataContext.getScopeGroupId(), ruleGroup.getNameMap(), ruleGroup.getDescriptionMap(), serviceContext); } else { importedRuleGroup = MDRRuleGroupLocalServiceUtil.updateRuleGroup( existingRuleGroup.getRuleGroupId(), ruleGroup.getNameMap(), ruleGroup.getDescriptionMap(), serviceContext); } } else { importedRuleGroup = MDRRuleGroupLocalServiceUtil.addRuleGroup( portletDataContext.getScopeGroupId(), ruleGroup.getNameMap(), ruleGroup.getDescriptionMap(), serviceContext); } portletDataContext.importClassedModel(ruleGroup, importedRuleGroup); }
/** * Returns a new service context object identical to this service context object. * * @return a new service context object */ @Override public Object clone() { ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(isAddGroupPermissions()); serviceContext.setAddGuestPermissions(isAddGuestPermissions()); serviceContext.setAssetCategoryIds(getAssetCategoryIds()); serviceContext.setAssetEntryVisible(isAssetEntryVisible()); serviceContext.setAssetLinkEntryIds(getAssetLinkEntryIds()); serviceContext.setAssetTagNames(getAssetTagNames()); serviceContext.setAttributes(getAttributes()); serviceContext.setCommand(getCommand()); serviceContext.setCompanyId(getCompanyId()); serviceContext.setCreateDate(getCreateDate()); serviceContext.setCurrentURL(getCurrentURL()); serviceContext.setExpandoBridgeAttributes(getExpandoBridgeAttributes()); serviceContext.setFailOnPortalException(isFailOnPortalException()); serviceContext.setGroupPermissions(getGroupPermissions()); serviceContext.setGuestPermissions(getGuestPermissions()); serviceContext.setHeaders(getHeaders()); serviceContext.setIndexingEnabled(isIndexingEnabled()); serviceContext.setLanguageId(getLanguageId()); serviceContext.setLayoutFullURL(getLayoutFullURL()); serviceContext.setLayoutURL(getLayoutURL()); serviceContext.setModifiedDate(getModifiedDate()); serviceContext.setPathFriendlyURLPrivateGroup(getPathFriendlyURLPrivateGroup()); serviceContext.setPathFriendlyURLPrivateUser(getPathFriendlyURLPrivateUser()); serviceContext.setPathFriendlyURLPublic(getPathFriendlyURLPublic()); serviceContext.setPathMain(getPathMain()); serviceContext.setPlid(getPlid()); serviceContext.setPortalURL(getPortalURL()); serviceContext.setPortletPreferencesIds(getPortletPreferencesIds()); serviceContext.setRemoteAddr(getRemoteAddr()); serviceContext.setRemoteHost(getRemoteHost()); serviceContext.setRequest(getRequest()); serviceContext.setScopeGroupId(getScopeGroupId()); serviceContext.setSignedIn(isSignedIn()); serviceContext.setUserDisplayURL(getUserDisplayURL()); serviceContext.setUserId(getUserId()); serviceContext.setUuid(getUuid()); serviceContext.setWorkflowAction(getWorkflowAction()); return serviceContext; }
@Override public List<WorkflowTask> search( long companyId, long userId, String taskName, String assetType, Long[] assetPrimaryKey, Date dueDateGT, Date dueDateLT, Boolean completed, Boolean searchByUserRoles, boolean andOperator, int start, int end, OrderByComparator<WorkflowTask> orderByComparator) throws WorkflowException { try { ServiceContext serviceContext = new ServiceContext(); serviceContext.setCompanyId(companyId); serviceContext.setUserId(userId); List<KaleoTaskInstanceToken> kaleoTaskInstanceTokens = KaleoTaskInstanceTokenLocalServiceUtil.search( taskName, assetType, assetPrimaryKey, dueDateGT, dueDateLT, completed, searchByUserRoles, andOperator, start, end, KaleoTaskInstanceTokenOrderByComparator.getOrderByComparator(orderByComparator), serviceContext); return toWorkflowTasks(kaleoTaskInstanceTokens); } catch (Exception e) { throw new WorkflowException(e); } }
protected CalendarResource getCalendarResource(long companyId, long groupId) throws PortalException, SystemException { ServiceContext serviceContext = new ServiceContext(); serviceContext.setCompanyId(companyId); long userId = UserLocalServiceUtil.getDefaultUserId(companyId); serviceContext.setUserId(userId); Group group = groupLocalService.getGroup(groupId); if (group.isUser()) { return CalendarResourceUtil.getUserCalendarResource(group.getCreatorUserId(), serviceContext); } return CalendarResourceUtil.getGroupCalendarResource(groupId, serviceContext); }
@Override public WorkflowTask assignWorkflowTaskToUser( long companyId, long userId, long workflowTaskInstanceId, long assigneeUserId, String comment, Date dueDate, Map<String, Serializable> workflowContext) throws WorkflowException { ServiceContext serviceContext = new ServiceContext(); serviceContext.setCompanyId(companyId); serviceContext.setUserId(userId); return _taskManager.assignWorkflowTaskToUser( workflowTaskInstanceId, assigneeUserId, comment, dueDate, workflowContext, serviceContext); }
@Override public int getWorkflowTaskCountByWorkflowInstance( long companyId, Long userId, long workflowInstanceId, Boolean completed) throws WorkflowException { try { ServiceContext serviceContext = new ServiceContext(); serviceContext.setCompanyId(companyId); if (userId != null) { serviceContext.setUserId(userId); } return KaleoTaskInstanceTokenLocalServiceUtil.getKaleoTaskInstanceTokensCount( workflowInstanceId, completed, serviceContext); } catch (Exception e) { throw new WorkflowException(e); } }
public void cascadeFileEntryTypes(long userId, DLFolder dlFolder) throws PortalException, SystemException { List<DLFileEntryType> dlFileEntryTypes = getFolderFileEntryTypes(new long[] {dlFolder.getGroupId()}, dlFolder.getFolderId(), true); List<Long> fileEntryTypeIds = getFileEntryTypeIds(dlFileEntryTypes); long defaultFileEntryTypeId = getDefaultFileEntryTypeId(dlFolder.getFolderId()); ServiceContext serviceContext = new ServiceContext(); serviceContext.setCompanyId(dlFolder.getCompanyId()); serviceContext.setScopeGroupId(dlFolder.getGroupId()); serviceContext.setUserId(userId); cascadeFileEntryTypes( dlFolder.getGroupId(), dlFolder.getFolderId(), defaultFileEntryTypeId, fileEntryTypeIds, serviceContext); }
@Override protected void doImportStagedModel( PortletDataContext portletDataContext, Element ruleGroupInstanceElement, String path, MDRRuleGroupInstance ruleGroupInstance) throws Exception { long userId = portletDataContext.getUserId(ruleGroupInstance.getUserUuid()); String ruleGroupPath = StagedModelPathUtil.getPath( portletDataContext, MDRRuleGroup.class.getName(), ruleGroupInstance.getRuleGroupId()); MDRRuleGroup ruleGroup = (MDRRuleGroup) portletDataContext.getZipEntryAsObject(ruleGroupPath); StagedModelDataHandlerUtil.importStagedModel( portletDataContext, ruleGroupInstanceElement, ruleGroupPath, ruleGroup); Map<Long, Long> ruleGroupIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(MDRRuleGroup.class); Long ruleGroupId = MapUtil.getLong( ruleGroupIds, ruleGroupInstance.getRuleGroupId(), ruleGroupInstance.getRuleGroupId()); long classPK = 0; String layoutUuid = ruleGroupInstanceElement.attributeValue("layout-uuid"); try { if (Validator.isNotNull(layoutUuid)) { Layout layout = LayoutLocalServiceUtil.getLayoutByUuidAndGroupId( layoutUuid, portletDataContext.getScopeGroupId(), portletDataContext.isPrivateLayout()); classPK = layout.getPrimaryKey(); } else { LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet( portletDataContext.getScopeGroupId(), portletDataContext.isPrivateLayout()); classPK = layoutSet.getLayoutSetId(); } } catch (Exception e) { if (_log.isWarnEnabled()) { StringBundler sb = new StringBundler(5); sb.append("Layout "); sb.append(layoutUuid); sb.append(" is missing for rule group instance "); sb.append(ruleGroupInstance.getRuleGroupInstanceId()); sb.append(", skipping this rule group instance."); _log.warn(sb.toString()); } return; } ServiceContext serviceContext = portletDataContext.createServiceContext( ruleGroupInstanceElement, ruleGroupInstance, MDRPortletDataHandler.NAMESPACE); serviceContext.setUserId(userId); MDRRuleGroupInstance importedRuleGroupInstance = null; if (portletDataContext.isDataStrategyMirror()) { MDRRuleGroupInstance existingMDRRuleGroupInstance = MDRRuleGroupInstanceUtil.fetchByUUID_G( ruleGroupInstance.getUuid(), portletDataContext.getScopeGroupId()); if (existingMDRRuleGroupInstance == null) { serviceContext.setUuid(ruleGroupInstance.getUuid()); importedRuleGroupInstance = MDRRuleGroupInstanceLocalServiceUtil.addRuleGroupInstance( portletDataContext.getScopeGroupId(), ruleGroupInstance.getClassName(), classPK, ruleGroupId, ruleGroupInstance.getPriority(), serviceContext); } else { importedRuleGroupInstance = MDRRuleGroupInstanceLocalServiceUtil.updateRuleGroupInstance( existingMDRRuleGroupInstance.getRuleGroupInstanceId(), ruleGroupInstance.getPriority()); } } else { importedRuleGroupInstance = MDRRuleGroupInstanceLocalServiceUtil.addRuleGroupInstance( portletDataContext.getScopeGroupId(), ruleGroupInstance.getClassName(), classPK, ruleGroupId, ruleGroupInstance.getPriority(), serviceContext); } portletDataContext.importClassedModel( ruleGroupInstance, importedRuleGroupInstance, MDRPortletDataHandler.NAMESPACE); }
protected File doExportLayoutsAsFile( long groupId, boolean privateLayout, long[] layoutIds, Map<String, String[]> parameterMap, Date startDate, Date endDate) throws Exception { boolean exportCategories = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.CATEGORIES); boolean exportIgnoreLastPublishDate = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.IGNORE_LAST_PUBLISH_DATE); boolean exportPermissions = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.PERMISSIONS); boolean exportPortletDataAll = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.PORTLET_DATA_ALL); boolean exportTheme = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.THEME); boolean exportThemeSettings = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.THEME_REFERENCE); boolean exportLogo = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.LOGO); boolean exportLayoutSetSettings = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.LAYOUT_SET_SETTINGS); boolean updateLastPublishDate = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.UPDATE_LAST_PUBLISH_DATE); if (_log.isDebugEnabled()) { _log.debug("Export permissions " + exportPermissions); _log.debug("Export theme " + exportTheme); } LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(groupId, privateLayout); long companyId = layoutSet.getCompanyId(); long defaultUserId = UserLocalServiceUtil.getDefaultUserId(companyId); ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext(); if (serviceContext == null) { serviceContext = new ServiceContext(); serviceContext.setCompanyId(companyId); serviceContext.setSignedIn(false); serviceContext.setUserId(defaultUserId); ServiceContextThreadLocal.pushServiceContext(serviceContext); } serviceContext.setAttribute("exporting", Boolean.TRUE); long layoutSetBranchId = MapUtil.getLong(parameterMap, "layoutSetBranchId"); serviceContext.setAttribute("layoutSetBranchId", layoutSetBranchId); long lastPublishDate = System.currentTimeMillis(); if (endDate != null) { lastPublishDate = endDate.getTime(); } if (exportIgnoreLastPublishDate) { endDate = null; startDate = null; } StopWatch stopWatch = null; if (_log.isInfoEnabled()) { stopWatch = new StopWatch(); stopWatch.start(); } LayoutCache layoutCache = new LayoutCache(); ZipWriter zipWriter = ZipWriterFactoryUtil.getZipWriter(); PortletDataContext portletDataContext = PortletDataContextFactoryUtil.createExportPortletDataContext( companyId, groupId, parameterMap, startDate, endDate, zipWriter); portletDataContext.setPortetDataContextListener( new PortletDataContextListenerImpl(portletDataContext)); Document document = SAXReaderUtil.createDocument(); Element rootElement = document.addElement("root"); portletDataContext.setExportDataRootElement(rootElement); Element headerElement = rootElement.addElement("header"); headerElement.addAttribute( "available-locales", StringUtil.merge(LanguageUtil.getAvailableLocales(portletDataContext.getScopeGroupId()))); headerElement.addAttribute("build-number", String.valueOf(ReleaseInfo.getBuildNumber())); headerElement.addAttribute("export-date", Time.getRFC822()); if (portletDataContext.hasDateRange()) { headerElement.addAttribute("start-date", String.valueOf(portletDataContext.getStartDate())); headerElement.addAttribute("end-date", String.valueOf(portletDataContext.getEndDate())); } headerElement.addAttribute("company-id", String.valueOf(portletDataContext.getCompanyId())); headerElement.addAttribute( "company-group-id", String.valueOf(portletDataContext.getCompanyGroupId())); headerElement.addAttribute("group-id", String.valueOf(groupId)); headerElement.addAttribute( "user-personal-site-group-id", String.valueOf(portletDataContext.getUserPersonalSiteGroupId())); headerElement.addAttribute("private-layout", String.valueOf(privateLayout)); Group group = layoutSet.getGroup(); String type = "layout-set"; if (group.isLayoutPrototype()) { type = "layout-prototype"; LayoutPrototype layoutPrototype = LayoutPrototypeLocalServiceUtil.getLayoutPrototype(group.getClassPK()); headerElement.addAttribute("type-uuid", layoutPrototype.getUuid()); } else if (group.isLayoutSetPrototype()) { type = "layout-set-prototype"; LayoutSetPrototype layoutSetPrototype = LayoutSetPrototypeLocalServiceUtil.getLayoutSetPrototype(group.getClassPK()); headerElement.addAttribute("type-uuid", layoutSetPrototype.getUuid()); } headerElement.addAttribute("type", type); if (exportTheme || exportThemeSettings) { headerElement.addAttribute("theme-id", layoutSet.getThemeId()); headerElement.addAttribute("color-scheme-id", layoutSet.getColorSchemeId()); } if (exportLogo) { Image image = ImageLocalServiceUtil.getImage(layoutSet.getLogoId()); if ((image != null) && (image.getTextObj() != null)) { String logoPath = ExportImportPathUtil.getRootPath(portletDataContext); logoPath += "/logo"; headerElement.addAttribute("logo-path", logoPath); portletDataContext.addZipEntry(logoPath, image.getTextObj()); } } if (exportLayoutSetSettings) { Element settingsElement = headerElement.addElement("settings"); settingsElement.addCDATA(layoutSet.getSettings()); } Element cssElement = headerElement.addElement("css"); cssElement.addCDATA(layoutSet.getCss()); Map<String, Object[]> portletIds = new LinkedHashMap<String, Object[]>(); List<Layout> layouts = LayoutLocalServiceUtil.getLayouts(groupId, privateLayout); List<Portlet> portlets = getDataSiteLevelPortlets(companyId); long plid = LayoutConstants.DEFAULT_PLID; if (!layouts.isEmpty()) { Layout firstLayout = layouts.get(0); plid = firstLayout.getPlid(); } if (group.isStagingGroup()) { group = group.getLiveGroup(); } for (Portlet portlet : portlets) { String portletId = portlet.getRootPortletId(); if (!group.isStagedPortlet(portletId)) { continue; } String key = PortletPermissionUtil.getPrimaryKey(0, portletId); if (portletIds.get(key) == null) { portletIds.put( key, new Object[] {portletId, plid, groupId, StringPool.BLANK, StringPool.BLANK}); } } Element missingReferencesElement = rootElement.addElement("missing-references"); portletDataContext.setMissingReferencesElement(missingReferencesElement); portletDataContext.addDeletionSystemEventStagedModelTypes(new StagedModelType(Layout.class)); Element layoutsElement = portletDataContext.getExportDataGroupElement(Layout.class); String layoutSetPrototypeUuid = layoutSet.getLayoutSetPrototypeUuid(); if (Validator.isNotNull(layoutSetPrototypeUuid)) { LayoutSetPrototype layoutSetPrototype = LayoutSetPrototypeLocalServiceUtil.getLayoutSetPrototypeByUuidAndCompanyId( layoutSetPrototypeUuid, companyId); layoutsElement.addAttribute("layout-set-prototype-uuid", layoutSetPrototypeUuid); layoutsElement.addAttribute( "layout-set-prototype-name", layoutSetPrototype.getName(LocaleUtil.getDefault())); } for (Layout layout : layouts) { exportLayout(portletDataContext, portlets, layoutIds, portletIds, layout); } long previousScopeGroupId = portletDataContext.getScopeGroupId(); Element portletsElement = rootElement.addElement("portlets"); for (Map.Entry<String, Object[]> portletIdsEntry : portletIds.entrySet()) { Object[] portletObjects = portletIdsEntry.getValue(); String portletId = null; plid = LayoutConstants.DEFAULT_PLID; long scopeGroupId = 0; String scopeType = StringPool.BLANK; String scopeLayoutUuid = null; if (portletObjects.length == 4) { portletId = (String) portletIdsEntry.getValue()[0]; plid = (Long) portletIdsEntry.getValue()[1]; scopeGroupId = (Long) portletIdsEntry.getValue()[2]; scopeLayoutUuid = (String) portletIdsEntry.getValue()[3]; } else { portletId = (String) portletIdsEntry.getValue()[0]; plid = (Long) portletIdsEntry.getValue()[1]; scopeGroupId = (Long) portletIdsEntry.getValue()[2]; scopeType = (String) portletIdsEntry.getValue()[3]; scopeLayoutUuid = (String) portletIdsEntry.getValue()[4]; } Layout layout = LayoutLocalServiceUtil.fetchLayout(plid); if (layout == null) { if (!group.isCompany() && (plid <= LayoutConstants.DEFAULT_PLID)) { continue; } if (_log.isWarnEnabled()) { _log.warn("Assuming global scope because no layout was found"); } layout = new LayoutImpl(); layout.setGroupId(groupId); layout.setCompanyId(companyId); } portletDataContext.setPlid(plid); portletDataContext.setOldPlid(plid); portletDataContext.setScopeGroupId(scopeGroupId); portletDataContext.setScopeType(scopeType); portletDataContext.setScopeLayoutUuid(scopeLayoutUuid); boolean[] exportPortletControls = getExportPortletControls(companyId, portletId, parameterMap, type); _portletExporter.exportPortlet( portletDataContext, layoutCache, portletId, layout, portletsElement, defaultUserId, exportPermissions, exportPortletControls[0], exportPortletControls[1], exportPortletControls[2], exportPortletControls[3]); } portletDataContext.setScopeGroupId(previousScopeGroupId); exportAssetCategories( portletDataContext, exportPortletDataAll, exportCategories, group.isCompany()); _portletExporter.exportAssetLinks(portletDataContext); _portletExporter.exportAssetTags(portletDataContext); _portletExporter.exportComments(portletDataContext); _portletExporter.exportExpandoTables(portletDataContext); _portletExporter.exportLocks(portletDataContext); _deletionSystemEventExporter.exportDeletionSystemEvents(portletDataContext); if (exportPermissions) { _permissionExporter.exportPortletDataPermissions(portletDataContext); } _portletExporter.exportRatingsEntries(portletDataContext, rootElement); if (exportTheme && !portletDataContext.isPerformDirectBinaryImport()) { exportTheme(layoutSet, zipWriter); } ExportImportHelperUtil.writeManifestSummary(document, portletDataContext.getManifestSummary()); if (_log.isInfoEnabled()) { if (stopWatch != null) { _log.info("Exporting layouts takes " + stopWatch.getTime() + " ms"); } else { _log.info("Exporting layouts is finished"); } } portletDataContext.addZipEntry("/manifest.xml", document.formattedString()); try { return zipWriter.getFile(); } finally { if (updateLastPublishDate) { updateLastPublishDate(layoutSet, lastPublishDate); } } }
@Override public WorkflowTask completeWorkflowTask( long companyId, long userId, long workflowTaskInstanceId, String transitionName, String comment, Map<String, Serializable> workflowContext) throws WorkflowException { Lock lock = null; try { lock = LockManagerUtil.lock( userId, WorkflowTask.class.getName(), workflowTaskInstanceId, String.valueOf(userId), false, 1000); } catch (PortalException pe) { if (pe instanceof DuplicateLockException) { throw new WorkflowException( "Workflow task " + workflowTaskInstanceId + " is locked by user " + userId, pe); } throw new WorkflowException("Unable to lock workflow task " + workflowTaskInstanceId, pe); } try { ServiceContext serviceContext = new ServiceContext(); serviceContext.setCompanyId(companyId); serviceContext.setUserId(userId); WorkflowTask workflowTask = _taskManager.completeWorkflowTask( workflowTaskInstanceId, transitionName, comment, workflowContext, serviceContext); KaleoTaskInstanceToken kaleoTaskInstanceToken = KaleoTaskInstanceTokenLocalServiceUtil.getKaleoTaskInstanceToken( workflowTask.getWorkflowTaskId()); KaleoInstanceToken kaleoInstanceToken = kaleoTaskInstanceToken.getKaleoInstanceToken(); if (workflowContext == null) { workflowContext = WorkflowContextUtil.convert(kaleoInstanceToken.getKaleoInstance().getWorkflowContext()); } workflowContext.put(WorkflowConstants.CONTEXT_TASK_COMMENTS, comment); workflowContext.put(WorkflowConstants.CONTEXT_TRANSITION_NAME, transitionName); ExecutionContext executionContext = new ExecutionContext( kaleoInstanceToken, kaleoTaskInstanceToken, workflowContext, serviceContext); _kaleoSignaler.signalExit(transitionName, executionContext); return workflowTask; } catch (Exception e) { throw new WorkflowException("Unable to complete task", e); } finally { LockManagerUtil.unlock(lock.getClassName(), lock.getKey()); } }
protected File doExport(PortletDataContext portletDataContext) throws Exception { boolean exportPermissions = MapUtil.getBoolean( portletDataContext.getParameterMap(), PortletDataHandlerKeys.PERMISSIONS); if (_log.isDebugEnabled()) { _log.debug("Export permissions " + exportPermissions); } StopWatch stopWatch = new StopWatch(); stopWatch.start(); Layout layout = _layoutLocalService.getLayout(portletDataContext.getPlid()); if (!layout.isTypeControlPanel() && !layout.isTypePanel() && !layout.isTypePortlet()) { throw new LayoutImportException("Layout type " + layout.getType() + " is not valid"); } ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext(); if (serviceContext == null) { serviceContext = new ServiceContext(); serviceContext.setCompanyId(layout.getCompanyId()); serviceContext.setSignedIn(false); long defaultUserId = _userLocalService.getDefaultUserId(layout.getCompanyId()); serviceContext.setUserId(defaultUserId); ServiceContextThreadLocal.pushServiceContext(serviceContext); } long layoutSetBranchId = MapUtil.getLong(portletDataContext.getParameterMap(), "layoutSetBranchId"); serviceContext.setAttribute("layoutSetBranchId", layoutSetBranchId); long scopeGroupId = portletDataContext.getGroupId(); javax.portlet.PortletPreferences jxPortletPreferences = PortletPreferencesFactoryUtil.getLayoutPortletSetup( layout, portletDataContext.getPortletId()); String scopeType = GetterUtil.getString(jxPortletPreferences.getValue("lfrScopeType", null)); String scopeLayoutUuid = GetterUtil.getString(jxPortletPreferences.getValue("lfrScopeLayoutUuid", null)); if (Validator.isNotNull(scopeType)) { Group scopeGroup = null; if (scopeType.equals("company")) { scopeGroup = _groupLocalService.getCompanyGroup(layout.getCompanyId()); } else if (Validator.isNotNull(scopeLayoutUuid)) { scopeGroup = layout.getScopeGroup(); } if (scopeGroup != null) { scopeGroupId = scopeGroup.getGroupId(); } } portletDataContext.setScopeType(scopeType); portletDataContext.setScopeLayoutUuid(scopeLayoutUuid); Document document = SAXReaderUtil.createDocument(); Element rootElement = document.addElement("root"); portletDataContext.setExportDataRootElement(rootElement); Element headerElement = rootElement.addElement("header"); headerElement.addAttribute( "available-locales", StringUtil.merge( LanguageUtil.getAvailableLocales( PortalUtil.getSiteGroupId(portletDataContext.getScopeGroupId())))); headerElement.addAttribute("build-number", String.valueOf(ReleaseInfo.getBuildNumber())); headerElement.addAttribute("export-date", Time.getRFC822()); if (portletDataContext.hasDateRange()) { headerElement.addAttribute("start-date", String.valueOf(portletDataContext.getStartDate())); headerElement.addAttribute("end-date", String.valueOf(portletDataContext.getEndDate())); } headerElement.addAttribute("type", "portlet"); headerElement.addAttribute("company-id", String.valueOf(portletDataContext.getCompanyId())); headerElement.addAttribute( "company-group-id", String.valueOf(portletDataContext.getCompanyGroupId())); headerElement.addAttribute("group-id", String.valueOf(scopeGroupId)); headerElement.addAttribute( "user-personal-site-group-id", String.valueOf(portletDataContext.getUserPersonalSiteGroupId())); headerElement.addAttribute("private-layout", String.valueOf(layout.isPrivateLayout())); headerElement.addAttribute("root-portlet-id", portletDataContext.getRootPortletId()); Element missingReferencesElement = rootElement.addElement("missing-references"); portletDataContext.setMissingReferencesElement(missingReferencesElement); Map<String, Boolean> exportPortletControlsMap = ExportImportHelperUtil.getExportPortletControlsMap( layout.getCompanyId(), portletDataContext.getPortletId(), portletDataContext.getParameterMap()); exportPortlet( portletDataContext, layout, rootElement, exportPermissions, exportPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_ARCHIVED_SETUPS), exportPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_DATA), exportPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_SETUP), exportPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_USER_PREFERENCES)); exportService( portletDataContext, rootElement, exportPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_SETUP)); exportAssetLinks(portletDataContext); exportExpandoTables(portletDataContext); exportLocks(portletDataContext); _deletionSystemEventExporter.exportDeletionSystemEvents(portletDataContext); if (exportPermissions) { _permissionExporter.exportPortletDataPermissions(portletDataContext); } ExportImportHelperUtil.writeManifestSummary(document, portletDataContext.getManifestSummary()); if (_log.isInfoEnabled()) { _log.info("Exporting portlet took " + stopWatch.getTime() + " ms"); } try { portletDataContext.addZipEntry("/manifest.xml", document.formattedString()); } catch (IOException ioe) { throw new SystemException(ioe); } ZipWriter zipWriter = portletDataContext.getZipWriter(); return zipWriter.getFile(); }
protected File doExportLayoutsAsFile( long groupId, boolean privateLayout, long[] layoutIds, Map<String, String[]> parameterMap, Date startDate, Date endDate) throws Exception { boolean exportCategories = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.CATEGORIES); boolean exportIgnoreLastPublishDate = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.IGNORE_LAST_PUBLISH_DATE); boolean exportPermissions = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.PERMISSIONS); boolean exportUserPermissions = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.USER_PERMISSIONS); boolean exportPortletArchivedSetups = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.PORTLET_ARCHIVED_SETUPS); boolean exportPortletUserPreferences = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.PORTLET_USER_PREFERENCES); boolean exportTheme = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.THEME); boolean exportThemeSettings = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.THEME_REFERENCE); boolean exportLogo = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.LOGO); boolean exportLayoutSetSettings = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.LAYOUT_SET_SETTINGS); boolean publishToRemote = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.PUBLISH_TO_REMOTE); boolean updateLastPublishDate = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.UPDATE_LAST_PUBLISH_DATE); if (_log.isDebugEnabled()) { _log.debug("Export categories " + exportCategories); _log.debug("Export permissions " + exportPermissions); _log.debug("Export user permissions " + exportUserPermissions); _log.debug("Export portlet archived setups " + exportPortletArchivedSetups); _log.debug("Export portlet user preferences " + exportPortletUserPreferences); _log.debug("Export theme " + exportTheme); } LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(groupId, privateLayout); long companyId = layoutSet.getCompanyId(); long defaultUserId = UserLocalServiceUtil.getDefaultUserId(companyId); ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext(); if (serviceContext == null) { serviceContext = new ServiceContext(); serviceContext.setCompanyId(companyId); serviceContext.setSignedIn(false); serviceContext.setUserId(defaultUserId); ServiceContextThreadLocal.pushServiceContext(serviceContext); } serviceContext.setAttribute("exporting", Boolean.TRUE); long layoutSetBranchId = MapUtil.getLong(parameterMap, "layoutSetBranchId"); serviceContext.setAttribute("layoutSetBranchId", layoutSetBranchId); long lastPublishDate = System.currentTimeMillis(); if (endDate != null) { lastPublishDate = endDate.getTime(); } if (exportIgnoreLastPublishDate) { endDate = null; startDate = null; } StopWatch stopWatch = null; if (_log.isInfoEnabled()) { stopWatch = new StopWatch(); stopWatch.start(); } LayoutCache layoutCache = new LayoutCache(); ZipWriter zipWriter = ZipWriterFactoryUtil.getZipWriter(); PortletDataContext portletDataContext = new PortletDataContextImpl( companyId, groupId, parameterMap, new HashSet<String>(), startDate, endDate, zipWriter); portletDataContext.setPortetDataContextListener( new PortletDataContextListenerImpl(portletDataContext)); Document document = SAXReaderUtil.createDocument(); Element rootElement = document.addElement("root"); Element headerElement = rootElement.addElement("header"); headerElement.addAttribute("build-number", String.valueOf(ReleaseInfo.getBuildNumber())); headerElement.addAttribute("export-date", Time.getRFC822()); if (portletDataContext.hasDateRange()) { headerElement.addAttribute("start-date", String.valueOf(portletDataContext.getStartDate())); headerElement.addAttribute("end-date", String.valueOf(portletDataContext.getEndDate())); } headerElement.addAttribute("group-id", String.valueOf(groupId)); headerElement.addAttribute("private-layout", String.valueOf(privateLayout)); Group group = layoutSet.getGroup(); String type = "layout-set"; if (group.isLayoutSetPrototype()) { type = "layout-set-prototype"; LayoutSetPrototype layoutSetPrototype = LayoutSetPrototypeLocalServiceUtil.getLayoutSetPrototype(group.getClassPK()); headerElement.addAttribute("type-uuid", layoutSetPrototype.getUuid()); } headerElement.addAttribute("type", type); if (exportTheme || exportThemeSettings) { headerElement.addAttribute("theme-id", layoutSet.getThemeId()); headerElement.addAttribute("color-scheme-id", layoutSet.getColorSchemeId()); } if (exportLogo) { Image image = ImageLocalServiceUtil.getImage(layoutSet.getLogoId()); if (image != null) { String logoPath = getLayoutSetLogoPath(portletDataContext); headerElement.addAttribute("logo-path", logoPath); portletDataContext.addZipEntry(logoPath, image.getTextObj()); } } if (exportLayoutSetSettings) { Element settingsElement = headerElement.addElement("settings"); settingsElement.addCDATA(layoutSet.getSettings()); } Element cssElement = headerElement.addElement("css"); cssElement.addCDATA(layoutSet.getCss()); Portlet layoutConfigurationPortlet = PortletLocalServiceUtil.getPortletById( portletDataContext.getCompanyId(), PortletKeys.LAYOUT_CONFIGURATION); Map<String, Object[]> portletIds = new LinkedHashMap<String, Object[]>(); List<Layout> layouts = null; if ((layoutIds == null) || (layoutIds.length == 0)) { layouts = LayoutLocalServiceUtil.getLayouts(groupId, privateLayout); } else { layouts = LayoutLocalServiceUtil.getLayouts(groupId, privateLayout, layoutIds); } List<Portlet> portlets = getAlwaysExportablePortlets(companyId); if (!layouts.isEmpty()) { Layout firstLayout = layouts.get(0); if (group.isStagingGroup()) { group = group.getLiveGroup(); } for (Portlet portlet : portlets) { String portletId = portlet.getRootPortletId(); if (!group.isStagedPortlet(portletId)) { continue; } String key = PortletPermissionUtil.getPrimaryKey(0, portletId); if (portletIds.get(key) == null) { portletIds.put( key, new Object[] { portletId, firstLayout.getPlid(), groupId, StringPool.BLANK, StringPool.BLANK }); } } } Element layoutsElement = rootElement.addElement("layouts"); String layoutSetPrototypeUuid = layoutSet.getLayoutSetPrototypeUuid(); if (Validator.isNotNull(layoutSetPrototypeUuid)) { LayoutSetPrototype layoutSetPrototype = LayoutSetPrototypeLocalServiceUtil.getLayoutSetPrototypeByUuid(layoutSetPrototypeUuid); layoutsElement.addAttribute("layout-set-prototype-uuid", layoutSetPrototypeUuid); if (publishToRemote) { String path = getLayoutSetPrototype(portletDataContext, layoutSetPrototypeUuid); File layoutSetPrototypeFile = null; InputStream inputStream = null; try { layoutSetPrototypeFile = SitesUtil.exportLayoutSetPrototype(layoutSetPrototype, serviceContext); inputStream = new FileInputStream(layoutSetPrototypeFile); portletDataContext.addZipEntry(path.concat(".lar"), inputStream); portletDataContext.addZipEntry(path.concat(".xml"), layoutSetPrototype); } finally { StreamUtil.cleanUp(inputStream); FileUtil.delete(layoutSetPrototypeFile); } } } for (Layout layout : layouts) { exportLayout( portletDataContext, layoutConfigurationPortlet, layoutCache, portlets, portletIds, exportPermissions, exportUserPermissions, layout, layoutsElement); } if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM < 5) { Element rolesElement = rootElement.addElement("roles"); if (exportPermissions) { _permissionExporter.exportLayoutRoles(layoutCache, companyId, groupId, rolesElement); } } long previousScopeGroupId = portletDataContext.getScopeGroupId(); Element portletsElement = rootElement.addElement("portlets"); for (Map.Entry<String, Object[]> portletIdsEntry : portletIds.entrySet()) { Object[] portletObjects = portletIdsEntry.getValue(); String portletId = null; long plid = 0; long scopeGroupId = 0; String scopeType = StringPool.BLANK; String scopeLayoutUuid = null; if (portletObjects.length == 4) { portletId = (String) portletIdsEntry.getValue()[0]; plid = (Long) portletIdsEntry.getValue()[1]; scopeGroupId = (Long) portletIdsEntry.getValue()[2]; scopeLayoutUuid = (String) portletIdsEntry.getValue()[3]; } else { portletId = (String) portletIdsEntry.getValue()[0]; plid = (Long) portletIdsEntry.getValue()[1]; scopeGroupId = (Long) portletIdsEntry.getValue()[2]; scopeType = (String) portletIdsEntry.getValue()[3]; scopeLayoutUuid = (String) portletIdsEntry.getValue()[4]; } Layout layout = LayoutLocalServiceUtil.getLayout(plid); portletDataContext.setPlid(layout.getPlid()); portletDataContext.setOldPlid(layout.getPlid()); portletDataContext.setScopeGroupId(scopeGroupId); portletDataContext.setScopeType(scopeType); portletDataContext.setScopeLayoutUuid(scopeLayoutUuid); boolean[] exportPortletControls = getExportPortletControls(companyId, portletId, portletDataContext, parameterMap); _portletExporter.exportPortlet( portletDataContext, layoutCache, portletId, layout, portletsElement, defaultUserId, exportPermissions, exportPortletArchivedSetups, exportPortletControls[0], exportPortletControls[1], exportPortletUserPreferences, exportUserPermissions); } portletDataContext.setScopeGroupId(previousScopeGroupId); if (exportCategories) { exportAssetCategories(portletDataContext); } _portletExporter.exportAssetLinks(portletDataContext); _portletExporter.exportAssetTags(portletDataContext); _portletExporter.exportComments(portletDataContext); _portletExporter.exportExpandoTables(portletDataContext); _portletExporter.exportLocks(portletDataContext); if (exportPermissions) { _permissionExporter.exportPortletDataPermissions(portletDataContext); } _portletExporter.exportRatingsEntries(portletDataContext, rootElement); if (exportTheme && !portletDataContext.isPerformDirectBinaryImport()) { exportTheme(layoutSet, zipWriter); } if (_log.isInfoEnabled()) { if (stopWatch != null) { _log.info("Exporting layouts takes " + stopWatch.getTime() + " ms"); } else { _log.info("Exporting layouts is finished"); } } portletDataContext.addZipEntry("/manifest.xml", document.formattedString()); try { return zipWriter.getFile(); } finally { if (updateLastPublishDate) { updateLastPublishDate(layoutSet, lastPublishDate); } } }
public void merge(ServiceContext serviceContext) { setAddGroupPermissions(serviceContext.isAddGroupPermissions()); setAddGuestPermissions(serviceContext.isAddGuestPermissions()); if (serviceContext.getAssetCategoryIds() != null) { setAssetCategoryIds(serviceContext.getAssetCategoryIds()); } if (serviceContext.getAssetLinkEntryIds() != null) { setAssetLinkEntryIds(serviceContext.getAssetLinkEntryIds()); } if (serviceContext.getAssetTagNames() != null) { setAssetTagNames(serviceContext.getAssetTagNames()); } if (serviceContext.getAttributes() != null) { setAttributes(serviceContext.getAttributes()); } if (Validator.isNotNull(serviceContext.getCommand())) { setCommand(serviceContext.getCommand()); } if (serviceContext.getCompanyId() > 0) { setCompanyId(serviceContext.getCompanyId()); } if (serviceContext.getCreateDate() != null) { setCreateDate(serviceContext.getCreateDate()); } if (Validator.isNotNull(serviceContext.getCurrentURL())) { setCurrentURL(serviceContext.getCurrentURL()); } if (serviceContext.getExpandoBridgeAttributes() != null) { setExpandoBridgeAttributes(serviceContext.getExpandoBridgeAttributes()); } if (serviceContext.getGroupPermissions() != null) { setGroupPermissions(serviceContext.getGroupPermissions()); } if (serviceContext.getGuestPermissions() != null) { setGuestPermissions(serviceContext.getGuestPermissions()); } if (serviceContext.getHeaders() != null) { setHeaders(serviceContext.getHeaders()); } setFailOnPortalException(serviceContext.isFailOnPortalException()); setLanguageId(serviceContext.getLanguageId()); if (Validator.isNotNull(serviceContext.getLayoutFullURL())) { setLayoutFullURL(serviceContext.getLayoutFullURL()); } if (Validator.isNotNull(serviceContext.getLayoutURL())) { setLayoutURL(serviceContext.getLayoutURL()); } if (serviceContext.getModifiedDate() != null) { setModifiedDate(serviceContext.getModifiedDate()); } if (Validator.isNotNull(serviceContext.getPathMain())) { setPathMain(serviceContext.getPathMain()); } if (serviceContext.getPlid() > 0) { setPlid(serviceContext.getPlid()); } if (Validator.isNotNull(serviceContext.getPortalURL())) { setPortalURL(serviceContext.getPortalURL()); } if (serviceContext.getPortletPreferencesIds() != null) { setPortletPreferencesIds(serviceContext.getPortletPreferencesIds()); } if (Validator.isNotNull(serviceContext.getRemoteAddr())) { setRemoteAddr(serviceContext.getRemoteAddr()); } if (Validator.isNotNull(serviceContext.getRemoteHost())) { setRemoteHost(serviceContext.getRemoteHost()); } if (serviceContext.getScopeGroupId() > 0) { setScopeGroupId(serviceContext.getScopeGroupId()); } setSignedIn(serviceContext.isSignedIn()); if (Validator.isNotNull(serviceContext.getUserDisplayURL())) { setUserDisplayURL(serviceContext.getUserDisplayURL()); } if (serviceContext.getUserId() > 0) { setUserId(serviceContext.getUserId()); } if (Validator.isNotNull(serviceContext.getUuid())) { setUuid(serviceContext.getUuid()); } if (serviceContext.getWorkflowAction() > 0) { setWorkflowAction(serviceContext.getWorkflowAction()); } }
protected void searchMyEntries() throws Exception { User user1 = UserTestUtil.addUser(null, 0); long initialUser1SearchGroupEntriesCount = searchGroupEntriesCount(group.getGroupId(), user1.getUserId()); User user2 = UserTestUtil.addUser(null, 0); long initialUser2SearchGroupEntriesCount = searchGroupEntriesCount(group.getGroupId(), user2.getUserId()); ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId()); BaseModel<?> parentBaseModel1 = getParentBaseModel(group, serviceContext); BaseModel<?> parentBaseModel2 = getParentBaseModel(group, serviceContext); String name = PrincipalThreadLocal.getName(); long userId = serviceContext.getUserId(); try { PrincipalThreadLocal.setName(user1.getUserId()); serviceContext.setUserId(user1.getUserId()); baseModel = addBaseModel(parentBaseModel1, true, RandomTestUtil.randomString(), serviceContext); baseModel = addBaseModel(parentBaseModel1, true, RandomTestUtil.randomString(), serviceContext); baseModel = addBaseModel(parentBaseModel2, true, RandomTestUtil.randomString(), serviceContext); PrincipalThreadLocal.setName(user2.getUserId()); serviceContext.setUserId(user2.getUserId()); baseModel = addBaseModel(parentBaseModel1, true, RandomTestUtil.randomString(), serviceContext); baseModel = addBaseModel(parentBaseModel2, true, RandomTestUtil.randomString(), serviceContext); } finally { PrincipalThreadLocal.setName(name); serviceContext.setUserId(userId); } Assert.assertEquals( initialUser1SearchGroupEntriesCount + 3, searchGroupEntriesCount(group.getGroupId(), user1.getUserId())); Assert.assertEquals( initialUser2SearchGroupEntriesCount + 2, searchGroupEntriesCount(group.getGroupId(), user2.getUserId())); moveParentBaseModelToTrash((Long) parentBaseModel2.getPrimaryKeyObj()); Assert.assertEquals( initialUser1SearchGroupEntriesCount + 2, searchGroupEntriesCount(group.getGroupId(), user1.getUserId())); Assert.assertEquals( initialUser2SearchGroupEntriesCount + 1, searchGroupEntriesCount(group.getGroupId(), user2.getUserId())); TrashHandler parentTrashHandler = TrashHandlerRegistryUtil.getTrashHandler(getParentBaseModelClassName()); parentTrashHandler.restoreTrashEntry( user1.getUserId(), (Long) parentBaseModel2.getPrimaryKeyObj()); Assert.assertEquals( initialUser1SearchGroupEntriesCount + 3, searchGroupEntriesCount(group.getGroupId(), user1.getUserId())); Assert.assertEquals( initialUser2SearchGroupEntriesCount + 2, searchGroupEntriesCount(group.getGroupId(), user2.getUserId())); }
@Override protected void doImportStagedModel( PortletDataContext portletDataContext, Element element, String path, MDRRule rule) throws Exception { String ruleGroupPath = StagedModelPathUtil.getPath( portletDataContext, MDRRuleGroup.class.getName(), rule.getRuleGroupId()); MDRRuleGroup ruleGroup = (MDRRuleGroup) portletDataContext.getZipEntryAsObject(ruleGroupPath); StagedModelDataHandlerUtil.importStagedModel( portletDataContext, element, ruleGroupPath, ruleGroup); Map<Long, Long> ruleGroupIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(MDRRuleGroup.class); long ruleGroupId = MapUtil.getLong(ruleGroupIds, rule.getRuleGroupId(), rule.getRuleGroupId()); ServiceContext serviceContext = portletDataContext.createServiceContext(element, rule, MDRPortletDataHandler.NAMESPACE); serviceContext.setUserId(portletDataContext.getUserId(rule.getUserUuid())); MDRRule importedRule = null; if (portletDataContext.isDataStrategyMirror()) { MDRRule existingRule = MDRRuleUtil.fetchByUUID_G(rule.getUuid(), portletDataContext.getScopeGroupId()); if (existingRule == null) { serviceContext.setUuid(rule.getUuid()); importedRule = MDRRuleLocalServiceUtil.addRule( ruleGroupId, rule.getNameMap(), rule.getDescriptionMap(), rule.getType(), rule.getTypeSettingsProperties(), serviceContext); } else { importedRule = MDRRuleLocalServiceUtil.updateRule( existingRule.getRuleId(), rule.getNameMap(), rule.getDescriptionMap(), rule.getType(), rule.getTypeSettingsProperties(), serviceContext); } } else { importedRule = MDRRuleLocalServiceUtil.addRule( ruleGroupId, rule.getNameMap(), rule.getDescriptionMap(), rule.getType(), rule.getTypeSettingsProperties(), serviceContext); } portletDataContext.importClassedModel(rule, importedRule, MDRPortletDataHandler.NAMESPACE); }
protected void doImportPortletInfo(PortletDataContext portletDataContext, long userId) throws Exception { Map<String, String[]> parameterMap = portletDataContext.getParameterMap(); boolean importPermissions = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.PERMISSIONS); StopWatch stopWatch = new StopWatch(); stopWatch.start(); ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext(); if (serviceContext == null) { serviceContext = new ServiceContext(); serviceContext.setCompanyId(portletDataContext.getCompanyId()); serviceContext.setSignedIn(false); serviceContext.setUserId(userId); ServiceContextThreadLocal.pushServiceContext(serviceContext); } // LAR validation validateFile( portletDataContext.getCompanyId(), portletDataContext.getGroupId(), portletDataContext.getPortletId(), portletDataContext.getZipReader()); // Source and target group id Map<Long, Long> groupIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Group.class); groupIds.put(portletDataContext.getSourceGroupId(), portletDataContext.getGroupId()); // Manifest ManifestSummary manifestSummary = ExportImportHelperUtil.getManifestSummary(portletDataContext); if (BackgroundTaskThreadLocal.hasBackgroundTask()) { PortletDataHandlerStatusMessageSenderUtil.sendStatusMessage( "portlet", portletDataContext.getPortletId(), manifestSummary); } portletDataContext.setManifestSummary(manifestSummary); // Read expando tables, locks and permissions to make them // available to the data handlers through the portlet data context Element rootElement = portletDataContext.getImportDataRootElement(); Element portletElement = null; try { portletElement = rootElement.element("portlet"); Document portletDocument = SAXReaderUtil.read( portletDataContext.getZipEntryAsString(portletElement.attributeValue("path"))); portletElement = portletDocument.getRootElement(); } catch (DocumentException de) { throw new SystemException(de); } LayoutCache layoutCache = new LayoutCache(); if (importPermissions) { _permissionImporter.checkRoles( layoutCache, portletDataContext.getCompanyId(), portletDataContext.getGroupId(), userId, portletElement); _permissionImporter.readPortletDataPermissions(portletDataContext); } readExpandoTables(portletDataContext); readLocks(portletDataContext); Element portletDataElement = portletElement.element("portlet-data"); Map<String, Boolean> importPortletControlsMap = ExportImportHelperUtil.getImportPortletControlsMap( portletDataContext.getCompanyId(), portletDataContext.getPortletId(), parameterMap, portletDataElement, manifestSummary); Layout layout = _layoutLocalService.getLayout(portletDataContext.getPlid()); try { // Portlet preferences importPortletPreferences( portletDataContext, layout.getCompanyId(), portletDataContext.getGroupId(), layout, portletElement, true, importPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_ARCHIVED_SETUPS), importPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_DATA), importPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_SETUP), importPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_USER_PREFERENCES)); // Portlet data if (importPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_DATA)) { if (_log.isDebugEnabled()) { _log.debug("Importing portlet data"); } importPortletData(portletDataContext, portletDataElement); } } finally { resetPortletScope(portletDataContext, portletDataContext.getGroupId()); } // Portlet permissions if (importPermissions) { if (_log.isDebugEnabled()) { _log.debug("Importing portlet permissions"); } _permissionImporter.importPortletPermissions( layoutCache, portletDataContext.getCompanyId(), portletDataContext.getGroupId(), userId, layout, portletElement, portletDataContext.getPortletId()); if (userId > 0) { Indexer<User> indexer = IndexerRegistryUtil.nullSafeGetIndexer(User.class); User user = _userLocalService.fetchUser(userId); indexer.reindex(user); } } // Asset links if (_log.isDebugEnabled()) { _log.debug("Importing asset links"); } importAssetLinks(portletDataContext); // Deletion system events _deletionSystemEventImporter.importDeletionSystemEvents(portletDataContext); if (_log.isInfoEnabled()) { _log.info("Importing portlet takes " + stopWatch.getTime() + " ms"); } // Service portlet preferences boolean importPortletSetup = importPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_SETUP); if (importPortletSetup) { try { List<Element> serviceElements = rootElement.elements("service"); for (Element serviceElement : serviceElements) { Document serviceDocument = SAXReaderUtil.read( portletDataContext.getZipEntryAsString(serviceElement.attributeValue("path"))); importServicePortletPreferences(portletDataContext, serviceDocument.getRootElement()); } } catch (DocumentException de) { throw new SystemException(de); } } ZipReader zipReader = portletDataContext.getZipReader(); zipReader.close(); }
@Override protected void doImportStagedModel(PortletDataContext portletDataContext, FileEntry fileEntry) throws Exception { long userId = portletDataContext.getUserId(fileEntry.getUserUuid()); if (!fileEntry.isDefaultRepository()) { // References has been automatically imported, nothing to do here return; } Map<Long, Long> folderIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Folder.class); long folderId = MapUtil.getLong(folderIds, fileEntry.getFolderId(), fileEntry.getFolderId()); long[] assetCategoryIds = portletDataContext.getAssetCategoryIds(DLFileEntry.class, fileEntry.getFileEntryId()); String[] assetTagNames = portletDataContext.getAssetTagNames(DLFileEntry.class, fileEntry.getFileEntryId()); ServiceContext serviceContext = portletDataContext.createServiceContext(fileEntry, DLFileEntry.class); serviceContext.setAttribute("sourceFileName", "A." + fileEntry.getExtension()); serviceContext.setUserId(userId); Element fileEntryElement = portletDataContext.getImportDataElement(fileEntry); String binPath = fileEntryElement.attributeValue("bin-path"); InputStream is = null; if (Validator.isNull(binPath) && portletDataContext.isPerformDirectBinaryImport()) { try { is = FileEntryUtil.getContentStream(fileEntry); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn("Unable to retrieve content for file entry " + fileEntry.getFileEntryId(), e); } return; } } else { is = portletDataContext.getZipEntryAsInputStream(binPath); } if (is == null) { if (_log.isWarnEnabled()) { _log.warn("No file found for file entry " + fileEntry.getFileEntryId()); } return; } importMetaData(portletDataContext, fileEntryElement, fileEntry, serviceContext); FileEntry importedFileEntry = null; String titleWithExtension = DLUtil.getTitleWithExtension(fileEntry); String extension = fileEntry.getExtension(); String periodAndExtension = StringPool.PERIOD.concat(extension); if (portletDataContext.isDataStrategyMirror()) { FileEntry existingFileEntry = fetchStagedModelByUuidAndGroupId( fileEntry.getUuid(), portletDataContext.getScopeGroupId()); FileVersion fileVersion = fileEntry.getFileVersion(); if (existingFileEntry == null) { String fileEntryTitle = fileEntry.getTitle(); FileEntry existingTitleFileEntry = FileEntryUtil.fetchByR_F_T( portletDataContext.getScopeGroupId(), folderId, fileEntryTitle); if (existingTitleFileEntry != null) { if ((fileEntry.getGroupId() == portletDataContext.getSourceGroupId()) && portletDataContext.isDataStrategyMirrorWithOverwriting()) { DLAppLocalServiceUtil.deleteFileEntry(existingTitleFileEntry.getFileEntryId()); } else { boolean titleHasExtension = false; if (fileEntryTitle.endsWith(periodAndExtension)) { fileEntryTitle = FileUtil.stripExtension(fileEntryTitle); titleHasExtension = true; } for (int i = 1; ; i++) { fileEntryTitle += StringPool.SPACE + i; titleWithExtension = fileEntryTitle + periodAndExtension; existingTitleFileEntry = FileEntryUtil.fetchByR_F_T( portletDataContext.getScopeGroupId(), folderId, titleWithExtension); if (existingTitleFileEntry == null) { if (titleHasExtension) { fileEntryTitle += periodAndExtension; } break; } } } } serviceContext.setAttribute("fileVersionUuid", fileVersion.getUuid()); serviceContext.setUuid(fileEntry.getUuid()); importedFileEntry = DLAppLocalServiceUtil.addFileEntry( userId, portletDataContext.getScopeGroupId(), folderId, titleWithExtension, fileEntry.getMimeType(), fileEntryTitle, fileEntry.getDescription(), null, is, fileEntry.getSize(), serviceContext); if (fileEntry.isInTrash()) { importedFileEntry = DLAppServiceUtil.moveFileEntryToTrash(importedFileEntry.getFileEntryId()); } } else { FileVersion latestExistingFileVersion = existingFileEntry.getLatestFileVersion(true); boolean indexEnabled = serviceContext.isIndexingEnabled(); boolean deleteFileEntry = false; boolean updateFileEntry = false; if (!Validator.equals(fileVersion.getUuid(), latestExistingFileVersion.getUuid())) { deleteFileEntry = true; updateFileEntry = true; } else { InputStream existingFileVersionInputStream = null; try { existingFileVersionInputStream = latestExistingFileVersion.getContentStream(false); } catch (Exception e) { if (_log.isDebugEnabled()) { _log.debug(e, e); } } finally { if (existingFileVersionInputStream != null) { existingFileVersionInputStream.close(); } } if (existingFileVersionInputStream == null) { updateFileEntry = true; } } try { serviceContext.setIndexingEnabled(false); if (updateFileEntry) { DLFileVersion alreadyExistingFileVersion = DLFileVersionLocalServiceUtil.getFileVersionByUuidAndGroupId( fileVersion.getUuid(), existingFileEntry.getGroupId()); if (alreadyExistingFileVersion != null) { serviceContext.setAttribute( "existingDLFileVersionId", alreadyExistingFileVersion.getFileVersionId()); } serviceContext.setUuid(fileVersion.getUuid()); importedFileEntry = DLAppLocalServiceUtil.updateFileEntry( userId, existingFileEntry.getFileEntryId(), titleWithExtension, fileEntry.getMimeType(), fileEntry.getTitle(), fileEntry.getDescription(), null, false, is, fileEntry.getSize(), serviceContext); } else { DLAppLocalServiceUtil.updateAsset( userId, existingFileEntry, latestExistingFileVersion, assetCategoryIds, assetTagNames, null); importedFileEntry = existingFileEntry; } if (importedFileEntry.getFolderId() != folderId) { importedFileEntry = DLAppLocalServiceUtil.moveFileEntry( userId, importedFileEntry.getFileEntryId(), folderId, serviceContext); } if (importedFileEntry instanceof LiferayFileEntry) { LiferayFileEntry liferayFileEntry = (LiferayFileEntry) importedFileEntry; Indexer<DLFileEntry> indexer = IndexerRegistryUtil.nullSafeGetIndexer(DLFileEntry.class); indexer.reindex((DLFileEntry) liferayFileEntry.getModel()); } if (deleteFileEntry && ExportImportThreadLocal.isStagingInProcess()) { DLAppServiceUtil.deleteFileVersion( latestExistingFileVersion.getFileEntryId(), latestExistingFileVersion.getVersion()); } } finally { serviceContext.setIndexingEnabled(indexEnabled); } } } else { try { importedFileEntry = DLAppLocalServiceUtil.addFileEntry( userId, portletDataContext.getScopeGroupId(), folderId, titleWithExtension, fileEntry.getMimeType(), fileEntry.getTitle(), fileEntry.getDescription(), null, is, fileEntry.getSize(), serviceContext); } catch (DuplicateFileException dfe) { String title = fileEntry.getTitle(); String[] titleParts = title.split("\\.", 2); title = titleParts[0] + StringUtil.randomString(); if (titleParts.length > 1) { title += StringPool.PERIOD + titleParts[1]; } if (!title.endsWith(periodAndExtension)) { title += periodAndExtension; } importedFileEntry = DLAppLocalServiceUtil.addFileEntry( userId, portletDataContext.getScopeGroupId(), folderId, title, fileEntry.getMimeType(), title, fileEntry.getDescription(), null, is, fileEntry.getSize(), serviceContext); } } if (portletDataContext.getBooleanParameter( DLPortletDataHandler.NAMESPACE, "previews-and-thumbnails")) { DLProcessorRegistryUtil.importGeneratedFiles( portletDataContext, fileEntry, importedFileEntry, fileEntryElement); } portletDataContext.importClassedModel(fileEntry, importedFileEntry, DLFileEntry.class); Map<Long, Long> fileEntryIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(FileEntry.class); fileEntryIds.put(fileEntry.getFileEntryId(), importedFileEntry.getFileEntryId()); }