List of usage examples for com.liferay.portal.kernel.service ServiceContext setCommand
public void setCommand(String command)
From source file:com.liferay.blogs.service.impl.BlogsEntryLocalServiceImpl.java
License:Open Source License
@Override public void checkEntries() throws PortalException { Date now = new Date(); int count = blogsEntryPersistence.countByLtD_S(now, WorkflowConstants.STATUS_SCHEDULED); if (count == 0) { return;/*from w ww . j a va2 s.com*/ } List<BlogsEntry> entries = blogsEntryPersistence.findByLtD_S(now, WorkflowConstants.STATUS_SCHEDULED); for (BlogsEntry entry : entries) { ServiceContext serviceContext = new ServiceContext(); String[] trackbacks = StringUtil.split(entry.getTrackbacks()); serviceContext.setAttribute("trackbacks", trackbacks); serviceContext.setCommand(Constants.UPDATE); String portletId = PortletProviderUtil.getPortletId(BlogsEntry.class.getName(), PortletProvider.Action.VIEW); if (Validator.isNotNull(portletId)) { String layoutFullURL = PortalUtil.getLayoutFullURL(entry.getGroupId(), portletId); serviceContext.setLayoutFullURL(layoutFullURL); } serviceContext.setScopeGroupId(entry.getGroupId()); blogsEntryLocalService.updateStatus(entry.getStatusByUserId(), entry.getEntryId(), WorkflowConstants.STATUS_APPROVED, serviceContext, new HashMap<String, Serializable>()); } }
From source file:com.liferay.blogs.service.impl.BlogsEntryLocalServiceImpl.java
License:Open Source License
@Indexable(type = IndexableType.REINDEX) @Override// ww w . jav a 2 s. com public BlogsEntry updateStatus(long userId, long entryId, int status, ServiceContext serviceContext, Map<String, Serializable> workflowContext) throws PortalException { // Entry User user = userPersistence.findByPrimaryKey(userId); Date now = new Date(); BlogsEntry entry = blogsEntryPersistence.findByPrimaryKey(entryId); int oldStatus = entry.getStatus(); if ((status == WorkflowConstants.STATUS_APPROVED) && now.before(entry.getDisplayDate())) { status = WorkflowConstants.STATUS_SCHEDULED; } entry.setStatus(status); entry.setStatusByUserId(user.getUserId()); entry.setStatusByUserName(user.getFullName()); entry.setStatusDate(serviceContext.getModifiedDate(now)); if ((status == WorkflowConstants.STATUS_APPROVED) && Validator.isNull(entry.getUrlTitle())) { entry.setUrlTitle(getUniqueUrlTitle(entryId, entry.getGroupId(), entry.getTitle())); } blogsEntryPersistence.update(entry); // Statistics blogsStatsUserLocalService.updateStatsUser(entry.getGroupId(), entry.getUserId(), entry.getDisplayDate()); AssetEntry assetEntry = assetEntryLocalService.fetchEntry(BlogsEntry.class.getName(), entryId); if ((assetEntry == null) || (assetEntry.getPublishDate() == null)) { serviceContext.setCommand(Constants.ADD); } JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject(); extraDataJSONObject.put("title", entry.getTitle()); if (status == WorkflowConstants.STATUS_APPROVED) { // Asset assetEntryLocalService.updateEntry(BlogsEntry.class.getName(), entryId, entry.getDisplayDate(), null, true, true); // Social if ((oldStatus != WorkflowConstants.STATUS_IN_TRASH) && (oldStatus != WorkflowConstants.STATUS_SCHEDULED)) { if (serviceContext.isCommandUpdate()) { SocialActivityManagerUtil.addActivity(user.getUserId(), entry, BlogsActivityKeys.UPDATE_ENTRY, extraDataJSONObject.toString(), 0); } else { SocialActivityManagerUtil.addUniqueActivity(user.getUserId(), entry, BlogsActivityKeys.ADD_ENTRY, extraDataJSONObject.toString(), 0); } } // Trash if (oldStatus == WorkflowConstants.STATUS_IN_TRASH) { if (PropsValues.BLOGS_ENTRY_COMMENTS_ENABLED) { CommentManagerUtil.restoreDiscussionFromTrash(BlogsEntry.class.getName(), entryId); } trashEntryLocalService.deleteEntry(BlogsEntry.class.getName(), entryId); } if (oldStatus != WorkflowConstants.STATUS_IN_TRASH) { // Subscriptions notifySubscribers(userId, entry, serviceContext, workflowContext); // Ping String[] trackbacks = (String[]) serviceContext.getAttribute("trackbacks"); Boolean pingOldTrackbacks = ParamUtil.getBoolean(serviceContext, "pingOldTrackbacks"); pingGoogle(entry, serviceContext); pingPingback(entry, serviceContext); pingTrackbacks(entry, trackbacks, pingOldTrackbacks, serviceContext); } } else { // Asset assetEntryLocalService.updateVisible(BlogsEntry.class.getName(), entryId, false); // Social if ((status == WorkflowConstants.STATUS_SCHEDULED) && (oldStatus != WorkflowConstants.STATUS_IN_TRASH)) { if (serviceContext.isCommandUpdate()) { SocialActivityManagerUtil.addActivity(user.getUserId(), entry, BlogsActivityKeys.UPDATE_ENTRY, extraDataJSONObject.toString(), 0); } else { SocialActivityManagerUtil.addUniqueActivity(user.getUserId(), entry, BlogsActivityKeys.ADD_ENTRY, extraDataJSONObject.toString(), 0); } } // Trash if (status == WorkflowConstants.STATUS_IN_TRASH) { if (PropsValues.BLOGS_ENTRY_COMMENTS_ENABLED) { CommentManagerUtil.moveDiscussionToTrash(BlogsEntry.class.getName(), entryId); } trashEntryLocalService.addTrashEntry(userId, entry.getGroupId(), BlogsEntry.class.getName(), entry.getEntryId(), entry.getUuid(), null, oldStatus, null, null); } else if (oldStatus == WorkflowConstants.STATUS_IN_TRASH) { if (PropsValues.BLOGS_ENTRY_COMMENTS_ENABLED) { CommentManagerUtil.restoreDiscussionFromTrash(BlogsEntry.class.getName(), entryId); } trashEntryLocalService.deleteEntry(BlogsEntry.class.getName(), entryId); } } return entry; }
From source file:com.liferay.blogs.service.test.BlogsEntryStatusTransitionTest.java
License:Open Source License
protected ServiceContext getServiceContext(BlogsEntry entry) throws Exception { ServiceContext serviceContext = new ServiceContext(); String[] trackbacks = StringUtil.split(entry.getTrackbacks()); serviceContext.setAttribute("trackbacks", trackbacks); serviceContext.setCommand(Constants.UPDATE); String portletId = PortletProviderUtil.getPortletId(BlogsEntry.class.getName(), PortletProvider.Action.VIEW); String layoutFullURL = PortalUtil.getLayoutFullURL(entry.getGroupId(), portletId); serviceContext.setLayoutFullURL(layoutFullURL); serviceContext.setScopeGroupId(entry.getGroupId()); return serviceContext; }
From source file:com.liferay.blogs.test.util.BlogsTestUtil.java
License:Open Source License
public static void populateNotificationsServiceContext(ServiceContext serviceContext, String command) throws Exception { serviceContext.setAttribute("entryURL", "http://localhost"); if (Validator.isNotNull(command)) { serviceContext.setCommand(command); }// w w w . j a va 2s .c o m serviceContext.setLayoutFullURL("http://localhost"); }
From source file:com.liferay.bookmarks.util.test.BookmarksTestUtil.java
License:Open Source License
public static BookmarksEntry addEntry(String name, long folderId, boolean approved, ServiceContext serviceContext) throws Exception { boolean workflowEnabled = WorkflowThreadLocal.isEnabled(); try {//from w ww . j a v a 2 s .c om WorkflowThreadLocal.setEnabled(true); String url = "http://www.liferay.com"; String description = "This is a test entry."; serviceContext = (ServiceContext) serviceContext.clone(); serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT); BookmarksEntry entry = BookmarksEntryServiceUtil.addEntry(serviceContext.getScopeGroupId(), folderId, name, url, description, serviceContext); serviceContext.setCommand(Constants.ADD); serviceContext.setLayoutFullURL("http://localhost"); if (approved) { entry.setStatus(WorkflowConstants.STATUS_APPROVED); entry = BookmarksEntryServiceUtil.updateEntry(entry.getEntryId(), serviceContext.getScopeGroupId(), entry.getFolderId(), entry.getName(), entry.getUrl(), entry.getUrl(), serviceContext); } return entry; } finally { WorkflowThreadLocal.setEnabled(workflowEnabled); } }
From source file:com.liferay.bookmarks.util.test.BookmarksTestUtil.java
License:Open Source License
public static BookmarksEntry updateEntry(BookmarksEntry entry, String name) throws Exception { ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(entry.getGroupId()); serviceContext.setCommand(Constants.UPDATE); serviceContext.setLayoutFullURL("http://localhost"); return BookmarksEntryLocalServiceUtil.updateEntry(TestPropsValues.getUserId(), entry.getEntryId(), entry.getGroupId(), entry.getFolderId(), name, entry.getUrl(), entry.getDescription(), serviceContext);//from w ww.j av a 2s .c om }
From source file:com.liferay.document.library.web.internal.webdav.DLWebDAVStorageImpl.java
License:Open Source License
@Override public int putResource(WebDAVRequest webDAVRequest) throws WebDAVException { File file = null;/*from ww w .j a v a 2 s. c o m*/ try { HttpServletRequest request = webDAVRequest.getHttpServletRequest(); String[] pathArray = webDAVRequest.getPathArray(); long companyId = webDAVRequest.getCompanyId(); long groupId = webDAVRequest.getGroupId(); long parentFolderId = getParentFolderId(companyId, pathArray); String title = getTitle(pathArray); String description = StringPool.BLANK; String changeLog = StringPool.BLANK; ServiceContext serviceContext = ServiceContextFactory.getInstance(request); serviceContext.setAddGroupPermissions(isAddGroupPermissions(groupId)); serviceContext.setAddGuestPermissions(true); String extension = FileUtil.getExtension(title); file = FileUtil.createTempFile(extension); FileUtil.write(file, request.getInputStream()); String contentType = getContentType(request, file, title, extension); try { FileEntry fileEntry = _dlAppService.getFileEntry(groupId, parentFolderId, title); if (!hasLock(fileEntry, webDAVRequest.getLockUuid()) && (fileEntry.getLock() != null)) { return WebDAVUtil.SC_LOCKED; } long fileEntryId = fileEntry.getFileEntryId(); description = fileEntry.getDescription(); populateServiceContext(serviceContext, fileEntry); serviceContext.setCommand(Constants.UPDATE_WEBDAV); _dlAppService.updateFileEntry(fileEntryId, title, contentType, title, description, changeLog, false, file, serviceContext); } catch (NoSuchFileEntryException nsfee) { if (_log.isDebugEnabled()) { _log.debug(nsfee, nsfee); } serviceContext.setCommand(Constants.ADD_WEBDAV); _dlAppService.addFileEntry(groupId, parentFolderId, title, contentType, title, description, changeLog, file, serviceContext); } if (_log.isInfoEnabled()) { _log.info("Added " + StringUtil.merge(pathArray, StringPool.SLASH)); } return HttpServletResponse.SC_CREATED; } catch (FileSizeException fse) { if (_log.isDebugEnabled()) { _log.debug(fse, fse); } return HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE; } catch (NoSuchFolderException nsfe) { if (_log.isDebugEnabled()) { _log.debug(nsfe, nsfe); } return HttpServletResponse.SC_CONFLICT; } catch (PrincipalException pe) { if (_log.isDebugEnabled()) { _log.debug(pe, pe); } return HttpServletResponse.SC_FORBIDDEN; } catch (PortalException pe) { if (_log.isWarnEnabled()) { _log.warn(pe, pe); } return HttpServletResponse.SC_CONFLICT; } catch (Exception e) { throw new WebDAVException(e); } finally { FileUtil.delete(file); } }
From source file:com.liferay.dynamic.data.lists.service.impl.DDLRecordLocalServiceImpl.java
License:Open Source License
/** * Reverts the record to the given version. * * @param userId the primary key of the user who is reverting the record * @param recordId the primary key of the record * @param version the version to revert to * @param serviceContext the service context to be applied. This can set * the record modified date./* w w w. ja va 2s .co m*/ * @throws PortalException if a portal exception occurred */ @Override public void revertRecord(long userId, long recordId, String version, ServiceContext serviceContext) throws PortalException { DDLRecordVersion recordVersion = ddlRecordVersionLocalService.getRecordVersion(recordId, version); if (!recordVersion.isApproved()) { return; } DDMFormValues ddmFormValues = storageEngine.getDDMFormValues(recordVersion.getDDMStorageId()); serviceContext.setCommand(Constants.REVERT); ddlRecordLocalService.updateRecord(userId, recordId, true, recordVersion.getDisplayIndex(), ddmFormValues, serviceContext); }
From source file:com.liferay.dynamic.data.mapping.service.impl.DDMFormInstanceRecordLocalServiceImpl.java
License:Open Source License
@Override public void revertFormInstanceRecord(long userId, long ddmFormInstanceRecordId, String version, ServiceContext serviceContext) throws PortalException { DDMFormInstanceRecordVersion ddmFormInstanceRecordVersion = ddmFormInstanceRecordVersionLocalService .getFormInstanceRecordVersion(ddmFormInstanceRecordId, version); if (!ddmFormInstanceRecordVersion.isApproved()) { return;// w w w . j a v a 2 s .co m } StorageEngine storageEngine = storageEngineAccessor.getStorageEngine(); DDMFormValues ddmFormValues = storageEngine.getDDMFormValues(ddmFormInstanceRecordVersion.getStorageId()); serviceContext.setCommand(Constants.REVERT); updateFormInstanceRecord(userId, ddmFormInstanceRecordId, true, ddmFormValues, serviceContext); }
From source file:com.liferay.dynamic.data.mapping.service.impl.DDMStructureLocalServiceImpl.java
License:Open Source License
@Override public void revertStructure(long userId, long structureId, String version, ServiceContext serviceContext) throws PortalException { DDMStructureVersion structureVersion = ddmStructureVersionLocalService.getStructureVersion(structureId, version);//from w w w .java 2 s. c o m if (!structureVersion.isApproved()) { throw new InvalidStructureVersionException("Unable to revert from an unapproved file version"); } DDMStructure structure = structureVersion.getStructure(); serviceContext.setAttribute("majorVersion", Boolean.TRUE); serviceContext.setAttribute("status", WorkflowConstants.STATUS_APPROVED); serviceContext.setCommand(Constants.REVERT); ddmStructureLocalService.updateStructure(userId, structure.getGroupId(), structureVersion.getParentStructureId(), structure.getClassNameId(), structure.getStructureKey(), structureVersion.getNameMap(), structureVersion.getDescriptionMap(), structureVersion.getDDMForm(), structureVersion.getDDMFormLayout(), serviceContext); }